react-reason-editor 1.0.166 → 1.0.168

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.
@@ -1 +1 @@
1
- const e=require("./rolldown-runtime-BeavJI0R.cjs"),t=require("./dist-2-kjLBhJ.cjs"),n=require("./editorConfig-BJeXCimT.cjs"),r=require("./toggle-JU5XOZYT.cjs"),s=require("./locales-mNtGplJd.cjs"),i=require("./floating-ui.dom-DG-jWCyc.cjs"),o=require("./useButtonProps-DbMOdE1Q.cjs"),l=require("./theme.cjs"),a=require("./Ai-DVWZg0-D.cjs"),c=require("./Harper-C3DvE8Ft.cjs"),d=require("./Drawio-CoTNWfCf.cjs"),h=require("./ReadAloud.cjs"),u=require("./Transcribe.cjs"),p=require("./SelectSimilar.cjs"),m=require("./WordCount.cjs");let f=require("@tiptap/react"),g=require("react");g=e.__toESM(g,1);let x=require("@tiptap/core"),b=require("@tiptap/pm/state"),y=require("react/jsx-runtime"),v=require("lucide-react"),w=require("react-dom"),k=require("@tiptap/react/menus"),S=require("@tiptap/pm/view"),j=require("@tiptap/pm/model"),C=require("use-voice-control/react"),N=require("easydrawer"),E=require("@tiptap/pm/commands"),A=require("use-voice-control/client");function T({children:e,label:n,className:r,icon:s,shortcut:i}){const o=(0,g.useRef)(null),l=(0,g.isValidElement)(e)?(0,g.cloneElement)(e,{tooltip:n?void 0:e.props?.tooltip,tooltipOptions:n?void 0:e.props?.tooltipOptions}):e;return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:s}),(0,y.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[l,n&&(0,y.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:n}),i&&(0,y.jsx)("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 ml-auto whitespace-nowrap shrink-0",children:i})]})]})}function M(){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,y.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,y.jsx)(y.Fragment,{})}function _(){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,y.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,y.jsx)(y.Fragment,{})}function D({message:e}){const[t,n]=(0,g.useState)(!0);return(0,g.useEffect)(()=>{const e=setTimeout(()=>n(!1),2e3);return()=>clearTimeout(e)},[]),t?(0,w.createPortal)((0,y.jsx)("div",{className:"fixed bottom-4 right-4 z-[100] animate-in fade-in slide-in-from-bottom-2",children:(0,y.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 O(){const{editor:e}=(0,f.useCurrentEditor)(),[t,n]=(0,g.useState)(1.25),[r,s]=(0,g.useState)(null),i=e=>{s(e)},o=(0,g.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,g.useEffect)(()=>{o(t)},[o,t]),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,y.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,y.jsx)(v.ZoomOut,{size:16})}),(0,y.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,y.jsx)(v.ZoomIn,{size:16})})]}),r&&(0,y.jsx)(D,{message:r})]})}var $={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 R(){const{editor:e}=(0,f.useCurrentEditor)(),[t,n]=(0,g.useState)(!1),[r,s]=(0,g.useState)("page"),[i,o]=(0,g.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,g.useRef)(null),a=(0,g.useRef)(null),[c,d]=(0,g.useState)({top:0,left:-9999,visibility:"hidden"});if((0,g.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,g.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,y.jsxs)("div",{className:"relative",ref:l,children:[(0,y.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,y.jsx)(v.Settings,{className:"w-4 h-4"}),(0,y.jsx)(v.ChevronDown,{className:"w-3 h-3"})]}),t&&(0,w.createPortal)((0,y.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,y.jsx)("div",{className:"flex border-b dark:border-gray-700 shrink-0",children:["page","spacing","header-footer"].map(e=>(0,y.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,y.jsxs)("div",{className:"flex-1 min-h-0 p-4 space-y-4 overflow-y-auto",children:["page"===r&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-2 text-gray-700 dark:text-gray-300",children:"Presets"}),(0,y.jsx)("div",{className:"grid grid-cols-4 gap-2",children:Object.entries($).map(([e,t])=>(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Height (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Width (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Gap (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Gap Border Color"}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.jsx)("input",{type:"color",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"w-10 h-9 rounded cursor-pointer"}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Page Margins (px)"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Left"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Right"}),(0,y.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,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Content Margins (px)"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Header Left (supports HTML)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.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,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Footer Left (supports HTML)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.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,y.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 I=[1,2,3,4];function P({editor:e,onClose:t,defaultLevel:n=3}){const[r,s]=(0,g.useState)([]),[i,o]=(0,g.useState)(""),[l,a]=(0,g.useState)(n),[c,d]=(0,g.useState)(null);(0,g.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,g.useMemo)(()=>{const e=i.trim().toLowerCase();return r.filter(t=>t.level<=l&&(""===e||t.text.toLowerCase().includes(e)))},[r,i,l]),u=(0,g.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,w.createPortal)((0,y.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,y.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)(v.ListTree,{size:15,className:"text-blue-500"}),(0,y.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:"Table of Contents"})]}),(0,y.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,y.jsx)(v.X,{size:14})})]}),(0,y.jsxs)("div",{className:"border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,y.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,y.jsx)(v.Search,{size:13,className:"shrink-0 text-gray-400"}),(0,y.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,y.jsx)("button",{onClick:()=>o(""),className:"shrink-0 text-gray-400 hover:text-gray-600",title:"Clear filter",children:(0,y.jsx)(v.X,{size:12})})]}),(0,y.jsxs)("div",{className:"mt-2 flex items-center gap-1",children:[(0,y.jsx)("span",{className:"mr-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400",children:"Level"}),I.map(e=>(0,y.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,y.jsx)("nav",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:0===h.length?(0,y.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,y.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 L({editor:e,className:n}){const[r,s]=(0,g.useState)(null),i=(0,g.useRef)(null),o=(0,g.useCallback)(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),l=(0,g.useCallback)(()=>{o(),i.current=setTimeout(()=>s(null),120)},[o]),a=(0,g.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,g.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,y.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,y.jsx)("div",{className:"harper-tooltip-header",children:(0,y.jsx)("span",{className:"harper-tooltip-kind",children:d.kind})}),(0,y.jsx)("p",{className:"harper-tooltip-message",children:d.message}),(0,y.jsxs)("div",{className:"harper-tooltip-actions",children:[0===d.suggestions.length?(0,y.jsx)("span",{className:"harper-tooltip-empty",children:"No suggestions"}):d.suggestions.map((t,n)=>(0,y.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,y.jsx)("button",{type:"button",className:"harper-tooltip-ignore",onClick:()=>{e.chain().focus().ignoreHarperSuggestion(d.id).run(),s(null)},children:"Ignore"})]})]})}var z={status:"closed"};function B({icon:e,label:t,onClick:n,disabled:r,title:s}){return(0,y.jsxs)("button",{type:"button",disabled:r,onClick:n,title:s,className:"ai-menu-row",children:[(0,y.jsx)(e,{className:"ai-menu-row-icon"}),t]})}function F(){const e=o.useEditorInstance(),t=o.useEditableEditor(),n=(0,g.useRef)(null),r=(0,g.useRef)(null),[s,l]=(0,g.useState)(""),[c,d]=(0,g.useState)(-1),[h,u]=(0,g.useState)(null),[p,m]=(0,g.useState)(!1),[x,b]=(0,g.useState)(null),k=(0,f.useEditorState)({editor:e,selector:({editor:e})=>e?a.getAiState(e.state)?.panel??z:z}),S=(0,g.useMemo)(()=>"closed"===k.status?null:"reviewing"===k.status?{from:k.suggestion.from,to:k.suggestion.to}:{from:k.from,to:k.to},[k]),j="closed"!==k.status,C=!!S&&S.to>S.from,N=S?S.to-S.from:0,E=e?a.getAiOptions(e)?.commands??[]:[],A=s.trim().toLowerCase(),T=(0,g.useMemo)(()=>{const e=a.commandsForSelection(E,C);return A?e.filter(e=>`${e.label} ${e.description??""}`.toLowerCase().includes(A)):e},[E,A,C]),M=(0,g.useMemo)(()=>a.groupCommands(T),[T]);if((0,g.useEffect)(()=>{if("menu"===k.status){const e=requestAnimationFrame(()=>r.current?.focus());return()=>cancelAnimationFrame(e)}"closed"===k.status&&(l(""),u(null),d(-1),m(!1))},[k.status]),(0,g.useEffect)(()=>{d(e=>e>=T.length?T.length-1:e)},[T.length]),(0,g.useEffect)(()=>{if(!e||!S||!n.current)return void b(null);const t={getBoundingClientRect:()=>(0,f.posToDOMRect)(e.view,S.from,S.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,S?.from,S?.to,k]),(0,g.useEffect)(()=>{if(!j||!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=a.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)}},[j,e,h]),!(t&&e&&j&&x))return null;const _=t=>{t.options?.length?u(t):e.commands.runAiCommand(t.id)};return(0,w.createPortal)((0,y.jsxs)("div",{ref:n,role:"dialog","aria-label":"Ask AI",className:"ai-menu",style:{position:"fixed",top:x.y,left:x.x,zIndex:60},children:[(0,y.jsxs)("div",{className:"ai-menu-input-row",children:[(0,y.jsx)(v.Sparkles,{className:"ai-menu-input-icon"}),(0,y.jsx)("input",{ref:r,value:s,onChange:e=>{l(e.target.value),d(e.target.value.trim()?0:-1)},onKeyDown:t=>{if("ArrowDown"===t.key)return t.preventDefault(),void d(e=>T.length?(e+1)%T.length:-1);if("ArrowUp"===t.key)return t.preventDefault(),void d(e=>T.length?e<=0?T.length-1:e-1:-1);if("Enter"===t.key){t.preventDefault();const n=c>=0?T[c]: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"===k.status&&h&&(0,y.jsxs)("div",{className:"ai-menu-commands",children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>u(null),children:[(0,y.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),h.label]}),h.options?.map(t=>(0,y.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>{u(null),e.commands.runAiCommand(h.id,t.label)},children:(0,y.jsx)("span",{className:"ai-menu-command-text",children:(0,y.jsx)("span",{className:"ai-menu-command-label",children:t.label})})},t.id))]}),"menu"===k.status&&!h&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"ai-menu-hint",children:C?`${N.toLocaleString()} characters selected`:"Nothing selected — select text for rewrite actions"}),(0,y.jsxs)("div",{className:"ai-menu-commands",children:[0===M.length&&(0,y.jsx)("div",{className:"ai-menu-empty",children:"No matching actions"}),M.map(e=>(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"ai-menu-group-label",children:a.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>{const t=T.indexOf(e);return(0,y.jsxs)("button",{type:"button","data-active":t===c?"true":void 0,onMouseEnter:()=>d(t),onClick:()=>_(e),className:"ai-menu-command",children:[(0,y.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,y.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,y.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id)})]},e.group))]})]}),"loading"===k.status&&(0,y.jsxs)("div",{className:"ai-menu-loading",children:[(0,y.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,y.jsx)("span",{className:"ai-menu-loading-label",children:"Custom"===k.commandLabel?"Generating…":`${k.commandLabel}…`}),(0,y.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,y.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}),"error"===k.status&&(0,y.jsxs)("div",{className:"ai-menu-error",children:[(0,y.jsx)("p",{className:"ai-menu-error-message",children:k.message}),(0,y.jsxs)("div",{className:"ai-menu-review",children:[(0,y.jsx)(B,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,y.jsx)(B,{icon:v.X,label:"Dismiss",onClick:()=>e.commands.closeAiMenu()})]})]}),"reviewing"===k.status&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"ai-menu-preview","aria-live":"polite",children:k.suggestion.suggestedText||"…"}),k.suggestion.isStreaming?(0,y.jsxs)("div",{className:"ai-menu-loading",children:[(0,y.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,y.jsxs)("span",{className:"ai-menu-loading-label",children:[k.commandLabel,"…"]}),(0,y.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,y.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}):(0,y.jsxs)("div",{className:"ai-menu-review",children:[(0,y.jsx)(B,{icon:v.Check,label:"replace"===k.suggestion.mode?"Replace selection":"Insert",title:"⌘/Ctrl + Enter",onClick:()=>e.commands.acceptAiSuggestion()}),(0,y.jsx)(B,{icon:v.CornerDownRight,label:"Insert below",onClick:()=>e.commands.insertAiSuggestionBelow()}),(0,y.jsx)(B,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,y.jsx)(B,{icon:v.Copy,label:p?"Copied":"Copy",onClick:()=>(async e=>{try{await navigator.clipboard.writeText(e),m(!0),setTimeout(()=>m(!1),1500)}catch{}})(k.suggestion.suggestedText)}),(0,y.jsx)(B,{icon:v.X,label:"Discard",onClick:()=>e.commands.discardAiSuggestion()})]})]})]}),document.body)}function V({editor:e,label:t="AI"}){const{editor:n}=o.useTiptapEditor(e),r=(0,g.useRef)(null),s=(0,g.useRef)(null),[l,c]=(0,g.useState)(!1),[d,h]=(0,g.useState)(null),[u,p]=(0,g.useState)(null),{hasSelection:m,isBusy:x}=(0,f.useEditorState)({editor:n,selector:({editor:e})=>{if(!e)return{hasSelection:!1,isBusy:!1};const t=a.getAiState(e.state)?.panel.status;return{hasSelection:!e.state.selection.empty,isBusy:"loading"===t||"reviewing"===t}}})??{hasSelection:!1,isBusy:!1},b=n?a.getAiOptions(n)?.commands??[]:[],k=(0,g.useMemo)(()=>a.groupCommands(a.commandsForSelection(b,m)),[b,m]);if((0,g.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,k.length,d]),(0,g.useEffect)(()=>{if(!l)return h(null),void p(null);const e=e=>{const t=e.target;s.current?.contains(t)||r.current?.contains(t)||c(!1)},t=e=>{"Escape"===e.key&&c(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l]),!a.isAiEnabled(n))return null;const S=(e,t)=>{!e.options?.length||t?(c(!1),n?.chain().focus().run(),n?.commands.runAiCommand(e.id,t)):h(e)};return(0,y.jsxs)(y.Fragment,{children:[(0,y.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:()=>c(e=>!e),children:[x?(0,y.jsx)(v.Loader2,{className:"ai-toolbar-icon ai-menu-spin"}):(0,y.jsx)(v.Sparkles,{className:"ai-toolbar-icon"}),t&&(0,y.jsx)("span",{className:"ai-toolbar-label",children:t}),(0,y.jsx)(v.ChevronDown,{className:"ai-toolbar-chevron"})]}),l&&(0,w.createPortal)((0,y.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:d?(0,y.jsxs)("div",{className:"ai-menu-commands",children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>h(null),children:[(0,y.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),d.label]}),d.options?.map(e=>(0,y.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>S(d,e.label),children:(0,y.jsx)("span",{className:"ai-menu-command-text",children:(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label})})},e.id))]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-command ai-menu-ask",onClick:()=>{c(!1),n?.chain().focus().run(),n?.commands.openAiMenu()},children:[(0,y.jsx)(v.Sparkles,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:"Ask AI anything…"}),(0,y.jsx)("span",{className:"ai-menu-command-description",children:"Write your own instruction"})]}),(0,y.jsx)("span",{className:"ai-menu-command-shortcut",children:"⌘J"})]}),(0,y.jsx)("div",{className:"ai-menu-hint",children:m?"Runs on the selected text":"Select text to rewrite it, or generate from the caret"}),(0,y.jsx)("div",{className:"ai-menu-commands",children:k.map(e=>(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"ai-menu-group-label",children:a.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>(0,y.jsxs)("button",{type:"button",className:"ai-menu-command",onClick:()=>S(e),children:[(0,y.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,y.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,y.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id))]},e.group))})]})}),document.body)]})}var W={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 q(e){const t=(0,g.useCallback)(t=>e?u.subscribeTranscribe(e,t):()=>{},[e]);if("none"===(0,g.useSyncExternalStore)(t,()=>{const t=e?u.getTranscribeStorage(e):void 0;return t?`${t.listening}|${t.phraseId}|${t.error?.message??""}`:"none"},()=>"none")||!e)return H;const n=u.getTranscribeStorage(e);return n?{available:!0,isListening:n.listening,partial:n.partial,lastPhrase:n.lastPhrase,phraseId:n.phraseId,error:n.error}:H}function U({editor:e,durationMs:t=2e3}){const{isListening:n,lastPhrase:r,phraseId:s}=q(e);return(0,y.jsx)(C.SpokenPhraseOverlay,{durationMs:t,phrase:r,phraseId:s,visible:n})}var J=[".dropdown-container",".dropdown-portal","[data-richtext-portal]","[data-radix-popper-content-wrapper]","[data-radix-portal]",'[role="dialog"]','[role="menu"]','[role="listbox"]'].join(",");var K="rte-custom-styles",G="rte-custom-style-presets",X="rte-active-style-preset";function Y(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 Z(e){const t=(0,g.useRef)(!1);return{onMouseDown:e=>{t.current=e.target===e.currentTarget},onClick:n=>{t.current&&n.target===n.currentTarget&&(t.current=!1,e())}}}function Q({onClose:e}){const[t,n]=(0,g.useState)(()=>{try{const e=localStorage.getItem(G);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,g.useState)(()=>{try{return localStorage.getItem(X)||t[0]?.id||"1"}catch{return"1"}}),[i,o]=(0,g.useState)(null),[l,a]=(0,g.useState)(""),c=t.find(e=>e.id===r)||t[0],[d,h]=(0,g.useState)(c?.rules||[]),u=(0,g.useRef)(d.length?Math.max(...d.map(e=>e.id),0)+1:1),p=e=>{let t=document.getElementById(K);t||(t=document.createElement("style"),t.id=K,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(X,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(G,JSON.stringify(s)),a(""),m(r.id)},x=(e,r)=>{if(!r.trim())return;const s=t.map(t=>t.id===e?{...t,name:r}:t);n(s),localStorage.setItem(G,JSON.stringify(s)),o(null)},b=(e,t,n)=>h(r=>r.map(r=>r.id===e?{...r,[t]:n}:r)),k=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...k}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)(v.Paintbrush,{size:16,className:"text-blue-500"}),(0,y.jsx)("span",{className:"text-sm font-semibold",children:"Customize Editor Styles"})]}),(0,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:14})})]}),(0,y.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 dark:border-slate-700 space-y-2",children:[(0,y.jsx)("div",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Style Presets"}),(0,y.jsx)("div",{className:"flex gap-2 flex-wrap",children:t.map(e=>(0,y.jsxs)("div",{className:"flex items-center gap-1",children:[(0,y.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,y.jsx)("input",{autoFocus:!0,type:"text",value:l,onChange:e=>a(e.target.value),onBlur:()=>x(e.id,l),onKeyDown:t=>"Enter"===t.key&&x(e.id,l),className:"w-20 px-1 py-0.5 text-xs bg-transparent border-b border-current outline-none"}):(0,y.jsx)("span",{onDoubleClick:()=>{o(e.id),a(e.name)},children:e.name})}),t.length>1&&(0,y.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(G,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,y.jsx)(v.X,{size:12})})]},e.id))}),t.length<10&&(0,y.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,y.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,y.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,y.jsx)(v.Plus,{size:12}),"Add"]})]})]}),(0,y.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,y.jsx)("code",{className:"bg-gray-100 dark:bg-slate-800 px-1 rounded",children:".ProseMirror"})," elements."]}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-4 space-y-2",children:[0===d.length&&(0,y.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,y.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,y.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,y.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,y.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,y.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,y.jsx)(v.Trash2,{size:13})})]},e.id))]}),(0,y.jsxs)("div",{className:"px-4 py-3 border-t border-gray-100 dark:border-slate-700 flex items-center justify-between",children:[(0,y.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,y.jsx)(v.Plus,{size:12}),"Add Rule"]}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.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,y.jsx)("button",{onClick:()=>{const e=t.map(e=>e.id===r?{...e,rules:[...d]}:e);n(e),localStorage.setItem(G,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 ee({children:e,label:t,shortcut:n,icon:r,displayIcon:s}){const i=(0,g.useRef)(null);return(0,y.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,y.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,y.jsx)("span",{className:"flex-1 text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,y.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n}),(0,y.jsx)("span",{className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0,children:e}),(0,y.jsx)("span",{className:"hidden",children:e})]})}function te({icon:e,label:t,shortcut:n,onClick:r,disabled:s}){return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,y.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,y.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n})]})}function ne({icon:e,label:t,checked:n,onChange:r}){return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,y.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),(0,y.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,y.jsx)(v.Check,{size:12,strokeWidth:3})})]})}function re({children:e,label:t,name:n,active:r,onClick:s}){return(0,y.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,y.jsx)(v.ChevronDown,{size:10,className:"opacity-40 mt-0.5"})]})}function se({top:e,left:t,right:n,className:r="",children:s}){const i=(0,g.useRef)(null),[o,l]=(0,g.useState)({top:e,left:-9999,visibility:"hidden"});return(0,g.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,y.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:Y,ref:i,style:o,children:s})}function ie({onClose:e,documentTitle:t,editor:n,initialTab:r="info"}){const[s,i]=(0,g.useState)(r),[o,l]=(0,g.useState)(()=>m.getWordCountStats(n));(0,g.useEffect)(()=>{if(!n)return;const e=()=>l(m.getWordCountStats(n));return e(),n.on("update",e),()=>{n.off("update",e)}},[n]);const{createdDate:a,modifiedDate:c}=(0,g.useMemo)(()=>({createdDate:new Date(Date.now()-2592e6),modifiedDate:new Date}),[]),[d,h]=(0,g.useState)(""),[u,p]=(0,g.useState)("viewer"),[f,x]=(0,g.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()&&(f.sharedWith.find(e=>e.email===d)?alert("Already shared with this email"):(x(e=>({...e,sharedWith:[...e.sharedWith,{email:d,role:u,sharedAt:(new Date).toISOString()}]})),h("")))},k=e=>{switch(e){case"editor":return(0,y.jsx)(v.Edit3,{size:14});case"commentor":return(0,y.jsx)(v.MessageSquare,{size:14});case"viewer":return(0,y.jsx)(v.Eye,{size:14});default:return null}},S=[{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}],j=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=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...C}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,y.jsx)(v.FileText,{size:18,className:"text-blue-500 shrink-0"}),(0,y.jsxs)("div",{className:"min-w-0",children:[(0,y.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white truncate",children:t}),(0,y.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,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:16})})]}),(0,y.jsx)("div",{className:"px-6 pt-3",children:(0,y.jsxs)("div",{className:"inline-flex gap-1 p-1 rounded-lg bg-gray-100 dark:bg-slate-800",children:[(0,y.jsx)("button",{className:j("info"),onClick:()=>i("info"),type:"button",children:"Info & word count"}),(0,y.jsx)("button",{className:j("share"),onClick:()=>i("share"),type:"button",children:"Sharing"})]})}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("info"===s?"":"hidden"),children:[(0,y.jsxs)("div",{className:"space-y-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Document Name"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white break-words",children:t})]}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Created"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:a.toLocaleDateString()})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Last Modified"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:c.toLocaleDateString()})]})]}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Access"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:f.isPublic?"Public":"Private"})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Shared with"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:1===f.sharedWith.length?"1 person":`${f.sharedWith.length} people`})]})]})]}),(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("h3",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400",children:"Word Count"}),(0,y.jsx)("table",{className:"w-full text-sm",children:(0,y.jsx)("tbody",{children:S.map(e=>(0,y.jsxs)("tr",{className:"border-b border-gray-100 dark:border-slate-700 last:border-b-0",children:[(0,y.jsx)("td",{className:"py-1.5 pr-2 text-gray-500 dark:text-gray-400",children:e.label}),(0,y.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,y.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,y.jsx)(v.Share2,{size:14}),"Manage sharing"]})]}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("share"===s?"":"hidden"),children:[(0,y.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,y.jsxs)("div",{className:"flex items-center gap-3",children:[f.isPublic?(0,y.jsx)(v.Globe,{size:18,className:"text-blue-500"}):(0,y.jsx)(v.Lock,{size:18,className:"text-gray-400"}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:f.isPublic?"Public":"Private"}),(0,y.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:f.isPublic?"Anyone with link can view":"Only invited people can access"})]})]}),(0,y.jsxs)("div",{className:"flex items-center gap-3",children:[f.isPublic&&f.shareLink&&(0,y.jsx)("button",{onClick:()=>{f.shareLink&&(navigator.clipboard.writeText(f.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,y.jsx)("button",{onClick:()=>{x(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 "+(f.isPublic?"bg-blue-500":"bg-gray-300 dark:bg-slate-700"),children:(0,y.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition "+(f.isPublic?"translate-x-6":"translate-x-1")})})]})]}),(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Add people"}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.jsxs)("div",{className:"relative flex-1",children:[(0,y.jsx)(v.Mail,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),(0,y.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,y.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,y.jsx)("option",{value:"viewer",children:"Viewer"}),(0,y.jsx)("option",{value:"commentor",children:"Commentor"}),(0,y.jsx)("option",{value:"editor",children:"Editor"})]}),(0,y.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,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"People with access"}),(0,y.jsx)("div",{className:"space-y-1 max-h-[280px] overflow-y-auto",children:f.sharedWith.length>0?f.sharedWith.map(e=>(0,y.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,y.jsxs)("div",{className:"flex items-center gap-3 flex-1",children:[(0,y.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,y.jsxs)("div",{className:"min-w-0",children:[(0,y.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.email}),(0,y.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Added ",new Date(e.sharedAt).toLocaleDateString()]})]})]}),(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:k(e.role)}),(0,y.jsxs)("select",{value:e.role,onChange:t=>{return n=e.email,r=t.target.value,void x(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,y.jsx)("option",{value:"viewer",children:"Viewer"}),(0,y.jsx)("option",{value:"commentor",children:"Commentor"}),(0,y.jsx)("option",{value:"editor",children:"Editor"})]}),(0,y.jsx)("button",{onClick:()=>{return t=e.email,void x(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,y.jsx)(v.X,{size:14})})]})]},e.email)):(0,y.jsxs)("div",{className:"text-center py-8",children:[(0,y.jsx)(v.Users,{size:24,className:"mx-auto text-gray-300 mb-2 opacity-50"}),(0,y.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No one else has access yet"})]})})]})]})]})]}),document.body)}function oe({onClose:e,currentName:t}){const[n,r]=(0,g.useState)(t),s=()=>{n.trim()&&n!==t&&alert(`File renamed to: ${n}`),e()},i=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...i}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white",children:"Rename document"}),(0,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:16})})]}),(0,y.jsx)("div",{className:"p-6 space-y-4",children:(0,y.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,y.jsxs)("div",{className:"flex gap-2 px-6 py-4 border-t border-gray-100 dark:border-slate-700 justify-end",children:[(0,y.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,y.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 le=({theme:e,setTheme:t,onOpenSettings:r,onAddComment:i,commentDisabled:o,showComments:a,onToggleComments:c,commentCount:u})=>{const[m,x]=(0,g.useState)(null),[b,k]=(0,g.useState)(null),[S,j]=(0,g.useState)(!1),[C,N]=(0,g.useState)(!1),[E,D]=(0,g.useState)(!1),[$,I]=(0,g.useState)(!1),[z,B]=(0,g.useState)(null),F=!!r,H=(0,g.useRef)(null),Z=s.useLocale(),{editor:le}=(0,f.useCurrentEditor)(),ae="Untitled Document",ce=!!le?.extensionManager.extensions.some(e=>"harper"===e.name);(0,g.useEffect)(()=>{le&&ce&&(E?le.chain().focus().runProofing().run():le.commands.clearProofing())},[E,le,ce]);const de=function(e){const t=(0,g.useCallback)(t=>e?h.subscribeReadAloud(e,t):()=>{},[e]);if("none"===(0,g.useSyncExternalStore)(t,()=>{const t=e?h.getReadAloudStorage(e):void 0;return t?`${t.state}|${t.currentChunk?.index??-1}|${t.error?.message??""}`:"none"},()=>"none")||!e)return W;const n=h.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}:W}(le??null),he=q(le??null),ue=le&&!le.state.selection.empty?"selection":"document",pe=!!le&&h.getReadAloudText(le).length>0,me=!!le?.extensionManager.extensions.some(e=>"PaginationPlus"===e.name),[fe,ge]=(0,g.useState)(!0);(0,g.useEffect)(()=>{if(!le||!me)return;const e=le.storage?.PaginationPlus?.enabled;"boolean"==typeof e&&ge(e)},[le,me]);const xe=(0,g.useCallback)(e=>{le&&(e?le.commands.enablePagination?.():le.commands.disablePagination?.(),ge(e))},[le]),be=(0,g.useCallback)(()=>{le?.chain().focus().run(),document.execCommand("cut")},[le]),ye=(0,g.useCallback)(()=>{le?.chain().focus().run(),document.execCommand("copy")},[le]),ve=(0,g.useCallback)(async()=>{le?.chain().focus().run();try{const e=await navigator.clipboard.readText();le?.commands.insertContent(e)}catch{document.execCommand("paste")}},[le]),we=(0,g.useCallback)(async()=>{le?.chain().focus().run();try{const e=await navigator.clipboard.readText();le?.chain().focus().insertContent(e,{parseOptions:{preserveWhitespace:!0}}).run()}catch{document.execCommand("paste")}},[le]),ke=(0,g.useCallback)(()=>{le?.commands.deleteSelection()},[le]),Se=(0,g.useCallback)(()=>{le?.chain().focus().selectAll().run()},[le]),je=!!le?.extensionManager.extensions.some(e=>"selectSimilar"===e.name),[Ce,Ne]=(0,g.useState)(0);(0,g.useEffect)(()=>{if(!le||!je)return;const e=()=>Ne(p.selectSimilarPluginKey.getState(le.state)?.ranges.length??0);return e(),le.on("transaction",e),()=>{le.off("transaction",e)}},[le,je]);const Ee=(0,g.useCallback)(e=>{le?.chain().focus().selectSimilar(e).run()},[le]),Ae=(0,g.useCallback)(()=>{le?.chain().focus().clearSimilarSelection().run()},[le]);(0,g.useEffect)(()=>{try{const e=localStorage.getItem(X),t=JSON.parse(localStorage.getItem(G)||"[]");if(t.length>0){const n=t.find(t=>t.id===e)||t[0];if(n&&n.rules.length>0){let e=document.getElementById(K);e||(e=document.createElement("style"),e.id=K,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(m===e)return x(null),void k(null);const n=t.currentTarget.getBoundingClientRect();k({top:n.bottom+4,left:n.left}),x(e)},Me=()=>{x(null),k(null)};return(0,g.useEffect)(()=>{if(!m)return;const e=e=>{(function(e,t=document){const n=e;return!!n?.isConnected&&!n.closest(J)&&!t.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')})(e.target)&&Me()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[m]),(0,y.jsxs)(y.Fragment,{children:[(0,y.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:Y,children:[(0,y.jsx)(n.Z,{hideWhenDisabled:!0}),(0,y.jsx)(n.$$2,{hideWhenDisabled:!0}),(0,y.jsx)("div",{className:"border-l border-gray-200 dark:border-slate-700 mx-0.5 px-0.5",children:(0,y.jsx)(O,{})}),(0,y.jsx)(n.F$1,{}),(0,y.jsx)(n.y$2,{}),(0,y.jsx)(n.h$4,{}),(0,y.jsx)(n.y$1,{}),(0,y.jsx)(n.d$1,{}),(0,y.jsx)(n.M$1,{}),(0,y.jsx)(V,{}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"block",label:"Block Format",active:"block"===m,onClick:Te,children:(0,y.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,y.jsx)("line",{x1:"2",y1:"4",x2:"14",y2:"4"}),(0,y.jsx)("line",{x1:"2",y1:"8",x2:"11",y2:"8"}),(0,y.jsx)("line",{x1:"2",y1:"12",x2:"8",y2:"12"})]})}),"block"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H1",label:"Heading 1",shortcut:"Ctrl+Alt+1",children:(0,y.jsx)(n.$$1,{level:1})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H2",label:"Heading 2",shortcut:"Ctrl+Alt+2",children:(0,y.jsx)(n.$$1,{level:2})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H3",label:"Heading 3",shortcut:"Ctrl+Alt+3",children:(0,y.jsx)(n.$$1,{level:3})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H4",label:"Heading 4",shortcut:"Ctrl+Alt+4",children:(0,y.jsx)(n.$$1,{level:4})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H5",label:"Heading 5",shortcut:"Ctrl+Alt+5",children:(0,y.jsx)(n.$$1,{level:5})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H6",label:"Heading 6",shortcut:"Ctrl+Alt+6",children:(0,y.jsx)(n.$$1,{level:6})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Bullet List",shortcut:"Ctrl+Shift+8",children:(0,y.jsx)(n.r$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Ordered List",shortcut:"Ctrl+Shift+7",children:(0,y.jsx)(n.n$4,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Check List",shortcut:"Ctrl+Shift+9",children:(0,y.jsx)(n.r,{})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Blockquote",shortcut:"Ctrl+Shift+B",children:(0,y.jsx)(n.m$2,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Code Block",shortcut:"Ctrl+Alt+C",children:(0,y.jsx)(n.k$2,{})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-1",children:(0,y.jsx)(T,{label:"Clear Format",children:(0,y.jsx)(n.n$3,{})})}),(0,y.jsxs)("button",{onClick:()=>{Me(),j(!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,y.jsx)(v.Paintbrush,{size:14,className:"text-gray-400 shrink-0"}),"Customize default styles…"]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"textstyles",label:"Text Styles",active:"textstyles"===m,onClick:Te,children:(0,y.jsx)("span",{className:"text-sm font-mono",children:"Tt"})}),"textstyles"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Text Styles"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Strikethrough",shortcut:"Ctrl+Shift+S",children:(0,y.jsx)(n.u$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Inline Code",shortcut:"Ctrl+E",children:(0,y.jsx)(n.m$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Text Color",shortcut:"Alt+Shift+C",children:(0,y.jsx)(n.h$3,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Superscript",shortcut:"Ctrl+.",children:(0,y.jsx)(_,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Subscript",shortcut:"Ctrl+,",children:(0,y.jsx)(M,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Indent",children:(0,y.jsx)(n.l$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Line Spacing",children:(0,y.jsx)(n.f,{})})}),(0,y.jsx)("div",{className:"col-span-2",children:(0,y.jsx)(T,{label:"Alignment",children:(0,y.jsx)(n.A$1,{})})})]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"insert",label:"Insert",active:"insert"===m,onClick:Te,children:(0,y.jsx)(v.Plus,{size:16})}),"insert"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[300px]",left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Insert"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Link",children:(0,y.jsx)(n.Be,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Emoji",children:(0,y.jsx)(n.ne,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Table",children:(0,y.jsx)(n.st,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Image",children:(0,y.jsx)(n.te,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Meme",children:(0,y.jsx)(n.T$3,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Document",children:(0,y.jsx)(n.E,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Columns",shortcut:"Ctrl+Alt+G",children:(0,y.jsx)(n.b,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Callout",children:(0,y.jsx)(n.F,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Twitter",children:(0,y.jsx)(n.N,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Divider",shortcut:"Ctrl+Alt+S",children:(0,y.jsx)(n.h,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Video",children:(0,y.jsx)(n.M,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Math",children:(0,y.jsx)(n.Dt,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Flowchart",children:(0,y.jsx)(n.P,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Drawio",children:(0,y.jsx)(d.RichTextDrawio,{})})}),i&&(0,y.jsx)("div",{children:(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:(0,y.jsx)(v.MessageSquarePlus,{size:14})}),(0,y.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:"Comment"})]})})]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"edit",label:"Edit",active:"edit"===m,onClick:Te,children:(0,y.jsx)(v.Clipboard,{size:16})}),"edit"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Clipboard"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Scissors,{size:14}),label:"Cut",shortcut:"Ctrl+X",onClick:()=>{Me(),be()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Clipboard,{size:14}),label:"Copy",shortcut:"Ctrl+C",onClick:()=>{Me(),ye()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.ClipboardPaste,{size:14}),label:"Paste",shortcut:"Ctrl+V",onClick:()=>{Me(),ve()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.ClipboardType,{size:14}),label:"Paste Plain",shortcut:"Ctrl+Shift+V",onClick:()=>{Me(),we()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Trash2,{size:14}),label:"Delete",shortcut:"Del",onClick:()=>{Me(),ke()}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Selection"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.TextCursorInput,{size:14}),label:"Select All",shortcut:"Ctrl+A",onClick:()=>{Me(),Se()}}),je&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(te,{icon:(0,y.jsx)(v.Type,{size:14}),label:"Select All Similar Fonts",onClick:()=>{Me(),Ee("font")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Palette,{size:14}),label:"Select All Similar Styles",onClick:()=>{Me(),Ee("style")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.TextSelect,{size:14}),label:"Select All Similar Formatting",onClick:()=>{Me(),Ee("formatting")}}),(0,y.jsx)(te,{disabled:0===Ce,icon:(0,y.jsx)(v.X,{size:14}),label:Ce?`Clear Multi-Selection (${Ce})`:"Clear Multi-Selection",shortcut:"Esc",onClick:()=>{Me(),Ae()}}),(0,y.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,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"tools",label:"Tools",active:"tools"===m,onClick:Te,children:(0,y.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,y.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"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Document"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.FileText,{size:14}),label:"Document info & word count",onClick:()=>{Me(),B("info")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Share2,{size:14}),label:"Share",onClick:()=>{Me(),B("share")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Edit3,{size:14}),label:"Rename",onClick:()=>{Me(),I(!0)}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Copy,{size:14}),label:"Make a copy",onClick:()=>{Me(),alert("Document copied to your drive")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Download,{size:14}),label:"Download",onClick:()=>{Me(),alert("Downloading document...")}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Tools"}),c&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.MessageSquare,{size:14}),label:u?`Comments Panel (${u})`:"Comments Panel",checked:!!a,onChange:()=>c()}),c&&(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(T,{label:"Find / Replace",children:(0,y.jsx)(n.I,{})}),(0,y.jsx)(T,{label:"View Source",children:(0,y.jsx)(n.n,{})}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(ne,{icon:(0,y.jsx)(v.ListTree,{size:14}),label:"Table of Contents",checked:C,onChange:N}),ce&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.SpellCheck,{size:14}),label:"Spelling & Grammar",checked:E,onChange:D}),(de.available||he.available)&&(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),de.available&&(0,y.jsx)(te,{disabled:!de.isActive&&!pe,icon:de.isActive?(0,y.jsx)(v.VolumeX,{size:14}):(0,y.jsx)(v.Volume2,{size:14}),label:de.isActive?"Stop reading":"selection"===ue?"Read selection aloud":"Read document aloud",shortcut:"Ctrl+Shift+S",onClick:()=>{Me(),le?.commands.toggleReadAloud()}}),he.available&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.Mic,{size:14}),label:(0,A.isTranscriptionSupported)()?he.isListening?"Dictating — click to stop":"Dictate into the document":"Dictation unavailable in this browser",checked:he.isListening,onChange:()=>{(0,A.isTranscriptionSupported)()&&le?.commands.toggleTranscribe()}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),me&&(0,y.jsx)(ne,{icon:fe?(0,y.jsx)(v.File,{size:14}):(0,y.jsx)(v.Globe,{size:14}),label:fe?"Page Layout: A4":"Page Layout: Web",checked:fe,onChange:xe}),(0,y.jsx)(T,{label:"Page Settings",shortcut:"Ctrl+Shift+P",children:(0,y.jsx)(R,{})}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(T,{label:"Import Word",children:(0,y.jsx)(n.Zh,{})}),(0,y.jsx)(T,{label:"Export Word",children:(0,y.jsx)(n.d,{})}),(0,y.jsx)(T,{label:"Export PDF",children:(0,y.jsx)(n.a$1,{})})]}),document.body)]}),(0,y.jsxs)("div",{className:"ml-auto dropdown-container",children:[(0,y.jsx)("button",{ref:H,title:"Settings",onClick:e=>{F?(x(null),k(null),r()):((e,t)=>{if(m===e)return x(null),void k(null);const n=t.currentTarget.getBoundingClientRect();k({top:n.bottom+4,left:n.left,right:window.innerWidth-n.right}),x(e)})("settings",e)},className:"flex items-center gap-0.5 p-1.5 rounded transition-colors "+("settings"===m?"bg-gray-200 dark:bg-slate-700":"text-gray-500 hover:bg-gray-100 dark:hover:bg-slate-800"),children:(0,y.jsx)(v.Settings,{size:16})}),!F&&"settings"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"w-[260px] px-2 py-2 shadow-2xl",right:b.right,top:b.top,children:[(0,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Theme"}),(0,y.jsxs)("div",{className:"flex gap-1 mb-2 px-1",children:[(0,y.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,y.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,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Accent Color"}),(0,y.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,y.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,y.jsx)("div",{className:"border-t border-gray-100 dark:border-slate-700 my-1"}),(0,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Language"}),(0,y.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,y.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 "+(Z.lang===e?"bg-blue-500/20 border-blue-500":""),children:[t," ",n]},e))})]}),document.body)]})]}),S&&(0,y.jsx)(Q,{onClose:()=>j(!1)}),C&&le&&(0,y.jsx)(P,{editor:le,onClose:()=>N(!1)}),ce&&E&&le&&(0,y.jsx)(L,{editor:le}),he.available&&(0,y.jsx)(U,{editor:le??null}),$&&(0,y.jsx)(oe,{onClose:()=>I(!1),currentName:ae}),z&&(0,y.jsx)(ie,{documentTitle:ae,editor:le,initialTab:z,onClose:()=>B(null)})]})},ae=[{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."}],ce=[/^#{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],de=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function he(e){return n.ye.parse(e,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function ue(e){const t=e.trim();return t?function(e){return function(e){return ce.some(t=>t.test(e))||de.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}(t)?{content:he(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}var pe=["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 me(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}function fe(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 ge=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 fe(35,n)}return s},xe=/^(?: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,be=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,ye=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,ve=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function we(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(xe,"");return t!==e?t:e.replace(be,"")}(n),n=function(e){if(!ye.test(e))return e;const t=e.replace(ye,"").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 ke=new b.PluginKey("ai");function Se(e){return ke.getState(e)}function je(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 Ce(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 Ne(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=function(e,t){return t<=0?"":e.length<=t?e:`…${e.slice(e.length-t)}`}(i,Math.floor(r/2)),a=o.length>r-l.length?`${o.slice(0,r-l.length)}…`:o;return`${l}${l&&a?"\n":""}${a}`.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(ke,{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=we(t,{streaming:o});e.view.dispatch(e.view.state.tr.setMeta(ke,{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(!we(o))return void e.view.dispatch(e.view.state.tr.setMeta(ke,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:"The model returned an empty response."}));p(o,!1)}catch(Ie){if(h.signal.aborted||u!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(ke,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:Ie instanceof Error?Ie.message:"Something went wrong."}))}}x.Extension.create({name:"ai",addOptions:()=>({commands:ae,getCompletion:ge,systemPrompt:pe,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(ke,{type:"open-menu",from:r,to:s})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(ke,{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(ke,{type:"settle"}));else{const{from:e,to:s}=je(r,t.selection);n(t.tr.setMeta(ke,{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}=je(Se(n)?.panel??{status:"closed"},n.selection);return!(!1!==s.requiresSelection&&i===o||s.options?.length&&!t||(Ne(r,this.options,this.storage,{instruction:me(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}=je(Se(t)?.panel??{status:"closed"},t.selection);return Ne(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&&(Ne(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}=ue(o);return!!l&&(e(),n().insertContentAt({from:s,to:i},l,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(ke,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(ke,{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}=ue(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(ke,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new b.Plugin({key:ke,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(ke);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:Ce(t.doc,r,e),lastRequest:s}}},props:{decorations(e){return this.getState(e)?.decorations??S.DecorationSet.empty}}})]}});var Ee=()=>new Map,Ae=e=>{const t=Ee();return e.forEach((e,n)=>{t.set(n,e)}),t},Te=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},Me=()=>new Set,_e=e=>e[e.length-1],De=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Oe=Array.from,$e=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Re=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ie=Array.isArray,Pe=class{constructor(){this._observers=Ee()}on(e,t){return Te(this._observers,e,Me).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 Oe((this._observers.get(e)||Ee()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ee()}},Le=Math.floor,ze=Math.abs,Be=(e,t)=>e<t?e:t,Fe=(e,t)=>e>t?e:t,Ve=(Number.isNaN,e=>0!==e?e<0:1/e<0),We=Number.MAX_SAFE_INTEGER,He=Number.MIN_SAFE_INTEGER,qe=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&Le(e)===e),Ue=(Number.isNaN,Number.parseInt,String.fromCharCode),Je=(String.fromCodePoint,Ue(65535),/^\s*/g),Ke=/([A-Z])/g,Ge=(e,t)=>(e=>e.replace(Je,""))(e.replace(Ke,e=>`${t}${(e=>e.toLowerCase())(e)}`)),Xe="undefined"!=typeof TextEncoder?new TextEncoder:null,Ye=Xe?e=>Xe.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},Ze="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ze&&1===Ze.decode(new Uint8Array).length&&(Ze=null);var Qe,et,tt,nt,rt=(e,t)=>((e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t();return n})(t,()=>e).join(""),st=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},it=()=>new st,ot=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},lt=(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},at=lt,ct=(e,t)=>{for(;t>127;)lt(e,128|127&t),t=Le(t/128);lt(e,127&t)},dt=(e,t)=>{const n=Ve(t);for(n&&(t=-t),lt(e,(t>63?128:0)|(n?64:0)|63&t),t=Le(t/64);t>0;)lt(e,(t>127?128:0)|127&t),t=Le(t/128)},ht=new Uint8Array(3e4),ut=ht.length/3,pt=Xe&&Xe.encodeInto?(e,t)=>{if(t.length<ut){const n=Xe.encodeInto(t,ht).written||0;ct(e,n);for(let t=0;t<n;t++)lt(e,ht[t])}else ft(e,Ye(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;ct(e,r);for(let s=0;s<r;s++)lt(e,n.codePointAt(s))},mt=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=Be(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(Fe(2*n,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},ft=(e,t)=>{ct(e,t.byteLength),mt(e,t)},gt=(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*Fe(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},xt=new DataView(new ArrayBuffer(4)),bt=(e,t)=>{switch(typeof t){case"string":lt(e,119),pt(e,t);break;case"number":qe(t)&&ze(t)<=2147483647?(lt(e,125),dt(e,t)):(n=t,xt.setFloat32(0,n),xt.getFloat32(0)===n?(lt(e,124),((e,t)=>{gt(e,4).setFloat32(0,t,!1)})(e,t)):(lt(e,123),((e,t)=>{gt(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":lt(e,122),((e,t)=>{gt(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)lt(e,126);else if(Ie(t)){lt(e,117),ct(e,t.length);for(let n=0;n<t.length;n++)bt(e,t[n])}else if(t instanceof Uint8Array)lt(e,116),ft(e,t);else{lt(e,118);const n=Object.keys(t);ct(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];pt(e,s),bt(e,t[s])}}break;case"boolean":lt(e,t?120:121);break;default:lt(e,127)}var n},yt=class extends st{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ct(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},vt=e=>{e.count>0&&(dt(e.encoder,1===e.count?e.s:-e.s),e.count>1&&ct(e.encoder,e.count-2))},wt=class{constructor(){this.encoder=new st,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),ot(this.encoder)}},kt=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);dt(e.encoder,t),e.count>1&&ct(e.encoder,e.count-2)}},St=class{constructor(){this.encoder=new st,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(kt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return kt(this),ot(this.encoder)}},jt=class{constructor(){this.sarr=[],this.s="",this.lensE=new wt}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 st;return this.sarr.push(this.s),this.s="",pt(e,this.sarr.join("")),mt(e,this.lensE.toUint8Array()),ot(e)}},Ct=e=>new Error(e),Nt=()=>{throw Ct("Method unimplemented")},Et=()=>{throw Ct("Unexpected case")},At=Ct("Unexpected end of array"),Tt=Ct("Integer out of Range"),Mt=class{constructor(e){this.arr=e,this.pos=0}},_t=e=>new Mt(e),Dt=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,$t(e)),Ot=e=>e.arr[e.pos++],$t=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>We)throw Tt}throw At},Rt=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>We)throw Tt}throw At},It=Ze?e=>Ze.decode(Dt(e)):e=>{let t=$t(e);if(0===t)return"";{let n=String.fromCodePoint(Ot(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ot(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))}},Pt=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Lt=[e=>{},e=>null,Rt,e=>Pt(e,4).getFloat32(0,!1),e=>Pt(e,8).getFloat64(0,!1),e=>Pt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,It,e=>{const t=$t(e),n={};for(let r=0;r<t;r++)n[It(e)]=zt(e);return n},e=>{const t=$t(e),n=[];for(let r=0;r<t;r++)n.push(zt(e));return n},Dt],zt=e=>Lt[127-Ot(e)](e),Bt=class extends Mt{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=$t(this)+1:this.count=-1),this.count--,this.s;var e}},Ft=class extends Mt{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=Rt(this);const e=Ve(this.s);this.count=1,e&&(this.s=-this.s,this.count=$t(this)+2)}return this.count--,this.s}},Vt=class extends Mt{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=Rt(this),t=1&e;this.diff=Le(e/2),this.count=1,t&&(this.count=$t(this)+2)}return this.s+=this.diff,this.count--,this.s}},Wt=class{constructor(e){this.decoder=new Ft(e),this.str=It(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)),qt=Math.random,Ut=()=>Ht(new Uint32Array(1))[0],Jt=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(e^Ut()&15>>e/4).toString(16)),Kt=Date.now,Gt=e=>new Promise(e),Xt=(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&&(Xt=localStorage,!1)}catch(lu){}var Yt,Zt=Xt,Qt=Symbol("Equality"),en=(e,t)=>e===t||!!e?.[Qt]?.(t)||!1,tn=Object.assign,nn=Object.keys,rn=e=>nn(e).length,sn=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},on=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ln=Object.freeze,an=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||an(e[t])}return ln(e)},cn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&cn(e,t,n+1)}},dn=(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[Qt])return e[Qt](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)||!dn(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(rn(e)!==rn(t))return!1;for(const n in e)if(!on(e,n)||!dn(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(!dn(e[n],t[n]))return!1;break;default:return!1}return!0},hn="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),un="undefined"!=typeof window&&"undefined"!=typeof document&&!hn,pn=("undefined"!=typeof navigator&&/Mac/.test(navigator.platform),[]),mn=e=>(()=>{if(void 0===Qe)if(hn){Qe=Ee();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];"-"===r[0]?(null!==t&&Qe.set(t,""),t=r):null!==t?(Qe.set(t,r),t=null):pn.push(r)}null!==t&&Qe.set(t,"")}else"object"==typeof location?(Qe=Ee(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");Qe.set(`--${Ge(t,"-")}`,n),Qe.set(`-${Ge(t,"-")}`,n)}})):Qe=Ee();return Qe})().has(e),fn=e=>(e=>void 0===e?null:e)(hn?process.env[e.toUpperCase().replaceAll("-","_")]:Zt.getItem(e)),gn=e=>mn("--"+e)||null!==fn(e),xn=gn("production"),bn=(hn&&(et=process.env.FORCE_COLOR,tt=["true","1","2"],tt.includes(et))||!mn("--no-colors")&&!gn("no-color")&&(!hn||process.stdout.isTTY)&&(!hn||mn("--color")||null!==fn("COLORTERM")||(fn("TERM")||"").includes("color")),un?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ue(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")),yn=class{constructor(e,t){this.left=e,this.right=t}},vn=(e,t)=>new yn(e,t),wn=e=>e.next()>=.5,kn=(e,t,n)=>Le(e.next()*(n+1-t)+t),Sn=(e,t,n)=>Le(e.next()*(n+1-t)+t),jn=(e,t,n)=>Sn(e,t,n),Cn=e=>Ue(jn(e,97,122)),Nn=(e,t)=>t[jn(e,0,t.length-1)],En=Symbol("0schema"),An=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(rt(" ",2*(this._rerrs.length-t))+`${null!=n.path?`[${n.path}] `:""}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join("\n")}},Tn=(e,t)=>e===t||null!=e&&null!=t&&e.constructor===t.constructor&&(e[Qt]?en(e,t):Ie(e)?$e(e,e=>Re(t,t=>Tn(e,t))):"object"==typeof e&&sn(e,(e,n)=>Tn(e,t[n]))),Mn=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Tn(t,n)}equals(e){return this.constructor===e.constructor&&dn(this.shape,e.shape)}[En](){return!0}[Qt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Nt()}get nullable(){return or(this,wr)}get optional(){return new Fn(this)}cast(e){return Cr(e,this),e}expect(e){return Cr(e,this),e}},_n=class extends Mn{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}},Dn=(e,t=null)=>new _n(e,t),On=(Dn(_n),class extends Mn{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}}),$n=e=>new On(e),Rn=(Dn(On),class extends Mn{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}}),In=(...e)=>new Rn(e),Pn=Dn(Rn),Ln=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),zn=e=>gr.check(e)?[Ln(e)]:Pn.check(e)?e.shape.map(e=>e+""):fr.check(e)?["[+-]?\\d+.?\\d*"]:xr.check(e)?[".*"]:lr.check(e)?e.shape.map(zn).flat(1):void Et(),Bn=(Dn(class extends Mn{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(zn).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")),Fn=class extends Mn{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[Bn](){return!0}},Vn=Dn(Fn),Wn=class extends Mn{check(e,t){return t?.extend(null,"never",typeof e),!1}},Hn=(new Wn,Dn(Wn),class e extends Mn{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):sn(this.shape,(n,r)=>{const s=this._isPartial&&!on(e,r)||n.check(e[r],t);return!s&&t?.extend(r.toString(),n.toString(),typeof e[r],"Object property does not match"),s})}}),qn=Dn(Hn),Un=$n(e=>null!=e&&(e.constructor===Object||null==e.constructor)),Jn=class extends Mn{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return null!=e&&sn(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)})}},Kn=(e,t)=>new Jn(e,t),Gn=Dn(Jn),Xn=class extends Mn{constructor(e){super(),this.shape=e}check(e,t){return null!=e&&sn(this.shape,(n,r)=>{const s=n.check(e[r],t);return!s&&t?.extend(r.toString(),"Tuple",typeof n),s})}},Yn=(Dn(Xn),class extends Mn{constructor(e){super(),this.shape=1===e.length?e[0]:new ir(e)}check(e,t){const n=Ie(e)&&$e(e,e=>this.shape.check(e));return!n&&t?.extend(null,"Array",""),n}}),Zn=(...e)=>new Yn(e),Qn=Dn(Yn),er=$n(e=>Ie(e)),tr=class extends Mn{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}},nr=(Dn(tr),((e,t=null)=>new tr(Mn,t))()),rr=Dn(class extends Mn{constructor(e){super(),this.len=e.length-1,this.args=((...e)=>new Xn(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}}),sr=$n(e=>"function"==typeof e),ir=(Dn(class extends Mn{constructor(e){super(),this.shape=e}check(e,t){const n=$e(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,"Intersectinon",typeof e),n}},e=>e.shape.length>0),class extends Mn{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){const n=Re(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),n}}),or=(...e)=>e.findIndex(e=>lr.check(e))>=0?or(...e.map(e=>jr(e)).map(e=>lr.check(e)?e.shape:[e]).flat(1)):1===e.length?e[0]:new ir(e),lr=Dn(ir),ar=()=>!0,cr=$n(ar),dr=Dn(On,e=>e.shape===ar),hr=$n(e=>"bigint"==typeof e),ur=$n(e=>e===hr),pr=$n(e=>"symbol"==typeof e),mr=($n(e=>e===pr),$n(e=>"number"==typeof e)),fr=$n(e=>e===mr),gr=$n(e=>"string"==typeof e),xr=$n(e=>e===gr),br=$n(e=>"boolean"==typeof e),yr=$n(e=>e===br),vr=In(void 0),wr=(Dn(Rn,e=>1===e.shape.length&&void 0===e.shape[0]),In(void 0),In(null)),kr=Dn(Rn,e=>1===e.shape.length&&null===e.shape[0]),Sr=(Dn(Uint8Array),Dn(_n,e=>e.shape===Uint8Array),or(mr,gr,wr,vr,hr,br,pr)),jr=((()=>{const e=Zn(cr),t=Kn(gr,cr),n=or(mr,gr,wr,br,e,t);e.shape=n,t.shape.values=n})(),e=>{if(nr.check(e))return e;if(Un.check(e)){const t={};for(const n in e)t[n]=jr(e[n]);return new Hn(t)}return er.check(e)?or(...e.map(jr)):Sr.check(e)?In(e):sr.check(e)?Dn(e):void Et()}),Cr=xn?()=>{}:(e,t)=>{const n=new An;if(!t.check(e,n))throw Ct(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Nr=(nt=cr,new class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:jr(e),h:t}),this}else(e){return this.if(cr,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 Ct("Unhandled pattern")}}}(nt)).if(fr,(e,t)=>kn(t,He,We)).if(xr,(e,t)=>((e,t=0,n=20)=>{const r=jn(e,t,n);let s="";for(let i=0;i<r;i++)s+=Cn(e);return s})(t)).if(yr,(e,t)=>wn(t)).if(ur,(e,t)=>BigInt(kn(t,He,We))).if(lr,(e,t)=>Er(t,Nn(t,e.shape))).if(qn,(e,t)=>{const n={};for(const r in e.shape){let s=e.shape[r];if(Vn.check(s)){if(wn(t))continue;s=s.shape}n[r]=Nr(s,t)}return n}).if(Qn,(e,t)=>{const n=[],r=Sn(t,0,42);for(let s=0;s<r;s++)n.push(Er(t,e.shape));return n}).if(Pn,(e,t)=>Nn(t,e.shape)).if(kr,(e,t)=>null).if(rr,(e,t)=>{const n=Er(t,e.res);return()=>n}).if(dr,(e,t)=>Er(t,Nn(t,[mr,gr,wr,vr,hr,br,Zn(mr),Kn(or("a","b","c"),mr)]))).if(Gn,(e,t)=>{const n={},r=kn(t,0,3);for(let s=0;s<r;s++)n[Er(t,e.shape.keys)]=Er(t,e.shape.values);return n}).done(),Er=(e,t)=>Nr(jr(t),e),Ar="undefined"!=typeof document?document:{},Tr=($n(e=>e.nodeType===Dr),"undefined"!=typeof DOMParser&&new DOMParser,$n(e=>e.nodeType===Tr),$n(e=>e.nodeType===Mr),Ar.ELEMENT_NODE),Mr=Ar.TEXT_NODE,_r=(Ar.CDATA_SECTION_NODE,Ar.COMMENT_NODE,Ar.DOCUMENT_NODE),Dr=(Ar.DOCUMENT_TYPE_NODE,Ar.DOCUMENT_FRAGMENT_NODE),Or=($n(e=>e.nodeType===_r),JSON.stringify,Yt=clearTimeout,class{constructor(e){this._=e}destroy(){Yt(this._)}}),$r=(e,t)=>new Or(setTimeout(t,e)),Rr=Symbol,Ir=Rr(),Pr=Rr(),Lr=(Rr(),Rr(),Rr(),Rr()),zr=(Rr(),Rr()),Br=(Rr(),Kt(),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)=>{Vr.forEach(t=>t.print(e))}),Fr=(...e)=>{e.unshift(zr),Vr.forEach(t=>t.print(e))},Vr=Me(),Wr=e=>({[Symbol.iterator](){return this},next:e}),Hr=(e,t)=>Wr(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),qr=class{constructor(e,t){this.clock=e,this.len=t}},Ur=class{constructor(){this.clients=new Map}},Jr=(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])Fs(e,s,l.clock,l.len,n)}}),Kr=(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=Le((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)},Gr=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 qr(r.clock,Fe(r.len,s.clock+s.len-r.clock)):(n<t&&(e[n]=s),n++)}e.length=n})},Xr=e=>{const t=new Ur;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++)De(i,e[t].clients.get(s)||[]);t.clients.set(s,i)}});return Gr(t),t},Yr=(e,t,n,r)=>{Te(e.clients,t,()=>[]).push(new qr(n,r))},Zr=()=>new Ur,Qr=(e,t)=>{ct(e.restEncoder,t.clients.size),Oe(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),ct(e.restEncoder,t);const r=n.length;ct(e.restEncoder,r);for(let s=0;s<r;s++){const t=n[s];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},es=e=>{const t=new Ur,n=$t(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=$t(e.restDecoder),r=$t(e.restDecoder);if(r>0){const s=Te(t.clients,n,()=>[]);for(let t=0;t<r;t++)s.push(new qr(e.readDsClock(),e.readDsLen()))}}return t},ts=(e,t,n)=>{const r=new Ur,s=$t(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=$t(e.restDecoder),i=$t(e.restDecoder),o=n.clients.get(s)||[],l=$s(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Yr(r,s,l,i-l);let e=Is(o,n),a=o[e];for(!a.deleted&&a.id.clock<n&&(o.splice(e+1,0,To(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,To(t,a,i-a.id.clock)),a.delete(t))}else Yr(r,s,n,i-n)}}if(r.clients.size>0){const e=new cs;return ct(e.restEncoder,0),Qr(e,r),e.toUint8Array()}return null},ns=Ut,rs=class e extends Pe{constructor({guid:e=Jt(),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=ns(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ds,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=Gt(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>Gt(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||Js(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Oe(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Js(this,e,t)}get(e,t=fi){const n=Te(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==fi&&r!==t){if(r===fi){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,$i)}getText(e=""){return this.get(e,Zi)}getMap(e=""){return this.get(e,Ii)}getXmlElement(e=""){return this.get(e,to)}getXmlFragment(e=""){return this.get(e,eo)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Oe(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,Js(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()}},ss=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=$t(this.restDecoder),this.dsCurrVal}readDsLen(){const e=$t(this.restDecoder)+1;return this.dsCurrVal+=e,e}},is=class extends ss{constructor(e){super(e),this.keys=[],$t(e),this.keyClockDecoder=new Vt(Dt(e)),this.clientDecoder=new Ft(Dt(e)),this.leftClockDecoder=new Vt(Dt(e)),this.rightClockDecoder=new Vt(Dt(e)),this.infoDecoder=new Bt(Dt(e),Ot),this.stringDecoder=new Wt(Dt(e)),this.parentInfoDecoder=new Bt(Dt(e),Ot),this.typeRefDecoder=new Ft(Dt(e)),this.lenDecoder=new Ft(Dt(e))}readLeftID(){return new xs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new xs(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 zt(this.restDecoder)}readBuf(){return Dt(this.restDecoder)}readJSON(){return zt(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}}},os=class{constructor(){this.restEncoder=it()}toUint8Array(){return ot(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ct(this.restEncoder,e)}writeDsLen(e){ct(this.restEncoder,e)}},ls=class extends os{writeLeftID(e){ct(this.restEncoder,e.client),ct(this.restEncoder,e.clock)}writeRightID(e){ct(this.restEncoder,e.client),ct(this.restEncoder,e.clock)}writeClient(e){ct(this.restEncoder,e)}writeInfo(e){at(this.restEncoder,e)}writeString(e){pt(this.restEncoder,e)}writeParentInfo(e){ct(this.restEncoder,e?1:0)}writeTypeRef(e){ct(this.restEncoder,e)}writeLen(e){ct(this.restEncoder,e)}writeAny(e){bt(this.restEncoder,e)}writeBuf(e){ft(this.restEncoder,e)}writeJSON(e){pt(this.restEncoder,JSON.stringify(e))}writeKey(e){pt(this.restEncoder,e)}},as=class{constructor(){this.restEncoder=it(),this.dsCurrVal=0}toUint8Array(){return ot(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,ct(this.restEncoder,t)}writeDsLen(e){0===e&&Et(),ct(this.restEncoder,e-1),this.dsCurrVal+=e}},cs=class extends as{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new St,this.clientEncoder=new wt,this.leftClockEncoder=new St,this.rightClockEncoder=new St,this.infoEncoder=new yt(at),this.stringEncoder=new jt,this.parentInfoEncoder=new yt(at),this.typeRefEncoder=new wt,this.lenEncoder=new wt}toUint8Array(){const e=it();return ct(e,0),ft(e,this.keyClockEncoder.toUint8Array()),ft(e,this.clientEncoder.toUint8Array()),ft(e,this.leftClockEncoder.toUint8Array()),ft(e,this.rightClockEncoder.toUint8Array()),ft(e,ot(this.infoEncoder)),ft(e,this.stringEncoder.toUint8Array()),ft(e,ot(this.parentInfoEncoder)),ft(e,this.typeRefEncoder.toUint8Array()),ft(e,this.lenEncoder.toUint8Array()),mt(e,ot(this.restEncoder)),ot(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){bt(this.restEncoder,e)}writeBuf(e){ft(this.restEncoder,e)}writeJSON(e){bt(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)}},ds=(e,t,n)=>{const r=new Map;n.forEach((e,n)=>{$s(t,n)>e&&r.set(n,e)}),Os(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),ct(e.restEncoder,r.size),Oe(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{((e,t,n,r)=>{r=Fe(r,t[0].id.clock);const s=Is(t,r);ct(e.restEncoder,t.length-s),e.writeClient(n),ct(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)})},hs=(e,t,n,r=is)=>{const s=_t(t);((e,t,n,r=new is(e))=>{Js(t,e=>{e.local=!1;let t=!1;const n=e.doc,s=n.store,i=((e,t,n)=>{const r=[];let s=Oe(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 Ds,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!==Ro){const s=Te(h,d.id.client,()=>$s(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,$s(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 cs;return ds(e,l,new Map),ct(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,s,((e,t)=>{const n=Ee(),r=$t(e.restDecoder);for(let s=0;s<r;s++){const r=$t(e.restDecoder),s=new Array(r),i=e.readClient();let o=$t(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 oo(ys(i,o),t),o+=t;break}case 10:{const t=$t(e.restDecoder);s[n]=new Ro(ys(i,o),t),o+=t;break}default:{const l=!(192&r),a=new Do(ys(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(),Oo(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<$s(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=ti([o.update,i.update])}}else s.pendingStructs=i;const l=ts(r,e,s);if(s.pendingDs){const t=new is(_t(s.pendingDs));$t(t.restDecoder);const n=ts(t,e,s);s.pendingDs=l&&n?ti([l,n]):l||n}else s.pendingDs=l;if(t){const t=s.pendingStructs.update;s.pendingStructs=null,hs(e.doc,t)}},n,!1)})(s,e,n,new r(s))},us=class{constructor(){this.l=[]}},ps=()=>new us,ms=(e,t)=>e.l.push(t),fs=(e,t)=>{const n=e.l;n.length,e.l=n.filter(e=>t!==e),e.l.length},gs=(e,t,n)=>cn(e.l,[t,n]),xs=class{constructor(e,t){this.client=e,this.clock=t}},bs=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ys=(e,t)=>new xs(e,t),vs=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Et()},ws=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1},ks=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}},js=(e,t,n)=>{let r=null,s=null;return null===e._item?s=vs(e):r=ys(e._item.id.client,e._item.id.clock),new ks(r,s,t,n)},Cs=(e,t,n=0)=>{let r=e._start;if(n<0){if(0===t)return js(e,null,n);t--}for(;null!==r;){if(!r.deleted&&r.countable){if(r.length>t)return js(e,ys(r.id.client,r.id.clock+t),n);t-=r.length}if(null===r.right&&n<0)return js(e,r.lastId,n);r=r.right}return js(e,null,n)},Ns=(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($s(r,s.client)<=s.clock)return null;const e=n?Eo(r,s):((e,t)=>{const n=Ps(e,t);return{item:n,diff:t.clock-n.id.clock}})(r,s),t=e.item;if(!(t instanceof Do))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 Et();{if($s(r,i.client)<=i.clock)return null;const{item:e}=n?Eo(r,i):{item:Ps(r,i)};if(!(e instanceof Do&&e.content instanceof No))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)},Es=class{constructor(e,t){this.ds=e,this.sv=t}},As=(e,t)=>new Es(e,t),Ts=(As(Zr(),new Map),e=>As((e=>{const t=Zr();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 qr(s,i))}}r.length>0&&t.clients.set(n,r)}),t})(e.store),Os(e.store))),Ms=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Kr(t.ds,e.id),_s=(e,t)=>{const n=Te(e.meta,_s,Me),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<$s(r,n)&&zs(e,ys(n,t))}),Jr(e,t.ds,e=>{}),n.add(t))},Ds=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Os=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},$s=(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},Rs=(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 Et()}n.push(t)},Is=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=Le(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=Le((n+r)/2)}throw Et()},Ps=(e,t)=>{const n=e.clients.get(t.client);return n[Is(n,t.clock)]},Ls=(e,t,n)=>{const r=Is(t,n),s=t[r];return s.id.clock<n&&s instanceof Do?(t.splice(r+1,0,To(e,s,n-s.id.clock)),r+1):r},zs=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Ls(e,n,t.clock)]},Bs=(e,t,n)=>{const r=t.clients.get(n.client),s=Is(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==oo&&r.splice(s+1,0,To(e,i,n.clock-i.id.clock+1)),i},Fs=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,l=Ls(e,t,n);do{o=t[l++],i<o.id.clock+o.length&&Ls(e,t,i),s(o)}while(l<t.length&&t[l].id.clock<i)},Vs=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Ur,this.beforeState=Os(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}},Ws=(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)||(Gr(t.deleteSet),((e,t)=>{ds(e,t.doc.store,t.beforeState)})(e,t),Qr(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)&&Te(e.changed,t,Me).add(n)},qs=(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 Do&&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},Us=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Gr(i),n.afterState=Os(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(()=>{gs(r._dEH,t,n)}))}),e.push(()=>r.emit("afterTransaction",[n,r])),e.push(()=>{n._needFormattingCleanup&&Gi(n)})}),cn(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=Is(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 Do&&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=Be(r.length-1,1+Is(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+qs(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=Fe(Is(e,r),1);for(let t=e.length-1;t>=n;)t-=1+qs(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=Is(r,n);i+1<r.length&&qs(r,i+1)>1||i>0&&qs(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(Br(zr,Ir,"[yjs] ",Pr,Lr,"Changed the client-id because another client seems to be using it."),r.clientID=ns()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new ls;Ws(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new cs;Ws(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])):Us(e,t+1)}}},Js=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new Vs(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&&Us(s,0)}}return o},Ks=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Gs=(e,t,n)=>{Jr(e,n.deletions,n=>{n instanceof Do&&t.scope.some(t=>t===e.doc||ws(t,n))&&Ao(n,!1)})},Xs=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;Js(s,n=>{for(;t.length>0&&null===e.currStackItem;){const r=s.store,o=t.pop(),l=new Set,a=[];let c=!1;Jr(n,o.insertions,e=>{if(e instanceof Do){if(null!==e.redone){let{item:t,diff:s}=Eo(r,e.id);s>0&&(t=zs(n,ys(t.id.client,t.id.clock+s))),e=t}!e.deleted&&i.some(t=>t===n.doc||ws(t,e))&&a.push(e)}}),Jr(n,o.deletions,e=>{e instanceof Do&&i.some(t=>t===n.doc||ws(t,e))&&!Kr(o.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==_o(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},Ys=class extends Pe{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:o=(Ie(e)?e[0].doc:e instanceof rs?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 Ur;e.afterState.forEach((t,n)=>{const r=e.beforeState.get(n)||0,i=t-r;i>0&&Yr(s,n,r,i)});const i=Kt();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=Xr([t.deletions,e.deleteSet]),t.insertions=Xr([t.insertions,s])}else r.push(new Ks(e.deleteSet,s)),o=!0;t||n||(this.lastChange=i),Jr(e,e.deleteSet,t=>{t instanceof Do&&this.scope.some(n=>n===e.doc||ws(n,t))&&Ao(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.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(e){const t=new Set(this.scope);(e=Ie(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof fi?e.doc!==this.doc:e!==this.doc)&&Fr("[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=>Gs(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Gs(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=Xs(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=Xs(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),this.doc.off("destroy",this.destroy),super.destroy()}},Zs=class{constructor(e,t){this.gen=function*(e){const t=$t(e.restDecoder);for(let n=0;n<t;n++){const t=$t(e.restDecoder),n=e.readClient();let r=$t(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=$t(e.restDecoder);yield new Ro(ys(n,r),t),r+=t}else if(31&t){const s=!(192&t),i=new Do(ys(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(),Oo(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new oo(ys(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===Ro);return this.curr}},Qs=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ei=(e,t)=>{if(e.constructor===oo){const{client:n,clock:r}=e.id;return new oo(ys(n,r+t),e.length-t)}if(e.constructor===Ro){const{client:n,clock:r}=e.id;return new Ro(ys(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new Do(ys(r,s+t),null,ys(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ti=(e,t=is,n=cs)=>{if(1===e.length)return e[0];const r=e.map(e=>new t(_t(e)));let s=r.map(e=>new Zs(e,!0)),i=null;const o=new n,l=new Qs(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===Ro?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)ri(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===Ro)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{ri(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Ro(ys(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===Ro?i.struct.length-=t:n=ei(n,t)),i.struct.mergeWith(n)||(ri(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!==Ro;n=e.next())ri(l,i.struct,i.offset),i={struct:n,offset:0}}return null!==i&&(ri(l,i.struct,i.offset),i=null),si(l),Qr(o,Xr(r.map(e=>es(e)))),o.toUint8Array()},ni=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ot(e.encoder.restEncoder)}),e.encoder.restEncoder=it(),e.written=0)},ri=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ni(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),ct(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},si=e=>{ni(e);const t=e.encoder.restEncoder;ct(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];ct(t,r.written),mt(t,r.restEncoder)}},ii="You must not compute changes after the event-handler fired.",oi=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=li(this.currentTarget,this.target))}deletes(e){return Kr(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Ct(ii);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=_e(e.content.getContent())}else null!==e&&this.deletes(e)?(s="update",i=_e(e.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=_e(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 Ct(ii);const t=this.target,n=Me(),r=Me(),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}},li=(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},ai=()=>{Fr("Invalid access: Add Yjs type to a document before reading data.")},ci=0,di=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ci++}},hi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ci++},ui=(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)=>ze(t-e.index)<ze(t-n.index)?e:n);let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=ci++})(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&&ze(n.index-s)<r.parent.length/80?(hi(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return hi(r,t,n),r}{const r=new di(t,n);return e.push(r),r}})(e._searchMarker,r,s)},pi=(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=Fe(t,s.index+n))}},mi=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;Te(s,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;gs(r._eH,n,t)},fi=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ps(),this._dEH=ps(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Nt()}clone(){throw Nt()}_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){ms(this._eH,e)}observeDeep(e){ms(this._dEH,e)}unobserve(e){fs(this._eH,e)}unobserveDeep(e){fs(this._dEH,e)}toJSON(){}},gi=(e,t,n)=>{e.doc??ai(),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},xi=e=>{e.doc??ai();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},bi=(e,t)=>{const n=[];let r=e._start;for(;null!==r;){if(r.countable&&Ms(r,t)){const e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},yi=(e,t)=>{let n=0,r=e._start;for(e.doc??ai();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 yi(e,(r,s)=>{n.push(t(r,s,e))}),n},wi=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}}}},ki=(e,t)=>{e.doc??ai();const n=ui(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 Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new go(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 Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new lo(new Uint8Array(n))),s.integrate(e,0);break;case rs:s=new Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new ho(n)),s.integrate(e,0);break;default:if(!(n instanceof fi))throw new Error("Unexpected content type in insert operation");s=new Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new No(n)),s.integrate(e,0)}}}),d()},ji=()=>Ct("Length exceeded!"),Ci=(e,t,n,r)=>{if(n>t._length)throw ji();if(0===n)return t._searchMarker&&pi(t._searchMarker,n,r.length),Si(e,t,null,r);const s=n,i=ui(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&&zs(e,ys(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&pi(t._searchMarker,s,r.length),Si(e,t,o,r)},Ni=(e,t,n,r)=>{if(0===r)return;const s=n,i=r,o=ui(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&&zs(e,ys(l.id.client,l.id.clock+n)),n-=l.length);for(;r>0&&null!==l;)l.deleted||(r<l.length&&zs(e,ys(l.id.client,l.id.clock+r)),l.delete(e),r-=l.length),l=l.right;if(r>0)throw ji();t._searchMarker&&pi(t._searchMarker,s,-i+r)},Ei=(e,t,n)=>{const r=t._map.get(n);void 0!==r&&r.delete(e)},Ai=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let l;if(null==r)l=new go([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new go([r]);break;case Uint8Array:l=new lo(r);break;case rs:l=new ho(r);break;default:if(!(r instanceof fi))throw new Error("Unexpected content type");l=new No(r)}new Do(ys(o,$s(i.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Ti=(e,t)=>{e.doc??ai();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},Mi=e=>{const t={};return e.doc??ai(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},_i=(e,t)=>{e.doc??ai();const n=e._map.get(t);return void 0!==n&&!n.deleted},Di=e=>(e.doc??ai(),((e,t)=>Wr(()=>{let n;do{n=e.next()}while(!n.done&&!t(n.value));return n}))(e._map.entries(),e=>!e[1].deleted)),Oi=class extends oi{},$i=class e extends fi{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 fi?e.clone():e)),t}get length(){return this.doc??ai(),this._length}_callObserver(e,t){super._callObserver(e,t),mi(this,e,new Oi(this,e))}insert(e,t){null!==this.doc?Js(this.doc,n=>{Ci(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Js(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?Js(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return ki(this,e)}toArray(){return xi(this)}slice(e=0,t=this.length){return gi(this,e,t)}toJSON(){return this.map(e=>e instanceof fi?e.toJSON():e)}map(e){return vi(this,e)}forEach(e){yi(this,e)}[Symbol.iterator](){return wi(this)}_write(e){e.writeTypeRef(yo)}},Ri=class extends oi{constructor(e,t,n){super(e,t),this.keysChanged=n}},Ii=class e extends fi{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 fi?e.clone():e)}),t}_callObserver(e,t){mi(this,e,new Ri(this,e,t))}toJSON(){this.doc??ai();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const r=t.content.getContent()[t.length-1];e[n]=r instanceof fi?r.toJSON():r}}),e}get size(){return[...Di(this)].length}keys(){return Hr(Di(this),e=>e[0])}values(){return Hr(Di(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Hr(Di(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ai(),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?Js(this.doc,t=>{Ei(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ti(this,e)}has(e){return _i(this,e)}clear(){null!==this.doc?Js(this.doc,e=>{this.forEach(function(t,n,r){Ei(e,r,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(vo)}},Pi=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||rn(e)===rn(t)&&sn(e,(e,n)=>(void 0!==e||on(t,n))&&en(t[n],e)))(e,t),Li=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){null===this.right&&Et(),this.right.content.constructor===po?this.right.deleted||Vi(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},zi=(e,t,n)=>{for(;null!==t.right&&n>0;)t.right.content.constructor===po?t.right.deleted||Vi(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&zs(e,ys(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},Bi=(e,t,n,r)=>{const s=new Map,i=r?ui(t,n):null;return i?zi(e,new Li(i.p.left,i.p,i.index,s),n-i.index):zi(e,new Li(null,t._start,0,s),n)},Fi=(e,t,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===po&&Pi(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 Do(ys(i,$s(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new po(o,r));c.integrate(e,0),n.right=c,n.forward()})},Vi=(e,t)=>{const{key:n,value:r}=t;null===r?e.delete(n):e.set(n,r)},Wi=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===po&&Pi(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(!Pi(c,a)){o.set(l,c);const{left:r,right:d}=n;n.right=new Do(ys(i,$s(s.store,i)),r,r&&r.lastId,d,d&&d.id,t,null,new po(l,a)),n.right.integrate(e,0),n.forward()}}return o},qi=(e,t,n,r,s)=>{n.currentAttributes.forEach((e,t)=>{void 0===s[t]&&(s[t]=null)});const i=e.doc,o=i.clientID;Wi(n,s);const l=Hi(e,t,n,s),a=r.constructor===String?new xo(r):r instanceof fi?new No(r):new uo(r);let{left:c,right:d,index:h}=n;t._searchMarker&&pi(t._searchMarker,n.index,a.getLength()),d=new Do(ys(o,$s(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(),Fi(e,t,n,l)},Ui=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;Wi(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===po));){if(!n.right.deleted)switch(n.right.content.constructor){case po:{const{key:t,value:i}=n.right.content,o=s[t];if(void 0!==o){if(Pi(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&&zs(e,ys(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 Do(ys(o,$s(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new xo(s)),n.right.integrate(e,0),n.forward()}Fi(e,t,n,l)},Ji=(e,t,n,r,s)=>{let i=t;const o=Ee();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===po){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 po:{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||Vi(s,n);break}}}t=t.right}return l},Ki=e=>{let t=0;return Js(e.doc,n=>{let r=e._start,s=e._start,i=Ee();const o=Ae(i);for(;s;)!1===s.deleted&&(s.content.constructor===po?Vi(o,s.content):(t+=Ji(n,r,s,i,o),i=Ae(o),r=s)),s=s.right}),t},Gi=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&&Fs(e,n.store.clients.get(r),i,s,e=>{e.deleted||e.content.constructor!==po||e.constructor===oo||t.add(e.parent)})}Js(n,n=>{Jr(e,e.deleteSet,e=>{if(e instanceof oo||!e.parent._hasFormatting||t.has(e.parent))return;const r=e.parent;e.content.constructor===po?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===po){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}})(n,e)});for(const e of t)Ki(e)})},Xi=(e,t,n)=>{const r=n,s=Ae(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case No:case uo:case xo:n<t.right.length&&zs(e,ys(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&Ji(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&pi(o._searchMarker,t.index,-r+n),t},Yi=class extends oi{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=[];Js(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=tn({},o))),a=0}e&&t.push(e),i=null}};for(;null!==s;){switch(s.content.constructor){case No:case uo: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 xo: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 po:{const{key:t,value:l}=s.content;if(this.adds(s))this.deletes(s)||(Pi(n.get(t)??null,l)?null!==l&&s.delete(e):("retain"===i&&d(),Pi(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;Pi(e,l)||("retain"===i&&d(),o[t]=e)}else if(!s.deleted){r.set(t,l);const n=o[t];void 0!==n&&(Pi(n,l)?null!==n&&s.delete(e):("retain"===i&&d(),null===l?delete o[t]:o[t]=l))}s.deleted||("insert"===i&&d(),Vi(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}},Zi=class e extends fi{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ai(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(lu){}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 Yi(this,e,t);mi(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ai();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===xo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Js(this.doc,n=>{const r=new Li(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)&&qi(n,this,r,o,i.attributes||{})}else void 0!==i.retain?Ui(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&Xi(n,r,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??ai();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(Ms(l,e)||void 0!==t&&Ms(l,t))switch(l.content.constructor){case xo:{const r=s.get("ychange");void 0===e||Ms(l,e)?void 0===t||Ms(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 No:case uo:{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 po:Ms(l,e)&&(a(),Vi(s,l.content))}l=l.right}a()};return e||t?Js(i,n=>{e&&_s(n,e),t&&_s(n,t),c()},"cleanup"):c(),r}insert(e,t,n){if(t.length<=0)return;const r=this.doc;null!==r?Js(r,r=>{const s=Bi(r,this,e,!n);n||(n={},s.currentAttributes.forEach((e,t)=>{n[t]=e})),qi(r,this,s,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const r=this.doc;null!==r?Js(r,r=>{const s=Bi(r,this,e,!n);qi(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?Js(n,n=>{Xi(n,Bi(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?Js(r,r=>{const s=Bi(r,this,e,!1);null!==s.right&&Ui(r,this,s,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?Js(this.doc,t=>{Ei(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ti(this,e)}getAttributes(){return Mi(this)}_write(e){e.writeTypeRef(wo)}},Qi=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ai()}[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!==to&&t.constructor!==eo||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})}},eo=class e extends fi{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 fi?e.clone():e)),t}get length(){return this.doc??ai(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new Qi(this,e)}querySelector(e){e=e.toUpperCase();const t=new Qi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Oe(new Qi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){mi(this,e,new no(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),yi(this,s=>{r.insertBefore(s.toDOM(e,t,n),null)}),r}insert(e,t){null!==this.doc?Js(this.doc,n=>{Ci(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Js(this.doc,n=>{const r=e&&e instanceof fi?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 Ct("Reference item not found");n.splice(r,0,...t)}}delete(e,t=1){null!==this.doc?Js(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return xi(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ki(this,e)}slice(e=0,t=this.length){return gi(this,e,t)}forEach(e){yi(this,e)}_write(e){e.writeTypeRef(So)}},to=class e extends eo{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 fi?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?Js(this.doc,t=>{Ei(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ti(this,e)}hasAttribute(e){return _i(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&&Ms(s,t)&&(n[r]=s.content.getContent()[s.length-1])}),n})(0,e):Mi(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 yi(this,s=>{r.appendChild(s.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(ko),e.writeKey(this.nodeName)}},no=class extends oi{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)})}},ro=class e extends Ii{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(jo),e.writeKey(this.hookName)}},so=class e extends Zi{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(Co)}},io=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Nt()}mergeWith(e){return!1}write(e,t,n){throw Nt()}integrate(e,t){throw Nt()}},oo=class extends io{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),Rs(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},lo=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 Nt()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ao=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){Yr(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}},co=(e,t)=>new rs({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ho=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(co(this.doc.guid,this.opts))}splice(e){throw Nt()}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}},uo=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 Nt()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},po=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 Nt()}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}},mo=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}},fo="development"===fn("node_env"),go=class e{constructor(e){this.arr=e,fo&&an(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}},xo=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}},bo=[e=>new $i,e=>new Ii,e=>new Zi,e=>new to(e.readKey()),e=>new eo,e=>new ro(e.readKey()),e=>new so],yo=0,vo=1,wo=2,ko=3,So=4,jo=5,Co=6,No=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 Nt()}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}},Eo=(e,t)=>{let n,r=t,s=0;do{s>0&&(r=ys(r.client,r.clock+s)),n=Ps(e,r),s=r.clock-n.id.clock,r=n.redone}while(null!==r&&n instanceof Do);return{item:n,diff:s}},Ao=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},To=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new Do(ys(r,s+n),t,ys(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=ys(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},Mo=(e,t)=>Re(e,e=>Kr(e.deletions,t)),_o=(e,t,n,r,s,i)=>{const o=e.doc,l=o.store,a=o.clientID,c=t.redone;if(null!==c)return zs(e,c);let d,h=t.parent._item,u=null;if(null!==h&&!0===h.deleted){if(null===h.redone&&(!n.has(h)||null===_o(e,h,n,r,s,i)))return null;for(;null!==h.redone;)h=zs(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:zs(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:zs(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||Kr(r,u.right.id)||Mo(i.undoStack,u.right.id)||Mo(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=zs(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=ys(a,$s(l,a)),f=new Do(m,u,u&&u.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,Ao(f,!0),f.integrate(e,0),f},Do=class e extends io{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>=$s(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=$s(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===xs&&this.id.client!==this.parent.client&&this.parent.clock>=$s(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=zs(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===oo||this.right&&this.right.constructor===oo)this.parent=null;else if(this.parent){if(this.parent.constructor===xs){const e=Ps(n,this.parent);e.constructor===oo?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=Bs(e,e.doc.store,ys(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),bs(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,r.clear();else if(bs(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!s.has(Ps(e.doc.store,t.origin)))break;r.has(Ps(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),Rs(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 oo(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:ys(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&bs(e.origin,this.lastId)&&this.right===e&&bs(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(),Yr(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 Et();this.content.gc(e),t?((e,t,n)=>{const r=e.clients.get(t.id.client);r[Is(r,t.id.clock)]=n})(e,this,new oo(this.id,this.length)):this.content=new ao(this.length)}write(e,t){const n=t>0?ys(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===xs?(e.writeParentInfo(!1),e.writeLeftID(t)):Et();null!==s&&e.writeString(s)}this.content.write(e,t)}},Oo=(e,t)=>$o[31&t](e),$o=[()=>{Et()},e=>new ao(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 mo(n)},e=>new lo(e.readBuf()),e=>new xo(e.readString()),e=>new uo(e.readJSON()),e=>new po(e.readKey(),e.readJSON()),e=>new No(bo[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new go(n)},e=>new ho(co(e.readString(),e.readAny())),()=>{Et()}],Ro=class extends io{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Et()}write(e,t){e.writeInfo(10),ct(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Io="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Po="__ $YJS$ __";function Lo(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&&Fo(e.charCodeAt(r-1))&&Bo(e.charCodeAt(r))&&n--,n}if(s.content.size||i.content.size){let e=Lo(s.content,i.content,n+1);if(null!=e)return e}n+=s.nodeSize}else n+=s.nodeSize}}function zo(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&&Fo(e.charCodeAt(s-1))&&Bo(e.charCodeAt(s))&&(n++,r++),{a:n,b:r}}if(o.content.size||l.content.size){let e=zo(o.content,l.content,n-1,r-1);if(e)return e}n-=a,r-=a}else n-=a,r-=a}}function Bo(e){return e>=56320&&e<57344}function Fo(e){return e>=55296&&e<56320}Io[Po],Io[Po]=!0;var Vo=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 Lo(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return zo(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)":""))}};Vo.empty=new Vo([],0);var Wo={index:0,offset:0};function Ho(e,t){return Wo.index=e,Wo.offset=t,Wo}function qo(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(!qo(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!qo(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Uo=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&&qo(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}};Uo.none=[];var Jo=class extends Error{},Ko=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=Xo(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(Go(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(Vo.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 Go(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(Go(i.content,t-s-1,n-s-1)))}function Xo(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=Xo(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))}Ko.empty=new Ko(Vo.empty,0,0);var Yo=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Zo(t,n);if(null==r.next)return e.empty;let s=Qo(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]);il(e,n).forEach(e=>{r||s.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)})})});let i=t[r.join(",")]=new Yo(r.indexOf(e.length-1)>-1);for(let e=0;e<s.length;e++){let r=s[e][1].sort(sl);i.next.push({type:s[e][0],next:t[r.join(",")]||n(r)})}return i}(il(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 Vo.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")}};Yo.empty=new Yo(!0);var Zo=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 Qo(e){let t=[];do{t.push(el(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function el(e){let t=[];do{t.push(tl(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function tl(e){let t=function(e){if(e.eat("(")){let t=Qo(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=rl(e,t)}return t}function nl(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function rl(e,t){let n=nl(e),r=n;return e.eat(",")&&(r="}"!=e.next?nl(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function sl(e,t){return t-e}function il(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(sl)}var ol=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 ul(this,t,!1);return n.addAll(e,Uo.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ul(this,t,!0);return n.addAll(e,Uo.none,t.from,t.to),Ko.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(pl(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=ml(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=ml(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)))}},ll={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},al={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},cl={ol:!0,ul:!0};function dl(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}var hl=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=Uo.none,this.match=s||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Vo.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=Vo.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Vo.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&&!ll.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ul=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=dl(null,t.preserveWhitespace,0)|(n?4:0);r=s?new hl(s.type,s.attrs,Uo.none,!0,t.topMatch||s.type.contentMatch,i):new hl(n?null:e.schema.topNodeType,null,Uo.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();cl.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&&cl.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:al.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(ll.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=Uo.none;for(let s of r.concat(e.marks))(t.type?t.type.allowsMarkType(s.type):fl(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=dl(e,s,i.options);4&i.options&&0==i.content.length&&(o|=4);let l=Uo.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):fl(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new hl(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 pl(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ml(e){let t={};for(let n in e)t[n]=e[n];return t}function fl(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 gl=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=bl(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 bl(t).createTextNode(e.text);let{dom:n,contentDOM:r}=vl(bl(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(bl(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=xl(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return xl(e.marks)}};function xl(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function bl(e){return e.document||window.document}var yl=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=yl.get(e);return void 0===t&&yl.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 wl=Math.pow(2,16);function kl(e,t){return e+t*wl}function Sl(e){return 65535&e}var jl=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}},Cl=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))/wl}(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:kl(o/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new jl(s,h,i)}r+=c-a}return n?e+r:new jl(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])}};Cl.empty=new Cl([]);var Nl=Object.create(null),El=class{getMap(){return Cl.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=Nl[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 Nl)throw new RangeError("Duplicate use of step JSON ID "+e);return Nl[e]=t,t.prototype.jsonID=e,t}},Al=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(lu){if(lu instanceof Jo)return e.fail(lu.message);throw lu}}};function Tl(e,t,n){let r=[];for(let s=0;s<e.childCount;s++){let i=e.child(s);i.content.size&&(i=i.copy(Tl(i.content,t,i))),i.isInline&&(i=t(i,n,s)),r.push(i)}return Vo.fromArray(r)}var Ml=class e extends El{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 Ko(Tl(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 Al.fromReplace(e,this.from,this.to,s)}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:"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))}};El.jsonID("addMark",Ml);var _l=class e extends El{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 Ko(Tl(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Al.fromReplace(e,this.from,this.to,n)}invert(){return new Ml(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))}};El.jsonID("removeMark",_l);var Dl=class e extends El{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Al.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.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 Ol(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))}};El.jsonID("addNodeMark",Dl);var Ol=class e extends El{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Al.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Dl(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))}};El.jsonID("removeNodeMark",Ol);var $l=class e extends El{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Il(e,this.from,this.to)?Al.fail("Structure replace would overwrite content"):Al.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Cl([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?Ko.empty:new Ko(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?Ko.empty:new Ko(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,Ko.fromJSON(t,n.slice),!!n.structure)}};$l.MAP_BIAS=1,El.jsonID("replace",$l);var Rl=class e extends El{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&&(Il(e,this.from,this.gapFrom)||Il(e,this.gapTo,this.to)))return Al.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Al.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Al.fromReplace(e,this.from,this.to,n):Al.fail("Content does not fit in gap")}getMap(){return new Cl([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,Ko.fromJSON(t,n.slice),n.insert,!!n.structure)}};function Il(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}El.jsonID("replaceAround",Rl),El.jsonID("attr",class e extends El{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 Al.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 Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.from(r),0,t.isLeaf?0:1))}getMap(){return Cl.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)}}),El.jsonID("docAttr",class e extends El{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 Al.ok(n)}getMap(){return Cl.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 Pl=Error;((Pl=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype)).constructor=Pl,Pl.prototype.name="TransformError";var Ll=Object.create(null),zl=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Bl(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=Ko.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?Ko.empty:t),0==o&&Xl(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),Xl(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new Wl(e):Gl(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?Gl(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Gl(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 Jl(e.node(0))}static atStart(e){return Gl(e,e,0,0,1)||new Jl(e)}static atEnd(e){return Gl(e,e,e.content.size,e.childCount,-1)||new Jl(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Ll[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 Ll)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ll[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Wl.between(this.$anchor,this.$head).getBookmark()}};zl.prototype.visible=!0;var Bl=class{constructor(e,t){this.$from=e,this.$to=t}},Fl=!1;function Vl(e){Fl||e.parent.inlineContent||(Fl=!0)}var Wl=class e extends zl{constructor(e,t=e){Vl(e),Vl(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 zl.near(r);let s=t.resolve(n.map(this.anchor));return new e(s.parent.inlineContent?s:r,r)}replace(e,t=Ko.empty){if(super.replace(e,t),t==Ko.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=zl.findFrom(n,r,!0)||zl.findFrom(n,-r,!0);if(!e)return zl.near(n,r);n=e.$head}return t.parent.inlineContent||(0==s||(t=(zl.findFrom(t,-r,!0)||zl.findFrom(t,r,!0)).$anchor).pos<n.pos!=s<0)&&(t=n),new e(t,n)}};zl.jsonID("text",Wl);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 Wl.between(e.resolve(this.anchor),e.resolve(this.head))}},ql=class e extends zl{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?zl.near(i):new e(i)}content(){return new Ko(Vo.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 Ul(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}};ql.prototype.visible=!1,zl.jsonID("node",ql);var Ul=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&&ql.isSelectable(n)?new ql(t):zl.near(t)}},Jl=class e extends zl{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Ko.empty){if(t==Ko.empty){e.delete(0,e.doc.content.size);let t=zl.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 Kl}};zl.jsonID("all",Jl);var Kl={map(){return this},resolve:e=>new Jl(e)};function Gl(e,t,n,r,s,i=!1){if(t.inlineContent)return Wl.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&&ql.isSelectable(r))return ql.create(e,n-(s<0?r.nodeSize:0))}else{let t=Gl(e,r,n+s,s<0?r.childCount:0,s,i);if(t)return t}n+=r.nodeSize*s}return null}function Xl(e,t,n){let r=e.steps.length-1;if(r<t)return;let s,i=e.steps[r];(i instanceof $l||i instanceof Rl)&&(e.mapping.maps[r].forEach((e,t,n,r)=>{s??=r}),e.setSelection(zl.near(e.doc.resolve(s),n)))}function Yl(e,t){return t&&e?e.bind(t):e}var Zl=class{constructor(e,t,n){this.name=e,this.init=Yl(t.init,n),this.apply=Yl(t.apply,n)}};function Ql(e,t,n){for(let r in e){let s=e[r];s instanceof Function?s=s.bind(t):"handleDOMEvents"==r&&(s=Ql(s,t,{})),n[r]=s}return n}new Zl("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Zl("selection",{init:(e,t)=>e.selection||zl.atStart(t.doc),apply:e=>e.selection}),new Zl("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new Zl("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});var ea=class{constructor(e){this.spec=e,this.props={},e.props&&Ql(e.props,this,this.props),this.key=e.key?e.key.key:na("plugin")}getState(e){return e[this.key]}},ta=Object.create(null);function na(e){return e in ta?e+"$"+ ++ta[e]:(ta[e]=0,e+"$")}var ra=class{constructor(e="key"){this.key=na(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},sa=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},ia=function(e,t,n,r){return n&&(la(e,t,n,r,-1)||la(e,t,n,r,1))},oa=/^(img|br|input|textarea|hr)$/i;function la(e,t,n,r,s){for(var i;;){if(e==n&&t==r)return!0;if(t==(s<0?0:aa(e))){let n=e.parentNode;if(!n||1!=n.nodeType||ca(e)||oa.test(e.nodeName)||"false"==e.contentEditable)return!1;t=sa(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?aa(e):0}}}}function aa(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ca(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 da=function(e){return e.focusNode&&ia(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ha(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}var ua="undefined"!=typeof navigator?navigator:null,pa="undefined"!=typeof document?document:null,ma=ua&&ua.userAgent||"",fa=/Edge\/(\d+)/.exec(ma),ga=/MSIE \d/.exec(ma),xa=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ma),ba=!!(ga||xa||fa),ya=ga?document.documentMode:xa?+xa[1]:fa?+fa[1]:0,va=!ba&&/gecko\/(\d+)/i.test(ma);va&&(/Firefox\/(\d+)/.exec(ma)||[0,0])[1];var wa=!ba&&/Chrome\/(\d+)/.exec(ma),ka=!!wa,Sa=wa?+wa[1]:0,ja=!ba&&!!ua&&/Apple Computer/.test(ua.vendor),Ca=ja&&(/Mobile\/\w+/.test(ma)||!!ua&&ua.maxTouchPoints>2),Na=Ca||!!ua&&/Mac/.test(ua.platform),Ea=!!ua&&/Win/.test(ua.platform),Aa=/Android \d/.test(ma),Ta=!!pa&&"webkitFontSmoothing"in pa.documentElement.style,Ma=Ta?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,_a=function(e){e&&(this.nodeName=e)};function Da(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 Oa(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof ql){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(La(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else La(e)}(e,n),!Da(e))return;let r=e.input.mouseDown;if(!t&&ka&&r){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&ia(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,sa(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&ba&&ya<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let r,s,{anchor:i,head:o}=n;!$a||n instanceof Wl||(n.$from.parent.inlineContent||(r=Ra(e,n.from)),n.empty||n.$from.parent.inlineContent||(s=Ra(e,n.to))),e.docView.setSelection(i,o,e,t),$a&&(r&&Pa(r),s&&Pa(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(()=>{Da(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}_a.prototype=Object.create(null),new _a;var $a=ja||ka&&Sa<63;function Ra(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(ja&&s&&"false"==s.contentEditable)return Ia(s);if(!(s&&"false"!=s.contentEditable||i&&"false"!=i.contentEditable)){if(s)return Ia(s);if(i)return Ia(i)}}function Ia(e){return e.contentEditable="true",ja&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function Pa(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function La(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function za(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||Wl.between(t,n,r)}function Ba(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&&zl.findFrom(i,t)}function Fa(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Va(e,t,n){let r=e.state.selection;if(!(r instanceof Wl)){if(r instanceof ql&&r.node.isInline)return Fa(e,new Wl(t>0?r.$to:r.$from));{let n=Ba(e.state,t);return!!n&&Fa(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 Fa(e,new Wl(r.$anchor,i))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ba(e.state,t);return!!(n&&n instanceof ql)&&Fa(e,n)}if(!(Na&&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)&&(ql.isSelectable(i)?Fa(e,new ql(t<0?e.state.doc.resolve(s.pos-i.nodeSize):s)):!!Ta&&Fa(e,new Wl(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}function Wa(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 qa(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<Wa(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(Ua(n))break;{let t=n.previousSibling;for(;t&&Ha(t,-1);)s=n.parentNode,i=sa(t),t=t.previousSibling;if(t)n=t,r=Wa(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}o?Ja(e,n,r):s&&Ja(e,s,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=Wa(n);for(;;)if(r<o){if(1!=n.nodeType)break;if(!Ha(n.childNodes[r],1))break;s=n,i=++r}else{if(Ua(n))break;{let t=n.nextSibling;for(;t&&Ha(t,1);)s=t.parentNode,i=sa(t)+1,t=t.nextSibling;if(t)n=t,r=0,o=Wa(n);else{if(n=n.parentNode,n==e.dom)break;r=o=0}}}s&&Ja(e,s,i)}(e)}function Ua(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Ja(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!ca(e);)t=sa(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&&!ca(e);)t=sa(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(da(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&&Oa(e)},50)}function Ka(e,t){let n=e.state.doc.resolve(t);if(!ka&&!Ea&&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 Ga(e,t,n){let r=e.state.selection;if(r instanceof Wl&&!r.empty||n.indexOf("s")>-1)return!1;if(Na&&n.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ba(e.state,t);if(n&&n instanceof ql)return Fa(e,n)}if(!s.parent.inlineContent){let n=t<0?s:i,o=r instanceof Jl?zl.near(n,t):zl.findFrom(n,t);return!!o&&Fa(e,o)}return!1}function Xa(e,t){if(!(e.state.selection instanceof Wl))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 Ya(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Za(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")||gl.fromSchema(e.state.schema),l=lc(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=oc[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 Qa(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 Ko(Vo.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=gl.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=lc(),s=r.body,i=/<([a-z][^>\s]+)/i.exec(e);if((n=i&&oc[i[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),s.innerHTML=function(e){let t=window.trustedTypes;if(!t)return e;if(!ac){if(ac=t.defaultPolicy)try{return ac.createHTML(e)}catch(n){}ac=t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})}return ac.createHTML(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),Ta&&function(e){let t=e.querySelectorAll(ka?"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")||ol.fromSchema(e.state.schema)).parseSlice(i,{preserveWhitespace:!(!a&&!d),context:s,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||ec.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(lu){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;try{e.checkAttrs(n[l+1])}catch(lu){break}s=Vo.from(e.create(n[l+1],s)),i++,o++}return new Ko(s,i,o)}(ic(o,+d[1],+d[2]),d[4]);else if(o=Ko.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&&nc(n,r,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=rc(i[i.length-1],r.length));let t=tc(e,n);i.push(t),s=s.matchType(t.type),r=n}}),i)return Vo.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=ic(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,a)}),o}var ec=/^(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 tc(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Vo.from(e));return e}function nc(e,t,n,r,s){if(s<e.length&&s<t.length&&e[s]==t[s]){let i=nc(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(Vo.from(tc(n,e,s+1))))}}function rc(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,rc(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Vo.empty,!0);return e.copy(n.append(r))}function sc(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=sc(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(Vo.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(l))}function ic(e,t,n){return t<e.openStart&&(e=new Ko(sc(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Ko(sc(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var oc={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 lc(){return document.implementation.createHTMLDocument("title")}var ac=null,cc={},dc={};function hc(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function uc(e){return{left:e.clientX,top:e.clientY}}function pc(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 mc(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 fc(e,t,n,r){return pc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}function gc(e,t,n,r){return pc(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=xc(e,t,!0),s=e.state.doc;return!!r&&(mc(e,r,"pointer"),r instanceof Wl&&s.eq(e.state.doc)&&(e.input.mouseDown=new kc(e,r)),!0)}(e,n,r)}function xc(e,t,n){let r=e.state.doc;if(-1==t)return r.inlineContent?Wl.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 Wl.create(r,t+1,t+1+e.content.size);if(n&&ql.isSelectable(e))return ql.create(r,t)}return null}function bc(e){return Nc(e)}dc.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(),!Aa||!ka||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Ca||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||Na&&72==n&&"c"==r)return Xa(e,-1)||qa(e,-1);if(46==n&&!t.shiftKey||Na&&68==n&&"c"==r)return Xa(e,1)||qa(e,1);if(13==n||27==n)return!0;if(37==n||Na&&66==n&&"c"==r){let t=37==n?"ltr"==Ka(e,e.state.selection.from)?-1:1:-1;return Va(e,t,r)||qa(e,t)}if(39==n||Na&&70==n&&"c"==r){let t=39==n?"ltr"==Ka(e,e.state.selection.from)?1:-1:1;return Va(e,t,r)||qa(e,t)}return 38==n||Na&&80==n&&"c"==r?Ga(e,-1,r)||qa(e,-1):40==n||Na&&78==n&&"c"==r?function(e){if(!ja||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;Ya(e,n,"true"),setTimeout(()=>Ya(e,n,"false"),20)}return!1}(e)||Ga(e,1,r)||qa(e,1):r==(Na?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():hc(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,ha(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},dc.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},dc.keypress=(e,t)=>{let n=t;if(Sc(e)||!n.charCode||n.ctrlKey&&!n.altKey||Na&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof Wl&&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 yc=Na?"metaKey":"ctrlKey";cc.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=bc(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[yc]&&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(uc(n));o&&("singleClick"==i?e.input.mouseDown=new wc(e,o,n,!!r):("doubleClick"==i?fc:gc)(e,o.pos,o.inside,n)?n.preventDefault():hc(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}},wc=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[yc],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 ql&&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()),hc(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||Oa(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(uc(e))),this.updateAllowDefault(e),this.allowDefault||!t?hc(this.view,"pointer"):function(e,t,n,r,s){return pc(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 ql&&(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(ql.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&&(mc(e,ql.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&&ql.isSelectable(r))&&(mc(e,new ql(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||ja&&this.mightDrag&&!this.mightDrag.node.isAtom||ka&&!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)?(mc(this.view,zl.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):hc(this.view,"pointer")}move(e){this.updateAllowDefault(e),hc(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)}},kc=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(),hc(this.view,"pointer");let t=this.view.posAtCoords(uc(e)),n=t&&xc(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];mc(this.view,Wl.create(r,i,o),"pointer")}};function Sc(e,t){return!!e.composing||!!(ja&&Math.abs(Date.now()-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}cc.touchstart=e=>{e.input.lastTouch=Date.now(),bc(e),hc(e,"pointer")},cc.touchmove=e=>{e.input.lastTouch=Date.now(),hc(e,"pointer")},cc.contextmenu=e=>bc(e);var jc=Aa?5e3:-1;function Cc(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Nc(e),t))}function Nc(e,t=!1){if(!(Aa&&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(da(n)){for(l=o;s&&!s.node;)s=s.parent;let e=s.node;if(s&&e.isAtom&&ql.isSelectable(e)&&s.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,s=t==aa(e);r||s;){if(e==n)return!0;let t=sa(e);if(!(e=e.parentNode))return!1;r=r&&0==t,s=s&&t==aa(e)}}(n.focusNode,n.focusOffset,s.dom))){let e=s.posBefore;a=new ql(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=za(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}}dc.compositionstart=dc.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof Wl&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ka&&Ea&&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(),Nc(e,!0),e.markCursor=null;else if(Nc(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}Cc(e,jc)},dc.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++,Cc(e,20))};var Ec=ba&&ya<15||Ca&&Ma<604;function Ac(e,t,n,r,s){let i=Qa(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,s,i||Ko.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 Tc(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," "):""}cc.copy=dc.cut=(e,t)=>{let n=t,r=e.state.selection,s="cut"==n.type;if(r.empty)return;let i=Ec?null:n.clipboardData,{dom:o,text:l}=Za(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"))},dc.paste=(e,t)=>{let n=t;if(e.composing&&!Aa)return;let r=Ec?null:n.clipboardData,s=e.input.shiftKey&&45!=e.input.lastKeyCode;r&&Ac(e,Tc(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?Ac(e,r.value,null,s,t):Ac(e,r.textContent,r.innerHTML,s,t)},50)}(e,n)};var Mc=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},_c=Na?"altKey":"ctrlKey";function Dc(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[_c]}cc.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(uc(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof ql?i.to-1:i.to));else if(r&&r.mightDrag)s=ql.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=ql.create(e.state.doc,t.posBefore))}let{dom:l,text:a,slice:c}=Za(e,(s||e.state.selection).content());(!n.dataTransfer.files.length||!ka||Sa>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Ec?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Ec||n.dataTransfer.setData("text/plain",a),e.dragging=new Mc(c,Dc(e,n),s)},cc.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},dc.dragover=dc.dragenter=(e,t)=>t.preventDefault(),dc.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(uc(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=Qa(e,Tc(t.dataTransfer),Ec?null:t.dataTransfer.getData("text/html"),!1,s);let o=!(!n||!Dc(e,t));if(e.someProp("handleDrop",n=>n(e,t,i||Ko.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&&ql.isSelectable(i.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new ql(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(za(e,u,a.doc.resolve(t)))}e.focus(),e.dispatch(a.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},cc.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Oa(e)},20))},cc.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)},cc.beforeinput=(e,t)=>{if(Aa&&"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,ha(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 au in dc)cc[au]=dc[au];function Oc(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 $c=class e{constructor(e,t){this.toDOM=e,this.spec=t||zc,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 Pc(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&&Oc(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Rc=class e{constructor(e,t){this.attrs=e,this.spec=t||zc}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 Pc(s,i,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&Oc(this.attrs,t.attrs)&&Oc(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},Ic=class e{constructor(e,t){this.attrs=e,this.spec=t||zc}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 Pc(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&&Oc(this.attrs,t.attrs)&&Oc(this.spec,t.spec)}destroy(){}},Pc=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 $c(n,r))}static inline(t,n,r,s){return new e(t,n,new Rc(r,s))}static node(t,n,r,s){return new e(t,n,new Ic(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Rc}get widget(){return this.type instanceof $c}},Lc=[],zc={},Bc=class e{constructor(e,t){this.local=e.length?e:Lc,this.children=t.length?t:Lc}static create(e,t){return t.length?Uc(t,e,0,zc):Fc}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==Fc||0==e.maps.length?this:this.mapInner(e,t,0,0,n||zc)}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!=Fc?(l[c]=d,l[c+1]=h,l[c+2]=r):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=Uc(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 Bc(t.sort(Jc),l)}(this.children,o||[],t,n,r,s,i):o?new e(o.sort(Jc),Lc):Fc}add(t,n){return n.length?this==Fc?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,Uc(o,e,l+1,zc)),i+=3}});let o=Wc(i?qc(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(Jc):this.local,s||this.children)}remove(e){return 0==e.length||this==Fc?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!=Fc?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):Fc}forChild(t,n){if(this==Fc)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 Rc){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(Jc),Lc);return r?new Vc([t,r]):t}return r||Fc}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 Kc(this.localsInner(e))}localsInner(e){if(this==Fc)return Lc;if(e.inlineContent||!this.local.some(Rc.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Rc||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Bc.empty=new Bc([],[]),Bc.removeOverlap=Kc;var Fc=Bc.empty,Vc=class e{constructor(e){this.members=e}map(t,n){const r=this.members.map(e=>e.map(t,n,zc));return e.from(r)}forChild(t,n){if(n.isLeaf)return Bc.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(t,n);i!=Fc&&(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?Kc(n?t:t.sort(Jc)):Lc}static from(t){switch(t.length){case 0:return Fc;case 1:return t[0];default:return new e(t.every(e=>e instanceof Bc)?t:t.reduce((e,t)=>e.concat(t instanceof Bc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Wc(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 Pc(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 qc(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function Uc(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=Uc(l,t,n+o+1,r);e!=Fc&&s.push(o,o+t.nodeSize,e)}});let o=Wc(i?qc(e):e,-n).sort(Jc);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 Bc(o,s):Fc}function Jc(e,t){return e.from-t.from||e.to-t.to}function Kc(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),Gc(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),Gc(t,s+1,i.copy(r.to,i.to)))}}return t}function Gc(e,t,n){for(;t<e.length&&Jc(n,e[t])>0;)t++;e.splice(t,0,n)}var Xc=/[\uD800-\uDBFF]/,Yc=/[\uDC00-\uDFFF]/,Zc=(e,t)=>e>>>t|e<<32-t,Qc=e=>Zc(e,2)^Zc(e,13)^Zc(e,22),ed=e=>Zc(e,6)^Zc(e,11)^Zc(e,25),td=e=>Zc(e,7)^Zc(e,18)^e>>>3,nd=e=>Zc(e,17)^Zc(e,19)^e>>>10,rd=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]),sd=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),id=class{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(sd),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=nd(t[d-2])+t[d-7]+td(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+ed(o)+(o&l^~o&a)+rd[u]+t[u]>>>0,h=Qc(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}},od=new ra("y-sync"),ld=new ra("y-undo"),ad=(new ra("yjs-cursor"),e=>{return bn((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=it();return e(t),ot(t)})(t=>bt(t,e)))(e),(new id).digest(t))));var t}),cd=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Kr(t.ds,e.id),dd=[{light:"#ecd44433",dark:"#ecd444"}],hd=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=Me();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(r=t)[Le(qt()*r.length)])}var r;return e.get(n)},ud=(e,{colors:t=dd,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:s=()=>{},mapping:i}={})=>{let o=!1;const l=new fd(e,i),a=new ea({props:{editable:e=>{const t=od.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:od,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(od);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return e.docChanged&&(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||$r(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=ld.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)},od)})}},destroy:()=>{l.destroy()}})});return a},pd=(e,t,n,r)=>{if(null==n)return r;if(!(null===r||n>1&&r<=1||Wd(t,e,n,r)))return r;const s=Vd(t,e,n);return null!==s?s:r},md=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:"nodeRange"===n?t.selection.depth:void 0,anchor:Ld(t.selection.anchor,e.type,e.mapping),head:Ld(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},fd=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=md(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()&&(un&&null===this._domSelectionInView&&($r(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=Ar.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=As(Zr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(od,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Ko(Vo.from(e),0,0));t.setMeta(od,{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=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Ko(Vo.from(t),0,0));if(e){const t=Be(Fe(e.anchor,0),n.doc.content.size),r=Be(Fe(e.head,0),n.doc.content.size);n.setSelection(Wl.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(od,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,s=this.type;if(e||(e=Ts(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||Et(),r=new rs({gc:!1}),hs(r,t),t=Ts(r),hs(r,e),e=Ts(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[Is(e,s._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{Jr(r,e,e=>{})});const o=(e,t)=>{const r="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:r,type:e,color:hd(n.colorMapping,n.colors,r)}},l=bi(s,new Es(t.ds,e.sv)).map(n=>!n._item.deleted||cd(n._item,e)||cd(n._item,t)?xd(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 Ko(Vo.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(od,{isChangeOrigin:!0}))},od)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=od.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);Jr(t,t.deleteSet,e=>{if(e.constructor===Do){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=>gd(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 Ko(Vo.from(n),0,0));((e,t,n,r)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Jl(e.doc));else if("node"===t.type){const r=Bd(n.doc,n.type,t.anchor,n.mapping);null!==r&&e.setSelection(((e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?ql.create(e.doc,t):Wl.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=zl.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:i,depth:r});return t.ranges.length?t:Wl.near(e.doc.resolve(s))}catch(lu){return Wl.near(e.doc.resolve(s))}})(e,Bd(n.doc,n.type,t.anchor,n.mapping),Bd(n.doc,n.type,t.head,n.mapping),t.depth);null!==r&&e.setSelection(r)}else{let s=Bd(n.doc,n.type,t.anchor,n.mapping),i=Bd(n.doc,n.type,t.head,n.mapping);null!=r&&(s=pd(e.doc,r,t.absAnchor,s),i=pd(e.doc,r,t.absHead,i)),null===s&&(s=i),null===i&&(i=s),null!==s&&null!==i&&e.setSelection(Wl.between(e.doc.resolve(s),e.doc.resolve(i)))}})(s,this.beforeTransactionSelection,this,r),s=s.setMeta(od,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Ys}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{Id(this.doc,this.type,e,this),this.beforeTransactionSelection=md(this,this.prosemirrorView.state)},od)}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))}},gd=(e,t,n,r,s,i)=>{const o=n.mapping.get(e);if(void 0===o){if(e instanceof to)return xd(e,t,n,r,s,i);throw Nt()}return o},xd=(e,t,n,r,s,i)=>{const o=[],l=e=>{if(e instanceof to){const l=gd(e,t,n,r,s,i);null!==l&&o.push(l)}else{const l=(e._item.right?.content)?.type;l instanceof Zi&&!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=bd(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):bi(e,new Es(s.ds,r.sv)).forEach(l);try{const l=e.getAttributes(r);void 0!==r&&(cd(e._item,r)?cd(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(lu){return e.doc.transact(t=>{e._item.delete(t)},od),n.mapping.delete(e),null}},bd=(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,$d(n.attributes,t)))}}catch(lu){return e.doc.transact(t=>{e._item.delete(t)},od),null}return o},yd=(e,t)=>e instanceof Array?((e,t)=>{const n=new so,r=e.map(e=>({insert:e.text,attributes:Rd(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new to(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,kd(e).map(e=>yd(e,t))),t.mapping.set(n,e),n})(e,t),vd=e=>"object"==typeof e&&null!==e,wd=(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)&&wd(o,l)}return r},kd=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&&nn(e.attributes||{}).length===t[n].marks.length&&sn(e.attributes,(e,r)=>{const s=Od(r),i=t[n].marks;return!!i.find(e=>e.type.name===s)&&wd(e,i.find(e=>e.type.name===s)?.attrs)}))},jd=(e,t)=>{if(e instanceof to&&!(t instanceof Array)&&Pd(e,t)){const n=kd(t);return e._length===n.length&&wd(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>jd(e,n[t]))}return e instanceof so&&t instanceof Array&&Sd(e,t)},Cd=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Nd=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>r.mapping.delete(e)),e.delete(t,n))},Ed=(e,t,n,r,s,i)=>{if(r<s){const o=[];for(let e=r;e<s;e++)o.push(yd(n[e],i));e.insert(t,o)}},Ad=(e,t,n,r)=>t instanceof so&&n instanceof Array?(Sd(t,n)?r.mapping.set(t,n):_d(t,n,r),!0):!(!(t instanceof to)||n instanceof Array||!Pd(t,n)||(jd(t,n)?r.mapping.set(t,n):Id(e,t,n,r),0)),Td=(e,t,n,r,s,i,o,l,a)=>{const c=Be(i-s,l-o);for(let d=0;d<c;d++){const i=r[s+d],l=n[o+d];Ad(e,i,l,a)||(Nd(t,o+d,1,a),Ed(t,o+d,n,o+d,o+d+1,a))}Nd(t,o+c,i-s-c,a),Ed(t,o+c,n,o+c,l,a)},Md=(e,t,n)=>{const r=e.toArray(),s=kd(t),i=s.length,o=r.length,l=Be(o,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=r[a],t=s[a];if(Cd(n.mapping.get(e),t))d=!0;else if(!jd(e,t))break}for(;a+c<l;c++){const e=r[o-c-1],t=s[i-c-1];if(Cd(n.mapping.get(e),t))d=!0;else if(!jd(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},_d=(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 xo?t+=n.content.str:n.content instanceof po&&(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,Rd(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&&Xc.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&&Yc.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})))},Dd=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Od=e=>Dd.exec(e)?.[1]??e,$d=(e,t)=>{const n=[];for(const r in e)n.push(t.mark(Od(r),e[r]));return n},Rd=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const r=Te(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${ad(e.toJSON())}`:e.type.name]=e.attrs}}),n},Id=(e,t,n,r)=>{if(t instanceof to&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(t,n),t instanceof to){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=kd(n),i=s.length,o=t.toArray(),l=o.length,a=Be(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&&Cd(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 so&&t instanceof Array||e.yChild instanceof to&&!(t instanceof Array))}))return!1;let o=0,l=0;for(const a of i){Td(e,t,n,r,o,a.yIndex,l,a.pIndex,s);const i=n[a.pIndex];Ad(e,a.yChild,i,s),o=a.yIndex+1,l=a.pIndex+1}return Td(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(!Cd(r.mapping.get(e),t)){if(!jd(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(!Cd(r.mapping.get(e),t)){if(!jd(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 so&&a instanceof Array)Sd(n,a)||_d(n,a,r),c+=1;else{let s=n instanceof to&&Pd(n,a),i=h instanceof to&&Pd(h,u);if(s&&i){const e=Md(n,a,r),t=Md(h,u,r);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?s=!1:i=!1}s?(Id(e,n,a,r),c+=1):i?(Id(e,h,u,r),d+=1):(r.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[yd(a,r)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&o[0]instanceof so?(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(yd(s[t],r));t.insert(c,e)}},od)},Pd=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,Ld=(e,t,n)=>{if(0===e)return Cs(t,0,-1);let r=null===t._first?null:t._first.content.type;for(;null!==r&&t!==r;){if(r instanceof so){if(r._length>=e)return Cs(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 ks(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 ks(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 Et();if(0===e&&r.constructor!==so&&r!==t)return zd(r._item.parent,r._item)}return Cs(t,t._length,-1)},zd=(e,t)=>{let n=null,r=null;return null===e._item?r=vs(e):n=ys(e._item.id.client,e._item.id.clock),new ks(n,r,t.id)},Bd=(e,t,n,r)=>{const s=Ns(n,e);if(null===s||s.type!==t&&!ws(t,s.type._item))return null;let i=s.type,o=0;if(i.constructor===so)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 so)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 so)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=Ns(t,e);return null!==r&&r.type instanceof so&&null!==t.item&&n<=1})(e,n,l)?null:l},Fd=(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])},Vd=(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&&Fd(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)},Wd=(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||!Fd(s.parent.attrs,i.parent.attrs);if(o||l){const s=Vd(e,t,n);return null!==s&&s!==r}return!1},Hd=new Set(["paragraph"]);function qd(e){return!!e.getMeta(od)}function Ud(e,t){const n=od.getState(e);return Bd(n.doc,n.type,t,n.binding.mapping)||0}function Jd(e,t){const n=od.getState(e);return Ld(t,n.type,n.binding.mapping)}var Kd=class e extends x.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}}};x.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 Kd?e.yRelativePosition:null;if(qd(t)&&r)return{position:new Kd(Ud(n,r),r),mapResult:null};const s=(0,x.getUpdatedPosition)(e,t),i=s.position.position;return{position:new Kd(i,null!=r?r:Jd(n,i)),mapResult:s.mapResult}}(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>function(e,t){return new Kd(e,Jd(t,e))}(e,this.editor.state)},addCommands:()=>({undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ld.getState(t).undoManager.undoStack.length&&(!n||(e=>{const t=ld.getState(e).undoManager;if(null!=t)return t.undo(),!0})(t))),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ld.getState(t).undoManager.redoStack.length&&(!n||(e=>{const t=ld.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 ea({key:ld,state:{init:(r,s)=>{const i=od.getState(s);let o=n;if(!o){const n=i.doc,r=new Set(n?n._observers.get("destroy"):[]);o=new Ys(i.type,{trackedOrigins:new Set([od].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Do&&e.content instanceof No&&(e.content.type instanceof Zi||e.content.type instanceof to&&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=od.getState(r).binding,i=t.undoManager,o=i.undoStack.length>0,l=i.redoStack.length>0;return s?{undoManager:i,prevSel:md(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=od.getState(e.state),n=ld.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const r=t.binding;r&&n.meta.set(r,ld.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}=ld.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()}}},[ud(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new b.Plugin({key:new b.PluginKey("filterInvalidContent"),filterTransaction:t=>{if(!qd(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)||void 0===t||t.destroy()}}),!0}}})].filter(Boolean)}});function Gd(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 Xd=[{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 Yd(){const e=n.m$3(),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,g.useState)(!1),[c,d]=(0,g.useState)("note"),[h,u]=(0,g.useState)(""),[p,m]=(0,g.useState)("");(0,g.useEffect)(()=>{l&&(d(s||"note"),u(i||""),m(o||""))},[l,s,i,o]);const f=(0,g.useCallback)(()=>{t&&(t.chain().updateAttributes(n.q.name,{type:c,title:h,body:p}).focus().run(),a(!1))},[t,c,h,p]),x=(0,g.useCallback)(()=>{a(!1)},[]),b=(0,g.useCallback)(()=>{Gd(n.q.name,t)},[t]),v=(0,g.useCallback)(()=>t.isActive(n.q.name),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:v,children:(0,y.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,y.jsxs)(n.o$1,{onOpenChange:a,open:l,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{icon:"Pencil",tooltip:r("editor.callout.edit.title")})}),(0,y.jsxs)(n.h$1,{children:[(0,y.jsx)(n.m,{children:r("editor.callout.edit.title")}),(0,y.jsxs)("div",{className:"richtext-space-y-4 richtext-py-4",children:[(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.type")}),(0,y.jsxs)(n.R,{onValueChange:d,value:c,children:[(0,y.jsx)(n.B,{children:(0,y.jsx)(n.S,{className:"richtext-text-accent",placeholder:r("editor.callout.dialog.type.placeholder")})}),(0,y.jsx)(n.V$1,{children:Xd.map(e=>(0,y.jsx)(n.D$2,{value:e.value,children:r(`editor.callout.type.${e.value}`)},e.value))})]})]}),(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.title.label")}),(0,y.jsx)(n.i$1,{onChange:e=>u(e.target.value),placeholder:r("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.body.label")}),(0,y.jsx)(n.i$1,{onChange:e=>m(e.target.value),placeholder:r("editor.callout.dialog.body.placeholder"),type:"text",value:p})]})]}),(0,y.jsxs)(n.n$2,{children:[(0,y.jsx)(n.x$1,{onClick:x,variant:"outline",children:r("editor.callout.dialog.button.cancel")}),(0,y.jsx)(n.x$1,{onClick:f,children:r("editor.callout.dialog.button.apply")})]})]})]}),(0,y.jsx)(n.f$2,{action:b,icon:"Trash2",tooltip:r("editor.delete")})]})}):(0,y.jsx)(y.Fragment,{})}function Zd(){const e=n.m$3(),t=n.d$2(),{t:r}=n._(),s=(0,g.useCallback)(()=>t.isActive(n.A.name),[t]),i=(0,g.useCallback)(()=>Gd(n.A.name,t),[t]),o=(0,g.useCallback)(()=>t.chain().focus().addColBefore().run(),[t]),l=(0,g.useCallback)(()=>t.chain().focus().addColAfter().run(),[t]),a=(0,g.useCallback)(()=>t.chain().focus().deleteCol().run(),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:s,children:(0,y.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,y.jsx)(n.f$2,{action:o,icon:"ColumnAddLeft",tooltip:r("editor.table.menu.insertColumnBefore")}),(0,y.jsx)(n.f$2,{action:l,icon:"ColumnAddRight",tooltip:r("editor.table.menu.insertColumnAfter")}),(0,y.jsx)(n.f$2,{action:a,icon:"DeleteColumn",tooltip:r("editor.table.menu.deleteColumn")}),(0,y.jsx)(n.f$2,{action:i,icon:"Trash2",tooltip:r("editor.table.menu.delete_column")})]})}):(0,y.jsx)(y.Fragment,{})}function Qd(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$2[s]}),isActive:()=>e.isActive("image",{width:n.p$2[s]})}}))}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.updateImageGif({width:n.p$2[s]}),isActive:()=>e.isActive("image",{width:n.p$2[s]})}}))}function th(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 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?.setAlignImageGif?.(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?.setAlignImageMermaid?.(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?.setAlignImageDrawer?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ih(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 oh(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 lh=!1;function ah({editor:e,attrs:t,extension:r}){const[s,i]=(0,g.useState)(!1),o=(0,g.useRef)(null),l=(0,g.useRef)(null),{alt:a,align:c}=t,d=r?.options.upload;(0,g.useEffect)(()=>{s&&setTimeout(()=>{(async()=>{const e=document.querySelector("#easydrawer");e&&(o.current=new N.Editor(e,{wheelEventsEnabled:!1,disableZoom:!0}),l.current=(0,N.makeDropdownToolbar)(o.current),l.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(a)))})()},200)},[s]);const h=()=>{if(lh){for(;o.current.history.redoStackSize>0;)o.current.history.redo();lh=!1}else o.current.history.undo()};return(0,y.jsxs)(n.o$1,{onOpenChange:i,open:s,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{action:()=>i(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:"Edit Drawer"}),(0,y.jsxs)("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[(0,y.jsx)("div",{className:"richtext-size-full",id:"easydrawer"}),(0,y.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(!lh){for(;o.current.history.undoStackSize>0;)h();lh=!0}},onRedo:()=>{lh||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,y.jsx)(n.n$2,{children:(0,y.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 ch({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function dh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=n.Ht(s,n.ve.name),o=n.v(n.ve.name),l=(0,g.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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(ah,{attrs:i,editor:s,extension:o},`bubbleMenu-drawer-${t}`):(0,y.jsx)(ch,{editor:s,item:e},`bubbleMenu-drawer-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function hh({children:e,visible:t,toggleVisible:r}){const{t:s}=n._(),i=n.d$2(),[o,l]=(0,g.useState)(null);(0,g.useEffect)(()=>{n.l().then(l)},[]);const{text:a,macros:c}=n.Ht(i,n.Wt.name,{text:"",macros:""}),[d,h]=(0,g.useState)(decodeURIComponent(a||"")),[u,p]=(0,g.useState)(decodeURIComponent(c||""));(0,g.useEffect)(()=>{t&&(h(decodeURIComponent(a||"")),p(decodeURIComponent(c||"")))},[t]);const m=(0,g.useCallback)(()=>{i.chain().focus().setKatex({text:encodeURIComponent(d),macros:encodeURIComponent(u)}).run(),h(""),p(""),r(!1)},[i,d,u,r]),f=(0,g.useMemo)(()=>{if(!o)return d;try{return o.renderToString(d,{macros:n.Y(u||"")})}catch{return d}},[d,u,o]),x=(0,g.useMemo)(()=>`${d}`.trim()?f:null,[d,f]);return(0,y.jsxs)(n.o$1,{onOpenChange:r,open:t,children:[(0,y.jsx)(n.s,{asChild:!0,children:e}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:s("editor.formula.dialog.text")}),(0,y.jsx)("div",{style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,y.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,y.jsxs)("div",{className:"richtext-flex-1",children:[(0,y.jsx)(n.s$2,{className:"mb-[6px]",children:"Expression"}),(0,y.jsx)(n.i,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:e=>h(e.target.value),placeholder:"Text",required:!0,rows:10,value:d,style:{color:"var(--richtext-foreground)"}}),(0,y.jsx)(n.s$2,{className:"mb-[6px]",children:"Macros"}),(0,y.jsx)(n.i,{onChange:e=>p(e.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"var(--richtext-foreground)"}})]}),(0,y.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:x||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),(0,y.jsx)(n.n$2,{children:(0,y.jsx)(n.x$1,{onClick:m,type:"button",children:"Save changes"})})]})]})}function uh(){const e=n.m$3(),t=n.d$2(),[r,s]=(0,g.useState)(!1),i=(0,g.useCallback)(()=>t.isActive(n.Wt.name),[t]),o=(0,g.useCallback)(()=>Gd(n.Wt.name,t),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:i,children:(0,y.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,y.jsx)(hh,{toggleVisible:s,visible:r,children:(0,y.jsx)(n.f$2,{action:()=>s(!r),tooltip:"Edit",children:(0,y.jsx)(v.Pencil,{size:16})})}),(0,y.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,y.jsx)(v.Trash2,{size:16})})]})}):(0,y.jsx)(y.Fragment,{})}function ph(e){const{t:t}=n._();return(0,y.jsxs)("div",{className:"richtext-flex richtext-flex-nowrap",children:[(0,y.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,y.jsx)(n.f$2,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onEdit()}}),(0,y.jsx)(n.f$2,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onClear()}})]})}function mh(){const e=n.m$3(),t=n.d$2(),[r,s]=(0,g.useState)(!1),i=n.Ht(t,n.Fe.name)?.href,o=(0,g.useCallback)(({editor:e})=>e.isActive(n.Fe.name),[]),l=(0,g.useCallback)(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),s(!1)},[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:(0,y.jsx)(y.Fragment,{children:(0,y.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,y.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,y.jsx)(ph,{editor:t,link:i,onClear:l,onEdit:()=>{s(!0)}})})})}):(0,y.jsx)(y.Fragment,{})}function fh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentdisabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function gh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=(0,g.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()}}},...Qd(e,t),...th(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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(fh,{editor:s,item:e},`bubbleMenu-image-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function xh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=(0,g.useMemo)(()=>function(e,t){return[...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,E.deleteSelection)(t,n)}}}]}(s,t),[s,t,e]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(fh,{editor:s,item:e},`bubbleMenu-image-gif-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function bh(){const{t:e}=n._(),t=n.m$3(),r=n.d$2(),s=(0,g.useMemo)(()=>function(e,t){return[...oh(e,t),...ih(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,E.deleteSelection)(t,n)}}}]}(r,e),[r,e]);return t?(0,y.jsx)(k.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$1.name}(e))return i=!0,!1}),i},children:s?.length?(0,y.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,y.jsx)(fh,{editor:r,item:e},`bubbleMenu-video-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}var yh="graph TB\na--\x3eb",vh=({editor:e,attrs:t,extension:r})=>{const{alt:s,align:i}=t,[o,l]=(0,g.useState)(decodeURIComponent(s??yh)),[a,c]=(0,g.useState)(""),[d,h]=(0,g.useState)(!1),u=(0,g.useRef)(null),[p,m]=(0,g.useState)(null),f=r?.options.upload,x=(0,g.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,g.useEffect)(()=>{p&&d&&(p.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o))},[p,d]),(0,g.useEffect)(()=>{p&&d&&b(o)},[p,o]),(0,y.jsxs)(n.o$1,{onOpenChange:h,open:d,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:"Edit Mermaid"}),(0,y.jsx)("div",{ref:x,style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,y.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,y.jsx)(n.i,{autoFocus:!0,className:"richtext-flex-1",defaultValue:yh,onChange:e=>l(e.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"var(--richtext-foreground)"}}),(0,y.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,y.jsx)(n.n$2,{children:(0,y.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 wh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function kh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=n.Ht(s,n.O.name),o=n.v(n.O.name),l=(0,g.useMemo)(()=>function(e,t){return[...rh(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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(vh,{attrs:i,editor:s,extension:o},`bubbleMenu-mermaid-${t}`):(0,y.jsx)(wh,{editor:s,item:e},`bubbleMenu-mermaid-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function Sh({hiddenActions:e=[]}){const{t:t}=n._(),r=n.m$3(),s=n.d$2(),i=t=>e.includes(t);return r?(0,y.jsx)(k.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:({editor:e})=>(0,x.isActive)(e.view.state,n.ct.name),children:(0,y.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,y.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,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("addRowAbove")&&(0,y.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,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("mergeCells")&&(0,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("deleteTable")&&(0,y.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,y.jsx)(y.Fragment,{})}function jh(){const{t:e}=n._(),[t,r]=(0,g.useState)(!1),s=n.d$2(),i=(0,g.useMemo)(()=>n.a({t:e})?.[0]?.commands,[e]),o=(0,g.useMemo)(()=>i?.find(e=>e?.isActive?.(s))?.label,[s.state.selection.ranges,t,s,i,e]),l=(0,g.useMemo)(()=>i?.find(e=>e?.isActive?.(s)),[s.state.selection.ranges,t,s,i]);return(0,y.jsxs)(n.i$2,{modal:!0,onOpenChange:r,open:t,children:[(0,y.jsx)(n.o$2,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,y.jsx)(n.f$2,{dataState:!!o,tooltip:o||e("editor.paragraph.tooltip"),children:(0,y.jsx)(n.c,{name:l?.iconName||"Type"})})}),(0,y.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,y.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,y.jsxs)("div",{className:"!richtext-min-w-[16px]",children:[i&&(0,y.jsx)(v.Check,{size:16}),!o&&t.label===e("editor.paragraph.tooltip")&&!i&&(0,y.jsx)(v.Check,{size:16})]}),(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[t.iconName&&(0,y.jsx)(n.c,{className:"!richtext-mr-1 !richtext-text-lg",name:t.iconName}),t.label]})]},t.name)})})]})}function Ch(){const e=n.d$2();return(t=e)&&"function"==typeof t.commands.openAiMenu?(0,y.jsx)(n.f$2,{action:()=>e.commands.openAiMenu(),shortcutKeys:["mod","J"],tooltip:"Ask AI",children:(0,y.jsx)(v.Sparkles,{className:"richtext-size-4 richtext-text-violet-600"})}):null;var t}function Nh(){return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(Ch,{}),(0,y.jsx)(jh,{}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.h$4,{}),(0,y.jsx)(n.y$1,{}),(0,y.jsx)(n.d$1,{}),(0,y.jsx)(n.m$1,{}),(0,y.jsx)(n.Be,{}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.h$3,{}),(0,y.jsx)(n.M$1,{}),(0,y.jsx)(n.A$1,{})]})}function Eh({buttonBubble:e}){const t=n.d$2();return n.m$3()?(0,y.jsx)(k.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 b.TextSelection},children:e?(0,y.jsx)(y.Fragment,{children:e}):(0,y.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,y.jsx)(Nh,{})})}):(0,y.jsx)(y.Fragment,{})}function Ah(){const{t:e}=n._(),t=n.m$3(),r=n.d$2(),[s,i]=(0,g.useState)(!1),o=(0,g.useCallback)(({editor:e})=>e.isActive(n.k.name),[]),l=(0,g.useCallback)(()=>Gd(n.k.name,r),[r]);return t?(0,y.jsx)(k.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:(0,y.jsx)(y.Fragment,{children:s?(0,y.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,y.jsx)(n.T$2,{editor:r,onSetLink:e=>{r.commands.updateTweet({src:e}),i(!1)}})}):(0,y.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,y.jsx)(n.f$2,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{i(!0)}}),(0,y.jsx)(n.f$2,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):(0,y.jsx)(y.Fragment,{})}function Th(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 Mh(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 j.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 b.SelectionRange(i.resolve(c),i.resolve(d));s.push(p)}),s}var _h=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 Dh(e.resolve(this.anchor),e.resolve(this.head),this.depth)}},Dh=class e extends b.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=Mh(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 _h(this.anchor,this.head,this.depth)}};Dh.prototype.visible=!1;try{b.Selection.jsonID("nodeRange",Dh)}catch{}function Oh(e){return e instanceof Dh}x.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(!Oh(i)){const e=Dh.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(!Oh(i)){const e=Dh.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=Dh.create(s,0,s.content.size,t);return i.setSelection(o),n.dispatch(i),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Oh(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new b.Plugin({key:new b.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=Dh.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=Oh(r);if(e=!1,!t)return s?(e=!0,Th(r.ranges)):null;const{$from:i,$to:o}=r;if(!s&&i.sameParent(o))return null;const l=Mh(i,o,this.options.depth);return l.length?(e=!0,Th(l)):null}}})]}});var $h=[{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}],Rh={edges:["left","top"],threshold:12,strength:500};function Ih(e){return void 0===e||"left"===e?{...Rh}:"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}:{...Rh,...e}}function Ph(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 Lh(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function zh(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 Bh(e,t){let n="first"===t?e.firstElementChild:e.lastElementChild;for(;n;){const e=n.getBoundingClientRect();if(zh(e))return e;n="first"===t?n.nextElementSibling:n.previousElementSibling}return null}var Fh=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=Bh(s,"first"),o=Bh(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(...$h),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&&!Lh(i,r,n.allowedContainers))return null;const a=r>0?i.node(r-1):null,c=r>0?i.index(r-1):0,d=Ph({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=Lh(i,c,n.allowedContainers)),p){const r=Ph({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?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 Vh(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 Wh(e){var t;null===(t=e.parentNode)||void 0===t||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=Fh({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 Mh(s.resolve(i.pos),s.resolve(i.pos+i.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}(e,t,n,r),d=Mh(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=Vh(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}(i,f);m.setAttribute("dir",x);const y=(null==n?void 0:n.enabled)&&(null==r?void 0:r.node),v=1===u.length;let w,k;y&&v?(w=i.state.doc.slice(f,g),k=b.NodeSelection.create(i.state.doc,f)):(k=Dh.create(i.state.doc,f,g),w=k.content());const S=function(e){return!e||!e.some(e=>{const t=e.trim().toLowerCase();return"margin"===t||t.startsWith("margin-")})}(s);u.forEach(e=>{const t=Vh(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);S&&(n.style.margin="0"),m.append(n)}),m.style.position="absolute",m.style.top="-10000px",document.body.append(m),e.dataTransfer.clearData();const j=function(e,t){return"rtl"===e?t:0}(x,m.getBoundingClientRect().width);e.dataTransfer.setDragImage(m,j,0);let C=!1;const N=()=>{C||(C=!0,Wh(m),document.removeEventListener("drop",N),document.removeEventListener("dragend",N))},E=k instanceof b.NodeSelection?k:void 0;i.dragging={slice:w,move:!0,node:E},p.setSelection(k),i.dispatch(p),document.addEventListener("drop",N),document.addEventListener("dragend",N)}var qh=(e,t)=>{const n=e.resolve(t),{depth:r}=n;return 0===r?t:n.pos-n.parentOffset-1},Uh=(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 Jh(e,t,n){let r=0;for(let s=t;s<n;s+=1)r+=e.child(s).nodeSize;return r}var Kh=(e,t)=>{const n=od.getState(e);return n?Ld(t,n.type,n.binding.mapping):null},Gh=(e,t)=>{const n=od.getState(e);return n?Bd(n.doc,n.type,t,n.binding.mapping)||0:-1},Xh=(e,t)=>{let n=t;for(;(null==n?void 0:n.parentNode)&&n.parentNode!==e.dom;)n=n.parentNode;return n},Yh=new b.PluginKey("dragHandle"),Zh=({pluginKey:e=Yh,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,y=null,v=null,w=null;function k(){v=null,w=null}function S(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function j(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,v=Oh(n)?{anchorPos:n.from,nodeCount:n.ranges.length,depth:null!==(s=n.depth)&&void 0!==s?s:0}:null,t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function N(e){a?.(e),v=null,S(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function E(e){if(!e.target||!r.view.dom.contains(e.target))return;if((0,x.isFirefox)()){const e=r.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable="false",e.contentEditable="true")})}if(!v||r.view.state.selection.empty)return;const t=r.state.selection.from,n=Kh(r.state,t);w={...v,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,y=null),k()}return h.appendChild(t),{unbind(){A()},plugin:new b.Plugin({key:"string"==typeof e?new b.PluginKey(e):e,state:{init:()=>({locked:!1}),apply(e,n,s,i){!function(e,t){w&&(w=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}}(w,e,{isChangeOrigin:qd(e),getAbsolutePos:e=>Gh(t,e)}))}(e,i);const l=e.getMeta("lockDragHandle"),a=e.getMeta("hideDragHandle");if(void 0!==l&&(p=l),a)return S(),p=!1,m=null,f=-1,o?.({editor:r,node:null,pos:-1}),n;if(e.docChanged&&-1!==f&&t)if(qd(e)){const e=Gh(i,u);e!==f&&(f=e)}else{const t=e.mapping.map(f);t!==f&&(f=t,u=Kh(i,f))}return n}},appendTransaction:(e,t,n)=>function(e){if(!w)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)+Jh(i,0,o);return{anchor:a,head:a+Jh(i,o,o+l),count:l}}(e,t,n,r);if(!s)return null;const i=Dh.create(e,s.anchor,s.head,r);return i.ranges.length===n?i:null}catch{return null}}(e.doc,w.anchorPos,w.nodeCount,w.depth);return t?(k(),e.tr.setSelection(t)):(w=null,v=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)||void 0===n||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 S();if(t.draggable=!p,e.state.doc.eq(s.doc)||-1===f)return;let i=e.nodeDOM(f);if(i=Xh(e,i),i===e.dom)return;if(1!==(null==i?void 0:i.nodeType))return;const l=e.posAtDOM(i,0),a=Uh(r.state.doc,l),c=qh(r.state.doc,l);m=a,f=c,u=Kh(e.state,f),o?.({editor:r,node:m,pos:f}),j(i)},destroy(){A(),t&&Wh(h)}}},props:{handleDOMEvents:{keydown:e=>!(!t||p||!e.hasFocus()||(S(),m=null,f=-1,o?.({editor:r,node:null,pos:-1}),1)),mouseleave:(e,t)=>(p||t.target&&!h.contains(t.relatedTarget)&&(S(),m=null,f=-1,o?.({editor:r,node:null,pos:-1})),!1),mousemove:(e,n)=>!(!t||p||(y={x:n.clientX,y:n.clientY},g||(g=requestAnimationFrame(()=>{if(g=null,!y)return;const{x:n,y:s}=y;y=null;const i=Fh({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=Xh(e,l),l===e.dom)return;if(1!==(null==l?void 0:l.nodeType))return;const t=e.posAtDOM(l,0);a=Uh(r.state.doc,t),d=qh(r.state.doc,t)}var h;a!==m&&(m=a,f=null!==(h=d)&&void 0!==h?h:-1,u=Kh(e.state,f),o?.({editor:r,node:m,pos:f}),j(l),t&&(r.isEditable?(t.style.visibility="",t.style.pointerEvents="auto"):S()))})),1))}}})}};function Qh(e){var t,n;return!1===e||void 0===e?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ih("none")}:!0===e?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ih("left")}:{enabled:!0,rules:null!==(t=e.rules)&&void 0!==t?t:[],defaultRules:null===(n=e.defaultRules)||void 0===n||n,allowedContainers:e.allowedContainers,edgeDetection:Ih(e.edgeDetection)}}var eu={placement:"left-start",strategy:"absolute"},tu=(x.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=Qh(this.options.nested);return[Zh({computePositionConfig:{...eu,...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=Yh,onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a,computePositionConfig:c=eu,nested:d=!1}=e,h=(0,g.useRef)(null);null===h.current&&"undefined"!=typeof document&&(h.current=document.createElement("div"));const u={onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a},p=(0,g.useRef)(u);p.current=u;const m=(0,g.useMemo)(()=>Qh(d),[JSON.stringify(d)]);(0,g.useEffect)(()=>{const e=h.current;e&&(e.className=t)},[t]),(0,g.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}=Zh({editor:r,element:e,pluginKey:s,computePositionConfig:{...eu,...c},onElementDragStart:e=>{var t,n;return null===(t=(n=p.current).onElementDragStart)||void 0===t?void 0:t.call(n,e)},onElementDragEnd:e=>{var t,n;return null===(t=(n=p.current).onElementDragEnd)||void 0===t?void 0:t.call(n,e)},onNodeChange:e=>{var t,n;return null===(t=(n=p.current).onNodeChange)||void 0===t?void 0:t.call(n,e)},getReferencedVirtualElement:()=>{var e,t,n;return null!==(e=null===(t=(n=p.current).getReferencedVirtualElement)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null},nestedOptions:m});return r.registerPlugin(t),()=>{r.isDestroyed||r.unregisterPlugin(s),n()}},[r,s,c,m]);const f=h.current;return f?(0,w.createPortal)(n,f):null});function nu(){const e=n.d$2(),t=n.m$3(),{t:r}=n._(),[s,i]=(0,g.useState)(null),[o,l]=(0,g.useState)(-1),[a,c]=(0,g.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,g.useCallback)(e=>{e.node&&i(e.node),l(e.pos),requestAnimationFrame(()=>{e.editor.commands.focus()})},[]);(0,g.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,y.jsx)(tu,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:m,pluginKey:"RichTextBubbleMenuDragHandle",children:(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,y.jsx)(n.f$2,{disabled:!t,icon:"Grip",tooltip:r("editor.draghandle.grip"),action:e=>{e.preventDefault(),e.stopPropagation(),f(!a)}}),(0,y.jsxs)(n.h$5,{onOpenChange:f,open:a,children:[(0,y.jsx)(n.x,{className:"richtext-pointer-events-none"}),(0,y.jsxs)(n.u$2,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[(0,y.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,y.jsx)(n.c,{name:"Trash2"}),(0,y.jsx)("span",{children:r("editor.remove")})]}),u?(0,y.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,y.jsx)(n.c,{name:"PaintRoller"}),(0,y.jsx)("span",{children:r("editor.clear.tooltip")})]}):null,(0,y.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,y.jsx)(n.c,{name:"Copy"}),(0,y.jsx)("span",{children:r("editor.copy")})]}),d||h?(0,y.jsx)(n.y$3,{}):null,d?(0,y.jsxs)(n.l$2,{children:[(0,y.jsxs)(n.p$1,{className:"richtext-flex richtext-gap-3",children:[(0,y.jsx)(n.c,{name:"AlignCenter"}),(0,y.jsx)("span",{children:r("editor.textalign.tooltip")})]}),(0,y.jsx)(n.n$5,{children:(0,y.jsxs)(n.f$1,{children:[(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("left"),children:[(0,y.jsx)(n.c,{name:"AlignLeft"}),(0,y.jsx)("span",{children:r("editor.textalign.left.tooltip")})]}),(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("center"),children:[(0,y.jsx)(n.c,{name:"AlignCenter"}),(0,y.jsx)("span",{children:r("editor.textalign.center.tooltip")})]}),(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("right"),children:[(0,y.jsx)(n.c,{name:"AlignRight"}),(0,y.jsx)("span",{children:r("editor.textalign.right.tooltip")})]})]})})]}):null,h?(0,y.jsxs)(n.l$2,{children:[(0,y.jsxs)(n.p$1,{className:"richtext-flex richtext-gap-3",children:[(0,y.jsx)(n.c,{name:"IndentIncrease"}),(0,y.jsx)("span",{children:r("editor.indent")})]}),(0,y.jsx)(n.n$5,{children:(0,y.jsxs)(n.f$1,{children:[(0,y.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,y.jsx)(n.c,{name:"IndentIncrease"}),(0,y.jsx)("span",{children:r("editor.indent.tooltip")})]}),(0,y.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,y.jsx)(n.c,{name:"IndentDecrease"}),(0,y.jsx)("span",{children:r("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}var ru={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function su({listLanguages:e}){const{t:t}=n._(),[r,s]=(0,g.useState)(!1),i=n.d$2(),o=(0,g.useMemo)(()=>{const{selection:e}=i.state,t=e.$from.parent;if("codeBlock"===t.type.name){const e=t.attrs.language||"plaintext";return ru[e]||e}},[i.state,e]),l=(0,g.useMemo)(()=>{let t=e||[];return e?.includes("plaintext")||(t=["plaintext",...t]),t.map(e=>({label:ru[e]||e,value:e}))},[e]);return(0,y.jsxs)(n.i$2,{modal:!0,onOpenChange:s,open:r,children:[(0,y.jsx)(n.o$2,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,y.jsxs)(n.f$2,{dataState:!!o,children:[(0,y.jsx)(y.Fragment,o?{children:o}:{children:t("editor.paragraph.tooltip")}),(0,y.jsx)(n.c,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),(0,y.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:l?.map(e=>(0,y.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,y.jsx)("div",{className:"!richtext-min-w-[20px]",children:o===e.value&&(0,y.jsx)(v.Check,{size:16})}),(0,y.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:e.label})]},e.value))})]})}function iu(){const e=n.m$3(),t=n.d$2(),r=n.v(n.M$2.name),s=(0,g.useCallback)(({editor:e})=>e.isActive(n.M$2.name),[]),i=(0,g.useMemo)(()=>r?r.options?.lowlight?.listLanguages?.()||["plaintext","html","css","js","ts"]:[],[r]),o=(0,g.useCallback)(()=>Gd(n.M$2.name,t),[t]);return e?(0,y.jsx)(k.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,y.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,y.jsx)(su,{listLanguages:i}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.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,y.jsx)(v.Copy,{size:16})}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,y.jsx)(v.Trash2,{size:16})})]})}):(0,y.jsx)(y.Fragment,{})}var ou=()=>(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(Yd,{}),(0,y.jsx)(Zd,{}),(0,y.jsx)(dh,{}),(0,y.jsx)(uh,{}),(0,y.jsx)(mh,{}),(0,y.jsx)(gh,{}),(0,y.jsx)(bh,{}),(0,y.jsx)(xh,{}),(0,y.jsx)(kh,{}),(0,y.jsx)(Sh,{}),(0,y.jsx)(Eh,{}),(0,y.jsx)(Ah,{}),(0,y.jsx)(iu,{}),(0,y.jsx)(nu,{}),(0,y.jsx)(n.D,{}),(0,y.jsx)(F,{})]});Object.defineProperty(exports,"BubbleMenus",{enumerable:!0,get:function(){return ou}}),Object.defineProperty(exports,"RichTextToolbar",{enumerable:!0,get:function(){return le}});
1
+ const e=require("./rolldown-runtime-BeavJI0R.cjs"),t=require("./dist-2-kjLBhJ.cjs"),n=require("./editorConfig-Nlnbb5zI.cjs"),r=require("./toggle-JU5XOZYT.cjs"),s=require("./locales-mNtGplJd.cjs"),i=require("./floating-ui.dom-DG-jWCyc.cjs"),o=require("./useButtonProps-DbMOdE1Q.cjs"),l=require("./theme.cjs"),a=require("./Ai-DVWZg0-D.cjs"),c=require("./Harper-C3DvE8Ft.cjs"),d=require("./Drawio-CoTNWfCf.cjs"),h=require("./ReadAloud.cjs"),u=require("./Transcribe.cjs"),p=require("./SelectSimilar.cjs"),m=require("./WordCount.cjs");let f=require("@tiptap/react"),g=require("react");g=e.__toESM(g,1);let x=require("@tiptap/core"),b=require("@tiptap/pm/state"),y=require("react/jsx-runtime"),v=require("lucide-react"),w=require("react-dom"),k=require("@tiptap/react/menus"),S=require("@tiptap/pm/view"),j=require("@tiptap/pm/model"),C=require("use-voice-control/react"),N=require("easydrawer"),E=require("@tiptap/pm/commands"),A=require("use-voice-control/client");function T({children:e,label:n,className:r,icon:s,shortcut:i}){const o=(0,g.useRef)(null),l=(0,g.isValidElement)(e)?(0,g.cloneElement)(e,{tooltip:n?void 0:e.props?.tooltip,tooltipOptions:n?void 0:e.props?.tooltipOptions}):e;return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:s}),(0,y.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[l,n&&(0,y.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:n}),i&&(0,y.jsx)("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 ml-auto whitespace-nowrap shrink-0",children:i})]})]})}function M(){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,y.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,y.jsx)(y.Fragment,{})}function _(){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,y.jsx)(r.ActionButton,{action:()=>{d||l&&(l(),h())},dataState:c,disabled:d,icon:t,shortcutKeys:s,tooltip:n,tooltipOptions:i}):(0,y.jsx)(y.Fragment,{})}function D({message:e}){const[t,n]=(0,g.useState)(!0);return(0,g.useEffect)(()=>{const e=setTimeout(()=>n(!1),2e3);return()=>clearTimeout(e)},[]),t?(0,w.createPortal)((0,y.jsx)("div",{className:"fixed bottom-4 right-4 z-[100] animate-in fade-in slide-in-from-bottom-2",children:(0,y.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 O(){const{editor:e}=(0,f.useCurrentEditor)(),[t,n]=(0,g.useState)(1.25),[r,s]=(0,g.useState)(null),i=e=>{s(e)},o=(0,g.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,g.useEffect)(()=>{o(t)},[o,t]),(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,y.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,y.jsx)(v.ZoomOut,{size:16})}),(0,y.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,y.jsx)(v.ZoomIn,{size:16})})]}),r&&(0,y.jsx)(D,{message:r})]})}var $={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 R(){const{editor:e}=(0,f.useCurrentEditor)(),[t,n]=(0,g.useState)(!1),[r,s]=(0,g.useState)("page"),[i,o]=(0,g.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,g.useRef)(null),a=(0,g.useRef)(null),[c,d]=(0,g.useState)({top:0,left:-9999,visibility:"hidden"});if((0,g.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,g.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,y.jsxs)("div",{className:"relative",ref:l,children:[(0,y.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,y.jsx)(v.Settings,{className:"w-4 h-4"}),(0,y.jsx)(v.ChevronDown,{className:"w-3 h-3"})]}),t&&(0,w.createPortal)((0,y.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,y.jsx)("div",{className:"flex border-b dark:border-gray-700 shrink-0",children:["page","spacing","header-footer"].map(e=>(0,y.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,y.jsxs)("div",{className:"flex-1 min-h-0 p-4 space-y-4 overflow-y-auto",children:["page"===r&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-2 text-gray-700 dark:text-gray-300",children:"Presets"}),(0,y.jsx)("div",{className:"grid grid-cols-4 gap-2",children:Object.entries($).map(([e,t])=>(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Height (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Width (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Page Gap (px)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Gap Border Color"}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.jsx)("input",{type:"color",value:i.pageGapBorderColor,onChange:e=>h({pageGapBorderColor:e.target.value}),className:"w-10 h-9 rounded cursor-pointer"}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Page Margins (px)"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Left"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Right"}),(0,y.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,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"block text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Content Margins (px)"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Top"}),(0,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs text-gray-600 dark:text-gray-400 mb-1",children:"Bottom"}),(0,y.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,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Header Left (supports HTML)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.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,y.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,y.jsxs)("div",{children:[(0,y.jsx)("label",{className:"block text-xs font-semibold mb-1 text-gray-700 dark:text-gray-300",children:"Footer Left (supports HTML)"}),(0,y.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,y.jsxs)("div",{children:[(0,y.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,y.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 I=[1,2,3,4];function P({editor:e,onClose:t,defaultLevel:n=3}){const[r,s]=(0,g.useState)([]),[i,o]=(0,g.useState)(""),[l,a]=(0,g.useState)(n),[c,d]=(0,g.useState)(null);(0,g.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,g.useMemo)(()=>{const e=i.trim().toLowerCase();return r.filter(t=>t.level<=l&&(""===e||t.text.toLowerCase().includes(e)))},[r,i,l]),u=(0,g.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,w.createPortal)((0,y.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,y.jsxs)("div",{className:"flex items-center justify-between border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)(v.ListTree,{size:15,className:"text-blue-500"}),(0,y.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:"Table of Contents"})]}),(0,y.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,y.jsx)(v.X,{size:14})})]}),(0,y.jsxs)("div",{className:"border-b border-gray-100 px-3 py-2 dark:border-slate-700",children:[(0,y.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,y.jsx)(v.Search,{size:13,className:"shrink-0 text-gray-400"}),(0,y.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,y.jsx)("button",{onClick:()=>o(""),className:"shrink-0 text-gray-400 hover:text-gray-600",title:"Clear filter",children:(0,y.jsx)(v.X,{size:12})})]}),(0,y.jsxs)("div",{className:"mt-2 flex items-center gap-1",children:[(0,y.jsx)("span",{className:"mr-1 text-[10px] font-semibold uppercase tracking-wide text-gray-400",children:"Level"}),I.map(e=>(0,y.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,y.jsx)("nav",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:0===h.length?(0,y.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,y.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 L({editor:e,className:n}){const[r,s]=(0,g.useState)(null),i=(0,g.useRef)(null),o=(0,g.useCallback)(()=>{i.current&&(clearTimeout(i.current),i.current=null)},[]),l=(0,g.useCallback)(()=>{o(),i.current=setTimeout(()=>s(null),120)},[o]),a=(0,g.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,g.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,y.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,y.jsx)("div",{className:"harper-tooltip-header",children:(0,y.jsx)("span",{className:"harper-tooltip-kind",children:d.kind})}),(0,y.jsx)("p",{className:"harper-tooltip-message",children:d.message}),(0,y.jsxs)("div",{className:"harper-tooltip-actions",children:[0===d.suggestions.length?(0,y.jsx)("span",{className:"harper-tooltip-empty",children:"No suggestions"}):d.suggestions.map((t,n)=>(0,y.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,y.jsx)("button",{type:"button",className:"harper-tooltip-ignore",onClick:()=>{e.chain().focus().ignoreHarperSuggestion(d.id).run(),s(null)},children:"Ignore"})]})]})}var z={status:"closed"};function B({icon:e,label:t,onClick:n,disabled:r,title:s}){return(0,y.jsxs)("button",{type:"button",disabled:r,onClick:n,title:s,className:"ai-menu-row",children:[(0,y.jsx)(e,{className:"ai-menu-row-icon"}),t]})}function F(){const e=o.useEditorInstance(),t=o.useEditableEditor(),n=(0,g.useRef)(null),r=(0,g.useRef)(null),[s,l]=(0,g.useState)(""),[c,d]=(0,g.useState)(-1),[h,u]=(0,g.useState)(null),[p,m]=(0,g.useState)(!1),[x,b]=(0,g.useState)(null),k=(0,f.useEditorState)({editor:e,selector:({editor:e})=>e?a.getAiState(e.state)?.panel??z:z}),S=(0,g.useMemo)(()=>"closed"===k.status?null:"reviewing"===k.status?{from:k.suggestion.from,to:k.suggestion.to}:{from:k.from,to:k.to},[k]),j="closed"!==k.status,C=!!S&&S.to>S.from,N=S?S.to-S.from:0,E=e?a.getAiOptions(e)?.commands??[]:[],A=s.trim().toLowerCase(),T=(0,g.useMemo)(()=>{const e=a.commandsForSelection(E,C);return A?e.filter(e=>`${e.label} ${e.description??""}`.toLowerCase().includes(A)):e},[E,A,C]),M=(0,g.useMemo)(()=>a.groupCommands(T),[T]);if((0,g.useEffect)(()=>{if("menu"===k.status){const e=requestAnimationFrame(()=>r.current?.focus());return()=>cancelAnimationFrame(e)}"closed"===k.status&&(l(""),u(null),d(-1),m(!1))},[k.status]),(0,g.useEffect)(()=>{d(e=>e>=T.length?T.length-1:e)},[T.length]),(0,g.useEffect)(()=>{if(!e||!S||!n.current)return void b(null);const t={getBoundingClientRect:()=>(0,f.posToDOMRect)(e.view,S.from,S.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,S?.from,S?.to,k]),(0,g.useEffect)(()=>{if(!j||!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=a.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)}},[j,e,h]),!(t&&e&&j&&x))return null;const _=t=>{t.options?.length?u(t):e.commands.runAiCommand(t.id)};return(0,w.createPortal)((0,y.jsxs)("div",{ref:n,role:"dialog","aria-label":"Ask AI",className:"ai-menu",style:{position:"fixed",top:x.y,left:x.x,zIndex:60},children:[(0,y.jsxs)("div",{className:"ai-menu-input-row",children:[(0,y.jsx)(v.Sparkles,{className:"ai-menu-input-icon"}),(0,y.jsx)("input",{ref:r,value:s,onChange:e=>{l(e.target.value),d(e.target.value.trim()?0:-1)},onKeyDown:t=>{if("ArrowDown"===t.key)return t.preventDefault(),void d(e=>T.length?(e+1)%T.length:-1);if("ArrowUp"===t.key)return t.preventDefault(),void d(e=>T.length?e<=0?T.length-1:e-1:-1);if("Enter"===t.key){t.preventDefault();const n=c>=0?T[c]: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"===k.status&&h&&(0,y.jsxs)("div",{className:"ai-menu-commands",children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>u(null),children:[(0,y.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),h.label]}),h.options?.map(t=>(0,y.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>{u(null),e.commands.runAiCommand(h.id,t.label)},children:(0,y.jsx)("span",{className:"ai-menu-command-text",children:(0,y.jsx)("span",{className:"ai-menu-command-label",children:t.label})})},t.id))]}),"menu"===k.status&&!h&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"ai-menu-hint",children:C?`${N.toLocaleString()} characters selected`:"Nothing selected — select text for rewrite actions"}),(0,y.jsxs)("div",{className:"ai-menu-commands",children:[0===M.length&&(0,y.jsx)("div",{className:"ai-menu-empty",children:"No matching actions"}),M.map(e=>(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"ai-menu-group-label",children:a.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>{const t=T.indexOf(e);return(0,y.jsxs)("button",{type:"button","data-active":t===c?"true":void 0,onMouseEnter:()=>d(t),onClick:()=>_(e),className:"ai-menu-command",children:[(0,y.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,y.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,y.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id)})]},e.group))]})]}),"loading"===k.status&&(0,y.jsxs)("div",{className:"ai-menu-loading",children:[(0,y.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,y.jsx)("span",{className:"ai-menu-loading-label",children:"Custom"===k.commandLabel?"Generating…":`${k.commandLabel}…`}),(0,y.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,y.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}),"error"===k.status&&(0,y.jsxs)("div",{className:"ai-menu-error",children:[(0,y.jsx)("p",{className:"ai-menu-error-message",children:k.message}),(0,y.jsxs)("div",{className:"ai-menu-review",children:[(0,y.jsx)(B,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,y.jsx)(B,{icon:v.X,label:"Dismiss",onClick:()=>e.commands.closeAiMenu()})]})]}),"reviewing"===k.status&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"ai-menu-preview","aria-live":"polite",children:k.suggestion.suggestedText||"…"}),k.suggestion.isStreaming?(0,y.jsxs)("div",{className:"ai-menu-loading",children:[(0,y.jsx)(v.Loader2,{className:"ai-menu-row-icon ai-menu-spin"}),(0,y.jsxs)("span",{className:"ai-menu-loading-label",children:[k.commandLabel,"…"]}),(0,y.jsxs)("button",{type:"button",className:"ai-menu-stop",onClick:()=>e.commands.stopAiGeneration(),children:[(0,y.jsx)(v.Square,{className:"ai-menu-row-icon"}),"Stop"]})]}):(0,y.jsxs)("div",{className:"ai-menu-review",children:[(0,y.jsx)(B,{icon:v.Check,label:"replace"===k.suggestion.mode?"Replace selection":"Insert",title:"⌘/Ctrl + Enter",onClick:()=>e.commands.acceptAiSuggestion()}),(0,y.jsx)(B,{icon:v.CornerDownRight,label:"Insert below",onClick:()=>e.commands.insertAiSuggestionBelow()}),(0,y.jsx)(B,{icon:v.RotateCcw,label:"Try again",onClick:()=>e.commands.retryAiSuggestion()}),(0,y.jsx)(B,{icon:v.Copy,label:p?"Copied":"Copy",onClick:()=>(async e=>{try{await navigator.clipboard.writeText(e),m(!0),setTimeout(()=>m(!1),1500)}catch{}})(k.suggestion.suggestedText)}),(0,y.jsx)(B,{icon:v.X,label:"Discard",onClick:()=>e.commands.discardAiSuggestion()})]})]})]}),document.body)}function V({editor:e,label:t="AI"}){const{editor:n}=o.useTiptapEditor(e),r=(0,g.useRef)(null),s=(0,g.useRef)(null),[l,c]=(0,g.useState)(!1),[d,h]=(0,g.useState)(null),[u,p]=(0,g.useState)(null),{hasSelection:m,isBusy:x}=(0,f.useEditorState)({editor:n,selector:({editor:e})=>{if(!e)return{hasSelection:!1,isBusy:!1};const t=a.getAiState(e.state)?.panel.status;return{hasSelection:!e.state.selection.empty,isBusy:"loading"===t||"reviewing"===t}}})??{hasSelection:!1,isBusy:!1},b=n?a.getAiOptions(n)?.commands??[]:[],k=(0,g.useMemo)(()=>a.groupCommands(a.commandsForSelection(b,m)),[b,m]);if((0,g.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,k.length,d]),(0,g.useEffect)(()=>{if(!l)return h(null),void p(null);const e=e=>{const t=e.target;s.current?.contains(t)||r.current?.contains(t)||c(!1)},t=e=>{"Escape"===e.key&&c(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l]),!a.isAiEnabled(n))return null;const S=(e,t)=>{!e.options?.length||t?(c(!1),n?.chain().focus().run(),n?.commands.runAiCommand(e.id,t)):h(e)};return(0,y.jsxs)(y.Fragment,{children:[(0,y.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:()=>c(e=>!e),children:[x?(0,y.jsx)(v.Loader2,{className:"ai-toolbar-icon ai-menu-spin"}):(0,y.jsx)(v.Sparkles,{className:"ai-toolbar-icon"}),t&&(0,y.jsx)("span",{className:"ai-toolbar-label",children:t}),(0,y.jsx)(v.ChevronDown,{className:"ai-toolbar-chevron"})]}),l&&(0,w.createPortal)((0,y.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:d?(0,y.jsxs)("div",{className:"ai-menu-commands",children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-row",onClick:()=>h(null),children:[(0,y.jsx)(v.ArrowLeft,{className:"ai-menu-row-icon"}),d.label]}),d.options?.map(e=>(0,y.jsx)("button",{type:"button",className:"ai-menu-command",onClick:()=>S(d,e.label),children:(0,y.jsx)("span",{className:"ai-menu-command-text",children:(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label})})},e.id))]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)("button",{type:"button",className:"ai-menu-command ai-menu-ask",onClick:()=>{c(!1),n?.chain().focus().run(),n?.commands.openAiMenu()},children:[(0,y.jsx)(v.Sparkles,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:"Ask AI anything…"}),(0,y.jsx)("span",{className:"ai-menu-command-description",children:"Write your own instruction"})]}),(0,y.jsx)("span",{className:"ai-menu-command-shortcut",children:"⌘J"})]}),(0,y.jsx)("div",{className:"ai-menu-hint",children:m?"Runs on the selected text":"Select text to rewrite it, or generate from the caret"}),(0,y.jsx)("div",{className:"ai-menu-commands",children:k.map(e=>(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"ai-menu-group-label",children:a.AI_COMMAND_GROUP_LABELS[e.group]}),e.commands.map(e=>(0,y.jsxs)("button",{type:"button",className:"ai-menu-command",onClick:()=>S(e),children:[(0,y.jsx)(e.icon,{className:"ai-menu-row-icon"}),(0,y.jsxs)("span",{className:"ai-menu-command-text",children:[(0,y.jsx)("span",{className:"ai-menu-command-label",children:e.label}),e.description&&(0,y.jsx)("span",{className:"ai-menu-command-description",children:e.description})]}),e.options?.length?(0,y.jsx)("span",{className:"ai-menu-command-more",children:"›"}):null]},e.id))]},e.group))})]})}),document.body)]})}var W={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 q(e){const t=(0,g.useCallback)(t=>e?u.subscribeTranscribe(e,t):()=>{},[e]);if("none"===(0,g.useSyncExternalStore)(t,()=>{const t=e?u.getTranscribeStorage(e):void 0;return t?`${t.listening}|${t.phraseId}|${t.error?.message??""}`:"none"},()=>"none")||!e)return H;const n=u.getTranscribeStorage(e);return n?{available:!0,isListening:n.listening,partial:n.partial,lastPhrase:n.lastPhrase,phraseId:n.phraseId,error:n.error}:H}function U({editor:e,durationMs:t=2e3}){const{isListening:n,lastPhrase:r,phraseId:s}=q(e);return(0,y.jsx)(C.SpokenPhraseOverlay,{durationMs:t,phrase:r,phraseId:s,visible:n})}var J=[".dropdown-container",".dropdown-portal","[data-richtext-portal]","[data-radix-popper-content-wrapper]","[data-radix-portal]",'[role="dialog"]','[role="menu"]','[role="listbox"]'].join(",");var K="rte-custom-styles",G="rte-custom-style-presets",X="rte-active-style-preset";function Y(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 Z(e){const t=(0,g.useRef)(!1);return{onMouseDown:e=>{t.current=e.target===e.currentTarget},onClick:n=>{t.current&&n.target===n.currentTarget&&(t.current=!1,e())}}}function Q({onClose:e}){const[t,n]=(0,g.useState)(()=>{try{const e=localStorage.getItem(G);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,g.useState)(()=>{try{return localStorage.getItem(X)||t[0]?.id||"1"}catch{return"1"}}),[i,o]=(0,g.useState)(null),[l,a]=(0,g.useState)(""),c=t.find(e=>e.id===r)||t[0],[d,h]=(0,g.useState)(c?.rules||[]),u=(0,g.useRef)(d.length?Math.max(...d.map(e=>e.id),0)+1:1),p=e=>{let t=document.getElementById(K);t||(t=document.createElement("style"),t.id=K,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(X,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(G,JSON.stringify(s)),a(""),m(r.id)},x=(e,r)=>{if(!r.trim())return;const s=t.map(t=>t.id===e?{...t,name:r}:t);n(s),localStorage.setItem(G,JSON.stringify(s)),o(null)},b=(e,t,n)=>h(r=>r.map(r=>r.id===e?{...r,[t]:n}:r)),k=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...k}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)(v.Paintbrush,{size:16,className:"text-blue-500"}),(0,y.jsx)("span",{className:"text-sm font-semibold",children:"Customize Editor Styles"})]}),(0,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:14})})]}),(0,y.jsxs)("div",{className:"px-4 py-3 border-b border-gray-100 dark:border-slate-700 space-y-2",children:[(0,y.jsx)("div",{className:"text-xs font-semibold text-gray-700 dark:text-gray-300",children:"Style Presets"}),(0,y.jsx)("div",{className:"flex gap-2 flex-wrap",children:t.map(e=>(0,y.jsxs)("div",{className:"flex items-center gap-1",children:[(0,y.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,y.jsx)("input",{autoFocus:!0,type:"text",value:l,onChange:e=>a(e.target.value),onBlur:()=>x(e.id,l),onKeyDown:t=>"Enter"===t.key&&x(e.id,l),className:"w-20 px-1 py-0.5 text-xs bg-transparent border-b border-current outline-none"}):(0,y.jsx)("span",{onDoubleClick:()=>{o(e.id),a(e.name)},children:e.name})}),t.length>1&&(0,y.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(G,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,y.jsx)(v.X,{size:12})})]},e.id))}),t.length<10&&(0,y.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,y.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,y.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,y.jsx)(v.Plus,{size:12}),"Add"]})]})]}),(0,y.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,y.jsx)("code",{className:"bg-gray-100 dark:bg-slate-800 px-1 rounded",children:".ProseMirror"})," elements."]}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-4 space-y-2",children:[0===d.length&&(0,y.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,y.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,y.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,y.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,y.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,y.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,y.jsx)(v.Trash2,{size:13})})]},e.id))]}),(0,y.jsxs)("div",{className:"px-4 py-3 border-t border-gray-100 dark:border-slate-700 flex items-center justify-between",children:[(0,y.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,y.jsx)(v.Plus,{size:12}),"Add Rule"]}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.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,y.jsx)("button",{onClick:()=>{const e=t.map(e=>e.id===r?{...e,rules:[...d]}:e);n(e),localStorage.setItem(G,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 ee({children:e,label:t,shortcut:n,icon:r,displayIcon:s}){const i=(0,g.useRef)(null);return(0,y.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,y.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,y.jsx)("span",{className:"flex-1 text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,y.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n}),(0,y.jsx)("span",{className:"absolute inset-0 opacity-0 pointer-events-none","aria-hidden":!0,children:e}),(0,y.jsx)("span",{className:"hidden",children:e})]})}function te({icon:e,label:t,shortcut:n,onClick:r,disabled:s}){return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,y.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),n&&(0,y.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 ml-4 whitespace-nowrap",children:n})]})}function ne({icon:e,label:t,checked:n,onChange:r}){return(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:e}),(0,y.jsx)("span",{className:"flex-1 text-left text-sm text-gray-700 dark:text-gray-200",children:t}),(0,y.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,y.jsx)(v.Check,{size:12,strokeWidth:3})})]})}function re({children:e,label:t,name:n,active:r,onClick:s}){return(0,y.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,y.jsx)(v.ChevronDown,{size:10,className:"opacity-40 mt-0.5"})]})}function se({top:e,left:t,right:n,className:r="",children:s}){const i=(0,g.useRef)(null),[o,l]=(0,g.useState)({top:e,left:-9999,visibility:"hidden"});return(0,g.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,y.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:Y,ref:i,style:o,children:s})}function ie({onClose:e,documentTitle:t,editor:n,initialTab:r="info"}){const[s,i]=(0,g.useState)(r),[o,l]=(0,g.useState)(()=>m.getWordCountStats(n));(0,g.useEffect)(()=>{if(!n)return;const e=()=>l(m.getWordCountStats(n));return e(),n.on("update",e),()=>{n.off("update",e)}},[n]);const{createdDate:a,modifiedDate:c}=(0,g.useMemo)(()=>({createdDate:new Date(Date.now()-2592e6),modifiedDate:new Date}),[]),[d,h]=(0,g.useState)(""),[u,p]=(0,g.useState)("viewer"),[f,x]=(0,g.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()&&(f.sharedWith.find(e=>e.email===d)?alert("Already shared with this email"):(x(e=>({...e,sharedWith:[...e.sharedWith,{email:d,role:u,sharedAt:(new Date).toISOString()}]})),h("")))},k=e=>{switch(e){case"editor":return(0,y.jsx)(v.Edit3,{size:14});case"commentor":return(0,y.jsx)(v.MessageSquare,{size:14});case"viewer":return(0,y.jsx)(v.Eye,{size:14});default:return null}},S=[{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}],j=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=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...C}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,y.jsx)(v.FileText,{size:18,className:"text-blue-500 shrink-0"}),(0,y.jsxs)("div",{className:"min-w-0",children:[(0,y.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white truncate",children:t}),(0,y.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,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:16})})]}),(0,y.jsx)("div",{className:"px-6 pt-3",children:(0,y.jsxs)("div",{className:"inline-flex gap-1 p-1 rounded-lg bg-gray-100 dark:bg-slate-800",children:[(0,y.jsx)("button",{className:j("info"),onClick:()=>i("info"),type:"button",children:"Info & word count"}),(0,y.jsx)("button",{className:j("share"),onClick:()=>i("share"),type:"button",children:"Sharing"})]})}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("info"===s?"":"hidden"),children:[(0,y.jsxs)("div",{className:"space-y-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Document Name"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white break-words",children:t})]}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Created"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:a.toLocaleDateString()})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Last Modified"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:c.toLocaleDateString()})]})]}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Access"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:f.isPublic?"Public":"Private"})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Shared with"}),(0,y.jsx)("p",{className:"text-sm text-gray-900 dark:text-white",children:1===f.sharedWith.length?"1 person":`${f.sharedWith.length} people`})]})]})]}),(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("h3",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400",children:"Word Count"}),(0,y.jsx)("table",{className:"w-full text-sm",children:(0,y.jsx)("tbody",{children:S.map(e=>(0,y.jsxs)("tr",{className:"border-b border-gray-100 dark:border-slate-700 last:border-b-0",children:[(0,y.jsx)("td",{className:"py-1.5 pr-2 text-gray-500 dark:text-gray-400",children:e.label}),(0,y.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,y.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,y.jsx)(v.Share2,{size:14}),"Manage sharing"]})]}),(0,y.jsxs)("div",{className:"overflow-y-auto flex-1 p-6 space-y-6 "+("share"===s?"":"hidden"),children:[(0,y.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,y.jsxs)("div",{className:"flex items-center gap-3",children:[f.isPublic?(0,y.jsx)(v.Globe,{size:18,className:"text-blue-500"}):(0,y.jsx)(v.Lock,{size:18,className:"text-gray-400"}),(0,y.jsxs)("div",{children:[(0,y.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white",children:f.isPublic?"Public":"Private"}),(0,y.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:f.isPublic?"Anyone with link can view":"Only invited people can access"})]})]}),(0,y.jsxs)("div",{className:"flex items-center gap-3",children:[f.isPublic&&f.shareLink&&(0,y.jsx)("button",{onClick:()=>{f.shareLink&&(navigator.clipboard.writeText(f.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,y.jsx)("button",{onClick:()=>{x(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 "+(f.isPublic?"bg-blue-500":"bg-gray-300 dark:bg-slate-700"),children:(0,y.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition "+(f.isPublic?"translate-x-6":"translate-x-1")})})]})]}),(0,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("label",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Add people"}),(0,y.jsxs)("div",{className:"flex gap-2",children:[(0,y.jsxs)("div",{className:"relative flex-1",children:[(0,y.jsx)(v.Mail,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),(0,y.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,y.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,y.jsx)("option",{value:"viewer",children:"Viewer"}),(0,y.jsx)("option",{value:"commentor",children:"Commentor"}),(0,y.jsx)("option",{value:"editor",children:"Editor"})]}),(0,y.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,y.jsxs)("div",{className:"space-y-2",children:[(0,y.jsx)("h3",{className:"text-sm font-medium text-gray-900 dark:text-white",children:"People with access"}),(0,y.jsx)("div",{className:"space-y-1 max-h-[280px] overflow-y-auto",children:f.sharedWith.length>0?f.sharedWith.map(e=>(0,y.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,y.jsxs)("div",{className:"flex items-center gap-3 flex-1",children:[(0,y.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,y.jsxs)("div",{className:"min-w-0",children:[(0,y.jsx)("p",{className:"text-sm font-medium text-gray-900 dark:text-white truncate",children:e.email}),(0,y.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Added ",new Date(e.sharedAt).toLocaleDateString()]})]})]}),(0,y.jsxs)("div",{className:"flex items-center gap-2",children:[(0,y.jsx)("span",{className:"text-gray-400 dark:text-gray-500",children:k(e.role)}),(0,y.jsxs)("select",{value:e.role,onChange:t=>{return n=e.email,r=t.target.value,void x(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,y.jsx)("option",{value:"viewer",children:"Viewer"}),(0,y.jsx)("option",{value:"commentor",children:"Commentor"}),(0,y.jsx)("option",{value:"editor",children:"Editor"})]}),(0,y.jsx)("button",{onClick:()=>{return t=e.email,void x(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,y.jsx)(v.X,{size:14})})]})]},e.email)):(0,y.jsxs)("div",{className:"text-center py-8",children:[(0,y.jsx)(v.Users,{size:24,className:"mx-auto text-gray-300 mb-2 opacity-50"}),(0,y.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"No one else has access yet"})]})})]})]})]})]}),document.body)}function oe({onClose:e,currentName:t}){const[n,r]=(0,g.useState)(t),s=()=>{n.trim()&&n!==t&&alert(`File renamed to: ${n}`),e()},i=Z(e);return(0,w.createPortal)((0,y.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,y.jsx)("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-sm",...i}),(0,y.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,y.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100 dark:border-slate-700",children:[(0,y.jsx)("h2",{className:"font-semibold text-gray-900 dark:text-white",children:"Rename document"}),(0,y.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-slate-800",children:(0,y.jsx)(v.X,{size:16})})]}),(0,y.jsx)("div",{className:"p-6 space-y-4",children:(0,y.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,y.jsxs)("div",{className:"flex gap-2 px-6 py-4 border-t border-gray-100 dark:border-slate-700 justify-end",children:[(0,y.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,y.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 le=({theme:e,setTheme:t,onOpenSettings:r,onAddComment:i,commentDisabled:o,showComments:a,onToggleComments:c,commentCount:u})=>{const[m,x]=(0,g.useState)(null),[b,k]=(0,g.useState)(null),[S,j]=(0,g.useState)(!1),[C,N]=(0,g.useState)(!1),[E,D]=(0,g.useState)(!1),[$,I]=(0,g.useState)(!1),[z,B]=(0,g.useState)(null),F=!!r,H=(0,g.useRef)(null),Z=s.useLocale(),{editor:le}=(0,f.useCurrentEditor)(),ae="Untitled Document",ce=!!le?.extensionManager.extensions.some(e=>"harper"===e.name);(0,g.useEffect)(()=>{le&&ce&&(E?le.chain().focus().runProofing().run():le.commands.clearProofing())},[E,le,ce]);const de=function(e){const t=(0,g.useCallback)(t=>e?h.subscribeReadAloud(e,t):()=>{},[e]);if("none"===(0,g.useSyncExternalStore)(t,()=>{const t=e?h.getReadAloudStorage(e):void 0;return t?`${t.state}|${t.currentChunk?.index??-1}|${t.error?.message??""}`:"none"},()=>"none")||!e)return W;const n=h.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}:W}(le??null),he=q(le??null),ue=le&&!le.state.selection.empty?"selection":"document",pe=!!le&&h.getReadAloudText(le).length>0,me=!!le?.extensionManager.extensions.some(e=>"PaginationPlus"===e.name),[fe,ge]=(0,g.useState)(!0);(0,g.useEffect)(()=>{if(!le||!me)return;const e=le.storage?.PaginationPlus?.enabled;"boolean"==typeof e&&ge(e)},[le,me]);const xe=(0,g.useCallback)(e=>{le&&(e?le.commands.enablePagination?.():le.commands.disablePagination?.(),ge(e))},[le]),be=(0,g.useCallback)(()=>{le?.chain().focus().run(),document.execCommand("cut")},[le]),ye=(0,g.useCallback)(()=>{le?.chain().focus().run(),document.execCommand("copy")},[le]),ve=(0,g.useCallback)(async()=>{le?.chain().focus().run();try{const e=await navigator.clipboard.readText();le?.commands.insertContent(e)}catch{document.execCommand("paste")}},[le]),we=(0,g.useCallback)(async()=>{le?.chain().focus().run();try{const e=await navigator.clipboard.readText();le?.chain().focus().insertContent(e,{parseOptions:{preserveWhitespace:!0}}).run()}catch{document.execCommand("paste")}},[le]),ke=(0,g.useCallback)(()=>{le?.commands.deleteSelection()},[le]),Se=(0,g.useCallback)(()=>{le?.chain().focus().selectAll().run()},[le]),je=!!le?.extensionManager.extensions.some(e=>"selectSimilar"===e.name),[Ce,Ne]=(0,g.useState)(0);(0,g.useEffect)(()=>{if(!le||!je)return;const e=()=>Ne(p.selectSimilarPluginKey.getState(le.state)?.ranges.length??0);return e(),le.on("transaction",e),()=>{le.off("transaction",e)}},[le,je]);const Ee=(0,g.useCallback)(e=>{le?.chain().focus().selectSimilar(e).run()},[le]),Ae=(0,g.useCallback)(()=>{le?.chain().focus().clearSimilarSelection().run()},[le]);(0,g.useEffect)(()=>{try{const e=localStorage.getItem(X),t=JSON.parse(localStorage.getItem(G)||"[]");if(t.length>0){const n=t.find(t=>t.id===e)||t[0];if(n&&n.rules.length>0){let e=document.getElementById(K);e||(e=document.createElement("style"),e.id=K,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(m===e)return x(null),void k(null);const n=t.currentTarget.getBoundingClientRect();k({top:n.bottom+4,left:n.left}),x(e)},Me=()=>{x(null),k(null)};return(0,g.useEffect)(()=>{if(!m)return;const e=e=>{(function(e,t=document){const n=e;return!!n?.isConnected&&!n.closest(J)&&!t.querySelector('[role="dialog"],[role="menu"],[role="listbox"]')})(e.target)&&Me()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[m]),(0,y.jsxs)(y.Fragment,{children:[(0,y.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:Y,children:[(0,y.jsx)(n.Z,{hideWhenDisabled:!0}),(0,y.jsx)(n.$$2,{hideWhenDisabled:!0}),(0,y.jsx)("div",{className:"border-l border-gray-200 dark:border-slate-700 mx-0.5 px-0.5",children:(0,y.jsx)(O,{})}),(0,y.jsx)(n.F$1,{}),(0,y.jsx)(n.y$2,{}),(0,y.jsx)(n.h$4,{}),(0,y.jsx)(n.y$1,{}),(0,y.jsx)(n.d$1,{}),(0,y.jsx)(n.M$1,{}),(0,y.jsx)(V,{}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"block",label:"Block Format",active:"block"===m,onClick:Te,children:(0,y.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,y.jsx)("line",{x1:"2",y1:"4",x2:"14",y2:"4"}),(0,y.jsx)("line",{x1:"2",y1:"8",x2:"11",y2:"8"}),(0,y.jsx)("line",{x1:"2",y1:"12",x2:"8",y2:"12"})]})}),"block"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H1",label:"Heading 1",shortcut:"Ctrl+Alt+1",children:(0,y.jsx)(n.$$1,{level:1})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H2",label:"Heading 2",shortcut:"Ctrl+Alt+2",children:(0,y.jsx)(n.$$1,{level:2})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H3",label:"Heading 3",shortcut:"Ctrl+Alt+3",children:(0,y.jsx)(n.$$1,{level:3})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H4",label:"Heading 4",shortcut:"Ctrl+Alt+4",children:(0,y.jsx)(n.$$1,{level:4})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H5",label:"Heading 5",shortcut:"Ctrl+Alt+5",children:(0,y.jsx)(n.$$1,{level:5})})}),(0,y.jsx)("div",{children:(0,y.jsx)(ee,{icon:"H6",label:"Heading 6",shortcut:"Ctrl+Alt+6",children:(0,y.jsx)(n.$$1,{level:6})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Bullet List",shortcut:"Ctrl+Shift+8",children:(0,y.jsx)(n.r$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Ordered List",shortcut:"Ctrl+Shift+7",children:(0,y.jsx)(n.n$4,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Check List",shortcut:"Ctrl+Shift+9",children:(0,y.jsx)(n.r,{})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Blockquote",shortcut:"Ctrl+Shift+B",children:(0,y.jsx)(n.m$2,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Code Block",shortcut:"Ctrl+Alt+C",children:(0,y.jsx)(n.k$2,{})})})]}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-1",children:(0,y.jsx)(T,{label:"Clear Format",children:(0,y.jsx)(n.n$3,{})})}),(0,y.jsxs)("button",{onClick:()=>{Me(),j(!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,y.jsx)(v.Paintbrush,{size:14,className:"text-gray-400 shrink-0"}),"Customize default styles…"]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"textstyles",label:"Text Styles",active:"textstyles"===m,onClick:Te,children:(0,y.jsx)("span",{className:"text-sm font-mono",children:"Tt"})}),"textstyles"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[400px]",left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Text Styles"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1 py-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Strikethrough",shortcut:"Ctrl+Shift+S",children:(0,y.jsx)(n.u$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Inline Code",shortcut:"Ctrl+E",children:(0,y.jsx)(n.m$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Text Color",shortcut:"Alt+Shift+C",children:(0,y.jsx)(n.h$3,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Superscript",shortcut:"Ctrl+.",children:(0,y.jsx)(_,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Subscript",shortcut:"Ctrl+,",children:(0,y.jsx)(M,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Indent",children:(0,y.jsx)(n.l$1,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Line Spacing",children:(0,y.jsx)(n.f,{})})}),(0,y.jsx)("div",{className:"col-span-2",children:(0,y.jsx)(T,{label:"Alignment",children:(0,y.jsx)(n.A$1,{})})})]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"insert",label:"Insert",active:"insert"===m,onClick:Te,children:(0,y.jsx)(v.Plus,{size:16})}),"insert"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"min-w-[300px]",left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Insert"}),(0,y.jsxs)("div",{className:"grid grid-cols-2 gap-0.5 px-1",children:[(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Link",children:(0,y.jsx)(n.Be,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Emoji",children:(0,y.jsx)(n.ne,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Table",children:(0,y.jsx)(n.st,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Image",children:(0,y.jsx)(n.te,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Meme",children:(0,y.jsx)(n.T$3,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Document",children:(0,y.jsx)(n.E,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Columns",shortcut:"Ctrl+Alt+G",children:(0,y.jsx)(n.b,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Callout",children:(0,y.jsx)(n.F,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Twitter",children:(0,y.jsx)(n.N,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Divider",shortcut:"Ctrl+Alt+S",children:(0,y.jsx)(n.h,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Video",children:(0,y.jsx)(n.M,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Math",children:(0,y.jsx)(n.Dt,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Flowchart",children:(0,y.jsx)(n.P,{})})}),(0,y.jsx)("div",{children:(0,y.jsx)(T,{label:"Drawio",children:(0,y.jsx)(d.RichTextDrawio,{})})}),i&&(0,y.jsx)("div",{children:(0,y.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,y.jsx)("span",{className:"w-5 flex items-center justify-center text-gray-500 dark:text-gray-400 shrink-0",children:(0,y.jsx)(v.MessageSquarePlus,{size:14})}),(0,y.jsx)("span",{className:"text-xs whitespace-nowrap truncate",children:"Comment"})]})})]})]}),document.body)]}),(0,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"edit",label:"Edit",active:"edit"===m,onClick:Te,children:(0,y.jsx)(v.Clipboard,{size:16})}),"edit"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Clipboard"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Scissors,{size:14}),label:"Cut",shortcut:"Ctrl+X",onClick:()=>{Me(),be()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Clipboard,{size:14}),label:"Copy",shortcut:"Ctrl+C",onClick:()=>{Me(),ye()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.ClipboardPaste,{size:14}),label:"Paste",shortcut:"Ctrl+V",onClick:()=>{Me(),ve()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.ClipboardType,{size:14}),label:"Paste Plain",shortcut:"Ctrl+Shift+V",onClick:()=>{Me(),we()}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Trash2,{size:14}),label:"Delete",shortcut:"Del",onClick:()=>{Me(),ke()}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Selection"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.TextCursorInput,{size:14}),label:"Select All",shortcut:"Ctrl+A",onClick:()=>{Me(),Se()}}),je&&(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(te,{icon:(0,y.jsx)(v.Type,{size:14}),label:"Select All Similar Fonts",onClick:()=>{Me(),Ee("font")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Palette,{size:14}),label:"Select All Similar Styles",onClick:()=>{Me(),Ee("style")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.TextSelect,{size:14}),label:"Select All Similar Formatting",onClick:()=>{Me(),Ee("formatting")}}),(0,y.jsx)(te,{disabled:0===Ce,icon:(0,y.jsx)(v.X,{size:14}),label:Ce?`Clear Multi-Selection (${Ce})`:"Clear Multi-Selection",shortcut:"Esc",onClick:()=>{Me(),Ae()}}),(0,y.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,y.jsxs)("div",{className:"dropdown-container",children:[(0,y.jsx)(re,{name:"tools",label:"Tools",active:"tools"===m,onClick:Te,children:(0,y.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,y.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"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{left:b.left,top:b.top,children:[(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Document"}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.FileText,{size:14}),label:"Document info & word count",onClick:()=>{Me(),B("info")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Share2,{size:14}),label:"Share",onClick:()=>{Me(),B("share")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Edit3,{size:14}),label:"Rename",onClick:()=>{Me(),I(!0)}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Copy,{size:14}),label:"Make a copy",onClick:()=>{Me(),alert("Document copied to your drive")}}),(0,y.jsx)(te,{icon:(0,y.jsx)(v.Download,{size:14}),label:"Download",onClick:()=>{Me(),alert("Downloading document...")}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)("div",{className:"px-2 py-1 text-[10px] font-semibold uppercase text-gray-400 tracking-wide",children:"Tools"}),c&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.MessageSquare,{size:14}),label:u?`Comments Panel (${u})`:"Comments Panel",checked:!!a,onChange:()=>c()}),c&&(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(T,{label:"Find / Replace",children:(0,y.jsx)(n.I,{})}),(0,y.jsx)(T,{label:"View Source",children:(0,y.jsx)(n.n,{})}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(ne,{icon:(0,y.jsx)(v.ListTree,{size:14}),label:"Table of Contents",checked:C,onChange:N}),ce&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.SpellCheck,{size:14}),label:"Spelling & Grammar",checked:E,onChange:D}),(de.available||he.available)&&(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),de.available&&(0,y.jsx)(te,{disabled:!de.isActive&&!pe,icon:de.isActive?(0,y.jsx)(v.VolumeX,{size:14}):(0,y.jsx)(v.Volume2,{size:14}),label:de.isActive?"Stop reading":"selection"===ue?"Read selection aloud":"Read document aloud",shortcut:"Ctrl+Shift+S",onClick:()=>{Me(),le?.commands.toggleReadAloud()}}),he.available&&(0,y.jsx)(ne,{icon:(0,y.jsx)(v.Mic,{size:14}),label:(0,A.isTranscriptionSupported)()?he.isListening?"Dictating — click to stop":"Dictate into the document":"Dictation unavailable in this browser",checked:he.isListening,onChange:()=>{(0,A.isTranscriptionSupported)()&&le?.commands.toggleTranscribe()}}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),me&&(0,y.jsx)(ne,{icon:fe?(0,y.jsx)(v.File,{size:14}):(0,y.jsx)(v.Globe,{size:14}),label:fe?"Page Layout: A4":"Page Layout: Web",checked:fe,onChange:xe}),(0,y.jsx)(T,{label:"Page Settings",shortcut:"Ctrl+Shift+P",children:(0,y.jsx)(R,{})}),(0,y.jsx)("div",{className:"my-1 border-t border-gray-100 dark:border-slate-700"}),(0,y.jsx)(T,{label:"Import Word",children:(0,y.jsx)(n.Zh,{})}),(0,y.jsx)(T,{label:"Export Word",children:(0,y.jsx)(n.d,{})}),(0,y.jsx)(T,{label:"Export PDF",children:(0,y.jsx)(n.a$1,{})})]}),document.body)]}),(0,y.jsxs)("div",{className:"ml-auto dropdown-container",children:[(0,y.jsx)("button",{ref:H,title:"Settings",onClick:e=>{F?(x(null),k(null),r()):((e,t)=>{if(m===e)return x(null),void k(null);const n=t.currentTarget.getBoundingClientRect();k({top:n.bottom+4,left:n.left,right:window.innerWidth-n.right}),x(e)})("settings",e)},className:"flex items-center gap-0.5 p-1.5 rounded transition-colors "+("settings"===m?"bg-gray-200 dark:bg-slate-700":"text-gray-500 hover:bg-gray-100 dark:hover:bg-slate-800"),children:(0,y.jsx)(v.Settings,{size:16})}),!F&&"settings"===m&&b&&(0,w.createPortal)((0,y.jsxs)(se,{className:"w-[260px] px-2 py-2 shadow-2xl",right:b.right,top:b.top,children:[(0,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Theme"}),(0,y.jsxs)("div",{className:"flex gap-1 mb-2 px-1",children:[(0,y.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,y.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,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Accent Color"}),(0,y.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,y.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,y.jsx)("div",{className:"border-t border-gray-100 dark:border-slate-700 my-1"}),(0,y.jsx)("div",{className:"text-[10px] font-semibold mb-1 text-gray-500 dark:text-gray-400 uppercase px-1",children:"Language"}),(0,y.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,y.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 "+(Z.lang===e?"bg-blue-500/20 border-blue-500":""),children:[t," ",n]},e))})]}),document.body)]})]}),S&&(0,y.jsx)(Q,{onClose:()=>j(!1)}),C&&le&&(0,y.jsx)(P,{editor:le,onClose:()=>N(!1)}),ce&&E&&le&&(0,y.jsx)(L,{editor:le}),he.available&&(0,y.jsx)(U,{editor:le??null}),$&&(0,y.jsx)(oe,{onClose:()=>I(!1),currentName:ae}),z&&(0,y.jsx)(ie,{documentTitle:ae,editor:le,initialTab:z,onClose:()=>B(null)})]})},ae=[{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."}],ce=[/^#{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],de=[/\*\*[^\s*][^*]*\*\*/,/\[[^\]]+\]\([^)\s]+\)/,/`[^`\n]+`/];function he(e){return n.ye.parse(e,{gfm:!0,breaks:!0,async:!1}).replace(/<\/?(thead|tbody)>/g,"")}function ue(e){const t=e.trim();return t?function(e){return function(e){return ce.some(t=>t.test(e))||de.some(t=>t.test(e))}(e)||/\n/.test(e.trim())}(t)?{content:he(t),isHtml:!0}:{content:t,isHtml:!1}:{content:"",isHtml:!1}}var pe=["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 me(e,t){const n=e.prompt.trim();return t?n.endsWith(":")?`${n} ${t}.`:`${n} (${t})`:n}function fe(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 ge=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 fe(35,n)}return s},xe=/^(?: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,be=/^(?:sure|certainly|of course|absolutely|got it|okay|ok)[,!.]?[ \t]*/i,ye=/^[ \t]*(?:```|~~~)[^\n]*\r?\n/,ve=/\r?\n[ \t]*(?:```|~~~)[ \t]*$/;function we(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(xe,"");return t!==e?t:e.replace(be,"")}(n),n=function(e){if(!ye.test(e))return e;const t=e.replace(ye,"").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 ke=new b.PluginKey("ai");function Se(e){return ke.getState(e)}function je(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 Ce(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 Ne(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=function(e,t){return t<=0?"":e.length<=t?e:`…${e.slice(e.length-t)}`}(i,Math.floor(r/2)),a=o.length>r-l.length?`${o.slice(0,r-l.length)}…`:o;return`${l}${l&&a?"\n":""}${a}`.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(ke,{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=we(t,{streaming:o});e.view.dispatch(e.view.state.tr.setMeta(ke,{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(!we(o))return void e.view.dispatch(e.view.state.tr.setMeta(ke,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:"The model returned an empty response."}));p(o,!1)}catch(Ie){if(h.signal.aborted||u!==n.requestToken||e.isDestroyed)return;e.view.dispatch(e.view.state.tr.setMeta(ke,{type:"set-error",from:s,to:i,commandLabel:r.commandLabel,message:Ie instanceof Error?Ie.message:"Something went wrong."}))}}x.Extension.create({name:"ai",addOptions:()=>({commands:ae,getCompletion:ge,systemPrompt:pe,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(ke,{type:"open-menu",from:r,to:s})),!0},closeAiMenu:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(ke,{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(ke,{type:"settle"}));else{const{from:e,to:s}=je(r,t.selection);n(t.tr.setMeta(ke,{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}=je(Se(n)?.panel??{status:"closed"},n.selection);return!(!1!==s.requiresSelection&&i===o||s.options?.length&&!t||(Ne(r,this.options,this.storage,{instruction:me(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}=je(Se(t)?.panel??{status:"closed"},t.selection);return Ne(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&&(Ne(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}=ue(o);return!!l&&(e(),n().insertContentAt({from:s,to:i},l,{parseOptions:{preserveWhitespace:!1}}).command(({tr:e})=>(e.setMeta(ke,{type:"close"}),!0)).run())},discardAiSuggestion:()=>({state:t,dispatch:n})=>(e(),n&&n(t.tr.setMeta(ke,{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}=ue(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(ke,{type:"close"}),!0)).run()}}},addProseMirrorPlugins(){const e=this.options;return[new b.Plugin({key:ke,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(ke);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:Ce(t.doc,r,e),lastRequest:s}}},props:{decorations(e){return this.getState(e)?.decorations??S.DecorationSet.empty}}})]}});var Ee=()=>new Map,Ae=e=>{const t=Ee();return e.forEach((e,n)=>{t.set(n,e)}),t},Te=(e,t,n)=>{let r=e.get(t);return void 0===r&&e.set(t,r=n()),r},Me=()=>new Set,_e=e=>e[e.length-1],De=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Oe=Array.from,$e=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},Re=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},Ie=Array.isArray,Pe=class{constructor(){this._observers=Ee()}on(e,t){return Te(this._observers,e,Me).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 Oe((this._observers.get(e)||Ee()).values()).forEach(e=>e(...t))}destroy(){this._observers=Ee()}},Le=Math.floor,ze=Math.abs,Be=(e,t)=>e<t?e:t,Fe=(e,t)=>e>t?e:t,Ve=(Number.isNaN,e=>0!==e?e<0:1/e<0),We=Number.MAX_SAFE_INTEGER,He=Number.MIN_SAFE_INTEGER,qe=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&Le(e)===e),Ue=(Number.isNaN,Number.parseInt,String.fromCharCode),Je=(String.fromCodePoint,Ue(65535),/^\s*/g),Ke=/([A-Z])/g,Ge=(e,t)=>(e=>e.replace(Je,""))(e.replace(Ke,e=>`${t}${(e=>e.toLowerCase())(e)}`)),Xe="undefined"!=typeof TextEncoder?new TextEncoder:null,Ye=Xe?e=>Xe.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},Ze="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Ze&&1===Ze.decode(new Uint8Array).length&&(Ze=null);var Qe,et,tt,nt,rt=(e,t)=>((e,t)=>{const n=new Array(e);for(let r=0;r<e;r++)n[r]=t();return n})(t,()=>e).join(""),st=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},it=()=>new st,ot=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},lt=(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},at=lt,ct=(e,t)=>{for(;t>127;)lt(e,128|127&t),t=Le(t/128);lt(e,127&t)},dt=(e,t)=>{const n=Ve(t);for(n&&(t=-t),lt(e,(t>63?128:0)|(n?64:0)|63&t),t=Le(t/64);t>0;)lt(e,(t>127?128:0)|127&t),t=Le(t/128)},ht=new Uint8Array(3e4),ut=ht.length/3,pt=Xe&&Xe.encodeInto?(e,t)=>{if(t.length<ut){const n=Xe.encodeInto(t,ht).written||0;ct(e,n);for(let t=0;t<n;t++)lt(e,ht[t])}else ft(e,Ye(t))}:(e,t)=>{const n=unescape(encodeURIComponent(t)),r=n.length;ct(e,r);for(let s=0;s<r;s++)lt(e,n.codePointAt(s))},mt=(e,t)=>{const n=e.cbuf.length,r=e.cpos,s=Be(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(Fe(2*n,i)),e.cbuf.set(t.subarray(s)),e.cpos=i)},ft=(e,t)=>{ct(e,t.byteLength),mt(e,t)},gt=(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*Fe(n,t)),e.cpos=0)})(e,t);const n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},xt=new DataView(new ArrayBuffer(4)),bt=(e,t)=>{switch(typeof t){case"string":lt(e,119),pt(e,t);break;case"number":qe(t)&&ze(t)<=2147483647?(lt(e,125),dt(e,t)):(n=t,xt.setFloat32(0,n),xt.getFloat32(0)===n?(lt(e,124),((e,t)=>{gt(e,4).setFloat32(0,t,!1)})(e,t)):(lt(e,123),((e,t)=>{gt(e,8).setFloat64(0,t,!1)})(e,t)));break;case"bigint":lt(e,122),((e,t)=>{gt(e,8).setBigInt64(0,t,!1)})(e,t);break;case"object":if(null===t)lt(e,126);else if(Ie(t)){lt(e,117),ct(e,t.length);for(let n=0;n<t.length;n++)bt(e,t[n])}else if(t instanceof Uint8Array)lt(e,116),ft(e,t);else{lt(e,118);const n=Object.keys(t);ct(e,n.length);for(let r=0;r<n.length;r++){const s=n[r];pt(e,s),bt(e,t[s])}}break;case"boolean":lt(e,t?120:121);break;default:lt(e,127)}var n},yt=class extends st{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&ct(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}},vt=e=>{e.count>0&&(dt(e.encoder,1===e.count?e.s:-e.s),e.count>1&&ct(e.encoder,e.count-2))},wt=class{constructor(){this.encoder=new st,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),ot(this.encoder)}},kt=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);dt(e.encoder,t),e.count>1&&ct(e.encoder,e.count-2)}},St=class{constructor(){this.encoder=new st,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(kt(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return kt(this),ot(this.encoder)}},jt=class{constructor(){this.sarr=[],this.s="",this.lensE=new wt}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 st;return this.sarr.push(this.s),this.s="",pt(e,this.sarr.join("")),mt(e,this.lensE.toUint8Array()),ot(e)}},Ct=e=>new Error(e),Nt=()=>{throw Ct("Method unimplemented")},Et=()=>{throw Ct("Unexpected case")},At=Ct("Unexpected end of array"),Tt=Ct("Integer out of Range"),Mt=class{constructor(e){this.arr=e,this.pos=0}},_t=e=>new Mt(e),Dt=e=>((e,t)=>{const n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n})(e,$t(e)),Ot=e=>e.arr[e.pos++],$t=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>We)throw Tt}throw At},Rt=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>We)throw Tt}throw At},It=Ze?e=>Ze.decode(Dt(e)):e=>{let t=$t(e);if(0===t)return"";{let n=String.fromCodePoint(Ot(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Ot(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))}},Pt=(e,t)=>{const n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Lt=[e=>{},e=>null,Rt,e=>Pt(e,4).getFloat32(0,!1),e=>Pt(e,8).getFloat64(0,!1),e=>Pt(e,8).getBigInt64(0,!1),e=>!1,e=>!0,It,e=>{const t=$t(e),n={};for(let r=0;r<t;r++)n[It(e)]=zt(e);return n},e=>{const t=$t(e),n=[];for(let r=0;r<t;r++)n.push(zt(e));return n},Dt],zt=e=>Lt[127-Ot(e)](e),Bt=class extends Mt{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=$t(this)+1:this.count=-1),this.count--,this.s;var e}},Ft=class extends Mt{constructor(e){super(e),this.s=0,this.count=0}read(){if(0===this.count){this.s=Rt(this);const e=Ve(this.s);this.count=1,e&&(this.s=-this.s,this.count=$t(this)+2)}return this.count--,this.s}},Vt=class extends Mt{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(0===this.count){const e=Rt(this),t=1&e;this.diff=Le(e/2),this.count=1,t&&(this.count=$t(this)+2)}return this.s+=this.diff,this.count--,this.s}},Wt=class{constructor(e){this.decoder=new Ft(e),this.str=It(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)),qt=Math.random,Ut=()=>Ht(new Uint32Array(1))[0],Jt=()=>"10000000-1000-4000-8000-100000000000".replace(/[018]/g,e=>(e^Ut()&15>>e/4).toString(16)),Kt=Date.now,Gt=e=>new Promise(e),Xt=(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&&(Xt=localStorage,!1)}catch(lu){}var Yt,Zt=Xt,Qt=Symbol("Equality"),en=(e,t)=>e===t||!!e?.[Qt]?.(t)||!1,tn=Object.assign,nn=Object.keys,rn=e=>nn(e).length,sn=(e,t)=>{for(const n in e)if(!t(e[n],n))return!1;return!0},on=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ln=Object.freeze,an=e=>{for(const t in e){const n=e[t];"object"!=typeof n&&"function"!=typeof n||an(e[t])}return ln(e)},cn=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&cn(e,t,n+1)}},dn=(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[Qt])return e[Qt](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)||!dn(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(rn(e)!==rn(t))return!1;for(const n in e)if(!on(e,n)||!dn(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(!dn(e[n],t[n]))return!1;break;default:return!1}return!0},hn="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),un="undefined"!=typeof window&&"undefined"!=typeof document&&!hn,pn=("undefined"!=typeof navigator&&/Mac/.test(navigator.platform),[]),mn=e=>(()=>{if(void 0===Qe)if(hn){Qe=Ee();const e=process.argv;let t=null;for(let n=0;n<e.length;n++){const r=e[n];"-"===r[0]?(null!==t&&Qe.set(t,""),t=r):null!==t?(Qe.set(t,r),t=null):pn.push(r)}null!==t&&Qe.set(t,"")}else"object"==typeof location?(Qe=Ee(),(location.search||"?").slice(1).split("&").forEach(e=>{if(0!==e.length){const[t,n]=e.split("=");Qe.set(`--${Ge(t,"-")}`,n),Qe.set(`-${Ge(t,"-")}`,n)}})):Qe=Ee();return Qe})().has(e),fn=e=>(e=>void 0===e?null:e)(hn?process.env[e.toUpperCase().replaceAll("-","_")]:Zt.getItem(e)),gn=e=>mn("--"+e)||null!==fn(e),xn=gn("production"),bn=(hn&&(et=process.env.FORCE_COLOR,tt=["true","1","2"],tt.includes(et))||!mn("--no-colors")&&!gn("no-color")&&(!hn||process.stdout.isTTY)&&(!hn||mn("--color")||null!==fn("COLORTERM")||(fn("TERM")||"").includes("color")),un?e=>{let t="";for(let n=0;n<e.byteLength;n++)t+=Ue(e[n]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")),yn=class{constructor(e,t){this.left=e,this.right=t}},vn=(e,t)=>new yn(e,t),wn=e=>e.next()>=.5,kn=(e,t,n)=>Le(e.next()*(n+1-t)+t),Sn=(e,t,n)=>Le(e.next()*(n+1-t)+t),jn=(e,t,n)=>Sn(e,t,n),Cn=e=>Ue(jn(e,97,122)),Nn=(e,t)=>t[jn(e,0,t.length-1)],En=Symbol("0schema"),An=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(rt(" ",2*(this._rerrs.length-t))+`${null!=n.path?`[${n.path}] `:""}${n.has} doesn't match ${n.expected}. ${n.message}`)}return e.join("\n")}},Tn=(e,t)=>e===t||null!=e&&null!=t&&e.constructor===t.constructor&&(e[Qt]?en(e,t):Ie(e)?$e(e,e=>Re(t,t=>Tn(e,t))):"object"==typeof e&&sn(e,(e,n)=>Tn(e,t[n]))),Mn=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Tn(t,n)}equals(e){return this.constructor===e.constructor&&dn(this.shape,e.shape)}[En](){return!0}[Qt](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Nt()}get nullable(){return or(this,wr)}get optional(){return new Fn(this)}cast(e){return Cr(e,this),e}expect(e){return Cr(e,this),e}},_n=class extends Mn{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}},Dn=(e,t=null)=>new _n(e,t),On=(Dn(_n),class extends Mn{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}}),$n=e=>new On(e),Rn=(Dn(On),class extends Mn{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}}),In=(...e)=>new Rn(e),Pn=Dn(Rn),Ln=RegExp.escape||(e=>e.replace(/[().|&,$^[\]]/g,e=>"\\"+e)),zn=e=>gr.check(e)?[Ln(e)]:Pn.check(e)?e.shape.map(e=>e+""):fr.check(e)?["[+-]?\\d+.?\\d*"]:xr.check(e)?[".*"]:lr.check(e)?e.shape.map(zn).flat(1):void Et(),Bn=(Dn(class extends Mn{constructor(e){super(),this.shape=e,this._r=new RegExp("^"+e.map(zn).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")),Fn=class extends Mn{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[Bn](){return!0}},Vn=Dn(Fn),Wn=class extends Mn{check(e,t){return t?.extend(null,"never",typeof e),!1}},Hn=(new Wn,Dn(Wn),class e extends Mn{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):sn(this.shape,(n,r)=>{const s=this._isPartial&&!on(e,r)||n.check(e[r],t);return!s&&t?.extend(r.toString(),n.toString(),typeof e[r],"Object property does not match"),s})}}),qn=Dn(Hn),Un=$n(e=>null!=e&&(e.constructor===Object||null==e.constructor)),Jn=class extends Mn{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return null!=e&&sn(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)})}},Kn=(e,t)=>new Jn(e,t),Gn=Dn(Jn),Xn=class extends Mn{constructor(e){super(),this.shape=e}check(e,t){return null!=e&&sn(this.shape,(n,r)=>{const s=n.check(e[r],t);return!s&&t?.extend(r.toString(),"Tuple",typeof n),s})}},Yn=(Dn(Xn),class extends Mn{constructor(e){super(),this.shape=1===e.length?e[0]:new ir(e)}check(e,t){const n=Ie(e)&&$e(e,e=>this.shape.check(e));return!n&&t?.extend(null,"Array",""),n}}),Zn=(...e)=>new Yn(e),Qn=Dn(Yn),er=$n(e=>Ie(e)),tr=class extends Mn{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}},nr=(Dn(tr),((e,t=null)=>new tr(Mn,t))()),rr=Dn(class extends Mn{constructor(e){super(),this.len=e.length-1,this.args=((...e)=>new Xn(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}}),sr=$n(e=>"function"==typeof e),ir=(Dn(class extends Mn{constructor(e){super(),this.shape=e}check(e,t){const n=$e(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,"Intersectinon",typeof e),n}},e=>e.shape.length>0),class extends Mn{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){const n=Re(this.shape,n=>n.check(e,t));return t?.extend(null,"Union",typeof e),n}}),or=(...e)=>e.findIndex(e=>lr.check(e))>=0?or(...e.map(e=>jr(e)).map(e=>lr.check(e)?e.shape:[e]).flat(1)):1===e.length?e[0]:new ir(e),lr=Dn(ir),ar=()=>!0,cr=$n(ar),dr=Dn(On,e=>e.shape===ar),hr=$n(e=>"bigint"==typeof e),ur=$n(e=>e===hr),pr=$n(e=>"symbol"==typeof e),mr=($n(e=>e===pr),$n(e=>"number"==typeof e)),fr=$n(e=>e===mr),gr=$n(e=>"string"==typeof e),xr=$n(e=>e===gr),br=$n(e=>"boolean"==typeof e),yr=$n(e=>e===br),vr=In(void 0),wr=(Dn(Rn,e=>1===e.shape.length&&void 0===e.shape[0]),In(void 0),In(null)),kr=Dn(Rn,e=>1===e.shape.length&&null===e.shape[0]),Sr=(Dn(Uint8Array),Dn(_n,e=>e.shape===Uint8Array),or(mr,gr,wr,vr,hr,br,pr)),jr=((()=>{const e=Zn(cr),t=Kn(gr,cr),n=or(mr,gr,wr,br,e,t);e.shape=n,t.shape.values=n})(),e=>{if(nr.check(e))return e;if(Un.check(e)){const t={};for(const n in e)t[n]=jr(e[n]);return new Hn(t)}return er.check(e)?or(...e.map(jr)):Sr.check(e)?In(e):sr.check(e)?Dn(e):void Et()}),Cr=xn?()=>{}:(e,t)=>{const n=new An;if(!t.check(e,n))throw Ct(`Expected value to be of type ${t.constructor.name}.\n${n.toString()}`)},Nr=(nt=cr,new class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:jr(e),h:t}),this}else(e){return this.if(cr,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 Ct("Unhandled pattern")}}}(nt)).if(fr,(e,t)=>kn(t,He,We)).if(xr,(e,t)=>((e,t=0,n=20)=>{const r=jn(e,t,n);let s="";for(let i=0;i<r;i++)s+=Cn(e);return s})(t)).if(yr,(e,t)=>wn(t)).if(ur,(e,t)=>BigInt(kn(t,He,We))).if(lr,(e,t)=>Er(t,Nn(t,e.shape))).if(qn,(e,t)=>{const n={};for(const r in e.shape){let s=e.shape[r];if(Vn.check(s)){if(wn(t))continue;s=s.shape}n[r]=Nr(s,t)}return n}).if(Qn,(e,t)=>{const n=[],r=Sn(t,0,42);for(let s=0;s<r;s++)n.push(Er(t,e.shape));return n}).if(Pn,(e,t)=>Nn(t,e.shape)).if(kr,(e,t)=>null).if(rr,(e,t)=>{const n=Er(t,e.res);return()=>n}).if(dr,(e,t)=>Er(t,Nn(t,[mr,gr,wr,vr,hr,br,Zn(mr),Kn(or("a","b","c"),mr)]))).if(Gn,(e,t)=>{const n={},r=kn(t,0,3);for(let s=0;s<r;s++)n[Er(t,e.shape.keys)]=Er(t,e.shape.values);return n}).done(),Er=(e,t)=>Nr(jr(t),e),Ar="undefined"!=typeof document?document:{},Tr=($n(e=>e.nodeType===Dr),"undefined"!=typeof DOMParser&&new DOMParser,$n(e=>e.nodeType===Tr),$n(e=>e.nodeType===Mr),Ar.ELEMENT_NODE),Mr=Ar.TEXT_NODE,_r=(Ar.CDATA_SECTION_NODE,Ar.COMMENT_NODE,Ar.DOCUMENT_NODE),Dr=(Ar.DOCUMENT_TYPE_NODE,Ar.DOCUMENT_FRAGMENT_NODE),Or=($n(e=>e.nodeType===_r),JSON.stringify,Yt=clearTimeout,class{constructor(e){this._=e}destroy(){Yt(this._)}}),$r=(e,t)=>new Or(setTimeout(t,e)),Rr=Symbol,Ir=Rr(),Pr=Rr(),Lr=(Rr(),Rr(),Rr(),Rr()),zr=(Rr(),Rr()),Br=(Rr(),Kt(),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)=>{Vr.forEach(t=>t.print(e))}),Fr=(...e)=>{e.unshift(zr),Vr.forEach(t=>t.print(e))},Vr=Me(),Wr=e=>({[Symbol.iterator](){return this},next:e}),Hr=(e,t)=>Wr(()=>{const{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}}),qr=class{constructor(e,t){this.clock=e,this.len=t}},Ur=class{constructor(){this.clients=new Map}},Jr=(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])Fs(e,s,l.clock,l.len,n)}}),Kr=(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=Le((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)},Gr=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 qr(r.clock,Fe(r.len,s.clock+s.len-r.clock)):(n<t&&(e[n]=s),n++)}e.length=n})},Xr=e=>{const t=new Ur;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++)De(i,e[t].clients.get(s)||[]);t.clients.set(s,i)}});return Gr(t),t},Yr=(e,t,n,r)=>{Te(e.clients,t,()=>[]).push(new qr(n,r))},Zr=()=>new Ur,Qr=(e,t)=>{ct(e.restEncoder,t.clients.size),Oe(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),ct(e.restEncoder,t);const r=n.length;ct(e.restEncoder,r);for(let s=0;s<r;s++){const t=n[s];e.writeDsClock(t.clock),e.writeDsLen(t.len)}})},es=e=>{const t=new Ur,n=$t(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=$t(e.restDecoder),r=$t(e.restDecoder);if(r>0){const s=Te(t.clients,n,()=>[]);for(let t=0;t<r;t++)s.push(new qr(e.readDsClock(),e.readDsLen()))}}return t},ts=(e,t,n)=>{const r=new Ur,s=$t(e.restDecoder);for(let i=0;i<s;i++){e.resetDsCurVal();const s=$t(e.restDecoder),i=$t(e.restDecoder),o=n.clients.get(s)||[],l=$s(n,s);for(let n=0;n<i;n++){const n=e.readDsClock(),i=n+e.readDsLen();if(n<l){l<i&&Yr(r,s,l,i-l);let e=Is(o,n),a=o[e];for(!a.deleted&&a.id.clock<n&&(o.splice(e+1,0,To(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,To(t,a,i-a.id.clock)),a.delete(t))}else Yr(r,s,n,i-n)}}if(r.clients.size>0){const e=new cs;return ct(e.restEncoder,0),Qr(e,r),e.toUint8Array()}return null},ns=Ut,rs=class e extends Pe{constructor({guid:e=Jt(),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=ns(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Ds,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=Gt(e=>{this.on("load",()=>{this.isLoaded=!0,e(this)})});const l=()=>Gt(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||Js(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Oe(this.subdocs).map(e=>e.guid))}transact(e,t=null){return Js(this,e,t)}get(e,t=fi){const n=Te(this.share,e,()=>{const e=new t;return e._integrate(this,null),e}),r=n.constructor;if(t!==fi&&r!==t){if(r===fi){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,$i)}getText(e=""){return this.get(e,Zi)}getMap(e=""){return this.get(e,Ii)}getXmlElement(e=""){return this.get(e,to)}getXmlFragment(e=""){return this.get(e,eo)}toJSON(){const e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,Oe(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,Js(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()}},ss=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=$t(this.restDecoder),this.dsCurrVal}readDsLen(){const e=$t(this.restDecoder)+1;return this.dsCurrVal+=e,e}},is=class extends ss{constructor(e){super(e),this.keys=[],$t(e),this.keyClockDecoder=new Vt(Dt(e)),this.clientDecoder=new Ft(Dt(e)),this.leftClockDecoder=new Vt(Dt(e)),this.rightClockDecoder=new Vt(Dt(e)),this.infoDecoder=new Bt(Dt(e),Ot),this.stringDecoder=new Wt(Dt(e)),this.parentInfoDecoder=new Bt(Dt(e),Ot),this.typeRefDecoder=new Ft(Dt(e)),this.lenDecoder=new Ft(Dt(e))}readLeftID(){return new xs(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new xs(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 zt(this.restDecoder)}readBuf(){return Dt(this.restDecoder)}readJSON(){return zt(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}}},os=class{constructor(){this.restEncoder=it()}toUint8Array(){return ot(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){ct(this.restEncoder,e)}writeDsLen(e){ct(this.restEncoder,e)}},ls=class extends os{writeLeftID(e){ct(this.restEncoder,e.client),ct(this.restEncoder,e.clock)}writeRightID(e){ct(this.restEncoder,e.client),ct(this.restEncoder,e.clock)}writeClient(e){ct(this.restEncoder,e)}writeInfo(e){at(this.restEncoder,e)}writeString(e){pt(this.restEncoder,e)}writeParentInfo(e){ct(this.restEncoder,e?1:0)}writeTypeRef(e){ct(this.restEncoder,e)}writeLen(e){ct(this.restEncoder,e)}writeAny(e){bt(this.restEncoder,e)}writeBuf(e){ft(this.restEncoder,e)}writeJSON(e){pt(this.restEncoder,JSON.stringify(e))}writeKey(e){pt(this.restEncoder,e)}},as=class{constructor(){this.restEncoder=it(),this.dsCurrVal=0}toUint8Array(){return ot(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,ct(this.restEncoder,t)}writeDsLen(e){0===e&&Et(),ct(this.restEncoder,e-1),this.dsCurrVal+=e}},cs=class extends as{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new St,this.clientEncoder=new wt,this.leftClockEncoder=new St,this.rightClockEncoder=new St,this.infoEncoder=new yt(at),this.stringEncoder=new jt,this.parentInfoEncoder=new yt(at),this.typeRefEncoder=new wt,this.lenEncoder=new wt}toUint8Array(){const e=it();return ct(e,0),ft(e,this.keyClockEncoder.toUint8Array()),ft(e,this.clientEncoder.toUint8Array()),ft(e,this.leftClockEncoder.toUint8Array()),ft(e,this.rightClockEncoder.toUint8Array()),ft(e,ot(this.infoEncoder)),ft(e,this.stringEncoder.toUint8Array()),ft(e,ot(this.parentInfoEncoder)),ft(e,this.typeRefEncoder.toUint8Array()),ft(e,this.lenEncoder.toUint8Array()),mt(e,ot(this.restEncoder)),ot(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){bt(this.restEncoder,e)}writeBuf(e){ft(this.restEncoder,e)}writeJSON(e){bt(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)}},ds=(e,t,n)=>{const r=new Map;n.forEach((e,n)=>{$s(t,n)>e&&r.set(n,e)}),Os(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),ct(e.restEncoder,r.size),Oe(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{((e,t,n,r)=>{r=Fe(r,t[0].id.clock);const s=Is(t,r);ct(e.restEncoder,t.length-s),e.writeClient(n),ct(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)})},hs=(e,t,n,r=is)=>{const s=_t(t);((e,t,n,r=new is(e))=>{Js(t,e=>{e.local=!1;let t=!1;const n=e.doc,s=n.store,i=((e,t,n)=>{const r=[];let s=Oe(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 Ds,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!==Ro){const s=Te(h,d.id.client,()=>$s(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,$s(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 cs;return ds(e,l,new Map),ct(e.restEncoder,0),{missing:a,update:e.toUint8Array()}}return null})(e,s,((e,t)=>{const n=Ee(),r=$t(e.restDecoder);for(let s=0;s<r;s++){const r=$t(e.restDecoder),s=new Array(r),i=e.readClient();let o=$t(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 oo(ys(i,o),t),o+=t;break}case 10:{const t=$t(e.restDecoder);s[n]=new Ro(ys(i,o),t),o+=t;break}default:{const l=!(192&r),a=new Do(ys(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(),Oo(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<$s(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=ti([o.update,i.update])}}else s.pendingStructs=i;const l=ts(r,e,s);if(s.pendingDs){const t=new is(_t(s.pendingDs));$t(t.restDecoder);const n=ts(t,e,s);s.pendingDs=l&&n?ti([l,n]):l||n}else s.pendingDs=l;if(t){const t=s.pendingStructs.update;s.pendingStructs=null,hs(e.doc,t)}},n,!1)})(s,e,n,new r(s))},us=class{constructor(){this.l=[]}},ps=()=>new us,ms=(e,t)=>e.l.push(t),fs=(e,t)=>{const n=e.l;n.length,e.l=n.filter(e=>t!==e),e.l.length},gs=(e,t,n)=>cn(e.l,[t,n]),xs=class{constructor(e,t){this.client=e,this.clock=t}},bs=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,ys=(e,t)=>new xs(e,t),vs=e=>{for(const[t,n]of e.doc.share.entries())if(n===e)return t;throw Et()},ws=(e,t)=>{for(;null!==t;){if(t.parent===e)return!0;t=t.parent._item}return!1},ks=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}},js=(e,t,n)=>{let r=null,s=null;return null===e._item?s=vs(e):r=ys(e._item.id.client,e._item.id.clock),new ks(r,s,t,n)},Cs=(e,t,n=0)=>{let r=e._start;if(n<0){if(0===t)return js(e,null,n);t--}for(;null!==r;){if(!r.deleted&&r.countable){if(r.length>t)return js(e,ys(r.id.client,r.id.clock+t),n);t-=r.length}if(null===r.right&&n<0)return js(e,r.lastId,n);r=r.right}return js(e,null,n)},Ns=(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($s(r,s.client)<=s.clock)return null;const e=n?Eo(r,s):((e,t)=>{const n=Ps(e,t);return{item:n,diff:t.clock-n.id.clock}})(r,s),t=e.item;if(!(t instanceof Do))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 Et();{if($s(r,i.client)<=i.clock)return null;const{item:e}=n?Eo(r,i):{item:Ps(r,i)};if(!(e instanceof Do&&e.content instanceof No))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)},Es=class{constructor(e,t){this.ds=e,this.sv=t}},As=(e,t)=>new Es(e,t),Ts=(As(Zr(),new Map),e=>As((e=>{const t=Zr();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 qr(s,i))}}r.length>0&&t.clients.set(n,r)}),t})(e.store),Os(e.store))),Ms=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!Kr(t.ds,e.id),_s=(e,t)=>{const n=Te(e.meta,_s,Me),r=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<$s(r,n)&&zs(e,ys(n,t))}),Jr(e,t.ds,e=>{}),n.add(t))},Ds=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Os=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},$s=(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},Rs=(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 Et()}n.push(t)},Is=(e,t)=>{let n=0,r=e.length-1,s=e[r],i=s.id.clock;if(i===t)return r;let o=Le(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=Le((n+r)/2)}throw Et()},Ps=(e,t)=>{const n=e.clients.get(t.client);return n[Is(n,t.clock)]},Ls=(e,t,n)=>{const r=Is(t,n),s=t[r];return s.id.clock<n&&s instanceof Do?(t.splice(r+1,0,To(e,s,n-s.id.clock)),r+1):r},zs=(e,t)=>{const n=e.doc.store.clients.get(t.client);return n[Ls(e,n,t.clock)]},Bs=(e,t,n)=>{const r=t.clients.get(n.client),s=Is(r,n.clock),i=r[s];return n.clock!==i.id.clock+i.length-1&&i.constructor!==oo&&r.splice(s+1,0,To(e,i,n.clock-i.id.clock+1)),i},Fs=(e,t,n,r,s)=>{if(0===r)return;const i=n+r;let o,l=Ls(e,t,n);do{o=t[l++],i<o.id.clock+o.length&&Ls(e,t,i),s(o)}while(l<t.length&&t[l].id.clock<i)},Vs=class{constructor(e,t,n){this.doc=e,this.deleteSet=new Ur,this.beforeState=Os(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}},Ws=(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)||(Gr(t.deleteSet),((e,t)=>{ds(e,t.doc.store,t.beforeState)})(e,t),Qr(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)&&Te(e.changed,t,Me).add(n)},qs=(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 Do&&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},Us=(e,t)=>{if(t<e.length){const n=e[t],r=n.doc,s=r.store,i=n.deleteSet,o=n._mergeStructs;try{Gr(i),n.afterState=Os(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(()=>{gs(r._dEH,t,n)}))}),e.push(()=>r.emit("afterTransaction",[n,r])),e.push(()=>{n._needFormattingCleanup&&Gi(n)})}),cn(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=Is(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 Do&&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=Be(r.length-1,1+Is(r,n.clock+n.len-1)),t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+qs(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=Fe(Is(e,r),1);for(let t=e.length-1;t>=n;)t-=1+qs(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=Is(r,n);i+1<r.length&&qs(r,i+1)>1||i>0&&qs(r,i)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(Br(zr,Ir,"[yjs] ",Pr,Lr,"Changed the client-id because another client seems to be using it."),r.clientID=ns()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){const e=new ls;Ws(e,n)&&r.emit("update",[e.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){const e=new cs;Ws(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])):Us(e,t+1)}}},Js=(e,t,n=null,r=!0)=>{const s=e._transactionCleanups;let i=!1,o=null;null===e._transaction&&(i=!0,e._transaction=new Vs(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&&Us(s,0)}}return o},Ks=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}},Gs=(e,t,n)=>{Jr(e,n.deletions,n=>{n instanceof Do&&t.scope.some(t=>t===e.doc||ws(t,n))&&Ao(n,!1)})},Xs=(e,t,n)=>{let r=null;const s=e.doc,i=e.scope;Js(s,n=>{for(;t.length>0&&null===e.currStackItem;){const r=s.store,o=t.pop(),l=new Set,a=[];let c=!1;Jr(n,o.insertions,e=>{if(e instanceof Do){if(null!==e.redone){let{item:t,diff:s}=Eo(r,e.id);s>0&&(t=zs(n,ys(t.id.client,t.id.clock+s))),e=t}!e.deleted&&i.some(t=>t===n.doc||ws(t,e))&&a.push(e)}}),Jr(n,o.deletions,e=>{e instanceof Do&&i.some(t=>t===n.doc||ws(t,e))&&!Kr(o.insertions,e.id)&&l.add(e)}),l.forEach(t=>{c=null!==_o(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},Ys=class extends Pe{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:s=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:o=(Ie(e)?e[0].doc:e instanceof rs?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 Ur;e.afterState.forEach((t,n)=>{const r=e.beforeState.get(n)||0,i=t-r;i>0&&Yr(s,n,r,i)});const i=Kt();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=Xr([t.deletions,e.deleteSet]),t.insertions=Xr([t.insertions,s])}else r.push(new Ks(e.deleteSet,s)),o=!0;t||n||(this.lastChange=i),Jr(e,e.deleteSet,t=>{t instanceof Do&&this.scope.some(n=>n===e.doc||ws(n,t))&&Ao(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.destroy=this.destroy.bind(this),this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",this.destroy)}addToScope(e){const t=new Set(this.scope);(e=Ie(e)?e:[e]).forEach(e=>{t.has(e)||(t.add(e),(e instanceof fi?e.doc!==this.doc:e!==this.doc)&&Fr("[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=>Gs(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Gs(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=Xs(this,this.undoStack,"undo")}finally{this.undoing=!1}return e}redo(){let e;this.redoing=!0;try{e=Xs(this,this.redoStack,"redo")}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),this.doc.off("destroy",this.destroy),super.destroy()}},Zs=class{constructor(e,t){this.gen=function*(e){const t=$t(e.restDecoder);for(let n=0;n<t;n++){const t=$t(e.restDecoder),n=e.readClient();let r=$t(e.restDecoder);for(let s=0;s<t;s++){const t=e.readInfo();if(10===t){const t=$t(e.restDecoder);yield new Ro(ys(n,r),t),r+=t}else if(31&t){const s=!(192&t),i=new Do(ys(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(),Oo(e,t));yield i,r+=i.length}else{const t=e.readLen();yield new oo(ys(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===Ro);return this.curr}},Qs=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}},ei=(e,t)=>{if(e.constructor===oo){const{client:n,clock:r}=e.id;return new oo(ys(n,r+t),e.length-t)}if(e.constructor===Ro){const{client:n,clock:r}=e.id;return new Ro(ys(n,r+t),e.length-t)}{const n=e,{client:r,clock:s}=n.id;return new Do(ys(r,s+t),null,ys(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},ti=(e,t=is,n=cs)=>{if(1===e.length)return e[0];const r=e.map(e=>new t(_t(e)));let s=r.map(e=>new Zs(e,!0)),i=null;const o=new n,l=new Qs(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===Ro?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)ri(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===Ro)i.struct.length=n.id.clock+n.length-i.struct.id.clock;else{ri(l,i.struct,i.offset);const e=n.id.clock-i.struct.id.clock-i.struct.length;i={struct:new Ro(ys(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===Ro?i.struct.length-=t:n=ei(n,t)),i.struct.mergeWith(n)||(ri(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!==Ro;n=e.next())ri(l,i.struct,i.offset),i={struct:n,offset:0}}return null!==i&&(ri(l,i.struct,i.offset),i=null),si(l),Qr(o,Xr(r.map(e=>es(e)))),o.toUint8Array()},ni=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:ot(e.encoder.restEncoder)}),e.encoder.restEncoder=it(),e.written=0)},ri=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&ni(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),ct(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},si=e=>{ni(e);const t=e.encoder.restEncoder;ct(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){const r=e.clientStructs[n];ct(t,r.written),mt(t,r.restEncoder)}},ii="You must not compute changes after the event-handler fired.",oi=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=li(this.currentTarget,this.target))}deletes(e){return Kr(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Ct(ii);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=_e(e.content.getContent())}else null!==e&&this.deletes(e)?(s="update",i=_e(e.content.getContent())):(s="add",i=void 0)}else{if(!this.deletes(r))return;s="delete",i=_e(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 Ct(ii);const t=this.target,n=Me(),r=Me(),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}},li=(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},ai=()=>{Fr("Invalid access: Add Yjs type to a document before reading data.")},ci=0,di=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=ci++}},hi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=ci++},ui=(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)=>ze(t-e.index)<ze(t-n.index)?e:n);let r=e._start,s=0;for(null!==n&&(r=n.p,s=n.index,(e=>{e.timestamp=ci++})(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&&ze(n.index-s)<r.parent.length/80?(hi(n,r,s),n):((e,t,n)=>{if(e.length>=80){const r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return hi(r,t,n),r}{const r=new di(t,n);return e.push(r),r}})(e._searchMarker,r,s)},pi=(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=Fe(t,s.index+n))}},mi=(e,t,n)=>{const r=e,s=t.changedParentTypes;for(;Te(s,e,()=>[]).push(n),null!==e._item;)e=e._item.parent;gs(r._eH,n,t)},fi=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=ps(),this._dEH=ps(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Nt()}clone(){throw Nt()}_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){ms(this._eH,e)}observeDeep(e){ms(this._dEH,e)}unobserve(e){fs(this._eH,e)}unobserveDeep(e){fs(this._dEH,e)}toJSON(){}},gi=(e,t,n)=>{e.doc??ai(),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},xi=e=>{e.doc??ai();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},bi=(e,t)=>{const n=[];let r=e._start;for(;null!==r;){if(r.countable&&Ms(r,t)){const e=r.content.getContent();for(let t=0;t<e.length;t++)n.push(e[t])}r=r.right}return n},yi=(e,t)=>{let n=0,r=e._start;for(e.doc??ai();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 yi(e,(r,s)=>{n.push(t(r,s,e))}),n},wi=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}}}},ki=(e,t)=>{e.doc??ai();const n=ui(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 Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new go(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 Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new lo(new Uint8Array(n))),s.integrate(e,0);break;case rs:s=new Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new ho(n)),s.integrate(e,0);break;default:if(!(n instanceof fi))throw new Error("Unexpected content type in insert operation");s=new Do(ys(o,$s(l,o)),s,s&&s.lastId,a,a&&a.id,t,null,new No(n)),s.integrate(e,0)}}}),d()},ji=()=>Ct("Length exceeded!"),Ci=(e,t,n,r)=>{if(n>t._length)throw ji();if(0===n)return t._searchMarker&&pi(t._searchMarker,n,r.length),Si(e,t,null,r);const s=n,i=ui(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&&zs(e,ys(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&pi(t._searchMarker,s,r.length),Si(e,t,o,r)},Ni=(e,t,n,r)=>{if(0===r)return;const s=n,i=r,o=ui(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&&zs(e,ys(l.id.client,l.id.clock+n)),n-=l.length);for(;r>0&&null!==l;)l.deleted||(r<l.length&&zs(e,ys(l.id.client,l.id.clock+r)),l.delete(e),r-=l.length),l=l.right;if(r>0)throw ji();t._searchMarker&&pi(t._searchMarker,s,-i+r)},Ei=(e,t,n)=>{const r=t._map.get(n);void 0!==r&&r.delete(e)},Ai=(e,t,n,r)=>{const s=t._map.get(n)||null,i=e.doc,o=i.clientID;let l;if(null==r)l=new go([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:l=new go([r]);break;case Uint8Array:l=new lo(r);break;case rs:l=new ho(r);break;default:if(!(r instanceof fi))throw new Error("Unexpected content type");l=new No(r)}new Do(ys(o,$s(i.store,o)),s,s&&s.lastId,null,null,t,n,l).integrate(e,0)},Ti=(e,t)=>{e.doc??ai();const n=e._map.get(t);return void 0===n||n.deleted?void 0:n.content.getContent()[n.length-1]},Mi=e=>{const t={};return e.doc??ai(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},_i=(e,t)=>{e.doc??ai();const n=e._map.get(t);return void 0!==n&&!n.deleted},Di=e=>(e.doc??ai(),((e,t)=>Wr(()=>{let n;do{n=e.next()}while(!n.done&&!t(n.value));return n}))(e._map.entries(),e=>!e[1].deleted)),Oi=class extends oi{},$i=class e extends fi{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 fi?e.clone():e)),t}get length(){return this.doc??ai(),this._length}_callObserver(e,t){super._callObserver(e,t),mi(this,e,new Oi(this,e))}insert(e,t){null!==this.doc?Js(this.doc,n=>{Ci(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}push(e){null!==this.doc?Js(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?Js(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,t)}get(e){return ki(this,e)}toArray(){return xi(this)}slice(e=0,t=this.length){return gi(this,e,t)}toJSON(){return this.map(e=>e instanceof fi?e.toJSON():e)}map(e){return vi(this,e)}forEach(e){yi(this,e)}[Symbol.iterator](){return wi(this)}_write(e){e.writeTypeRef(yo)}},Ri=class extends oi{constructor(e,t,n){super(e,t),this.keysChanged=n}},Ii=class e extends fi{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 fi?e.clone():e)}),t}_callObserver(e,t){mi(this,e,new Ri(this,e,t))}toJSON(){this.doc??ai();const e={};return this._map.forEach((t,n)=>{if(!t.deleted){const r=t.content.getContent()[t.length-1];e[n]=r instanceof fi?r.toJSON():r}}),e}get size(){return[...Di(this)].length}keys(){return Hr(Di(this),e=>e[0])}values(){return Hr(Di(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return Hr(Di(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??ai(),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?Js(this.doc,t=>{Ei(t,this,e)}):this._prelimContent.delete(e)}set(e,t){return null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._prelimContent.set(e,t),t}get(e){return Ti(this,e)}has(e){return _i(this,e)}clear(){null!==this.doc?Js(this.doc,e=>{this.forEach(function(t,n,r){Ei(e,r,n)})}):this._prelimContent.clear()}_write(e){e.writeTypeRef(vo)}},Pi=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||rn(e)===rn(t)&&sn(e,(e,n)=>(void 0!==e||on(t,n))&&en(t[n],e)))(e,t),Li=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){null===this.right&&Et(),this.right.content.constructor===po?this.right.deleted||Vi(this.currentAttributes,this.right.content):this.right.deleted||(this.index+=this.right.length),this.left=this.right,this.right=this.right.right}},zi=(e,t,n)=>{for(;null!==t.right&&n>0;)t.right.content.constructor===po?t.right.deleted||Vi(t.currentAttributes,t.right.content):t.right.deleted||(n<t.right.length&&zs(e,ys(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},Bi=(e,t,n,r)=>{const s=new Map,i=r?ui(t,n):null;return i?zi(e,new Li(i.p.left,i.p,i.index,s),n-i.index):zi(e,new Li(null,t._start,0,s),n)},Fi=(e,t,n,r)=>{for(;null!==n.right&&(!0===n.right.deleted||n.right.content.constructor===po&&Pi(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 Do(ys(i,$s(s.store,i)),l,l&&l.lastId,a,a&&a.id,t,null,new po(o,r));c.integrate(e,0),n.right=c,n.forward()})},Vi=(e,t)=>{const{key:n,value:r}=t;null===r?e.delete(n):e.set(n,r)},Wi=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===po&&Pi(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(!Pi(c,a)){o.set(l,c);const{left:r,right:d}=n;n.right=new Do(ys(i,$s(s.store,i)),r,r&&r.lastId,d,d&&d.id,t,null,new po(l,a)),n.right.integrate(e,0),n.forward()}}return o},qi=(e,t,n,r,s)=>{n.currentAttributes.forEach((e,t)=>{void 0===s[t]&&(s[t]=null)});const i=e.doc,o=i.clientID;Wi(n,s);const l=Hi(e,t,n,s),a=r.constructor===String?new xo(r):r instanceof fi?new No(r):new uo(r);let{left:c,right:d,index:h}=n;t._searchMarker&&pi(t._searchMarker,n.index,a.getLength()),d=new Do(ys(o,$s(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(),Fi(e,t,n,l)},Ui=(e,t,n,r,s)=>{const i=e.doc,o=i.clientID;Wi(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===po));){if(!n.right.deleted)switch(n.right.content.constructor){case po:{const{key:t,value:i}=n.right.content,o=s[t];if(void 0!==o){if(Pi(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&&zs(e,ys(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 Do(ys(o,$s(i.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new xo(s)),n.right.integrate(e,0),n.forward()}Fi(e,t,n,l)},Ji=(e,t,n,r,s)=>{let i=t;const o=Ee();for(;i&&(!i.countable||i.deleted);){if(!i.deleted&&i.content.constructor===po){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 po:{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||Vi(s,n);break}}}t=t.right}return l},Ki=e=>{let t=0;return Js(e.doc,n=>{let r=e._start,s=e._start,i=Ee();const o=Ae(i);for(;s;)!1===s.deleted&&(s.content.constructor===po?Vi(o,s.content):(t+=Ji(n,r,s,i,o),i=Ae(o),r=s)),s=s.right}),t},Gi=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&&Fs(e,n.store.clients.get(r),i,s,e=>{e.deleted||e.content.constructor!==po||e.constructor===oo||t.add(e.parent)})}Js(n,n=>{Jr(e,e.deleteSet,e=>{if(e instanceof oo||!e.parent._hasFormatting||t.has(e.parent))return;const r=e.parent;e.content.constructor===po?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===po){const r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}})(n,e)});for(const e of t)Ki(e)})},Xi=(e,t,n)=>{const r=n,s=Ae(t.currentAttributes),i=t.right;for(;n>0&&null!==t.right;){if(!1===t.right.deleted)switch(t.right.content.constructor){case No:case uo:case xo:n<t.right.length&&zs(e,ys(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e)}t.forward()}i&&Ji(e,i,t.right,s,t.currentAttributes);const o=(t.left||t.right).parent;return o._searchMarker&&pi(o._searchMarker,t.index,-r+n),t},Yi=class extends oi{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=[];Js(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=tn({},o))),a=0}e&&t.push(e),i=null}};for(;null!==s;){switch(s.content.constructor){case No:case uo: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 xo: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 po:{const{key:t,value:l}=s.content;if(this.adds(s))this.deletes(s)||(Pi(n.get(t)??null,l)?null!==l&&s.delete(e):("retain"===i&&d(),Pi(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;Pi(e,l)||("retain"===i&&d(),o[t]=e)}else if(!s.deleted){r.set(t,l);const n=o[t];void 0!==n&&(Pi(n,l)?null!==n&&s.delete(e):("retain"===i&&d(),null===l?delete o[t]:o[t]=l))}s.deleted||("insert"===i&&d(),Vi(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}},Zi=class e extends fi{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??ai(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(lu){}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 Yi(this,e,t);mi(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??ai();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===xo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){null!==this.doc?Js(this.doc,n=>{const r=new Li(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)&&qi(n,this,r,o,i.attributes||{})}else void 0!==i.retain?Ui(n,this,r,i.retain,i.attributes||{}):void 0!==i.delete&&Xi(n,r,i.delete)}}):this._pending.push(()=>this.applyDelta(e))}toDelta(e,t,n){this.doc??ai();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(Ms(l,e)||void 0!==t&&Ms(l,t))switch(l.content.constructor){case xo:{const r=s.get("ychange");void 0===e||Ms(l,e)?void 0===t||Ms(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 No:case uo:{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 po:Ms(l,e)&&(a(),Vi(s,l.content))}l=l.right}a()};return e||t?Js(i,n=>{e&&_s(n,e),t&&_s(n,t),c()},"cleanup"):c(),r}insert(e,t,n){if(t.length<=0)return;const r=this.doc;null!==r?Js(r,r=>{const s=Bi(r,this,e,!n);n||(n={},s.currentAttributes.forEach((e,t)=>{n[t]=e})),qi(r,this,s,t,n)}):this._pending.push(()=>this.insert(e,t,n))}insertEmbed(e,t,n){const r=this.doc;null!==r?Js(r,r=>{const s=Bi(r,this,e,!n);qi(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?Js(n,n=>{Xi(n,Bi(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?Js(r,r=>{const s=Bi(r,this,e,!1);null!==s.right&&Ui(r,this,s,t,n)}):this._pending.push(()=>this.format(e,t,n))}removeAttribute(e){null!==this.doc?Js(this.doc,t=>{Ei(t,this,e)}):this._pending.push(()=>this.removeAttribute(e))}setAttribute(e,t){null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._pending.push(()=>this.setAttribute(e,t))}getAttribute(e){return Ti(this,e)}getAttributes(){return Mi(this)}_write(e){e.writeTypeRef(wo)}},Qi=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??ai()}[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!==to&&t.constructor!==eo||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})}},eo=class e extends fi{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 fi?e.clone():e)),t}get length(){return this.doc??ai(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new Qi(this,e)}querySelector(e){e=e.toUpperCase();const t=new Qi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),Oe(new Qi(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){mi(this,e,new no(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),yi(this,s=>{r.insertBefore(s.toDOM(e,t,n),null)}),r}insert(e,t){null!==this.doc?Js(this.doc,n=>{Ci(n,this,e,t)}):this._prelimContent.splice(e,0,...t)}insertAfter(e,t){if(null!==this.doc)Js(this.doc,n=>{const r=e&&e instanceof fi?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 Ct("Reference item not found");n.splice(r,0,...t)}}delete(e,t=1){null!==this.doc?Js(this.doc,n=>{Ni(n,this,e,t)}):this._prelimContent.splice(e,t)}toArray(){return xi(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ki(this,e)}slice(e=0,t=this.length){return gi(this,e,t)}forEach(e){yi(this,e)}_write(e){e.writeTypeRef(So)}},to=class e extends eo{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 fi?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?Js(this.doc,t=>{Ei(t,this,e)}):this._prelimAttrs.delete(e)}setAttribute(e,t){null!==this.doc?Js(this.doc,n=>{Ai(n,this,e,t)}):this._prelimAttrs.set(e,t)}getAttribute(e){return Ti(this,e)}hasAttribute(e){return _i(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&&Ms(s,t)&&(n[r]=s.content.getContent()[s.length-1])}),n})(0,e):Mi(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 yi(this,s=>{r.appendChild(s.toDOM(e,t,n))}),void 0!==n&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(ko),e.writeKey(this.nodeName)}},no=class extends oi{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)})}},ro=class e extends Ii{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(jo),e.writeKey(this.hookName)}},so=class e extends Zi{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(Co)}},io=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Nt()}mergeWith(e){return!1}write(e,t,n){throw Nt()}integrate(e,t){throw Nt()}},oo=class extends io{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),Rs(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},lo=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 Nt()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}},ao=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){Yr(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}},co=(e,t)=>new rs({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),ho=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(co(this.doc.guid,this.opts))}splice(e){throw Nt()}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}},uo=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 Nt()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}},po=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 Nt()}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}},mo=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}},fo="development"===fn("node_env"),go=class e{constructor(e){this.arr=e,fo&&an(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}},xo=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}},bo=[e=>new $i,e=>new Ii,e=>new Zi,e=>new to(e.readKey()),e=>new eo,e=>new ro(e.readKey()),e=>new so],yo=0,vo=1,wo=2,ko=3,So=4,jo=5,Co=6,No=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 Nt()}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}},Eo=(e,t)=>{let n,r=t,s=0;do{s>0&&(r=ys(r.client,r.clock+s)),n=Ps(e,r),s=r.clock-n.id.clock,r=n.redone}while(null!==r&&n instanceof Do);return{item:n,diff:s}},Ao=(e,t)=>{for(;null!==e&&e.keep!==t;)e.keep=t,e=e.parent._item},To=(e,t,n)=>{const{client:r,clock:s}=t.id,i=new Do(ys(r,s+n),t,ys(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=ys(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},Mo=(e,t)=>Re(e,e=>Kr(e.deletions,t)),_o=(e,t,n,r,s,i)=>{const o=e.doc,l=o.store,a=o.clientID,c=t.redone;if(null!==c)return zs(e,c);let d,h=t.parent._item,u=null;if(null!==h&&!0===h.deleted){if(null===h.redone&&(!n.has(h)||null===_o(e,h,n,r,s,i)))return null;for(;null!==h.redone;)h=zs(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:zs(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:zs(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||Kr(r,u.right.id)||Mo(i.undoStack,u.right.id)||Mo(i.redoStack,u.right.id));)for(u=u.right;u.redone;)u=zs(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=ys(a,$s(l,a)),f=new Do(m,u,u&&u.lastId,d,d&&d.id,p,t.parentSub,t.content.copy());return t.redone=m,Ao(f,!0),f.integrate(e,0),f},Do=class e extends io{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>=$s(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=$s(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===xs&&this.id.client!==this.parent.client&&this.parent.clock>=$s(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=Bs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=zs(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===oo||this.right&&this.right.constructor===oo)this.parent=null;else if(this.parent){if(this.parent.constructor===xs){const e=Ps(n,this.parent);e.constructor===oo?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=Bs(e,e.doc.store,ys(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),bs(this.origin,t.origin)){if(t.id.client<this.id.client)n=t,r.clear();else if(bs(this.rightOrigin,t.rightOrigin))break}else{if(null===t.origin||!s.has(Ps(e.doc.store,t.origin)))break;r.has(Ps(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),Rs(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 oo(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:ys(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&bs(e.origin,this.lastId)&&this.right===e&&bs(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(),Yr(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 Et();this.content.gc(e),t?((e,t,n)=>{const r=e.clients.get(t.id.client);r[Is(r,t.id.clock)]=n})(e,this,new oo(this.id,this.length)):this.content=new ao(this.length)}write(e,t){const n=t>0?ys(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===xs?(e.writeParentInfo(!1),e.writeLeftID(t)):Et();null!==s&&e.writeString(s)}this.content.write(e,t)}},Oo=(e,t)=>$o[31&t](e),$o=[()=>{Et()},e=>new ao(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 mo(n)},e=>new lo(e.readBuf()),e=>new xo(e.readString()),e=>new uo(e.readJSON()),e=>new po(e.readKey(),e.readJSON()),e=>new No(bo[e.readTypeRef()](e)),e=>{const t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new go(n)},e=>new ho(co(e.readString(),e.readAny())),()=>{Et()}],Ro=class extends io{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){Et()}write(e,t){e.writeInfo(10),ct(e.restEncoder,this.length-t)}getMissing(e,t){return null}},Io="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},Po="__ $YJS$ __";function Lo(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&&Fo(e.charCodeAt(r-1))&&Bo(e.charCodeAt(r))&&n--,n}if(s.content.size||i.content.size){let e=Lo(s.content,i.content,n+1);if(null!=e)return e}n+=s.nodeSize}else n+=s.nodeSize}}function zo(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&&Fo(e.charCodeAt(s-1))&&Bo(e.charCodeAt(s))&&(n++,r++),{a:n,b:r}}if(o.content.size||l.content.size){let e=zo(o.content,l.content,n-1,r-1);if(e)return e}n-=a,r-=a}else n-=a,r-=a}}function Bo(e){return e>=56320&&e<57344}function Fo(e){return e>=55296&&e<56320}Io[Po],Io[Po]=!0;var Vo=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 Lo(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return zo(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)":""))}};Vo.empty=new Vo([],0);var Wo={index:0,offset:0};function Ho(e,t){return Wo.index=e,Wo.offset=t,Wo}function qo(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(!qo(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!qo(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Uo=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&&qo(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}};Uo.none=[];var Jo=class extends Error{},Ko=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=Xo(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(Go(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(Vo.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 Go(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(Go(i.content,t-s-1,n-s-1)))}function Xo(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=Xo(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))}Ko.empty=new Ko(Vo.empty,0,0);var Yo=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Zo(t,n);if(null==r.next)return e.empty;let s=Qo(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]);il(e,n).forEach(e=>{r||s.push([t,r=[]]),-1==r.indexOf(e)&&r.push(e)})})});let i=t[r.join(",")]=new Yo(r.indexOf(e.length-1)>-1);for(let e=0;e<s.length;e++){let r=s[e][1].sort(sl);i.next.push({type:s[e][0],next:t[r.join(",")]||n(r)})}return i}(il(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 Vo.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")}};Yo.empty=new Yo(!0);var Zo=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 Qo(e){let t=[];do{t.push(el(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function el(e){let t=[];do{t.push(tl(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function tl(e){let t=function(e){if(e.eat("(")){let t=Qo(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=rl(e,t)}return t}function nl(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function rl(e,t){let n=nl(e),r=n;return e.eat(",")&&(r="}"!=e.next?nl(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}function sl(e,t){return t-e}function il(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(sl)}var ol=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 ul(this,t,!1);return n.addAll(e,Uo.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ul(this,t,!0);return n.addAll(e,Uo.none,t.from,t.to),Ko.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(pl(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=ml(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=ml(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)))}},ll={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},al={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},cl={ol:!0,ul:!0};function dl(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}var hl=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=Uo.none,this.match=s||(4&i?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Vo.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=Vo.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Vo.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&&!ll.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ul=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=dl(null,t.preserveWhitespace,0)|(n?4:0);r=s?new hl(s.type,s.attrs,Uo.none,!0,t.topMatch||s.type.contentMatch,i):new hl(n?null:e.schema.topNodeType,null,Uo.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();cl.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&&cl.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:al.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(ll.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=Uo.none;for(let s of r.concat(e.marks))(t.type?t.type.allowsMarkType(s.type):fl(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=dl(e,s,i.options);4&i.options&&0==i.content.length&&(o|=4);let l=Uo.none;return n=n.filter(t=>!(i.type?i.type.allowsMarkType(t.type):fl(t.type,e))||(l=t.addToSet(l),!1)),this.nodes.push(new hl(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 pl(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ml(e){let t={};for(let n in e)t[n]=e[n];return t}function fl(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 gl=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=bl(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 bl(t).createTextNode(e.text);let{dom:n,contentDOM:r}=vl(bl(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(bl(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=xl(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return xl(e.marks)}};function xl(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function bl(e){return e.document||window.document}var yl=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=yl.get(e);return void 0===t&&yl.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 wl=Math.pow(2,16);function kl(e,t){return e+t*wl}function Sl(e){return 65535&e}var jl=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}},Cl=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))/wl}(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:kl(o/3,e-l),h=e==l?2:e==d?1:4;return(t<0?e!=l:e!=d)&&(h|=8),new jl(s,h,i)}r+=c-a}return n?e+r:new jl(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])}};Cl.empty=new Cl([]);var Nl=Object.create(null),El=class{getMap(){return Cl.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=Nl[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 Nl)throw new RangeError("Duplicate use of step JSON ID "+e);return Nl[e]=t,t.prototype.jsonID=e,t}},Al=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(lu){if(lu instanceof Jo)return e.fail(lu.message);throw lu}}};function Tl(e,t,n){let r=[];for(let s=0;s<e.childCount;s++){let i=e.child(s);i.content.size&&(i=i.copy(Tl(i.content,t,i))),i.isInline&&(i=t(i,n,s)),r.push(i)}return Vo.fromArray(r)}var Ml=class e extends El{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 Ko(Tl(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 Al.fromReplace(e,this.from,this.to,s)}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:"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))}};El.jsonID("addMark",Ml);var _l=class e extends El{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 Ko(Tl(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return Al.fromReplace(e,this.from,this.to,n)}invert(){return new Ml(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))}};El.jsonID("removeMark",_l);var Dl=class e extends El{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Al.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.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 Ol(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))}};El.jsonID("addNodeMark",Dl);var Ol=class e extends El{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Al.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new Dl(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))}};El.jsonID("removeNodeMark",Ol);var $l=class e extends El{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&Il(e,this.from,this.to)?Al.fail("Structure replace would overwrite content"):Al.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Cl([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?Ko.empty:new Ko(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?Ko.empty:new Ko(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,Ko.fromJSON(t,n.slice),!!n.structure)}};$l.MAP_BIAS=1,El.jsonID("replace",$l);var Rl=class e extends El{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&&(Il(e,this.from,this.gapFrom)||Il(e,this.gapTo,this.to)))return Al.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Al.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?Al.fromReplace(e,this.from,this.to,n):Al.fail("Content does not fit in gap")}getMap(){return new Cl([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,Ko.fromJSON(t,n.slice),n.insert,!!n.structure)}};function Il(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}El.jsonID("replaceAround",Rl),El.jsonID("attr",class e extends El{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 Al.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 Al.fromReplace(e,this.pos,this.pos+1,new Ko(Vo.from(r),0,t.isLeaf?0:1))}getMap(){return Cl.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)}}),El.jsonID("docAttr",class e extends El{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 Al.ok(n)}getMap(){return Cl.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 Pl=Error;((Pl=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype)).constructor=Pl,Pl.prototype.name="TransformError";var Ll=Object.create(null),zl=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Bl(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=Ko.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?Ko.empty:t),0==o&&Xl(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),Xl(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new Wl(e):Gl(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?Gl(e.node(0),e.node(s),e.before(s+1),e.index(s),t,n):Gl(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 Jl(e.node(0))}static atStart(e){return Gl(e,e,0,0,1)||new Jl(e)}static atEnd(e){return Gl(e,e,e.content.size,e.childCount,-1)||new Jl(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Ll[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 Ll)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ll[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Wl.between(this.$anchor,this.$head).getBookmark()}};zl.prototype.visible=!0;var Bl=class{constructor(e,t){this.$from=e,this.$to=t}},Fl=!1;function Vl(e){Fl||e.parent.inlineContent||(Fl=!0)}var Wl=class e extends zl{constructor(e,t=e){Vl(e),Vl(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 zl.near(r);let s=t.resolve(n.map(this.anchor));return new e(s.parent.inlineContent?s:r,r)}replace(e,t=Ko.empty){if(super.replace(e,t),t==Ko.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=zl.findFrom(n,r,!0)||zl.findFrom(n,-r,!0);if(!e)return zl.near(n,r);n=e.$head}return t.parent.inlineContent||(0==s||(t=(zl.findFrom(t,-r,!0)||zl.findFrom(t,r,!0)).$anchor).pos<n.pos!=s<0)&&(t=n),new e(t,n)}};zl.jsonID("text",Wl);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 Wl.between(e.resolve(this.anchor),e.resolve(this.head))}},ql=class e extends zl{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?zl.near(i):new e(i)}content(){return new Ko(Vo.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 Ul(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}};ql.prototype.visible=!1,zl.jsonID("node",ql);var Ul=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&&ql.isSelectable(n)?new ql(t):zl.near(t)}},Jl=class e extends zl{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Ko.empty){if(t==Ko.empty){e.delete(0,e.doc.content.size);let t=zl.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 Kl}};zl.jsonID("all",Jl);var Kl={map(){return this},resolve:e=>new Jl(e)};function Gl(e,t,n,r,s,i=!1){if(t.inlineContent)return Wl.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&&ql.isSelectable(r))return ql.create(e,n-(s<0?r.nodeSize:0))}else{let t=Gl(e,r,n+s,s<0?r.childCount:0,s,i);if(t)return t}n+=r.nodeSize*s}return null}function Xl(e,t,n){let r=e.steps.length-1;if(r<t)return;let s,i=e.steps[r];(i instanceof $l||i instanceof Rl)&&(e.mapping.maps[r].forEach((e,t,n,r)=>{s??=r}),e.setSelection(zl.near(e.doc.resolve(s),n)))}function Yl(e,t){return t&&e?e.bind(t):e}var Zl=class{constructor(e,t,n){this.name=e,this.init=Yl(t.init,n),this.apply=Yl(t.apply,n)}};function Ql(e,t,n){for(let r in e){let s=e[r];s instanceof Function?s=s.bind(t):"handleDOMEvents"==r&&(s=Ql(s,t,{})),n[r]=s}return n}new Zl("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new Zl("selection",{init:(e,t)=>e.selection||zl.atStart(t.doc),apply:e=>e.selection}),new Zl("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new Zl("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});var ea=class{constructor(e){this.spec=e,this.props={},e.props&&Ql(e.props,this,this.props),this.key=e.key?e.key.key:na("plugin")}getState(e){return e[this.key]}},ta=Object.create(null);function na(e){return e in ta?e+"$"+ ++ta[e]:(ta[e]=0,e+"$")}var ra=class{constructor(e="key"){this.key=na(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},sa=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},ia=function(e,t,n,r){return n&&(la(e,t,n,r,-1)||la(e,t,n,r,1))},oa=/^(img|br|input|textarea|hr)$/i;function la(e,t,n,r,s){for(var i;;){if(e==n&&t==r)return!0;if(t==(s<0?0:aa(e))){let n=e.parentNode;if(!n||1!=n.nodeType||ca(e)||oa.test(e.nodeName)||"false"==e.contentEditable)return!1;t=sa(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?aa(e):0}}}}function aa(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ca(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 da=function(e){return e.focusNode&&ia(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function ha(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}var ua="undefined"!=typeof navigator?navigator:null,pa="undefined"!=typeof document?document:null,ma=ua&&ua.userAgent||"",fa=/Edge\/(\d+)/.exec(ma),ga=/MSIE \d/.exec(ma),xa=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ma),ba=!!(ga||xa||fa),ya=ga?document.documentMode:xa?+xa[1]:fa?+fa[1]:0,va=!ba&&/gecko\/(\d+)/i.test(ma);va&&(/Firefox\/(\d+)/.exec(ma)||[0,0])[1];var wa=!ba&&/Chrome\/(\d+)/.exec(ma),ka=!!wa,Sa=wa?+wa[1]:0,ja=!ba&&!!ua&&/Apple Computer/.test(ua.vendor),Ca=ja&&(/Mobile\/\w+/.test(ma)||!!ua&&ua.maxTouchPoints>2),Na=Ca||!!ua&&/Mac/.test(ua.platform),Ea=!!ua&&/Win/.test(ua.platform),Aa=/Android \d/.test(ma),Ta=!!pa&&"webkitFontSmoothing"in pa.documentElement.style,Ma=Ta?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,_a=function(e){e&&(this.nodeName=e)};function Da(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 Oa(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof ql){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(La(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else La(e)}(e,n),!Da(e))return;let r=e.input.mouseDown;if(!t&&ka&&r){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&ia(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,sa(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&ba&&ya<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{let r,s,{anchor:i,head:o}=n;!$a||n instanceof Wl||(n.$from.parent.inlineContent||(r=Ra(e,n.from)),n.empty||n.$from.parent.inlineContent||(s=Ra(e,n.to))),e.docView.setSelection(i,o,e,t),$a&&(r&&Pa(r),s&&Pa(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(()=>{Da(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")},20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}_a.prototype=Object.create(null),new _a;var $a=ja||ka&&Sa<63;function Ra(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(ja&&s&&"false"==s.contentEditable)return Ia(s);if(!(s&&"false"!=s.contentEditable||i&&"false"!=i.contentEditable)){if(s)return Ia(s);if(i)return Ia(i)}}function Ia(e){return e.contentEditable="true",ja&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function Pa(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function La(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function za(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||Wl.between(t,n,r)}function Ba(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&&zl.findFrom(i,t)}function Fa(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function Va(e,t,n){let r=e.state.selection;if(!(r instanceof Wl)){if(r instanceof ql&&r.node.isInline)return Fa(e,new Wl(t>0?r.$to:r.$from));{let n=Ba(e.state,t);return!!n&&Fa(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 Fa(e,new Wl(r.$anchor,i))}if(!r.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ba(e.state,t);return!!(n&&n instanceof ql)&&Fa(e,n)}if(!(Na&&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)&&(ql.isSelectable(i)?Fa(e,new ql(t<0?e.state.doc.resolve(s.pos-i.nodeSize):s)):!!Ta&&Fa(e,new Wl(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}function Wa(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 qa(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<Wa(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(Ua(n))break;{let t=n.previousSibling;for(;t&&Ha(t,-1);)s=n.parentNode,i=sa(t),t=t.previousSibling;if(t)n=t,r=Wa(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}}o?Ja(e,n,r):s&&Ja(e,s,i)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let s,i,o=Wa(n);for(;;)if(r<o){if(1!=n.nodeType)break;if(!Ha(n.childNodes[r],1))break;s=n,i=++r}else{if(Ua(n))break;{let t=n.nextSibling;for(;t&&Ha(t,1);)s=t.parentNode,i=sa(t)+1,t=t.nextSibling;if(t)n=t,r=0,o=Wa(n);else{if(n=n.parentNode,n==e.dom)break;r=o=0}}}s&&Ja(e,s,i)}(e)}function Ua(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function Ja(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!ca(e);)t=sa(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&&!ca(e);)t=sa(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(da(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&&Oa(e)},50)}function Ka(e,t){let n=e.state.doc.resolve(t);if(!ka&&!Ea&&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 Ga(e,t,n){let r=e.state.selection;if(r instanceof Wl&&!r.empty||n.indexOf("s")>-1)return!1;if(Na&&n.indexOf("m")>-1)return!1;let{$from:s,$to:i}=r;if(!s.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ba(e.state,t);if(n&&n instanceof ql)return Fa(e,n)}if(!s.parent.inlineContent){let n=t<0?s:i,o=r instanceof Jl?zl.near(n,t):zl.findFrom(n,t);return!!o&&Fa(e,o)}return!1}function Xa(e,t){if(!(e.state.selection instanceof Wl))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 Ya(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function Za(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")||gl.fromSchema(e.state.schema),l=lc(),a=l.createElement("div");a.appendChild(o.serializeFragment(r,{document:l}));let c,d=a.firstChild,h=0;for(;d&&1==d.nodeType&&(c=oc[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 Qa(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 Ko(Vo.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=gl.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=lc(),s=r.body,i=/<([a-z][^>\s]+)/i.exec(e);if((n=i&&oc[i[1].toLowerCase()])&&(e=n.map(e=>"<"+e+">").join("")+e+n.map(e=>"</"+e+">").reverse().join("")),s.innerHTML=function(e){let t=window.trustedTypes;if(!t)return e;if(!ac){if(ac=t.defaultPolicy)try{return ac.createHTML(e)}catch(n){}ac=t.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})}return ac.createHTML(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),Ta&&function(e){let t=e.querySelectorAll(ka?"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")||ol.fromSchema(e.state.schema)).parseSlice(i,{preserveWhitespace:!(!a&&!d),context:s,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||ec.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(lu){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;try{e.checkAttrs(n[l+1])}catch(lu){break}s=Vo.from(e.create(n[l+1],s)),i++,o++}return new Ko(s,i,o)}(ic(o,+d[1],+d[2]),d[4]);else if(o=Ko.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&&nc(n,r,e,i[i.length-1],0))i[i.length-1]=t;else{i.length&&(i[i.length-1]=rc(i[i.length-1],r.length));let t=tc(e,n);i.push(t),s=s.matchType(t.type),r=n}}),i)return Vo.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=ic(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,a)}),o}var ec=/^(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 tc(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,Vo.from(e));return e}function nc(e,t,n,r,s){if(s<e.length&&s<t.length&&e[s]==t[s]){let i=nc(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(Vo.from(tc(n,e,s+1))))}}function rc(e,t){if(0==t)return e;let n=e.content.replaceChild(e.childCount-1,rc(e.lastChild,t-1)),r=e.contentMatchAt(e.childCount).fillBefore(Vo.empty,!0);return e.copy(n.append(r))}function sc(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=sc(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(Vo.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(l))}function ic(e,t,n){return t<e.openStart&&(e=new Ko(sc(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new Ko(sc(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}var oc={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 lc(){return document.implementation.createHTMLDocument("title")}var ac=null,cc={},dc={};function hc(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function uc(e){return{left:e.clientX,top:e.clientY}}function pc(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 mc(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 fc(e,t,n,r){return pc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}function gc(e,t,n,r){return pc(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=xc(e,t,!0),s=e.state.doc;return!!r&&(mc(e,r,"pointer"),r instanceof Wl&&s.eq(e.state.doc)&&(e.input.mouseDown=new kc(e,r)),!0)}(e,n,r)}function xc(e,t,n){let r=e.state.doc;if(-1==t)return r.inlineContent?Wl.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 Wl.create(r,t+1,t+1+e.content.size);if(n&&ql.isSelectable(e))return ql.create(r,t)}return null}function bc(e){return Nc(e)}dc.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(),!Aa||!ka||13!=n.keyCode))if(229!=n.keyCode&&e.domObserver.forceFlush(),!Ca||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||Na&&72==n&&"c"==r)return Xa(e,-1)||qa(e,-1);if(46==n&&!t.shiftKey||Na&&68==n&&"c"==r)return Xa(e,1)||qa(e,1);if(13==n||27==n)return!0;if(37==n||Na&&66==n&&"c"==r){let t=37==n?"ltr"==Ka(e,e.state.selection.from)?-1:1:-1;return Va(e,t,r)||qa(e,t)}if(39==n||Na&&70==n&&"c"==r){let t=39==n?"ltr"==Ka(e,e.state.selection.from)?1:-1:1;return Va(e,t,r)||qa(e,t)}return 38==n||Na&&80==n&&"c"==r?Ga(e,-1,r)||qa(e,-1):40==n||Na&&78==n&&"c"==r?function(e){if(!ja||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;Ya(e,n,"true"),setTimeout(()=>Ya(e,n,"false"),20)}return!1}(e)||Ga(e,1,r)||qa(e,1):r==(Na?"m":"c")&&(66==n||73==n||89==n||90==n)}(e,n)?n.preventDefault():hc(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,ha(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},dc.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},dc.keypress=(e,t)=>{let n=t;if(Sc(e)||!n.charCode||n.ctrlKey&&!n.altKey||Na&&n.metaKey)return;if(e.someProp("handleKeyPress",t=>t(e,n)))return void n.preventDefault();let r=e.state.selection;if(!(r instanceof Wl&&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 yc=Na?"metaKey":"ctrlKey";cc.mousedown=(e,t)=>{let n=t;e.input.shiftKey=n.shiftKey;let r=bc(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[yc]&&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(uc(n));o&&("singleClick"==i?e.input.mouseDown=new wc(e,o,n,!!r):("doubleClick"==i?fc:gc)(e,o.pos,o.inside,n)?n.preventDefault():hc(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}},wc=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[yc],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 ql&&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()),hc(e,"pointer")}done(){super.done(),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>{this.view.isDestroyed||Oa(this.view)})}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(uc(e))),this.updateAllowDefault(e),this.allowDefault||!t?hc(this.view,"pointer"):function(e,t,n,r,s){return pc(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 ql&&(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(ql.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&&(mc(e,ql.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&&ql.isSelectable(r))&&(mc(e,new ql(n),"pointer"),!0)}(e,n))}(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():0==e.button&&(this.flushed||ja&&this.mightDrag&&!this.mightDrag.node.isAtom||ka&&!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)?(mc(this.view,zl.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):hc(this.view,"pointer")}move(e){this.updateAllowDefault(e),hc(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)}},kc=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(),hc(this.view,"pointer");let t=this.view.posAtCoords(uc(e)),n=t&&xc(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];mc(this.view,Wl.create(r,i,o),"pointer")}};function Sc(e,t){return!!e.composing||!!(ja&&Math.abs(Date.now()-e.input.compositionEndedAt)<500)&&(e.input.compositionEndedAt=-2e8,!0)}cc.touchstart=e=>{e.input.lastTouch=Date.now(),bc(e),hc(e,"pointer")},cc.touchmove=e=>{e.input.lastTouch=Date.now(),hc(e,"pointer")},cc.contextmenu=e=>bc(e);var jc=Aa?5e3:-1;function Cc(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>Nc(e),t))}function Nc(e,t=!1){if(!(Aa&&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(da(n)){for(l=o;s&&!s.node;)s=s.parent;let e=s.node;if(s&&e.isAtom&&ql.isSelectable(e)&&s.parent&&(!e.isInline||!function(e,t,n){for(let r=0==t,s=t==aa(e);r||s;){if(e==n)return!0;let t=sa(e);if(!(e=e.parentNode))return!1;r=r&&0==t,s=s&&t==aa(e)}}(n.focusNode,n.focusOffset,s.dom))){let e=s.posBefore;a=new ql(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=za(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}}dc.compositionstart=dc.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof Wl&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ka&&Ea&&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(),Nc(e,!0),e.markCursor=null;else if(Nc(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}Cc(e,jc)},dc.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++,Cc(e,20))};var Ec=ba&&ya<15||Ca&&Ma<604;function Ac(e,t,n,r,s){let i=Qa(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,s,i||Ko.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 Tc(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," "):""}cc.copy=dc.cut=(e,t)=>{let n=t,r=e.state.selection,s="cut"==n.type;if(r.empty)return;let i=Ec?null:n.clipboardData,{dom:o,text:l}=Za(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"))},dc.paste=(e,t)=>{let n=t;if(e.composing&&!Aa)return;let r=Ec?null:n.clipboardData,s=e.input.shiftKey&&45!=e.input.lastKeyCode;r&&Ac(e,Tc(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?Ac(e,r.value,null,s,t):Ac(e,r.textContent,r.innerHTML,s,t)},50)}(e,n)};var Mc=class{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}},_c=Na?"altKey":"ctrlKey";function Dc(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[_c]}cc.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(uc(n));if(o&&o.pos>=i.from&&o.pos<=(i instanceof ql?i.to-1:i.to));else if(r&&r.mightDrag)s=ql.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=ql.create(e.state.doc,t.posBefore))}let{dom:l,text:a,slice:c}=Za(e,(s||e.state.selection).content());(!n.dataTransfer.files.length||!ka||Sa>120)&&n.dataTransfer.clearData(),n.dataTransfer.setData(Ec?"Text":"text/html",l.innerHTML),n.dataTransfer.effectAllowed="copyMove",Ec||n.dataTransfer.setData("text/plain",a),e.dragging=new Mc(c,Dc(e,n),s)},cc.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},dc.dragover=dc.dragenter=(e,t)=>t.preventDefault(),dc.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(uc(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=Qa(e,Tc(t.dataTransfer),Ec?null:t.dataTransfer.getData("text/html"),!1,s);let o=!(!n||!Dc(e,t));if(e.someProp("handleDrop",n=>n(e,t,i||Ko.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&&ql.isSelectable(i.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(i.content.firstChild))a.setSelection(new ql(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(za(e,u,a.doc.resolve(t)))}e.focus(),e.dispatch(a.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},cc.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&Oa(e)},20))},cc.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)},cc.beforeinput=(e,t)=>{if(Aa&&"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,ha(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 au in dc)cc[au]=dc[au];function Oc(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 $c=class e{constructor(e,t){this.toDOM=e,this.spec=t||zc,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 Pc(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&&Oc(this.spec,t.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Rc=class e{constructor(e,t){this.attrs=e,this.spec=t||zc}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 Pc(s,i,this)}valid(e,t){return t.from<t.to}eq(t){return this==t||t instanceof e&&Oc(this.attrs,t.attrs)&&Oc(this.spec,t.spec)}static is(t){return t.type instanceof e}destroy(){}},Ic=class e{constructor(e,t){this.attrs=e,this.spec=t||zc}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 Pc(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&&Oc(this.attrs,t.attrs)&&Oc(this.spec,t.spec)}destroy(){}},Pc=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 $c(n,r))}static inline(t,n,r,s){return new e(t,n,new Rc(r,s))}static node(t,n,r,s){return new e(t,n,new Ic(r,s))}get spec(){return this.type.spec}get inline(){return this.type instanceof Rc}get widget(){return this.type instanceof $c}},Lc=[],zc={},Bc=class e{constructor(e,t){this.local=e.length?e:Lc,this.children=t.length?t:Lc}static create(e,t){return t.length?Uc(t,e,0,zc):Fc}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==Fc||0==e.maps.length?this:this.mapInner(e,t,0,0,n||zc)}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!=Fc?(l[c]=d,l[c+1]=h,l[c+2]=r):(l[c+1]=-2,a=!0)}else a=!0}if(a){let a=Uc(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 Bc(t.sort(Jc),l)}(this.children,o||[],t,n,r,s,i):o?new e(o.sort(Jc),Lc):Fc}add(t,n){return n.length?this==Fc?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,Uc(o,e,l+1,zc)),i+=3}});let o=Wc(i?qc(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(Jc):this.local,s||this.children)}remove(e){return 0==e.length||this==Fc?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!=Fc?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):Fc}forChild(t,n){if(this==Fc)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 Rc){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(Jc),Lc);return r?new Vc([t,r]):t}return r||Fc}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 Kc(this.localsInner(e))}localsInner(e){if(this==Fc)return Lc;if(e.inlineContent||!this.local.some(Rc.is))return this.local;let t=[];for(let n=0;n<this.local.length;n++)this.local[n].type instanceof Rc||t.push(this.local[n]);return t}forEachSet(e){e(this)}};Bc.empty=new Bc([],[]),Bc.removeOverlap=Kc;var Fc=Bc.empty,Vc=class e{constructor(e){this.members=e}map(t,n){const r=this.members.map(e=>e.map(t,n,zc));return e.from(r)}forChild(t,n){if(n.isLeaf)return Bc.empty;let r=[];for(let s=0;s<this.members.length;s++){let i=this.members[s].forChild(t,n);i!=Fc&&(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?Kc(n?t:t.sort(Jc)):Lc}static from(t){switch(t.length){case 0:return Fc;case 1:return t[0];default:return new e(t.every(e=>e instanceof Bc)?t:t.reduce((e,t)=>e.concat(t instanceof Bc?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Wc(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 Pc(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 qc(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function Uc(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=Uc(l,t,n+o+1,r);e!=Fc&&s.push(o,o+t.nodeSize,e)}});let o=Wc(i?qc(e):e,-n).sort(Jc);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 Bc(o,s):Fc}function Jc(e,t){return e.from-t.from||e.to-t.to}function Kc(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),Gc(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),Gc(t,s+1,i.copy(r.to,i.to)))}}return t}function Gc(e,t,n){for(;t<e.length&&Jc(n,e[t])>0;)t++;e.splice(t,0,n)}var Xc=/[\uD800-\uDBFF]/,Yc=/[\uDC00-\uDFFF]/,Zc=(e,t)=>e>>>t|e<<32-t,Qc=e=>Zc(e,2)^Zc(e,13)^Zc(e,22),ed=e=>Zc(e,6)^Zc(e,11)^Zc(e,25),td=e=>Zc(e,7)^Zc(e,18)^e>>>3,nd=e=>Zc(e,17)^Zc(e,19)^e>>>10,rd=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]),sd=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),id=class{constructor(){const e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(sd),this._W=new Uint32Array(e,64,64)}_updateHash(){const e=this._H,t=this._W;for(let d=16;d<64;d++)t[d]=nd(t[d-2])+t[d-7]+td(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+ed(o)+(o&l^~o&a)+rd[u]+t[u]>>>0,h=Qc(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}},od=new ra("y-sync"),ld=new ra("y-undo"),ad=(new ra("yjs-cursor"),e=>{return bn((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=it();return e(t),ot(t)})(t=>bt(t,e)))(e),(new id).digest(t))));var t}),cd=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!Kr(t.ds,e.id),dd=[{light:"#ecd44433",dark:"#ecd444"}],hd=(e,t,n)=>{if(!e.has(n)){if(e.size<t.length){const n=Me();e.forEach(e=>n.add(e)),t=t.filter(e=>!n.has(e))}e.set(n,(r=t)[Le(qt()*r.length)])}var r;return e.get(n)},ud=(e,{colors:t=dd,colorMapping:n=new Map,permanentUserData:r=null,onFirstRender:s=()=>{},mapping:i}={})=>{let o=!1;const l=new fd(e,i),a=new ea({props:{editable:e=>{const t=od.getState(e);return null==t.snapshot&&null==t.prevSnapshot}},key:od,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(od);if(void 0!==n){t=Object.assign({},t);for(const e in n)t[e]=n[e]}return e.docChanged&&(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||$r(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=ld.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)},od)})}},destroy:()=>{l.destroy()}})});return a},pd=(e,t,n,r)=>{if(null==n)return r;if(!(null===r||n>1&&r<=1||Wd(t,e,n,r)))return r;const s=Vd(t,e,n);return null!==s?s:r},md=(e,t)=>{const n=t.selection.jsonID;return{type:n,depth:"nodeRange"===n?t.selection.depth:void 0,anchor:Ld(t.selection.anchor,e.type,e.mapping),head:Ld(t.selection.head,e.type,e.mapping),absAnchor:t.selection.anchor,absHead:t.selection.head}},fd=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=md(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()&&(un&&null===this._domSelectionInView&&($r(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=Ar.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=As(Zr(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(od,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{const e=this.type.toArray().map(e=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Ko(Vo.from(e),0,0));t.setMeta(od,{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=>xd(e,this.prosemirrorView.state.schema,this)).filter(e=>null!==e),n=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new Ko(Vo.from(t),0,0));if(e){const t=Be(Fe(e.anchor,0),n.doc.content.size),r=Be(Fe(e.head,0),n.doc.content.size);n.setSelection(Wl.create(n.doc,t,r))}this.prosemirrorView.dispatch(n.setMeta(od,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,n){let r=this.doc,s=this.type;if(e||(e=Ts(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if(e instanceof Uint8Array&&t instanceof Uint8Array||Et(),r=new rs({gc:!1}),hs(r,t),t=Ts(r),hs(r,e),e=Ts(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[Is(e,s._item.id.clock)].content.type}this.mapping.clear(),this.mux(()=>{r.transact(r=>{const i=n.permanentUserData;i&&i.dss.forEach(e=>{Jr(r,e,e=>{})});const o=(e,t)=>{const r="added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t);return{user:r,type:e,color:hd(n.colorMapping,n.colors,r)}},l=bi(s,new Es(t.ds,e.sv)).map(n=>!n._item.deleted||cd(n._item,e)||cd(n._item,t)?xd(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 Ko(Vo.from(l),0,0));this.prosemirrorView.dispatch(a.setMeta(od,{isChangeOrigin:!0}))},od)})}_typeChanged(e,t){if(null==this.prosemirrorView)return;const n=od.getState(this.prosemirrorView.state);0!==e.length&&null==n.snapshot&&null==n.prevSnapshot?this.mux(()=>{const e=(e,t)=>this.mapping.delete(t);Jr(t,t.deleteSet,e=>{if(e.constructor===Do){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=>gd(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 Ko(Vo.from(n),0,0));((e,t,n,r)=>{if(null!==t&&null!==t.anchor&&null!==t.head)if("all"===t.type)e.setSelection(new Jl(e.doc));else if("node"===t.type){const r=Bd(n.doc,n.type,t.anchor,n.mapping);null!==r&&e.setSelection(((e,t)=>{const n=e.doc.resolve(t);return n.nodeAfter?ql.create(e.doc,t):Wl.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=zl.fromJSON(e.doc,{type:"nodeRange",anchor:s,head:i,depth:r});return t.ranges.length?t:Wl.near(e.doc.resolve(s))}catch(lu){return Wl.near(e.doc.resolve(s))}})(e,Bd(n.doc,n.type,t.anchor,n.mapping),Bd(n.doc,n.type,t.head,n.mapping),t.depth);null!==r&&e.setSelection(r)}else{let s=Bd(n.doc,n.type,t.anchor,n.mapping),i=Bd(n.doc,n.type,t.head,n.mapping);null!=r&&(s=pd(e.doc,r,t.absAnchor,s),i=pd(e.doc,r,t.absHead,i)),null===s&&(s=i),null===i&&(i=s),null!==s&&null!==i&&e.setSelection(Wl.between(e.doc.resolve(s),e.doc.resolve(i)))}})(s,this.beforeTransactionSelection,this,r),s=s.setMeta(od,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Ys}),null!==this.beforeTransactionSelection&&this._isLocalCursorInView()&&s.scrollIntoView(),this.prosemirrorView.dispatch(s)}):this.renderSnapshot(n.snapshot,n.prevSnapshot)}_prosemirrorChanged(e){this.doc.transact(()=>{Id(this.doc,this.type,e,this),this.beforeTransactionSelection=md(this,this.prosemirrorView.state)},od)}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))}},gd=(e,t,n,r,s,i)=>{const o=n.mapping.get(e);if(void 0===o){if(e instanceof to)return xd(e,t,n,r,s,i);throw Nt()}return o},xd=(e,t,n,r,s,i)=>{const o=[],l=e=>{if(e instanceof to){const l=gd(e,t,n,r,s,i);null!==l&&o.push(l)}else{const l=(e._item.right?.content)?.type;l instanceof Zi&&!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=bd(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):bi(e,new Es(s.ds,r.sv)).forEach(l);try{const l=e.getAttributes(r);void 0!==r&&(cd(e._item,r)?cd(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(lu){return e.doc.transact(t=>{e._item.delete(t)},od),n.mapping.delete(e),null}},bd=(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,$d(n.attributes,t)))}}catch(lu){return e.doc.transact(t=>{e._item.delete(t)},od),null}return o},yd=(e,t)=>e instanceof Array?((e,t)=>{const n=new so,r=e.map(e=>({insert:e.text,attributes:Rd(e.marks,t)}));return n.applyDelta(r),t.mapping.set(n,e),n})(e,t):((e,t)=>{const n=new to(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,kd(e).map(e=>yd(e,t))),t.mapping.set(n,e),n})(e,t),vd=e=>"object"==typeof e&&null!==e,wd=(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)&&wd(o,l)}return r},kd=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&&nn(e.attributes||{}).length===t[n].marks.length&&sn(e.attributes,(e,r)=>{const s=Od(r),i=t[n].marks;return!!i.find(e=>e.type.name===s)&&wd(e,i.find(e=>e.type.name===s)?.attrs)}))},jd=(e,t)=>{if(e instanceof to&&!(t instanceof Array)&&Pd(e,t)){const n=kd(t);return e._length===n.length&&wd(e.getAttributes(),t.attrs)&&e.toArray().every((e,t)=>jd(e,n[t]))}return e instanceof so&&t instanceof Array&&Sd(e,t)},Cd=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Nd=(e,t,n,r)=>{n>0&&(e.slice(t,t+n).forEach(e=>r.mapping.delete(e)),e.delete(t,n))},Ed=(e,t,n,r,s,i)=>{if(r<s){const o=[];for(let e=r;e<s;e++)o.push(yd(n[e],i));e.insert(t,o)}},Ad=(e,t,n,r)=>t instanceof so&&n instanceof Array?(Sd(t,n)?r.mapping.set(t,n):_d(t,n,r),!0):!(!(t instanceof to)||n instanceof Array||!Pd(t,n)||(jd(t,n)?r.mapping.set(t,n):Id(e,t,n,r),0)),Td=(e,t,n,r,s,i,o,l,a)=>{const c=Be(i-s,l-o);for(let d=0;d<c;d++){const i=r[s+d],l=n[o+d];Ad(e,i,l,a)||(Nd(t,o+d,1,a),Ed(t,o+d,n,o+d,o+d+1,a))}Nd(t,o+c,i-s-c,a),Ed(t,o+c,n,o+c,l,a)},Md=(e,t,n)=>{const r=e.toArray(),s=kd(t),i=s.length,o=r.length,l=Be(o,i);let a=0,c=0,d=!1;for(;a<l;a++){const e=r[a],t=s[a];if(Cd(n.mapping.get(e),t))d=!0;else if(!jd(e,t))break}for(;a+c<l;c++){const e=r[o-c-1],t=s[i-c-1];if(Cd(n.mapping.get(e),t))d=!0;else if(!jd(e,t))break}return{equalityFactor:a+c,foundMappedChild:d}},_d=(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 xo?t+=n.content.str:n.content instanceof po&&(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,Rd(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&&Xc.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&&Yc.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})))},Dd=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Od=e=>Dd.exec(e)?.[1]??e,$d=(e,t)=>{const n=[];for(const r in e)n.push(t.mark(Od(r),e[r]));return n},Rd=(e,t)=>{const n={};return e.forEach(e=>{if("ychange"!==e.type.name){const r=Te(t.isOMark,e.type,()=>!e.type.excludes(e.type));n[r?`${e.type.name}--${ad(e.toJSON())}`:e.type.name]=e.attrs}}),n},Id=(e,t,n,r)=>{if(t instanceof to&&t.nodeName!==n.type.name)throw new Error("node name mismatch!");if(r.mapping.set(t,n),t instanceof to){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=kd(n),i=s.length,o=t.toArray(),l=o.length,a=Be(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&&Cd(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 so&&t instanceof Array||e.yChild instanceof to&&!(t instanceof Array))}))return!1;let o=0,l=0;for(const a of i){Td(e,t,n,r,o,a.yIndex,l,a.pIndex,s);const i=n[a.pIndex];Ad(e,a.yChild,i,s),o=a.yIndex+1,l=a.pIndex+1}return Td(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(!Cd(r.mapping.get(e),t)){if(!jd(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(!Cd(r.mapping.get(e),t)){if(!jd(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 so&&a instanceof Array)Sd(n,a)||_d(n,a,r),c+=1;else{let s=n instanceof to&&Pd(n,a),i=h instanceof to&&Pd(h,u);if(s&&i){const e=Md(n,a,r),t=Md(h,u,r);e.foundMappedChild&&!t.foundMappedChild?i=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?s=!1:i=!1}s?(Id(e,n,a,r),c+=1):i?(Id(e,h,u,r),d+=1):(r.mapping.delete(t.get(c)),t.delete(c,1),t.insert(c,[yd(a,r)]),c+=1)}}const n=l-c-d;if(1===l&&0===i&&o[0]instanceof so?(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(yd(s[t],r));t.insert(c,e)}},od)},Pd=(e,t)=>!(t instanceof Array)&&e.nodeName===t.type.name,Ld=(e,t,n)=>{if(0===e)return Cs(t,0,-1);let r=null===t._first?null:t._first.content.type;for(;null!==r&&t!==r;){if(r instanceof so){if(r._length>=e)return Cs(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 ks(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 ks(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 Et();if(0===e&&r.constructor!==so&&r!==t)return zd(r._item.parent,r._item)}return Cs(t,t._length,-1)},zd=(e,t)=>{let n=null,r=null;return null===e._item?r=vs(e):n=ys(e._item.id.client,e._item.id.clock),new ks(n,r,t.id)},Bd=(e,t,n,r)=>{const s=Ns(n,e);if(null===s||s.type!==t&&!ws(t,s.type._item))return null;let i=s.type,o=0;if(i.constructor===so)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 so)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 so)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=Ns(t,e);return null!==r&&r.type instanceof so&&null!==t.item&&n<=1})(e,n,l)?null:l},Fd=(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])},Vd=(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&&Fd(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)},Wd=(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||!Fd(s.parent.attrs,i.parent.attrs);if(o||l){const s=Vd(e,t,n);return null!==s&&s!==r}return!1},Hd=new Set(["paragraph"]);function qd(e){return!!e.getMeta(od)}function Ud(e,t){const n=od.getState(e);return Bd(n.doc,n.type,t,n.binding.mapping)||0}function Jd(e,t){const n=od.getState(e);return Ld(t,n.type,n.binding.mapping)}var Kd=class e extends x.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}}};x.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 Kd?e.yRelativePosition:null;if(qd(t)&&r)return{position:new Kd(Ud(n,r),r),mapResult:null};const s=(0,x.getUpdatedPosition)(e,t),i=s.position.position;return{position:new Kd(i,null!=r?r:Jd(n,i)),mapResult:s.mapResult}}(e,t,this.editor.state),this.editor.utils.createMappablePosition=e=>function(e,t){return new Kd(e,Jd(t,e))}(e,this.editor.state)},addCommands:()=>({undo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ld.getState(t).undoManager.undoStack.length&&(!n||(e=>{const t=ld.getState(e).undoManager;if(null!=t)return t.undo(),!0})(t))),redo:()=>({tr:e,state:t,dispatch:n})=>(e.setMeta("preventDispatch",!0),0!==ld.getState(t).undoManager.redoStack.length&&(!n||(e=>{const t=ld.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 ea({key:ld,state:{init:(r,s)=>{const i=od.getState(s);let o=n;if(!o){const n=i.doc,r=new Set(n?n._observers.get("destroy"):[]);o=new Ys(i.type,{trackedOrigins:new Set([od].concat(t)),deleteFilter:t=>((e,t)=>!(e instanceof Do&&e.content instanceof No&&(e.content.type instanceof Zi||e.content.type instanceof to&&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=od.getState(r).binding,i=t.undoManager,o=i.undoStack.length>0,l=i.redoStack.length>0;return s?{undoManager:i,prevSel:md(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=od.getState(e.state),n=ld.getState(e.state).undoManager;return n.on("stack-item-added",({stackItem:n})=>{const r=t.binding;r&&n.meta.set(r,ld.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}=ld.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()}}},[ud(e,{...this.options.ySyncOptions,onFirstRender:this.options.onFirstRender}),t,this.editor.options.enableContentCheck&&new b.Plugin({key:new b.PluginKey("filterInvalidContent"),filterTransaction:t=>{if(!qd(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)||void 0===t||t.destroy()}}),!0}}})].filter(Boolean)}});function Gd(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 Xd=[{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 Yd(){const e=n.m$3(),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,g.useState)(!1),[c,d]=(0,g.useState)("note"),[h,u]=(0,g.useState)(""),[p,m]=(0,g.useState)("");(0,g.useEffect)(()=>{l&&(d(s||"note"),u(i||""),m(o||""))},[l,s,i,o]);const f=(0,g.useCallback)(()=>{t&&(t.chain().updateAttributes(n.q.name,{type:c,title:h,body:p}).focus().run(),a(!1))},[t,c,h,p]),x=(0,g.useCallback)(()=>{a(!1)},[]),b=(0,g.useCallback)(()=>{Gd(n.q.name,t)},[t]),v=(0,g.useCallback)(()=>t.isActive(n.q.name),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"top",offset:8,flip:!0},pluginKey:"RichTextBubbleCallout",shouldShow:v,children:(0,y.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,y.jsxs)(n.o$1,{onOpenChange:a,open:l,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{icon:"Pencil",tooltip:r("editor.callout.edit.title")})}),(0,y.jsxs)(n.h$1,{children:[(0,y.jsx)(n.m,{children:r("editor.callout.edit.title")}),(0,y.jsxs)("div",{className:"richtext-space-y-4 richtext-py-4",children:[(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.type")}),(0,y.jsxs)(n.R,{onValueChange:d,value:c,children:[(0,y.jsx)(n.B,{children:(0,y.jsx)(n.S,{className:"richtext-text-accent",placeholder:r("editor.callout.dialog.type.placeholder")})}),(0,y.jsx)(n.V$1,{children:Xd.map(e=>(0,y.jsx)(n.D$2,{value:e.value,children:r(`editor.callout.type.${e.value}`)},e.value))})]})]}),(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.title.label")}),(0,y.jsx)(n.i$1,{onChange:e=>u(e.target.value),placeholder:r("editor.callout.dialog.title.placeholder"),type:"text",value:h})]}),(0,y.jsxs)("div",{className:"richtext-space-y-2",children:[(0,y.jsx)(n.s$2,{children:r("editor.callout.dialog.body.label")}),(0,y.jsx)(n.i$1,{onChange:e=>m(e.target.value),placeholder:r("editor.callout.dialog.body.placeholder"),type:"text",value:p})]})]}),(0,y.jsxs)(n.n$2,{children:[(0,y.jsx)(n.x$1,{onClick:x,variant:"outline",children:r("editor.callout.dialog.button.cancel")}),(0,y.jsx)(n.x$1,{onClick:f,children:r("editor.callout.dialog.button.apply")})]})]})]}),(0,y.jsx)(n.f$2,{action:b,icon:"Trash2",tooltip:r("editor.delete")})]})}):(0,y.jsx)(y.Fragment,{})}function Zd(){const e=n.m$3(),t=n.d$2(),{t:r}=n._(),s=(0,g.useCallback)(()=>t.isActive(n.A.name),[t]),i=(0,g.useCallback)(()=>Gd(n.A.name,t),[t]),o=(0,g.useCallback)(()=>t.chain().focus().addColBefore().run(),[t]),l=(0,g.useCallback)(()=>t.chain().focus().addColAfter().run(),[t]),a=(0,g.useCallback)(()=>t.chain().focus().deleteCol().run(),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleColumns",shouldShow:s,children:(0,y.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,y.jsx)(n.f$2,{action:o,icon:"ColumnAddLeft",tooltip:r("editor.table.menu.insertColumnBefore")}),(0,y.jsx)(n.f$2,{action:l,icon:"ColumnAddRight",tooltip:r("editor.table.menu.insertColumnAfter")}),(0,y.jsx)(n.f$2,{action:a,icon:"DeleteColumn",tooltip:r("editor.table.menu.deleteColumn")}),(0,y.jsx)(n.f$2,{action:i,icon:"Trash2",tooltip:r("editor.table.menu.delete_column")})]})}):(0,y.jsx)(y.Fragment,{})}function Qd(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$2[s]}),isActive:()=>e.isActive("image",{width:n.p$2[s]})}}))}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.updateImageGif({width:n.p$2[s]}),isActive:()=>e.isActive("image",{width:n.p$2[s]})}}))}function th(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 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?.setAlignImageGif?.(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?.setAlignImageMermaid?.(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?.setAlignImageDrawer?.(s),isActive:()=>e.isActive({align:s})||!1,disabled:!1}}))}function ih(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 oh(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 lh=!1;function ah({editor:e,attrs:t,extension:r}){const[s,i]=(0,g.useState)(!1),o=(0,g.useRef)(null),l=(0,g.useRef)(null),{alt:a,align:c}=t,d=r?.options.upload;(0,g.useEffect)(()=>{s&&setTimeout(()=>{(async()=>{const e=document.querySelector("#easydrawer");e&&(o.current=new N.Editor(e,{wheelEventsEnabled:!1,disableZoom:!0}),l.current=(0,N.makeDropdownToolbar)(o.current),l.current.addDefaultToolWidgets(),o.current.loadFromSVG(decodeURIComponent(a)))})()},200)},[s]);const h=()=>{if(lh){for(;o.current.history.redoStackSize>0;)o.current.history.redo();lh=!1}else o.current.history.undo()};return(0,y.jsxs)(n.o$1,{onOpenChange:i,open:s,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{action:()=>i(!0),icon:"Pencil",tooltip:"Edit Drawer"})}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:"Edit Drawer"}),(0,y.jsxs)("div",{style:{height:"100%",borderWidth:1,background:"white",position:"relative"},children:[(0,y.jsx)("div",{className:"richtext-size-full",id:"easydrawer"}),(0,y.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(!lh){for(;o.current.history.undoStackSize>0;)h();lh=!0}},onRedo:()=>{lh||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,y.jsx)(n.n$2,{children:(0,y.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 ch({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function dh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=n.Ht(s,n.ve.name),o=n.v(n.ve.name),l=(0,g.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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(ah,{attrs:i,editor:s,extension:o},`bubbleMenu-drawer-${t}`):(0,y.jsx)(ch,{editor:s,item:e},`bubbleMenu-drawer-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function hh({children:e,visible:t,toggleVisible:r}){const{t:s}=n._(),i=n.d$2(),[o,l]=(0,g.useState)(null);(0,g.useEffect)(()=>{n.l().then(l)},[]);const{text:a,macros:c}=n.Ht(i,n.Wt.name,{text:"",macros:""}),[d,h]=(0,g.useState)(decodeURIComponent(a||"")),[u,p]=(0,g.useState)(decodeURIComponent(c||""));(0,g.useEffect)(()=>{t&&(h(decodeURIComponent(a||"")),p(decodeURIComponent(c||"")))},[t]);const m=(0,g.useCallback)(()=>{i.chain().focus().setKatex({text:encodeURIComponent(d),macros:encodeURIComponent(u)}).run(),h(""),p(""),r(!1)},[i,d,u,r]),f=(0,g.useMemo)(()=>{if(!o)return d;try{return o.renderToString(d,{macros:n.Y(u||"")})}catch{return d}},[d,u,o]),x=(0,g.useMemo)(()=>`${d}`.trim()?f:null,[d,f]);return(0,y.jsxs)(n.o$1,{onOpenChange:r,open:t,children:[(0,y.jsx)(n.s,{asChild:!0,children:e}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:s("editor.formula.dialog.text")}),(0,y.jsx)("div",{style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,y.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,y.jsxs)("div",{className:"richtext-flex-1",children:[(0,y.jsx)(n.s$2,{className:"mb-[6px]",children:"Expression"}),(0,y.jsx)(n.i,{autoFocus:!0,className:"richtext-mb-[10px]",onChange:e=>h(e.target.value),placeholder:"Text",required:!0,rows:10,value:d,style:{color:"var(--richtext-foreground)"}}),(0,y.jsx)(n.s$2,{className:"mb-[6px]",children:"Macros"}),(0,y.jsx)(n.i,{onChange:e=>p(e.target.value),placeholder:"Macros",rows:10,value:u,style:{color:"var(--richtext-foreground)"}})]}),(0,y.jsx)("div",{className:"richtext-flex richtext-flex-1 richtext-items-center richtext-justify-center richtext-rounded-[10px] richtext-p-[10px]",dangerouslySetInnerHTML:{__html:x||""},style:{height:"100%",borderWidth:1,minHeight:500,background:"#fff"}})]})}),(0,y.jsx)(n.n$2,{children:(0,y.jsx)(n.x$1,{onClick:m,type:"button",children:"Save changes"})})]})]})}function uh(){const e=n.m$3(),t=n.d$2(),[r,s]=(0,g.useState)(!1),i=(0,g.useCallback)(()=>t.isActive(n.Wt.name),[t]),o=(0,g.useCallback)(()=>Gd(n.Wt.name,t),[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleKatex",shouldShow:i,children:(0,y.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,y.jsx)(hh,{toggleVisible:s,visible:r,children:(0,y.jsx)(n.f$2,{action:()=>s(!r),tooltip:"Edit",children:(0,y.jsx)(v.Pencil,{size:16})})}),(0,y.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,y.jsx)(v.Trash2,{size:16})})]})}):(0,y.jsx)(y.Fragment,{})}function ph(e){const{t:t}=n._();return(0,y.jsxs)("div",{className:"richtext-flex richtext-flex-nowrap",children:[(0,y.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,y.jsx)(n.f$2,{icon:"Pencil",tooltip:t("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onEdit()}}),(0,y.jsx)(n.f$2,{icon:"Unlink",tooltip:t("editor.link.unlink.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{e?.onClear()}})]})}function mh(){const e=n.m$3(),t=n.d$2(),[r,s]=(0,g.useState)(!1),i=n.Ht(t,n.Fe.name)?.href,o=(0,g.useCallback)(({editor:e})=>e.isActive(n.Fe.name),[]),l=(0,g.useCallback)(()=>{t.chain().extendMarkRange("link").unsetLink().focus().run(),s(!1)},[t]);return e?(0,y.jsx)(k.BubbleMenu,{editor:t,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleLink",shouldShow:o,children:(0,y.jsx)(y.Fragment,{children:(0,y.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,y.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,y.jsx)(ph,{editor:t,link:i,onClear:l,onEdit:()=>{s(!0)}})})})}):(0,y.jsx)(y.Fragment,{})}function fh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentdisabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function gh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=(0,g.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()}}},...Qd(e,t),...th(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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(fh,{editor:s,item:e},`bubbleMenu-image-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function xh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=(0,g.useMemo)(()=>function(e,t){return[...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,E.deleteSelection)(t,n)}}}]}(s,t),[s,t,e]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(fh,{editor:s,item:e},`bubbleMenu-image-gif-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function bh(){const{t:e}=n._(),t=n.m$3(),r=n.d$2(),s=(0,g.useMemo)(()=>function(e,t){return[...oh(e,t),...ih(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,E.deleteSelection)(t,n)}}}]}(r,e),[r,e]);return t?(0,y.jsx)(k.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$1.name}(e))return i=!0,!1}),i},children:s?.length?(0,y.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,y.jsx)(fh,{editor:r,item:e},`bubbleMenu-video-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}var yh="graph TB\na--\x3eb",vh=({editor:e,attrs:t,extension:r})=>{const{alt:s,align:i}=t,[o,l]=(0,g.useState)(decodeURIComponent(s??yh)),[a,c]=(0,g.useState)(""),[d,h]=(0,g.useState)(!1),u=(0,g.useRef)(null),[p,m]=(0,g.useState)(null),f=r?.options.upload,x=(0,g.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,g.useEffect)(()=>{p&&d&&(p.initialize({darkMode:!1,startOnLoad:!1,fontSize:12,theme:"base"}),b(o))},[p,d]),(0,g.useEffect)(()=>{p&&d&&b(o)},[p,o]),(0,y.jsxs)(n.o$1,{onOpenChange:h,open:d,children:[(0,y.jsx)(n.s,{asChild:!0,children:(0,y.jsx)(n.f$2,{action:()=>h(!0),icon:"Pencil",tooltip:"Edit Mermaid"})}),(0,y.jsxs)(n.h$1,{className:"richtext-z-[99999] !richtext-max-w-[1300px]",children:[(0,y.jsx)(n.m,{children:"Edit Mermaid"}),(0,y.jsx)("div",{ref:x,style:{height:"100%",border:"1px solid var(--richtext-border)"},children:(0,y.jsxs)("div",{className:"richtext-flex richtext-gap-[10px] richtext-rounded-[10px] richtext-p-[10px]",children:[(0,y.jsx)(n.i,{autoFocus:!0,className:"richtext-flex-1",defaultValue:yh,onChange:e=>l(e.target.value),placeholder:"Text",required:!0,rows:10,value:o,style:{color:"var(--richtext-foreground)"}}),(0,y.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,y.jsx)(n.n$2,{children:(0,y.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 wh({item:e,disabled:t,editor:r}){const s=e.component;return s?(0,y.jsx)(g.Fragment,{children:"divider"===e.type?(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}):(0,y.jsx)(s,{...e.componentProps,disabled:t||e?.componentProps?.disabled,editor:r})}):(0,y.jsx)(y.Fragment,{})}function kh(){const{lang:e,t:t}=n._(),r=n.m$3(),s=n.d$2(),i=n.Ht(s,n.O.name),o=n.v(n.O.name),l=(0,g.useMemo)(()=>function(e,t){return[...rh(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,E.deleteSelection)(t,n)}}}]}(s,t),[s,e,t]);return r?(0,y.jsx)(k.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,y.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,y.jsx)(vh,{attrs:i,editor:s,extension:o},`bubbleMenu-mermaid-${t}`):(0,y.jsx)(wh,{editor:s,item:e},`bubbleMenu-mermaid-${t}`))}):(0,y.jsx)(y.Fragment,{})}):(0,y.jsx)(y.Fragment,{})}function Sh({hiddenActions:e=[]}){const{t:t}=n._(),r=n.m$3(),s=n.d$2(),i=t=>e.includes(t);return r?(0,y.jsx)(k.BubbleMenu,{editor:s,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTable",shouldShow:({editor:e})=>(0,x.isActive)(e.view.state,n.ct.name),children:(0,y.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,y.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,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("addRowAbove")&&(0,y.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,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("mergeCells")&&(0,y.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,y.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,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),!i("deleteTable")&&(0,y.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,y.jsx)(y.Fragment,{})}function jh(){const{t:e}=n._(),[t,r]=(0,g.useState)(!1),s=n.d$2(),i=(0,g.useMemo)(()=>n.a({t:e})?.[0]?.commands,[e]),o=(0,g.useMemo)(()=>i?.find(e=>e?.isActive?.(s))?.label,[s.state.selection.ranges,t,s,i,e]),l=(0,g.useMemo)(()=>i?.find(e=>e?.isActive?.(s)),[s.state.selection.ranges,t,s,i]);return(0,y.jsxs)(n.i$2,{modal:!0,onOpenChange:r,open:t,children:[(0,y.jsx)(n.o$2,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,y.jsx)(n.f$2,{dataState:!!o,tooltip:o||e("editor.paragraph.tooltip"),children:(0,y.jsx)(n.c,{name:l?.iconName||"Type"})})}),(0,y.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,y.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,y.jsxs)("div",{className:"!richtext-min-w-[16px]",children:[i&&(0,y.jsx)(v.Check,{size:16}),!o&&t.label===e("editor.paragraph.tooltip")&&!i&&(0,y.jsx)(v.Check,{size:16})]}),(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:[t.iconName&&(0,y.jsx)(n.c,{className:"!richtext-mr-1 !richtext-text-lg",name:t.iconName}),t.label]})]},t.name)})})]})}function Ch(){const e=n.d$2();return(t=e)&&"function"==typeof t.commands.openAiMenu?(0,y.jsx)(n.f$2,{action:()=>e.commands.openAiMenu(),shortcutKeys:["mod","J"],tooltip:"Ask AI",children:(0,y.jsx)(v.Sparkles,{className:"richtext-size-4 richtext-text-violet-600"})}):null;var t}function Nh(){return(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(Ch,{}),(0,y.jsx)(jh,{}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.h$4,{}),(0,y.jsx)(n.y$1,{}),(0,y.jsx)(n.d$1,{}),(0,y.jsx)(n.m$1,{}),(0,y.jsx)(n.Be,{}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.h$3,{}),(0,y.jsx)(n.M$1,{}),(0,y.jsx)(n.A$1,{})]})}function Eh({buttonBubble:e}){const t=n.d$2();return n.m$3()?(0,y.jsx)(k.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 b.TextSelection},children:e?(0,y.jsx)(y.Fragment,{children:e}):(0,y.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,y.jsx)(Nh,{})})}):(0,y.jsx)(y.Fragment,{})}function Ah(){const{t:e}=n._(),t=n.m$3(),r=n.d$2(),[s,i]=(0,g.useState)(!1),o=(0,g.useCallback)(({editor:e})=>e.isActive(n.k.name),[]),l=(0,g.useCallback)(()=>Gd(n.k.name,r),[r]);return t?(0,y.jsx)(k.BubbleMenu,{editor:r,options:{placement:"bottom",offset:8,flip:!0},pluginKey:"RichTextBubbleTwitter",shouldShow:o,children:(0,y.jsx)(y.Fragment,{children:s?(0,y.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,y.jsx)(n.T$2,{editor:r,onSetLink:e=>{r.commands.updateTweet({src:e}),i(!1)}})}):(0,y.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,y.jsx)(n.f$2,{icon:"Pencil",tooltip:e("editor.link.edit.tooltip"),tooltipOptions:{sideOffset:15},action:()=>{i(!0)}}),(0,y.jsx)(n.f$2,{action:l,icon:"Trash",tooltip:e("editor.delete"),tooltipOptions:{sideOffset:15}})]})})}):(0,y.jsx)(y.Fragment,{})}function Th(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 Mh(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 j.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 b.SelectionRange(i.resolve(c),i.resolve(d));s.push(p)}),s}var _h=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 Dh(e.resolve(this.anchor),e.resolve(this.head),this.depth)}},Dh=class e extends b.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=Mh(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 _h(this.anchor,this.head,this.depth)}};Dh.prototype.visible=!1;try{b.Selection.jsonID("nodeRange",Dh)}catch{}function Oh(e){return e instanceof Dh}x.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(!Oh(i)){const e=Dh.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(!Oh(i)){const e=Dh.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=Dh.create(s,0,s.content.size,t);return i.setSelection(o),n.dispatch(i),!0}}},onSelectionUpdate(){const{selection:e}=this.editor.state;Oh(e)&&this.editor.view.dom.classList.add("ProseMirror-noderangeselection")},addProseMirrorPlugins(){let e=!1,t=!1;return[new b.Plugin({key:new b.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=Dh.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=Oh(r);if(e=!1,!t)return s?(e=!0,Th(r.ranges)):null;const{$from:i,$to:o}=r;if(!s&&i.sameParent(o))return null;const l=Mh(i,o,this.options.depth);return l.length?(e=!0,Th(l)):null}}})]}});var $h=[{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}],Rh={edges:["left","top"],threshold:12,strength:500};function Ih(e){return void 0===e||"left"===e?{...Rh}:"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}:{...Rh,...e}}function Ph(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 Lh(e,t,n){return Array.from({length:t},(e,n)=>t-1-n).some(t=>n.includes(e.node(t).type.name))}function zh(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 Bh(e,t){let n="first"===t?e.firstElementChild:e.lastElementChild;for(;n;){const e=n.getBoundingClientRect();if(zh(e))return e;n="first"===t?n.nextElementSibling:n.previousElementSibling}return null}var Fh=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=Bh(s,"first"),o=Bh(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(...$h),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&&!Lh(i,r,n.allowedContainers))return null;const a=r>0?i.node(r-1):null,c=r>0?i.index(r-1):0,d=Ph({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=Lh(i,c,n.allowedContainers)),p){const r=Ph({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?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 Vh(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 Wh(e){var t;null===(t=e.parentNode)||void 0===t||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=Fh({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 Mh(s.resolve(i.pos),s.resolve(i.pos+i.resultNode.nodeSize+o),0,{extendOnBoundaryOverlap:!1})}(e,t,n,r),d=Mh(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=Vh(e,t);return(n?getComputedStyle(n).direction:getComputedStyle(e.dom).direction)||"ltr"}(i,f);m.setAttribute("dir",x);const y=(null==n?void 0:n.enabled)&&(null==r?void 0:r.node),v=1===u.length;let w,k;y&&v?(w=i.state.doc.slice(f,g),k=b.NodeSelection.create(i.state.doc,f)):(k=Dh.create(i.state.doc,f,g),w=k.content());const S=function(e){return!e||!e.some(e=>{const t=e.trim().toLowerCase();return"margin"===t||t.startsWith("margin-")})}(s);u.forEach(e=>{const t=Vh(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);S&&(n.style.margin="0"),m.append(n)}),m.style.position="absolute",m.style.top="-10000px",document.body.append(m),e.dataTransfer.clearData();const j=function(e,t){return"rtl"===e?t:0}(x,m.getBoundingClientRect().width);e.dataTransfer.setDragImage(m,j,0);let C=!1;const N=()=>{C||(C=!0,Wh(m),document.removeEventListener("drop",N),document.removeEventListener("dragend",N))},E=k instanceof b.NodeSelection?k:void 0;i.dragging={slice:w,move:!0,node:E},p.setSelection(k),i.dispatch(p),document.addEventListener("drop",N),document.addEventListener("dragend",N)}var qh=(e,t)=>{const n=e.resolve(t),{depth:r}=n;return 0===r?t:n.pos-n.parentOffset-1},Uh=(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 Jh(e,t,n){let r=0;for(let s=t;s<n;s+=1)r+=e.child(s).nodeSize;return r}var Kh=(e,t)=>{const n=od.getState(e);return n?Ld(t,n.type,n.binding.mapping):null},Gh=(e,t)=>{const n=od.getState(e);return n?Bd(n.doc,n.type,t,n.binding.mapping)||0:-1},Xh=(e,t)=>{let n=t;for(;(null==n?void 0:n.parentNode)&&n.parentNode!==e.dom;)n=n.parentNode;return n},Yh=new b.PluginKey("dragHandle"),Zh=({pluginKey:e=Yh,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,y=null,v=null,w=null;function k(){v=null,w=null}function S(){t&&(t.style.visibility="hidden",t.style.pointerEvents="none")}function j(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,v=Oh(n)?{anchorPos:n.from,nodeCount:n.ranges.length,depth:null!==(s=n.depth)&&void 0!==s?s:0}:null,t&&(t.dataset.dragging="true"),setTimeout(()=>{t&&(t.style.pointerEvents="none")},0)}function N(e){a?.(e),v=null,S(),t&&(t.style.pointerEvents="auto",t.dataset.dragging="false")}function E(e){if(!e.target||!r.view.dom.contains(e.target))return;if((0,x.isFirefox)()){const e=r.view.dom;requestAnimationFrame(()=>{e.isContentEditable&&(e.contentEditable="false",e.contentEditable="true")})}if(!v||r.view.state.selection.empty)return;const t=r.state.selection.from,n=Kh(r.state,t);w={...v,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,y=null),k()}return h.appendChild(t),{unbind(){A()},plugin:new b.Plugin({key:"string"==typeof e?new b.PluginKey(e):e,state:{init:()=>({locked:!1}),apply(e,n,s,i){!function(e,t){w&&(w=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}}(w,e,{isChangeOrigin:qd(e),getAbsolutePos:e=>Gh(t,e)}))}(e,i);const l=e.getMeta("lockDragHandle"),a=e.getMeta("hideDragHandle");if(void 0!==l&&(p=l),a)return S(),p=!1,m=null,f=-1,o?.({editor:r,node:null,pos:-1}),n;if(e.docChanged&&-1!==f&&t)if(qd(e)){const e=Gh(i,u);e!==f&&(f=e)}else{const t=e.mapping.map(f);t!==f&&(f=t,u=Kh(i,f))}return n}},appendTransaction:(e,t,n)=>function(e){if(!w)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)+Jh(i,0,o);return{anchor:a,head:a+Jh(i,o,o+l),count:l}}(e,t,n,r);if(!s)return null;const i=Dh.create(e,s.anchor,s.head,r);return i.ranges.length===n?i:null}catch{return null}}(e.doc,w.anchorPos,w.nodeCount,w.depth);return t?(k(),e.tr.setSelection(t)):(w=null,v=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)||void 0===n||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 S();if(t.draggable=!p,e.state.doc.eq(s.doc)||-1===f)return;let i=e.nodeDOM(f);if(i=Xh(e,i),i===e.dom)return;if(1!==(null==i?void 0:i.nodeType))return;const l=e.posAtDOM(i,0),a=Uh(r.state.doc,l),c=qh(r.state.doc,l);m=a,f=c,u=Kh(e.state,f),o?.({editor:r,node:m,pos:f}),j(i)},destroy(){A(),t&&Wh(h)}}},props:{handleDOMEvents:{keydown:e=>!(!t||p||!e.hasFocus()||(S(),m=null,f=-1,o?.({editor:r,node:null,pos:-1}),1)),mouseleave:(e,t)=>(p||t.target&&!h.contains(t.relatedTarget)&&(S(),m=null,f=-1,o?.({editor:r,node:null,pos:-1})),!1),mousemove:(e,n)=>!(!t||p||(y={x:n.clientX,y:n.clientY},g||(g=requestAnimationFrame(()=>{if(g=null,!y)return;const{x:n,y:s}=y;y=null;const i=Fh({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=Xh(e,l),l===e.dom)return;if(1!==(null==l?void 0:l.nodeType))return;const t=e.posAtDOM(l,0);a=Uh(r.state.doc,t),d=qh(r.state.doc,t)}var h;a!==m&&(m=a,f=null!==(h=d)&&void 0!==h?h:-1,u=Kh(e.state,f),o?.({editor:r,node:m,pos:f}),j(l),t&&(r.isEditable?(t.style.visibility="",t.style.pointerEvents="auto"):S()))})),1))}}})}};function Qh(e){var t,n;return!1===e||void 0===e?{enabled:!1,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ih("none")}:!0===e?{enabled:!0,rules:[],defaultRules:!0,allowedContainers:void 0,edgeDetection:Ih("left")}:{enabled:!0,rules:null!==(t=e.rules)&&void 0!==t?t:[],defaultRules:null===(n=e.defaultRules)||void 0===n||n,allowedContainers:e.allowedContainers,edgeDetection:Ih(e.edgeDetection)}}var eu={placement:"left-start",strategy:"absolute"},tu=(x.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=Qh(this.options.nested);return[Zh({computePositionConfig:{...eu,...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=Yh,onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a,computePositionConfig:c=eu,nested:d=!1}=e,h=(0,g.useRef)(null);null===h.current&&"undefined"!=typeof document&&(h.current=document.createElement("div"));const u={onNodeChange:i,onElementDragStart:o,onElementDragEnd:l,getReferencedVirtualElement:a},p=(0,g.useRef)(u);p.current=u;const m=(0,g.useMemo)(()=>Qh(d),[JSON.stringify(d)]);(0,g.useEffect)(()=>{const e=h.current;e&&(e.className=t)},[t]),(0,g.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}=Zh({editor:r,element:e,pluginKey:s,computePositionConfig:{...eu,...c},onElementDragStart:e=>{var t,n;return null===(t=(n=p.current).onElementDragStart)||void 0===t?void 0:t.call(n,e)},onElementDragEnd:e=>{var t,n;return null===(t=(n=p.current).onElementDragEnd)||void 0===t?void 0:t.call(n,e)},onNodeChange:e=>{var t,n;return null===(t=(n=p.current).onNodeChange)||void 0===t?void 0:t.call(n,e)},getReferencedVirtualElement:()=>{var e,t,n;return null!==(e=null===(t=(n=p.current).getReferencedVirtualElement)||void 0===t?void 0:t.call(n))&&void 0!==e?e:null},nestedOptions:m});return r.registerPlugin(t),()=>{r.isDestroyed||r.unregisterPlugin(s),n()}},[r,s,c,m]);const f=h.current;return f?(0,w.createPortal)(n,f):null});function nu(){const e=n.d$2(),t=n.m$3(),{t:r}=n._(),[s,i]=(0,g.useState)(null),[o,l]=(0,g.useState)(-1),[a,c]=(0,g.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,g.useCallback)(e=>{e.node&&i(e.node),l(e.pos),requestAnimationFrame(()=>{e.editor.commands.focus()})},[]);(0,g.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,y.jsx)(tu,{className:"richtext-transition-all richtext-duration-200 richtext-ease-out",editor:e,onNodeChange:m,pluginKey:"RichTextBubbleMenuDragHandle",children:(0,y.jsxs)("div",{className:"richtext-flex richtext-items-center richtext-gap-0.5",children:[(0,y.jsx)(n.f$2,{disabled:!t,icon:"Grip",tooltip:r("editor.draghandle.grip"),action:e=>{e.preventDefault(),e.stopPropagation(),f(!a)}}),(0,y.jsxs)(n.h$5,{onOpenChange:f,open:a,children:[(0,y.jsx)(n.x,{className:"richtext-pointer-events-none"}),(0,y.jsxs)(n.u$2,{align:"start",className:"richtext-w-48",hideWhenDetached:!0,side:"bottom",sideOffset:0,children:[(0,y.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,y.jsx)(n.c,{name:"Trash2"}),(0,y.jsx)("span",{children:r("editor.remove")})]}),u?(0,y.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,y.jsx)(n.c,{name:"PaintRoller"}),(0,y.jsx)("span",{children:r("editor.clear.tooltip")})]}):null,(0,y.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,y.jsx)(n.c,{name:"Copy"}),(0,y.jsx)("span",{children:r("editor.copy")})]}),d||h?(0,y.jsx)(n.y$3,{}):null,d?(0,y.jsxs)(n.l$2,{children:[(0,y.jsxs)(n.p$1,{className:"richtext-flex richtext-gap-3",children:[(0,y.jsx)(n.c,{name:"AlignCenter"}),(0,y.jsx)("span",{children:r("editor.textalign.tooltip")})]}),(0,y.jsx)(n.n$5,{children:(0,y.jsxs)(n.f$1,{children:[(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("left"),children:[(0,y.jsx)(n.c,{name:"AlignLeft"}),(0,y.jsx)("span",{children:r("editor.textalign.left.tooltip")})]}),(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("center"),children:[(0,y.jsx)(n.c,{name:"AlignCenter"}),(0,y.jsx)("span",{children:r("editor.textalign.center.tooltip")})]}),(0,y.jsxs)(n.g,{className:"richtext-flex richtext-gap-3",onClick:()=>p("right"),children:[(0,y.jsx)(n.c,{name:"AlignRight"}),(0,y.jsx)("span",{children:r("editor.textalign.right.tooltip")})]})]})})]}):null,h?(0,y.jsxs)(n.l$2,{children:[(0,y.jsxs)(n.p$1,{className:"richtext-flex richtext-gap-3",children:[(0,y.jsx)(n.c,{name:"IndentIncrease"}),(0,y.jsx)("span",{children:r("editor.indent")})]}),(0,y.jsx)(n.n$5,{children:(0,y.jsxs)(n.f$1,{children:[(0,y.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,y.jsx)(n.c,{name:"IndentIncrease"}),(0,y.jsx)("span",{children:r("editor.indent.tooltip")})]}),(0,y.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,y.jsx)(n.c,{name:"IndentDecrease"}),(0,y.jsx)("span",{children:r("editor.outdent.tooltip")})]})]})})]}):null]})]})]})})}var ru={plaintext:"Plain Text",js:"JavaScript",ts:"TypeScript",css:"CSS",html:"HTML",python:"Python",bash:"Bash"};function su({listLanguages:e}){const{t:t}=n._(),[r,s]=(0,g.useState)(!1),i=n.d$2(),o=(0,g.useMemo)(()=>{const{selection:e}=i.state,t=e.$from.parent;if("codeBlock"===t.type.name){const e=t.attrs.language||"plaintext";return ru[e]||e}},[i.state,e]),l=(0,g.useMemo)(()=>{let t=e||[];return e?.includes("plaintext")||(t=["plaintext",...t]),t.map(e=>({label:ru[e]||e,value:e}))},[e]);return(0,y.jsxs)(n.i$2,{modal:!0,onOpenChange:s,open:r,children:[(0,y.jsx)(n.o$2,{asChild:!0,className:"hover:richtext-bg-accent data-[state=on]:richtext-bg-accent",children:(0,y.jsxs)(n.f$2,{dataState:!!o,children:[(0,y.jsx)(y.Fragment,o?{children:o}:{children:t("editor.paragraph.tooltip")}),(0,y.jsx)(n.c,{className:"richtext-ml-1 richtext-size-3 richtext-text-zinc-500",name:"MenuDown"})]})}),(0,y.jsx)(n.s$3,{align:"start",className:"!richtext-w-[initial] !richtext-p-[4px]",hideWhenDetached:!0,side:"bottom",children:l?.map(e=>(0,y.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,y.jsx)("div",{className:"!richtext-min-w-[20px]",children:o===e.value&&(0,y.jsx)(v.Check,{size:16})}),(0,y.jsx)("div",{className:"richtext-flex richtext-items-center richtext-gap-1",children:e.label})]},e.value))})]})}function iu(){const e=n.m$3(),t=n.d$2(),r=n.v(n.M$2.name),s=(0,g.useCallback)(({editor:e})=>e.isActive(n.M$2.name),[]),i=(0,g.useMemo)(()=>r?r.options?.lowlight?.listLanguages?.()||["plaintext","html","css","js","ts"]:[],[r]),o=(0,g.useCallback)(()=>Gd(n.M$2.name,t),[t]);return e?(0,y.jsx)(k.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,y.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,y.jsx)(su,{listLanguages:i}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.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,y.jsx)(v.Copy,{size:16})}),(0,y.jsx)(n.k$1,{className:"!richtext-mx-1 !richtext-my-2 !richtext-h-[16px]",orientation:"vertical"}),(0,y.jsx)(n.f$2,{action:o,tooltip:"Delete",children:(0,y.jsx)(v.Trash2,{size:16})})]})}):(0,y.jsx)(y.Fragment,{})}var ou=()=>(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(Yd,{}),(0,y.jsx)(Zd,{}),(0,y.jsx)(dh,{}),(0,y.jsx)(uh,{}),(0,y.jsx)(mh,{}),(0,y.jsx)(gh,{}),(0,y.jsx)(bh,{}),(0,y.jsx)(xh,{}),(0,y.jsx)(kh,{}),(0,y.jsx)(Sh,{}),(0,y.jsx)(Eh,{}),(0,y.jsx)(Ah,{}),(0,y.jsx)(iu,{}),(0,y.jsx)(nu,{}),(0,y.jsx)(n.D,{}),(0,y.jsx)(F,{})]});Object.defineProperty(exports,"BubbleMenus",{enumerable:!0,get:function(){return ou}}),Object.defineProperty(exports,"RichTextToolbar",{enumerable:!0,get:function(){return le}});