react-reason-editor 1.0.80 → 1.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BubbleMenus-vqNuXWlm.cjs → BubbleMenus-D1uFJJL1.cjs} +1 -1
- package/dist/{BubbleMenus-CIOMgQ-M.js → BubbleMenus-DIKbCm67.js} +1 -1
- package/dist/FontSize.cjs +1 -1
- package/dist/FontSize.js +1 -1
- package/dist/{Heading-Bcrl3eKU.js → Heading-BCa-LW8o.js} +1 -1
- package/dist/Heading.cjs +1 -1
- package/dist/Heading.js +1 -1
- package/dist/LineHeight.cjs +1 -1
- package/dist/LineHeight.js +1 -1
- package/dist/{MoreMark-Bfsa3STU.js → MoreMark-DOhnB4xI.js} +1 -1
- package/dist/MoreMark.cjs +1 -1
- package/dist/MoreMark.js +1 -1
- package/dist/{ReasonDocs-Cwj6pAAY.js → ReasonDocs-D-vS87iT.js} +104 -105
- package/dist/{ReasonDocs-CXj3ne3U.cjs → ReasonDocs-UxpbwteO.cjs} +1 -1
- package/dist/{RichTextProvider-BuTrDlZY.cjs → RichTextProvider-COW59xhl.cjs} +1 -1
- package/dist/{RichTextProvider-D9EtjDKS.js → RichTextProvider-ChSp_ZVC.js} +1 -1
- package/dist/{bubble-BhkjoWdo.js → bubble-BrxMujzD.js} +1 -1
- package/dist/bubble.cjs +1 -1
- package/dist/bubble.js +1 -1
- package/dist/docs-agent.cjs +1 -1
- package/dist/docs-agent.js +1 -1
- package/dist/dropdown-menu-By9VjdjW.cjs +1 -0
- package/dist/dropdown-menu-tmQwCqOR.js +2 -0
- package/dist/editor-kit.cjs +1 -1
- package/dist/editor-kit.js +1 -1
- package/dist/editorConfig-BAZYamPM.cjs +1 -0
- package/dist/{editorConfig-BR7z-P0e.js → editorConfig-DqEFArGq.js} +1 -1
- package/dist/features/settings/sections/FileSourcesSection.d.ts +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/reason-docs.cjs +1 -1
- package/dist/reason-docs.js +1 -1
- package/dist/{reason-toolbar-skin-CD4T53He.cjs → reason-toolbar-skin-C5X8hUwr.cjs} +1 -1
- package/dist/{reason-toolbar-skin-BNYK97ET.js → reason-toolbar-skin-e9MfqS7c.js} +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/dist/dropdown-menu-BNKyUimd.cjs +0 -1
- package/dist/dropdown-menu-BhMqMb9N.js +0 -2
- package/dist/editorConfig-CHBSp2KG.cjs +0 -1
- package/dist/features/settings/sections/StorageSection.d.ts +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./rolldown-runtime-BeavJI0R.cjs"),t=require("./dist-2-kjLBhJ.cjs"),n=require("./editorConfig-CHBSp2KG.cjs"),r=require("./toggle-JU5XOZYT.cjs"),s=require("./locales-DRkmn37v.cjs"),i=require("./floating-ui.dom-DG-jWCyc.cjs"),o=require("./useButtonProps-BBiR6DPI.cjs"),l=require("./theme.cjs"),a=require("./cdn-loader-BGIuN138-7PrAg-Ef.cjs"),c=require("./Harper-nz_06NJH.cjs"),d=require("./Ai-CfgczVyp.cjs"),h=require("./Drawio-CD_Tea_o.cjs"),u=require("./ReadAloud.cjs"),p=require("./Transcribe.cjs"),m=require("./SelectSimilar.cjs"),f=require("./WordCount.cjs");let g=require("@tiptap/react"),x=require("react");x=e.__toESM(x,1);let b=require("@tiptap/core"),y=require("@tiptap/pm/state"),w=require("react/jsx-runtime"),v=require("lucide-react"),k=require("react-dom"),j=require("@tiptap/react/menus"),S=require("@tiptap/pm/view"),C=require("@tiptap/pm/model"),N=require("use-voice-control/react"),E=require("easydrawer"),A=require("@tiptap/pm/commands"),T=require("use-voice-control/client");function M({children:e,label:n,className:r,icon:s,shortcut:i}){const o=(0,x.useRef)(null),l=(0,x.isValidElement)(e)?(0,x.cloneElement)(e,{tooltip:n?void 0:e.props?.tooltip,tooltipOptions:n?void 0:e.props?.tooltipOptions}):e;return(0,w.jsxs)("div",{ref:o,className:t.cn("flex items-center gap-2 px-2 py-0.5 rounded cursor-pointer w-full text-left","hover:bg-gray-100/80 dark:hover:bg-slate-800/80","transition-colors",r),onClick:e=>{e.stopPropagation(),e.target.closest('button, [role="button"], a')||(o.current?.querySelector("button"))?.click()},children:[s&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:s}),(0,w.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[l,n&&(0,w.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:n}),i&&(0,w.jsx)("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 ml-auto whitespace-nowrap shrink-0",children:i})]})]})}function _(){const e=o.useButtonProps("subscript"),{icon:t,tooltip:n,shortcutKeys:s,tooltipOptions:i={},action:l,isActive:a}=e?.componentProps??{},{dataState:c,disabled:d,update:h}=o.useToggleActive(a);return e?(0,w.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,w.jsx)(w.Fragment,{})}function D(){const e=o.useButtonProps("superscript"),{icon:t,tooltip:n,shortcutKeys:s,tooltipOptions:i={},action:l,isActive:a}=e?.componentProps??{},{dataState:c,disabled:d,update:h}=o.useToggleActive(a);return e?(0,w.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,w.jsx)(w.Fragment,{})}function O({message:e}){const[t,n]=(0,x.useState)(!0);return(0,x.useEffect)(()=>{const e=setTimeout(()=>n(!1),2e3);return()=>clearTimeout(e)},[]),t?(0,k.createPortal)((0,w.jsx)("div",{className:"fixed bottom-4 right-4 z-[100] animate-in fade-in slide-in-from-bottom-2",children:(0,w.jsx)("div",{className:"bg-gray-900 dark:bg-gray-800 text-white px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium",children:e})}),document.body):null}function $(){const{editor:e}=(0,g.useCurrentEditor)(),[t,n]=(0,x.useState)(1.25),[r,s]=(0,x.useState)(null),i=e=>{s(e)},o=(0,x.useCallback)(t=>{const n=e?.view?.dom??document.querySelector(".ProseMirror");if(!n)return;const r=n;r.style.zoom=String(t),r.style.transform="",r.style.transformOrigin=""},[e]);return(0,x.useEffect)(()=>{o(t)},[o,t]),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,w.jsx)("button",{onClick:()=>{const e=Math.max(t-.25,.5);n(e),o(e),i(`Zoom: ${Math.round(100*e)}%`)},title:`Zoom Out (${Math.round(100*t)}%)`,className:"richtext-p-1 richtext-h-8 richtext-flex richtext-items-center richtext-justify-center richtext-rounded text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white transition-colors",children:(0,w.jsx)(v.ZoomOut,{size:16})}),(0,w.jsx)("button",{onClick:()=>{const e=Math.min(t+.25,2);n(e),o(e),i(`Zoom: ${Math.round(100*e)}%`)},title:`Zoom In (${Math.round(100*t)}%)`,className:"richtext-p-1 richtext-h-8 richtext-flex richtext-items-center richtext-justify-center richtext-rounded text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white transition-colors",children:(0,w.jsx)(v.ZoomIn,{size:16})})]}),r&&(0,w.jsx)(O,{message:r})]})}var R={a4:{name:"A4",pageHeight:1123,pageWidth:794,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},a3:{name:"A3",pageHeight:1591,pageWidth:1123,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},letter:{name:"Letter",pageHeight:1100,pageWidth:850,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},legal:{name:"Legal",pageHeight:1400,pageWidth:850,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72}};function I(){const{editor:e}=(0,g.useCurrentEditor)(),[t,n]=(0,x.useState)(!1),[r,s]=(0,x.useState)("page"),[i,o]=(0,x.useState)({pageHeight:1056,pageWidth:816,pageGap:50,pageGapBorderSize:1,pageGapBorderColor:"#e5e5e5",pageBreakBackground:"#ffffff",marginTop:48,marginBottom:48,marginLeft:72,marginRight:72,contentMarginTop:10,contentMarginBottom:10,headerLeft:"",headerRight:"Page {page}",footerLeft:"",footerRight:""}),l=(0,x.useRef)(null),a=(0,x.useRef)(null),[c,d]=(0,x.useState)({top:0,left:-9999,visibility:"hidden"});if((0,x.useEffect)(()=>{if(!t)return;const e=e=>{const t=e.target;t?.isConnected&&(l.current?.contains(t)||a.current?.contains(t)||n(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t]),(0,x.useLayoutEffect)(()=>{if(!t)return;const e=()=>{const e=a.current,t=l.current;if(!e||!t)return;const n=window.innerWidth,r=window.innerHeight,s=t.getBoundingClientRect(),i=t.closest(".dropdown-portal")?.getBoundingClientRect()??s,{offsetWidth:o,offsetHeight:c}=e;let h=i.right+8;h+o>n-8&&(h=i.left-o-8),h=Math.max(8,Math.min(h,n-o-8));const u=Math.max(8,Math.min(s.top,r-c-8));d({top:u,left:h,maxHeight:r-u-8})};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[t,r]),!e)return null;const h=t=>{const n={...i,...t};o(n),t.pageHeight&&e.commands.updatePageHeight?.(t.pageHeight),t.pageWidth&&e.commands.updatePageWidth?.(t.pageWidth),t.pageGap&&e.commands.updatePageGap?.(t.pageGap),(t.marginTop||t.marginBottom||t.marginLeft||t.marginRight)&&e.commands.updateMargins?.({top:t.marginTop??i.marginTop,bottom:t.marginBottom??i.marginBottom,left:t.marginLeft??i.marginLeft,right:t.marginRight??i.marginRight}),(t.contentMarginTop||t.contentMarginBottom)&&e.commands.updateContentMargins?.({top:t.contentMarginTop??i.contentMarginTop,bottom:t.contentMarginBottom??i.contentMarginBottom}),(t.headerLeft||t.headerRight)&&e.commands.updateHeaderContent?.(t.headerLeft??i.headerLeft,t.headerRight??i.headerRight),(t.footerLeft||t.footerRight)&&e.commands.updateFooterContent?.(t.footerLeft??i.footerLeft,t.footerRight??i.footerRight),t.pageBreakBackground&&e.commands.updatePageBreakBackground?.(t.pageBreakBackground)};return(0,w.jsxs)("div",{className:"relative",ref:l,children:[(0,w.jsxs)("button",{onClick:()=>n(!t),className:"flex items-center gap-1 px-2 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800 rounded transition-colors",title:"Page settings",children:[(0,w.jsx)(v.Settings,{className:"w-4 h-4"}),(0,w.jsx)(v.ChevronDown,{className:"w-3 h-3"})]}),t&&(0,k.createPortal)((0,w.jsxs)("div",{ref:a,"data-richtext-portal":!0,className:"dropdown-portal fixed flex flex-col overflow-hidden bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg shadow-2xl z-50 w-96 max-w-[calc(100vw-16px)]",style:c,children:[(0,w.jsx)("div",{className:"flex border-b dark:border-gray-700 shrink-0",children:["page","spacing","header-footer"].map(e=>(0,w.jsxs)("button",{onClick:()=>s(e),className:"flex-1 px-3 py-2 text-sm font-medium transition-colors "+(r===e?"border-b-2 border-blue-500 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200"),children:["page"===e&&"Page","spacing"===e&&"Spacing","header-footer"===e&&"Header/Footer"]},e))}),(0,w.jsxs)("div",{className:"flex-1 min-h-0 p-4 space-y-4 overflow-y-auto",children:["page"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-2 text-gray-700 dark:text-gray-300",children:"Presets"}),(0,w.jsx)("div",{className:"grid grid-cols-4 gap-2",children:Object.entries(R).map(([e,t])=>(0,w.jsx)("button",{onClick:()=>(e=>{h({pageHeight:e.pageHeight,pageWidth:e.pageWidth,marginTop:e.marginTop,marginBottom:e.marginBottom,marginLeft:e.marginLeft,marginRight:e.marginRight})})(t),className:"px-2 py-1 text-xs bg-gray-50 dark:bg-gray-800 border dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:t.name},e))})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Height (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageHeight,onChange:e=>h({pageHeight:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:400,max:2e3})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Width (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageWidth,onChange:e=>h({pageWidth:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:400,max:2e3})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Gap (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageGap,onChange:e=>h({pageGap:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:100})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Gap Border Color"}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsx)("input",{type:"color",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"w-10 h-9 rounded cursor-pointer"}),(0,w.jsx)("input",{type:"text",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"flex-1 px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"})]})]})]}),"spacing"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Page Margins (px)"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,w.jsx)("input",{type:"number",value:i.marginTop,onChange:e=>h({marginTop:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,w.jsx)("input",{type:"number",value:i.marginBottom,onChange:e=>h({marginBottom:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Left"}),(0,w.jsx)("input",{type:"number",value:i.marginLeft,onChange:e=>h({marginLeft:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Right"}),(0,w.jsx)("input",{type:"number",value:i.marginRight,onChange:e=>h({marginRight:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Content Margins (px)"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,w.jsx)("input",{type:"number",value:i.contentMarginTop,onChange:e=>h({contentMarginTop:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:50})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,w.jsx)("input",{type:"number",value:i.contentMarginBottom,onChange:e=>h({contentMarginBottom:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:50})]})]})]})]}),"header-footer"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Header Left (supports HTML)"}),(0,w.jsx)("textarea",{value:i.headerLeft,onChange:e=>h({headerLeft:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., <strong>Company Name</strong>"})]}),(0,w.jsxs)("div",{children:[(0,w.jsxs)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:["Header Right (use ","{page}"," for page number)"]}),(0,w.jsx)("textarea",{value:i.headerRight,onChange:e=>h({headerRight:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., Page {page}"})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Footer Left (supports HTML)"}),(0,w.jsx)("textarea",{value:i.footerLeft,onChange:e=>h({footerLeft:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., <em>Confidential</em>"})]}),(0,w.jsxs)("div",{children:[(0,w.jsxs)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:["Footer Right (use ","{page}"," for page number)"]}),(0,w.jsx)("textarea",{value:i.footerRight,onChange:e=>h({footerRight:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., Page {page} of {total}"})]})]})]})]}),document.body)]})}var P=[1,2,3,4];function L({editor:e,onClose:t,defaultLevel:n=3}){const[r,s]=(0,x.useState)([]),[i,o]=(0,x.useState)(""),[l,a]=(0,x.useState)(n),[c,d]=(0,x.useState)(null);(0,x.useEffect)(()=>{if(!e)return;const t=()=>{const t=[];e.state.doc.descendants((e,n)=>{"heading"===e.type.name&&t.push({level:e.attrs.level,text:e.textContent,pos:n,index:t.length})}),s(t)};return t(),e.on("update",t),()=>e.off("update",t)},[e]);const h=(0,x.useMemo)(()=>{const e=i.trim().toLowerCase();return r.filter(t=>t.level<=l&&(""===e||t.text.toLowerCase().includes(e)))},[r,i,l]),u=(0,x.useCallback)(t=>{if(!e)return;const n=e.view.nodeDOM(t);n&&"function"==typeof n.scrollIntoView&&n.scrollIntoView({behavior:"smooth",block:"start"}),e.chain().focus().setTextSelection(t+1).run(),d(t)},[e]);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed right-4 top-24 z-50 flex w-72 max-h-[70vh] flex-col rounded-lg border border-gray-200/60 bg-white/80 shadow-xl backdrop-blur-md dark:border-slate-700/60 dark:bg-slate-900/80",children:[(0,w.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)(v.ListTree,{size:15,className:"text-blue-500"}),(0,w.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:"Table of Contents"})]}),(0,w.jsx)("button",{onClick:t,title:"Hide table of contents",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:14})})]}),(0,w.jsxs)("div",{className:"border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-800",children:[(0,w.jsx)(v.Search,{size:13,className:"shrink-0 text-gray-400"}),(0,w.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:"Filter headings…",className:"w-full bg-transparent text-xs text-gray-700 outline-none placeholder:text-gray-400 dark:text-gray-200"}),i&&(0,w.jsx)("button",{onClick:()=>o(""),className:"shrink-0 text-gray-400 hover:text-gray-600",title:"Clear filter",children:(0,w.jsx)(v.X,{size:12})})]}),(0,w.jsxs)("div",{className:"mt-2 flex items-center gap-1",children:[(0,w.jsx)("span",{className:"mr-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400",children:"Level"}),P.map(e=>(0,w.jsxs)("button",{onClick:()=>a(e),title:`Unfold headings up to H${e}`,className:"flex-1 rounded px-1.5 py-1 text-[11px] font-medium transition-colors "+(l===e?"bg-blue-500 text-white":"border border-gray-200 text-gray-600 hover:bg-gray-100 dark:border-slate-700 dark:text-gray-300 dark:hover:bg-slate-800"),children:["H",e]},e))]})]}),(0,w.jsx)("nav",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:0===h.length?(0,w.jsx)("div",{className:"px-2 py-6 text-center text-xs text-gray-400",children:0===r.length?"No headings yet.":"No headings match your filter."}):h.map(e=>(0,w.jsx)("button",{onClick:()=>u(e.pos),style:{paddingLeft:12*(e.level-1)+8+"px"},className:"block w-full truncate rounded py-1.5 pr-2 text-left text-xs transition-colors "+(c===e.pos?"bg-blue-50 font-medium text-blue-700 dark:bg-blue-900/30 dark:text-blue-300":"text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-slate-800"),children:e.text||`Heading ${e.level}`},e.pos))})]}),document.body)}function z({editor:e,className:n}){const[r,s]=(0,x.useState)(null),i=(0,x.useRef)(null),o=(0,x.useCallback)(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),l=(0,x.useCallback)(()=>{o(),i.current=setTimeout(()=>s(null),120)},[o]),a=(0,x.useCallback)(t=>{if(!e)return;const n=t.getAttribute("data-harper-id");if(!n)return;const r=c.getHarperState(e.state)?.issues.get(n);if(!r)return;const i=t.getBoundingClientRect();o(),s({issue:r,top:i.bottom+6,left:i.left})},[e,o]);if((0,x.useEffect)(()=>{if(!e)return;const t=e.view.dom,n=e=>{const t=e.target?.closest("[data-harper-id]");t&&a(t)},r=e=>{e.relatedTarget?.closest("[data-harper-id]")||l()};return t.addEventListener("mouseover",n),t.addEventListener("mouseout",r),()=>{t.removeEventListener("mouseover",n),t.removeEventListener("mouseout",r)}},[e,a,l]),!e||!r)return null;const{issue:d,top:h,left:u}=r;return(0,w.jsxs)("div",{role:"dialog","aria-label":"Proofing suggestion",className:t.cn("harper-tooltip",n),style:{position:"fixed",top:h,left:u,zIndex:60},onMouseEnter:o,onMouseLeave:l,children:[(0,w.jsx)("div",{className:"harper-tooltip-header",children:(0,w.jsx)("span",{className:"harper-tooltip-kind",children:d.kind})}),(0,w.jsx)("p",{className:"harper-tooltip-message",children:d.message}),(0,w.jsxs)("div",{className:"harper-tooltip-actions",children:[0===d.suggestions.length?(0,w.jsx)("span",{className:"harper-tooltip-empty",children:"No suggestions"}):d.suggestions.map((t,n)=>(0,w.jsx)("button",{type:"button",className:"harper-tooltip-suggestion",onClick:()=>(t=>{e.chain().focus().applyHarperSuggestion(d.id,t).run(),s(null)})(n),children:t.label||"(empty)"},`${t.kind}-${t.replacement}-${n}`)),(0,w.jsx)("button",{type:"button",className:"harper-tooltip-ignore",onClick:()=>{e.chain().focus().ignoreHarperSuggestion(d.id).run(),s(null)},children:"Ignore"})]})]})}var B={status:"closed"};function F({icon:e,label:t,onClick:n,disabled:r,title:s}){return(0,w.jsxs)("button",{type:"button",disabled:r,onClick:n,title:s,className:"ai-menu-row",children:[(0,w.jsx)(e,{className:"ai-menu-row-icon"}),t]})}function V(){const e=o.useEditorInstance(),t=o.useEditableEditor(),n=(0,x.useRef)(null),r=(0,x.useRef)(null),[s,l]=(0,x.useState)(""),[a,c]=(0,x.useState)(-1),[h,u]=(0,x.useState)(null),[p,m]=(0,x.useState)(!1),[f,b]=(0,x.useState)(null),y=(0,g.useEditorState)({editor:e,selector:({editor:e})=>e?d.getAiState(e.state)?.panel??B:B}),j=(0,x.useMemo)(()=>"closed"===y.status?null:"reviewing"===y.status?{from:y.suggestion.from,to:y.suggestion.to}:{from:y.from,to:y.to},[y]),S="closed"!==y.status,C=!!j&&j.to>j.from,N=j?j.to-j.from:0,E=e?d.getAiOptions(e)?.commands??[]:[],A=s.trim().toLowerCase(),T=(0,x.useMemo)(()=>{const e=d.commandsForSelection(E,C);return A?e.filter(e=>`${e.label} ${e.description??""}`.toLowerCase().includes(A)):e},[E,A,C]),M=(0,x.useMemo)(()=>d.groupCommands(T),[T]);if((0,x.useEffect)(()=>{if("menu"===y.status){const e=requestAnimationFrame(()=>r.current?.focus());return()=>cancelAnimationFrame(e)}"closed"===y.status&&(l(""),u(null),c(-1),m(!1))},[y.status]),(0,x.useEffect)(()=>{c(e=>e>=T.length?T.length-1:e)},[T.length]),(0,x.useEffect)(()=>{if(!e||!j||!n.current)return void b(null);const t={getBoundingClientRect:()=>(0,g.posToDOMRect)(e.view,j.from,j.to)},r=()=>{n.current&&i.computePosition(t,n.current,{placement:"bottom-start",strategy:"fixed",middleware:[i.offset(8),i.flip(),i.shift({padding:8})]}).then(({x:e,y:t})=>b({x:e,y:t}))};return r(),window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),()=>{window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0)}},[e,j?.from,j?.to,y]),(0,x.useEffect)(()=>{if(!S||!e)return;const t=t=>{n.current&&!n.current.contains(t.target)&&e.commands.closeAiMenu()},r=t=>{if("Escape"===t.key)return h?void u(null):void e.commands.closeAiMenu();if("Enter"===t.key&&(t.metaKey||t.ctrlKey)){const n=d.getAiState(e.state)?.panel;"reviewing"!==n?.status||n.suggestion.isStreaming||(t.preventDefault(),e.commands.acceptAiSuggestion())}};return document.addEventListener("mousedown",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r)}},[S,e,h]),!(t&&e&&S&&f))return null;const _=t=>{t.options?.length?u(t):e.commands.runAiCommand(t.id)};return(0,k.createPortal)((0,w.jsxs)("div",{ref:n,role:"dialog","aria-label":"Ask AI",className:"ai-menu",style:{position:"fixed",top:f.y,left:f.x,zIndex:60},children:[(0,w.jsxs)("div",{className:"ai-menu-input-row",children:[(0,w.jsx)(v.Sparkles,{className:"ai-menu-input-icon"}),(0,w.jsx)("input",{ref:r,value:s,onChange:e=>{l(e.target.value),c(e.target.value.trim()?0:-1)},onKeyDown:t=>{if("ArrowDown"===t.key)return t.preventDefault(),void c(e=>T.length?(e+1)%T.length:-1);if("ArrowUp"===t.key)return t.preventDefault(),void c(e=>T.length?e<=0?T.length-1:e-1:-1);if("Enter"===t.key){t.preventDefault();const n=a>=0?T[a]:void 0;if(n)return void _(n);s.trim()&&e.commands.submitAiPrompt(s)}},placeholder:C?"Ask AI to change the selection…":"Ask AI anything…",className:"ai-menu-input","aria-label":"Ask AI"})]}),"menu"===y.status&&h&&(0,w.jsxs)("div",{className:"ai-menu-commands",children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>u(null),children:[(0,w.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),h.label]}),h.options?.map(t=>(0,w.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>{u(null),e.commands.runAiCommand(h.id,t.label)},children:(0,w.jsx)("span",{className:"ai-menu-command-text",children:(0,w.jsx)("span",{className:"ai-menu-command-label",children:t.label})})},t.id))]}),"menu"===y.status&&!h&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("div",{className:"ai-menu-hint",children:C?`${N.toLocaleString()} characters selected`:"Nothing selected — select text for rewrite actions"}),(0,w.jsxs)("div",{className:"ai-menu-commands",children:[0===M.length&&(0,w.jsx)("div",{className:"ai-menu-empty",children:"No matching actions"}),M.map(e=>(0,w.jsxs)("div",{children:[(0,w.jsx)("div",{className:"ai-menu-group-label",children:d.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>{const t=T.indexOf(e);return(0,w.jsxs)("button",{type:"button","data-active":t===a?"true":void 0,onMouseEnter:()=>c(t),onClick:()=>_(e),className:"ai-menu-command",children:[(0,w.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,w.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,w.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id)})]},e.group))]})]}),"loading"===y.status&&(0,w.jsxs)("div",{className:"ai-menu-loading",children:[(0,w.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,w.jsx)("span",{className:"ai-menu-loading-label",children:"Custom"===y.commandLabel?"Generating…":`${y.commandLabel}…`}),(0,w.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,w.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}),"error"===y.status&&(0,w.jsxs)("div",{className:"ai-menu-error",children:[(0,w.jsx)("p",{className:"ai-menu-error-message",children:y.message}),(0,w.jsxs)("div",{className:"ai-menu-review",children:[(0,w.jsx)(F,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,w.jsx)(F,{icon:v.X,label:"Dismiss",onClick:()=>e.commands.closeAiMenu()})]})]}),"reviewing"===y.status&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("div",{className:"ai-menu-preview","aria-live":"polite",children:y.suggestion.suggestedText||"…"}),y.suggestion.isStreaming?(0,w.jsxs)("div",{className:"ai-menu-loading",children:[(0,w.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,w.jsxs)("span",{className:"ai-menu-loading-label",children:[y.commandLabel,"…"]}),(0,w.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,w.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}):(0,w.jsxs)("div",{className:"ai-menu-review",children:[(0,w.jsx)(F,{icon:v.Check,label:"replace"===y.suggestion.mode?"Replace selection":"Insert",title:"⌘/Ctrl + Enter",onClick:()=>e.commands.acceptAiSuggestion()}),(0,w.jsx)(F,{icon:v.CornerDownRight,label:"Insert below",onClick:()=>e.commands.insertAiSuggestionBelow()}),(0,w.jsx)(F,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,w.jsx)(F,{icon:v.Copy,label:p?"Copied":"Copy",onClick:()=>(async e=>{try{await navigator.clipboard.writeText(e),m(!0),setTimeout(()=>m(!1),1500)}catch{}})(y.suggestion.suggestedText)}),(0,w.jsx)(F,{icon:v.X,label:"Discard",onClick:()=>e.commands.discardAiSuggestion()})]})]})]}),document.body)}function W({editor:e,label:t="AI"}){const{editor:n}=o.useTiptapEditor(e),r=(0,x.useRef)(null),s=(0,x.useRef)(null),[l,a]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[u,p]=(0,x.useState)(null),{hasSelection:m,isBusy:f}=(0,g.useEditorState)({editor:n,selector:({editor:e})=>{if(!e)return{hasSelection:!1,isBusy:!1};const t=d.getAiState(e.state)?.panel.status;return{hasSelection:!e.state.selection.empty,isBusy:"loading"===t||"reviewing"===t}}})??{hasSelection:!1,isBusy:!1},b=n?d.getAiOptions(n)?.commands??[]:[],y=(0,x.useMemo)(()=>d.groupCommands(d.commandsForSelection(b,m)),[b,m]);if((0,x.useEffect)(()=>{if(!l||!r.current||!s.current)return;const e=r.current,t=()=>{s.current&&i.computePosition(e,s.current,{placement:"bottom-start",strategy:"fixed",middleware:[i.offset(6),i.flip(),i.shift({padding:8})]}).then(({x:e,y:t})=>p({x:e,y:t}))};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[l,y.length,c]),(0,x.useEffect)(()=>{if(!l)return h(null),void p(null);const e=e=>{const t=e.target;s.current?.contains(t)||r.current?.contains(t)||a(!1)},t=e=>{"Escape"===e.key&&a(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l]),!d.isAiEnabled(n))return null;const j=(e,t)=>{!e.options?.length||t?(a(!1),n?.chain().focus().run(),n?.commands.runAiCommand(e.id,t)):h(e)};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("button",{ref:r,type:"button",title:"AI writing assistant (Ctrl/⌘ + J)","aria-haspopup":"menu","aria-expanded":l,"data-state":l?"open":"closed",className:"ai-toolbar-button",onMouseDown:e=>e.preventDefault(),onClick:()=>a(e=>!e),children:[f?(0,w.jsx)(v.Loader2,{className:"ai-toolbar-icon ai-menu-spin"}):(0,w.jsx)(v.Sparkles,{className:"ai-toolbar-icon"}),t&&(0,w.jsx)("span",{className:"ai-toolbar-label",children:t}),(0,w.jsx)(v.ChevronDown,{className:"ai-toolbar-chevron"})]}),l&&(0,k.createPortal)((0,w.jsx)("div",{ref:s,role:"menu","aria-label":"AI actions",className:"ai-menu ai-toolbar-menu",style:{position:"fixed",top:u?.y??-9999,left:u?.x??-9999,visibility:u?"visible":"hidden",zIndex:60},children:c?(0,w.jsxs)("div",{className:"ai-menu-commands",children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>h(null),children:[(0,w.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),c.label]}),c.options?.map(e=>(0,w.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>j(c,e.label),children:(0,w.jsx)("span",{className:"ai-menu-command-text",children:(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label})})},e.id))]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-command ai-menu-ask",onClick:()=>{a(!1),n?.chain().focus().run(),n?.commands.openAiMenu()},children:[(0,w.jsx)(v.Sparkles,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:"Ask AI anything…"}),(0,w.jsx)("span",{className:"ai-menu-command-description",children:"Write your own instruction"})]}),(0,w.jsx)("span",{className:"ai-menu-command-shortcut",children:"⌘J"})]}),(0,w.jsx)("div",{className:"ai-menu-hint",children:m?"Runs on the selected text":"Select text to rewrite it, or generate from the caret"}),(0,w.jsx)("div",{className:"ai-menu-commands",children:y.map(e=>(0,w.jsxs)("div",{children:[(0,w.jsx)("div",{className:"ai-menu-group-label",children:d.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>(0,w.jsxs)("button",{type:"button",className:"ai-menu-command",onClick:()=>j(e),children:[(0,w.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,w.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,w.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id))]},e.group))})]})}),document.body)]})}var q={available:!1,state:"idle",isActive:!1,isSpeaking:!1,isPaused:!1,currentChunk:null,error:null};var H={available:!1,isListening:!1,partial:"",lastPhrase:"",phraseId:0,error:null};function U(e){const t=(0,x.useCallback)(t=>e?p.subscribeTranscribe(e,t):()=>{},[e]);if("none"===(0,x.useSyncExternalStore)(t,()=>{const t=e?p.getTranscribeStorage(e):void 0;return t?`${t.listening}|${t.phraseId}|${t.error?.message??""}`:"none"},()=>"none")||!e)return H;const n=p.getTranscribeStorage(e);return n?{available:!0,isListening:n.listening,partial:n.partial,lastPhrase:n.lastPhrase,phraseId:n.phraseId,error:n.error}:H}function J({editor:e,durationMs:t=2e3}){const{isListening:n,lastPhrase:r,phraseId:s}=U(e);return(0,w.jsx)(N.SpokenPhraseOverlay,{durationMs:t,phrase:r,phraseId:s,visible:n})}var K=[".dropdown-container",".dropdown-portal","[data-richtext-portal]","[data-radix-popper-content-wrapper]","[data-radix-portal]",'[role="dialog"]','[role="menu"]','[role="listbox"]'].join(",");var G="rte-custom-styles",X="rte-custom-style-presets",Y="rte-active-style-preset";function Z(e){(function(e){const t=e;return!!t?.closest&&!t.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')&&!!t.closest('button, [role="button"], [role="menuitem"], [role="menuitemcheckbox"]')})(e.target)&&e.preventDefault()}function Q(e){const t=(0,x.useRef)(!1);return{onMouseDown:e=>{t.current=e.target===e.currentTarget},onClick:n=>{t.current&&n.target===n.currentTarget&&(t.current=!1,e())}}}function ee({onClose:e}){const[t,n]=(0,x.useState)(()=>{try{const e=localStorage.getItem(X);return e?JSON.parse(e):[{id:"1",name:"Default",rules:[{id:1,selector:".ProseMirror p",property:"font-size",value:"16px"},{id:2,selector:".ProseMirror h1",property:"color",value:"#111827"}],active:!0}]}catch{return[]}}),[r,s]=(0,x.useState)(()=>{try{return localStorage.getItem(Y)||t[0]?.id||"1"}catch{return"1"}}),[i,o]=(0,x.useState)(null),[l,a]=(0,x.useState)(""),c=t.find(e=>e.id===r)||t[0],[d,h]=(0,x.useState)(c?.rules||[]),u=(0,x.useRef)(d.length?Math.max(...d.map(e=>e.id),0)+1:1),p=e=>{let t=document.getElementById(G);t||(t=document.createElement("style"),t.id=G,document.head.appendChild(t)),t.textContent=e.filter(e=>e.selector&&e.property&&e.value).map(e=>`${e.selector} { ${e.property}: ${e.value}; }`).join("\n")},m=e=>{const n=t.find(t=>t.id===e);n&&(s(e),h([...n.rules]),p(n.rules),localStorage.setItem(Y,e))},f=()=>{if(t.length>=10)return void alert("Maximum 10 style presets allowed");if(!l.trim())return void alert("Please enter a name for the preset");const e=Math.max(...t.map(e=>parseInt(e.id)),0)+1,r={id:String(e),name:l,rules:[{id:1,selector:".ProseMirror p",property:"font-size",value:"16px"}],active:!1},s=[...t,r];n(s),localStorage.setItem(X,JSON.stringify(s)),a(""),m(r.id)},g=(e,r)=>{if(!r.trim())return;const s=t.map(t=>t.id===e?{...t,name:r}:t);n(s),localStorage.setItem(X,JSON.stringify(s)),o(null)},b=(e,t,n)=>h(r=>r.map(r=>r.id===e?{...r,[t]:n}:r)),y=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...y}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[640px] max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)(v.Paintbrush,{size:16,className:"text-blue-500"}),(0,w.jsx)("span",{className:"text-sm font-semibold",children:"Customize Editor Styles"})]}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:14})})]}),(0,w.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 dark:border-slate-700 space-y-2",children:[(0,w.jsx)("div",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Style Presets"}),(0,w.jsx)("div",{className:"flex gap-2 flex-wrap",children:t.map(e=>(0,w.jsxs)("div",{className:"flex items-center gap-1",children:[(0,w.jsx)("button",{onClick:()=>m(e.id),className:"px-3 py-1.5 text-xs rounded transition-colors "+(r===e.id?"bg-blue-500 text-white border-blue-600":"border border-gray-200 dark:border-slate-700 hover:bg-gray-50 dark:hover:bg-slate-800"),children:i===e.id?(0,w.jsx)("input",{autoFocus:!0,type:"text",value:l,onChange:e=>a(e.target.value),onBlur:()=>g(e.id,l),onKeyDown:t=>"Enter"===t.key&&g(e.id,l),className:"w-20 px-1 py-0.5 text-xs bg-transparent border-b border-current outline-none"}):(0,w.jsx)("span",{onDoubleClick:()=>{o(e.id),a(e.name)},children:e.name})}),t.length>1&&(0,w.jsx)("button",{onClick:()=>(e=>{if(t.length<=1)return void alert("Cannot delete the last preset");if(!confirm("Are you sure you want to delete this preset?"))return;const s=t.filter(t=>t.id!==e);n(s),localStorage.setItem(X,JSON.stringify(s)),r===e&&m(s[0].id)})(e.id),className:"p-0.5 rounded text-gray-400 hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:(0,w.jsx)(v.X,{size:12})})]},e.id))}),t.length<10&&(0,w.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,w.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"New preset name...",onKeyDown:e=>"Enter"===e.key&&f(),className:"flex-1 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700"}),(0,w.jsxs)("button",{onClick:f,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:[(0,w.jsx)(v.Plus,{size:12}),"Add"]})]})]}),(0,w.jsxs)("div",{className:"px-4 py-2 text-xs text-gray-500 dark:text-gray-400 border-b border-gray-100 dark:border-slate-700",children:["CSS rules applied live to the editor. Target ",(0,w.jsx)("code",{className:"bg-gray-100 dark:bg-slate-800 px-1 rounded",children:".ProseMirror"})," elements."]}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-4 space-y-2",children:[0===d.length&&(0,w.jsx)("div",{className:"text-center text-xs text-gray-400 py-6",children:"No rules yet. Click + Add Rule to begin."}),d.map(e=>(0,w.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,w.jsx)("input",{className:"flex-1 min-w-0 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:".ProseMirror p",value:e.selector,onChange:t=>b(e.id,"selector",t.target.value)}),(0,w.jsx)("input",{className:"w-32 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:"font-size",value:e.property,onChange:t=>b(e.id,"property",t.target.value)}),(0,w.jsx)("input",{className:"w-28 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:"16px",value:e.value,onChange:t=>b(e.id,"value",t.target.value)}),(0,w.jsx)("button",{onClick:()=>{return t=e.id,h(e=>e.filter(e=>e.id!==t));var t},className:"p-1 rounded text-gray-300 hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,w.jsx)(v.Trash2,{size:13})})]},e.id))]}),(0,w.jsxs)("div",{className:"px-4 py-3 border-t border-gray-100 dark:border-slate-700 flex items-center justify-between",children:[(0,w.jsxs)("button",{onClick:()=>{const e={id:u.current++,selector:"",property:"",value:""};h(t=>[...t,e])},className:"flex items-center gap-1.5 px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:[(0,w.jsx)(v.Plus,{size:12}),"Add Rule"]}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsx)("button",{onClick:e,className:"px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:"Cancel"}),(0,w.jsx)("button",{onClick:()=>{const e=t.map(e=>e.id===r?{...e,rules:[...d]}:e);n(e),localStorage.setItem(X,JSON.stringify(e)),p(d)},className:"px-3 py-1.5 text-xs bg-blue-500 text-white rounded hover:bg-blue-600",children:"Save Style"})]})]})]})]}),document.body)}function te({children:e,label:t,shortcut:n,icon:r,displayIcon:s}){const i=(0,x.useRef)(null);return(0,w.jsxs)("div",{ref:i,onClick:e=>{e.target.closest('button, [role="button"], a, select')||(i.current?.querySelector('button, [role="button"]'))?.click()},className:"relative flex items-center gap-3 px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors",children:[(r||s)&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0 text-sm font-mono",children:s||r}),(0,w.jsx)("span",{className:"flex-1 text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,w.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n}),(0,w.jsx)("span",{className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0,children:e}),(0,w.jsx)("span",{className:"hidden",children:e})]})}function ne({icon:e,label:t,shortcut:n,onClick:r,disabled:s}){return(0,w.jsxs)("button",{onClick:r,disabled:s,className:"flex items-center gap-3 w-full px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:[e&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,w.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,w.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n})]})}function re({icon:e,label:t,checked:n,onChange:r}){return(0,w.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":n,onClick:()=>r(!n),className:"flex items-center gap-3 w-full px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors",children:[e&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,w.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),(0,w.jsx)("span",{className:"flex h-4 w-4 items-center justify-center rounded border shrink-0 transition-colors "+(n?"bg-blue-500 border-blue-500 text-white":"border-gray-300 dark:border-slate-600"),children:n&&(0,w.jsx)(v.Check,{size:12,strokeWidth:3})})]})}function se({children:e,label:t,name:n,active:r,onClick:s}){return(0,w.jsxs)("button",{title:t,onClick:e=>s(n,e),className:"flex items-center gap-0.5 px-1.5 py-1 rounded text-sm font-medium transition-colors "+(r?"bg-gray-200 dark:bg-slate-700 text-gray-900 dark:text-white":"text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white"),children:[e,(0,w.jsx)(v.ChevronDown,{size:10,className:"opacity-40 mt-0.5"})]})}function ie({top:e,left:t,right:n,className:r="",children:s}){const i=(0,x.useRef)(null),[o,l]=(0,x.useState)({top:e,left:-9999,visibility:"hidden"});return(0,x.useLayoutEffect)(()=>{const r=()=>{const r=i.current;if(!r)return;const s=window.innerWidth,o=window.innerHeight,a=Math.max(160,o-e-8);if(s<=640)return void l({top:e,left:8,right:8,width:"auto",minWidth:0,maxWidth:"none",maxHeight:a,overflowY:"auto"});const c=r.offsetWidth,d=null!=n?s-n-c:t??8,h=Math.max(8,Math.min(d,s-c-8));l({top:e,left:h,maxWidth:s-16,maxHeight:a,overflowY:"auto"})};return r(),window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[e,t,n]),(0,w.jsx)("div",{className:`fixed bg-white/70 dark:bg-slate-900/70 backdrop-blur-md border border-gray-200/60 dark:border-slate-700/60 rounded-lg shadow-xl py-1 z-50 min-w-[220px] dropdown-portal ${r}`,onMouseDown:Z,ref:i,style:o,children:s})}function oe({onClose:e,documentTitle:t,editor:n,initialTab:r="info"}){const[s,i]=(0,x.useState)(r),[o,l]=(0,x.useState)(()=>f.getWordCountStats(n));(0,x.useEffect)(()=>{if(!n)return;const e=()=>l(f.getWordCountStats(n));return e(),n.on("update",e),()=>{n.off("update",e)}},[n]);const{createdDate:a,modifiedDate:c}=(0,x.useMemo)(()=>({createdDate:new Date(Date.now()-2592e6),modifiedDate:new Date}),[]),[d,h]=(0,x.useState)(""),[u,p]=(0,x.useState)("viewer"),[m,g]=(0,x.useState)({isPublic:!1,sharedWith:[{email:"alice@example.com",role:"editor",sharedAt:(new Date).toISOString(),name:"Alice"},{email:"bob@example.com",role:"viewer",sharedAt:(new Date).toISOString(),name:"Bob"}],shareLink:null}),b=()=>{d.trim()&&(m.sharedWith.find(e=>e.email===d)?alert("Already shared with this email"):(g(e=>({...e,sharedWith:[...e.sharedWith,{email:d,role:u,sharedAt:(new Date).toISOString()}]})),h("")))},y=e=>{switch(e){case"editor":return(0,w.jsx)(v.Edit3,{size:14});case"commentor":return(0,w.jsx)(v.MessageSquare,{size:14});case"viewer":return(0,w.jsx)(v.Eye,{size:14});default:return null}},j=[{label:"Words",value:o.words},{label:"Characters (with spaces)",value:o.charactersWithSpaces},{label:"Characters (no spaces)",value:o.charactersNoSpaces},{label:"Sentences",value:o.sentences},{label:"Paragraphs",value:o.paragraphs},{label:"Links",value:o.links},{label:"Images",value:o.images}],S=e=>"px-3 py-1.5 text-sm rounded-md transition-colors "+(s===e?"bg-white dark:bg-slate-900 text-gray-900 dark:text-white shadow-sm font-medium":"text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"),C=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...C}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[600px] max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,w.jsx)(v.FileText,{size:18,className:"text-blue-500 shrink-0"}),(0,w.jsxs)("div",{className:"min-w-0",children:[(0,w.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white truncate",children:t}),(0,w.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"info"===s?"Document details and statistics":"Manage who can access this document"})]})]}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:16})})]}),(0,w.jsx)("div",{className:"px-6 pt-3",children:(0,w.jsxs)("div",{className:"inline-flex gap-1 p-1 rounded-lg bg-gray-100 dark:bg-slate-800",children:[(0,w.jsx)("button",{className:S("info"),onClick:()=>i("info"),type:"button",children:"Info & word count"}),(0,w.jsx)("button",{className:S("share"),onClick:()=>i("share"),type:"button",children:"Sharing"})]})}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("info"===s?"":"hidden"),children:[(0,w.jsxs)("div",{className:"space-y-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Document Name"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white break-words",children:t})]}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Created"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:a.toLocaleDateString()})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Last Modified"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:c.toLocaleDateString()})]})]}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Access"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:m.isPublic?"Public":"Private"})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Shared with"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:1===m.sharedWith.length?"1 person":`${m.sharedWith.length} people`})]})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("h3",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400",children:"Word Count"}),(0,w.jsx)("table",{className:"w-full text-sm",children:(0,w.jsx)("tbody",{children:j.map(e=>(0,w.jsxs)("tr",{className:"border-b border-gray-100 dark:border-slate-700 last:border-b-0",children:[(0,w.jsx)("td",{className:"py-1.5 pr-2 text-gray-500 dark:text-gray-400",children:e.label}),(0,w.jsx)("td",{className:"py-1.5 text-right font-semibold tabular-nums text-gray-900 dark:text-white",children:e.value.toLocaleString()})]},e.label))})})]}),(0,w.jsxs)("button",{onClick:()=>i("share"),className:"flex items-center gap-2 px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800 text-gray-700 dark:text-gray-200",children:[(0,w.jsx)(v.Share2,{size:14}),"Manage sharing"]})]}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("share"===s?"":"hidden"),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between p-4 rounded-lg border border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/50",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3",children:[m.isPublic?(0,w.jsx)(v.Globe,{size:18,className:"text-blue-500"}):(0,w.jsx)(v.Lock,{size:18,className:"text-gray-400"}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:m.isPublic?"Public":"Private"}),(0,w.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:m.isPublic?"Anyone with link can view":"Only invited people can access"})]})]}),(0,w.jsxs)("div",{className:"flex items-center gap-3",children:[m.isPublic&&m.shareLink&&(0,w.jsx)("button",{onClick:()=>{m.shareLink&&(navigator.clipboard.writeText(m.shareLink),alert("Link copied to clipboard"))},className:"px-2 py-1 text-xs border border-gray-300 dark:border-slate-600 rounded hover:bg-gray-100 dark:hover:bg-slate-700 transition-colors",children:"Copy link"}),(0,w.jsx)("button",{onClick:()=>{g(e=>({...e,isPublic:!e.isPublic,shareLink:e.isPublic?null:`https://docs.example.com/share/${Math.random().toString(36).slice(2,9)}`}))},className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors "+(m.isPublic?"bg-blue-500":"bg-gray-300 dark:bg-slate-700"),children:(0,w.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition "+(m.isPublic?"translate-x-6":"translate-x-1")})})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Add people"}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsxs)("div",{className:"relative flex-1",children:[(0,w.jsx)(v.Mail,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),(0,w.jsx)("input",{type:"email",placeholder:"email@example.com",value:d,onChange:e=>h(e.target.value),onKeyDown:e=>"Enter"===e.key&&b(),className:"w-full pl-9 pr-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white placeholder-gray-500"})]}),(0,w.jsxs)("select",{value:u,onChange:e=>p(e.target.value),className:"px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white",children:[(0,w.jsx)("option",{value:"viewer",children:"Viewer"}),(0,w.jsx)("option",{value:"commentor",children:"Commentor"}),(0,w.jsx)("option",{value:"editor",children:"Editor"})]}),(0,w.jsx)("button",{onClick:b,className:"px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors",children:"Share"})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"People with access"}),(0,w.jsx)("div",{className:"space-y-1 max-h-[280px] overflow-y-auto",children:m.sharedWith.length>0?m.sharedWith.map(e=>(0,w.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800/50 transition-colors",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3 flex-1",children:[(0,w.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-gradient-to-br from-blue-400 to-blue-600 text-white text-xs font-medium",children:e.email.substring(0,2).toUpperCase()}),(0,w.jsxs)("div",{className:"min-w-0",children:[(0,w.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.email}),(0,w.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Added ",new Date(e.sharedAt).toLocaleDateString()]})]})]}),(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:y(e.role)}),(0,w.jsxs)("select",{value:e.role,onChange:t=>{return n=e.email,r=t.target.value,void g(e=>({...e,sharedWith:e.sharedWith.map(e=>e.email===n?{...e,role:r}:e)}));var n,r},className:"px-2 py-1 text-xs border border-gray-200 dark:border-slate-700 rounded bg-white dark:bg-slate-800 text-gray-900 dark:text-white",children:[(0,w.jsx)("option",{value:"viewer",children:"Viewer"}),(0,w.jsx)("option",{value:"commentor",children:"Commentor"}),(0,w.jsx)("option",{value:"editor",children:"Editor"})]}),(0,w.jsx)("button",{onClick:()=>{return t=e.email,void g(e=>({...e,sharedWith:e.sharedWith.filter(e=>e.email!==t)}));var t},className:"p-1 text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors",children:(0,w.jsx)(v.X,{size:14})})]})]},e.email)):(0,w.jsxs)("div",{className:"text-center py-8",children:[(0,w.jsx)(v.Users,{size:24,className:"mx-auto text-gray-300 mb-2 opacity-50"}),(0,w.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No one else has access yet"})]})})]})]})]})]}),document.body)}function le({onClose:e,currentName:t}){const[n,r]=(0,x.useState)(t),s=()=>{n.trim()&&n!==t&&alert(`File renamed to: ${n}`),e()},i=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...i}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[400px]",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white",children:"Rename document"}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:16})})]}),(0,w.jsx)("div",{className:"p-6 space-y-4",children:(0,w.jsx)("input",{type:"text",value:n,onChange:e=>r(e.target.value),onKeyDown:e=>"Enter"===e.key&&s(),autoFocus:!0,className:"w-full px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white"})}),(0,w.jsxs)("div",{className:"flex gap-2 px-6 py-4 border-t border-gray-100 dark:border-slate-700 justify-end",children:[(0,w.jsx)("button",{onClick:e,className:"px-4 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800",children:"Cancel"}),(0,w.jsx)("button",{onClick:s,className:"px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600",children:"Rename"})]})]})]}),document.body)}var ae=({theme:e,setTheme:t,onOpenSettings:r,onAddComment:i,commentDisabled:o,showComments:a,onToggleComments:c,commentCount:d})=>{const[p,f]=(0,x.useState)(null),[b,y]=(0,x.useState)(null),[j,S]=(0,x.useState)(!1),[C,N]=(0,x.useState)(!1),[E,A]=(0,x.useState)(!1),[O,R]=(0,x.useState)(!1),[P,B]=(0,x.useState)(null),F=!!r,V=(0,x.useRef)(null),H=s.useLocale(),{editor:Q}=(0,g.useCurrentEditor)(),ae="Untitled Document",ce=!!Q?.extensionManager.extensions.some(e=>"harper"===e.name);(0,x.useEffect)(()=>{Q&&ce&&(E?Q.chain().focus().runProofing().run():Q.commands.clearProofing())},[E,Q,ce]);const de=function(e){const t=(0,x.useCallback)(t=>e?u.subscribeReadAloud(e,t):()=>{},[e]);if("none"===(0,x.useSyncExternalStore)(t,()=>{const t=e?u.getReadAloudStorage(e):void 0;return t?`${t.state}|${t.currentChunk?.index??-1}|${t.error?.message??""}`:"none"},()=>"none")||!e)return q;const n=u.getReadAloudStorage(e);return n?{available:!0,state:n.state,isActive:"idle"!==n.state,isSpeaking:"speaking"===n.state,isPaused:"paused"===n.state,currentChunk:n.currentChunk,error:n.error}:q}(Q??null),he=U(Q??null),ue=Q&&!Q.state.selection.empty?"selection":"document",pe=!!Q&&u.getReadAloudText(Q).length>0,me=!!Q?.extensionManager.extensions.some(e=>"PaginationPlus"===e.name),[fe,ge]=(0,x.useState)(!0);(0,x.useEffect)(()=>{if(!Q||!me)return;const e=Q.storage?.PaginationPlus?.enabled;"boolean"==typeof e&&ge(e)},[Q,me]);const xe=(0,x.useCallback)(e=>{Q&&(e?Q.commands.enablePagination?.():Q.commands.disablePagination?.(),ge(e))},[Q]),be=(0,x.useCallback)(()=>{Q?.chain().focus().run(),document.execCommand("cut")},[Q]),ye=(0,x.useCallback)(()=>{Q?.chain().focus().run(),document.execCommand("copy")},[Q]),we=(0,x.useCallback)(async()=>{Q?.chain().focus().run();try{const e=await navigator.clipboard.readText();Q?.commands.insertContent(e)}catch{document.execCommand("paste")}},[Q]),ve=(0,x.useCallback)(async()=>{Q?.chain().focus().run();try{const e=await navigator.clipboard.readText();Q?.chain().focus().insertContent(e,{parseOptions:{preserveWhitespace:!0}}).run()}catch{document.execCommand("paste")}},[Q]),ke=(0,x.useCallback)(()=>{Q?.commands.deleteSelection()},[Q]),je=(0,x.useCallback)(()=>{Q?.chain().focus().selectAll().run()},[Q]),Se=!!Q?.extensionManager.extensions.some(e=>"selectSimilar"===e.name),[Ce,Ne]=(0,x.useState)(0);(0,x.useEffect)(()=>{if(!Q||!Se)return;const e=()=>Ne(m.selectSimilarPluginKey.getState(Q.state)?.ranges.length??0);return e(),Q.on("transaction",e),()=>{Q.off("transaction",e)}},[Q,Se]);const Ee=(0,x.useCallback)(e=>{Q?.chain().focus().selectSimilar(e).run()},[Q]),Ae=(0,x.useCallback)(()=>{Q?.chain().focus().clearSimilarSelection().run()},[Q]);(0,x.useEffect)(()=>{try{const e=localStorage.getItem(Y),t=JSON.parse(localStorage.getItem(X)||"[]");if(t.length>0){const n=t.find(t=>t.id===e)||t[0];if(n&&n.rules.length>0){let e=document.getElementById(G);e||(e=document.createElement("style"),e.id=G,document.head.appendChild(e)),e.textContent=n.rules.filter(e=>e.selector&&e.property&&e.value).map(e=>`${e.selector} { ${e.property}: ${e.value}; }`).join("\n")}}}catch{}},[]);const Te=(e,t)=>{if(p===e)return f(null),void y(null);const n=t.currentTarget.getBoundingClientRect();y({top:n.bottom+4,left:n.left}),f(e)},Me=()=>{f(null),y(null)};return(0,x.useEffect)(()=>{if(!p)return;const e=e=>{(function(e,t=document){const n=e;return!!n?.isConnected&&!n.closest(K)&&!t.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')})(e.target)&&Me()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[p]),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"flex items-center gap-0.5 border-b border-gray-200 dark:border-slate-700 px-2 py-1 flex-wrap",onMouseDown:Z,children:[(0,w.jsx)(n.Z,{hideWhenDisabled:!0}),(0,w.jsx)(n.$$1,{hideWhenDisabled:!0}),(0,w.jsx)("div",{className:"border-l border-gray-200 dark:border-slate-700 mx-0.5 px-0.5",children:(0,w.jsx)($,{})}),(0,w.jsx)(n.F$1,{}),(0,w.jsx)(n.y$2,{}),(0,w.jsx)(n.h$4,{}),(0,w.jsx)(n.y$1,{}),(0,w.jsx)(n.d$1,{}),(0,w.jsx)(n.M$1,{}),(0,w.jsx)(W,{}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"block",label:"Block Format",active:"block"===p,onClick:Te,children:(0,w.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,w.jsx)("line",{x1:"2",y1:"4",x2:"14",y2:"4"}),(0,w.jsx)("line",{x1:"2",y1:"8",x2:"11",y2:"8"}),(0,w.jsx)("line",{x1:"2",y1:"12",x2:"8",y2:"12"})]})}),"block"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H1",label:"Heading 1",shortcut:"Ctrl+Alt+1",children:(0,w.jsx)(n.$,{level:1})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H2",label:"Heading 2",shortcut:"Ctrl+Alt+2",children:(0,w.jsx)(n.$,{level:2})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H3",label:"Heading 3",shortcut:"Ctrl+Alt+3",children:(0,w.jsx)(n.$,{level:3})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H4",label:"Heading 4",shortcut:"Ctrl+Alt+4",children:(0,w.jsx)(n.$,{level:4})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H5",label:"Heading 5",shortcut:"Ctrl+Alt+5",children:(0,w.jsx)(n.$,{level:5})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H6",label:"Heading 6",shortcut:"Ctrl+Alt+6",children:(0,w.jsx)(n.$,{level:6})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Bullet List",shortcut:"Ctrl+Shift+8",children:(0,w.jsx)(n.r$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Ordered List",shortcut:"Ctrl+Shift+7",children:(0,w.jsx)(n.n$4,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Check List",shortcut:"Ctrl+Shift+9",children:(0,w.jsx)(n.r,{})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Blockquote",shortcut:"Ctrl+Shift+B",children:(0,w.jsx)(n.p$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Code Block",shortcut:"Ctrl+Alt+C",children:(0,w.jsx)(n.k$2,{})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-1",children:(0,w.jsx)(M,{label:"Clear Format",children:(0,w.jsx)(n.n$3,{})})}),(0,w.jsxs)("button",{onClick:()=>{Me(),S(!0)},className:"flex items-center gap-3 w-full px-3 py-1.5 text-sm text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 rounded transition-colors",children:[(0,w.jsx)(v.Paintbrush,{size:14,className:"text-gray-400 shrink-0"}),"Customize default styles…"]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"textstyles",label:"Text Styles",active:"textstyles"===p,onClick:Te,children:(0,w.jsx)("span",{className:"text-sm font-mono",children:"Tt"})}),"textstyles"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Text Styles"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Strikethrough",shortcut:"Ctrl+Shift+S",children:(0,w.jsx)(n.u$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Inline Code",shortcut:"Ctrl+E",children:(0,w.jsx)(n.m$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Text Color",shortcut:"Alt+Shift+C",children:(0,w.jsx)(n.h$3,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Superscript",shortcut:"Ctrl+.",children:(0,w.jsx)(D,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Subscript",shortcut:"Ctrl+,",children:(0,w.jsx)(_,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Indent",children:(0,w.jsx)(n.l,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Line Spacing",children:(0,w.jsx)(n.f,{})})}),(0,w.jsx)("div",{className:"col-span-2",children:(0,w.jsx)(M,{label:"Alignment",children:(0,w.jsx)(n.A$1,{})})})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"insert",label:"Insert",active:"insert"===p,onClick:Te,children:(0,w.jsx)(v.Plus,{size:16})}),"insert"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[300px]",left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Insert"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Link",children:(0,w.jsx)(n.Be,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Emoji",children:(0,w.jsx)(n.ne,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Table",children:(0,w.jsx)(n.at,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Image",children:(0,w.jsx)(n.te,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Meme",children:(0,w.jsx)(n.T$2,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Document",children:(0,w.jsx)(n.E,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Columns",shortcut:"Ctrl+Alt+G",children:(0,w.jsx)(n.b,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Callout",children:(0,w.jsx)(n.F,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Twitter",children:(0,w.jsx)(n.N,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Divider",shortcut:"Ctrl+Alt+S",children:(0,w.jsx)(n.h,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Video",children:(0,w.jsx)(n.M,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Math",children:(0,w.jsx)(n.Dt,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Flowchart",children:(0,w.jsx)(n.P,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Drawio",children:(0,w.jsx)(h.RichTextDrawio,{})})}),i&&(0,w.jsx)("div",{children:(0,w.jsxs)("button",{type:"button",disabled:o,onClick:()=>{Me(),i()},className:"flex items-center gap-2 px-2 py-0.5 rounded cursor-pointer w-full text-left hover:bg-gray-100/80 dark:hover:bg-slate-800/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:(0,w.jsx)(v.MessageSquarePlus,{size:14})}),(0,w.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:"Comment"})]})})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"edit",label:"Edit",active:"edit"===p,onClick:Te,children:(0,w.jsx)(v.Clipboard,{size:16})}),"edit"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Clipboard"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Scissors,{size:14}),label:"Cut",shortcut:"Ctrl+X",onClick:()=>{Me(),be()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Clipboard,{size:14}),label:"Copy",shortcut:"Ctrl+C",onClick:()=>{Me(),ye()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.ClipboardPaste,{size:14}),label:"Paste",shortcut:"Ctrl+V",onClick:()=>{Me(),we()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.ClipboardType,{size:14}),label:"Paste Plain",shortcut:"Ctrl+Shift+V",onClick:()=>{Me(),ve()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Trash2,{size:14}),label:"Delete",shortcut:"Del",onClick:()=>{Me(),ke()}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Selection"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.TextCursorInput,{size:14}),label:"Select All",shortcut:"Ctrl+A",onClick:()=>{Me(),je()}}),Se&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Type,{size:14}),label:"Select All Similar Fonts",onClick:()=>{Me(),Ee("font")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Palette,{size:14}),label:"Select All Similar Styles",onClick:()=>{Me(),Ee("style")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.TextSelect,{size:14}),label:"Select All Similar Formatting",onClick:()=>{Me(),Ee("formatting")}}),(0,w.jsx)(ne,{disabled:0===Ce,icon:(0,w.jsx)(v.X,{size:14}),label:Ce?`Clear Multi-Selection (${Ce})`:"Clear Multi-Selection",shortcut:"Esc",onClick:()=>{Me(),Ae()}}),(0,w.jsx)("div",{className:"px-3 pb-1.5 pt-0.5 text-[10px] leading-snug text-gray-400 dark:text-gray-500",children:"Formatting applied afterwards lands on every highlighted run at once."})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"tools",label:"Tools",active:"tools"===p,onClick:Te,children:(0,w.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,w.jsx)("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})})}),"tools"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Document"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.FileText,{size:14}),label:"Document info & word count",onClick:()=>{Me(),B("info")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Share2,{size:14}),label:"Share",onClick:()=>{Me(),B("share")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Edit3,{size:14}),label:"Rename",onClick:()=>{Me(),R(!0)}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Copy,{size:14}),label:"Make a copy",onClick:()=>{Me(),alert("Document copied to your drive")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Download,{size:14}),label:"Download",onClick:()=>{Me(),alert("Downloading document...")}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Tools"}),c&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.MessageSquare,{size:14}),label:d?`Comments Panel (${d})`:"Comments Panel",checked:!!a,onChange:()=>c()}),c&&(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(M,{label:"Find / Replace",children:(0,w.jsx)(n.I,{})}),(0,w.jsx)(M,{label:"View Source",children:(0,w.jsx)(n.n,{})}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(re,{icon:(0,w.jsx)(v.ListTree,{size:14}),label:"Table of Contents",checked:C,onChange:N}),ce&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.SpellCheck,{size:14}),label:"Spelling & Grammar",checked:E,onChange:A}),(de.available||he.available)&&(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),de.available&&(0,w.jsx)(ne,{disabled:!de.isActive&&!pe,icon:de.isActive?(0,w.jsx)(v.VolumeX,{size:14}):(0,w.jsx)(v.Volume2,{size:14}),label:de.isActive?"Stop reading":"selection"===ue?"Read selection aloud":"Read document aloud",shortcut:"Ctrl+Shift+S",onClick:()=>{Me(),Q?.commands.toggleReadAloud()}}),he.available&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.Mic,{size:14}),label:(0,T.isTranscriptionSupported)()?he.isListening?"Dictating — click to stop":"Dictate into the document":"Dictation unavailable in this browser",checked:he.isListening,onChange:()=>{(0,T.isTranscriptionSupported)()&&Q?.commands.toggleTranscribe()}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),me&&(0,w.jsx)(re,{icon:fe?(0,w.jsx)(v.File,{size:14}):(0,w.jsx)(v.Globe,{size:14}),label:fe?"Page Layout: A4":"Page Layout: Web",checked:fe,onChange:xe}),(0,w.jsx)(M,{label:"Page Settings",shortcut:"Ctrl+Shift+P",children:(0,w.jsx)(I,{})}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(M,{label:"Import Word",children:(0,w.jsx)(n.Th,{})}),(0,w.jsx)(M,{label:"Export Word",children:(0,w.jsx)(n.d,{})}),(0,w.jsx)(M,{label:"Export PDF",children:(0,w.jsx)(n.a$1,{})})]}),document.body)]}),(0,w.jsxs)("div",{className:"ml-auto dropdown-container",children:[(0,w.jsx)("button",{ref:V,title:"Settings",onClick:e=>{F?(f(null),y(null),r()):((e,t)=>{if(p===e)return f(null),void y(null);const n=t.currentTarget.getBoundingClientRect();y({top:n.bottom+4,left:n.left,right:window.innerWidth-n.right}),f(e)})("settings",e)},className:"flex items-center gap-0.5 p-1.5 rounded transition-colors "+("settings"===p?"bg-gray-200 dark:bg-slate-700":"text-gray-500 hover:bg-gray-100 dark:hover:bg-slate-800"),children:(0,w.jsx)(v.Settings,{size:16})}),!F&&"settings"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"w-[260px] px-2 py-2 shadow-2xl",right:b.right,top:b.top,children:[(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Theme"}),(0,w.jsxs)("div",{className:"flex gap-1 mb-2 px-1",children:[(0,w.jsx)("button",{onClick:()=>t("light"),className:"flex-1 px-2 py-1 text-xs border rounded "+("light"===e?"bg-blue-500 text-white border-blue-600":"hover:bg-gray-100 dark:hover:bg-slate-800"),children:"☀️ Light"}),(0,w.jsx)("button",{onClick:()=>t("dark"),className:"flex-1 px-2 py-1 text-xs border rounded "+("dark"===e?"bg-blue-500 text-white border-blue-600":"hover:bg-gray-100 dark:hover:bg-slate-800"),children:"🌙 Dark"})]}),(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Accent Color"}),(0,w.jsx)("div",{className:"grid grid-cols-4 gap-0.5 px-1 mb-2",children:["default","red","blue","green","orange","rose","violet","yellow"].map(e=>(0,w.jsx)("button",{onClick:()=>l.themeActions.setColor(e),className:"px-1.5 py-1 text-[10px] border rounded hover:bg-gray-100 dark:hover:bg-slate-800 capitalize",children:e},e))}),(0,w.jsx)("div",{className:"border-t border-gray-100 dark:border-slate-700 my-1"}),(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Language"}),(0,w.jsx)("div",{className:"grid grid-cols-2 gap-0.5 px-1 max-h-[180px] overflow-y-auto",children:[{code:"en",flag:"🇺🇸",label:"English"},{code:"es",flag:"🇪🇸",label:"Español"},{code:"de",flag:"🇩🇪",label:"Deutsch"},{code:"zh_CN",flag:"🇨🇳",label:"中文"},{code:"ja",flag:"🇯🇵",label:"日本語"},{code:"ar",flag:"🇸🇦",label:"العربية"},{code:"fr",flag:"🇫🇷",label:"Français"},{code:"pt_BR",flag:"🇧🇷",label:"Português"},{code:"ru",flag:"🇷🇺",label:"Русский"},{code:"tr",flag:"🇹🇷",label:"Türkçe"},{code:"it",flag:"🇮🇹",label:"Italiano"},{code:"fa",flag:"🇮🇷",label:"فارسی"},{code:"nl",flag:"🇳🇱",label:"Nederlands"},{code:"ko",flag:"🇰🇷",label:"한국어"},{code:"hi",flag:"🇮🇳",label:"हिन्दी"},{code:"hu_HU",flag:"🇭🇺",label:"Magyar"},{code:"vi",flag:"🇻🇳",label:"Tiếng Việt"},{code:"fi",flag:"🇫🇮",label:"Suomi"}].map(({code:e,flag:t,label:n})=>(0,w.jsxs)("button",{onClick:()=>s.localeActions.setLang(e),className:"px-1.5 py-1 text-[10px] border rounded text-left hover:bg-gray-100 dark:hover:bg-slate-800 "+(H.lang===e?"bg-blue-500/20 border-blue-500":""),children:[t," ",n]},e))})]}),document.body)]})]}),j&&(0,w.jsx)(ee,{onClose:()=>S(!1)}),C&&Q&&(0,w.jsx)(L,{editor:Q,onClose:()=>N(!1)}),ce&&E&&Q&&(0,w.jsx)(z,{editor:Q}),he.available&&(0,w.jsx)(J,{editor:Q??null}),O&&(0,w.jsx)(le,{onClose:()=>R(!1),currentName:ae}),P&&(0,w.jsx)(oe,{documentTitle:ae,editor:Q,initialTab:P,onClose:()=>B(null)})]})},ce=[{id:"improve",label:"Improve writing",description:"Clearer, tighter, same meaning",icon:v.Sparkles,group:"edit",prompt:"Improve the clarity, flow and word choice of the text. Keep the author's meaning, voice, facts and level of formality exactly as they are, and keep roughly the same length."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:v.CheckCheck,group:"edit",prompt:"Correct spelling, grammar, punctuation and obvious typos in the text. Change nothing else: keep the original wording, sentence structure, tone and formatting. If the text is already correct, return it unchanged."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:v.Minus,group:"edit",prompt:"Rewrite the text roughly half as long. Cut redundancy, filler and hedging, but keep every claim, figure, name and qualifier that carries meaning."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:v.Plus,group:"edit",prompt:"Expand the text with useful detail, explanation and structure, staying on the same topic and in the same voice. Do not invent facts, statistics, quotations or sources — expand only on what the text already implies."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:v.Feather,group:"edit",prompt:"Rewrite the text in plain, direct language: common words, shorter sentences, active voice. Keep all of the original meaning, including any technical terms that have no plain equivalent."},{id:"rephrase",label:"Rephrase",description:"Same point, fresh wording",icon:v.ArrowRightLeft,group:"edit",prompt:"Rewrite the text with different wording and sentence structure while preserving its meaning, tone and approximate length. Avoid reusing the original phrasing."},{id:"professional",label:"Professional tone",description:"Polished and businesslike",icon:v.Briefcase,group:"tone",prompt:"Rewrite the text in a polished, professional tone: precise, courteous, free of slang and exclamation marks. Do not change the meaning or add new claims."},{id:"casual",label:"Casual tone",description:"Relaxed and conversational",icon:v.Coffee,group:"tone",prompt:"Rewrite the text in a relaxed, conversational tone, as if explaining it to a colleague. Keep it clear and keep the meaning unchanged; do not add jokes or filler."},{id:"confident",label:"More confident",description:"Drop the hedging",icon:v.PenLine,group:"tone",prompt:'Rewrite the text so it reads more decisively: remove hedges such as "maybe", "I think" and "sort of", and use active voice. Keep any genuine uncertainty that the text explicitly states.'},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:v.SmilePlus,group:"tone",prompt:"Add a small number of relevant emoji to the text, at most one per sentence. Do not change any of the wording."},{id:"summarize",label:"Summarize",description:"Condense into a short paragraph",icon:v.FileText,group:"transform",prompt:"Summarize the text in one short paragraph that captures its main point and the reasoning behind it. Use only information present in the text."},{id:"key-points",label:"Key takeaways",description:"Turn it into a bullet list",icon:v.ListTree,group:"transform",prompt:'Rewrite the text as a list of the key takeaways, one per line, each starting with "- ". Keep each line to a single sentence and use only information present in the text.'},{id:"action-items",label:"Extract action items",description:"Who does what, next",icon:v.ListChecks,group:"transform",prompt:'List the concrete action items implied by the text, one per line, each starting with "- " and written as an imperative with the owner named when the text names one. If the text contains no action items, return "- No action items.".'},{id:"explain",label:"Explain this",description:"Plain-English explanation",icon:v.Baby,group:"transform",prompt:"Explain what the text means in plain English, in one short paragraph a non-expert can follow. Explain the text; do not rewrite or evaluate it."},{id:"translate",label:"Translate",description:"Into another language",icon:v.Languages,group:"transform",options:[{id:"en",label:"English"},{id:"es",label:"Spanish"},{id:"fr",label:"French"},{id:"de",label:"German"},{id:"pt",label:"Portuguese"},{id:"it",label:"Italian"},{id:"zh",label:"Chinese (Simplified)"},{id:"ja",label:"Japanese"},{id:"ko",label:"Korean"},{id:"hi",label:"Hindi"},{id:"ar",label:"Arabic"},{id:"ru",label:"Russian"}],prompt:"Translate the text accurately, preserving tone, formatting, line breaks, names, URLs, code and numbers. Target language:"},{id:"continue",label:"Continue writing",description:"Pick up where the text stops",icon:v.WandSparkles,group:"generate",requiresSelection:!1,prompt:"Continue the document from where it stops, in the same voice, tense and formatting. Write one or two paragraphs that follow naturally. Do not repeat what has already been written and do not invent sources or statistics."},{id:"outline",label:"Draft an outline",description:"Headings for this document",icon:v.ListTree,group:"generate",requiresSelection:!1,prompt:'Draft a working outline for this document, one heading per line, each starting with "- ". Base it on what the document is already about.'},{id:"counterpoint",label:"Counterpoint",description:"The strongest objection",icon:v.Quote,group:"transform",prompt:"State the strongest good-faith objection to the argument in the text, in one short paragraph. Name the assumption it challenges. Do not invent evidence, sources or statistics."}],de=[/^#{1,6}\s+/m,/^\s*[-*+]\s+\S/m,/^\s*\d+\.\s+\S/m,/^\s*>\s+\S/m,/^\s*[-*]\s+\[[ xX]\]/m,/^\|.+\|\s*$/m,/^\s*(?:---|\*\*\*)\s*$/m],he=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function ue(e){return n.me$1.parse(e,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function pe(e){const t=e.trim();return t?function(e){return function(e){return de.some(t=>t.test(e))||he.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}(t)?{content:ue(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}function me(e,t){return new Promise((n,r)=>{const s=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(s),r(new DOMException("Aborted","AbortError"))},{once:!0})})}var fe=async(e,t,n)=>{const r=function(e,t,n){const r=`${e} ${t}`.toLowerCase(),s=n.trim();if(!s)return r.includes("outline")?"- Background\n- What changed\n- Why it matters\n- Next steps":`${t.trim()||"New content"}\n\n(Offline demo response — configure Ai.configure({ getCompletion }) to use a real model.)`;if(r.includes("emoji"))return`${s} ✨📝`;if(r.includes("shorter")||r.includes("concise")){const e=s.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return r.includes("longer")||r.includes("expand")?`${s} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:r.includes("key-points")||r.includes("action-items")||r.includes("takeaway")?s.split(/(?<=[.!?])\s+/).map(e=>e.trim()).filter(Boolean).map(e=>`- ${e.replace(/[.!?]$/,"")}`).join("\n"):r.includes("simplify")?s.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):s.charAt(0).toUpperCase()+s.slice(1).replace(/\s{2,}/g," ")}(e.commandId,e.instruction,e.selectedText).split(/(\s+)/).filter(Boolean);let s="";for(const i of r){if(n.aborted)throw new DOMException("Aborted","AbortError");s+=i,t(s),i.trim()&&await me(35,n)}return s},ge=["You are a writing assistant inside a rich-text editor.","Return only the text that should appear in the document — nothing else.","Never add a preamble, sign-off, explanation, or commentary about what you changed.","Never wrap the answer in Markdown code fences or quotation marks unless the original text was itself fenced or quoted.","Preserve the original language of the text unless asked to translate.","Preserve quotations, citations, URLs, code, numbers and proper nouns exactly, unless the instruction is explicitly about changing them.","Never invent facts, statistics, sources, citations or links.","Match the surrounding formatting: plain paragraphs separated by blank lines, and one item per line for lists."].join("\n");function xe(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}var be=/^(?:sure|certainly|of course|absolutely|got it|okay|ok|here(?:'|’)?s|here is|here are|below is|i(?:'|’)?ve|i have)\b[^\n:]{0,120}:[ \t]*\r?\n+/i,ye=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,we=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,ve=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function ke(e,{streaming:t=!1}={}){if(!e)return"";let n=function(e){return e.replace(/\r\n/g,"\n").replace(/[ \t]+$/gm,"").replace(/\n{3,}/g,"\n\n")}(e);return n=function(e){const t=e.replace(be,"");return t!==e?t:e.replace(ye,"")}(n),n=function(e){if(!we.test(e))return e;const t=e.replace(we,"").replace(ve,"");return/(?:^|\n)[ \t]*(?:```|~~~)/.test(t)?e:t}(n),t||(n=function(e){const t=e.trim();if(t.length<2)return e;for(const[n,r]of[['"','"'],["“","”"],["'","'"],["‘","’"]]){if(!t.startsWith(n)||!t.endsWith(r))continue;const e=t.slice(n.length,t.length-r.length);if(!e.includes(r))return e}return e}(n)),n=n.replace(/^\n+/,""),t?n.replace(/[ \t]+$/," ").replace(/^[ \t]+/,""):n.trim()}var je=new y.PluginKey("ai");function Se(e){return je.getState(e)}function Ce(e,t){switch(e.status){case"menu":case"loading":case"error":return{from:e.from,to:e.to};case"reviewing":return{from:e.suggestion.from,to:e.suggestion.to};default:return t}}function Ne(e,t,n){if("loading"===t.status)return S.DecorationSet.create(e,[S.Decoration.widget(t.to,()=>{const e=document.createElement("span");return e.className=n.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:r,to:s,suggestedText:i,mode:o}=t.suggestion,l=[];return"replace"===o&&s>r&&l.push(S.Decoration.inline(r,s,{class:n.removedClass})),l.push(S.Decoration.widget(s,()=>{const e=document.createElement("span");return e.className=n.insertedClass,e.textContent=i||"…",e},{side:1})),S.DecorationSet.create(e,l)}return S.DecorationSet.empty}async function Ee(e,t,n,r,s,i){const{view:o}=e,l=e.state.doc,a=s===i?"":l.textBetween(s,i,"\n"),c=function(e,t,n,r){if(r<=0)return"";const s=r+200,i=e.textBetween(Math.max(0,t-s),t,"\n"),o=e.textBetween(n,Math.min(e.content.size,n+s),"\n"),l=(a=i,(c=Math.floor(r/2))<=0?"":a.length<=c?a:`…${a.slice(a.length-c)}`);var a,c;const d=o.length>r-l.length?`${o.slice(0,r-l.length)}…`:o;return`${l}${l&&d?"\n":""}${d}`.trim()}(l,s,i,t.contextChars),d=a?"replace":"insert";n.abortController?.abort();const h=new AbortController;n.abortController=h;const u=n.requestToken+=1;o.dispatch(o.state.tr.setMeta(je,{type:"set-loading",from:s,to:i,commandId:r.commandId,commandLabel:r.commandLabel,instruction:r.instruction,option:r.option}));const p=(t,o)=>{if(u!==n.requestToken||e.isDestroyed)return;const l=ke(t,{streaming:o});e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-suggestion",commandLabel:r.commandLabel,suggestion:{from:s,to:i,originalText:a,suggestedText:l,mode:d,isStreaming:o}}))};try{const o=await t.getCompletion({instruction:r.instruction,selectedText:a,documentText:c,commandId:r.commandId,commandLabel:r.commandLabel,option:r.option,systemPrompt:t.systemPrompt,mode:d},e=>p(e,!0),h.signal);if(u!==n.requestToken||e.isDestroyed)return;if(!ke(o))return void e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:"The model returned an empty response."}));p(o,!1)}catch(Le){if(h.signal.aborted||u!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:Le instanceof Error?Le.message:"Something went wrong."}))}}b.Extension.create({name:"ai",addOptions:()=>({commands:ce,getCompletion:fe,systemPrompt:ge,contextChars:4e3,removedClass:"ai-removed-text",insertedClass:"ai-suggested-text",loadingClass:"ai-loading-indicator"}),addStorage:()=>({requestToken:0,abortController:null}),onDestroy(){this.storage.abortController?.abort()},addKeyboardShortcuts(){return{"Mod-j":()=>this.editor.commands.openAiMenu()}},addCommands(){const e=()=>{this.storage.abortController?.abort(),this.storage.abortController=null,this.storage.requestToken+=1};return{openAiMenu:()=>({state:t,dispatch:n})=>{e();const{from:r,to:s}=t.selection;return n&&n(t.tr.setMeta(je,{type:"open-menu",from:r,to:s})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(je,{type:"close"})),!0),stopAiGeneration:()=>({state:t,dispatch:n})=>{const r=Se(t)?.panel;if(!r||"loading"!==r.status&&"reviewing"!==r.status)return!1;if("reviewing"===r.status&&!r.suggestion.isStreaming)return!1;if(e(),!n)return!0;if("reviewing"===r.status)n(t.tr.setMeta(je,{type:"settle"}));else{const{from:e,to:s}=Ce(r,t.selection);n(t.tr.setMeta(je,{type:"open-menu",from:e,to:s}))}return!0},runAiCommand:(e,t)=>({state:n,editor:r})=>{const s=this.options.commands.find(t=>t.id===e);if(!s)return!1;const{from:i,to:o}=Ce(Se(n)?.panel??{status:"closed"},n.selection);return!(!1!==s.requiresSelection&&i===o||s.options?.length&&!t||(Ee(r,this.options,this.storage,{instruction:xe(s,t),commandId:s.id,commandLabel:t?`${s.label} → ${t}`:s.label,option:t},i,o),0))},submitAiPrompt:e=>({state:t,editor:n})=>{const r=e.trim();if(!r)return!1;const{from:s,to:i}=Ce(Se(t)?.panel??{status:"closed"},t.selection);return Ee(n,this.options,this.storage,{instruction:r,commandId:"custom",commandLabel:"Custom"},s,i),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const n=Se(e)?.lastRequest;return!!n&&(Ee(t,this.options,this.storage,{instruction:n.instruction,commandId:n.commandId,commandLabel:n.commandLabel,option:n.option},n.from,n.to),!0)},acceptAiSuggestion:()=>({state:t,chain:n})=>{const r=Se(t)?.panel;if(!r||"reviewing"!==r.status||r.suggestion.isStreaming)return!1;const{from:s,to:i,suggestedText:o}=r.suggestion,{content:l}=pe(o);return!!l&&(e(),n().insertContentAt({from:s,to:i},l,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(je,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(je,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:t,chain:n})=>{const r=Se(t)?.panel;if(!r||"reviewing"!==r.status||r.suggestion.isStreaming)return!1;const{to:s,suggestedText:i}=r.suggestion,{content:o}=pe(i);if(!o)return!1;const l=t.doc.resolve(Math.min(s,t.doc.content.size)),a=l.depth>0?l.after(l.depth):l.pos;return e(),n().insertContentAt(a,o,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(je,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new y.Plugin({key:je,state:{init:()=>({panel:{status:"closed"},decorations:S.DecorationSet.empty,lastRequest:null}),apply(t,n){let r=n.panel,s=n.lastRequest;t.docChanged&&(r=function(e,t){switch(e.status){case"closed":default:return e;case"menu":case"loading":case"error":return{...e,from:t.map(e.from),to:t.map(e.to)};case"reviewing":return{...e,suggestion:{...e.suggestion,from:t.map(e.suggestion.from),to:t.map(e.suggestion.to)}}}}(r,t.mapping));const i=t.getMeta(je);if(i)switch(i.type){case"open-menu":r={status:"menu",from:i.from,to:i.to};break;case"set-loading":r={status:"loading",from:i.from,to:i.to,commandLabel:i.commandLabel},s={instruction:i.instruction,commandId:i.commandId,commandLabel:i.commandLabel,option:i.option,from:i.from,to:i.to};break;case"set-suggestion":r={status:"reviewing",suggestion:i.suggestion,commandLabel:i.commandLabel};break;case"set-error":r={status:"error",from:i.from,to:i.to,commandLabel:i.commandLabel,message:i.message};break;case"settle":"reviewing"===r.status&&(r={...r,suggestion:{...r.suggestion,isStreaming:!1}});break;case"close":r={status:"closed"}}return{panel:r,decorations:Ne(t.doc,r,e),lastRequest:s}}},props:{decorations(e){return this.getState(e)?.decorations??S.DecorationSet.empty}}})]}});var Ae=()=>new Map,Te=e=>{const t=Ae();return e.forEach((e,n)=>{t.set(n,e)}),t},Me=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},_e=()=>new Set,De=e=>e[e.length-1],Oe=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},$e=Array.from,Re=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ie=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Pe=Array.isArray,Le=class{constructor(){this._observers=Ae()}on(e,t){return Me(this._observers,e,_e).add(t),t}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||Ae()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ae()}},ze=Math.floor,Be=Math.abs,Fe=(e,t)=>e<t?e:t,Ve=(e,t)=>e>t?e:t,We=(Number.isNaN,e=>0!==e?e<0:1/e<0),qe=Number.MAX_SAFE_INTEGER,He=Number.MIN_SAFE_INTEGER,Ue=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&ze(e)===e),Je=(Number.isNaN,Number.parseInt,String.fromCharCode),Ke=(String.fromCodePoint,Je(65535),/^\s*/g),Ge=/([A-Z])/g,Xe=(e,t)=>(e=>e.replace(Ke,""))(e.replace(Ge,e=>`${t}${(e=>e.toLowerCase())(e)}`)),Ye="undefined"!=typeof TextEncoder?new TextEncoder:null,Ze=Ye?e=>Ye.encode(e):e=>{const t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},Qe="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Qe&&1===Qe.decode(new Uint8Array).length&&(Qe=null);var et,tt,nt,rt,st=(e,t)=>((e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t();return n})(t,()=>e).join(""),it=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ot=()=>new it,lt=e=>{const t=new Uint8Array((e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t})(e));let n=0;for(let r=0;r<e.bufs.length;r++){const s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},at=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),e.cpos=0),e.cbuf[e.cpos++]=t},ct=at,dt=(e,t)=>{for(;t>127;)at(e,128|127&t),t=ze(t/128);at(e,127&t)},ht=(e,t)=>{const n=We(t);for(n&&(t=-t),at(e,(t>63?128:0)|(n?64:0)|63&t),t=ze(t/64);t>0;)at(e,(t>127?128:0)|127&t),t=ze(t/128)},ut=new Uint8Array(3e4),pt=ut.length/3,mt=Ye&&Ye.encodeInto?(e,t)=>{if(t.length<pt){const n=Ye.encodeInto(t,ut).written||0;dt(e,n);for(let t=0;t<n;t++)at(e,ut[t])}else gt(e,Ze(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;dt(e,r);for(let s=0;s<r;s++)at(e,n.codePointAt(s))},ft=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=Fe(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ve(2*n,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},gt=(e,t)=>{dt(e,t.byteLength),ft(e,t)},xt=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*Ve(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},bt=new DataView(new ArrayBuffer(4)),yt=(e,t)=>{switch(typeof t){case"string":at(e,119),mt(e,t);break;case"number":Ue(t)&&Be(t)<=2147483647?(at(e,125),ht(e,t)):(n=t,bt.setFloat32(0,n),bt.getFloat32(0)===n?(at(e,124),((e,t)=>{xt(e,4).setFloat32(0,t,!1)})(e,t)):(at(e,123),((e,t)=>{xt(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":at(e,122),((e,t)=>{xt(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)at(e,126);else if(Pe(t)){at(e,117),dt(e,t.length);for(let n=0;n<t.length;n++)yt(e,t[n])}else if(t instanceof Uint8Array)at(e,116),gt(e,t);else{at(e,118);const n=Object.keys(t);dt(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];mt(e,s),yt(e,t[s])}}break;case"boolean":at(e,t?120:121);break;default:at(e,127)}var n},wt=class extends it{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&dt(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},vt=e=>{e.count>0&&(ht(e.encoder,1===e.count?e.s:-e.s),e.count>1&&dt(e.encoder,e.count-2))},kt=class{constructor(){this.encoder=new it,this.s=0,this.count=0}write(e){this.s===e?this.count++:(vt(this),this.count=1,this.s=e)}toUint8Array(){return vt(this),lt(this.encoder)}},jt=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);ht(e.encoder,t),e.count>1&&dt(e.encoder,e.count-2)}},St=class{constructor(){this.encoder=new it,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(jt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return jt(this),lt(this.encoder)}},Ct=class{constructor(){this.sarr=[],this.s="",this.lensE=new kt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new it;return this.sarr.push(this.s),this.s="",mt(e,this.sarr.join("")),ft(e,this.lensE.toUint8Array()),lt(e)}},Nt=e=>new Error(e),Et=()=>{throw Nt("Method unimplemented")},At=()=>{throw Nt("Unexpected case")},Tt=Nt("Unexpected end of array"),Mt=Nt("Integer out of Range"),_t=class{constructor(e){this.arr=e,this.pos=0}},Dt=e=>new _t(e),Ot=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,Rt(e)),$t=e=>e.arr[e.pos++],Rt=e=>{let t=0,n=1;const r=e.arr.length;for(;e.pos<r;){const r=e.arr[e.pos++];if(t+=(127&r)*n,n*=128,r<128)return t;if(t>qe)throw Mt}throw Tt},It=e=>{let t=e.arr[e.pos++],n=63&t,r=64;const s=(64&t)>0?-1:1;if(!(128&t))return s*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n+=(127&t)*r,r*=128,t<128)return s*n;if(n>qe)throw Mt}throw Tt},Pt=Qe?e=>Qe.decode(Ot(e)):e=>{let t=Rt(e);if(0===t)return"";{let n=String.fromCodePoint($t(e));if(--t<100)for(;t--;)n+=String.fromCodePoint($t(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},Lt=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},zt=[e=>{},e=>null,It,e=>Lt(e,4).getFloat32(0,!1),e=>Lt(e,8).getFloat64(0,!1),e=>Lt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Pt,e=>{const t=Rt(e),n={};for(let r=0;r<t;r++)n[Pt(e)]=Bt(e);return n},e=>{const t=Rt(e),n=[];for(let r=0;r<t;r++)n.push(Bt(e));return n},Ot],Bt=e=>zt[127-$t(e)](e),Ft=class extends _t{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=Rt(this)+1:this.count=-1),this.count--,this.s;var e}},Vt=class extends _t{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=It(this);const e=We(this.s);this.count=1,e&&(this.s=-this.s,this.count=Rt(this)+2)}return this.count--,this.s}},Wt=class extends _t{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=It(this),t=1&e;this.diff=ze(e/2),this.count=1,t&&(this.count=Rt(this)+2)}return this.s+=this.diff,this.count--,this.s}},qt=class{constructor(e){this.decoder=new Vt(e),this.str=Pt(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}},Ht=(crypto.subtle,crypto.getRandomValues.bind(crypto)),Ut=Math.random,Jt=()=>Ht(new Uint32Array(1))[0],Kt=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(e^Jt()&15>>e/4).toString(16)),Gt=Date.now,Xt=e=>new Promise(e),Yt=(Promise.all.bind(Promise),new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}});try{"undefined"!=typeof localStorage&&localStorage&&(Yt=localStorage,!1)}catch(au){}var Zt,Qt=Yt,en=Symbol("Equality"),tn=(e,t)=>e===t||!!e?.[en]?.(t)||!1,nn=Object.assign,rn=Object.keys,sn=e=>rn(e).length,on=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},ln=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),an=Object.freeze,cn=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||cn(e[t])}return an(e)},dn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&dn(e,t,n+1)}},hn=(e,t)=>{if(e===t)return!0;if(null==e||null==t||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(null!=e[en])return e[en](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;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!hn(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(sn(e)!==sn(t))return!1;for(const n in e)if(!ln(e,n)||!hn(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!hn(e[n],t[n]))return!1;break;default:return!1}return!0},un="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),pn="undefined"!=typeof window&&"undefined"!=typeof document&&!un,mn=("undefined"!=typeof navigator&&/Mac/.test(navigator.platform),[]),fn=e=>(()=>{if(void 0===et)if(un){et=Ae();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];"-"===r[0]?(null!==t&&et.set(t,""),t=r):null!==t?(et.set(t,r),t=null):mn.push(r)}null!==t&&et.set(t,"")}else"object"==typeof location?(et=Ae(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");et.set(`--${Xe(t,"-")}`,n),et.set(`-${Xe(t,"-")}`,n)}})):et=Ae();return et})().has(e),gn=e=>(e=>void 0===e?null:e)(un?process.env[e.toUpperCase().replaceAll("-","_")]:Qt.getItem(e)),xn=e=>fn("--"+e)||null!==gn(e),bn=xn("production"),yn=(un&&(tt=process.env.FORCE_COLOR,nt=["true","1","2"],nt.includes(tt))||!fn("--no-colors")&&!xn("no-color")&&(!un||process.stdout.isTTY)&&(!un||fn("--color")||null!==gn("COLORTERM")||(gn("TERM")||"").includes("color")),pn?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Je(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")),wn=class{constructor(e,t){this.left=e,this.right=t}},vn=(e,t)=>new wn(e,t),kn=e=>e.next()>=.5,jn=(e,t,n)=>ze(e.next()*(n+1-t)+t),Sn=(e,t,n)=>ze(e.next()*(n+1-t)+t),Cn=(e,t,n)=>Sn(e,t,n),Nn=e=>Je(Cn(e,97,122)),En=(e,t)=>t[Cn(e,0,t.length-1)],An=Symbol("0schema"),Tn=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){const e=[];for(let t=this._rerrs.length-1;t>0;t--){const n=this._rerrs[t];e.push(st(" ",2*(this._rerrs.length-t))+`${null!=n.path?`[${n.path}] `:""}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join("\n")}},Mn=(e,t)=>e===t||null!=e&&null!=t&&e.constructor===t.constructor&&(e[en]?tn(e,t):Pe(e)?Re(e,e=>Ie(t,t=>Mn(e,t))):"object"==typeof e&&on(e,(e,n)=>Mn(e,t[n]))),_n=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Mn(t,n)}equals(e){return this.constructor===e.constructor&&hn(this.shape,e.shape)}[An](){return!0}[en](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Et()}get nullable(){return lr(this,kr)}get optional(){return new Vn(this)}cast(e){return Nr(e,this),e}expect(e){return Nr(e,this),e}},Dn=class extends _n{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){const n=e?.constructor===this.shape&&(null==this._c||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),n}},On=(e,t=null)=>new Dn(e,t),$n=(On(Dn),class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=this.shape(e);return!n&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),n}}),Rn=e=>new $n(e),In=(On($n),class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(" | "),e.toString()),n}}),Pn=(...e)=>new In(e),Ln=On(In),zn=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Bn=e=>xr.check(e)?[zn(e)]:Ln.check(e)?e.shape.map(e=>e+""):gr.check(e)?["[+-]?\\d+.?\\d*"]:br.check(e)?[".*"]:ar.check(e)?e.shape.map(Bn).flat(1):void At(),Fn=(On(class extends _n{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Bn).map(e=>`(${e.join("|")})`).join("")+"$")}check(e,t){const n=null!=this._r.exec(e);return!n&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),n}}),Symbol("optional")),Vn=class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=void 0===e||this.shape.check(e);return!n&&t?.extend(null,"undefined (optional)","()"),n}get[Fn](){return!0}},Wn=On(Vn),qn=class extends _n{check(e,t){return t?.extend(null,"never",typeof e),!1}},Hn=(new qn,On(qn),class e extends _n{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 null==e?(t?.extend(null,"object","null"),!1):on(this.shape,(n,r)=>{const s=this._isPartial&&!ln(e,r)||n.check(e[r],t);return!s&&t?.extend(r.toString(),n.toString(),typeof e[r],"Object property does not match"),s})}}),Un=On(Hn),Jn=Rn(e=>null!=e&&(e.constructor===Object||null==e.constructor)),Kn=class extends _n{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return null!=e&&on(e,(n,r)=>{const s=this.shape.keys.check(r,t);return!s&&t?.extend(r+"","Record",typeof e,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(n,t)})}},Gn=(e,t)=>new Kn(e,t),Xn=On(Kn),Yn=class extends _n{constructor(e){super(),this.shape=e}check(e,t){return null!=e&&on(this.shape,(n,r)=>{const s=n.check(e[r],t);return!s&&t?.extend(r.toString(),"Tuple",typeof n),s})}},Zn=(On(Yn),class extends _n{constructor(e){super(),this.shape=1===e.length?e[0]:new or(e)}check(e,t){const n=Pe(e)&&Re(e,e=>this.shape.check(e));return!n&&t?.extend(null,"Array",""),n}}),Qn=(...e)=>new Zn(e),er=On(Zn),tr=Rn(e=>Pe(e)),nr=class extends _n{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){const n=e instanceof this.shape&&(null==this._c||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},rr=(On(nr),((e,t=null)=>new nr(_n,t))()),sr=On(class extends _n{constructor(e){super(),this.len=e.length-1,this.args=((...e)=>new Yn(e))(...e.slice(-1)),this.res=e[this.len]}check(e,t){const n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,"function",typeof e),n}}),ir=Rn(e=>"function"==typeof e),or=(On(class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=Re(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,"Intersectinon",typeof e),n}},e=>e.shape.length>0),class extends _n{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){const n=Ie(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),n}}),lr=(...e)=>e.findIndex(e=>ar.check(e))>=0?lr(...e.map(e=>Cr(e)).map(e=>ar.check(e)?e.shape:[e]).flat(1)):1===e.length?e[0]:new or(e),ar=On(or),cr=()=>!0,dr=Rn(cr),hr=On($n,e=>e.shape===cr),ur=Rn(e=>"bigint"==typeof e),pr=Rn(e=>e===ur),mr=Rn(e=>"symbol"==typeof e),fr=(Rn(e=>e===mr),Rn(e=>"number"==typeof e)),gr=Rn(e=>e===fr),xr=Rn(e=>"string"==typeof e),br=Rn(e=>e===xr),yr=Rn(e=>"boolean"==typeof e),wr=Rn(e=>e===yr),vr=Pn(void 0),kr=(On(In,e=>1===e.shape.length&&void 0===e.shape[0]),Pn(void 0),Pn(null)),jr=On(In,e=>1===e.shape.length&&null===e.shape[0]),Sr=(On(Uint8Array),On(Dn,e=>e.shape===Uint8Array),lr(fr,xr,kr,vr,ur,yr,mr)),Cr=((()=>{const e=Qn(dr),t=Gn(xr,dr),n=lr(fr,xr,kr,yr,e,t);e.shape=n,t.shape.values=n})(),e=>{if(rr.check(e))return e;if(Jn.check(e)){const t={};for(const n in e)t[n]=Cr(e[n]);return new Hn(t)}return tr.check(e)?lr(...e.map(Cr)):Sr.check(e)?Pn(e):ir.check(e)?On(e):void At()}),Nr=bn?()=>{}:(e,t)=>{const n=new Tn;if(!t.check(e,n))throw Nt(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Er=(rt=dr,new class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Cr(e),h:t}),this}else(e){return this.if(dr,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){const r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Nt("Unhandled pattern")}}}(rt)).if(gr,(e,t)=>jn(t,He,qe)).if(br,(e,t)=>((e,t=0,n=20)=>{const r=Cn(e,t,n);let s="";for(let i=0;i<r;i++)s+=Nn(e);return s})(t)).if(wr,(e,t)=>kn(t)).if(pr,(e,t)=>BigInt(jn(t,He,qe))).if(ar,(e,t)=>Ar(t,En(t,e.shape))).if(Un,(e,t)=>{const n={};for(const r in e.shape){let s=e.shape[r];if(Wn.check(s)){if(kn(t))continue;s=s.shape}n[r]=Er(s,t)}return n}).if(er,(e,t)=>{const n=[],r=Sn(t,0,42);for(let s=0;s<r;s++)n.push(Ar(t,e.shape));return n}).if(Ln,(e,t)=>En(t,e.shape)).if(jr,(e,t)=>null).if(sr,(e,t)=>{const n=Ar(t,e.res);return()=>n}).if(hr,(e,t)=>Ar(t,En(t,[fr,xr,kr,vr,ur,yr,Qn(fr),Gn(lr("a","b","c"),fr)]))).if(Xn,(e,t)=>{const n={},r=jn(t,0,3);for(let s=0;s<r;s++)n[Ar(t,e.shape.keys)]=Ar(t,e.shape.values);return n}).done(),Ar=(e,t)=>Er(Cr(t),e),Tr="undefined"!=typeof document?document:{},Mr=(Rn(e=>e.nodeType===Or),"undefined"!=typeof DOMParser&&new DOMParser,Rn(e=>e.nodeType===Mr),Rn(e=>e.nodeType===_r),Tr.ELEMENT_NODE),_r=Tr.TEXT_NODE,Dr=(Tr.CDATA_SECTION_NODE,Tr.COMMENT_NODE,Tr.DOCUMENT_NODE),Or=(Tr.DOCUMENT_TYPE_NODE,Tr.DOCUMENT_FRAGMENT_NODE),$r=(Rn(e=>e.nodeType===Dr),JSON.stringify,Zt=clearTimeout,class{constructor(e){this._=e}destroy(){Zt(this._)}}),Rr=(e,t)=>new $r(setTimeout(t,e)),Ir=Symbol,Pr=Ir(),Lr=Ir(),zr=(Ir(),Ir(),Ir(),Ir()),Br=(Ir(),Ir()),Fr=(Ir(),Gt(),vn("font-weight","bold"),vn("font-weight","normal"),vn("color","blue"),vn("color","green"),vn("color","grey"),vn("color","red"),vn("color","purple"),vn("color","orange"),vn("color","black"),(...e)=>{Wr.forEach(t=>t.print(e))}),Vr=(...e)=>{e.unshift(Br),Wr.forEach(t=>t.print(e))},Wr=_e(),qr=e=>({[Symbol.iterator](){return this},next:e}),Hr=(e,t)=>qr(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),Ur=class{constructor(e,t){this.clock=e,this.len=t}},Jr=class{constructor(){this.clients=new Map}},Kr=(e,t,n)=>t.clients.forEach((t,r)=>{const s=e.doc.store.clients.get(r);if(null!=s){const r=s[s.length-1],i=r.id.clock+r.length;for(let o=0,l=t[o];o<t.length&&l.clock<i;l=t[++o])Vs(e,s,l.clock,l.len,n)}}),Gr=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,r=e.length-1;for(;n<=r;){const s=ze((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null})(n,t.clock)},Xr=e=>{e.clients.forEach(e=>{let t,n;for(e.sort((e,t)=>e.clock-t.clock),t=1,n=1;t<e.length;t++){const r=e[n-1],s=e[t];r.clock+r.len>=s.clock?e[n-1]=new Ur(r.clock,Ve(r.len,s.clock+s.len-r.clock)):(n<t&&(e[n]=s),n++)}e.length=n})},Yr=e=>{const t=new Jr;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){const i=r.slice();for(let t=n+1;t<e.length;t++)Oe(i,e[t].clients.get(s)||[]);t.clients.set(s,i)}});return Xr(t),t},Zr=(e,t,n,r)=>{Me(e.clients,t,()=>[]).push(new Ur(n,r))},Qr=()=>new Jr,es=(e,t)=>{dt(e.restEncoder,t.clients.size),$e(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),dt(e.restEncoder,t);const r=n.length;dt(e.restEncoder,r);for(let s=0;s<r;s++){const t=n[s];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},ts=e=>{const t=new Jr,n=Rt(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=Rt(e.restDecoder),r=Rt(e.restDecoder);if(r>0){const s=Me(t.clients,n,()=>[]);for(let t=0;t<r;t++)s.push(new Ur(e.readDsClock(),e.readDsLen()))}}return t},ns=(e,t,n)=>{const r=new Jr,s=Rt(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=Rt(e.restDecoder),i=Rt(e.restDecoder),o=n.clients.get(s)||[],l=Rs(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Zr(r,s,l,i-l);let e=Ps(o,n),a=o[e];for(!a.deleted&&a.id.clock<n&&(o.splice(e+1,0,Mo(t,a,n-a.id.clock)),e++);e<o.length&&(a=o[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&o.splice(e,0,Mo(t,a,i-a.id.clock)),a.delete(t))}else Zr(r,s,n,i-n)}}if(r.clients.size>0){const e=new ds;return dt(e.restEncoder,0),es(e,r),e.toUint8Array()}return null},rs=Jt,ss=class e extends Le{constructor({guid:e=Kt(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:s=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=rs(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Os,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Xt(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>Xt(e=>{const t=n=>{void 0!==n&&!0!==n||(this.off("sync",t),e())};this.on("sync",t)});this.on("sync",e=>{!1===e&&this.isSynced&&(this.whenSynced=l()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;null===e||this.shouldLoad||Ks(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Ks(this,e,t)}get(e,t=gi){const n=Me(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==gi&&r!==t){if(r===gi){const r=new t;r._map=n._map,n._map.forEach(e=>{for(;null!==e;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;null!==e;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=""){return this.get(e,Ri)}getText(e=""){return this.get(e,Qi)}getMap(e=""){return this.get(e,Pi)}getXmlElement(e=""){return this.get(e,no)}getXmlFragment(e=""){return this.get(e,to)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ks(t.parent.doc,e=>{const 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()}},is=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Rt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Rt(this.restDecoder)+1;return this.dsCurrVal+=e,e}},os=class extends is{constructor(e){super(e),this.keys=[],Rt(e),this.keyClockDecoder=new Wt(Ot(e)),this.clientDecoder=new Vt(Ot(e)),this.leftClockDecoder=new Wt(Ot(e)),this.rightClockDecoder=new Wt(Ot(e)),this.infoDecoder=new Ft(Ot(e),$t),this.stringDecoder=new qt(Ot(e)),this.parentInfoDecoder=new Ft(Ot(e),$t),this.typeRefDecoder=new Vt(Ot(e)),this.lenDecoder=new Vt(Ot(e))}readLeftID(){return new bs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new bs(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Bt(this.restDecoder)}readBuf(){return Ot(this.restDecoder)}readJSON(){return Bt(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}},ls=class{constructor(){this.restEncoder=ot()}toUint8Array(){return lt(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){dt(this.restEncoder,e)}writeDsLen(e){dt(this.restEncoder,e)}},as=class extends ls{writeLeftID(e){dt(this.restEncoder,e.client),dt(this.restEncoder,e.clock)}writeRightID(e){dt(this.restEncoder,e.client),dt(this.restEncoder,e.clock)}writeClient(e){dt(this.restEncoder,e)}writeInfo(e){ct(this.restEncoder,e)}writeString(e){mt(this.restEncoder,e)}writeParentInfo(e){dt(this.restEncoder,e?1:0)}writeTypeRef(e){dt(this.restEncoder,e)}writeLen(e){dt(this.restEncoder,e)}writeAny(e){yt(this.restEncoder,e)}writeBuf(e){gt(this.restEncoder,e)}writeJSON(e){mt(this.restEncoder,JSON.stringify(e))}writeKey(e){mt(this.restEncoder,e)}},cs=class{constructor(){this.restEncoder=ot(),this.dsCurrVal=0}toUint8Array(){return lt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,dt(this.restEncoder,t)}writeDsLen(e){0===e&&At(),dt(this.restEncoder,e-1),this.dsCurrVal+=e}},ds=class extends cs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new St,this.clientEncoder=new kt,this.leftClockEncoder=new St,this.rightClockEncoder=new St,this.infoEncoder=new wt(ct),this.stringEncoder=new Ct,this.parentInfoEncoder=new wt(ct),this.typeRefEncoder=new kt,this.lenEncoder=new kt}toUint8Array(){const e=ot();return dt(e,0),gt(e,this.keyClockEncoder.toUint8Array()),gt(e,this.clientEncoder.toUint8Array()),gt(e,this.leftClockEncoder.toUint8Array()),gt(e,this.rightClockEncoder.toUint8Array()),gt(e,lt(this.infoEncoder)),gt(e,this.stringEncoder.toUint8Array()),gt(e,lt(this.parentInfoEncoder)),gt(e,this.typeRefEncoder.toUint8Array()),gt(e,this.lenEncoder.toUint8Array()),ft(e,lt(this.restEncoder)),lt(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){yt(this.restEncoder,e)}writeBuf(e){gt(this.restEncoder,e)}writeJSON(e){yt(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},hs=(e,t,n)=>{const r=new Map;n.forEach((e,n)=>{Rs(t,n)>e&&r.set(n,e)}),$s(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),dt(e.restEncoder,r.size),$e(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{((e,t,n,r)=>{r=Ve(r,t[0].id.clock);const s=Ps(t,r);dt(e.restEncoder,t.length-s),e.writeClient(n),dt(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)})(e,t.clients.get(n),n,r)})},us=(e,t,n,r=os)=>{const s=Dt(t);((e,t,n,r=new os(e))=>{Ks(t,e=>{e.local=!1;let t=!1;const n=e.doc,s=n.store,i=((e,t,n)=>{const r=[];let s=$e(n.keys()).sort((e,t)=>e-t);if(0===s.length)return null;const i=()=>{if(0===s.length)return null;let e=n.get(s[s.length-1]);for(;e.refs.length===e.i;){if(s.pop(),!(s.length>0))return null;e=n.get(s[s.length-1])}return e};let o=i();if(null===o)return null;const l=new Os,a=new Map,c=(e,t)=>{const n=a.get(e);(null==n||n>t)&&a.set(e,t)};let d=o.refs[o.i++];const h=new Map,u=()=>{for(const e of r){const t=e.id.client,r=n.get(t);r?(r.i--,l.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):l.clients.set(t,[e]),s=s.filter(e=>e!==t)}r.length=0};for(;;){if(d.constructor!==Io){const s=Me(h,d.id.client,()=>Rs(t,d.id.client))-d.id.clock;if(s<0)r.push(d),c(d.id.client,d.id.clock-1),u();else{const i=d.getMissing(e,t);if(null!==i){r.push(d);const e=n.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){d=e.refs[e.i++];continue}c(i,Rs(t,i)),u()}else(0===s||s<d.length)&&(d.integrate(e,s),h.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(null!==o&&o.i<o.refs.length)d=o.refs[o.i++];else{if(o=i(),null===o)break;d=o.refs[o.i++]}}if(l.clients.size>0){const e=new ds;return hs(e,l,new Map),dt(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,s,((e,t)=>{const n=Ae(),r=Rt(e.restDecoder);for(let s=0;s<r;s++){const r=Rt(e.restDecoder),s=new Array(r),i=e.readClient();let o=Rt(e.restDecoder);n.set(i,{i:0,refs:s});for(let n=0;n<r;n++){const r=e.readInfo();switch(31&r){case 0:{const t=e.readLen();s[n]=new lo(ws(i,o),t),o+=t;break}case 10:{const t=Rt(e.restDecoder);s[n]=new Io(ws(i,o),t),o+=t;break}default:{const l=!(192&r),a=new Oo(ws(i,o),null,128&~r?null:e.readLeftID(),null,64&~r?null:e.readRightID(),l?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!l||32&~r?null:e.readString(),$o(e,r));s[n]=a,o+=a.length}}}}return n})(r,n)),o=s.pendingStructs;if(o){for(const[e,n]of o.missing)if(n<Rs(s,e)){t=!0;break}if(i){for(const[e,t]of i.missing){const n=o.missing.get(e);(null==n||n>t)&&o.missing.set(e,t)}o.update=ni([o.update,i.update])}}else s.pendingStructs=i;const l=ns(r,e,s);if(s.pendingDs){const t=new os(Dt(s.pendingDs));Rt(t.restDecoder);const n=ns(t,e,s);s.pendingDs=l&&n?ni([l,n]):l||n}else s.pendingDs=l;if(t){const t=s.pendingStructs.update;s.pendingStructs=null,us(e.doc,t)}},n,!1)})(s,e,n,new r(s))},ps=class{constructor(){this.l=[]}},ms=()=>new ps,fs=(e,t)=>e.l.push(t),gs=(e,t)=>{const n=e.l;n.length,e.l=n.filter(e=>t!==e),e.l.length},xs=(e,t,n)=>dn(e.l,[t,n]),bs=class{constructor(e,t){this.client=e,this.clock=t}},ys=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ws=(e,t)=>new bs(e,t),vs=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw At()},ks=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1},js=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},Ss=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},Cs=(e,t,n)=>{let r=null,s=null;return null===e._item?s=vs(e):r=ws(e._item.id.client,e._item.id.clock),new js(r,s,t,n)},Ns=(e,t,n=0)=>{let r=e._start;if(n<0){if(0===t)return Cs(e,null,n);t--}for(;null!==r;){if(!r.deleted&&r.countable){if(r.length>t)return Cs(e,ws(r.id.client,r.id.clock+t),n);t-=r.length}if(null===r.right&&n<0)return Cs(e,r.lastId,n);r=r.right}return Cs(e,null,n)},Es=(e,t,n=!0)=>{const r=t.store,s=e.item,i=e.type,o=e.tname,l=e.assoc;let a=null,c=0;if(null!==s){if(Rs(r,s.client)<=s.clock)return null;const e=n?Ao(r,s):((e,t)=>{const n=Ls(e,t);return{item:n,diff:t.clock-n.id.clock}})(r,s),t=e.item;if(!(t instanceof Oo))return null;if(a=t.parent,null===a._item||!a._item.deleted){c=t.deleted||!t.countable?0:e.diff+(l>=0?0:1);let n=t.left;for(;null!==n;)!n.deleted&&n.countable&&(c+=n.length),n=n.left}}else{if(null!==o)a=t.get(o);else{if(null===i)throw At();{if(Rs(r,i.client)<=i.clock)return null;const{item:e}=n?Ao(r,i):{item:Ls(r,i)};if(!(e instanceof Oo&&e.content instanceof Eo))return null;a=e.content.type}}c=l>=0?a._length:0}return((e,t,n=0)=>new Ss(e,t,n))(a,c,e.assoc)},As=class{constructor(e,t){this.ds=e,this.sv=t}},Ts=(e,t)=>new As(e,t),Ms=(Ts(Qr(),new Map),e=>Ts((e=>{const t=Qr();return e.clients.forEach((e,n)=>{const r=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const s=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;r.push(new Ur(s,i))}}r.length>0&&t.clients.set(n,r)}),t})(e.store),$s(e.store))),_s=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Gr(t.ds,e.id),Ds=(e,t)=>{const n=Me(e.meta,Ds,_e),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<Rs(r,n)&&Bs(e,ws(n,t))}),Kr(e,t.ds,e=>{}),n.add(t))},Os=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},$s=e=>{const t=new Map;return e.clients.forEach((e,n)=>{const r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},Rs=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const r=n[n.length-1];return r.id.clock+r.length},Is=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw At()}n.push(t)},Ps=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=ze(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=ze((n+r)/2)}throw At()},Ls=(e,t)=>{const n=e.clients.get(t.client);return n[Ps(n,t.clock)]},zs=(e,t,n)=>{const r=Ps(t,n),s=t[r];return s.id.clock<n&&s instanceof Oo?(t.splice(r+1,0,Mo(e,s,n-s.id.clock)),r+1):r},Bs=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[zs(e,n,t.clock)]},Fs=(e,t,n)=>{const r=t.clients.get(n.client),s=Ps(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==lo&&r.splice(s+1,0,Mo(e,i,n.clock-i.id.clock+1)),i},Vs=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,l=zs(e,t,n);do{o=t[l++],i<o.id.clock+o.length&&zs(e,t,i),s(o)}while(l<t.length&&t[l].id.clock<i)},Ws=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Jr,this.beforeState=$s(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},qs=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1})(t.afterState,(e,n)=>t.beforeState.get(n)!==e)||(Xr(t.deleteSet),((e,t)=>{hs(e,t.doc.store,t.beforeState)})(e,t),es(e,t.deleteSet),0)),Hs=(e,t,n)=>{const r=t._item;(null===r||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Me(e.changed,t,_e).add(n)},Us=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--s-1])n instanceof Oo&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);const i=t-s;return i&&e.splice(t+1-i,i),i},Js=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Xr(i),n.afterState=$s(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const e=[];n.changed.forEach((t,r)=>e.push(()=>{null!==r._item&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(null===r._item||!r._item.deleted)&&((t=t.filter(e=>null===e.target._item||!e.target._item.deleted)).forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{xs(r._dEH,t,n)}))}),e.push(()=>r.emit("afterTransaction",[n,r])),e.push(()=>{n._needFormattingCleanup&&Xi(n)})}),dn(e,[])}finally{r.gc&&((e,t,n)=>{for(const[r,s]of e.clients.entries()){const e=t.clients.get(r);for(let r=s.length-1;r>=0;r--){const i=s[r],o=i.clock+i.len;for(let r=Ps(e,i.clock),s=e[r];r<e.length&&s.id.clock<o;s=e[++r]){const s=e[r];if(i.clock+i.len<=s.id.clock)break;s instanceof Oo&&s.deleted&&!s.keep&&n(s)&&s.gc(t,!1)}}}})(i,s,r.gcFilter),((e,t)=>{e.clients.forEach((e,n)=>{const r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=Fe(r.length-1,1+Ps(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Us(r,e)}})})(i,s),n.afterState.forEach((e,t)=>{const r=n.beforeState.get(t)||0;if(r!==e){const e=s.clients.get(t),n=Ve(Ps(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Us(e,t)}});for(let e=o.length-1;e>=0;e--){const{client:t,clock:n}=o[e].id,r=s.clients.get(t),i=Ps(r,n);i+1<r.length&&Us(r,i+1)>1||i>0&&Us(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(Fr(Br,Pr,"[yjs] ",Lr,zr,"Changed the client-id because another client seems to be using it."),r.clientID=rs()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new as;qs(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new ds;qs(e,n)&&r.emit("updateV2",[e.toUint8Array(),n.origin,r,n])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=n;(l.size>0||c.size>0||a.size>0)&&(l.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),c.forEach(e=>r.subdocs.delete(e)),r.emit("subdocs",[{loaded:a,added:l,removed:c},r,n]),c.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):Js(e,t+1)}}},Ks=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new Ws(e,n,r),s.push(e._transaction),1===s.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===s[0];e._transaction=null,t&&Js(s,0)}}return o},Gs=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Xs=(e,t,n)=>{Kr(e,n.deletions,n=>{n instanceof Oo&&t.scope.some(t=>t===e.doc||ks(t,n))&&To(n,!1)})},Ys=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;Ks(s,n=>{for(;t.length>0&&null===e.currStackItem;){const r=s.store,o=t.pop(),l=new Set,a=[];let c=!1;Kr(n,o.insertions,e=>{if(e instanceof Oo){if(null!==e.redone){let{item:t,diff:s}=Ao(r,e.id);s>0&&(t=Bs(n,ws(t.id.client,t.id.clock+s))),e=t}!e.deleted&&i.some(t=>t===n.doc||ks(t,e))&&a.push(e)}}),Kr(n,o.deletions,e=>{e instanceof Oo&&i.some(t=>t===n.doc||ks(t,e))&&!Gr(o.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==Do(n,t,l,o.insertions,e.ignoreRemoteMapChanges,e)||c});for(let t=a.length-1;t>=0;t--){const r=a[t];e.deleteFilter(r)&&(r.delete(n),c=!0)}e.currStackItem=c?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);const o=e.currStackItem;if(null!=o){const t=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Zs=class extends Le{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:o=(Pe(e)?e[0].doc:e instanceof ss?e:e.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,s.add(this),this.trackedOrigins=s,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,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;const t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);const s=new Jr;e.afterState.forEach((t,n)=>{const r=e.beforeState.get(n)||0,i=t-r;i>0&&Zr(s,n,r,i)});const i=Gt();let o=!1;if(this.lastChange>0&&i-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){const t=r[r.length-1];t.deletions=Yr([t.deletions,e.deleteSet]),t.insertions=Yr([t.insertions,s])}else r.push(new Gs(e.deleteSet,s)),o=!0;t||n||(this.lastChange=i),Kr(e,e.deleteSet,t=>{t instanceof Oo&&this.scope.some(n=>n===e.doc||ks(n,t))&&To(t,!0)});const l=[{stackItem:r[r.length-1],origin:e.origin,type:t?"redo":"undo",changedParentTypes:e.changedParentTypes},this];o?this.emit("stack-item-added",l):this.emit("stack-item-updated",l)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const t=new Set(this.scope);(e=Pe(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof gi?e.doc!==this.doc:e!==this.doc)&&Vr("[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=>Xs(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Xs(n,this,e)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){let e;this.undoing=!0;try{e=Ys(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=Ys(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}},Qs=class{constructor(e,t){this.gen=function*(e){const t=Rt(e.restDecoder);for(let n=0;n<t;n++){const t=Rt(e.restDecoder),n=e.readClient();let r=Rt(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=Rt(e.restDecoder);yield new Io(ws(n,r),t),r+=t}else if(31&t){const s=!(192&t),i=new Oo(ws(n,r),null,128&~t?null:e.readLeftID(),null,64&~t?null:e.readRightID(),s?e.readParentInfo()?e.readString():e.readLeftID():null,!s||32&~t?null:e.readString(),$o(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new lo(ws(n,r),t),r+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Io);return this.curr}},ei=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ti=(e,t)=>{if(e.constructor===lo){const{client:n,clock:r}=e.id;return new lo(ws(n,r+t),e.length-t)}if(e.constructor===Io){const{client:n,clock:r}=e.id;return new Io(ws(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new Oo(ws(r,s+t),null,ws(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ni=(e,t=os,n=ds)=>{if(1===e.length)return e[0];const r=e.map(e=>new t(Dt(e)));let s=r.map(e=>new Qs(e,!0)),i=null;const o=new n,l=new ei(o);for(;s=s.filter(e=>null!==e.curr),s.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Io?1:-1:n}return t.curr.id.client-e.curr.id.client}),0!==s.length;){const e=s[0],t=e.curr.id.client;if(null!==i){let n=e.curr,r=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),r=!0;if(null===n||n.id.client!==t||r&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)si(l,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===Io)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{si(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Io(ws(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===Io?i.struct.length-=t:n=ti(n,t)),i.struct.mergeWith(n)||(si(l,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==Io;n=e.next())si(l,i.struct,i.offset),i={struct:n,offset:0}}return null!==i&&(si(l,i.struct,i.offset),i=null),ii(l),es(o,Yr(r.map(e=>ts(e)))),o.toUint8Array()},ri=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:lt(e.encoder.restEncoder)}),e.encoder.restEncoder=ot(),e.written=0)},si=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ri(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),dt(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},ii=e=>{ri(e);const t=e.encoder.restEncoder;dt(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];dt(t,r.written),ft(t,r.restEncoder)}},oi="You must not compute changes after the event-handler fired.",li=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=ai(this.currentTarget,this.target))}deletes(e){return Gr(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Nt(oi);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(null!==n){const r=t._map.get(n);let s,i;if(this.adds(r)){let e=r.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(r)){if(null===e||!this.deletes(e))return;s="delete",i=De(e.content.getContent())}else null!==e&&this.deletes(e)?(s="update",i=De(e.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=De(r.content.getContent())}e.set(n,{action:s,oldValue:i})}}),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(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw Nt(oi);const t=this.target,n=_e(),r=_e(),s=[];if(e={added:n,deleted:r,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&s.push(e)};for(let s=t._start;null!==s;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=s.length,r.add(s)):this.adds(s)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(s.content.getContent()),n.add(s)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=s.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}},ai=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&null!==r;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},ci=()=>{Vr("Invalid access: Add Yjs type to a document before reading data.")},di=0,hi=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=di++}},ui=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=di++},pi=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce((e,n)=>Be(t-e.index)<Be(t-n.index)?e:n);let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=di++})(n));null!==r.right&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;null!==r.left&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return null!==n&&Be(n.index-s)<r.parent.length/80?(ui(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return ui(r,t,n),r}{const r=new hi(t,n);return e.push(r),r}})(e._searchMarker,r,s)},mi=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let t=s.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(s.index-=t.length);if(null===t||!0===t.marker){e.splice(r,1);continue}s.p=t,t.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Ve(t,s.index+n))}},fi=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;Me(s,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;xs(r._eH,n,t)},gi=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ms(),this._dEH=ms(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Et()}clone(){throw Et()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){fs(this._eH,e)}observeDeep(e){fs(this._dEH,e)}unobserve(e){gs(this._eH,e)}unobserveDeep(e){gs(this._dEH,e)}toJSON(){}},xi=(e,t,n)=>{e.doc??ci(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;null!==i&&r>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)s.push(e[n]),r--;t=0}}i=i.right}return s},bi=e=>{e.doc??ci();const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},yi=(e,t)=>{const n=[];let r=e._start;for(;null!==r;){if(r.countable&&_s(r,t)){const e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},wi=(e,t)=>{let n=0,r=e._start;for(e.doc??ci();null!==r;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}r=r.right}},vi=(e,t)=>{const n=[];return wi(e,(r,s)=>{n.push(t(r,s,e))}),n},ki=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}const e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},ji=(e,t)=>{e.doc??ci();const n=pi(e,t);let r=e._start;for(null!==n&&(r=n.p,t-=n.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Si=(e,t,n,r)=>{let s=n;const i=e.doc,o=i.clientID,l=i.store,a=null===n?t._start:n.right;let c=[];const d=()=>{c.length>0&&(s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new xo(c)),s.integrate(e,0),c=[])};r.forEach(n=>{if(null===n)c.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(n);break;default:switch(d(),n.constructor){case Uint8Array:case ArrayBuffer:s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new ao(new Uint8Array(n))),s.integrate(e,0);break;case ss:s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new uo(n)),s.integrate(e,0);break;default:if(!(n instanceof gi))throw new Error("Unexpected content type in insert operation");s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new Eo(n)),s.integrate(e,0)}}}),d()},Ci=()=>Nt("Length exceeded!"),Ni=(e,t,n,r)=>{if(n>t._length)throw Ci();if(0===n)return t._searchMarker&&mi(t._searchMarker,n,r.length),Si(e,t,null,r);const s=n,i=pi(t,n);let o=t._start;for(null!==i&&(o=i.p,0===(n-=i.index)&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Bs(e,ws(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&mi(t._searchMarker,s,r.length),Si(e,t,o,r)},Ei=(e,t,n,r)=>{if(0===r)return;const s=n,i=r,o=pi(t,n);let l=t._start;for(null!==o&&(l=o.p,n-=o.index);null!==l&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&Bs(e,ws(l.id.client,l.id.clock+n)),n-=l.length);for(;r>0&&null!==l;)l.deleted||(r<l.length&&Bs(e,ws(l.id.client,l.id.clock+r)),l.delete(e),r-=l.length),l=l.right;if(r>0)throw Ci();t._searchMarker&&mi(t._searchMarker,s,-i+r)},Ai=(e,t,n)=>{const r=t._map.get(n);void 0!==r&&r.delete(e)},Ti=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let l;if(null==r)l=new xo([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new xo([r]);break;case Uint8Array:l=new ao(r);break;case ss:l=new uo(r);break;default:if(!(r instanceof gi))throw new Error("Unexpected content type");l=new Eo(r)}new Oo(ws(o,Rs(i.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Mi=(e,t)=>{e.doc??ci();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},_i=e=>{const t={};return e.doc??ci(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Di=(e,t)=>{e.doc??ci();const n=e._map.get(t);return void 0!==n&&!n.deleted},Oi=e=>{return e.doc??ci(),t=e._map.entries(),n=e=>!e[1].deleted,qr(()=>{let e;do{e=t.next()}while(!e.done&&!n(e.value));return e});var t,n},$i=class extends li{},Ri=class e extends gi{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const 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(){const t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}get length(){return this.doc??ci(),this._length}_callObserver(e,t){super._callObserver(e,t),fi(this,e,new $i(this,e))}insert(e,t){null!==this.doc?Ks(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Ks(this.doc,t=>{((e,t,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;Si(e,t,r,n)})(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?Ks(this.doc,n=>{Ei(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return ji(this,e)}toArray(){return bi(this)}slice(e=0,t=this.length){return xi(this,e,t)}toJSON(){return this.map(e=>e instanceof gi?e.toJSON():e)}map(e){return vi(this,e)}forEach(e){wi(this,e)}[Symbol.iterator](){return ki(this)}_write(e){e.writeTypeRef(wo)}},Ii=class extends li{constructor(e,t,n){super(e,t),this.keysChanged=n}},Pi=class e extends gi{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?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(){const t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof gi?e.clone():e)}),t}_callObserver(e,t){fi(this,e,new Ii(this,e,t))}toJSON(){this.doc??ci();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const r=t.content.getContent()[t.length-1];e[n]=r instanceof gi?r.toJSON():r}}),e}get size(){return[...Oi(this)].length}keys(){return Hr(Oi(this),e=>e[0])}values(){return Hr(Oi(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Hr(Oi(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ci(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Mi(this,e)}has(e){return Di(this,e)}clear(){null!==this.doc?Ks(this.doc,e=>{this.forEach(function(t,n,r){Ai(e,r,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(vo)}},Li=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||sn(e)===sn(t)&&on(e,(e,n)=>(void 0!==e||ln(t,n))&&tn(t[n],e)))(e,t),zi=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){null===this.right&&At(),this.right.content.constructor===mo?this.right.deleted||Wi(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Bi=(e,t,n)=>{for(;null!==t.right&&n>0;)t.right.content.constructor===mo?t.right.deleted||Wi(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&Bs(e,ws(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},Fi=(e,t,n,r)=>{const s=new Map,i=r?pi(t,n):null;return i?Bi(e,new zi(i.p.left,i.p,i.index,s),n-i.index):Bi(e,new zi(null,t._start,0,s),n)},Vi=(e,t,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===mo&&Li(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=e.doc,i=s.clientID;r.forEach((r,o)=>{const l=n.left,a=n.right,c=new Oo(ws(i,Rs(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new mo(o,r));c.integrate(e,0),n.right=c,n.forward()})},Wi=(e,t)=>{const{key:n,value:r}=t;null===r?e.delete(n):e.set(n,r)},qi=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===mo&&Li(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Hi=(e,t,n,r)=>{const s=e.doc,i=s.clientID,o=new Map;for(const l in r){const a=r[l],c=n.currentAttributes.get(l)??null;if(!Li(c,a)){o.set(l,c);const{left:r,right:d}=n;n.right=new Oo(ws(i,Rs(s.store,i)),r,r&&r.lastId,d,d&&d.id,t,null,new mo(l,a)),n.right.integrate(e,0),n.forward()}}return o},Ui=(e,t,n,r,s)=>{n.currentAttributes.forEach((e,t)=>{void 0===s[t]&&(s[t]=null)});const i=e.doc,o=i.clientID;qi(n,s);const l=Hi(e,t,n,s),a=r.constructor===String?new bo(r):r instanceof gi?new Eo(r):new po(r);let{left:c,right:d,index:h}=n;t._searchMarker&&mi(t._searchMarker,n.index,a.getLength()),d=new Oo(ws(o,Rs(i.store,o)),c,c&&c.lastId,d,d&&d.id,t,null,a),d.integrate(e,0),n.right=d,n.index=h,n.forward(),Vi(e,t,n,l)},Ji=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;qi(n,s);const l=Hi(e,t,n,s);e:for(;null!==n.right&&(r>0||l.size>0&&(n.right.deleted||n.right.content.constructor===mo));){if(!n.right.deleted)switch(n.right.content.constructor){case mo:{const{key:t,value:i}=n.right.content,o=s[t];if(void 0!==o){if(Li(o,i))l.delete(t);else{if(0===r)break e;l.set(t,i)}n.right.delete(e)}else n.currentAttributes.set(t,i);break}default:r<n.right.length&&Bs(e,ws(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let s="";for(;r>0;r--)s+="\n";n.right=new Oo(ws(o,Rs(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new bo(s)),n.right.integrate(e,0),n.forward()}Vi(e,t,n,l)},Ki=(e,t,n,r,s)=>{let i=t;const o=Ae();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===mo){const e=i.content;o.set(e.key,e)}i=i.right}let l=0,a=!1;for(;t!==i;){if(n===t&&(a=!0),!t.deleted){const n=t.content;switch(n.constructor){case mo:{const{key:i,value:c}=n,d=r.get(i)??null;o.get(i)===n&&d!==c||(t.delete(e),l++,a||(s.get(i)??null)!==c||d===c||(null===d?s.delete(i):s.set(i,d))),a||t.deleted||Wi(s,n);break}}}t=t.right}return l},Gi=e=>{let t=0;return Ks(e.doc,n=>{let r=e._start,s=e._start,i=Ae();const o=Te(i);for(;s;)!1===s.deleted&&(s.content.constructor===mo?Wi(o,s.content):(t+=Ki(n,r,s,i,o),i=Te(o),r=s)),s=s.right}),t},Xi=e=>{const t=new Set,n=e.doc;for(const[r,s]of e.afterState.entries()){const i=e.beforeState.get(r)||0;s!==i&&Vs(e,n.store.clients.get(r),i,s,e=>{e.deleted||e.content.constructor!==mo||e.constructor===lo||t.add(e.parent)})}Ks(n,n=>{Kr(e,e.deleteSet,e=>{if(e instanceof lo||!e.parent._hasFormatting||t.has(e.parent))return;const r=e.parent;e.content.constructor===mo?t.add(r):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===mo){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}})(n,e)});for(const e of t)Gi(e)})},Yi=(e,t,n)=>{const r=n,s=Te(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case Eo:case po:case bo:n<t.right.length&&Bs(e,ws(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&Ki(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&mi(o._searchMarker,t.index,-r+n),t},Zi=class extends li{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];Ks(e,e=>{const n=new Map,r=new Map;let s=this.target._start,i=null;const o={};let l="",a=0,c=0;const d=()=>{if(null!==i){let e=null;switch(i){case"delete":c>0&&(e={delete:c}),c=0;break;case"insert":("object"==typeof l||l.length>0)&&(e={insert:l},n.size>0&&(e.attributes={},n.forEach((t,n)=>{null!==t&&(e.attributes[n]=t)}))),l="";break;case"retain":a>0&&(e={retain:a},(e=>{for(const t in e)return!1;return!0})(o)||(e.attributes=nn({},o))),a=0}e&&t.push(e),i=null}};for(;null!==s;){switch(s.content.constructor){case Eo:case po:this.adds(s)?this.deletes(s)||(d(),i="insert",l=s.content.getContent()[0],d()):this.deletes(s)?("delete"!==i&&(d(),i="delete"),c+=1):s.deleted||("retain"!==i&&(d(),i="retain"),a+=1);break;case bo:this.adds(s)?this.deletes(s)||("insert"!==i&&(d(),i="insert"),l+=s.content.str):this.deletes(s)?("delete"!==i&&(d(),i="delete"),c+=s.length):s.deleted||("retain"!==i&&(d(),i="retain"),a+=s.length);break;case mo:{const{key:t,value:l}=s.content;if(this.adds(s))this.deletes(s)||(Li(n.get(t)??null,l)?null!==l&&s.delete(e):("retain"===i&&d(),Li(l,r.get(t)??null)?delete o[t]:o[t]=l));else if(this.deletes(s)){r.set(t,l);const e=n.get(t)??null;Li(e,l)||("retain"===i&&d(),o[t]=e)}else if(!s.deleted){r.set(t,l);const n=o[t];void 0!==n&&(Li(n,l)?null!==n&&s.delete(e):("retain"===i&&d(),null===l?delete o[t]:o[t]=l))}s.deleted||("insert"===i&&d(),Wi(n,s.content));break}}s=s.right}for(d();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}}),this._delta=t}return this._delta}},Qi=class e extends gi{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ci(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(au){}this._pending=null}_copy(){return new e}clone(){const t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);const n=new Zi(this,e,t);fi(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ci();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===bo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Ks(this.doc,n=>{const r=new zi(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const i=e[s];if(void 0!==i.insert){const o=t||"string"!=typeof i.insert||s!==e.length-1||null!==r.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&Ui(n,this,r,o,i.attributes||{})}else void 0!==i.retain?Ji(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&Yi(n,r,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??ci();const r=[],s=new Map,i=this.doc;let o="",l=this._start;function a(){if(o.length>0){const e={};let t=!1;s.forEach((n,r)=>{t=!0,e[r]=n});const n={insert:o};t&&(n.attributes=e),r.push(n),o=""}}const c=()=>{for(;null!==l;){if(_s(l,e)||void 0!==t&&_s(l,t))switch(l.content.constructor){case bo:{const r=s.get("ychange");void 0===e||_s(l,e)?void 0===t||_s(l,t)?void 0!==r&&(a(),s.delete("ychange")):void 0!==r&&r.user===l.id.client&&"added"===r.type||(a(),s.set("ychange",n?n("added",l.id):{type:"added"})):void 0!==r&&r.user===l.id.client&&"removed"===r.type||(a(),s.set("ychange",n?n("removed",l.id):{type:"removed"})),o+=l.content.str;break}case Eo:case po:{a();const e={insert:l.content.getContent()[0]};if(s.size>0){const t={};e.attributes=t,s.forEach((e,n)=>{t[n]=e})}r.push(e);break}case mo:_s(l,e)&&(a(),Wi(s,l.content))}l=l.right}a()};return e||t?Ks(i,n=>{e&&Ds(n,e),t&&Ds(n,t),c()},"cleanup"):c(),r}insert(e,t,n){if(t.length<=0)return;const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!n);n||(n={},s.currentAttributes.forEach((e,t)=>{n[t]=e})),Ui(r,this,s,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!n);Ui(r,this,s,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(0===t)return;const n=this.doc;null!==n?Ks(n,n=>{Yi(n,Fi(n,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(0===t)return;const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!1);null!==s.right&&Ji(r,this,s,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Mi(this,e)}getAttributes(){return _i(this)}_write(e){e.writeTypeRef(ko)}},eo=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ci()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==no&&t.constructor!==to||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},to=class e extends gi{constructor(){super(),this._prelimContent=[]}get firstChild(){const 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(){const t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}get length(){return this.doc??ci(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new eo(this,e)}querySelector(e){e=e.toUpperCase();const t=new eo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new eo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){fi(this,e,new ro(this,t,e))}toString(){return vi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const r=e.createDocumentFragment();return void 0!==n&&n._createAssociation(r,this),wi(this,s=>{r.insertBefore(s.toDOM(e,t,n),null)}),r}insert(e,t){null!==this.doc?Ks(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Ks(this.doc,n=>{const r=e&&e instanceof gi?e._item:e;Si(n,this,r,t)});else{const n=this._prelimContent,r=null===e?0:n.findIndex(t=>t===e)+1;if(0===r&&null!==e)throw Nt("Reference item not found");n.splice(r,0,...t)}}delete(e,t=1){null!==this.doc?Ks(this.doc,n=>{Ei(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return bi(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ji(this,e)}slice(e=0,t=this.length){return xi(this,e,t)}forEach(e){wi(this,e)}_write(e){e.writeTypeRef(So)}},no=class e extends to{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const 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(){const t=new e(this.nodeName);return((e,t)=>{for(const n in e)t(e[n],n)})(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}toString(){const e=this.getAttributes(),t=[],n=[];for(const i in e)n.push(i);n.sort();const r=n.length;for(let i=0;i<r;i++){const r=n[i];t.push(r+'="'+e[r]+'"')}const s=this.nodeName.toLocaleLowerCase();return`<${s}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${s}>`}removeAttribute(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Mi(this,e)}hasAttribute(e){return Di(this,e)}getAttributes(e){return e?((e,t)=>{const n={};return this._map.forEach((e,r)=>{let s=e;for(;null!==s&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;null!==s&&_s(s,t)&&(n[r]=s.content.getContent()[s.length-1])}),n})(0,e):_i(this)}toDOM(e=document,t={},n){const r=e.createElement(this.nodeName),s=this.getAttributes();for(const i in s){const e=s[i];"string"==typeof e&&r.setAttribute(i,e)}return wi(this,s=>{r.appendChild(s.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(jo),e.writeKey(this.nodeName)}},ro=class extends li{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)})}},so=class e extends Pi{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){const t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){const r=t[this.hookName];let s;return s=void 0!==r?r.createDom(this):document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(Co),e.writeKey(this.hookName)}},io=class e extends Qi{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){const t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){const r=e.createTextNode(this.toString());return void 0!==n&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{const t=[];for(const r in e.attributes){const n=[];for(const t in e.attributes[r])n.push({key:t,value:e.attributes[r][t]});n.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:r,attrs:n})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n="";for(let r=0;r<t.length;r++){const e=t[r];n+=`<${e.nodeName}`;for(let t=0;t<e.attrs.length;t++){const r=e.attrs[t];n+=` ${r.key}="${r.value}"`}n+=">"}n+=e.insert;for(let r=t.length-1;r>=0;r--)n+=`</${t[r].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(No)}},oo=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Et()}mergeWith(e){return!1}write(e,t,n){throw Et()}integrate(e,t){throw Et()}},lo=class extends oo{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),Is(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},ao=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 Et()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},co=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){const n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Zr(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}},ho=(e,t)=>new ss({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),uo=class e{constructor(e){e._item,this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(ho(this.doc.guid,this.opts))}splice(e){throw Et()}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}},po=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 Et()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},mo=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 Et()}mergeWith(e){return!1}integrate(e,t){const 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}},fo=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){const 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){const n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}},go="development"===gn("node_env"),xo=class e{constructor(e){this.arr=e,go&&cn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){const 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){const n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},bo=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){const n=new e(this.str.slice(t));this.str=this.str.slice(0,t);const r=this.str.charCodeAt(t-1);return 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(0===t?this.str:this.str.slice(t))}getRef(){return 4}},yo=[e=>new Ri,e=>new Pi,e=>new Qi,e=>new no(e.readKey()),e=>new to,e=>new so(e.readKey()),e=>new io],wo=0,vo=1,ko=2,jo=3,So=4,Co=5,No=6,Eo=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 Et()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)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(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;null!==t;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Ao=(e,t)=>{let n,r=t,s=0;do{s>0&&(r=ws(r.client,r.clock+s)),n=Ls(e,r),s=r.clock-n.id.clock,r=n.redone}while(null!==r&&n instanceof Oo);return{item:n,diff:s}},To=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},Mo=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new Oo(ws(r,s+n),t,ws(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=ws(t.redone.client,t.redone.clock+n)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=n,i},_o=(e,t)=>Ie(e,e=>Gr(e.deletions,t)),Do=(e,t,n,r,s,i)=>{const o=e.doc,l=o.store,a=o.clientID,c=t.redone;if(null!==c)return Bs(e,c);let d,h=t.parent._item,u=null;if(null!==h&&!0===h.deleted){if(null===h.redone&&(!n.has(h)||null===Do(e,h,n,r,s,i)))return null;for(;null!==h.redone;)h=Bs(e,h.redone)}const p=null===h?t.parent:h.content.type;if(null===t.parentSub){for(u=t.left,d=t;null!==u;){let t=u;for(;null!==t&&t.parent._item!==h;)t=null===t.redone?null:Bs(e,t.redone);if(null!==t&&t.parent._item===h){u=t;break}u=u.left}for(;null!==d;){let t=d;for(;null!==t&&t.parent._item!==h;)t=null===t.redone?null:Bs(e,t.redone);if(null!==t&&t.parent._item===h){d=t;break}d=d.right}}else{if(d=null,t.right&&!s){for(u=t;null!==u&&null!==u.right&&(u.right.redone||Gr(r,u.right.id)||_o(i.undoStack,u.right.id)||_o(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=Bs(e,u.redone);if(u&&null!==u.right)return null}else u=p._map.get(t.parentSub)||null;null!==u&&u.parent._item!==h&&(u=p._map.get(t.parentSub)||null)}const m=ws(a,Rs(l,a)),f=new Oo(m,u,u&&u.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,To(f,!0),f.integrate(e,0),f},Oo=class e extends oo{constructor(e,t,n,r,s,i,o,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=s,this.parent=i,this.parentSub=o,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(e){(8&this.info)>0!==e&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>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>=Rs(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Rs(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===bs&&this.id.client!==this.parent.client&&this.parent.clock>=Rs(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Fs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Bs(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lo||this.right&&this.right.constructor===lo)this.parent=null;else if(this.parent){if(this.parent.constructor===bs){const e=Ls(n,this.parent);e.constructor===lo?this.parent=null:this.parent=e.content.type}}else 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);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Fs(e,e.doc.store,ws(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||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,n=this.left;if(null!==n)t=n.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const r=new Set,s=new Set;for(;null!==t&&t!==this.right;){if(s.add(t),r.add(t),ys(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,r.clear();else if(ys(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!s.has(Ls(e.doc.store,t.origin)))break;r.has(Ls(e.doc.store,t.origin))||(n=t,r.clear())}t=t.right}this.left=n}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Is(e.doc.store,this),this.content.integrate(e,this),Hs(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new lo(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:ws(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ys(e.origin,this.lastId)&&this.right===e&&ys(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),Zr(e.deleteSet,this.id.client,this.id.clock,this.length),Hs(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw At();this.content.gc(e),t?((e,t,n)=>{const r=e.clients.get(t.id.client);r[Ps(r,t.id.clock)]=n})(e,this,new lo(this.id,this.length)):this.content=new co(this.length)}write(e,t){const n=t>0?ws(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,s=this.parentSub,i=31&this.content.getRef()|(null===n?0:128)|(null===r?0:64)|(null===s?0:32);if(e.writeInfo(i),null!==n&&e.writeLeftID(n),null!==r&&e.writeRightID(r),null===n&&null===r){const t=this.parent;if(void 0!==t._item){const n=t._item;if(null===n){const n=vs(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===bs?(e.writeParentInfo(!1),e.writeLeftID(t)):At();null!==s&&e.writeString(s)}this.content.write(e,t)}},$o=(e,t)=>Ro[31&t](e),Ro=[()=>{At()},e=>new co(e.readLen()),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++){const t=e.readString();"undefined"===t?n.push(void 0):n.push(JSON.parse(t))}return new fo(n)},e=>new ao(e.readBuf()),e=>new bo(e.readString()),e=>new po(e.readJSON()),e=>new mo(e.readKey(),e.readJSON()),e=>new Eo(yo[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new xo(n)},e=>new uo(ho(e.readString(),e.readAny())),()=>{At()}],Io=class extends oo{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){At()}write(e,t){e.writeInfo(10),dt(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Po="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Lo="__ $YJS$ __";function zo(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let s=e.child(r),i=t.child(r);if(s!=i){if(!s.sameMarkup(i))return n;if(s.isText&&s.text!=i.text){let e=s.text,t=i.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Vo(e.charCodeAt(r-1))&&Fo(e.charCodeAt(r))&&n--,n}if(s.content.size||i.content.size){let e=zo(s.content,i.content,n+1);if(null!=e)return e}n+=s.nodeSize}else n+=s.nodeSize}}function Bo(e,t,n,r){for(let s=e.childCount,i=t.childCount;;){if(0==s||0==i)return s==i?null:{a:n,b:r};let o=e.child(--s),l=t.child(--i),a=o.nodeSize;if(o!=l){if(!o.sameMarkup(l))return{a:n,b:r};if(o.isText&&o.text!=l.text){let e=o.text,t=l.text,s=e.length,i=t.length;for(;s>0&&i>0&&e[s-1]==t[i-1];)s--,i--,n--,r--;return s&&i&&s<e.length&&Vo(e.charCodeAt(s-1))&&Fo(e.charCodeAt(s))&&(n++,r++),{a:n,b:r}}if(o.content.size||l.content.size){let e=Bo(o.content,l.content,n-1,r-1);if(e)return e}n-=a,r-=a}else n-=a,r-=a}}function Fo(e){return e>=56320&&e<57344}function Vo(e){return e>=55296&&e<56320}Po[Lo],Po[Lo]=!0;var Wo=class e{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,r=0,s){for(let i=0,o=0;o<t;i++){let l=this.content[i],a=o+l.nodeSize;if(a>e&&!1!==n(l,r+o,s||null,i)&&l.content.size){let s=o+1;l.nodesBetween(Math.max(0,e-s),Math.min(l.content.size,t-s),n,r+s)}o=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let s="",i=!0;return this.nodesBetween(e,t,(o,l)=>{let a=o.isText?o.text.slice(Math.max(e,l)-l,t-l):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&a||o.isTextblock)&&n&&(i?i=!1:s+=n),s+=a},0),s}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,s=this.content.slice(),i=0;for(n.isText&&n.sameMarkup(r)&&(s[s.length-1]=n.withText(n.text+r.text),i=1);i<t.content.length;i++)s.push(t.content[i]);return new e(s,this.size+t.size)}cut(t,n=this.size){if(0==t&&n==this.size)return this;let r=[],s=0;if(n>t)for(let e=0,i=0;i<n;e++){let o=this.content[e],l=i+o.nodeSize;l>t&&((i<t||l>n)&&(o=o.isText?o.cut(Math.max(0,t-i),Math.min(o.text.length,n-i)):o.cut(Math.max(0,t-i-1),Math.min(o.content.size,n-i-1))),r.push(o),s+=o.nodeSize),i=l}return new e(r,s)}cutByIndex(t,n){return t==n?e.empty:0==t&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let s=this.content.slice(),i=this.size+n.nodeSize-r.nodeSize;return s[t]=n,new e(s,i)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return zo(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Bo(this,e,t,n)}findIndex(e){if(0==e)return Ho(0,e);if(e==this.size)return Ho(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e)return r==e?Ho(t+1,r):Ho(t,n);n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let s=t[e];r+=s.nodeSize,e&&s.isText&&t[e-1].sameMarkup(s)?(n||(n=t.slice(0,e)),n[n.length-1]=s.withText(n[n.length-1].text+s.text)):n&&n.push(s)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};Wo.empty=new Wo([],0);var qo={index:0,offset:0};function Ho(e,t){return qo.index=e,qo.offset=t,qo}function Uo(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!Uo(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Uo(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Jo=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Uo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};Jo.none=[];var Ko=class extends Error{},Go=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Yo(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(Xo(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,s=n.openEnd||0;if("number"!=typeof r||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new e(Wo.fromJSON(t,n.content),r,s)}static maxOpen(t,n=!0){let r=0,s=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)s++;return new e(t,r,s)}};function Xo(e,t,n){let{index:r,offset:s}=e.findIndex(t),i=e.maybeChild(r),{index:o,offset:l}=e.findIndex(n);if(s==t||i.isText){if(l!=n&&!e.child(o).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return e.replaceChild(r,i.copy(Xo(i.content,t-s-1,n-s-1)))}function Yo(e,t,n,r,s,i){let{index:o,offset:l}=e.findIndex(t),a=e.maybeChild(o);if(l==t||a.isText)return i&&r<=0&&s<=0&&!i.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let c=Yo(a.content,t-l-1,n,0==o?r-1:0,o==e.childCount-1?s-1:0,a);return c&&e.replaceChild(o,a.copy(c))}Go.empty=new Go(Wo.empty,0,0);var Zo=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Qo(t,n);if(null==r.next)return e.empty;let s=el(r);r.next&&r.err("Unexpected trailing text");let i=function(e){let t=Object.create(null);return function n(r){let s=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<s.length;e++)s[e][0]==t&&(r=s[e][1]);ol(e,n).forEach(e=>{r||s.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)})})});let i=t[r.join(",")]=new Zo(r.indexOf(e.length-1)>-1);for(let e=0;e<s.length;e++){let r=s[e][1].sort(il);i.next.push({type:s[e][0],next:t[r.join(",")]||n(r)})}return i}(ol(e,0))}(function(e){let t=[[]];return s(function e(t,i){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,i)),[]);if("seq"!=t.type){if("star"==t.type){let o=n();return r(i,o),s(e(t.expr,o),o),[r(o)]}if("plus"==t.type){let o=n();return s(e(t.expr,i),o),s(e(t.expr,o),o),[r(o)]}if("opt"==t.type)return[r(i)].concat(e(t.expr,i));if("range"==t.type){let o=i;for(let r=0;r<t.min;r++){let r=n();s(e(t.expr,o),r),o=r}if(-1==t.max)s(e(t.expr,o),o);else for(let i=t.min;i<t.max;i++){let i=n();r(o,i),s(e(t.expr,o),i),o=i}return[r(o)]}if("name"==t.type)return[r(i,void 0,t.value)];throw new Error("Unknown expr type")}for(let r=0;;r++){let o=e(t.exprs[r],i);if(r==t.exprs.length-1)return o;s(o,i=n())}}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let s={term:r,to:n};return t[e].push(s),s}function s(e,t){e.forEach(e=>e.to=t)}}(s));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],s=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];i.push(n.name),!s||n.isText||n.hasRequiredAttrs()||(s=!1),-1==r.indexOf(o)&&r.push(o)}s&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(i,r),i}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let s=t;r&&s<n;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!t.isText&&!t.hasRequiredAttrs())return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function s(i,o){let l=i.matchFragment(e,n);if(l&&(!t||l.validEnd))return Wo.from(o.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==r.indexOf(n)){r.push(n);let e=s(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),s=r.match;if(s.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<s.next.length;e++){let{type:i,next:o}=s.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||r.type&&!o.validEnd||(n.push({match:i.contentMatch,type:i,via:r}),t[i.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map((t,n)=>{let r=n+(t.validEnd?"*":" ")+" ";for(let s=0;s<t.next.length;s++)r+=(s?", ":"")+t.next[s].type.name+"->"+e.indexOf(t.next[s].next);return r}).join("\n")}};Zo.empty=new Zo(!0);var Qo=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function el(e){let t=[];do{t.push(tl(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function tl(e){let t=[];do{t.push(nl(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function nl(e){let t=function(e){if(e.eat("(")){let t=el(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let s=[];for(let i in n){let e=n[i];e.isInGroup(t)&&s.push(e)}return 0==s.length&&e.err("No node type or group '"+t+"' found"),s}(e,e.next).map(t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t}));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(e);for(;;)if(e.eat("+"))t={type:"plus",expr:t};else if(e.eat("*"))t={type:"star",expr:t};else if(e.eat("?"))t={type:"opt",expr:t};else{if(!e.eat("{"))break;t=sl(e,t)}return t}function rl(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function sl(e,t){let n=rl(e),r=n;return e.eat(",")&&(r="}"!=e.next?rl(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function il(e,t){return t-e}function ol(e,t){let n=[];return function t(r){let s=e[r];if(1==s.length&&!s[0].term)return t(s[0].to);n.push(r);for(let e=0;e<s.length;e++){let{term:r,to:i}=s[e];r||-1!=n.indexOf(i)||t(i)}}(t),n.sort(il)}var ll=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new pl(this,t,!1);return n.addAll(e,Jo.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new pl(this,t,!0);return n.addAll(e,Jo.none,t.from,t.to),Go.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(ml(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let r=this.styles[s],i=r.style;if(!(0!=i.indexOf(e)||r.context&&!n.matchesContext(r.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let r in e.marks){let t=e.marks[r].spec.parseDOM;t&&t.forEach(e=>{n(e=fl(e)),e.mark||e.ignore||e.clearMark||(e.mark=r)})}for(let r in e.nodes){let t=e.nodes[r].spec.parseDOM;t&&t.forEach(e=>{n(e=fl(e)),e.node||e.ignore||e.mark||(e.node=r)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},al={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},cl={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},dl={ol:!0,ul:!0};function hl(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}var ul=class{constructor(e,t,n,r,s,i){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=i,this.content=[],this.activeMarks=Jo.none,this.match=s||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Wo.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=Wo.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Wo.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!al.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},pl=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r,s=t.topNode,i=hl(null,t.preserveWhitespace,0)|(n?4:0);r=s?new ul(s.type,s.attrs,Jo.none,!0,t.topMatch||s.type.contentMatch,i):new ul(n?null:e.schema.topNodeType,null,Jo.none,!0,null,i),this.nodes=[r],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,s=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:i}=this.parser;if("full"===s||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if("full"===s)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],s=e.previousSibling;(!t||s&&"BR"==s.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,s=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,o=e.nodeName.toLowerCase();dl.hasOwnProperty(o)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&dl.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:cl.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,r=this.needsBlock;if(al.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),n=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(s),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=r}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let e=this.parser.matchedStyles[r],s=n.getPropertyValue(e);if(s)for(let n;;){let r=this.parser.matchStyle(e,s,this,n);if(!r)break;if(r.ignore)return null;if(t=r.clearMark?t.filter(e=>!r.clearMark(e)):t.concat(this.parser.schema.marks[r.mark].create(r.attrs)),!1!==r.consuming)break;n=r}}return t}addElementByRule(e,t,n,r){let s,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(s=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;"string"==typeof t.contentElement?r=e.querySelector(t.contentElement):"function"==typeof t.contentElement?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}s&&this.sync(o)&&this.open--}addAll(e,t,n,r){let s=n||0;for(let i=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];i!=o;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,t);this.findAtPoint(e,s)}findPlace(e,t,n){let r,s;for(let i=this.open,o=0;i>=0;i--){let t=this.nodes[i],l=t.findWrapping(e);if(l&&(!r||r.length>l.length+o)&&(r=l,s=t,!l.length))break;if(t.solid){if(n)break;o+=2}}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=Jo.none;for(let s of r.concat(e.marks))(t.type?t.type.allowsMarkType(s.type):gl(s.type,e.type))&&(n=s.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,r)),s}enterInner(e,t,n,r=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let o=hl(e,s,i.options);4&i.options&&0==i.content.length&&(o|=4);let l=Jo.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):gl(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new ul(e,t,l,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=1)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),s=-(n?n.depth+1:0)+(r?0:1),i=(e,o)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;o>=s;o--)if(i(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=s?n.node(o-s).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;o--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}};function ml(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function fl(e){let t={};for(let n in e)t[n]=e[n];return t}function gl(e,t){let n=t.schema.nodes;for(let r in n){let s=n[r];if(!s.allowsMarkType(e))continue;let i=[],o=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:s}=e.edge(n);if(r==t)return!0;if(i.indexOf(s)<0&&o(s))return!0}};if(o(s.contentMatch))return!0}}var xl=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=yl(t).createDocumentFragment());let r=n,s=[];return e.forEach(e=>{if(s.length||e.marks.length){let n=0,i=0;for(;n<s.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(s[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<s.length;)r=s.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],o=this.serializeMark(n,e.isInline,t);o&&(s.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return yl(t).createTextNode(e.text);let{dom:n,contentDOM:r}=vl(yl(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&vl(yl(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:vl(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=bl(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return bl(e.marks)}};function bl(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function yl(e){return e.document||window.document}var wl=new WeakMap;function vl(e,t,n,r){if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let s,i=t[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=function(e){let t=wl.get(e);return void 0===t&&wl.set(e,t=function(e){let t=null;return function e(n){if(n&&"object"==typeof n)if(Array.isArray(n))if("string"==typeof n[0])t||(t=[]),t.push(n);else for(let t=0;t<n.length;t++)e(n[t]);else for(let t in n)e(n[t])}(e),t}(e)),t}(r))&&s.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let h=d;h<t.length;h++){let s=t[h];if(0===s){if(h<t.length-1||h>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}if("string"==typeof s)a.appendChild(e.createTextNode(s));else{let{dom:t,contentDOM:i}=vl(e,s,n,r);if(a.appendChild(t),i){if(o)throw new RangeError("Multiple content holes");o=i}}}return{dom:a,contentDOM:o}}var kl=Math.pow(2,16);function jl(e,t){return e+t*kl}function Sl(e){return 65535&e}var Cl=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}},Nl=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=Sl(e);if(!this.inverted)for(let r=0;r<n;r++)t+=this.ranges[3*r+2]-this.ranges[3*r+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/kl}(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let l=this.ranges[o]-(this.inverted?r:0);if(l>e)break;let a=this.ranges[o+s],c=this.ranges[o+i],d=l+a;if(e<=d){let s=l+r+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return s;let i=e==(t<0?l:d)?null:jl(o/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new Cl(s,h,i)}r+=c-a}return n?e+r:new Cl(e+r,0,null)}touches(e,t){let n=0,r=Sl(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let t=this.ranges[o]-(this.inverted?n:0);if(t>e)break;let l=this.ranges[o+s];if(e<=t+l&&o==3*r)return!0;n+=this.ranges[o+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let i=this.ranges[r],o=i-(this.inverted?s:0),l=i+(this.inverted?0:s),a=this.ranges[r+t],c=this.ranges[r+n];e(o,o+a,l,l+c),s+=c-a}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};Nl.empty=new Nl([]);var El=Object.create(null),Al=class{getMap(){return Nl.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=El[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in El)throw new RangeError("Duplicate use of step JSON ID "+e);return El[e]=t,t.prototype.jsonID=e,t}},Tl=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,s){try{return e.ok(t.replace(n,r,s))}catch(au){if(au instanceof Ko)return e.fail(au.message);throw au}}};function Ml(e,t,n){let r=[];for(let s=0;s<e.childCount;s++){let i=e.child(s);i.content.size&&(i=i.copy(Ml(i.content,t,i))),i.isInline&&(i=t(i,n,s)),r.push(i)}return Wo.fromArray(r)}var _l=class e extends Al{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),s=new Go(Ml(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,r),t.openStart,t.openEnd);return Tl.fromReplace(e,this.from,this.to,s)}invert(){return new Dl(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new e(n.from,n.to,t.markFromJSON(n.mark))}};Al.jsonID("addMark",_l);var Dl=class e extends Al{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Go(Ml(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Tl.fromReplace(e,this.from,this.to,n)}invert(){return new _l(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new e(n.from,n.to,t.markFromJSON(n.mark))}};Al.jsonID("removeMark",Dl);var Ol=class e extends Al{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(n),0,t.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new $l(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if("number"!=typeof n.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new e(n.pos,t.markFromJSON(n.mark))}};Al.jsonID("addNodeMark",Ol);var $l=class e extends Al{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Ol(this.pos,this.mark):this}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if("number"!=typeof n.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new e(n.pos,t.markFromJSON(n.mark))}};Al.jsonID("removeNodeMark",$l);var Rl=class e extends Al{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Pl(e,this.from,this.to)?Tl.fail("Structure replace would overwrite content"):Tl.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Nl([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.to,-1),r=this.from==this.to&&e.MAP_BIAS<0?n:t.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new e(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let n=this.slice.size+t.slice.size==0?Go.empty:new Go(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}}{let n=this.slice.size+t.slice.size==0?Go.empty:new Go(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new e(n.from,n.to,Go.fromJSON(t,n.slice),!!n.structure)}};Rl.MAP_BIAS=1,Al.jsonID("replace",Rl);var Il=class e extends Al{constructor(e,t,n,r,s,i,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=s,this.insert=i,this.structure=o}apply(e){if(this.structure&&(Pl(e,this.from,this.gapFrom)||Pl(e,this.gapTo,this.to)))return Tl.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Tl.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Tl.fromReplace(e,this.from,this.to,n):Tl.fail("Content does not fit in gap")}getMap(){return new Nl([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),s=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||s<n.pos||i>r.pos?null:new e(n.pos,r.pos,s,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to||"number"!=typeof n.gapFrom||"number"!=typeof n.gapTo||"number"!=typeof n.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new e(n.from,n.to,n.gapFrom,n.gapTo,Go.fromJSON(t,n.slice),n.insert,!!n.structure)}};function Pl(e,t,n){let r=e.resolve(t),s=n-t,i=r.depth;for(;s>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,s--;if(s>0){let e=r.node(i).maybeChild(r.indexAfter(i));for(;s>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,s--}}return!1}Al.jsonID("replaceAround",Il),Al.jsonID("attr",class e extends Al{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(r),0,t.isLeaf?0:1))}getMap(){return Nl.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if("number"!=typeof n.pos||"string"!=typeof n.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new e(n.pos,n.attr,n.value)}}),Al.jsonID("docAttr",class e extends Al{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return Tl.ok(n)}getMap(){return Nl.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,n){if("string"!=typeof n.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new e(n.attr,n.value)}});var Ll=Error;((Ll=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype)).constructor=Ll,Ll.prototype.name="TransformError";var zl=Object.create(null),Bl=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Fl(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=Go.empty){let n=t.content.lastChild,r=null;for(let o=0;o<t.openEnd;o++)r=n,n=n.lastChild;let s=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(s);e.replaceRange(c.map(l.pos),c.map(a.pos),o?Go.empty:t),0==o&&Yl(e,s,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:i,$to:o}=r[s],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(o.pos);s?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),Yl(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new ql(e):Xl(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let s=e.depth-1;s>=0;s--){let r=t<0?Xl(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Xl(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Kl(e.node(0))}static atStart(e){return Xl(e,e,0,0,1)||new Kl(e)}static atEnd(e){return Xl(e,e,e.content.size,e.childCount,-1)||new Kl(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=zl[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in zl)throw new RangeError("Duplicate use of selection JSON ID "+e);return zl[e]=t,t.prototype.jsonID=e,t}getBookmark(){return ql.between(this.$anchor,this.$head).getBookmark()}};Bl.prototype.visible=!0;var Fl=class{constructor(e,t){this.$from=e,this.$to=t}},Vl=!1;function Wl(e){Vl||e.parent.inlineContent||(Vl=!0)}var ql=class e extends Bl{constructor(e,t=e){Wl(e),Wl(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return Bl.near(r);let s=t.resolve(n.map(this.anchor));return new e(s.parent.inlineContent?s:r,r)}replace(e,t=Go.empty){if(super.replace(e,t),t==Go.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Hl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if("number"!=typeof n.anchor||"number"!=typeof n.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let s=t.pos-n.pos;if(r&&!s||(r=s>=0?1:-1),!n.parent.inlineContent){let e=Bl.findFrom(n,r,!0)||Bl.findFrom(n,-r,!0);if(!e)return Bl.near(n,r);n=e.$head}return t.parent.inlineContent||(0==s||(t=(Bl.findFrom(t,-r,!0)||Bl.findFrom(t,r,!0)).$anchor).pos<n.pos!=s<0)&&(t=n),new e(t,n)}};Bl.jsonID("text",ql);var Hl=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return ql.between(e.resolve(this.anchor),e.resolve(this.head))}},Ul=class e extends Bl{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:s}=n.mapResult(this.anchor),i=t.resolve(s);return r?Bl.near(i):new e(i)}content(){return new Go(Wo.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Jl(this.anchor)}static fromJSON(t,n){if("number"!=typeof n.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}};Ul.prototype.visible=!1,Bl.jsonID("node",Ul);var Jl=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Hl(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&Ul.isSelectable(n)?new Ul(t):Bl.near(t)}},Kl=class e extends Bl{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Go.empty){if(t==Go.empty){e.delete(0,e.doc.content.size);let t=Bl.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return Gl}};Bl.jsonID("all",Kl);var Gl={map(){return this},resolve:e=>new Kl(e)};function Xl(e,t,n,r,s,i=!1){if(t.inlineContent)return ql.create(e,n);for(let o=r-(s>0?0:1);s>0?o<t.childCount:o>=0;o+=s){let r=t.child(o);if(r.isAtom){if(!i&&Ul.isSelectable(r))return Ul.create(e,n-(s<0?r.nodeSize:0))}else{let t=Xl(e,r,n+s,s<0?r.childCount:0,s,i);if(t)return t}n+=r.nodeSize*s}return null}function Yl(e,t,n){let r=e.steps.length-1;if(r<t)return;let s,i=e.steps[r];(i instanceof Rl||i instanceof Il)&&(e.mapping.maps[r].forEach((e,t,n,r)=>{s??=r}),e.setSelection(Bl.near(e.doc.resolve(s),n)))}function Zl(e,t){return t&&e?e.bind(t):e}var Ql=class{constructor(e,t,n){this.name=e,this.init=Zl(t.init,n),this.apply=Zl(t.apply,n)}};function ea(e,t,n){for(let r in e){let s=e[r];s instanceof Function?s=s.bind(t):"handleDOMEvents"==r&&(s=ea(s,t,{})),n[r]=s}return n}new Ql("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Ql("selection",{init:(e,t)=>e.selection||Bl.atStart(t.doc),apply:e=>e.selection}),new Ql("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new Ql("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});var ta=class{constructor(e){this.spec=e,this.props={},e.props&&ea(e.props,this,this.props),this.key=e.key?e.key.key:ra("plugin")}getState(e){return e[this.key]}},na=Object.create(null);function ra(e){return e in na?e+"$"+ ++na[e]:(na[e]=0,e+"$")}var sa=class{constructor(e="key"){this.key=ra(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},ia=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},oa=function(e,t,n,r){return n&&(aa(e,t,n,r,-1)||aa(e,t,n,r,1))},la=/^(img|br|input|textarea|hr)$/i;function aa(e,t,n,r,s){for(var i;;){if(e==n&&t==r)return!0;if(t==(s<0?0:ca(e))){let n=e.parentNode;if(!n||1!=n.nodeType||da(e)||la.test(e.nodeName)||"false"==e.contentEditable)return!1;t=ia(e)+(s<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(s<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=s}else e=n,t=s<0?ca(e):0}}}}function ca(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function da(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var ha=function(e){return e.focusNode&&oa(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ua(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}var pa="undefined"!=typeof navigator?navigator:null,ma="undefined"!=typeof document?document:null,fa=pa&&pa.userAgent||"",ga=/Edge\/(\d+)/.exec(fa),xa=/MSIE \d/.exec(fa),ba=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(fa),ya=!!(xa||ba||ga),wa=xa?document.documentMode:ba?+ba[1]:ga?+ga[1]:0,va=!ya&&/gecko\/(\d+)/i.test(fa);va&&(/Firefox\/(\d+)/.exec(fa)||[0,0])[1];var ka=!ya&&/Chrome\/(\d+)/.exec(fa),ja=!!ka,Sa=ka?+ka[1]:0,Ca=!ya&&!!pa&&/Apple Computer/.test(pa.vendor),Na=Ca&&(/Mobile\/\w+/.test(fa)||!!pa&&pa.maxTouchPoints>2),Ea=Na||!!pa&&/Mac/.test(pa.platform),Aa=!!pa&&/Win/.test(pa.platform),Ta=/Android \d/.test(fa),Ma=!!ma&&"webkitFontSmoothing"in ma.documentElement.style,_a=Ma?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Da=function(e){e&&(this.nodeName=e)};function Oa(e){return e.editable?e.hasFocus():function(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function $a(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof Ul){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(za(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else za(e)}(e,n),!Oa(e))return;let r=e.input.mouseDown;if(!t&&ja&&r){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&oa(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)&&r.delaySelUpdate())return void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r="IMG"==n.nodeName;r?t.collapse(n.parentNode,ia(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&ya&&wa<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let r,s,{anchor:i,head:o}=n;!Ra||n instanceof ql||(n.$from.parent.inlineContent||(r=Ia(e,n.from)),n.empty||n.$from.parent.inlineContent||(s=Ia(e,n.to))),e.docView.setSelection(i,o,e,t),Ra&&(r&&La(r),s&&La(s)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,s=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==r&&n.anchorOffset==s||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{Oa(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}Da.prototype=Object.create(null),new Da;var Ra=Ca||ja&&Sa<63;function Ia(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),s=r<n.childNodes.length?n.childNodes[r]:null,i=r?n.childNodes[r-1]:null;if(Ca&&s&&"false"==s.contentEditable)return Pa(s);if(!(s&&"false"!=s.contentEditable||i&&"false"!=i.contentEditable)){if(s)return Pa(s);if(i)return Pa(i)}}function Pa(e){return e.contentEditable="true",Ca&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function La(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function za(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Ba(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||ql.between(t,n,r)}function Fa(e,t){let{$anchor:n,$head:r}=e.selection,s=t>0?n.max(r):n.min(r),i=s.parent.inlineContent?s.depth?e.doc.resolve(t>0?s.after():s.before()):null:s;return i&&Bl.findFrom(i,t)}function Va(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Wa(e,t,n){let r=e.state.selection;if(!(r instanceof ql)){if(r instanceof Ul&&r.node.isInline)return Va(e,new ql(t>0?r.$to:r.$from));{let n=Fa(e.state,t);return!!n&&Va(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=r,s=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+s.nodeSize*(t<0?-1:1));return Va(e,new ql(r.$anchor,i))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Fa(e.state,t);return!!(n&&n instanceof Ul)&&Va(e,n)}if(!(Ea&&n.indexOf("m")>-1)){let n,s=r.$head,i=s.textOffset?null:t<0?s.nodeBefore:s.nodeAfter;if(!i||i.isText)return!1;let o=t<0?s.pos-i.nodeSize:s.pos;return!!(i.isAtom||(n=e.docView.descAt(o))&&!n.contentDOM)&&(Ul.isSelectable(i)?Va(e,new Ul(t<0?e.state.doc.resolve(s.pos-i.nodeSize):s)):!!Ma&&Va(e,new ql(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}function qa(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Ha(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function Ua(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=!1;for(va&&1==n.nodeType&&r<qa(n)&&Ha(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(1!=n.nodeType)break;{let e=n.childNodes[r-1];if(Ha(e,-1))s=n,i=--r;else{if(3!=e.nodeType)break;n=e,r=n.nodeValue.length}}}else{if(Ja(n))break;{let t=n.previousSibling;for(;t&&Ha(t,-1);)s=n.parentNode,i=ia(t),t=t.previousSibling;if(t)n=t,r=qa(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}o?Ka(e,n,r):s&&Ka(e,s,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=qa(n);for(;;)if(r<o){if(1!=n.nodeType)break;if(!Ha(n.childNodes[r],1))break;s=n,i=++r}else{if(Ja(n))break;{let t=n.nextSibling;for(;t&&Ha(t,1);)s=t.parentNode,i=ia(t)+1,t=t.nextSibling;if(t)n=t,r=0,o=qa(n);else{if(n=n.parentNode,n==e.dom)break;r=o=0}}}s&&Ka(e,s,i)}(e)}function Ja(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Ka(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!da(e);)t=ia(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=r,n=0):(e=function(e,t){for(;e&&!t&&!da(e);)t=ia(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(ha(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:s}=e;setTimeout(()=>{e.state==s&&$a(e)},50)}function Ga(e,t){let n=e.state.doc.resolve(t);if(!ja&&!Aa&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),s=(n.top+n.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),s=(n.top+n.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Xa(e,t,n){let r=e.state.selection;if(r instanceof ql&&!r.empty||n.indexOf("s")>-1)return!1;if(Ea&&n.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Fa(e.state,t);if(n&&n instanceof Ul)return Va(e,n)}if(!s.parent.inlineContent){let n=t<0?s:i,o=r instanceof Kl?Bl.near(n,t):Bl.findFrom(n,t);return!!o&&Va(e,o)}return!1}function Ya(e,t){if(!(e.state.selection instanceof ql))return!0;let{$head:n,$anchor:r,empty:s}=e.state.selection;if(!n.sameParent(r))return!0;if(!s)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let r=e.state.tr;return t<0?r.delete(n.pos-i.nodeSize,n.pos):r.delete(n.pos,n.pos+i.nodeSize),e.dispatch(r),!0}return!1}function Za(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Qa(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:s,openEnd:i}=t;for(;s>1&&i>1&&1==r.childCount&&1==r.firstChild.childCount;){s--,i--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let o=e.someProp("clipboardSerializer")||xl.fromSchema(e.state.schema),l=ac(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=lc[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),h++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${s} ${i}${h?` -${h}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function ec(e,t,n,r,s){let i,o,l=s.parent.type.spec.code;if(!n&&!t)return null;let a=!!t&&(r||l||!n);if(a){if(e.someProp("transformPastedText",n=>{t=n(t,l||r,e)}),l)return o=new Go(Wo.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{o=t(o,e,!0)}),o;let n=e.someProp("clipboardTextParser",n=>n(t,s,r,e));if(n)o=n;else{let n=s.marks(),{schema:r}=e.state,o=xl.fromSchema(r);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,r=ac(),s=r.body,i=/<([a-z][^>\s]+)/i.exec(e);if((n=i&&lc[i[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),s.innerHTML=function(e){let t=window.trustedTypes;return t?(cc||(cc=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),cc.createHTML(e)):e}(e),n)for(let o=0;o<n.length;o++)s=s.querySelector(n[o])||s;for(let o=0;o<r.styleSheets.length;o++){let e=r.styleSheets[o];for(let t=0;t<e.rules.length;t++){let n=e.rules[t];if(n instanceof CSSStyleRule){let e=s.querySelectorAll(n.selectorText);for(let t=0;t<e.length;t++)e[t].style.cssText+=n.style.cssText}}}return s}(n),Ma&&function(e){let t=e.querySelectorAll(ja?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let r=t[n];1==r.childNodes.length&&" "==r.textContent&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),r)}}(i);let c=i&&i.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let h=+d[3];h>0;h--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||ll.fromSchema(e.state.schema)).parseSlice(i,{preserveWhitespace:!(!a&&!d),context:s,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||tc.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n,r=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(au){return e}let{content:s,openStart:i,openEnd:o}=e;for(let l=n.length-2;l>=0;l-=2){let e=r.nodes[n[l]];if(!e||e.hasRequiredAttrs())break;s=Wo.from(e.create(n[l+1],s)),i++,o++}return new Go(s,i,o)}(oc(o,+d[1],+d[2]),d[4]);else if(o=Go.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r,s=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=s.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&r.length&&rc(n,r,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=sc(i[i.length-1],r.length));let t=nc(e,n);i.push(t),s=s.matchType(t.type),r=n}}),i)return Wo.from(i)}return e}(o.content,s),!0),o.openStart||o.openEnd){let e=0,t=0;for(let n=o.content.firstChild;e<o.openStart&&!n.type.spec.isolating;e++,n=n.firstChild);for(let n=o.content.lastChild;t<o.openEnd&&!n.type.spec.isolating;t++,n=n.lastChild);o=oc(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,a)}),o}var tc=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function nc(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Wo.from(e));return e}function rc(e,t,n,r,s){if(s<e.length&&s<t.length&&e[s]==t[s]){let i=rc(e,t,n,r.lastChild,s+1);if(i)return r.copy(r.content.replaceChild(r.childCount-1,i));if(r.contentMatchAt(r.childCount).matchType(s==e.length-1?n.type:e[s+1]))return r.copy(r.content.append(Wo.from(nc(n,e,s+1))))}}function sc(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,sc(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Wo.empty,!0);return e.copy(n.append(r))}function ic(e,t,n,r,s,i){let o=t<0?e.firstChild:e.lastChild,l=o.content;return e.childCount>1&&(i=0),s<r-1&&(l=ic(l,t,n,r,s+1,i)),s>=n&&(l=t<0?o.contentMatchAt(0).fillBefore(l,i<=s).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(Wo.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(l))}function oc(e,t,n){return t<e.openStart&&(e=new Go(ic(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Go(ic(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var lc={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function ac(){return document.implementation.createHTMLDocument("title")}var cc=null,dc={},hc={};function uc(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function pc(e){return{left:e.clientX,top:e.clientY}}function mc(e,t,n,r,s){if(-1==r)return!1;let i=e.state.doc.resolve(r);for(let o=i.depth+1;o>0;o--)if(e.someProp(t,t=>o>i.depth?t(e,n,i.nodeAfter,i.before(o),s,!0):t(e,n,i.node(o),i.before(o),s,!1)))return!0;return!1}function fc(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}function gc(e,t,n,r){return mc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}function xc(e,t,n,r){return mc(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",n=>n(e,t,r))||function(e,t,n){if(0!=n.button)return!1;let r=bc(e,t,!0),s=e.state.doc;return!!r&&(fc(e,r,"pointer"),r instanceof ql&&s.eq(e.state.doc)&&(e.input.mouseDown=new jc(e,r)),!0)}(e,n,r)}function bc(e,t,n){let r=e.state.doc;if(-1==t)return r.inlineContent?ql.create(r,0,r.content.size):null;let s=r.resolve(t);for(let i=s.depth+1;i>0;i--){let e=i>s.depth?s.nodeAfter:s.node(i),t=s.before(i);if(e.inlineContent)return ql.create(r,t+1,t+1+e.content.size);if(n&&Ul.isSelectable(e))return Ul.create(r,t)}return null}function yc(e){return Ec(e)}hc.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!Sc(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!Ta||!ja||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Na||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||function(e,t){let n=t.keyCode,r=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||Ea&&72==n&&"c"==r)return Ya(e,-1)||Ua(e,-1);if(46==n&&!t.shiftKey||Ea&&68==n&&"c"==r)return Ya(e,1)||Ua(e,1);if(13==n||27==n)return!0;if(37==n||Ea&&66==n&&"c"==r){let t=37==n?"ltr"==Ga(e,e.state.selection.from)?-1:1:-1;return Wa(e,t,r)||Ua(e,t)}if(39==n||Ea&&70==n&&"c"==r){let t=39==n?"ltr"==Ga(e,e.state.selection.from)?1:-1:1;return Wa(e,t,r)||Ua(e,t)}return 38==n||Ea&&80==n&&"c"==r?Xa(e,-1,r)||Ua(e,-1):40==n||Ea&&78==n&&"c"==r?function(e){if(!Ca||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Za(e,n,"true"),setTimeout(()=>Za(e,n,"false"),20)}return!1}(e)||Xa(e,1,r)||Ua(e,1):r==(Ea?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():uc(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,ua(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},hc.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},hc.keypress=(e,t)=>{let n=t;if(Sc(e)||!n.charCode||n.ctrlKey&&!n.altKey||Ea&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof ql&&r.$from.sameParent(r.$to))){let t=String.fromCharCode(n.charCode),s=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,r.$from.pos,r.$to.pos,t,s))||e.dispatch(s()),n.preventDefault()}};var wc=Ea?"metaKey":"ctrlKey";dc.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=yc(e),s=Date.now(),i="singleClick";s-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}(n,e.input.lastClick)&&!n[wc]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:s,x:n.clientX,y:n.clientY,type:i,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(pc(n));o&&("singleClick"==i?e.input.mouseDown=new kc(e,o,n,!!r):("doubleClick"==i?gc:xc)(e,o.pos,o.inside,n)?n.preventDefault():uc(e,"pointer"))};var vc=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){0==e.buttons&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},kc=class extends vc{constructor(e,t,n,r){let s,i;if(super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[wc],this.allowDefault=n.shiftKey,t.inside>-1)s=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);s=n.parent,i=n.depth?n.before():0}const o=r?null:n.target,l=o?e.docView.nearestDesc(o,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;0==n.button&&(s.type.spec.draggable&&!1!==s.type.spec.selectable||a instanceof Ul&&a.from<=i&&a.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!va||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),uc(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||$a(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(pc(e))),this.updateAllowDefault(e),this.allowDefault||!t?uc(this.view,"pointer"):function(e,t,n,r,s){return mc(e,"handleClickOn",t,n,r)||e.someProp("handleClick",n=>n(e,t,r))||(s?function(e,t){if(-1==t)return!1;let n,r,s=e.state.selection;s instanceof Ul&&(n=s.node);let i=e.state.doc.resolve(t);for(let o=i.depth+1;o>0;o--){let e=o>i.depth?i.nodeAfter:i.node(o);if(Ul.isSelectable(e)){r=n&&s.$from.depth>0&&o>=s.$from.depth&&i.before(s.$from.depth+1)==s.$from.pos?i.before(s.$from.depth):i.before(o);break}}return null!=r&&(fc(e,Ul.create(e.state.doc,r),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&Ul.isSelectable(r))&&(fc(e,new Ul(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||Ca&&this.mightDrag&&!this.mightDrag.node.isAtom||ja&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(fc(this.view,Bl.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):uc(this.view,"pointer")}move(e){this.updateAllowDefault(e),uc(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return!!this.allowDefault&&(this.delayedSelectionSync=!0,!0)}},jc=class extends vc{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(0==e.buttons||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc))return void this.done();e.preventDefault(),uc(this.view,"pointer");let t=this.view.posAtCoords(pc(e)),n=t&&bc(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,s=this.startSelection,[i,o]=n.from<s.from?[s.to,n.from]:[s.from,n.to];fc(this.view,ql.create(r,i,o),"pointer")}};function Sc(e,t){return!!e.composing||!!(Ca&&Math.abs(Date.now()-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}dc.touchstart=e=>{e.input.lastTouch=Date.now(),yc(e),uc(e,"pointer")},dc.touchmove=e=>{e.input.lastTouch=Date.now(),uc(e,"pointer")},dc.contextmenu=e=>yc(e);var Cc=Ta?5e3:-1;function Nc(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Ec(e),t))}function Ec(e,t=!1){if(!(Ta&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),function(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}(e),t||e.docView&&e.docView.dirty){let n=function(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let s=e.docView.nearestDesc(n.focusNode),i=s&&0==s.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let l,a,c=r.resolve(o);if(ha(n)){for(l=o;s&&!s.node;)s=s.parent;let e=s.node;if(s&&e.isAtom&&Ul.isSelectable(e)&&s.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,s=t==ca(e);r||s;){if(e==n)return!0;let t=ia(e);if(!(e=e.parentNode))return!1;r=r&&0==t,s=s&&t==ca(e)}}(n.focusNode,n.focusOffset,s.dom))){let e=s.posBefore;a=new Ul(o==e?c:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,s=o;for(let r=0;r<n.rangeCount;r++){let i=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),s=Math.max(s,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,o]=s==e.state.selection.anchor?[s,t]:[t,s],c=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);return a||(a=Ba(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)),a}(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}hc.compositionstart=hc.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof ql&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ja&&Aa&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return 1==r.nodeType&&"false"==r.contentEditable}(e)))e.markCursor=e.state.storedMarks||n.marks(),Ec(e,!0),e.markCursor=null;else if(Ec(e,!t.selection.empty),va&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Nc(e,Cc)},hc.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Nc(e,20))};var Ac=ya&&wa<15||Na&&_a<604;function Tc(e,t,n,r,s){let i=ec(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,s,i||Go.empty)))return!0;if(!i)return!1;let o=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Mc(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}dc.copy=hc.cut=(e,t)=>{let n=t,r=e.state.selection,s="cut"==n.type;if(r.empty)return;let i=Ac?null:n.clipboardData,{dom:o,text:l}=Qa(e,r.content());i?(n.preventDefault(),i.clearData(),i.setData("text/html",o.innerHTML),i.setData("text/plain",l)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),s=document.createRange();s.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(s),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,o),s&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},hc.paste=(e,t)=>{let n=t;if(e.composing&&!Ta)return;let r=Ac?null:n.clipboardData,s=e.input.shiftKey&&45!=e.input.lastKeyCode;r&&Tc(e,Mc(r),r.getData("text/html"),s,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let s=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Tc(e,r.value,null,s,t):Tc(e,r.textContent,r.innerHTML,s,t)},50)}(e,n)};var _c=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Dc=Ea?"altKey":"ctrlKey";function Oc(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[Dc]}dc.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let s,i=e.state.selection,o=i.empty?null:e.posAtCoords(pc(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof Ul?i.to-1:i.to));else if(r&&r.mightDrag)s=Ul.create(e.state.doc,r.mightDrag.pos);else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(s=Ul.create(e.state.doc,t.posBefore))}let{dom:l,text:a,slice:c}=Qa(e,(s||e.state.selection).content());(!n.dataTransfer.files.length||!ja||Sa>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Ac?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Ac||n.dataTransfer.setData("text/plain",a),e.dragging=new _c(c,Oc(e,n),s)},dc.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},hc.dragover=hc.dragenter=(e,t)=>t.preventDefault(),hc.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(pc(t));if(!r)return;let s=e.state.doc.resolve(r.pos),i=n&&n.slice;i?e.someProp("transformPasted",t=>{i=t(i,e,!1)}):i=ec(e,Mc(t.dataTransfer),Ac?null:t.dataTransfer.getData("text/html"),!1,s);let o=!(!n||!Oc(e,t));if(e.someProp("handleDrop",n=>n(e,t,i||Go.empty,o)))return void t.preventDefault();if(!i)return;t.preventDefault();let l=i?function(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let s=n.content;for(let i=0;i<n.openStart;i++)s=s.firstChild.content;for(let i=1;i<=(0==n.openStart&&n.size?2:1);i++)for(let e=r.depth;e>=0;e--){let t=e==r.depth?0:r.pos<=(r.start(e+1)+r.end(e+1))/2?-1:1,n=r.index(e)+(t>0?1:0),o=r.node(e),l=!1;if(1==i)l=o.canReplace(n,n,s);else{let e=o.contentMatchAt(n).findWrapping(s.firstChild.type);l=e&&o.canReplaceWith(n,n,e[0])}if(l)return 0==t?r.pos:t<0?r.before(e+1):r.after(e+1)}return null}(e.state.doc,s.pos,i):s.pos;l??=s.pos;let a=e.state.tr;if(o){let{node:e}=n;e?e.replace(a):a.deleteSelection()}let c=a.mapping.map(l),d=0==i.openStart&&0==i.openEnd&&1==i.content.childCount,h=a.doc;if(d?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(h))return;let u=a.doc.resolve(c);if(d&&Ul.isSelectable(i.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new Ul(u));else{let t=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((e,n,r,s)=>t=s),a.setSelection(Ba(e,u,a.doc.resolve(t)))}e.focus(),e.dispatch(a.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},dc.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&$a(e)},20))},dc.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},dc.beforeinput=(e,t)=>{if(Ta&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,ua(8,"Backspace"))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let cu in hc)dc[cu]=hc[cu];function $c(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var Rc=class e{constructor(e,t){this.toDOM=e,this.spec=t||Bc,this.side=this.spec.side||0}map(e,t,n,r){let{pos:s,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Lc(s-n,s-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&$c(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Ic=class e{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,n,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return s>=i?null:new Lc(s,i,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&$c(this.attrs,t.attrs)&&$c(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},Pc=class e{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,n,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let i=e.mapResult(t.to+r,-1);return i.deleted||i.pos<=s.pos?null:new Lc(s.pos-n,i.pos-n,this)}valid(e,t){let n,{index:r,offset:s}=e.content.findIndex(t.from);return s==t.from&&!(n=e.child(r)).isText&&s+n.nodeSize==t.to}eq(t){return this==t||t instanceof e&&$c(this.attrs,t.attrs)&&$c(this.spec,t.spec)}destroy(){}},Lc=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new Rc(n,r))}static inline(t,n,r,s){return new e(t,n,new Ic(r,s))}static node(t,n,r,s){return new e(t,n,new Pc(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ic}get widget(){return this.type instanceof Rc}},zc=[],Bc={},Fc=class e{constructor(e,t){this.local=e.length?e:zc,this.children=t.length?t:zc}static create(e,t){return t.length?Jc(t,e,0,Bc):Vc}find(e,t,n){let r=[];return this.findInner(null==e?0:e,null==t?1e9:t,r,0,n),r}findInner(e,t,n,r,s){for(let i=0;i<this.local.length;i++){let o=this.local[i];o.from<=t&&o.to>=e&&(!s||s(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let o=this.children[i]+1;this.children[i+2].findInner(e-o,t-o,n,r+o,s)}}map(e,t,n){return this==Vc||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Bc)}mapInner(t,n,r,s,i){let o;for(let e=0;e<this.local.length;e++){let l=this.local[e].map(t,r,s);l&&l.type.valid(n,l)?(o||(o=[])).push(l):i.onRemove&&i.onRemove(this.local[e].spec)}return this.children.length?function(e,t,n,r,s,i,o){let l=e.slice();for(let c=0,d=i;c<n.maps.length;c++){let e=0;n.maps[c].forEach((t,n,r,s)=>{let i=s-r-(n-t);for(let o=0;o<l.length;o+=3){let r=l[o+1];if(r<0||t>r+d-e)continue;let s=l[o]+d-e;n>=s?l[o+1]=t<=s?-2:-1:t>=d&&i&&(l[o]+=i,l[o+1]+=i)}e+=i}),d=n.maps[c].map(d,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(-2==l[c+1]){a=!0,l[c+1]=-1;continue}let t=n.map(e[c]+i),d=t-s;if(d<0||d>=r.content.size){a=!0;continue}let h=n.map(e[c+1]+i,-1)-s,{index:u,offset:p}=r.content.findIndex(d),m=r.maybeChild(u);if(m&&p==d&&p+m.nodeSize==h){let r=l[c+2].mapInner(n,m,t+1,e[c]+i+1,o);r!=Vc?(l[c]=d,l[c+1]=h,l[c+2]=r):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=Jc(function(e,t,n,r,s,i,o){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(r,s,t);l?n.push(l):o.onRemove&&o.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let a=0;a<e.length;a+=3)-1==e[a+1]&&l(e[a+2],t[a]+i+1);return n}(l,e,t,n,s,i,o),r,0,o);t=a.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<a.children.length;e+=3){let n=a.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,a.children[e],a.children[e+1],a.children[e+2])}}return new Fc(t.sort(Kc),l)}(this.children,o||[],t,n,r,s,i):o?new e(o.sort(Kc),zc):Vc}add(t,n){return n.length?this==Vc?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let s,i=0;t.forEach((e,t)=>{let o,l=t+r;if(o=Hc(n,e,l)){for(s||(s=this.children.slice());i<s.length&&s[i]<t;)i+=3;s[i]==t?s[i+2]=s[i+2].addInner(e,o,l+1):s.splice(i,0,t,t+e.nodeSize,Jc(o,e,l+1,Bc)),i+=3}});let o=qc(i?Uc(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(Kc):this.local,s||this.children)}remove(e){return 0==e.length||this==Vc?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,s=this.local;for(let e=0;e<r.length;e+=3){let s,i=r[e]+n,o=r[e+1]+n;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<o&&(t[n]=null,(s||(s=[])).push(e));if(!s)continue;r==this.children&&(r=this.children.slice());let l=r[e+2].removeInner(s,i+1);l!=Vc?r[e+2]=l:(r.splice(e,3),e-=3)}if(s.length)for(let e,i=0;i<t.length;i++)if(e=t[i])for(let t=0;t<s.length;t++)s[t].eq(e,n)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return r==this.children&&s==this.local?this:s.length||r.length?new e(s,r):Vc}forChild(t,n){if(this==Vc)return this;if(n.isLeaf)return e.empty;let r,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let i=t+1,o=i+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>i&&t.type instanceof Ic){let e=Math.max(i,t.from)-i,n=Math.min(o,t.to)-i;e<n&&(s||(s=[])).push(t.copy(e,n))}}if(s){let t=new e(s.sort(Kc),zc);return r?new Wc([t,r]):t}return r||Vc}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return Gc(this.localsInner(e))}localsInner(e){if(this==Vc)return zc;if(e.inlineContent||!this.local.some(Ic.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Ic||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Fc.empty=new Fc([],[]),Fc.removeOverlap=Gc;var Vc=Fc.empty,Wc=class e{constructor(e){this.members=e}map(t,n){const r=this.members.map(e=>e.map(t,n,Bc));return e.from(r)}forChild(t,n){if(n.isLeaf)return Fc.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(t,n);i!=Vc&&(i instanceof e?r=r.concat(i.members):r.push(i))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<s.length;e++)t.push(s[e])}else t=s}return t?Gc(n?t:t.sort(Kc)):zc}static from(t){switch(t.length){case 0:return Vc;case 1:return t[0];default:return new e(t.every(e=>e instanceof Fc)?t:t.reduce((e,t)=>e.concat(t instanceof Fc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function qc(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let s=e[r];n.push(new Lc(s.from+t,s.to+t,s.type))}return n}function Hc(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,s=null;for(let i,o=0;o<e.length;o++)(i=e[o])&&i.from>n&&i.to<r&&((s||(s=[])).push(i),e[o]=null);return s}function Uc(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function Jc(e,t,n,r){let s=[],i=!1;t.forEach((t,o)=>{let l=Hc(e,t,o+n);if(l){i=!0;let e=Jc(l,t,n+o+1,r);e!=Vc&&s.push(o,o+t.nodeSize,e)}});let o=qc(i?Uc(e):e,-n).sort(Kc);for(let l=0;l<o.length;l++)o[l].type.valid(t,o[l])||(r.onRemove&&r.onRemove(o[l].spec),o.splice(l--,1));return o.length||s.length?new Fc(o,s):Vc}function Kc(e,t){return e.from-t.from||e.to-t.to}function Gc(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let s=n+1;s<t.length;s++){let i=t[s];if(i.from!=r.from){i.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,i.from),Xc(t,s,r.copy(i.from,r.to)));break}i.to!=r.to&&(t==e&&(t=e.slice()),t[s]=i.copy(i.from,r.to),Xc(t,s+1,i.copy(r.to,i.to)))}}return t}function Xc(e,t,n){for(;t<e.length&&Kc(n,e[t])>0;)t++;e.splice(t,0,n)}var Yc=/[\uD800-\uDBFF]/,Zc=/[\uDC00-\uDFFF]/,Qc=(e,t)=>e>>>t|e<<32-t,ed=e=>Qc(e,2)^Qc(e,13)^Qc(e,22),td=e=>Qc(e,6)^Qc(e,11)^Qc(e,25),nd=e=>Qc(e,7)^Qc(e,18)^e>>>3,rd=e=>Qc(e,17)^Qc(e,19)^e>>>10,sd=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]),id=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),od=class{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(id),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=rd(t[d-2])+t[d-7]+nd(t[d-15])+t[d-16];let n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],l=e[5],a=e[6],c=e[7];for(let d,h,u=0;u<64;u++)d=c+td(o)+(o&l^~o&a)+sd[u]+t[u]>>>0,h=ed(n)+(n&r^n&s^r&s)>>>0,c=a,a=l,l=o,o=i+d>>>0,i=s,s=r,r=n,n=d+h>>>0;e[0]+=n,e[1]+=r,e[2]+=s,e[3]+=i,e[4]+=o,e[5]+=l,e[6]+=a,e[7]+=c}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<8*(3-t%4),t++;this._W[n]|=128<<8*(3-t%4)}this._updateHash()}const n=t%64!=0;this._W.fill(0,0,16);let r=0;for(;t<e.length;r++)for(let n=3;n>=0&&t<e.length;n--)this._W[r]|=e[t++]<<8*n;n||(this._W[r-(t%4==0?0:1)]|=128<<8*(3-t%4)),this._W[14]=e.byteLength/536870912,this._W[15]=8*e.byteLength,this._updateHash();const s=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let e=0;e<4;e++)s[4*i+e]=this._H[i]>>>8*(3-e);return s}},ld=new sa("y-sync"),ad=new sa("y-undo"),cd=(new sa("yjs-cursor"),e=>{return yn((e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)})((t=(e=>(e=>{const t=ot();return e(t),lt(t)})(t=>yt(t,e)))(e),(new od).digest(t))));var t}),dd=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Gr(t.ds,e.id),hd=[{light:"#ecd44433",dark:"#ecd444"}],ud=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=_e();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(r=t)[ze(Ut()*r.length)])}var r;return e.get(n)},pd=(e,{colors:t=hd,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:s=()=>{},mapping:i}={})=>{let o=!1;const l=new gd(e,i),a=new ta({props:{editable:e=>{const t=ld.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:ld,state:{init:(s,i)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r}),apply:(e,t)=>{const n=e.getMeta(ld);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return t.addToHistory=!1!==e.getMeta("addToHistory"),t.isChangeOrigin=void 0!==n&&!!n.isChangeOrigin,t.isUndoRedoOperation=void 0!==n&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,null!==l.prosemirrorView&&(void 0===n||null==n.snapshot&&null==n.prevSnapshot||Rr(0,()=>{null!=l.prosemirrorView&&(null==n.restore?l._renderSnapshot(n.snapshot,n.prevSnapshot,t):(l._renderSnapshot(n.snapshot,n.snapshot,t),delete t.restore,delete t.snapshot,delete t.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))})),t}},view:e=>(l.initView(e),i??l._forceRerender(),s(),{update:()=>{const t=a.getState(e.state);if(null==t.snapshot&&null==t.prevSnapshot&&(o||null!==e.state.doc.content.findDiffStart(e.state.doc.type.createAndFill().content))){if(o=!0,!1===t.addToHistory&&!t.isChangeOrigin){const t=ad.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}l.mux(()=>{t.doc.transact(n=>{n.meta.set("addToHistory",t.addToHistory),l._prosemirrorChanged(e.state.doc)},ld)})}},destroy:()=>{l.destroy()}})});return a},md=(e,t,n,r)=>{if(null==n)return r;if(!(null===r||n>1&&r<=1||qd(t,e,n,r)))return r;const s=Wd(t,e,n);return null!==s?s:r},fd=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:"nodeRange"===n?t.selection.depth:void 0,anchor:zd(t.selection.anchor,e.type,e.mapping),head:zd(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},gd=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=(()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else void 0!==n&&n()}})(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{null===this.beforeTransactionSelection&&null!=this.prosemirrorView&&(this.beforeTransactionSelection=fd(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return!!this.prosemirrorView.hasFocus()&&(pn&&null===this._domSelectionInView&&(Rr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView)}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(null==e||null==e.anchorNode)return!1;const t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),0===t.getClientRects().length&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);const n=t.getBoundingClientRect(),r=Tr.documentElement;return n.bottom>=0&&n.right>=0&&n.left<=(window.innerWidth||r.clientWidth||0)&&n.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(e,t){t||(t=Ts(Qr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(ld,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>bd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(e),0,0));t.setMeta(ld,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=null!==this.beforeTransactionSelection?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(e=>bd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(t),0,0));if(e){const t=Fe(Ve(e.anchor,0),n.doc.content.size),r=Fe(Ve(e.head,0),n.doc.content.size);n.setSelection(ql.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(ld,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,s=this.type;if(e||(e=Ms(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||At(),r=new ss({gc:!1}),us(r,t),t=Ms(r),us(r,e),e=Ms(r),null===s._item){const e=Array.from(this.doc.share.keys()).find(e=>this.doc.share.get(e)===this.type);s=r.getXmlFragment(e)}else{const e=r.store.clients.get(s._item.id.client)??[];s=e[Ps(e,s._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{Kr(r,e,e=>{})});const o=(e,t)=>{const r="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:r,type:e,color:ud(n.colorMapping,n.colors,r)}},l=yi(s,new As(t.ds,e.sv)).map(n=>!n._item.deleted||dd(n._item,e)||dd(n._item,t)?bd(n,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,o):null).filter(e=>null!==e),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(ld,{isChangeOrigin:!0}))},ld)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=ld.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);Kr(t,t.deleteSet,e=>{if(e.constructor===Oo){const t=e.content.type;t&&this.mapping.delete(t)}}),t.changed.forEach(e),t.changedParentTypes.forEach(e),this.mapping.clear();const n=this.type.toArray().map(e=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),r=this.prosemirrorView.state.doc;let s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(n),0,0));((e,t,n,r)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Kl(e.doc));else if("node"===t.type){const r=Fd(n.doc,n.type,t.anchor,n.mapping);null!==r&&e.setSelection(((e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?Ul.create(e.doc,t):ql.near(n)})(e,r))}else if("nodeRange"===t.type){const r=((e,t,n,r)=>{if(null===t||null===n)return null;const s=Math.min(Math.max(t,0),e.doc.content.size),i=Math.min(Math.max(n,0),e.doc.content.size);try{const t=Bl.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:i,depth:r});return t.ranges.length?t:ql.near(e.doc.resolve(s))}catch(au){return ql.near(e.doc.resolve(s))}})(e,Fd(n.doc,n.type,t.anchor,n.mapping),Fd(n.doc,n.type,t.head,n.mapping),t.depth);null!==r&&e.setSelection(r)}else{let s=Fd(n.doc,n.type,t.anchor,n.mapping),i=Fd(n.doc,n.type,t.head,n.mapping);null!=r&&(s=md(e.doc,r,t.absAnchor,s),i=md(e.doc,r,t.absHead,i)),null===s&&(s=i),null===i&&(i=s),null!==s&&null!==i&&e.setSelection(ql.between(e.doc.resolve(s),e.doc.resolve(i)))}})(s,this.beforeTransactionSelection,this,r),s=s.setMeta(ld,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Zs}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{Pd(this.doc,this.type,e,this),this.beforeTransactionSelection=fd(this,this.prosemirrorView.state)},ld)}initView(e){null!=this.prosemirrorView&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){null!=this.prosemirrorView&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},xd=(e,t,n,r,s,i)=>{const o=n.mapping.get(e);if(void 0===o){if(e instanceof no)return bd(e,t,n,r,s,i);throw Et()}return o},bd=(e,t,n,r,s,i)=>{const o=[],l=e=>{if(e instanceof no){const l=xd(e,t,n,r,s,i);null!==l&&o.push(l)}else{const l=(e._item.right?.content)?.type;l instanceof Qi&&!l._item.deleted&&l._item.id.client===l.doc.clientID&&(e.applyDelta([{retain:e.length},...l.toDelta()]),l.doc.transact(e=>{l._item.delete(e)}));const a=yd(e,t,n,r,s,i);null!==a&&a.forEach(e=>{null!==e&&o.push(e)})}};void 0===r||void 0===s?e.toArray().forEach(l):yi(e,new As(s.ds,r.sv)).forEach(l);try{const l=e.getAttributes(r);void 0!==r&&(dd(e._item,r)?dd(e._item,s)||(l.ychange=i?i("added",e._item.id):{type:"added"}):l.ychange=i?i("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,l,o);return n.mapping.set(e,a),a}catch(au){return e.doc.transact(t=>{e._item.delete(t)},ld),n.mapping.delete(e),null}},yd=(e,t,n,r,s,i)=>{const o=[],l=e.toDelta(r,s,i);try{for(let e=0;e<l.length;e++){const n=l[e];o.push(t.text(n.insert,Rd(n.attributes,t)))}}catch(au){return e.doc.transact(t=>{e._item.delete(t)},ld),null}return o},wd=(e,t)=>e instanceof Array?((e,t)=>{const n=new io,r=e.map(e=>({insert:e.text,attributes:Id(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new no(e.type.name);for(const r in e.attrs){const t=e.attrs[r];null!==t&&"ychange"!==r&&n.setAttribute(r,t)}return n.insert(0,jd(e).map(e=>wd(e,t))),t.mapping.set(n,e),n})(e,t),vd=e=>"object"==typeof e&&null!==e,kd=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);let r=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&r;s++){const i=n[s],o=e[i],l=t[i];r="ychange"===i||o===l||vd(o)&&vd(l)&&kd(o,l)}return r},jd=e=>{const t=e.content.content,n=[];for(let r=0;r<t.length;r++){const e=t[r];if(e.isText){const e=[];for(let n=t[r];r<t.length&&n.isText;n=t[++r])e.push(n);r--,n.push(e)}else n.push(e)}return n},Sd=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&rn(e.attributes||{}).length===t[n].marks.length&&on(e.attributes,(e,r)=>{const s=$d(r),i=t[n].marks;return!!i.find(e=>e.type.name===s)&&kd(e,i.find(e=>e.type.name===s)?.attrs)}))},Cd=(e,t)=>{if(e instanceof no&&!(t instanceof Array)&&Ld(e,t)){const n=jd(t);return e._length===n.length&&kd(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Cd(e,n[t]))}return e instanceof io&&t instanceof Array&&Sd(e,t)},Nd=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Ed=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>r.mapping.delete(e)),e.delete(t,n))},Ad=(e,t,n,r,s,i)=>{if(r<s){const o=[];for(let e=r;e<s;e++)o.push(wd(n[e],i));e.insert(t,o)}},Td=(e,t,n,r)=>t instanceof io&&n instanceof Array?(Sd(t,n)?r.mapping.set(t,n):Dd(t,n,r),!0):!(!(t instanceof no)||n instanceof Array||!Ld(t,n)||(Cd(t,n)?r.mapping.set(t,n):Pd(e,t,n,r),0)),Md=(e,t,n,r,s,i,o,l,a)=>{const c=Fe(i-s,l-o);for(let d=0;d<c;d++){const i=r[s+d],l=n[o+d];Td(e,i,l,a)||(Ed(t,o+d,1,a),Ad(t,o+d,n,o+d,o+d+1,a))}Ed(t,o+c,i-s-c,a),Ad(t,o+c,n,o+c,l,a)},_d=(e,t,n)=>{const r=e.toArray(),s=jd(t),i=s.length,o=r.length,l=Fe(o,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=r[a],t=s[a];if(Nd(n.mapping.get(e),t))d=!0;else if(!Cd(e,t))break}for(;a+c<l;c++){const e=r[o-c-1],t=s[i-c-1];if(Nd(n.mapping.get(e),t))d=!0;else if(!Cd(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},Dd=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:r,str:s}=(e=>{let t="",n=e._start;const r={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof bo?t+=n.content.str:n.content instanceof mo&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}})(e),i=t.map(e=>({insert:e.text,attributes:Object.assign({},r,Id(e.marks,n))})),{insert:o,remove:l,index:a}=((e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Yc.test(e[n-1])&&n--;r+n<e.length&&r+n<t.length&&e[e.length-r-1]===t[t.length-r-1];)r++;return r>0&&Zc.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}})(s,i.map(e=>e.insert).join(""));e.delete(a,l),e.insert(a,o),e.applyDelta(i.map(e=>({retain:e.insert.length,attributes:e.attributes})))},Od=/(.*)(--[a-zA-Z0-9+/=]{8})$/,$d=e=>Od.exec(e)?.[1]??e,Rd=(e,t)=>{const n=[];for(const r in e)n.push(t.mark($d(r),e[r]));return n},Id=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const r=Me(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${cd(e.toJSON())}`:e.type.name]=e.attrs}}),n},Pd=(e,t,n,r)=>{if(t instanceof no&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(t,n),t instanceof no){const e=t.getAttributes(),r=n.attrs;for(const n in r)null!==r[n]?e[n]!==r[n]&&"ychange"!==n&&t.setAttribute(n,r[n]):t.removeAttribute(n);for(const n in e)void 0===r[n]&&t.removeAttribute(n)}const s=jd(n),i=s.length,o=t.toArray(),l=o.length,a=Fe(i,l);if(((e,t,n,r,s)=>{const i=((e,t,n)=>{const r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});const s=[];if(e.forEach((e,i)=>{const o=n.mapping.get(e),l=r.get(o);void 0!==l&&Nd(o,t[l])&&s.push({yIndex:i,pIndex:l,yChild:e})}),0===s.length)return[];const i=new Array(s.length),o=[];for(let a=0;a<s.length;a++){let e=0,t=o.length;for(;e<t;){const n=e+t>>1;s[o[n]].pIndex<s[a].pIndex?e=n+1:t=n}i[a]=e>0?o[e-1]:-1,o[e]=a}const l=[];for(let a=o[o.length-1];-1!==a;a=i[a])l.push(s[a]);return l.reverse()})(r,n,s);if(i.length<2||!i.some(e=>e.yIndex!==e.pIndex)||i.some(e=>{const t=n[e.pIndex];return!(e.yChild instanceof io&&t instanceof Array||e.yChild instanceof no&&!(t instanceof Array))}))return!1;let o=0,l=0;for(const a of i){Md(e,t,n,r,o,a.yIndex,l,a.pIndex,s);const i=n[a.pIndex];Td(e,a.yChild,i,s),o=a.yIndex+1,l=a.pIndex+1}return Md(e,t,n,r,o,r.length,l,n.length,s),!0})(e,t,s,o,r))return;let c=0,d=0;for(;c<a;c++){const e=o[c],t=s[c];if(!Nd(r.mapping.get(e),t)){if(!Cd(e,t))break;r.mapping.set(e,t)}}for(;d+c+1<a;d++){const e=o[l-d-1],t=s[i-d-1];if(!Nd(r.mapping.get(e),t)){if(!Cd(e,t))break;r.mapping.set(e,t)}}e.transact(()=>{for(;l-c-d>0&&i-c-d>0;){const n=o[c],a=s[c],h=o[l-d-1],u=s[i-d-1];if(n instanceof io&&a instanceof Array)Sd(n,a)||Dd(n,a,r),c+=1;else{let s=n instanceof no&&Ld(n,a),i=h instanceof no&&Ld(h,u);if(s&&i){const e=_d(n,a,r),t=_d(h,u,r);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?s=!1:i=!1}s?(Pd(e,n,a,r),c+=1):i?(Pd(e,h,u,r),d+=1):(r.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[wd(a,r)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&o[0]instanceof io?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):n>0&&(t.slice(c,c+n).forEach(e=>r.mapping.delete(e)),t.delete(c,n)),c+d<i){const e=[];for(let t=c;t<i-d;t++)e.push(wd(s[t],r));t.insert(c,e)}},ld)},Ld=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,zd=(e,t,n)=>{if(0===e)return Ns(t,0,-1);let r=null===t._first?null:t._first.content.type;for(;null!==r&&t!==r;){if(r instanceof io){if(r._length>=e)return Ns(r,e,-1);if(e-=r._length,null!==r._item&&null!==r._item.next)r=r._item.next.content.type;else{do{r=null===r._item?null:r._item.parent,e--}while(r!==t&&null!==r&&null!==r._item&&null===r._item.next);null!==r&&r!==t&&(r=null===r._item?null:r._item.next.content.type)}}else{const s=(n.get(r)||{nodeSize:0}).nodeSize;if(null!==r._first&&e<s)r=r._first.content.type,e--;else{if(1===e&&0===r._length&&s>1)return new js(null===r._item?null:r._item.id,null===r._item?vs(r):null,null);if(e-=s,null!==r._item&&null!==r._item.next)r=r._item.next.content.type;else{if(0===e)return r=null===r._item?r:r._item.parent,new js(null===r._item?null:r._item.id,null===r._item?vs(r):null,null);do{r=r._item.parent,e--}while(r!==t&&null===r._item.next);r!==t&&(r=r._item.next.content.type)}}}if(null===r)throw At();if(0===e&&r.constructor!==io&&r!==t)return Bd(r._item.parent,r._item)}return Ns(t,t._length,-1)},Bd=(e,t)=>{let n=null,r=null;return null===e._item?r=vs(e):n=ws(e._item.id.client,e._item.id.clock),new js(n,r,t.id)},Fd=(e,t,n,r)=>{const s=Es(n,e);if(null===s||s.type!==t&&!ks(t,s.type._item))return null;let i=s.type,o=0;if(i.constructor===io)o=s.index;else if(null===i._item||!i._item.deleted){let e=i._first,t=0;for(;t<i._length&&t<s.index&&null!==e;){if(!e.deleted){const n=e.content.type;if(t++,n instanceof io)o+=n._length;else{const e=r.get(n);if(null==e)return null;o+=e.nodeSize}}e=e.right}o+=1}for(;i!==t&&null!==i._item;){const e=i._item.parent;if(null===e._item||!e._item.deleted){o+=1;let t=e._first;for(;null!==t;){const e=t.content.type;if(e===i)break;if(!t.deleted)if(e instanceof io)o+=e._length;else{const t=r.get(e);if(null==t)return null;o+=t.nodeSize}t=t.right}}i=e}const l=o-1;return((e,t,n)=>{if(null===n)return!1;const r=Es(t,e);return null!==r&&r.type instanceof io&&null!==t.item&&n<=1})(e,n,l)?null:l},Vd=(e,t)=>{if(e===t)return!0;const n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},Wd=(e,t,n)=>{let r=0,s=0;for(;s<e.childCount;s++){const t=e.child(s);if(r+t.nodeSize>n)break;r+=t.nodeSize}if(s>=e.childCount)return null;const i=e.child(s),o=e.resolve(n),l=(e,t)=>{if(0===o.depth){const s=e+(n-r),i=e+1,o=e+t.nodeSize-1;return Math.max(i,Math.min(s,o))}return((e,t,n)=>{let r=t+1,s=n;for(let i=1;i<e.depth;i++){const t=e.index(i);if(t>=s.childCount)return null;for(let e=0;e<t;e++)r+=s.child(e).nodeSize;if(r+=1,s=s.child(t),s.type!==e.node(i+1).type)return null}return s.isTextblock?r+Math.min(e.parentOffset,s.content.size):null})(o,e,t)},a=(n,r=!1)=>{let i=0;for(let t=0;t<=s;t++)n(e.child(t))&&i++;let o=0,a=-1,c=null,d=0;for(let e=0;e<t.childCount;e++){const r=t.child(e);n(r)&&(o++,o===i&&(a=d,c=r)),d+=r.nodeSize}return null===c||r&&(1!==i||1!==o)?null:l(a,c)},c=e=>e.type===i.type&&Vd(e.attrs,i.attrs),d=i.textContent,h=a(e=>c(e)&&e.textContent===d);if(null!==h)return h;const u=a(e=>e.type===i.type&&e.textContent===d);if(null!==u)return u;if((e=>{const t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{const r=t[n];return null==r||!Object.prototype.hasOwnProperty.call(r,"default")||r.default!==e.attrs[n]})})(i)){const e=a(c,!0);if(null!==e)return e}return a(e=>c(e)&&""!==d&&""!==e.textContent&&(d.startsWith(e.textContent)||e.textContent.startsWith(d)),!0)},qd=(e,t,n,r)=>{if(null===r)return!1;const s=e.resolve(n),i=t.resolve(r);if(!s.parent.isTextblock)return!1;if(!i.parent.isTextblock)return!0;if(s.parent.textContent!==i.parent.textContent)return!0;if(0!==s.parentOffset&&0===i.parentOffset)return!0;const o=0===s.parentOffset&&0===i.parentOffset,l=s.parentOffset!==i.parentOffset||s.parent.type!==i.parent.type||!Vd(s.parent.attrs,i.parent.attrs);if(o||l){const s=Wd(e,t,n);return null!==s&&s!==r}return!1},Hd=new Set(["paragraph"]);function Ud(e){return!!e.getMeta(ld)}function Jd(e,t){const n=ld.getState(e);return Fd(n.doc,n.type,t,n.binding.mapping)||0}function Kd(e,t){const n=ld.getState(e);return zd(t,n.type,n.binding.mapping)}var Gd=class e extends b.MappablePosition{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}}};b.Extension.create({name:"collaboration",priority:1e3,addOptions:()=>({document:null,field:"default",fragment:null,provider:null}),addStorage:()=>({isDisabled:!1}),onCreate(){this.editor.extensionManager.extensions.find(e=>"undoRedo"===e.name)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>function(e,t,n){const r=e instanceof Gd?e.yRelativePosition:null;if(Ud(t)&&r)return{position:new Gd(Jd(n,r),r),mapResult:null};const s=(0,b.getUpdatedPosition)(e,t),i=s.position.position;return{position:new Gd(i,null!=r?r:Kd(n,i)),mapResult:s.mapResult}}(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>function(e,t){return new Gd(e,Kd(t,e))}(e,this.editor.state)},addCommands:()=>({undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ad.getState(t).undoManager.undoStack.length&&(!n||(e=>{const t=ad.getState(e).undoManager;if(null!=t)return t.undo(),!0})(t))),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ad.getState(t).undoManager.redoStack.length&&(!n||(e=>{const t=ad.getState(e).undoManager;if(null!=t)return t.redo(),!0})(t)))}),addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=(({protectedNodes:e=Hd,trackedOrigins:t=[],undoManager:n=null}={})=>new ta({key:ad,state:{init:(r,s)=>{const i=ld.getState(s);let o=n;if(!o){const n=i.doc,r=new Set(n?n._observers.get("destroy"):[]);o=new Zs(i.type,{trackedOrigins:new Set([ld].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Oo&&e.content instanceof Eo&&(e.content.type instanceof Qi||e.content.type instanceof no&&t.has(e.content.type.nodeName))&&0!==e.content.type._length))(t,e),captureTransaction:e=>!1!==e.meta.get("addToHistory")});const s=n?n._observers.get("destroy"):new Set;o._yTiptapDocDestroyListeners=Array.from(s||[]).filter(e=>!r.has(e))}return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(e,t,n,r)=>{const s=ld.getState(r).binding,i=t.undoManager,o=i.undoStack.length>0,l=i.redoStack.length>0;return s?{undoManager:i,prevSel:fd(s,n),hasUndoOps:o,hasRedoOps:l}:o!==t.hasUndoOps||l!==t.hasRedoOps?Object.assign({},t,{hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}):t}},view:e=>{const t=ld.getState(e.state),n=ad.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const r=t.binding;r&&n.meta.set(r,ad.getState(e.state).prevSel)}),n.on("stack-item-popped",({stackItem:e})=>{const n=t.binding;n&&(n.beforeTransactionSelection=e.meta.get(n)||n.beforeTransactionSelection)}),{destroy:()=>{n.destroy();const e=n._yTiptapDocDestroyListeners;e&&n.doc&&(e.forEach(e=>n.doc.off("destroy",e)),n._yTiptapDocDestroyListeners=null)}}}}))(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{const{undoManager:t}=ad.getState(e.state);t.restore&&(t.restore(),t.restore=()=>{});const r=n?n(e):void 0;return{destroy:()=>{const e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on("afterTransaction",t.afterTransactionHandler),t._observers=n},null!=r&&r.destroy&&r.destroy()}}},[pd(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new y.Plugin({key:new y.PluginKey("filterInvalidContent"),filterTransaction:t=>{if(!Ud(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(n){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:n,editor:this.editor,disableCollaboration:()=>{var t;null==(t=e.doc)||t.destroy()}}),!0}}})].filter(Boolean)}});function Xd(e,t){const{state:n}=t,r=n.selection.$anchor;let s=!1;if(r.depth)for(let i=r.depth;i>0;i--)r.node(i).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r.before(i),r.after(i)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const i=r.pos;if(i){const r=n.tr.doc.nodeAt(i);r&&r.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i,i+r.nodeSize)),s=!0)}}return s}var Yd=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function Zd(){const e=n.m$2(),t=n.d$3(),{t:r}=n._(),{type:s,title:i,body:o}=n.Ht(t,n.q.name,{type:"note",title:"",body:""}),[l,a]=(0,x.useState)(!1),[c,d]=(0,x.useState)("note"),[h,u]=(0,x.useState)(""),[p,m]=(0,x.useState)("");(0,x.useEffect)(()=>{l&&(d(s||"note"),u(i||""),m(o||""))},[l,s,i,o]);const f=(0,x.useCallback)(()=>{t&&(t.chain().updateAttributes(n.q.name,{type:c,title:h,body:p}).focus().run(),a(!1))},[t,c,h,p]),g=(0,x.useCallback)(()=>{a(!1)},[]),b=(0,x.useCallback)(()=>{Xd(n.q.name,t)},[t]),y=(0,x.useCallback)(()=>t.isActive(n.q.name),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsxs)(n.o,{onOpenChange:a,open:l,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:r("editor.callout.edit.title")})}),(0,w.jsxs)(n.h$1,{children:[(0,w.jsx)(n.m,{children:r("editor.callout.edit.title")}),(0,w.jsxs)("div",{className:"richtext-space-y-4 richtext-py-4",children:[(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.type")}),(0,w.jsxs)(n.R,{onValueChange:d,value:c,children:[(0,w.jsx)(n.B,{children:(0,w.jsx)(n.S,{className:"richtext-text-accent",placeholder:r("editor.callout.dialog.type.placeholder")})}),(0,w.jsx)(n.V,{children:Yd.map(e=>(0,w.jsx)(n.D$1,{value:e.value,children:r(`editor.callout.type.${e.value}`)},e.value))})]})]}),(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.title.label")}),(0,w.jsx)(n.i$1,{onChange:e=>u(e.target.value),placeholder:r("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.body.label")}),(0,w.jsx)(n.i$1,{onChange:e=>m(e.target.value),placeholder:r("editor.callout.dialog.body.placeholder"),type:"text",value:p})]})]}),(0,w.jsxs)(n.n$2,{children:[(0,w.jsx)(n.x$1,{onClick:g,variant:"outline",children:r("editor.callout.dialog.button.cancel")}),(0,w.jsx)(n.x$1,{onClick:f,children:r("editor.callout.dialog.button.apply")})]})]})]}),(0,w.jsx)(n.f$2,{action:b,icon:"Trash2",tooltip:r("editor.delete")})]})}):(0,w.jsx)(w.Fragment,{})}function Qd(){const e=n.m$2(),t=n.d$3(),{t:r}=n._(),s=(0,x.useCallback)(()=>t.isActive(n.A.name),[t]),i=(0,x.useCallback)(()=>Xd(n.A.name,t),[t]),o=(0,x.useCallback)(()=>t.chain().focus().addColBefore().run(),[t]),l=(0,x.useCallback)(()=>t.chain().focus().addColAfter().run(),[t]),a=(0,x.useCallback)(()=>t.chain().focus().deleteCol().run(),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:s,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(n.f$2,{action:o,icon:"ColumnAddLeft",tooltip:r("editor.table.menu.insertColumnBefore")}),(0,w.jsx)(n.f$2,{action:l,icon:"ColumnAddRight",tooltip:r("editor.table.menu.insertColumnAfter")}),(0,w.jsx)(n.f$2,{action:a,icon:"DeleteColumn",tooltip:r("editor.table.menu.deleteColumn")}),(0,w.jsx)(n.f$2,{action:i,icon:"Trash2",tooltip:r("editor.table.menu.delete_column")})]})}):(0,w.jsx)(w.Fragment,{})}function eh(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateImage({width:n.p$3[s]}),isActive:()=>e.isActive("image",{width:n.p$3[s]})}}))}function th(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateImageGif({width:n.p$3[s]}),isActive:()=>e.isActive("image",{width:n.p$3[s]})}}))}function nh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImage?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function rh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageGif?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function sh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageMermaid?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ih(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageDrawer?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function oh(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(t=>({type:`video-align-${t.type}`,component:n.f$2,componentProps:{tooltip:t.tooltip,icon:t.icon,action:()=>e.commands.updateVideo({align:t.type}),isActive:()=>e.getAttributes("video").align===t.type}}))}function lh(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`video-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateVideo({width:n.u$3[s]}),isActive:()=>e.isActive("video",{width:n.u$3[s]})}}))}var ah=!1;function ch({editor:e,attrs:t,extension:r}){const[s,i]=(0,x.useState)(!1),o=(0,x.useRef)(null),l=(0,x.useRef)(null),{alt:a,align:c}=t,d=r?.options.upload;(0,x.useEffect)(()=>{s&&setTimeout(()=>{(async()=>{const e=document.querySelector("#easydrawer");e&&(o.current=new E.Editor(e,{wheelEventsEnabled:!1,disableZoom:!0}),l.current=(0,E.makeDropdownToolbar)(o.current),l.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(a)))})()},200)},[s]);const h=()=>{if(ah){for(;o.current.history.redoStackSize>0;)o.current.history.redo();ah=!1}else o.current.history.undo()};return(0,w.jsxs)(n.o,{onOpenChange:i,open:s,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{action:()=>i(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:"Edit Drawer"}),(0,w.jsxs)("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[(0,w.jsx)("div",{className:"richtext-size-full",id:"easydrawer"}),(0,w.jsx)(n.me,{changeBorderColorShape:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setBorderColor(e),n.serializeState())},changeColorShape:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setColor(e),n.serializeState())},changeShape:e=>{const t=l.current.getWidgetById("shape");t&&t.setShapeType(e)},onClear:()=>{if(!ah){for(;o.current.history.undoStackSize>0;)h();ah=!0}},onRedo:()=>{ah||o.current.history.redo()},onThicknessChange:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setThickness(e),n.serializeState())},onUndo:h,refEditor:o,setColorHighlight:e=>{const t=o.current.toolController.getPrimaryTools()[3],n=l.current.getWidgetById("pen-2");t&&n&&(t.setColor(e),n.serializeState())},setColorPen:e=>{const t=o.current.toolController.getPrimaryTools()[2],n=l.current.getWidgetById("pen-1");t&&n&&(t.setColor(e),n.serializeState())},setThicknessPen:e=>{const t=o.current.toolController.getPrimaryTools()[2],n=l.current.getWidgetById("pen-1");t&&n&&(t.setThickness(e),n.serializeState())}})]}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:async()=>{if(o.current){const t=o.current.toSVG(),r=t.outerHTML,s=`drawer-${n.a$2()}.svg`;let i=n.n$1(t.outerHTML);if(d){const e=n.s$1(i,s);i=await d(e)}e?.chain().focus().setDrawer({type:"drawer",src:i,alt:encodeURIComponent(r),width:426,height:212},!!r).run(),e?.commands.setAlignImageDrawer(c)}i(!1)},type:"button",children:"Save changes"})})]})]})}function dh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function hh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$3(),i=n.Ht(s,n.ve.name),o=n.v$1(n.ve.name),l=(0,x.useMemo)(()=>function(e,t){return[...ih(e,t),{type:"edit",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(e.type.name===n.ve.name)return i=!0,!1}),i},children:l?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l?.map((e,t)=>"edit"===e.type&&i?.src?(0,w.jsx)(ch,{attrs:i,editor:s,extension:o},`bubbleMenu-drawer-${t}`):(0,w.jsx)(dh,{editor:s,item:e},`bubbleMenu-drawer-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function uh({children:e,visible:t,toggleVisible:r}){const{t:s}=n._(),i=n.d$3(),[o,l]=(0,x.useState)(null);(0,x.useEffect)(()=>{a.l().then(l)},[]);const{text:c,macros:d}=n.Ht(i,n.Wt.name,{text:"",macros:""}),[h,u]=(0,x.useState)(decodeURIComponent(c||"")),[p,m]=(0,x.useState)(decodeURIComponent(d||""));(0,x.useEffect)(()=>{t&&(u(decodeURIComponent(c||"")),m(decodeURIComponent(d||"")))},[t]);const f=(0,x.useCallback)(()=>{i.chain().focus().setKatex({text:encodeURIComponent(h),macros:encodeURIComponent(p)}).run(),u(""),m(""),r(!1)},[i,h,p,r]),g=(0,x.useMemo)(()=>{if(!o)return h;try{return o.renderToString(h,{macros:n.Y(p||"")})}catch{return h}},[h,p,o]),b=(0,x.useMemo)(()=>`${h}`.trim()?g:null,[h,g]);return(0,w.jsxs)(n.o,{onOpenChange:r,open:t,children:[(0,w.jsx)(n.s,{asChild:!0,children:e}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:s("editor.formula.dialog.text")}),(0,w.jsx)("div",{style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,w.jsxs)("div",{className:"richtext-flex-1",children:[(0,w.jsx)(n.s$2,{className:"mb-[6px]",children:"Expression"}),(0,w.jsx)(n.i,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:e=>u(e.target.value),placeholder:"Text",required:!0,rows:10,value:h,style:{color:"var(--richtext-foreground)"}}),(0,w.jsx)(n.s$2,{className:"mb-[6px]",children:"Macros"}),(0,w.jsx)(n.i,{onChange:e=>m(e.target.value),placeholder:"Macros",rows:10,value:p,style:{color:"var(--richtext-foreground)"}})]}),(0,w.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:b||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:f,type:"button",children:"Save changes"})})]})]})}function ph(){const e=n.m$2(),t=n.d$3(),[r,s]=(0,x.useState)(!1),i=(0,x.useCallback)(()=>t.isActive(n.Wt.name),[t]),o=(0,x.useCallback)(()=>Xd(n.Wt.name,t),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:i,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(uh,{toggleVisible:s,visible:r,children:(0,w.jsx)(n.f$2,{action:()=>s(!r),tooltip:"Edit",children:(0,w.jsx)(v.Pencil,{size:16})})}),(0,w.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,w.jsx)(v.Trash2,{size:16})})]})}):(0,w.jsx)(w.Fragment,{})}function mh(e){const{t:t}=n._();return(0,w.jsxs)("div",{className:"richtext-flex richtext-flex-nowrap",children:[(0,w.jsx)(n.f$2,{disabled:!e?.link,icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e?.link,"_blank")}}),(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onEdit()}}),(0,w.jsx)(n.f$2,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onClear()}})]})}function fh(){const e=n.m$2(),t=n.d$3(),[r,s]=(0,x.useState)(!1),i=n.Ht(t,n.Fe.name)?.href,o=(0,x.useCallback)(({editor:e})=>e.isActive(n.Fe.name),[]),l=(0,x.useCallback)(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),s(!1)},[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:(0,w.jsx)(w.Fragment,{children:(0,w.jsx)("div",r?{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(n.De,{editor:t,onClose:()=>{s(!1)},onSetLink:(e,n,r)=>{const{from:i}=t.state.selection,o=i+(n?.length??0);t.chain().extendMarkRange("link").insertContent({type:"text",text:n,marks:[{type:"link",attrs:{href:e,target:r?"_blank":""}}]}).setLink({href:e}).setTextSelection({from:i,to:o}).focus().run(),s(!1)}})}:{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(mh,{editor:t,link:i,onClear:l,onEdit:()=>{s(!0)}})})})}):(0,w.jsx)(w.Fragment,{})}function gh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentdisabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function xh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$3(),i=(0,x.useMemo)(()=>function(e,t){return[{type:"flipX",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const{flipX:t}=e.getAttributes("image");e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!t}).run()}}},{type:"flipY",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const{flipY:t}=e.getAttributes("image");e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!t}).run()}}},...eh(e,t),...nh(e,t),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.ae.name}(e))return i=!0,!1}),i},children:i?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:i?.map((e,t)=>(0,w.jsx)(gh,{editor:s,item:e},`bubbleMenu-image-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function bh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$3(),i=(0,x.useMemo)(()=>function(e,t){return[...th(e,t),...rh(e,t),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,t,e]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.C.name}(e))return i=!0,!1}),i},children:i?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:i?.map((e,t)=>(0,w.jsx)(gh,{editor:s,item:e},`bubbleMenu-image-gif-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function yh(){const{t:e}=n._(),t=n.m$2(),r=n.d$3(),s=(0,x.useMemo)(()=>function(e,t){return[...lh(e,t),...oh(e),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(r,e),[r,e]);return t?(0,w.jsx)(j.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.T.name}(e))return i=!0,!1}),i},children:s?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s?.map((e,t)=>(0,w.jsx)(gh,{editor:r,item:e},`bubbleMenu-video-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}var wh="graph TB\na--\x3eb",vh=({editor:e,attrs:t,extension:r})=>{const{alt:s,align:i}=t,[o,l]=(0,x.useState)(decodeURIComponent(s??wh)),[a,c]=(0,x.useState)(""),[d,h]=(0,x.useState)(!1),u=(0,x.useRef)(null),[p,m]=(0,x.useState)(null),f=r?.options.upload,g=(0,x.useCallback)(e=>{e&&import("mermaid").then(e=>{m(e.default)})},[]),b=async e=>{try{const{svg:t}=await p.render("mermaid-svg",e);c(t)}catch{c("")}};return(0,x.useEffect)(()=>{p&&d&&(p.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o))},[p,d]),(0,x.useEffect)(()=>{p&&d&&b(o)},[p,o]),(0,w.jsxs)(n.o,{onOpenChange:h,open:d,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:"Edit Mermaid"}),(0,w.jsx)("div",{ref:g,style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,w.jsx)(n.i,{autoFocus:!0,className:"richtext-flex-1",defaultValue:wh,onChange:e=>l(e.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"var(--richtext-foreground)"}}),(0,w.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:a},ref:u,style:{height:"100%",border:"1px solid var(--richtext-border)",minHeight:500}})]})}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:async()=>{if(""!==o){if(o){const t=u.current.querySelector("svg"),{width:r,height:s}=t.getBoundingClientRect(),l=`mermaid-${n.a$2()}.svg`;let a=n.n$1(t.outerHTML);if(f){const e=n.s$1(a,l);a=await f(e)}e?.chain().focus().setMermaid({type:"mermaid",src:a,alt:encodeURIComponent(o),width:r,height:s},!!o).run(),e?.commands.setAlignImageMermaid(i)}h(!1)}},type:"button",children:"Save changes"})})]})]})};function kh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function jh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$3(),i=n.Ht(s,n.O.name),o=n.v$1(n.O.name),l=(0,x.useMemo)(()=>function(e,t){return[...sh(e,t),{type:"edit",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.O.name}(e))return i=!0,!1}),i},children:l?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l?.map((e,t)=>"edit"===e.type&&i?.src?(0,w.jsx)(vh,{attrs:i,editor:s,extension:o},`bubbleMenu-mermaid-${t}`):(0,w.jsx)(kh,{editor:s,item:e},`bubbleMenu-mermaid-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function Sh({hiddenActions:e=[]}){const{t:t}=n._(),r=n.m$2(),s=n.d$3(),i=t=>e.includes(t);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:({editor:e})=>(0,b.isActive)(e.view.state,n.st.name),children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!i("addColumnBefore")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addColumnBefore().run()},disabled:!s?.can()?.addColumnBefore?.(),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!i("addColumnAfter")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addColumnAfter().run()},disabled:!s?.can()?.addColumnAfter?.(),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!i("deleteColumn")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteColumn().run()},disabled:!s?.can().deleteColumn?.(),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("addRowAbove")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addRowBefore().run()},disabled:!s?.can().addRowBefore?.(),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!i("addRowBelow")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addRowAfter().run()},disabled:!s?.can()?.addRowAfter?.(),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!i("deleteRow")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteRow().run()},disabled:!s?.can()?.deleteRow?.(),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("mergeCells")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().mergeCells().run()},disabled:!s?.can()?.mergeCells?.(),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!i("splitCells")&&(0,w.jsx)(n.f$2,{action:function(){s?.chain().focus().splitCell().run()},disabled:!s?.can()?.splitCell?.(),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("deleteTable")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteTable().run()},disabled:!s?.can()?.deleteTable?.(),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):(0,w.jsx)(w.Fragment,{})}function Ch(){const{t:e}=n._(),[t,r]=(0,x.useState)(!1),s=n.d$3(),i=(0,x.useMemo)(()=>n.a({t:e})?.[0]?.commands,[e]),o=(0,x.useMemo)(()=>i?.find(e=>e?.isActive?.(s))?.label,[s.state.selection.ranges,t,s,i,e]),l=(0,x.useMemo)(()=>i?.find(e=>e?.isActive?.(s)),[s.state.selection.ranges,t,s,i]);return(0,w.jsxs)(n.i$2,{modal:!0,onOpenChange:r,open:t,children:[(0,w.jsx)(n.o$1,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,w.jsx)(n.f$2,{dataState:!!o,tooltip:o||e("editor.paragraph.tooltip"),children:(0,w.jsx)(n.c,{name:l?.iconName||"Type"})})}),(0,w.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:i?.map(t=>{const i=t?.isActive?.(s);return(0,w.jsxs)("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-1.5 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:e=>{e.preventDefault(),t.action({editor:s,range:s.state.selection.ranges}),r(!1)},children:[(0,w.jsxs)("div",{className:"!richtext-min-w-[16px]",children:[i&&(0,w.jsx)(v.Check,{size:16}),!o&&t.label===e("editor.paragraph.tooltip")&&!i&&(0,w.jsx)(v.Check,{size:16})]}),(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[t.iconName&&(0,w.jsx)(n.c,{className:"!richtext-mr-1 !richtext-text-lg",name:t.iconName}),t.label]})]},t.name)})})]})}function Nh(){const e=n.d$3();return(t=e)&&"function"==typeof t.commands.openAiMenu?(0,w.jsx)(n.f$2,{action:()=>e.commands.openAiMenu(),shortcutKeys:["mod","J"],tooltip:"Ask AI",children:(0,w.jsx)(v.Sparkles,{className:"richtext-size-4 richtext-text-violet-600"})}):null;var t}function Eh(){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Nh,{}),(0,w.jsx)(Ch,{}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.h$4,{}),(0,w.jsx)(n.y$1,{}),(0,w.jsx)(n.d$1,{}),(0,w.jsx)(n.m$1,{}),(0,w.jsx)(n.Be,{}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.h$3,{}),(0,w.jsx)(n.M$1,{}),(0,w.jsx)(n.A$1,{})]})}function Ah({buttonBubble:e}){const t=n.d$3();return n.m$2()?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:n,to:r}=t;return!e.isActive("codeBlock")&&n.pos!==r&&"closed"===Se(e.view.state)?.panel.status&&t instanceof y.TextSelection},children:e?(0,w.jsx)(w.Fragment,{children:e}):(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(Eh,{})})}):(0,w.jsx)(w.Fragment,{})}function Th(){const{t:e}=n._(),t=n.m$2(),r=n.d$3(),[s,i]=(0,x.useState)(!1),o=(0,x.useCallback)(({editor:e})=>e.isActive(n.k.name),[]),l=(0,x.useCallback)(()=>Xd(n.k.name,r),[r]);return t?(0,w.jsx)(j.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:(0,w.jsx)(w.Fragment,{children:s?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(n.T$1,{editor:r,onSetLink:e=>{r.commands.updateTweet({src:e}),i(!1)}})}):(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{i(!0)}}),(0,w.jsx)(n.f$2,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):(0,w.jsx)(w.Fragment,{})}function Mh(e){if(!e.length)return S.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(e=>{const n=e.$from.pos,r=e.$from.nodeAfter;r&&t.push(S.Decoration.node(n,n+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),S.DecorationSet.create(n,t)}function _h(e,t,n,r={}){const s=[],i=e.node(0),{extendOnBoundaryOverlap:o=!0}=r;"number"==typeof n&&n>=0||(n=e.sameParent(t)?Math.max(0,e.sharedDepth(t.pos)-1):e.sharedDepth(t.pos));const l=new C.NodeRange(e,t,n),a=0===l.depth?0:i.resolve(l.start).posAtIndex(0);return l.parent.forEach((n,r)=>{const c=a+r,d=c+n.nodeSize,h=function(e,t,n){const r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}(c,n.nodeSize,n),u=o?t.pos>=h.start&&e.pos<=h.end:t.pos>h.start&&e.pos<h.end;if(c<l.start||c>=l.end)return;if(!u)return;const p=new y.SelectionRange(i.resolve(c),i.resolve(d));s.push(p)}),s}var Dh=class e{constructor(e,t,n){this.anchor=e,this.head=t,this.depth=null!=n?n:0}map(t){return new e(t.map(this.anchor),t.map(this.head),this.depth)}resolve(e){return new Oh(e.resolve(this.anchor),e.resolve(this.head),this.depth)}},Oh=class e extends y.Selection{constructor(e,t,n,r=1){const{doc:s}=e,i=e===t,o=e.pos===s.content.size&&t.pos===s.content.size,l=i&&!o?s.resolve(t.pos+(r>0?1:-1)):t,a=i&&o?s.resolve(e.pos-(r>0?1:-1)):e,c=_h(a.min(l),a.max(l),n);super(l.pos>=e.pos?c[0].$from:c[c.length-1].$to,l.pos>=e.pos?c[c.length-1].$to:c[0].$from,c),this.depth=n}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof e&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const r=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new e(r,s,this.depth)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head,depth:this.depth}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const t=this.ranges.slice(0,-1),n=t[0].$from,r=t[t.length-1].$to;return new e(n,r,this.depth)}const n=this.ranges[0],r=t.resolve(Math.max(0,n.$from.pos-1));return new e(this.$anchor,r,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const t=this.ranges.slice(1),n=t[0].$from,r=t[t.length-1].$to;return new e(r,n,this.depth)}const n=this.ranges[this.ranges.length-1],r=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new e(this.$anchor,r,this.depth)}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head),n.depth)}static create(e,t,n,r,s=1){return new this(e.resolve(t),e.resolve(n),r,s)}getBookmark(){return new Dh(this.anchor,this.head,this.depth)}};Oh.prototype.visible=!1;try{y.Selection.jsonID("nodeRange",Oh)}catch{}function $h(e){return e instanceof Oh}b.Extension.create({name:"nodeRange",addOptions:()=>({depth:void 0,key:"Mod"}),addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,selection:i,tr:o}=r,{anchor:l,head:a}=i;if(!$h(i)){const e=Oh.create(s,l,a,t,-1);return o.setSelection(e),n.dispatch(o),!0}const c=i.extendBackwards();return o.setSelection(c),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,selection:i,tr:o}=r,{anchor:l,head:a}=i;if(!$h(i)){const e=Oh.create(s,l,a,t);return o.setSelection(e),n.dispatch(o),!0}const c=i.extendForwards();return o.setSelection(c),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,tr:i}=r,o=Oh.create(s,0,s.content.size,t);return i.setSelection(o),n.dispatch(i),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$h(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new y.Plugin({key:new y.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(e,n)=>{const{key:r}=this.options,s=/Mac/.test(navigator.platform),i=!!n.shiftKey,o=!!n.ctrlKey,l=!!n.altKey,a=!!n.metaKey;return(null==r||"Shift"===r&&i||"Control"===r&&o||"Alt"===r&&l||"Meta"===r&&a||"Mod"===r&&(s?a:o))&&(t=!0),!!t&&(document.addEventListener("mouseup",()=>{t=!1;const{state:n}=e,{doc:r,selection:s,tr:i}=n,{$anchor:o,$head:l}=s;if(o.sameParent(l))return;const a=Oh.create(r,o.pos,l.pos,this.options.depth);i.setSelection(a),e.dispatch(i)},{once:!0}),!1)}},decorations:n=>{const{selection:r}=n,s=$h(r);if(e=!1,!t)return s?(e=!0,Mh(r.ranges)):null;const{$from:i,$to:o}=r;if(!s&&i.sameParent(o))return null;const l=_h(i,o,this.options.depth);return l.length?(e=!0,Mh(l)):null}}})]}});var Rh=[{id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},{id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=e.firstChild;return t&&["listItem","taskItem"].includes(t.type.name)?1e3:0}},{id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&"tableHeader"===t.type.name?1e3:0},{id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0}],Ih={edges:["left","top"],threshold:12,strength:500};function Ph(e){return void 0===e||"left"===e?{...Ih}:"right"===e?{edges:["right","top"],threshold:12,strength:500}:"both"===e?{edges:["left","right","top"],threshold:12,strength:500}:"none"===e?{edges:[],threshold:0,strength:0}:{...Ih,...e}}function Lh(e,t,n,r){let s=1e3,i=!1;if(t.every(t=>{const n=t.evaluate(e);return s-=n,!(s<=0&&(i=!0,1))}),i)return-1;const o=e.view.nodeDOM(e.pos);return s-=function(e,t,n,r){return t&&0!==n.edges.length&&function(e,t,n){if(0===n.edges.length)return!1;const r=t.getBoundingClientRect(),{threshold:s,edges:i}=n;return i.some(t=>"left"===t?e.x-r.left<s:"right"===t?r.right-e.x<s:"top"===t?e.y-r.top<s:"bottom"===t&&r.bottom-e.y<s)}(e,t,n)?n.strength*r:0}(r,o,n,e.depth),s<=0?-1:s}function zh(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function Bh(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function Fh(e,t){let n="first"===t?e.firstElementChild:e.lastElementChild;for(;n;){const e=n.getBoundingClientRect();if(Bh(e))return e;n="first"===t?n.nextElementSibling:n.previousElementSibling}return null}var Vh=e=>{const{x:t,y:n,editor:r,nestedOptions:s}=e,{view:i,state:o}=r,l=function(e,t,n,r=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,i=Fh(s,"first"),o=Fh(s,"last");if(!i||!o)return null;const l=Math.min(Math.max(i.top+r,n),o.bottom-r),a=Math.abs(i.left-o.left)<.5,c=Math.abs(i.right-o.right)<.5;let d=i;a&&c&&(d=i);const h=Math.min(Math.max(d.left+r,t),d.right-r);return Number.isFinite(h)&&Number.isFinite(l)?{x:h,y:l}:null}(i,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:a,y:c}=l;if(null==s?void 0:s.enabled){const e=function(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const r=e.posAtCoords({left:t.x,top:t.y});if(!r)return null;const{doc:s}=e.state,i=s.resolve(r.pos),o=[];n.defaultRules&&o.push(...Rh),o.push(...n.rules);const l=Array.from({length:i.depth},(e,t)=>i.depth-t).map(r=>{const s=i.node(r),l=i.before(r);if(n.allowedContainers&&r>0&&!zh(i,r,n.allowedContainers))return null;const a=r>0?i.node(r-1):null,c=r>0?i.index(r-1):0,d=Lh({node:s,pos:l,depth:r,parent:a,index:c,isFirst:0===c,isLast:c===(a?a.childCount:1)-1,$pos:i,view:e},o,n.edgeDetection,t);return d<0?null:{node:s,pos:l,depth:r,score:d,dom:e.nodeDOM(l)}}).filter(e=>null!==e),a=i.nodeAfter;if(a&&a.isAtom&&!a.isInline){const s=r.pos,c=i.depth+1,d=i.parent,h=i.index(),u=d.childCount;let p=!0;if(n.allowedContainers&&(p=zh(i,c,n.allowedContainers)),p){const r=Lh({node:a,pos:s,depth:c,parent:d,index:h,isFirst:0===h,isLast:h===u-1,$pos:i,view:e},o,n.edgeDetection,t);if(r>=0){const t=e.nodeDOM(s);t&&l.push({node:a,pos:s,depth:c,score:r,dom:t})}}}if(0===l.length)return null;l.sort((e,t)=>t.score!==e.score?t.score-e.score:t.depth-e.depth);const c=l[0];return c.dom?{node:c.node,pos:c.pos,dom:c.dom}:null}(i,{x:a,y:c},s);return e?{resultElement:e.dom,resultNode:e.node,pos:e.pos}:{resultElement:null,resultNode:null,pos:null}}const d=i.root.elementsFromPoint(a,c);let h,u;if(Array.prototype.some.call(d,e=>{if(!i.dom.contains(e))return!1;const t=function(e,t){var n;let r=e;for(;(null==r?void 0:r.parentElement)&&r.parentElement!==t.dom;)r=r.parentElement;if((null==r?void 0:r.parentElement)===t.dom&&(null==(n=r.pmViewDesc)?void 0:n.node))return r}(e,i);return!!t&&(h=t,!0)}),!h){const e=i.posAtCoords({left:a,top:c});if(e){const t=o.doc.resolve(e.pos),n=Math.min(t.depth,1),r=n>0?t.before(n):t.pos,s=o.doc.nodeAt(r);if(s){const e=i.nodeDOM(r);return{resultElement:e instanceof HTMLElement?e:null,resultNode:s,pos:r}}}return{resultElement:null,resultNode:null,pos:null}}try{u=i.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(u);if(!p){const e=o.doc.resolve(u),t=e.parent;return{resultElement:h,resultNode:t,pos:e.start()}}return{resultElement:h,resultNode:p,pos:u}};function Wh(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:r,offset:s}=e.domAtPos(t),i=r.childNodes[s];return i instanceof Element?i:r instanceof Element?r:r.nodeType===Node.TEXT_NODE&&r.parentElement?r.parentElement:null}function qh(e){var t;null==(t=e.parentNode)||t.removeChild(e)}function Hh(e,t,n,r,s){const{view:i}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:a}=i.state.selection,c=function(e,t,n,r){const{doc:s}=t.view.state;if((null==n?void 0:n.enabled)&&(null==r?void 0:r.node)&&r.pos>=0){const e=r.pos,t=r.pos+r.node.nodeSize;return[{$from:s.resolve(e),$to:s.resolve(t)}]}const i=Vh({editor:t,x:e.clientX,y:e.clientY,direction:"right",nestedOptions:n});if(!i.resultNode||null===i.pos)return[];const o=i.resultNode.isText||i.resultNode.isAtom?0:-1;return _h(s.resolve(i.pos),s.resolve(i.pos+i.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}(e,t,n,r),d=_h(l,a,0,{extendOnBoundaryOverlap:!1}),h=d.some(e=>c.find(t=>t.$from===e.$from&&t.$to===e.$to)),u=o||!h?c:d;if(!u.length)return;const{tr:p}=i.state,m=document.createElement("div"),f=u[0].$from.pos,g=u[u.length-1].$to.pos,x=function(e,t){const n=Wh(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}(i,f);m.setAttribute("dir",x);const b=(null==n?void 0:n.enabled)&&(null==r?void 0:r.node),w=1===u.length;let v,k;b&&w?(v=i.state.doc.slice(f,g),k=y.NodeSelection.create(i.state.doc,f)):(k=Oh.create(i.state.doc,f,g),v=k.content());const j=function(e){return!e||!e.some(e=>{const t=e.trim().toLowerCase();return"margin"===t||t.startsWith("margin-")})}(s);u.forEach(e=>{const t=Wh(i,e.$from.pos);if(!t)return;const n=function(e,t){const n=e.cloneNode(!0),r=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return r.forEach((e,n)=>{s[n].style.cssText=function(e,t){const n=getComputedStyle(e);if(t)return t.map(e=>e.trim()).filter(e=>e.length>0).map(e=>`${e}:${n.getPropertyValue(e)};`).join("");let r="";for(let s=0;s<n.length;s+=1)r+=`${n[s]}:${n.getPropertyValue(n[s])};`;return r}(e,t)}),n}(t,s);j&&(n.style.margin="0"),m.append(n)}),m.style.position="absolute",m.style.top="-10000px",document.body.append(m),e.dataTransfer.clearData();const S=function(e,t){return"rtl"===e?t:0}(x,m.getBoundingClientRect().width);e.dataTransfer.setDragImage(m,S,0);let C=!1;const N=()=>{C||(C=!0,qh(m),document.removeEventListener("drop",N),document.removeEventListener("dragend",N))},E=k instanceof y.NodeSelection?k:void 0;i.dragging={slice:v,move:!0,node:E},p.setSelection(k),i.dispatch(p),document.addEventListener("drop",N),document.addEventListener("dragend",N)}var Uh=(e,t)=>{const n=e.resolve(t),{depth:r}=n;return 0===r?t:n.pos-n.parentOffset-1},Jh=(e,t)=>{const n=e.nodeAt(t),r=e.resolve(t);let{depth:s}=r,i=n;for(;s>0;){const e=r.node(s);s-=1,0===s&&(i=e)}return i};function Kh(e,t,n){let r=0;for(let s=t;s<n;s+=1)r+=e.child(s).nodeSize;return r}var Gh=(e,t)=>{const n=ld.getState(e);return n?zd(t,n.type,n.binding.mapping):null},Xh=(e,t)=>{const n=ld.getState(e);return n?Fd(n.doc,n.type,t,n.binding.mapping)||0:-1},Yh=(e,t)=>{let n=t;for(;(null==n?void 0:n.parentNode)&&n.parentNode!==e.dom;)n=n.parentNode;return n},Zh=new y.PluginKey("dragHandle"),Qh=({pluginKey:e=Zh,element:t,editor:r,computePositionConfig:s,getReferencedVirtualElement:i,onNodeChange:o,onElementDragStart:l,onElementDragEnd:a,nestedOptions:c,dragImageProperties:d})=>{const h=document.createElement("div");let u,p=!1,m=null,f=-1,g=null,x=null,w=null,v=null;function k(){w=null,v=null}function j(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function S(e){const r=(null==i?void 0:i())||{getBoundingClientRect:()=>e.getBoundingClientRect()};n.xt(r,t,s).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function C(e){var n,s;l?.(e),Hh(e,r,c,{node:m,pos:f},d),n=r.state.selection,w=$h(n)?{anchorPos:n.from,nodeCount:n.ranges.length,depth:null!=(s=n.depth)?s:0}:null,t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function N(e){a?.(e),w=null,j(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function E(e){if(!e.target||!r.view.dom.contains(e.target))return;if((0,b.isFirefox)()){const e=r.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable="false",e.contentEditable="true")})}if(!w||r.view.state.selection.empty)return;const t=r.state.selection.from,n=Gh(r.state,t);v={...w,anchorPos:t,relativeAnchorPos:null!=n?n:void 0},r.view.dispatch(r.state.tr.setMeta("addToHistory",!1))}function A(){t.removeEventListener("dragstart",C),t.removeEventListener("dragend",N),document.removeEventListener("drop",E),g&&(cancelAnimationFrame(g),g=null,x=null),k()}return h.appendChild(t),{unbind(){A()},plugin:new y.Plugin({key:"string"==typeof e?new y.PluginKey(e):e,state:{init:()=>({locked:!1}),apply(e,n,s,i){!function(e,t){v&&(v=function(e,t,n){if(!t.docChanged)return e;if(n.isChangeOrigin&&null!=e.relativeAnchorPos){const t=n.getAbsolutePos(e.relativeAnchorPos);return!Number.isFinite(t)||t<=0?null:{...e,anchorPos:t}}const r=t.mapping.mapResult(e.anchorPos,1);return r.deleted?null:{...e,anchorPos:r.pos}}(v,e,{isChangeOrigin:Ud(e),getAbsolutePos:e=>Xh(t,e)}))}(e,i);const l=e.getMeta("lockDragHandle"),a=e.getMeta("hideDragHandle");if(void 0!==l&&(p=l),a)return j(),p=!1,m=null,f=-1,o?.({editor:r,node:null,pos:-1}),n;if(e.docChanged&&-1!==f&&t)if(Ud(e)){const e=Xh(i,u);e!==f&&(f=e)}else{const t=e.mapping.map(f);t!==f&&(f=t,u=Gh(i,f))}return n}},appendTransaction:(e,t,n)=>function(e){if(!v)return null;const t=function(e,t,n,r){try{const s=function(e,t,n,r){const s=e.resolve(t),i=s.node(r);let o=s.index(r);o>=i.childCount&&(o=Math.max(0,i.childCount-n));const l=Math.min(n,i.childCount-o);if(l<=0)return null;const a=s.start(r)+Kh(i,0,o);return{anchor:a,head:a+Kh(i,o,o+l),count:l}}(e,t,n,r);if(!s)return null;const i=Oh.create(e,s.anchor,s.head,r);return i.ranges.length===n?i:null}catch{return null}}(e.doc,v.anchorPos,v.nodeCount,v.depth);return t?(k(),e.tr.setSelection(t)):(v=null,w=null,null)}(n),view:e=>{var n;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",null==(n=r.view.dom.parentElement)||n.appendChild(h),h.style.pointerEvents="none",h.style.position="absolute",h.style.top="0",h.style.left="0",h.style.zIndex="10",t.addEventListener("dragstart",C),t.addEventListener("dragend",N),document.addEventListener("drop",E),{update(n,s){if(!t)return;if(!r.isEditable)return void j();if(t.draggable=!p,e.state.doc.eq(s.doc)||-1===f)return;let i=e.nodeDOM(f);if(i=Yh(e,i),i===e.dom)return;if(1!==(null==i?void 0:i.nodeType))return;const l=e.posAtDOM(i,0),a=Jh(r.state.doc,l),c=Uh(r.state.doc,l);m=a,f=c,u=Gh(e.state,f),o?.({editor:r,node:m,pos:f}),S(i)},destroy(){A(),t&&qh(h)}}},props:{handleDOMEvents:{keydown:e=>!(!t||p||!e.hasFocus()||(j(),m=null,f=-1,o?.({editor:r,node:null,pos:-1}),1)),mouseleave:(e,t)=>(p||t.target&&!h.contains(t.relatedTarget)&&(j(),m=null,f=-1,o?.({editor:r,node:null,pos:-1})),!1),mousemove:(e,n)=>!(!t||p||(x={x:n.clientX,y:n.clientY},g||(g=requestAnimationFrame(()=>{if(g=null,!x)return;const{x:n,y:s}=x;x=null;const i=Vh({x:n,y:s,direction:"right",editor:r,nestedOptions:c});if(!i.resultElement)return;let l=i.resultElement,a=i.resultNode,d=i.pos;if(!(null==c?void 0:c.enabled)){if(l=Yh(e,l),l===e.dom)return;if(1!==(null==l?void 0:l.nodeType))return;const t=e.posAtDOM(l,0);a=Jh(r.state.doc,t),d=Uh(r.state.doc,t)}a!==m&&(m=a,f=null!=d?d:-1,u=Gh(e.state,f),o?.({editor:r,node:m,pos:f}),S(l),t&&(r.isEditable?(t.style.visibility="",t.style.pointerEvents="auto"):j()))})),1))}}})}};function eu(e){var t,n;return!1===e||void 0===e?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ph("none")}:!0===e?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ph("left")}:{enabled:!0,rules:null!=(t=e.rules)?t:[],defaultRules:null==(n=e.defaultRules)||n,allowedContainers:e.allowedContainers,edgeDetection:Ph(e.edgeDetection)}}var tu={placement:"left-start",strategy:"absolute"},nu=(b.Extension.create({name:"dragHandle",addOptions:()=>({render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}),addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=eu(this.options.nested);return[Qh({computePositionConfig:{...tu,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}}),e=>{const{className:t="drag-handle",children:n,editor:r,pluginKey:s=Zh,onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a,computePositionConfig:c=tu,nested:d=!1}=e,h=(0,x.useRef)(null);null===h.current&&"undefined"!=typeof document&&(h.current=document.createElement("div"));const u=(0,x.useMemo)(()=>eu(d),[JSON.stringify(d)]);(0,x.useEffect)(()=>{const e=h.current;e&&(e.className=t)},[t]),(0,x.useEffect)(()=>{if("undefined"==typeof document)return;if(r.isDestroyed)return;const e=h.current;if(!e)return;e.style.visibility="hidden",e.style.position="absolute",e.dataset.dragging="false";const{plugin:t,unbind:n}=Qh({editor:r,element:e,pluginKey:s,computePositionConfig:{...tu,...c},onElementDragStart:o,onElementDragEnd:l,onNodeChange:i,getReferencedVirtualElement:a,nestedOptions:u});return r.registerPlugin(t),()=>{r.isDestroyed||r.unregisterPlugin(s),n()}},[r,i,a,s,c,o,l,u]);const p=h.current;return p?(0,k.createPortal)(n,p):null});function ru(){const e=n.d$3(),t=n.m$2(),{t:r}=n._(),[s,i]=(0,x.useState)(null),[o,l]=(0,x.useState)(-1),[a,c]=(0,x.useState)(!1),d=e?.extensionManager?.extensions?.some(e=>e?.name===n.y.name),h=e?.extensionManager?.extensions?.some(e=>e?.name===n.h$2.name),u=e?.extensionManager?.extensions?.some(e=>e?.name===n.c$1.name);function p(t){e.commands.setTextAlign(t)}const m=(0,x.useCallback)(e=>{e.node&&i(e.node),l(e.pos),requestAnimationFrame(()=>{e.editor.commands.focus()})},[]);(0,x.useEffect)(()=>(a?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[a]);const f=e=>{t&&c(e)};return(0,w.jsx)(nu,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:m,pluginKey:"RichTextBubbleMenuDragHandle",children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,w.jsx)(n.f$2,{disabled:!t,icon:"Grip",tooltip:r("editor.draghandle.grip"),action:e=>{e.preventDefault(),e.stopPropagation(),f(!a)}}),(0,w.jsxs)(n.d$2,{onOpenChange:f,open:a,children:[(0,w.jsx)(n.x,{className:"richtext-pointer-events-none"}),(0,w.jsxs)(n.u$2,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:function(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()},children:[(0,w.jsx)(n.c,{name:"Trash2"}),(0,w.jsx)("span",{children:r("editor.remove")})]}),u?(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",onClick:function(){const t=e.chain();t.setNodeSelection(o).unsetAllMarks(),"paragraph"!==s?.type.name&&t.setParagraph(),t.run()},children:[(0,w.jsx)(n.c,{name:"PaintRoller"}),(0,w.jsx)("span",{children:r("editor.clear.tooltip")})]}):null,(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",onClick:function(){e.commands.setNodeSelection(o);const{$anchor:t}=e.state.selection,n=t.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+(s?.nodeSize||0),n.toJSON()).run()},children:[(0,w.jsx)(n.c,{name:"Copy"}),(0,w.jsx)("span",{children:r("editor.copy")})]}),d||h?(0,w.jsx)(n.v,{}):null,d?(0,w.jsxs)(n.l$1,{children:[(0,w.jsxs)(n.p$2,{className:"richtext-flex richtext-gap-3",children:[(0,w.jsx)(n.c,{name:"AlignCenter"}),(0,w.jsx)("span",{children:r("editor.textalign.tooltip")})]}),(0,w.jsx)(n.n$5,{children:(0,w.jsxs)(n.f$1,{children:[(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",onClick:()=>p("left"),children:[(0,w.jsx)(n.c,{name:"AlignLeft"}),(0,w.jsx)("span",{children:r("editor.textalign.left.tooltip")})]}),(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",onClick:()=>p("center"),children:[(0,w.jsx)(n.c,{name:"AlignCenter"}),(0,w.jsx)("span",{children:r("editor.textalign.center.tooltip")})]}),(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",onClick:()=>p("right"),children:[(0,w.jsx)(n.c,{name:"AlignRight"}),(0,w.jsx)("span",{children:r("editor.textalign.right.tooltip")})]})]})})]}):null,h?(0,w.jsxs)(n.l$1,{children:[(0,w.jsxs)(n.p$2,{className:"richtext-flex richtext-gap-3",children:[(0,w.jsx)(n.c,{name:"IndentIncrease"}),(0,w.jsx)("span",{children:r("editor.indent")})]}),(0,w.jsx)(n.n$5,{children:(0,w.jsxs)(n.f$1,{children:[(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",disabled:s?.attrs?.indent>=n.u.max,onClick:function(){const t=n.p(e.state.tr,o,1);t.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(t)},children:[(0,w.jsx)(n.c,{name:"IndentIncrease"}),(0,w.jsx)("span",{children:r("editor.indent.tooltip")})]}),(0,w.jsxs)(n.b$1,{className:"richtext-flex richtext-gap-3",disabled:s?.attrs?.indent<=n.u.min,onClick:function(){const t=n.p(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(t)},children:[(0,w.jsx)(n.c,{name:"IndentDecrease"}),(0,w.jsx)("span",{children:r("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}var su={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function iu({listLanguages:e}){const{t:t}=n._(),[r,s]=(0,x.useState)(!1),i=n.d$3(),o=(0,x.useMemo)(()=>{const{selection:e}=i.state,t=e.$from.parent;if("codeBlock"===t.type.name){const e=t.attrs.language||"plaintext";return su[e]||e}},[i.state,e]),l=(0,x.useMemo)(()=>{let t=e||[];return e?.includes("plaintext")||(t=["plaintext",...t]),t.map(e=>({label:su[e]||e,value:e}))},[e]);return(0,w.jsxs)(n.i$2,{modal:!0,onOpenChange:s,open:r,children:[(0,w.jsx)(n.o$1,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,w.jsxs)(n.f$2,{dataState:!!o,children:[(0,w.jsx)(w.Fragment,o?{children:o}:{children:t("editor.paragraph.tooltip")}),(0,w.jsx)(n.c,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),(0,w.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:l?.map(e=>(0,w.jsxs)("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:t=>{t.preventDefault(),i.chain().focus().setCodeBlock({language:e.value}).run(),s(!1)},children:[(0,w.jsx)("div",{className:"!richtext-min-w-[20px]",children:o===e.value&&(0,w.jsx)(v.Check,{size:16})}),(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:e.label})]},e.value))})]})}function ou(){const e=n.m$2(),t=n.d$3(),r=n.v$1(n.M$2.name),s=(0,x.useCallback)(({editor:e})=>e.isActive(n.M$2.name),[]),i=(0,x.useMemo)(()=>r?r.options?.lowlight?.listLanguages?.()||["plaintext","html","css","js","ts"]:[],[r]),o=(0,x.useCallback)(()=>Xd(n.M$2.name,t),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:s,getReferencedVirtualElement:()=>{const{from:e}=t.state.selection,n=t.view.domAtPos(e).node.parentElement;return n?{getBoundingClientRect:()=>n.getBoundingClientRect()}:null},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(iu,{listLanguages:i}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.f$2,{action:()=>{const e=(()=>{const{from:e}=t.state.selection,n=t.state.doc.resolve(e);for(let t=n.depth;t>=0;t--){const e=n.node(t);if("codeBlock"===e.type.name)return e.textContent}return""})();navigator.clipboard.writeText(e)},tooltip:"Copy",children:(0,w.jsx)(v.Copy,{size:16})}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,w.jsx)(v.Trash2,{size:16})})]})}):(0,w.jsx)(w.Fragment,{})}var lu=()=>(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Zd,{}),(0,w.jsx)(Qd,{}),(0,w.jsx)(hh,{}),(0,w.jsx)(ph,{}),(0,w.jsx)(fh,{}),(0,w.jsx)(xh,{}),(0,w.jsx)(yh,{}),(0,w.jsx)(bh,{}),(0,w.jsx)(jh,{}),(0,w.jsx)(Sh,{}),(0,w.jsx)(Ah,{}),(0,w.jsx)(Th,{}),(0,w.jsx)(ou,{}),(0,w.jsx)(ru,{}),(0,w.jsx)(n.D,{}),(0,w.jsx)(V,{})]});Object.defineProperty(exports,"BubbleMenus",{enumerable:!0,get:function(){return lu}}),Object.defineProperty(exports,"RichTextToolbar",{enumerable:!0,get:function(){return ae}});
|
|
1
|
+
const e=require("./rolldown-runtime-BeavJI0R.cjs"),t=require("./dist-2-kjLBhJ.cjs"),n=require("./editorConfig-BAZYamPM.cjs"),r=require("./toggle-JU5XOZYT.cjs"),s=require("./locales-DRkmn37v.cjs"),i=require("./floating-ui.dom-DG-jWCyc.cjs"),o=require("./useButtonProps-BBiR6DPI.cjs"),l=require("./theme.cjs"),a=require("./cdn-loader-BGIuN138-7PrAg-Ef.cjs"),c=require("./Harper-nz_06NJH.cjs"),d=require("./Ai-CfgczVyp.cjs"),h=require("./Drawio-CD_Tea_o.cjs"),u=require("./ReadAloud.cjs"),p=require("./Transcribe.cjs"),m=require("./SelectSimilar.cjs"),f=require("./WordCount.cjs");let g=require("@tiptap/react"),x=require("react");x=e.__toESM(x,1);let b=require("@tiptap/core"),y=require("@tiptap/pm/state"),w=require("react/jsx-runtime"),v=require("lucide-react"),k=require("react-dom"),j=require("@tiptap/react/menus"),S=require("@tiptap/pm/view"),C=require("@tiptap/pm/model"),N=require("use-voice-control/react"),E=require("easydrawer"),A=require("@tiptap/pm/commands"),T=require("use-voice-control/client");function M({children:e,label:n,className:r,icon:s,shortcut:i}){const o=(0,x.useRef)(null),l=(0,x.isValidElement)(e)?(0,x.cloneElement)(e,{tooltip:n?void 0:e.props?.tooltip,tooltipOptions:n?void 0:e.props?.tooltipOptions}):e;return(0,w.jsxs)("div",{ref:o,className:t.cn("flex items-center gap-2 px-2 py-0.5 rounded cursor-pointer w-full text-left","hover:bg-gray-100/80 dark:hover:bg-slate-800/80","transition-colors",r),onClick:e=>{e.stopPropagation(),e.target.closest('button, [role="button"], a')||(o.current?.querySelector("button"))?.click()},children:[s&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:s}),(0,w.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[l,n&&(0,w.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:n}),i&&(0,w.jsx)("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 ml-auto whitespace-nowrap shrink-0",children:i})]})]})}function _(){const e=o.useButtonProps("subscript"),{icon:t,tooltip:n,shortcutKeys:s,tooltipOptions:i={},action:l,isActive:a}=e?.componentProps??{},{dataState:c,disabled:d,update:h}=o.useToggleActive(a);return e?(0,w.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,w.jsx)(w.Fragment,{})}function D(){const e=o.useButtonProps("superscript"),{icon:t,tooltip:n,shortcutKeys:s,tooltipOptions:i={},action:l,isActive:a}=e?.componentProps??{},{dataState:c,disabled:d,update:h}=o.useToggleActive(a);return e?(0,w.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,w.jsx)(w.Fragment,{})}function O({message:e}){const[t,n]=(0,x.useState)(!0);return(0,x.useEffect)(()=>{const e=setTimeout(()=>n(!1),2e3);return()=>clearTimeout(e)},[]),t?(0,k.createPortal)((0,w.jsx)("div",{className:"fixed bottom-4 right-4 z-[100] animate-in fade-in slide-in-from-bottom-2",children:(0,w.jsx)("div",{className:"bg-gray-900 dark:bg-gray-800 text-white px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium",children:e})}),document.body):null}function $(){const{editor:e}=(0,g.useCurrentEditor)(),[t,n]=(0,x.useState)(1.25),[r,s]=(0,x.useState)(null),i=e=>{s(e)},o=(0,x.useCallback)(t=>{const n=e?.view?.dom??document.querySelector(".ProseMirror");if(!n)return;const r=n;r.style.zoom=String(t),r.style.transform="",r.style.transformOrigin=""},[e]);return(0,x.useEffect)(()=>{o(t)},[o,t]),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,w.jsx)("button",{onClick:()=>{const e=Math.max(t-.25,.5);n(e),o(e),i(`Zoom: ${Math.round(100*e)}%`)},title:`Zoom Out (${Math.round(100*t)}%)`,className:"richtext-p-1 richtext-h-8 richtext-flex richtext-items-center richtext-justify-center richtext-rounded text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white transition-colors",children:(0,w.jsx)(v.ZoomOut,{size:16})}),(0,w.jsx)("button",{onClick:()=>{const e=Math.min(t+.25,2);n(e),o(e),i(`Zoom: ${Math.round(100*e)}%`)},title:`Zoom In (${Math.round(100*t)}%)`,className:"richtext-p-1 richtext-h-8 richtext-flex richtext-items-center richtext-justify-center richtext-rounded text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white transition-colors",children:(0,w.jsx)(v.ZoomIn,{size:16})})]}),r&&(0,w.jsx)(O,{message:r})]})}var R={a4:{name:"A4",pageHeight:1123,pageWidth:794,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},a3:{name:"A3",pageHeight:1591,pageWidth:1123,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},letter:{name:"Letter",pageHeight:1100,pageWidth:850,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72},legal:{name:"Legal",pageHeight:1400,pageWidth:850,marginTop:72,marginBottom:72,marginLeft:72,marginRight:72}};function I(){const{editor:e}=(0,g.useCurrentEditor)(),[t,n]=(0,x.useState)(!1),[r,s]=(0,x.useState)("page"),[i,o]=(0,x.useState)({pageHeight:1056,pageWidth:816,pageGap:50,pageGapBorderSize:1,pageGapBorderColor:"#e5e5e5",pageBreakBackground:"#ffffff",marginTop:48,marginBottom:48,marginLeft:72,marginRight:72,contentMarginTop:10,contentMarginBottom:10,headerLeft:"",headerRight:"Page {page}",footerLeft:"",footerRight:""}),l=(0,x.useRef)(null),a=(0,x.useRef)(null),[c,d]=(0,x.useState)({top:0,left:-9999,visibility:"hidden"});if((0,x.useEffect)(()=>{if(!t)return;const e=e=>{const t=e.target;t?.isConnected&&(l.current?.contains(t)||a.current?.contains(t)||n(!1))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t]),(0,x.useLayoutEffect)(()=>{if(!t)return;const e=()=>{const e=a.current,t=l.current;if(!e||!t)return;const n=window.innerWidth,r=window.innerHeight,s=t.getBoundingClientRect(),i=t.closest(".dropdown-portal")?.getBoundingClientRect()??s,{offsetWidth:o,offsetHeight:c}=e;let h=i.right+8;h+o>n-8&&(h=i.left-o-8),h=Math.max(8,Math.min(h,n-o-8));const u=Math.max(8,Math.min(s.top,r-c-8));d({top:u,left:h,maxHeight:r-u-8})};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[t,r]),!e)return null;const h=t=>{const n={...i,...t};o(n),t.pageHeight&&e.commands.updatePageHeight?.(t.pageHeight),t.pageWidth&&e.commands.updatePageWidth?.(t.pageWidth),t.pageGap&&e.commands.updatePageGap?.(t.pageGap),(t.marginTop||t.marginBottom||t.marginLeft||t.marginRight)&&e.commands.updateMargins?.({top:t.marginTop??i.marginTop,bottom:t.marginBottom??i.marginBottom,left:t.marginLeft??i.marginLeft,right:t.marginRight??i.marginRight}),(t.contentMarginTop||t.contentMarginBottom)&&e.commands.updateContentMargins?.({top:t.contentMarginTop??i.contentMarginTop,bottom:t.contentMarginBottom??i.contentMarginBottom}),(t.headerLeft||t.headerRight)&&e.commands.updateHeaderContent?.(t.headerLeft??i.headerLeft,t.headerRight??i.headerRight),(t.footerLeft||t.footerRight)&&e.commands.updateFooterContent?.(t.footerLeft??i.footerLeft,t.footerRight??i.footerRight),t.pageBreakBackground&&e.commands.updatePageBreakBackground?.(t.pageBreakBackground)};return(0,w.jsxs)("div",{className:"relative",ref:l,children:[(0,w.jsxs)("button",{onClick:()=>n(!t),className:"flex items-center gap-1 px-2 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-800 rounded transition-colors",title:"Page settings",children:[(0,w.jsx)(v.Settings,{className:"w-4 h-4"}),(0,w.jsx)(v.ChevronDown,{className:"w-3 h-3"})]}),t&&(0,k.createPortal)((0,w.jsxs)("div",{ref:a,"data-richtext-portal":!0,className:"dropdown-portal fixed flex flex-col overflow-hidden bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg shadow-2xl z-50 w-96 max-w-[calc(100vw-16px)]",style:c,children:[(0,w.jsx)("div",{className:"flex border-b dark:border-gray-700 shrink-0",children:["page","spacing","header-footer"].map(e=>(0,w.jsxs)("button",{onClick:()=>s(e),className:"flex-1 px-3 py-2 text-sm font-medium transition-colors "+(r===e?"border-b-2 border-blue-500 text-blue-600 dark:text-blue-400":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200"),children:["page"===e&&"Page","spacing"===e&&"Spacing","header-footer"===e&&"Header/Footer"]},e))}),(0,w.jsxs)("div",{className:"flex-1 min-h-0 p-4 space-y-4 overflow-y-auto",children:["page"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-2 text-gray-700 dark:text-gray-300",children:"Presets"}),(0,w.jsx)("div",{className:"grid grid-cols-4 gap-2",children:Object.entries(R).map(([e,t])=>(0,w.jsx)("button",{onClick:()=>(e=>{h({pageHeight:e.pageHeight,pageWidth:e.pageWidth,marginTop:e.marginTop,marginBottom:e.marginBottom,marginLeft:e.marginLeft,marginRight:e.marginRight})})(t),className:"px-2 py-1 text-xs bg-gray-50 dark:bg-gray-800 border dark:border-gray-700 rounded hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:t.name},e))})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Height (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageHeight,onChange:e=>h({pageHeight:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:400,max:2e3})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Width (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageWidth,onChange:e=>h({pageWidth:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:400,max:2e3})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Gap (px)"}),(0,w.jsx)("input",{type:"number",value:i.pageGap,onChange:e=>h({pageGap:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:100})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Gap Border Color"}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsx)("input",{type:"color",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"w-10 h-9 rounded cursor-pointer"}),(0,w.jsx)("input",{type:"text",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"flex-1 px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"})]})]})]}),"spacing"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Page Margins (px)"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,w.jsx)("input",{type:"number",value:i.marginTop,onChange:e=>h({marginTop:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,w.jsx)("input",{type:"number",value:i.marginBottom,onChange:e=>h({marginBottom:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Left"}),(0,w.jsx)("input",{type:"number",value:i.marginLeft,onChange:e=>h({marginLeft:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Right"}),(0,w.jsx)("input",{type:"number",value:i.marginRight,onChange:e=>h({marginRight:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:200})]})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Content Margins (px)"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,w.jsx)("input",{type:"number",value:i.contentMarginTop,onChange:e=>h({contentMarginTop:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:50})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,w.jsx)("input",{type:"number",value:i.contentMarginBottom,onChange:e=>h({contentMarginBottom:Number(e.target.value)}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100",min:0,max:50})]})]})]})]}),"header-footer"===r&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Header Left (supports HTML)"}),(0,w.jsx)("textarea",{value:i.headerLeft,onChange:e=>h({headerLeft:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., <strong>Company Name</strong>"})]}),(0,w.jsxs)("div",{children:[(0,w.jsxs)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:["Header Right (use ","{page}"," for page number)"]}),(0,w.jsx)("textarea",{value:i.headerRight,onChange:e=>h({headerRight:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., Page {page}"})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Footer Left (supports HTML)"}),(0,w.jsx)("textarea",{value:i.footerLeft,onChange:e=>h({footerLeft:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., <em>Confidential</em>"})]}),(0,w.jsxs)("div",{children:[(0,w.jsxs)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:["Footer Right (use ","{page}"," for page number)"]}),(0,w.jsx)("textarea",{value:i.footerRight,onChange:e=>h({footerRight:e.target.value}),className:"w-full px-2 py-1 border dark:border-gray-700 rounded text-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 font-mono",rows:3,placeholder:"e.g., Page {page} of {total}"})]})]})]})]}),document.body)]})}var P=[1,2,3,4];function L({editor:e,onClose:t,defaultLevel:n=3}){const[r,s]=(0,x.useState)([]),[i,o]=(0,x.useState)(""),[l,a]=(0,x.useState)(n),[c,d]=(0,x.useState)(null);(0,x.useEffect)(()=>{if(!e)return;const t=()=>{const t=[];e.state.doc.descendants((e,n)=>{"heading"===e.type.name&&t.push({level:e.attrs.level,text:e.textContent,pos:n,index:t.length})}),s(t)};return t(),e.on("update",t),()=>e.off("update",t)},[e]);const h=(0,x.useMemo)(()=>{const e=i.trim().toLowerCase();return r.filter(t=>t.level<=l&&(""===e||t.text.toLowerCase().includes(e)))},[r,i,l]),u=(0,x.useCallback)(t=>{if(!e)return;const n=e.view.nodeDOM(t);n&&"function"==typeof n.scrollIntoView&&n.scrollIntoView({behavior:"smooth",block:"start"}),e.chain().focus().setTextSelection(t+1).run(),d(t)},[e]);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed right-4 top-24 z-50 flex w-72 max-h-[70vh] flex-col rounded-lg border border-gray-200/60 bg-white/80 shadow-xl backdrop-blur-md dark:border-slate-700/60 dark:bg-slate-900/80",children:[(0,w.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)(v.ListTree,{size:15,className:"text-blue-500"}),(0,w.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:"Table of Contents"})]}),(0,w.jsx)("button",{onClick:t,title:"Hide table of contents",className:"rounded p-1 text-gray-400 hover:bg-gray-100 hover:text-gray-600 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:14})})]}),(0,w.jsxs)("div",{className:"border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-800",children:[(0,w.jsx)(v.Search,{size:13,className:"shrink-0 text-gray-400"}),(0,w.jsx)("input",{type:"text",value:i,onChange:e=>o(e.target.value),placeholder:"Filter headings…",className:"w-full bg-transparent text-xs text-gray-700 outline-none placeholder:text-gray-400 dark:text-gray-200"}),i&&(0,w.jsx)("button",{onClick:()=>o(""),className:"shrink-0 text-gray-400 hover:text-gray-600",title:"Clear filter",children:(0,w.jsx)(v.X,{size:12})})]}),(0,w.jsxs)("div",{className:"mt-2 flex items-center gap-1",children:[(0,w.jsx)("span",{className:"mr-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400",children:"Level"}),P.map(e=>(0,w.jsxs)("button",{onClick:()=>a(e),title:`Unfold headings up to H${e}`,className:"flex-1 rounded px-1.5 py-1 text-[11px] font-medium transition-colors "+(l===e?"bg-blue-500 text-white":"border border-gray-200 text-gray-600 hover:bg-gray-100 dark:border-slate-700 dark:text-gray-300 dark:hover:bg-slate-800"),children:["H",e]},e))]})]}),(0,w.jsx)("nav",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:0===h.length?(0,w.jsx)("div",{className:"px-2 py-6 text-center text-xs text-gray-400",children:0===r.length?"No headings yet.":"No headings match your filter."}):h.map(e=>(0,w.jsx)("button",{onClick:()=>u(e.pos),style:{paddingLeft:12*(e.level-1)+8+"px"},className:"block w-full truncate rounded py-1.5 pr-2 text-left text-xs transition-colors "+(c===e.pos?"bg-blue-50 font-medium text-blue-700 dark:bg-blue-900/30 dark:text-blue-300":"text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-slate-800"),children:e.text||`Heading ${e.level}`},e.pos))})]}),document.body)}function z({editor:e,className:n}){const[r,s]=(0,x.useState)(null),i=(0,x.useRef)(null),o=(0,x.useCallback)(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),l=(0,x.useCallback)(()=>{o(),i.current=setTimeout(()=>s(null),120)},[o]),a=(0,x.useCallback)(t=>{if(!e)return;const n=t.getAttribute("data-harper-id");if(!n)return;const r=c.getHarperState(e.state)?.issues.get(n);if(!r)return;const i=t.getBoundingClientRect();o(),s({issue:r,top:i.bottom+6,left:i.left})},[e,o]);if((0,x.useEffect)(()=>{if(!e)return;const t=e.view.dom,n=e=>{const t=e.target?.closest("[data-harper-id]");t&&a(t)},r=e=>{e.relatedTarget?.closest("[data-harper-id]")||l()};return t.addEventListener("mouseover",n),t.addEventListener("mouseout",r),()=>{t.removeEventListener("mouseover",n),t.removeEventListener("mouseout",r)}},[e,a,l]),!e||!r)return null;const{issue:d,top:h,left:u}=r;return(0,w.jsxs)("div",{role:"dialog","aria-label":"Proofing suggestion",className:t.cn("harper-tooltip",n),style:{position:"fixed",top:h,left:u,zIndex:60},onMouseEnter:o,onMouseLeave:l,children:[(0,w.jsx)("div",{className:"harper-tooltip-header",children:(0,w.jsx)("span",{className:"harper-tooltip-kind",children:d.kind})}),(0,w.jsx)("p",{className:"harper-tooltip-message",children:d.message}),(0,w.jsxs)("div",{className:"harper-tooltip-actions",children:[0===d.suggestions.length?(0,w.jsx)("span",{className:"harper-tooltip-empty",children:"No suggestions"}):d.suggestions.map((t,n)=>(0,w.jsx)("button",{type:"button",className:"harper-tooltip-suggestion",onClick:()=>(t=>{e.chain().focus().applyHarperSuggestion(d.id,t).run(),s(null)})(n),children:t.label||"(empty)"},`${t.kind}-${t.replacement}-${n}`)),(0,w.jsx)("button",{type:"button",className:"harper-tooltip-ignore",onClick:()=>{e.chain().focus().ignoreHarperSuggestion(d.id).run(),s(null)},children:"Ignore"})]})]})}var B={status:"closed"};function F({icon:e,label:t,onClick:n,disabled:r,title:s}){return(0,w.jsxs)("button",{type:"button",disabled:r,onClick:n,title:s,className:"ai-menu-row",children:[(0,w.jsx)(e,{className:"ai-menu-row-icon"}),t]})}function V(){const e=o.useEditorInstance(),t=o.useEditableEditor(),n=(0,x.useRef)(null),r=(0,x.useRef)(null),[s,l]=(0,x.useState)(""),[a,c]=(0,x.useState)(-1),[h,u]=(0,x.useState)(null),[p,m]=(0,x.useState)(!1),[f,b]=(0,x.useState)(null),y=(0,g.useEditorState)({editor:e,selector:({editor:e})=>e?d.getAiState(e.state)?.panel??B:B}),j=(0,x.useMemo)(()=>"closed"===y.status?null:"reviewing"===y.status?{from:y.suggestion.from,to:y.suggestion.to}:{from:y.from,to:y.to},[y]),S="closed"!==y.status,C=!!j&&j.to>j.from,N=j?j.to-j.from:0,E=e?d.getAiOptions(e)?.commands??[]:[],A=s.trim().toLowerCase(),T=(0,x.useMemo)(()=>{const e=d.commandsForSelection(E,C);return A?e.filter(e=>`${e.label} ${e.description??""}`.toLowerCase().includes(A)):e},[E,A,C]),M=(0,x.useMemo)(()=>d.groupCommands(T),[T]);if((0,x.useEffect)(()=>{if("menu"===y.status){const e=requestAnimationFrame(()=>r.current?.focus());return()=>cancelAnimationFrame(e)}"closed"===y.status&&(l(""),u(null),c(-1),m(!1))},[y.status]),(0,x.useEffect)(()=>{c(e=>e>=T.length?T.length-1:e)},[T.length]),(0,x.useEffect)(()=>{if(!e||!j||!n.current)return void b(null);const t={getBoundingClientRect:()=>(0,g.posToDOMRect)(e.view,j.from,j.to)},r=()=>{n.current&&i.computePosition(t,n.current,{placement:"bottom-start",strategy:"fixed",middleware:[i.offset(8),i.flip(),i.shift({padding:8})]}).then(({x:e,y:t})=>b({x:e,y:t}))};return r(),window.addEventListener("resize",r),window.addEventListener("scroll",r,!0),()=>{window.removeEventListener("resize",r),window.removeEventListener("scroll",r,!0)}},[e,j?.from,j?.to,y]),(0,x.useEffect)(()=>{if(!S||!e)return;const t=t=>{n.current&&!n.current.contains(t.target)&&e.commands.closeAiMenu()},r=t=>{if("Escape"===t.key)return h?void u(null):void e.commands.closeAiMenu();if("Enter"===t.key&&(t.metaKey||t.ctrlKey)){const n=d.getAiState(e.state)?.panel;"reviewing"!==n?.status||n.suggestion.isStreaming||(t.preventDefault(),e.commands.acceptAiSuggestion())}};return document.addEventListener("mousedown",t),document.addEventListener("keydown",r),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("keydown",r)}},[S,e,h]),!(t&&e&&S&&f))return null;const _=t=>{t.options?.length?u(t):e.commands.runAiCommand(t.id)};return(0,k.createPortal)((0,w.jsxs)("div",{ref:n,role:"dialog","aria-label":"Ask AI",className:"ai-menu",style:{position:"fixed",top:f.y,left:f.x,zIndex:60},children:[(0,w.jsxs)("div",{className:"ai-menu-input-row",children:[(0,w.jsx)(v.Sparkles,{className:"ai-menu-input-icon"}),(0,w.jsx)("input",{ref:r,value:s,onChange:e=>{l(e.target.value),c(e.target.value.trim()?0:-1)},onKeyDown:t=>{if("ArrowDown"===t.key)return t.preventDefault(),void c(e=>T.length?(e+1)%T.length:-1);if("ArrowUp"===t.key)return t.preventDefault(),void c(e=>T.length?e<=0?T.length-1:e-1:-1);if("Enter"===t.key){t.preventDefault();const n=a>=0?T[a]:void 0;if(n)return void _(n);s.trim()&&e.commands.submitAiPrompt(s)}},placeholder:C?"Ask AI to change the selection…":"Ask AI anything…",className:"ai-menu-input","aria-label":"Ask AI"})]}),"menu"===y.status&&h&&(0,w.jsxs)("div",{className:"ai-menu-commands",children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>u(null),children:[(0,w.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),h.label]}),h.options?.map(t=>(0,w.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>{u(null),e.commands.runAiCommand(h.id,t.label)},children:(0,w.jsx)("span",{className:"ai-menu-command-text",children:(0,w.jsx)("span",{className:"ai-menu-command-label",children:t.label})})},t.id))]}),"menu"===y.status&&!h&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("div",{className:"ai-menu-hint",children:C?`${N.toLocaleString()} characters selected`:"Nothing selected — select text for rewrite actions"}),(0,w.jsxs)("div",{className:"ai-menu-commands",children:[0===M.length&&(0,w.jsx)("div",{className:"ai-menu-empty",children:"No matching actions"}),M.map(e=>(0,w.jsxs)("div",{children:[(0,w.jsx)("div",{className:"ai-menu-group-label",children:d.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>{const t=T.indexOf(e);return(0,w.jsxs)("button",{type:"button","data-active":t===a?"true":void 0,onMouseEnter:()=>c(t),onClick:()=>_(e),className:"ai-menu-command",children:[(0,w.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,w.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,w.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id)})]},e.group))]})]}),"loading"===y.status&&(0,w.jsxs)("div",{className:"ai-menu-loading",children:[(0,w.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,w.jsx)("span",{className:"ai-menu-loading-label",children:"Custom"===y.commandLabel?"Generating…":`${y.commandLabel}…`}),(0,w.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,w.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}),"error"===y.status&&(0,w.jsxs)("div",{className:"ai-menu-error",children:[(0,w.jsx)("p",{className:"ai-menu-error-message",children:y.message}),(0,w.jsxs)("div",{className:"ai-menu-review",children:[(0,w.jsx)(F,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,w.jsx)(F,{icon:v.X,label:"Dismiss",onClick:()=>e.commands.closeAiMenu()})]})]}),"reviewing"===y.status&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)("div",{className:"ai-menu-preview","aria-live":"polite",children:y.suggestion.suggestedText||"…"}),y.suggestion.isStreaming?(0,w.jsxs)("div",{className:"ai-menu-loading",children:[(0,w.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,w.jsxs)("span",{className:"ai-menu-loading-label",children:[y.commandLabel,"…"]}),(0,w.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,w.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}):(0,w.jsxs)("div",{className:"ai-menu-review",children:[(0,w.jsx)(F,{icon:v.Check,label:"replace"===y.suggestion.mode?"Replace selection":"Insert",title:"⌘/Ctrl + Enter",onClick:()=>e.commands.acceptAiSuggestion()}),(0,w.jsx)(F,{icon:v.CornerDownRight,label:"Insert below",onClick:()=>e.commands.insertAiSuggestionBelow()}),(0,w.jsx)(F,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,w.jsx)(F,{icon:v.Copy,label:p?"Copied":"Copy",onClick:()=>(async e=>{try{await navigator.clipboard.writeText(e),m(!0),setTimeout(()=>m(!1),1500)}catch{}})(y.suggestion.suggestedText)}),(0,w.jsx)(F,{icon:v.X,label:"Discard",onClick:()=>e.commands.discardAiSuggestion()})]})]})]}),document.body)}function W({editor:e,label:t="AI"}){const{editor:n}=o.useTiptapEditor(e),r=(0,x.useRef)(null),s=(0,x.useRef)(null),[l,a]=(0,x.useState)(!1),[c,h]=(0,x.useState)(null),[u,p]=(0,x.useState)(null),{hasSelection:m,isBusy:f}=(0,g.useEditorState)({editor:n,selector:({editor:e})=>{if(!e)return{hasSelection:!1,isBusy:!1};const t=d.getAiState(e.state)?.panel.status;return{hasSelection:!e.state.selection.empty,isBusy:"loading"===t||"reviewing"===t}}})??{hasSelection:!1,isBusy:!1},b=n?d.getAiOptions(n)?.commands??[]:[],y=(0,x.useMemo)(()=>d.groupCommands(d.commandsForSelection(b,m)),[b,m]);if((0,x.useEffect)(()=>{if(!l||!r.current||!s.current)return;const e=r.current,t=()=>{s.current&&i.computePosition(e,s.current,{placement:"bottom-start",strategy:"fixed",middleware:[i.offset(6),i.flip(),i.shift({padding:8})]}).then(({x:e,y:t})=>p({x:e,y:t}))};return t(),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[l,y.length,c]),(0,x.useEffect)(()=>{if(!l)return h(null),void p(null);const e=e=>{const t=e.target;s.current?.contains(t)||r.current?.contains(t)||a(!1)},t=e=>{"Escape"===e.key&&a(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l]),!d.isAiEnabled(n))return null;const j=(e,t)=>{!e.options?.length||t?(a(!1),n?.chain().focus().run(),n?.commands.runAiCommand(e.id,t)):h(e)};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("button",{ref:r,type:"button",title:"AI writing assistant (Ctrl/⌘ + J)","aria-haspopup":"menu","aria-expanded":l,"data-state":l?"open":"closed",className:"ai-toolbar-button",onMouseDown:e=>e.preventDefault(),onClick:()=>a(e=>!e),children:[f?(0,w.jsx)(v.Loader2,{className:"ai-toolbar-icon ai-menu-spin"}):(0,w.jsx)(v.Sparkles,{className:"ai-toolbar-icon"}),t&&(0,w.jsx)("span",{className:"ai-toolbar-label",children:t}),(0,w.jsx)(v.ChevronDown,{className:"ai-toolbar-chevron"})]}),l&&(0,k.createPortal)((0,w.jsx)("div",{ref:s,role:"menu","aria-label":"AI actions",className:"ai-menu ai-toolbar-menu",style:{position:"fixed",top:u?.y??-9999,left:u?.x??-9999,visibility:u?"visible":"hidden",zIndex:60},children:c?(0,w.jsxs)("div",{className:"ai-menu-commands",children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>h(null),children:[(0,w.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),c.label]}),c.options?.map(e=>(0,w.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>j(c,e.label),children:(0,w.jsx)("span",{className:"ai-menu-command-text",children:(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label})})},e.id))]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("button",{type:"button",className:"ai-menu-command ai-menu-ask",onClick:()=>{a(!1),n?.chain().focus().run(),n?.commands.openAiMenu()},children:[(0,w.jsx)(v.Sparkles,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:"Ask AI anything…"}),(0,w.jsx)("span",{className:"ai-menu-command-description",children:"Write your own instruction"})]}),(0,w.jsx)("span",{className:"ai-menu-command-shortcut",children:"⌘J"})]}),(0,w.jsx)("div",{className:"ai-menu-hint",children:m?"Runs on the selected text":"Select text to rewrite it, or generate from the caret"}),(0,w.jsx)("div",{className:"ai-menu-commands",children:y.map(e=>(0,w.jsxs)("div",{children:[(0,w.jsx)("div",{className:"ai-menu-group-label",children:d.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>(0,w.jsxs)("button",{type:"button",className:"ai-menu-command",onClick:()=>j(e),children:[(0,w.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,w.jsxs)("span",{className:"ai-menu-command-text",children:[(0,w.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,w.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,w.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id))]},e.group))})]})}),document.body)]})}var q={available:!1,state:"idle",isActive:!1,isSpeaking:!1,isPaused:!1,currentChunk:null,error:null};var H={available:!1,isListening:!1,partial:"",lastPhrase:"",phraseId:0,error:null};function U(e){const t=(0,x.useCallback)(t=>e?p.subscribeTranscribe(e,t):()=>{},[e]);if("none"===(0,x.useSyncExternalStore)(t,()=>{const t=e?p.getTranscribeStorage(e):void 0;return t?`${t.listening}|${t.phraseId}|${t.error?.message??""}`:"none"},()=>"none")||!e)return H;const n=p.getTranscribeStorage(e);return n?{available:!0,isListening:n.listening,partial:n.partial,lastPhrase:n.lastPhrase,phraseId:n.phraseId,error:n.error}:H}function J({editor:e,durationMs:t=2e3}){const{isListening:n,lastPhrase:r,phraseId:s}=U(e);return(0,w.jsx)(N.SpokenPhraseOverlay,{durationMs:t,phrase:r,phraseId:s,visible:n})}var K=[".dropdown-container",".dropdown-portal","[data-richtext-portal]","[data-radix-popper-content-wrapper]","[data-radix-portal]",'[role="dialog"]','[role="menu"]','[role="listbox"]'].join(",");var G="rte-custom-styles",X="rte-custom-style-presets",Y="rte-active-style-preset";function Z(e){(function(e){const t=e;return!!t?.closest&&!t.closest('input, textarea, select, [contenteditable="true"], [role="textbox"]')&&!!t.closest('button, [role="button"], [role="menuitem"], [role="menuitemcheckbox"]')})(e.target)&&e.preventDefault()}function Q(e){const t=(0,x.useRef)(!1);return{onMouseDown:e=>{t.current=e.target===e.currentTarget},onClick:n=>{t.current&&n.target===n.currentTarget&&(t.current=!1,e())}}}function ee({onClose:e}){const[t,n]=(0,x.useState)(()=>{try{const e=localStorage.getItem(X);return e?JSON.parse(e):[{id:"1",name:"Default",rules:[{id:1,selector:".ProseMirror p",property:"font-size",value:"16px"},{id:2,selector:".ProseMirror h1",property:"color",value:"#111827"}],active:!0}]}catch{return[]}}),[r,s]=(0,x.useState)(()=>{try{return localStorage.getItem(Y)||t[0]?.id||"1"}catch{return"1"}}),[i,o]=(0,x.useState)(null),[l,a]=(0,x.useState)(""),c=t.find(e=>e.id===r)||t[0],[d,h]=(0,x.useState)(c?.rules||[]),u=(0,x.useRef)(d.length?Math.max(...d.map(e=>e.id),0)+1:1),p=e=>{let t=document.getElementById(G);t||(t=document.createElement("style"),t.id=G,document.head.appendChild(t)),t.textContent=e.filter(e=>e.selector&&e.property&&e.value).map(e=>`${e.selector} { ${e.property}: ${e.value}; }`).join("\n")},m=e=>{const n=t.find(t=>t.id===e);n&&(s(e),h([...n.rules]),p(n.rules),localStorage.setItem(Y,e))},f=()=>{if(t.length>=10)return void alert("Maximum 10 style presets allowed");if(!l.trim())return void alert("Please enter a name for the preset");const e=Math.max(...t.map(e=>parseInt(e.id)),0)+1,r={id:String(e),name:l,rules:[{id:1,selector:".ProseMirror p",property:"font-size",value:"16px"}],active:!1},s=[...t,r];n(s),localStorage.setItem(X,JSON.stringify(s)),a(""),m(r.id)},g=(e,r)=>{if(!r.trim())return;const s=t.map(t=>t.id===e?{...t,name:r}:t);n(s),localStorage.setItem(X,JSON.stringify(s)),o(null)},b=(e,t,n)=>h(r=>r.map(r=>r.id===e?{...r,[t]:n}:r)),y=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...y}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[640px] max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)(v.Paintbrush,{size:16,className:"text-blue-500"}),(0,w.jsx)("span",{className:"text-sm font-semibold",children:"Customize Editor Styles"})]}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:14})})]}),(0,w.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 dark:border-slate-700 space-y-2",children:[(0,w.jsx)("div",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Style Presets"}),(0,w.jsx)("div",{className:"flex gap-2 flex-wrap",children:t.map(e=>(0,w.jsxs)("div",{className:"flex items-center gap-1",children:[(0,w.jsx)("button",{onClick:()=>m(e.id),className:"px-3 py-1.5 text-xs rounded transition-colors "+(r===e.id?"bg-blue-500 text-white border-blue-600":"border border-gray-200 dark:border-slate-700 hover:bg-gray-50 dark:hover:bg-slate-800"),children:i===e.id?(0,w.jsx)("input",{autoFocus:!0,type:"text",value:l,onChange:e=>a(e.target.value),onBlur:()=>g(e.id,l),onKeyDown:t=>"Enter"===t.key&&g(e.id,l),className:"w-20 px-1 py-0.5 text-xs bg-transparent border-b border-current outline-none"}):(0,w.jsx)("span",{onDoubleClick:()=>{o(e.id),a(e.name)},children:e.name})}),t.length>1&&(0,w.jsx)("button",{onClick:()=>(e=>{if(t.length<=1)return void alert("Cannot delete the last preset");if(!confirm("Are you sure you want to delete this preset?"))return;const s=t.filter(t=>t.id!==e);n(s),localStorage.setItem(X,JSON.stringify(s)),r===e&&m(s[0].id)})(e.id),className:"p-0.5 rounded text-gray-400 hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 transition-colors",children:(0,w.jsx)(v.X,{size:12})})]},e.id))}),t.length<10&&(0,w.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,w.jsx)("input",{type:"text",value:l,onChange:e=>a(e.target.value),placeholder:"New preset name...",onKeyDown:e=>"Enter"===e.key&&f(),className:"flex-1 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700"}),(0,w.jsxs)("button",{onClick:f,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:[(0,w.jsx)(v.Plus,{size:12}),"Add"]})]})]}),(0,w.jsxs)("div",{className:"px-4 py-2 text-xs text-gray-500 dark:text-gray-400 border-b border-gray-100 dark:border-slate-700",children:["CSS rules applied live to the editor. Target ",(0,w.jsx)("code",{className:"bg-gray-100 dark:bg-slate-800 px-1 rounded",children:".ProseMirror"})," elements."]}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-4 space-y-2",children:[0===d.length&&(0,w.jsx)("div",{className:"text-center text-xs text-gray-400 py-6",children:"No rules yet. Click + Add Rule to begin."}),d.map(e=>(0,w.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,w.jsx)("input",{className:"flex-1 min-w-0 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:".ProseMirror p",value:e.selector,onChange:t=>b(e.id,"selector",t.target.value)}),(0,w.jsx)("input",{className:"w-32 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:"font-size",value:e.property,onChange:t=>b(e.id,"property",t.target.value)}),(0,w.jsx)("input",{className:"w-28 px-2 py-1.5 text-xs border rounded bg-white dark:bg-slate-800 border-gray-200 dark:border-slate-700 font-mono",placeholder:"16px",value:e.value,onChange:t=>b(e.id,"value",t.target.value)}),(0,w.jsx)("button",{onClick:()=>{return t=e.id,h(e=>e.filter(e=>e.id!==t));var t},className:"p-1 rounded text-gray-300 hover:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,w.jsx)(v.Trash2,{size:13})})]},e.id))]}),(0,w.jsxs)("div",{className:"px-4 py-3 border-t border-gray-100 dark:border-slate-700 flex items-center justify-between",children:[(0,w.jsxs)("button",{onClick:()=>{const e={id:u.current++,selector:"",property:"",value:""};h(t=>[...t,e])},className:"flex items-center gap-1.5 px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:[(0,w.jsx)(v.Plus,{size:12}),"Add Rule"]}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsx)("button",{onClick:e,className:"px-3 py-1.5 text-xs border rounded hover:bg-gray-50 dark:hover:bg-slate-800",children:"Cancel"}),(0,w.jsx)("button",{onClick:()=>{const e=t.map(e=>e.id===r?{...e,rules:[...d]}:e);n(e),localStorage.setItem(X,JSON.stringify(e)),p(d)},className:"px-3 py-1.5 text-xs bg-blue-500 text-white rounded hover:bg-blue-600",children:"Save Style"})]})]})]})]}),document.body)}function te({children:e,label:t,shortcut:n,icon:r,displayIcon:s}){const i=(0,x.useRef)(null);return(0,w.jsxs)("div",{ref:i,onClick:e=>{e.target.closest('button, [role="button"], a, select')||(i.current?.querySelector('button, [role="button"]'))?.click()},className:"relative flex items-center gap-3 px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors",children:[(r||s)&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0 text-sm font-mono",children:s||r}),(0,w.jsx)("span",{className:"flex-1 text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,w.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n}),(0,w.jsx)("span",{className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0,children:e}),(0,w.jsx)("span",{className:"hidden",children:e})]})}function ne({icon:e,label:t,shortcut:n,onClick:r,disabled:s}){return(0,w.jsxs)("button",{onClick:r,disabled:s,className:"flex items-center gap-3 w-full px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:[e&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,w.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,w.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n})]})}function re({icon:e,label:t,checked:n,onChange:r}){return(0,w.jsxs)("button",{type:"button",role:"menuitemcheckbox","aria-checked":n,onClick:()=>r(!n),className:"flex items-center gap-3 w-full px-3 py-1.5 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors",children:[e&&(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,w.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),(0,w.jsx)("span",{className:"flex h-4 w-4 items-center justify-center rounded border shrink-0 transition-colors "+(n?"bg-blue-500 border-blue-500 text-white":"border-gray-300 dark:border-slate-600"),children:n&&(0,w.jsx)(v.Check,{size:12,strokeWidth:3})})]})}function se({children:e,label:t,name:n,active:r,onClick:s}){return(0,w.jsxs)("button",{title:t,onClick:e=>s(n,e),className:"flex items-center gap-0.5 px-1.5 py-1 rounded text-sm font-medium transition-colors "+(r?"bg-gray-200 dark:bg-slate-700 text-gray-900 dark:text-white":"text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 hover:text-gray-900 dark:hover:text-white"),children:[e,(0,w.jsx)(v.ChevronDown,{size:10,className:"opacity-40 mt-0.5"})]})}function ie({top:e,left:t,right:n,className:r="",children:s}){const i=(0,x.useRef)(null),[o,l]=(0,x.useState)({top:e,left:-9999,visibility:"hidden"});return(0,x.useLayoutEffect)(()=>{const r=()=>{const r=i.current;if(!r)return;const s=window.innerWidth,o=window.innerHeight,a=Math.max(160,o-e-8);if(s<=640)return void l({top:e,left:8,right:8,width:"auto",minWidth:0,maxWidth:"none",maxHeight:a,overflowY:"auto"});const c=r.offsetWidth,d=null!=n?s-n-c:t??8,h=Math.max(8,Math.min(d,s-c-8));l({top:e,left:h,maxWidth:s-16,maxHeight:a,overflowY:"auto"})};return r(),window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[e,t,n]),(0,w.jsx)("div",{className:`fixed bg-white/70 dark:bg-slate-900/70 backdrop-blur-md border border-gray-200/60 dark:border-slate-700/60 rounded-lg shadow-xl py-1 z-50 min-w-[220px] dropdown-portal ${r}`,onMouseDown:Z,ref:i,style:o,children:s})}function oe({onClose:e,documentTitle:t,editor:n,initialTab:r="info"}){const[s,i]=(0,x.useState)(r),[o,l]=(0,x.useState)(()=>f.getWordCountStats(n));(0,x.useEffect)(()=>{if(!n)return;const e=()=>l(f.getWordCountStats(n));return e(),n.on("update",e),()=>{n.off("update",e)}},[n]);const{createdDate:a,modifiedDate:c}=(0,x.useMemo)(()=>({createdDate:new Date(Date.now()-2592e6),modifiedDate:new Date}),[]),[d,h]=(0,x.useState)(""),[u,p]=(0,x.useState)("viewer"),[m,g]=(0,x.useState)({isPublic:!1,sharedWith:[{email:"alice@example.com",role:"editor",sharedAt:(new Date).toISOString(),name:"Alice"},{email:"bob@example.com",role:"viewer",sharedAt:(new Date).toISOString(),name:"Bob"}],shareLink:null}),b=()=>{d.trim()&&(m.sharedWith.find(e=>e.email===d)?alert("Already shared with this email"):(g(e=>({...e,sharedWith:[...e.sharedWith,{email:d,role:u,sharedAt:(new Date).toISOString()}]})),h("")))},y=e=>{switch(e){case"editor":return(0,w.jsx)(v.Edit3,{size:14});case"commentor":return(0,w.jsx)(v.MessageSquare,{size:14});case"viewer":return(0,w.jsx)(v.Eye,{size:14});default:return null}},j=[{label:"Words",value:o.words},{label:"Characters (with spaces)",value:o.charactersWithSpaces},{label:"Characters (no spaces)",value:o.charactersNoSpaces},{label:"Sentences",value:o.sentences},{label:"Paragraphs",value:o.paragraphs},{label:"Links",value:o.links},{label:"Images",value:o.images}],S=e=>"px-3 py-1.5 text-sm rounded-md transition-colors "+(s===e?"bg-white dark:bg-slate-900 text-gray-900 dark:text-white shadow-sm font-medium":"text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200"),C=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...C}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[600px] max-h-[85vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,w.jsx)(v.FileText,{size:18,className:"text-blue-500 shrink-0"}),(0,w.jsxs)("div",{className:"min-w-0",children:[(0,w.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white truncate",children:t}),(0,w.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-0.5",children:"info"===s?"Document details and statistics":"Manage who can access this document"})]})]}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:16})})]}),(0,w.jsx)("div",{className:"px-6 pt-3",children:(0,w.jsxs)("div",{className:"inline-flex gap-1 p-1 rounded-lg bg-gray-100 dark:bg-slate-800",children:[(0,w.jsx)("button",{className:S("info"),onClick:()=>i("info"),type:"button",children:"Info & word count"}),(0,w.jsx)("button",{className:S("share"),onClick:()=>i("share"),type:"button",children:"Sharing"})]})}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("info"===s?"":"hidden"),children:[(0,w.jsxs)("div",{className:"space-y-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Document Name"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white break-words",children:t})]}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Created"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:a.toLocaleDateString()})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Last Modified"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:c.toLocaleDateString()})]})]}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Access"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:m.isPublic?"Public":"Private"})]}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Shared with"}),(0,w.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:1===m.sharedWith.length?"1 person":`${m.sharedWith.length} people`})]})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("h3",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400",children:"Word Count"}),(0,w.jsx)("table",{className:"w-full text-sm",children:(0,w.jsx)("tbody",{children:j.map(e=>(0,w.jsxs)("tr",{className:"border-b border-gray-100 dark:border-slate-700 last:border-b-0",children:[(0,w.jsx)("td",{className:"py-1.5 pr-2 text-gray-500 dark:text-gray-400",children:e.label}),(0,w.jsx)("td",{className:"py-1.5 text-right font-semibold tabular-nums text-gray-900 dark:text-white",children:e.value.toLocaleString()})]},e.label))})})]}),(0,w.jsxs)("button",{onClick:()=>i("share"),className:"flex items-center gap-2 px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800 text-gray-700 dark:text-gray-200",children:[(0,w.jsx)(v.Share2,{size:14}),"Manage sharing"]})]}),(0,w.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("share"===s?"":"hidden"),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between p-4 rounded-lg border border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/50",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3",children:[m.isPublic?(0,w.jsx)(v.Globe,{size:18,className:"text-blue-500"}):(0,w.jsx)(v.Lock,{size:18,className:"text-gray-400"}),(0,w.jsxs)("div",{children:[(0,w.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:m.isPublic?"Public":"Private"}),(0,w.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:m.isPublic?"Anyone with link can view":"Only invited people can access"})]})]}),(0,w.jsxs)("div",{className:"flex items-center gap-3",children:[m.isPublic&&m.shareLink&&(0,w.jsx)("button",{onClick:()=>{m.shareLink&&(navigator.clipboard.writeText(m.shareLink),alert("Link copied to clipboard"))},className:"px-2 py-1 text-xs border border-gray-300 dark:border-slate-600 rounded hover:bg-gray-100 dark:hover:bg-slate-700 transition-colors",children:"Copy link"}),(0,w.jsx)("button",{onClick:()=>{g(e=>({...e,isPublic:!e.isPublic,shareLink:e.isPublic?null:`https://docs.example.com/share/${Math.random().toString(36).slice(2,9)}`}))},className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors "+(m.isPublic?"bg-blue-500":"bg-gray-300 dark:bg-slate-700"),children:(0,w.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition "+(m.isPublic?"translate-x-6":"translate-x-1")})})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Add people"}),(0,w.jsxs)("div",{className:"flex gap-2",children:[(0,w.jsxs)("div",{className:"relative flex-1",children:[(0,w.jsx)(v.Mail,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),(0,w.jsx)("input",{type:"email",placeholder:"email@example.com",value:d,onChange:e=>h(e.target.value),onKeyDown:e=>"Enter"===e.key&&b(),className:"w-full pl-9 pr-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white placeholder-gray-500"})]}),(0,w.jsxs)("select",{value:u,onChange:e=>p(e.target.value),className:"px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white",children:[(0,w.jsx)("option",{value:"viewer",children:"Viewer"}),(0,w.jsx)("option",{value:"commentor",children:"Commentor"}),(0,w.jsx)("option",{value:"editor",children:"Editor"})]}),(0,w.jsx)("button",{onClick:b,className:"px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors",children:"Share"})]})]}),(0,w.jsxs)("div",{className:"space-y-2",children:[(0,w.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"People with access"}),(0,w.jsx)("div",{className:"space-y-1 max-h-[280px] overflow-y-auto",children:m.sharedWith.length>0?m.sharedWith.map(e=>(0,w.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800/50 transition-colors",children:[(0,w.jsxs)("div",{className:"flex items-center gap-3 flex-1",children:[(0,w.jsx)("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-gradient-to-br from-blue-400 to-blue-600 text-white text-xs font-medium",children:e.email.substring(0,2).toUpperCase()}),(0,w.jsxs)("div",{className:"min-w-0",children:[(0,w.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.email}),(0,w.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Added ",new Date(e.sharedAt).toLocaleDateString()]})]})]}),(0,w.jsxs)("div",{className:"flex items-center gap-2",children:[(0,w.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:y(e.role)}),(0,w.jsxs)("select",{value:e.role,onChange:t=>{return n=e.email,r=t.target.value,void g(e=>({...e,sharedWith:e.sharedWith.map(e=>e.email===n?{...e,role:r}:e)}));var n,r},className:"px-2 py-1 text-xs border border-gray-200 dark:border-slate-700 rounded bg-white dark:bg-slate-800 text-gray-900 dark:text-white",children:[(0,w.jsx)("option",{value:"viewer",children:"Viewer"}),(0,w.jsx)("option",{value:"commentor",children:"Commentor"}),(0,w.jsx)("option",{value:"editor",children:"Editor"})]}),(0,w.jsx)("button",{onClick:()=>{return t=e.email,void g(e=>({...e,sharedWith:e.sharedWith.filter(e=>e.email!==t)}));var t},className:"p-1 text-gray-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors",children:(0,w.jsx)(v.X,{size:14})})]})]},e.email)):(0,w.jsxs)("div",{className:"text-center py-8",children:[(0,w.jsx)(v.Users,{size:24,className:"mx-auto text-gray-300 mb-2 opacity-50"}),(0,w.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No one else has access yet"})]})})]})]})]})]}),document.body)}function le({onClose:e,currentName:t}){const[n,r]=(0,x.useState)(t),s=()=>{n.trim()&&n!==t&&alert(`File renamed to: ${n}`),e()},i=Q(e);return(0,k.createPortal)((0,w.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,w.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...i}),(0,w.jsxs)("div",{className:"relative bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-700 rounded-xl shadow-2xl w-[400px]",onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,w.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white",children:"Rename document"}),(0,w.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,w.jsx)(v.X,{size:16})})]}),(0,w.jsx)("div",{className:"p-6 space-y-4",children:(0,w.jsx)("input",{type:"text",value:n,onChange:e=>r(e.target.value),onKeyDown:e=>"Enter"===e.key&&s(),autoFocus:!0,className:"w-full px-3 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg bg-white dark:bg-slate-800 text-gray-900 dark:text-white"})}),(0,w.jsxs)("div",{className:"flex gap-2 px-6 py-4 border-t border-gray-100 dark:border-slate-700 justify-end",children:[(0,w.jsx)("button",{onClick:e,className:"px-4 py-2 text-sm border border-gray-200 dark:border-slate-700 rounded-lg hover:bg-gray-50 dark:hover:bg-slate-800",children:"Cancel"}),(0,w.jsx)("button",{onClick:s,className:"px-4 py-2 text-sm bg-blue-500 text-white rounded-lg hover:bg-blue-600",children:"Rename"})]})]})]}),document.body)}var ae=({theme:e,setTheme:t,onOpenSettings:r,onAddComment:i,commentDisabled:o,showComments:a,onToggleComments:c,commentCount:d})=>{const[p,f]=(0,x.useState)(null),[b,y]=(0,x.useState)(null),[j,S]=(0,x.useState)(!1),[C,N]=(0,x.useState)(!1),[E,A]=(0,x.useState)(!1),[O,R]=(0,x.useState)(!1),[P,B]=(0,x.useState)(null),F=!!r,V=(0,x.useRef)(null),H=s.useLocale(),{editor:Q}=(0,g.useCurrentEditor)(),ae="Untitled Document",ce=!!Q?.extensionManager.extensions.some(e=>"harper"===e.name);(0,x.useEffect)(()=>{Q&&ce&&(E?Q.chain().focus().runProofing().run():Q.commands.clearProofing())},[E,Q,ce]);const de=function(e){const t=(0,x.useCallback)(t=>e?u.subscribeReadAloud(e,t):()=>{},[e]);if("none"===(0,x.useSyncExternalStore)(t,()=>{const t=e?u.getReadAloudStorage(e):void 0;return t?`${t.state}|${t.currentChunk?.index??-1}|${t.error?.message??""}`:"none"},()=>"none")||!e)return q;const n=u.getReadAloudStorage(e);return n?{available:!0,state:n.state,isActive:"idle"!==n.state,isSpeaking:"speaking"===n.state,isPaused:"paused"===n.state,currentChunk:n.currentChunk,error:n.error}:q}(Q??null),he=U(Q??null),ue=Q&&!Q.state.selection.empty?"selection":"document",pe=!!Q&&u.getReadAloudText(Q).length>0,me=!!Q?.extensionManager.extensions.some(e=>"PaginationPlus"===e.name),[fe,ge]=(0,x.useState)(!0);(0,x.useEffect)(()=>{if(!Q||!me)return;const e=Q.storage?.PaginationPlus?.enabled;"boolean"==typeof e&&ge(e)},[Q,me]);const xe=(0,x.useCallback)(e=>{Q&&(e?Q.commands.enablePagination?.():Q.commands.disablePagination?.(),ge(e))},[Q]),be=(0,x.useCallback)(()=>{Q?.chain().focus().run(),document.execCommand("cut")},[Q]),ye=(0,x.useCallback)(()=>{Q?.chain().focus().run(),document.execCommand("copy")},[Q]),we=(0,x.useCallback)(async()=>{Q?.chain().focus().run();try{const e=await navigator.clipboard.readText();Q?.commands.insertContent(e)}catch{document.execCommand("paste")}},[Q]),ve=(0,x.useCallback)(async()=>{Q?.chain().focus().run();try{const e=await navigator.clipboard.readText();Q?.chain().focus().insertContent(e,{parseOptions:{preserveWhitespace:!0}}).run()}catch{document.execCommand("paste")}},[Q]),ke=(0,x.useCallback)(()=>{Q?.commands.deleteSelection()},[Q]),je=(0,x.useCallback)(()=>{Q?.chain().focus().selectAll().run()},[Q]),Se=!!Q?.extensionManager.extensions.some(e=>"selectSimilar"===e.name),[Ce,Ne]=(0,x.useState)(0);(0,x.useEffect)(()=>{if(!Q||!Se)return;const e=()=>Ne(m.selectSimilarPluginKey.getState(Q.state)?.ranges.length??0);return e(),Q.on("transaction",e),()=>{Q.off("transaction",e)}},[Q,Se]);const Ee=(0,x.useCallback)(e=>{Q?.chain().focus().selectSimilar(e).run()},[Q]),Ae=(0,x.useCallback)(()=>{Q?.chain().focus().clearSimilarSelection().run()},[Q]);(0,x.useEffect)(()=>{try{const e=localStorage.getItem(Y),t=JSON.parse(localStorage.getItem(X)||"[]");if(t.length>0){const n=t.find(t=>t.id===e)||t[0];if(n&&n.rules.length>0){let e=document.getElementById(G);e||(e=document.createElement("style"),e.id=G,document.head.appendChild(e)),e.textContent=n.rules.filter(e=>e.selector&&e.property&&e.value).map(e=>`${e.selector} { ${e.property}: ${e.value}; }`).join("\n")}}}catch{}},[]);const Te=(e,t)=>{if(p===e)return f(null),void y(null);const n=t.currentTarget.getBoundingClientRect();y({top:n.bottom+4,left:n.left}),f(e)},Me=()=>{f(null),y(null)};return(0,x.useEffect)(()=>{if(!p)return;const e=e=>{(function(e,t=document){const n=e;return!!n?.isConnected&&!n.closest(K)&&!t.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')})(e.target)&&Me()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[p]),(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)("div",{className:"flex items-center gap-0.5 border-b border-gray-200 dark:border-slate-700 px-2 py-1 flex-wrap",onMouseDown:Z,children:[(0,w.jsx)(n.Z,{hideWhenDisabled:!0}),(0,w.jsx)(n.$$1,{hideWhenDisabled:!0}),(0,w.jsx)("div",{className:"border-l border-gray-200 dark:border-slate-700 mx-0.5 px-0.5",children:(0,w.jsx)($,{})}),(0,w.jsx)(n.F$1,{}),(0,w.jsx)(n.y$2,{}),(0,w.jsx)(n.h$4,{}),(0,w.jsx)(n.y$1,{}),(0,w.jsx)(n.d$1,{}),(0,w.jsx)(n.M$1,{}),(0,w.jsx)(W,{}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"block",label:"Block Format",active:"block"===p,onClick:Te,children:(0,w.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,w.jsx)("line",{x1:"2",y1:"4",x2:"14",y2:"4"}),(0,w.jsx)("line",{x1:"2",y1:"8",x2:"11",y2:"8"}),(0,w.jsx)("line",{x1:"2",y1:"12",x2:"8",y2:"12"})]})}),"block"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H1",label:"Heading 1",shortcut:"Ctrl+Alt+1",children:(0,w.jsx)(n.$,{level:1})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H2",label:"Heading 2",shortcut:"Ctrl+Alt+2",children:(0,w.jsx)(n.$,{level:2})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H3",label:"Heading 3",shortcut:"Ctrl+Alt+3",children:(0,w.jsx)(n.$,{level:3})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H4",label:"Heading 4",shortcut:"Ctrl+Alt+4",children:(0,w.jsx)(n.$,{level:4})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H5",label:"Heading 5",shortcut:"Ctrl+Alt+5",children:(0,w.jsx)(n.$,{level:5})})}),(0,w.jsx)("div",{children:(0,w.jsx)(te,{icon:"H6",label:"Heading 6",shortcut:"Ctrl+Alt+6",children:(0,w.jsx)(n.$,{level:6})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Bullet List",shortcut:"Ctrl+Shift+8",children:(0,w.jsx)(n.r$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Ordered List",shortcut:"Ctrl+Shift+7",children:(0,w.jsx)(n.n$4,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Check List",shortcut:"Ctrl+Shift+9",children:(0,w.jsx)(n.r,{})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Blockquote",shortcut:"Ctrl+Shift+B",children:(0,w.jsx)(n.p$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Code Block",shortcut:"Ctrl+Alt+C",children:(0,w.jsx)(n.k$2,{})})})]}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-1",children:(0,w.jsx)(M,{label:"Clear Format",children:(0,w.jsx)(n.n$3,{})})}),(0,w.jsxs)("button",{onClick:()=>{Me(),S(!0)},className:"flex items-center gap-3 w-full px-3 py-1.5 text-sm text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-slate-800 rounded transition-colors",children:[(0,w.jsx)(v.Paintbrush,{size:14,className:"text-gray-400 shrink-0"}),"Customize default styles…"]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"textstyles",label:"Text Styles",active:"textstyles"===p,onClick:Te,children:(0,w.jsx)("span",{className:"text-sm font-mono",children:"Tt"})}),"textstyles"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Text Styles"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Strikethrough",shortcut:"Ctrl+Shift+S",children:(0,w.jsx)(n.u$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Inline Code",shortcut:"Ctrl+E",children:(0,w.jsx)(n.m$1,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Text Color",shortcut:"Alt+Shift+C",children:(0,w.jsx)(n.h$3,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Superscript",shortcut:"Ctrl+.",children:(0,w.jsx)(D,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Subscript",shortcut:"Ctrl+,",children:(0,w.jsx)(_,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Indent",children:(0,w.jsx)(n.l,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Line Spacing",children:(0,w.jsx)(n.f,{})})}),(0,w.jsx)("div",{className:"col-span-2",children:(0,w.jsx)(M,{label:"Alignment",children:(0,w.jsx)(n.A$1,{})})})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"insert",label:"Insert",active:"insert"===p,onClick:Te,children:(0,w.jsx)(v.Plus,{size:16})}),"insert"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"min-w-[300px]",left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Insert"}),(0,w.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Link",children:(0,w.jsx)(n.Be,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Emoji",children:(0,w.jsx)(n.ne,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Table",children:(0,w.jsx)(n.at,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Image",children:(0,w.jsx)(n.te,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Meme",children:(0,w.jsx)(n.T$2,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Document",children:(0,w.jsx)(n.E,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Columns",shortcut:"Ctrl+Alt+G",children:(0,w.jsx)(n.b,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Callout",children:(0,w.jsx)(n.F,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Twitter",children:(0,w.jsx)(n.N,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Divider",shortcut:"Ctrl+Alt+S",children:(0,w.jsx)(n.h,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Video",children:(0,w.jsx)(n.M,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Math",children:(0,w.jsx)(n.Dt,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Flowchart",children:(0,w.jsx)(n.P,{})})}),(0,w.jsx)("div",{children:(0,w.jsx)(M,{label:"Drawio",children:(0,w.jsx)(h.RichTextDrawio,{})})}),i&&(0,w.jsx)("div",{children:(0,w.jsxs)("button",{type:"button",disabled:o,onClick:()=>{Me(),i()},className:"flex items-center gap-2 px-2 py-0.5 rounded cursor-pointer w-full text-left hover:bg-gray-100/80 dark:hover:bg-slate-800/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,w.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:(0,w.jsx)(v.MessageSquarePlus,{size:14})}),(0,w.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:"Comment"})]})})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"edit",label:"Edit",active:"edit"===p,onClick:Te,children:(0,w.jsx)(v.Clipboard,{size:16})}),"edit"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Clipboard"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Scissors,{size:14}),label:"Cut",shortcut:"Ctrl+X",onClick:()=>{Me(),be()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Clipboard,{size:14}),label:"Copy",shortcut:"Ctrl+C",onClick:()=>{Me(),ye()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.ClipboardPaste,{size:14}),label:"Paste",shortcut:"Ctrl+V",onClick:()=>{Me(),we()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.ClipboardType,{size:14}),label:"Paste Plain",shortcut:"Ctrl+Shift+V",onClick:()=>{Me(),ve()}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Trash2,{size:14}),label:"Delete",shortcut:"Del",onClick:()=>{Me(),ke()}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Selection"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.TextCursorInput,{size:14}),label:"Select All",shortcut:"Ctrl+A",onClick:()=>{Me(),je()}}),Se&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Type,{size:14}),label:"Select All Similar Fonts",onClick:()=>{Me(),Ee("font")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Palette,{size:14}),label:"Select All Similar Styles",onClick:()=>{Me(),Ee("style")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.TextSelect,{size:14}),label:"Select All Similar Formatting",onClick:()=>{Me(),Ee("formatting")}}),(0,w.jsx)(ne,{disabled:0===Ce,icon:(0,w.jsx)(v.X,{size:14}),label:Ce?`Clear Multi-Selection (${Ce})`:"Clear Multi-Selection",shortcut:"Esc",onClick:()=>{Me(),Ae()}}),(0,w.jsx)("div",{className:"px-3 pb-1.5 pt-0.5 text-[10px] leading-snug text-gray-400 dark:text-gray-500",children:"Formatting applied afterwards lands on every highlighted run at once."})]})]}),document.body)]}),(0,w.jsxs)("div",{className:"dropdown-container",children:[(0,w.jsx)(se,{name:"tools",label:"Tools",active:"tools"===p,onClick:Te,children:(0,w.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,w.jsx)("path",{d:"M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"})})}),"tools"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{left:b.left,top:b.top,children:[(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Document"}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.FileText,{size:14}),label:"Document info & word count",onClick:()=>{Me(),B("info")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Share2,{size:14}),label:"Share",onClick:()=>{Me(),B("share")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Edit3,{size:14}),label:"Rename",onClick:()=>{Me(),R(!0)}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Copy,{size:14}),label:"Make a copy",onClick:()=>{Me(),alert("Document copied to your drive")}}),(0,w.jsx)(ne,{icon:(0,w.jsx)(v.Download,{size:14}),label:"Download",onClick:()=>{Me(),alert("Downloading document...")}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Tools"}),c&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.MessageSquare,{size:14}),label:d?`Comments Panel (${d})`:"Comments Panel",checked:!!a,onChange:()=>c()}),c&&(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(M,{label:"Find / Replace",children:(0,w.jsx)(n.I,{})}),(0,w.jsx)(M,{label:"View Source",children:(0,w.jsx)(n.n,{})}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(re,{icon:(0,w.jsx)(v.ListTree,{size:14}),label:"Table of Contents",checked:C,onChange:N}),ce&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.SpellCheck,{size:14}),label:"Spelling & Grammar",checked:E,onChange:A}),(de.available||he.available)&&(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),de.available&&(0,w.jsx)(ne,{disabled:!de.isActive&&!pe,icon:de.isActive?(0,w.jsx)(v.VolumeX,{size:14}):(0,w.jsx)(v.Volume2,{size:14}),label:de.isActive?"Stop reading":"selection"===ue?"Read selection aloud":"Read document aloud",shortcut:"Ctrl+Shift+S",onClick:()=>{Me(),Q?.commands.toggleReadAloud()}}),he.available&&(0,w.jsx)(re,{icon:(0,w.jsx)(v.Mic,{size:14}),label:(0,T.isTranscriptionSupported)()?he.isListening?"Dictating — click to stop":"Dictate into the document":"Dictation unavailable in this browser",checked:he.isListening,onChange:()=>{(0,T.isTranscriptionSupported)()&&Q?.commands.toggleTranscribe()}}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),me&&(0,w.jsx)(re,{icon:fe?(0,w.jsx)(v.File,{size:14}):(0,w.jsx)(v.Globe,{size:14}),label:fe?"Page Layout: A4":"Page Layout: Web",checked:fe,onChange:xe}),(0,w.jsx)(M,{label:"Page Settings",shortcut:"Ctrl+Shift+P",children:(0,w.jsx)(I,{})}),(0,w.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,w.jsx)(M,{label:"Import Word",children:(0,w.jsx)(n.Th,{})}),(0,w.jsx)(M,{label:"Export Word",children:(0,w.jsx)(n.d,{})}),(0,w.jsx)(M,{label:"Export PDF",children:(0,w.jsx)(n.a$1,{})})]}),document.body)]}),(0,w.jsxs)("div",{className:"ml-auto dropdown-container",children:[(0,w.jsx)("button",{ref:V,title:"Settings",onClick:e=>{F?(f(null),y(null),r()):((e,t)=>{if(p===e)return f(null),void y(null);const n=t.currentTarget.getBoundingClientRect();y({top:n.bottom+4,left:n.left,right:window.innerWidth-n.right}),f(e)})("settings",e)},className:"flex items-center gap-0.5 p-1.5 rounded transition-colors "+("settings"===p?"bg-gray-200 dark:bg-slate-700":"text-gray-500 hover:bg-gray-100 dark:hover:bg-slate-800"),children:(0,w.jsx)(v.Settings,{size:16})}),!F&&"settings"===p&&b&&(0,k.createPortal)((0,w.jsxs)(ie,{className:"w-[260px] px-2 py-2 shadow-2xl",right:b.right,top:b.top,children:[(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Theme"}),(0,w.jsxs)("div",{className:"flex gap-1 mb-2 px-1",children:[(0,w.jsx)("button",{onClick:()=>t("light"),className:"flex-1 px-2 py-1 text-xs border rounded "+("light"===e?"bg-blue-500 text-white border-blue-600":"hover:bg-gray-100 dark:hover:bg-slate-800"),children:"☀️ Light"}),(0,w.jsx)("button",{onClick:()=>t("dark"),className:"flex-1 px-2 py-1 text-xs border rounded "+("dark"===e?"bg-blue-500 text-white border-blue-600":"hover:bg-gray-100 dark:hover:bg-slate-800"),children:"🌙 Dark"})]}),(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Accent Color"}),(0,w.jsx)("div",{className:"grid grid-cols-4 gap-0.5 px-1 mb-2",children:["default","red","blue","green","orange","rose","violet","yellow"].map(e=>(0,w.jsx)("button",{onClick:()=>l.themeActions.setColor(e),className:"px-1.5 py-1 text-[10px] border rounded hover:bg-gray-100 dark:hover:bg-slate-800 capitalize",children:e},e))}),(0,w.jsx)("div",{className:"border-t border-gray-100 dark:border-slate-700 my-1"}),(0,w.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Language"}),(0,w.jsx)("div",{className:"grid grid-cols-2 gap-0.5 px-1 max-h-[180px] overflow-y-auto",children:[{code:"en",flag:"🇺🇸",label:"English"},{code:"es",flag:"🇪🇸",label:"Español"},{code:"de",flag:"🇩🇪",label:"Deutsch"},{code:"zh_CN",flag:"🇨🇳",label:"中文"},{code:"ja",flag:"🇯🇵",label:"日本語"},{code:"ar",flag:"🇸🇦",label:"العربية"},{code:"fr",flag:"🇫🇷",label:"Français"},{code:"pt_BR",flag:"🇧🇷",label:"Português"},{code:"ru",flag:"🇷🇺",label:"Русский"},{code:"tr",flag:"🇹🇷",label:"Türkçe"},{code:"it",flag:"🇮🇹",label:"Italiano"},{code:"fa",flag:"🇮🇷",label:"فارسی"},{code:"nl",flag:"🇳🇱",label:"Nederlands"},{code:"ko",flag:"🇰🇷",label:"한국어"},{code:"hi",flag:"🇮🇳",label:"हिन्दी"},{code:"hu_HU",flag:"🇭🇺",label:"Magyar"},{code:"vi",flag:"🇻🇳",label:"Tiếng Việt"},{code:"fi",flag:"🇫🇮",label:"Suomi"}].map(({code:e,flag:t,label:n})=>(0,w.jsxs)("button",{onClick:()=>s.localeActions.setLang(e),className:"px-1.5 py-1 text-[10px] border rounded text-left hover:bg-gray-100 dark:hover:bg-slate-800 "+(H.lang===e?"bg-blue-500/20 border-blue-500":""),children:[t," ",n]},e))})]}),document.body)]})]}),j&&(0,w.jsx)(ee,{onClose:()=>S(!1)}),C&&Q&&(0,w.jsx)(L,{editor:Q,onClose:()=>N(!1)}),ce&&E&&Q&&(0,w.jsx)(z,{editor:Q}),he.available&&(0,w.jsx)(J,{editor:Q??null}),O&&(0,w.jsx)(le,{onClose:()=>R(!1),currentName:ae}),P&&(0,w.jsx)(oe,{documentTitle:ae,editor:Q,initialTab:P,onClose:()=>B(null)})]})},ce=[{id:"improve",label:"Improve writing",description:"Clearer, tighter, same meaning",icon:v.Sparkles,group:"edit",prompt:"Improve the clarity, flow and word choice of the text. Keep the author's meaning, voice, facts and level of formality exactly as they are, and keep roughly the same length."},{id:"fix",label:"Fix spelling & grammar",description:"Correct mistakes only",icon:v.CheckCheck,group:"edit",prompt:"Correct spelling, grammar, punctuation and obvious typos in the text. Change nothing else: keep the original wording, sentence structure, tone and formatting. If the text is already correct, return it unchanged."},{id:"shorter",label:"Make shorter",description:"Trim to the essentials",icon:v.Minus,group:"edit",prompt:"Rewrite the text roughly half as long. Cut redundancy, filler and hedging, but keep every claim, figure, name and qualifier that carries meaning."},{id:"longer",label:"Make longer",description:"Expand with more detail",icon:v.Plus,group:"edit",prompt:"Expand the text with useful detail, explanation and structure, staying on the same topic and in the same voice. Do not invent facts, statistics, quotations or sources — expand only on what the text already implies."},{id:"simplify",label:"Simplify language",description:"Plainer words, shorter sentences",icon:v.Feather,group:"edit",prompt:"Rewrite the text in plain, direct language: common words, shorter sentences, active voice. Keep all of the original meaning, including any technical terms that have no plain equivalent."},{id:"rephrase",label:"Rephrase",description:"Same point, fresh wording",icon:v.ArrowRightLeft,group:"edit",prompt:"Rewrite the text with different wording and sentence structure while preserving its meaning, tone and approximate length. Avoid reusing the original phrasing."},{id:"professional",label:"Professional tone",description:"Polished and businesslike",icon:v.Briefcase,group:"tone",prompt:"Rewrite the text in a polished, professional tone: precise, courteous, free of slang and exclamation marks. Do not change the meaning or add new claims."},{id:"casual",label:"Casual tone",description:"Relaxed and conversational",icon:v.Coffee,group:"tone",prompt:"Rewrite the text in a relaxed, conversational tone, as if explaining it to a colleague. Keep it clear and keep the meaning unchanged; do not add jokes or filler."},{id:"confident",label:"More confident",description:"Drop the hedging",icon:v.PenLine,group:"tone",prompt:'Rewrite the text so it reads more decisively: remove hedges such as "maybe", "I think" and "sort of", and use active voice. Keep any genuine uncertainty that the text explicitly states.'},{id:"emojify",label:"Emojify",description:"Add relevant emoji",icon:v.SmilePlus,group:"tone",prompt:"Add a small number of relevant emoji to the text, at most one per sentence. Do not change any of the wording."},{id:"summarize",label:"Summarize",description:"Condense into a short paragraph",icon:v.FileText,group:"transform",prompt:"Summarize the text in one short paragraph that captures its main point and the reasoning behind it. Use only information present in the text."},{id:"key-points",label:"Key takeaways",description:"Turn it into a bullet list",icon:v.ListTree,group:"transform",prompt:'Rewrite the text as a list of the key takeaways, one per line, each starting with "- ". Keep each line to a single sentence and use only information present in the text.'},{id:"action-items",label:"Extract action items",description:"Who does what, next",icon:v.ListChecks,group:"transform",prompt:'List the concrete action items implied by the text, one per line, each starting with "- " and written as an imperative with the owner named when the text names one. If the text contains no action items, return "- No action items.".'},{id:"explain",label:"Explain this",description:"Plain-English explanation",icon:v.Baby,group:"transform",prompt:"Explain what the text means in plain English, in one short paragraph a non-expert can follow. Explain the text; do not rewrite or evaluate it."},{id:"translate",label:"Translate",description:"Into another language",icon:v.Languages,group:"transform",options:[{id:"en",label:"English"},{id:"es",label:"Spanish"},{id:"fr",label:"French"},{id:"de",label:"German"},{id:"pt",label:"Portuguese"},{id:"it",label:"Italian"},{id:"zh",label:"Chinese (Simplified)"},{id:"ja",label:"Japanese"},{id:"ko",label:"Korean"},{id:"hi",label:"Hindi"},{id:"ar",label:"Arabic"},{id:"ru",label:"Russian"}],prompt:"Translate the text accurately, preserving tone, formatting, line breaks, names, URLs, code and numbers. Target language:"},{id:"continue",label:"Continue writing",description:"Pick up where the text stops",icon:v.WandSparkles,group:"generate",requiresSelection:!1,prompt:"Continue the document from where it stops, in the same voice, tense and formatting. Write one or two paragraphs that follow naturally. Do not repeat what has already been written and do not invent sources or statistics."},{id:"outline",label:"Draft an outline",description:"Headings for this document",icon:v.ListTree,group:"generate",requiresSelection:!1,prompt:'Draft a working outline for this document, one heading per line, each starting with "- ". Base it on what the document is already about.'},{id:"counterpoint",label:"Counterpoint",description:"The strongest objection",icon:v.Quote,group:"transform",prompt:"State the strongest good-faith objection to the argument in the text, in one short paragraph. Name the assumption it challenges. Do not invent evidence, sources or statistics."}],de=[/^#{1,6}\s+/m,/^\s*[-*+]\s+\S/m,/^\s*\d+\.\s+\S/m,/^\s*>\s+\S/m,/^\s*[-*]\s+\[[ xX]\]/m,/^\|.+\|\s*$/m,/^\s*(?:---|\*\*\*)\s*$/m],he=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function ue(e){return n.me$1.parse(e,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function pe(e){const t=e.trim();return t?function(e){return function(e){return de.some(t=>t.test(e))||he.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}(t)?{content:ue(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}function me(e,t){return new Promise((n,r)=>{const s=setTimeout(n,e);t.addEventListener("abort",()=>{clearTimeout(s),r(new DOMException("Aborted","AbortError"))},{once:!0})})}var fe=async(e,t,n)=>{const r=function(e,t,n){const r=`${e} ${t}`.toLowerCase(),s=n.trim();if(!s)return r.includes("outline")?"- Background\n- What changed\n- Why it matters\n- Next steps":`${t.trim()||"New content"}\n\n(Offline demo response — configure Ai.configure({ getCompletion }) to use a real model.)`;if(r.includes("emoji"))return`${s} ✨📝`;if(r.includes("shorter")||r.includes("concise")){const e=s.split(/\s+/),t=Math.max(1,Math.ceil(e.length/2));return e.slice(0,t).join(" ")}return r.includes("longer")||r.includes("expand")?`${s} In other words, this point matters because it clarifies the reader's understanding and adds useful context.`:r.includes("key-points")||r.includes("action-items")||r.includes("takeaway")?s.split(/(?<=[.!?])\s+/).map(e=>e.trim()).filter(Boolean).map(e=>`- ${e.replace(/[.!?]$/,"")}`).join("\n"):r.includes("simplify")?s.replace(/[;:]/g,".").split(". ").map(e=>e.trim()).filter(Boolean).join(". "):s.charAt(0).toUpperCase()+s.slice(1).replace(/\s{2,}/g," ")}(e.commandId,e.instruction,e.selectedText).split(/(\s+)/).filter(Boolean);let s="";for(const i of r){if(n.aborted)throw new DOMException("Aborted","AbortError");s+=i,t(s),i.trim()&&await me(35,n)}return s},ge=["You are a writing assistant inside a rich-text editor.","Return only the text that should appear in the document — nothing else.","Never add a preamble, sign-off, explanation, or commentary about what you changed.","Never wrap the answer in Markdown code fences or quotation marks unless the original text was itself fenced or quoted.","Preserve the original language of the text unless asked to translate.","Preserve quotations, citations, URLs, code, numbers and proper nouns exactly, unless the instruction is explicitly about changing them.","Never invent facts, statistics, sources, citations or links.","Match the surrounding formatting: plain paragraphs separated by blank lines, and one item per line for lists."].join("\n");function xe(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}var be=/^(?:sure|certainly|of course|absolutely|got it|okay|ok|here(?:'|’)?s|here is|here are|below is|i(?:'|’)?ve|i have)\b[^\n:]{0,120}:[ \t]*\r?\n+/i,ye=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,we=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,ve=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function ke(e,{streaming:t=!1}={}){if(!e)return"";let n=function(e){return e.replace(/\r\n/g,"\n").replace(/[ \t]+$/gm,"").replace(/\n{3,}/g,"\n\n")}(e);return n=function(e){const t=e.replace(be,"");return t!==e?t:e.replace(ye,"")}(n),n=function(e){if(!we.test(e))return e;const t=e.replace(we,"").replace(ve,"");return/(?:^|\n)[ \t]*(?:```|~~~)/.test(t)?e:t}(n),t||(n=function(e){const t=e.trim();if(t.length<2)return e;for(const[n,r]of[['"','"'],["“","”"],["'","'"],["‘","’"]]){if(!t.startsWith(n)||!t.endsWith(r))continue;const e=t.slice(n.length,t.length-r.length);if(!e.includes(r))return e}return e}(n)),n=n.replace(/^\n+/,""),t?n.replace(/[ \t]+$/," ").replace(/^[ \t]+/,""):n.trim()}var je=new y.PluginKey("ai");function Se(e){return je.getState(e)}function Ce(e,t){switch(e.status){case"menu":case"loading":case"error":return{from:e.from,to:e.to};case"reviewing":return{from:e.suggestion.from,to:e.suggestion.to};default:return t}}function Ne(e,t,n){if("loading"===t.status)return S.DecorationSet.create(e,[S.Decoration.widget(t.to,()=>{const e=document.createElement("span");return e.className=n.loadingClass,e.textContent="● ● ●",e},{side:1})]);if("reviewing"===t.status){const{from:r,to:s,suggestedText:i,mode:o}=t.suggestion,l=[];return"replace"===o&&s>r&&l.push(S.Decoration.inline(r,s,{class:n.removedClass})),l.push(S.Decoration.widget(s,()=>{const e=document.createElement("span");return e.className=n.insertedClass,e.textContent=i||"…",e},{side:1})),S.DecorationSet.create(e,l)}return S.DecorationSet.empty}async function Ee(e,t,n,r,s,i){const{view:o}=e,l=e.state.doc,a=s===i?"":l.textBetween(s,i,"\n"),c=function(e,t,n,r){if(r<=0)return"";const s=r+200,i=e.textBetween(Math.max(0,t-s),t,"\n"),o=e.textBetween(n,Math.min(e.content.size,n+s),"\n"),l=(a=i,(c=Math.floor(r/2))<=0?"":a.length<=c?a:`…${a.slice(a.length-c)}`);var a,c;const d=o.length>r-l.length?`${o.slice(0,r-l.length)}…`:o;return`${l}${l&&d?"\n":""}${d}`.trim()}(l,s,i,t.contextChars),d=a?"replace":"insert";n.abortController?.abort();const h=new AbortController;n.abortController=h;const u=n.requestToken+=1;o.dispatch(o.state.tr.setMeta(je,{type:"set-loading",from:s,to:i,commandId:r.commandId,commandLabel:r.commandLabel,instruction:r.instruction,option:r.option}));const p=(t,o)=>{if(u!==n.requestToken||e.isDestroyed)return;const l=ke(t,{streaming:o});e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-suggestion",commandLabel:r.commandLabel,suggestion:{from:s,to:i,originalText:a,suggestedText:l,mode:d,isStreaming:o}}))};try{const o=await t.getCompletion({instruction:r.instruction,selectedText:a,documentText:c,commandId:r.commandId,commandLabel:r.commandLabel,option:r.option,systemPrompt:t.systemPrompt,mode:d},e=>p(e,!0),h.signal);if(u!==n.requestToken||e.isDestroyed)return;if(!ke(o))return void e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:"The model returned an empty response."}));p(o,!1)}catch(Le){if(h.signal.aborted||u!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(je,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:Le instanceof Error?Le.message:"Something went wrong."}))}}b.Extension.create({name:"ai",addOptions:()=>({commands:ce,getCompletion:fe,systemPrompt:ge,contextChars:4e3,removedClass:"ai-removed-text",insertedClass:"ai-suggested-text",loadingClass:"ai-loading-indicator"}),addStorage:()=>({requestToken:0,abortController:null}),onDestroy(){this.storage.abortController?.abort()},addKeyboardShortcuts(){return{"Mod-j":()=>this.editor.commands.openAiMenu()}},addCommands(){const e=()=>{this.storage.abortController?.abort(),this.storage.abortController=null,this.storage.requestToken+=1};return{openAiMenu:()=>({state:t,dispatch:n})=>{e();const{from:r,to:s}=t.selection;return n&&n(t.tr.setMeta(je,{type:"open-menu",from:r,to:s})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(je,{type:"close"})),!0),stopAiGeneration:()=>({state:t,dispatch:n})=>{const r=Se(t)?.panel;if(!r||"loading"!==r.status&&"reviewing"!==r.status)return!1;if("reviewing"===r.status&&!r.suggestion.isStreaming)return!1;if(e(),!n)return!0;if("reviewing"===r.status)n(t.tr.setMeta(je,{type:"settle"}));else{const{from:e,to:s}=Ce(r,t.selection);n(t.tr.setMeta(je,{type:"open-menu",from:e,to:s}))}return!0},runAiCommand:(e,t)=>({state:n,editor:r})=>{const s=this.options.commands.find(t=>t.id===e);if(!s)return!1;const{from:i,to:o}=Ce(Se(n)?.panel??{status:"closed"},n.selection);return!(!1!==s.requiresSelection&&i===o||s.options?.length&&!t||(Ee(r,this.options,this.storage,{instruction:xe(s,t),commandId:s.id,commandLabel:t?`${s.label} → ${t}`:s.label,option:t},i,o),0))},submitAiPrompt:e=>({state:t,editor:n})=>{const r=e.trim();if(!r)return!1;const{from:s,to:i}=Ce(Se(t)?.panel??{status:"closed"},t.selection);return Ee(n,this.options,this.storage,{instruction:r,commandId:"custom",commandLabel:"Custom"},s,i),!0},retryAiSuggestion:()=>({state:e,editor:t})=>{const n=Se(e)?.lastRequest;return!!n&&(Ee(t,this.options,this.storage,{instruction:n.instruction,commandId:n.commandId,commandLabel:n.commandLabel,option:n.option},n.from,n.to),!0)},acceptAiSuggestion:()=>({state:t,chain:n})=>{const r=Se(t)?.panel;if(!r||"reviewing"!==r.status||r.suggestion.isStreaming)return!1;const{from:s,to:i,suggestedText:o}=r.suggestion,{content:l}=pe(o);return!!l&&(e(),n().insertContentAt({from:s,to:i},l,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(je,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(je,{type:"close"})),!0),insertAiSuggestionBelow:()=>({state:t,chain:n})=>{const r=Se(t)?.panel;if(!r||"reviewing"!==r.status||r.suggestion.isStreaming)return!1;const{to:s,suggestedText:i}=r.suggestion,{content:o}=pe(i);if(!o)return!1;const l=t.doc.resolve(Math.min(s,t.doc.content.size)),a=l.depth>0?l.after(l.depth):l.pos;return e(),n().insertContentAt(a,o,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(je,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new y.Plugin({key:je,state:{init:()=>({panel:{status:"closed"},decorations:S.DecorationSet.empty,lastRequest:null}),apply(t,n){let r=n.panel,s=n.lastRequest;t.docChanged&&(r=function(e,t){switch(e.status){case"closed":default:return e;case"menu":case"loading":case"error":return{...e,from:t.map(e.from),to:t.map(e.to)};case"reviewing":return{...e,suggestion:{...e.suggestion,from:t.map(e.suggestion.from),to:t.map(e.suggestion.to)}}}}(r,t.mapping));const i=t.getMeta(je);if(i)switch(i.type){case"open-menu":r={status:"menu",from:i.from,to:i.to};break;case"set-loading":r={status:"loading",from:i.from,to:i.to,commandLabel:i.commandLabel},s={instruction:i.instruction,commandId:i.commandId,commandLabel:i.commandLabel,option:i.option,from:i.from,to:i.to};break;case"set-suggestion":r={status:"reviewing",suggestion:i.suggestion,commandLabel:i.commandLabel};break;case"set-error":r={status:"error",from:i.from,to:i.to,commandLabel:i.commandLabel,message:i.message};break;case"settle":"reviewing"===r.status&&(r={...r,suggestion:{...r.suggestion,isStreaming:!1}});break;case"close":r={status:"closed"}}return{panel:r,decorations:Ne(t.doc,r,e),lastRequest:s}}},props:{decorations(e){return this.getState(e)?.decorations??S.DecorationSet.empty}}})]}});var Ae=()=>new Map,Te=e=>{const t=Ae();return e.forEach((e,n)=>{t.set(n,e)}),t},Me=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},_e=()=>new Set,De=e=>e[e.length-1],Oe=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},$e=Array.from,Re=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Ie=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Pe=Array.isArray,Le=class{constructor(){this._observers=Ae()}on(e,t){return Me(this._observers,e,_e).add(t),t}once(e,t){const n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){const n=this._observers.get(e);void 0!==n&&(n.delete(t),0===n.size&&this._observers.delete(e))}emit(e,t){return $e((this._observers.get(e)||Ae()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ae()}},ze=Math.floor,Be=Math.abs,Fe=(e,t)=>e<t?e:t,Ve=(e,t)=>e>t?e:t,We=(Number.isNaN,e=>0!==e?e<0:1/e<0),qe=Number.MAX_SAFE_INTEGER,He=Number.MIN_SAFE_INTEGER,Ue=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&ze(e)===e),Je=(Number.isNaN,Number.parseInt,String.fromCharCode),Ke=(String.fromCodePoint,Je(65535),/^\s*/g),Ge=/([A-Z])/g,Xe=(e,t)=>(e=>e.replace(Ke,""))(e.replace(Ge,e=>`${t}${(e=>e.toLowerCase())(e)}`)),Ye="undefined"!=typeof TextEncoder?new TextEncoder:null,Ze=Ye?e=>Ye.encode(e):e=>{const t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let s=0;s<n;s++)r[s]=t.codePointAt(s);return r},Qe="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Qe&&1===Qe.decode(new Uint8Array).length&&(Qe=null);var et,tt,nt,rt,st=(e,t)=>((e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t();return n})(t,()=>e).join(""),it=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},ot=()=>new it,lt=e=>{const t=new Uint8Array((e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t})(e));let n=0;for(let r=0;r<e.bufs.length;r++){const s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},at=(e,t)=>{const n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*n),e.cpos=0),e.cbuf[e.cpos++]=t},ct=at,dt=(e,t)=>{for(;t>127;)at(e,128|127&t),t=ze(t/128);at(e,127&t)},ht=(e,t)=>{const n=We(t);for(n&&(t=-t),at(e,(t>63?128:0)|(n?64:0)|63&t),t=ze(t/64);t>0;)at(e,(t>127?128:0)|127&t),t=ze(t/128)},ut=new Uint8Array(3e4),pt=ut.length/3,mt=Ye&&Ye.encodeInto?(e,t)=>{if(t.length<pt){const n=Ye.encodeInto(t,ut).written||0;dt(e,n);for(let t=0;t<n;t++)at(e,ut[t])}else gt(e,Ze(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;dt(e,r);for(let s=0;s<r;s++)at(e,n.codePointAt(s))},ft=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=Fe(n-r,t.length),i=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,i>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(Ve(2*n,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},gt=(e,t)=>{dt(e,t.byteLength),ft(e,t)},xt=(e,t)=>{((e,t)=>{const n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*Ve(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},bt=new DataView(new ArrayBuffer(4)),yt=(e,t)=>{switch(typeof t){case"string":at(e,119),mt(e,t);break;case"number":Ue(t)&&Be(t)<=2147483647?(at(e,125),ht(e,t)):(n=t,bt.setFloat32(0,n),bt.getFloat32(0)===n?(at(e,124),((e,t)=>{xt(e,4).setFloat32(0,t,!1)})(e,t)):(at(e,123),((e,t)=>{xt(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":at(e,122),((e,t)=>{xt(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)at(e,126);else if(Pe(t)){at(e,117),dt(e,t.length);for(let n=0;n<t.length;n++)yt(e,t[n])}else if(t instanceof Uint8Array)at(e,116),gt(e,t);else{at(e,118);const n=Object.keys(t);dt(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];mt(e,s),yt(e,t[s])}}break;case"boolean":at(e,t?120:121);break;default:at(e,127)}var n},wt=class extends it{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&dt(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},vt=e=>{e.count>0&&(ht(e.encoder,1===e.count?e.s:-e.s),e.count>1&&dt(e.encoder,e.count-2))},kt=class{constructor(){this.encoder=new it,this.s=0,this.count=0}write(e){this.s===e?this.count++:(vt(this),this.count=1,this.s=e)}toUint8Array(){return vt(this),lt(this.encoder)}},jt=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);ht(e.encoder,t),e.count>1&&dt(e.encoder,e.count-2)}},St=class{constructor(){this.encoder=new it,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(jt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return jt(this),lt(this.encoder)}},Ct=class{constructor(){this.sarr=[],this.s="",this.lensE=new kt}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length)}toUint8Array(){const e=new it;return this.sarr.push(this.s),this.s="",mt(e,this.sarr.join("")),ft(e,this.lensE.toUint8Array()),lt(e)}},Nt=e=>new Error(e),Et=()=>{throw Nt("Method unimplemented")},At=()=>{throw Nt("Unexpected case")},Tt=Nt("Unexpected end of array"),Mt=Nt("Integer out of Range"),_t=class{constructor(e){this.arr=e,this.pos=0}},Dt=e=>new _t(e),Ot=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,Rt(e)),$t=e=>e.arr[e.pos++],Rt=e=>{let t=0,n=1;const r=e.arr.length;for(;e.pos<r;){const r=e.arr[e.pos++];if(t+=(127&r)*n,n*=128,r<128)return t;if(t>qe)throw Mt}throw Tt},It=e=>{let t=e.arr[e.pos++],n=63&t,r=64;const s=(64&t)>0?-1:1;if(!(128&t))return s*n;const i=e.arr.length;for(;e.pos<i;){if(t=e.arr[e.pos++],n+=(127&t)*r,r*=128,t<128)return s*n;if(n>qe)throw Mt}throw Tt},Pt=Qe?e=>Qe.decode(Ot(e)):e=>{let t=Rt(e);if(0===t)return"";{let n=String.fromCodePoint($t(e));if(--t<100)for(;t--;)n+=String.fromCodePoint($t(e));else for(;t>0;){const r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}},Lt=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},zt=[e=>{},e=>null,It,e=>Lt(e,4).getFloat32(0,!1),e=>Lt(e,8).getFloat64(0,!1),e=>Lt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Pt,e=>{const t=Rt(e),n={};for(let r=0;r<t;r++)n[Pt(e)]=Bt(e);return n},e=>{const t=Rt(e),n=[];for(let r=0;r<t;r++)n.push(Bt(e));return n},Ot],Bt=e=>zt[127-$t(e)](e),Ft=class extends _t{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=Rt(this)+1:this.count=-1),this.count--,this.s;var e}},Vt=class extends _t{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=It(this);const e=We(this.s);this.count=1,e&&(this.s=-this.s,this.count=Rt(this)+2)}return this.count--,this.s}},Wt=class extends _t{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=It(this),t=1&e;this.diff=ze(e/2),this.count=1,t&&(this.count=Rt(this)+2)}return this.s+=this.diff,this.count--,this.s}},qt=class{constructor(e){this.decoder=new Vt(e),this.str=Pt(this.decoder),this.spos=0}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}},Ht=(crypto.subtle,crypto.getRandomValues.bind(crypto)),Ut=Math.random,Jt=()=>Ht(new Uint32Array(1))[0],Kt=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(e^Jt()&15>>e/4).toString(16)),Gt=Date.now,Xt=e=>new Promise(e),Yt=(Promise.all.bind(Promise),new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}});try{"undefined"!=typeof localStorage&&localStorage&&(Yt=localStorage,!1)}catch(au){}var Zt,Qt=Yt,en=Symbol("Equality"),tn=(e,t)=>e===t||!!e?.[en]?.(t)||!1,nn=Object.assign,rn=Object.keys,sn=e=>rn(e).length,on=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},ln=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),an=Object.freeze,cn=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||cn(e[t])}return an(e)},dn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&dn(e,t,n+1)}},hn=(e,t)=>{if(e===t)return!0;if(null==e||null==t||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(null!=e[en])return e[en](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;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(const n of e.keys())if(!t.has(n)||!hn(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(sn(e)!==sn(t))return!1;for(const n in e)if(!ln(e,n)||!hn(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!hn(e[n],t[n]))return!1;break;default:return!1}return!0},un="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),pn="undefined"!=typeof window&&"undefined"!=typeof document&&!un,mn=("undefined"!=typeof navigator&&/Mac/.test(navigator.platform),[]),fn=e=>(()=>{if(void 0===et)if(un){et=Ae();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];"-"===r[0]?(null!==t&&et.set(t,""),t=r):null!==t?(et.set(t,r),t=null):mn.push(r)}null!==t&&et.set(t,"")}else"object"==typeof location?(et=Ae(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");et.set(`--${Xe(t,"-")}`,n),et.set(`-${Xe(t,"-")}`,n)}})):et=Ae();return et})().has(e),gn=e=>(e=>void 0===e?null:e)(un?process.env[e.toUpperCase().replaceAll("-","_")]:Qt.getItem(e)),xn=e=>fn("--"+e)||null!==gn(e),bn=xn("production"),yn=(un&&(tt=process.env.FORCE_COLOR,nt=["true","1","2"],nt.includes(tt))||!fn("--no-colors")&&!xn("no-color")&&(!un||process.stdout.isTTY)&&(!un||fn("--color")||null!==gn("COLORTERM")||(gn("TERM")||"").includes("color")),pn?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Je(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")),wn=class{constructor(e,t){this.left=e,this.right=t}},vn=(e,t)=>new wn(e,t),kn=e=>e.next()>=.5,jn=(e,t,n)=>ze(e.next()*(n+1-t)+t),Sn=(e,t,n)=>ze(e.next()*(n+1-t)+t),Cn=(e,t,n)=>Sn(e,t,n),Nn=e=>Je(Cn(e,97,122)),En=(e,t)=>t[Cn(e,0,t.length-1)],An=Symbol("0schema"),Tn=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){const e=[];for(let t=this._rerrs.length-1;t>0;t--){const n=this._rerrs[t];e.push(st(" ",2*(this._rerrs.length-t))+`${null!=n.path?`[${n.path}] `:""}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join("\n")}},Mn=(e,t)=>e===t||null!=e&&null!=t&&e.constructor===t.constructor&&(e[en]?tn(e,t):Pe(e)?Re(e,e=>Ie(t,t=>Mn(e,t))):"object"==typeof e&&on(e,(e,n)=>Mn(e,t[n]))),_n=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Mn(t,n)}equals(e){return this.constructor===e.constructor&&hn(this.shape,e.shape)}[An](){return!0}[en](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Et()}get nullable(){return lr(this,kr)}get optional(){return new Vn(this)}cast(e){return Nr(e,this),e}expect(e){return Nr(e,this),e}},Dn=class extends _n{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){const n=e?.constructor===this.shape&&(null==this._c||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor!==this.shape?"Constructor match failed":"Check failed"),n}},On=(e,t=null)=>new Dn(e,t),$n=(On(Dn),class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=this.shape(e);return!n&&t?.extend(null,"custom prop",e?.constructor.name,"failed to check custom prop"),n}}),Rn=e=>new $n(e),In=(On($n),class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(" | "),e.toString()),n}}),Pn=(...e)=>new In(e),Ln=On(In),zn=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),Bn=e=>xr.check(e)?[zn(e)]:Ln.check(e)?e.shape.map(e=>e+""):gr.check(e)?["[+-]?\\d+.?\\d*"]:br.check(e)?[".*"]:ar.check(e)?e.shape.map(Bn).flat(1):void At(),Fn=(On(class extends _n{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(Bn).map(e=>`(${e.join("|")})`).join("")+"$")}check(e,t){const n=null!=this._r.exec(e);return!n&&t?.extend(null,this._r.toString(),e.toString(),"String doesn't match string template."),n}}),Symbol("optional")),Vn=class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=void 0===e||this.shape.check(e);return!n&&t?.extend(null,"undefined (optional)","()"),n}get[Fn](){return!0}},Wn=On(Vn),qn=class extends _n{check(e,t){return t?.extend(null,"never",typeof e),!1}},Hn=(new qn,On(qn),class e extends _n{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 null==e?(t?.extend(null,"object","null"),!1):on(this.shape,(n,r)=>{const s=this._isPartial&&!ln(e,r)||n.check(e[r],t);return!s&&t?.extend(r.toString(),n.toString(),typeof e[r],"Object property does not match"),s})}}),Un=On(Hn),Jn=Rn(e=>null!=e&&(e.constructor===Object||null==e.constructor)),Kn=class extends _n{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return null!=e&&on(e,(n,r)=>{const s=this.shape.keys.check(r,t);return!s&&t?.extend(r+"","Record",typeof e,s?"Key doesn't match schema":"Value doesn't match value"),s&&this.shape.values.check(n,t)})}},Gn=(e,t)=>new Kn(e,t),Xn=On(Kn),Yn=class extends _n{constructor(e){super(),this.shape=e}check(e,t){return null!=e&&on(this.shape,(n,r)=>{const s=n.check(e[r],t);return!s&&t?.extend(r.toString(),"Tuple",typeof n),s})}},Zn=(On(Yn),class extends _n{constructor(e){super(),this.shape=1===e.length?e[0]:new or(e)}check(e,t){const n=Pe(e)&&Re(e,e=>this.shape.check(e));return!n&&t?.extend(null,"Array",""),n}}),Qn=(...e)=>new Zn(e),er=On(Zn),tr=Rn(e=>Pe(e)),nr=class extends _n{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){const n=e instanceof this.shape&&(null==this._c||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}},rr=(On(nr),((e,t=null)=>new nr(_n,t))()),sr=On(class extends _n{constructor(e){super(),this.len=e.length-1,this.args=((...e)=>new Yn(e))(...e.slice(-1)),this.res=e[this.len]}check(e,t){const n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,"function",typeof e),n}}),ir=Rn(e=>"function"==typeof e),or=(On(class extends _n{constructor(e){super(),this.shape=e}check(e,t){const n=Re(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,"Intersectinon",typeof e),n}},e=>e.shape.length>0),class extends _n{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){const n=Ie(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),n}}),lr=(...e)=>e.findIndex(e=>ar.check(e))>=0?lr(...e.map(e=>Cr(e)).map(e=>ar.check(e)?e.shape:[e]).flat(1)):1===e.length?e[0]:new or(e),ar=On(or),cr=()=>!0,dr=Rn(cr),hr=On($n,e=>e.shape===cr),ur=Rn(e=>"bigint"==typeof e),pr=Rn(e=>e===ur),mr=Rn(e=>"symbol"==typeof e),fr=(Rn(e=>e===mr),Rn(e=>"number"==typeof e)),gr=Rn(e=>e===fr),xr=Rn(e=>"string"==typeof e),br=Rn(e=>e===xr),yr=Rn(e=>"boolean"==typeof e),wr=Rn(e=>e===yr),vr=Pn(void 0),kr=(On(In,e=>1===e.shape.length&&void 0===e.shape[0]),Pn(void 0),Pn(null)),jr=On(In,e=>1===e.shape.length&&null===e.shape[0]),Sr=(On(Uint8Array),On(Dn,e=>e.shape===Uint8Array),lr(fr,xr,kr,vr,ur,yr,mr)),Cr=((()=>{const e=Qn(dr),t=Gn(xr,dr),n=lr(fr,xr,kr,yr,e,t);e.shape=n,t.shape.values=n})(),e=>{if(rr.check(e))return e;if(Jn.check(e)){const t={};for(const n in e)t[n]=Cr(e[n]);return new Hn(t)}return tr.check(e)?lr(...e.map(Cr)):Sr.check(e)?Pn(e):ir.check(e)?On(e):void At()}),Nr=bn?()=>{}:(e,t)=>{const n=new Tn;if(!t.check(e,n))throw Nt(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Er=(rt=dr,new class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:Cr(e),h:t}),this}else(e){return this.if(dr,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){const r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Nt("Unhandled pattern")}}}(rt)).if(gr,(e,t)=>jn(t,He,qe)).if(br,(e,t)=>((e,t=0,n=20)=>{const r=Cn(e,t,n);let s="";for(let i=0;i<r;i++)s+=Nn(e);return s})(t)).if(wr,(e,t)=>kn(t)).if(pr,(e,t)=>BigInt(jn(t,He,qe))).if(ar,(e,t)=>Ar(t,En(t,e.shape))).if(Un,(e,t)=>{const n={};for(const r in e.shape){let s=e.shape[r];if(Wn.check(s)){if(kn(t))continue;s=s.shape}n[r]=Er(s,t)}return n}).if(er,(e,t)=>{const n=[],r=Sn(t,0,42);for(let s=0;s<r;s++)n.push(Ar(t,e.shape));return n}).if(Ln,(e,t)=>En(t,e.shape)).if(jr,(e,t)=>null).if(sr,(e,t)=>{const n=Ar(t,e.res);return()=>n}).if(hr,(e,t)=>Ar(t,En(t,[fr,xr,kr,vr,ur,yr,Qn(fr),Gn(lr("a","b","c"),fr)]))).if(Xn,(e,t)=>{const n={},r=jn(t,0,3);for(let s=0;s<r;s++)n[Ar(t,e.shape.keys)]=Ar(t,e.shape.values);return n}).done(),Ar=(e,t)=>Er(Cr(t),e),Tr="undefined"!=typeof document?document:{},Mr=(Rn(e=>e.nodeType===Or),"undefined"!=typeof DOMParser&&new DOMParser,Rn(e=>e.nodeType===Mr),Rn(e=>e.nodeType===_r),Tr.ELEMENT_NODE),_r=Tr.TEXT_NODE,Dr=(Tr.CDATA_SECTION_NODE,Tr.COMMENT_NODE,Tr.DOCUMENT_NODE),Or=(Tr.DOCUMENT_TYPE_NODE,Tr.DOCUMENT_FRAGMENT_NODE),$r=(Rn(e=>e.nodeType===Dr),JSON.stringify,Zt=clearTimeout,class{constructor(e){this._=e}destroy(){Zt(this._)}}),Rr=(e,t)=>new $r(setTimeout(t,e)),Ir=Symbol,Pr=Ir(),Lr=Ir(),zr=(Ir(),Ir(),Ir(),Ir()),Br=(Ir(),Ir()),Fr=(Ir(),Gt(),vn("font-weight","bold"),vn("font-weight","normal"),vn("color","blue"),vn("color","green"),vn("color","grey"),vn("color","red"),vn("color","purple"),vn("color","orange"),vn("color","black"),(...e)=>{Wr.forEach(t=>t.print(e))}),Vr=(...e)=>{e.unshift(Br),Wr.forEach(t=>t.print(e))},Wr=_e(),qr=e=>({[Symbol.iterator](){return this},next:e}),Hr=(e,t)=>qr(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),Ur=class{constructor(e,t){this.clock=e,this.len=t}},Jr=class{constructor(){this.clients=new Map}},Kr=(e,t,n)=>t.clients.forEach((t,r)=>{const s=e.doc.store.clients.get(r);if(null!=s){const r=s[s.length-1],i=r.id.clock+r.length;for(let o=0,l=t[o];o<t.length&&l.clock<i;l=t[++o])Vs(e,s,l.clock,l.len,n)}}),Gr=(e,t)=>{const n=e.clients.get(t.client);return void 0!==n&&null!==((e,t)=>{let n=0,r=e.length-1;for(;n<=r;){const s=ze((n+r)/2),i=e[s],o=i.clock;if(o<=t){if(t<o+i.len)return s;n=s+1}else r=s-1}return null})(n,t.clock)},Xr=e=>{e.clients.forEach(e=>{let t,n;for(e.sort((e,t)=>e.clock-t.clock),t=1,n=1;t<e.length;t++){const r=e[n-1],s=e[t];r.clock+r.len>=s.clock?e[n-1]=new Ur(r.clock,Ve(r.len,s.clock+s.len-r.clock)):(n<t&&(e[n]=s),n++)}e.length=n})},Yr=e=>{const t=new Jr;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){const i=r.slice();for(let t=n+1;t<e.length;t++)Oe(i,e[t].clients.get(s)||[]);t.clients.set(s,i)}});return Xr(t),t},Zr=(e,t,n,r)=>{Me(e.clients,t,()=>[]).push(new Ur(n,r))},Qr=()=>new Jr,es=(e,t)=>{dt(e.restEncoder,t.clients.size),$e(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),dt(e.restEncoder,t);const r=n.length;dt(e.restEncoder,r);for(let s=0;s<r;s++){const t=n[s];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},ts=e=>{const t=new Jr,n=Rt(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=Rt(e.restDecoder),r=Rt(e.restDecoder);if(r>0){const s=Me(t.clients,n,()=>[]);for(let t=0;t<r;t++)s.push(new Ur(e.readDsClock(),e.readDsLen()))}}return t},ns=(e,t,n)=>{const r=new Jr,s=Rt(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=Rt(e.restDecoder),i=Rt(e.restDecoder),o=n.clients.get(s)||[],l=Rs(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Zr(r,s,l,i-l);let e=Ps(o,n),a=o[e];for(!a.deleted&&a.id.clock<n&&(o.splice(e+1,0,Mo(t,a,n-a.id.clock)),e++);e<o.length&&(a=o[e++],a.id.clock<i);)a.deleted||(i<a.id.clock+a.length&&o.splice(e,0,Mo(t,a,i-a.id.clock)),a.delete(t))}else Zr(r,s,n,i-n)}}if(r.clients.size>0){const e=new ds;return dt(e.restEncoder,0),es(e,r),e.toUint8Array()}return null},rs=Jt,ss=class e extends Le{constructor({guid:e=Kt(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:s=null,autoLoad:i=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=rs(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Os,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=i,this.meta=s,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Xt(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>Xt(e=>{const t=n=>{void 0!==n&&!0!==n||(this.off("sync",t),e())};this.on("sync",t)});this.on("sync",e=>{!1===e&&this.isSynced&&(this.whenSynced=l()),this.isSynced=void 0===e||!0===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const e=this._item;null===e||this.shouldLoad||Ks(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set($e(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Ks(this,e,t)}get(e,t=gi){const n=Me(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==gi&&r!==t){if(r===gi){const r=new t;r._map=n._map,n._map.forEach(e=>{for(;null!==e;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;null!==e;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=""){return this.get(e,Ri)}getText(e=""){return this.get(e,Qi)}getMap(e=""){return this.get(e,Pi)}getXmlElement(e=""){return this.get(e,no)}getXmlFragment(e=""){return this.get(e,to)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,$e(this.subdocs).forEach(e=>e.destroy());const t=this._item;if(null!==t){this._item=null;const n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,Ks(t.parent.doc,e=>{const 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()}},is=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=Rt(this.restDecoder),this.dsCurrVal}readDsLen(){const e=Rt(this.restDecoder)+1;return this.dsCurrVal+=e,e}},os=class extends is{constructor(e){super(e),this.keys=[],Rt(e),this.keyClockDecoder=new Wt(Ot(e)),this.clientDecoder=new Vt(Ot(e)),this.leftClockDecoder=new Wt(Ot(e)),this.rightClockDecoder=new Wt(Ot(e)),this.infoDecoder=new Ft(Ot(e),$t),this.stringDecoder=new qt(Ot(e)),this.parentInfoDecoder=new Ft(Ot(e),$t),this.typeRefDecoder=new Vt(Ot(e)),this.lenDecoder=new Vt(Ot(e))}readLeftID(){return new bs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new bs(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Bt(this.restDecoder)}readBuf(){return Ot(this.restDecoder)}readJSON(){return Bt(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}},ls=class{constructor(){this.restEncoder=ot()}toUint8Array(){return lt(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){dt(this.restEncoder,e)}writeDsLen(e){dt(this.restEncoder,e)}},as=class extends ls{writeLeftID(e){dt(this.restEncoder,e.client),dt(this.restEncoder,e.clock)}writeRightID(e){dt(this.restEncoder,e.client),dt(this.restEncoder,e.clock)}writeClient(e){dt(this.restEncoder,e)}writeInfo(e){ct(this.restEncoder,e)}writeString(e){mt(this.restEncoder,e)}writeParentInfo(e){dt(this.restEncoder,e?1:0)}writeTypeRef(e){dt(this.restEncoder,e)}writeLen(e){dt(this.restEncoder,e)}writeAny(e){yt(this.restEncoder,e)}writeBuf(e){gt(this.restEncoder,e)}writeJSON(e){mt(this.restEncoder,JSON.stringify(e))}writeKey(e){mt(this.restEncoder,e)}},cs=class{constructor(){this.restEncoder=ot(),this.dsCurrVal=0}toUint8Array(){return lt(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,dt(this.restEncoder,t)}writeDsLen(e){0===e&&At(),dt(this.restEncoder,e-1),this.dsCurrVal+=e}},ds=class extends cs{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new St,this.clientEncoder=new kt,this.leftClockEncoder=new St,this.rightClockEncoder=new St,this.infoEncoder=new wt(ct),this.stringEncoder=new Ct,this.parentInfoEncoder=new wt(ct),this.typeRefEncoder=new kt,this.lenEncoder=new kt}toUint8Array(){const e=ot();return dt(e,0),gt(e,this.keyClockEncoder.toUint8Array()),gt(e,this.clientEncoder.toUint8Array()),gt(e,this.leftClockEncoder.toUint8Array()),gt(e,this.rightClockEncoder.toUint8Array()),gt(e,lt(this.infoEncoder)),gt(e,this.stringEncoder.toUint8Array()),gt(e,lt(this.parentInfoEncoder)),gt(e,this.typeRefEncoder.toUint8Array()),gt(e,this.lenEncoder.toUint8Array()),ft(e,lt(this.restEncoder)),lt(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){yt(this.restEncoder,e)}writeBuf(e){gt(this.restEncoder,e)}writeJSON(e){yt(this.restEncoder,e)}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}},hs=(e,t,n)=>{const r=new Map;n.forEach((e,n)=>{Rs(t,n)>e&&r.set(n,e)}),$s(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),dt(e.restEncoder,r.size),$e(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{((e,t,n,r)=>{r=Ve(r,t[0].id.clock);const s=Ps(t,r);dt(e.restEncoder,t.length-s),e.writeClient(n),dt(e.restEncoder,r);const i=t[s];i.write(e,r-i.id.clock);for(let o=s+1;o<t.length;o++)t[o].write(e,0)})(e,t.clients.get(n),n,r)})},us=(e,t,n,r=os)=>{const s=Dt(t);((e,t,n,r=new os(e))=>{Ks(t,e=>{e.local=!1;let t=!1;const n=e.doc,s=n.store,i=((e,t,n)=>{const r=[];let s=$e(n.keys()).sort((e,t)=>e-t);if(0===s.length)return null;const i=()=>{if(0===s.length)return null;let e=n.get(s[s.length-1]);for(;e.refs.length===e.i;){if(s.pop(),!(s.length>0))return null;e=n.get(s[s.length-1])}return e};let o=i();if(null===o)return null;const l=new Os,a=new Map,c=(e,t)=>{const n=a.get(e);(null==n||n>t)&&a.set(e,t)};let d=o.refs[o.i++];const h=new Map,u=()=>{for(const e of r){const t=e.id.client,r=n.get(t);r?(r.i--,l.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):l.clients.set(t,[e]),s=s.filter(e=>e!==t)}r.length=0};for(;;){if(d.constructor!==Io){const s=Me(h,d.id.client,()=>Rs(t,d.id.client))-d.id.clock;if(s<0)r.push(d),c(d.id.client,d.id.clock-1),u();else{const i=d.getMissing(e,t);if(null!==i){r.push(d);const e=n.get(i)||{refs:[],i:0};if(e.refs.length!==e.i){d=e.refs[e.i++];continue}c(i,Rs(t,i)),u()}else(0===s||s<d.length)&&(d.integrate(e,s),h.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(null!==o&&o.i<o.refs.length)d=o.refs[o.i++];else{if(o=i(),null===o)break;d=o.refs[o.i++]}}if(l.clients.size>0){const e=new ds;return hs(e,l,new Map),dt(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,s,((e,t)=>{const n=Ae(),r=Rt(e.restDecoder);for(let s=0;s<r;s++){const r=Rt(e.restDecoder),s=new Array(r),i=e.readClient();let o=Rt(e.restDecoder);n.set(i,{i:0,refs:s});for(let n=0;n<r;n++){const r=e.readInfo();switch(31&r){case 0:{const t=e.readLen();s[n]=new lo(ws(i,o),t),o+=t;break}case 10:{const t=Rt(e.restDecoder);s[n]=new Io(ws(i,o),t),o+=t;break}default:{const l=!(192&r),a=new Oo(ws(i,o),null,128&~r?null:e.readLeftID(),null,64&~r?null:e.readRightID(),l?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!l||32&~r?null:e.readString(),$o(e,r));s[n]=a,o+=a.length}}}}return n})(r,n)),o=s.pendingStructs;if(o){for(const[e,n]of o.missing)if(n<Rs(s,e)){t=!0;break}if(i){for(const[e,t]of i.missing){const n=o.missing.get(e);(null==n||n>t)&&o.missing.set(e,t)}o.update=ni([o.update,i.update])}}else s.pendingStructs=i;const l=ns(r,e,s);if(s.pendingDs){const t=new os(Dt(s.pendingDs));Rt(t.restDecoder);const n=ns(t,e,s);s.pendingDs=l&&n?ni([l,n]):l||n}else s.pendingDs=l;if(t){const t=s.pendingStructs.update;s.pendingStructs=null,us(e.doc,t)}},n,!1)})(s,e,n,new r(s))},ps=class{constructor(){this.l=[]}},ms=()=>new ps,fs=(e,t)=>e.l.push(t),gs=(e,t)=>{const n=e.l;n.length,e.l=n.filter(e=>t!==e),e.l.length},xs=(e,t,n)=>dn(e.l,[t,n]),bs=class{constructor(e,t){this.client=e,this.clock=t}},ys=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ws=(e,t)=>new bs(e,t),vs=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw At()},ks=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1},js=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},Ss=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}},Cs=(e,t,n)=>{let r=null,s=null;return null===e._item?s=vs(e):r=ws(e._item.id.client,e._item.id.clock),new js(r,s,t,n)},Ns=(e,t,n=0)=>{let r=e._start;if(n<0){if(0===t)return Cs(e,null,n);t--}for(;null!==r;){if(!r.deleted&&r.countable){if(r.length>t)return Cs(e,ws(r.id.client,r.id.clock+t),n);t-=r.length}if(null===r.right&&n<0)return Cs(e,r.lastId,n);r=r.right}return Cs(e,null,n)},Es=(e,t,n=!0)=>{const r=t.store,s=e.item,i=e.type,o=e.tname,l=e.assoc;let a=null,c=0;if(null!==s){if(Rs(r,s.client)<=s.clock)return null;const e=n?Ao(r,s):((e,t)=>{const n=Ls(e,t);return{item:n,diff:t.clock-n.id.clock}})(r,s),t=e.item;if(!(t instanceof Oo))return null;if(a=t.parent,null===a._item||!a._item.deleted){c=t.deleted||!t.countable?0:e.diff+(l>=0?0:1);let n=t.left;for(;null!==n;)!n.deleted&&n.countable&&(c+=n.length),n=n.left}}else{if(null!==o)a=t.get(o);else{if(null===i)throw At();{if(Rs(r,i.client)<=i.clock)return null;const{item:e}=n?Ao(r,i):{item:Ls(r,i)};if(!(e instanceof Oo&&e.content instanceof Eo))return null;a=e.content.type}}c=l>=0?a._length:0}return((e,t,n=0)=>new Ss(e,t,n))(a,c,e.assoc)},As=class{constructor(e,t){this.ds=e,this.sv=t}},Ts=(e,t)=>new As(e,t),Ms=(Ts(Qr(),new Map),e=>Ts((e=>{const t=Qr();return e.clients.forEach((e,n)=>{const r=[];for(let t=0;t<e.length;t++){const n=e[t];if(n.deleted){const s=n.id.clock;let i=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[1+ ++t])i+=n.length;r.push(new Ur(s,i))}}r.length>0&&t.clients.set(n,r)}),t})(e.store),$s(e.store))),_s=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Gr(t.ds,e.id),Ds=(e,t)=>{const n=Me(e.meta,Ds,_e),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<Rs(r,n)&&Bs(e,ws(n,t))}),Kr(e,t.ds,e=>{}),n.add(t))},Os=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},$s=e=>{const t=new Map;return e.clients.forEach((e,n)=>{const r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},Rs=(e,t)=>{const n=e.clients.get(t);if(void 0===n)return 0;const r=n[n.length-1];return r.id.clock+r.length},Is=(e,t)=>{let n=e.clients.get(t.id.client);if(void 0===n)n=[],e.clients.set(t.id.client,n);else{const e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw At()}n.push(t)},Ps=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=ze(t/(i+s.length-1)*r);for(;n<=r;){if(s=e[o],i=s.id.clock,i<=t){if(t<i+s.length)return o;n=o+1}else r=o-1;o=ze((n+r)/2)}throw At()},Ls=(e,t)=>{const n=e.clients.get(t.client);return n[Ps(n,t.clock)]},zs=(e,t,n)=>{const r=Ps(t,n),s=t[r];return s.id.clock<n&&s instanceof Oo?(t.splice(r+1,0,Mo(e,s,n-s.id.clock)),r+1):r},Bs=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[zs(e,n,t.clock)]},Fs=(e,t,n)=>{const r=t.clients.get(n.client),s=Ps(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==lo&&r.splice(s+1,0,Mo(e,i,n.clock-i.id.clock+1)),i},Vs=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,l=zs(e,t,n);do{o=t[l++],i<o.id.clock+o.length&&zs(e,t,i),s(o)}while(l<t.length&&t[l].id.clock<i)},Ws=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Jr,this.beforeState=$s(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}},qs=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[n,r]of e)if(t(r,n))return!0;return!1})(t.afterState,(e,n)=>t.beforeState.get(n)!==e)||(Xr(t.deleteSet),((e,t)=>{hs(e,t.doc.store,t.beforeState)})(e,t),es(e,t.deleteSet),0)),Hs=(e,t,n)=>{const r=t._item;(null===r||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&Me(e.changed,t,_e).add(n)},Us=(e,t)=>{let n=e[t],r=e[t-1],s=t;for(;s>0&&r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n);n=r,r=e[--s-1])n instanceof Oo&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);const i=t-s;return i&&e.splice(t+1-i,i),i},Js=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Xr(i),n.afterState=$s(n.doc.store),r.emit("beforeObserverCalls",[n,r]);const e=[];n.changed.forEach((t,r)=>e.push(()=>{null!==r._item&&r._item.deleted||r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(null===r._item||!r._item.deleted)&&((t=t.filter(e=>null===e.target._item||!e.target._item.deleted)).forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{xs(r._dEH,t,n)}))}),e.push(()=>r.emit("afterTransaction",[n,r])),e.push(()=>{n._needFormattingCleanup&&Xi(n)})}),dn(e,[])}finally{r.gc&&((e,t,n)=>{for(const[r,s]of e.clients.entries()){const e=t.clients.get(r);for(let r=s.length-1;r>=0;r--){const i=s[r],o=i.clock+i.len;for(let r=Ps(e,i.clock),s=e[r];r<e.length&&s.id.clock<o;s=e[++r]){const s=e[r];if(i.clock+i.len<=s.id.clock)break;s instanceof Oo&&s.deleted&&!s.keep&&n(s)&&s.gc(t,!1)}}}})(i,s,r.gcFilter),((e,t)=>{e.clients.forEach((e,n)=>{const r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){const n=e[t];for(let e=Fe(r.length-1,1+Ps(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+Us(r,e)}})})(i,s),n.afterState.forEach((e,t)=>{const r=n.beforeState.get(t)||0;if(r!==e){const e=s.clients.get(t),n=Ve(Ps(e,r),1);for(let t=e.length-1;t>=n;)t-=1+Us(e,t)}});for(let e=o.length-1;e>=0;e--){const{client:t,clock:n}=o[e].id,r=s.clients.get(t),i=Ps(r,n);i+1<r.length&&Us(r,i+1)>1||i>0&&Us(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(Fr(Br,Pr,"[yjs] ",Lr,zr,"Changed the client-id because another client seems to be using it."),r.clientID=rs()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new as;qs(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new ds;qs(e,n)&&r.emit("updateV2",[e.toUint8Array(),n.origin,r,n])}const{subdocsAdded:l,subdocsLoaded:a,subdocsRemoved:c}=n;(l.size>0||c.size>0||a.size>0)&&(l.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),c.forEach(e=>r.subdocs.delete(e)),r.emit("subdocs",[{loaded:a,added:l,removed:c},r,n]),c.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):Js(e,t+1)}}},Ks=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new Ws(e,n,r),s.push(e._transaction),1===s.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{o=t(e._transaction)}finally{if(i){const t=e._transaction===s[0];e._transaction=null,t&&Js(s,0)}}return o},Gs=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Xs=(e,t,n)=>{Kr(e,n.deletions,n=>{n instanceof Oo&&t.scope.some(t=>t===e.doc||ks(t,n))&&To(n,!1)})},Ys=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;Ks(s,n=>{for(;t.length>0&&null===e.currStackItem;){const r=s.store,o=t.pop(),l=new Set,a=[];let c=!1;Kr(n,o.insertions,e=>{if(e instanceof Oo){if(null!==e.redone){let{item:t,diff:s}=Ao(r,e.id);s>0&&(t=Bs(n,ws(t.id.client,t.id.clock+s))),e=t}!e.deleted&&i.some(t=>t===n.doc||ks(t,e))&&a.push(e)}}),Kr(n,o.deletions,e=>{e instanceof Oo&&i.some(t=>t===n.doc||ks(t,e))&&!Gr(o.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==Do(n,t,l,o.insertions,e.ignoreRemoteMapChanges,e)||c});for(let t=a.length-1;t>=0;t--){const r=a[t];e.deleteFilter(r)&&(r.delete(n),c=!0)}e.currStackItem=c?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);const o=e.currStackItem;if(null!=o){const t=r.changedParentTypes;e.emit("stack-item-popped",[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o},Zs=class extends Le{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:o=(Pe(e)?e[0].doc:e instanceof ss?e:e.doc)}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,s.add(this),this.trackedOrigins=s,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=i,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;const t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);const s=new Jr;e.afterState.forEach((t,n)=>{const r=e.beforeState.get(n)||0,i=t-r;i>0&&Zr(s,n,r,i)});const i=Gt();let o=!1;if(this.lastChange>0&&i-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){const t=r[r.length-1];t.deletions=Yr([t.deletions,e.deleteSet]),t.insertions=Yr([t.insertions,s])}else r.push(new Gs(e.deleteSet,s)),o=!0;t||n||(this.lastChange=i),Kr(e,e.deleteSet,t=>{t instanceof Oo&&this.scope.some(n=>n===e.doc||ks(n,t))&&To(t,!0)});const l=[{stackItem:r[r.length-1],origin:e.origin,type:t?"redo":"undo",changedParentTypes:e.changedParentTypes},this];o?this.emit("stack-item-added",l):this.emit("stack-item-updated",l)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(e){const t=new Set(this.scope);(e=Pe(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof gi?e.doc!==this.doc:e!==this.doc)&&Vr("[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=>Xs(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Xs(n,this,e)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){let e;this.undoing=!0;try{e=Ys(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=Ys(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}},Qs=class{constructor(e,t){this.gen=function*(e){const t=Rt(e.restDecoder);for(let n=0;n<t;n++){const t=Rt(e.restDecoder),n=e.readClient();let r=Rt(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=Rt(e.restDecoder);yield new Io(ws(n,r),t),r+=t}else if(31&t){const s=!(192&t),i=new Oo(ws(n,r),null,128&~t?null:e.readLeftID(),null,64&~t?null:e.readRightID(),s?e.readParentInfo()?e.readString():e.readLeftID():null,!s||32&~t?null:e.readString(),$o(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new lo(ws(n,r),t),r+=t}}}}(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Io);return this.curr}},ei=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ti=(e,t)=>{if(e.constructor===lo){const{client:n,clock:r}=e.id;return new lo(ws(n,r+t),e.length-t)}if(e.constructor===Io){const{client:n,clock:r}=e.id;return new Io(ws(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new Oo(ws(r,s+t),null,ws(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ni=(e,t=os,n=ds)=>{if(1===e.length)return e[0];const r=e.map(e=>new t(Dt(e)));let s=r.map(e=>new Qs(e,!0)),i=null;const o=new n,l=new ei(o);for(;s=s.filter(e=>null!==e.curr),s.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){const n=e.curr.id.clock-t.curr.id.clock;return 0===n?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Io?1:-1:n}return t.curr.id.client-e.curr.id.client}),0!==s.length;){const e=s[0],t=e.curr.id.client;if(null!==i){let n=e.curr,r=!1;for(;null!==n&&n.id.clock+n.length<=i.struct.id.clock+i.struct.length&&n.id.client>=i.struct.id.client;)n=e.next(),r=!0;if(null===n||n.id.client!==t||r&&n.id.clock>i.struct.id.clock+i.struct.length)continue;if(t!==i.struct.id.client)si(l,i.struct,i.offset),i={struct:n,offset:0},e.next();else if(i.struct.id.clock+i.struct.length<n.id.clock)if(i.struct.constructor===Io)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{si(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Io(ws(t,i.struct.id.clock+i.struct.length),e),offset:0}}else{const t=i.struct.id.clock+i.struct.length-n.id.clock;t>0&&(i.struct.constructor===Io?i.struct.length-=t:n=ti(n,t)),i.struct.mergeWith(n)||(si(l,i.struct,i.offset),i={struct:n,offset:0},e.next())}}else i={struct:e.curr,offset:0},e.next();for(let n=e.curr;null!==n&&n.id.client===t&&n.id.clock===i.struct.id.clock+i.struct.length&&n.constructor!==Io;n=e.next())si(l,i.struct,i.offset),i={struct:n,offset:0}}return null!==i&&(si(l,i.struct,i.offset),i=null),ii(l),es(o,Yr(r.map(e=>ts(e)))),o.toUint8Array()},ri=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:lt(e.encoder.restEncoder)}),e.encoder.restEncoder=ot(),e.written=0)},si=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ri(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),dt(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},ii=e=>{ri(e);const t=e.encoder.restEncoder;dt(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];dt(t,r.written),ft(t,r.restEncoder)}},oi="You must not compute changes after the event-handler fired.",li=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=ai(this.currentTarget,this.target))}deletes(e){return Gr(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Nt(oi);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(null!==n){const r=t._map.get(n);let s,i;if(this.adds(r)){let e=r.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(r)){if(null===e||!this.deletes(e))return;s="delete",i=De(e.content.getContent())}else null!==e&&this.deletes(e)?(s="update",i=De(e.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=De(r.content.getContent())}e.set(n,{action:s,oldValue:i})}}),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(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw Nt(oi);const t=this.target,n=_e(),r=_e(),s=[];if(e={added:n,deleted:r,delta:s,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null;const i=()=>{e&&s.push(e)};for(let s=t._start;null!==s;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&(null!==e&&void 0!==e.delete||(i(),e={delete:0}),e.delete+=s.length,r.add(s)):this.adds(s)?(null!==e&&void 0!==e.insert||(i(),e={insert:[]}),e.insert=e.insert.concat(s.content.getContent()),n.add(s)):(null!==e&&void 0!==e.retain||(i(),e={retain:0}),e.retain+=s.length);null!==e&&void 0===e.retain&&i()}this._changes=e}return e}},ai=(e,t)=>{const n=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&null!==r;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},ci=()=>{Vr("Invalid access: Add Yjs type to a document before reading data.")},di=0,hi=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=di++}},ui=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=di++},pi=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const n=0===e._searchMarker.length?null:e._searchMarker.reduce((e,n)=>Be(t-e.index)<Be(t-n.index)?e:n);let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=di++})(n));null!==r.right&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;null!==r.left&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return null!==n&&Be(n.index-s)<r.parent.length/80?(ui(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return ui(r,t,n),r}{const r=new hi(t,n);return e.push(r),r}})(e._searchMarker,r,s)},mi=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){const s=e[r];if(n>0){let t=s.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(s.index-=t.length);if(null===t||!0===t.marker){e.splice(r,1);continue}s.p=t,t.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=Ve(t,s.index+n))}},fi=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;Me(s,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;xs(r._eH,n,t)},gi=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ms(),this._dEH=ms(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Et()}clone(){throw Et()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){fs(this._eH,e)}observeDeep(e){fs(this._dEH,e)}unobserve(e){gs(this._eH,e)}unobserveDeep(e){gs(this._dEH,e)}toJSON(){}},xi=(e,t,n)=>{e.doc??ci(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t;const s=[];let i=e._start;for(;null!==i&&r>0;){if(i.countable&&!i.deleted){const e=i.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)s.push(e[n]),r--;t=0}}i=i.right}return s},bi=e=>{e.doc??ci();const t=[];let n=e._start;for(;null!==n;){if(n.countable&&!n.deleted){const e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},yi=(e,t)=>{const n=[];let r=e._start;for(;null!==r;){if(r.countable&&_s(r,t)){const e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},wi=(e,t)=>{let n=0,r=e._start;for(e.doc??ci();null!==r;){if(r.countable&&!r.deleted){const s=r.content.getContent();for(let r=0;r<s.length;r++)t(s[r],n++,e)}r=r.right}},vi=(e,t)=>{const n=[];return wi(e,(r,s)=>{n.push(t(r,s,e))}),n},ki=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(null===n){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}const e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},ji=(e,t)=>{e.doc??ci();const n=pi(e,t);let r=e._start;for(null!==n&&(r=n.p,t-=n.index);null!==r;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},Si=(e,t,n,r)=>{let s=n;const i=e.doc,o=i.clientID,l=i.store,a=null===n?t._start:n.right;let c=[];const d=()=>{c.length>0&&(s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new xo(c)),s.integrate(e,0),c=[])};r.forEach(n=>{if(null===n)c.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:c.push(n);break;default:switch(d(),n.constructor){case Uint8Array:case ArrayBuffer:s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new ao(new Uint8Array(n))),s.integrate(e,0);break;case ss:s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new uo(n)),s.integrate(e,0);break;default:if(!(n instanceof gi))throw new Error("Unexpected content type in insert operation");s=new Oo(ws(o,Rs(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new Eo(n)),s.integrate(e,0)}}}),d()},Ci=()=>Nt("Length exceeded!"),Ni=(e,t,n,r)=>{if(n>t._length)throw Ci();if(0===n)return t._searchMarker&&mi(t._searchMarker,n,r.length),Si(e,t,null,r);const s=n,i=pi(t,n);let o=t._start;for(null!==i&&(o=i.p,0===(n-=i.index)&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));null!==o;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&Bs(e,ws(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&mi(t._searchMarker,s,r.length),Si(e,t,o,r)},Ei=(e,t,n,r)=>{if(0===r)return;const s=n,i=r,o=pi(t,n);let l=t._start;for(null!==o&&(l=o.p,n-=o.index);null!==l&&n>0;l=l.right)!l.deleted&&l.countable&&(n<l.length&&Bs(e,ws(l.id.client,l.id.clock+n)),n-=l.length);for(;r>0&&null!==l;)l.deleted||(r<l.length&&Bs(e,ws(l.id.client,l.id.clock+r)),l.delete(e),r-=l.length),l=l.right;if(r>0)throw Ci();t._searchMarker&&mi(t._searchMarker,s,-i+r)},Ai=(e,t,n)=>{const r=t._map.get(n);void 0!==r&&r.delete(e)},Ti=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let l;if(null==r)l=new xo([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new xo([r]);break;case Uint8Array:l=new ao(r);break;case ss:l=new uo(r);break;default:if(!(r instanceof gi))throw new Error("Unexpected content type");l=new Eo(r)}new Oo(ws(o,Rs(i.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Mi=(e,t)=>{e.doc??ci();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},_i=e=>{const t={};return e.doc??ci(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},Di=(e,t)=>{e.doc??ci();const n=e._map.get(t);return void 0!==n&&!n.deleted},Oi=e=>{return e.doc??ci(),t=e._map.entries(),n=e=>!e[1].deleted,qr(()=>{let e;do{e=t.next()}while(!e.done&&!n(e.value));return e});var t,n},$i=class extends li{},Ri=class e extends gi{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const 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(){const t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}get length(){return this.doc??ci(),this._length}_callObserver(e,t){super._callObserver(e,t),fi(this,e,new $i(this,e))}insert(e,t){null!==this.doc?Ks(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Ks(this.doc,t=>{((e,t,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;Si(e,t,r,n)})(t,this,e)}):this._prelimContent.push(...e)}unshift(e){this.insert(0,e)}delete(e,t=1){null!==this.doc?Ks(this.doc,n=>{Ei(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return ji(this,e)}toArray(){return bi(this)}slice(e=0,t=this.length){return xi(this,e,t)}toJSON(){return this.map(e=>e instanceof gi?e.toJSON():e)}map(e){return vi(this,e)}forEach(e){wi(this,e)}[Symbol.iterator](){return ki(this)}_write(e){e.writeTypeRef(wo)}},Ii=class extends li{constructor(e,t,n){super(e,t),this.keysChanged=n}},Pi=class e extends gi{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?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(){const t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof gi?e.clone():e)}),t}_callObserver(e,t){fi(this,e,new Ii(this,e,t))}toJSON(){this.doc??ci();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const r=t.content.getContent()[t.length-1];e[n]=r instanceof gi?r.toJSON():r}}),e}get size(){return[...Oi(this)].length}keys(){return Hr(Oi(this),e=>e[0])}values(){return Hr(Oi(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Hr(Oi(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ci(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Mi(this,e)}has(e){return Di(this,e)}clear(){null!==this.doc?Ks(this.doc,e=>{this.forEach(function(t,n,r){Ai(e,r,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(vo)}},Li=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||sn(e)===sn(t)&&on(e,(e,n)=>(void 0!==e||ln(t,n))&&tn(t[n],e)))(e,t),zi=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){null===this.right&&At(),this.right.content.constructor===mo?this.right.deleted||Wi(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},Bi=(e,t,n)=>{for(;null!==t.right&&n>0;)t.right.content.constructor===mo?t.right.deleted||Wi(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&Bs(e,ws(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length),t.left=t.right,t.right=t.right.right;return t},Fi=(e,t,n,r)=>{const s=new Map,i=r?pi(t,n):null;return i?Bi(e,new zi(i.p.left,i.p,i.index,s),n-i.index):Bi(e,new zi(null,t._start,0,s),n)},Vi=(e,t,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===mo&&Li(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();const s=e.doc,i=s.clientID;r.forEach((r,o)=>{const l=n.left,a=n.right,c=new Oo(ws(i,Rs(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new mo(o,r));c.integrate(e,0),n.right=c,n.forward()})},Wi=(e,t)=>{const{key:n,value:r}=t;null===r?e.delete(n):e.set(n,r)},qi=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===mo&&Li(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Hi=(e,t,n,r)=>{const s=e.doc,i=s.clientID,o=new Map;for(const l in r){const a=r[l],c=n.currentAttributes.get(l)??null;if(!Li(c,a)){o.set(l,c);const{left:r,right:d}=n;n.right=new Oo(ws(i,Rs(s.store,i)),r,r&&r.lastId,d,d&&d.id,t,null,new mo(l,a)),n.right.integrate(e,0),n.forward()}}return o},Ui=(e,t,n,r,s)=>{n.currentAttributes.forEach((e,t)=>{void 0===s[t]&&(s[t]=null)});const i=e.doc,o=i.clientID;qi(n,s);const l=Hi(e,t,n,s),a=r.constructor===String?new bo(r):r instanceof gi?new Eo(r):new po(r);let{left:c,right:d,index:h}=n;t._searchMarker&&mi(t._searchMarker,n.index,a.getLength()),d=new Oo(ws(o,Rs(i.store,o)),c,c&&c.lastId,d,d&&d.id,t,null,a),d.integrate(e,0),n.right=d,n.index=h,n.forward(),Vi(e,t,n,l)},Ji=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;qi(n,s);const l=Hi(e,t,n,s);e:for(;null!==n.right&&(r>0||l.size>0&&(n.right.deleted||n.right.content.constructor===mo));){if(!n.right.deleted)switch(n.right.content.constructor){case mo:{const{key:t,value:i}=n.right.content,o=s[t];if(void 0!==o){if(Li(o,i))l.delete(t);else{if(0===r)break e;l.set(t,i)}n.right.delete(e)}else n.currentAttributes.set(t,i);break}default:r<n.right.length&&Bs(e,ws(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let s="";for(;r>0;r--)s+="\n";n.right=new Oo(ws(o,Rs(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new bo(s)),n.right.integrate(e,0),n.forward()}Vi(e,t,n,l)},Ki=(e,t,n,r,s)=>{let i=t;const o=Ae();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===mo){const e=i.content;o.set(e.key,e)}i=i.right}let l=0,a=!1;for(;t!==i;){if(n===t&&(a=!0),!t.deleted){const n=t.content;switch(n.constructor){case mo:{const{key:i,value:c}=n,d=r.get(i)??null;o.get(i)===n&&d!==c||(t.delete(e),l++,a||(s.get(i)??null)!==c||d===c||(null===d?s.delete(i):s.set(i,d))),a||t.deleted||Wi(s,n);break}}}t=t.right}return l},Gi=e=>{let t=0;return Ks(e.doc,n=>{let r=e._start,s=e._start,i=Ae();const o=Te(i);for(;s;)!1===s.deleted&&(s.content.constructor===mo?Wi(o,s.content):(t+=Ki(n,r,s,i,o),i=Te(o),r=s)),s=s.right}),t},Xi=e=>{const t=new Set,n=e.doc;for(const[r,s]of e.afterState.entries()){const i=e.beforeState.get(r)||0;s!==i&&Vs(e,n.store.clients.get(r),i,s,e=>{e.deleted||e.content.constructor!==mo||e.constructor===lo||t.add(e.parent)})}Ks(n,n=>{Kr(e,e.deleteSet,e=>{if(e instanceof lo||!e.parent._hasFormatting||t.has(e.parent))return;const r=e.parent;e.content.constructor===mo?t.add(r):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===mo){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}})(n,e)});for(const e of t)Gi(e)})},Yi=(e,t,n)=>{const r=n,s=Te(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case Eo:case po:case bo:n<t.right.length&&Bs(e,ws(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&Ki(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&mi(o._searchMarker,t.index,-r+n),t},Zi=class extends li{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{null===e?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];Ks(e,e=>{const n=new Map,r=new Map;let s=this.target._start,i=null;const o={};let l="",a=0,c=0;const d=()=>{if(null!==i){let e=null;switch(i){case"delete":c>0&&(e={delete:c}),c=0;break;case"insert":("object"==typeof l||l.length>0)&&(e={insert:l},n.size>0&&(e.attributes={},n.forEach((t,n)=>{null!==t&&(e.attributes[n]=t)}))),l="";break;case"retain":a>0&&(e={retain:a},(e=>{for(const t in e)return!1;return!0})(o)||(e.attributes=nn({},o))),a=0}e&&t.push(e),i=null}};for(;null!==s;){switch(s.content.constructor){case Eo:case po:this.adds(s)?this.deletes(s)||(d(),i="insert",l=s.content.getContent()[0],d()):this.deletes(s)?("delete"!==i&&(d(),i="delete"),c+=1):s.deleted||("retain"!==i&&(d(),i="retain"),a+=1);break;case bo:this.adds(s)?this.deletes(s)||("insert"!==i&&(d(),i="insert"),l+=s.content.str):this.deletes(s)?("delete"!==i&&(d(),i="delete"),c+=s.length):s.deleted||("retain"!==i&&(d(),i="retain"),a+=s.length);break;case mo:{const{key:t,value:l}=s.content;if(this.adds(s))this.deletes(s)||(Li(n.get(t)??null,l)?null!==l&&s.delete(e):("retain"===i&&d(),Li(l,r.get(t)??null)?delete o[t]:o[t]=l));else if(this.deletes(s)){r.set(t,l);const e=n.get(t)??null;Li(e,l)||("retain"===i&&d(),o[t]=e)}else if(!s.deleted){r.set(t,l);const n=o[t];void 0!==n&&(Li(n,l)?null!==n&&s.delete(e):("retain"===i&&d(),null===l?delete o[t]:o[t]=l))}s.deleted||("insert"===i&&d(),Wi(n,s.content));break}}s=s.right}for(d();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop()}}),this._delta=t}return this._delta}},Qi=class e extends gi{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ci(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(au){}this._pending=null}_copy(){return new e}clone(){const t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);const n=new Zi(this,e,t);fi(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ci();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===bo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Ks(this.doc,n=>{const r=new zi(null,this._start,0,new Map);for(let s=0;s<e.length;s++){const i=e[s];if(void 0!==i.insert){const o=t||"string"!=typeof i.insert||s!==e.length-1||null!==r.right||"\n"!==i.insert.slice(-1)?i.insert:i.insert.slice(0,-1);("string"!=typeof o||o.length>0)&&Ui(n,this,r,o,i.attributes||{})}else void 0!==i.retain?Ji(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&Yi(n,r,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??ci();const r=[],s=new Map,i=this.doc;let o="",l=this._start;function a(){if(o.length>0){const e={};let t=!1;s.forEach((n,r)=>{t=!0,e[r]=n});const n={insert:o};t&&(n.attributes=e),r.push(n),o=""}}const c=()=>{for(;null!==l;){if(_s(l,e)||void 0!==t&&_s(l,t))switch(l.content.constructor){case bo:{const r=s.get("ychange");void 0===e||_s(l,e)?void 0===t||_s(l,t)?void 0!==r&&(a(),s.delete("ychange")):void 0!==r&&r.user===l.id.client&&"added"===r.type||(a(),s.set("ychange",n?n("added",l.id):{type:"added"})):void 0!==r&&r.user===l.id.client&&"removed"===r.type||(a(),s.set("ychange",n?n("removed",l.id):{type:"removed"})),o+=l.content.str;break}case Eo:case po:{a();const e={insert:l.content.getContent()[0]};if(s.size>0){const t={};e.attributes=t,s.forEach((e,n)=>{t[n]=e})}r.push(e);break}case mo:_s(l,e)&&(a(),Wi(s,l.content))}l=l.right}a()};return e||t?Ks(i,n=>{e&&Ds(n,e),t&&Ds(n,t),c()},"cleanup"):c(),r}insert(e,t,n){if(t.length<=0)return;const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!n);n||(n={},s.currentAttributes.forEach((e,t)=>{n[t]=e})),Ui(r,this,s,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!n);Ui(r,this,s,t,n||{})}):this._pending.push(()=>this.insertEmbed(e,t,n||{}))}delete(e,t){if(0===t)return;const n=this.doc;null!==n?Ks(n,n=>{Yi(n,Fi(n,this,e,!0),t)}):this._pending.push(()=>this.delete(e,t))}format(e,t,n){if(0===t)return;const r=this.doc;null!==r?Ks(r,r=>{const s=Fi(r,this,e,!1);null!==s.right&&Ji(r,this,s,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Mi(this,e)}getAttributes(){return _i(this)}_write(e){e.writeTypeRef(ko)}},eo=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ci()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==no&&t.constructor!==to||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item}else e=t._start}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,null===e?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},to=class e extends gi{constructor(){super(),this._prelimContent=[]}get firstChild(){const 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(){const t=new e;return t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}get length(){return this.doc??ci(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new eo(this,e)}querySelector(e){e=e.toUpperCase();const t=new eo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),$e(new eo(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){fi(this,e,new ro(this,t,e))}toString(){return vi(this,e=>e.toString()).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},n){const r=e.createDocumentFragment();return void 0!==n&&n._createAssociation(r,this),wi(this,s=>{r.insertBefore(s.toDOM(e,t,n),null)}),r}insert(e,t){null!==this.doc?Ks(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Ks(this.doc,n=>{const r=e&&e instanceof gi?e._item:e;Si(n,this,r,t)});else{const n=this._prelimContent,r=null===e?0:n.findIndex(t=>t===e)+1;if(0===r&&null!==e)throw Nt("Reference item not found");n.splice(r,0,...t)}}delete(e,t=1){null!==this.doc?Ks(this.doc,n=>{Ei(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return bi(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ji(this,e)}slice(e=0,t=this.length){return xi(this,e,t)}forEach(e){wi(this,e)}_write(e){e.writeTypeRef(So)}},no=class e extends to{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const 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(){const t=new e(this.nodeName);return((e,t)=>{for(const n in e)t(e[n],n)})(this.getAttributes(),(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof gi?e.clone():e)),t}toString(){const e=this.getAttributes(),t=[],n=[];for(const i in e)n.push(i);n.sort();const r=n.length;for(let i=0;i<r;i++){const r=n[i];t.push(r+'="'+e[r]+'"')}const s=this.nodeName.toLocaleLowerCase();return`<${s}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${s}>`}removeAttribute(e){null!==this.doc?Ks(this.doc,t=>{Ai(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Ks(this.doc,n=>{Ti(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Mi(this,e)}hasAttribute(e){return Di(this,e)}getAttributes(e){return e?((e,t)=>{const n={};return this._map.forEach((e,r)=>{let s=e;for(;null!==s&&(!t.sv.has(s.id.client)||s.id.clock>=(t.sv.get(s.id.client)||0));)s=s.left;null!==s&&_s(s,t)&&(n[r]=s.content.getContent()[s.length-1])}),n})(0,e):_i(this)}toDOM(e=document,t={},n){const r=e.createElement(this.nodeName),s=this.getAttributes();for(const i in s){const e=s[i];"string"==typeof e&&r.setAttribute(i,e)}return wi(this,s=>{r.appendChild(s.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(jo),e.writeKey(this.nodeName)}},ro=class extends li{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{null===e?this.childListChanged=!0:this.attributesChanged.add(e)})}},so=class e extends Pi{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){const t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){const r=t[this.hookName];let s;return s=void 0!==r?r.createDom(this):document.createElement(this.hookName),s.setAttribute("data-yjs-hook",this.hookName),void 0!==n&&n._createAssociation(s,this),s}_write(e){e.writeTypeRef(Co),e.writeKey(this.hookName)}},io=class e extends Qi{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){const t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){const r=e.createTextNode(this.toString());return void 0!==n&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{const t=[];for(const r in e.attributes){const n=[];for(const t in e.attributes[r])n.push({key:t,value:e.attributes[r][t]});n.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:r,attrs:n})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n="";for(let r=0;r<t.length;r++){const e=t[r];n+=`<${e.nodeName}`;for(let t=0;t<e.attrs.length;t++){const r=e.attrs[t];n+=` ${r.key}="${r.value}"`}n+=">"}n+=e.insert;for(let r=t.length-1;r>=0;r--)n+=`</${t[r].nodeName}>`;return n}).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef(No)}},oo=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Et()}mergeWith(e){return!1}write(e,t,n){throw Et()}integrate(e,t){throw Et()}},lo=class extends oo{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),Is(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},ao=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 Et()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},co=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){const n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){Zr(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}},ho=(e,t)=>new ss({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),uo=class e{constructor(e){e._item,this.doc=e;const t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),null!==e.meta&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(ho(this.doc.guid,this.opts))}splice(e){throw Et()}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}},po=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 Et()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},mo=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 Et()}mergeWith(e){return!1}integrate(e,t){const 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}},fo=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){const 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){const n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];e.writeString(void 0===t?"undefined":JSON.stringify(t))}}getRef(){return 2}},go="development"===gn("node_env"),xo=class e{constructor(e){this.arr=e,go&&cn(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){const 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){const n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){const t=this.arr[r];e.writeAny(t)}}getRef(){return 8}},bo=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){const n=new e(this.str.slice(t));this.str=this.str.slice(0,t);const r=this.str.charCodeAt(t-1);return 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(0===t?this.str:this.str.slice(t))}getRef(){return 4}},yo=[e=>new Ri,e=>new Pi,e=>new Qi,e=>new no(e.readKey()),e=>new to,e=>new so(e.readKey()),e=>new io],wo=0,vo=1,ko=2,jo=3,So=4,Co=5,No=6,Eo=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 Et()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;null!==t;)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(;null!==t;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;null!==t;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}},Ao=(e,t)=>{let n,r=t,s=0;do{s>0&&(r=ws(r.client,r.clock+s)),n=Ls(e,r),s=r.clock-n.id.clock,r=n.redone}while(null!==r&&n instanceof Oo);return{item:n,diff:s}},To=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},Mo=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new Oo(ws(r,s+n),t,ws(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),null!==t.redone&&(i.redone=ws(t.redone.client,t.redone.clock+n)),t.right=i,null!==i.right&&(i.right.left=i),e._mergeStructs.push(i),null!==i.parentSub&&null===i.right&&i.parent._map.set(i.parentSub,i),t.length=n,i},_o=(e,t)=>Ie(e,e=>Gr(e.deletions,t)),Do=(e,t,n,r,s,i)=>{const o=e.doc,l=o.store,a=o.clientID,c=t.redone;if(null!==c)return Bs(e,c);let d,h=t.parent._item,u=null;if(null!==h&&!0===h.deleted){if(null===h.redone&&(!n.has(h)||null===Do(e,h,n,r,s,i)))return null;for(;null!==h.redone;)h=Bs(e,h.redone)}const p=null===h?t.parent:h.content.type;if(null===t.parentSub){for(u=t.left,d=t;null!==u;){let t=u;for(;null!==t&&t.parent._item!==h;)t=null===t.redone?null:Bs(e,t.redone);if(null!==t&&t.parent._item===h){u=t;break}u=u.left}for(;null!==d;){let t=d;for(;null!==t&&t.parent._item!==h;)t=null===t.redone?null:Bs(e,t.redone);if(null!==t&&t.parent._item===h){d=t;break}d=d.right}}else{if(d=null,t.right&&!s){for(u=t;null!==u&&null!==u.right&&(u.right.redone||Gr(r,u.right.id)||_o(i.undoStack,u.right.id)||_o(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=Bs(e,u.redone);if(u&&null!==u.right)return null}else u=p._map.get(t.parentSub)||null;null!==u&&u.parent._item!==h&&(u=p._map.get(t.parentSub)||null)}const m=ws(a,Rs(l,a)),f=new Oo(m,u,u&&u.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,To(f,!0),f.integrate(e,0),f},Oo=class e extends oo{constructor(e,t,n,r,s,i,o,l){super(e,l.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=s,this.parent=i,this.parentSub=o,this.redone=null,this.content=l,this.info=this.content.isCountable()?2:0}set marker(e){(8&this.info)>0!==e&&(this.info^=8)}get marker(){return(8&this.info)>0}get keep(){return(1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(2&this.info)>0}get deleted(){return(4&this.info)>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>=Rs(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Rs(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===bs&&this.id.client!==this.parent.client&&this.parent.clock>=Rs(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Fs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=Bs(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===lo||this.right&&this.right.constructor===lo)this.parent=null;else if(this.parent){if(this.parent.constructor===bs){const e=Ls(n,this.parent);e.constructor===lo?this.parent=null:this.parent=e.content.type}}else 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);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=Fs(e,e.doc.store,ws(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||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,n=this.left;if(null!==n)t=n.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const r=new Set,s=new Set;for(;null!==t&&t!==this.right;){if(s.add(t),r.add(t),ys(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,r.clear();else if(ys(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!s.has(Ls(e.doc.store,t.origin)))break;r.has(Ls(e.doc.store,t.origin))||(n=t,r.clear())}t=t.right}this.left=n}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Is(e.doc.store,this),this.content.integrate(e,this),Hs(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e)}else new lo(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:ws(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&ys(e.origin,this.lastId)&&this.right===e&&ys(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),Zr(e.deleteSet,this.id.client,this.id.clock,this.length),Hs(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw At();this.content.gc(e),t?((e,t,n)=>{const r=e.clients.get(t.id.client);r[Ps(r,t.id.clock)]=n})(e,this,new lo(this.id,this.length)):this.content=new co(this.length)}write(e,t){const n=t>0?ws(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,s=this.parentSub,i=31&this.content.getRef()|(null===n?0:128)|(null===r?0:64)|(null===s?0:32);if(e.writeInfo(i),null!==n&&e.writeLeftID(n),null!==r&&e.writeRightID(r),null===n&&null===r){const t=this.parent;if(void 0!==t._item){const n=t._item;if(null===n){const n=vs(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===bs?(e.writeParentInfo(!1),e.writeLeftID(t)):At();null!==s&&e.writeString(s)}this.content.write(e,t)}},$o=(e,t)=>Ro[31&t](e),Ro=[()=>{At()},e=>new co(e.readLen()),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++){const t=e.readString();"undefined"===t?n.push(void 0):n.push(JSON.parse(t))}return new fo(n)},e=>new ao(e.readBuf()),e=>new bo(e.readString()),e=>new po(e.readJSON()),e=>new mo(e.readKey(),e.readJSON()),e=>new Eo(yo[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new xo(n)},e=>new uo(ho(e.readString(),e.readAny())),()=>{At()}],Io=class extends oo{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){At()}write(e,t){e.writeInfo(10),dt(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Po="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Lo="__ $YJS$ __";function zo(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let s=e.child(r),i=t.child(r);if(s!=i){if(!s.sameMarkup(i))return n;if(s.isText&&s.text!=i.text){let e=s.text,t=i.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Vo(e.charCodeAt(r-1))&&Fo(e.charCodeAt(r))&&n--,n}if(s.content.size||i.content.size){let e=zo(s.content,i.content,n+1);if(null!=e)return e}n+=s.nodeSize}else n+=s.nodeSize}}function Bo(e,t,n,r){for(let s=e.childCount,i=t.childCount;;){if(0==s||0==i)return s==i?null:{a:n,b:r};let o=e.child(--s),l=t.child(--i),a=o.nodeSize;if(o!=l){if(!o.sameMarkup(l))return{a:n,b:r};if(o.isText&&o.text!=l.text){let e=o.text,t=l.text,s=e.length,i=t.length;for(;s>0&&i>0&&e[s-1]==t[i-1];)s--,i--,n--,r--;return s&&i&&s<e.length&&Vo(e.charCodeAt(s-1))&&Fo(e.charCodeAt(s))&&(n++,r++),{a:n,b:r}}if(o.content.size||l.content.size){let e=Bo(o.content,l.content,n-1,r-1);if(e)return e}n-=a,r-=a}else n-=a,r-=a}}function Fo(e){return e>=56320&&e<57344}function Vo(e){return e>=55296&&e<56320}Po[Lo],Po[Lo]=!0;var Wo=class e{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let n=0;n<e.length;n++)this.size+=e[n].nodeSize}nodesBetween(e,t,n,r=0,s){for(let i=0,o=0;o<t;i++){let l=this.content[i],a=o+l.nodeSize;if(a>e&&!1!==n(l,r+o,s||null,i)&&l.content.size){let s=o+1;l.nodesBetween(Math.max(0,e-s),Math.min(l.content.size,t-s),n,r+s)}o=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let s="",i=!0;return this.nodesBetween(e,t,(o,l)=>{let a=o.isText?o.text.slice(Math.max(e,l)-l,t-l):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&a||o.isTextblock)&&n&&(i?i=!1:s+=n),s+=a},0),s}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,s=this.content.slice(),i=0;for(n.isText&&n.sameMarkup(r)&&(s[s.length-1]=n.withText(n.text+r.text),i=1);i<t.content.length;i++)s.push(t.content[i]);return new e(s,this.size+t.size)}cut(t,n=this.size){if(0==t&&n==this.size)return this;let r=[],s=0;if(n>t)for(let e=0,i=0;i<n;e++){let o=this.content[e],l=i+o.nodeSize;l>t&&((i<t||l>n)&&(o=o.isText?o.cut(Math.max(0,t-i),Math.min(o.text.length,n-i)):o.cut(Math.max(0,t-i-1),Math.min(o.content.size,n-i-1))),r.push(o),s+=o.nodeSize),i=l}return new e(r,s)}cutByIndex(t,n){return t==n?e.empty:0==t&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let s=this.content.slice(),i=this.size+n.nodeSize-r.nodeSize;return s[t]=n,new e(s,i)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return zo(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return Bo(this,e,t,n)}findIndex(e){if(0==e)return Ho(0,e);if(e==this.size)return Ho(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e)return r==e?Ho(t+1,r):Ho(t,n);n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let s=t[e];r+=s.nodeSize,e&&s.isText&&t[e-1].sameMarkup(s)?(n||(n=t.slice(0,e)),n[n.length-1]=s.withText(n[n.length-1].text+s.text)):n&&n.push(s)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};Wo.empty=new Wo([],0);var qo={index:0,offset:0};function Ho(e,t){return qo.index=e,qo.offset=t,qo}function Uo(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!Uo(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Uo(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Jo=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!n&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(s)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Uo(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};Jo.none=[];var Ko=class extends Error{},Go=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=Yo(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(Xo(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,s=n.openEnd||0;if("number"!=typeof r||"number"!=typeof s)throw new RangeError("Invalid input for Slice.fromJSON");return new e(Wo.fromJSON(t,n.content),r,s)}static maxOpen(t,n=!0){let r=0,s=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)s++;return new e(t,r,s)}};function Xo(e,t,n){let{index:r,offset:s}=e.findIndex(t),i=e.maybeChild(r),{index:o,offset:l}=e.findIndex(n);if(s==t||i.isText){if(l!=n&&!e.child(o).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(r!=o)throw new RangeError("Removing non-flat range");return e.replaceChild(r,i.copy(Xo(i.content,t-s-1,n-s-1)))}function Yo(e,t,n,r,s,i){let{index:o,offset:l}=e.findIndex(t),a=e.maybeChild(o);if(l==t||a.isText)return i&&r<=0&&s<=0&&!i.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let c=Yo(a.content,t-l-1,n,0==o?r-1:0,o==e.childCount-1?s-1:0,a);return c&&e.replaceChild(o,a.copy(c))}Go.empty=new Go(Wo.empty,0,0);var Zo=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Qo(t,n);if(null==r.next)return e.empty;let s=el(r);r.next&&r.err("Unexpected trailing text");let i=function(e){let t=Object.create(null);return function n(r){let s=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<s.length;e++)s[e][0]==t&&(r=s[e][1]);ol(e,n).forEach(e=>{r||s.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)})})});let i=t[r.join(",")]=new Zo(r.indexOf(e.length-1)>-1);for(let e=0;e<s.length;e++){let r=s[e][1].sort(il);i.next.push({type:s[e][0],next:t[r.join(",")]||n(r)})}return i}(ol(e,0))}(function(e){let t=[[]];return s(function e(t,i){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,i)),[]);if("seq"!=t.type){if("star"==t.type){let o=n();return r(i,o),s(e(t.expr,o),o),[r(o)]}if("plus"==t.type){let o=n();return s(e(t.expr,i),o),s(e(t.expr,o),o),[r(o)]}if("opt"==t.type)return[r(i)].concat(e(t.expr,i));if("range"==t.type){let o=i;for(let r=0;r<t.min;r++){let r=n();s(e(t.expr,o),r),o=r}if(-1==t.max)s(e(t.expr,o),o);else for(let i=t.min;i<t.max;i++){let i=n();r(o,i),s(e(t.expr,o),i),o=i}return[r(o)]}if("name"==t.type)return[r(i,void 0,t.value)];throw new Error("Unknown expr type")}for(let r=0;;r++){let o=e(t.exprs[r],i);if(r==t.exprs.length-1)return o;s(o,i=n())}}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let s={term:r,to:n};return t[e].push(s),s}function s(e,t){e.forEach(e=>e.to=t)}}(s));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],s=!e.validEnd,i=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];i.push(n.name),!s||n.isText||n.hasRequiredAttrs()||(s=!1),-1==r.indexOf(o)&&r.push(o)}s&&t.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(i,r),i}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let s=t;r&&s<n;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!t.isText&&!t.hasRequiredAttrs())return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function s(i,o){let l=i.matchFragment(e,n);if(l&&(!t||l.validEnd))return Wo.from(o.map(e=>e.createAndFill()));for(let e=0;e<i.next.length;e++){let{type:t,next:n}=i.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==r.indexOf(n)){r.push(n);let e=s(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let n=0;n<this.wrapCache.length;n+=2)if(this.wrapCache[n]==e)return this.wrapCache[n+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),s=r.match;if(s.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<s.next.length;e++){let{type:i,next:o}=s.next[e];i.isLeaf||i.hasRequiredAttrs()||i.name in t||r.type&&!o.validEnd||(n.push({match:i.contentMatch,type:i,via:r}),t[i.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map((t,n)=>{let r=n+(t.validEnd?"*":" ")+" ";for(let s=0;s<t.next.length;s++)r+=(s?", ":"")+t.next[s].type.name+"->"+e.indexOf(t.next[s].next);return r}).join("\n")}};Zo.empty=new Zo(!0);var Qo=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function el(e){let t=[];do{t.push(tl(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function tl(e){let t=[];do{t.push(nl(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function nl(e){let t=function(e){if(e.eat("(")){let t=el(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let s=[];for(let i in n){let e=n[i];e.isInGroup(t)&&s.push(e)}return 0==s.length&&e.err("No node type or group '"+t+"' found"),s}(e,e.next).map(t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t}));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(e);for(;;)if(e.eat("+"))t={type:"plus",expr:t};else if(e.eat("*"))t={type:"star",expr:t};else if(e.eat("?"))t={type:"opt",expr:t};else{if(!e.eat("{"))break;t=sl(e,t)}return t}function rl(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function sl(e,t){let n=rl(e),r=n;return e.eat(",")&&(r="}"!=e.next?rl(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function il(e,t){return t-e}function ol(e,t){let n=[];return function t(r){let s=e[r];if(1==s.length&&!s[0].term)return t(s[0].to);n.push(r);for(let e=0;e<s.length;e++){let{term:r,to:i}=s[e];r||-1!=n.indexOf(i)||t(i)}}(t),n.sort(il)}var ll=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new pl(this,t,!1);return n.addAll(e,Jo.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new pl(this,t,!0);return n.addAll(e,Jo.none,t.from,t.to),Go.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(ml(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let r=this.styles[s],i=r.style;if(!(0!=i.indexOf(e)||r.context&&!n.matchesContext(r.context)||i.length>e.length&&(61!=i.charCodeAt(e.length)||i.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let r in e.marks){let t=e.marks[r].spec.parseDOM;t&&t.forEach(e=>{n(e=fl(e)),e.mark||e.ignore||e.clearMark||(e.mark=r)})}for(let r in e.nodes){let t=e.nodes[r].spec.parseDOM;t&&t.forEach(e=>{n(e=fl(e)),e.node||e.ignore||e.mark||(e.node=r)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},al={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},cl={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},dl={ol:!0,ul:!0};function hl(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}var ul=class{constructor(e,t,n,r,s,i){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=i,this.content=[],this.activeMarks=Jo.none,this.match=s||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Wo.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=Wo.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Wo.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!al.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},pl=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r,s=t.topNode,i=hl(null,t.preserveWhitespace,0)|(n?4:0);r=s?new ul(s.type,s.attrs,Jo.none,!0,t.topMatch||s.type.contentMatch,i):new ul(n?null:e.schema.topNodeType,null,Jo.none,!0,null,i),this.nodes=[r],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,s=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:i}=this.parser;if("full"===s||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(s)if("full"===s)n=n.replace(/\r\n?/g,"\n");else if(i.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(i.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(i.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(i.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],s=e.previousSibling;(!t||s&&"BR"==s.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(i.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,s=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i,o=e.nodeName.toLowerCase();dl.hasOwnProperty(o)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&dl.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let l=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(i=this.parser.matchTag(e,this,n));e:if(l?l.ignore:cl.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!l||l.skip||l.closeParent){l&&l.closeParent?this.open=Math.max(0,this.open-1):l&&l.skip.nodeType&&(e=l.skip);let n,r=this.needsBlock;if(al.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),n=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let i=l&&l.skip?t:this.readStyles(e,t);i&&this.addAll(e,i),n&&this.sync(s),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,l,n,!1===l.consuming?i:void 0)}this.localPreserveWS=r}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let e=this.parser.matchedStyles[r],s=n.getPropertyValue(e);if(s)for(let n;;){let r=this.parser.matchStyle(e,s,this,n);if(!r)break;if(r.ignore)return null;if(t=r.clearMark?t.filter(e=>!r.clearMark(e)):t.concat(this.parser.schema.marks[r.mark].create(r.attrs)),!1!==r.consuming)break;n=r}}return t}addElementByRule(e,t,n,r){let s,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(i,t.attrs||null,n,t.preserveWhitespace);e&&(s=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;"string"==typeof t.contentElement?r=e.querySelector(t.contentElement):"function"==typeof t.contentElement?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}s&&this.sync(o)&&this.open--}addAll(e,t,n,r){let s=n||0;for(let i=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];i!=o;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,t);this.findAtPoint(e,s)}findPlace(e,t,n){let r,s;for(let i=this.open,o=0;i>=0;i--){let t=this.nodes[i],l=t.findWrapping(e);if(l&&(!r||r.length>l.length+o)&&(r=l,s=t,!l.length))break;if(t.solid){if(n)break;o+=2}}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=Jo.none;for(let s of r.concat(e.marks))(t.type?t.type.allowsMarkType(s.type):gl(s.type,e.type))&&(n=s.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let s=this.findPlace(e.create(t),n,!1);return s&&(s=this.enterInner(e,t,n,!0,r)),s}enterInner(e,t,n,r=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let o=hl(e,s,i.options);4&i.options&&0==i.content.length&&(o|=4);let l=Jo.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):gl(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new ul(e,t,l,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=1)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),s=-(n?n.depth+1:0)+(r?0:1),i=(e,o)=>{for(;e>=0;e--){let l=t[e];if(""==l){if(e==t.length-1||0==e)continue;for(;o>=s;o--)if(i(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=s?n.node(o-s).type:null;if(!e||e.name!=l&&!e.isInGroup(l))return!1;o--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}};function ml(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function fl(e){let t={};for(let n in e)t[n]=e[n];return t}function gl(e,t){let n=t.schema.nodes;for(let r in n){let s=n[r];if(!s.allowsMarkType(e))continue;let i=[],o=e=>{i.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:s}=e.edge(n);if(r==t)return!0;if(i.indexOf(s)<0&&o(s))return!0}};if(o(s.contentMatch))return!0}}var xl=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=yl(t).createDocumentFragment());let r=n,s=[];return e.forEach(e=>{if(s.length||e.marks.length){let n=0,i=0;for(;n<s.length&&i<e.marks.length;){let t=e.marks[i];if(this.marks[t.type.name]){if(!t.eq(s[n][0])||!1===t.type.spec.spanning)break;n++,i++}else i++}for(;n<s.length;)r=s.pop()[1];for(;i<e.marks.length;){let n=e.marks[i++],o=this.serializeMark(n,e.isInline,t);o&&(s.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return yl(t).createTextNode(e.text);let{dom:n,contentDOM:r}=vl(yl(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(n),n=s.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&vl(yl(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:vl(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=bl(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return bl(e.marks)}};function bl(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function yl(e){return e.document||window.document}var wl=new WeakMap;function vl(e,t,n,r){if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let s,i=t[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(r&&(s=function(e){let t=wl.get(e);return void 0===t&&wl.set(e,t=function(e){let t=null;return function e(n){if(n&&"object"==typeof n)if(Array.isArray(n))if("string"==typeof n[0])t||(t=[]),t.push(n);else for(let t=0;t<n.length;t++)e(n[t]);else for(let t in n)e(n[t])}(e),t}(e)),t}(r))&&s.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?e.createElementNS(n,i):e.createElement(i),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?a.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):"style"==e&&a.style?a.style.cssText=c[e]:a.setAttribute(e,c[e])}}for(let h=d;h<t.length;h++){let s=t[h];if(0===s){if(h<t.length-1||h>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}if("string"==typeof s)a.appendChild(e.createTextNode(s));else{let{dom:t,contentDOM:i}=vl(e,s,n,r);if(a.appendChild(t),i){if(o)throw new RangeError("Multiple content holes");o=i}}}return{dom:a,contentDOM:o}}var kl=Math.pow(2,16);function jl(e,t){return e+t*kl}function Sl(e){return 65535&e}var Cl=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}},Nl=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=Sl(e);if(!this.inverted)for(let r=0;r<n;r++)t+=this.ranges[3*r+2]-this.ranges[3*r+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/kl}(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let l=this.ranges[o]-(this.inverted?r:0);if(l>e)break;let a=this.ranges[o+s],c=this.ranges[o+i],d=l+a;if(e<=d){let s=l+r+((a?e==l?-1:e==d?1:t:t)<0?0:c);if(n)return s;let i=e==(t<0?l:d)?null:jl(o/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new Cl(s,h,i)}r+=c-a}return n?e+r:new Cl(e+r,0,null)}touches(e,t){let n=0,r=Sl(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let t=this.ranges[o]-(this.inverted?n:0);if(t>e)break;let l=this.ranges[o+s];if(e<=t+l&&o==3*r)return!0;n+=this.ranges[o+i]-l}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let i=this.ranges[r],o=i-(this.inverted?s:0),l=i+(this.inverted?0:s),a=this.ranges[r+t],c=this.ranges[r+n];e(o,o+a,l,l+c),s+=c-a}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};Nl.empty=new Nl([]);var El=Object.create(null),Al=class{getMap(){return Nl.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=El[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in El)throw new RangeError("Duplicate use of step JSON ID "+e);return El[e]=t,t.prototype.jsonID=e,t}},Tl=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,s){try{return e.ok(t.replace(n,r,s))}catch(au){if(au instanceof Ko)return e.fail(au.message);throw au}}};function Ml(e,t,n){let r=[];for(let s=0;s<e.childCount;s++){let i=e.child(s);i.content.size&&(i=i.copy(Ml(i.content,t,i))),i.isInline&&(i=t(i,n,s)),r.push(i)}return Wo.fromArray(r)}var _l=class e extends Al{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),s=new Go(Ml(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,r),t.openStart,t.openEnd);return Tl.fromReplace(e,this.from,this.to,s)}invert(){return new Dl(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new e(n.from,n.to,t.markFromJSON(n.mark))}};Al.jsonID("addMark",_l);var Dl=class e extends Al{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Go(Ml(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Tl.fromReplace(e,this.from,this.to,n)}invert(){return new _l(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new e(n.from,n.to,t.markFromJSON(n.mark))}};Al.jsonID("removeMark",Dl);var Ol=class e extends Al{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(n),0,t.isLeaf?0:1))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new $l(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if("number"!=typeof n.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new e(n.pos,t.markFromJSON(n.mark))}};Al.jsonID("addNodeMark",Ol);var $l=class e extends Al{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Ol(this.pos,this.mark):this}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if("number"!=typeof n.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new e(n.pos,t.markFromJSON(n.mark))}};Al.jsonID("removeNodeMark",$l);var Rl=class e extends Al{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Pl(e,this.from,this.to)?Tl.fail("Structure replace would overwrite content"):Tl.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Nl([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.to,-1),r=this.from==this.to&&e.MAP_BIAS<0?n:t.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new e(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let n=this.slice.size+t.slice.size==0?Go.empty:new Go(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}}{let n=this.slice.size+t.slice.size==0?Go.empty:new Go(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new e(n.from,n.to,Go.fromJSON(t,n.slice),!!n.structure)}};Rl.MAP_BIAS=1,Al.jsonID("replace",Rl);var Il=class e extends Al{constructor(e,t,n,r,s,i,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=s,this.insert=i,this.structure=o}apply(e){if(this.structure&&(Pl(e,this.from,this.gapFrom)||Pl(e,this.gapTo,this.to)))return Tl.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Tl.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Tl.fromReplace(e,this.from,this.to,n):Tl.fail("Content does not fit in gap")}getMap(){return new Nl([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),s=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),i=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||s<n.pos||i>r.pos?null:new e(n.pos,r.pos,s,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if("number"!=typeof n.from||"number"!=typeof n.to||"number"!=typeof n.gapFrom||"number"!=typeof n.gapTo||"number"!=typeof n.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new e(n.from,n.to,n.gapFrom,n.gapTo,Go.fromJSON(t,n.slice),n.insert,!!n.structure)}};function Pl(e,t,n){let r=e.resolve(t),s=n-t,i=r.depth;for(;s>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,s--;if(s>0){let e=r.node(i).maybeChild(r.indexAfter(i));for(;s>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,s--}}return!1}Al.jsonID("replaceAround",Il),Al.jsonID("attr",class e extends Al{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return Tl.fail("No node at attribute step's position");let n=Object.create(null);for(let s in t.attrs)n[s]=t.attrs[s];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return Tl.fromReplace(e,this.pos,this.pos+1,new Go(Wo.from(r),0,t.isLeaf?0:1))}getMap(){return Nl.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if("number"!=typeof n.pos||"string"!=typeof n.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new e(n.pos,n.attr,n.value)}}),Al.jsonID("docAttr",class e extends Al{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return Tl.ok(n)}getMap(){return Nl.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,n){if("string"!=typeof n.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new e(n.attr,n.value)}});var Ll=Error;((Ll=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype)).constructor=Ll,Ll.prototype.name="TransformError";var zl=Object.create(null),Bl=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Fl(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=Go.empty){let n=t.content.lastChild,r=null;for(let o=0;o<t.openEnd;o++)r=n,n=n.lastChild;let s=e.steps.length,i=this.ranges;for(let o=0;o<i.length;o++){let{$from:l,$to:a}=i[o],c=e.mapping.slice(s);e.replaceRange(c.map(l.pos),c.map(a.pos),o?Go.empty:t),0==o&&Yl(e,s,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:i,$to:o}=r[s],l=e.mapping.slice(n),a=l.map(i.pos),c=l.map(o.pos);s?e.deleteRange(a,c):(e.replaceRangeWith(a,c,t),Yl(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new ql(e):Xl(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let s=e.depth-1;s>=0;s--){let r=t<0?Xl(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Xl(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Kl(e.node(0))}static atStart(e){return Xl(e,e,0,0,1)||new Kl(e)}static atEnd(e){return Xl(e,e,e.content.size,e.childCount,-1)||new Kl(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=zl[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in zl)throw new RangeError("Duplicate use of selection JSON ID "+e);return zl[e]=t,t.prototype.jsonID=e,t}getBookmark(){return ql.between(this.$anchor,this.$head).getBookmark()}};Bl.prototype.visible=!0;var Fl=class{constructor(e,t){this.$from=e,this.$to=t}},Vl=!1;function Wl(e){Vl||e.parent.inlineContent||(Vl=!0)}var ql=class e extends Bl{constructor(e,t=e){Wl(e),Wl(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return Bl.near(r);let s=t.resolve(n.map(this.anchor));return new e(s.parent.inlineContent?s:r,r)}replace(e,t=Go.empty){if(super.replace(e,t),t==Go.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new Hl(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,n){if("number"!=typeof n.anchor||"number"!=typeof n.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let s=t.pos-n.pos;if(r&&!s||(r=s>=0?1:-1),!n.parent.inlineContent){let e=Bl.findFrom(n,r,!0)||Bl.findFrom(n,-r,!0);if(!e)return Bl.near(n,r);n=e.$head}return t.parent.inlineContent||(0==s||(t=(Bl.findFrom(t,-r,!0)||Bl.findFrom(t,r,!0)).$anchor).pos<n.pos!=s<0)&&(t=n),new e(t,n)}};Bl.jsonID("text",ql);var Hl=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return ql.between(e.resolve(this.anchor),e.resolve(this.head))}},Ul=class e extends Bl{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:s}=n.mapResult(this.anchor),i=t.resolve(s);return r?Bl.near(i):new e(i)}content(){return new Go(Wo.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Jl(this.anchor)}static fromJSON(t,n){if("number"!=typeof n.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}};Ul.prototype.visible=!1,Bl.jsonID("node",Ul);var Jl=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new Hl(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&Ul.isSelectable(n)?new Ul(t):Bl.near(t)}},Kl=class e extends Bl{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Go.empty){if(t==Go.empty){e.delete(0,e.doc.content.size);let t=Bl.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return Gl}};Bl.jsonID("all",Kl);var Gl={map(){return this},resolve:e=>new Kl(e)};function Xl(e,t,n,r,s,i=!1){if(t.inlineContent)return ql.create(e,n);for(let o=r-(s>0?0:1);s>0?o<t.childCount:o>=0;o+=s){let r=t.child(o);if(r.isAtom){if(!i&&Ul.isSelectable(r))return Ul.create(e,n-(s<0?r.nodeSize:0))}else{let t=Xl(e,r,n+s,s<0?r.childCount:0,s,i);if(t)return t}n+=r.nodeSize*s}return null}function Yl(e,t,n){let r=e.steps.length-1;if(r<t)return;let s,i=e.steps[r];(i instanceof Rl||i instanceof Il)&&(e.mapping.maps[r].forEach((e,t,n,r)=>{s??=r}),e.setSelection(Bl.near(e.doc.resolve(s),n)))}function Zl(e,t){return t&&e?e.bind(t):e}var Ql=class{constructor(e,t,n){this.name=e,this.init=Zl(t.init,n),this.apply=Zl(t.apply,n)}};function ea(e,t,n){for(let r in e){let s=e[r];s instanceof Function?s=s.bind(t):"handleDOMEvents"==r&&(s=ea(s,t,{})),n[r]=s}return n}new Ql("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Ql("selection",{init:(e,t)=>e.selection||Bl.atStart(t.doc),apply:e=>e.selection}),new Ql("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new Ql("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});var ta=class{constructor(e){this.spec=e,this.props={},e.props&&ea(e.props,this,this.props),this.key=e.key?e.key.key:ra("plugin")}getState(e){return e[this.key]}},na=Object.create(null);function ra(e){return e in na?e+"$"+ ++na[e]:(na[e]=0,e+"$")}var sa=class{constructor(e="key"){this.key=ra(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},ia=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},oa=function(e,t,n,r){return n&&(aa(e,t,n,r,-1)||aa(e,t,n,r,1))},la=/^(img|br|input|textarea|hr)$/i;function aa(e,t,n,r,s){for(var i;;){if(e==n&&t==r)return!0;if(t==(s<0?0:ca(e))){let n=e.parentNode;if(!n||1!=n.nodeType||da(e)||la.test(e.nodeName)||"false"==e.contentEditable)return!1;t=ia(e)+(s<0?0:1),e=n}else{if(1!=e.nodeType)return!1;{let n=e.childNodes[t+(s<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable){if(!(null===(i=n.pmViewDesc)||void 0===i?void 0:i.ignoreForSelection))return!1;t+=s}else e=n,t=s<0?ca(e):0}}}}function ca(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function da(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var ha=function(e){return e.focusNode&&oa(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ua(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}var pa="undefined"!=typeof navigator?navigator:null,ma="undefined"!=typeof document?document:null,fa=pa&&pa.userAgent||"",ga=/Edge\/(\d+)/.exec(fa),xa=/MSIE \d/.exec(fa),ba=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(fa),ya=!!(xa||ba||ga),wa=xa?document.documentMode:ba?+ba[1]:ga?+ga[1]:0,va=!ya&&/gecko\/(\d+)/i.test(fa);va&&(/Firefox\/(\d+)/.exec(fa)||[0,0])[1];var ka=!ya&&/Chrome\/(\d+)/.exec(fa),ja=!!ka,Sa=ka?+ka[1]:0,Ca=!ya&&!!pa&&/Apple Computer/.test(pa.vendor),Na=Ca&&(/Mobile\/\w+/.test(fa)||!!pa&&pa.maxTouchPoints>2),Ea=Na||!!pa&&/Mac/.test(pa.platform),Aa=!!pa&&/Win/.test(pa.platform),Ta=/Android \d/.test(fa),Ma=!!ma&&"webkitFontSmoothing"in ma.documentElement.style,_a=Ma?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,Da=function(e){e&&(this.nodeName=e)};function Oa(e){return e.editable?e.hasFocus():function(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(n){return!1}}(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function $a(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof Ul){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(za(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else za(e)}(e,n),!Oa(e))return;let r=e.input.mouseDown;if(!t&&ja&&r){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&oa(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)&&r.delaySelUpdate())return void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r="IMG"==n.nodeName;r?t.collapse(n.parentNode,ia(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&ya&&wa<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let r,s,{anchor:i,head:o}=n;!Ra||n instanceof ql||(n.$from.parent.inlineContent||(r=Ia(e,n.from)),n.empty||n.$from.parent.inlineContent||(s=Ia(e,n.to))),e.docView.setSelection(i,o,e,t),Ra&&(r&&La(r),s&&La(s)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,s=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==r&&n.anchorOffset==s||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout(()=>{Oa(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}Da.prototype=Object.create(null),new Da;var Ra=Ca||ja&&Sa<63;function Ia(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),s=r<n.childNodes.length?n.childNodes[r]:null,i=r?n.childNodes[r-1]:null;if(Ca&&s&&"false"==s.contentEditable)return Pa(s);if(!(s&&"false"!=s.contentEditable||i&&"false"!=i.contentEditable)){if(s)return Pa(s);if(i)return Pa(i)}}function Pa(e){return e.contentEditable="true",Ca&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function La(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function za(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Ba(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||ql.between(t,n,r)}function Fa(e,t){let{$anchor:n,$head:r}=e.selection,s=t>0?n.max(r):n.min(r),i=s.parent.inlineContent?s.depth?e.doc.resolve(t>0?s.after():s.before()):null:s;return i&&Bl.findFrom(i,t)}function Va(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Wa(e,t,n){let r=e.state.selection;if(!(r instanceof ql)){if(r instanceof Ul&&r.node.isInline)return Va(e,new ql(t>0?r.$to:r.$from));{let n=Fa(e.state,t);return!!n&&Va(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=r,s=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=e.state.doc.resolve(n.pos+s.nodeSize*(t<0?-1:1));return Va(e,new ql(r.$anchor,i))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Fa(e.state,t);return!!(n&&n instanceof Ul)&&Va(e,n)}if(!(Ea&&n.indexOf("m")>-1)){let n,s=r.$head,i=s.textOffset?null:t<0?s.nodeBefore:s.nodeAfter;if(!i||i.isText)return!1;let o=t<0?s.pos-i.nodeSize:s.pos;return!!(i.isAtom||(n=e.docView.descAt(o))&&!n.contentDOM)&&(Ul.isSelectable(i)?Va(e,new Ul(t<0?e.state.doc.resolve(s.pos-i.nodeSize):s)):!!Ma&&Va(e,new ql(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}function qa(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Ha(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function Ua(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=!1;for(va&&1==n.nodeType&&r<qa(n)&&Ha(n.childNodes[r],-1)&&(o=!0);;)if(r>0){if(1!=n.nodeType)break;{let e=n.childNodes[r-1];if(Ha(e,-1))s=n,i=--r;else{if(3!=e.nodeType)break;n=e,r=n.nodeValue.length}}}else{if(Ja(n))break;{let t=n.previousSibling;for(;t&&Ha(t,-1);)s=n.parentNode,i=ia(t),t=t.previousSibling;if(t)n=t,r=qa(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}o?Ka(e,n,r):s&&Ka(e,s,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=qa(n);for(;;)if(r<o){if(1!=n.nodeType)break;if(!Ha(n.childNodes[r],1))break;s=n,i=++r}else{if(Ja(n))break;{let t=n.nextSibling;for(;t&&Ha(t,1);)s=t.parentNode,i=ia(t)+1,t=t.nextSibling;if(t)n=t,r=0,o=qa(n);else{if(n=n.parentNode,n==e.dom)break;r=o=0}}}s&&Ka(e,s,i)}(e)}function Ja(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Ka(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!da(e);)t=ia(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=r,n=0):(e=function(e,t){for(;e&&!t&&!da(e);)t=ia(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(ha(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:s}=e;setTimeout(()=>{e.state==s&&$a(e)},50)}function Ga(e,t){let n=e.state.doc.resolve(t);if(!ja&&!Aa&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),s=(n.top+n.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),s=(n.top+n.bottom)/2;if(s>r.top&&s<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function Xa(e,t,n){let r=e.state.selection;if(r instanceof ql&&!r.empty||n.indexOf("s")>-1)return!1;if(Ea&&n.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Fa(e.state,t);if(n&&n instanceof Ul)return Va(e,n)}if(!s.parent.inlineContent){let n=t<0?s:i,o=r instanceof Kl?Bl.near(n,t):Bl.findFrom(n,t);return!!o&&Va(e,o)}return!1}function Ya(e,t){if(!(e.state.selection instanceof ql))return!0;let{$head:n,$anchor:r,empty:s}=e.state.selection;if(!n.sameParent(r))return!0;if(!s)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let i=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(i&&!i.isText){let r=e.state.tr;return t<0?r.delete(n.pos-i.nodeSize,n.pos):r.delete(n.pos,n.pos+i.nodeSize),e.dispatch(r),!0}return!1}function Za(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Qa(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:s,openEnd:i}=t;for(;s>1&&i>1&&1==r.childCount&&1==r.firstChild.childCount;){s--,i--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let o=e.someProp("clipboardSerializer")||xl.fromSchema(e.state.schema),l=ac(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=lc[d.nodeName.toLowerCase()]);){for(let e=c.length-1;e>=0;e--){let t=l.createElement(c[e]);for(;a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t),h++}d=a.firstChild}return d&&1==d.nodeType&&d.setAttribute("data-pm-slice",`${s} ${i}${h?` -${h}`:""} ${JSON.stringify(n)}`),{dom:a,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function ec(e,t,n,r,s){let i,o,l=s.parent.type.spec.code;if(!n&&!t)return null;let a=!!t&&(r||l||!n);if(a){if(e.someProp("transformPastedText",n=>{t=n(t,l||r,e)}),l)return o=new Go(Wo.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{o=t(o,e,!0)}),o;let n=e.someProp("clipboardTextParser",n=>n(t,s,r,e));if(n)o=n;else{let n=s.marks(),{schema:r}=e.state,o=xl.fromSchema(r);i=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=i.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),i=function(e){let t=/^(\s*<meta [^>]*>)*/.exec(e);t&&(e=e.slice(t[0].length));let n,r=ac(),s=r.body,i=/<([a-z][^>\s]+)/i.exec(e);if((n=i&&lc[i[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),s.innerHTML=function(e){let t=window.trustedTypes;return t?(cc||(cc=t.defaultPolicy||t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),cc.createHTML(e)):e}(e),n)for(let o=0;o<n.length;o++)s=s.querySelector(n[o])||s;for(let o=0;o<r.styleSheets.length;o++){let e=r.styleSheets[o];for(let t=0;t<e.rules.length;t++){let n=e.rules[t];if(n instanceof CSSStyleRule){let e=s.querySelectorAll(n.selectorText);for(let t=0;t<e.length;t++)e[t].style.cssText+=n.style.cssText}}}return s}(n),Ma&&function(e){let t=e.querySelectorAll(ja?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let r=t[n];1==r.childNodes.length&&" "==r.textContent&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),r)}}(i);let c=i&&i.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let h=+d[3];h>0;h--){let e=i.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;i=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||ll.fromSchema(e.state.schema)).parseSlice(i,{preserveWhitespace:!(!a&&!d),context:s,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||tc.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n,r=e.content.firstChild.type.schema;try{n=JSON.parse(t)}catch(au){return e}let{content:s,openStart:i,openEnd:o}=e;for(let l=n.length-2;l>=0;l-=2){let e=r.nodes[n[l]];if(!e||e.hasRequiredAttrs())break;s=Wo.from(e.create(n[l+1],s)),i++,o++}return new Go(s,i,o)}(oc(o,+d[1],+d[2]),d[4]);else if(o=Go.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r,s=t.node(n).contentMatchAt(t.index(n)),i=[];if(e.forEach(e=>{if(!i)return;let t,n=s.findWrapping(e.type);if(!n)return i=null;if(t=i.length&&r.length&&rc(n,r,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=sc(i[i.length-1],r.length));let t=nc(e,n);i.push(t),s=s.matchType(t.type),r=n}}),i)return Wo.from(i)}return e}(o.content,s),!0),o.openStart||o.openEnd){let e=0,t=0;for(let n=o.content.firstChild;e<o.openStart&&!n.type.spec.isolating;e++,n=n.firstChild);for(let n=o.content.lastChild;t<o.openEnd&&!n.type.spec.isolating;t++,n=n.lastChild);o=oc(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,a)}),o}var tc=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function nc(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Wo.from(e));return e}function rc(e,t,n,r,s){if(s<e.length&&s<t.length&&e[s]==t[s]){let i=rc(e,t,n,r.lastChild,s+1);if(i)return r.copy(r.content.replaceChild(r.childCount-1,i));if(r.contentMatchAt(r.childCount).matchType(s==e.length-1?n.type:e[s+1]))return r.copy(r.content.append(Wo.from(nc(n,e,s+1))))}}function sc(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,sc(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Wo.empty,!0);return e.copy(n.append(r))}function ic(e,t,n,r,s,i){let o=t<0?e.firstChild:e.lastChild,l=o.content;return e.childCount>1&&(i=0),s<r-1&&(l=ic(l,t,n,r,s+1,i)),s>=n&&(l=t<0?o.contentMatchAt(0).fillBefore(l,i<=s).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(Wo.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(l))}function oc(e,t,n){return t<e.openStart&&(e=new Go(ic(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Go(ic(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var lc={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function ac(){return document.implementation.createHTMLDocument("title")}var cc=null,dc={},hc={};function uc(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function pc(e){return{left:e.clientX,top:e.clientY}}function mc(e,t,n,r,s){if(-1==r)return!1;let i=e.state.doc.resolve(r);for(let o=i.depth+1;o>0;o--)if(e.someProp(t,t=>o>i.depth?t(e,n,i.nodeAfter,i.before(o),s,!0):t(e,n,i.node(o),i.before(o),s,!1)))return!0;return!1}function fc(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}function gc(e,t,n,r){return mc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}function xc(e,t,n,r){return mc(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",n=>n(e,t,r))||function(e,t,n){if(0!=n.button)return!1;let r=bc(e,t,!0),s=e.state.doc;return!!r&&(fc(e,r,"pointer"),r instanceof ql&&s.eq(e.state.doc)&&(e.input.mouseDown=new jc(e,r)),!0)}(e,n,r)}function bc(e,t,n){let r=e.state.doc;if(-1==t)return r.inlineContent?ql.create(r,0,r.content.size):null;let s=r.resolve(t);for(let i=s.depth+1;i>0;i--){let e=i>s.depth?s.nodeAfter:s.node(i),t=s.before(i);if(e.inlineContent)return ql.create(r,t+1,t+1+e.content.size);if(n&&Ul.isSelectable(e))return Ul.create(r,t)}return null}function yc(e){return Ec(e)}hc.keydown=(e,t)=>{let n=t;if(e.input.shiftKey=16==n.keyCode||n.shiftKey,!Sc(e)&&(e.input.lastKeyCode=n.keyCode,e.input.lastKeyCodeTime=Date.now(),!Ta||!ja||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Na||13!=n.keyCode||n.ctrlKey||n.altKey||n.metaKey)e.someProp("handleKeyDown",t=>t(e,n))||function(e,t){let n=t.keyCode,r=function(e){let t="";return e.ctrlKey&&(t+="c"),e.metaKey&&(t+="m"),e.altKey&&(t+="a"),e.shiftKey&&(t+="s"),t}(t);if(8==n||Ea&&72==n&&"c"==r)return Ya(e,-1)||Ua(e,-1);if(46==n&&!t.shiftKey||Ea&&68==n&&"c"==r)return Ya(e,1)||Ua(e,1);if(13==n||27==n)return!0;if(37==n||Ea&&66==n&&"c"==r){let t=37==n?"ltr"==Ga(e,e.state.selection.from)?-1:1:-1;return Wa(e,t,r)||Ua(e,t)}if(39==n||Ea&&70==n&&"c"==r){let t=39==n?"ltr"==Ga(e,e.state.selection.from)?1:-1:1;return Wa(e,t,r)||Ua(e,t)}return 38==n||Ea&&80==n&&"c"==r?Xa(e,-1,r)||Ua(e,-1):40==n||Ea&&78==n&&"c"==r?function(e){if(!Ca||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;Za(e,n,"true"),setTimeout(()=>Za(e,n,"false"),20)}return!1}(e)||Xa(e,1,r)||Ua(e,1):r==(Ea?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():uc(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,ua(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},hc.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},hc.keypress=(e,t)=>{let n=t;if(Sc(e)||!n.charCode||n.ctrlKey&&!n.altKey||Ea&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof ql&&r.$from.sameParent(r.$to))){let t=String.fromCharCode(n.charCode),s=()=>e.state.tr.insertText(t).scrollIntoView();/[\r\n]/.test(t)||e.someProp("handleTextInput",n=>n(e,r.$from.pos,r.$to.pos,t,s))||e.dispatch(s()),n.preventDefault()}};var wc=Ea?"metaKey":"ctrlKey";dc.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=yc(e),s=Date.now(),i="singleClick";s-e.input.lastClick.time<500&&function(e,t){let n=t.x-e.clientX,r=t.y-e.clientY;return n*n+r*r<100}(n,e.input.lastClick)&&!n[wc]&&e.input.lastClick.button==n.button&&("singleClick"==e.input.lastClick.type?i="doubleClick":"doubleClick"==e.input.lastClick.type&&(i="tripleClick")),e.input.lastClick={time:s,x:n.clientX,y:n.clientY,type:i,button:n.button},e.input.mouseDown&&e.input.mouseDown.done();let o=e.posAtCoords(pc(n));o&&("singleClick"==i?e.input.mouseDown=new kc(e,o,n,!!r):("doubleClick"==i?gc:xc)(e,o.pos,o.inside,n)?n.preventDefault():uc(e,"pointer"))};var vc=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){0==e.buttons&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},kc=class extends vc{constructor(e,t,n,r){let s,i;if(super(e),this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!n[wc],this.allowDefault=n.shiftKey,t.inside>-1)s=e.state.doc.nodeAt(t.inside),i=t.inside;else{let n=e.state.doc.resolve(t.pos);s=n.parent,i=n.depth?n.before():0}const o=r?null:n.target,l=o?e.docView.nearestDesc(o,!0):null;this.target=l&&1==l.nodeDOM.nodeType?l.nodeDOM:null;let{selection:a}=e.state;0==n.button&&(s.type.spec.draggable&&!1!==s.type.spec.selectable||a instanceof Ul&&a.from<=i&&a.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!(!this.target||this.target.draggable),setUneditable:!(!this.target||!va||this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),uc(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||$a(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(pc(e))),this.updateAllowDefault(e),this.allowDefault||!t?uc(this.view,"pointer"):function(e,t,n,r,s){return mc(e,"handleClickOn",t,n,r)||e.someProp("handleClick",n=>n(e,t,r))||(s?function(e,t){if(-1==t)return!1;let n,r,s=e.state.selection;s instanceof Ul&&(n=s.node);let i=e.state.doc.resolve(t);for(let o=i.depth+1;o>0;o--){let e=o>i.depth?i.nodeAfter:i.node(o);if(Ul.isSelectable(e)){r=n&&s.$from.depth>0&&o>=s.$from.depth&&i.before(s.$from.depth+1)==s.$from.pos?i.before(s.$from.depth):i.before(o);break}}return null!=r&&(fc(e,Ul.create(e.state.doc,r),"pointer"),!0)}(e,n):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&Ul.isSelectable(r))&&(fc(e,new Ul(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||Ca&&this.mightDrag&&!this.mightDrag.node.isAtom||ja&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(fc(this.view,Bl.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):uc(this.view,"pointer")}move(e){this.updateAllowDefault(e),uc(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return!!this.allowDefault&&(this.delayedSelectionSync=!0,!0)}},jc=class extends vc{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(0==e.buttons||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc))return void this.done();e.preventDefault(),uc(this.view,"pointer");let t=this.view.posAtCoords(pc(e)),n=t&&bc(this.view,t.inside,!1);if(!n)return;let{doc:r}=this.view.state,s=this.startSelection,[i,o]=n.from<s.from?[s.to,n.from]:[s.from,n.to];fc(this.view,ql.create(r,i,o),"pointer")}};function Sc(e,t){return!!e.composing||!!(Ca&&Math.abs(Date.now()-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}dc.touchstart=e=>{e.input.lastTouch=Date.now(),yc(e),uc(e,"pointer")},dc.touchmove=e=>{e.input.lastTouch=Date.now(),uc(e,"pointer")},dc.contextmenu=e=>yc(e);var Cc=Ta?5e3:-1;function Nc(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Ec(e),t))}function Ec(e,t=!1){if(!(Ta&&e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),function(e){for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now());e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}(e),t||e.docView&&e.docView.dirty){let n=function(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let s=e.docView.nearestDesc(n.focusNode),i=s&&0==s.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let l,a,c=r.resolve(o);if(ha(n)){for(l=o;s&&!s.node;)s=s.parent;let e=s.node;if(s&&e.isAtom&&Ul.isSelectable(e)&&s.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,s=t==ca(e);r||s;){if(e==n)return!0;let t=ia(e);if(!(e=e.parentNode))return!1;r=r&&0==t,s=s&&t==ca(e)}}(n.focusNode,n.focusOffset,s.dom))){let e=s.posBefore;a=new Ul(o==e?c:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,s=o;for(let r=0;r<n.rangeCount;r++){let i=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(i.startContainer,i.startOffset,1)),s=Math.max(s,e.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(t<0)return null;[l,o]=s==e.state.selection.anchor?[s,t]:[t,s],c=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);return a||(a=Ba(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!i?1:-1)),a}(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):!e.markCursor&&!t||r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.updateState(e.state):e.dispatch(e.state.tr.deleteSelection()),!0}return!1}}hc.compositionstart=hc.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof ql&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ja&&Aa&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return 1==r.nodeType&&"false"==r.contentEditable}(e)))e.markCursor=e.state.storedMarks||n.marks(),Ec(e,!0),e.markCursor=null;else if(Ec(e,!t.selection.empty),va&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}Nc(e,Cc)},hc.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=Date.now(),e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,Nc(e,20))};var Ac=ya&&wa<15||Na&&_a<604;function Tc(e,t,n,r,s){let i=ec(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,s,i||Go.empty)))return!0;if(!i)return!1;let o=function(e){return 0==e.openStart&&0==e.openEnd&&1==e.content.childCount?e.content.firstChild:null}(i),l=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(i);return e.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Mc(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}dc.copy=hc.cut=(e,t)=>{let n=t,r=e.state.selection,s="cut"==n.type;if(r.empty)return;let i=Ac?null:n.clipboardData,{dom:o,text:l}=Qa(e,r.content());i?(n.preventDefault(),i.clearData(),i.setData("text/html",o.innerHTML),i.setData("text/plain",l)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),s=document.createRange();s.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(s),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,o),s&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},hc.paste=(e,t)=>{let n=t;if(e.composing&&!Ta)return;let r=Ac?null:n.clipboardData,s=e.input.shiftKey&&45!=e.input.lastKeyCode;r&&Tc(e,Mc(r),r.getData("text/html"),s,n)?n.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let s=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?Tc(e,r.value,null,s,t):Tc(e,r.textContent,r.innerHTML,s,t)},50)}(e,n)};var _c=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},Dc=Ea?"altKey":"ctrlKey";function Oc(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[Dc]}dc.dragstart=(e,t)=>{let n=t,r=e.input.mouseDown;if(r&&r.done(),!n.dataTransfer)return;let s,i=e.state.selection,o=i.empty?null:e.posAtCoords(pc(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof Ul?i.to-1:i.to));else if(r&&r.mightDrag)s=Ul.create(e.state.doc,r.mightDrag.pos);else if(n.target&&1==n.target.nodeType){let t=e.docView.nearestDesc(n.target,!0);t&&t.node.type.spec.draggable&&t!=e.docView&&(s=Ul.create(e.state.doc,t.posBefore))}let{dom:l,text:a,slice:c}=Qa(e,(s||e.state.selection).content());(!n.dataTransfer.files.length||!ja||Sa>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Ac?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Ac||n.dataTransfer.setData("text/plain",a),e.dragging=new _c(c,Oc(e,n),s)},dc.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},hc.dragover=hc.dragenter=(e,t)=>t.preventDefault(),hc.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(pc(t));if(!r)return;let s=e.state.doc.resolve(r.pos),i=n&&n.slice;i?e.someProp("transformPasted",t=>{i=t(i,e,!1)}):i=ec(e,Mc(t.dataTransfer),Ac?null:t.dataTransfer.getData("text/html"),!1,s);let o=!(!n||!Oc(e,t));if(e.someProp("handleDrop",n=>n(e,t,i||Go.empty,o)))return void t.preventDefault();if(!i)return;t.preventDefault();let l=i?function(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let s=n.content;for(let i=0;i<n.openStart;i++)s=s.firstChild.content;for(let i=1;i<=(0==n.openStart&&n.size?2:1);i++)for(let e=r.depth;e>=0;e--){let t=e==r.depth?0:r.pos<=(r.start(e+1)+r.end(e+1))/2?-1:1,n=r.index(e)+(t>0?1:0),o=r.node(e),l=!1;if(1==i)l=o.canReplace(n,n,s);else{let e=o.contentMatchAt(n).findWrapping(s.firstChild.type);l=e&&o.canReplaceWith(n,n,e[0])}if(l)return 0==t?r.pos:t<0?r.before(e+1):r.after(e+1)}return null}(e.state.doc,s.pos,i):s.pos;l??=s.pos;let a=e.state.tr;if(o){let{node:e}=n;e?e.replace(a):a.deleteSelection()}let c=a.mapping.map(l),d=0==i.openStart&&0==i.openEnd&&1==i.content.childCount,h=a.doc;if(d?a.replaceRangeWith(c,c,i.content.firstChild):a.replaceRange(c,c,i),a.doc.eq(h))return;let u=a.doc.resolve(c);if(d&&Ul.isSelectable(i.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new Ul(u));else{let t=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((e,n,r,s)=>t=s),a.setSelection(Ba(e,u,a.doc.resolve(t)))}e.focus(),e.dispatch(a.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},dc.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&$a(e)},20))},dc.blur=(e,t)=>{let n=t;e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),n.relatedTarget&&e.dom.contains(n.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},dc.beforeinput=(e,t)=>{if(Ta&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t)return;if(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,ua(8,"Backspace"))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}};for(let cu in hc)dc[cu]=hc[cu];function $c(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}var Rc=class e{constructor(e,t){this.toDOM=e,this.spec=t||Bc,this.side=this.spec.side||0}map(e,t,n,r){let{pos:s,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Lc(s-n,s-n,this)}valid(){return!0}eq(t){return this==t||t instanceof e&&(this.spec.key&&this.spec.key==t.spec.key||this.toDOM==t.toDOM&&$c(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Ic=class e{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,n,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return s>=i?null:new Lc(s,i,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&$c(this.attrs,t.attrs)&&$c(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},Pc=class e{constructor(e,t){this.attrs=e,this.spec=t||Bc}map(e,t,n,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let i=e.mapResult(t.to+r,-1);return i.deleted||i.pos<=s.pos?null:new Lc(s.pos-n,i.pos-n,this)}valid(e,t){let n,{index:r,offset:s}=e.content.findIndex(t.from);return s==t.from&&!(n=e.child(r)).isText&&s+n.nodeSize==t.to}eq(t){return this==t||t instanceof e&&$c(this.attrs,t.attrs)&&$c(this.spec,t.spec)}destroy(){}},Lc=class e{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(t,n){return new e(t,n,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(t,n,r){return new e(t,t,new Rc(n,r))}static inline(t,n,r,s){return new e(t,n,new Ic(r,s))}static node(t,n,r,s){return new e(t,n,new Pc(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Ic}get widget(){return this.type instanceof Rc}},zc=[],Bc={},Fc=class e{constructor(e,t){this.local=e.length?e:zc,this.children=t.length?t:zc}static create(e,t){return t.length?Jc(t,e,0,Bc):Vc}find(e,t,n){let r=[];return this.findInner(null==e?0:e,null==t?1e9:t,r,0,n),r}findInner(e,t,n,r,s){for(let i=0;i<this.local.length;i++){let o=this.local[i];o.from<=t&&o.to>=e&&(!s||s(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let o=this.children[i]+1;this.children[i+2].findInner(e-o,t-o,n,r+o,s)}}map(e,t,n){return this==Vc||0==e.maps.length?this:this.mapInner(e,t,0,0,n||Bc)}mapInner(t,n,r,s,i){let o;for(let e=0;e<this.local.length;e++){let l=this.local[e].map(t,r,s);l&&l.type.valid(n,l)?(o||(o=[])).push(l):i.onRemove&&i.onRemove(this.local[e].spec)}return this.children.length?function(e,t,n,r,s,i,o){let l=e.slice();for(let c=0,d=i;c<n.maps.length;c++){let e=0;n.maps[c].forEach((t,n,r,s)=>{let i=s-r-(n-t);for(let o=0;o<l.length;o+=3){let r=l[o+1];if(r<0||t>r+d-e)continue;let s=l[o]+d-e;n>=s?l[o+1]=t<=s?-2:-1:t>=d&&i&&(l[o]+=i,l[o+1]+=i)}e+=i}),d=n.maps[c].map(d,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(-2==l[c+1]){a=!0,l[c+1]=-1;continue}let t=n.map(e[c]+i),d=t-s;if(d<0||d>=r.content.size){a=!0;continue}let h=n.map(e[c+1]+i,-1)-s,{index:u,offset:p}=r.content.findIndex(d),m=r.maybeChild(u);if(m&&p==d&&p+m.nodeSize==h){let r=l[c+2].mapInner(n,m,t+1,e[c]+i+1,o);r!=Vc?(l[c]=d,l[c+1]=h,l[c+2]=r):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=Jc(function(e,t,n,r,s,i,o){function l(e,t){for(let i=0;i<e.local.length;i++){let l=e.local[i].map(r,s,t);l?n.push(l):o.onRemove&&o.onRemove(e.local[i].spec)}for(let n=0;n<e.children.length;n+=3)l(e.children[n+2],e.children[n]+t+1)}for(let a=0;a<e.length;a+=3)-1==e[a+1]&&l(e[a+2],t[a]+i+1);return n}(l,e,t,n,s,i,o),r,0,o);t=a.local;for(let e=0;e<l.length;e+=3)l[e+1]<0&&(l.splice(e,3),e-=3);for(let e=0,t=0;e<a.children.length;e+=3){let n=a.children[e];for(;t<l.length&&l[t]<n;)t+=3;l.splice(t,0,a.children[e],a.children[e+1],a.children[e+2])}}return new Fc(t.sort(Kc),l)}(this.children,o||[],t,n,r,s,i):o?new e(o.sort(Kc),zc):Vc}add(t,n){return n.length?this==Vc?e.create(t,n):this.addInner(t,n,0):this}addInner(t,n,r){let s,i=0;t.forEach((e,t)=>{let o,l=t+r;if(o=Hc(n,e,l)){for(s||(s=this.children.slice());i<s.length&&s[i]<t;)i+=3;s[i]==t?s[i+2]=s[i+2].addInner(e,o,l+1):s.splice(i,0,t,t+e.nodeSize,Jc(o,e,l+1,Bc)),i+=3}});let o=qc(i?Uc(n):n,-r);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||o.splice(e--,1);return new e(o.length?this.local.concat(o).sort(Kc):this.local,s||this.children)}remove(e){return 0==e.length||this==Vc?this:this.removeInner(e,0)}removeInner(t,n){let r=this.children,s=this.local;for(let e=0;e<r.length;e+=3){let s,i=r[e]+n,o=r[e+1]+n;for(let e,n=0;n<t.length;n++)(e=t[n])&&e.from>i&&e.to<o&&(t[n]=null,(s||(s=[])).push(e));if(!s)continue;r==this.children&&(r=this.children.slice());let l=r[e+2].removeInner(s,i+1);l!=Vc?r[e+2]=l:(r.splice(e,3),e-=3)}if(s.length)for(let e,i=0;i<t.length;i++)if(e=t[i])for(let t=0;t<s.length;t++)s[t].eq(e,n)&&(s==this.local&&(s=this.local.slice()),s.splice(t--,1));return r==this.children&&s==this.local?this:s.length||r.length?new e(s,r):Vc}forChild(t,n){if(this==Vc)return this;if(n.isLeaf)return e.empty;let r,s;for(let e=0;e<this.children.length;e+=3)if(this.children[e]>=t){this.children[e]==t&&(r=this.children[e+2]);break}let i=t+1,o=i+n.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<o&&t.to>i&&t.type instanceof Ic){let e=Math.max(i,t.from)-i,n=Math.min(o,t.to)-i;e<n&&(s||(s=[])).push(t.copy(e,n))}}if(s){let t=new e(s.sort(Kc),zc);return r?new Wc([t,r]):t}return r||Vc}eq(t){if(this==t)return!0;if(!(t instanceof e)||this.local.length!=t.local.length||this.children.length!=t.children.length)return!1;for(let e=0;e<this.local.length;e++)if(!this.local[e].eq(t.local[e]))return!1;for(let e=0;e<this.children.length;e+=3)if(this.children[e]!=t.children[e]||this.children[e+1]!=t.children[e+1]||!this.children[e+2].eq(t.children[e+2]))return!1;return!0}locals(e){return Gc(this.localsInner(e))}localsInner(e){if(this==Vc)return zc;if(e.inlineContent||!this.local.some(Ic.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Ic||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Fc.empty=new Fc([],[]),Fc.removeOverlap=Gc;var Vc=Fc.empty,Wc=class e{constructor(e){this.members=e}map(t,n){const r=this.members.map(e=>e.map(t,n,Bc));return e.from(r)}forChild(t,n){if(n.isLeaf)return Fc.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(t,n);i!=Vc&&(i instanceof e?r=r.concat(i.members):r.push(i))}return e.from(r)}eq(t){if(!(t instanceof e)||t.members.length!=this.members.length)return!1;for(let e=0;e<this.members.length;e++)if(!this.members[e].eq(t.members[e]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<s.length;e++)t.push(s[e])}else t=s}return t?Gc(n?t:t.sort(Kc)):zc}static from(t){switch(t.length){case 0:return Vc;case 1:return t[0];default:return new e(t.every(e=>e instanceof Fc)?t:t.reduce((e,t)=>e.concat(t instanceof Fc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function qc(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let s=e[r];n.push(new Lc(s.from+t,s.to+t,s.type))}return n}function Hc(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,s=null;for(let i,o=0;o<e.length;o++)(i=e[o])&&i.from>n&&i.to<r&&((s||(s=[])).push(i),e[o]=null);return s}function Uc(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function Jc(e,t,n,r){let s=[],i=!1;t.forEach((t,o)=>{let l=Hc(e,t,o+n);if(l){i=!0;let e=Jc(l,t,n+o+1,r);e!=Vc&&s.push(o,o+t.nodeSize,e)}});let o=qc(i?Uc(e):e,-n).sort(Kc);for(let l=0;l<o.length;l++)o[l].type.valid(t,o[l])||(r.onRemove&&r.onRemove(o[l].spec),o.splice(l--,1));return o.length||s.length?new Fc(o,s):Vc}function Kc(e,t){return e.from-t.from||e.to-t.to}function Gc(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let s=n+1;s<t.length;s++){let i=t[s];if(i.from!=r.from){i.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,i.from),Xc(t,s,r.copy(i.from,r.to)));break}i.to!=r.to&&(t==e&&(t=e.slice()),t[s]=i.copy(i.from,r.to),Xc(t,s+1,i.copy(r.to,i.to)))}}return t}function Xc(e,t,n){for(;t<e.length&&Kc(n,e[t])>0;)t++;e.splice(t,0,n)}var Yc=/[\uD800-\uDBFF]/,Zc=/[\uDC00-\uDFFF]/,Qc=(e,t)=>e>>>t|e<<32-t,ed=e=>Qc(e,2)^Qc(e,13)^Qc(e,22),td=e=>Qc(e,6)^Qc(e,11)^Qc(e,25),nd=e=>Qc(e,7)^Qc(e,18)^e>>>3,rd=e=>Qc(e,17)^Qc(e,19)^e>>>10,sd=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]),id=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),od=class{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(id),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=rd(t[d-2])+t[d-7]+nd(t[d-15])+t[d-16];let n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],l=e[5],a=e[6],c=e[7];for(let d,h,u=0;u<64;u++)d=c+td(o)+(o&l^~o&a)+sd[u]+t[u]>>>0,h=ed(n)+(n&r^n&s^r&s)>>>0,c=a,a=l,l=o,o=i+d>>>0,i=s,s=r,r=n,n=d+h>>>0;e[0]+=n,e[1]+=r,e[2]+=s,e[3]+=i,e[4]+=o,e[5]+=l,e[6]+=a,e[7]+=c}digest(e){let t=0;for(;t+56<=e.length;){let n=0;for(;n<16&&t+3<e.length;n++)this._W[n]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!=0){for(this._W.fill(0,n,16);t<e.length;)this._W[n]|=e[t]<<8*(3-t%4),t++;this._W[n]|=128<<8*(3-t%4)}this._updateHash()}const n=t%64!=0;this._W.fill(0,0,16);let r=0;for(;t<e.length;r++)for(let n=3;n>=0&&t<e.length;n--)this._W[r]|=e[t++]<<8*n;n||(this._W[r-(t%4==0?0:1)]|=128<<8*(3-t%4)),this._W[14]=e.byteLength/536870912,this._W[15]=8*e.byteLength,this._updateHash();const s=new Uint8Array(32);for(let i=0;i<this._H.length;i++)for(let e=0;e<4;e++)s[4*i+e]=this._H[i]>>>8*(3-e);return s}},ld=new sa("y-sync"),ad=new sa("y-undo"),cd=(new sa("yjs-cursor"),e=>{return yn((e=>{for(let t=6;t<e.length;t++)e[t%6]=e[t%6]^e[t];return e.slice(0,6)})((t=(e=>(e=>{const t=ot();return e(t),lt(t)})(t=>yt(t,e)))(e),(new od).digest(t))));var t}),dd=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Gr(t.ds,e.id),hd=[{light:"#ecd44433",dark:"#ecd444"}],ud=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=_e();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(r=t)[ze(Ut()*r.length)])}var r;return e.get(n)},pd=(e,{colors:t=hd,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:s=()=>{},mapping:i}={})=>{let o=!1;const l=new gd(e,i),a=new ta({props:{editable:e=>{const t=ld.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:ld,state:{init:(s,i)=>({type:e,doc:e.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:t,colorMapping:n,permanentUserData:r}),apply:(e,t)=>{const n=e.getMeta(ld);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return t.addToHistory=!1!==e.getMeta("addToHistory"),t.isChangeOrigin=void 0!==n&&!!n.isChangeOrigin,t.isUndoRedoOperation=void 0!==n&&!!n.isChangeOrigin&&!!n.isUndoRedoOperation,null!==l.prosemirrorView&&(void 0===n||null==n.snapshot&&null==n.prevSnapshot||Rr(0,()=>{null!=l.prosemirrorView&&(null==n.restore?l._renderSnapshot(n.snapshot,n.prevSnapshot,t):(l._renderSnapshot(n.snapshot,n.snapshot,t),delete t.restore,delete t.snapshot,delete t.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))})),t}},view:e=>(l.initView(e),i??l._forceRerender(),s(),{update:()=>{const t=a.getState(e.state);if(null==t.snapshot&&null==t.prevSnapshot&&(o||null!==e.state.doc.content.findDiffStart(e.state.doc.type.createAndFill().content))){if(o=!0,!1===t.addToHistory&&!t.isChangeOrigin){const t=ad.getState(e.state),n=t&&t.undoManager;n&&n.stopCapturing()}l.mux(()=>{t.doc.transact(n=>{n.meta.set("addToHistory",t.addToHistory),l._prosemirrorChanged(e.state.doc)},ld)})}},destroy:()=>{l.destroy()}})});return a},md=(e,t,n,r)=>{if(null==n)return r;if(!(null===r||n>1&&r<=1||qd(t,e,n,r)))return r;const s=Wd(t,e,n);return null!==s?s:r},fd=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:"nodeRange"===n?t.selection.depth:void 0,anchor:zd(t.selection.anchor,e.type,e.mapping),head:zd(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},gd=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=(()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else void 0!==n&&n()}})(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{null===this.beforeTransactionSelection&&null!=this.prosemirrorView&&(this.beforeTransactionSelection=fd(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return!!this.prosemirrorView.hasFocus()&&(pn&&null===this._domSelectionInView&&(Rr(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView)}_isDomSelectionInView(){const e=this.prosemirrorView._root.getSelection();if(null==e||null==e.anchorNode)return!1;const t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),0===t.getClientRects().length&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);const n=t.getBoundingClientRect(),r=Tr.documentElement;return n.bottom>=0&&n.right>=0&&n.left<=(window.innerWidth||r.clientWidth||0)&&n.top<=(window.innerHeight||r.clientHeight||0)}renderSnapshot(e,t){t||(t=Ts(Qr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(ld,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>bd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(e),0,0));t.setMeta(ld,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{const e=null!==this.beforeTransactionSelection?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(e=>bd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(t),0,0));if(e){const t=Fe(Ve(e.anchor,0),n.doc.content.size),r=Fe(Ve(e.head,0),n.doc.content.size);n.setSelection(ql.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(ld,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,s=this.type;if(e||(e=Ms(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||At(),r=new ss({gc:!1}),us(r,t),t=Ms(r),us(r,e),e=Ms(r),null===s._item){const e=Array.from(this.doc.share.keys()).find(e=>this.doc.share.get(e)===this.type);s=r.getXmlFragment(e)}else{const e=r.store.clients.get(s._item.id.client)??[];s=e[Ps(e,s._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{Kr(r,e,e=>{})});const o=(e,t)=>{const r="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:r,type:e,color:ud(n.colorMapping,n.colors,r)}},l=yi(s,new As(t.ds,e.sv)).map(n=>!n._item.deleted||dd(n._item,e)||dd(n._item,t)?bd(n,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,o):null).filter(e=>null!==e),a=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(ld,{isChangeOrigin:!0}))},ld)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=ld.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);Kr(t,t.deleteSet,e=>{if(e.constructor===Oo){const t=e.content.type;t&&this.mapping.delete(t)}}),t.changed.forEach(e),t.changedParentTypes.forEach(e),this.mapping.clear();const n=this.type.toArray().map(e=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),r=this.prosemirrorView.state.doc;let s=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Go(Wo.from(n),0,0));((e,t,n,r)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Kl(e.doc));else if("node"===t.type){const r=Fd(n.doc,n.type,t.anchor,n.mapping);null!==r&&e.setSelection(((e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?Ul.create(e.doc,t):ql.near(n)})(e,r))}else if("nodeRange"===t.type){const r=((e,t,n,r)=>{if(null===t||null===n)return null;const s=Math.min(Math.max(t,0),e.doc.content.size),i=Math.min(Math.max(n,0),e.doc.content.size);try{const t=Bl.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:i,depth:r});return t.ranges.length?t:ql.near(e.doc.resolve(s))}catch(au){return ql.near(e.doc.resolve(s))}})(e,Fd(n.doc,n.type,t.anchor,n.mapping),Fd(n.doc,n.type,t.head,n.mapping),t.depth);null!==r&&e.setSelection(r)}else{let s=Fd(n.doc,n.type,t.anchor,n.mapping),i=Fd(n.doc,n.type,t.head,n.mapping);null!=r&&(s=md(e.doc,r,t.absAnchor,s),i=md(e.doc,r,t.absHead,i)),null===s&&(s=i),null===i&&(i=s),null!==s&&null!==i&&e.setSelection(ql.between(e.doc.resolve(s),e.doc.resolve(i)))}})(s,this.beforeTransactionSelection,this,r),s=s.setMeta(ld,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Zs}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{Pd(this.doc,this.type,e,this),this.beforeTransactionSelection=fd(this,this.prosemirrorView.state)},ld)}initView(e){null!=this.prosemirrorView&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){null!=this.prosemirrorView&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},xd=(e,t,n,r,s,i)=>{const o=n.mapping.get(e);if(void 0===o){if(e instanceof no)return bd(e,t,n,r,s,i);throw Et()}return o},bd=(e,t,n,r,s,i)=>{const o=[],l=e=>{if(e instanceof no){const l=xd(e,t,n,r,s,i);null!==l&&o.push(l)}else{const l=(e._item.right?.content)?.type;l instanceof Qi&&!l._item.deleted&&l._item.id.client===l.doc.clientID&&(e.applyDelta([{retain:e.length},...l.toDelta()]),l.doc.transact(e=>{l._item.delete(e)}));const a=yd(e,t,n,r,s,i);null!==a&&a.forEach(e=>{null!==e&&o.push(e)})}};void 0===r||void 0===s?e.toArray().forEach(l):yi(e,new As(s.ds,r.sv)).forEach(l);try{const l=e.getAttributes(r);void 0!==r&&(dd(e._item,r)?dd(e._item,s)||(l.ychange=i?i("added",e._item.id):{type:"added"}):l.ychange=i?i("removed",e._item.id):{type:"removed"});const a=t.node(e.nodeName,l,o);return n.mapping.set(e,a),a}catch(au){return e.doc.transact(t=>{e._item.delete(t)},ld),n.mapping.delete(e),null}},yd=(e,t,n,r,s,i)=>{const o=[],l=e.toDelta(r,s,i);try{for(let e=0;e<l.length;e++){const n=l[e];o.push(t.text(n.insert,Rd(n.attributes,t)))}}catch(au){return e.doc.transact(t=>{e._item.delete(t)},ld),null}return o},wd=(e,t)=>e instanceof Array?((e,t)=>{const n=new io,r=e.map(e=>({insert:e.text,attributes:Id(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new no(e.type.name);for(const r in e.attrs){const t=e.attrs[r];null!==t&&"ychange"!==r&&n.setAttribute(r,t)}return n.insert(0,jd(e).map(e=>wd(e,t))),t.mapping.set(n,e),n})(e,t),vd=e=>"object"==typeof e&&null!==e,kd=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);let r=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&r;s++){const i=n[s],o=e[i],l=t[i];r="ychange"===i||o===l||vd(o)&&vd(l)&&kd(o,l)}return r},jd=e=>{const t=e.content.content,n=[];for(let r=0;r<t.length;r++){const e=t[r];if(e.isText){const e=[];for(let n=t[r];r<t.length&&n.isText;n=t[++r])e.push(n);r--,n.push(e)}else n.push(e)}return n},Sd=(e,t)=>{const n=e.toDelta();return n.length===t.length&&n.every((e,n)=>e.insert===t[n].text&&rn(e.attributes||{}).length===t[n].marks.length&&on(e.attributes,(e,r)=>{const s=$d(r),i=t[n].marks;return!!i.find(e=>e.type.name===s)&&kd(e,i.find(e=>e.type.name===s)?.attrs)}))},Cd=(e,t)=>{if(e instanceof no&&!(t instanceof Array)&&Ld(e,t)){const n=jd(t);return e._length===n.length&&kd(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>Cd(e,n[t]))}return e instanceof io&&t instanceof Array&&Sd(e,t)},Nd=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Ed=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>r.mapping.delete(e)),e.delete(t,n))},Ad=(e,t,n,r,s,i)=>{if(r<s){const o=[];for(let e=r;e<s;e++)o.push(wd(n[e],i));e.insert(t,o)}},Td=(e,t,n,r)=>t instanceof io&&n instanceof Array?(Sd(t,n)?r.mapping.set(t,n):Dd(t,n,r),!0):!(!(t instanceof no)||n instanceof Array||!Ld(t,n)||(Cd(t,n)?r.mapping.set(t,n):Pd(e,t,n,r),0)),Md=(e,t,n,r,s,i,o,l,a)=>{const c=Fe(i-s,l-o);for(let d=0;d<c;d++){const i=r[s+d],l=n[o+d];Td(e,i,l,a)||(Ed(t,o+d,1,a),Ad(t,o+d,n,o+d,o+d+1,a))}Ed(t,o+c,i-s-c,a),Ad(t,o+c,n,o+c,l,a)},_d=(e,t,n)=>{const r=e.toArray(),s=jd(t),i=s.length,o=r.length,l=Fe(o,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=r[a],t=s[a];if(Nd(n.mapping.get(e),t))d=!0;else if(!Cd(e,t))break}for(;a+c<l;c++){const e=r[o-c-1],t=s[i-c-1];if(Nd(n.mapping.get(e),t))d=!0;else if(!Cd(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},Dd=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:r,str:s}=(e=>{let t="",n=e._start;const r={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof bo?t+=n.content.str:n.content instanceof mo&&(r[n.content.key]=null)),n=n.right;return{str:t,nAttrs:r}})(e),i=t.map(e=>({insert:e.text,attributes:Object.assign({},r,Id(e.marks,n))})),{insert:o,remove:l,index:a}=((e,t)=>{let n=0,r=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;for(n>0&&Yc.test(e[n-1])&&n--;r+n<e.length&&r+n<t.length&&e[e.length-r-1]===t[t.length-r-1];)r++;return r>0&&Zc.test(e[e.length-r])&&r--,{index:n,remove:e.length-n-r,insert:t.slice(n,t.length-r)}})(s,i.map(e=>e.insert).join(""));e.delete(a,l),e.insert(a,o),e.applyDelta(i.map(e=>({retain:e.insert.length,attributes:e.attributes})))},Od=/(.*)(--[a-zA-Z0-9+/=]{8})$/,$d=e=>Od.exec(e)?.[1]??e,Rd=(e,t)=>{const n=[];for(const r in e)n.push(t.mark($d(r),e[r]));return n},Id=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const r=Me(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${cd(e.toJSON())}`:e.type.name]=e.attrs}}),n},Pd=(e,t,n,r)=>{if(t instanceof no&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(t,n),t instanceof no){const e=t.getAttributes(),r=n.attrs;for(const n in r)null!==r[n]?e[n]!==r[n]&&"ychange"!==n&&t.setAttribute(n,r[n]):t.removeAttribute(n);for(const n in e)void 0===r[n]&&t.removeAttribute(n)}const s=jd(n),i=s.length,o=t.toArray(),l=o.length,a=Fe(i,l);if(((e,t,n,r,s)=>{const i=((e,t,n)=>{const r=new Map;t.forEach((e,t)=>{r.has(e)||r.set(e,t)});const s=[];if(e.forEach((e,i)=>{const o=n.mapping.get(e),l=r.get(o);void 0!==l&&Nd(o,t[l])&&s.push({yIndex:i,pIndex:l,yChild:e})}),0===s.length)return[];const i=new Array(s.length),o=[];for(let a=0;a<s.length;a++){let e=0,t=o.length;for(;e<t;){const n=e+t>>1;s[o[n]].pIndex<s[a].pIndex?e=n+1:t=n}i[a]=e>0?o[e-1]:-1,o[e]=a}const l=[];for(let a=o[o.length-1];-1!==a;a=i[a])l.push(s[a]);return l.reverse()})(r,n,s);if(i.length<2||!i.some(e=>e.yIndex!==e.pIndex)||i.some(e=>{const t=n[e.pIndex];return!(e.yChild instanceof io&&t instanceof Array||e.yChild instanceof no&&!(t instanceof Array))}))return!1;let o=0,l=0;for(const a of i){Md(e,t,n,r,o,a.yIndex,l,a.pIndex,s);const i=n[a.pIndex];Td(e,a.yChild,i,s),o=a.yIndex+1,l=a.pIndex+1}return Md(e,t,n,r,o,r.length,l,n.length,s),!0})(e,t,s,o,r))return;let c=0,d=0;for(;c<a;c++){const e=o[c],t=s[c];if(!Nd(r.mapping.get(e),t)){if(!Cd(e,t))break;r.mapping.set(e,t)}}for(;d+c+1<a;d++){const e=o[l-d-1],t=s[i-d-1];if(!Nd(r.mapping.get(e),t)){if(!Cd(e,t))break;r.mapping.set(e,t)}}e.transact(()=>{for(;l-c-d>0&&i-c-d>0;){const n=o[c],a=s[c],h=o[l-d-1],u=s[i-d-1];if(n instanceof io&&a instanceof Array)Sd(n,a)||Dd(n,a,r),c+=1;else{let s=n instanceof no&&Ld(n,a),i=h instanceof no&&Ld(h,u);if(s&&i){const e=_d(n,a,r),t=_d(h,u,r);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?s=!1:i=!1}s?(Pd(e,n,a,r),c+=1):i?(Pd(e,h,u,r),d+=1):(r.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[wd(a,r)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&o[0]instanceof io?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):n>0&&(t.slice(c,c+n).forEach(e=>r.mapping.delete(e)),t.delete(c,n)),c+d<i){const e=[];for(let t=c;t<i-d;t++)e.push(wd(s[t],r));t.insert(c,e)}},ld)},Ld=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,zd=(e,t,n)=>{if(0===e)return Ns(t,0,-1);let r=null===t._first?null:t._first.content.type;for(;null!==r&&t!==r;){if(r instanceof io){if(r._length>=e)return Ns(r,e,-1);if(e-=r._length,null!==r._item&&null!==r._item.next)r=r._item.next.content.type;else{do{r=null===r._item?null:r._item.parent,e--}while(r!==t&&null!==r&&null!==r._item&&null===r._item.next);null!==r&&r!==t&&(r=null===r._item?null:r._item.next.content.type)}}else{const s=(n.get(r)||{nodeSize:0}).nodeSize;if(null!==r._first&&e<s)r=r._first.content.type,e--;else{if(1===e&&0===r._length&&s>1)return new js(null===r._item?null:r._item.id,null===r._item?vs(r):null,null);if(e-=s,null!==r._item&&null!==r._item.next)r=r._item.next.content.type;else{if(0===e)return r=null===r._item?r:r._item.parent,new js(null===r._item?null:r._item.id,null===r._item?vs(r):null,null);do{r=r._item.parent,e--}while(r!==t&&null===r._item.next);r!==t&&(r=r._item.next.content.type)}}}if(null===r)throw At();if(0===e&&r.constructor!==io&&r!==t)return Bd(r._item.parent,r._item)}return Ns(t,t._length,-1)},Bd=(e,t)=>{let n=null,r=null;return null===e._item?r=vs(e):n=ws(e._item.id.client,e._item.id.clock),new js(n,r,t.id)},Fd=(e,t,n,r)=>{const s=Es(n,e);if(null===s||s.type!==t&&!ks(t,s.type._item))return null;let i=s.type,o=0;if(i.constructor===io)o=s.index;else if(null===i._item||!i._item.deleted){let e=i._first,t=0;for(;t<i._length&&t<s.index&&null!==e;){if(!e.deleted){const n=e.content.type;if(t++,n instanceof io)o+=n._length;else{const e=r.get(n);if(null==e)return null;o+=e.nodeSize}}e=e.right}o+=1}for(;i!==t&&null!==i._item;){const e=i._item.parent;if(null===e._item||!e._item.deleted){o+=1;let t=e._first;for(;null!==t;){const e=t.content.type;if(e===i)break;if(!t.deleted)if(e instanceof io)o+=e._length;else{const t=r.get(e);if(null==t)return null;o+=t.nodeSize}t=t.right}}i=e}const l=o-1;return((e,t,n)=>{if(null===n)return!1;const r=Es(t,e);return null!==r&&r.type instanceof io&&null!==t.item&&n<=1})(e,n,l)?null:l},Vd=(e,t)=>{if(e===t)return!0;const n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])},Wd=(e,t,n)=>{let r=0,s=0;for(;s<e.childCount;s++){const t=e.child(s);if(r+t.nodeSize>n)break;r+=t.nodeSize}if(s>=e.childCount)return null;const i=e.child(s),o=e.resolve(n),l=(e,t)=>{if(0===o.depth){const s=e+(n-r),i=e+1,o=e+t.nodeSize-1;return Math.max(i,Math.min(s,o))}return((e,t,n)=>{let r=t+1,s=n;for(let i=1;i<e.depth;i++){const t=e.index(i);if(t>=s.childCount)return null;for(let e=0;e<t;e++)r+=s.child(e).nodeSize;if(r+=1,s=s.child(t),s.type!==e.node(i+1).type)return null}return s.isTextblock?r+Math.min(e.parentOffset,s.content.size):null})(o,e,t)},a=(n,r=!1)=>{let i=0;for(let t=0;t<=s;t++)n(e.child(t))&&i++;let o=0,a=-1,c=null,d=0;for(let e=0;e<t.childCount;e++){const r=t.child(e);n(r)&&(o++,o===i&&(a=d,c=r)),d+=r.nodeSize}return null===c||r&&(1!==i||1!==o)?null:l(a,c)},c=e=>e.type===i.type&&Vd(e.attrs,i.attrs),d=i.textContent,h=a(e=>c(e)&&e.textContent===d);if(null!==h)return h;const u=a(e=>e.type===i.type&&e.textContent===d);if(null!==u)return u;if((e=>{const t=e.type.spec.attrs||{};return Object.keys(e.attrs).some(n=>{const r=t[n];return null==r||!Object.prototype.hasOwnProperty.call(r,"default")||r.default!==e.attrs[n]})})(i)){const e=a(c,!0);if(null!==e)return e}return a(e=>c(e)&&""!==d&&""!==e.textContent&&(d.startsWith(e.textContent)||e.textContent.startsWith(d)),!0)},qd=(e,t,n,r)=>{if(null===r)return!1;const s=e.resolve(n),i=t.resolve(r);if(!s.parent.isTextblock)return!1;if(!i.parent.isTextblock)return!0;if(s.parent.textContent!==i.parent.textContent)return!0;if(0!==s.parentOffset&&0===i.parentOffset)return!0;const o=0===s.parentOffset&&0===i.parentOffset,l=s.parentOffset!==i.parentOffset||s.parent.type!==i.parent.type||!Vd(s.parent.attrs,i.parent.attrs);if(o||l){const s=Wd(e,t,n);return null!==s&&s!==r}return!1},Hd=new Set(["paragraph"]);function Ud(e){return!!e.getMeta(ld)}function Jd(e,t){const n=ld.getState(e);return Fd(n.doc,n.type,t,n.binding.mapping)||0}function Kd(e,t){const n=ld.getState(e);return zd(t,n.type,n.binding.mapping)}var Gd=class e extends b.MappablePosition{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}}};b.Extension.create({name:"collaboration",priority:1e3,addOptions:()=>({document:null,field:"default",fragment:null,provider:null}),addStorage:()=>({isDisabled:!1}),onCreate(){this.editor.extensionManager.extensions.find(e=>"undoRedo"===e.name)},onBeforeCreate(){this.editor.utils.getUpdatedPosition=(e,t)=>function(e,t,n){const r=e instanceof Gd?e.yRelativePosition:null;if(Ud(t)&&r)return{position:new Gd(Jd(n,r),r),mapResult:null};const s=(0,b.getUpdatedPosition)(e,t),i=s.position.position;return{position:new Gd(i,null!=r?r:Kd(n,i)),mapResult:s.mapResult}}(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>function(e,t){return new Gd(e,Kd(t,e))}(e,this.editor.state)},addCommands:()=>({undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ad.getState(t).undoManager.undoStack.length&&(!n||(e=>{const t=ad.getState(e).undoManager;if(null!=t)return t.undo(),!0})(t))),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ad.getState(t).undoManager.redoStack.length&&(!n||(e=>{const t=ad.getState(e).undoManager;if(null!=t)return t.redo(),!0})(t)))}),addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Mod-y":()=>this.editor.commands.redo(),"Shift-Mod-z":()=>this.editor.commands.redo()}},addProseMirrorPlugins(){const e=this.options.fragment?this.options.fragment:this.options.document.getXmlFragment(this.options.field),t=(({protectedNodes:e=Hd,trackedOrigins:t=[],undoManager:n=null}={})=>new ta({key:ad,state:{init:(r,s)=>{const i=ld.getState(s);let o=n;if(!o){const n=i.doc,r=new Set(n?n._observers.get("destroy"):[]);o=new Zs(i.type,{trackedOrigins:new Set([ld].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Oo&&e.content instanceof Eo&&(e.content.type instanceof Qi||e.content.type instanceof no&&t.has(e.content.type.nodeName))&&0!==e.content.type._length))(t,e),captureTransaction:e=>!1!==e.meta.get("addToHistory")});const s=n?n._observers.get("destroy"):new Set;o._yTiptapDocDestroyListeners=Array.from(s||[]).filter(e=>!r.has(e))}return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(e,t,n,r)=>{const s=ld.getState(r).binding,i=t.undoManager,o=i.undoStack.length>0,l=i.redoStack.length>0;return s?{undoManager:i,prevSel:fd(s,n),hasUndoOps:o,hasRedoOps:l}:o!==t.hasUndoOps||l!==t.hasRedoOps?Object.assign({},t,{hasUndoOps:i.undoStack.length>0,hasRedoOps:i.redoStack.length>0}):t}},view:e=>{const t=ld.getState(e.state),n=ad.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const r=t.binding;r&&n.meta.set(r,ad.getState(e.state).prevSel)}),n.on("stack-item-popped",({stackItem:e})=>{const n=t.binding;n&&(n.beforeTransactionSelection=e.meta.get(n)||n.beforeTransactionSelection)}),{destroy:()=>{n.destroy();const e=n._yTiptapDocDestroyListeners;e&&n.doc&&(e.forEach(e=>n.doc.off("destroy",e)),n._yTiptapDocDestroyListeners=null)}}}}))(this.options.yUndoOptions),n=t.spec.view;return t.spec.view=e=>{const{undoManager:t}=ad.getState(e.state);t.restore&&(t.restore(),t.restore=()=>{});const r=n?n(e):void 0;return{destroy:()=>{const e=t.trackedOrigins.has(t),n=t._observers;t.restore=()=>{e&&t.trackedOrigins.add(t),t.doc.on("afterTransaction",t.afterTransactionHandler),t._observers=n},null!=r&&r.destroy&&r.destroy()}}},[pd(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new y.Plugin({key:new y.PluginKey("filterInvalidContent"),filterTransaction:t=>{if(!Ud(t))return!0;if(this.storage.isDisabled)return!1;if(!t.docChanged)return!0;try{return t.doc.check(),!0}catch(n){return this.storage.isDisabled=!0,this.editor.emit("contentError",{error:n,editor:this.editor,disableCollaboration:()=>{var t;null==(t=e.doc)||t.destroy()}}),!0}}})].filter(Boolean)}});function Xd(e,t){const{state:n}=t,r=n.selection.$anchor;let s=!1;if(r.depth)for(let i=r.depth;i>0;i--)r.node(i).type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(r.before(i),r.after(i)).scrollIntoView()),s=!0);else{const r=n.selection.node;r&&r.type.name===e&&(t.chain().deleteSelection().run(),s=!0)}if(!s){const i=r.pos;if(i){const r=n.tr.doc.nodeAt(i);r&&r.type.name===e&&(t.dispatchTransaction&&t.dispatchTransaction(n.tr.delete(i,i+r.nodeSize)),s=!0)}}return s}var Yd=[{value:"note",label:"Note",icon:"Info"},{value:"tip",label:"Tip",icon:"Lightbulb"},{value:"important",label:"Important",icon:"AlertCircle"},{value:"warning",label:"Warning",icon:"TriangleAlert"},{value:"caution",label:"Caution",icon:"OctagonAlert"}];function Zd(){const e=n.m$2(),t=n.d$2(),{t:r}=n._(),{type:s,title:i,body:o}=n.Ht(t,n.q.name,{type:"note",title:"",body:""}),[l,a]=(0,x.useState)(!1),[c,d]=(0,x.useState)("note"),[h,u]=(0,x.useState)(""),[p,m]=(0,x.useState)("");(0,x.useEffect)(()=>{l&&(d(s||"note"),u(i||""),m(o||""))},[l,s,i,o]);const f=(0,x.useCallback)(()=>{t&&(t.chain().updateAttributes(n.q.name,{type:c,title:h,body:p}).focus().run(),a(!1))},[t,c,h,p]),g=(0,x.useCallback)(()=>{a(!1)},[]),b=(0,x.useCallback)(()=>{Xd(n.q.name,t)},[t]),y=(0,x.useCallback)(()=>t.isActive(n.q.name),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:y,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsxs)(n.o,{onOpenChange:a,open:l,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:r("editor.callout.edit.title")})}),(0,w.jsxs)(n.h$1,{children:[(0,w.jsx)(n.m,{children:r("editor.callout.edit.title")}),(0,w.jsxs)("div",{className:"richtext-space-y-4 richtext-py-4",children:[(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.type")}),(0,w.jsxs)(n.R,{onValueChange:d,value:c,children:[(0,w.jsx)(n.B,{children:(0,w.jsx)(n.S,{className:"richtext-text-accent",placeholder:r("editor.callout.dialog.type.placeholder")})}),(0,w.jsx)(n.V,{children:Yd.map(e=>(0,w.jsx)(n.D$1,{value:e.value,children:r(`editor.callout.type.${e.value}`)},e.value))})]})]}),(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.title.label")}),(0,w.jsx)(n.i$1,{onChange:e=>u(e.target.value),placeholder:r("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),(0,w.jsxs)("div",{className:"richtext-space-y-2",children:[(0,w.jsx)(n.s$2,{children:r("editor.callout.dialog.body.label")}),(0,w.jsx)(n.i$1,{onChange:e=>m(e.target.value),placeholder:r("editor.callout.dialog.body.placeholder"),type:"text",value:p})]})]}),(0,w.jsxs)(n.n$2,{children:[(0,w.jsx)(n.x$1,{onClick:g,variant:"outline",children:r("editor.callout.dialog.button.cancel")}),(0,w.jsx)(n.x$1,{onClick:f,children:r("editor.callout.dialog.button.apply")})]})]})]}),(0,w.jsx)(n.f$2,{action:b,icon:"Trash2",tooltip:r("editor.delete")})]})}):(0,w.jsx)(w.Fragment,{})}function Qd(){const e=n.m$2(),t=n.d$2(),{t:r}=n._(),s=(0,x.useCallback)(()=>t.isActive(n.A.name),[t]),i=(0,x.useCallback)(()=>Xd(n.A.name,t),[t]),o=(0,x.useCallback)(()=>t.chain().focus().addColBefore().run(),[t]),l=(0,x.useCallback)(()=>t.chain().focus().addColAfter().run(),[t]),a=(0,x.useCallback)(()=>t.chain().focus().deleteCol().run(),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:s,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(n.f$2,{action:o,icon:"ColumnAddLeft",tooltip:r("editor.table.menu.insertColumnBefore")}),(0,w.jsx)(n.f$2,{action:l,icon:"ColumnAddRight",tooltip:r("editor.table.menu.insertColumnAfter")}),(0,w.jsx)(n.f$2,{action:a,icon:"DeleteColumn",tooltip:r("editor.table.menu.deleteColumn")}),(0,w.jsx)(n.f$2,{action:i,icon:"Trash2",tooltip:r("editor.table.menu.delete_column")})]})}):(0,w.jsx)(w.Fragment,{})}function eh(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateImage({width:n.p$3[s]}),isActive:()=>e.isActive("image",{width:n.p$3[s]})}}))}function th(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateImageGif({width:n.p$3[s]}),isActive:()=>e.isActive("image",{width:n.p$3[s]})}}))}function nh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImage?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function rh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageGif?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function sh(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageMermaid?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ih(e,t){const r={left:"AlignLeft",center:"AlignCenter",right:"AlignRight"};return["left","center","right"].map(s=>({type:`image-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.textalign.${s}.tooltip`),icon:r[s],action:()=>e.commands?.setAlignImageDrawer?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function oh(e){return[{type:"flex-start",icon:"AlignLeft",tooltip:"Align left"},{type:"center",icon:"AlignCenter",tooltip:"Align center"},{type:"flex-end",icon:"AlignRight",tooltip:"Align right"}].map(t=>({type:`video-align-${t.type}`,component:n.f$2,componentProps:{tooltip:t.tooltip,icon:t.icon,action:()=>e.commands.updateVideo({align:t.type}),isActive:()=>e.getAttributes("video").align===t.type}}))}function lh(e,t){const r=["SizeS","SizeM","SizeL"];return["size-small","size-medium","size-large"].map((s,i)=>({type:`video-${s}`,component:n.f$2,componentProps:{tooltip:t(`editor.${s.replace("-",".")}.tooltip`),icon:r[i],action:()=>e.commands.updateVideo({width:n.u$3[s]}),isActive:()=>e.isActive("video",{width:n.u$3[s]})}}))}var ah=!1;function ch({editor:e,attrs:t,extension:r}){const[s,i]=(0,x.useState)(!1),o=(0,x.useRef)(null),l=(0,x.useRef)(null),{alt:a,align:c}=t,d=r?.options.upload;(0,x.useEffect)(()=>{s&&setTimeout(()=>{(async()=>{const e=document.querySelector("#easydrawer");e&&(o.current=new E.Editor(e,{wheelEventsEnabled:!1,disableZoom:!0}),l.current=(0,E.makeDropdownToolbar)(o.current),l.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(a)))})()},200)},[s]);const h=()=>{if(ah){for(;o.current.history.redoStackSize>0;)o.current.history.redo();ah=!1}else o.current.history.undo()};return(0,w.jsxs)(n.o,{onOpenChange:i,open:s,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{action:()=>i(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:"Edit Drawer"}),(0,w.jsxs)("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[(0,w.jsx)("div",{className:"richtext-size-full",id:"easydrawer"}),(0,w.jsx)(n.me,{changeBorderColorShape:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setBorderColor(e),n.serializeState())},changeColorShape:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setColor(e),n.serializeState())},changeShape:e=>{const t=l.current.getWidgetById("shape");t&&t.setShapeType(e)},onClear:()=>{if(!ah){for(;o.current.history.undoStackSize>0;)h();ah=!0}},onRedo:()=>{ah||o.current.history.redo()},onThicknessChange:e=>{const t=o.current.toolController.getPrimaryTools()[5],n=l.current.getWidgetById("shape");t&&n&&(t.setThickness(e),n.serializeState())},onUndo:h,refEditor:o,setColorHighlight:e=>{const t=o.current.toolController.getPrimaryTools()[3],n=l.current.getWidgetById("pen-2");t&&n&&(t.setColor(e),n.serializeState())},setColorPen:e=>{const t=o.current.toolController.getPrimaryTools()[2],n=l.current.getWidgetById("pen-1");t&&n&&(t.setColor(e),n.serializeState())},setThicknessPen:e=>{const t=o.current.toolController.getPrimaryTools()[2],n=l.current.getWidgetById("pen-1");t&&n&&(t.setThickness(e),n.serializeState())}})]}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:async()=>{if(o.current){const t=o.current.toSVG(),r=t.outerHTML,s=`drawer-${n.a$2()}.svg`;let i=n.n$1(t.outerHTML);if(d){const e=n.s$1(i,s);i=await d(e)}e?.chain().focus().setDrawer({type:"drawer",src:i,alt:encodeURIComponent(r),width:426,height:212},!!r).run(),e?.commands.setAlignImageDrawer(c)}i(!1)},type:"button",children:"Save changes"})})]})]})}function dh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function hh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$2(),i=n.Ht(s,n.ve.name),o=n.v(n.ve.name),l=(0,x.useMemo)(()=>function(e,t){return[...ih(e,t),{type:"edit",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleDrawer",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(e.type.name===n.ve.name)return i=!0,!1}),i},children:l?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l?.map((e,t)=>"edit"===e.type&&i?.src?(0,w.jsx)(ch,{attrs:i,editor:s,extension:o},`bubbleMenu-drawer-${t}`):(0,w.jsx)(dh,{editor:s,item:e},`bubbleMenu-drawer-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function uh({children:e,visible:t,toggleVisible:r}){const{t:s}=n._(),i=n.d$2(),[o,l]=(0,x.useState)(null);(0,x.useEffect)(()=>{a.l().then(l)},[]);const{text:c,macros:d}=n.Ht(i,n.Wt.name,{text:"",macros:""}),[h,u]=(0,x.useState)(decodeURIComponent(c||"")),[p,m]=(0,x.useState)(decodeURIComponent(d||""));(0,x.useEffect)(()=>{t&&(u(decodeURIComponent(c||"")),m(decodeURIComponent(d||"")))},[t]);const f=(0,x.useCallback)(()=>{i.chain().focus().setKatex({text:encodeURIComponent(h),macros:encodeURIComponent(p)}).run(),u(""),m(""),r(!1)},[i,h,p,r]),g=(0,x.useMemo)(()=>{if(!o)return h;try{return o.renderToString(h,{macros:n.Y(p||"")})}catch{return h}},[h,p,o]),b=(0,x.useMemo)(()=>`${h}`.trim()?g:null,[h,g]);return(0,w.jsxs)(n.o,{onOpenChange:r,open:t,children:[(0,w.jsx)(n.s,{asChild:!0,children:e}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:s("editor.formula.dialog.text")}),(0,w.jsx)("div",{style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,w.jsxs)("div",{className:"richtext-flex-1",children:[(0,w.jsx)(n.s$2,{className:"mb-[6px]",children:"Expression"}),(0,w.jsx)(n.i,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:e=>u(e.target.value),placeholder:"Text",required:!0,rows:10,value:h,style:{color:"var(--richtext-foreground)"}}),(0,w.jsx)(n.s$2,{className:"mb-[6px]",children:"Macros"}),(0,w.jsx)(n.i,{onChange:e=>m(e.target.value),placeholder:"Macros",rows:10,value:p,style:{color:"var(--richtext-foreground)"}})]}),(0,w.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:b||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:f,type:"button",children:"Save changes"})})]})]})}function ph(){const e=n.m$2(),t=n.d$2(),[r,s]=(0,x.useState)(!1),i=(0,x.useCallback)(()=>t.isActive(n.Wt.name),[t]),o=(0,x.useCallback)(()=>Xd(n.Wt.name,t),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:i,children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(uh,{toggleVisible:s,visible:r,children:(0,w.jsx)(n.f$2,{action:()=>s(!r),tooltip:"Edit",children:(0,w.jsx)(v.Pencil,{size:16})})}),(0,w.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,w.jsx)(v.Trash2,{size:16})})]})}):(0,w.jsx)(w.Fragment,{})}function mh(e){const{t:t}=n._();return(0,w.jsxs)("div",{className:"richtext-flex richtext-flex-nowrap",children:[(0,w.jsx)(n.f$2,{disabled:!e?.link,icon:"ExternalLink",tooltip:t("editor.link.open.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{window.open(e?.link,"_blank")}}),(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onEdit()}}),(0,w.jsx)(n.f$2,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onClear()}})]})}function fh(){const e=n.m$2(),t=n.d$2(),[r,s]=(0,x.useState)(!1),i=n.Ht(t,n.Fe.name)?.href,o=(0,x.useCallback)(({editor:e})=>e.isActive(n.Fe.name),[]),l=(0,x.useCallback)(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),s(!1)},[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:(0,w.jsx)(w.Fragment,{children:(0,w.jsx)("div",r?{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(n.De,{editor:t,onClose:()=>{s(!1)},onSetLink:(e,n,r)=>{const{from:i}=t.state.selection,o=i+(n?.length??0);t.chain().extendMarkRange("link").insertContent({type:"text",text:n,marks:[{type:"link",attrs:{href:e,target:r?"_blank":""}}]}).setLink({href:e}).setTextSelection({from:i,to:o}).focus().run(),s(!1)}})}:{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(mh,{editor:t,link:i,onClear:l,onEdit:()=>{s(!0)}})})})}):(0,w.jsx)(w.Fragment,{})}function gh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentdisabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function xh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$2(),i=(0,x.useMemo)(()=>function(e,t){return[{type:"flipX",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.tooltip.flipX"),icon:"FlipX",action:()=>{const{flipX:t}=e.getAttributes("image");e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipX:!t}).run()}}},{type:"flipY",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.tooltip.flipY"),icon:"FlipY",action:()=>{const{flipY:t}=e.getAttributes("image");e.chain().focus(void 0,{scrollIntoView:!1}).updateImage({flipY:!t}).run()}}},...eh(e,t),...nh(e,t),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImage",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.ae.name}(e))return i=!0,!1}),i},children:i?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:i?.map((e,t)=>(0,w.jsx)(gh,{editor:s,item:e},`bubbleMenu-image-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function bh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$2(),i=(0,x.useMemo)(()=>function(e,t){return[...th(e,t),...rh(e,t),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,t,e]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleImageGif",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.C.name}(e))return i=!0,!1}),i},children:i?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:i?.map((e,t)=>(0,w.jsx)(gh,{editor:s,item:e},`bubbleMenu-image-gif-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function yh(){const{t:e}=n._(),t=n.m$2(),r=n.d$2(),s=(0,x.useMemo)(()=>function(e,t){return[...lh(e,t),...oh(e),{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(r,e),[r,e]);return t?(0,w.jsx)(j.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleVideo",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.T.name}(e))return i=!0,!1}),i},children:s?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:s?.map((e,t)=>(0,w.jsx)(gh,{editor:r,item:e},`bubbleMenu-video-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}var wh="graph TB\na--\x3eb",vh=({editor:e,attrs:t,extension:r})=>{const{alt:s,align:i}=t,[o,l]=(0,x.useState)(decodeURIComponent(s??wh)),[a,c]=(0,x.useState)(""),[d,h]=(0,x.useState)(!1),u=(0,x.useRef)(null),[p,m]=(0,x.useState)(null),f=r?.options.upload,g=(0,x.useCallback)(e=>{e&&import("mermaid").then(e=>{m(e.default)})},[]),b=async e=>{try{const{svg:t}=await p.render("mermaid-svg",e);c(t)}catch{c("")}};return(0,x.useEffect)(()=>{p&&d&&(p.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o))},[p,d]),(0,x.useEffect)(()=>{p&&d&&b(o)},[p,o]),(0,w.jsxs)(n.o,{onOpenChange:h,open:d,children:[(0,w.jsx)(n.s,{asChild:!0,children:(0,w.jsx)(n.f$2,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),(0,w.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,w.jsx)(n.m,{children:"Edit Mermaid"}),(0,w.jsx)("div",{ref:g,style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,w.jsx)(n.i,{autoFocus:!0,className:"richtext-flex-1",defaultValue:wh,onChange:e=>l(e.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"var(--richtext-foreground)"}}),(0,w.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:a},ref:u,style:{height:"100%",border:"1px solid var(--richtext-border)",minHeight:500}})]})}),(0,w.jsx)(n.n$2,{children:(0,w.jsx)(n.x$1,{onClick:async()=>{if(""!==o){if(o){const t=u.current.querySelector("svg"),{width:r,height:s}=t.getBoundingClientRect(),l=`mermaid-${n.a$2()}.svg`;let a=n.n$1(t.outerHTML);if(f){const e=n.s$1(a,l);a=await f(e)}e?.chain().focus().setMermaid({type:"mermaid",src:a,alt:encodeURIComponent(o),width:r,height:s},!!o).run(),e?.commands.setAlignImageMermaid(i)}h(!1)}},type:"button",children:"Save changes"})})]})]})};function kh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,w.jsx)(x.Fragment,{children:"divider"===e.type?(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,w.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,w.jsx)(w.Fragment,{})}function jh(){const{lang:e,t:t}=n._(),r=n.m$2(),s=n.d$2(),i=n.Ht(s,n.O.name),o=n.v(n.O.name),l=(0,x.useMemo)(()=>function(e,t){return[...sh(e,t),{type:"edit",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.edit"),icon:"Pencil",action:()=>!0}},{type:"remove",component:n.f$2,componentProps:{editor:e,tooltip:t("editor.remove"),icon:"Trash2",action:()=>{const{state:t,dispatch:n}=e.view;(0,A.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleMermaid",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:r,to:s}=t;let i=!1;return e.view.state.doc.nodesBetween(r.pos,s,e=>{if(function(e){return e.type.name===n.O.name}(e))return i=!0,!1}),i},children:l?.length?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:l?.map((e,t)=>"edit"===e.type&&i?.src?(0,w.jsx)(vh,{attrs:i,editor:s,extension:o},`bubbleMenu-mermaid-${t}`):(0,w.jsx)(kh,{editor:s,item:e},`bubbleMenu-mermaid-${t}`))}):(0,w.jsx)(w.Fragment,{})}):(0,w.jsx)(w.Fragment,{})}function Sh({hiddenActions:e=[]}){const{t:t}=n._(),r=n.m$2(),s=n.d$2(),i=t=>e.includes(t);return r?(0,w.jsx)(j.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:({editor:e})=>(0,b.isActive)(e.view.state,n.st.name),children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[!i("addColumnBefore")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addColumnBefore().run()},disabled:!s?.can()?.addColumnBefore?.(),icon:"BetweenHorizonalEnd",tooltip:t("editor.table.menu.insertColumnBefore"),tooltipOptions:{sideOffset:15}}),!i("addColumnAfter")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addColumnAfter().run()},disabled:!s?.can()?.addColumnAfter?.(),icon:"BetweenHorizonalStart",tooltip:t("editor.table.menu.insertColumnAfter"),tooltipOptions:{sideOffset:15}}),!i("deleteColumn")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteColumn().run()},disabled:!s?.can().deleteColumn?.(),icon:"DeleteColumn",tooltip:t("editor.table.menu.deleteColumn"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("addRowAbove")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addRowBefore().run()},disabled:!s?.can().addRowBefore?.(),icon:"BetweenVerticalEnd",tooltip:t("editor.table.menu.insertRowAbove"),tooltipOptions:{sideOffset:15}}),!i("addRowBelow")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().addRowAfter().run()},disabled:!s?.can()?.addRowAfter?.(),icon:"BetweenVerticalStart",tooltip:t("editor.table.menu.insertRowBelow"),tooltipOptions:{sideOffset:15}}),!i("deleteRow")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteRow().run()},disabled:!s?.can()?.deleteRow?.(),icon:"DeleteRow",tooltip:t("editor.table.menu.deleteRow"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("mergeCells")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().mergeCells().run()},disabled:!s?.can()?.mergeCells?.(),icon:"TableCellsMerge",tooltip:t("editor.table.menu.mergeCells"),tooltipOptions:{sideOffset:15}}),!i("splitCells")&&(0,w.jsx)(n.f$2,{action:function(){s?.chain().focus().splitCell().run()},disabled:!s?.can()?.splitCell?.(),icon:"TableCellsSplit",tooltip:t("editor.table.menu.splitCells"),tooltipOptions:{sideOffset:15}}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("deleteTable")&&(0,w.jsx)(n.f$2,{action:function(){s.chain().focus().deleteTable().run()},disabled:!s?.can()?.deleteTable?.(),icon:"Trash2",tooltip:t("editor.table.menu.deleteTable"),tooltipOptions:{sideOffset:15}})]})}):(0,w.jsx)(w.Fragment,{})}function Ch(){const{t:e}=n._(),[t,r]=(0,x.useState)(!1),s=n.d$2(),i=(0,x.useMemo)(()=>n.a({t:e})?.[0]?.commands,[e]),o=(0,x.useMemo)(()=>i?.find(e=>e?.isActive?.(s))?.label,[s.state.selection.ranges,t,s,i,e]),l=(0,x.useMemo)(()=>i?.find(e=>e?.isActive?.(s)),[s.state.selection.ranges,t,s,i]);return(0,w.jsxs)(n.i$2,{modal:!0,onOpenChange:r,open:t,children:[(0,w.jsx)(n.o$1,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,w.jsx)(n.f$2,{dataState:!!o,tooltip:o||e("editor.paragraph.tooltip"),children:(0,w.jsx)(n.c,{name:l?.iconName||"Type"})})}),(0,w.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:i?.map(t=>{const i=t?.isActive?.(s);return(0,w.jsxs)("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-1.5 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:e=>{e.preventDefault(),t.action({editor:s,range:s.state.selection.ranges}),r(!1)},children:[(0,w.jsxs)("div",{className:"!richtext-min-w-[16px]",children:[i&&(0,w.jsx)(v.Check,{size:16}),!o&&t.label===e("editor.paragraph.tooltip")&&!i&&(0,w.jsx)(v.Check,{size:16})]}),(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[t.iconName&&(0,w.jsx)(n.c,{className:"!richtext-mr-1 !richtext-text-lg",name:t.iconName}),t.label]})]},t.name)})})]})}function Nh(){const e=n.d$2();return(t=e)&&"function"==typeof t.commands.openAiMenu?(0,w.jsx)(n.f$2,{action:()=>e.commands.openAiMenu(),shortcutKeys:["mod","J"],tooltip:"Ask AI",children:(0,w.jsx)(v.Sparkles,{className:"richtext-size-4 richtext-text-violet-600"})}):null;var t}function Eh(){return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Nh,{}),(0,w.jsx)(Ch,{}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.h$4,{}),(0,w.jsx)(n.y$1,{}),(0,w.jsx)(n.d$1,{}),(0,w.jsx)(n.m$1,{}),(0,w.jsx)(n.Be,{}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.h$3,{}),(0,w.jsx)(n.M$1,{}),(0,w.jsx)(n.A$1,{})]})}function Ah({buttonBubble:e}){const t=n.d$2();return n.m$2()?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleText",shouldShow:({editor:e})=>{const{selection:t}=e.view.state,{$from:n,to:r}=t;return!e.isActive("codeBlock")&&n.pos!==r&&"closed"===Se(e.view.state)?.panel.status&&t instanceof y.TextSelection},children:e?(0,w.jsx)(w.Fragment,{children:e}):(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(Eh,{})})}):(0,w.jsx)(w.Fragment,{})}function Th(){const{t:e}=n._(),t=n.m$2(),r=n.d$2(),[s,i]=(0,x.useState)(!1),o=(0,x.useCallback)(({editor:e})=>e.isActive(n.k.name),[]),l=(0,x.useCallback)(()=>Xd(n.k.name,r),[r]);return t?(0,w.jsx)(j.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:(0,w.jsx)(w.Fragment,{children:s?(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-4 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:(0,w.jsx)(n.T$1,{editor:r,onSetLink:e=>{r.commands.updateTweet({src:e}),i(!1)}})}):(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(n.f$2,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{i(!0)}}),(0,w.jsx)(n.f$2,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):(0,w.jsx)(w.Fragment,{})}function Mh(e){if(!e.length)return S.DecorationSet.empty;const t=[],n=e[0].$from.node(0);return e.forEach(e=>{const n=e.$from.pos,r=e.$from.nodeAfter;r&&t.push(S.Decoration.node(n,n+r.nodeSize,{class:"ProseMirror-selectednoderange"}))}),S.DecorationSet.create(n,t)}function _h(e,t,n,r={}){const s=[],i=e.node(0),{extendOnBoundaryOverlap:o=!0}=r;"number"==typeof n&&n>=0||(n=e.sameParent(t)?Math.max(0,e.sharedDepth(t.pos)-1):e.sharedDepth(t.pos));const l=new C.NodeRange(e,t,n),a=0===l.depth?0:i.resolve(l.start).posAtIndex(0);return l.parent.forEach((n,r)=>{const c=a+r,d=c+n.nodeSize,h=function(e,t,n){const r=n.isText||n.isAtom?0:1;return{start:e+r,end:e+t-r}}(c,n.nodeSize,n),u=o?t.pos>=h.start&&e.pos<=h.end:t.pos>h.start&&e.pos<h.end;if(c<l.start||c>=l.end)return;if(!u)return;const p=new y.SelectionRange(i.resolve(c),i.resolve(d));s.push(p)}),s}var Dh=class e{constructor(e,t,n){this.anchor=e,this.head=t,this.depth=null!=n?n:0}map(t){return new e(t.map(this.anchor),t.map(this.head),this.depth)}resolve(e){return new Oh(e.resolve(this.anchor),e.resolve(this.head),this.depth)}},Oh=class e extends y.Selection{constructor(e,t,n,r=1){const{doc:s}=e,i=e===t,o=e.pos===s.content.size&&t.pos===s.content.size,l=i&&!o?s.resolve(t.pos+(r>0?1:-1)):t,a=i&&o?s.resolve(e.pos-(r>0?1:-1)):e,c=_h(a.min(l),a.max(l),n);super(l.pos>=e.pos?c[0].$from:c[c.length-1].$to,l.pos>=e.pos?c[c.length-1].$to:c[0].$from,c),this.depth=n}get $to(){return this.ranges[this.ranges.length-1].$to}eq(t){return t instanceof e&&t.$from.pos===this.$from.pos&&t.$to.pos===this.$to.pos}map(t,n){const r=t.resolve(n.map(this.anchor)),s=t.resolve(n.map(this.head));return new e(r,s,this.depth)}toJSON(){return{type:"nodeRange",anchor:this.anchor,head:this.head,depth:this.depth}}get isForwards(){return this.head>=this.anchor}get isBackwards(){return!this.isForwards}extendBackwards(){const{doc:t}=this.$from;if(this.isForwards&&this.ranges.length>1){const t=this.ranges.slice(0,-1),n=t[0].$from,r=t[t.length-1].$to;return new e(n,r,this.depth)}const n=this.ranges[0],r=t.resolve(Math.max(0,n.$from.pos-1));return new e(this.$anchor,r,this.depth)}extendForwards(){const{doc:t}=this.$from;if(this.isBackwards&&this.ranges.length>1){const t=this.ranges.slice(1),n=t[0].$from,r=t[t.length-1].$to;return new e(r,n,this.depth)}const n=this.ranges[this.ranges.length-1],r=t.resolve(Math.min(t.content.size,n.$to.pos+1));return new e(this.$anchor,r,this.depth)}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head),n.depth)}static create(e,t,n,r,s=1){return new this(e.resolve(t),e.resolve(n),r,s)}getBookmark(){return new Dh(this.anchor,this.head,this.depth)}};Oh.prototype.visible=!1;try{y.Selection.jsonID("nodeRange",Oh)}catch{}function $h(e){return e instanceof Oh}b.Extension.create({name:"nodeRange",addOptions:()=>({depth:void 0,key:"Mod"}),addKeyboardShortcuts(){return{"Shift-ArrowUp":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,selection:i,tr:o}=r,{anchor:l,head:a}=i;if(!$h(i)){const e=Oh.create(s,l,a,t,-1);return o.setSelection(e),n.dispatch(o),!0}const c=i.extendBackwards();return o.setSelection(c),n.dispatch(o),!0},"Shift-ArrowDown":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,selection:i,tr:o}=r,{anchor:l,head:a}=i;if(!$h(i)){const e=Oh.create(s,l,a,t);return o.setSelection(e),n.dispatch(o),!0}const c=i.extendForwards();return o.setSelection(c),n.dispatch(o),!0},"Mod-a":({editor:e})=>{const{depth:t}=this.options,{view:n,state:r}=e,{doc:s,tr:i}=r,o=Oh.create(s,0,s.content.size,t);return i.setSelection(o),n.dispatch(i),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;$h(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new y.Plugin({key:new y.PluginKey("nodeRange"),props:{attributes:()=>e?{class:"ProseMirror-noderangeselection"}:{class:""},handleDOMEvents:{mousedown:(e,n)=>{const{key:r}=this.options,s=/Mac/.test(navigator.platform),i=!!n.shiftKey,o=!!n.ctrlKey,l=!!n.altKey,a=!!n.metaKey;return(null==r||"Shift"===r&&i||"Control"===r&&o||"Alt"===r&&l||"Meta"===r&&a||"Mod"===r&&(s?a:o))&&(t=!0),!!t&&(document.addEventListener("mouseup",()=>{t=!1;const{state:n}=e,{doc:r,selection:s,tr:i}=n,{$anchor:o,$head:l}=s;if(o.sameParent(l))return;const a=Oh.create(r,o.pos,l.pos,this.options.depth);i.setSelection(a),e.dispatch(i)},{once:!0}),!1)}},decorations:n=>{const{selection:r}=n,s=$h(r);if(e=!1,!t)return s?(e=!0,Mh(r.ranges)):null;const{$from:i,$to:o}=r;if(!s&&i.sameParent(o))return null;const l=_h(i,o,this.options.depth);return l.length?(e=!0,Mh(l)):null}}})]}});var Rh=[{id:"listItemFirstChild",evaluate:({parent:e,isFirst:t})=>t&&e&&["listItem","taskItem"].includes(e.type.name)?1e3:0},{id:"listWrapperDeprioritize",evaluate:({node:e})=>{const t=e.firstChild;return t&&["listItem","taskItem"].includes(t.type.name)?1e3:0}},{id:"tableStructure",evaluate:({node:e,parent:t})=>["tableRow","tableCell","tableHeader"].includes(e.type.name)||t&&"tableHeader"===t.type.name?1e3:0},{id:"inlineContent",evaluate:({node:e})=>e.isInline||e.isText?1e3:0}],Ih={edges:["left","top"],threshold:12,strength:500};function Ph(e){return void 0===e||"left"===e?{...Ih}:"right"===e?{edges:["right","top"],threshold:12,strength:500}:"both"===e?{edges:["left","right","top"],threshold:12,strength:500}:"none"===e?{edges:[],threshold:0,strength:0}:{...Ih,...e}}function Lh(e,t,n,r){let s=1e3,i=!1;if(t.every(t=>{const n=t.evaluate(e);return s-=n,!(s<=0&&(i=!0,1))}),i)return-1;const o=e.view.nodeDOM(e.pos);return s-=function(e,t,n,r){return t&&0!==n.edges.length&&function(e,t,n){if(0===n.edges.length)return!1;const r=t.getBoundingClientRect(),{threshold:s,edges:i}=n;return i.some(t=>"left"===t?e.x-r.left<s:"right"===t?r.right-e.x<s:"top"===t?e.y-r.top<s:"bottom"===t&&r.bottom-e.y<s)}(e,t,n)?n.strength*r:0}(r,o,n,e.depth),s<=0?-1:s}function zh(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function Bh(e){return Number.isFinite(e.top)&&Number.isFinite(e.bottom)&&Number.isFinite(e.left)&&Number.isFinite(e.right)&&e.width>0&&e.height>0}function Fh(e,t){let n="first"===t?e.firstElementChild:e.lastElementChild;for(;n;){const e=n.getBoundingClientRect();if(Bh(e))return e;n="first"===t?n.nextElementSibling:n.previousElementSibling}return null}var Vh=e=>{const{x:t,y:n,editor:r,nestedOptions:s}=e,{view:i,state:o}=r,l=function(e,t,n,r=5){if(!Number.isFinite(t)||!Number.isFinite(n))return null;const s=e.dom,i=Fh(s,"first"),o=Fh(s,"last");if(!i||!o)return null;const l=Math.min(Math.max(i.top+r,n),o.bottom-r),a=Math.abs(i.left-o.left)<.5,c=Math.abs(i.right-o.right)<.5;let d=i;a&&c&&(d=i);const h=Math.min(Math.max(d.left+r,t),d.right-r);return Number.isFinite(h)&&Number.isFinite(l)?{x:h,y:l}:null}(i,t,n,5);if(!l)return{resultElement:null,resultNode:null,pos:null};const{x:a,y:c}=l;if(null==s?void 0:s.enabled){const e=function(e,t,n){if(!Number.isFinite(t.x)||!Number.isFinite(t.y))return null;const r=e.posAtCoords({left:t.x,top:t.y});if(!r)return null;const{doc:s}=e.state,i=s.resolve(r.pos),o=[];n.defaultRules&&o.push(...Rh),o.push(...n.rules);const l=Array.from({length:i.depth},(e,t)=>i.depth-t).map(r=>{const s=i.node(r),l=i.before(r);if(n.allowedContainers&&r>0&&!zh(i,r,n.allowedContainers))return null;const a=r>0?i.node(r-1):null,c=r>0?i.index(r-1):0,d=Lh({node:s,pos:l,depth:r,parent:a,index:c,isFirst:0===c,isLast:c===(a?a.childCount:1)-1,$pos:i,view:e},o,n.edgeDetection,t);return d<0?null:{node:s,pos:l,depth:r,score:d,dom:e.nodeDOM(l)}}).filter(e=>null!==e),a=i.nodeAfter;if(a&&a.isAtom&&!a.isInline){const s=r.pos,c=i.depth+1,d=i.parent,h=i.index(),u=d.childCount;let p=!0;if(n.allowedContainers&&(p=zh(i,c,n.allowedContainers)),p){const r=Lh({node:a,pos:s,depth:c,parent:d,index:h,isFirst:0===h,isLast:h===u-1,$pos:i,view:e},o,n.edgeDetection,t);if(r>=0){const t=e.nodeDOM(s);t&&l.push({node:a,pos:s,depth:c,score:r,dom:t})}}}if(0===l.length)return null;l.sort((e,t)=>t.score!==e.score?t.score-e.score:t.depth-e.depth);const c=l[0];return c.dom?{node:c.node,pos:c.pos,dom:c.dom}:null}(i,{x:a,y:c},s);return e?{resultElement:e.dom,resultNode:e.node,pos:e.pos}:{resultElement:null,resultNode:null,pos:null}}const d=i.root.elementsFromPoint(a,c);let h,u;if(Array.prototype.some.call(d,e=>{if(!i.dom.contains(e))return!1;const t=function(e,t){var n;let r=e;for(;(null==r?void 0:r.parentElement)&&r.parentElement!==t.dom;)r=r.parentElement;if((null==r?void 0:r.parentElement)===t.dom&&(null==(n=r.pmViewDesc)?void 0:n.node))return r}(e,i);return!!t&&(h=t,!0)}),!h){const e=i.posAtCoords({left:a,top:c});if(e){const t=o.doc.resolve(e.pos),n=Math.min(t.depth,1),r=n>0?t.before(n):t.pos,s=o.doc.nodeAt(r);if(s){const e=i.nodeDOM(r);return{resultElement:e instanceof HTMLElement?e:null,resultNode:s,pos:r}}}return{resultElement:null,resultNode:null,pos:null}}try{u=i.posAtDOM(h,0)}catch{return{resultElement:null,resultNode:null,pos:null}}const p=o.doc.nodeAt(u);if(!p){const e=o.doc.resolve(u),t=e.parent;return{resultElement:h,resultNode:t,pos:e.start()}}return{resultElement:h,resultNode:p,pos:u}};function Wh(e,t){const n=e.nodeDOM(t);if(n instanceof Element&&n!==e.dom)return n;const{node:r,offset:s}=e.domAtPos(t),i=r.childNodes[s];return i instanceof Element?i:r instanceof Element?r:r.nodeType===Node.TEXT_NODE&&r.parentElement?r.parentElement:null}function qh(e){var t;null==(t=e.parentNode)||t.removeChild(e)}function Hh(e,t,n,r,s){const{view:i}=t;if(!e.dataTransfer)return;const{empty:o,$from:l,$to:a}=i.state.selection,c=function(e,t,n,r){const{doc:s}=t.view.state;if((null==n?void 0:n.enabled)&&(null==r?void 0:r.node)&&r.pos>=0){const e=r.pos,t=r.pos+r.node.nodeSize;return[{$from:s.resolve(e),$to:s.resolve(t)}]}const i=Vh({editor:t,x:e.clientX,y:e.clientY,direction:"right",nestedOptions:n});if(!i.resultNode||null===i.pos)return[];const o=i.resultNode.isText||i.resultNode.isAtom?0:-1;return _h(s.resolve(i.pos),s.resolve(i.pos+i.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}(e,t,n,r),d=_h(l,a,0,{extendOnBoundaryOverlap:!1}),h=d.some(e=>c.find(t=>t.$from===e.$from&&t.$to===e.$to)),u=o||!h?c:d;if(!u.length)return;const{tr:p}=i.state,m=document.createElement("div"),f=u[0].$from.pos,g=u[u.length-1].$to.pos,x=function(e,t){const n=Wh(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}(i,f);m.setAttribute("dir",x);const b=(null==n?void 0:n.enabled)&&(null==r?void 0:r.node),w=1===u.length;let v,k;b&&w?(v=i.state.doc.slice(f,g),k=y.NodeSelection.create(i.state.doc,f)):(k=Oh.create(i.state.doc,f,g),v=k.content());const j=function(e){return!e||!e.some(e=>{const t=e.trim().toLowerCase();return"margin"===t||t.startsWith("margin-")})}(s);u.forEach(e=>{const t=Wh(i,e.$from.pos);if(!t)return;const n=function(e,t){const n=e.cloneNode(!0),r=[e,...Array.from(e.getElementsByTagName("*"))],s=[n,...Array.from(n.getElementsByTagName("*"))];return r.forEach((e,n)=>{s[n].style.cssText=function(e,t){const n=getComputedStyle(e);if(t)return t.map(e=>e.trim()).filter(e=>e.length>0).map(e=>`${e}:${n.getPropertyValue(e)};`).join("");let r="";for(let s=0;s<n.length;s+=1)r+=`${n[s]}:${n.getPropertyValue(n[s])};`;return r}(e,t)}),n}(t,s);j&&(n.style.margin="0"),m.append(n)}),m.style.position="absolute",m.style.top="-10000px",document.body.append(m),e.dataTransfer.clearData();const S=function(e,t){return"rtl"===e?t:0}(x,m.getBoundingClientRect().width);e.dataTransfer.setDragImage(m,S,0);let C=!1;const N=()=>{C||(C=!0,qh(m),document.removeEventListener("drop",N),document.removeEventListener("dragend",N))},E=k instanceof y.NodeSelection?k:void 0;i.dragging={slice:v,move:!0,node:E},p.setSelection(k),i.dispatch(p),document.addEventListener("drop",N),document.addEventListener("dragend",N)}var Uh=(e,t)=>{const n=e.resolve(t),{depth:r}=n;return 0===r?t:n.pos-n.parentOffset-1},Jh=(e,t)=>{const n=e.nodeAt(t),r=e.resolve(t);let{depth:s}=r,i=n;for(;s>0;){const e=r.node(s);s-=1,0===s&&(i=e)}return i};function Kh(e,t,n){let r=0;for(let s=t;s<n;s+=1)r+=e.child(s).nodeSize;return r}var Gh=(e,t)=>{const n=ld.getState(e);return n?zd(t,n.type,n.binding.mapping):null},Xh=(e,t)=>{const n=ld.getState(e);return n?Fd(n.doc,n.type,t,n.binding.mapping)||0:-1},Yh=(e,t)=>{let n=t;for(;(null==n?void 0:n.parentNode)&&n.parentNode!==e.dom;)n=n.parentNode;return n},Zh=new y.PluginKey("dragHandle"),Qh=({pluginKey:e=Zh,element:t,editor:r,computePositionConfig:s,getReferencedVirtualElement:i,onNodeChange:o,onElementDragStart:l,onElementDragEnd:a,nestedOptions:c,dragImageProperties:d})=>{const h=document.createElement("div");let u,p=!1,m=null,f=-1,g=null,x=null,w=null,v=null;function k(){w=null,v=null}function j(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function S(e){const r=(null==i?void 0:i())||{getBoundingClientRect:()=>e.getBoundingClientRect()};n.xt(r,t,s).then(e=>{Object.assign(t.style,{position:e.strategy,left:`${e.x}px`,top:`${e.y}px`})})}function C(e){var n,s;l?.(e),Hh(e,r,c,{node:m,pos:f},d),n=r.state.selection,w=$h(n)?{anchorPos:n.from,nodeCount:n.ranges.length,depth:null!=(s=n.depth)?s:0}:null,t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function N(e){a?.(e),w=null,j(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function E(e){if(!e.target||!r.view.dom.contains(e.target))return;if((0,b.isFirefox)()){const e=r.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable="false",e.contentEditable="true")})}if(!w||r.view.state.selection.empty)return;const t=r.state.selection.from,n=Gh(r.state,t);v={...w,anchorPos:t,relativeAnchorPos:null!=n?n:void 0},r.view.dispatch(r.state.tr.setMeta("addToHistory",!1))}function A(){t.removeEventListener("dragstart",C),t.removeEventListener("dragend",N),document.removeEventListener("drop",E),g&&(cancelAnimationFrame(g),g=null,x=null),k()}return h.appendChild(t),{unbind(){A()},plugin:new y.Plugin({key:"string"==typeof e?new y.PluginKey(e):e,state:{init:()=>({locked:!1}),apply(e,n,s,i){!function(e,t){v&&(v=function(e,t,n){if(!t.docChanged)return e;if(n.isChangeOrigin&&null!=e.relativeAnchorPos){const t=n.getAbsolutePos(e.relativeAnchorPos);return!Number.isFinite(t)||t<=0?null:{...e,anchorPos:t}}const r=t.mapping.mapResult(e.anchorPos,1);return r.deleted?null:{...e,anchorPos:r.pos}}(v,e,{isChangeOrigin:Ud(e),getAbsolutePos:e=>Xh(t,e)}))}(e,i);const l=e.getMeta("lockDragHandle"),a=e.getMeta("hideDragHandle");if(void 0!==l&&(p=l),a)return j(),p=!1,m=null,f=-1,o?.({editor:r,node:null,pos:-1}),n;if(e.docChanged&&-1!==f&&t)if(Ud(e)){const e=Xh(i,u);e!==f&&(f=e)}else{const t=e.mapping.map(f);t!==f&&(f=t,u=Gh(i,f))}return n}},appendTransaction:(e,t,n)=>function(e){if(!v)return null;const t=function(e,t,n,r){try{const s=function(e,t,n,r){const s=e.resolve(t),i=s.node(r);let o=s.index(r);o>=i.childCount&&(o=Math.max(0,i.childCount-n));const l=Math.min(n,i.childCount-o);if(l<=0)return null;const a=s.start(r)+Kh(i,0,o);return{anchor:a,head:a+Kh(i,o,o+l),count:l}}(e,t,n,r);if(!s)return null;const i=Oh.create(e,s.anchor,s.head,r);return i.ranges.length===n?i:null}catch{return null}}(e.doc,v.anchorPos,v.nodeCount,v.depth);return t?(k(),e.tr.setSelection(t)):(v=null,w=null,null)}(n),view:e=>{var n;return t.draggable=!0,t.style.pointerEvents="auto",t.dataset.dragging="false",null==(n=r.view.dom.parentElement)||n.appendChild(h),h.style.pointerEvents="none",h.style.position="absolute",h.style.top="0",h.style.left="0",h.style.zIndex="10",t.addEventListener("dragstart",C),t.addEventListener("dragend",N),document.addEventListener("drop",E),{update(n,s){if(!t)return;if(!r.isEditable)return void j();if(t.draggable=!p,e.state.doc.eq(s.doc)||-1===f)return;let i=e.nodeDOM(f);if(i=Yh(e,i),i===e.dom)return;if(1!==(null==i?void 0:i.nodeType))return;const l=e.posAtDOM(i,0),a=Jh(r.state.doc,l),c=Uh(r.state.doc,l);m=a,f=c,u=Gh(e.state,f),o?.({editor:r,node:m,pos:f}),S(i)},destroy(){A(),t&&qh(h)}}},props:{handleDOMEvents:{keydown:e=>!(!t||p||!e.hasFocus()||(j(),m=null,f=-1,o?.({editor:r,node:null,pos:-1}),1)),mouseleave:(e,t)=>(p||t.target&&!h.contains(t.relatedTarget)&&(j(),m=null,f=-1,o?.({editor:r,node:null,pos:-1})),!1),mousemove:(e,n)=>!(!t||p||(x={x:n.clientX,y:n.clientY},g||(g=requestAnimationFrame(()=>{if(g=null,!x)return;const{x:n,y:s}=x;x=null;const i=Vh({x:n,y:s,direction:"right",editor:r,nestedOptions:c});if(!i.resultElement)return;let l=i.resultElement,a=i.resultNode,d=i.pos;if(!(null==c?void 0:c.enabled)){if(l=Yh(e,l),l===e.dom)return;if(1!==(null==l?void 0:l.nodeType))return;const t=e.posAtDOM(l,0);a=Jh(r.state.doc,t),d=Uh(r.state.doc,t)}a!==m&&(m=a,f=null!=d?d:-1,u=Gh(e.state,f),o?.({editor:r,node:m,pos:f}),S(l),t&&(r.isEditable?(t.style.visibility="",t.style.pointerEvents="auto"):j()))})),1))}}})}};function eu(e){var t,n;return!1===e||void 0===e?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ph("none")}:!0===e?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ph("left")}:{enabled:!0,rules:null!=(t=e.rules)?t:[],defaultRules:null==(n=e.defaultRules)||n,allowedContainers:e.allowedContainers,edgeDetection:Ph(e.edgeDetection)}}var tu={placement:"left-start",strategy:"absolute"},nu=(b.Extension.create({name:"dragHandle",addOptions:()=>({render(){const e=document.createElement("div");return e.classList.add("drag-handle"),e},computePositionConfig:{},locked:!1,onNodeChange:()=>null,onElementDragStart:void 0,onElementDragEnd:void 0,nested:!1,dragImageProperties:void 0}),addCommands(){return{lockDragHandle:()=>({editor:e})=>(this.options.locked=!0,e.commands.setMeta("lockDragHandle",this.options.locked)),unlockDragHandle:()=>({editor:e})=>(this.options.locked=!1,e.commands.setMeta("lockDragHandle",this.options.locked)),toggleDragHandle:()=>({editor:e})=>(this.options.locked=!this.options.locked,e.commands.setMeta("lockDragHandle",this.options.locked))}},addProseMirrorPlugins(){const e=this.options.render(),t=eu(this.options.nested);return[Qh({computePositionConfig:{...tu,...this.options.computePositionConfig},getReferencedVirtualElement:this.options.getReferencedVirtualElement,element:e,editor:this.editor,onNodeChange:this.options.onNodeChange,onElementDragStart:this.options.onElementDragStart,onElementDragEnd:this.options.onElementDragEnd,nestedOptions:t,dragImageProperties:this.options.dragImageProperties}).plugin]}}),e=>{const{className:t="drag-handle",children:n,editor:r,pluginKey:s=Zh,onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a,computePositionConfig:c=tu,nested:d=!1}=e,h=(0,x.useRef)(null);null===h.current&&"undefined"!=typeof document&&(h.current=document.createElement("div"));const u=(0,x.useMemo)(()=>eu(d),[JSON.stringify(d)]);(0,x.useEffect)(()=>{const e=h.current;e&&(e.className=t)},[t]),(0,x.useEffect)(()=>{if("undefined"==typeof document)return;if(r.isDestroyed)return;const e=h.current;if(!e)return;e.style.visibility="hidden",e.style.position="absolute",e.dataset.dragging="false";const{plugin:t,unbind:n}=Qh({editor:r,element:e,pluginKey:s,computePositionConfig:{...tu,...c},onElementDragStart:o,onElementDragEnd:l,onNodeChange:i,getReferencedVirtualElement:a,nestedOptions:u});return r.registerPlugin(t),()=>{r.isDestroyed||r.unregisterPlugin(s),n()}},[r,i,a,s,c,o,l,u]);const p=h.current;return p?(0,k.createPortal)(n,p):null});function ru(){const e=n.d$2(),t=n.m$2(),{t:r}=n._(),[s,i]=(0,x.useState)(null),[o,l]=(0,x.useState)(-1),[a,c]=(0,x.useState)(!1),d=e?.extensionManager?.extensions?.some(e=>e?.name===n.y.name),h=e?.extensionManager?.extensions?.some(e=>e?.name===n.h$2.name),u=e?.extensionManager?.extensions?.some(e=>e?.name===n.c$1.name);function p(t){e.commands.setTextAlign(t)}const m=(0,x.useCallback)(e=>{e.node&&i(e.node),l(e.pos),requestAnimationFrame(()=>{e.editor.commands.focus()})},[]);(0,x.useEffect)(()=>(a?e.commands.setMeta("lockDragHandle",!0):e.commands.setMeta("lockDragHandle",!1),()=>{e.commands.setMeta("lockDragHandle",!1)}),[a]);const f=e=>{t&&c(e)};return(0,w.jsx)(nu,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:m,pluginKey:"RichTextBubbleMenuDragHandle",children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,w.jsx)(n.f$2,{disabled:!t,icon:"Grip",tooltip:r("editor.draghandle.grip"),action:e=>{e.preventDefault(),e.stopPropagation(),f(!a)}}),(0,w.jsxs)(n.h$5,{onOpenChange:f,open:a,children:[(0,w.jsx)(n.x,{className:"richtext-pointer-events-none"}),(0,w.jsxs)(n.u$2,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3 richtext-bg-opacity-10 hover:richtext-bg-red-400 hover:richtext-bg-opacity-20 focus:richtext-bg-red-400 focus:richtext-bg-opacity-30 focus:richtext-text-red-500 dark:hover:richtext-bg-opacity-20 dark:hover:richtext-text-red-500",onClick:function(){e.chain().setMeta("hideDragHandle",!0).setNodeSelection(o).deleteSelection().run()},children:[(0,w.jsx)(n.c,{name:"Trash2"}),(0,w.jsx)("span",{children:r("editor.remove")})]}),u?(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:function(){const t=e.chain();t.setNodeSelection(o).unsetAllMarks(),"paragraph"!==s?.type.name&&t.setParagraph(),t.run()},children:[(0,w.jsx)(n.c,{name:"PaintRoller"}),(0,w.jsx)("span",{children:r("editor.clear.tooltip")})]}):null,(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:function(){e.commands.setNodeSelection(o);const{$anchor:t}=e.state.selection,n=t.node(1)||e.state.selection.node;e.chain().setMeta("hideDragHandle",!0).insertContentAt(o+(s?.nodeSize||0),n.toJSON()).run()},children:[(0,w.jsx)(n.c,{name:"Copy"}),(0,w.jsx)("span",{children:r("editor.copy")})]}),d||h?(0,w.jsx)(n.y$3,{}):null,d?(0,w.jsxs)(n.l$1,{children:[(0,w.jsxs)(n.p$2,{className:"richtext-flex richtext-gap-3",children:[(0,w.jsx)(n.c,{name:"AlignCenter"}),(0,w.jsx)("span",{children:r("editor.textalign.tooltip")})]}),(0,w.jsx)(n.n$5,{children:(0,w.jsxs)(n.f$1,{children:[(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("left"),children:[(0,w.jsx)(n.c,{name:"AlignLeft"}),(0,w.jsx)("span",{children:r("editor.textalign.left.tooltip")})]}),(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("center"),children:[(0,w.jsx)(n.c,{name:"AlignCenter"}),(0,w.jsx)("span",{children:r("editor.textalign.center.tooltip")})]}),(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("right"),children:[(0,w.jsx)(n.c,{name:"AlignRight"}),(0,w.jsx)("span",{children:r("editor.textalign.right.tooltip")})]})]})})]}):null,h?(0,w.jsxs)(n.l$1,{children:[(0,w.jsxs)(n.p$2,{className:"richtext-flex richtext-gap-3",children:[(0,w.jsx)(n.c,{name:"IndentIncrease"}),(0,w.jsx)("span",{children:r("editor.indent")})]}),(0,w.jsx)(n.n$5,{children:(0,w.jsxs)(n.f$1,{children:[(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",disabled:s?.attrs?.indent>=n.u.max,onClick:function(){const t=n.p(e.state.tr,o,1);t.setMeta("hideDragHandle",!0),e.view.dispatch&&e.view.dispatch(t)},children:[(0,w.jsx)(n.c,{name:"IndentIncrease"}),(0,w.jsx)("span",{children:r("editor.indent.tooltip")})]}),(0,w.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",disabled:s?.attrs?.indent<=n.u.min,onClick:function(){const t=n.p(e.state.tr,o,-1);e.view.dispatch&&e.view.dispatch(t)},children:[(0,w.jsx)(n.c,{name:"IndentDecrease"}),(0,w.jsx)("span",{children:r("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}var su={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function iu({listLanguages:e}){const{t:t}=n._(),[r,s]=(0,x.useState)(!1),i=n.d$2(),o=(0,x.useMemo)(()=>{const{selection:e}=i.state,t=e.$from.parent;if("codeBlock"===t.type.name){const e=t.attrs.language||"plaintext";return su[e]||e}},[i.state,e]),l=(0,x.useMemo)(()=>{let t=e||[];return e?.includes("plaintext")||(t=["plaintext",...t]),t.map(e=>({label:su[e]||e,value:e}))},[e]);return(0,w.jsxs)(n.i$2,{modal:!0,onOpenChange:s,open:r,children:[(0,w.jsx)(n.o$1,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,w.jsxs)(n.f$2,{dataState:!!o,children:[(0,w.jsx)(w.Fragment,o?{children:o}:{children:t("editor.paragraph.tooltip")}),(0,w.jsx)(n.c,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),(0,w.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:l?.map(e=>(0,w.jsxs)("div",{className:"richtext-flex richtext-w-full richtext-items-center richtext-gap-3 richtext-rounded-sm !richtext-border-none !richtext-bg-transparent richtext-px-2 richtext-py-1.5 richtext-text-left richtext-text-sm richtext-text-foreground !richtext-outline-none richtext-transition-colors hover:!richtext-bg-accent",onClick:t=>{t.preventDefault(),i.chain().focus().setCodeBlock({language:e.value}).run(),s(!1)},children:[(0,w.jsx)("div",{className:"!richtext-min-w-[20px]",children:o===e.value&&(0,w.jsx)(v.Check,{size:16})}),(0,w.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:e.label})]},e.value))})]})}function ou(){const e=n.m$2(),t=n.d$2(),r=n.v(n.M$2.name),s=(0,x.useCallback)(({editor:e})=>e.isActive(n.M$2.name),[]),i=(0,x.useMemo)(()=>r?r.options?.lowlight?.listLanguages?.()||["plaintext","html","css","js","ts"]:[],[r]),o=(0,x.useCallback)(()=>Xd(n.M$2.name,t),[t]);return e?(0,w.jsx)(j.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleCodeBlock",shouldShow:s,getReferencedVirtualElement:()=>{const{from:e}=t.state.selection,n=t.view.domAtPos(e).node.parentElement;return n?{getBoundingClientRect:()=>n.getBoundingClientRect()}:null},children:(0,w.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-2 richtext-rounded-md !richtext-border !richtext-border-solid !richtext-border-border richtext-bg-popover richtext-p-1 richtext-text-popover-foreground richtext-shadow-md richtext-outline-none",children:[(0,w.jsx)(iu,{listLanguages:i}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.f$2,{action:()=>{const e=(()=>{const{from:e}=t.state.selection,n=t.state.doc.resolve(e);for(let t=n.depth;t>=0;t--){const e=n.node(t);if("codeBlock"===e.type.name)return e.textContent}return""})();navigator.clipboard.writeText(e)},tooltip:"Copy",children:(0,w.jsx)(v.Copy,{size:16})}),(0,w.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,w.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,w.jsx)(v.Trash2,{size:16})})]})}):(0,w.jsx)(w.Fragment,{})}var lu=()=>(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Zd,{}),(0,w.jsx)(Qd,{}),(0,w.jsx)(hh,{}),(0,w.jsx)(ph,{}),(0,w.jsx)(fh,{}),(0,w.jsx)(xh,{}),(0,w.jsx)(yh,{}),(0,w.jsx)(bh,{}),(0,w.jsx)(jh,{}),(0,w.jsx)(Sh,{}),(0,w.jsx)(Ah,{}),(0,w.jsx)(Th,{}),(0,w.jsx)(ou,{}),(0,w.jsx)(ru,{}),(0,w.jsx)(n.D,{}),(0,w.jsx)(V,{})]});Object.defineProperty(exports,"BubbleMenus",{enumerable:!0,get:function(){return lu}}),Object.defineProperty(exports,"RichTextToolbar",{enumerable:!0,get:function(){return ae}});
|