wiki-viewer 2.11.2 → 2.11.4

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.
Files changed (75) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +3 -3
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
  14. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
  15. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
  16. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
  18. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
  19. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
  20. package/.next/standalone/.next/server/app/api/agent/internal/span/route.js.nft.json +1 -1
  21. package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
  22. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
  23. package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
  25. package/.next/standalone/.next/server/app/api/pdf/save/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/share/[token]/asset/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/branch/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
  37. package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
  38. package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
  40. package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
  42. package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
  43. package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
  44. package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
  46. package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
  47. package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
  49. package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
  50. package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
  51. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
  52. package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
  54. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
  55. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  56. package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
  57. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  58. package/.next/standalone/.next/server/app/s/[token]/page_client-reference-manifest.js +1 -1
  59. package/.next/standalone/.next/server/app/signin/page_client-reference-manifest.js +1 -1
  60. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0st27bi._.js +1 -1
  61. package/.next/standalone/.next/server/chunks/ssr/_0oq8kwv._.js +20 -20
  62. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  63. package/.next/standalone/.next/server/pages/500.html +1 -1
  64. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  65. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  66. package/.next/standalone/.next/static/chunks/064kw6cpi-47..css +1 -0
  67. package/.next/standalone/.next/static/chunks/{0zx8l56mczo3g.js → 078zm3b1n76-7.js} +3 -3
  68. package/.next/standalone/.next/static/chunks/{09z52vnt~jxdl.css → 0~uyhld0wvekn.css} +2 -2
  69. package/.next/standalone/package.json +1 -1
  70. package/.next/standalone/server.js +1 -1
  71. package/package.json +1 -1
  72. package/.next/standalone/.next/static/chunks/09.erdz0y5yfg.css +0 -1
  73. /package/.next/standalone/.next/static/{CciQ9yC2bDmmOcjYpnJoI → 3vqIsEfg3Z_zStz4UWIyh}/_buildManifest.js +0 -0
  74. /package/.next/standalone/.next/static/{CciQ9yC2bDmmOcjYpnJoI → 3vqIsEfg3Z_zStz4UWIyh}/_clientMiddlewareManifest.js +0 -0
  75. /package/.next/standalone/.next/static/{CciQ9yC2bDmmOcjYpnJoI → 3vqIsEfg3Z_zStz4UWIyh}/_ssgManifest.js +0 -0
@@ -2,7 +2,7 @@
2
2
 
3
3
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
4
4
 
5
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return f.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},ep=({contentRef:e,descriptionId:t})=>{let n=ed("DialogDescriptionWarning"),r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${n.contentName}}.`;return f.useEffect(()=>{let n=e.current?.getAttribute("aria-describedby");t&&n&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},eh=e.i(975157);let ef=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(K,{ref:n,className:(0,eh.cn)("fixed inset-0 z-40 bg-overlay backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));ef.displayName="SheetOverlay";let em={bottom:"inset-x-0 bottom-0 data-[state=open]:slide-in-from-bottom data-[state=closed]:slide-out-to-bottom",top:"inset-x-0 top-0 data-[state=open]:slide-in-from-top data-[state=closed]:slide-out-to-top",left:"inset-y-0 left-0 data-[state=open]:slide-in-from-left data-[state=closed]:slide-out-to-left",right:"inset-y-0 right-0 data-[state=open]:slide-in-from-right data-[state=closed]:slide-out-to-right"},eg=f.forwardRef(({side:e="bottom",showClose:t=!1,className:n,overlayClassName:r,children:i,...o},a)=>(0,s.jsxs)(W,{children:[(0,s.jsx)(ef,{className:r}),(0,s.jsxs)(X,{ref:a,className:(0,eh.cn)("fixed z-50 bg-background shadow-golden transition-all ease-in-out","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:duration-300",em[e],n),...o,children:[i,t&&(0,s.jsxs)(eo,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring disabled:pointer-events-none",children:[(0,s.jsx)(h,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]}));eg.displayName="SheetContent",f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(en,{ref:n,className:(0,eh.cn)("text-sm font-medium leading-none tracking-tight",e),...t})).displayName="SheetTitle",f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ei,{ref:n,className:(0,eh.cn)("text-sm text-muted-foreground",e),...t})).displayName="SheetDescription";var eb=e.i(187014);function ex(e,t){eb.toast.success(e,t)}function ey(e,t){eb.toast.error(e,t)}var ev=e.i(354502),ew=e.i(199075),ek=e.i(755146),eN=e.i(534537);let eS={inter:{id:"inter",label:"Inter",kind:"sans",cssValue:"var(--font-inter), ui-sans-serif, system-ui, -apple-system, sans-serif"},satoshi:{id:"satoshi",label:"Satoshi",kind:"sans",cssValue:"var(--font-satoshi), ui-sans-serif, system-ui, -apple-system, sans-serif"},"general-sans":{id:"general-sans",label:"General Sans",kind:"sans",cssValue:"var(--font-general-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},roboto:{id:"roboto",label:"Roboto",kind:"sans",cssValue:"var(--font-roboto), ui-sans-serif, system-ui, -apple-system, sans-serif"},"open-sans":{id:"open-sans",label:"Open Sans",kind:"sans",cssValue:"var(--font-open-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},lexend:{id:"lexend",label:"Lexend",kind:"sans",cssValue:"var(--font-lexend), ui-sans-serif, system-ui, -apple-system, sans-serif"},"atkinson-hyperlegible":{id:"atkinson-hyperlegible",label:"Atkinson Hyperlegible",kind:"sans",cssValue:"var(--font-atkinson-hyperlegible), ui-sans-serif, system-ui, -apple-system, sans-serif"},"elms-sans":{id:"elms-sans",label:"Elms Sans",kind:"sans",cssValue:"var(--font-elms-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},"stack-sans-notch":{id:"stack-sans-notch",label:"Stack Notch",kind:"sans",cssValue:"var(--font-stack-sans-notch), ui-sans-serif, system-ui, -apple-system, sans-serif"},"stack-sans-text":{id:"stack-sans-text",label:"Stack Text",kind:"sans",cssValue:"var(--font-stack-sans-text), ui-sans-serif, system-ui, -apple-system, sans-serif"},datatype:{id:"datatype",label:"Datatype",kind:"sans",cssValue:"var(--font-datatype), ui-sans-serif, system-ui, -apple-system, sans-serif"},"miranda-sans":{id:"miranda-sans",label:"Miranda Sans",kind:"sans",cssValue:"var(--font-miranda-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},luciole:{id:"luciole",label:"Luciole",kind:"sans",cssValue:"var(--font-luciole), ui-sans-serif, system-ui, -apple-system, sans-serif"},verdana:{id:"verdana",label:"Verdana",kind:"sans",cssValue:"Verdana, Geneva, Tahoma, sans-serif"},newsreader:{id:"newsreader",label:"Newsreader",kind:"serif",cssValue:"var(--font-newsreader), Georgia, serif"},fraunces:{id:"fraunces",label:"Fraunces",kind:"serif",cssValue:"var(--font-fraunces), Georgia, serif"},sentient:{id:"sentient",label:"Sentient",kind:"serif",cssValue:"var(--font-sentient), Georgia, serif"},gambetta:{id:"gambetta",label:"Gambetta",kind:"serif",cssValue:"var(--font-gambetta), Georgia, serif"},merriweather:{id:"merriweather",label:"Merriweather",kind:"serif",cssValue:"var(--font-merriweather), Georgia, serif"},baskerville:{id:"baskerville",label:"Baskerville",kind:"serif",cssValue:"var(--font-libre-baskerville), Georgia, serif"},palatino:{id:"palatino",label:"Palatino",kind:"serif",cssValue:"Palatino Linotype, Palatino, Book Antiqua, Georgia, serif"},"plex-mono":{id:"plex-mono",label:"IBM Plex Mono",kind:"mono",cssValue:"var(--font-plex-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"jetbrains-mono":{id:"jetbrains-mono",label:"JetBrains Mono",kind:"mono",cssValue:"var(--font-jetbrains-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"fira-code":{id:"fira-code",label:"Fira Code",kind:"mono",cssValue:"var(--font-fira-code), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"roboto-mono":{id:"roboto-mono",label:"Roboto Mono",kind:"mono",cssValue:"var(--font-roboto-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"space-mono":{id:"space-mono",label:"Space Mono",kind:"mono",cssValue:"var(--font-space-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"source-code-pro":{id:"source-code-pro",label:"Source Code Pro",kind:"mono",cssValue:"var(--font-source-code-pro), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"}},eC=["inter","satoshi","general-sans","roboto","open-sans","lexend","atkinson-hyperlegible","elms-sans","stack-sans-notch","stack-sans-text","datatype","miranda-sans","luciole","verdana"],ej=["plex-mono","jetbrains-mono","fira-code","roboto-mono","space-mono","source-code-pro"],eE=["inter","satoshi","general-sans","roboto","open-sans","lexend","atkinson-hyperlegible","elms-sans","stack-sans-notch","stack-sans-text","datatype","miranda-sans","luciole","verdana","newsreader","fraunces","sentient","gambetta","merriweather","baskerville","palatino","plex-mono","jetbrains-mono","fira-code","roboto-mono","space-mono","source-code-pro"],eM={classic:{id:"classic",label:"Classic",description:"Inter, Newsreader, Fraunces — the original pairing",fonts:{ui:"inter",body:"newsreader",heading:"fraunces",code:"plex-mono"}},modern:{id:"modern",label:"Modern",description:"Satoshi, Sentient, Gambetta — clean and contemporary",fonts:{ui:"satoshi",body:"sentient",heading:"gambetta",code:"plex-mono"}},literary:{id:"literary",label:"Literary",description:"General Sans, Merriweather, Baskerville — magazine-style contrast",fonts:{ui:"general-sans",body:"merriweather",heading:"baskerville",code:"plex-mono"}},legible:{id:"legible",label:"Legible",description:"Atkinson Hyperlegible, Lexend — built for accessibility",fonts:{ui:"atkinson-hyperlegible",body:"atkinson-hyperlegible",heading:"lexend",code:"plex-mono"}},warm:{id:"warm",label:"Warm",description:"Luciole, Palatino — humanist and generously proportioned",fonts:{ui:"luciole",body:"palatino",heading:"palatino",code:"plex-mono"}},stack:{id:"stack",label:"Stack",description:"Stack Sans Text/Notch, Sentient — display headings, calm reading",fonts:{ui:"stack-sans-text",body:"sentient",heading:"stack-sans-notch",code:"plex-mono"}}},eA=["classic","modern","literary","legible","warm","stack"],eT=[.8,.9,1,1.1,1.2,1.3,1.4,1.5];function eO(e){return"number"==typeof e&&Number.isFinite(e)&&e>=.5&&e<=2}let e_="wiki-fonts",eD="inter",eR="newsreader",eI="fraunces",eL="plex-mono";function eP(e){return`--font-scale-${e}`}function ez(){let e=document.documentElement,t=e.dataset.fontUi||eD,n=e.dataset.fontBody||eR,r=e.dataset.fontHeading||eI,i=e.dataset.fontCode||eL,s=(t,n)=>{let r=e.style.getPropertyValue(eP(t)),i=r?Number.parseFloat(r):NaN;return eO(i)?i:n};return{ui:t,body:n,heading:r,code:i,uiScale:s("ui",1),bodyScale:s("body",1),headingScale:s("heading",1)}}let e$=(0,eN.create)(e=>{let t=ez();return{ui:t.ui,body:t.body,heading:t.heading,code:t.code,uiScale:t.uiScale,bodyScale:t.bodyScale,headingScale:t.headingScale,setFont:(t,n)=>{{let e=document.documentElement,r=e.dataset.fontUi||eD,i=e.dataset.fontBody||eR,s=e.dataset.fontHeading||eI,o=e.dataset.fontCode||eL,a={...ez(),ui:"ui"===t?n:r,body:"body"===t?n:i,heading:"heading"===t?n:s,code:"code"===t?n:o};localStorage.setItem(e_,JSON.stringify(a)),e.dataset.fontUi=a.ui,e.dataset.fontBody=a.body,e.dataset.fontHeading=a.heading,e.dataset.fontCode=a.code}e(e=>"ui"===t?{...e,ui:n}:"body"===t?{...e,body:n}:"heading"===t?{...e,heading:n}:"code"===t?{...e,code:n}:e)},setScale:(t,n)=>{if(eO(n)){{let e=document.documentElement,r=ez(),i={...r,uiScale:"ui"===t?n:r.uiScale,bodyScale:"body"===t?n:r.bodyScale,headingScale:"heading"===t?n:r.headingScale};localStorage.setItem(e_,JSON.stringify(i)),e.style.setProperty(eP(t),String(n))}e(e=>"ui"===t?{...e,uiScale:n}:"body"===t?{...e,bodyScale:n}:"heading"===t?{...e,headingScale:n}:e)}},applyPreset:t=>{let n=eM[t].fonts;{let e=document.documentElement,t={...ez(),ui:n.ui,body:n.body,heading:n.heading,code:n.code};localStorage.setItem(e_,JSON.stringify(t)),e.dataset.fontUi=n.ui,e.dataset.fontBody=n.body,e.dataset.fontHeading=n.heading,e.dataset.fontCode=n.code}e(e=>({...e,ui:n.ui,body:n.body,heading:n.heading,code:n.code}))}}}),eB=[{id:"focusMode",label:"Focus mode",description:"Dim everything except the block you're reading."},{id:"breadcrumb",label:"Sticky breadcrumb",description:"Current heading trail pinned to the top while you scroll."}],eF="wiki-experiments",eH=(0,eN.create)(e=>({flags:function(){let e=Object.fromEntries(eB.map(e=>[e.id,!1]));try{let t=localStorage.getItem(eF),n=t?JSON.parse(t):{};for(let t of eB)"boolean"==typeof n[t.id]&&(e[t.id]=n[t.id])}catch{}return e}(),toggle:t=>e(e=>{let n={...e.flags,[t]:!e.flags[t]};try{localStorage.setItem(eF,JSON.stringify(n))}catch{}return{flags:n}})}));function eU(e){return eH(t=>t.flags[e])}function eV(e){return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}function eW(){let e=eH(e=>e.flags),t=eH(e=>e.toggle);return(0,s.jsx)("div",{className:"space-y-1.5",children:eB.map(n=>{let r=e[n.id];return(0,s.jsxs)("button",{type:"button",onClick:()=>t(n.id),"aria-pressed":r,className:`flex w-full items-start justify-between gap-3 rounded-md border px-3 py-2 text-left transition-colors ${r?"border-ring bg-accent":"border-border hover:bg-accent/50"}`,children:[(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsx)("span",{className:"block text-sm font-medium",children:n.label}),(0,s.jsx)("span",{className:"block text-xs text-muted-foreground",children:n.description})]}),(0,s.jsx)("span",{"aria-hidden":!0,className:`mt-0.5 flex h-5 w-9 shrink-0 items-center rounded-full px-0.5 transition-colors ${r?"bg-primary":"bg-muted-foreground/30"}`,children:(0,s.jsx)("span",{className:`h-4 w-4 rounded-full bg-background transition-transform ${r?"translate-x-4":"translate-x-0"}`})})]},n.id)})})}function eq(){let{ui:e,body:t,heading:n,code:r}=e$(),i=e$(e=>e.applyPreset),o=eA.find(i=>{let s=eM[i].fonts;return s.ui===e&&s.body===t&&s.heading===n&&s.code===r}),a=o?eM[o]:null;return(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground font-medium",children:"Quick presets"}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button",className:"w-full flex items-center justify-between gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors",children:[(0,s.jsx)("span",{children:a?a.label:"Custom"}),(0,s.jsx)(b,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{className:"w-64",children:eA.map(e=>{let t=eM[e];return(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>i(e),className:"flex-col items-start gap-0.5 py-2",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[o===e?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"font-medium",children:t.label})]}),(0,s.jsx)("span",{className:"pl-[1.375rem] text-xs text-muted-foreground leading-snug",children:t.description})]},e)})})]})]})}function eK({role:e}){let t=e$(),n="ui"===e?t.uiScale:"body"===e?t.bodyScale:t.headingScale,r=e$(e=>e.setScale);return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button","aria-label":"Font size",className:"flex items-center gap-1 rounded-md border border-border px-2 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors shrink-0",children:[(0,s.jsxs)("span",{className:"tabular-nums",children:[Math.round(100*n),"%"]}),(0,s.jsx)(b,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{align:"end",className:"w-24",children:eT.map(t=>(0,s.jsx)(ek.DropdownMenuItem,{onClick:()=>r(e,t),className:n===t?"font-medium":"",children:(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[n===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"tabular-nums",children:[Math.round(100*t),"%"]})]})},t))})]})}function eG({role:e,ids:t}){let n=e$(),r="ui"===e?n.ui:"body"===e?n.body:n.heading,i=e$(e=>e.setFont),o="ui"===e?"UI font":"body"===e?"Body font":"Heading font";return(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground font-medium",children:o}),(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button",className:"flex-1 min-w-0 flex items-center justify-between gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors",children:[(0,s.jsx)("span",{className:"truncate",children:eS[r]?.label??"Select font"}),(0,s.jsx)(b,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{className:"w-56",children:t.map(t=>{let n=eS[t];return(0,s.jsx)(ek.DropdownMenuItem,{onClick:()=>i(e,t),className:r===t?"font-medium":"",children:(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[r===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{style:{fontFamily:n.cssValue},children:n.label})]})},t)})})]}),(0,s.jsx)(eK,{role:e})]})]})}function eJ({open:e,onOpenChange:t}){let[n,r]=(0,f.useState)(!1),[i,o]=(0,f.useState)(!1),[a,l]=(0,f.useState)(null),[c,d]=(0,f.useState)("env"),[p,b]=(0,f.useState)(""),[w,k]=(0,f.useState)(""),[N,S]=(0,f.useState)(null),{data:C}=ew.authClient.useSession(),[j,E]=(0,f.useState)(!1),[M,A]=(0,f.useState)([]),[T,O]=(0,f.useState)([]),[_,D]=(0,f.useState)(null),[R,I]=(0,f.useState)(null),[L,P]=(0,f.useState)(""),[z,$]=(0,f.useState)(""),[F,H]=(0,f.useState)(!1),[U,V]=(0,f.useState)(null),[W,q]=(0,f.useState)(null),[K,G]=(0,f.useState)(!1),[J,Z]=(0,f.useState)(!1),X=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/system/admins"));if(!e.ok)return;let t=await e.json();E(!!t.isAdmin),A(t.admins??[]),O(t.users??[])}catch{}},[]),Y=(0,f.useCallback)(async()=>{r(!0),l(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/auth-settings"));if(!e.ok)throw Error("Failed to load settings");let t=await e.json();b(t.allowedEmails.join("\n")),k(t.allowedDomains.join("\n")),d(t.source),S("number"==typeof t.rateLimit?t.rateLimit:null)}catch(e){l(e instanceof Error?e.message:"Failed to load")}finally{r(!1)}},[]),Q=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/system/api-key"));if(!e.ok)return;let t=await e.json();q(t.key??null)}catch{}},[]);async function ee(){o(!0),l(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/auth-settings"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({allowedEmails:eV(p),allowedDomains:eV(w)})}),n=await e.json();if(!e.ok){l(n.error??"Save failed"),ey(n.error??"Save failed");return}n.source&&d(n.source),t(!1)}catch{l("Save failed")}finally{o(!1)}}(0,f.useEffect)(()=>{e&&(Y(),X(),Q())},[e,Y,X,Q]);let et=0===eV(p).length&&0===eV(w).length;return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eg,{side:"right",className:"w-[90vw] max-w-sm md:w-80 sm:max-w-md flex flex-col border-l border-border p-0",overlayClassName:"backdrop-blur-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",children:"Settings"}),(0,s.jsxs)(eo,{className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,s.jsx)(h,{className:"h-3.5 w-3.5"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]}),n?(0,s.jsx)("div",{className:"flex flex-1 items-center justify-center",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,s.jsxs)("div",{className:"flex-1 space-y-5 overflow-y-auto px-4 py-4",children:[C?.user&&(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Account"}),(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border bg-muted/40 p-3",children:[(0,s.jsxs)("div",{className:"text-sm min-w-0",children:[(0,s.jsx)("div",{className:"font-medium truncate",children:C.user.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:C.user.email})]}),(0,s.jsx)("button",{type:"button",onClick:async()=>{await ew.authClient.signOut(),window.location.href=(0,ev.apiUrl)("/signin")},className:"ml-2 shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent",children:"Sign out"})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Typography"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Choose fonts for interface chrome, body text, and headings. Mix and match freely, or use a preset."}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(eq,{}),(0,s.jsx)(eG,{role:"ui",ids:eC}),(0,s.jsx)(eG,{role:"body",ids:eE}),(0,s.jsx)(eG,{role:"heading",ids:eE}),(0,s.jsx)(eG,{role:"code",ids:ej})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Lab"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Experimental reading features. Toggle each on or off. Saved on this device."}),(0,s.jsx)(eW,{})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Signup allowlist"}),(0,s.jsxs)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:["Control who can create an account. Leave both lists empty to allow any email. Saving here overrides the"," ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AUTH_ALLOWED_EMAILS"})," ","and"," ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AUTH_ALLOWED_DOMAIN"})," ","environment variables."]}),"env"===c&&(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md bg-muted px-3 py-2 text-xs text-muted-foreground",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),(0,s.jsx)("span",{children:"Current values come from environment variables. Saving moves the allowlist into config and takes precedence going forward."})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{htmlFor:"allowed-emails",className:"text-sm font-medium",children:"Allowed emails"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"One per line (or comma-separated). Exact match, case-insensitive."}),(0,s.jsx)("textarea",{id:"allowed-emails",value:p,onChange:e=>b(e.target.value),spellCheck:!1,rows:5,placeholder:"alice@example.com bob@example.com",className:"w-full resize-y rounded-md border border-border bg-background px-3 py-2 font-mono text-sm outline-none focus:ring-2 focus:ring-primary"})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{htmlFor:"allowed-domains",className:"text-sm font-medium",children:"Allowed domains"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"One per line (or comma-separated). Matches any email at that domain."}),(0,s.jsx)("textarea",{id:"allowed-domains",value:w,onChange:e=>k(e.target.value),spellCheck:!1,rows:4,placeholder:"example.com trusted.org",className:"w-full resize-y rounded-md border border-border bg-background px-3 py-2 font-mono text-sm outline-none focus:ring-2 focus:ring-primary"})]}),et&&(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-ink",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),(0,s.jsx)("span",{children:"Both lists are empty. Anyone with the signup URL can create an account."})]}),a&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),a]})]}),j&&(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Admins"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Admins can create workspaces, add users, and manage access."}),_&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),_]}),(0,s.jsxs)("div",{className:"space-y-2 rounded-md border border-border p-3",children:[(0,s.jsx)("div",{className:"text-xs font-medium",children:"Add user"}),U?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Created ",(0,s.jsx)("span",{className:"font-medium text-foreground",children:U.email}),". Share this temporary password now, it will not be shown again."]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 rounded bg-muted px-2 py-1.5 font-mono text-sm select-all",children:U.tempPassword}),(0,s.jsx)("button",{type:"button",className:"shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent",onClick:()=>void navigator.clipboard?.writeText(U.tempPassword),children:"Copy"})]}),(0,s.jsx)("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>{V(null),P(""),$(""),X()},children:"Done"})]}):(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("input",{type:"email",value:L,onChange:e=>P(e.target.value),placeholder:"email@team.com",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm outline-none focus:ring-2 focus:ring-primary"}),(0,s.jsx)("input",{type:"text",value:z,onChange:e=>$(e.target.value),placeholder:"Name (optional)",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm outline-none focus:ring-2 focus:ring-primary"}),(0,s.jsxs)(v.Button,{size:"sm",className:"w-full gap-1.5",disabled:F||!L.trim(),onClick:async()=>{H(!0),D(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/users"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:L.trim(),name:z.trim()})}),t=await e.json();e.ok&&t.tempPassword?V({email:t.email??L.trim(),tempPassword:t.tempPassword}):D(t.message??t.error??"Failed to create user")}catch{D("Network error")}finally{H(!1)}},children:[F&&(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),"Create user"]})]})]}),(0,s.jsxs)("div",{className:"space-y-1 rounded-md border border-border overflow-hidden",children:[T.map(e=>{let t=M.includes(e.id);return(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/40 hover:bg-muted/60 transition-colors",children:[(0,s.jsxs)("div",{className:"text-sm min-w-0",children:[(0,s.jsx)("div",{className:"font-medium truncate",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:e.email})]}),(0,s.jsx)("button",{type:"button",disabled:R===e.id,className:"ml-2 shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent disabled:opacity-50",onClick:async()=>{I(e.id),D(null);try{let n=await fetch((0,ev.apiUrl)("/api/system/admins"),{method:t?"DELETE":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:e.id})}),r=await n.json();n.ok?r.admins&&A(r.admins):D(r.message??r.error??"Failed")}catch{D("Network error")}finally{I(null)}},children:R===e.id?(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}):t?"Demote":"Promote"})]},e.id)}),0===T.length&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No users yet."})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"API Access"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Copy this key into external tools (e.g. termyard Settings → Integrations → Wiki-viewer API Key). The key never leaves this machine automatically."}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 font-mono text-xs select-all",children:W??"—"}),(0,s.jsx)("button",{type:"button",title:"Copy API key",className:"shrink-0 rounded border border-border px-2 py-1 text-xs hover:bg-accent disabled:opacity-50 flex items-center gap-1",disabled:!W,onClick:()=>{W&&navigator.clipboard?.writeText(W).then(()=>{G(!0),setTimeout(()=>G(!1),2e3)})},children:K?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3 w-3"})," Copied"]}):"Copy"}),(0,s.jsx)("button",{type:"button",title:"Rotate API key — external tools will need the new key",className:"shrink-0 rounded border border-border px-2 py-1 text-xs hover:bg-accent disabled:opacity-50 flex items-center gap-1",disabled:J,onClick:async()=>{if(confirm("Rotate the API key? Any tool using the current key will need to be updated.")){Z(!0);try{let e=await fetch((0,ev.apiUrl)("/api/system/api-key"),{method:"POST"}),t=await e.json();t.key&&q(t.key)}catch{}finally{Z(!1)}}},children:J?(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(y,{className:"h-3 w-3"})," Rotate"]})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/60",children:["Stored at ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"~/.wiki-viewer/api-key"}),". Rotating immediately invalidates the old key."]})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Agent rate limit"}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-muted-foreground",children:"Per agent"}),(0,s.jsx)("span",{className:"font-mono",children:null!==N?`${N} ops/min`:"--"})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/60",children:["Override with ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AGENT_RATE_LIMIT"})," env var."]})]})]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3 shrink-0",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>t(!1),disabled:i,children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",onClick:ee,disabled:i||n,className:"gap-1.5",children:[i&&(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}let eZ=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(K,{ref:n,className:(0,eh.cn)("fixed inset-0 z-40 bg-overlay backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));eZ.displayName=K.displayName;let eX=f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(W,{children:[(0,s.jsx)(eZ,{}),(0,s.jsxs)(X,{ref:r,className:(0,eh.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-card p-6 shadow-golden rounded-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",e),...n,children:[t,(0,s.jsxs)(eo,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,s.jsx)(h,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]}));function eY({className:e,...t}){return(0,s.jsx)("div",{className:(0,eh.cn)("flex flex-col space-y-1.5 text-center sm:text-left min-w-0",e),...t})}function eQ({className:e,...t}){return(0,s.jsx)("div",{className:(0,eh.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}eX.displayName=X.displayName,eY.displayName="DialogHeader",eQ.displayName="DialogFooter";let e0=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(en,{ref:n,className:(0,eh.cn)("text-lg font-normal leading-none tracking-tight",e),...t}));e0.displayName=en.displayName;let e1=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ei,{ref:n,className:(0,eh.cn)("text-sm text-muted-foreground break-words",e),...t}));function e2({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i="Delete",onConfirm:o,variant:a="destructive"}){return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eX,{className:"sm:max-w-sm",children:[(0,s.jsxs)(eY,{children:[(0,s.jsx)(e0,{children:n}),(0,s.jsx)(e1,{children:r})]}),(0,s.jsxs)(eQ,{className:"gap-2 sm:gap-0",children:[(0,s.jsx)(v.Button,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),(0,s.jsx)(v.Button,{variant:a,onClick:()=>{o(),t(!1)},children:i})]})]})})}e1.displayName=ei.displayName;var e3=e.i(10137);let e5=(0,o.default)("folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),e4=(0,o.default)("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]),e6=(0,o.default)("git-branch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]),e9=(0,o.default)("hard-drive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]]),e7=(0,o.default)("server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]),e8=(0,o.default)("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]),te=(0,o.default)("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]),tt=(0,o.default)("star-off",[["path",{d:"M8.34 8.34 2 9.27l5 4.87L5.82 21 12 17.77 18.18 21l-.59-3.43",key:"16m0ql"}],["path",{d:"M18.42 12.76 22 9.27l-6.91-1L12 2l-1.44 2.91",key:"1vt8nq"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);function tn({onSelect:e}){let[t,n]=(0,f.useState)("local"),[r,i]=(0,f.useState)(null),[o,a]=(0,f.useState)(!0),[l,c]=(0,f.useState)(null),[d,p]=(0,f.useState)(""),[m,g]=(0,f.useState)(!1),[b,y]=(0,f.useState)([]),[w,k]=(0,f.useState)(!1),N=(0,f.useRef)(null),S=(0,f.useRef)(null),[C,j]=(0,f.useState)(""),[E,M]=(0,f.useState)(""),[A,T]=(0,f.useState)(""),[O,_]=(0,f.useState)(""),[D,R]=(0,f.useState)(""),[I,L]=(0,f.useState)(""),[P,z]=(0,f.useState)(!1),[$,B]=(0,f.useState)(null),[F,H]=(0,f.useState)(""),[U,V]=(0,f.useState)(""),[W,q]=(0,f.useState)("agent"),[K,G]=(0,f.useState)(""),[J,Z]=(0,f.useState)(""),[X,Y]=(0,f.useState)(!1),[Q,ee]=(0,f.useState)(""),[et,en]=(0,f.useState)(!1),[er,ei]=(0,f.useState)(null),es=async()=>{let t=F.trim();if(!t)return void ei("SSH target is required (user@host:/path).");if("keyfile"===W&&!K.trim())return void ei("Private key path is required for key-file auth.");if("password"===W&&!J)return void ei("Password is required for password auth.");en(!0),ei(null);try{let n={sshTarget:t,sshAuthMethod:W};U.trim()&&(n.sshPort=Number(U.trim())),"keyfile"===W&&K.trim()&&(n.sshKeyPath=K.trim()),"password"===W&&J&&(n.sshPassword=J),X&&(n.sshReadOnly=!0),Q.trim()&&(n.name=Q.trim());let r=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){let e=await r.json();ei(e.error??e.message??"Mount failed.");return}let{workspace:i}=await r.json();Z(""),e(i.id)}catch{ei("Network error.")}finally{en(!1)}},eo=async()=>{let t=C.trim();if(!t)return void B("Repository URL is required.");z(!0),B(null);try{let n={remoteUrl:t};E.trim()&&(n.branch=E.trim()),A.trim()&&(n.subpath=A.trim()),O.trim()&&(n.username=O.trim()),D.trim()&&(n.token=D.trim()),I.trim()&&(n.name=I.trim());let r=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){let e=await r.json();B(e.error??e.message??"Clone failed.");return}let{workspace:i}=await r.json();R(""),e(i.id)}catch{B("Network error.")}finally{z(!1)}},ea=(0,f.useCallback)(async(e,t=!0)=>{S.current&&(clearTimeout(S.current),S.current=null),a(!0),c(null);try{let n=await fetch((0,ev.apiUrl)(`/api/system/browse?path=${encodeURIComponent(e)}`));if(!n.ok){let e=await n.json();c(e.error??"Cannot open directory");return}let r=await n.json();i(r),t&&p(r.path)}catch{c("Network error")}finally{a(!1)}},[]);(0,f.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch((0,ev.apiUrl)("/api/system/config"));if(t.ok&&!e){let e=await t.json();y(e.pinnedPaths??[]),await ea(e.lastOpenedPath??"");return}}catch{}e||await ea("")})(),()=>{e=!0}},[]);let el=async t=>{let n=t??r?.path;if(n){g(!0);try{let t=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rootDir:n})});if(!t.ok){let e=await t.json();c(e.message??e.error??"Cannot use that directory");return}let{workspace:r}=await t.json();e(r.id)}catch{c("Network error")}finally{g(!1)}}},ec=!!r&&b.includes(r.path),ed=async()=>{if(r){k(!0);try{let e=ec?"unpin":"pin";(await fetch((0,ev.apiUrl)("/api/system/pins"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path,action:e})})).ok&&y(t=>"pin"===e?[...t,r.path]:t.filter(e=>e!==r.path))}catch{}finally{k(!1)}}},eu=async e=>{try{(await fetch((0,ev.apiUrl)("/api/system/pins"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,action:"unpin"})})).ok&&y(t=>t.filter(t=>t!==e))}catch{}},ep=(r?.path??"").split(/[/\\]/).filter(Boolean).reduce((e,t)=>{let n=e[e.length-1]?.path??"/";return e.push({label:t,path:`${"/"===n?"":n}/${t}`}),e},[{label:"/",path:"/"}]);return(0,s.jsx)("div",{className:"flex flex-1 items-center justify-center bg-background p-4",children:(0,s.jsxs)("div",{className:"flex w-full max-w-xl flex-col gap-4",children:[(0,s.jsxs)("div",{className:"text-center space-y-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-1",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-8 w-8"}),(0,s.jsx)("span",{className:"text-xl font-semibold tracking-tight",children:"Wiki Viewer"})]}),(0,s.jsx)("h1",{className:"text-xl font-medium",children:"git"===t?"Add a Git repository":"ssh"===t?"Add a remote directory over SSH":"Choose a directory"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"git"===t?(0,s.jsxs)(s.Fragment,{children:["Clone a remote repo and serve it as a read-only workspace.",(0,s.jsx)("br",{}),"The server clones it, so the URL must be reachable from the server."]}):"ssh"===t?(0,s.jsxs)(s.Fragment,{children:["Mount a remote directory over SSH (sshfs) — no local clone.",(0,s.jsx)("br",{}),"Requires sshfs + FUSE installed on the server."]}):(0,s.jsxs)(s.Fragment,{children:["Select the folder wiki-viewer should serve.",(0,s.jsx)("br",{}),"This directory lives on the server, so use the browser below."]})})]}),(0,s.jsxs)("div",{className:"flex items-center self-center rounded-lg border bg-muted p-0.5 gap-0.5",children:[(0,s.jsxs)(v.Button,{variant:"local"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>{n("local"),R(""),B(null)},children:[(0,s.jsx)(e5,{className:"h-3.5 w-3.5"}),"Local folder"]}),(0,s.jsxs)(v.Button,{variant:"git"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>n("git"),children:[(0,s.jsx)(e6,{className:"h-3.5 w-3.5"}),"From Git"]}),(0,s.jsxs)(v.Button,{variant:"ssh"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>{n("ssh"),ei(null)},children:[(0,s.jsx)(e7,{className:"h-3.5 w-3.5"}),"Over SSH"]})]}),"git"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-4 pt-4 pb-3 flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Repository URL"}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"https://github.com/org/repo.git",value:C,onChange:e=>{j(e.target.value),B(null)},disabled:P,autoComplete:"off",spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Only https:// URLs are supported."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Branch ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"main (default branch if empty)",value:E,onChange:e=>{M(e.target.value),B(null)},disabled:P})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Subdirectory ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"docs (whole repo if empty)",value:A,onChange:e=>{T(e.target.value),B(null)},disabled:P,spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Serve only this folder from the repo. Faster to clone for large repos with docs in a subfolder."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Username ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"x-access-token (default)",value:O,onChange:e=>{_(e.target.value),B(null)},disabled:P,autoComplete:"off"})}),(0,s.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:["GitLab uses ",(0,s.jsx)("code",{className:"font-mono",children:"oauth2"}),"; Bitbucket uses your account username."]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Access token ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{type:"password",className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Personal access token",value:D,onChange:e=>{R(e.target.value),B(null)},disabled:P,autoComplete:"off"})]}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Required only for private repos. Stored securely on the server and never shown again."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Display name ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Defaults to the repository name",value:I,onChange:e=>{L(e.target.value),B(null)},disabled:P})})]}),$&&(0,s.jsx)("p",{className:"text-sm text-destructive",children:$})]}),(0,s.jsxs)("div",{className:"border-t px-4 py-3 flex items-center justify-between gap-3 bg-muted",children:[(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Git workspaces are read-only, so editing is disabled."}),(0,s.jsx)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:P,onClick:eo,children:P?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"})," Cloning..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e6,{className:"h-3.5 w-3.5"})," Clone and add"]})})]})]}),"ssh"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-4 pt-4 pb-3 flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"SSH target"}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"user@host:/abs/path",value:F,onChange:e=>{H(e.target.value),ei(null)},disabled:et,autoComplete:"off",spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The remote path must be absolute."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Port ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"22",inputMode:"numeric",value:U,onChange:e=>{V(e.target.value.replace(/[^0-9]/g,"")),ei(null)},disabled:et})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Authentication"}),(0,s.jsx)("div",{className:"flex items-center self-start rounded-lg border bg-muted p-0.5 gap-0.5",children:["agent","keyfile","password"].map(e=>(0,s.jsx)(v.Button,{variant:W===e?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>{q(e),ei(null)},disabled:et,children:"agent"===e?"SSH agent":"keyfile"===e?"Key file":"Password"},e))}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"agent"===W?"Uses the server's ssh-agent and default keys (~/.ssh/id_*).":"keyfile"===W?"Uses a specific private key on the server.":"Stored securely on the server and never shown again."})]}),"keyfile"===W&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Private key path"}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"~/.ssh/id_ed25519",value:K,onChange:e=>{G(e.target.value),ei(null)},disabled:et,autoComplete:"off",spellCheck:!1})]})]}),"password"===W&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Password"}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{type:"password",className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"SSH password",value:J,onChange:e=>{Z(e.target.value),ei(null)},disabled:et,autoComplete:"off"})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Display name ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Defaults to host:path",value:Q,onChange:e=>{ee(e.target.value),ei(null)},disabled:et})})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs font-medium cursor-pointer select-none",children:[(0,s.jsx)("input",{type:"checkbox",checked:X,onChange:e=>Y(e.target.checked),disabled:et}),"Mount read-only"]}),er&&(0,s.jsx)("p",{className:"text-sm text-destructive",children:er})]}),(0,s.jsxs)("div",{className:"border-t px-4 py-3 flex items-center justify-between gap-3 bg-muted",children:[(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Served live over SSH — nothing is copied to disk."}),(0,s.jsx)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:et,onClick:es,children:et?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"})," Mounting..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7,{className:"h-3.5 w-3.5"})," Mount and add"]})})]})]}),"local"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsx)("div",{className:"flex items-center gap-2 border-b px-3 py-2 bg-muted",children:(0,s.jsx)("input",{ref:N,className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",value:d,onChange:e=>{let t=e.target.value;p(t),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{S.current=null,ea(t.trim(),!1)},500)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),S.current&&(clearTimeout(S.current),S.current=null),ea(d.trim())),"Escape"===e.key&&(S.current&&(clearTimeout(S.current),S.current=null),p(r?.path??""),N.current?.blur())},spellCheck:!1,placeholder:"Enter a path…"})}),(0,s.jsx)("div",{className:"flex items-center gap-1 border-b px-3 py-1.5 bg-muted/50 overflow-x-auto shrink-0 min-h-[32px]",children:ep.map((e,t)=>(0,s.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[t>0&&(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3 text-muted-foreground/50"}),(0,s.jsx)("button",{type:"button",className:"text-xs hover:text-foreground text-muted-foreground transition-colors rounded px-0.5",onClick:()=>ea(e.path),children:0===t?(0,s.jsx)(e9,{className:"h-3.5 w-3.5"}):e.label})]},e.path))}),(0,s.jsx)("div",{className:"max-h-60 overflow-y-auto",children:o?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l?(0,s.jsx)("div",{className:"px-4 py-3 text-sm text-destructive",children:l}):(0,s.jsxs)(s.Fragment,{children:[r?.parent&&(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground transition-colors",onClick:()=>ea(r.parent),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0"}),(0,s.jsx)("span",{className:"text-xs",children:".."})]}),r?.entries.length===0&&(0,s.jsx)("p",{className:"px-4 py-3 text-sm text-muted-foreground/60",children:"No subdirectories"}),r?.entries.map(e=>(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground transition-colors",onClick:()=>ea(e.path),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("span",{className:"truncate",children:e.name})]},e.path))]})}),(0,s.jsxs)("div",{className:"border-t px-3 py-2 flex items-center justify-between gap-2 bg-muted",children:[(0,s.jsxs)("button",{type:"button",className:(0,eh.cn)("flex items-center gap-1.5 text-xs transition-colors rounded px-1.5 py-1",ec?"text-foreground hover:text-destructive":"text-muted-foreground hover:text-foreground"),title:ec?"Remove from favorites":"Add to favorites for quick access",onClick:ed,disabled:w||!r,children:[w?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):ec?(0,s.jsx)(tt,{className:"h-3.5 w-3.5"}):(0,s.jsx)(te,{className:"h-3.5 w-3.5"}),ec?"Unfavorite":"Favorite"]}),(0,s.jsxs)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:!r||m,onClick:()=>el(),children:[m?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(e4,{className:"h-3.5 w-3.5"}),"Select"]})]})]}),"local"===t&&b.length>0&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsx)("div",{className:"px-3 py-2 border-b bg-muted",children:(0,s.jsxs)("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1.5",children:[(0,s.jsx)(te,{className:"h-3 w-3"})," Pinned"]})}),(0,s.jsx)("div",{className:"max-h-40 overflow-y-auto",children:b.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-accent group",children:[(0,s.jsxs)("button",{type:"button",className:"flex-1 flex items-center gap-2 text-sm text-left min-w-0",onClick:()=>ea(e),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("span",{className:"truncate text-xs",children:e})]}),(0,s.jsx)("button",{type:"button",className:"shrink-0 text-muted-foreground/50 hover:text-destructive opacity-0 group-hover:opacity-100 transition-all",onClick:()=>eu(e),title:"Remove from favorites",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]},e))})]}),"local"===t&&r?.shortcuts&&r.shortcuts.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap gap-1.5 justify-center",children:r.shortcuts.map(e=>(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>ea(e.path),children:["Home"===e.label?(0,s.jsx)(e8,{className:"h-3 w-3"}):(0,s.jsx)(e9,{className:"h-3 w-3"}),e.label]},e.path))})]})})}var tr=e.i(391548),ti=e.i(567776);let ts=(0,o.default)("trash-2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),to=(0,o.default)("clock",[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);var ta=e.i(793479),tl=e.i(461614),tc="Switch",[td,tu]=(0,N.createContextScope)(tc),[tp,th]=td(tc),tf=f.forwardRef((e,t)=>{let{__scopeSwitch:n,name:r,checked:i,defaultChecked:o,required:a,disabled:l,value:c="on",onCheckedChange:d,form:u,...p}=e,[h,m]=f.useState(null),g=(0,k.useComposedRefs)(t,e=>m(e)),b=f.useRef(!1),x=!h||u||!!h.closest("form"),[y,v]=(0,C.useControllableState)({prop:i,defaultProp:o??!1,onChange:d,caller:tc});return(0,s.jsxs)(tp,{scope:n,checked:y,disabled:l,children:[(0,s.jsx)(T.Primitive.button,{type:"button",role:"switch","aria-checked":y,"aria-required":a,"data-state":tx(y),"data-disabled":l?"":void 0,disabled:l,value:c,...p,ref:g,onClick:(0,w.composeEventHandlers)(e.onClick,e=>{v(e=>!e),x&&(b.current=e.isPropagationStopped(),b.current||e.stopPropagation())})}),x&&(0,s.jsx)(tb,{control:h,bubbles:!b.current,name:r,value:c,checked:y,required:a,disabled:l,form:u,style:{transform:"translateX(-100%)"}})]})});tf.displayName=tc;var tm="SwitchThumb",tg=f.forwardRef((e,t)=>{let{__scopeSwitch:n,...r}=e,i=th(tm,n);return(0,s.jsx)(T.Primitive.span,{"data-state":tx(i.checked),"data-disabled":i.disabled?"":void 0,...r,ref:t})});tg.displayName=tm;var tb=f.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...i},o)=>{let a,l=f.useRef(null),c=(0,k.useComposedRefs)(l,o),d=(a=f.useRef({value:n,previous:n}),f.useMemo(()=>(a.current.value!==n&&(a.current.previous=a.current.value,a.current.value=n),a.current.previous),[n])),u=(0,tl.useSize)(t);return f.useEffect(()=>{let e=l.current;if(!e)return;let t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"checked").set;if(d!==n&&t){let i=new Event("click",{bubbles:r});t.call(e,n),e.dispatchEvent(i)}},[d,n,r]),(0,s.jsx)("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...i,tabIndex:-1,ref:c,style:{...i.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});function tx(e){return e?"checked":"unchecked"}function ty({className:e,...t}){return(0,s.jsx)(tf,{"data-slot":"switch",className:(0,eh.cn)("peer data-[state=checked]:bg-[var(--switch-checked)] data-[state=unchecked]:bg-input inline-flex h-5 w-9 shrink-0 items-center rounded-sm border-2 border-transparent shadow-e-1 transition-all outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:(0,s.jsx)(tg,{"data-slot":"switch-thumb",className:"bg-background pointer-events-none block size-4 rounded-sm shadow-e-1 ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})}tb.displayName="SwitchBubbleInput";var tv=e.i(380560),tw=e.i(206102),tk=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,t)=>{let n=(0,tw.createSlot)(`Primitive.${t}`),r=f.forwardRef((e,r)=>{let{asChild:i,...o}=e;return"u">typeof window&&(window[Symbol.for("radix-ui")]=!0),(0,s.jsx)(i?n:t,{...o,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),tN=f.forwardRef((e,t)=>(0,s.jsx)(tk.label,{...e,ref:t,onMouseDown:t=>{t.target.closest("button, input, select, textarea")||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));tN.displayName="Label";var tS=e.i(294237);let tC=(0,tS.cva)("text-sm font-normal leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50"),tj=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(tN,{ref:n,className:(0,eh.cn)(tC(),e),...t}));tj.displayName=tN.displayName;var tE=e.i(671485);function tM({open:e,onOpenChange:t,filePath:n}){let[r,i]=(0,f.useState)([]),[o,a]=(0,f.useState)(!0),[l,d]=(0,f.useState)(!1),[p,h]=(0,f.useState)(""),[m,b]=(0,f.useState)(!1),[x,y]=(0,f.useState)(!1),[w,k]=(0,f.useState)("7"),[N,S]=(0,f.useState)(null),C=(0,f.useCallback)(async()=>{a(!0);try{let e=await (0,tE.wsFetch)(`/api/share?path=${encodeURIComponent(n)}`);if(e.ok){let t=await e.json();i(t.shares??[])}}catch{}a(!1)},[n]);(0,f.useEffect)(()=>{e&&C()},[e,C]);let j=async()=>{d(!0);try{let e={path:n};if(m&&p.trim()&&(e.password=p.trim()),x&&w){let t=new Date;t.setDate(t.getDate()+Number(w)),e.expiresAt=t.toISOString()}let t=await (0,tE.wsFetch)("/api/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();ey(e.error??"Failed to create share link");return}ex("Share link created"),h(""),b(!1),y(!1),k("7"),await C()}catch{ey("Failed to create share link")}finally{d(!1)}},E=async e=>{try{if(!(await fetch((0,ev.apiUrl)(`/api/share/${e}`),{method:"DELETE"})).ok)return void ey("Failed to revoke share link");ex("Share link revoked"),await C()}catch{ey("Failed to revoke share link")}};return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eX,{className:"sm:max-w-md",children:[(0,s.jsxs)(eY,{children:[(0,s.jsx)(e0,{children:"Share document"}),(0,s.jsx)(e1,{children:"Create a public link to share this document as read-only."})]}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"rounded-sm border border-border p-3 space-y-3",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"New share link"}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)(tj,{htmlFor:"share-pwd",className:"text-xs gap-1.5 flex items-center",children:[(0,s.jsx)(ti.Lock,{className:"h-3 w-3 text-muted-foreground"}),"Password protect"]}),(0,s.jsx)(ty,{id:"share-pwd",checked:m,onCheckedChange:b})]}),m&&(0,s.jsx)(ta.Input,{type:"password",placeholder:"Set a password",value:p,onChange:e=>h(e.target.value)}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)(tj,{htmlFor:"share-expiry",className:"text-xs gap-1.5 flex items-center",children:[(0,s.jsx)(to,{className:"h-3 w-3 text-muted-foreground"}),"Set expiration"]}),(0,s.jsx)(ty,{id:"share-expiry",checked:x,onCheckedChange:y})]}),x&&(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ta.Input,{type:"number",min:1,max:365,value:w,onChange:e=>k(e.target.value),className:"w-20"}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:"days"})]}),(0,s.jsxs)(v.Button,{size:"sm",className:"w-full gap-1.5",onClick:j,disabled:l,children:[l?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(c,{className:"h-3.5 w-3.5"}),"Create link"]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:r.length>0?`Active links (${r.length})`:o?"Loading...":"No active links"}),o&&(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}),r.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-sm border border-border p-2",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:(0,s.jsxs)("span",{className:"text-xs truncate",children:[window.location.origin,"/s/",e.token]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[e.hasPassword&&(0,s.jsxs)("span",{className:"flex items-center gap-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsx)(ti.Lock,{className:"h-2.5 w-2.5"}),"pwd"]}),e.expiresAt&&(0,s.jsxs)("span",{className:"flex items-center gap-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsx)(to,{className:"h-2.5 w-2.5"}),function(e){let t=new Date(e),n=new Date,r=t.getTime()-n.getTime();if(r<=0)return"expired";let i=Math.floor(r/864e5),s=Math.floor(r%864e5/36e5);return i>0?`${i}d`:s>0?`${s}h`:"<1h"}(e.expiresAt)]}),(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[e.viewCount," view",1!==e.viewCount?"s":""]}),e.isExpired&&(0,s.jsx)("span",{className:"text-[10px] text-destructive",children:"expired"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Copy link",onClick:()=>{var t,n;let r;return t=e.url,n=e.token,r=`${window.location.origin}${t}`,void(navigator.clipboard.writeText(r),S(n),setTimeout(()=>S(null),2e3))},children:N===e.token?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-success"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",title:"Revoke link",onClick:()=>E(e.token),children:(0,s.jsx)(ts,{className:"h-3.5 w-3.5"})})]})]},e.id))]})]})]})})}let tA=(0,o.default)("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]);var tT=e.i(412473);let tO=(0,eN.create)(e=>({isOpen:!1,open:()=>e({isOpen:!0}),close:()=>e({isOpen:!1}),toggle:()=>e(e=>({isOpen:!e.isOpen})),clearMessages:()=>{},activity:[],connections:[],hasToken:!1,pollIntervalMs:1e4,rateLimit:null,loadActivity:async()=>{if((0,ev.isLite)())return;let t=localStorage.getItem("wiki-agent-token")??null,n=!!(t&&t.trim());try{let t=await (0,tE.wsFetch)("/api/agent/activity?limit=50",{headers:{}});if(!t.ok)return void e({hasToken:n});let r=(await t.json()).events??[],i=function(e){let t=new Date(Date.now()-3e5).toISOString(),n=new Map;for(let r of e){if(r.at<t)continue;let e=n.get(r.by);e?n.set(r.by,{opCount:e.opCount+1,lastSeen:r.at>e.lastSeen?r.at:e.lastSeen}):n.set(r.by,{opCount:1,lastSeen:r.at})}return Array.from(n.entries()).map(([e,t])=>({by:e,...t})).sort((e,t)=>e.lastSeen<t.lastSeen?1:-1)}(r),s=null;try{let e=await (0,tE.wsFetch)("/api/agent/settings",{headers:{}});e.ok&&(s=(await e.json()).rateLimit??null)}catch{}e({activity:r,connections:i,hasToken:n,rateLimit:s})}catch{e({hasToken:n})}}})),t_=(0,o.default)("circle-check-big",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]),tD=(0,o.default)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),tR=(0,o.default)("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);function tI(e){let t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function tL({scope:e}){return(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 font-mono",children:[e.paths.join(", ")," · ",e.ops.join(",")]})}function tP({reg:e,onApprove:t,onDeny:n}){let[r,i]=(0,f.useState)(!1);async function o(t){i(!0);try{await t(e.registrationId)}finally{i(!1)}}return(0,s.jsxs)("li",{className:"py-1.5 border-b border-border/40 last:border-0",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-1",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"text-xs font-mono truncate",children:e.displayName}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 truncate",children:e.agentId}),(0,s.jsx)(tL,{scope:e.requestedScope})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsxs)(v.Button,{size:"sm",variant:"default",className:"h-6 px-2 text-[10px]",disabled:r,onClick:()=>void o(t),title:"Approve",children:[(0,s.jsx)(t_,{className:"h-3 w-3 mr-0.5"}),"Approve"]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[10px] text-destructive hover:text-destructive",disabled:r,onClick:()=>void o(n),title:"Deny",children:[(0,s.jsx)(tD,{className:"h-3 w-3 mr-0.5"}),"Deny"]})]})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 mt-0.5",children:["Requested ",tI(e.requestedAt)]})]})}function tz({agent:e,onRevoke:t}){let[n,r]=(0,f.useState)(!1);return(0,s.jsxs)("li",{className:"py-1.5 border-b border-border/40 last:border-0",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-1",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"text-xs font-mono truncate",children:e.displayName}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 truncate",children:e.id}),(0,s.jsx)(tL,{scope:e.scope})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive",disabled:n,onClick:async()=>{r(!0);try{await t(e.id)}finally{r(!1)}},title:"Revoke agent",children:(0,s.jsx)(ts,{className:"h-3 w-3"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 mt-0.5",children:["Last seen ",tI(e.lastSeen)]})]})}function t$(){let[e,t]=(0,f.useState)([]),[n,r]=(0,f.useState)([]),[i,o]=(0,f.useState)(!1);(0,f.useEffect)(()=>{fetch((0,ev.apiUrl)("/api/owner/init"),{credentials:"same-origin"}).then(e=>{(e.ok||204===e.status)&&o(!0)}).catch(()=>{o(!0)})},[]);let a=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/agent/admin/registrations"),{credentials:"same-origin"});if(!e.ok)return;let n=await e.json();t(n.pending)}catch{}},[]),l=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/agent/admin/agents"),{credentials:"same-origin"});if(!e.ok)return;let t=await e.json();r(t.agents)}catch{}},[]);(0,f.useEffect)(()=>{if(!i)return;a(),l();let e=setInterval(()=>void a(),5e3),t=setInterval(()=>void l(),3e4);return()=>{clearInterval(e),clearInterval(t)}},[i,a,l]);let c=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/registrations/${e}/approve`),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:"{}"})).ok?(eb.toast.success("Agent approved"),await Promise.all([a(),l()])):eb.toast.error("Failed to approve agent")},[a,l]),d=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/registrations/${e}/deny`),{method:"POST",credentials:"same-origin"})).ok?(eb.toast.success("Registration denied"),await a()):eb.toast.error("Failed to deny registration")},[a]),u=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/agents/${encodeURIComponent(e)}/revoke`),{method:"POST",credentials:"same-origin"})).ok?(eb.toast.success("Agent revoked"),await l()):eb.toast.error("Failed to revoke agent")},[l]);return(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Agents · approve & manage access"}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-5 w-5 p-0",title:"Refresh",onClick:()=>void Promise.all([a(),l()]),children:(0,s.jsx)(tR,{className:"h-3 w-3"})})]}),e.length>0&&(0,s.jsxs)("div",{className:"rounded-md border border-amber-500/40 bg-amber-50/10 p-2",children:[(0,s.jsxs)("p",{className:"text-[10px] font-semibold uppercase tracking-widest text-amber-600/80 mb-1 flex items-center gap-1",children:[(0,s.jsx)(to,{className:"h-3 w-3"}),"Waiting for your approval (",e.length,")"]}),(0,s.jsx)("ul",{children:e.map(e=>(0,s.jsx)(tP,{reg:e,onApprove:c,onDeny:d},e.registrationId))})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-2",children:0===n.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 py-1",children:["No assistants connected yet."," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"Connect one above; once it requests access it’ll appear here for you to approve."})]}):(0,s.jsx)("ul",{children:n.map(e=>(0,s.jsx)(tz,{agent:e,onRevoke:u},e.id))})}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 leading-relaxed",children:"Each assistant gets its own access that you can revoke anytime. New requests appear above for your approval before they can read or edit anything."})]})}class tB extends Error{status;constructor(e,t){super(e),this.status=t,this.name="FetchPageError"}}async function tF(e,t){let n=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`,{signal:t});if(!n.ok)throw new tB(`Failed to fetch page: ${e}`,n.status);let r=await n.json(),i=n.headers.get("X-Wiki-Revision"),s=null!==i?Number(i):null;return{path:e,content:r.content,frontmatter:null,revision:s}}class tH extends Error{currentRevision;serverContent;constructor(e,t){super("File was modified externally. Reloaded with latest content."),this.currentRevision=e,this.serverContent=t,this.name="StaleRevisionError"}}async function tU(e,t,n){let r={path:e,content:t};null!==n&&(r.baseRevision=n);let i=await (0,tE.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(409===i.status){let n=await i.json(),r=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`),s=r.ok?(await r.json()).content:t;throw new tH(n.currentRevision??0,s)}if(!i.ok)throw Error("Failed to save page");return{revision:(await i.json()).revision??null}}async function tV(e,t=""){await tU(e,t,null)}let tW="kb-page-cache",tq=new Map,tK=new Map;function tG(e){if(tq.delete(e.path),tq.set(e.path,e),tq.size>30){let e=tq.keys().next().value;void 0!==e&&tq.delete(e)}}function tJ(e){if(tq.has(e)||tK.has(e))return;let t=tF(e).then(e=>(tG(e),e)).finally(()=>{tK.delete(e)});tK.set(e,t),t.catch(()=>{})}function tZ(e){try{localStorage.setItem(tW,JSON.stringify(e))}catch{}}let tX="kb-edit-mode",tY=null,tQ=null,t0=null,t1=(0,eN.create)((e,t)=>({currentPath:null,content:"",frontmatter:null,saveStatus:"idle",loadStatus:"idle",isDirty:!1,isLoading:!1,lastSavedAt:null,currentRevision:null,editMode:"suggesting"===localStorage.getItem(tX)?"suggesting":"editing",setEditMode:t=>{localStorage.setItem(tX,t),e({editMode:t})},loadPage:async n=>{let r,i=t();i.isDirty&&i.currentPath&&i.currentPath!==n&&await t().save(),e({currentPath:n,isLoading:!0,loadStatus:"loading",isDirty:!1,content:"",currentRevision:null});let s=(r=tq.get(n))?(tq.delete(n),tq.set(n,r),r):null,o=s??function(e){try{let t=localStorage.getItem(tW);if(!t)return null;let n=JSON.parse(t);if(n.path!==e)return null;return n}catch{return null}}(n);o&&e({content:o.content,frontmatter:o.frontmatter,isLoading:!1,loadStatus:"ok",...s?{currentRevision:s.revision}:{}});let a=tK.get(n);if(a)try{let r=await a;if(t().currentPath!==n)return;e({content:r.content,frontmatter:r.frontmatter,isLoading:!1,loadStatus:"ok",currentRevision:r.revision}),tZ({path:n,content:r.content,frontmatter:r.frontmatter});return}catch{}t0?.abort();let l=new AbortController;t0=l;try{let r=await tF(n,l.signal);if(tG(r),t().currentPath!==n)return;e({content:r.content,frontmatter:r.frontmatter,isLoading:!1,loadStatus:"ok",currentRevision:r.revision}),tZ({path:n,content:r.content,frontmatter:r.frontmatter})}catch(r){if(r instanceof DOMException&&"AbortError"===r.name||t().currentPath!==n)return;r instanceof tB&&404===r.status?e({isLoading:!1,loadStatus:"missing",content:""}):e({isLoading:!1,loadStatus:"error"})}},updateContent:n=>{"suggesting"===t().editMode?e({content:n}):(e({content:n,isDirty:!0}),tY&&clearTimeout(tY),tY=setTimeout(()=>{t().save()},500))},updateFrontmatter:n=>{e({frontmatter:{...t().frontmatter,...n},isDirty:!0}),tY&&clearTimeout(tY),tY=setTimeout(()=>{t().save()},500)},save:async()=>{let{currentPath:n,content:r,isDirty:i,currentRevision:s,editMode:o}=t();if(n&&i&&"suggesting"!==o){e({saveStatus:"saving"});try{let i=await tU(n,r,s);e({saveStatus:"saved",isDirty:!1,lastSavedAt:Date.now(),currentRevision:i.revision??s}),tZ({path:n,content:r,frontmatter:t().frontmatter}),tG({path:n,content:r,frontmatter:t().frontmatter,revision:i.revision??s}),tQ&&clearTimeout(tQ),tQ=setTimeout(()=>{"saved"===t().saveStatus&&e({saveStatus:"idle"})},2e3)}catch(r){r instanceof tH?(e({content:r.serverContent,isDirty:!1,saveStatus:"error",currentRevision:r.currentRevision}),tZ({path:n,content:r.serverContent,frontmatter:t().frontmatter})):e({saveStatus:"error"})}}},createMissingPage:async n=>{let{currentPath:r}=t();if(!r)return;let i=`# ${n}
5
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return f.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},ep=({contentRef:e,descriptionId:t})=>{let n=ed("DialogDescriptionWarning"),r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${n.contentName}}.`;return f.useEffect(()=>{let n=e.current?.getAttribute("aria-describedby");t&&n&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},eh=e.i(975157);let ef=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(K,{ref:n,className:(0,eh.cn)("fixed inset-0 z-40 bg-overlay backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));ef.displayName="SheetOverlay";let em={bottom:"inset-x-0 bottom-0 data-[state=open]:slide-in-from-bottom data-[state=closed]:slide-out-to-bottom",top:"inset-x-0 top-0 data-[state=open]:slide-in-from-top data-[state=closed]:slide-out-to-top",left:"inset-y-0 left-0 data-[state=open]:slide-in-from-left data-[state=closed]:slide-out-to-left",right:"inset-y-0 right-0 data-[state=open]:slide-in-from-right data-[state=closed]:slide-out-to-right"},eg=f.forwardRef(({side:e="bottom",showClose:t=!1,className:n,overlayClassName:r,children:i,...o},a)=>(0,s.jsxs)(W,{children:[(0,s.jsx)(ef,{className:r}),(0,s.jsxs)(X,{ref:a,className:(0,eh.cn)("fixed z-50 bg-background shadow-golden transition-all ease-in-out","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-200 data-[state=open]:duration-300",em[e],n),...o,children:[i,t&&(0,s.jsxs)(eo,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring disabled:pointer-events-none",children:[(0,s.jsx)(h,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]}));eg.displayName="SheetContent",f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(en,{ref:n,className:(0,eh.cn)("text-sm font-medium leading-none tracking-tight",e),...t})).displayName="SheetTitle",f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ei,{ref:n,className:(0,eh.cn)("text-sm text-muted-foreground",e),...t})).displayName="SheetDescription";var eb=e.i(187014);function ex(e,t){eb.toast.success(e,t)}function ey(e,t){eb.toast.error(e,t)}var ev=e.i(354502),ew=e.i(199075),ek=e.i(755146),eN=e.i(534537);let eS={inter:{id:"inter",label:"Inter",kind:"sans",cssValue:"var(--font-inter), ui-sans-serif, system-ui, -apple-system, sans-serif"},satoshi:{id:"satoshi",label:"Satoshi",kind:"sans",cssValue:"var(--font-satoshi), ui-sans-serif, system-ui, -apple-system, sans-serif"},"general-sans":{id:"general-sans",label:"General Sans",kind:"sans",cssValue:"var(--font-general-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},roboto:{id:"roboto",label:"Roboto",kind:"sans",cssValue:"var(--font-roboto), ui-sans-serif, system-ui, -apple-system, sans-serif"},"open-sans":{id:"open-sans",label:"Open Sans",kind:"sans",cssValue:"var(--font-open-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},lexend:{id:"lexend",label:"Lexend",kind:"sans",cssValue:"var(--font-lexend), ui-sans-serif, system-ui, -apple-system, sans-serif"},"atkinson-hyperlegible":{id:"atkinson-hyperlegible",label:"Atkinson Hyperlegible",kind:"sans",cssValue:"var(--font-atkinson-hyperlegible), ui-sans-serif, system-ui, -apple-system, sans-serif"},"elms-sans":{id:"elms-sans",label:"Elms Sans",kind:"sans",cssValue:"var(--font-elms-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},"stack-sans-notch":{id:"stack-sans-notch",label:"Stack Notch",kind:"sans",cssValue:"var(--font-stack-sans-notch), ui-sans-serif, system-ui, -apple-system, sans-serif"},"stack-sans-text":{id:"stack-sans-text",label:"Stack Text",kind:"sans",cssValue:"var(--font-stack-sans-text), ui-sans-serif, system-ui, -apple-system, sans-serif"},datatype:{id:"datatype",label:"Datatype",kind:"sans",cssValue:"var(--font-datatype), ui-sans-serif, system-ui, -apple-system, sans-serif"},"miranda-sans":{id:"miranda-sans",label:"Miranda Sans",kind:"sans",cssValue:"var(--font-miranda-sans), ui-sans-serif, system-ui, -apple-system, sans-serif"},luciole:{id:"luciole",label:"Luciole",kind:"sans",cssValue:"var(--font-luciole), ui-sans-serif, system-ui, -apple-system, sans-serif"},verdana:{id:"verdana",label:"Verdana",kind:"sans",cssValue:"Verdana, Geneva, Tahoma, sans-serif"},newsreader:{id:"newsreader",label:"Newsreader",kind:"serif",cssValue:"var(--font-newsreader), Georgia, serif"},fraunces:{id:"fraunces",label:"Fraunces",kind:"serif",cssValue:"var(--font-fraunces), Georgia, serif"},sentient:{id:"sentient",label:"Sentient",kind:"serif",cssValue:"var(--font-sentient), Georgia, serif"},gambetta:{id:"gambetta",label:"Gambetta",kind:"serif",cssValue:"var(--font-gambetta), Georgia, serif"},merriweather:{id:"merriweather",label:"Merriweather",kind:"serif",cssValue:"var(--font-merriweather), Georgia, serif"},baskerville:{id:"baskerville",label:"Baskerville",kind:"serif",cssValue:"var(--font-libre-baskerville), Georgia, serif"},palatino:{id:"palatino",label:"Palatino",kind:"serif",cssValue:"Palatino Linotype, Palatino, Book Antiqua, Georgia, serif"},"plex-mono":{id:"plex-mono",label:"IBM Plex Mono",kind:"mono",cssValue:"var(--font-plex-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"jetbrains-mono":{id:"jetbrains-mono",label:"JetBrains Mono",kind:"mono",cssValue:"var(--font-jetbrains-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"fira-code":{id:"fira-code",label:"Fira Code",kind:"mono",cssValue:"var(--font-fira-code), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"roboto-mono":{id:"roboto-mono",label:"Roboto Mono",kind:"mono",cssValue:"var(--font-roboto-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"space-mono":{id:"space-mono",label:"Space Mono",kind:"mono",cssValue:"var(--font-space-mono), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},"source-code-pro":{id:"source-code-pro",label:"Source Code Pro",kind:"mono",cssValue:"var(--font-source-code-pro), ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"}},eC=["inter","satoshi","general-sans","roboto","open-sans","lexend","atkinson-hyperlegible","elms-sans","stack-sans-notch","stack-sans-text","datatype","miranda-sans","luciole","verdana"],ej=["plex-mono","jetbrains-mono","fira-code","roboto-mono","space-mono","source-code-pro"],eE=["inter","satoshi","general-sans","roboto","open-sans","lexend","atkinson-hyperlegible","elms-sans","stack-sans-notch","stack-sans-text","datatype","miranda-sans","luciole","verdana","newsreader","fraunces","sentient","gambetta","merriweather","baskerville","palatino","plex-mono","jetbrains-mono","fira-code","roboto-mono","space-mono","source-code-pro"],eM={classic:{id:"classic",label:"Classic",description:"Inter, Newsreader, Fraunces — the original pairing",fonts:{ui:"inter",body:"newsreader",heading:"fraunces",code:"plex-mono"}},modern:{id:"modern",label:"Modern",description:"Satoshi, Sentient, Gambetta — clean and contemporary",fonts:{ui:"satoshi",body:"sentient",heading:"gambetta",code:"plex-mono"}},literary:{id:"literary",label:"Literary",description:"General Sans, Merriweather, Baskerville — magazine-style contrast",fonts:{ui:"general-sans",body:"merriweather",heading:"baskerville",code:"plex-mono"}},legible:{id:"legible",label:"Legible",description:"Atkinson Hyperlegible, Lexend — built for accessibility",fonts:{ui:"atkinson-hyperlegible",body:"atkinson-hyperlegible",heading:"lexend",code:"plex-mono"}},warm:{id:"warm",label:"Warm",description:"Luciole, Palatino — humanist and generously proportioned",fonts:{ui:"luciole",body:"palatino",heading:"palatino",code:"plex-mono"}},stack:{id:"stack",label:"Stack",description:"Stack Sans Text/Notch, Sentient — display headings, calm reading",fonts:{ui:"stack-sans-text",body:"sentient",heading:"stack-sans-notch",code:"plex-mono"}}},eA=["classic","modern","literary","legible","warm","stack"],eT=[.8,.9,1,1.1,1.2,1.3,1.4,1.5];function eO(e){return"number"==typeof e&&Number.isFinite(e)&&e>=.5&&e<=2}let e_="wiki-fonts",eD="inter",eR="newsreader",eI="fraunces",eL="plex-mono";function eP(e){return`--font-scale-${e}`}function ez(){let e=document.documentElement,t=e.dataset.fontUi||eD,n=e.dataset.fontBody||eR,r=e.dataset.fontHeading||eI,i=e.dataset.fontCode||eL,s=(t,n)=>{let r=e.style.getPropertyValue(eP(t)),i=r?Number.parseFloat(r):NaN;return eO(i)?i:n};return{ui:t,body:n,heading:r,code:i,uiScale:s("ui",1),bodyScale:s("body",1),headingScale:s("heading",1),codeScale:s("code",1)}}let e$=(0,eN.create)(e=>{let t=ez();return{ui:t.ui,body:t.body,heading:t.heading,code:t.code,uiScale:t.uiScale,bodyScale:t.bodyScale,headingScale:t.headingScale,codeScale:t.codeScale,setFont:(t,n)=>{{let e=document.documentElement,r=e.dataset.fontUi||eD,i=e.dataset.fontBody||eR,s=e.dataset.fontHeading||eI,o=e.dataset.fontCode||eL,a={...ez(),ui:"ui"===t?n:r,body:"body"===t?n:i,heading:"heading"===t?n:s,code:"code"===t?n:o};localStorage.setItem(e_,JSON.stringify(a)),e.dataset.fontUi=a.ui,e.dataset.fontBody=a.body,e.dataset.fontHeading=a.heading,e.dataset.fontCode=a.code}e(e=>"ui"===t?{...e,ui:n}:"body"===t?{...e,body:n}:"heading"===t?{...e,heading:n}:"code"===t?{...e,code:n}:e)},setScale:(t,n)=>{if(eO(n)){{let e=document.documentElement,r=ez(),i={...r,uiScale:"ui"===t?n:r.uiScale,bodyScale:"body"===t?n:r.bodyScale,headingScale:"heading"===t?n:r.headingScale,codeScale:"code"===t?n:r.codeScale};localStorage.setItem(e_,JSON.stringify(i)),e.style.setProperty(eP(t),String(n))}e(e=>"ui"===t?{...e,uiScale:n}:"body"===t?{...e,bodyScale:n}:"heading"===t?{...e,headingScale:n}:"code"===t?{...e,codeScale:n}:e)}},applyPreset:t=>{let n=eM[t].fonts;{let e=document.documentElement,t={...ez(),ui:n.ui,body:n.body,heading:n.heading,code:n.code};localStorage.setItem(e_,JSON.stringify(t)),e.dataset.fontUi=n.ui,e.dataset.fontBody=n.body,e.dataset.fontHeading=n.heading,e.dataset.fontCode=n.code}e(e=>({...e,ui:n.ui,body:n.body,heading:n.heading,code:n.code}))}}}),eB=[{id:"focusMode",label:"Focus mode",description:"Dim everything except the block you're reading."},{id:"breadcrumb",label:"Sticky breadcrumb",description:"Current heading trail pinned to the top while you scroll."}],eF="wiki-experiments",eH=(0,eN.create)(e=>({flags:function(){let e=Object.fromEntries(eB.map(e=>[e.id,!1]));try{let t=localStorage.getItem(eF),n=t?JSON.parse(t):{};for(let t of eB)"boolean"==typeof n[t.id]&&(e[t.id]=n[t.id])}catch{}return e}(),toggle:t=>e(e=>{let n={...e.flags,[t]:!e.flags[t]};try{localStorage.setItem(eF,JSON.stringify(n))}catch{}return{flags:n}})}));function eU(e){return eH(t=>t.flags[e])}function eV(e){return e.split(/[\n,]/).map(e=>e.trim()).filter(Boolean)}function eW(){let e=eH(e=>e.flags),t=eH(e=>e.toggle);return(0,s.jsx)("div",{className:"space-y-1.5",children:eB.map(n=>{let r=e[n.id];return(0,s.jsxs)("button",{type:"button",onClick:()=>t(n.id),"aria-pressed":r,className:`flex w-full items-start justify-between gap-3 rounded-md border px-3 py-2 text-left transition-colors ${r?"border-ring bg-accent":"border-border hover:bg-accent/50"}`,children:[(0,s.jsxs)("span",{className:"min-w-0",children:[(0,s.jsx)("span",{className:"block text-sm font-medium",children:n.label}),(0,s.jsx)("span",{className:"block text-xs text-muted-foreground",children:n.description})]}),(0,s.jsx)("span",{"aria-hidden":!0,className:`mt-0.5 flex h-5 w-9 shrink-0 items-center rounded-full px-0.5 transition-colors ${r?"bg-primary":"bg-muted-foreground/30"}`,children:(0,s.jsx)("span",{className:`h-4 w-4 rounded-full bg-background transition-transform ${r?"translate-x-4":"translate-x-0"}`})})]},n.id)})})}function eq(){let{ui:e,body:t,heading:n,code:r}=e$(),i=e$(e=>e.applyPreset),o=eA.find(i=>{let s=eM[i].fonts;return s.ui===e&&s.body===t&&s.heading===n&&s.code===r}),a=o?eM[o]:null;return(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground font-medium",children:"Quick presets"}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button",className:"w-full flex items-center justify-between gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors",children:[(0,s.jsx)("span",{children:a?a.label:"Custom"}),(0,s.jsx)(b,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{className:"w-64",children:eA.map(e=>{let t=eM[e];return(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>i(e),className:"flex-col items-start gap-0.5 py-2",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[o===e?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"font-medium",children:t.label})]}),(0,s.jsx)("span",{className:"pl-[1.375rem] text-xs text-muted-foreground leading-snug",children:t.description})]},e)})})]})]})}function eK({role:e}){let t=e$(),n="ui"===e?t.uiScale:"body"===e?t.bodyScale:"heading"===e?t.headingScale:t.codeScale,r=e$(e=>e.setScale);return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button","aria-label":"Font size",className:"flex items-center gap-1 rounded-md border border-border px-2 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors shrink-0",children:[(0,s.jsxs)("span",{className:"tabular-nums",children:[Math.round(100*n),"%"]}),(0,s.jsx)(b,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{align:"end",className:"w-24",children:eT.map(t=>(0,s.jsx)(ek.DropdownMenuItem,{onClick:()=>r(e,t),className:n===t?"font-medium":"",children:(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[n===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"tabular-nums",children:[Math.round(100*t),"%"]})]})},t))})]})}function eG({role:e,ids:t}){let n=e$(),r="ui"===e?n.ui:"body"===e?n.body:"heading"===e?n.heading:n.code,i=e$(e=>e.setFont),o="ui"===e?"UI font":"body"===e?"Body font":"heading"===e?"Heading font":"Code font";return(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs text-muted-foreground font-medium",children:o}),(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)("button",{type:"button",className:"flex-1 min-w-0 flex items-center justify-between gap-2 rounded-md border border-border px-3 py-2 text-sm text-foreground hover:bg-accent/50 transition-colors",children:[(0,s.jsx)("span",{className:"truncate",children:eS[r]?.label??"Select font"}),(0,s.jsx)(b,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})}),(0,s.jsx)(ek.DropdownMenuContent,{className:"w-56",children:t.map(t=>{let n=eS[t];return(0,s.jsx)(ek.DropdownMenuItem,{onClick:()=>i(e,t),className:r===t?"font-medium":"",children:(0,s.jsxs)("span",{className:"flex items-center gap-2 w-full",children:[r===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{style:{fontFamily:n.cssValue},children:n.label})]})},t)})})]}),(0,s.jsx)(eK,{role:e})]})]})}function eJ({open:e,onOpenChange:t}){let[n,r]=(0,f.useState)(!1),[i,o]=(0,f.useState)(!1),[a,l]=(0,f.useState)(null),[c,d]=(0,f.useState)("env"),[p,b]=(0,f.useState)(""),[w,k]=(0,f.useState)(""),[N,S]=(0,f.useState)(null),{data:C}=ew.authClient.useSession(),[j,E]=(0,f.useState)(!1),[M,A]=(0,f.useState)([]),[T,O]=(0,f.useState)([]),[_,D]=(0,f.useState)(null),[R,I]=(0,f.useState)(null),[L,P]=(0,f.useState)(""),[z,$]=(0,f.useState)(""),[F,H]=(0,f.useState)(!1),[U,V]=(0,f.useState)(null),[W,q]=(0,f.useState)(null),[K,G]=(0,f.useState)(!1),[J,Z]=(0,f.useState)(!1),X=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/system/admins"));if(!e.ok)return;let t=await e.json();E(!!t.isAdmin),A(t.admins??[]),O(t.users??[])}catch{}},[]),Y=(0,f.useCallback)(async()=>{r(!0),l(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/auth-settings"));if(!e.ok)throw Error("Failed to load settings");let t=await e.json();b(t.allowedEmails.join("\n")),k(t.allowedDomains.join("\n")),d(t.source),S("number"==typeof t.rateLimit?t.rateLimit:null)}catch(e){l(e instanceof Error?e.message:"Failed to load")}finally{r(!1)}},[]),Q=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/system/api-key"));if(!e.ok)return;let t=await e.json();q(t.key??null)}catch{}},[]);async function ee(){o(!0),l(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/auth-settings"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({allowedEmails:eV(p),allowedDomains:eV(w)})}),n=await e.json();if(!e.ok){l(n.error??"Save failed"),ey(n.error??"Save failed");return}n.source&&d(n.source),t(!1)}catch{l("Save failed")}finally{o(!1)}}(0,f.useEffect)(()=>{e&&(Y(),X(),Q())},[e,Y,X,Q]);let et=0===eV(p).length&&0===eV(w).length;return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eg,{side:"right",className:"w-[90vw] max-w-sm md:w-80 sm:max-w-md flex flex-col border-l border-border p-0",overlayClassName:"backdrop-blur-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",children:"Settings"}),(0,s.jsxs)(eo,{className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring",children:[(0,s.jsx)(h,{className:"h-3.5 w-3.5"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]}),n?(0,s.jsx)("div",{className:"flex flex-1 items-center justify-center",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,s.jsxs)("div",{className:"flex-1 space-y-5 overflow-y-auto px-4 py-4",children:[C?.user&&(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Account"}),(0,s.jsxs)("div",{className:"flex items-center justify-between rounded-md border border-border bg-muted/40 p-3",children:[(0,s.jsxs)("div",{className:"text-sm min-w-0",children:[(0,s.jsx)("div",{className:"font-medium truncate",children:C.user.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:C.user.email})]}),(0,s.jsx)("button",{type:"button",onClick:async()=>{await ew.authClient.signOut(),window.location.href=(0,ev.apiUrl)("/signin")},className:"ml-2 shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent",children:"Sign out"})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Typography"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Choose fonts for interface chrome, body text, and headings. Mix and match freely, or use a preset."}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)(eq,{}),(0,s.jsx)(eG,{role:"ui",ids:eC}),(0,s.jsx)(eG,{role:"body",ids:eE}),(0,s.jsx)(eG,{role:"heading",ids:eE}),(0,s.jsx)(eG,{role:"code",ids:ej})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Lab"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Experimental reading features. Toggle each on or off. Saved on this device."}),(0,s.jsx)(eW,{})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Signup allowlist"}),(0,s.jsxs)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:["Control who can create an account. Leave both lists empty to allow any email. Saving here overrides the"," ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AUTH_ALLOWED_EMAILS"})," ","and"," ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AUTH_ALLOWED_DOMAIN"})," ","environment variables."]}),"env"===c&&(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md bg-muted px-3 py-2 text-xs text-muted-foreground",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),(0,s.jsx)("span",{children:"Current values come from environment variables. Saving moves the allowlist into config and takes precedence going forward."})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{htmlFor:"allowed-emails",className:"text-sm font-medium",children:"Allowed emails"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"One per line (or comma-separated). Exact match, case-insensitive."}),(0,s.jsx)("textarea",{id:"allowed-emails",value:p,onChange:e=>b(e.target.value),spellCheck:!1,rows:5,placeholder:"alice@example.com bob@example.com",className:"w-full resize-y rounded-md border border-border bg-background px-3 py-2 font-mono text-sm outline-none focus:ring-2 focus:ring-primary"})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)("label",{htmlFor:"allowed-domains",className:"text-sm font-medium",children:"Allowed domains"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"One per line (or comma-separated). Matches any email at that domain."}),(0,s.jsx)("textarea",{id:"allowed-domains",value:w,onChange:e=>k(e.target.value),spellCheck:!1,rows:4,placeholder:"example.com trusted.org",className:"w-full resize-y rounded-md border border-border bg-background px-3 py-2 font-mono text-sm outline-none focus:ring-2 focus:ring-primary"})]}),et&&(0,s.jsxs)("div",{className:"flex items-start gap-2 rounded-md bg-warning-soft px-3 py-2 text-xs text-warning-ink",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),(0,s.jsx)("span",{children:"Both lists are empty. Anyone with the signup URL can create an account."})]}),a&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),a]})]}),j&&(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Admins"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Admins can create workspaces, add users, and manage access."}),_&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-destructive",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),_]}),(0,s.jsxs)("div",{className:"space-y-2 rounded-md border border-border p-3",children:[(0,s.jsx)("div",{className:"text-xs font-medium",children:"Add user"}),U?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Created ",(0,s.jsx)("span",{className:"font-medium text-foreground",children:U.email}),". Share this temporary password now, it will not be shown again."]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 rounded bg-muted px-2 py-1.5 font-mono text-sm select-all",children:U.tempPassword}),(0,s.jsx)("button",{type:"button",className:"shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent",onClick:()=>void navigator.clipboard?.writeText(U.tempPassword),children:"Copy"})]}),(0,s.jsx)("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>{V(null),P(""),$(""),X()},children:"Done"})]}):(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("input",{type:"email",value:L,onChange:e=>P(e.target.value),placeholder:"email@team.com",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm outline-none focus:ring-2 focus:ring-primary"}),(0,s.jsx)("input",{type:"text",value:z,onChange:e=>$(e.target.value),placeholder:"Name (optional)",className:"w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm outline-none focus:ring-2 focus:ring-primary"}),(0,s.jsxs)(v.Button,{size:"sm",className:"w-full gap-1.5",disabled:F||!L.trim(),onClick:async()=>{H(!0),D(null);try{let e=await fetch((0,ev.apiUrl)("/api/system/users"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:L.trim(),name:z.trim()})}),t=await e.json();e.ok&&t.tempPassword?V({email:t.email??L.trim(),tempPassword:t.tempPassword}):D(t.message??t.error??"Failed to create user")}catch{D("Network error")}finally{H(!1)}},children:[F&&(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),"Create user"]})]})]}),(0,s.jsxs)("div",{className:"space-y-1 rounded-md border border-border overflow-hidden",children:[T.map(e=>{let t=M.includes(e.id);return(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/40 hover:bg-muted/60 transition-colors",children:[(0,s.jsxs)("div",{className:"text-sm min-w-0",children:[(0,s.jsx)("div",{className:"font-medium truncate",children:e.name}),(0,s.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:e.email})]}),(0,s.jsx)("button",{type:"button",disabled:R===e.id,className:"ml-2 shrink-0 text-xs px-2 py-1 rounded border border-border hover:bg-accent disabled:opacity-50",onClick:async()=>{I(e.id),D(null);try{let n=await fetch((0,ev.apiUrl)("/api/system/admins"),{method:t?"DELETE":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:e.id})}),r=await n.json();n.ok?r.admins&&A(r.admins):D(r.message??r.error??"Failed")}catch{D("Network error")}finally{I(null)}},children:R===e.id?(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}):t?"Demote":"Promote"})]},e.id)}),0===T.length&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No users yet."})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"API Access"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Copy this key into external tools (e.g. termyard Settings → Integrations → Wiki-viewer API Key). The key never leaves this machine automatically."}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("code",{className:"flex-1 truncate rounded bg-muted px-2 py-1 font-mono text-xs select-all",children:W??"—"}),(0,s.jsx)("button",{type:"button",title:"Copy API key",className:"shrink-0 rounded border border-border px-2 py-1 text-xs hover:bg-accent disabled:opacity-50 flex items-center gap-1",disabled:!W,onClick:()=>{W&&navigator.clipboard?.writeText(W).then(()=>{G(!0),setTimeout(()=>G(!1),2e3)})},children:K?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3 w-3"})," Copied"]}):"Copy"}),(0,s.jsx)("button",{type:"button",title:"Rotate API key — external tools will need the new key",className:"shrink-0 rounded border border-border px-2 py-1 text-xs hover:bg-accent disabled:opacity-50 flex items-center gap-1",disabled:J,onClick:async()=>{if(confirm("Rotate the API key? Any tool using the current key will need to be updated.")){Z(!0);try{let e=await fetch((0,ev.apiUrl)("/api/system/api-key"),{method:"POST"}),t=await e.json();t.key&&q(t.key)}catch{}finally{Z(!1)}}},children:J?(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(y,{className:"h-3 w-3"})," Rotate"]})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/60",children:["Stored at ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"~/.wiki-viewer/api-key"}),". Rotating immediately invalidates the old key."]})]})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Agent rate limit"}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"text-muted-foreground",children:"Per agent"}),(0,s.jsx)("span",{className:"font-mono",children:null!==N?`${N} ops/min`:"--"})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/60",children:["Override with ",(0,s.jsx)("code",{className:"bg-muted px-0.5 rounded",children:"AGENT_RATE_LIMIT"})," env var."]})]})]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-border px-4 py-3 shrink-0",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>t(!1),disabled:i,children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",onClick:ee,disabled:i||n,className:"gap-1.5",children:[i&&(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}),"Save"]})]})]})})}let eZ=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(K,{ref:n,className:(0,eh.cn)("fixed inset-0 z-40 bg-overlay backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));eZ.displayName=K.displayName;let eX=f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(W,{children:[(0,s.jsx)(eZ,{}),(0,s.jsxs)(X,{ref:r,className:(0,eh.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-card p-6 shadow-golden rounded-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",e),...n,children:[t,(0,s.jsxs)(eo,{className:"absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,s.jsx)(h,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"sr-only",children:"Close"})]})]})]}));function eY({className:e,...t}){return(0,s.jsx)("div",{className:(0,eh.cn)("flex flex-col space-y-1.5 text-center sm:text-left min-w-0",e),...t})}function eQ({className:e,...t}){return(0,s.jsx)("div",{className:(0,eh.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t})}eX.displayName=X.displayName,eY.displayName="DialogHeader",eQ.displayName="DialogFooter";let e0=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(en,{ref:n,className:(0,eh.cn)("text-lg font-normal leading-none tracking-tight",e),...t}));e0.displayName=en.displayName;let e1=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ei,{ref:n,className:(0,eh.cn)("text-sm text-muted-foreground break-words",e),...t}));function e2({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i="Delete",onConfirm:o,variant:a="destructive"}){return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eX,{className:"sm:max-w-sm",children:[(0,s.jsxs)(eY,{children:[(0,s.jsx)(e0,{children:n}),(0,s.jsx)(e1,{children:r})]}),(0,s.jsxs)(eQ,{className:"gap-2 sm:gap-0",children:[(0,s.jsx)(v.Button,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),(0,s.jsx)(v.Button,{variant:a,onClick:()=>{o(),t(!1)},children:i})]})]})})}e1.displayName=ei.displayName;var e3=e.i(10137);let e5=(0,o.default)("folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),e4=(0,o.default)("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]),e6=(0,o.default)("git-branch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]),e9=(0,o.default)("hard-drive",[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]]),e7=(0,o.default)("server",[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]]),e8=(0,o.default)("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]),te=(0,o.default)("star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]),tt=(0,o.default)("star-off",[["path",{d:"M8.34 8.34 2 9.27l5 4.87L5.82 21 12 17.77 18.18 21l-.59-3.43",key:"16m0ql"}],["path",{d:"M18.42 12.76 22 9.27l-6.91-1L12 2l-1.44 2.91",key:"1vt8nq"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);function tn({onSelect:e}){let[t,n]=(0,f.useState)("local"),[r,i]=(0,f.useState)(null),[o,a]=(0,f.useState)(!0),[l,c]=(0,f.useState)(null),[d,p]=(0,f.useState)(""),[m,g]=(0,f.useState)(!1),[b,y]=(0,f.useState)([]),[w,k]=(0,f.useState)(!1),N=(0,f.useRef)(null),S=(0,f.useRef)(null),[C,j]=(0,f.useState)(""),[E,M]=(0,f.useState)(""),[A,T]=(0,f.useState)(""),[O,_]=(0,f.useState)(""),[D,R]=(0,f.useState)(""),[I,L]=(0,f.useState)(""),[P,z]=(0,f.useState)(!1),[$,B]=(0,f.useState)(null),[F,H]=(0,f.useState)(""),[U,V]=(0,f.useState)(""),[W,q]=(0,f.useState)("agent"),[K,G]=(0,f.useState)(""),[J,Z]=(0,f.useState)(""),[X,Y]=(0,f.useState)(!1),[Q,ee]=(0,f.useState)(""),[et,en]=(0,f.useState)(!1),[er,ei]=(0,f.useState)(null),es=async()=>{let t=F.trim();if(!t)return void ei("SSH target is required (user@host:/path).");if("keyfile"===W&&!K.trim())return void ei("Private key path is required for key-file auth.");if("password"===W&&!J)return void ei("Password is required for password auth.");en(!0),ei(null);try{let n={sshTarget:t,sshAuthMethod:W};U.trim()&&(n.sshPort=Number(U.trim())),"keyfile"===W&&K.trim()&&(n.sshKeyPath=K.trim()),"password"===W&&J&&(n.sshPassword=J),X&&(n.sshReadOnly=!0),Q.trim()&&(n.name=Q.trim());let r=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){let e=await r.json();ei(e.error??e.message??"Mount failed.");return}let{workspace:i}=await r.json();Z(""),e(i.id)}catch{ei("Network error.")}finally{en(!1)}},eo=async()=>{let t=C.trim();if(!t)return void B("Repository URL is required.");z(!0),B(null);try{let n={remoteUrl:t};E.trim()&&(n.branch=E.trim()),A.trim()&&(n.subpath=A.trim()),O.trim()&&(n.username=O.trim()),D.trim()&&(n.token=D.trim()),I.trim()&&(n.name=I.trim());let r=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!r.ok){let e=await r.json();B(e.error??e.message??"Clone failed.");return}let{workspace:i}=await r.json();R(""),e(i.id)}catch{B("Network error.")}finally{z(!1)}},ea=(0,f.useCallback)(async(e,t=!0)=>{S.current&&(clearTimeout(S.current),S.current=null),a(!0),c(null);try{let n=await fetch((0,ev.apiUrl)(`/api/system/browse?path=${encodeURIComponent(e)}`));if(!n.ok){let e=await n.json();c(e.error??"Cannot open directory");return}let r=await n.json();i(r),t&&p(r.path)}catch{c("Network error")}finally{a(!1)}},[]);(0,f.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch((0,ev.apiUrl)("/api/system/config"));if(t.ok&&!e){let e=await t.json();y(e.pinnedPaths??[]),await ea(e.lastOpenedPath??"");return}}catch{}e||await ea("")})(),()=>{e=!0}},[]);let el=async t=>{let n=t??r?.path;if(n){g(!0);try{let t=await fetch((0,ev.apiUrl)("/api/system/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rootDir:n})});if(!t.ok){let e=await t.json();c(e.message??e.error??"Cannot use that directory");return}let{workspace:r}=await t.json();e(r.id)}catch{c("Network error")}finally{g(!1)}}},ec=!!r&&b.includes(r.path),ed=async()=>{if(r){k(!0);try{let e=ec?"unpin":"pin";(await fetch((0,ev.apiUrl)("/api/system/pins"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r.path,action:e})})).ok&&y(t=>"pin"===e?[...t,r.path]:t.filter(e=>e!==r.path))}catch{}finally{k(!1)}}},eu=async e=>{try{(await fetch((0,ev.apiUrl)("/api/system/pins"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,action:"unpin"})})).ok&&y(t=>t.filter(t=>t!==e))}catch{}},ep=(r?.path??"").split(/[/\\]/).filter(Boolean).reduce((e,t)=>{let n=e[e.length-1]?.path??"/";return e.push({label:t,path:`${"/"===n?"":n}/${t}`}),e},[{label:"/",path:"/"}]);return(0,s.jsx)("div",{className:"flex flex-1 items-center justify-center bg-background p-4",children:(0,s.jsxs)("div",{className:"flex w-full max-w-xl flex-col gap-4",children:[(0,s.jsxs)("div",{className:"text-center space-y-1",children:[(0,s.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-1",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-8 w-8"}),(0,s.jsx)("span",{className:"text-xl font-semibold tracking-tight",children:"Wiki Viewer"})]}),(0,s.jsx)("h1",{className:"text-xl font-medium",children:"git"===t?"Add a Git repository":"ssh"===t?"Add a remote directory over SSH":"Choose a directory"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"git"===t?(0,s.jsxs)(s.Fragment,{children:["Clone a remote repo and serve it as a read-only workspace.",(0,s.jsx)("br",{}),"The server clones it, so the URL must be reachable from the server."]}):"ssh"===t?(0,s.jsxs)(s.Fragment,{children:["Mount a remote directory over SSH (sshfs) — no local clone.",(0,s.jsx)("br",{}),"Requires sshfs + FUSE installed on the server."]}):(0,s.jsxs)(s.Fragment,{children:["Select the folder wiki-viewer should serve.",(0,s.jsx)("br",{}),"This directory lives on the server, so use the browser below."]})})]}),(0,s.jsxs)("div",{className:"flex items-center self-center rounded-lg border bg-muted p-0.5 gap-0.5",children:[(0,s.jsxs)(v.Button,{variant:"local"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>{n("local"),R(""),B(null)},children:[(0,s.jsx)(e5,{className:"h-3.5 w-3.5"}),"Local folder"]}),(0,s.jsxs)(v.Button,{variant:"git"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>n("git"),children:[(0,s.jsx)(e6,{className:"h-3.5 w-3.5"}),"From Git"]}),(0,s.jsxs)(v.Button,{variant:"ssh"===t?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs gap-1.5",onClick:()=>{n("ssh"),ei(null)},children:[(0,s.jsx)(e7,{className:"h-3.5 w-3.5"}),"Over SSH"]})]}),"git"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-4 pt-4 pb-3 flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Repository URL"}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"https://github.com/org/repo.git",value:C,onChange:e=>{j(e.target.value),B(null)},disabled:P,autoComplete:"off",spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Only https:// URLs are supported."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Branch ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"main (default branch if empty)",value:E,onChange:e=>{M(e.target.value),B(null)},disabled:P})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Subdirectory ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"docs (whole repo if empty)",value:A,onChange:e=>{T(e.target.value),B(null)},disabled:P,spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Serve only this folder from the repo. Faster to clone for large repos with docs in a subfolder."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Username ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"x-access-token (default)",value:O,onChange:e=>{_(e.target.value),B(null)},disabled:P,autoComplete:"off"})}),(0,s.jsxs)("p",{className:"text-[11px] text-muted-foreground",children:["GitLab uses ",(0,s.jsx)("code",{className:"font-mono",children:"oauth2"}),"; Bitbucket uses your account username."]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Access token ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{type:"password",className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Personal access token",value:D,onChange:e=>{R(e.target.value),B(null)},disabled:P,autoComplete:"off"})]}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Required only for private repos. Stored securely on the server and never shown again."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Display name ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Defaults to the repository name",value:I,onChange:e=>{L(e.target.value),B(null)},disabled:P})})]}),$&&(0,s.jsx)("p",{className:"text-sm text-destructive",children:$})]}),(0,s.jsxs)("div",{className:"border-t px-4 py-3 flex items-center justify-between gap-3 bg-muted",children:[(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Git workspaces are read-only, so editing is disabled."}),(0,s.jsx)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:P,onClick:eo,children:P?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"})," Cloning..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e6,{className:"h-3.5 w-3.5"})," Clone and add"]})})]})]}),"ssh"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-4 pt-4 pb-3 flex flex-col gap-3",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"SSH target"}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"user@host:/abs/path",value:F,onChange:e=>{H(e.target.value),ei(null)},disabled:et,autoComplete:"off",spellCheck:!1})}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"The remote path must be absolute."})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Port ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"22",inputMode:"numeric",value:U,onChange:e=>{V(e.target.value.replace(/[^0-9]/g,"")),ei(null)},disabled:et})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Authentication"}),(0,s.jsx)("div",{className:"flex items-center self-start rounded-lg border bg-muted p-0.5 gap-0.5",children:["agent","keyfile","password"].map(e=>(0,s.jsx)(v.Button,{variant:W===e?"default":"ghost",size:"sm",className:"h-7 px-3 text-xs",onClick:()=>{q(e),ei(null)},disabled:et,children:"agent"===e?"SSH agent":"keyfile"===e?"Key file":"Password"},e))}),(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"agent"===W?"Uses the server's ssh-agent and default keys (~/.ssh/id_*).":"keyfile"===W?"Uses a specific private key on the server.":"Stored securely on the server and never shown again."})]}),"keyfile"===W&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Private key path"}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",placeholder:"~/.ssh/id_ed25519",value:K,onChange:e=>{G(e.target.value),ei(null)},disabled:et,autoComplete:"off",spellCheck:!1})]})]}),"password"===W&&(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("label",{className:"text-xs font-medium",children:"Password"}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:[(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,s.jsx)("input",{type:"password",className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"SSH password",value:J,onChange:e=>{Z(e.target.value),ei(null)},disabled:et,autoComplete:"off"})]})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsxs)("label",{className:"text-xs font-medium",children:["Display name ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground",children:"(optional)"})]}),(0,s.jsx)("div",{className:"flex items-center gap-2 rounded-md border bg-muted px-3 py-2",children:(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none min-w-0",placeholder:"Defaults to host:path",value:Q,onChange:e=>{ee(e.target.value),ei(null)},disabled:et})})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 text-xs font-medium cursor-pointer select-none",children:[(0,s.jsx)("input",{type:"checkbox",checked:X,onChange:e=>Y(e.target.checked),disabled:et}),"Mount read-only"]}),er&&(0,s.jsx)("p",{className:"text-sm text-destructive",children:er})]}),(0,s.jsxs)("div",{className:"border-t px-4 py-3 flex items-center justify-between gap-3 bg-muted",children:[(0,s.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Served live over SSH — nothing is copied to disk."}),(0,s.jsx)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:et,onClick:es,children:et?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"})," Mounting..."]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7,{className:"h-3.5 w-3.5"})," Mount and add"]})})]})]}),"local"===t&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsx)("div",{className:"flex items-center gap-2 border-b px-3 py-2 bg-muted",children:(0,s.jsx)("input",{ref:N,className:"flex-1 bg-transparent text-sm outline-none font-mono min-w-0",value:d,onChange:e=>{let t=e.target.value;p(t),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{S.current=null,ea(t.trim(),!1)},500)},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),S.current&&(clearTimeout(S.current),S.current=null),ea(d.trim())),"Escape"===e.key&&(S.current&&(clearTimeout(S.current),S.current=null),p(r?.path??""),N.current?.blur())},spellCheck:!1,placeholder:"Enter a path…"})}),(0,s.jsx)("div",{className:"flex items-center gap-1 border-b px-3 py-1.5 bg-muted/50 overflow-x-auto shrink-0 min-h-[32px]",children:ep.map((e,t)=>(0,s.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[t>0&&(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3 text-muted-foreground/50"}),(0,s.jsx)("button",{type:"button",className:"text-xs hover:text-foreground text-muted-foreground transition-colors rounded px-0.5",onClick:()=>ea(e.path),children:0===t?(0,s.jsx)(e9,{className:"h-3.5 w-3.5"}):e.label})]},e.path))}),(0,s.jsx)("div",{className:"max-h-60 overflow-y-auto",children:o?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):l?(0,s.jsx)("div",{className:"px-4 py-3 text-sm text-destructive",children:l}):(0,s.jsxs)(s.Fragment,{children:[r?.parent&&(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground transition-colors",onClick:()=>ea(r.parent),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0"}),(0,s.jsx)("span",{className:"text-xs",children:".."})]}),r?.entries.length===0&&(0,s.jsx)("p",{className:"px-4 py-3 text-sm text-muted-foreground/60",children:"No subdirectories"}),r?.entries.map(e=>(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground transition-colors",onClick:()=>ea(e.path),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("span",{className:"truncate",children:e.name})]},e.path))]})}),(0,s.jsxs)("div",{className:"border-t px-3 py-2 flex items-center justify-between gap-2 bg-muted",children:[(0,s.jsxs)("button",{type:"button",className:(0,eh.cn)("flex items-center gap-1.5 text-xs transition-colors rounded px-1.5 py-1",ec?"text-foreground hover:text-destructive":"text-muted-foreground hover:text-foreground"),title:ec?"Remove from favorites":"Add to favorites for quick access",onClick:ed,disabled:w||!r,children:[w?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):ec?(0,s.jsx)(tt,{className:"h-3.5 w-3.5"}):(0,s.jsx)(te,{className:"h-3.5 w-3.5"}),ec?"Unfavorite":"Favorite"]}),(0,s.jsxs)(v.Button,{size:"sm",className:"shrink-0 gap-1.5",disabled:!r||m,onClick:()=>el(),children:[m?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(e4,{className:"h-3.5 w-3.5"}),"Select"]})]})]}),"local"===t&&b.length>0&&(0,s.jsxs)("div",{className:"rounded-lg border bg-card shadow-sm overflow-hidden",children:[(0,s.jsx)("div",{className:"px-3 py-2 border-b bg-muted",children:(0,s.jsxs)("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1.5",children:[(0,s.jsx)(te,{className:"h-3 w-3"})," Pinned"]})}),(0,s.jsx)("div",{className:"max-h-40 overflow-y-auto",children:b.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 hover:bg-accent group",children:[(0,s.jsxs)("button",{type:"button",className:"flex-1 flex items-center gap-2 text-sm text-left min-w-0",onClick:()=>ea(e),children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("span",{className:"truncate text-xs",children:e})]}),(0,s.jsx)("button",{type:"button",className:"shrink-0 text-muted-foreground/50 hover:text-destructive opacity-0 group-hover:opacity-100 transition-all",onClick:()=>eu(e),title:"Remove from favorites",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]},e))})]}),"local"===t&&r?.shortcuts&&r.shortcuts.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap gap-1.5 justify-center",children:r.shortcuts.map(e=>(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>ea(e.path),children:["Home"===e.label?(0,s.jsx)(e8,{className:"h-3 w-3"}):(0,s.jsx)(e9,{className:"h-3 w-3"}),e.label]},e.path))})]})})}var tr=e.i(391548),ti=e.i(567776);let ts=(0,o.default)("trash-2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]),to=(0,o.default)("clock",[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]);var ta=e.i(793479),tl=e.i(461614),tc="Switch",[td,tu]=(0,N.createContextScope)(tc),[tp,th]=td(tc),tf=f.forwardRef((e,t)=>{let{__scopeSwitch:n,name:r,checked:i,defaultChecked:o,required:a,disabled:l,value:c="on",onCheckedChange:d,form:u,...p}=e,[h,m]=f.useState(null),g=(0,k.useComposedRefs)(t,e=>m(e)),b=f.useRef(!1),x=!h||u||!!h.closest("form"),[y,v]=(0,C.useControllableState)({prop:i,defaultProp:o??!1,onChange:d,caller:tc});return(0,s.jsxs)(tp,{scope:n,checked:y,disabled:l,children:[(0,s.jsx)(T.Primitive.button,{type:"button",role:"switch","aria-checked":y,"aria-required":a,"data-state":tx(y),"data-disabled":l?"":void 0,disabled:l,value:c,...p,ref:g,onClick:(0,w.composeEventHandlers)(e.onClick,e=>{v(e=>!e),x&&(b.current=e.isPropagationStopped(),b.current||e.stopPropagation())})}),x&&(0,s.jsx)(tb,{control:h,bubbles:!b.current,name:r,value:c,checked:y,required:a,disabled:l,form:u,style:{transform:"translateX(-100%)"}})]})});tf.displayName=tc;var tm="SwitchThumb",tg=f.forwardRef((e,t)=>{let{__scopeSwitch:n,...r}=e,i=th(tm,n);return(0,s.jsx)(T.Primitive.span,{"data-state":tx(i.checked),"data-disabled":i.disabled?"":void 0,...r,ref:t})});tg.displayName=tm;var tb=f.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...i},o)=>{let a,l=f.useRef(null),c=(0,k.useComposedRefs)(l,o),d=(a=f.useRef({value:n,previous:n}),f.useMemo(()=>(a.current.value!==n&&(a.current.previous=a.current.value,a.current.value=n),a.current.previous),[n])),u=(0,tl.useSize)(t);return f.useEffect(()=>{let e=l.current;if(!e)return;let t=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"checked").set;if(d!==n&&t){let i=new Event("click",{bubbles:r});t.call(e,n),e.dispatchEvent(i)}},[d,n,r]),(0,s.jsx)("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...i,tabIndex:-1,ref:c,style:{...i.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});function tx(e){return e?"checked":"unchecked"}function ty({className:e,...t}){return(0,s.jsx)(tf,{"data-slot":"switch",className:(0,eh.cn)("peer data-[state=checked]:bg-[var(--switch-checked)] data-[state=unchecked]:bg-input inline-flex h-5 w-9 shrink-0 items-center rounded-sm border-2 border-transparent shadow-e-1 transition-all outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:(0,s.jsx)(tg,{"data-slot":"switch-thumb",className:"bg-background pointer-events-none block size-4 rounded-sm shadow-e-1 ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0"})})}tb.displayName="SwitchBubbleInput";var tv=e.i(380560),tw=e.i(206102),tk=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"].reduce((e,t)=>{let n=(0,tw.createSlot)(`Primitive.${t}`),r=f.forwardRef((e,r)=>{let{asChild:i,...o}=e;return"u">typeof window&&(window[Symbol.for("radix-ui")]=!0),(0,s.jsx)(i?n:t,{...o,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),tN=f.forwardRef((e,t)=>(0,s.jsx)(tk.label,{...e,ref:t,onMouseDown:t=>{t.target.closest("button, input, select, textarea")||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));tN.displayName="Label";var tS=e.i(294237);let tC=(0,tS.cva)("text-sm font-normal leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50"),tj=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(tN,{ref:n,className:(0,eh.cn)(tC(),e),...t}));tj.displayName=tN.displayName;var tE=e.i(671485);function tM({open:e,onOpenChange:t,filePath:n}){let[r,i]=(0,f.useState)([]),[o,a]=(0,f.useState)(!0),[l,d]=(0,f.useState)(!1),[p,h]=(0,f.useState)(""),[m,b]=(0,f.useState)(!1),[x,y]=(0,f.useState)(!1),[w,k]=(0,f.useState)("7"),[N,S]=(0,f.useState)(null),C=(0,f.useCallback)(async()=>{a(!0);try{let e=await (0,tE.wsFetch)(`/api/share?path=${encodeURIComponent(n)}`);if(e.ok){let t=await e.json();i(t.shares??[])}}catch{}a(!1)},[n]);(0,f.useEffect)(()=>{e&&C()},[e,C]);let j=async()=>{d(!0);try{let e={path:n};if(m&&p.trim()&&(e.password=p.trim()),x&&w){let t=new Date;t.setDate(t.getDate()+Number(w)),e.expiresAt=t.toISOString()}let t=await (0,tE.wsFetch)("/api/share",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let e=await t.json();ey(e.error??"Failed to create share link");return}ex("Share link created"),h(""),b(!1),y(!1),k("7"),await C()}catch{ey("Failed to create share link")}finally{d(!1)}},E=async e=>{try{if(!(await fetch((0,ev.apiUrl)(`/api/share/${e}`),{method:"DELETE"})).ok)return void ey("Failed to revoke share link");ex("Share link revoked"),await C()}catch{ey("Failed to revoke share link")}};return(0,s.jsx)(B,{open:e,onOpenChange:t,children:(0,s.jsxs)(eX,{className:"sm:max-w-md",children:[(0,s.jsxs)(eY,{children:[(0,s.jsx)(e0,{children:"Share document"}),(0,s.jsx)(e1,{children:"Create a public link to share this document as read-only."})]}),(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsxs)("div",{className:"rounded-sm border border-border p-3 space-y-3",children:[(0,s.jsx)("h3",{className:"text-sm font-medium",children:"New share link"}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)(tj,{htmlFor:"share-pwd",className:"text-xs gap-1.5 flex items-center",children:[(0,s.jsx)(ti.Lock,{className:"h-3 w-3 text-muted-foreground"}),"Password protect"]}),(0,s.jsx)(ty,{id:"share-pwd",checked:m,onCheckedChange:b})]}),m&&(0,s.jsx)(ta.Input,{type:"password",placeholder:"Set a password",value:p,onChange:e=>h(e.target.value)}),(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)(tj,{htmlFor:"share-expiry",className:"text-xs gap-1.5 flex items-center",children:[(0,s.jsx)(to,{className:"h-3 w-3 text-muted-foreground"}),"Set expiration"]}),(0,s.jsx)(ty,{id:"share-expiry",checked:x,onCheckedChange:y})]}),x&&(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ta.Input,{type:"number",min:1,max:365,value:w,onChange:e=>k(e.target.value),className:"w-20"}),(0,s.jsx)("span",{className:"text-xs text-muted-foreground",children:"days"})]}),(0,s.jsxs)(v.Button,{size:"sm",className:"w-full gap-1.5",onClick:j,disabled:l,children:[l?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(c,{className:"h-3.5 w-3.5"}),"Create link"]})]}),(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:r.length>0?`Active links (${r.length})`:o?"Loading...":"No active links"}),o&&(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}),r.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded-sm border border-border p-2",children:[(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:(0,s.jsxs)("span",{className:"text-xs truncate",children:[window.location.origin,"/s/",e.token]})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[e.hasPassword&&(0,s.jsxs)("span",{className:"flex items-center gap-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsx)(ti.Lock,{className:"h-2.5 w-2.5"}),"pwd"]}),e.expiresAt&&(0,s.jsxs)("span",{className:"flex items-center gap-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsx)(to,{className:"h-2.5 w-2.5"}),function(e){let t=new Date(e),n=new Date,r=t.getTime()-n.getTime();if(r<=0)return"expired";let i=Math.floor(r/864e5),s=Math.floor(r%864e5/36e5);return i>0?`${i}d`:s>0?`${s}h`:"<1h"}(e.expiresAt)]}),(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[e.viewCount," view",1!==e.viewCount?"s":""]}),e.isExpired&&(0,s.jsx)("span",{className:"text-[10px] text-destructive",children:"expired"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Copy link",onClick:()=>{var t,n;let r;return t=e.url,n=e.token,r=`${window.location.origin}${t}`,void(navigator.clipboard.writeText(r),S(n),setTimeout(()=>S(null),2e3))},children:N===e.token?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-success"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",title:"Revoke link",onClick:()=>E(e.token),children:(0,s.jsx)(ts,{className:"h-3.5 w-3.5"})})]})]},e.id))]})]})]})})}let tA=(0,o.default)("wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]);var tT=e.i(412473);let tO=(0,eN.create)(e=>({isOpen:!1,open:()=>e({isOpen:!0}),close:()=>e({isOpen:!1}),toggle:()=>e(e=>({isOpen:!e.isOpen})),clearMessages:()=>{},activity:[],connections:[],hasToken:!1,pollIntervalMs:1e4,rateLimit:null,loadActivity:async()=>{if((0,ev.isLite)())return;let t=localStorage.getItem("wiki-agent-token")??null,n=!!(t&&t.trim());try{let t=await (0,tE.wsFetch)("/api/agent/activity?limit=50",{headers:{}});if(!t.ok)return void e({hasToken:n});let r=(await t.json()).events??[],i=function(e){let t=new Date(Date.now()-3e5).toISOString(),n=new Map;for(let r of e){if(r.at<t)continue;let e=n.get(r.by);e?n.set(r.by,{opCount:e.opCount+1,lastSeen:r.at>e.lastSeen?r.at:e.lastSeen}):n.set(r.by,{opCount:1,lastSeen:r.at})}return Array.from(n.entries()).map(([e,t])=>({by:e,...t})).sort((e,t)=>e.lastSeen<t.lastSeen?1:-1)}(r),s=null;try{let e=await (0,tE.wsFetch)("/api/agent/settings",{headers:{}});e.ok&&(s=(await e.json()).rateLimit??null)}catch{}e({activity:r,connections:i,hasToken:n,rateLimit:s})}catch{e({hasToken:n})}}})),t_=(0,o.default)("circle-check-big",[["path",{d:"M21.801 10A10 10 0 1 1 17 3.335",key:"yps3ct"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]),tD=(0,o.default)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),tR=(0,o.default)("refresh-cw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);function tI(e){let t=Date.now()-new Date(e).getTime();return t<6e4?"just now":t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}function tL({scope:e}){return(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 font-mono",children:[e.paths.join(", ")," · ",e.ops.join(",")]})}function tP({reg:e,onApprove:t,onDeny:n}){let[r,i]=(0,f.useState)(!1);async function o(t){i(!0);try{await t(e.registrationId)}finally{i(!1)}}return(0,s.jsxs)("li",{className:"py-1.5 border-b border-border/40 last:border-0",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-1",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"text-xs font-mono truncate",children:e.displayName}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 truncate",children:e.agentId}),(0,s.jsx)(tL,{scope:e.requestedScope})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsxs)(v.Button,{size:"sm",variant:"default",className:"h-6 px-2 text-[10px]",disabled:r,onClick:()=>void o(t),title:"Approve",children:[(0,s.jsx)(t_,{className:"h-3 w-3 mr-0.5"}),"Approve"]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[10px] text-destructive hover:text-destructive",disabled:r,onClick:()=>void o(n),title:"Deny",children:[(0,s.jsx)(tD,{className:"h-3 w-3 mr-0.5"}),"Deny"]})]})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 mt-0.5",children:["Requested ",tI(e.requestedAt)]})]})}function tz({agent:e,onRevoke:t}){let[n,r]=(0,f.useState)(!1);return(0,s.jsxs)("li",{className:"py-1.5 border-b border-border/40 last:border-0",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-1",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("p",{className:"text-xs font-mono truncate",children:e.displayName}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 truncate",children:e.id}),(0,s.jsx)(tL,{scope:e.scope})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0 text-destructive hover:text-destructive",disabled:n,onClick:async()=>{r(!0);try{await t(e.id)}finally{r(!1)}},title:"Revoke agent",children:(0,s.jsx)(ts,{className:"h-3 w-3"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 mt-0.5",children:["Last seen ",tI(e.lastSeen)]})]})}function t$(){let[e,t]=(0,f.useState)([]),[n,r]=(0,f.useState)([]),[i,o]=(0,f.useState)(!1);(0,f.useEffect)(()=>{fetch((0,ev.apiUrl)("/api/owner/init"),{credentials:"same-origin"}).then(e=>{(e.ok||204===e.status)&&o(!0)}).catch(()=>{o(!0)})},[]);let a=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/agent/admin/registrations"),{credentials:"same-origin"});if(!e.ok)return;let n=await e.json();t(n.pending)}catch{}},[]),l=(0,f.useCallback)(async()=>{try{let e=await fetch((0,ev.apiUrl)("/api/agent/admin/agents"),{credentials:"same-origin"});if(!e.ok)return;let t=await e.json();r(t.agents)}catch{}},[]);(0,f.useEffect)(()=>{if(!i)return;a(),l();let e=setInterval(()=>void a(),5e3),t=setInterval(()=>void l(),3e4);return()=>{clearInterval(e),clearInterval(t)}},[i,a,l]);let c=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/registrations/${e}/approve`),{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:"{}"})).ok?(eb.toast.success("Agent approved"),await Promise.all([a(),l()])):eb.toast.error("Failed to approve agent")},[a,l]),d=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/registrations/${e}/deny`),{method:"POST",credentials:"same-origin"})).ok?(eb.toast.success("Registration denied"),await a()):eb.toast.error("Failed to deny registration")},[a]),u=(0,f.useCallback)(async e=>{(await fetch((0,ev.apiUrl)(`/api/agent/admin/agents/${encodeURIComponent(e)}/revoke`),{method:"POST",credentials:"same-origin"})).ok?(eb.toast.success("Agent revoked"),await l()):eb.toast.error("Failed to revoke agent")},[l]);return(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Agents · approve & manage access"}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-5 w-5 p-0",title:"Refresh",onClick:()=>void Promise.all([a(),l()]),children:(0,s.jsx)(tR,{className:"h-3 w-3"})})]}),e.length>0&&(0,s.jsxs)("div",{className:"rounded-md border border-amber-500/40 bg-amber-50/10 p-2",children:[(0,s.jsxs)("p",{className:"text-[10px] font-semibold uppercase tracking-widest text-amber-600/80 mb-1 flex items-center gap-1",children:[(0,s.jsx)(to,{className:"h-3 w-3"}),"Waiting for your approval (",e.length,")"]}),(0,s.jsx)("ul",{children:e.map(e=>(0,s.jsx)(tP,{reg:e,onApprove:c,onDeny:d},e.registrationId))})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-2",children:0===n.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 py-1",children:["No assistants connected yet."," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"Connect one above; once it requests access it’ll appear here for you to approve."})]}):(0,s.jsx)("ul",{children:n.map(e=>(0,s.jsx)(tz,{agent:e,onRevoke:u},e.id))})}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/60 leading-relaxed",children:"Each assistant gets its own access that you can revoke anytime. New requests appear above for your approval before they can read or edit anything."})]})}class tB extends Error{status;constructor(e,t){super(e),this.status=t,this.name="FetchPageError"}}async function tF(e,t){let n=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`,{signal:t});if(!n.ok)throw new tB(`Failed to fetch page: ${e}`,n.status);let r=await n.json(),i=n.headers.get("X-Wiki-Revision"),s=null!==i?Number(i):null;return{path:e,content:r.content,frontmatter:null,revision:s}}class tH extends Error{currentRevision;serverContent;constructor(e,t){super("File was modified externally. Reloaded with latest content."),this.currentRevision=e,this.serverContent=t,this.name="StaleRevisionError"}}async function tU(e,t,n){let r={path:e,content:t};null!==n&&(r.baseRevision=n);let i=await (0,tE.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(409===i.status){let n=await i.json(),r=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`),s=r.ok?(await r.json()).content:t;throw new tH(n.currentRevision??0,s)}if(!i.ok)throw Error("Failed to save page");return{revision:(await i.json()).revision??null}}async function tV(e,t=""){await tU(e,t,null)}let tW="kb-page-cache",tq=new Map,tK=new Map;function tG(e){if(tq.delete(e.path),tq.set(e.path,e),tq.size>30){let e=tq.keys().next().value;void 0!==e&&tq.delete(e)}}function tJ(e){if(tq.has(e)||tK.has(e))return;let t=tF(e).then(e=>(tG(e),e)).finally(()=>{tK.delete(e)});tK.set(e,t),t.catch(()=>{})}function tZ(e){try{localStorage.setItem(tW,JSON.stringify(e))}catch{}}let tX="kb-edit-mode",tY=null,tQ=null,t0=null,t1=(0,eN.create)((e,t)=>({currentPath:null,content:"",frontmatter:null,saveStatus:"idle",loadStatus:"idle",isDirty:!1,isLoading:!1,lastSavedAt:null,currentRevision:null,editMode:"suggesting"===localStorage.getItem(tX)?"suggesting":"editing",setEditMode:t=>{localStorage.setItem(tX,t),e({editMode:t})},loadPage:async n=>{let r,i=t();i.isDirty&&i.currentPath&&i.currentPath!==n&&await t().save(),e({currentPath:n,isLoading:!0,loadStatus:"loading",isDirty:!1,content:"",currentRevision:null});let s=(r=tq.get(n))?(tq.delete(n),tq.set(n,r),r):null,o=s??function(e){try{let t=localStorage.getItem(tW);if(!t)return null;let n=JSON.parse(t);if(n.path!==e)return null;return n}catch{return null}}(n);o&&e({content:o.content,frontmatter:o.frontmatter,isLoading:!1,loadStatus:"ok",...s?{currentRevision:s.revision}:{}});let a=tK.get(n);if(a)try{let r=await a;if(t().currentPath!==n)return;e({content:r.content,frontmatter:r.frontmatter,isLoading:!1,loadStatus:"ok",currentRevision:r.revision}),tZ({path:n,content:r.content,frontmatter:r.frontmatter});return}catch{}t0?.abort();let l=new AbortController;t0=l;try{let r=await tF(n,l.signal);if(tG(r),t().currentPath!==n)return;e({content:r.content,frontmatter:r.frontmatter,isLoading:!1,loadStatus:"ok",currentRevision:r.revision}),tZ({path:n,content:r.content,frontmatter:r.frontmatter})}catch(r){if(r instanceof DOMException&&"AbortError"===r.name||t().currentPath!==n)return;r instanceof tB&&404===r.status?e({isLoading:!1,loadStatus:"missing",content:""}):e({isLoading:!1,loadStatus:"error"})}},updateContent:n=>{"suggesting"===t().editMode?e({content:n}):(e({content:n,isDirty:!0}),tY&&clearTimeout(tY),tY=setTimeout(()=>{t().save()},500))},updateFrontmatter:n=>{e({frontmatter:{...t().frontmatter,...n},isDirty:!0}),tY&&clearTimeout(tY),tY=setTimeout(()=>{t().save()},500)},save:async()=>{let{currentPath:n,content:r,isDirty:i,currentRevision:s,editMode:o}=t();if(n&&i&&"suggesting"!==o){e({saveStatus:"saving"});try{let i=await tU(n,r,s);e({saveStatus:"saved",isDirty:!1,lastSavedAt:Date.now(),currentRevision:i.revision??s}),tZ({path:n,content:r,frontmatter:t().frontmatter}),tG({path:n,content:r,frontmatter:t().frontmatter,revision:i.revision??s}),tQ&&clearTimeout(tQ),tQ=setTimeout(()=>{"saved"===t().saveStatus&&e({saveStatus:"idle"})},2e3)}catch(r){r instanceof tH?(e({content:r.serverContent,isDirty:!1,saveStatus:"error",currentRevision:r.currentRevision}),tZ({path:n,content:r.serverContent,frontmatter:t().frontmatter})):e({saveStatus:"error"})}}},createMissingPage:async n=>{let{currentPath:r}=t();if(!r)return;let i=`# ${n}
6
6
 
7
7
  `;try{await tV(`${r}/index.md`,i),e({content:i,isDirty:!1,loadStatus:"ok"}),tZ({path:r,content:i,frontmatter:null})}catch{}},clear:()=>{tY&&clearTimeout(tY),tQ&&clearTimeout(tQ),e({currentPath:null,content:"",frontmatter:null,saveStatus:"idle",loadStatus:"idle",isDirty:!1,isLoading:!1,lastSavedAt:null,currentRevision:null})},syncRevision:t=>{e({currentRevision:t})}}));function t2(e){let t=Math.max(0,Math.round((Date.now()-new Date(e).getTime())/1e3));if(t<45)return"just now";let n=t,r="second";for(let[e,t]of[[60,"second"],[60,"minute"],[24,"hour"],[7,"day"]]){if(n<e)break;n=Math.floor(n/e),r=t}return new Intl.RelativeTimeFormat("en",{numeric:"always",style:"short"}).format(-n,r).replace(/\s+/g," ").replace(/\./g,"")}async function t3(e){if(!/\.(md|markdown)$/i.test(e))return 0;for(let t of[`/api/agent/sidecar/${e}`,`/api/agent/files/${e}/pending`,`/api/agent/files/${e}`])try{let e=await (0,tE.wsFetch)(t);if(!e.ok)continue;let n=await e.json();if(Array.isArray(n.pending))return n.pending.length;if(Array.isArray(n.events)&&t.includes("/pending"))return n.events.length;if("number"==typeof n.pendingCount)return n.pendingCount;if("number"==typeof n.count)return n.count;if("number"==typeof n.total)return n.total;if(Array.isArray(n.suggestions)||Array.isArray(n.comments)||n.blockProvenance){let e=Array.isArray(n.suggestions)?n.suggestions.filter(e=>e&&"object"==typeof e&&"pending"===e.status).length:0,t=Array.isArray(n.comments)?n.comments.filter(e=>e&&"object"==typeof e&&!e.resolved).length:0,r=n.blockProvenance&&"object"==typeof n.blockProvenance?Object.keys(n.blockProvenance).length:0;return e+t+r}}catch{}return 0}let t5=(0,f.memo)(function({event:e}){var t,n;let r,i,o,a,l;return(0,s.jsxs)("div",{className:"flex items-start gap-2.5 rounded-md px-2 py-2 hover:bg-background/50",children:[(0,s.jsx)("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-[10px] font-semibold shadow-sm ring-1 ring-black/5",style:(r=function(e){let t=0;for(let n=0;n<e.length;n+=1)t=31*t+e.charCodeAt(n)|0;return Math.abs(t)}(e.by)%360,{backgroundColor:`hsl(${r} 72% 42%)`,color:"white"}),title:e.by,"aria-hidden":!0,children:((i=(t=e.by).split(/[:/]/).pop()??t).replace(/[^a-z0-9]/gi,"").slice(0,2)||i.slice(0,2)||"??").toUpperCase()}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"truncate text-xs text-foreground/85",children:(o=((n=e.by).split(/[:/]/).pop()??n).replace(/[-_]+/g," ").replace(/^./,e=>e.toUpperCase()),a=e.type,l=Array.isArray(e.refs)?(e.refs??[]).length:+("string"==typeof e.ref),"block.append"===a||"block.inserted"===a&&"end"===e.position?`${o} appended ${l||1} block${1===(l||1)?"":"s"}`:"block.prepend"===a||"block.inserted"===a&&"start"===e.position?`${o} prepended ${l||1} block${1===(l||1)?"":"s"}`:"block.inserted"===a?`${o} inserted ${l||1} block${1===(l||1)?"":"s"}`:"block.replaced"===a||"file.rawWritten"===a?`${o} edited`:"block.deleted"===a?`${o} deleted ${l||1} block${1===(l||1)?"":"s"}`:"suggestion.added"===a?`${o} suggested a change`:"suggestion.accepted"===a?`${o} accepted a suggestion`:"suggestion.rejected"===a?`${o} rejected a suggestion`:"comment.added"===a?`${o} commented`:"comment.replied"===a?`${o} replied`:"comment.resolved"===a?`${o} resolved a comment`:"comment.reopened"===a?`${o} reopened a comment`:"file.externallyEdited"===a?`${o} changed file externally`:`${o} ${a.replace(/^\w+\./,"").replace(/([a-z])([A-Z])/g,"$1 $2")}`)}),(0,s.jsx)("p",{className:"truncate text-[10px] text-muted-foreground",children:t2(e.at)})]})]})});function t4({group:e,reviewCount:t}){let n=t1(e=>e.loadPage),r=e.events[0];return(0,s.jsxs)("section",{className:"space-y-1.5 rounded-md border border-border/70 bg-background/50 p-2",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>void n(e.path),className:"min-w-0 text-left",title:e.path,children:[(0,s.jsx)("p",{className:"truncate text-xs font-medium text-foreground/90",children:e.filename}),(0,s.jsx)("p",{className:"truncate text-[10px] text-muted-foreground",children:e.path})]}),(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-1.5",children:[t>0&&(0,s.jsxs)("button",{type:"button",onClick:()=>void n(e.path),className:"inline-flex items-center rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] font-medium text-amber-700 hover:bg-amber-500/15",title:"Open file for review",children:["review ",t]}),(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground",children:t2(r.at)})]})]}),(0,s.jsx)("div",{className:"space-y-0.5",children:e.events.map(e=>(0,s.jsx)(t5,{event:e},`${e.path}-${e.id}`))})]})}function t6({activity:e}){let t=(0,f.useMemo)(()=>(function(e){let t=new Map;for(let n of e){let e=t.get(n.path)??[];e.push(n),t.set(n.path,e)}return Array.from(t.entries()).map(([e,t])=>({path:e,filename:e.split("/").pop()??e,latestAt:t[0]?.at??"",events:t})).sort((e,t)=>e.latestAt<t.latestAt?1:-1)})(e),[e]),[n,r]=(0,f.useState)({});return((0,f.useEffect)(()=>{let e=!1,n=Array.from(new Set(t.map(e=>e.path)));return 0===n.length?(r({}),()=>{e=!0}):((async()=>{let t=await Promise.all(n.map(async e=>[e,await t3(e)]));e||r(Object.fromEntries(t.filter(([,e])=>e>0)))})(),()=>{e=!0})},[t]),0===t.length)?(0,s.jsx)("p",{className:"py-2 text-xs text-muted-foreground/60",children:"No events recorded"}):(0,s.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,s.jsx)(t4,{group:e,reviewCount:n[e.path]??0},e.path))})}let t9="npx skills add anh-chu/wiki-viewer/agents/wiki-viewer-skill";function t7(e){let[t,n]=(0,f.useState)(!1);return{copied:t,copy:(0,f.useCallback)(async()=>{await navigator.clipboard.writeText(e()),n(!0),setTimeout(()=>n(!1),1500)},[e])}}function t8({currentPath:e}){let t=tO(e=>e.isOpen),n=tO(e=>e.close),r=tO(e=>e.activity),i=tO(e=>e.connections),o=tO(e=>e.loadActivity),{copied:l,copy:c}=function(e){let[t,n]=(0,f.useState)(!1);return{copied:t,copy:(0,f.useCallback)(async()=>{let t=window.location.origin,r=`# 1. Register
8
8
  REG=$(curl -s -X POST -H 'Content-Type: application/json' \\
@@ -18,7 +18,7 @@ TOKEN=<paste token here>
18
18
  # 3. Read snapshot
19
19
  curl -s -H "Authorization: Bearer $TOKEN" \\
20
20
  -H "X-Agent-Id: ai:claude" \\
21
- ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[d,u]=(0,f.useState)(""),p=(0,f.useRef)(null),m=window.location.origin,b=(0,f.useCallback)(()=>t9,[]),x=(0,f.useCallback)(()=>d.replace(/\$WIKI_URL/g,m),[d,m]),y=(0,f.useCallback)(()=>`npx wiki-viewer-mcp register --url ${m} --id ai:myagent --name "My Agent"`,[m]),w=(0,f.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:m,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[m]),k=t7(b),N=t7(x),S=t7(y),C=t7(w);return((0,f.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,f.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,f.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,f.useEffect)(()=>{t&&fetch((0,ev.apiUrl)("/api/agents/install")).then(e=>e.json()).then(e=>{e.bootstrapPrompt&&u(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,s.jsxs)("aside",{ref:p,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-[90vw] max-w-sm md:w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(a,{className:"h-4 w-4 text-muted-foreground"}),(0,s.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,s.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,s.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,s.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void N.copy(),disabled:!d,children:N.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:t9}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void k.copy(),children:k.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:y()}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void S.copy(),children:S.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,s.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void C.copy(),children:C.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3 w-3"})," curl example"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/skill"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/install"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,s.jsx)(t$,{}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,s.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,s.jsx)(tA,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,s.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,s.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,s.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,s.jsx)(t6,{activity:r})})]}),(0,s.jsx)("section",{children:(0,s.jsx)("a",{href:(0,ev.apiUrl)("/docs/agent-collab-plan.md"),target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var ne=e.i(406347);let nt=(0,o.default)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),nn=(0,o.default)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),nr=(0,o.default)("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]),ni=(0,o.default)("file-plus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),ns=(0,o.default)("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),no=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),na=(0,o.default)("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);function nl({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,f.useState)(""),d=(0,f.useRef)(null);if((0,f.useEffect)(()=>{let e=e=>{let t=e.target;d.current?.contains(t)||t?.closest?.("[data-branch-trigger]")||a()},t=e=>{"Escape"===e.key&&a()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a]),"u"<typeof document)return null;let p=t.length>8,h=l.trim().toLowerCase(),m=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tv.createPortal)((0,s.jsx)("div",{ref:d,"data-branch-portal":!0,style:{position:"fixed",top:e.top,left:e.left},className:"pointer-events-auto z-[9999] flex max-h-72 w-52 flex-col overflow-hidden rounded-md border bg-popover p-1 shadow-md",children:n?(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===t.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("input",{autoFocus:!0,value:l,onChange:e=>c(e.target.value),placeholder:"Filter branches…",className:"mb-1 w-full shrink-0 rounded border bg-background px-1.5 py-1 text-[11px] outline-none focus:ring-1 focus:ring-ring"}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:0===m.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):m.map(e=>(0,s.jsxs)("button",{type:"button",disabled:i||e.current,className:(0,eh.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",e.current?"font-semibold text-foreground":"text-muted-foreground"),onClick:t=>{t.stopPropagation(),e.current||o(e.name)},children:[e.current?(0,s.jsx)(g.Check,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)("span",{className:"w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name}),r===e.name&&(0,s.jsx)(u.Loader2,{className:"ml-auto h-3 w-3 shrink-0 animate-spin"})]},e.name))})]})}),document.body)}var nc=e.i(918552),nd=e.i(136131),nu="ContextMenu",[np,nh]=(0,N.createContextScope)(nu,[nc.createMenuScope]),nf=(0,nc.createMenuScope)(),[nm,ng]=np(nu),nb=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=f.useState(!1),c=nf(t),d=(0,nd.useCallbackRef)(r),u=f.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(nm,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(nc.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nb.displayName=nu;var nx="ContextMenuTrigger",ny=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=ng(nx,n),a=nf(n),l=f.useRef({x:0,y:0}),c=f.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=f.useRef(0),u=f.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return f.useEffect(()=>u,[u]),f.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(nc.Anchor,{...a,virtualRef:c}),(0,s.jsx)(T.Primitive.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:(0,w.composeEventHandlers)(e.onContextMenu,e=>{u(),p(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:(0,w.composeEventHandlers)(e.onPointerDown,nO(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nO(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nO(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nO(u))})]})});ny.displayName=nx;var nv=e=>{let{__scopeContextMenu:t,...n}=e,r=nf(t);return(0,s.jsx)(nc.Portal,{...r,...n})};nv.displayName="ContextMenuPortal";var nw="ContextMenuContent",nk=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=ng(nw,n),o=nf(n),a=f.useRef(!1);return(0,s.jsx)(nc.Content,{...o,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&a.current&&t.preventDefault(),a.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||i.modal||(a.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});nk.displayName=nw,f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nN=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Label,{...i,...r,ref:t})});nN.displayName="ContextMenuLabel";var nS=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Item,{...i,...r,ref:t})});nS.displayName="ContextMenuItem";var nC=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.CheckboxItem,{...i,...r,ref:t})});nC.displayName="ContextMenuCheckboxItem",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nj=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioItem,{...i,...r,ref:t})});nj.displayName="ContextMenuRadioItem";var nE=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.ItemIndicator,{...i,...r,ref:t})});nE.displayName="ContextMenuItemIndicator";var nM=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Separator,{...i,...r,ref:t})});nM.displayName="ContextMenuSeparator",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nA=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubTrigger,{...i,...r,ref:t})});nA.displayName="ContextMenuSubTrigger";var nT=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubContent,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});function nO(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nT.displayName="ContextMenuSubContent";var n_=e.i(149427);f.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nA,{ref:i,className:(0,eh.cn)("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,(0,s.jsx)(e3.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nA.displayName,f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nT,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})).displayName=nT.displayName;let nD=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nv,{children:(0,s.jsx)(nk,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})}));nD.displayName=nk.displayName;let nR=f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nS,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));nR.displayName=nS.displayName,f.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nC,{ref:i,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nE,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nC.displayName,f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nj,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nE,{children:(0,s.jsx)(n_.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nj.displayName,f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nN,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nN.displayName;let nI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nM,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));nI.displayName=nM.displayName;let nL="wiki-humanize-names",nP=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nL),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nL,"1"):localStorage.removeItem(nL),e({humanize:n})}})),nz="wiki-show-hidden",n$=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nz),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nz,"1"):localStorage.removeItem(nz),e({showHidden:n})}}));function nB(e){return e.split(".").pop()?.toLowerCase()??""}function nF(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=e.split("/").pop()??e;if(n.startsWith(".")&&-1===n.indexOf(".",1))return"source";let r=nB(e);return r?["md","markdown"].includes(r)?"editor":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(r)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(r)?"media":"docx"===r?"docx":["xlsx","xlsm"].includes(r)?"xlsx":"pptx"===r?"pptx":"html"===r?"html":(["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(r),"source"):"source"}let nH=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function nU(e){let t=nF(e,"file");return"editor"===t||"text"===t||nH.has(nB(e))}function nV(e){return["md","markdown"].includes(nB(e))}function nW(e){return"image"===nF(e,"file")}function nq(e){return"html"===nF(e,"file")}let nK={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nG({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nD,{className:"w-48",children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(nR,{onSelect:()=>t.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(nR,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(nR,{onSelect:()=>t.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(nI,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nR,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nR,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(nI,{})]}),(0,s.jsxs)(nR,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nR,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(nI,{}),(0,s.jsxs)(nR,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nJ({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(e5,{className:(0,eh.cn)(n,"text-foreground/70")}):"app"===t?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/70")}):"node-app"===t?(0,s.jsx)(no,{className:(0,eh.cn)(n,"text-emerald-500")}):nq(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):nW(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nU(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)(n,"text-foreground/60")})}let nZ=(0,f.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:f,isPulling:m,branchOpen:g,branchPos:b,branches:x,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nP(e=>e.humanize);return(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:r=>{if("Enter"===r.key||" "===r.key)r.preventDefault(),"dir"===e.type?n.toggleFolder(e):"app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e);else if("ArrowDown"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else if("ArrowUp"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n-1]?.focus()}else if("ArrowRight"===r.key){if(r.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===r.key){if(r.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(t>0){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=r.currentTarget,i=t.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=i-1;e>=0;e--)if(Number.parseInt(t[e].style.paddingLeft??"0",10)<s){t[e].focus();break}}}},onDragStart:t=>n.handleDragStart(t,e),onDragOver:t=>"dir"===e.type?n.handleDragOver(t,e.path,"dir"):t.preventDefault(),onDragLeave:()=>n.setDragOverPath(null),onDrop:t=>"dir"===e.type?n.handleDropOnFolder(t,e.path):t.preventDefault(),onMouseEnter:()=>k(e),onMouseLeave:N,className:(0,eh.cn)("tree-row-reveal flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none touch-target",a?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",p&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*t+8}px`,...nK},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),r&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,s.jsx)(e3.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200 ease-out",style:{transform:e.expanded?"rotate(90deg)":"rotate(0deg)"}}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"",children:"dir"===e.type?e.expanded?(0,s.jsx)(e4,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(e5,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"app"===e.type?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"node-app"===e.type?(0,s.jsx)(no,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nq(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):nW(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nU(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",title:T?e.name:void 0,children:T?(E=(j=(C=(S=e.name).lastIndexOf("."))>0&&C<S.length-1)?S.slice(0,C):S,M=j?S.slice(C):"",(A=E.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[\s_-]+/).filter(Boolean).map(e=>/^[A-Z0-9]+$/.test(e)?e:e[0].toUpperCase()+e.slice(1))).length?A.join(" ")+M:S):e.name}),e.git&&(0,s.jsxs)("span",{className:"relative flex shrink-0 items-center gap-0.5 rounded-sm bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),g){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let r=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:r.bottom+4,left:r.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,s.jsx)("span",{className:"ml-0.5 text-foreground/70",children:"*"})]}),m?(0,s.jsx)(u.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,s.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,r)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,s.jsx)(tR,{className:"h-2.5 w-2.5"})}),g&&b&&(0,s.jsx)(nl,{pos:b,branches:x,loading:y,busyName:w,disabled:null!==w,onPick:t=>{let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,r)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),f&&(0,s.jsx)("span",{className:"ml-0.5 h-1.5 w-1.5 rounded-full bg-emerald-400 shrink-0 animate-pulse",title:"Agent recently active"}),(0,s.jsx)("div",{className:"hover-reveal flex max-w-0 shrink-0 items-center overflow-hidden opacity-0 transition-all duration-150 group-hover:max-w-7 group-hover:opacity-100 focus-within:max-w-7 focus-within:opacity-100",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{})]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.toggleFavorite(e,i),children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",h&&"fill-current text-amber-400")}),h?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nG,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nX=(0,f.memo)(function(e){let{ctx:t,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:o,nodeBranches:a,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:p,favorites:m,isMobile:b,activeWorkspaceId:x,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=n$(e=>e.showHidden),M=(0,f.useRef)(null),A=(0,f.useCallback)(e=>{let n=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||n)&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>t.prefetch(e),120))},[t]),T=(0,f.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,f.useMemo)(()=>{let t=[],n=(e,r)=>{for(let i of e)!(!E&&i.name.startsWith("."))&&(t.push({kind:"row",node:i,depth:r}),"dir"===i.type&&(N===i.path&&t.push({kind:"newfolder",node:i,depth:r}),y===i.path&&t.push({kind:"newfile",node:i,depth:r})),("dir"===i.type||"app"===i.type||"node-app"===i.type)&&i.expanded&&(i.children&&i.children.length>0?n(i.children,r+1):i.children?.length===0&&t.push({kind:"empty",node:i,depth:r})))};return n(e.nodes,0),t},[e.nodes,y,N,E]);return(0,s.jsx)(s.Fragment,{children:O.map(e=>{let{node:f,depth:y}=e;if("row"===e.kind){let e=i===f.path;return(0,s.jsx)(nZ,{node:f,depth:y,ctx:t,isMobile:b,activeWorkspaceId:x,sidebarScrollRef:j,isActive:n===f.path,isDragOver:r===f.path,isFavorited:m.some(e=>e.path===f.path),isAgentActive:p.has(f.path),isPulling:u===f.path,branchOpen:e,branchPos:e?o:null,branches:f.git?a[f.path]??[]:[],branchLoading:!!f.git&&!!c[f.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},f.path)}return"newfolder"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-foreground/70"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:S,onChange:e=>t.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFolder(),"Escape"===e.key&&(t.setNewFolderParent(null),t.setNewFolderName(""))}}),C&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:C}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFolder,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFolderParent(null),t.setNewFolderName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`nf-${f.path}`):"newfile"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:w,onChange:e=>t.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFile(),"Escape"===e.key&&(t.setNewFileParent(null),t.setNewFileName(""))}}),k&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFile,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFileParent(null),t.setNewFileName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`ff-${f.path}`):(0,s.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(y+1)*14+8+14+6+16+6}px`,...nK},children:"Empty"},`empty-${f.path}`)})})});function nY(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nQ(e){try{let t=localStorage.getItem(nY(e));return t?JSON.parse(t):[]}catch{return[]}}let n0=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nQ(t)})},toggle:(t,n)=>{let r=nQ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nY(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function n1({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=n0(e=>e.isFavorited(t.path));return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{let e=(0,tE.withWs)(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),n=document.createElement("a");n.href=e,n.download=t.name,document.body.appendChild(n),n.click(),n.remove()},children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n0.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",i&&"fill-current text-amber-400")}),i?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyPath(t.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(t.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyWikiLink(t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyUrl(t.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nU(t.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyRawContent(t.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyFormattedContent(t.path,t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),n]})]})]})}let n2=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n3=e.i(409082);let n5=(0,o.default)("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);var n4=e.i(847463),n6=e.i(917356),n9=/[\\\/_+.#"@\[\(\{&]/,n7=/[\\\/_+.#"@\[\(\{&]/g,n8=/[\s-]/,re=/[\s-]/g;function rt(e){return e.toLowerCase().replace(re," ")}var rn='[cmdk-group=""]',rr='[cmdk-group-items=""]',ri='[cmdk-item=""]',rs=`${ri}:not([aria-disabled="true"])`,ro="cmdk-item-select",ra="data-value",rl=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,s,o,a){if(o===n.length)return s===t.length?1:.99;var l=`${s},${o}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(o),f=r.indexOf(h,s),m=0;f>=0;)(c=e(t,n,r,i,f+1,o+1,a))>m&&(f===s?c*=1:n9.test(t.charAt(f-1))?(c*=.8,(u=t.slice(s,f-1).match(n7))&&s>0&&(c*=Math.pow(.999,u.length))):n8.test(t.charAt(f-1))?(c*=.9,(p=t.slice(s,f-1).match(re))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,f-s))),t.charAt(f)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(f-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,f+1,o+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,rt(r),rt(t),0,0,{})},rc=f.createContext(void 0),rd=f.createContext(void 0),ru=f.createContext(void 0),rp=f.forwardRef((e,t)=>{let n=rk(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=rk(()=>new Set),i=rk(()=>new Map),s=rk(()=>new Map),o=rk(()=>new Set),a=rv(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:m,disablePointerSelection:g=!1,vimBindings:b=!0,...x}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=f.useRef(null),N=rC();rw(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rw(()=>{N(6,O)},[]);let C=f.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,s,o,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)T(),M(),N(1,A);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(w);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(N(7,()=>{var e;n.current.selectedItemId=null==(e=_())?void 0:e.id,C.emit()}),r||N(5,O),(null==(s=a.current)?void 0:s.value)!==void 0){null==(l=(o=a.current).onValueChange)||l.call(o,null!=t?t:"");return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),j=f.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=s.current.get(e))?void 0:i.value)&&(s.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),N(2,()=>{M(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),N(3,()=>{T(),M(),n.current.value||A(),C.emit()}),()=>{s.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=_();N(4,()=>{T(),(null==t?void 0:t.getAttribute("id"))===e&&A(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{s.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:w,labelId:v,listInnerRef:k}),[]);function E(e,t){var r,i;let s=null!=(i=null==(r=a.current)?void 0:r.filter)?i:rl;return e?s(e,n.current.search,t):0}function M(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),s=0;r.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([n,s])});let r=k.current;D().sort((t,n)=>{var r,i;let s=t.getAttribute("id"),o=n.getAttribute("id");return(null!=(r=e.get(o))?r:0)-(null!=(i=e.get(s))?i:0)}).forEach(e=>{let t=e.closest(rr);t?t.appendChild(e.parentElement===t?e:e.closest(`${rr} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${rr} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${rn}[${ra}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function A(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(ra);C.setState("value",t||void 0)}function T(){var e,t,o,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=E(null!=(t=null==(e=s.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(o=s.current.get(i))?void 0:o.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function O(){var e,t,n;let r=_();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(rn))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function _(){var e;return null==(e=k.current)?void 0:e.querySelector(`${ri}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rs))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ra))}function I(e){var t;let n=_(),r=D(),i=r.findIndex(e=>e===n),s=r[i+e];null!=(t=a.current)&&t.loop&&(s=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),s&&C.setState("value",s.getAttribute(ra))}function L(e){let t=_(),n=null==t?void 0:t.closest(rn),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,rn):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,rn))?void 0:n.querySelector(rs);r?C.setState("value",r.getAttribute(ra)):I(e)}let P=()=>R(D().length-1),z=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},$=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return f.createElement(tk.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=x.onKeyDown)||t.call(x,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":b&&e.ctrlKey&&z(e);break;case"ArrowDown":z(e);break;case"p":case"k":b&&e.ctrlKey&&$(e);break;case"ArrowUp":$(e);break;case"Home":e.preventDefault(),R(0);break;case"End":e.preventDefault(),P();break;case"Enter":{e.preventDefault();let t=_();if(t){let e=new Event(ro);t.dispatchEvent(e)}}}}},f.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rE},l),rj(e,e=>f.createElement(rd.Provider,{value:C},f.createElement(rc.Provider,{value:j},e))))}),rh=f.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=f.useRef(null),o=f.useContext(ru),a=f.useContext(rc),l=rv(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rw(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rS(i,s,[e.value,e.children,s],e.keywords),u=f.useContext(rd),p=rN(e=>e.value&&e.value===d.current),h=rN(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function m(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(f.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(ro,m),()=>t.removeEventListener(ro,m)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:b,value:x,onSelect:y,forceMount:v,keywords:w,...N}=e;return f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!b,"aria-selected":!!p,"data-disabled":!!b,"data-selected":!!p,onPointerMove:b||a.getDisablePointerSelection()?void 0:g,onClick:b?void 0:m},e.children)}),rf=f.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=f.useRef(null),l=f.useRef(null),c=(0,S.useId)(),d=f.useContext(rc),u=rN(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rw(()=>d.group(o),[]),rS(o,a,[e.value,e.heading,l]);let p=f.useMemo(()=>({id:o,forceMount:i}),[i]);return f.createElement(tk.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&f.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rj(e,e=>f.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},f.createElement(ru.Provider,{value:p},e))))}),rm=f.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=f.useRef(null),s=rN(e=>!e.search);return n||s?f.createElement(tk.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rg=f.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=f.useContext(rd),o=rN(e=>e.search),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),f.createElement(tk.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:o,onChange:e=>{i||s.setState("search",e.target.value),null==n||n(e.target.value)}})}),rb=f.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=f.useRef(null),o=f.useRef(null),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{if(o.current&&s.current){let e=o.current,t=s.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rj(e,e=>f.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rx=f.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return f.createElement(B,{open:n,onOpenChange:r},f.createElement(W,{container:o},f.createElement(K,{"cmdk-overlay":"",className:i}),f.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},f.createElement(rp,{ref:t,...a}))))}),ry=Object.assign(rp,{List:rb,Item:rh,Input:rg,Group:rf,Separator:rm,Dialog:rx,Empty:f.forwardRef((e,t)=>rN(e=>0===e.filtered.count)?f.createElement(tk.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:f.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return f.createElement(tk.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rj(e,e=>f.createElement("div",{"aria-hidden":!0},e)))})});function rv(e){let t=f.useRef(e);return rw(()=>{t.current=e}),t}var rw="u"<typeof window?f.useEffect:f.useLayoutEffect;function rk(e){let t=f.useRef();return void 0===t.current&&(t.current=e()),t}function rN(e){let t=f.useContext(rd),n=()=>e(t.snapshot());return f.useSyncExternalStore(t.subscribe,n,n)}function rS(e,t,n,r=[]){let i=f.useRef(),s=f.useContext(rc);return rw(()=>{var o;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());s.value(e,a,l),null==(o=t.current)||o.setAttribute(ra,a),i.current=a}),i}var rC=()=>{let[e,t]=f.useState(),n=rk(()=>new Map);return rw(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rj({asChild:e,children:t},n){let r;return e&&f.isValidElement(t)?f.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var rE={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rM=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rA=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry,{ref:n,className:(0,eh.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function rT({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eX,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(e0,{className:"sr-only",children:"Search"}),(0,s.jsx)(rA,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}rA.displayName=ry.displayName;let rO=f.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rM,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(ry.Input,{ref:n,className:(0,eh.cn)("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));rO.displayName=ry.Input.displayName;let r_=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));r_.displayName=ry.List.displayName;let rD=f.forwardRef((e,t)=>(0,s.jsx)(ry.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rD.displayName=ry.Empty.displayName;let rR=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Group,{ref:n,className:(0,eh.cn)("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));rR.displayName=ry.Group.displayName;let rI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));rI.displayName=ry.Separator.displayName;let rL=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Item,{ref:n,className:(0,eh.cn)("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));rL.displayName=ry.Item.displayName;let rP=null,rz=null,r$=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rz&&clearTimeout(rz),rP?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rz&&clearTimeout(rz),t.trim())?(e({loading:!0}),new Promise(n=>{rz=setTimeout(()=>{rB(e,t).finally(n)},150)})):(rP?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rB(e,t){rP?.abort();let n=new AbortController;rP=n;try{let r=await (0,tE.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var rF=e.i(395624);function rH({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,s.jsx)(s.Fragment,{children:t.map((e,t)=>e.mark?(0,s.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,s.jsx)("span",{children:e.text},t))})}function rU({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=r$(e=>e.open),l=r$(e=>e.setOpen),c=r$(e=>e.query),d=r$(e=>e.setQuery),u=r$(e=>e.results),p=r$(e=>e.loading),h=r$(e=>e.truncated),m=r$(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,n6.useTheme)(),x=tO(e=>e.toggle),y=(0,rF.useViewWidthStore)(e=>e.width),v=(0,rF.useViewWidthStore)(e=>e.cycle),w=c.trimStart(),k=""===w||w.startsWith(">"),N=""===w&&t.length>0,S=k?"":c;function C(e){e(),l(!1),d("")}(0,f.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!o))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,f.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{m(S)},120);return()=>clearTimeout(e)},[S,k,o,m]);let j=(rF.VIEW_WIDTH_ORDER.indexOf(y)+1)%rF.VIEW_WIDTH_ORDER.length,E=rF.VIEW_WIDTH_LABEL[rF.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rT,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rO,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(r_,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rR,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rL,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(to,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate font-medium",children:t.name}),(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:t.path})]})]},t.path))}),(0,s.jsx)(rI,{})]}),k&&(0,s.jsxs)(rR,{heading:"Actions",children:[(0,s.jsxs)(rL,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n4.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rL,{value:"toggle-ai-panel",onSelect:()=>C(x),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rL,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n5,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rL,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(ni,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rL,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rL,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(n2,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",rF.VIEW_WIDTH_LABEL[y]," → ",E,")"]})]})]})]}),!k&&(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==S.trim()&&0===u.length&&(0,s.jsx)(rD,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rI,{}),(0,s.jsx)(rR,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rL,{value:t.path,onSelect:()=>{e(t.path),l(!1),d("")},children:(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate text-xs",children:t.path}),t.snippet&&(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,s.jsx)(rH,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(335884);let rV=(0,o.default)("cloud-download",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]);var rW=e.i(301138);let rq=(0,o.default)("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),rK=(0,o.default)("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),rG=(0,o.default)("panel-left-close",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]),rJ=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rZ=(0,o.default)("settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var rX=e.i(109680);function rY({onOpenFile:e}){let t=r$(e=>e.query),n=r$(e=>e.setQuery),r=r$(e=>e.results),i=r$(e=>e.loading),o=r$(e=>e.search),a=r$(e=>e.clear),[l,c]=(0,f.useState)(0),d=(0,f.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,f.useEffect)(()=>{c(0)},[r]),(0,f.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${l}"]`);e?.scrollIntoView({block:"nearest"})},[l]),(0,s.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(rM,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,s.jsx)("input",{type:"text",className:"w-full rounded-sm bg-muted py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?a():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),u(l)))}})]}),""!==t.trim()&&(0,s.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,s.jsxs)("button",{type:"button","data-idx":t,onClick:()=>u(t),onMouseEnter:()=>c(t),className:`block w-full px-2 py-1 text-left ${t===l?"bg-accent":"hover:bg-accent"}`,children:[(0,s.jsx)("div",{className:"truncate text-xs",children:e.path}),e.snippet&&(0,s.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,s.jsx)(rH,{html:e.snippet})})]},e.path))]})]})}var rQ=e.i(515288);function r0(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function r1({workspaces:e,activeWorkspaceId:t,rootPath:n,isWsAdmin:r,refreshingWsId:i,switchingBranch:o,switchingBranchName:a,wsBranches:l,branchPickerWsId:c,wsBranchPos:d,onSwitchWorkspace:u,onRefreshWorkspace:p,onPromptDeleteWorkspace:h,onAddWorkspace:f,setBranchPickerWsId:m,setWsBranchPos:x,loadWsBranches:y,handleSwitchBranch:w}){return(0,s.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(m(null),x(null))},children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:n??"",children:[(0,s.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"truncate text-xs font-medium",children:e.find(e=>e.id===t)?.name??"Workspace"}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:n??""})]}),(0,s.jsx)(b,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[e.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void u(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,eh.cn)("gap-2",e.id===t&&"font-medium"),children:[e.id===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,s.jsx)("span",{className:"truncate",children:e.name}),e.git?r?(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0 hover:bg-accent",title:"Switch branch",disabled:o===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),c===e.id){m(null),x(null);return}let n=t.currentTarget.getBoundingClientRect();x({top:n.bottom+4,left:n.left}),m(e.id),y(e.id)},children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e7,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.rootDir}),e.git?.lastPulledAt&&r0(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",r0(e.git.lastPulledAt)]})]}),r&&e.git&&(0,s.jsx)("button",{className:(0,eh.cn)("shrink-0 rounded p-0.5 hover:bg-accent transition-colors",e.git.lastError?"text-destructive":"text-muted-foreground hover:text-foreground"),title:e.git.lastError?`Last refresh failed: ${e.git.lastError}`:"Refresh",disabled:i===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(e.id)},children:(0,s.jsx)(tR,{className:(0,eh.cn)("h-3.5 w-3.5",i===e.id&&"animate-spin")})}),r&&(0,s.jsx)("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Delete workspace (does not delete files)",onClick:t=>{t.stopPropagation(),h(e.id)},children:(0,s.jsx)(ts,{className:"h-3.5 w-3.5"})})]},e.id)),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:f,children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!c||!d)return null;let t=e.find(e=>e.id===c);return t?(0,s.jsx)(nl,{pos:d,branches:(l[t.id]??[]).map(e=>({name:e,current:e===t.git?.branch})),loading:!l[t.id],busyName:o===t.id?a:null,disabled:o===t.id,onPick:e=>{w(t.id,e)},onClose:()=>{m(null),x(null)}}):null})()]})}let r2="wiki-sidebar-width";function r3(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let r5=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(r2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return r3(t)}return 288}(),setWidth:t=>{let n=r3(t);localStorage.setItem(r2,String(n)),e({width:n})}}));function r4(e){return e.split("/").pop()??e}function r6({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:f,sidebarWidth:x,setSidebarWidth:y,collapsed:w,setCollapsed:k,createEntry:N,setCreateEntry:S,handleCreateFile:C,handleCreateFolder:j,dragOverPath:E,setDragOverPath:M,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:O,treeCtx:_,favorites:D,recents:R,activePaths:I,setDialogs:L,handleRefreshWorkspace:P}){let{resolvedTheme:z,setTheme:$}=(0,n6.useTheme)(),B=nP(e=>e.humanize),F=n$(e=>e.showHidden);return(0,s.jsxs)(s.Fragment,{children:[!o&&!c&&i&&(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>d(!0),"aria-hidden":!0}),!o&&!c&&(0,s.jsxs)(rQ.Card,{style:i?void 0:{width:x},className:"fixed inset-y-0 left-0 z-50 w-[85vw] max-w-[20rem] md:relative md:z-auto md:w-auto md:max-w-none flex flex-col shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0 bg-sidebar border-sidebar-border text-sidebar-foreground",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",title:"Wiki Viewer v2.11.2",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,s.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>d(!0),children:(0,s.jsx)(rG,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rJ,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(b,{className:"h-3 w-3 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:()=>void n.refreshTree(),disabled:n.refreshingTree,children:n.refreshingTree?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tR,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{tO.getState().toggle(),i&&d(!0)},children:(0,s.jsx)(a,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[e.isWsAdmin&&e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.git&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{e.activeWorkspaceId&&P(e.activeWorkspaceId)},disabled:e.refreshingWsId===e.activeWorkspaceId,children:[e.refreshingWsId===e.activeWorkspaceId?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rV,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n$.getState().toggle(),children:[F?(0,s.jsx)(rq,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rW.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nP.getState().toggle(),children:[(0,s.jsx)(rX.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>$("dark"===z?"light":"dark"),children:["dark"===z?(0,s.jsx)(n4.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===z?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rZ,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),r.uploadError&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),r.uploadError]}),""===N.folder.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N.folder.name,onChange:e=>S(t=>({...t,folder:{...t.folder,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&j(),"Escape"===e.key&&S(e=>({...e,folder:{...e.folder,parent:null,name:""}}))}}),N.folder.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.folder.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:j,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,folder:{...e.folder,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),""===N.file.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:N.file.name,onChange:e=>S(t=>({...t,file:{...t.file,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&S(e=>({...e,file:{...e.file,parent:null,name:""}}))}}),N.file.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.file.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:C,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,file:{...e.file,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"border-b",children:(0,s.jsx)(rY,{onOpenFile:t.openFromSearch})}),(0,s.jsxs)("div",{ref:O,className:(0,eh.cn)("flex-1 overflow-auto py-1 ",""===E&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>A(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||M(null)},onDrop:e=>T(e,""),children:[D.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,favorites:!e.favorites})),children:[w.favorites?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(te,{className:"h-3 w-3"}),"Favorites",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:D.length})]}),!w.favorites&&D.map(n=>(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openFavoriteEntry(n)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openFavoriteEntry(n))},children:[(0,s.jsx)(nJ,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:B?n.name:void 0,children:B?r4(n.name):n.name}),(0,s.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:n.path.split("/").slice(0,-1).join("/")}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-amber-400 group-hover:opacity-100 focus:opacity-100",title:"Remove from favorites",onClick:t=>{t.stopPropagation(),n0.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nG,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:!0,activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),R.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,recent:!e.recent})),children:[w.recent?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(rK,{className:"h-3 w-3"}),"Recent",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:R.length})]}),!w.recent&&R.slice(0,8).map(n=>(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}),i&&d(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}))},children:[(0,s.jsx)(nJ,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",title:B?n.name:void 0,children:B?r4(n.name):n.name}),(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:n.path.split("/").slice(0,-1).join("/")})]})}),(0,s.jsx)(nG,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:D.some(e=>e.path===n.path),activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),n.rootLoading?(0,s.jsx)("div",{className:"flex justify-center py-6",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===n.roots.length?(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,s.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,s.jsx)(l.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(na,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nX,{ctx:_,nodes:n.roots,openPath:t.openFile?.path??null,dragOverPath:E,branchDropdownNode:n.branchDropdownNode,branchDropdownPos:n.branchDropdownPos,nodeBranches:n.nodeBranches,branchesLoading:n.branchesLoading,checkingOutBranch:n.checkingOutBranch,pullingRepo:n.pullingRepo,activePaths:I,favorites:D,isMobile:i,activeWorkspaceId:e.activeWorkspaceId,newFileParent:N.file.parent,newFileName:N.file.name,fileCreateError:N.file.error,newFolderParent:N.folder.parent,newFolderName:N.folder.name,folderError:N.folder.error,sidebarScrollRef:O})]}),(0,s.jsx)(r1,{workspaces:e.workspaces,activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isWsAdmin:e.isWsAdmin,refreshingWsId:e.refreshingWsId,switchingBranch:e.switchingBranch,switchingBranchName:e.switchingBranchName,wsBranches:e.wsBranches,branchPickerWsId:e.branchPickerWsId,wsBranchPos:e.wsBranchPos,onSwitchWorkspace:t=>void e.switchWorkspace(t),onRefreshWorkspace:e.handleRefreshWorkspace,onPromptDeleteWorkspace:t=>e.setDeletingWorkspaceId(t),onAddWorkspace:()=>e.setAddingWorkspace(!0),setBranchPickerWsId:e.setBranchPickerWsId,setWsBranchPos:e.setWsBranchPos,loadWsBranches:e.loadWsBranches,handleSwitchBranch:e.handleSwitchBranch}),(0,s.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;f(!0);let n=document.body.style.cursor,r=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=e=>{y(x+(e.clientX-t))},s=()=>{f(!1),document.body.style.cursor=n,document.body.style.userSelect=r,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},onDoubleClick:()=>y(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),y(x-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(x+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":x,className:(0,eh.cn)("absolute right-0 top-0 z-20 h-full w-1.5 cursor-col-resize -mr-px transition-colors hover:bg-primary/40 focus:bg-primary/40 focus:outline-none hidden md:block",p&&"bg-primary/60")})]})]})}function r9({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,favorites:c,recents:d,activePaths:u,setDeleting:p,setDialogs:h}){let[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)({favorites:!1,recent:!0}),[w,k]=(0,f.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,f.useRef)(null),S=(0,f.useRef)(null),C=r5(e=>e.width),j=r5(e=>e.setWidth),E=(0,f.useCallback)(async()=>{let e=w.file.name.trim();if(!e||null===w.file.parent)return;k(e=>({...e,file:{...e.file,error:null}}));let r=e.includes(".")?e:`${e}.md`,i=w.file.parent?`${w.file.parent}/${r}`:r,s=await fetch((0,tE.withWs)("/api/wiki/new-file"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i})});if(s.ok){let e=w.file.parent;k(e=>({...e,file:{parent:null,name:"",error:null}})),await n.reloadDir(e),t.openViewer({path:i,name:r,type:"file",modifiedAt:new Date().toISOString()})}else{let e=await s.json();k(t=>({...t,file:{...t.file,error:e.error??"Failed"}}))}},[w.file.parent,w.file.name,n,t]),M=(0,f.useCallback)(async()=>{let e=w.folder.name.trim();if(!e||null===w.folder.parent)return;k(e=>({...e,folder:{...e.folder,error:null}}));let t=w.folder.parent?`${w.folder.parent}/${e}`:e,r=await fetch((0,tE.withWs)("/api/wiki/folder"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(r.ok){let e=w.folder.parent;k(e=>({...e,folder:{parent:null,name:"",error:null}})),await n.reloadDir(e)}else{let e=await r.json();k(t=>({...t,folder:{...t.folder,error:e.error??"Failed"}}))}},[w.folder.parent,w.folder.name,n]);function A(e,t,n){e.preventDefault(),e.stopPropagation();let r=S.current;if(!r){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",x("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",x("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),x(null);let s=S.current;if(S.current=null,!s){e.dataTransfer.files.length>0&&await r.doUpload(e.dataTransfer.files,i);return}if(s.path===i||i.startsWith(`${s.path}/`))return;let o=i?`${i}/${s.name}`:s.name;if(o!==s.path&&(await fetch((0,tE.withWs)("/api/wiki/move"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:s.path,to:o})})).ok){let e=s.path.includes("/")?s.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),i!==e&&await n.reloadDir(i),t.openFile?.path===s.path&&t.openViewer({path:o,name:s.name,type:s.type,modifiedAt:s.modifiedAt})}}let O=(0,f.useRef)(null);O.current={toggleFolder:e=>void n.toggleFolder(e),openViewer:e=>void t.openViewer(e),copyPath:e=>t.copyPath(e),copyWikiLink:e=>t.copyWikiLink(e),copyUrl:e=>t.copyUrl(e),copyRawContent:e=>void t.copyRawContent(e),copyFormattedContent:(e,n)=>void t.copyFormattedContent(e,n),handleDownload:function(e){let t=(0,tE.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),n=document.createElement("a");n.href=t,n.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(n),n.click(),n.remove()},triggerUpload:e=>r.triggerUpload(e),handleCreateFile:E,handleCreateFolder:M,handleDragStart:function(e,t){S.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:A,handleDropOnFolder:(e,t)=>void T(e,t),handleGitPull:(e,t)=>void n.handleGitPull(e,t),handleCheckout:(e,t,r)=>void n.handleCheckout(e,t,r),loadBranches:e=>void n.loadBranches(e),prefetch:e=>void n.prefetch(e),toggleFavorite:(e,t)=>n0.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:x,setSidebarCollapsed:l,setBranchDropdownNode:e=>n.setBranchDropdownNode(e),setBranchDropdownPos:e=>n.setBranchDropdownPos(e),setNewFileParent:e=>k(t=>({...t,file:{...t.file,parent:e,error:null}})),setNewFileName:e=>k(t=>({...t,file:{...t.file,name:e}})),setFileCreateError:e=>k(t=>({...t,file:{...t.file,error:e}})),setNewFolderParent:e=>k(t=>({...t,folder:{...t.folder,parent:e,error:null}})),setNewFolderName:e=>k(t=>({...t,folder:{...t.folder,name:e}})),setFolderError:e=>k(t=>({...t,folder:{...t.folder,error:e}})),setDeletingPath:e=>p(t=>({...t,path:e})),setDeletingIsDir:e=>p(t=>({...t,isDir:e}))};let _=(0,f.useMemo)(()=>({toggleFolder:e=>O.current.toggleFolder(e),openViewer:e=>O.current.openViewer(e),copyPath:e=>O.current.copyPath(e),copyWikiLink:e=>O.current.copyWikiLink(e),copyUrl:e=>O.current.copyUrl(e),copyRawContent:e=>O.current.copyRawContent(e),copyFormattedContent:(e,t)=>O.current.copyFormattedContent(e,t),handleDownload:e=>O.current.handleDownload(e),triggerUpload:e=>O.current.triggerUpload(e),handleCreateFile:()=>O.current.handleCreateFile(),handleCreateFolder:()=>O.current.handleCreateFolder(),handleDragStart:(e,t)=>O.current.handleDragStart(e,t),handleDragOver:(e,t,n)=>O.current.handleDragOver(e,t,n),handleDropOnFolder:(e,t)=>O.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>O.current.handleGitPull(e,t),handleCheckout:(e,t,n)=>O.current.handleCheckout(e,t,n),loadBranches:e=>O.current.loadBranches(e),prefetch:e=>O.current.prefetch(e),toggleFavorite:(e,t)=>O.current.toggleFavorite(e,t),setDragOverPath:e=>O.current.setDragOverPath(e),setSidebarCollapsed:e=>O.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>O.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>O.current.setBranchDropdownPos(e),setNewFileParent:e=>O.current.setNewFileParent(e),setNewFileName:e=>O.current.setNewFileName(e),setFileCreateError:e=>O.current.setFileCreateError(e),setNewFolderParent:e=>O.current.setNewFolderParent(e),setNewFolderName:e=>O.current.setNewFolderName(e),setFolderError:e=>O.current.setFolderError(e),setDeletingPath:e=>O.current.setDeletingPath(e),setDeletingIsDir:e=>O.current.setDeletingIsDir(e)}),[]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rU,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tO.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(r6,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:m,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:b,setDragOverPath:x,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let r7=(0,o.default)("code-xml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]),r8=(0,o.default)("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),ie=(0,o.default)("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),it=(0,o.default)("share",[["path",{d:"M12 2v13",key:"1km8f5"}],["path",{d:"m16 6-4-4-4 4",key:"13yo43"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}]]),ir=(0,o.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);var ii=e.i(75470),is=e.i(801273),io=e.i(61086);function ia(e){let t=[],n="",r=!1,i=[];for(let s=0;s<e.length;s++){let o=e[s],a=e[s+1];r?'"'===o&&'"'===a?(n+='"',s++):'"'===o?r=!1:n+=o:'"'===o?r=!0:","===o?(i.push(n),n=""):"\n"===o||"\r"===o&&"\n"===a?(i.push(n),n="",i.length>0&&t.push(i),i=[],"\r"===o&&s++):n+=o}return i.push(n),i.some(e=>""!==e)&&t.push(i),t}function il(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function ic({path:e}){let[t,n]=(0,f.useState)([]),[r,i]=(0,f.useState)(""),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(1e3),y=(0,tE.withWs)(`/api/assets/${e}`);(0,f.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=ia(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,f.useCallback)((e,t,r)=>{n(n=>{let i=n.map(e=>[...e]);for(;i.length<=e;)i.push([]);for(;i[e].length<=t;)i[e].push("");return i[e][t]=r,i}),c(!0)},[]),k=async()=>{u(!0);let s=o?r:il(t);try{await (0,tE.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(ia(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=m?S.slice(0,b):S,j=m&&b<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:`CSV${t.length>0?` (${t.length-1} rows)`:""}`,children:[l&&(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:k,disabled:d,children:[(0,s.jsx)(is.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),m&&(0,s.jsxs)("span",{className:"text-[11px] text-amber-600 dark:text-amber-400 px-1",children:["Large file (",(r.length/1048576).toFixed(1)," MB,"," ",t.length.toLocaleString()," rows)"]}),(0,s.jsxs)("button",{onClick:()=>{o?n(ia(r)):i(il(t)),a(!o)},className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-md transition-colors border border-border ${o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"}`,children:[(0,s.jsx)(r7,{className:"h-3 w-3"}),o?"Table":"Source"]}),(0,s.jsx)("button",{onClick:()=>window.open(y,"_blank"),className:"inline-flex items-center justify-center rounded-md h-8 w-8 hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer",title:"Download CSV",children:(0,s.jsx)(ne.Download,{className:"h-4 w-4"})})]}),o?(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:(0,s.jsx)("textarea",{value:r,onChange:e=>{i(e.target.value),c(!0)},className:"w-full h-full min-h-[calc(100vh-12rem)] bg-transparent font-mono text-[13px] leading-relaxed resize-none focus:outline-none",spellCheck:!1})}):(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[(0,s.jsxs)("table",{className:"w-full border-collapse text-[13px]",children:[(0,s.jsx)("thead",{className:"sticky top-0 z-10",children:(0,s.jsxs)("tr",{className:"bg-muted/80 backdrop-blur-sm",children:[(0,s.jsx)("th",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground w-8",children:"#"}),N.map((e,t)=>(0,s.jsx)("th",{className:"border border-border px-3 py-1.5 text-left font-medium text-foreground min-w-[100px]",children:p?.r===0&&p?.c===t?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:e,onChange:e=>w(0,t,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{("Enter"===e.key||"Escape"===e.key)&&h(null),"Tab"===e.key&&(e.preventDefault(),h({r:0,c:t+1<N.length?t+1:0}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r:0,c:t}),children:e||" "})},t))]})}),(0,s.jsx)("tbody",{children:C.map((e,t)=>{let r=t+1;return(0,s.jsxs)("tr",{className:"hover:bg-accent/30 transition-colors group",children:[(0,s.jsxs)("td",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground/50",children:[(0,s.jsx)("span",{className:"group-hover:hidden",children:t+1}),(0,s.jsx)("button",{className:"hidden group-hover:inline text-destructive hover:text-destructive/80 text-[10px]",onClick:()=>{n(e=>e.filter((e,t)=>t!==r)),c(!0)},title:"Delete row",children:"×"})]}),N.map((t,n)=>{let i=e[n]??"",o=p?.r===r&&p?.c===n;return(0,s.jsx)("td",{className:"border border-border px-3 py-1.5",children:o?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:i,onChange:e=>w(r,n,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{"Escape"===e.key&&h(null),"Enter"===e.key&&h({r:r+1,c:n}),"Tab"===e.key&&(e.preventDefault(),e.shiftKey?h({r,c:Math.max(0,n-1)}):h({r:n+1>=N.length?r+1:r,c:n+1>=N.length?0:n+1}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r,c:n}),children:i||" "})},n)})]},t)})})]}),j&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border",children:[(0,s.jsxs)("button",{onClick:()=>x(e=>e+1e3),className:"text-[11px] text-foreground hover:bg-accent transition-colors px-2.5 py-1 rounded border border-border",children:["Show"," ",Math.min(1e3,S.length-b).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[b.toLocaleString()," /"," ",S.length.toLocaleString()," rows"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-border",children:[(0,s.jsx)("button",{onClick:()=>{let e=t[0]?.length||1;n(t=>[...t,Array(e).fill("")]),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add row"}),(0,s.jsx)("button",{onClick:()=>{n(e=>e.map(e=>[...e,""])),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add column"})]})]})]})}function id(e){this.content=e}id.prototype={constructor:id,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return -1},get:function(e){var t=this.find(e);return -1==t?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),s=r.content.slice();return -1==i?s.push(n||e,t):(s[i+1]=t,n&&(s[i]=n)),new id(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new id(n)},addToStart:function(e,t){return new id([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new id(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,n),new id(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=id.from(e)).size?new id(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=id.from(e)).size?new id(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=id.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},id.from=function(e){if(e instanceof id)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new id(t)};class iu{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;if(l>e&&!1!==n(a,r+o,i||null,s)&&a.content.size){let i=o+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}o=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",s=!0;return this.nodesBetween(e,t,(o,a)=>{let l=o.isText?o.text.slice(Math.max(e,a)-a,t-a):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&n&&(s?s=!1:i+=n),i+=l},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new iu(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,s=0;s<t;i++){let o=this.content[i],a=s+o.nodeSize;a>e&&((s<e||a>t)&&(o=o.isText?o.cut(Math.max(0,e-s),Math.min(o.text.length,t-s)):o.cut(Math.max(0,e-s-1),Math.min(o.content.size,t-s-1))),n.push(o),r+=o.nodeSize),s=a}return new iu(n,r)}cutByIndex(e,t){return e==t?iu.empty:0==e&&t==this.content.length?this:new iu(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new iu(r,i)}addToStart(e){return new iu([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iu(this.content.concat(e),this.size+e.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 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 function e(t,n,r){for(let i=0;;i++){if(i==t.childCount||i==n.childCount)return t.childCount==n.childCount?null:r;let s=t.child(i),o=n.child(i);if(s==o){r+=s.nodeSize;continue}if(!s.sameMarkup(o))return r;if(s.isText&&s.text!=o.text){for(let e=0;s.text[e]==o.text[e];e++)r++;return r}if(s.content.size||o.content.size){let t=e(s.content,o.content,r+1);if(null!=t)return t}r+=s.nodeSize}}(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return function e(t,n,r,i){for(let s=t.childCount,o=n.childCount;;){if(0==s||0==o)return s==o?null:{a:r,b:i};let a=t.child(--s),l=n.child(--o),c=a.nodeSize;if(a==l){r-=c,i-=c;continue}if(!a.sameMarkup(l))return{a:r,b:i};if(a.isText&&a.text!=l.text){let e=0,t=Math.min(a.text.length,l.text.length);for(;e<t&&a.text[a.text.length-e-1]==l.text[l.text.length-e-1];)e++,r--,i--;return{a:r,b:i}}if(a.content.size||l.content.size){let t=e(a.content,l.content,r-1,i-1);if(t)return t}r-=c,i-=c}}(this,e,t,n)}findIndex(e){if(0==e)return ih(0,e);if(e==this.size)return ih(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e){if(r==e)return ih(t+1,r);return ih(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(e,t){if(!t)return iu.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iu.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iu.empty;let t,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new iu(t||e,n)}static from(e){if(!e)return iu.empty;if(e instanceof iu)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iu([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iu.empty=new iu([],0);let ip={index:0,offset:0};function ih(e,t){return ip.index=e,ip.offset=t,ip}function im(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(!im(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!im(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class ig{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}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&&im(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 RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw 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(e){if(!e||Array.isArray(e)&&0==e.length)return ig.none;if(e instanceof ig)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}ig.none=[];class ib extends Error{}class ix{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=function e(t,n,r,i,s,o){let{index:a,offset:l}=t.findIndex(n),c=t.maybeChild(a);if(l==n||c.isText)return o&&i<=0&&s<=0&&!o.canReplace(a,a,r)?null:t.cut(0,n).append(r).append(t.cut(n));let d=e(c.content,n-l-1,r,0==a?i-1:0,a==t.childCount-1?s-1:0,c);return d&&t.replaceChild(a,c.copy(d))}(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new ix(n,this.openStart,this.openEnd)}removeBetween(e,t){return new ix(function e(t,n,r){let{index:i,offset:s}=t.findIndex(n),o=t.maybeChild(i),{index:a,offset:l}=t.findIndex(r);if(s==n||o.isText){if(l!=r&&!t.child(a).isText)throw RangeError("Removing non-flat range");return t.cut(0,n).append(t.cut(r))}if(i!=a)throw RangeError("Removing non-flat range");return t.replaceChild(i,o.copy(e(o.content,n-s-1,r-s-1)))}(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return ix.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw RangeError("Invalid input for Slice.fromJSON");return new ix(iu.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new ix(e,n,r)}}function iy(e,t){if(!t.type.compatibleContent(e.type))throw new ib("Cannot join "+t.type.name+" onto "+e.type.name)}function iv(e,t,n){let r=e.node(n);return iy(r,t.node(n)),r}function iw(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function ik(e,t,n,r){let i=(t||e).node(n),s=0,o=t?t.index(n):i.childCount;e&&(s=e.index(n),e.depth>n?s++:e.textOffset&&(iw(e.nodeAfter,r),s++));for(let e=s;e<o;e++)iw(i.child(e),r);t&&t.depth==n&&t.textOffset&&iw(t.nodeBefore,r)}function iN(e,t){return e.type.checkContent(t),e.copy(t)}function iS(e,t,n){let r=[];return ik(null,e,n,r),e.depth>n&&iw(iN(iv(e,t,n+1),iS(e,t,n+1)),r),ik(t,null,n,r),new iu(r)}ix.empty=new ix(iu.empty,0,0);class iC{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return ig.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var s=0;s<i.length;s++)!1!==i[s].type.spec.inclusive||r&&i[s].isInSet(r.marks)||(i=i[s--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new iA(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:s}=t.content.findIndex(i),o=i-s;if(n.push(t,e,r+s),!o||(t=t.child(e)).isText)break;i=o-1,r+=s+1}return new iC(t,n,i)}static resolveCached(e,t){let n=iM.get(e);if(n)for(let e=0;e<n.elts.length;e++){let r=n.elts[e];if(r.pos==t)return r}else iM.set(e,n=new ij);let r=n.elts[n.i]=iC.resolve(e,t);return n.i=(n.i+1)%iE,r}}class ij{constructor(){this.elts=[],this.i=0}}let iE=12,iM=new WeakMap;class iA{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let iT=Object.create(null);class iO{constructor(e,t,n,r=ig.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iu.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&im(this.attrs,t||e.defaultAttrs||iT)&&ig.sameSet(this.marks,n||ig.none)}copy(e=null){return e==this.content?this:new iO(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new iO(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return ix.empty;let r=this.resolve(e),i=this.resolve(t),s=n?0:r.sharedDepth(t),o=r.start(s);return new ix(r.node(s).content.cut(r.pos-o,i.pos-o),r.depth-s,i.depth-s)}replace(e,t,n){var r=this.resolve(e),i=this.resolve(t);if(n.openStart>r.depth)throw new ib("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new ib("Inconsistent open depths");return function e(t,n,r,i){let s=t.index(i),o=t.node(i);if(s==n.index(i)&&i<t.depth-r.openStart){let a=e(t,n,r,i+1);return o.copy(o.content.replaceChild(s,a))}if(!r.content.size)return iN(o,iS(t,n,i));if(r.openStart||r.openEnd||t.depth!=i||n.depth!=i){let{start:e,end:s}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(iu.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return iN(o,function e(t,n,r,i,s){let o=t.depth>s&&iv(t,n,s+1),a=i.depth>s&&iv(r,i,s+1),l=[];return ik(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iy(o,a),iw(iN(o,e(t,n,r,i,s+1)),l)):(o&&iw(iN(o,iS(t,n,s+1)),l),ik(n,r,s,l),a&&iw(iN(a,iS(r,i,s+1)),l)),ik(i,null,s,l),new iu(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return iN(e,i.cut(0,t.parentOffset).append(r.content).append(i.cut(n.parentOffset)))}}(r,i,n,0)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(!(t=t.maybeChild(n)))return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return iC.resolveCached(this,e)}resolveNoCache(e){return iC.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),iD(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=iu.empty,r=0,i=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,r,i),o=s&&s.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),s=i&&i.matchFragment(this.content,t);return!!s&&s.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=ig.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!ig.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){let n;if(!t)throw RangeError("Invalid input for Node.fromJSON");if(t.marks){if(!Array.isArray(t.marks))throw RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=iu.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}iO.prototype.text=void 0;class i_ extends iO{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):iD(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new i_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new i_(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function iD(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class iR{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new iI(e,t);if(null==i.next)return iR.empty;let s=function e(t){let n=[];do n.push(function(t){let n=[];do n.push(function(t){let n=function(t){if(t.eat("(")){let n=e(t);return t.eat(")")||t.err("Missing closing paren"),n}if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=(function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return 0==i.length&&e.err("No node type or group '"+t+"' found"),i})(t,t.next).map(e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}}(t);for(;;)if(t.eat("+"))n={type:"plus",expr:n};else if(t.eat("*"))n={type:"star",expr:n};else if(t.eat("?"))n={type:"opt",expr:n};else if(t.eat("{"))n=function(e,t){let n=iL(e),r=n;return e.eat(",")&&(r="}"!=e.next?iL(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}(t,n);else break;return n}(t));while(t.next&&")"!=t.next&&"|"!=t.next)return 1==n.length?n[0]:{type:"seq",exprs:n}}(t));while(t.eat("|"))return 1==n.length?n[0]:{type:"choice",exprs:n}}(i);i.next&&i.err("Unexpected trailing text");let o=(n=function(e){let t=[[]];return i(function e(t,s){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,s)),[]);if("seq"==t.type)for(let r=0;;r++){let o=e(t.exprs[r],s);if(r==t.exprs.length-1)return o;i(o,s=n())}else if("star"==t.type){let o=n();return r(s,o),i(e(t.expr,o),o),[r(o)]}else if("plus"==t.type){let o=n();return i(e(t.expr,s),o),i(e(t.expr,o),o),[r(o)]}else if("opt"==t.type)return[r(s)].concat(e(t.expr,s));else if("range"==t.type){let o=s;for(let r=0;r<t.min;r++){let r=n();i(e(t.expr,o),r),o=r}if(-1==t.max)i(e(t.expr,o),o);else for(let s=t.min;s<t.max;s++){let s=n();r(o,s),i(e(t.expr,o),s),o=s}return[r(o)]}else if("name"==t.type)return[r(s,void 0,t.value)];else throw Error("Unknown expr type")}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}}(s),r=Object.create(null),function e(t){let i=[];t.forEach(e=>{n[e].forEach(({term:e,to:t})=>{let r;if(e){for(let t=0;t<i.length;t++)i[t][0]==e&&(r=i[t][1]);iz(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new iR(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(iP);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(iz(n,0)));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,s=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];s.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),-1==r.indexOf(o)&&r.push(o)}i&&t.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(o,i),o}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 i=t;r&&i<n;i++)r=r.matchType(e.child(i).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 i(s,o){let a=s.matchFragment(e,n);if(a&&(!t||a.validEnd))return iu.from(o.map(e=>e.createAndFill()));for(let e=0;e<s.next.length;e++){let{type:t,next:n}=s.next[e];if(!(t.isText||t.hasRequiredAttrs())&&-1==r.indexOf(n)){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+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(),i=r.match;if(i.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<i.next.length;e++){let{type:s,next:o}=i.next[e];s.isLeaf||s.hasRequiredAttrs()||s.name in t||r.type&&!o.validEnd||(n.push({match:s.contentMatch,type:s,via:r}),t[s.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw 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 n=0;n<t.next.length;n++)r+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return r}).join("\n")}}iR.empty=new iR(!0);class iI{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 SyntaxError(e+" (in content expression '"+this.string+"')")}}function iL(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function iP(e,t){return t-e}function iz(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:s}=i[e];r||-1!=n.indexOf(s)||t(s)}}(t),n.sort(iP)}function i$(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function iB(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function iF(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function iH(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new iV(e,r,t[r]);return n}class iU{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=iH(e,n.attrs),this.defaultAttrs=i$(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==iR.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:iB(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new iO(this,this.computeAttrs(e),iu.from(t),ig.setFrom(n))}createChecked(e=null,t,n){return t=iu.from(t),this.checkContent(t),new iO(this,this.computeAttrs(e),t,ig.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iu.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(iu.empty,!0);return i?new iO(this,e,t.append(i),ig.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){iF(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){let t;if(null==this.markSet)return e;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:ig.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new iU(e,t,r));let r=t.spec.topNode||"doc";if(!n[r])throw RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw RangeError("The text node type should not have attributes");return n}}class iV{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let r=n.split("|");return n=>{let i=null===n?"null":typeof n;if(0>r.indexOf(i))throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class iW{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=iH(e,r.attrs),this.excluded=null;let i=i$(this.attrs);this.instance=i?new ig(this,i):null}create(e=null){return!e&&this.instance?this.instance:new ig(this,iB(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new iW(e,r++,t,i)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){iF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class iq{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=id.from(e.nodes),t.marks=id.from(e.marks||{}),this.nodes=iU.compile(this.spec.nodes,this),this.marks=iW.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],r=t.spec.content||"",i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=iR.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==i?null:i?iK(this,i.split(" ")):""!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:iK(this,n.split(" "))}this.nodeFromJSON=e=>iO.fromJSON(this,e),this.markFromJSON=e=>ig.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else if(e instanceof iU){if(e.schema!=this)throw RangeError("Node type from different schema used ("+e.name+")")}else throw RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new i_(n,n.defaultAttrs,e,ig.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError("Unknown node type: "+e);return t}}function iK(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],s=e.marks[i],o=s;if(s)n.push(s);else for(let t in e.marks){let r=e.marks[t];("_"==i||r.spec.group&&r.spec.group.split(" ").indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class iG{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(null!=e.tag)this.tags.push(e);else if(null!=e.style){let t=/[^=]*/.exec(e.style)[0];0>n.indexOf(t)&&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 i0(this,t,!1);return n.addAll(e,ig.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new i0(this,t,!0);return n.addAll(e,ig.none,t.from,t.to),ix.maxOpen(n.finish())}matchTag(e,t,n){for(let s=n?this.tags.indexOf(n)+1:0;s<this.tags.length;s++){var r,i;let n=this.tags[s];if(r=e,i=n.tag,(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,i)&&(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 i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],s=r.style;if(0==s.indexOf(e)&&(!r.context||n.matchesContext(r.context))&&(!(s.length>e.length)||61==s.charCodeAt(e.length)&&s.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 t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=i1(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=i1(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new iG(e,iG.schemaRules(e)))}}let iJ={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},iZ={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},iX={ol:!0,ul:!0};function iY(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class iQ{constructor(e,t,n,r,i,s){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=s,this.content=[],this.activeMarks=ig.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iu.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e=this.content[this.content.length-1],t;e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))&&(e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length)))}let t=iu.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iu.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&&!iJ.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class i0{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,s=iY(null,t.preserveWhitespace,0)|4*!!n;i=r?new iQ(r.type,r.attrs,ig.none,!0,t.topMatch||r.type.contentMatch,s):n?new iQ(null,null,ig.none,!0,null,s):new iQ(e.schema.topNodeType,null,ig.none,!0,null,s),this.nodes=[i],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,i=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:s}=this.parser;if("full"===i||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)if("full"===i)n=n.replace(/\r\n?/g,"\n");else if(s.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(s.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(s.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(s.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],i=e.previousSibling;(!t||i&&"BR"==i.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(s.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;iX.hasOwnProperty(s)&&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&&iX.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));e:if(a?a.ignore:iZ.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,r=this.needsBlock;if(iJ.hasOwnProperty(s))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=a&&a.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?o: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 e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1===n.consuming)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,s;if(t.node)if((s=this.parser.schema.nodes[t.node]).isLeaf)this.insertNode(s.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(s,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(s&&s.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)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let s=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,s=0;t>=0;t--){let o=this.nodes[t],a=o.findWrapping(e);if(a&&(!r||r.length>a.length+s)&&(r=a,i=o,!a.length))break;if(o.solid){if(n)break;s+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],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=ig.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):i2(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&(i=this.enterInner(e,t,n,!0,r)),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=iY(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=ig.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!i2(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new iQ(e,t,a,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;else 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),i=-(n?n.depth+1:0)+ +!r,s=(e,o)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;o>=i;o--)if(s(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;o--}}return!0};return s(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 e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function i1(e){let t={};for(let n in e)t[n]=e[n];return t}function i2(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let s=[],o=e=>{s.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||0>s.indexOf(i)&&o(i))return!0}};if(o(i.contentMatch))return!0}}class i3{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=i4(t).createDocumentFragment());let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,s=0;for(;n<i.length&&s<e.marks.length;){let t=e.marks[s];if(!this.marks[t.type.name]){s++;continue}if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,s++}for(;n<i.length;)r=i.pop()[1];for(;s<e.marks.length;){let n=e.marks[s++],o=this.serializeMark(n,e.isInline,t);o&&(i.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 i4(t).createTextNode(e.text);let{dom:n,contentDOM:r}=i9(i4(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw 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 i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&i9(i4(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:i9(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new i3(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=i5(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return i5(e.marks)}}function i5(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function i4(e){return e.document||window.document}let i6=new WeakMap;function i9(e,t,n,r){let i,s,o;if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let a=t[0],l;if("string"!=typeof a)throw RangeError("Invalid array passed to renderSpec");if(r&&(void 0===(s=i6.get(r))&&i6.set(r,(o=null,!function e(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])o||(o=[]),o.push(t);else for(let n=0;n<t.length;n++)e(t[n]);else for(let n in t)e(t[n])}(r),s=o)),l=s)&&l.indexOf(t)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let c=a.indexOf(" ");c>0&&(n=a.slice(0,c),a=a.slice(c+1));let d=n?e.createElementNS(n,a):e.createElement(a),u=t[1],p=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){for(let e in p=2,u)if(null!=u[e]){let t=e.indexOf(" ");t>0?d.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):"style"==e&&d.style?d.style.cssText=u[e]:d.setAttribute(e,u[e])}}for(let s=p;s<t.length;s++){let o=t[s];if(0===o){if(s<t.length-1||s>p)throw RangeError("Content hole must be the only child of its parent node");return{dom:d,contentDOM:d}}if("string"==typeof o)d.appendChild(e.createTextNode(o));else{let{dom:t,contentDOM:s}=i9(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class i7{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}}class i8{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&i8.empty)return i8.empty}recover(e){let t=0,n=65535&e;if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+(e-(65535&e))/65536}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,i=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let a=this.ranges[o]-(this.inverted?r:0);if(a>e)break;let l=this.ranges[o+i],c=this.ranges[o+s],d=a+l;if(e<=d){let i=l?e==a?-1:e==d?1:t:t,s=a+r+(i<0?0:c);if(n)return s;let u=e==(t<0?a:d)?null:o/3+(e-a)*65536,p=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(p|=8),new i7(s,p,u)}r+=c-l}return n?e+r:new i7(e+r,0,null)}touches(e,t){let n=0,r=65535&t,i=this.inverted?2:1,s=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let a=this.ranges[t+i];if(e<=o+a&&t==3*r)return!0;n+=this.ranges[t+s]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let s=this.ranges[r],o=s-(this.inverted?i:0),a=s+(this.inverted?0:i),l=this.ranges[r+t],c=this.ranges[r+n];e(o,o+l,a,a+c),i+=c-l}}invert(){return new i8(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?i8.empty:new i8(e<0?[0,-e,0]:[0,0,e])}}i8.empty=new i8([]);class se{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new se(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],null!=r&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new se;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new i7(e,r,null)}}let st=Object.create(null);class sn{getMap(){return i8.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=st[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in st)throw RangeError("Duplicate use of step JSON ID "+e);return st[e]=t,t.prototype.jsonID=e,t}}class sr{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sr(e,null)}static fail(e){return new sr(null,e)}static fromReplace(e,t,n,r){try{return sr.ok(e.replace(t,n,r))}catch(e){if(e instanceof ib)return sr.fail(e.message);throw e}}}function si(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(si(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iu.fromArray(r)}class ss extends sn{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)),i=new ix(si(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 sr.fromReplace(e,this.from,this.to,i)}invert(){return new so(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new ss(t.pos,n.pos,this.mark)}merge(e){return e instanceof ss&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ss(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new ss(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("addMark",ss);class so extends sn{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 ix(si(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sr.fromReplace(e,this.from,this.to,n)}invert(){return new ss(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new so(t.pos,n.pos,this.mark)}merge(e){return e instanceof so&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new so(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new so(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("removeMark",so);class sa extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new sa(this.pos,t.marks[n]);return new sa(this.pos,this.mark)}}return new sl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sa(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new sa(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("addNodeMark",sa);class sl extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sa(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sl(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new sl(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("removeNodeMark",sl);class sc extends sn{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&su(e,this.from,this.to)?sr.fail("Structure replace would overwrite content"):sr.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new i8([this.from,this.to-this.from,this.slice.size])}invert(e){return new sc(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&sc.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sc(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sc)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart)if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;else{let t=this.slice.size+e.slice.size==0?ix.empty:new ix(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new sc(e.from,this.to,t,this.structure)}{let t=this.slice.size+e.slice.size==0?ix.empty:new ix(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new sc(this.from,this.to+(e.to-e.from),t,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(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new sc(t.from,t.to,ix.fromJSON(e,t.slice),!!t.structure)}}sc.MAP_BIAS=1,sn.jsonID("replace",sc);class sd extends sn{constructor(e,t,n,r,i,s,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=s,this.structure=o}apply(e){if(this.structure&&(su(e,this.from,this.gapFrom)||su(e,this.gapTo,this.to)))return sr.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sr.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sr.fromReplace(e,this.from,this.to,n):sr.fail("Content does not fit in gap")}getMap(){return new i8([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new sd(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new sd(t.pos,n.pos,r,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(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new sd(t.from,t.to,t.gapFrom,t.gapTo,ix.fromJSON(e,t.slice),t.insert,!!t.structure)}}function su(e,t,n){let r=e.resolve(t),i=n-t,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let e=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function sp(e,t,n,r=n.contentMatch,i=!0){let s=e.doc.nodeAt(t),o=[],a=t+1;for(let t=0;t<s.childCount;t++){let l=s.child(t),c=a+l.nodeSize,d=r.matchType(l.type);if(d){r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new so(a,c,l.marks[t]));if(i&&l.isText&&"pre"!=n.whitespace){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||(r=new ix(iu.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sc(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sc(a,c,ix.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iu.empty,!0);e.replace(a,a,new ix(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function sh(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let s=e.$from.node(n),o=e.$from.index(n)+r,a=e.$to.indexAfter(n)-i;if(n<e.depth&&s.canReplace(o,a,t))return n;if(0==n||s.type.spec.isolating||!((0==o||s.canReplace(o,s.childCount))&&(a==s.childCount||s.canReplace(0,a))))break;o&&(r=1),a<s.childCount&&(i=1)}return null}function sf(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.contentMatchAt(r).findWrapping(t);if(!s)return null;let o=s.length?s[0]:t;return n.canReplaceWith(r,i,o)?s:null}(e,t),s=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.child(r),o=t.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?o:null}(r,t);return s?i.map(sm).concat({type:t,attrs:n}).concat(s.map(sm)):null}function sm(e){return{type:e,attrs:null}}function sg(e,t,n,r){t.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let i=e.mapping.slice(r).map(n+1+s+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function sb(e,t,n,r){t.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+s);e.replaceWith(i,i+1,t.type.schema.text("\n"))}})}function sx(e,t,n=1,r){let i=e.resolve(t),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>s;e--,t--){let n=i.node(e),s=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(s,n.childCount),a=r&&r[t+1];a&&(o=o.replaceChild(0,a.type.create(a.attrs)));let l=r&&r[t]||n;if(!n.canReplace(s+1,n.childCount)||!l.type.validContent(o))return!1}let a=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(a,a,l?l.type:i.node(s+1).type)}function sy(e,t){let n=e.resolve(t),r=n.index();return sv(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sv(e,t){return!!(e&&t&&!e.isLeaf&&function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let s=t.child(i),o=s.type==r?e.type.schema.nodes.text:s.type;if(!(n=n.matchType(o))||!e.type.allowsMarks(s.marks))return!1}return n.validEnd}(e,t))}function sw(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,s,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,s=r.nodeAfter):n>0?(i=r.node(e+1),o++,s=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),s=r.node(e+1)),i&&!i.isTextblock&&sv(i,s)&&r.node(e).canReplace(o,o+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function sk(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,s=r.index(t)+ +(n>0),o=r.node(t),a=!1;if(1==e)a=o.canReplace(s,s,i);else{let e=o.contentMatchAt(s).findWrapping(i.firstChild.type);a=e&&o.canReplaceWith(s,s,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function sN(e,t,n=t,r=ix.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return sS(i,s,r)?new sc(t,n,r):new sC(i,s,r).fit()}function sS(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sn.jsonID("replaceAround",sd);class sC{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iu.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=iu.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,s=n.depth,o=r.depth;for(;s&&o&&1==i.childCount;)i=i.firstChild.content,s--,o--;let a=new ix(i,s,o);return e>-1?new sd(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sc(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e=null,r=(n?(e=sM(this.unplaced.content,n-1).firstChild).content:this.unplaced.content).firstChild;for(let i=this.depth;i>=0;i--){let{type:s,match:o}=this.frontier[i],a,l=null;if(1==t&&(r?o.matchType(r.type)||(l=o.fillBefore(iu.from(r),!1)):e&&s.compatibleContent(e.type)))return{sliceDepth:n,frontierDepth:i,parent:e,inject:l};if(2==t&&r&&(a=o.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:e,wrap:a};if(e&&o.matchType(e.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=sM(e,t);return!!r.childCount&&!r.firstChild.isLeaf&&(this.unplaced=new ix(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=sM(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new ix(sj(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new ix(sj(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let s=this.unplaced,o=n?n.content:s.content,a=s.openStart-e,l=0,c=[],{match:d,type:u}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)c.push(r.child(e));d=d.matchFragment(r)}let p=o.size+e-(s.content.size-s.openEnd);for(;l<o.childCount;){let e=o.child(l),t=d.matchType(e.type);if(!t)break;(++l>1||0==a||e.content.size)&&(d=t,c.push(function e(t,n,r){if(n<=0)return t;let i=t.content;return n>1&&(i=i.replaceChild(0,e(i.firstChild,n-1,1==i.childCount?r-1:0))),n>0&&(i=t.type.contentMatch.fillBefore(i).append(i),r<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(iu.empty,!0)))),t.copy(i)}(e.mark(u.allowedMarks(e.marks)),1==l?a:0,l==o.childCount?p:-1)))}let h=l==o.childCount;h||(p=-1),this.placed=sE(this.placed,t,iu.from(c)),this.frontier[t].match=d,h&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=h?0==e?ix.empty:new ix(sj(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new ix(sj(s.content,e,l),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!sA(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return -1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){t:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),s=sA(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=sA(e,n,r,t,!0);if(!i||i.childCount)continue t}return{depth:t,fit:s,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=sE(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=sE(this.placed,this.depth,iu.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iu.empty,!0);e.childCount&&(this.placed=sE(this.placed,this.frontier.length,e))}}function sj(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(sj(e.firstChild.content,t-1,n)))}function sE(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(sE(e.lastChild.content,t-1,n)))}function sM(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function sA(e,t,n,r,i){let s=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,s.content,o)?a:null}function sT(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}class sO extends sn{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 sr.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(r),0,+!t.isLeaf))}getMap(){return i8.empty}invert(e){return new sO(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sO(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new sO(t.pos,t.attr,t.value)}}sn.jsonID("attr",sO);class s_ extends sn{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return sr.ok(n)}getMap(){return i8.empty}invert(e){return new s_(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new s_(t.attr,t.value)}}sn.jsonID("docAttr",s_);let sD=class extends Error{};(sD=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),sD.prototype.constructor=sD,sD.prototype.name="TransformError";class sR{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new se}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new sD(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,s)=>{e=Math.min(e,i),t=Math.max(t,s)})}return 1e9==e?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=ix.empty){let r=sN(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new ix(iu.from(n),0,0))}delete(e,t){return this.replace(e,t,ix.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return!function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),s=e.doc.resolve(n);if(sS(i,s,r))return e.step(new sc(t,n,r));let o=sT(i,s);0==o[o.length-1]&&o.pop();let a=-(i.depth+1);o.unshift(a);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?a=e:i.before(e)==t&&o.splice(1,0,-e)}let l=o.indexOf(a),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){var u;let t=c[e],n=(u=t.type).spec.defining||u.spec.definingForContent;if(n&&!t.sameMarkup(i.node(Math.abs(a)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let a=(t+d+1)%(r.openStart+1),u=c[a];if(u)for(let t=0;t<o.length;t++){let c=o[(t+l)%o.length],d=!0;c<0&&(d=!1,c=-c);let p=i.node(c-1),h=i.index(c-1);if(p.canReplaceWith(h,h,u.type,u.marks))return e.replace(i.before(c),d?s.after(c):n,new ix(function e(t,n,r,i,s){if(n<r){let s=t.firstChild;t=t.replaceChild(0,s.copy(e(s.content,n+1,r,i,s)))}if(n>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(iu.empty,!0))}return t}(r.content,0,r.openStart,a),a,r.openEnd))}}let p=e.steps.length;for(let a=o.length-1;a>=0&&(e.replace(t,n,r),!(e.steps.length>p));a--){let e=o[a];e<0||(t=i.before(e),n=s.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){var r=e,i=t;if(!n.isInline&&r==i&&this.doc.resolve(r).parent.content.size){let e=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)break}return null}(this.doc,r,n.type);null!=e&&(r=i=e)}return this.replaceRange(r,i,new ix(iu.from(n),0,0)),this}deleteRange(e,t){return!function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&0==r.parentOffset&&0==i.parentOffset){let s=r.sharedDepth(n),o=!1;for(let e=r.depth;e>s;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>s;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let s=sT(r,i);for(let t=0;t<s.length;t++){let n=s[t],o=t==s.length-1;if(o&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(t-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return e.delete(r.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return!function(e,t,n){let{$from:r,$to:i,depth:s}=t,o=r.before(s+1),a=i.after(s+1),l=o,c=a,d=iu.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iu.from(r.node(e).copy(d)),u++):l--;let p=iu.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iu.from(i.node(e).copy(p)),h++):c++;e.step(new sd(l,c,o,a,new ix(d.append(p),u,h),d.size-u,!0))}(this,e,t),this}join(e,t=1){return!function(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,s=e.doc.resolve(t-n),o=s.node().type;if(i&&o.inlineContent){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let a=e.steps.length;if(!1===r){let r=e.doc.resolve(t+n);sb(e,r.node(),r.before(),a)}o.inlineContent&&sp(e,t+n-1,o,s.node().contentMatchAt(s.index()),null==r);let l=e.mapping.slice(a),c=l.map(t-n);if(e.step(new sc(c,l.map(t+n,-1),ix.empty,!0)),!0===r){let t=e.doc.resolve(c);sg(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iu.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=iu.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sd(i,s,i,s,new ix(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){var i=this;if(!n.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;return i.doc.nodesBetween(e,t,(e,t)=>{var o,a,l;let c,d,u="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(n,u)&&(o=i.doc,a=i.mapping.slice(s).map(t),l=n,d=(c=o.resolve(a)).index(),c.parent.canReplaceWith(d,d+1,l))){let r=null;if(n.schema.linebreakReplacement){let e="pre"==n.whitespace,t=!!n.contentMatch.matchType(n.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&sb(i,e,t,s),sp(i,i.mapping.slice(s).map(t,1),n,void 0,null===r);let o=i.mapping.slice(s),a=o.map(t,1),l=o.map(t+e.nodeSize,1);return i.step(new sd(a,l,a+1,l-1,new ix(iu.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sg(i,e,t,s),!1}}),this}setNodeMarkup(e,t,n=null,r){return!function(e,t,n,r,i){let s=e.doc.nodeAt(t);if(!s)throw RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,o);if(!n.validContent(s.content))throw RangeError("Invalid content for node type "+n.name);e.step(new sd(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new ix(iu.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new sO(e,t,n)),this}setDocAttribute(e,t){return this.step(new s_(e,t)),this}addNodeMark(e,t){return this.step(new sa(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof ig)t.isInSet(n.marks)&&this.step(new sl(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sl(e,i)),r=i.removeFromSet(r);for(let e=s.length-1;e>=0;e--)this.step(s[e])}return this}split(e,t=1,n){return!function(e,t,n=1,r){let i=e.doc.resolve(t),s=iu.empty,o=iu.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iu.from(i.node(e).copy(s));let t=r&&r[a];o=iu.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sc(t,t,new ix(s.append(o),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){var r;let i,s,o,a;return r=this,o=[],a=[],r.doc.nodesBetween(e,t,(r,l,c)=>{if(!r.isInline)return;let d=r.marks;if(!n.isInSet(d)&&c.type.allowsMarkType(n.type)){let c=Math.max(l,e),u=Math.min(l+r.nodeSize,t),p=n.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(i&&i.to==c&&i.mark.eq(d[e])?i.to=u:o.push(i=new so(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new ss(c,u,n))}}),o.forEach(e=>r.step(e)),a.forEach(e=>r.step(e)),this}removeMark(e,t,n){var r;let i,s;return r=this,i=[],s=0,r.doc.nodesBetween(e,t,(r,o)=>{if(!r.isInline)return;s++;let a=null;if(n instanceof iW){let e=r.marks,t;for(;t=n.isInSet(e);)(a||(a=[])).push(t),e=t.removeFromSet(e)}else n?n.isInSet(r.marks)&&(a=[n]):a=r.marks;if(a&&a.length){let n=Math.min(o+r.nodeSize,t);for(let t=0;t<a.length;t++){let r=a[t],l;for(let e=0;e<i.length;e++){let t=i[e];t.step==s-1&&r.eq(i[e].style)&&(l=t)}l?(l.to=n,l.step=s):i.push({style:r,from:Math.max(o,e),to:n,step:s})}}}),i.forEach(e=>r.step(new so(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sp(this,e,t,n),this}}let sI=Object.create(null);class sL{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new sP(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=ix.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:a,$to:l}=s[o],c=e.mapping.slice(i);e.replaceRange(c.map(a.pos),c.map(l.pos),o?ix.empty:t),0==o&&sK(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n),l=a.map(s.pos),c=a.map(o.pos);i?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),sK(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new sB(e):sq(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?sq(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):sq(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new sV(e.node(0))}static atStart(e){return sq(e,e,0,0,1)||new sV(e)}static atEnd(e){return sq(e,e,e.content.size,e.childCount,-1)||new sV(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=sI[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sI)throw RangeError("Duplicate use of selection JSON ID "+e);return sI[e]=t,t.prototype.jsonID=e,t}getBookmark(){return sB.between(this.$anchor,this.$head).getBookmark()}}sL.prototype.visible=!0;class sP{constructor(e,t){this.$from=e,this.$to=t}}let sz=!1;function s$(e){sz||e.parent.inlineContent||(sz=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class sB extends sL{constructor(e,t=e){s$(e),s$(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return sL.near(n);let r=e.resolve(t.map(this.anchor));return new sB(r.parent.inlineContent?r:n,n)}replace(e,t=ix.empty){if(super.replace(e,t),t==ix.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof sB&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new sF(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw RangeError("Invalid input for TextSelection.fromJSON");return new sB(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let e=sL.findFrom(t,n,!0)||sL.findFrom(t,-n,!0);if(!e)return sL.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(sL.findFrom(e,-n,!0)||sL.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new sB(e,t)}}sL.jsonID("text",sB);class sF{constructor(e,t){this.anchor=e,this.head=t}map(e){return new sF(e.map(this.anchor),e.map(this.head))}resolve(e){return sB.between(e.resolve(this.anchor),e.resolve(this.head))}}class sH extends sL{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?sL.near(i):new sH(i)}content(){return new ix(iu.from(this.node),0,0)}eq(e){return e instanceof sH&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new sU(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new sH(e.resolve(t.anchor))}static create(e,t){return new sH(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}sH.prototype.visible=!1,sL.jsonID("node",sH);class sU{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new sF(n,n):new sU(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&sH.isSelectable(n)?new sH(t):sL.near(t)}}class sV extends sL{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=ix.empty){if(t==ix.empty){e.delete(0,e.doc.content.size);let t=sL.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new sV(e)}map(e){return new sV(e)}eq(e){return e instanceof sV}getBookmark(){return sW}}sL.jsonID("all",sV);let sW={map(){return this},resolve:e=>new sV(e)};function sq(e,t,n,r,i,s=!1){if(t.inlineContent)return sB.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(r.isAtom){if(!s&&sH.isSelectable(r))return sH.create(e,n-(i<0?r.nodeSize:0))}else{let t=sq(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function sK(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sc||s instanceof sd)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(sL.near(e.doc.resolve(r),n)))}class sG extends sR{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(1|this.updated)&-3,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return ig.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||ig.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(sL.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function sJ(e,t){return t&&e?e.bind(t):e}class sZ{constructor(e,t,n){this.name=e,this.init=sJ(t.init,n),this.apply=sJ(t.apply,n)}}let sX=[new sZ("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new sZ("selection",{init:(e,t)=>e.selection||sL.atStart(t.doc),apply:e=>e.selection}),new sZ("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new sZ("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class sY{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=sX.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new sZ(e.key,e.spec.state,e))})}}class sQ{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let s=0;s<this.config.plugins.length;s++){let o=this.config.plugins[s];if(o.spec.appendTransaction){let a=r?r[s].n:0,l=r?r[s].state:this,c=a<t.length&&o.spec.appendTransaction.call(o,a?t.slice(a):t,l,n);if(c&&n.filterTransaction(c,s)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<s?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),i=!0}r&&(r[s]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw RangeError("Applying a mismatched transaction");let t=new sQ(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new sG(this)}static create(e){let t=new sY(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new sQ(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new sY(this.schema,e.plugins),n=t.fields,r=new sQ(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw RangeError("Required config field 'schema' missing");let r=new sY(e.schema,e.plugins),i=new sQ(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=iO.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=sL.fromJSON(i.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let s in n){let o=n[s],a=o.spec.state;if(o.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,s)){i[r.name]=a.fromJSON.call(o,e,t[s],i);return}}i[r.name]=r.init(e,i)}}),i}}class s0{constructor(e){this.spec=e,this.props={},e.props&&function e(t,n,r){for(let i in t){let s=t[i];s instanceof Function?s=s.bind(n):"handleDOMEvents"==i&&(s=e(s,n,{})),r[i]=s}return r}(e.props,this,this.props),this.key=e.key?e.key.key:s2("plugin")}getState(e){return e[this.key]}}let s1=Object.create(null);function s2(e){return e in s1?e+"$"+ ++s1[e]:(s1[e]=0,e+"$")}class s3{constructor(e="key"){this.key=s2(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let s5=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},s4=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},s6=null,s9=function(e,t,n){let r=s6||(s6=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},s7=function(){s6=null},s8=function(e,t,n,r){return n&&(ot(e,t,n,r,-1)||ot(e,t,n,r,1))},oe=/^(img|br|input|textarea|hr)$/i;function ot(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:on(e))){let n=e.parentNode;if(!n||1!=n.nodeType||or(e)||oe.test(e.nodeName)||"false"==e.contentEditable)return!1;t=s5(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;let n=e.childNodes[t+(i<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable)if(null==(s=n.pmViewDesc)||!s.ignoreForSelection)return!1;else t+=i;else e=n,t=i<0?on(e):0}}}function on(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function or(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)}let oi=function(e){return e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oo(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oa="u">typeof navigator?navigator:null,ol="u">typeof document?document:null,oc=oa&&oa.userAgent||"",od=/Edge\/(\d+)/.exec(oc),ou=/MSIE \d/.exec(oc),op=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oc),oh=!!(ou||op||od),of=ou?document.documentMode:op?+op[1]:od?+od[1]:0,om=!oh&&/gecko\/(\d+)/i.test(oc);om&&(/Firefox\/(\d+)/.exec(oc)||[0,0])[1];let og=!oh&&/Chrome\/(\d+)/.exec(oc),ob=!!og,ox=og?+og[1]:0,oy=!oh&&!!oa&&/Apple Computer/.test(oa.vendor),ov=oy&&(/Mobile\/\w+/.test(oc)||!!oa&&oa.maxTouchPoints>2),ow=ov||!!oa&&/Mac/.test(oa.platform),ok=!!oa&&/Win/.test(oa.platform),oN=/Android \d/.test(oc),oS=!!ol&&"webkitFontSmoothing"in ol.documentElement.style,oC=oS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function oj(e,t){return"number"==typeof e?e:e[t]}function oE(e,t,n){let r=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,s=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(1!=o.nodeType){o=s4(o);continue}let e=o,n=e==s.body,a=n?function(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}(s):function(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}(e),l=0,c=0;if(t.top<a.top+oj(r,"top")?c=-(a.top-t.top+oj(i,"top")):t.bottom>a.bottom-oj(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+oj(i,"top")-a.top:t.bottom-a.bottom+oj(i,"bottom")),t.left<a.left+oj(r,"left")?l=-(a.left-t.left+oj(i,"left")):t.right>a.right-oj(r,"right")&&(l=t.right-a.right+oj(i,"right")),l||c)if(n)s.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,s=e.scrollTop-r;t={left:t.left-i,top:t.top-s,right:t.right-i,bottom:t.bottom-s}}let d=n?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o="absolute"==d?o.offsetParent:s4(o)}}function oM(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=s4(r));return t}function oA(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:s}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=s&&(r.scrollLeft=s)}}let oT=null;function oO(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function o_(e){return e.top<e.bottom||e.left<e.right}function oD(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(o_(e))return e}return Array.prototype.find.call(n,o_)||e.getBoundingClientRect()}let oR=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function oI(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=oS||om;if(3==r.nodeType)if(o&&(oR.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=oD(s9(r,i,i),n);if(om&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=oD(s9(r,i-1,i-1),-1);if(t.top==e.top){let n=oD(s9(r,i,i+1),-1);if(n.top!=e.top)return oL(n,n.left<t.left)}}return e}else{let e=i,t=i,s=n<0?1:-1;return n<0&&!i?(t++,s=-1):n>=0&&i==r.nodeValue.length?(e--,s=1):n<0?e--:t++,oL(oD(s9(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!0)}return oP(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1],t=3==e.nodeType?s9(e,on(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return oL(oD(t,1),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?s9(e,0,+!o):1==e.nodeType?e:null:null;if(t)return oL(oD(t,-1),!0)}return oL(oD(3==r.nodeType?s9(r):r,-n),n>=0)}function oL(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function oP(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function oz(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}let o$=/[\u0590-\u08ac]/,oB=null,oF=null,oH=!1;class oU{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){let r;if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}if(e==this.dom&&this.contentDOM)r=t>s5(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),s;if(i&&(!t||i.node))if(!n||!(s=i.nodeDOM)||(1==s.nodeType?s.contains(1==e.nodeType?e:e.parentNode):s==e))return i;else n=!1}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return -1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],s=t+i.size;if(s>e||i instanceof oZ){r=e-t;break}t=s}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof oV&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;(e=n?this.children[n-1]:null)&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?s5(e.dom)+1:0}}{let e,r=!0;for(;(e=n<this.children.length?this.children[n]:null)&&e.dom.parentNode!=this.contentDOM;n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?s5(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let s=n,o=0;;o++){let n=this.children[o],a=s+n.size;if(-1==r&&e<=a){let i=s+n.border;if(e>=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=s;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=s5(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||o==this.children.length-1)){t=a;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=s5(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}s=a}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),s=Math.max(e,t);for(let o=0,a=0;o<this.children.length;o++){let l=this.children[o],c=a+l.size;if(i>a&&s<c)return l.setSelection(e-a-l.border,t-a-l.border,n,r);a=c}let o=this.domFromPos(e,e?-1:1),a=t==e?o:this.domFromPos(t,t?-1:1),l=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((om||oy)&&e==t){let{node:e,offset:t}=o;if(3==e.nodeType){if((d=!!(t&&"\n"==e.nodeValue[t-1]))&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){"BR"==n.nodeName&&(o=a={node:n.parentNode,offset:s5(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(om&&c.focusNode&&c.focusNode!=a.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(r=!0)}if(!(r||d&&oy)&&s8(o.node,o.offset,c.anchorNode,c.anchorOffset)&&s8(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&om)){l.collapse(o.node,o.offset);try{e!=t&&l.extend(a.node,a.offset),u=!0}catch(e){}}if(!u){if(e>t){let e=o;o=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(o.node,o.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],s=n+i.size;if(n==s?e<=s&&t>=n:e<s&&t>n){let r=n+i.border,o=s-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==s?2:1,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=3:i.markDirty(e-r,t-r);return}i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=s}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class oV extends oU{constructor(e,t,n,r){let i,s=t.type.toDOM;if("function"==typeof s&&(s=s(n,()=>i?i.parent?i.parent.posBeforeChild(i):void 0:r)),!t.type.spec.raw){if(1!=s.nodeType){let e=document.createElement("span");e.appendChild(s),s=e}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class oW extends oU{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class oq extends oU{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(e,t,n,r){let i=r.nodeViews[t.type.name],s=i&&i(t,r,n);return s&&s.dom||(s=i3.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new oq(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let r=oq.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=o9(i,t,s,n)),e>0&&(i=o9(i,0,e,n));for(let e=0;e<i.length;e++)i[e].parent=r;return r.children=i,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class oK extends oU{constructor(e,t,n,r,i,s,o,a,l){super(e,[],i,s),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(e,t,n,r,i,s){let o=i.nodeViews[t.type.name],a,l=o&&o(t,i,()=>a?a.parent?a.parent.posBeforeChild(a):void 0:s,n,r),c=l&&l.dom,d=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=i3.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return(c=o2(c,n,t),l)?a=new oX(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new oJ(e,t,n,r,c,u,i):new oK(e,t,n,r,c,d||null,u,i,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>iu.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&o3(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,s=i&&i.pos>-1?i:null,o=i&&i.pos<0,a=new o4(this,s&&s.node,e);(function(e,t,n,r){let i=t.locals(e),s=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(s,o),n),s+=o.nodeSize}return}let o=0,a=[],l=null;for(let c=0;;){let d,u,p,h;for(;o<i.length&&i[o].to==s;){let e=i[o++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(o6);for(let e=0;e<u.length;e++)n(u[e],c,!!l)}else n(d,c,!!l);if(l)h=-1,p=l,l=null;else if(c<e.childCount)h=c,p=e.child(c++);else break;for(let e=0;e<a.length;e++)a[e].to<=s&&a.splice(e--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)a.push(i[o++]);let f=s+p.nodeSize;if(p.isText){let e=f;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<a.length;t++)a[t].to<e&&(e=a[t].to);e<f&&(l=p.cut(e-s),p=p.cut(0,e-s),f=e,h=-1)}else for(;o<i.length&&i[o].to<f;)o++;let m=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,m,t.forChild(s,p),h),s=f}})(this.node,this.innerDeco,(t,i,s)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!s&&a.syncToMarks(i==this.node.childCount?ig.none:this.node.child(i).marks,n,e,i),a.placeWidget(t,e,r)},(t,s,l,c)=>{let d;a.syncToMarks(t.marks,n,e,c),a.findNodeMatch(t,s,l,c)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=a.findIndexWithChild(i.node))>-1&&a.updateNodeAt(t,s,l,d,e)||a.updateNextNode(t,s,l,e,c,r)||a.addNode(t,s,l,e,r),r+=t.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(s&&this.protectLocalComposition(e,s),function e(t,n,r){let i=t.firstChild,s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=a.dom;if(l.parentNode==t){for(;l!=i;)i=o5(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof oq){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=o5(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),ov&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof sB)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(!this.node.inlineContent)return{node:i,pos:-1,text:""};{let e=i.nodeValue,s=function(e,t,n,r){for(let i=0,s=0;i<e.childCount&&s<=r;){let o=e.child(i++),a=s;if(s+=o.nodeSize,!o.isText)continue;let l=o.text;for(;i<e.childCount;){let t=e.child(i++);if(s+=t.nodeSize,!t.isText)break;l+=t.text}if(s>=n){if(s>=r&&l.slice(r-t.length-a,r-a)==t)return r-t.length;let e=a<r?l.lastIndexOf(t,r-a-1):-1;if(e>=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return -1}(this.node.content,e,n-t,r-t);return s<0?null:{node:i,pos:s,text:e}}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let s=new oW(this,i,t,r);e.input.compositionNodes.push(s),this.children=o9(this.children,n,n+r.length,e,s)}update(e,t,n,r){return 3!=this.dirty&&!!e.sameMarkup(this.node)&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(o3(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=o1(this.dom,this.nodeDOM,o0(this.outerDeco,this.node,t),o0(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function oG(e,t,n,r,i){o2(r,t,e);let s=new oK(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class oJ extends oK{constructor(e,t,n,r,i,s,o){super(e,t,n,r,i,null,s,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return 3!=this.dirty&&(0==this.dirty||!!this.inParent())&&!!e.sameMarkup(this.node)&&(this.updateOuterDeco(t),(0!=this.dirty||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new oJ(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(0==e||t==this.nodeDOM.nodeValue.length)&&(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class oZ extends oU{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class oX extends oK{constructor(e,t,n,r,i,s,o,a,l,c){super(e,t,n,r,i,s,o,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return(!!this.contentDOM||!!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}let oY=function(e){e&&(this.nodeName=e)};oY.prototype=Object.create(null);let oQ=[new oY];function o0(e,t,n){if(0==e.length)return oQ;let r=n?oQ[0]:new oY,i=[r];for(let s=0;s<e.length;s++){let o=e[s].type.attrs;if(o)for(let e in o.nodeName&&i.push(r=new oY(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new oY(t.isInline?"span":"div")),"class"==e?r.class=(r.class?r.class+" ":"")+s:"style"==e?r.style=(r.style?r.style+";":"")+s:"nodeName"!=e&&(r[e]=s))}}return i}function o1(e,t,n,r){if(n==oQ&&r==oQ)return t;let i=t;for(let t=0;t<r.length;t++){let s=r[t],o=n[t];if(t){let t;o&&o.nodeName==s.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==s.nodeName||((t=document.createElement(s.nodeName)).pmIsDeco=!0,t.appendChild(i),o=oQ[0]),i=t}!function(e,t,n){for(let r in t)"class"==r||"style"==r||"nodeName"==r||r in n||e.removeAttribute(r);for(let r in n)"class"!=r&&"style"!=r&&"nodeName"!=r&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<r.length;t++)-1==i.indexOf(r[t])&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)-1==r.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}(i,o||oQ[0],s)}return i}function o2(e,t,n){return o1(e,e,oQ,o0(t,n,1!=e.nodeType))}function o3(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function o5(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class o4{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,r=n.children.length,i=e.childCount,s=new Map,o=[];n:for(;i>0;){let a;for(;;)if(r){let e=n.children[r-1];if(e instanceof oq)n=e,r=e.children.length;else{a=e,r--;break}}else if(n==t)break n;else r=n.parent.children.indexOf(n),n=n.parent;let l=a.node;if(l){if(l!=e.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&!1!==e[i].type.spec.spanning;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[s])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=oq.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,r){let i=-1,s;if(r>=this.preMatch.index&&(s=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,n))i=this.top.children.indexOf(s,this.index);else for(let r=this.index,s=Math.min(this.top.children.length,r+5);r<s;r++){let s=this.top.children[r];if(s.matchesNode(e,t,n)&&!this.preMatch.matched.has(s)){i=r;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let s=this.top.children[r];return 3==s.dirty&&s.dom==s.contentDOM&&(s.dirty=2),!!s.update(e,t,n,i)&&(this.destroyBetween(this.index,r),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return -1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return -1}e=t}}updateNextNode(e,t,n,r,i,s){for(let o=this.index;o<this.top.children.length;o++){let a=this.top.children[o];if(a instanceof oK){let l=this.preMatch.matched.get(a);if(null!=l&&l!=i)return!1;let c=a.dom,d,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&3!=a.dirty&&o3(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,o),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(d=this.recreateWrapper(a,e,t,n,r,s)))return this.destroyBetween(this.index,o),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=2,d.updateChildren(r,s+1),d.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!o3(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=oK.create(this.top,t,n,r,i,s);if(o.contentDOM)for(let t of(o.children=e.children,e.children=[],o.children))t.parent=o;return e.destroy(),o}addNode(e,t,n,r,i){let s=oK.create(this.top,e,t,n,r,i);s.contentDOM&&s.updateChildren(r,i+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new oV(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof oq;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof oJ)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oy||ob)&&e&&"false"==e.dom.contentEditable&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let r=new oZ(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function o6(e,t){return e.type.side-t.type.side}function o9(e,t,n,r,i){let s=[];for(let o=0,a=0;o<e.length;o++){let l=e[o],c=a,d=a+=l.size;c>=n||d<=t?s.push(l):(c<t&&s.push(l.slice(0,t-c,r)),i&&(s.push(i),i=void 0),d>n&&s.push(l.slice(n-c,l.size,r)))}return s}function o7(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),s=i&&0==i.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),l,c;if(oi(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&sH.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==on(e);r||i;){if(e==n)return!0;let t=s5(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==on(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new sH(o==e?a:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let s=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(s.startContainer,s.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(s.endContainer,s.endOffset,-1))}if(t<0)return null;[l,o]=i==e.state.selection.anchor?[i,t]:[t,i],a=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!c){let n="pointer"==t||e.state.selection.head<a.pos&&!s?1:-1;c=aa(e,d,a,n)}return c}function o8(e){return e.editable?e.hasFocus():ac(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ae(e,t=!1){let n=e.state.selection;if(as(e,n),o8(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&ob){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&s8(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}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,s5(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oh&&of<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;at&&!(n instanceof sB)&&(n.$from.parent.inlineContent||(d=an(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=an(e,n.to))),e.docView.setSelection(l,c,e,t),at&&(d&&ai(d),u&&ai(u)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&((i=(r=e).dom.ownerDocument).removeEventListener("selectionchange",r.input.hideSelectionGuard),o=(s=r.domSelectionRange()).anchorNode,a=s.anchorOffset,i.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(s.anchorNode!=o||s.anchorOffset!=a)&&(i.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!o8(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let at=oy||ob&&ox<63;function an(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,s=r?n.childNodes[r-1]:null;if(oy&&i&&"false"==i.contentEditable)return ar(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return ar(i);else if(s)return ar(s)}}function ar(e){return e.contentEditable="true",oy&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ai(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function as(e,t){if(t instanceof sH){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ao(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ao(e)}function ao(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aa(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||sB.between(t,n,r)}function al(e){return(!e.editable||!!e.hasFocus())&&ac(e)}function ac(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(e){return!1}}function ad(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return s&&sL.findFrom(s,t)}function au(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ap(e,t,n){let r=e.state.selection;if(r instanceof sB){if(n.indexOf("s")>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let s=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return au(e,new sB(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=ad(e.state,t);return!!n&&n instanceof sH&&au(e,n)}else if(!(ow&&n.indexOf("m")>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,s;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return!!(i.isAtom||(s=e.docView.descAt(o))&&!s.contentDOM)&&(sH.isSelectable(i)?au(e,new sH(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!oS&&au(e,new sB(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof sH&&r.node.isInline)return au(e,new sB(t>0?r.$to:r.$from));let n=ad(e.state,t);return!!n&&au(e,n)}}function ah(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function af(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function am(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,s,o=!1;for(om&&1==n.nodeType&&r<ah(n)&&af(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(af(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(ag(n))break;else{let t=n.previousSibling;for(;t&&af(t,-1);)i=n.parentNode,s=s5(t),t=t.previousSibling;if(t)r=ah(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?ab(e,n,r):i&&ab(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=ah(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(af(i.childNodes[s],1))t=i,n=++s;else break}else if(ag(i))break;else{let r=i.nextSibling;for(;r&&af(r,1);)t=r.parentNode,n=s5(r)+1,r=r.nextSibling;if(r)s=0,o=ah(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&ab(e,t,n)}(e)}function ag(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function ab(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!or(e);)t=s5(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&&!or(e);)t=s5(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(oi(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:i}=e;setTimeout(()=>{e.state==i&&ae(e)},50)}function ax(e,t){let n=e.state.doc.resolve(t);if(!(ob||ok)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<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),i=(n.top+n.bottom)/2;if(i>r.top&&i<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 ay(e,t,n){let r=e.state.selection;if(r instanceof sB&&!r.empty||n.indexOf("s")>-1||ow&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=ad(e.state,t);if(n&&n instanceof sH)return au(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof sV?sL.near(n,t):sL.findFrom(n,t);return!!o&&au(e,o)}return!1}function av(e,t){if(!(e.state.selection instanceof sB))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let s=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let r=e.state.tr;return t<0?r.delete(n.pos-s.nodeSize,n.pos):r.delete(n.pos,n.pos+s.nodeSize),e.dispatch(r),!0}return!1}function aw(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function ak(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:s}=t;for(;i>1&&s>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,s--;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")||i3.fromSchema(e.state.schema),a=aT(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=aM[c.nodeName.toLowerCase()]);){for(let e=d.length-1;e>=0;e--){let t=a.createElement(d[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),u++}c=l.firstChild}return c&&1==c.nodeType&&c.setAttribute("data-pm-slice",`${i} ${s}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:l,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function aN(e,t,n,r,i){let s,o,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp("transformPastedText",n=>{t=n(t,a||r,e)}),a)return o=new ix(iu.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,i,r,e));if(n)o=n;else{let n=i.marks(),{schema:r}=e.state,o=i3.fromSchema(r);s=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),s=function(e){var t;let n,r=/^(\s*<meta [^>]*>)*/.exec(e);r&&(e=e.slice(r[0].length));let i=aT().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&aM[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(aO||(aO=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),aO.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),oS&&function(e){let t=e.querySelectorAll(ob?"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)}}(s);let c=s&&s.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;s=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||iG.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||aS.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch(t){return e}let{content:i,openStart:s,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=iu.from(t.create(r[e+1],i)),s++,o++}return new ix(i,s,o)}(aE(o,+d[1],+d[2]),d[4]);else if((o=ix.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,s=[];if(e.forEach(e=>{if(!s)return;let t=r.findWrapping(e.type),n;if(!t)return s=null;if(n=s.length&&i.length&&function e(t,n,r,i,s){if(s<t.length&&s<n.length&&t[s]==n[s]){let o=e(t,n,r,i.lastChild,s+1);if(o)return i.copy(i.content.replaceChild(i.childCount-1,o));if(i.contentMatchAt(i.childCount).matchType(s==t.length-1?r.type:t[s+1]))return i.copy(i.content.append(iu.from(aC(r,t,s+1))))}}(t,i,e,s[s.length-1],0))s[s.length-1]=n;else{s.length&&(s[s.length-1]=function e(t,n){if(0==n)return t;let r=t.content.replaceChild(t.childCount-1,e(t.lastChild,n-1)),i=t.contentMatchAt(t.childCount).fillBefore(iu.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=aC(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iu.from(s)}return e}(o.content,i),!0)).openStart||o.openEnd){let e=0,t=0;for(let t=o.content.firstChild;e<o.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=o.content.lastChild;t<o.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);o=aE(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let aS=/^(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 aC(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iu.from(e));return e}function aj(e,t,n,r,i,s){let o=t<0?e.firstChild:e.lastChild,a=o.content;return e.childCount>1&&(s=0),i<r-1&&(a=aj(a,t,n,r,i+1,s)),i>=n&&(a=t<0?o.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(iu.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function aE(e,t,n){return t<e.openStart&&(e=new ix(aj(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new ix(aj(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let aM={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},aA=null;function aT(){return aA||(aA=document.implementation.createHTMLDocument("title"))}let aO=null,a_={},aD={},aR={touchstart:!0,touchmove:!0};class aI{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function aL(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function aP(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>az(e,t))})}function az(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function a$(e){return{left:e.clientX,top:e.clientY}}function aB(e,t,n,r,i){if(-1==r)return!1;let s=e.state.doc.resolve(r);for(let r=s.depth+1;r>0;r--)if(e.someProp(t,t=>r>s.depth?t(e,n,s.nodeAfter,s.before(r),i,!0):t(e,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function aF(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)}aD.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!aV(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!oN||!ob||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!ov||13!=t.keyCode||t.ctrlKey||t.altKey||t.metaKey)e.someProp("handleKeyDown",n=>n(e,t))||function(e,t){let n,r=t.keyCode,i=(n="",t.ctrlKey&&(n+="c"),t.metaKey&&(n+="m"),t.altKey&&(n+="a"),t.shiftKey&&(n+="s"),n);if(8==r||ow&&72==r&&"c"==i)return av(e,-1)||am(e,-1);if(46==r&&!t.shiftKey||ow&&68==r&&"c"==i)return av(e,1)||am(e,1);if(13==r||27==r)return!0;if(37==r||ow&&66==r&&"c"==i){let t=37==r?"ltr"==ax(e,e.state.selection.from)?-1:1:-1;return ap(e,t,i)||am(e,t)}if(39==r||ow&&70==r&&"c"==i){let t=39==r?"ltr"==ax(e,e.state.selection.from)?1:-1:1;return ap(e,t,i)||am(e,t)}else if(38==r||ow&&80==r&&"c"==i)return ay(e,-1,i)||am(e,-1);else if(40==r||ow&&78==r&&"c"==i)return function(e){if(!oy||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;aw(e,n,"true"),setTimeout(()=>aw(e,n,"false"),20)}return!1}(e)||ay(e,1,i)||am(e,1);else if(i==(ow?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():aL(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,oo(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},aD.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},aD.keypress=(e,t)=>{if(aV(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||ow&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof sB)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),i=()=>e.state.tr.insertText(r).scrollIntoView();/[\r\n]/.test(r)||e.someProp("handleTextInput",t=>t(e,n.$from.pos,n.$to.pos,r,i))||e.dispatch(i()),t.preventDefault()}};let aH=ow?"metaKey":"ctrlKey";a_.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=aG(e),o=Date.now(),a="singleClick";o-e.input.lastClick.time<500&&(r=(n=e.input.lastClick).x-t.clientX)*r+(i=n.y-t.clientY)*i<100&&!t[aH]&&e.input.lastClick.button==t.button&&("singleClick"==e.input.lastClick.type?a="doubleClick":"doubleClick"==e.input.lastClick.type&&(a="tripleClick")),e.input.lastClick={time:o,x:t.clientX,y:t.clientY,type:a,button:t.button};let l=e.posAtCoords(a$(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new aU(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return aB(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return aB(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=e.state.doc;if(-1==t)return!!r.inlineContent&&(aF(e,sB.create(r,0,r.content.size),"pointer"),!0);let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),s=i.before(t);if(n.inlineContent)aF(e,sB.create(r,s+1,s+1+n.content.size),"pointer");else{if(!sH.isSelectable(n))continue;aF(e,sH.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():aL(e,"pointer"))};class aU{constructor(e,t,n,r){let i,s;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[aH],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),s=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,s=n.depth?n.before():0}const o=r?null:n.target,a=o?e.docView.nearestDesc(o,!0):null;this.target=a&&1==a.nodeDOM.nodeType?a.nodeDOM:null;let{selection:l}=e.state;0==n.button&&(i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof sH&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&om&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),aL(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>ae(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;if(this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(a$(e))),this.updateAllowDefault(e),this.allowDefault||!t)aL(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,aB(n,"handleClickOn",r,i,e)||n.someProp("handleClick",t=>t(n,r,e))||(s?function(e,t){if(-1==t)return!1;let n=e.state.selection,r,i;n instanceof sH&&(r=n.node);let s=e.state.doc.resolve(t);for(let e=s.depth+1;e>0;e--){let t=e>s.depth?s.nodeAfter:s.node(e);if(sH.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?s.before(n.$from.depth):s.before(e);break}}return null!=i&&(aF(e,sH.create(e.state.doc,i),"pointer"),!0)}(n,i):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&sH.isSelectable(r))&&(aF(e,new sH(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oy&&this.mightDrag&&!this.mightDrag.node.isAtom||ob&&!this.view.state.selection.visible&&2>=Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to)))?(aF(this.view,sL.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):aL(this.view,"pointer")}}move(e){this.updateAllowDefault(e),aL(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function aV(e,t){return!!e.composing||!!(oy&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}a_.touchstart=e=>{e.input.lastTouch=Date.now(),aG(e),aL(e,"pointer")},a_.touchmove=e=>{e.input.lastTouch=Date.now(),aL(e,"pointer")},a_.contextmenu=e=>aG(e);let aW=oN?5e3:-1;function aq(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>aG(e),t))}function aK(e){let t;for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=((t=document.createEvent("Event")).initEvent("event",!0,!0),t.timeStamp));e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function aG(e,t=!1){if(!oN||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),aK(e),t||e.docView&&e.docView.dirty){let n=o7(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}aD.compositionstart=aD.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof sB&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ob&&ok&&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(),aG(e,!0),e.markCursor=null;else if(aG(e,!t.selection.empty),om&&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}aq(e,aW)},aD.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,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++,aq(e,20))};let aJ=oh&&of<15||ov&&oC<604;function aZ(e,t,n,r,i){let s=aN(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,i,s||ix.empty)))return!0;if(!s)return!1;let o=0==s.openStart&&0==s.openEnd&&1==s.content.childCount?s.content.firstChild:null,a=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(s);return e.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function aX(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," "):""}a_.copy=aD.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=aJ?null:t.clipboardData,{dom:s,text:o}=ak(e,n.content());i?(t.preventDefault(),i.clearData(),i.setData("text/html",s.innerHTML),i.setData("text/plain",o)):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(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,s),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},aD.paste=(e,t)=>{if(e.composing&&!oN)return;let n=aJ?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&aZ(e,aX(n),n.getData("text/html"),r,t)?t.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 i=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?aZ(e,r.value,null,i,t):aZ(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class aY{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let aQ=ow?"altKey":"ctrlKey";function a0(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[aQ]}for(let e in a_.dragstart=(e,t)=>{let n,r=e.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=e.state.selection,s=i.empty?null:e.posAtCoords(a$(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof sH?i.to-1:i.to));else if(r&&r.mightDrag)n=sH.create(e.state.doc,r.mightDrag.pos);else if(t.target&&1==t.target.nodeType){let r=e.docView.nearestDesc(t.target,!0);r&&r.node.type.spec.draggable&&r!=e.docView&&(n=sH.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=ak(e,o);t.dataTransfer.files.length&&ob&&!(ox>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(aJ?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",aJ||t.dataTransfer.setData("text/plain",l),e.dragging=new aY(c,a0(e,t),n)},a_.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},aD.dragover=aD.dragenter=(e,t)=>t.preventDefault(),aD.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(a$(t));if(!r)return;let i=e.state.doc.resolve(r.pos),s=n&&n.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=aN(e,aX(t.dataTransfer),aJ?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&a0(e,t));if(e.someProp("handleDrop",n=>n(e,t,s||ix.empty,o)))return t.preventDefault();if(!s)return;t.preventDefault();let a=s?sk(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let l=e.state.tr;if(o){let{node:e}=n;e?e.replace(l):l.deleteSelection()}let c=l.mapping.map(a),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=l.doc;if(d?l.replaceRangeWith(c,c,s.content.firstChild):l.replaceRange(c,c,s),l.doc.eq(u))return;let p=l.doc.resolve(c);if(d&&sH.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new sH(p));else{let t=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),l.setSelection(aa(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},a_.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())&&ae(e)},20))},a_.blur=(e,t)=>{e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),t.relatedTarget&&e.dom.contains(t.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},a_.beforeinput=(e,t)=>{if(ob&&oN&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,oo(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)}},aD)a_[e]=aD[e];function a1(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}class a2{constructor(e,t){this.toDOM=e,this.spec=t||a9,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:s}=e.mapResult(t.from+r,this.side<0?-1:1);return s?null:new a4(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof a2&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&a1(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class a3{constructor(e,t){this.attrs=e,this.spec=t||a9}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,s=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=s?null:new a4(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof a3&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}static is(e){return e.type instanceof a3}destroy(){}}class a5{constructor(e,t){this.attrs=e,this.spec=t||a9}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let s=e.mapResult(t.to+r,-1);return s.deleted||s.pos<=i.pos?null:new a4(i.pos-n,s.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(e){return this==e||e instanceof a5&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}destroy(){}}class a4{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new a4(e,t,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(e,t,n){return new a4(e,e,new a2(t,n))}static inline(e,t,n,r){return new a4(e,t,new a3(n,r))}static node(e,t,n,r){return new a4(e,t,new a5(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof a3}get widget(){return this.type instanceof a2}}let a6=[],a9={};class a7{constructor(e,t){this.local=e.length?e:a6,this.children=t.length?t:a6}static create(e,t){return t.length?li(t,e,0,a9):a8}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,i){for(let s=0;s<this.local.length;s++){let o=this.local[s];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let o=this.children[s]+1;this.children[s+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==a8||0==e.maps.length?this:this.mapInner(e,t,0,0,n||a9)}mapInner(e,t,n,r,i){let s;for(let o=0;o<this.local.length;o++){let a=this.local[o].map(e,n,r);a&&a.type.valid(t,a)?(s||(s=[])).push(a):i.onRemove&&i.onRemove(this.local[o].spec)}return this.children.length?function(e,t,n,r,i,s,o){let a=e.slice();for(let e=0,t=s;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,s)=>{let o=s-i-(n-e);for(let i=0;i<a.length;i+=3){let s=a[i+1];if(s<0||e>s+t-r)continue;let l=a[i]+t-r;n>=l?a[i+1]=e<=l?-2:-1:e>=t&&o&&(a[i]+=o,a[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<a.length;t+=3)if(a[t+1]<0){if(-2==a[t+1]){l=!0,a[t+1]=-1;continue}let c=n.map(e[t]+s),d=c-i;if(d<0||d>=r.content.size){l=!0;continue}let u=n.map(e[t+1]+s,-1)-i,{index:p,offset:h}=r.content.findIndex(d),f=r.maybeChild(p);if(f&&h==d&&h+f.nodeSize==u){let r=a[t+2].mapInner(n,f,c+1,e[t]+s+1,o);r!=a8?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=li(function(e,t,n,r,i,s,o){for(let a=0;a<e.length;a+=3)-1==e[a+1]&&function e(t,s){for(let e=0;e<t.local.length;e++){let a=t.local[e].map(r,i,s);a?n.push(a):o.onRemove&&o.onRemove(t.local[e].spec)}for(let n=0;n<t.children.length;n+=3)e(t.children[n+2],t.children[n]+s+1)}(e[a+2],t[a]+s+1);return n}(a,e,t,n,i,s,o),r,0,o);t=l.local;for(let e=0;e<a.length;e+=3)a[e+1]<0&&(a.splice(e,3),e-=3);for(let e=0,t=0;e<l.children.length;e+=3){let n=l.children[e];for(;t<a.length&&a[t]<n;)t+=3;a.splice(t,0,l.children[e],l.children[e+1],l.children[e+2])}}return new a7(t.sort(ls),a)}(this.children,s||[],e,t,n,r,i):s?new a7(s.sort(ls),a6):a8}add(e,t){return t.length?this==a8?a7.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,i=0;e.forEach((e,s)=>{let o=s+n,a;if(a=ln(t,e,o)){for(r||(r=this.children.slice());i<r.length&&r[i]<s;)i+=3;r[i]==s?r[i+2]=r[i+2].addInner(e,a,o+1):r.splice(i,0,s,s+e.nodeSize,li(a,e,o+1,a9)),i+=3}});let s=lt(i?lr(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new a7(s.length?this.local.concat(s).sort(ls):this.local,r||this.children)}remove(e){return 0==e.length||this==a8?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let r=0;r<n.length;r+=3){let i,s=n[r]+t,o=n[r+1]+t;for(let t=0,n;t<e.length;t++)(n=e[t])&&n.from>s&&n.to<o&&(e[t]=null,(i||(i=[])).push(n));if(!i)continue;n==this.children&&(n=this.children.slice());let a=n[r+2].removeInner(i,s+1);a!=a8?n[r+2]=a:(n.splice(r,3),r-=3)}if(r.length){for(let n=0,i;n<e.length;n++)if(i=e[n])for(let e=0;e<r.length;e++)r[e].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(e--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new a7(r,n):a8}forChild(e,t){let n,r;if(this==a8)return this;if(t.isLeaf)return a7.empty;for(let t=0;t<this.children.length;t+=3)if(this.children[t]>=e){this.children[t]==e&&(n=this.children[t+2]);break}let i=e+1,s=i+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<s&&t.to>i&&t.type instanceof a3){let e=Math.max(i,t.from)-i,n=Math.min(s,t.to)-i;e<n&&(r||(r=[])).push(t.copy(e,n))}}if(r){let e=new a7(r.sort(ls),a6);return n?new le([e,n]):e}return n||a8}eq(e){if(this==e)return!0;if(!(e instanceof a7)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return lo(this.localsInner(e))}localsInner(e){if(this==a8)return a6;if(e.inlineContent||!this.local.some(a3.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof a3||t.push(this.local[e]);return t}forEachSet(e){e(this)}}a7.empty=new a7([],[]),a7.removeOverlap=lo;let a8=a7.empty;class le{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,a9));return le.from(n)}forChild(e,t){if(t.isLeaf)return a7.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=a8&&(i instanceof le?n=n.concat(i.members):n.push(i))}return le.from(n)}eq(e){if(!(e instanceof le)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?lo(n?t:t.sort(ls)):a6}static from(e){switch(e.length){case 0:return a8;case 1:return e[0];default:return new le(e.every(e=>e instanceof a7)?e:e.reduce((e,t)=>e.concat(t instanceof a7?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lt(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new a4(i.from+t,i.to+t,i.type))}return n}function ln(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,s;t<e.length;t++)(s=e[t])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),e[t]=null);return i}function lr(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function li(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=ln(e,t,o+n);if(a){s=!0;let e=li(a,t,n+o+1,r);e!=a8&&i.push(o,o+t.nodeSize,e)}});let o=lt(s?lr(e):e,-n).sort(ls);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new a7(o,i):a8}function ls(e,t){return e.from-t.from||e.to-t.to}function lo(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let s=t[i];if(s.from==r.from){s.to!=r.to&&(t==e&&(t=e.slice()),t[i]=s.copy(s.from,r.to),la(t,i+1,s.copy(r.to,s.to)));continue}s.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,s.from),la(t,i,r.copy(s.from,r.to)));break}}return t}function la(e,t,n){for(;t<e.length&&ls(n,e[t])>0;)t++;e.splice(t,0,n)}function ll(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=a8&&t.push(r)}),e.cursorWrapper&&t.push(a7.create(e.state.doc,[e.cursorWrapper.deco])),le.from(t)}let lc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ld=oh&&of<=11;class lu{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class lp{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lu,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);oh&&of<=11&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():oy&&e.composing&&t.some(e=>"childList"==e.type&&"TR"==e.target.nodeName)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),ld&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,lc)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(al(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(oh&&of<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=s4(n))t.add(n);for(let r=e.anchorNode;r;r=s4(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:3==n.nodeType?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){var e;let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=t.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&al(t)&&!this.ignoreSelectionChange(r),s=-1,o=-1,a=!1,l=[];if(t.editable)for(let e=0;e<n.length;e++){let t=this.registerMutation(n[e],l);t&&(s=s<0?t.from:Math.min(t.from,s),o=o<0?t.to:Math.max(t.to,o),t.typeOver&&(a=!0))}if(l.some(e=>"BR"==e.nodeName)&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode)){for(let e of l)if("BR"==e.nodeName&&e.parentNode){let t=e.nextSibling;for(;t&&1==t.nodeType;){if("false"==t.contentEditable){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(om&&l.length){let e=l.filter(e=>"BR"==e.nodeName);if(2==e.length){let[t,n]=e;t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of e){let e=r.parentNode;e&&"LI"==e.nodeName&&(!n||function(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}(t,n)!=e)&&r.remove()}}}let c=null;s<0&&i&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&oi(r)&&(c=o7(t))&&c.eq(sL.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,ae(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lh.has(e)&&(lh.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=om,lf||(console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),lf=!0))),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(e,t){var n;let{focusNode:r,focusOffset:i}=e.domSelectionRange();for(let s of t)if((null==(n=s.parentNode)?void 0:n.nodeName)=="TR"){let t=s.nextSibling;for(;t&&"TD"!=t.nodeName&&"TH"!=t.nodeName;)t=t.nextSibling;if(t){let n=t;for(;;){let e=n.firstChild;if(!e||1!=e.nodeType||"false"==e.contentEditable||/^(BR|IMG)$/.test(e.nodeName))break;n=e}n.insertBefore(s,n.firstChild),r==s&&e.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}(t,l)),this.handleDOMChange(s,o,a,l),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(r)||ae(t),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),3==r.nodeType&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(oh&&of<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:s}=e.addedNodes[t];(!n||0>Array.prototype.indexOf.call(e.addedNodes,n))&&(r=n),(!s||0>Array.prototype.indexOf.call(e.addedNodes,s))&&(i=s)}let s=r&&r.parentNode==e.target?s5(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?s5(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,a,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let lh=new WeakMap,lf=!1;function lm(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return s8(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lg(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(oy&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}else if(e.parentNode.lastChild==e||oy&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}let lb=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lx(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:aa(e,t.resolve(n.anchor),t.resolve(n.head))}function ly(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function lv(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class lw{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new aI,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(lj),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=lS(this),lN(this),this.nodeViews=lC(this),this.docView=oG(this.state.doc,lk(this),ll(this),this.dom,this),this.domObserver=new lp(this,(e,t,n,r)=>(function(e,t,n,r,i){let s,o,a,l=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=o7(e,t);if(n&&!e.state.selection.eq(n)){if(ob&&oN&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter"))))return;let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),l&&r.setMeta("composition",l),e.dispatch(r)}return}let c=e.state.doc.resolve(t),d=c.sharedDepth(n);t=c.before(d+1),n=e.state.doc.resolve(n).after(d+1);let u=e.state.selection,p=function(e,t,n){let r,{node:i,fromOffset:s,toOffset:o,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(r=[{node:d,offset:c.anchorOffset}],oi(c)||r.push({node:c.focusNode,offset:c.focusOffset})),ob&&8===e.input.lastKeyCode)for(let e=o;e>s;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if("BR"==t.nodeName&&!n){o=e;break}if(!n||n.size)break}let u=e.state.doc,p=e.someProp("domParser")||iG.fromSchema(e.state.schema),h=u.resolve(a),f=null,m=p.parse(i,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:s,to:o,preserveWhitespace:"pre"!=h.parent.type.whitespace||"full",findPositions:r,ruleFromNode:lg,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+a,head:t+a}}return{doc:m,sel:f,from:a,to:l}}(e,t,n),h=e.state.doc,f=h.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(s=e.state.selection.to,o="end"):(s=e.state.selection.from,o="start"),e.input.lastKeyCode=null;let m=function(e,t,n,r,i){let s=e.findDiffStart(t,n);if(null==s)return null;let{a:o,b:a}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==i){let e=Math.max(0,s-Math.min(o,a));r-=o+e-s}if(o<s&&e.size<t.size){let e=r<=s&&r>=o?s-r:0;(s-=e)&&s<t.size&&lv(t.textBetween(s-1,s+1))&&(s+=e?1:-1),a=s+(a-o),o=s}else if(a<s){let t=r<=s&&r>=a?s-r:0;(s-=t)&&s<e.size&&lv(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(f.content,p.doc.content,p.from,s,o);if(m&&e.input.domChangeCount++,(ov&&e.input.lastIOSEnter>Date.now()-225||oN)&&i.some(e=>1==e.nodeType&&!lb.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!m)if(r&&u instanceof sB&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))m={start:u.from,endA:u.to,endB:u.to};else{if(p.sel){let t=lx(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);l&&n.setMeta("composition",l),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof sB&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oh&&of<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),b=p.doc.resolveNoCache(m.endB-p.from),x=h.resolve(m.start),y=g.sameParent(b)&&g.parent.inlineContent&&x.end()>=m.endA;if((ov&&e.input.lastIOSEnter>Date.now()-225&&(!y||i.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!y&&g.pos<p.doc.content.size&&(!g.sameParent(b)||!g.parent.inlineContent)&&g.pos<b.pos&&!/\S/.test(p.doc.textBetween(g.pos,b.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&function(e,t,n,r,i){if(n-t<=i.pos-r.pos||ly(r,!0,!1)<i.pos)return!1;let s=e.resolve(t);if(!r.parent.isTextblock){let e=s.nodeAfter;return null!=e&&n==t+e.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=e.resolve(ly(s,!0,!0));return!(!o.parent.isTextblock||o.pos>n||ly(o,!0,!1)<n)&&r.parent.content.cut(r.parentOffset).eq(o.parent.content)}(h,m.start,m.endA,g,b)&&e.someProp("handleKeyDown",t=>t(e,oo(8,"Backspace")))){oN&&ob&&e.domObserver.suppressSelectionUpdates();return}ob&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),oN&&!y&&g.start()!=b.start()&&0==b.parentOffset&&g.depth==b.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,b=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oo(13,"Enter"))})},20));let v=m.start,w=m.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=lx(e,n.doc,p.sel);t&&!(ob&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oh&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==b.pos){oh&&of<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(m.start).marksAcross(h.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(a=function(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,s=r,o,a,l;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)s=n[e].removeFromSet(s);if(1==i.length&&0==s.length)a=i[0],o="add",l=e=>e.mark(a.addToSet(e.marks));else{if(0!=i.length||1!=s.length)return null;a=s[0],o="remove",l=e=>e.mark(a.removeFromSet(e.marks))}let c=[];for(let e=0;e<t.childCount;e++)c.push(l(t.child(e)));if(iu.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,b.parentOffset),x.parent.content.cut(x.parentOffset,m.endA-x.start())))){let t=k(e.state.tr);"add"==a.type?t.addMark(v,w,a.mark):t.removeMark(v,w,a.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==b.index()-!b.textOffset){let t=g.parent.textBetween(g.parentOffset,b.parentOffset),n=()=>k(e.state.tr.insertText(t,v,w));e.someProp("handleTextInput",r=>r(e,v,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())})(this,e,t,n,r)),this.domObserver.start(),function(e){for(let t in a_){let n=a_[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}(e,t)||az(e,t)||!e.editable&&t.type in aD||n(e,t)},aR[t]?{passive:!0}:void 0)}oy&&e.dom.addEventListener("input",()=>null),aP(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;for(let t in this._props={},e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&aP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(lj),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];for(let n in t.state=this.state,e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n,r,i;let s=this.state,o=!1,a=!1;e.storedMarks&&this.composing&&(aK(this),a=!0),this.state=e;let l=s.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=lC(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&aP(this),this.editable=lS(this),lN(this);let c=ll(this),d=lk(this),u=s.plugins==e.plugins||s.doc.eq(e.doc)?e.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",p=o||!this.docView.matchesNode(e.doc,d,c);(p||!e.selection.eq(s.selection))&&(a=!0);let h="preserve"==u&&a&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let s=(r.left+r.right)/2,o=i+1;o<Math.min(innerHeight,r.bottom);o+=5){let r=e.root.elementFromPoint(s,o);if(!r||r==e.dom||!e.dom.contains(r))continue;let a=r.getBoundingClientRect();if(a.top>=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:oM(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oh||ob)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&(r=s.selection,i=e.selection,a=Math.min(r.$anchor.sharedDepth(r.head),i.$anchor.sharedDepth(i.head)),r.$anchor.start(a)!=i.$anchor.start(a));if(p){let t=ob?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=on(e=e.childNodes[t-1])}else{if(!e.parentNode||or(e))return null;t=s5(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),r=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||or(e))return null;t=s5(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}(this)),(o||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=oG(e.doc,d,c,this.dom,this)),!t||this.trackWrites&&this.dom.contains(this.trackWrites)||(l=!0)}l||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&(t=this.docView.domFromPos(this.state.selection.anchor,0),n=this.domSelectionRange(),s8(t.node,t.offset,n.anchorNode,n.anchorOffset)))?ae(this,l):(as(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null==(n=this.dragging)?void 0:n.node)&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;oA(n,0==r?0:r-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof sH){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&oE(this,t.getBoundingClientRect(),e)}else oE(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(e&&e.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new aY(e.slice,e.move,r<0?void 0:sH.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(null!=n&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(null!=i&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let s=i[n].props[e];if(null!=s&&(r=t?t(s):s))return r}}hasFocus(){if(oh){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(oT)return e.focus(oT);let t=oM(e);e.focus(null==oT?{get preventScroll(){return oT={preventScroll:!0},!0}}:void 0),oT||(oT=!1,oA(t,0))}(this.dom),ae(this),this.domObserver.start()}get root(){let e=this._root;if(null==e){for(let e=this.dom.parentNode;e;e=e.parentNode)if(9==e.nodeType||11==e.nodeType&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return function(e,t){var n;let r,i,s=e.dom.ownerDocument,o,a=0,l=function(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(on(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(on(r.startContainer),r.startOffset)}}}(s,t.left,t.top);l&&({node:o,offset:a}=l);let c=(e.root.elementFromPoint?e.root:s).elementFromPoint(t.left,t.top);if(!c||!e.dom.contains(1!=c.nodeType?c.parentNode:c)){let n=e.dom.getBoundingClientRect();if(!oO(t,n)||!(c=function e(t,n,r){let i=t.childNodes.length;if(i&&r.top<r.bottom)for(let s=Math.max(0,Math.min(i-1,Math.floor(i*(n.top-r.top)/(r.bottom-r.top))-2)),o=s;;){let r=t.childNodes[o];if(1==r.nodeType){let t=r.getClientRects();for(let i=0;i<t.length;i++){let s=t[i];if(oO(n,s))return e(r,n,s)}}if((o=(o+1)%i)==s)break}return t}(e.dom,t,n)))return null}if(oy)for(let e=c;o&&e;e=s4(e))e.draggable&&(o=void 0);if(c=(r=(n=c).parentNode)&&/^li$/i.test(r.nodeName)&&t.left<n.getBoundingClientRect().left?r:n,o){let n;if(om&&1==o.nodeType&&(a=Math.min(a,o.childNodes.length))<o.childNodes.length){let e=o.childNodes[a],n;"IMG"==e.nodeName&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&a++}oS&&a&&1==o.nodeType&&1==(n=o.childNodes[a-1]).nodeType&&"false"==n.contentEditable&&n.getBoundingClientRect().top>=t.top&&a--,o==e.dom&&a==o.childNodes.length-1&&1==o.lastChild.nodeType&&t.top>o.lastChild.getBoundingClientRect().bottom?i=e.state.doc.content.size:(0==a||1!=o.nodeType||"BR"!=o.childNodes[a-1].nodeName)&&(i=function(e,t,n,r){let i=-1;for(let n=t,s=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!s&&o.left>r.left||o.top>r.top?i=t.posBefore:(!s&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),s=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,o,a,t))}null==i&&(i=function(e,t,n){let{node:r,offset:i}=function e(t,n){let r,i,s,o=2e8,a,l=0,c=n.top,d=n.top;for(let e=t.firstChild,u=0;e;e=e.nextSibling,u++){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=s9(e).getClientRects()}for(let p=0;p<t.length;p++){let h=t[p];if(h.top<=c&&h.bottom>=d){c=Math.max(h.bottom,c),d=Math.min(h.top,d);let t=h.left>n.left?h.left-n.left:h.right<n.left?n.left-h.right:0;if(t<o){s=e,o=t,a=t&&3==s.nodeType?{left:h.right<n.left?h.right:h.left,top:n.top}:n,1==e.nodeType&&t&&(l=u+ +(n.left>=(h.left+h.right)/2));continue}}else h.top>n.top&&!r&&h.left<=n.left&&h.right>=n.left&&(r=e,i={left:Math.max(h.left,Math.min(h.right,n.left)),top:h.top});!s&&(n.left>=h.right&&n.top>=h.top||n.left>=h.left&&n.top>=h.bottom)&&(l=u+1)}}return(!s&&r&&(s=r,a=i,o=0),s&&3==s.nodeType)?function(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let s=0;s<n;s++){r.setEnd(e,s+1),r.setStart(e,s);let n=oD(r,1);if(n.top!=n.bottom&&oO(t,n)){i={node:e,offset:s+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}(s,a):!s||o&&1==s.nodeType?{node:t,offset:l}:e(s,a)}(t,n),s=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();s=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,s)}(e,c,t));let d=e.docView.nearestDesc(c,!0);return{pos:i,inside:d?d.posAtStart-d.border:-1}}(this,e)}coordsAtPos(e,t=1){return oI(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return function(e,t,n){let r,i;return oB==t&&oF==n?oH:(oB=t,oF=n,oH="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,oz(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=oI(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=s9(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&("up"==n?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=i==r.parent.content.size,o=e.domSelection();return o?o$.test(r.parent.textContent)&&o.modify?oz(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:s,anchorOffset:a}=e.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",n,"character");let c=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&i==u;try{o.collapse(s,a),t&&(t!=s||i!=a)&&o.extend&&o.extend(t,i)}catch(e){}return null!=l&&(o.caretBidiLevel=l),p}):"left"==n||"backward"==n?!i:s:r.pos==r.start()||r.pos==r.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return aZ(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return aZ(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ak(this,e)}destroy(){if(this.docView){for(let e in this.domObserver.stop(),this.input.eventHandlers)this.dom.removeEventListener(e,this.input.eventHandlers[e]);clearTimeout(this.input.composingTimeout),clearTimeout(this.input.lastIOSEnterFallbackTimeout),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],ll(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,s7()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!az(this,e)&&a_[e.type]&&(this.editable||!(e.type in aD))&&a_[e.type](this,e)}domSelectionRange(){let e=this.domSelection();return e?oy&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){let n;if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return lm(e,n)}function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",r,!0),n?lm(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function lk(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[a4.node(0,e.state.doc.content.size,t)]}function lN(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:a4.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function lS(e){return!e.someProp("editable",t=>!1===t(e.state))}function lC(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function lj(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError("Plugins passed directly to the view must not have a state component")}lw.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var lE={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},lM={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},lA="u">typeof navigator&&/Mac/.test(navigator.platform),lT="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),lO=0;lO<10;lO++)lE[48+lO]=lE[96+lO]=String(lO);for(var lO=1;lO<=24;lO++)lE[lO+111]="F"+lO;for(var lO=65;lO<=90;lO++)lE[lO]=String.fromCharCode(lO+32),lM[lO]=String.fromCharCode(lO);for(var l_ in lE)lM.hasOwnProperty(l_)||(lM[l_]=lE[l_]);let lD="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lR="u">typeof navigator&&/Win/.test(navigator.platform);function lI(e,t,n=!0){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n&&t.shiftKey&&(e="Shift-"+e),e}function lL(e){let t=function(e){let t=Object.create(null);for(let n in e)t[function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"==o&&(o=" ");for(let e=0;e<s.length-1;e++){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))lD?i=!0:n=!0;else throw Error("Unrecognized modifier name: "+o)}return t&&(o="Alt-"+o),n&&(o="Ctrl-"+o),i&&(o="Meta-"+o),r&&(o="Shift-"+o),o}(n)]=e[n];return t}(e);return function(e,n){var r;let i=("Esc"==(r=!(lA&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||lT&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?lM:lE)[n.keyCode]||n.key||"Unidentified")&&(r="Escape"),"Del"==r&&(r="Delete"),"Left"==r&&(r="ArrowLeft"),"Up"==r&&(r="ArrowUp"),"Right"==r&&(r="ArrowRight"),"Down"==r&&(r="ArrowDown"),r),s,o=t[lI(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[lI(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(lR&&n.ctrlKey&&n.altKey)&&(s=lE[n.keyCode])&&s!=i){let r=t[lI(s,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}if("u">typeof WeakMap){let e=new WeakMap;t=t=>e.get(t),n=(t,n)=>(e.set(t,n),n)}else{let e=[],r=0;t=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},n=(t,n)=>(10==r&&(r=0),e[r++]=t,e[r++]=n)}var lP=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,s=r+1,o=i+1;for(let e=1;s<this.width&&this.map[t+e]==n;e++)s++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:s,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:s,bottom:o}=this.findCell(e);return"horiz"==t?(n<0?0==r:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?0==s:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:s}=this.findCell(e),{left:o,right:a,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let s=r*this.width+i,o=this.map[s];!n[o]&&(n[o]=!0,i==e.left&&i&&this.map[s-1]==o||r==e.top&&r&&this.map[s-this.width]==o||t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let s=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?s-1:this.map[n]}i=s}}static get(e){return t(e)||n(e,function(e){if("table"!=e.type.spec.tableRole)throw RangeError("Not a table node: "+e.type.name);let t=function(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),s=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(s+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);s+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=s:t!=s&&(t=Math.max(t,s))}return t}(e),n=e.childCount,r=[],i=0,s=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let a=0,l=0;a<n;a++){let c=e.child(a);l++;for(let e=0;;e++){for(;i<r.length&&0!=r[i];)i++;if(e==c.childCount)break;let d=c.child(e),{colspan:u,rowspan:p,colwidth:h}=d.attrs;for(let e=0;e<p;e++){if(e+a>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:l,n:p-e});break}let c=i+e*t;for(let e=0;e<u;e++){0==r[c+e]?r[c+e]=l:(s||(s=[])).push({type:"collision",row:a,pos:l,n:u-e});let n=h&&h[e];if(n){let r=(c+e)%t*2,i=o[r];null==i||i!=n&&1==o[r+1]?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=u,l+=d.nodeSize}let d=(a+1)*t,u=0;for(;i<d;)0==r[i++]&&u++;u&&(s||(s=[])).push({type:"missing",row:a,n:u}),l++}(0===t||0===n)&&(s||(s=[])).push({type:"zero_sized"});let a=new lP(t,n,r,s),l=!1;for(let e=0;!l&&e<o.length;e+=2)null!=o[e]&&o[e+1]<n&&(l=!0);return l&&function(e,t,n){e.problems||(e.problems=[]);let r={};for(let i=0;i<e.map.length;i++){let s=e.map[i];if(r[s])continue;r[s]=!0;let o=n.nodeAt(s);if(!o)throw RangeError(`No cell with offset ${s} found`);let a=null,l=o.attrs;for(let n=0;n<l.colspan;n++){let r=t[(i+n)%e.width*2];null==r||l.colwidth&&l.colwidth[n]==r||((a||(a=function(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}(l)))[n]=r)}a&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}(a,o,e),a}(e))}};function lz(e){let t=e.cached.tableNodeTypes;if(!t)for(let n in t=e.cached.tableNodeTypes={},e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}return t}let l$=new s3("selectingCells");function lB(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function lF(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function lH(e){let t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;let n=lB(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function lU(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function lV(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function lW(e,t,n){let r=e.node(-1),i=lP.get(r),s=e.start(-1),o=i.nextCell(e.pos-s,t,n);return null==o?null:e.node(0).resolve(s+o)}function lq(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function lK(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}var lG=class e extends sL{constructor(e,t=e){const n=e.node(-1),r=lP.get(n),i=e.start(-1),s=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),a=r.cellsInRect(s).filter(e=>e!=t.pos-i);a.unshift(t.pos-i);const l=a.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new sP(o.resolve(r),o.resolve(r+t.content.size))});super(l[0].$from,l[0].$to,l),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(lU(r)&&lU(i)&&lV(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return sB.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=lP.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},s=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let s=n*t.width+r.left,a=r.left;a<r.right;a++,s++){let n=t.map[s];if(i[n])continue;i[n]=!0;let a=t.findCell(n),l=e.nodeAt(n);if(!l)throw RangeError(`No cell with offset ${n} found`);let c=r.left-a.left,d=a.right-r.right;if(c>0||d>0){let e=l.attrs;if(c>0&&(e=lq(e,0,c)),d>0&&(e=lq(e,e.colspan-d,d)),a.left<r.left){if(!(l=l.type.createAndFill(e)))throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else l=l.type.create(e,l.content)}if(a.top<r.top||a.bottom>r.bottom){let e={...l.attrs,rowspan:Math.min(a.bottom,r.bottom)-Math.max(a.top,r.top)};l=a.top<r.top?l.type.createAndFill(e):l.type.create(e,l.content)}o.push(l)}s.push(e.child(n).copy(iu.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new ix(iu.from(o),1,1)}replace(e,t=ix.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n);e.replace(a.map(s.pos),a.map(o.pos),i?ix.empty:t)}let i=sL.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new ix(iu.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=lP.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);return!(Math.min(e,t)>0)&&Math.max(e+this.$anchorCell.nodeAfter.attrs.rowspan,t+this.$headCell.nodeAfter.attrs.rowspan)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=lP.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.top<=a.top?(o.top>0&&(t=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(t=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=lP.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);return!(Math.min(r,i)>0)&&Math.max(r+this.$anchorCell.nodeAfter.attrs.colspan,i+this.$headCell.nodeAfter.attrs.colspan)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=lP.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.left<=a.left?(o.left>0&&(t=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(t=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new lJ(this.$anchorCell.pos,this.$headCell.pos)}};lG.prototype.visible=!1,sL.jsonID("cell",lG);var lJ=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){let t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&lV(t,n)?new lG(t,n):sL.near(n,1)}};function lZ(e){if(!(e.selection instanceof lG))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(a4.node(n,n+e.nodeSize,{class:"selectedCell"}))}),a7.create(e.doc,t)}let lX=new s3("fix-tables");function lY(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=lP.get(t);if(!o.problems)return r;r||(r=e.tr);let a=[];for(let e=0;e<o.height;e++)a.push(0);for(let e=0;e<o.problems.length;e++){let i=o.problems[e];if("collision"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;let s=e.attrs;for(let e=0;e<s.rowspan;e++)a[i.row+e]+=i.n;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,lq(s,s.colspan-i.n,i.n))}else if("missing"==i.type)a[i.row]+=i.n;else if("overlong_rowspan"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-i.n})}else if("colwidth mismatch"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,colwidth:i.colwidth})}else if("zero_sized"==i.type){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}for(let e=0;e<a.length;e++)a[e]&&(null==i&&(i=e),s=e);for(let l=0,c=n+1;l<o.height;l++){let n=t.child(l),o=c+n.nodeSize,d=a[l];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<d;n++){let n=lz(e.schema)[t].createAndFill();n&&a.push(n)}let u=(0==l||i==l-1)&&s==l?c+1:o-1;r.insert(r.mapping.map(u),a)}c=o}return r.setMeta(lX,{fixTables:!0})}(e,t,r,n))};return t?t.doc!=e.doc&&function e(t,n,r,i){let s=t.childCount,o=n.childCount;n:for(let a=0,l=0;a<o;a++){let o=n.child(a);for(let e=l,n=Math.min(s,a+3);e<n;e++)if(t.child(e)==o){l=e+1,r+=o.nodeSize;continue n}i(o,r),l<s&&t.child(l).sameMarkup(o)?e(t.child(l),o,r+1,i):o.nodesBetween(0,o.content.size,i,r+1),r+=o.nodeSize}}(t.doc,e.doc,0,r):e.doc.descendants(r),n}function lQ(e){let t=lP.get(e),n=[],r=t.height,i=t.width;for(let s=0;s<r;s++){let r=[];for(let n=0;n<i;n++){let o=s*i+n,a=t.map[o];if(s>0){let e=o-i;if(a===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(a===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(a))}n.push(r)}return n}function l0(e,t){let n=[],r=lP.get(e),i=r.height,s=r.width;for(let o=0;o<i;o++){let i=e.child(o),a=[];for(let n=0;n<s;n++){let i=t[o][n];if(!i)continue;let s=r.map[o*r.width+n],l=e.nodeAt(s);if(!l)continue;let c=l.type.createChecked(i.attrs,i.content,i.marks);a.push(c)}let l=i.type.createChecked(i.attrs,a,i.marks);n.push(l)}return e.type.createChecked(e.attrs,n,e.marks)}function l1(e,t,n,r){let i,s=t[0]>n[0]?-1:1,o=e.splice(t[0],t.length),a=+(o.length%2==0);return i=-1===r&&1===s?n[0]-1:1===r&&-1===s?n[n.length-1]-a+1:-1===s?n[0]:n[n.length-1]-a,e.splice(i,0,...o),e}function l2(e){var t=e;for(let e=t.depth;e>=0;e-=1){let n=t.node(e);if((e=>"table"===e.type.spec.tableRole)(n))return{node:n,pos:0===e?0:t.before(e),start:t.start(e),depth:e}}return null}function l3(e,t){let n=l2(t.$from);if(!n)return;let r=lP.get(n.node);if(!(e<0)&&!(e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function l5(e,t){let n=l2(t.$from);if(!n)return;let r=lP.get(n.node);if(!(e<0)&&!(e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function l4(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l3(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=l3(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=l3(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l3(i,e.selection),l=l5(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=l3(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function l6(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l5(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=l5(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=l5(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l5(i,e.selection),l=l3(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=l5(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function l9(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function l7(e){let t=e.selection,n=lH(e),r=n.node(-1),i=n.start(-1),s=lP.get(r);return{...t instanceof lG?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function l8(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=lz(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0})(t,r,i+s)&&(s=0==i||i==t.width?null:0);for(let o=0;o<t.height;o++){let a=o*t.width+i;if(i>0&&i<t.width&&t.map[a-1]==t.map[a]){let s=t.map[a],l=r.nodeAt(s);e.setNodeMarkup(e.mapping.map(n+s),null,lK(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?lz(r.type.schema).cell:r.nodeAt(t.map[a+s]).type,c=t.positionAt(o,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function ce(e,{map:t,tableStart:n,table:r},i){let s=n;for(let e=0;e<i;e++)s+=r.child(e).nodeSize;let o=[],a=i>0?-1:0;(function(e,t,n){var r;let i=lz(t.type.schema).header_cell;for(let s=0;s<e.width;s++)if((null==(r=t.nodeAt(e.map[s+n*e.width]))?void 0:r.type)!=i)return!1;return!0})(t,r,i+a)&&(a=0==i||i==t.height?null:0);for(let s=0,c=t.width*i;s<t.width;s++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),s+=o.colspan-1}else{var l;let e=null==a?lz(r.type.schema).cell:null==(l=r.nodeAt(t.map[c+a*t.width]))?void 0:l.type,n=null==e?void 0:e.createAndFill();n&&o.push(n)}return e.insert(s,lz(r.type.schema).row.create(null,o)),e}function ct(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cn(e,t){let n=e.selection;if(!(n instanceof lG)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=l7(e),{map:i}=r;if(function({width:e,height:t,map:n},r){let i=r.top*e+r.left,s=i,o=(r.bottom-1)*e+r.left,a=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[s]==n[s-1]||r.right<e&&n[a]==n[a+1])return!0;s+=e,a+=e}for(let s=r.left;s<r.right;s++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}(i,r))return!1;if(t){let n,s,o=e.tr,a={},l=iu.empty;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let c=i.map[e*i.width+t],d=r.table.nodeAt(c);if(!a[c]&&d)if(a[c]=!0,null==n)n=c,s=d;else{ct(d)||(l=l.append(d.content));let e=o.mapping.map(c+r.tableStart);o.delete(e,e+d.nodeSize)}}if(null==n||null==s)return!0;if(o.setNodeMarkup(n+r.tableStart,null,{...lK(s.attrs,s.attrs.colspan,r.right-r.left-s.attrs.colspan),rowspan:r.bottom-r.top}),l.size>0){let e=n+1+s.content.size,t=ct(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new lG(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cr(e,t){var n;let r=lz(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof lG){if(s.$anchorCell.pos!=s.$headCell.pos)return!1;r=s.$anchorCell.nodeAfter,i=s.$anchorCell.pos}else{var o;if(!(r=function(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(s.$from)))return!1;i=null==(o=lB(s.$from))?void 0:o.pos}if(null==r||null==i||1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(t){let o,a=r.attrs,l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});let d=l7(e),u=e.tr;for(let e=0;e<d.right-d.left;e++)l.push(c?{...a,colwidth:c&&c[e]?[c[e]]:null}:a);for(let e=d.top;e<d.bottom;e++){let t=d.map.positionAt(e,d.left,d.table);e==d.top&&(t+=r.nodeSize);for(let i=d.left,s=0;i<d.right;i++,s++)(i!=d.left||e!=d.top)&&u.insert(o=u.mapping.map(t+d.tableStart,1),n({node:r,row:e,col:i}).createAndFill(l[s]))}u.setNodeMarkup(i,n({node:r,row:d.top,col:d.left}),l[0]),s instanceof lG&&u.setSelection(new lG(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function ci(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function cs(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=i.map.cellsInRect("column"==e?{left:i.left,top:0,right:i.right,bottom:i.map.height}:"row"==e?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)a[e].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[e],r.cell,a[e].attrs);if(0===s.steps.length)for(let e=0;e<o.length;e++)s.setNodeMarkup(i.tableStart+o[e],r.header_cell,a[e].attrs);n(s)}return!0};return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=ci("row",i,r),a=ci("column",i,r),l=+("column"===e?!!o:"row"===e&&!!a),c="column"==e?{left:0,top:l,right:1,bottom:i.map.height}:"row"==e?{left:l,top:0,right:i.map.width,bottom:1}:i,d="column"==e?a?r.cell:r.header_cell:"row"==e?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(c).forEach(e=>{let t=e+i.tableStart,n=s.doc.nodeAt(t);n&&s.setNodeMarkup(t,d,n.attrs)}),n(s)}return!0}}cs("row",{useDeprecatedLogic:!0}),cs("column",{useDeprecatedLogic:!0});let co=cs("cell",{useDeprecatedLogic:!0});function ca(e){return function(t,n){if(!lF(t))return!1;let r=function(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}(lH(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(sB.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cl(e,t){let n=e.selection;if(!(n instanceof lG))return!1;if(t){let r=e.tr,i=lz(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new ix(i,0,0))}),r.docChanged&&t(r)}return!0}function cc(e,t){let n=e.createAndFill();return new sR(n).replace(0,n.content.size,t).doc}function cd(e,t,n,r,i,s,o,a){if(0==o||o==t.height)return!1;let l=!1;for(let c=i;c<s;c++){let i=o*t.width+c,s=t.map[i];if(t.map[i-t.width]==s){l=!0;let i=n.nodeAt(s),{top:d,left:u}=t.findCell(s);e.setNodeMarkup(e.mapping.slice(a).map(s+r),null,{...i.attrs,rowspan:o-d}),e.insert(e.mapping.slice(a).map(t.positionAt(o,u,n)),i.type.createAndFill({...i.attrs,rowspan:d+i.attrs.rowspan-o})),c+=i.attrs.colspan-1}}return l}function cu(e,t,n,r,i,s,o,a){if(0==o||o==t.width)return!1;let l=!1;for(let c=i;c<s;c++){let i=c*t.width+o,s=t.map[i];if(t.map[i-1]==s){l=!0;let i=n.nodeAt(s),d=t.colCount(s),u=e.mapping.slice(a).map(s+r);e.setNodeMarkup(u,null,lq(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(lq(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cp(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=lP.get(s),{top:a,left:l}=r,c=l+i.width,d=a+i.height,u=e.tr,p=0;function h(){if(!(s=n?u.doc.nodeAt(n-1):u.doc))throw Error("No table found");o=lP.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=lz(e.doc.type.schema);if(i>t.width)for(let s=0,c=0;s<t.height;s++){let d,u=n.child(s);c+=u.nodeSize;let p=[];d=null==u.lastChild||u.lastChild.type==l.cell?o||(o=l.cell.createAndFill()):a||(a=l.header_cell.createAndFill());for(let e=t.width;e<i;e++)p.push(d);e.insert(e.mapping.slice(0).map(c-1+r),p)}if(s>t.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=!(e>=t.width)&&n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?a||(a=l.header_cell.createAndFill()):o||(o=l.cell.createAndFill()))}let d=l.row.create(null,iu.from(c)),u=[];for(let e=t.height;e<s;e++)u.push(d);e.insert(e.mapping.slice(0).map(r+n.nodeSize-2),u)}return!!(o||a)})(u,o,s,n,c,d)&&h(),cd(u,o,s,n,l,c,a,p)&&h(),cd(u,o,s,n,l,c,d,p)&&h(),cu(u,o,s,n,a,d,l,p)&&h(),cu(u,o,s,n,a,d,c,p)&&h();for(let e=a;e<d;e++){let t=o.positionAt(e,l,s),r=o.positionAt(e,c,s);u.replace(u.mapping.slice(p).map(t+n),u.mapping.slice(p).map(r+n),new ix(i.rows[e-a],0,0))}h(),u.setSelection(new lG(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let ch=lL({ArrowLeft:cm("horiz",-1),ArrowRight:cm("horiz",1),ArrowUp:cm("vert",-1),ArrowDown:cm("vert",1),"Shift-ArrowLeft":cg("horiz",-1),"Shift-ArrowRight":cg("horiz",1),"Shift-ArrowUp":cg("vert",-1),"Shift-ArrowDown":cg("vert",1),Backspace:cl,"Mod-Backspace":cl,Delete:cl,"Mod-Delete":cl});function cf(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cm(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof lG)return cf(n,r,sL.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cv(i,e,t);if(null==o)return!1;if("horiz"==e)return cf(n,r,sL.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=lW(s,e,t);return i=a?sL.near(a,1):t<0?sL.near(n.doc.resolve(s.before(-1)),-1):sL.near(n.doc.resolve(s.after(-1)),1),cf(n,r,i)}}}function cg(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof lG)s=o;else{let r=cv(i,e,t);if(null==r)return!1;s=new lG(n.doc.resolve(r))}let a=lW(s.$headCell,e,t);return!!a&&cf(n,r,new lG(s.$anchorCell,a))}}function cb(e,t){let n=lB(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new lG(n))),!0)}function cx(e,t,n){if(!lF(e.state))return!1;let r=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;1==t.childCount&&(n>0&&r>0||"table"==t.child(0).type.spec.tableRole);)n--,r--,t=t.child(0).content;let i=t.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if("row"==s)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,s=e?0:Math.max(0,n-1),l=e<t.childCount-1?0:Math.max(0,r-1);(s||l)&&(i=cc(lz(o).row,new ix(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cc(lz(o).row,new ix(t,n,r)).content:t)}return function(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:s}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+s}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(iu.empty),n[i]<r){let s=lz(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iu.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof lG){r||(r={width:1,height:1,rows:[iu.from(cc(lz(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=lP.get(t).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=function({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let s=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let a=s.child(i%s.childCount);n+a.attrs.colspan>r&&(a=a.type.createChecked(lq(a.attrs,a.attrs.colspan,n+a.attrs.colspan-r),a.content)),o.push(a),n+=a.attrs.colspan;for(let n=1;n<a.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+a.attrs.colspan}i.push(iu.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,s=0;r<i;r++,s++){let o=[],a=n[s%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(iu.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cp(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=lH(e.state),n=t.start(-1);return cp(e.state,e.dispatch,n,lP.get(t.node(-1)).findCell(t.pos-n),r),!0}}function cy(e,t){var n;let r;if(0!=t.button||t.ctrlKey||t.metaKey)return;let i=cw(e,t.target);if(t.shiftKey&&e.state.selection instanceof lG)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=lB(e.state.selection.$anchor))&&(null==(n=ck(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=ck(e,n),i=null==l$.getState(e.state);if(!r||!lV(t,r))if(!i)return;else r=t;let s=new lG(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(l$,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=l$.getState(e.state)&&e.dispatch(e.state.tr.setMeta(l$,-1))}function a(n){let r,a=l$.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(cw(e,n.target)!=i&&!(r=ck(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cv(e,t,n){if(!(e.state.selection instanceof sB))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))break;if("cell"==s.type.spec.tableRole||"header_cell"==s.type.spec.tableRole){let s=r.before(i),o="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(o)?s:null}}return null}function cw(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function ck(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&lB(e.state.doc.resolve(r))||lB(e.state.doc.resolve(i))}var cN=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),cS(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,cS(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function cS(e,t,n,r,i,s){let o=0,a=!0,l=t.firstChild,c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){let{colspan:d,colwidth:u}=c.child(e).attrs;for(let e=0;e<d;e++,n++){let c=i==n?s:u&&u[e],d=c?c+"px":"";if(o+=c||r,c||(a=!1),l)l.style.width!=d&&(l.style.width=d),l=l.nextSibling;else{let e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;l;){var d;let e=l.nextSibling;null==(d=l.parentNode)||d.removeChild(l),l=e}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}let cC=new s3("tableColumnResizing");var cj=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(cC);if(n&&null!=n.setHandle)return new e(n.setHandle,!1);if(n&&void 0!==n.setDragging)return new e(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&t.docChanged){let n=t.mapping.map(this.activeHandle,-1);return lU(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function cE(e,t,n,r){let i=e.posAtCoords({left:t.clientX+("right"==n?-r:r),top:t.clientY});if(!i)return -1;let{pos:s}=i,o=lB(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=lP.get(o.node(-1)),l=o.start(-1),c=a.map.indexOf(o.pos-l);return c%a.width==0?-1:l+a.map[c-1]}function cM(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function cA(e,t){e.dispatch(e.state.tr.setMeta(cC,{setHandle:t}))}function cT(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=lP.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,l=e.domAtPos(i.start(-1)).node;for(;l&&"TABLE"!=l.nodeName;)l=l.parentNode;l&&cS(s,l.firstChild,l,r,a,n)}var cO=f,c_=e.i(3909);let cD=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function cR(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let cI=(e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);if(!i){let n=r.blockRange(),i=n&&sh(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(cJ(e,i,t,-1))return!0;if(0==r.parent.content.size&&(cP(s,"end")||sH.isSelectable(s)))for(let n=r.depth;;n--){let o=sN(e.doc,r.before(n),r.after(n),ix.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(cP(s,"end")?sL.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):sH.create(n.doc,i.pos-s.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||r.node(n-1).childCount>1)break}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0)};function cL(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let s=t.nodeAfter,o=t.pos+1;for(;!s.isTextblock;o++){if(s.type.spec.isolating)return!1;let e=s.firstChild;if(!e)return!1;s=e}let a=sN(e.doc,i,o,ix.empty);if(!a||a.from!=i||a instanceof sc&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(sB.create(t.doc,i)),n(t.scrollIntoView())}return!0}function cP(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)break}return!1}let cz=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;s=c$(r)}let o=s&&s.nodeBefore;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function c$(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function cB(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let cF=(e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);if(!i)return!1;let s=i.nodeAfter;if(cJ(e,i,t,1))return!0;if(0==r.parent.content.size&&(cP(s,"start")||sH.isSelectable(s))){let n=sN(e.doc,r.before(),r.after(),ix.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(cP(s,"start")?sL.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):sH.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0)},cH=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;s=cU(r)}let o=s&&s.nodeAfter;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos)).scrollIntoView()),!0)};function cU(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}let cV=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!!n.parent.type.spec.code&&!!n.sameParent(r)&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function cW(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}let cq=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),o=cW(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(sL.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},cK=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof sV||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=cW(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,s.createAndFill());o.setSelection(sB.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},cG=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(sx(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&sh(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function cJ(e,t,n,r){let i,s,o,a=t.nodeBefore,l=t.nodeAfter,c,d,u=a.type.spec.isolating||l.type.spec.isolating;if(!u&&(i=t.nodeBefore,s=t.nodeAfter,o=t.index(),i&&s&&i.type.compatibleContent(s.type)&&(!i.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-i.nodeSize,t.pos).scrollIntoView()),!0):!!t.parent.canReplace(o,o+1)&&!!(s.isTextblock||sy(e.doc,t.pos))&&(n&&n(e.tr.join(t.pos).scrollIntoView()),!0))))return!0;let p=!u&&t.parent.canReplace(t.index(),t.index()+1);if(p&&(c=(d=a.contentMatchAt(a.childCount)).findWrapping(l.type))&&d.matchType(c[0]||l.type).validEnd){if(n){let r=t.pos+l.nodeSize,i=iu.empty;for(let e=c.length-1;e>=0;e--)i=iu.from(c[e].create(null,i));i=iu.from(a.copy(i));let s=e.tr.step(new sd(t.pos-1,r,t.pos,r,new ix(i,1,0),c.length,!0)),o=s.doc.resolve(r+2*c.length);o.nodeAfter&&o.nodeAfter.type==a.type&&sy(s.doc,o.pos)&&s.join(o.pos),n(s.scrollIntoView())}return!0}let h=l.type.spec.isolating||r>0&&u?null:sL.findFrom(t,1),f=h&&h.$from.blockRange(h.$to),m=f&&sh(f);if(null!=m&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(p&&cP(l,"start",!0)&&cP(a,"end")){let r=a,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let s=l,o=1;for(;!s.isTextblock;s=s.firstChild)o++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=iu.empty;for(let e=i.length-1;e>=0;e--)r=iu.from(i[e].copy(r));n(e.tr.step(new sd(t.pos-i.length,t.pos+l.nodeSize,t.pos+o,t.pos+l.nodeSize-o,new ix(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function cZ(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return!!i.node(s).isTextblock&&(n&&n(t.tr.setSelection(sB.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let cX=cZ(-1),cY=cZ(1);function cQ(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(s,o,(r,s)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(s),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(s,o,e,t)}r(i.scrollIntoView())}return!0}}function c0(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}let c1=c0(cD,cI,cz),c2=c0(cD,cF,cH),c3={Enter:c0(cV,cK,cG,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof sH&&e.selection.node.isBlock)return!!n.parentOffset&&!!sx(e.doc,n.pos)&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let i=[],s,o,a=!1,l=!1;for(let e=n.depth;;e--){if(n.node(e).isBlock){let t;a=n.end(e)==n.pos+(n.depth-e),l=n.start(e)==n.pos-(n.depth-e),o=cW(n.node(e-1).contentMatchAt(n.indexAfter(e-1)));i.unshift(t||(a&&o?{type:o}:null)),s=e;break}if(1==e)return!1;i.unshift(null)}let c=e.tr;(e.selection instanceof sB||e.selection instanceof sV)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=sx(c.doc,d,i.length,i);if(u||(i[0]=o?{type:o}:null,u=sx(c.doc,d,i.length,i)),!u)return!1;if(c.split(d,i.length,i),!a&&l&&n.node(s).type!=o){let e=c.mapping.map(n.before(s)),t=c.doc.resolve(e);o&&n.node(s-1).canReplaceWith(t.index(),t.index()+1,o)&&c.setNodeMarkup(c.mapping.map(n.before(s)),o)}return t&&t(c.scrollIntoView()),!0}),"Mod-Enter":cq,Backspace:c1,"Mod-Backspace":c1,"Shift-Backspace":c1,Delete:c2,"Mod-Delete":c2,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new sV(e.doc))),!0)},c5={"Ctrl-h":c3.Backspace,"Alt-Backspace":c3["Mod-Backspace"],"Ctrl-d":c3.Delete,"Ctrl-Alt-Backspace":c3["Mod-Delete"],"Alt-Delete":c3["Mod-Delete"],"Alt-d":c3["Mod-Delete"],"Ctrl-a":cX,"Ctrl-e":cY};for(let e in c3)c5[e]=c3[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var c4=Object.defineProperty,c6=(e,t)=>{for(var n in t)c4(e,n,{get:t[n],enumerable:!0})};function c9(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}var c7=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(s);return i.getMeta("preventDispatch")||this.hasCustomState||r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o=[],a=!!e,l=e||i.tr,c=()=>(a||!t||l.getMeta("preventDispatch")||this.hasCustomState||s.dispatch(l),o.every(e=>!0===e)),d={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(l,t),i=n(...e)(r);return o.push(i),d}])),run:c};return d}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o={tr:e,editor:r,view:s,state:c9({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},c8={};c6(c8,{blur:()=>de,clearContent:()=>dt,clearNodes:()=>dn,command:()=>dr,createParagraphNear:()=>di,cut:()=>ds,deleteCurrentNode:()=>da,deleteNode:()=>dc,deleteRange:()=>dd,deleteSelection:()=>dp,enter:()=>dh,exitCode:()=>df,extendMarkRange:()=>dw,first:()=>dk,focus:()=>dM,forEach:()=>dA,insertContent:()=>dT,insertContentAt:()=>dR,joinBackward:()=>dP,joinDown:()=>dL,joinForward:()=>dz,joinItemBackward:()=>d$,joinItemForward:()=>dB,joinTextblockBackward:()=>dF,joinTextblockForward:()=>dH,joinUp:()=>dI,keyboardShortcut:()=>dV,lift:()=>dq,liftEmptyBlock:()=>dK,liftListItem:()=>dG,newlineInCode:()=>dJ,resetAttributes:()=>dY,scrollIntoView:()=>dQ,selectAll:()=>d0,selectNodeBackward:()=>d1,selectNodeForward:()=>d2,selectParentNode:()=>d3,selectTextblockEnd:()=>d5,selectTextblockStart:()=>d4,setContent:()=>d9,setMark:()=>uI,setMeta:()=>uL,setNode:()=>uP,setNodeSelection:()=>uz,setTextDirection:()=>u$,setTextSelection:()=>uB,sinkListItem:()=>uF,splitBlock:()=>uU,splitListItem:()=>uV,toggleList:()=>uK,toggleMark:()=>uG,toggleNode:()=>uJ,toggleWrap:()=>uZ,undoInputRule:()=>uX,unsetAllMarks:()=>uY,unsetMark:()=>uQ,unsetTextDirection:()=>u0,updateAttributes:()=>u1,wrapIn:()=>u2,wrapInList:()=>u3});var de=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dt=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dn=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return!n||(i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,s=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),a=s.blockRange(o);if(!a)return;let l=sh(a);if(e.type.isTextblock){let{defaultType:e}=s.parent.contentMatchAt(s.index());t.setNodeMarkup(a.start,e)}(l||0===l)&&t.lift(a,l)})}),!0)},dr=e=>t=>e(t),di=()=>({state:e,dispatch:t})=>cK(e,t),ds=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,s=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,s.content),r.setSelection(new sB(r.doc.resolve(Math.max(o-1,0)))),!0},da=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;n-=1)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function dl(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var dc=e=>({tr:t,state:n,dispatch:r})=>{let i=dl(e,n.schema),s=t.selection.$anchor;for(let e=s.depth;e>0;e-=1)if(s.node(e).type===i){if(r){let n=s.before(e),r=s.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},dd=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},du=(e,t,n)=>{var r;return!e.parent.isInline||"left"===n&&e.pos>e.start()||"right"===n&&e.pos<e.end()?e.pos:(r=t.nodes[e.parent.type.name].spec).content&&/^text(\*|\+)/.test(r.content)?"left"===n?e.start()-1:e.end()+1:e.pos},dp=()=>({state:e,dispatch:t})=>{var n;let{$from:r,$to:i}=e.selection;if(e.selection.empty)return!1;let{from:s,to:o}={from:du(r,n=e.schema,"left"),to:du(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dh=()=>({commands:e})=>e.keyboardShortcut("Enter"),df=()=>({state:e,dispatch:t})=>cq(e,t);function dm(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dg(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dm(t[r])?t[r].test(e[r]):t[r]===e[r])}function db(e,t,n={}){return e.find(e=>e.type===t&&dg(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dx(e,t,n={}){return!!db(e,t,n)}function dy(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!db([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,o=i+1,a=s+r.node.nodeSize;for(;i>0&&dx([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&dx([...e.parent.child(o).marks],t,n);)a+=e.parent.child(o).nodeSize,o+=1;return{from:s,to:a}}function dv(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var dw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dv(e,r.schema),{doc:o,selection:a}=n,{$from:l,from:c,to:d}=a;if(i){let e=dy(l,s,t);if(e&&e.from<=c&&e.to>=d){let t=sB.create(o,e.from,e.to);n.setSelection(t)}}return!0},dk=e=>t=>{let n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function dN(e){return e instanceof sB}function dS(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function dC(e,t=null){if(!t)return null;let n=sL.atStart(e),r=sL.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?sB.create(e,dS(0,i,s),dS(e.content.size,i,s)):sB.create(e,dS(t,i,s),dS(t,i,s))}function dj(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function dE(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var dM=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(dE()||dj())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!dE()&&!dj()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{!n.isDestroyed&&(r.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&null===e||!1===e)return!0}catch{return!1}if(s&&null===e&&!dN(n.state.selection))return o(),!0;let a=dC(i.doc,e)||n.state.selection,l=n.state.selection.eq(a);return s&&(l||i.setSelection(a),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},dA=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),dT=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),dO=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){let r=t[n];3===r.nodeType&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):1===r.nodeType&&dO(r)}return e};function d_(e){if("u"<typeof window)throw Error("[tiptap error]: there is no window object available, so this function cannot be used");let t=`<body>${e}</body>`;return dO(new window.DOMParser().parseFromString(t,"text/html").body)}function dD(e,t,n){if(e instanceof iO||e instanceof iu)return e;n={slice:!0,parseOptions:{},...n};let r="object"==typeof e&&null!==e,i="string"==typeof e;if(r)try{if(Array.isArray(e)&&e.length>0)return iu.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error("[tiptap error]: Invalid JSON content",{cause:r});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),dD("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new iq({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(r=!0,i="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?iG.fromSchema(s).parseSlice(d_(e),n.parseOptions):iG.fromSchema(s).parse(d_(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=iG.fromSchema(t);return n.slice?r.parseSlice(d_(e),n.parseOptions).content:r.parse(d_(e),n.parseOptions)}return dD("",t,n)}var dR=(e,t,n)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){let i,a;n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l=e=>{s.emit("contentError",{editor:s,error:e,disableCollaboration:()=>{"collaboration"in s.storage&&"object"==typeof s.storage.collaboration&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:null!=(o=n.errorOnInvalidContent)?o:s.options.enableContentCheck})}catch(e){return l(e),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},p=!0,h=!0;if((!("type"in i)?i:[i]).forEach(e=>{e.check(),p=!!p&&e.isText&&0===e.marks.length,h=!!h&&e.isBlock}),d===u&&h){let{parent:e}=r.doc.resolve(d);!e.isTextblock||e.type.spec.code||e.childCount||(d-=1,u+=1)}if(p){if(Array.isArray(t))a=t.map(e=>e.text||"").join("");else if(t instanceof iu){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),a=e}else a="object"==typeof t&&t&&t.text?t.text:t;r.insertText(a,d,u)}else{a=i;let e=r.doc.resolve(d),t=e.node(),n=0===e.parentOffset,s=t.isText||t.isTextblock,o=t.content.size>0;n&&s&&o&&h&&(d=Math.max(0,d-1)),r.replaceWith(d,u,a)}n.updateSelection&&function(e,t){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof sc||r instanceof sd))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(sL.near(e.doc.resolve(s),-1))}(r,r.steps.length-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:a}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:a})}return!0},dI=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof sH,i;if(r){if(n.node.isTextblock||!sy(e.doc,n.from))return!1;i=n.from}else if(null==(i=sw(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(sH.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),dL=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof sH){if(n.node.isTextblock||!sy(e.doc,n.to))return!1;r=n.to}else if(null==(r=sw(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),dP=()=>({state:e,dispatch:t})=>cI(e,t),dz=()=>({state:e,dispatch:t})=>cF(e,t),d$=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dB=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dF=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);return!!i&&cL(e,i,t)})(e,t),dH=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);return!!i&&cL(e,i,t)})(e,t);function dU(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var dV=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let s=(function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"===o&&(o=" ");for(let e=0;e<s.length-1;e+=1){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))dE()||dU()?i=!0:n=!0;else throw Error(`Unrecognized modifier name: ${o}`)}return t&&(o=`Alt-${o}`),n&&(o=`Ctrl-${o}`),i&&(o=`Meta-${o}`),r&&(o=`Shift-${o}`),o})(e).split(/-(?!$)/),o=s.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),a=new KeyboardEvent("keydown",{key:"Space"===o?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,a))});return null==l||l.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function dW(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dl(t,e.schema):null,a=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),s=Math.min(i,t+e.nodeSize);a.push({node:e,from:n,to:s})});let l=i-r,c=a.filter(e=>!o||o.name===e.node.type.name).filter(e=>dg(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var dq=(e,t={})=>({state:n,dispatch:r})=>{let i=dl(e,n.schema);return!!dW(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sh(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},dK=()=>({state:e,dispatch:t})=>cG(e,t),dG=e=>({state:t,dispatch:n})=>{var r;return(r=dl(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);return!!s&&(!t||(n.node(s.depth-1).type==r?function(e,t,n,r){let i=e.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new sd(s-1,o,s,o,new ix(iu.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new iA(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sh(r);if(null==a)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(s,-1)-1);return sy(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),t(i.scrollIntoView()),!0}(e,t,r,s):function(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,s=n.startIndex;t>s;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let s=r.doc.resolve(n.start),o=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=s.node(-1),d=s.index(-1);if(!c.canReplace(d+ +!a,d+1,o.content.append(l?iu.empty:iu.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sd(u-!!a,p+ +!!l,u+1,p-1,new ix((a?iu.empty:iu.from(i.copy(iu.empty))).append(l?iu.empty:iu.from(i.copy(iu.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},dJ=()=>({state:e,dispatch:t})=>cV(e,t);function dZ(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function dX(e,t){let n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var dY=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,dX(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(s=>{o===s.type&&(l=!0,i&&n.addMark(r,r+e.nodeSize,o.create(dX(s.attrs,t))))})})}),l},dQ=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),d0=()=>({tr:e,dispatch:t})=>{if(t){let t=new sV(e.doc);e.setSelection(t)}return!0},d1=()=>({state:e,dispatch:t})=>cz(e,t),d2=()=>({state:e,dispatch:t})=>cH(e,t),d3=()=>({state:e,dispatch:t})=>((e,t)=>{let{$from:n,to:r}=e.selection,i,s=n.sharedDepth(r);return 0!=s&&(i=n.before(s),t&&t(e.tr.setSelection(sH.create(e.doc,i))),!0)})(e,t),d5=()=>({state:e,dispatch:t})=>cY(e,t),d4=()=>({state:e,dispatch:t})=>cX(e,t);function d6(e,t,n={},r={}){return dD(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var d9=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:s,dispatch:o,commands:a})=>{let{doc:l}=s;if("full"!==r.preserveWhitespace){let a=d6(e,i.schema,r,{errorOnInvalidContent:null!=t?t:i.options.enableContentCheck});return o&&s.replaceWith(0,l.content.size,a).setMeta("preventUpdate",!n),!0}return o&&s.setMeta("preventUpdate",!n),a.insertContentAt({from:0,to:l.content.size},e,{parseOptions:r,errorOnInvalidContent:null!=t?t:i.options.enableContentCheck})};function d7(e,t){let n=dv(t,e.schema),{from:r,to:i,empty:s}=e.selection,o=[];s?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let a=o.find(e=>e.type.name===n.name);return a?{...a.attrs}:{}}function d8(e,t){let n=new sR(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function ue(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function ut(e,t){for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function un(e){return t=>ut(t.$from,e)}function ur(e,t,n){return void 0===e.config[t]&&e.parent?ur(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?ur(e.parent,t,n):null}):e.config[t]}function ui(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=ur(e,"addExtensions",t);return n?[e,...ui(n())]:e}).flat(10)}function us(e,t){let n=i3.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uo(e){return"function"==typeof e}function ua(e,t,...n){return uo(e)?t?e.bind(t)(...n):e(...n):e}function ul(e){let t=e.filter(e=>"extension"===e.type);return{baseExtensions:t,nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function uc(e){let t=[],{nodeExtensions:n,markExtensions:r}=ul(e),i=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>"text"!==e.name).map(e=>e.name),a=r.map(e=>e.name),l=[...o,...a];return e.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage,extensions:i},r=ur(e,"addGlobalAttributes",n);r&&r().forEach(e=>{(Array.isArray(e.types)?e.types:"*"===e.types?l:"nodes"===e.types?o:"marks"===e.types?a:[]).forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...s,...r}})})})})}),i.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage},r=ur(e,"addAttributes",n);r&&Object.entries(r()).forEach(([n,r])=>{let i={...s,...r};"function"==typeof(null==i?void 0:i.default)&&(i.default=i.default()),(null==i?void 0:i.isRequired)&&(null==i?void 0:i.default)===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function ud(e){let t=[],n=function(e){let t=[],n="",r=!1,i=!1,s=0,o=e.length;for(let a=0;a<o;a+=1){let o=e[a];if("'"===o&&!i){r=!r,n+=o;continue}if('"'===o&&!r){i=!i,n+=o;continue}if(!r&&!i){if("("===o){s+=1,n+=o;continue}if(")"===o&&s>0){s-=1,n+=o;continue}if(";"===o&&0===s){t.push(n),n="";continue}}n+=o}return n&&t.push(n),t}(e||""),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(":");if(-1===i)continue;let s=r.slice(0,i).trim(),o=r.slice(i+1).trim();s&&o&&t.push([s,o])}return t}function uu(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if("class"===e){let r=t?String(t).split(" "):[],i=n[e]?n[e].split(" "):[],s=r.filter(e=>!i.includes(e));n[e]=[...i,...s].join(" ")}else if("style"===e){let r=new Map([...ud(n[e]),...ud(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function up(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>uu(e,t),{})}function uh(e,t){return"style"in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===r)return!1;let i=t.reduce((e,t)=>{var r;let i=t.attribute.parseHTML?t.attribute.parseHTML(n):"string"!=typeof(r=n.getAttribute(t.name))?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):"true"===r||"false"!==r&&r;return null==i?e:{...e,[t.name]:i}},{});return{...r,...i}}}}function uf(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>!("attrs"===e&&function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function um(e){var t,n;let r={};return!(null==(t=null==e?void 0:e.attribute)?void 0:t.isRequired)&&"default"in((null==e?void 0:e.attribute)||{})&&(r.default=e.attribute.default),(null==(n=null==e?void 0:e.attribute)?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function ug(e){return e.sort((e,t)=>{let n=ur(e,"priority")||100,r=ur(t,"priority")||100;return n>r?-1:+(n<r)})}function ub(e){var t;let n=ug(ui(e)),r=Array.from(new Set((t=n.map(e=>e.name)).filter((e,n)=>t.indexOf(e)!==n)));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(e=>`'${e}'`).join(", ")}]. This can lead to issues.`),n}function ux(e,t,n){let{from:r,to:i}=t,{blockSeparator:s="\n\n",textSerializers:o={}}=n||{},a="";return e.nodesBetween(r,i,(e,n,l,c)=>{var d;e.isBlock&&n>r&&(a+=s);let u=null==o?void 0:o[e.type.name];if(u)return l&&(a+=u({node:e,pos:n,parent:l,index:c,range:t})),!1;e.isText&&(a+=null==(d=null==e?void 0:e.text)?void 0:d.slice(Math.max(r,n)-n,i-n))}),a}function uy(e,t){let n={from:0,to:e.content.size};return ux(e,n,t)}function uv(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function uw(e,t){let n=dZ("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dl(t,e.schema),{from:r,to:i}=e.selection,s=[];e.doc.nodesBetween(r,i,e=>{s.push(e)});let o=s.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}(e,t):"mark"===n?d7(e,t):{}}function uk(e){let t,{mapping:n,steps:r}=e,i=[];return n.maps.forEach((e,t)=>{let s=[];if(e.ranges.length)e.forEach((e,t)=>{s.push({from:e,to:t})});else{let{from:e,to:n}=r[t];if(void 0===e||void 0===n)return;s.push({from:e,to:n})}s.forEach(({from:e,to:r})=>{let s=n.slice(t).map(e,-1),o=n.slice(t).map(r),a=n.invert().map(s,-1),l=n.invert().map(o);i.push({oldRange:{from:a,to:l},newRange:{from:s,to:o}})})}),1===(t=function(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return!Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=!0)})}(i)).length?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function uN(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=dy(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&(null==e?void 0:e.nodeSize)!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}function uS(e,t){return t.nodes[e]||t.marks[e]||null}function uC(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return!!r&&r.attribute.keepOnSplit}))}function uj(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dv(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dg(e.attrs,n,{strict:!1}));let o=0,a=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(s&&e.inlineContent&&!e.type.allowsMarkType(s))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),l=Math.min(i,t+e.nodeSize);o+=l-n,a.push(...e.marks.map(e=>({mark:e,from:n,to:l})))})}),0===o)return!1;let l=a.filter(e=>!s||s.name===e.mark.type.name).filter(e=>dg(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=a.filter(e=>!s||e.mark.type!==s&&e.mark.type.excludes(s)).reduce((e,t)=>e+t.to-t.from,0);return(l>0?l+c:l)>=o}function uE(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function uM(e,t){let{nodeExtensions:n}=ul(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=ua(ur(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function uA(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return!/\S/.test(null!=(r=e.text)?r:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let r=!0;return e.content.forEach(e=>{!1!==r&&(uA(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function uT(e){return e instanceof sH}var uO=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function u_(e,t){let n=t.mapping.mapResult(e.position);return{position:new uO(n.pos),mapResult:n}}function uD(e){return new uO(e)}function uR(e,t,n){let r=e.state.doc.content.size,i=dS(t,0,r),s=dS(n,0,r),o=e.coordsAtPos(i),a=e.coordsAtPos(s,-1),l=Math.min(o.top,a.top),c=Math.max(o.bottom,a.bottom),d=Math.min(o.left,a.left),u=Math.max(o.right,a.right),p={top:l,bottom:c,left:d,right:u,width:u-d,height:c-l,x:d,y:l};return{...p,toJSON:()=>p}}var uI=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dv(e,r.schema);if(i)if(o){let e=d7(r,l);n.addStoredMark(l.create({...e,...t}))}else a.forEach(e=>{let i=e.$from.pos,s=e.$to.pos;r.doc.nodesBetween(i,s,(e,r)=>{let o=Math.max(r,i),a=Math.min(r+e.nodeSize,s);e.marks.find(e=>e.type===l)?e.marks.forEach(e=>{l===e.type&&n.addMark(o,a,l.create({...e.attrs,...t}))}):n.addMark(o,a,l.create(t))})});return function(e,t,n){var r;let{selection:i}=t,s=null;if(dN(i)&&(s=i.$cursor),s){let t=null!=(r=e.storedMarks)?r:s.marks();return s.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:o}=i;return o.some(({$from:t,$to:r})=>{let i=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),s=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&s}return!i}),i})}(r,n,l)},uL=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),uP=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dl(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!cQ(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>cQ(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},uz=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=dS(e,0,n.content.size),i=sH.create(n,r);t.setSelection(i)}return!0},u$=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s,o,{selection:a}=r;return"number"==typeof t?(s=t,o=t):t&&"from"in t&&"to"in t?(s=t.from,o=t.to):(s=a.from,o=a.to),i&&n.doc.nodesBetween(s,o,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},uB=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=sB.atStart(n).from,o=sB.atEnd(n).to,a=dS(r,s,o),l=dS(i,s,o),c=sB.create(n,a,l);t.setSelection(c)}return!0},uF=e=>({state:t,dispatch:n})=>{var r;return(r=dl(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(0==o)return!1;let a=s.parent,l=a.child(o-1);if(l.type!=r)return!1;if(t){let n=l.lastChild&&l.lastChild.type==a.type,i=iu.from(n?r.create():null),o=new ix(iu.from(r.create(null,iu.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sd(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function uH(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(r)}}var uU=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=uC(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof sH&&s.node.isBlock)return!!a.parentOffset&&!!sx(o,a.pos)&&(r&&(e&&uH(n,i.extensionManager.splittableMarks),t.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;let d=l.parentOffset===l.parent.content.size,u=0===a.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(a.node(-1).contentMatchAt(a.indexAfter(-1))),p=d&&u?[{type:u,attrs:c}]:void 0,h=sx(t.doc,t.mapping.map(a.pos),1,p);if(!p&&!h&&sx(t.doc,t.mapping.map(a.pos),1,u?[{type:u}]:void 0)&&(h=!0,p=u?[{type:u,attrs:c}]:void 0),r){if(h&&(s instanceof sB&&t.deleteSelection(),t.split(t.mapping.map(a.pos),1,p),u&&!d&&!a.parentOffset&&a.parent.type!==u)){let e=t.mapping.map(a.before()),n=t.doc.resolve(e);a.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(a.before()),u)}e&&uH(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},uV=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dl(e,r.schema),{$from:l,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||l.depth<2||!l.sameParent(c))return!1;let u=l.node(-1);if(u.type!==a)return!1;let p=s.extensionManager.attributes;if(0===l.parent.content.size&&l.node(-1).childCount===l.indexAfter(-1)){if(2===l.depth||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(i){let e=iu.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iu.from(l.node(t).copy(e));let i=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,s={...uC(p,l.node().type.name,l.node().attrs),...t},c=(null==(o=a.contentMatch.defaultType)?void 0:o.createAndFill(s))||void 0;e=e.append(iu.from(a.createAndFill(null,c)||void 0));let d=l.before(l.depth-(r-1));n.replace(d,l.after(-i),new ix(e,4-r,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(sB.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,f={...uC(p,u.type.name,u.attrs),...t},m={...uC(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:f},{type:h,attrs:m}]:[{type:a,attrs:f}];if(!sx(n.doc,l.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=s.extensionManager,a=t||e.$to.parentOffset&&e.$from.marks();if(n.split(l.pos,2,g).scrollIntoView(),!a||!i)return!0;let c=a.filter(e=>o.includes(e.type.name));n.ensureMarks(c)}return!0},uW=(e,t)=>{let n=un(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sy(e.doc,n.pos))||(e.join(n.pos),!0)},uq=(e,t)=>{let n=un(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sy(e.doc,r))||(e.join(r),!0)},uK=(e,t,n,r={})=>({editor:i,tr:s,state:o,dispatch:a,chain:l,commands:c,can:d})=>{let{extensions:u,splittableMarks:p}=i.extensionManager,h=dl(e,o.schema),f=dl(t,o.schema),{selection:m,storedMarks:g}=o,{$from:b,$to:x}=m,y=b.blockRange(x),v=g||m.$to.parentOffset&&m.$from.marks();if(!y)return!1;let w=un(e=>uM(e.type.name,u))(m),k=0===m.from&&m.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&uM(S.type.name,u)?{node:S,pos:0,depth:0}:null,j=null!=w?w:C,E=!!w&&y.depth>=1&&y.depth-w.depth<=1,M=!!C;if((E||M)&&j){if(j.node.type===h)return k&&M?l().command(({tr:e,dispatch:t})=>{let n=function(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return sB.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(f).run():c.liftListItem(f);if(uM(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>uW(s,h)).command(()=>uq(s,h)).run()}return n&&v&&a?l().command(()=>{let e=d().wrapInList(h,r),t=v.filter(e=>p.includes(e.type.name));return s.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run()},uG=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dv(e,r.schema);return uj(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},uJ=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dl(e,r.schema),a=dl(t,r.schema),l=dW(r,o,n);return(r.selection.$anchor.sameParent(r.selection.$head)&&(s=r.selection.$anchor.parent.attrs),l)?i.setNode(a,s):i.setNode(o,{...s,...n})},uZ=(e,t={})=>({state:n,commands:r})=>{let i=dl(e,n.schema);return dW(n,i,t)?r.lift(i):r.wrapIn(i,t)},uX=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i,s=n[r];if(s.spec.isInputRules&&(i=s.getState(e))){if(t){let t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){let n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},uY=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return!!r||(t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0)},uQ=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dv(e,r.schema),{$from:c,empty:d,ranges:u}=a;if(!i)return!0;if(d&&o){let{from:e,to:t}=a,r=null==(s=c.marks().find(e=>e.type===l))?void 0:s.attrs,i=dy(c,l,r);i&&(e=i.from,t=i.to),n.removeMark(e,t,l)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,l)});return n.removeStoredMark(l),!0},u0=e=>({tr:t,state:n,dispatch:r})=>{let i,s,{selection:o}=n;return"number"==typeof e?(i=e,s=e):e&&"from"in e&&"to"in e?(i=e.from,s=e.to):(i=o.from,s=o.to),r&&t.doc.nodesBetween(i,s,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},u1=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{let a,c,d,u,p=e.$from.pos,h=e.$to.pos;n.selection.empty?r.doc.nodesBetween(p,h,(e,t)=>{s&&s===e.type&&(l=!0,d=Math.max(t,p),u=Math.min(t+e.nodeSize,h),a=t,c=e)}):r.doc.nodesBetween(p,h,(e,r)=>{r<p&&s&&s===e.type&&(l=!0,d=Math.max(r,p),u=Math.min(r+e.nodeSize,h),a=r,c=e),r>=p&&r<=h&&(s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(s=>{if(o===s.type&&(l=!0,i)){let i=Math.max(r,p),a=Math.min(r+e.nodeSize,h);n.addMark(i,a,o.create({...s.attrs,...t}))}}))}),c&&(void 0!==a&&i&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),o&&c.marks.length&&c.marks.forEach(e=>{o===e.type&&i&&n.addMark(d,u,o.create({...e.attrs,...t}))}))}),l},u2=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s),a=o&&sf(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u3=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s);if(!o)return!1;let a=r?n.tr:null;return!!function(e,t,n,r=null){let i=!1,s=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=o.resolve(t.start-2);s=new iA(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new iA(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sf(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iu.empty;for(let e=n.length-1;e>=0;e--)s=iu.from(n[e].type.create(n[e].attrs,s));e.step(new sd(t.start-2*!!r,t.end,t.start,t.end,new ix(s,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let a=n.length-o,l=t.start+n.length-2*!!r,c=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&sx(e.doc,l,a)&&(e.split(l,a),l+=2*a),l+=c.child(n).nodeSize}(e,t,a,i,n),!0)}(a,o,e,t)&&(r&&r(a.scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u5=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},u4=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function u6(e){var t;let{editor:n,from:r,to:i,text:s,rules:o,plugin:a}=e,{view:l}=n;if(l.composing)return!1;let c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(null==(t=c.nodeBefore||c.nodeAfter)?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1,u=((e,t=500)=>{let n="",r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,s)=>{var o,a;let l=(null==(a=(o=e.type.spec).toText)?void 0:a.call(o,{node:e,pos:t,parent:i,index:s}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?l:l.slice(0,Math.max(0,r-t))}),n})(c)+s;return o.forEach(e=>{if(d)return;let t=((e,t)=>{if(dm(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r})(u,e.find);if(!t)return;let o=l.state.tr,c=c9({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:f,can:m}=new c7({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:f,can:m})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function u9(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var u7=class{constructor(e={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...ua(ur(this,"addOptions",{name:this.name}))}}get storage(){return{...ua(ur(this,"addStorage",{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>(function e(t,n){let r={...t};return u9(t)&&u9(n)&&Object.keys(n).forEach(i=>{u9(n[i])&&u9(t[i])?r[i]=e(t[i],n[i]):r[i]=n[i]}),r})(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name="name"in e?e.name:t.parent.name,t}},u8=class e extends u7{constructor(){super(...arguments),this.type="mark"}static create(t={}){return new e("function"==typeof t?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;let s=i.find(e=>(null==e?void 0:e.type.name)===t.name);return s&&n.removeStoredMark(s),n.insertText(" ",r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pe=class{constructor(e){this.find=e.find,this.handler=e.handler}},pt=null,pn=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=ub(e),this.schema=function(e,t){var n;let r=uc(e),{nodeExtensions:i,markExtensions:s}=ul(e),o=null==(n=i.find(e=>ur(e,"topNode")))?void 0:n.name;return new iq({topNode:o,nodes:Object.fromEntries(i.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uf({...e.reduce((e,t)=>{let r=ur(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:ua(ur(n,"content",s)),marks:ua(ur(n,"marks",s)),group:ua(ur(n,"group",s)),inline:ua(ur(n,"inline",s)),atom:ua(ur(n,"atom",s)),selectable:ua(ur(n,"selectable",s)),draggable:ua(ur(n,"draggable",s)),code:ua(ur(n,"code",s)),whitespace:ua(ur(n,"whitespace",s)),linebreakReplacement:ua(ur(n,"linebreakReplacement",s)),defining:ua(ur(n,"defining",s)),isolating:ua(ur(n,"isolating",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:up(e,i)}));let c=ur(n,"renderText",s);return c&&(o.toText=c),[n.name,o]})),marks:Object.fromEntries(s.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uf({...e.reduce((e,t)=>{let r=ur(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:ua(ur(n,"inclusive",s)),excludes:ua(ur(n,"excludes",s)),group:ua(ur(n,"group",s)),spanning:ua(ur(n,"spanning",s)),code:ua(ur(n,"code",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:up(e,i)})),[n.name,o]}))})}(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:uS(t.name,this.schema)},r=ur(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return ug([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:uS(t.name,this.schema)},r=[],i=ur(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&ur(t,"exitable",n)&&(s.ArrowRight=()=>u8.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));s={...s,...t}}let o=new s0({props:{handleKeyDown:lL(s)}});r.push(o);let a=ur(t,"addInputRules",n);if(uE(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new s0({state:{init:()=>null,apply(e,i,s){let o=e.getMeta(r);if(o)return o;let a=e.getMeta("applyInputRules");return a&&setTimeout(()=>{let{text:e}=a;"string"==typeof e||(e=us(iu.from(e),s.schema));let{from:i}=a,o=i+e.length;u6({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>u6({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&u6({editor:t,from:i.pos,to:i.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if("Enter"!==i.key)return!1;let{$cursor:s}=e.state.selection;return!!s&&u6({editor:t,from:s.pos,to:s.pos,text:"\n",rules:n,plugin:r})}},isInputRules:!0});return r}({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let l=ur(t,"addPasteRules",n);if(uE(t,e.options.enablePasteRules)&&l){let t=l();if(t&&t.length){let n=function(e){let t,{editor:n,rules:r}=e,i=null,s=!1,o=!1,a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}let l=({state:e,from:r,to:i,rule:s,pasteEvt:o})=>{let l=e.tr;if(function(e){let{editor:t,state:n,from:r,to:i,rule:s,pasteEvent:o,dropEvent:a}=e,{commands:l,chain:c,can:d}=new c7({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,f,m,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let b=null!=(g=null!=(m=null==(f=e.content)?void 0:f.size)?m:e.nodeSize)?g:0,x=Math.max(r,t),y=Math.min(i,t+b);x>=y||((e,t,n)=>{if(dm(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),n.push(t.replaceWith)),n}):[]})(e.isText?e.text||"":e.textBetween(x-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=x+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},p=s.handler({state:n,range:i,match:e,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});u.push(p)})}),u.every(e=>null!==e)}({editor:n,state:c9({state:e,transaction:l}),from:Math.max(r-1,0),to:i.b-1,rule:s,pasteEvent:o,dropEvent:t})&&l.steps.length){try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}return a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null,l}};return r.map(e=>new s0({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pt=n)},r=()=>{pt&&(pt=null)};return window.addEventListener("dragstart",t),window.addEventListener("dragend",r),{destroy(){window.removeEventListener("dragstart",t),window.removeEventListener("dragend",r)}}},props:{handleDOMEvents:{drop:(e,n)=>{if(o=i===e.dom.parentElement,t=n,!o){let e=pt;(null==e?void 0:e.isEditable)&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;let r=null==(n=t.clipboardData)?void 0:n.getData("text/html");return a=t,s=!!(null==r?void 0:r.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,r)=>{let i=t[0],c="paste"===i.getMeta("uiEvent")&&!s,d="drop"===i.getMeta("uiEvent")&&!o,u=i.getMeta("applyPasteRules"),p=!!u;if(!c&&!d&&!p)return;if(p){var h,f;let t,{text:n}=u;"string"==typeof n||(n=us(iu.from(n),r.schema));let{from:i}=u,s=i+n.length;return l({rule:e,state:r,from:i,to:{b:s},pasteEvt:(h=n,null==(f=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||f.setData("text/html",h),t)})}let m=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof m&&g&&m!==g.b)return l({rule:e,state:r,from:m,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=ur(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uc(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(e,"addNodeView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dl(t.name,this.schema)},i=ur(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=up(r,n);return s({node:r,view:i,getPos:o,decorations:a,innerDecorations:l,editor:e,extension:t,HTMLAttributes:c})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return ug([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return ug([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"transformPastedHTML",r);return i?(t,n)=>{let s=e(t,n);return i.call(r,s)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(e,"addMarkView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dv(t.name,this.schema)},i=ur(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=up(r,n);return i()({mark:r,view:s,inline:o,editor:e,extension:t,HTMLAttributes:a,updateAttributes:t=>{!function(e,t,n={}){let{state:r}=t,{doc:i,tr:s}=r;i.descendants((t,r)=>{let i=s.mapping.map(r),o=s.mapping.map(r)+t.nodeSize,a=null;if(t.marks.forEach(t=>{if(t!==e)return!1;a=t}),!a)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==a.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});s.removeMark(i,o,e.type),s.addMark(i,o,t)}}),s.docChanged&&t.view.dispatch(s)}(r,e,t)}})}]:[]}))}destroy(){this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{var t;let n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:uS(e.name,this.schema)};"mark"===e.type&&(null==(t=ua(ur(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=ur(e,"onBeforeCreate",n),i=ur(e,"onCreate",n),s=ur(e,"onUpdate",n),o=ur(e,"onSelectionUpdate",n),a=ur(e,"onTransaction",n),l=ur(e,"onFocus",n),c=ur(e,"onBlur",n),d=ur(e,"onDestroy",n);r&&this.editor.on("beforeCreate",r),i&&this.editor.on("create",i),s&&this.editor.on("update",s),o&&this.editor.on("selectionUpdate",o),a&&this.editor.on("transaction",a),l&&this.editor.on("focus",l),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}};pn.resolve=ub,pn.sort=ug,pn.flatten=ui,c6({},{ClipboardTextSerializer:()=>pi,Commands:()=>ps,Delete:()=>po,Drop:()=>pa,Editable:()=>pl,FocusEvents:()=>pd,Keymap:()=>pu,Paste:()=>pp,Tabindex:()=>ph,TextDirection:()=>pf,focusEventsPluginKey:()=>pc});var pr=class e extends u7{constructor(){super(...arguments),this.type="extension"}static create(t={}){return new e("function"==typeof t?t():t)}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pi=pr.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:s}=i,o=Math.min(...s.map(e=>e.$from.pos)),a=Math.max(...s.map(e=>e.$to.pos)),l=uv(n);return ux(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),ps=pr.create({name:"commands",addCommands:()=>({...c8})}),po=pr.create({name:"delete",onUpdate({transaction:e,appendedTransactions:t}){var n,r,i;let s=()=>{var n,r,i,s;if(null!=(s=null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.filterTransaction)?void 0:i.call(r,e))?s:e.getMeta("y-sync$"))return;let o=d8(e.before,[e,...t]);uk(o).forEach(t=>{o.mapping.mapResult(t.oldRange.from).deletedAfter&&o.mapping.mapResult(t.oldRange.to).deletedBefore&&o.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let i=r+n.nodeSize-2,s=t.oldRange.from<=r&&i<=t.oldRange.to;this.editor.emit("delete",{type:"node",node:n,from:r,to:i,newFrom:o.mapping.map(r),newTo:o.mapping.map(i),deletedRange:t.oldRange,newRange:t.newRange,partial:!s,editor:this.editor,transaction:e,combinedTransform:o})})});let a=o.mapping;o.steps.forEach((t,n)=>{var r,i;if(t instanceof so){let s=a.slice(n).map(t.from,-1),l=a.slice(n).map(t.to),c=a.invert().map(s,-1),d=a.invert().map(l),u=s>0&&(null==(r=o.doc.nodeAt(s-1))?void 0:r.marks.some(e=>e.eq(t.mark))),p=null==(i=o.doc.nodeAt(l))?void 0:i.marks.some(e=>e.eq(t.mark));this.editor.emit("delete",{type:"mark",mark:t.mark,from:t.from,to:t.to,deletedRange:{from:c,to:d},newRange:{from:s,to:l},partial:!!(p||u),editor:this.editor,transaction:e,combinedTransform:o})}})};null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.async)||i?setTimeout(s,0):s()}}),pa=pr.create({name:"drop",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pl=pr.create({name:"editable",addProseMirrorPlugins(){return[new s0({key:new s3("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pc=new s3("focusEvents"),pd=pr.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new s0({key:pc,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),pu=pr.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:s}=n,{pos:o,parent:a}=s,l=s.parent.isTextblock&&o>0?t.doc.resolve(o-1):s,c=l.parent.type.spec.isolating,d=s.pos-s.parentOffset,u=c&&1===l.parent.childCount?d===s.pos:sL.atStart(r).from===o;return!!i&&!!a.type.isTextblock&&!a.textContent.length&&!!u&&(!u||"paragraph"!==s.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return dE()||dU()?i:r},addProseMirrorPlugins(){return[new s0({key:new s3("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventClearDocument"));if(!r||i)return;let{empty:s,from:o,to:a}=t.selection,l=sL.atStart(t.doc).from,c=sL.atEnd(t.doc).to;if(s||o!==l||a!==c||!uA(n.doc))return;let d=n.tr,u=c9({state:n,transaction:d}),{commands:p}=new c7({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pp=pr.create({name:"paste",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),ph=pr.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pf=pr.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=ul(this.extensions);return[{types:e.filter(e=>"text"!==e.name).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute("dir");return t&&("ltr"===t||"rtl"===t||"auto"===t)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new s0({key:new s3("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pm=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!=(e=this.actualDepth)?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return void console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(0===this.depth)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,o=n.isInline,a=this.pos+r+ +!s;if(a<0||a>this.resolvedPos.doc.nodeSize-2)return;let l=this.resolvedPos.doc.resolve(a);if(!i&&!o&&l.depth<=this.depth)return;let c=new e(l,this.editor,i,i||o?n:null);i&&(c.actualDepth=this.depth+1),t.push(c)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||0===this.children.length)return r;let i=Object.keys(t);return this.children.forEach(s=>{n&&r.length>0||(s.node.type.name===e&&i.every(e=>t[e]===s.node.attrs[e])&&r.push(s),n&&r.length>0||(r=r.concat(s.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},pg=`.ProseMirror {
21
+ ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[d,u]=(0,f.useState)(""),p=(0,f.useRef)(null),m=window.location.origin,b=(0,f.useCallback)(()=>t9,[]),x=(0,f.useCallback)(()=>d.replace(/\$WIKI_URL/g,m),[d,m]),y=(0,f.useCallback)(()=>`npx wiki-viewer-mcp register --url ${m} --id ai:myagent --name "My Agent"`,[m]),w=(0,f.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:m,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[m]),k=t7(b),N=t7(x),S=t7(y),C=t7(w);return((0,f.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,f.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,f.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,f.useEffect)(()=>{t&&fetch((0,ev.apiUrl)("/api/agents/install")).then(e=>e.json()).then(e=>{e.bootstrapPrompt&&u(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,s.jsxs)("aside",{ref:p,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-[90vw] max-w-sm md:w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(a,{className:"h-4 w-4 text-muted-foreground"}),(0,s.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,s.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,s.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,s.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void N.copy(),disabled:!d,children:N.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:t9}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void k.copy(),children:k.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:y()}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void S.copy(),children:S.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,s.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void C.copy(),children:C.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3 w-3"})," curl example"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/skill"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/install"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,s.jsx)(t$,{}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,s.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,s.jsx)(tA,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,s.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,s.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,s.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,s.jsx)(t6,{activity:r})})]}),(0,s.jsx)("section",{children:(0,s.jsx)("a",{href:(0,ev.apiUrl)("/docs/agent-collab-plan.md"),target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var ne=e.i(406347);let nt=(0,o.default)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),nn=(0,o.default)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),nr=(0,o.default)("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]),ni=(0,o.default)("file-plus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),ns=(0,o.default)("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]),no=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),na=(0,o.default)("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);function nl({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,f.useState)(""),d=(0,f.useRef)(null);if((0,f.useEffect)(()=>{let e=e=>{let t=e.target;d.current?.contains(t)||t?.closest?.("[data-branch-trigger]")||a()},t=e=>{"Escape"===e.key&&a()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a]),"u"<typeof document)return null;let p=t.length>8,h=l.trim().toLowerCase(),m=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tv.createPortal)((0,s.jsx)("div",{ref:d,"data-branch-portal":!0,style:{position:"fixed",top:e.top,left:e.left},className:"pointer-events-auto z-[9999] flex max-h-72 w-52 flex-col overflow-hidden rounded-md border bg-popover p-1 shadow-md",children:n?(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===t.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("input",{autoFocus:!0,value:l,onChange:e=>c(e.target.value),placeholder:"Filter branches…",className:"mb-1 w-full shrink-0 rounded border bg-background px-1.5 py-1 text-[11px] outline-none focus:ring-1 focus:ring-ring"}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:0===m.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):m.map(e=>(0,s.jsxs)("button",{type:"button",disabled:i||e.current,className:(0,eh.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",e.current?"font-semibold text-foreground":"text-muted-foreground"),onClick:t=>{t.stopPropagation(),e.current||o(e.name)},children:[e.current?(0,s.jsx)(g.Check,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)("span",{className:"w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name}),r===e.name&&(0,s.jsx)(u.Loader2,{className:"ml-auto h-3 w-3 shrink-0 animate-spin"})]},e.name))})]})}),document.body)}var nc=e.i(918552),nd=e.i(136131),nu="ContextMenu",[np,nh]=(0,N.createContextScope)(nu,[nc.createMenuScope]),nf=(0,nc.createMenuScope)(),[nm,ng]=np(nu),nb=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=f.useState(!1),c=nf(t),d=(0,nd.useCallbackRef)(r),u=f.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(nm,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(nc.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nb.displayName=nu;var nx="ContextMenuTrigger",ny=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=ng(nx,n),a=nf(n),l=f.useRef({x:0,y:0}),c=f.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=f.useRef(0),u=f.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return f.useEffect(()=>u,[u]),f.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(nc.Anchor,{...a,virtualRef:c}),(0,s.jsx)(T.Primitive.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:(0,w.composeEventHandlers)(e.onContextMenu,e=>{u(),p(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:(0,w.composeEventHandlers)(e.onPointerDown,nO(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nO(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nO(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nO(u))})]})});ny.displayName=nx;var nv=e=>{let{__scopeContextMenu:t,...n}=e,r=nf(t);return(0,s.jsx)(nc.Portal,{...r,...n})};nv.displayName="ContextMenuPortal";var nw="ContextMenuContent",nk=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=ng(nw,n),o=nf(n),a=f.useRef(!1);return(0,s.jsx)(nc.Content,{...o,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&a.current&&t.preventDefault(),a.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||i.modal||(a.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});nk.displayName=nw,f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nN=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Label,{...i,...r,ref:t})});nN.displayName="ContextMenuLabel";var nS=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Item,{...i,...r,ref:t})});nS.displayName="ContextMenuItem";var nC=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.CheckboxItem,{...i,...r,ref:t})});nC.displayName="ContextMenuCheckboxItem",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nj=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioItem,{...i,...r,ref:t})});nj.displayName="ContextMenuRadioItem";var nE=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.ItemIndicator,{...i,...r,ref:t})});nE.displayName="ContextMenuItemIndicator";var nM=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Separator,{...i,...r,ref:t})});nM.displayName="ContextMenuSeparator",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nA=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubTrigger,{...i,...r,ref:t})});nA.displayName="ContextMenuSubTrigger";var nT=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubContent,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});function nO(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nT.displayName="ContextMenuSubContent";var n_=e.i(149427);f.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nA,{ref:i,className:(0,eh.cn)("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,(0,s.jsx)(e3.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nA.displayName,f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nT,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})).displayName=nT.displayName;let nD=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nv,{children:(0,s.jsx)(nk,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})}));nD.displayName=nk.displayName;let nR=f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nS,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));nR.displayName=nS.displayName,f.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nC,{ref:i,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nE,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nC.displayName,f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nj,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nE,{children:(0,s.jsx)(n_.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nj.displayName,f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nN,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nN.displayName;let nI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nM,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));nI.displayName=nM.displayName;let nL="wiki-humanize-names",nP=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nL),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nL,"1"):localStorage.removeItem(nL),e({humanize:n})}})),nz="wiki-show-hidden",n$=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nz),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nz,"1"):localStorage.removeItem(nz),e({showHidden:n})}}));function nB(e){return e.split(".").pop()?.toLowerCase()??""}function nF(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=e.split("/").pop()??e;if(n.startsWith(".")&&-1===n.indexOf(".",1))return"source";let r=nB(e);return r?["md","markdown"].includes(r)?"editor":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(r)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(r)?"media":"docx"===r?"docx":["xlsx","xlsm"].includes(r)?"xlsx":"pptx"===r?"pptx":"html"===r?"html":(["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(r),"source"):"source"}let nH=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function nU(e){let t=nF(e,"file");return"editor"===t||"text"===t||nH.has(nB(e))}function nV(e){return["md","markdown"].includes(nB(e))}function nW(e){return"image"===nF(e,"file")}function nq(e){return"html"===nF(e,"file")}let nK={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nG({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nD,{className:"w-48",children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(nR,{onSelect:()=>t.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(nR,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(nR,{onSelect:()=>t.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(nI,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nR,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nR,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(nI,{})]}),(0,s.jsxs)(nR,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nR,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(nI,{}),(0,s.jsxs)(nR,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nJ({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(e5,{className:(0,eh.cn)(n,"text-foreground/70")}):"app"===t?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/70")}):"node-app"===t?(0,s.jsx)(no,{className:(0,eh.cn)(n,"text-emerald-500")}):nq(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):nW(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nU(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)(n,"text-foreground/60")})}let nZ=(0,f.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:f,isPulling:m,branchOpen:g,branchPos:b,branches:x,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nP(e=>e.humanize);return(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:r=>{if("Enter"===r.key||" "===r.key)r.preventDefault(),"dir"===e.type?n.toggleFolder(e):"app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e);else if("ArrowDown"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else if("ArrowUp"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n-1]?.focus()}else if("ArrowRight"===r.key){if(r.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===r.key){if(r.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(t>0){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=r.currentTarget,i=t.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=i-1;e>=0;e--)if(Number.parseInt(t[e].style.paddingLeft??"0",10)<s){t[e].focus();break}}}},onDragStart:t=>n.handleDragStart(t,e),onDragOver:t=>"dir"===e.type?n.handleDragOver(t,e.path,"dir"):t.preventDefault(),onDragLeave:()=>n.setDragOverPath(null),onDrop:t=>"dir"===e.type?n.handleDropOnFolder(t,e.path):t.preventDefault(),onMouseEnter:()=>k(e),onMouseLeave:N,className:(0,eh.cn)("tree-row-reveal flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none touch-target",a?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",p&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*t+8}px`,...nK},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),r&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,s.jsx)(e3.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200 ease-out",style:{transform:e.expanded?"rotate(90deg)":"rotate(0deg)"}}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"",children:"dir"===e.type?e.expanded?(0,s.jsx)(e4,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(e5,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"app"===e.type?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"node-app"===e.type?(0,s.jsx)(no,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nq(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):nW(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nU(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",title:T?e.name:void 0,children:T?(E=(j=(C=(S=e.name).lastIndexOf("."))>0&&C<S.length-1)?S.slice(0,C):S,M=j?S.slice(C):"",(A=E.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[\s_-]+/).filter(Boolean).map(e=>/^[A-Z0-9]+$/.test(e)?e:e[0].toUpperCase()+e.slice(1))).length?A.join(" ")+M:S):e.name}),e.git&&(0,s.jsxs)("span",{className:"relative flex shrink-0 items-center gap-0.5 rounded-sm bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),g){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let r=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:r.bottom+4,left:r.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,s.jsx)("span",{className:"ml-0.5 text-foreground/70",children:"*"})]}),m?(0,s.jsx)(u.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,s.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,r)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,s.jsx)(tR,{className:"h-2.5 w-2.5"})}),g&&b&&(0,s.jsx)(nl,{pos:b,branches:x,loading:y,busyName:w,disabled:null!==w,onPick:t=>{let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,r)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),f&&(0,s.jsx)("span",{className:"ml-0.5 h-1.5 w-1.5 rounded-full bg-emerald-400 shrink-0 animate-pulse",title:"Agent recently active"}),(0,s.jsx)("div",{className:"hover-reveal flex max-w-0 shrink-0 items-center overflow-hidden opacity-0 transition-all duration-150 group-hover:max-w-7 group-hover:opacity-100 focus-within:max-w-7 focus-within:opacity-100",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{})]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.toggleFavorite(e,i),children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",h&&"fill-current text-amber-400")}),h?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nG,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nX=(0,f.memo)(function(e){let{ctx:t,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:o,nodeBranches:a,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:p,favorites:m,isMobile:b,activeWorkspaceId:x,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=n$(e=>e.showHidden),M=(0,f.useRef)(null),A=(0,f.useCallback)(e=>{let n=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||n)&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>t.prefetch(e),120))},[t]),T=(0,f.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,f.useMemo)(()=>{let t=[],n=(e,r)=>{for(let i of e)!(!E&&i.name.startsWith("."))&&(t.push({kind:"row",node:i,depth:r}),"dir"===i.type&&(N===i.path&&t.push({kind:"newfolder",node:i,depth:r}),y===i.path&&t.push({kind:"newfile",node:i,depth:r})),("dir"===i.type||"app"===i.type||"node-app"===i.type)&&i.expanded&&(i.children&&i.children.length>0?n(i.children,r+1):i.children?.length===0&&t.push({kind:"empty",node:i,depth:r})))};return n(e.nodes,0),t},[e.nodes,y,N,E]);return(0,s.jsx)(s.Fragment,{children:O.map(e=>{let{node:f,depth:y}=e;if("row"===e.kind){let e=i===f.path;return(0,s.jsx)(nZ,{node:f,depth:y,ctx:t,isMobile:b,activeWorkspaceId:x,sidebarScrollRef:j,isActive:n===f.path,isDragOver:r===f.path,isFavorited:m.some(e=>e.path===f.path),isAgentActive:p.has(f.path),isPulling:u===f.path,branchOpen:e,branchPos:e?o:null,branches:f.git?a[f.path]??[]:[],branchLoading:!!f.git&&!!c[f.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},f.path)}return"newfolder"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-foreground/70"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:S,onChange:e=>t.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFolder(),"Escape"===e.key&&(t.setNewFolderParent(null),t.setNewFolderName(""))}}),C&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:C}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFolder,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFolderParent(null),t.setNewFolderName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`nf-${f.path}`):"newfile"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:w,onChange:e=>t.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFile(),"Escape"===e.key&&(t.setNewFileParent(null),t.setNewFileName(""))}}),k&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFile,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFileParent(null),t.setNewFileName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`ff-${f.path}`):(0,s.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(y+1)*14+8+14+6+16+6}px`,...nK},children:"Empty"},`empty-${f.path}`)})})});function nY(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nQ(e){try{let t=localStorage.getItem(nY(e));return t?JSON.parse(t):[]}catch{return[]}}let n0=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nQ(t)})},toggle:(t,n)=>{let r=nQ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nY(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function n1({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=n0(e=>e.isFavorited(t.path));return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{let e=(0,tE.withWs)(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),n=document.createElement("a");n.href=e,n.download=t.name,document.body.appendChild(n),n.click(),n.remove()},children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n0.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(te,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",i&&"fill-current text-amber-400")}),i?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyPath(t.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(t.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyWikiLink(t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyUrl(t.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nU(t.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyRawContent(t.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyFormattedContent(t.path,t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),n]})]})]})}let n2=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n3=e.i(409082);let n5=(0,o.default)("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);var n4=e.i(847463),n6=e.i(917356),n9=/[\\\/_+.#"@\[\(\{&]/,n7=/[\\\/_+.#"@\[\(\{&]/g,n8=/[\s-]/,re=/[\s-]/g;function rt(e){return e.toLowerCase().replace(re," ")}var rn='[cmdk-group=""]',rr='[cmdk-group-items=""]',ri='[cmdk-item=""]',rs=`${ri}:not([aria-disabled="true"])`,ro="cmdk-item-select",ra="data-value",rl=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,s,o,a){if(o===n.length)return s===t.length?1:.99;var l=`${s},${o}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(o),f=r.indexOf(h,s),m=0;f>=0;)(c=e(t,n,r,i,f+1,o+1,a))>m&&(f===s?c*=1:n9.test(t.charAt(f-1))?(c*=.8,(u=t.slice(s,f-1).match(n7))&&s>0&&(c*=Math.pow(.999,u.length))):n8.test(t.charAt(f-1))?(c*=.9,(p=t.slice(s,f-1).match(re))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,f-s))),t.charAt(f)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(f-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,f+1,o+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,rt(r),rt(t),0,0,{})},rc=f.createContext(void 0),rd=f.createContext(void 0),ru=f.createContext(void 0),rp=f.forwardRef((e,t)=>{let n=rk(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=rk(()=>new Set),i=rk(()=>new Map),s=rk(()=>new Map),o=rk(()=>new Set),a=rv(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:m,disablePointerSelection:g=!1,vimBindings:b=!0,...x}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=f.useRef(null),N=rC();rw(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rw(()=>{N(6,O)},[]);let C=f.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,s,o,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)T(),M(),N(1,A);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(w);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(N(7,()=>{var e;n.current.selectedItemId=null==(e=_())?void 0:e.id,C.emit()}),r||N(5,O),(null==(s=a.current)?void 0:s.value)!==void 0){null==(l=(o=a.current).onValueChange)||l.call(o,null!=t?t:"");return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),j=f.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=s.current.get(e))?void 0:i.value)&&(s.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),N(2,()=>{M(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),N(3,()=>{T(),M(),n.current.value||A(),C.emit()}),()=>{s.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=_();N(4,()=>{T(),(null==t?void 0:t.getAttribute("id"))===e&&A(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{s.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:w,labelId:v,listInnerRef:k}),[]);function E(e,t){var r,i;let s=null!=(i=null==(r=a.current)?void 0:r.filter)?i:rl;return e?s(e,n.current.search,t):0}function M(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),s=0;r.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([n,s])});let r=k.current;D().sort((t,n)=>{var r,i;let s=t.getAttribute("id"),o=n.getAttribute("id");return(null!=(r=e.get(o))?r:0)-(null!=(i=e.get(s))?i:0)}).forEach(e=>{let t=e.closest(rr);t?t.appendChild(e.parentElement===t?e:e.closest(`${rr} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${rr} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${rn}[${ra}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function A(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(ra);C.setState("value",t||void 0)}function T(){var e,t,o,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=E(null!=(t=null==(e=s.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(o=s.current.get(i))?void 0:o.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function O(){var e,t,n;let r=_();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(rn))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function _(){var e;return null==(e=k.current)?void 0:e.querySelector(`${ri}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rs))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ra))}function I(e){var t;let n=_(),r=D(),i=r.findIndex(e=>e===n),s=r[i+e];null!=(t=a.current)&&t.loop&&(s=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),s&&C.setState("value",s.getAttribute(ra))}function L(e){let t=_(),n=null==t?void 0:t.closest(rn),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,rn):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,rn))?void 0:n.querySelector(rs);r?C.setState("value",r.getAttribute(ra)):I(e)}let P=()=>R(D().length-1),z=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},$=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return f.createElement(tk.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=x.onKeyDown)||t.call(x,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":b&&e.ctrlKey&&z(e);break;case"ArrowDown":z(e);break;case"p":case"k":b&&e.ctrlKey&&$(e);break;case"ArrowUp":$(e);break;case"Home":e.preventDefault(),R(0);break;case"End":e.preventDefault(),P();break;case"Enter":{e.preventDefault();let t=_();if(t){let e=new Event(ro);t.dispatchEvent(e)}}}}},f.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rE},l),rj(e,e=>f.createElement(rd.Provider,{value:C},f.createElement(rc.Provider,{value:j},e))))}),rh=f.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=f.useRef(null),o=f.useContext(ru),a=f.useContext(rc),l=rv(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rw(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rS(i,s,[e.value,e.children,s],e.keywords),u=f.useContext(rd),p=rN(e=>e.value&&e.value===d.current),h=rN(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function m(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(f.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(ro,m),()=>t.removeEventListener(ro,m)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:b,value:x,onSelect:y,forceMount:v,keywords:w,...N}=e;return f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!b,"aria-selected":!!p,"data-disabled":!!b,"data-selected":!!p,onPointerMove:b||a.getDisablePointerSelection()?void 0:g,onClick:b?void 0:m},e.children)}),rf=f.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=f.useRef(null),l=f.useRef(null),c=(0,S.useId)(),d=f.useContext(rc),u=rN(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rw(()=>d.group(o),[]),rS(o,a,[e.value,e.heading,l]);let p=f.useMemo(()=>({id:o,forceMount:i}),[i]);return f.createElement(tk.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&f.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rj(e,e=>f.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},f.createElement(ru.Provider,{value:p},e))))}),rm=f.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=f.useRef(null),s=rN(e=>!e.search);return n||s?f.createElement(tk.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rg=f.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=f.useContext(rd),o=rN(e=>e.search),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),f.createElement(tk.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:o,onChange:e=>{i||s.setState("search",e.target.value),null==n||n(e.target.value)}})}),rb=f.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=f.useRef(null),o=f.useRef(null),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{if(o.current&&s.current){let e=o.current,t=s.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rj(e,e=>f.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rx=f.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return f.createElement(B,{open:n,onOpenChange:r},f.createElement(W,{container:o},f.createElement(K,{"cmdk-overlay":"",className:i}),f.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},f.createElement(rp,{ref:t,...a}))))}),ry=Object.assign(rp,{List:rb,Item:rh,Input:rg,Group:rf,Separator:rm,Dialog:rx,Empty:f.forwardRef((e,t)=>rN(e=>0===e.filtered.count)?f.createElement(tk.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:f.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return f.createElement(tk.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rj(e,e=>f.createElement("div",{"aria-hidden":!0},e)))})});function rv(e){let t=f.useRef(e);return rw(()=>{t.current=e}),t}var rw="u"<typeof window?f.useEffect:f.useLayoutEffect;function rk(e){let t=f.useRef();return void 0===t.current&&(t.current=e()),t}function rN(e){let t=f.useContext(rd),n=()=>e(t.snapshot());return f.useSyncExternalStore(t.subscribe,n,n)}function rS(e,t,n,r=[]){let i=f.useRef(),s=f.useContext(rc);return rw(()=>{var o;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());s.value(e,a,l),null==(o=t.current)||o.setAttribute(ra,a),i.current=a}),i}var rC=()=>{let[e,t]=f.useState(),n=rk(()=>new Map);return rw(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rj({asChild:e,children:t},n){let r;return e&&f.isValidElement(t)?f.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var rE={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rM=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rA=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry,{ref:n,className:(0,eh.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function rT({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eX,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(e0,{className:"sr-only",children:"Search"}),(0,s.jsx)(rA,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}rA.displayName=ry.displayName;let rO=f.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rM,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(ry.Input,{ref:n,className:(0,eh.cn)("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));rO.displayName=ry.Input.displayName;let r_=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));r_.displayName=ry.List.displayName;let rD=f.forwardRef((e,t)=>(0,s.jsx)(ry.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rD.displayName=ry.Empty.displayName;let rR=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Group,{ref:n,className:(0,eh.cn)("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));rR.displayName=ry.Group.displayName;let rI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));rI.displayName=ry.Separator.displayName;let rL=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Item,{ref:n,className:(0,eh.cn)("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));rL.displayName=ry.Item.displayName;let rP=null,rz=null,r$=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rz&&clearTimeout(rz),rP?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rz&&clearTimeout(rz),t.trim())?(e({loading:!0}),new Promise(n=>{rz=setTimeout(()=>{rB(e,t).finally(n)},150)})):(rP?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rB(e,t){rP?.abort();let n=new AbortController;rP=n;try{let r=await (0,tE.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var rF=e.i(395624);function rH({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,s.jsx)(s.Fragment,{children:t.map((e,t)=>e.mark?(0,s.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,s.jsx)("span",{children:e.text},t))})}function rU({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=r$(e=>e.open),l=r$(e=>e.setOpen),c=r$(e=>e.query),d=r$(e=>e.setQuery),u=r$(e=>e.results),p=r$(e=>e.loading),h=r$(e=>e.truncated),m=r$(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,n6.useTheme)(),x=tO(e=>e.toggle),y=(0,rF.useViewWidthStore)(e=>e.width),v=(0,rF.useViewWidthStore)(e=>e.cycle),w=c.trimStart(),k=""===w||w.startsWith(">"),N=""===w&&t.length>0,S=k?"":c;function C(e){e(),l(!1),d("")}(0,f.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!o))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,f.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{m(S)},120);return()=>clearTimeout(e)},[S,k,o,m]);let j=(rF.VIEW_WIDTH_ORDER.indexOf(y)+1)%rF.VIEW_WIDTH_ORDER.length,E=rF.VIEW_WIDTH_LABEL[rF.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rT,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rO,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(r_,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rR,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rL,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(to,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate font-medium",children:t.name}),(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:t.path})]})]},t.path))}),(0,s.jsx)(rI,{})]}),k&&(0,s.jsxs)(rR,{heading:"Actions",children:[(0,s.jsxs)(rL,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n4.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rL,{value:"toggle-ai-panel",onSelect:()=>C(x),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rL,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n5,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rL,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(ni,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rL,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rL,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(n2,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",rF.VIEW_WIDTH_LABEL[y]," → ",E,")"]})]})]})]}),!k&&(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==S.trim()&&0===u.length&&(0,s.jsx)(rD,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rI,{}),(0,s.jsx)(rR,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rL,{value:t.path,onSelect:()=>{e(t.path),l(!1),d("")},children:(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate text-xs",children:t.path}),t.snippet&&(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,s.jsx)(rH,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(335884);let rV=(0,o.default)("cloud-download",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]);var rW=e.i(301138);let rq=(0,o.default)("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),rK=(0,o.default)("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),rG=(0,o.default)("panel-left-close",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]),rJ=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rZ=(0,o.default)("settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var rX=e.i(109680);function rY({onOpenFile:e}){let t=r$(e=>e.query),n=r$(e=>e.setQuery),r=r$(e=>e.results),i=r$(e=>e.loading),o=r$(e=>e.search),a=r$(e=>e.clear),[l,c]=(0,f.useState)(0),d=(0,f.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,f.useEffect)(()=>{c(0)},[r]),(0,f.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${l}"]`);e?.scrollIntoView({block:"nearest"})},[l]),(0,s.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(rM,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,s.jsx)("input",{type:"text",className:"w-full rounded-sm bg-muted py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?a():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),u(l)))}})]}),""!==t.trim()&&(0,s.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,s.jsxs)("button",{type:"button","data-idx":t,onClick:()=>u(t),onMouseEnter:()=>c(t),className:`block w-full px-2 py-1 text-left ${t===l?"bg-accent":"hover:bg-accent"}`,children:[(0,s.jsx)("div",{className:"truncate text-xs",children:e.path}),e.snippet&&(0,s.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,s.jsx)(rH,{html:e.snippet})})]},e.path))]})]})}var rQ=e.i(515288);function r0(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function r1({workspaces:e,activeWorkspaceId:t,rootPath:n,isWsAdmin:r,refreshingWsId:i,switchingBranch:o,switchingBranchName:a,wsBranches:l,branchPickerWsId:c,wsBranchPos:d,onSwitchWorkspace:u,onRefreshWorkspace:p,onPromptDeleteWorkspace:h,onAddWorkspace:f,setBranchPickerWsId:m,setWsBranchPos:x,loadWsBranches:y,handleSwitchBranch:w}){return(0,s.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(m(null),x(null))},children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:n??"",children:[(0,s.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"truncate text-xs font-medium",children:e.find(e=>e.id===t)?.name??"Workspace"}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:n??""})]}),(0,s.jsx)(b,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[e.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void u(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,eh.cn)("gap-2",e.id===t&&"font-medium"),children:[e.id===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,s.jsx)("span",{className:"truncate",children:e.name}),e.git?r?(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0 hover:bg-accent",title:"Switch branch",disabled:o===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),c===e.id){m(null),x(null);return}let n=t.currentTarget.getBoundingClientRect();x({top:n.bottom+4,left:n.left}),m(e.id),y(e.id)},children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e7,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e6,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.rootDir}),e.git?.lastPulledAt&&r0(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",r0(e.git.lastPulledAt)]})]}),r&&e.git&&(0,s.jsx)("button",{className:(0,eh.cn)("shrink-0 rounded p-0.5 hover:bg-accent transition-colors",e.git.lastError?"text-destructive":"text-muted-foreground hover:text-foreground"),title:e.git.lastError?`Last refresh failed: ${e.git.lastError}`:"Refresh",disabled:i===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(e.id)},children:(0,s.jsx)(tR,{className:(0,eh.cn)("h-3.5 w-3.5",i===e.id&&"animate-spin")})}),r&&(0,s.jsx)("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Delete workspace (does not delete files)",onClick:t=>{t.stopPropagation(),h(e.id)},children:(0,s.jsx)(ts,{className:"h-3.5 w-3.5"})})]},e.id)),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:f,children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!c||!d)return null;let t=e.find(e=>e.id===c);return t?(0,s.jsx)(nl,{pos:d,branches:(l[t.id]??[]).map(e=>({name:e,current:e===t.git?.branch})),loading:!l[t.id],busyName:o===t.id?a:null,disabled:o===t.id,onPick:e=>{w(t.id,e)},onClose:()=>{m(null),x(null)}}):null})()]})}let r2="wiki-sidebar-width";function r3(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let r5=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(r2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return r3(t)}return 288}(),setWidth:t=>{let n=r3(t);localStorage.setItem(r2,String(n)),e({width:n})}}));function r4(e){return e.split("/").pop()??e}function r6({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:f,sidebarWidth:x,setSidebarWidth:y,collapsed:w,setCollapsed:k,createEntry:N,setCreateEntry:S,handleCreateFile:C,handleCreateFolder:j,dragOverPath:E,setDragOverPath:M,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:O,treeCtx:_,favorites:D,recents:R,activePaths:I,setDialogs:L,handleRefreshWorkspace:P}){let{resolvedTheme:z,setTheme:$}=(0,n6.useTheme)(),B=nP(e=>e.humanize),F=n$(e=>e.showHidden);return(0,s.jsxs)(s.Fragment,{children:[!o&&!c&&i&&(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>d(!0),"aria-hidden":!0}),!o&&!c&&(0,s.jsxs)(rQ.Card,{style:i?void 0:{width:x},className:"fixed inset-y-0 left-0 z-50 w-[85vw] max-w-[20rem] md:relative md:z-auto md:w-auto md:max-w-none flex flex-col shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0 bg-sidebar border-sidebar-border text-sidebar-foreground",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",title:"Wiki Viewer v2.11.4",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,s.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>d(!0),children:(0,s.jsx)(rG,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rJ,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(b,{className:"h-3 w-3 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:()=>void n.refreshTree(),disabled:n.refreshingTree,children:n.refreshingTree?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tR,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{tO.getState().toggle(),i&&d(!0)},children:(0,s.jsx)(a,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,s.jsx)(nn,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[e.isWsAdmin&&e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.git&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{e.activeWorkspaceId&&P(e.activeWorkspaceId)},disabled:e.refreshingWsId===e.activeWorkspaceId,children:[e.refreshingWsId===e.activeWorkspaceId?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rV,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n$.getState().toggle(),children:[F?(0,s.jsx)(rq,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rW.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nP.getState().toggle(),children:[(0,s.jsx)(rX.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>$("dark"===z?"light":"dark"),children:["dark"===z?(0,s.jsx)(n4.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===z?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rZ,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),r.uploadError&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,s.jsx)(m.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),r.uploadError]}),""===N.folder.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(e5,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N.folder.name,onChange:e=>S(t=>({...t,folder:{...t.folder,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&j(),"Escape"===e.key&&S(e=>({...e,folder:{...e.folder,parent:null,name:""}}))}}),N.folder.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.folder.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:j,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,folder:{...e.folder,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),""===N.file.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:N.file.name,onChange:e=>S(t=>({...t,file:{...t.file,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&S(e=>({...e,file:{...e.file,parent:null,name:""}}))}}),N.file.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.file.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:C,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,file:{...e.file,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"border-b",children:(0,s.jsx)(rY,{onOpenFile:t.openFromSearch})}),(0,s.jsxs)("div",{ref:O,className:(0,eh.cn)("flex-1 overflow-auto py-1 ",""===E&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>A(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||M(null)},onDrop:e=>T(e,""),children:[D.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,favorites:!e.favorites})),children:[w.favorites?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(te,{className:"h-3 w-3"}),"Favorites",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:D.length})]}),!w.favorites&&D.map(n=>(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openFavoriteEntry(n)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openFavoriteEntry(n))},children:[(0,s.jsx)(nJ,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:B?n.name:void 0,children:B?r4(n.name):n.name}),(0,s.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:n.path.split("/").slice(0,-1).join("/")}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-amber-400 group-hover:opacity-100 focus:opacity-100",title:"Remove from favorites",onClick:t=>{t.stopPropagation(),n0.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nG,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:!0,activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),R.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,recent:!e.recent})),children:[w.recent?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(rK,{className:"h-3 w-3"}),"Recent",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:R.length})]}),!w.recent&&R.slice(0,8).map(n=>(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}),i&&d(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}))},children:[(0,s.jsx)(nJ,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",title:B?n.name:void 0,children:B?r4(n.name):n.name}),(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:n.path.split("/").slice(0,-1).join("/")})]})}),(0,s.jsx)(nG,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:D.some(e=>e.path===n.path),activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),n.rootLoading?(0,s.jsx)("div",{className:"flex justify-center py-6",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===n.roots.length?(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,s.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,s.jsx)(l.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(na,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nX,{ctx:_,nodes:n.roots,openPath:t.openFile?.path??null,dragOverPath:E,branchDropdownNode:n.branchDropdownNode,branchDropdownPos:n.branchDropdownPos,nodeBranches:n.nodeBranches,branchesLoading:n.branchesLoading,checkingOutBranch:n.checkingOutBranch,pullingRepo:n.pullingRepo,activePaths:I,favorites:D,isMobile:i,activeWorkspaceId:e.activeWorkspaceId,newFileParent:N.file.parent,newFileName:N.file.name,fileCreateError:N.file.error,newFolderParent:N.folder.parent,newFolderName:N.folder.name,folderError:N.folder.error,sidebarScrollRef:O})]}),(0,s.jsx)(r1,{workspaces:e.workspaces,activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isWsAdmin:e.isWsAdmin,refreshingWsId:e.refreshingWsId,switchingBranch:e.switchingBranch,switchingBranchName:e.switchingBranchName,wsBranches:e.wsBranches,branchPickerWsId:e.branchPickerWsId,wsBranchPos:e.wsBranchPos,onSwitchWorkspace:t=>void e.switchWorkspace(t),onRefreshWorkspace:e.handleRefreshWorkspace,onPromptDeleteWorkspace:t=>e.setDeletingWorkspaceId(t),onAddWorkspace:()=>e.setAddingWorkspace(!0),setBranchPickerWsId:e.setBranchPickerWsId,setWsBranchPos:e.setWsBranchPos,loadWsBranches:e.loadWsBranches,handleSwitchBranch:e.handleSwitchBranch}),(0,s.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;f(!0);let n=document.body.style.cursor,r=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=e=>{y(x+(e.clientX-t))},s=()=>{f(!1),document.body.style.cursor=n,document.body.style.userSelect=r,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},onDoubleClick:()=>y(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),y(x-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(x+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":x,className:(0,eh.cn)("absolute right-0 top-0 z-20 h-full w-1.5 cursor-col-resize -mr-px transition-colors hover:bg-primary/40 focus:bg-primary/40 focus:outline-none hidden md:block",p&&"bg-primary/60")})]})]})}function r9({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,favorites:c,recents:d,activePaths:u,setDeleting:p,setDialogs:h}){let[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)({favorites:!1,recent:!0}),[w,k]=(0,f.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,f.useRef)(null),S=(0,f.useRef)(null),C=r5(e=>e.width),j=r5(e=>e.setWidth),E=(0,f.useCallback)(async()=>{let e=w.file.name.trim();if(!e||null===w.file.parent)return;k(e=>({...e,file:{...e.file,error:null}}));let r=e.includes(".")?e:`${e}.md`,i=w.file.parent?`${w.file.parent}/${r}`:r,s=await fetch((0,tE.withWs)("/api/wiki/new-file"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i})});if(s.ok){let e=w.file.parent;k(e=>({...e,file:{parent:null,name:"",error:null}})),await n.reloadDir(e),t.openViewer({path:i,name:r,type:"file",modifiedAt:new Date().toISOString()})}else{let e=await s.json();k(t=>({...t,file:{...t.file,error:e.error??"Failed"}}))}},[w.file.parent,w.file.name,n,t]),M=(0,f.useCallback)(async()=>{let e=w.folder.name.trim();if(!e||null===w.folder.parent)return;k(e=>({...e,folder:{...e.folder,error:null}}));let t=w.folder.parent?`${w.folder.parent}/${e}`:e,r=await fetch((0,tE.withWs)("/api/wiki/folder"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(r.ok){let e=w.folder.parent;k(e=>({...e,folder:{parent:null,name:"",error:null}})),await n.reloadDir(e)}else{let e=await r.json();k(t=>({...t,folder:{...t.folder,error:e.error??"Failed"}}))}},[w.folder.parent,w.folder.name,n]);function A(e,t,n){e.preventDefault(),e.stopPropagation();let r=S.current;if(!r){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",x("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",x("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),x(null);let s=S.current;if(S.current=null,!s){e.dataTransfer.files.length>0&&await r.doUpload(e.dataTransfer.files,i);return}if(s.path===i||i.startsWith(`${s.path}/`))return;let o=i?`${i}/${s.name}`:s.name;if(o!==s.path&&(await fetch((0,tE.withWs)("/api/wiki/move"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:s.path,to:o})})).ok){let e=s.path.includes("/")?s.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),i!==e&&await n.reloadDir(i),t.openFile?.path===s.path&&t.openViewer({path:o,name:s.name,type:s.type,modifiedAt:s.modifiedAt})}}let O=(0,f.useRef)(null);O.current={toggleFolder:e=>void n.toggleFolder(e),openViewer:e=>void t.openViewer(e),copyPath:e=>t.copyPath(e),copyWikiLink:e=>t.copyWikiLink(e),copyUrl:e=>t.copyUrl(e),copyRawContent:e=>void t.copyRawContent(e),copyFormattedContent:(e,n)=>void t.copyFormattedContent(e,n),handleDownload:function(e){let t=(0,tE.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),n=document.createElement("a");n.href=t,n.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(n),n.click(),n.remove()},triggerUpload:e=>r.triggerUpload(e),handleCreateFile:E,handleCreateFolder:M,handleDragStart:function(e,t){S.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:A,handleDropOnFolder:(e,t)=>void T(e,t),handleGitPull:(e,t)=>void n.handleGitPull(e,t),handleCheckout:(e,t,r)=>void n.handleCheckout(e,t,r),loadBranches:e=>void n.loadBranches(e),prefetch:e=>void n.prefetch(e),toggleFavorite:(e,t)=>n0.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:x,setSidebarCollapsed:l,setBranchDropdownNode:e=>n.setBranchDropdownNode(e),setBranchDropdownPos:e=>n.setBranchDropdownPos(e),setNewFileParent:e=>k(t=>({...t,file:{...t.file,parent:e,error:null}})),setNewFileName:e=>k(t=>({...t,file:{...t.file,name:e}})),setFileCreateError:e=>k(t=>({...t,file:{...t.file,error:e}})),setNewFolderParent:e=>k(t=>({...t,folder:{...t.folder,parent:e,error:null}})),setNewFolderName:e=>k(t=>({...t,folder:{...t.folder,name:e}})),setFolderError:e=>k(t=>({...t,folder:{...t.folder,error:e}})),setDeletingPath:e=>p(t=>({...t,path:e})),setDeletingIsDir:e=>p(t=>({...t,isDir:e}))};let _=(0,f.useMemo)(()=>({toggleFolder:e=>O.current.toggleFolder(e),openViewer:e=>O.current.openViewer(e),copyPath:e=>O.current.copyPath(e),copyWikiLink:e=>O.current.copyWikiLink(e),copyUrl:e=>O.current.copyUrl(e),copyRawContent:e=>O.current.copyRawContent(e),copyFormattedContent:(e,t)=>O.current.copyFormattedContent(e,t),handleDownload:e=>O.current.handleDownload(e),triggerUpload:e=>O.current.triggerUpload(e),handleCreateFile:()=>O.current.handleCreateFile(),handleCreateFolder:()=>O.current.handleCreateFolder(),handleDragStart:(e,t)=>O.current.handleDragStart(e,t),handleDragOver:(e,t,n)=>O.current.handleDragOver(e,t,n),handleDropOnFolder:(e,t)=>O.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>O.current.handleGitPull(e,t),handleCheckout:(e,t,n)=>O.current.handleCheckout(e,t,n),loadBranches:e=>O.current.loadBranches(e),prefetch:e=>O.current.prefetch(e),toggleFavorite:(e,t)=>O.current.toggleFavorite(e,t),setDragOverPath:e=>O.current.setDragOverPath(e),setSidebarCollapsed:e=>O.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>O.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>O.current.setBranchDropdownPos(e),setNewFileParent:e=>O.current.setNewFileParent(e),setNewFileName:e=>O.current.setNewFileName(e),setFileCreateError:e=>O.current.setFileCreateError(e),setNewFolderParent:e=>O.current.setNewFolderParent(e),setNewFolderName:e=>O.current.setNewFolderName(e),setFolderError:e=>O.current.setFolderError(e),setDeletingPath:e=>O.current.setDeletingPath(e),setDeletingIsDir:e=>O.current.setDeletingIsDir(e)}),[]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rU,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tO.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(r6,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:m,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:b,setDragOverPath:x,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let r7=(0,o.default)("code-xml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]),r8=(0,o.default)("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),ie=(0,o.default)("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),it=(0,o.default)("share",[["path",{d:"M12 2v13",key:"1km8f5"}],["path",{d:"m16 6-4-4-4 4",key:"13yo43"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}]]),ir=(0,o.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);var ii=e.i(75470),is=e.i(801273),io=e.i(61086);function ia(e){let t=[],n="",r=!1,i=[];for(let s=0;s<e.length;s++){let o=e[s],a=e[s+1];r?'"'===o&&'"'===a?(n+='"',s++):'"'===o?r=!1:n+=o:'"'===o?r=!0:","===o?(i.push(n),n=""):"\n"===o||"\r"===o&&"\n"===a?(i.push(n),n="",i.length>0&&t.push(i),i=[],"\r"===o&&s++):n+=o}return i.push(n),i.some(e=>""!==e)&&t.push(i),t}function il(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function ic({path:e}){let[t,n]=(0,f.useState)([]),[r,i]=(0,f.useState)(""),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(1e3),y=(0,tE.withWs)(`/api/assets/${e}`);(0,f.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=ia(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,f.useCallback)((e,t,r)=>{n(n=>{let i=n.map(e=>[...e]);for(;i.length<=e;)i.push([]);for(;i[e].length<=t;)i[e].push("");return i[e][t]=r,i}),c(!0)},[]),k=async()=>{u(!0);let s=o?r:il(t);try{await (0,tE.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(ia(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=m?S.slice(0,b):S,j=m&&b<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:`CSV${t.length>0?` (${t.length-1} rows)`:""}`,children:[l&&(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:k,disabled:d,children:[(0,s.jsx)(is.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),m&&(0,s.jsxs)("span",{className:"text-[11px] text-amber-600 dark:text-amber-400 px-1",children:["Large file (",(r.length/1048576).toFixed(1)," MB,"," ",t.length.toLocaleString()," rows)"]}),(0,s.jsxs)("button",{onClick:()=>{o?n(ia(r)):i(il(t)),a(!o)},className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-md transition-colors border border-border ${o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"}`,children:[(0,s.jsx)(r7,{className:"h-3 w-3"}),o?"Table":"Source"]}),(0,s.jsx)("button",{onClick:()=>window.open(y,"_blank"),className:"inline-flex items-center justify-center rounded-md h-8 w-8 hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer",title:"Download CSV",children:(0,s.jsx)(ne.Download,{className:"h-4 w-4"})})]}),o?(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:(0,s.jsx)("textarea",{value:r,onChange:e=>{i(e.target.value),c(!0)},className:"w-full h-full min-h-[calc(100vh-12rem)] bg-transparent font-mono text-[13px] leading-relaxed resize-none focus:outline-none",spellCheck:!1})}):(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[(0,s.jsxs)("table",{className:"w-full border-collapse text-[13px]",children:[(0,s.jsx)("thead",{className:"sticky top-0 z-10",children:(0,s.jsxs)("tr",{className:"bg-muted/80 backdrop-blur-sm",children:[(0,s.jsx)("th",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground w-8",children:"#"}),N.map((e,t)=>(0,s.jsx)("th",{className:"border border-border px-3 py-1.5 text-left font-medium text-foreground min-w-[100px]",children:p?.r===0&&p?.c===t?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:e,onChange:e=>w(0,t,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{("Enter"===e.key||"Escape"===e.key)&&h(null),"Tab"===e.key&&(e.preventDefault(),h({r:0,c:t+1<N.length?t+1:0}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r:0,c:t}),children:e||" "})},t))]})}),(0,s.jsx)("tbody",{children:C.map((e,t)=>{let r=t+1;return(0,s.jsxs)("tr",{className:"hover:bg-accent/30 transition-colors group",children:[(0,s.jsxs)("td",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground/50",children:[(0,s.jsx)("span",{className:"group-hover:hidden",children:t+1}),(0,s.jsx)("button",{className:"hidden group-hover:inline text-destructive hover:text-destructive/80 text-[10px]",onClick:()=>{n(e=>e.filter((e,t)=>t!==r)),c(!0)},title:"Delete row",children:"×"})]}),N.map((t,n)=>{let i=e[n]??"",o=p?.r===r&&p?.c===n;return(0,s.jsx)("td",{className:"border border-border px-3 py-1.5",children:o?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:i,onChange:e=>w(r,n,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{"Escape"===e.key&&h(null),"Enter"===e.key&&h({r:r+1,c:n}),"Tab"===e.key&&(e.preventDefault(),e.shiftKey?h({r,c:Math.max(0,n-1)}):h({r:n+1>=N.length?r+1:r,c:n+1>=N.length?0:n+1}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r,c:n}),children:i||" "})},n)})]},t)})})]}),j&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border",children:[(0,s.jsxs)("button",{onClick:()=>x(e=>e+1e3),className:"text-[11px] text-foreground hover:bg-accent transition-colors px-2.5 py-1 rounded border border-border",children:["Show"," ",Math.min(1e3,S.length-b).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[b.toLocaleString()," /"," ",S.length.toLocaleString()," rows"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-border",children:[(0,s.jsx)("button",{onClick:()=>{let e=t[0]?.length||1;n(t=>[...t,Array(e).fill("")]),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add row"}),(0,s.jsx)("button",{onClick:()=>{n(e=>e.map(e=>[...e,""])),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add column"})]})]})]})}function id(e){this.content=e}id.prototype={constructor:id,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return -1},get:function(e){var t=this.find(e);return -1==t?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),s=r.content.slice();return -1==i?s.push(n||e,t):(s[i+1]=t,n&&(s[i]=n)),new id(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new id(n)},addToStart:function(e,t){return new id([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new id(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,n),new id(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=id.from(e)).size?new id(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=id.from(e)).size?new id(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=id.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},id.from=function(e){if(e instanceof id)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new id(t)};class iu{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;if(l>e&&!1!==n(a,r+o,i||null,s)&&a.content.size){let i=o+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}o=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",s=!0;return this.nodesBetween(e,t,(o,a)=>{let l=o.isText?o.text.slice(Math.max(e,a)-a,t-a):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&n&&(s?s=!1:i+=n),i+=l},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new iu(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,s=0;s<t;i++){let o=this.content[i],a=s+o.nodeSize;a>e&&((s<e||a>t)&&(o=o.isText?o.cut(Math.max(0,e-s),Math.min(o.text.length,t-s)):o.cut(Math.max(0,e-s-1),Math.min(o.content.size,t-s-1))),n.push(o),r+=o.nodeSize),s=a}return new iu(n,r)}cutByIndex(e,t){return e==t?iu.empty:0==e&&t==this.content.length?this:new iu(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new iu(r,i)}addToStart(e){return new iu([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iu(this.content.concat(e),this.size+e.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 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 function e(t,n,r){for(let i=0;;i++){if(i==t.childCount||i==n.childCount)return t.childCount==n.childCount?null:r;let s=t.child(i),o=n.child(i);if(s==o){r+=s.nodeSize;continue}if(!s.sameMarkup(o))return r;if(s.isText&&s.text!=o.text){for(let e=0;s.text[e]==o.text[e];e++)r++;return r}if(s.content.size||o.content.size){let t=e(s.content,o.content,r+1);if(null!=t)return t}r+=s.nodeSize}}(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return function e(t,n,r,i){for(let s=t.childCount,o=n.childCount;;){if(0==s||0==o)return s==o?null:{a:r,b:i};let a=t.child(--s),l=n.child(--o),c=a.nodeSize;if(a==l){r-=c,i-=c;continue}if(!a.sameMarkup(l))return{a:r,b:i};if(a.isText&&a.text!=l.text){let e=0,t=Math.min(a.text.length,l.text.length);for(;e<t&&a.text[a.text.length-e-1]==l.text[l.text.length-e-1];)e++,r--,i--;return{a:r,b:i}}if(a.content.size||l.content.size){let t=e(a.content,l.content,r-1,i-1);if(t)return t}r-=c,i-=c}}(this,e,t,n)}findIndex(e){if(0==e)return ih(0,e);if(e==this.size)return ih(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e){if(r==e)return ih(t+1,r);return ih(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(e,t){if(!t)return iu.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iu.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iu.empty;let t,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new iu(t||e,n)}static from(e){if(!e)return iu.empty;if(e instanceof iu)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iu([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iu.empty=new iu([],0);let ip={index:0,offset:0};function ih(e,t){return ip.index=e,ip.offset=t,ip}function im(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(!im(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!im(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class ig{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}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&&im(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 RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw 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(e){if(!e||Array.isArray(e)&&0==e.length)return ig.none;if(e instanceof ig)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}ig.none=[];class ib extends Error{}class ix{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=function e(t,n,r,i,s,o){let{index:a,offset:l}=t.findIndex(n),c=t.maybeChild(a);if(l==n||c.isText)return o&&i<=0&&s<=0&&!o.canReplace(a,a,r)?null:t.cut(0,n).append(r).append(t.cut(n));let d=e(c.content,n-l-1,r,0==a?i-1:0,a==t.childCount-1?s-1:0,c);return d&&t.replaceChild(a,c.copy(d))}(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new ix(n,this.openStart,this.openEnd)}removeBetween(e,t){return new ix(function e(t,n,r){let{index:i,offset:s}=t.findIndex(n),o=t.maybeChild(i),{index:a,offset:l}=t.findIndex(r);if(s==n||o.isText){if(l!=r&&!t.child(a).isText)throw RangeError("Removing non-flat range");return t.cut(0,n).append(t.cut(r))}if(i!=a)throw RangeError("Removing non-flat range");return t.replaceChild(i,o.copy(e(o.content,n-s-1,r-s-1)))}(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return ix.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw RangeError("Invalid input for Slice.fromJSON");return new ix(iu.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new ix(e,n,r)}}function iy(e,t){if(!t.type.compatibleContent(e.type))throw new ib("Cannot join "+t.type.name+" onto "+e.type.name)}function iv(e,t,n){let r=e.node(n);return iy(r,t.node(n)),r}function iw(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function ik(e,t,n,r){let i=(t||e).node(n),s=0,o=t?t.index(n):i.childCount;e&&(s=e.index(n),e.depth>n?s++:e.textOffset&&(iw(e.nodeAfter,r),s++));for(let e=s;e<o;e++)iw(i.child(e),r);t&&t.depth==n&&t.textOffset&&iw(t.nodeBefore,r)}function iN(e,t){return e.type.checkContent(t),e.copy(t)}function iS(e,t,n){let r=[];return ik(null,e,n,r),e.depth>n&&iw(iN(iv(e,t,n+1),iS(e,t,n+1)),r),ik(t,null,n,r),new iu(r)}ix.empty=new ix(iu.empty,0,0);class iC{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return ig.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var s=0;s<i.length;s++)!1!==i[s].type.spec.inclusive||r&&i[s].isInSet(r.marks)||(i=i[s--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new iA(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:s}=t.content.findIndex(i),o=i-s;if(n.push(t,e,r+s),!o||(t=t.child(e)).isText)break;i=o-1,r+=s+1}return new iC(t,n,i)}static resolveCached(e,t){let n=iM.get(e);if(n)for(let e=0;e<n.elts.length;e++){let r=n.elts[e];if(r.pos==t)return r}else iM.set(e,n=new ij);let r=n.elts[n.i]=iC.resolve(e,t);return n.i=(n.i+1)%iE,r}}class ij{constructor(){this.elts=[],this.i=0}}let iE=12,iM=new WeakMap;class iA{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let iT=Object.create(null);class iO{constructor(e,t,n,r=ig.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iu.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&im(this.attrs,t||e.defaultAttrs||iT)&&ig.sameSet(this.marks,n||ig.none)}copy(e=null){return e==this.content?this:new iO(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new iO(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return ix.empty;let r=this.resolve(e),i=this.resolve(t),s=n?0:r.sharedDepth(t),o=r.start(s);return new ix(r.node(s).content.cut(r.pos-o,i.pos-o),r.depth-s,i.depth-s)}replace(e,t,n){var r=this.resolve(e),i=this.resolve(t);if(n.openStart>r.depth)throw new ib("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new ib("Inconsistent open depths");return function e(t,n,r,i){let s=t.index(i),o=t.node(i);if(s==n.index(i)&&i<t.depth-r.openStart){let a=e(t,n,r,i+1);return o.copy(o.content.replaceChild(s,a))}if(!r.content.size)return iN(o,iS(t,n,i));if(r.openStart||r.openEnd||t.depth!=i||n.depth!=i){let{start:e,end:s}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(iu.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return iN(o,function e(t,n,r,i,s){let o=t.depth>s&&iv(t,n,s+1),a=i.depth>s&&iv(r,i,s+1),l=[];return ik(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iy(o,a),iw(iN(o,e(t,n,r,i,s+1)),l)):(o&&iw(iN(o,iS(t,n,s+1)),l),ik(n,r,s,l),a&&iw(iN(a,iS(r,i,s+1)),l)),ik(i,null,s,l),new iu(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return iN(e,i.cut(0,t.parentOffset).append(r.content).append(i.cut(n.parentOffset)))}}(r,i,n,0)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(!(t=t.maybeChild(n)))return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return iC.resolveCached(this,e)}resolveNoCache(e){return iC.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),iD(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=iu.empty,r=0,i=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,r,i),o=s&&s.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),s=i&&i.matchFragment(this.content,t);return!!s&&s.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=ig.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!ig.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){let n;if(!t)throw RangeError("Invalid input for Node.fromJSON");if(t.marks){if(!Array.isArray(t.marks))throw RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=iu.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}iO.prototype.text=void 0;class i_ extends iO{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):iD(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new i_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new i_(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function iD(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class iR{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new iI(e,t);if(null==i.next)return iR.empty;let s=function e(t){let n=[];do n.push(function(t){let n=[];do n.push(function(t){let n=function(t){if(t.eat("(")){let n=e(t);return t.eat(")")||t.err("Missing closing paren"),n}if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=(function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return 0==i.length&&e.err("No node type or group '"+t+"' found"),i})(t,t.next).map(e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}}(t);for(;;)if(t.eat("+"))n={type:"plus",expr:n};else if(t.eat("*"))n={type:"star",expr:n};else if(t.eat("?"))n={type:"opt",expr:n};else if(t.eat("{"))n=function(e,t){let n=iL(e),r=n;return e.eat(",")&&(r="}"!=e.next?iL(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}(t,n);else break;return n}(t));while(t.next&&")"!=t.next&&"|"!=t.next)return 1==n.length?n[0]:{type:"seq",exprs:n}}(t));while(t.eat("|"))return 1==n.length?n[0]:{type:"choice",exprs:n}}(i);i.next&&i.err("Unexpected trailing text");let o=(n=function(e){let t=[[]];return i(function e(t,s){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,s)),[]);if("seq"==t.type)for(let r=0;;r++){let o=e(t.exprs[r],s);if(r==t.exprs.length-1)return o;i(o,s=n())}else if("star"==t.type){let o=n();return r(s,o),i(e(t.expr,o),o),[r(o)]}else if("plus"==t.type){let o=n();return i(e(t.expr,s),o),i(e(t.expr,o),o),[r(o)]}else if("opt"==t.type)return[r(s)].concat(e(t.expr,s));else if("range"==t.type){let o=s;for(let r=0;r<t.min;r++){let r=n();i(e(t.expr,o),r),o=r}if(-1==t.max)i(e(t.expr,o),o);else for(let s=t.min;s<t.max;s++){let s=n();r(o,s),i(e(t.expr,o),s),o=s}return[r(o)]}else if("name"==t.type)return[r(s,void 0,t.value)];else throw Error("Unknown expr type")}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}}(s),r=Object.create(null),function e(t){let i=[];t.forEach(e=>{n[e].forEach(({term:e,to:t})=>{let r;if(e){for(let t=0;t<i.length;t++)i[t][0]==e&&(r=i[t][1]);iz(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new iR(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(iP);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(iz(n,0)));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,s=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];s.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),-1==r.indexOf(o)&&r.push(o)}i&&t.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(o,i),o}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 i=t;r&&i<n;i++)r=r.matchType(e.child(i).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 i(s,o){let a=s.matchFragment(e,n);if(a&&(!t||a.validEnd))return iu.from(o.map(e=>e.createAndFill()));for(let e=0;e<s.next.length;e++){let{type:t,next:n}=s.next[e];if(!(t.isText||t.hasRequiredAttrs())&&-1==r.indexOf(n)){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+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(),i=r.match;if(i.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<i.next.length;e++){let{type:s,next:o}=i.next[e];s.isLeaf||s.hasRequiredAttrs()||s.name in t||r.type&&!o.validEnd||(n.push({match:s.contentMatch,type:s,via:r}),t[s.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw 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 n=0;n<t.next.length;n++)r+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return r}).join("\n")}}iR.empty=new iR(!0);class iI{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 SyntaxError(e+" (in content expression '"+this.string+"')")}}function iL(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function iP(e,t){return t-e}function iz(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:s}=i[e];r||-1!=n.indexOf(s)||t(s)}}(t),n.sort(iP)}function i$(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function iB(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function iF(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function iH(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new iV(e,r,t[r]);return n}class iU{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=iH(e,n.attrs),this.defaultAttrs=i$(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==iR.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:iB(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new iO(this,this.computeAttrs(e),iu.from(t),ig.setFrom(n))}createChecked(e=null,t,n){return t=iu.from(t),this.checkContent(t),new iO(this,this.computeAttrs(e),t,ig.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iu.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(iu.empty,!0);return i?new iO(this,e,t.append(i),ig.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){iF(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){let t;if(null==this.markSet)return e;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:ig.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new iU(e,t,r));let r=t.spec.topNode||"doc";if(!n[r])throw RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw RangeError("The text node type should not have attributes");return n}}class iV{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let r=n.split("|");return n=>{let i=null===n?"null":typeof n;if(0>r.indexOf(i))throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class iW{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=iH(e,r.attrs),this.excluded=null;let i=i$(this.attrs);this.instance=i?new ig(this,i):null}create(e=null){return!e&&this.instance?this.instance:new ig(this,iB(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new iW(e,r++,t,i)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){iF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class iq{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=id.from(e.nodes),t.marks=id.from(e.marks||{}),this.nodes=iU.compile(this.spec.nodes,this),this.marks=iW.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],r=t.spec.content||"",i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=iR.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==i?null:i?iK(this,i.split(" ")):""!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:iK(this,n.split(" "))}this.nodeFromJSON=e=>iO.fromJSON(this,e),this.markFromJSON=e=>ig.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else if(e instanceof iU){if(e.schema!=this)throw RangeError("Node type from different schema used ("+e.name+")")}else throw RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new i_(n,n.defaultAttrs,e,ig.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError("Unknown node type: "+e);return t}}function iK(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],s=e.marks[i],o=s;if(s)n.push(s);else for(let t in e.marks){let r=e.marks[t];("_"==i||r.spec.group&&r.spec.group.split(" ").indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class iG{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(null!=e.tag)this.tags.push(e);else if(null!=e.style){let t=/[^=]*/.exec(e.style)[0];0>n.indexOf(t)&&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 i0(this,t,!1);return n.addAll(e,ig.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new i0(this,t,!0);return n.addAll(e,ig.none,t.from,t.to),ix.maxOpen(n.finish())}matchTag(e,t,n){for(let s=n?this.tags.indexOf(n)+1:0;s<this.tags.length;s++){var r,i;let n=this.tags[s];if(r=e,i=n.tag,(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,i)&&(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 i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],s=r.style;if(0==s.indexOf(e)&&(!r.context||n.matchesContext(r.context))&&(!(s.length>e.length)||61==s.charCodeAt(e.length)&&s.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 t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=i1(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=i1(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new iG(e,iG.schemaRules(e)))}}let iJ={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},iZ={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},iX={ol:!0,ul:!0};function iY(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class iQ{constructor(e,t,n,r,i,s){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=s,this.content=[],this.activeMarks=ig.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iu.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e=this.content[this.content.length-1],t;e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))&&(e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length)))}let t=iu.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iu.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&&!iJ.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class i0{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,s=iY(null,t.preserveWhitespace,0)|4*!!n;i=r?new iQ(r.type,r.attrs,ig.none,!0,t.topMatch||r.type.contentMatch,s):n?new iQ(null,null,ig.none,!0,null,s):new iQ(e.schema.topNodeType,null,ig.none,!0,null,s),this.nodes=[i],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,i=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:s}=this.parser;if("full"===i||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)if("full"===i)n=n.replace(/\r\n?/g,"\n");else if(s.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(s.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(s.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(s.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],i=e.previousSibling;(!t||i&&"BR"==i.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(s.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;iX.hasOwnProperty(s)&&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&&iX.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));e:if(a?a.ignore:iZ.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,r=this.needsBlock;if(iJ.hasOwnProperty(s))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=a&&a.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?o: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 e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1===n.consuming)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,s;if(t.node)if((s=this.parser.schema.nodes[t.node]).isLeaf)this.insertNode(s.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(s,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(s&&s.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)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let s=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,s=0;t>=0;t--){let o=this.nodes[t],a=o.findWrapping(e);if(a&&(!r||r.length>a.length+s)&&(r=a,i=o,!a.length))break;if(o.solid){if(n)break;s+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],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=ig.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):i2(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&(i=this.enterInner(e,t,n,!0,r)),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=iY(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=ig.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!i2(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new iQ(e,t,a,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;else 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),i=-(n?n.depth+1:0)+ +!r,s=(e,o)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;o>=i;o--)if(s(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;o--}}return!0};return s(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 e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function i1(e){let t={};for(let n in e)t[n]=e[n];return t}function i2(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let s=[],o=e=>{s.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||0>s.indexOf(i)&&o(i))return!0}};if(o(i.contentMatch))return!0}}class i3{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=i4(t).createDocumentFragment());let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,s=0;for(;n<i.length&&s<e.marks.length;){let t=e.marks[s];if(!this.marks[t.type.name]){s++;continue}if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,s++}for(;n<i.length;)r=i.pop()[1];for(;s<e.marks.length;){let n=e.marks[s++],o=this.serializeMark(n,e.isInline,t);o&&(i.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 i4(t).createTextNode(e.text);let{dom:n,contentDOM:r}=i9(i4(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw 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 i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&i9(i4(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:i9(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new i3(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=i5(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return i5(e.marks)}}function i5(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function i4(e){return e.document||window.document}let i6=new WeakMap;function i9(e,t,n,r){let i,s,o;if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let a=t[0],l;if("string"!=typeof a)throw RangeError("Invalid array passed to renderSpec");if(r&&(void 0===(s=i6.get(r))&&i6.set(r,(o=null,!function e(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])o||(o=[]),o.push(t);else for(let n=0;n<t.length;n++)e(t[n]);else for(let n in t)e(t[n])}(r),s=o)),l=s)&&l.indexOf(t)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let c=a.indexOf(" ");c>0&&(n=a.slice(0,c),a=a.slice(c+1));let d=n?e.createElementNS(n,a):e.createElement(a),u=t[1],p=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){for(let e in p=2,u)if(null!=u[e]){let t=e.indexOf(" ");t>0?d.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):"style"==e&&d.style?d.style.cssText=u[e]:d.setAttribute(e,u[e])}}for(let s=p;s<t.length;s++){let o=t[s];if(0===o){if(s<t.length-1||s>p)throw RangeError("Content hole must be the only child of its parent node");return{dom:d,contentDOM:d}}if("string"==typeof o)d.appendChild(e.createTextNode(o));else{let{dom:t,contentDOM:s}=i9(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class i7{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}}class i8{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&i8.empty)return i8.empty}recover(e){let t=0,n=65535&e;if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+(e-(65535&e))/65536}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,i=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let a=this.ranges[o]-(this.inverted?r:0);if(a>e)break;let l=this.ranges[o+i],c=this.ranges[o+s],d=a+l;if(e<=d){let i=l?e==a?-1:e==d?1:t:t,s=a+r+(i<0?0:c);if(n)return s;let u=e==(t<0?a:d)?null:o/3+(e-a)*65536,p=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(p|=8),new i7(s,p,u)}r+=c-l}return n?e+r:new i7(e+r,0,null)}touches(e,t){let n=0,r=65535&t,i=this.inverted?2:1,s=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let a=this.ranges[t+i];if(e<=o+a&&t==3*r)return!0;n+=this.ranges[t+s]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let s=this.ranges[r],o=s-(this.inverted?i:0),a=s+(this.inverted?0:i),l=this.ranges[r+t],c=this.ranges[r+n];e(o,o+l,a,a+c),i+=c-l}}invert(){return new i8(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?i8.empty:new i8(e<0?[0,-e,0]:[0,0,e])}}i8.empty=new i8([]);class se{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new se(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],null!=r&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new se;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new i7(e,r,null)}}let st=Object.create(null);class sn{getMap(){return i8.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=st[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in st)throw RangeError("Duplicate use of step JSON ID "+e);return st[e]=t,t.prototype.jsonID=e,t}}class sr{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sr(e,null)}static fail(e){return new sr(null,e)}static fromReplace(e,t,n,r){try{return sr.ok(e.replace(t,n,r))}catch(e){if(e instanceof ib)return sr.fail(e.message);throw e}}}function si(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(si(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iu.fromArray(r)}class ss extends sn{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)),i=new ix(si(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 sr.fromReplace(e,this.from,this.to,i)}invert(){return new so(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new ss(t.pos,n.pos,this.mark)}merge(e){return e instanceof ss&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ss(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new ss(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("addMark",ss);class so extends sn{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 ix(si(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sr.fromReplace(e,this.from,this.to,n)}invert(){return new ss(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new so(t.pos,n.pos,this.mark)}merge(e){return e instanceof so&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new so(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new so(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("removeMark",so);class sa extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new sa(this.pos,t.marks[n]);return new sa(this.pos,this.mark)}}return new sl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sa(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new sa(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("addNodeMark",sa);class sl extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sa(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sl(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new sl(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("removeNodeMark",sl);class sc extends sn{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&su(e,this.from,this.to)?sr.fail("Structure replace would overwrite content"):sr.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new i8([this.from,this.to-this.from,this.slice.size])}invert(e){return new sc(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&sc.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sc(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sc)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart)if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;else{let t=this.slice.size+e.slice.size==0?ix.empty:new ix(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new sc(e.from,this.to,t,this.structure)}{let t=this.slice.size+e.slice.size==0?ix.empty:new ix(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new sc(this.from,this.to+(e.to-e.from),t,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(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new sc(t.from,t.to,ix.fromJSON(e,t.slice),!!t.structure)}}sc.MAP_BIAS=1,sn.jsonID("replace",sc);class sd extends sn{constructor(e,t,n,r,i,s,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=s,this.structure=o}apply(e){if(this.structure&&(su(e,this.from,this.gapFrom)||su(e,this.gapTo,this.to)))return sr.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sr.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sr.fromReplace(e,this.from,this.to,n):sr.fail("Content does not fit in gap")}getMap(){return new i8([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new sd(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new sd(t.pos,n.pos,r,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(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new sd(t.from,t.to,t.gapFrom,t.gapTo,ix.fromJSON(e,t.slice),t.insert,!!t.structure)}}function su(e,t,n){let r=e.resolve(t),i=n-t,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let e=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function sp(e,t,n,r=n.contentMatch,i=!0){let s=e.doc.nodeAt(t),o=[],a=t+1;for(let t=0;t<s.childCount;t++){let l=s.child(t),c=a+l.nodeSize,d=r.matchType(l.type);if(d){r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new so(a,c,l.marks[t]));if(i&&l.isText&&"pre"!=n.whitespace){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||(r=new ix(iu.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sc(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sc(a,c,ix.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iu.empty,!0);e.replace(a,a,new ix(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function sh(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let s=e.$from.node(n),o=e.$from.index(n)+r,a=e.$to.indexAfter(n)-i;if(n<e.depth&&s.canReplace(o,a,t))return n;if(0==n||s.type.spec.isolating||!((0==o||s.canReplace(o,s.childCount))&&(a==s.childCount||s.canReplace(0,a))))break;o&&(r=1),a<s.childCount&&(i=1)}return null}function sf(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.contentMatchAt(r).findWrapping(t);if(!s)return null;let o=s.length?s[0]:t;return n.canReplaceWith(r,i,o)?s:null}(e,t),s=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.child(r),o=t.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?o:null}(r,t);return s?i.map(sm).concat({type:t,attrs:n}).concat(s.map(sm)):null}function sm(e){return{type:e,attrs:null}}function sg(e,t,n,r){t.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let i=e.mapping.slice(r).map(n+1+s+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function sb(e,t,n,r){t.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+s);e.replaceWith(i,i+1,t.type.schema.text("\n"))}})}function sx(e,t,n=1,r){let i=e.resolve(t),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>s;e--,t--){let n=i.node(e),s=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(s,n.childCount),a=r&&r[t+1];a&&(o=o.replaceChild(0,a.type.create(a.attrs)));let l=r&&r[t]||n;if(!n.canReplace(s+1,n.childCount)||!l.type.validContent(o))return!1}let a=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(a,a,l?l.type:i.node(s+1).type)}function sy(e,t){let n=e.resolve(t),r=n.index();return sv(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sv(e,t){return!!(e&&t&&!e.isLeaf&&function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let s=t.child(i),o=s.type==r?e.type.schema.nodes.text:s.type;if(!(n=n.matchType(o))||!e.type.allowsMarks(s.marks))return!1}return n.validEnd}(e,t))}function sw(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,s,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,s=r.nodeAfter):n>0?(i=r.node(e+1),o++,s=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),s=r.node(e+1)),i&&!i.isTextblock&&sv(i,s)&&r.node(e).canReplace(o,o+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function sk(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,s=r.index(t)+ +(n>0),o=r.node(t),a=!1;if(1==e)a=o.canReplace(s,s,i);else{let e=o.contentMatchAt(s).findWrapping(i.firstChild.type);a=e&&o.canReplaceWith(s,s,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function sN(e,t,n=t,r=ix.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return sS(i,s,r)?new sc(t,n,r):new sC(i,s,r).fit()}function sS(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sn.jsonID("replaceAround",sd);class sC{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iu.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=iu.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,s=n.depth,o=r.depth;for(;s&&o&&1==i.childCount;)i=i.firstChild.content,s--,o--;let a=new ix(i,s,o);return e>-1?new sd(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sc(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e=null,r=(n?(e=sM(this.unplaced.content,n-1).firstChild).content:this.unplaced.content).firstChild;for(let i=this.depth;i>=0;i--){let{type:s,match:o}=this.frontier[i],a,l=null;if(1==t&&(r?o.matchType(r.type)||(l=o.fillBefore(iu.from(r),!1)):e&&s.compatibleContent(e.type)))return{sliceDepth:n,frontierDepth:i,parent:e,inject:l};if(2==t&&r&&(a=o.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:e,wrap:a};if(e&&o.matchType(e.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=sM(e,t);return!!r.childCount&&!r.firstChild.isLeaf&&(this.unplaced=new ix(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=sM(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new ix(sj(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new ix(sj(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let s=this.unplaced,o=n?n.content:s.content,a=s.openStart-e,l=0,c=[],{match:d,type:u}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)c.push(r.child(e));d=d.matchFragment(r)}let p=o.size+e-(s.content.size-s.openEnd);for(;l<o.childCount;){let e=o.child(l),t=d.matchType(e.type);if(!t)break;(++l>1||0==a||e.content.size)&&(d=t,c.push(function e(t,n,r){if(n<=0)return t;let i=t.content;return n>1&&(i=i.replaceChild(0,e(i.firstChild,n-1,1==i.childCount?r-1:0))),n>0&&(i=t.type.contentMatch.fillBefore(i).append(i),r<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(iu.empty,!0)))),t.copy(i)}(e.mark(u.allowedMarks(e.marks)),1==l?a:0,l==o.childCount?p:-1)))}let h=l==o.childCount;h||(p=-1),this.placed=sE(this.placed,t,iu.from(c)),this.frontier[t].match=d,h&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=h?0==e?ix.empty:new ix(sj(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new ix(sj(s.content,e,l),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!sA(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return -1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){t:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),s=sA(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=sA(e,n,r,t,!0);if(!i||i.childCount)continue t}return{depth:t,fit:s,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=sE(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=sE(this.placed,this.depth,iu.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iu.empty,!0);e.childCount&&(this.placed=sE(this.placed,this.frontier.length,e))}}function sj(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(sj(e.firstChild.content,t-1,n)))}function sE(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(sE(e.lastChild.content,t-1,n)))}function sM(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function sA(e,t,n,r,i){let s=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,s.content,o)?a:null}function sT(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}class sO extends sn{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 sr.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(r),0,+!t.isLeaf))}getMap(){return i8.empty}invert(e){return new sO(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sO(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new sO(t.pos,t.attr,t.value)}}sn.jsonID("attr",sO);class s_ extends sn{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return sr.ok(n)}getMap(){return i8.empty}invert(e){return new s_(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new s_(t.attr,t.value)}}sn.jsonID("docAttr",s_);let sD=class extends Error{};(sD=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),sD.prototype.constructor=sD,sD.prototype.name="TransformError";class sR{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new se}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new sD(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,s)=>{e=Math.min(e,i),t=Math.max(t,s)})}return 1e9==e?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=ix.empty){let r=sN(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new ix(iu.from(n),0,0))}delete(e,t){return this.replace(e,t,ix.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return!function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),s=e.doc.resolve(n);if(sS(i,s,r))return e.step(new sc(t,n,r));let o=sT(i,s);0==o[o.length-1]&&o.pop();let a=-(i.depth+1);o.unshift(a);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?a=e:i.before(e)==t&&o.splice(1,0,-e)}let l=o.indexOf(a),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){var u;let t=c[e],n=(u=t.type).spec.defining||u.spec.definingForContent;if(n&&!t.sameMarkup(i.node(Math.abs(a)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let a=(t+d+1)%(r.openStart+1),u=c[a];if(u)for(let t=0;t<o.length;t++){let c=o[(t+l)%o.length],d=!0;c<0&&(d=!1,c=-c);let p=i.node(c-1),h=i.index(c-1);if(p.canReplaceWith(h,h,u.type,u.marks))return e.replace(i.before(c),d?s.after(c):n,new ix(function e(t,n,r,i,s){if(n<r){let s=t.firstChild;t=t.replaceChild(0,s.copy(e(s.content,n+1,r,i,s)))}if(n>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(iu.empty,!0))}return t}(r.content,0,r.openStart,a),a,r.openEnd))}}let p=e.steps.length;for(let a=o.length-1;a>=0&&(e.replace(t,n,r),!(e.steps.length>p));a--){let e=o[a];e<0||(t=i.before(e),n=s.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){var r=e,i=t;if(!n.isInline&&r==i&&this.doc.resolve(r).parent.content.size){let e=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)break}return null}(this.doc,r,n.type);null!=e&&(r=i=e)}return this.replaceRange(r,i,new ix(iu.from(n),0,0)),this}deleteRange(e,t){return!function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&0==r.parentOffset&&0==i.parentOffset){let s=r.sharedDepth(n),o=!1;for(let e=r.depth;e>s;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>s;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let s=sT(r,i);for(let t=0;t<s.length;t++){let n=s[t],o=t==s.length-1;if(o&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(t-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return e.delete(r.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return!function(e,t,n){let{$from:r,$to:i,depth:s}=t,o=r.before(s+1),a=i.after(s+1),l=o,c=a,d=iu.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iu.from(r.node(e).copy(d)),u++):l--;let p=iu.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iu.from(i.node(e).copy(p)),h++):c++;e.step(new sd(l,c,o,a,new ix(d.append(p),u,h),d.size-u,!0))}(this,e,t),this}join(e,t=1){return!function(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,s=e.doc.resolve(t-n),o=s.node().type;if(i&&o.inlineContent){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let a=e.steps.length;if(!1===r){let r=e.doc.resolve(t+n);sb(e,r.node(),r.before(),a)}o.inlineContent&&sp(e,t+n-1,o,s.node().contentMatchAt(s.index()),null==r);let l=e.mapping.slice(a),c=l.map(t-n);if(e.step(new sc(c,l.map(t+n,-1),ix.empty,!0)),!0===r){let t=e.doc.resolve(c);sg(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iu.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=iu.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sd(i,s,i,s,new ix(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){var i=this;if(!n.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;return i.doc.nodesBetween(e,t,(e,t)=>{var o,a,l;let c,d,u="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(n,u)&&(o=i.doc,a=i.mapping.slice(s).map(t),l=n,d=(c=o.resolve(a)).index(),c.parent.canReplaceWith(d,d+1,l))){let r=null;if(n.schema.linebreakReplacement){let e="pre"==n.whitespace,t=!!n.contentMatch.matchType(n.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&sb(i,e,t,s),sp(i,i.mapping.slice(s).map(t,1),n,void 0,null===r);let o=i.mapping.slice(s),a=o.map(t,1),l=o.map(t+e.nodeSize,1);return i.step(new sd(a,l,a+1,l-1,new ix(iu.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sg(i,e,t,s),!1}}),this}setNodeMarkup(e,t,n=null,r){return!function(e,t,n,r,i){let s=e.doc.nodeAt(t);if(!s)throw RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,o);if(!n.validContent(s.content))throw RangeError("Invalid content for node type "+n.name);e.step(new sd(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new ix(iu.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new sO(e,t,n)),this}setDocAttribute(e,t){return this.step(new s_(e,t)),this}addNodeMark(e,t){return this.step(new sa(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof ig)t.isInSet(n.marks)&&this.step(new sl(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sl(e,i)),r=i.removeFromSet(r);for(let e=s.length-1;e>=0;e--)this.step(s[e])}return this}split(e,t=1,n){return!function(e,t,n=1,r){let i=e.doc.resolve(t),s=iu.empty,o=iu.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iu.from(i.node(e).copy(s));let t=r&&r[a];o=iu.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sc(t,t,new ix(s.append(o),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){var r;let i,s,o,a;return r=this,o=[],a=[],r.doc.nodesBetween(e,t,(r,l,c)=>{if(!r.isInline)return;let d=r.marks;if(!n.isInSet(d)&&c.type.allowsMarkType(n.type)){let c=Math.max(l,e),u=Math.min(l+r.nodeSize,t),p=n.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(i&&i.to==c&&i.mark.eq(d[e])?i.to=u:o.push(i=new so(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new ss(c,u,n))}}),o.forEach(e=>r.step(e)),a.forEach(e=>r.step(e)),this}removeMark(e,t,n){var r;let i,s;return r=this,i=[],s=0,r.doc.nodesBetween(e,t,(r,o)=>{if(!r.isInline)return;s++;let a=null;if(n instanceof iW){let e=r.marks,t;for(;t=n.isInSet(e);)(a||(a=[])).push(t),e=t.removeFromSet(e)}else n?n.isInSet(r.marks)&&(a=[n]):a=r.marks;if(a&&a.length){let n=Math.min(o+r.nodeSize,t);for(let t=0;t<a.length;t++){let r=a[t],l;for(let e=0;e<i.length;e++){let t=i[e];t.step==s-1&&r.eq(i[e].style)&&(l=t)}l?(l.to=n,l.step=s):i.push({style:r,from:Math.max(o,e),to:n,step:s})}}}),i.forEach(e=>r.step(new so(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sp(this,e,t,n),this}}let sI=Object.create(null);class sL{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new sP(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=ix.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:a,$to:l}=s[o],c=e.mapping.slice(i);e.replaceRange(c.map(a.pos),c.map(l.pos),o?ix.empty:t),0==o&&sK(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n),l=a.map(s.pos),c=a.map(o.pos);i?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),sK(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new sB(e):sq(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?sq(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):sq(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new sV(e.node(0))}static atStart(e){return sq(e,e,0,0,1)||new sV(e)}static atEnd(e){return sq(e,e,e.content.size,e.childCount,-1)||new sV(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=sI[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sI)throw RangeError("Duplicate use of selection JSON ID "+e);return sI[e]=t,t.prototype.jsonID=e,t}getBookmark(){return sB.between(this.$anchor,this.$head).getBookmark()}}sL.prototype.visible=!0;class sP{constructor(e,t){this.$from=e,this.$to=t}}let sz=!1;function s$(e){sz||e.parent.inlineContent||(sz=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class sB extends sL{constructor(e,t=e){s$(e),s$(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return sL.near(n);let r=e.resolve(t.map(this.anchor));return new sB(r.parent.inlineContent?r:n,n)}replace(e,t=ix.empty){if(super.replace(e,t),t==ix.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof sB&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new sF(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw RangeError("Invalid input for TextSelection.fromJSON");return new sB(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let e=sL.findFrom(t,n,!0)||sL.findFrom(t,-n,!0);if(!e)return sL.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(sL.findFrom(e,-n,!0)||sL.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new sB(e,t)}}sL.jsonID("text",sB);class sF{constructor(e,t){this.anchor=e,this.head=t}map(e){return new sF(e.map(this.anchor),e.map(this.head))}resolve(e){return sB.between(e.resolve(this.anchor),e.resolve(this.head))}}class sH extends sL{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?sL.near(i):new sH(i)}content(){return new ix(iu.from(this.node),0,0)}eq(e){return e instanceof sH&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new sU(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new sH(e.resolve(t.anchor))}static create(e,t){return new sH(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}sH.prototype.visible=!1,sL.jsonID("node",sH);class sU{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new sF(n,n):new sU(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&sH.isSelectable(n)?new sH(t):sL.near(t)}}class sV extends sL{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=ix.empty){if(t==ix.empty){e.delete(0,e.doc.content.size);let t=sL.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new sV(e)}map(e){return new sV(e)}eq(e){return e instanceof sV}getBookmark(){return sW}}sL.jsonID("all",sV);let sW={map(){return this},resolve:e=>new sV(e)};function sq(e,t,n,r,i,s=!1){if(t.inlineContent)return sB.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(r.isAtom){if(!s&&sH.isSelectable(r))return sH.create(e,n-(i<0?r.nodeSize:0))}else{let t=sq(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function sK(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sc||s instanceof sd)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(sL.near(e.doc.resolve(r),n)))}class sG extends sR{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(1|this.updated)&-3,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return ig.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||ig.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(sL.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function sJ(e,t){return t&&e?e.bind(t):e}class sZ{constructor(e,t,n){this.name=e,this.init=sJ(t.init,n),this.apply=sJ(t.apply,n)}}let sX=[new sZ("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new sZ("selection",{init:(e,t)=>e.selection||sL.atStart(t.doc),apply:e=>e.selection}),new sZ("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new sZ("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class sY{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=sX.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new sZ(e.key,e.spec.state,e))})}}class sQ{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let s=0;s<this.config.plugins.length;s++){let o=this.config.plugins[s];if(o.spec.appendTransaction){let a=r?r[s].n:0,l=r?r[s].state:this,c=a<t.length&&o.spec.appendTransaction.call(o,a?t.slice(a):t,l,n);if(c&&n.filterTransaction(c,s)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<s?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),i=!0}r&&(r[s]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw RangeError("Applying a mismatched transaction");let t=new sQ(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new sG(this)}static create(e){let t=new sY(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new sQ(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new sY(this.schema,e.plugins),n=t.fields,r=new sQ(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw RangeError("Required config field 'schema' missing");let r=new sY(e.schema,e.plugins),i=new sQ(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=iO.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=sL.fromJSON(i.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let s in n){let o=n[s],a=o.spec.state;if(o.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,s)){i[r.name]=a.fromJSON.call(o,e,t[s],i);return}}i[r.name]=r.init(e,i)}}),i}}class s0{constructor(e){this.spec=e,this.props={},e.props&&function e(t,n,r){for(let i in t){let s=t[i];s instanceof Function?s=s.bind(n):"handleDOMEvents"==i&&(s=e(s,n,{})),r[i]=s}return r}(e.props,this,this.props),this.key=e.key?e.key.key:s2("plugin")}getState(e){return e[this.key]}}let s1=Object.create(null);function s2(e){return e in s1?e+"$"+ ++s1[e]:(s1[e]=0,e+"$")}class s3{constructor(e="key"){this.key=s2(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let s5=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},s4=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},s6=null,s9=function(e,t,n){let r=s6||(s6=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},s7=function(){s6=null},s8=function(e,t,n,r){return n&&(ot(e,t,n,r,-1)||ot(e,t,n,r,1))},oe=/^(img|br|input|textarea|hr)$/i;function ot(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:on(e))){let n=e.parentNode;if(!n||1!=n.nodeType||or(e)||oe.test(e.nodeName)||"false"==e.contentEditable)return!1;t=s5(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;let n=e.childNodes[t+(i<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable)if(null==(s=n.pmViewDesc)||!s.ignoreForSelection)return!1;else t+=i;else e=n,t=i<0?on(e):0}}}function on(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function or(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)}let oi=function(e){return e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oo(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oa="u">typeof navigator?navigator:null,ol="u">typeof document?document:null,oc=oa&&oa.userAgent||"",od=/Edge\/(\d+)/.exec(oc),ou=/MSIE \d/.exec(oc),op=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oc),oh=!!(ou||op||od),of=ou?document.documentMode:op?+op[1]:od?+od[1]:0,om=!oh&&/gecko\/(\d+)/i.test(oc);om&&(/Firefox\/(\d+)/.exec(oc)||[0,0])[1];let og=!oh&&/Chrome\/(\d+)/.exec(oc),ob=!!og,ox=og?+og[1]:0,oy=!oh&&!!oa&&/Apple Computer/.test(oa.vendor),ov=oy&&(/Mobile\/\w+/.test(oc)||!!oa&&oa.maxTouchPoints>2),ow=ov||!!oa&&/Mac/.test(oa.platform),ok=!!oa&&/Win/.test(oa.platform),oN=/Android \d/.test(oc),oS=!!ol&&"webkitFontSmoothing"in ol.documentElement.style,oC=oS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function oj(e,t){return"number"==typeof e?e:e[t]}function oE(e,t,n){let r=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,s=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(1!=o.nodeType){o=s4(o);continue}let e=o,n=e==s.body,a=n?function(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}(s):function(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}(e),l=0,c=0;if(t.top<a.top+oj(r,"top")?c=-(a.top-t.top+oj(i,"top")):t.bottom>a.bottom-oj(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+oj(i,"top")-a.top:t.bottom-a.bottom+oj(i,"bottom")),t.left<a.left+oj(r,"left")?l=-(a.left-t.left+oj(i,"left")):t.right>a.right-oj(r,"right")&&(l=t.right-a.right+oj(i,"right")),l||c)if(n)s.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,s=e.scrollTop-r;t={left:t.left-i,top:t.top-s,right:t.right-i,bottom:t.bottom-s}}let d=n?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o="absolute"==d?o.offsetParent:s4(o)}}function oM(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=s4(r));return t}function oA(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:s}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=s&&(r.scrollLeft=s)}}let oT=null;function oO(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function o_(e){return e.top<e.bottom||e.left<e.right}function oD(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(o_(e))return e}return Array.prototype.find.call(n,o_)||e.getBoundingClientRect()}let oR=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function oI(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=oS||om;if(3==r.nodeType)if(o&&(oR.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=oD(s9(r,i,i),n);if(om&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=oD(s9(r,i-1,i-1),-1);if(t.top==e.top){let n=oD(s9(r,i,i+1),-1);if(n.top!=e.top)return oL(n,n.left<t.left)}}return e}else{let e=i,t=i,s=n<0?1:-1;return n<0&&!i?(t++,s=-1):n>=0&&i==r.nodeValue.length?(e--,s=1):n<0?e--:t++,oL(oD(s9(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!0)}return oP(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1],t=3==e.nodeType?s9(e,on(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return oL(oD(t,1),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?s9(e,0,+!o):1==e.nodeType?e:null:null;if(t)return oL(oD(t,-1),!0)}return oL(oD(3==r.nodeType?s9(r):r,-n),n>=0)}function oL(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function oP(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function oz(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}let o$=/[\u0590-\u08ac]/,oB=null,oF=null,oH=!1;class oU{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){let r;if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}if(e==this.dom&&this.contentDOM)r=t>s5(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),s;if(i&&(!t||i.node))if(!n||!(s=i.nodeDOM)||(1==s.nodeType?s.contains(1==e.nodeType?e:e.parentNode):s==e))return i;else n=!1}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return -1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],s=t+i.size;if(s>e||i instanceof oZ){r=e-t;break}t=s}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof oV&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;(e=n?this.children[n-1]:null)&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?s5(e.dom)+1:0}}{let e,r=!0;for(;(e=n<this.children.length?this.children[n]:null)&&e.dom.parentNode!=this.contentDOM;n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?s5(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let s=n,o=0;;o++){let n=this.children[o],a=s+n.size;if(-1==r&&e<=a){let i=s+n.border;if(e>=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=s;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=s5(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||o==this.children.length-1)){t=a;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=s5(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}s=a}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),s=Math.max(e,t);for(let o=0,a=0;o<this.children.length;o++){let l=this.children[o],c=a+l.size;if(i>a&&s<c)return l.setSelection(e-a-l.border,t-a-l.border,n,r);a=c}let o=this.domFromPos(e,e?-1:1),a=t==e?o:this.domFromPos(t,t?-1:1),l=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((om||oy)&&e==t){let{node:e,offset:t}=o;if(3==e.nodeType){if((d=!!(t&&"\n"==e.nodeValue[t-1]))&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){"BR"==n.nodeName&&(o=a={node:n.parentNode,offset:s5(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(om&&c.focusNode&&c.focusNode!=a.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(r=!0)}if(!(r||d&&oy)&&s8(o.node,o.offset,c.anchorNode,c.anchorOffset)&&s8(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&om)){l.collapse(o.node,o.offset);try{e!=t&&l.extend(a.node,a.offset),u=!0}catch(e){}}if(!u){if(e>t){let e=o;o=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(o.node,o.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],s=n+i.size;if(n==s?e<=s&&t>=n:e<s&&t>n){let r=n+i.border,o=s-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==s?2:1,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=3:i.markDirty(e-r,t-r);return}i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=s}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class oV extends oU{constructor(e,t,n,r){let i,s=t.type.toDOM;if("function"==typeof s&&(s=s(n,()=>i?i.parent?i.parent.posBeforeChild(i):void 0:r)),!t.type.spec.raw){if(1!=s.nodeType){let e=document.createElement("span");e.appendChild(s),s=e}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class oW extends oU{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class oq extends oU{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(e,t,n,r){let i=r.nodeViews[t.type.name],s=i&&i(t,r,n);return s&&s.dom||(s=i3.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new oq(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let r=oq.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=o9(i,t,s,n)),e>0&&(i=o9(i,0,e,n));for(let e=0;e<i.length;e++)i[e].parent=r;return r.children=i,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class oK extends oU{constructor(e,t,n,r,i,s,o,a,l){super(e,[],i,s),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(e,t,n,r,i,s){let o=i.nodeViews[t.type.name],a,l=o&&o(t,i,()=>a?a.parent?a.parent.posBeforeChild(a):void 0:s,n,r),c=l&&l.dom,d=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=i3.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return(c=o2(c,n,t),l)?a=new oX(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new oJ(e,t,n,r,c,u,i):new oK(e,t,n,r,c,d||null,u,i,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>iu.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&o3(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,s=i&&i.pos>-1?i:null,o=i&&i.pos<0,a=new o4(this,s&&s.node,e);(function(e,t,n,r){let i=t.locals(e),s=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(s,o),n),s+=o.nodeSize}return}let o=0,a=[],l=null;for(let c=0;;){let d,u,p,h;for(;o<i.length&&i[o].to==s;){let e=i[o++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(o6);for(let e=0;e<u.length;e++)n(u[e],c,!!l)}else n(d,c,!!l);if(l)h=-1,p=l,l=null;else if(c<e.childCount)h=c,p=e.child(c++);else break;for(let e=0;e<a.length;e++)a[e].to<=s&&a.splice(e--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)a.push(i[o++]);let f=s+p.nodeSize;if(p.isText){let e=f;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<a.length;t++)a[t].to<e&&(e=a[t].to);e<f&&(l=p.cut(e-s),p=p.cut(0,e-s),f=e,h=-1)}else for(;o<i.length&&i[o].to<f;)o++;let m=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,m,t.forChild(s,p),h),s=f}})(this.node,this.innerDeco,(t,i,s)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!s&&a.syncToMarks(i==this.node.childCount?ig.none:this.node.child(i).marks,n,e,i),a.placeWidget(t,e,r)},(t,s,l,c)=>{let d;a.syncToMarks(t.marks,n,e,c),a.findNodeMatch(t,s,l,c)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=a.findIndexWithChild(i.node))>-1&&a.updateNodeAt(t,s,l,d,e)||a.updateNextNode(t,s,l,e,c,r)||a.addNode(t,s,l,e,r),r+=t.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(s&&this.protectLocalComposition(e,s),function e(t,n,r){let i=t.firstChild,s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=a.dom;if(l.parentNode==t){for(;l!=i;)i=o5(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof oq){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=o5(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),ov&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof sB)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(!this.node.inlineContent)return{node:i,pos:-1,text:""};{let e=i.nodeValue,s=function(e,t,n,r){for(let i=0,s=0;i<e.childCount&&s<=r;){let o=e.child(i++),a=s;if(s+=o.nodeSize,!o.isText)continue;let l=o.text;for(;i<e.childCount;){let t=e.child(i++);if(s+=t.nodeSize,!t.isText)break;l+=t.text}if(s>=n){if(s>=r&&l.slice(r-t.length-a,r-a)==t)return r-t.length;let e=a<r?l.lastIndexOf(t,r-a-1):-1;if(e>=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return -1}(this.node.content,e,n-t,r-t);return s<0?null:{node:i,pos:s,text:e}}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let s=new oW(this,i,t,r);e.input.compositionNodes.push(s),this.children=o9(this.children,n,n+r.length,e,s)}update(e,t,n,r){return 3!=this.dirty&&!!e.sameMarkup(this.node)&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(o3(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=o1(this.dom,this.nodeDOM,o0(this.outerDeco,this.node,t),o0(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function oG(e,t,n,r,i){o2(r,t,e);let s=new oK(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class oJ extends oK{constructor(e,t,n,r,i,s,o){super(e,t,n,r,i,null,s,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return 3!=this.dirty&&(0==this.dirty||!!this.inParent())&&!!e.sameMarkup(this.node)&&(this.updateOuterDeco(t),(0!=this.dirty||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new oJ(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(0==e||t==this.nodeDOM.nodeValue.length)&&(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class oZ extends oU{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class oX extends oK{constructor(e,t,n,r,i,s,o,a,l,c){super(e,t,n,r,i,s,o,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return(!!this.contentDOM||!!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}let oY=function(e){e&&(this.nodeName=e)};oY.prototype=Object.create(null);let oQ=[new oY];function o0(e,t,n){if(0==e.length)return oQ;let r=n?oQ[0]:new oY,i=[r];for(let s=0;s<e.length;s++){let o=e[s].type.attrs;if(o)for(let e in o.nodeName&&i.push(r=new oY(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new oY(t.isInline?"span":"div")),"class"==e?r.class=(r.class?r.class+" ":"")+s:"style"==e?r.style=(r.style?r.style+";":"")+s:"nodeName"!=e&&(r[e]=s))}}return i}function o1(e,t,n,r){if(n==oQ&&r==oQ)return t;let i=t;for(let t=0;t<r.length;t++){let s=r[t],o=n[t];if(t){let t;o&&o.nodeName==s.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==s.nodeName||((t=document.createElement(s.nodeName)).pmIsDeco=!0,t.appendChild(i),o=oQ[0]),i=t}!function(e,t,n){for(let r in t)"class"==r||"style"==r||"nodeName"==r||r in n||e.removeAttribute(r);for(let r in n)"class"!=r&&"style"!=r&&"nodeName"!=r&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<r.length;t++)-1==i.indexOf(r[t])&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)-1==r.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}(i,o||oQ[0],s)}return i}function o2(e,t,n){return o1(e,e,oQ,o0(t,n,1!=e.nodeType))}function o3(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function o5(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class o4{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,r=n.children.length,i=e.childCount,s=new Map,o=[];n:for(;i>0;){let a;for(;;)if(r){let e=n.children[r-1];if(e instanceof oq)n=e,r=e.children.length;else{a=e,r--;break}}else if(n==t)break n;else r=n.parent.children.indexOf(n),n=n.parent;let l=a.node;if(l){if(l!=e.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&!1!==e[i].type.spec.spanning;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[s])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=oq.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,r){let i=-1,s;if(r>=this.preMatch.index&&(s=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,n))i=this.top.children.indexOf(s,this.index);else for(let r=this.index,s=Math.min(this.top.children.length,r+5);r<s;r++){let s=this.top.children[r];if(s.matchesNode(e,t,n)&&!this.preMatch.matched.has(s)){i=r;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let s=this.top.children[r];return 3==s.dirty&&s.dom==s.contentDOM&&(s.dirty=2),!!s.update(e,t,n,i)&&(this.destroyBetween(this.index,r),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return -1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return -1}e=t}}updateNextNode(e,t,n,r,i,s){for(let o=this.index;o<this.top.children.length;o++){let a=this.top.children[o];if(a instanceof oK){let l=this.preMatch.matched.get(a);if(null!=l&&l!=i)return!1;let c=a.dom,d,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&3!=a.dirty&&o3(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,o),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(d=this.recreateWrapper(a,e,t,n,r,s)))return this.destroyBetween(this.index,o),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=2,d.updateChildren(r,s+1),d.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!o3(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=oK.create(this.top,t,n,r,i,s);if(o.contentDOM)for(let t of(o.children=e.children,e.children=[],o.children))t.parent=o;return e.destroy(),o}addNode(e,t,n,r,i){let s=oK.create(this.top,e,t,n,r,i);s.contentDOM&&s.updateChildren(r,i+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new oV(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof oq;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof oJ)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oy||ob)&&e&&"false"==e.dom.contentEditable&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let r=new oZ(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function o6(e,t){return e.type.side-t.type.side}function o9(e,t,n,r,i){let s=[];for(let o=0,a=0;o<e.length;o++){let l=e[o],c=a,d=a+=l.size;c>=n||d<=t?s.push(l):(c<t&&s.push(l.slice(0,t-c,r)),i&&(s.push(i),i=void 0),d>n&&s.push(l.slice(n-c,l.size,r)))}return s}function o7(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),s=i&&0==i.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),l,c;if(oi(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&sH.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==on(e);r||i;){if(e==n)return!0;let t=s5(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==on(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new sH(o==e?a:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let s=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(s.startContainer,s.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(s.endContainer,s.endOffset,-1))}if(t<0)return null;[l,o]=i==e.state.selection.anchor?[i,t]:[t,i],a=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!c){let n="pointer"==t||e.state.selection.head<a.pos&&!s?1:-1;c=aa(e,d,a,n)}return c}function o8(e){return e.editable?e.hasFocus():ac(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ae(e,t=!1){let n=e.state.selection;if(as(e,n),o8(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&ob){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&s8(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}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,s5(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oh&&of<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;at&&!(n instanceof sB)&&(n.$from.parent.inlineContent||(d=an(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=an(e,n.to))),e.docView.setSelection(l,c,e,t),at&&(d&&ai(d),u&&ai(u)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&((i=(r=e).dom.ownerDocument).removeEventListener("selectionchange",r.input.hideSelectionGuard),o=(s=r.domSelectionRange()).anchorNode,a=s.anchorOffset,i.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(s.anchorNode!=o||s.anchorOffset!=a)&&(i.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!o8(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let at=oy||ob&&ox<63;function an(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,s=r?n.childNodes[r-1]:null;if(oy&&i&&"false"==i.contentEditable)return ar(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return ar(i);else if(s)return ar(s)}}function ar(e){return e.contentEditable="true",oy&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ai(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function as(e,t){if(t instanceof sH){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ao(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ao(e)}function ao(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aa(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||sB.between(t,n,r)}function al(e){return(!e.editable||!!e.hasFocus())&&ac(e)}function ac(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(e){return!1}}function ad(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return s&&sL.findFrom(s,t)}function au(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ap(e,t,n){let r=e.state.selection;if(r instanceof sB){if(n.indexOf("s")>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let s=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return au(e,new sB(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=ad(e.state,t);return!!n&&n instanceof sH&&au(e,n)}else if(!(ow&&n.indexOf("m")>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,s;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return!!(i.isAtom||(s=e.docView.descAt(o))&&!s.contentDOM)&&(sH.isSelectable(i)?au(e,new sH(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!oS&&au(e,new sB(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof sH&&r.node.isInline)return au(e,new sB(t>0?r.$to:r.$from));let n=ad(e.state,t);return!!n&&au(e,n)}}function ah(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function af(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function am(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,s,o=!1;for(om&&1==n.nodeType&&r<ah(n)&&af(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(af(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(ag(n))break;else{let t=n.previousSibling;for(;t&&af(t,-1);)i=n.parentNode,s=s5(t),t=t.previousSibling;if(t)r=ah(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?ab(e,n,r):i&&ab(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=ah(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(af(i.childNodes[s],1))t=i,n=++s;else break}else if(ag(i))break;else{let r=i.nextSibling;for(;r&&af(r,1);)t=r.parentNode,n=s5(r)+1,r=r.nextSibling;if(r)s=0,o=ah(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&ab(e,t,n)}(e)}function ag(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function ab(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!or(e);)t=s5(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&&!or(e);)t=s5(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(oi(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:i}=e;setTimeout(()=>{e.state==i&&ae(e)},50)}function ax(e,t){let n=e.state.doc.resolve(t);if(!(ob||ok)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<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),i=(n.top+n.bottom)/2;if(i>r.top&&i<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 ay(e,t,n){let r=e.state.selection;if(r instanceof sB&&!r.empty||n.indexOf("s")>-1||ow&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=ad(e.state,t);if(n&&n instanceof sH)return au(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof sV?sL.near(n,t):sL.findFrom(n,t);return!!o&&au(e,o)}return!1}function av(e,t){if(!(e.state.selection instanceof sB))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let s=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let r=e.state.tr;return t<0?r.delete(n.pos-s.nodeSize,n.pos):r.delete(n.pos,n.pos+s.nodeSize),e.dispatch(r),!0}return!1}function aw(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function ak(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:s}=t;for(;i>1&&s>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,s--;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")||i3.fromSchema(e.state.schema),a=aT(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=aM[c.nodeName.toLowerCase()]);){for(let e=d.length-1;e>=0;e--){let t=a.createElement(d[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),u++}c=l.firstChild}return c&&1==c.nodeType&&c.setAttribute("data-pm-slice",`${i} ${s}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:l,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function aN(e,t,n,r,i){let s,o,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp("transformPastedText",n=>{t=n(t,a||r,e)}),a)return o=new ix(iu.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,i,r,e));if(n)o=n;else{let n=i.marks(),{schema:r}=e.state,o=i3.fromSchema(r);s=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),s=function(e){var t;let n,r=/^(\s*<meta [^>]*>)*/.exec(e);r&&(e=e.slice(r[0].length));let i=aT().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&aM[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(aO||(aO=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),aO.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),oS&&function(e){let t=e.querySelectorAll(ob?"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)}}(s);let c=s&&s.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;s=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||iG.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||aS.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch(t){return e}let{content:i,openStart:s,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=iu.from(t.create(r[e+1],i)),s++,o++}return new ix(i,s,o)}(aE(o,+d[1],+d[2]),d[4]);else if((o=ix.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,s=[];if(e.forEach(e=>{if(!s)return;let t=r.findWrapping(e.type),n;if(!t)return s=null;if(n=s.length&&i.length&&function e(t,n,r,i,s){if(s<t.length&&s<n.length&&t[s]==n[s]){let o=e(t,n,r,i.lastChild,s+1);if(o)return i.copy(i.content.replaceChild(i.childCount-1,o));if(i.contentMatchAt(i.childCount).matchType(s==t.length-1?r.type:t[s+1]))return i.copy(i.content.append(iu.from(aC(r,t,s+1))))}}(t,i,e,s[s.length-1],0))s[s.length-1]=n;else{s.length&&(s[s.length-1]=function e(t,n){if(0==n)return t;let r=t.content.replaceChild(t.childCount-1,e(t.lastChild,n-1)),i=t.contentMatchAt(t.childCount).fillBefore(iu.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=aC(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iu.from(s)}return e}(o.content,i),!0)).openStart||o.openEnd){let e=0,t=0;for(let t=o.content.firstChild;e<o.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=o.content.lastChild;t<o.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);o=aE(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let aS=/^(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 aC(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iu.from(e));return e}function aj(e,t,n,r,i,s){let o=t<0?e.firstChild:e.lastChild,a=o.content;return e.childCount>1&&(s=0),i<r-1&&(a=aj(a,t,n,r,i+1,s)),i>=n&&(a=t<0?o.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(iu.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function aE(e,t,n){return t<e.openStart&&(e=new ix(aj(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new ix(aj(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let aM={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},aA=null;function aT(){return aA||(aA=document.implementation.createHTMLDocument("title"))}let aO=null,a_={},aD={},aR={touchstart:!0,touchmove:!0};class aI{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function aL(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function aP(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>az(e,t))})}function az(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function a$(e){return{left:e.clientX,top:e.clientY}}function aB(e,t,n,r,i){if(-1==r)return!1;let s=e.state.doc.resolve(r);for(let r=s.depth+1;r>0;r--)if(e.someProp(t,t=>r>s.depth?t(e,n,s.nodeAfter,s.before(r),i,!0):t(e,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function aF(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)}aD.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!aV(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!oN||!ob||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!ov||13!=t.keyCode||t.ctrlKey||t.altKey||t.metaKey)e.someProp("handleKeyDown",n=>n(e,t))||function(e,t){let n,r=t.keyCode,i=(n="",t.ctrlKey&&(n+="c"),t.metaKey&&(n+="m"),t.altKey&&(n+="a"),t.shiftKey&&(n+="s"),n);if(8==r||ow&&72==r&&"c"==i)return av(e,-1)||am(e,-1);if(46==r&&!t.shiftKey||ow&&68==r&&"c"==i)return av(e,1)||am(e,1);if(13==r||27==r)return!0;if(37==r||ow&&66==r&&"c"==i){let t=37==r?"ltr"==ax(e,e.state.selection.from)?-1:1:-1;return ap(e,t,i)||am(e,t)}if(39==r||ow&&70==r&&"c"==i){let t=39==r?"ltr"==ax(e,e.state.selection.from)?1:-1:1;return ap(e,t,i)||am(e,t)}else if(38==r||ow&&80==r&&"c"==i)return ay(e,-1,i)||am(e,-1);else if(40==r||ow&&78==r&&"c"==i)return function(e){if(!oy||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;aw(e,n,"true"),setTimeout(()=>aw(e,n,"false"),20)}return!1}(e)||ay(e,1,i)||am(e,1);else if(i==(ow?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():aL(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,oo(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},aD.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},aD.keypress=(e,t)=>{if(aV(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||ow&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof sB)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),i=()=>e.state.tr.insertText(r).scrollIntoView();/[\r\n]/.test(r)||e.someProp("handleTextInput",t=>t(e,n.$from.pos,n.$to.pos,r,i))||e.dispatch(i()),t.preventDefault()}};let aH=ow?"metaKey":"ctrlKey";a_.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=aG(e),o=Date.now(),a="singleClick";o-e.input.lastClick.time<500&&(r=(n=e.input.lastClick).x-t.clientX)*r+(i=n.y-t.clientY)*i<100&&!t[aH]&&e.input.lastClick.button==t.button&&("singleClick"==e.input.lastClick.type?a="doubleClick":"doubleClick"==e.input.lastClick.type&&(a="tripleClick")),e.input.lastClick={time:o,x:t.clientX,y:t.clientY,type:a,button:t.button};let l=e.posAtCoords(a$(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new aU(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return aB(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return aB(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=e.state.doc;if(-1==t)return!!r.inlineContent&&(aF(e,sB.create(r,0,r.content.size),"pointer"),!0);let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),s=i.before(t);if(n.inlineContent)aF(e,sB.create(r,s+1,s+1+n.content.size),"pointer");else{if(!sH.isSelectable(n))continue;aF(e,sH.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():aL(e,"pointer"))};class aU{constructor(e,t,n,r){let i,s;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[aH],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),s=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,s=n.depth?n.before():0}const o=r?null:n.target,a=o?e.docView.nearestDesc(o,!0):null;this.target=a&&1==a.nodeDOM.nodeType?a.nodeDOM:null;let{selection:l}=e.state;0==n.button&&(i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof sH&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&om&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),aL(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>ae(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;if(this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(a$(e))),this.updateAllowDefault(e),this.allowDefault||!t)aL(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,aB(n,"handleClickOn",r,i,e)||n.someProp("handleClick",t=>t(n,r,e))||(s?function(e,t){if(-1==t)return!1;let n=e.state.selection,r,i;n instanceof sH&&(r=n.node);let s=e.state.doc.resolve(t);for(let e=s.depth+1;e>0;e--){let t=e>s.depth?s.nodeAfter:s.node(e);if(sH.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?s.before(n.$from.depth):s.before(e);break}}return null!=i&&(aF(e,sH.create(e.state.doc,i),"pointer"),!0)}(n,i):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&sH.isSelectable(r))&&(aF(e,new sH(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oy&&this.mightDrag&&!this.mightDrag.node.isAtom||ob&&!this.view.state.selection.visible&&2>=Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to)))?(aF(this.view,sL.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):aL(this.view,"pointer")}}move(e){this.updateAllowDefault(e),aL(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function aV(e,t){return!!e.composing||!!(oy&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}a_.touchstart=e=>{e.input.lastTouch=Date.now(),aG(e),aL(e,"pointer")},a_.touchmove=e=>{e.input.lastTouch=Date.now(),aL(e,"pointer")},a_.contextmenu=e=>aG(e);let aW=oN?5e3:-1;function aq(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>aG(e),t))}function aK(e){let t;for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=((t=document.createEvent("Event")).initEvent("event",!0,!0),t.timeStamp));e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function aG(e,t=!1){if(!oN||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),aK(e),t||e.docView&&e.docView.dirty){let n=o7(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}aD.compositionstart=aD.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof sB&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ob&&ok&&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(),aG(e,!0),e.markCursor=null;else if(aG(e,!t.selection.empty),om&&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}aq(e,aW)},aD.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,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++,aq(e,20))};let aJ=oh&&of<15||ov&&oC<604;function aZ(e,t,n,r,i){let s=aN(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,i,s||ix.empty)))return!0;if(!s)return!1;let o=0==s.openStart&&0==s.openEnd&&1==s.content.childCount?s.content.firstChild:null,a=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(s);return e.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function aX(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," "):""}a_.copy=aD.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=aJ?null:t.clipboardData,{dom:s,text:o}=ak(e,n.content());i?(t.preventDefault(),i.clearData(),i.setData("text/html",s.innerHTML),i.setData("text/plain",o)):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(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,s),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},aD.paste=(e,t)=>{if(e.composing&&!oN)return;let n=aJ?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&aZ(e,aX(n),n.getData("text/html"),r,t)?t.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 i=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?aZ(e,r.value,null,i,t):aZ(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class aY{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let aQ=ow?"altKey":"ctrlKey";function a0(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[aQ]}for(let e in a_.dragstart=(e,t)=>{let n,r=e.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=e.state.selection,s=i.empty?null:e.posAtCoords(a$(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof sH?i.to-1:i.to));else if(r&&r.mightDrag)n=sH.create(e.state.doc,r.mightDrag.pos);else if(t.target&&1==t.target.nodeType){let r=e.docView.nearestDesc(t.target,!0);r&&r.node.type.spec.draggable&&r!=e.docView&&(n=sH.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=ak(e,o);t.dataTransfer.files.length&&ob&&!(ox>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(aJ?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",aJ||t.dataTransfer.setData("text/plain",l),e.dragging=new aY(c,a0(e,t),n)},a_.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},aD.dragover=aD.dragenter=(e,t)=>t.preventDefault(),aD.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(a$(t));if(!r)return;let i=e.state.doc.resolve(r.pos),s=n&&n.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=aN(e,aX(t.dataTransfer),aJ?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&a0(e,t));if(e.someProp("handleDrop",n=>n(e,t,s||ix.empty,o)))return t.preventDefault();if(!s)return;t.preventDefault();let a=s?sk(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let l=e.state.tr;if(o){let{node:e}=n;e?e.replace(l):l.deleteSelection()}let c=l.mapping.map(a),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=l.doc;if(d?l.replaceRangeWith(c,c,s.content.firstChild):l.replaceRange(c,c,s),l.doc.eq(u))return;let p=l.doc.resolve(c);if(d&&sH.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new sH(p));else{let t=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),l.setSelection(aa(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},a_.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())&&ae(e)},20))},a_.blur=(e,t)=>{e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),t.relatedTarget&&e.dom.contains(t.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},a_.beforeinput=(e,t)=>{if(ob&&oN&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,oo(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)}},aD)a_[e]=aD[e];function a1(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}class a2{constructor(e,t){this.toDOM=e,this.spec=t||a9,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:s}=e.mapResult(t.from+r,this.side<0?-1:1);return s?null:new a4(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof a2&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&a1(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class a3{constructor(e,t){this.attrs=e,this.spec=t||a9}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,s=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=s?null:new a4(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof a3&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}static is(e){return e.type instanceof a3}destroy(){}}class a5{constructor(e,t){this.attrs=e,this.spec=t||a9}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let s=e.mapResult(t.to+r,-1);return s.deleted||s.pos<=i.pos?null:new a4(i.pos-n,s.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(e){return this==e||e instanceof a5&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}destroy(){}}class a4{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new a4(e,t,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(e,t,n){return new a4(e,e,new a2(t,n))}static inline(e,t,n,r){return new a4(e,t,new a3(n,r))}static node(e,t,n,r){return new a4(e,t,new a5(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof a3}get widget(){return this.type instanceof a2}}let a6=[],a9={};class a7{constructor(e,t){this.local=e.length?e:a6,this.children=t.length?t:a6}static create(e,t){return t.length?li(t,e,0,a9):a8}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,i){for(let s=0;s<this.local.length;s++){let o=this.local[s];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let o=this.children[s]+1;this.children[s+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==a8||0==e.maps.length?this:this.mapInner(e,t,0,0,n||a9)}mapInner(e,t,n,r,i){let s;for(let o=0;o<this.local.length;o++){let a=this.local[o].map(e,n,r);a&&a.type.valid(t,a)?(s||(s=[])).push(a):i.onRemove&&i.onRemove(this.local[o].spec)}return this.children.length?function(e,t,n,r,i,s,o){let a=e.slice();for(let e=0,t=s;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,s)=>{let o=s-i-(n-e);for(let i=0;i<a.length;i+=3){let s=a[i+1];if(s<0||e>s+t-r)continue;let l=a[i]+t-r;n>=l?a[i+1]=e<=l?-2:-1:e>=t&&o&&(a[i]+=o,a[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<a.length;t+=3)if(a[t+1]<0){if(-2==a[t+1]){l=!0,a[t+1]=-1;continue}let c=n.map(e[t]+s),d=c-i;if(d<0||d>=r.content.size){l=!0;continue}let u=n.map(e[t+1]+s,-1)-i,{index:p,offset:h}=r.content.findIndex(d),f=r.maybeChild(p);if(f&&h==d&&h+f.nodeSize==u){let r=a[t+2].mapInner(n,f,c+1,e[t]+s+1,o);r!=a8?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=li(function(e,t,n,r,i,s,o){for(let a=0;a<e.length;a+=3)-1==e[a+1]&&function e(t,s){for(let e=0;e<t.local.length;e++){let a=t.local[e].map(r,i,s);a?n.push(a):o.onRemove&&o.onRemove(t.local[e].spec)}for(let n=0;n<t.children.length;n+=3)e(t.children[n+2],t.children[n]+s+1)}(e[a+2],t[a]+s+1);return n}(a,e,t,n,i,s,o),r,0,o);t=l.local;for(let e=0;e<a.length;e+=3)a[e+1]<0&&(a.splice(e,3),e-=3);for(let e=0,t=0;e<l.children.length;e+=3){let n=l.children[e];for(;t<a.length&&a[t]<n;)t+=3;a.splice(t,0,l.children[e],l.children[e+1],l.children[e+2])}}return new a7(t.sort(ls),a)}(this.children,s||[],e,t,n,r,i):s?new a7(s.sort(ls),a6):a8}add(e,t){return t.length?this==a8?a7.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,i=0;e.forEach((e,s)=>{let o=s+n,a;if(a=ln(t,e,o)){for(r||(r=this.children.slice());i<r.length&&r[i]<s;)i+=3;r[i]==s?r[i+2]=r[i+2].addInner(e,a,o+1):r.splice(i,0,s,s+e.nodeSize,li(a,e,o+1,a9)),i+=3}});let s=lt(i?lr(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new a7(s.length?this.local.concat(s).sort(ls):this.local,r||this.children)}remove(e){return 0==e.length||this==a8?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let r=0;r<n.length;r+=3){let i,s=n[r]+t,o=n[r+1]+t;for(let t=0,n;t<e.length;t++)(n=e[t])&&n.from>s&&n.to<o&&(e[t]=null,(i||(i=[])).push(n));if(!i)continue;n==this.children&&(n=this.children.slice());let a=n[r+2].removeInner(i,s+1);a!=a8?n[r+2]=a:(n.splice(r,3),r-=3)}if(r.length){for(let n=0,i;n<e.length;n++)if(i=e[n])for(let e=0;e<r.length;e++)r[e].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(e--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new a7(r,n):a8}forChild(e,t){let n,r;if(this==a8)return this;if(t.isLeaf)return a7.empty;for(let t=0;t<this.children.length;t+=3)if(this.children[t]>=e){this.children[t]==e&&(n=this.children[t+2]);break}let i=e+1,s=i+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<s&&t.to>i&&t.type instanceof a3){let e=Math.max(i,t.from)-i,n=Math.min(s,t.to)-i;e<n&&(r||(r=[])).push(t.copy(e,n))}}if(r){let e=new a7(r.sort(ls),a6);return n?new le([e,n]):e}return n||a8}eq(e){if(this==e)return!0;if(!(e instanceof a7)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return lo(this.localsInner(e))}localsInner(e){if(this==a8)return a6;if(e.inlineContent||!this.local.some(a3.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof a3||t.push(this.local[e]);return t}forEachSet(e){e(this)}}a7.empty=new a7([],[]),a7.removeOverlap=lo;let a8=a7.empty;class le{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,a9));return le.from(n)}forChild(e,t){if(t.isLeaf)return a7.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=a8&&(i instanceof le?n=n.concat(i.members):n.push(i))}return le.from(n)}eq(e){if(!(e instanceof le)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?lo(n?t:t.sort(ls)):a6}static from(e){switch(e.length){case 0:return a8;case 1:return e[0];default:return new le(e.every(e=>e instanceof a7)?e:e.reduce((e,t)=>e.concat(t instanceof a7?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lt(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new a4(i.from+t,i.to+t,i.type))}return n}function ln(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,s;t<e.length;t++)(s=e[t])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),e[t]=null);return i}function lr(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function li(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=ln(e,t,o+n);if(a){s=!0;let e=li(a,t,n+o+1,r);e!=a8&&i.push(o,o+t.nodeSize,e)}});let o=lt(s?lr(e):e,-n).sort(ls);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new a7(o,i):a8}function ls(e,t){return e.from-t.from||e.to-t.to}function lo(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let s=t[i];if(s.from==r.from){s.to!=r.to&&(t==e&&(t=e.slice()),t[i]=s.copy(s.from,r.to),la(t,i+1,s.copy(r.to,s.to)));continue}s.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,s.from),la(t,i,r.copy(s.from,r.to)));break}}return t}function la(e,t,n){for(;t<e.length&&ls(n,e[t])>0;)t++;e.splice(t,0,n)}function ll(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=a8&&t.push(r)}),e.cursorWrapper&&t.push(a7.create(e.state.doc,[e.cursorWrapper.deco])),le.from(t)}let lc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ld=oh&&of<=11;class lu{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class lp{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lu,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);oh&&of<=11&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():oy&&e.composing&&t.some(e=>"childList"==e.type&&"TR"==e.target.nodeName)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),ld&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,lc)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(al(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(oh&&of<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=s4(n))t.add(n);for(let r=e.anchorNode;r;r=s4(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:3==n.nodeType?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){var e;let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=t.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&al(t)&&!this.ignoreSelectionChange(r),s=-1,o=-1,a=!1,l=[];if(t.editable)for(let e=0;e<n.length;e++){let t=this.registerMutation(n[e],l);t&&(s=s<0?t.from:Math.min(t.from,s),o=o<0?t.to:Math.max(t.to,o),t.typeOver&&(a=!0))}if(l.some(e=>"BR"==e.nodeName)&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode)){for(let e of l)if("BR"==e.nodeName&&e.parentNode){let t=e.nextSibling;for(;t&&1==t.nodeType;){if("false"==t.contentEditable){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(om&&l.length){let e=l.filter(e=>"BR"==e.nodeName);if(2==e.length){let[t,n]=e;t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of e){let e=r.parentNode;e&&"LI"==e.nodeName&&(!n||function(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}(t,n)!=e)&&r.remove()}}}let c=null;s<0&&i&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&oi(r)&&(c=o7(t))&&c.eq(sL.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,ae(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lh.has(e)&&(lh.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=om,lf||(console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),lf=!0))),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(e,t){var n;let{focusNode:r,focusOffset:i}=e.domSelectionRange();for(let s of t)if((null==(n=s.parentNode)?void 0:n.nodeName)=="TR"){let t=s.nextSibling;for(;t&&"TD"!=t.nodeName&&"TH"!=t.nodeName;)t=t.nextSibling;if(t){let n=t;for(;;){let e=n.firstChild;if(!e||1!=e.nodeType||"false"==e.contentEditable||/^(BR|IMG)$/.test(e.nodeName))break;n=e}n.insertBefore(s,n.firstChild),r==s&&e.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}(t,l)),this.handleDOMChange(s,o,a,l),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(r)||ae(t),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),3==r.nodeType&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(oh&&of<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:s}=e.addedNodes[t];(!n||0>Array.prototype.indexOf.call(e.addedNodes,n))&&(r=n),(!s||0>Array.prototype.indexOf.call(e.addedNodes,s))&&(i=s)}let s=r&&r.parentNode==e.target?s5(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?s5(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,a,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let lh=new WeakMap,lf=!1;function lm(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return s8(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lg(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(oy&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}else if(e.parentNode.lastChild==e||oy&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}let lb=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lx(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:aa(e,t.resolve(n.anchor),t.resolve(n.head))}function ly(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function lv(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class lw{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new aI,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(lj),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=lS(this),lN(this),this.nodeViews=lC(this),this.docView=oG(this.state.doc,lk(this),ll(this),this.dom,this),this.domObserver=new lp(this,(e,t,n,r)=>(function(e,t,n,r,i){let s,o,a,l=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=o7(e,t);if(n&&!e.state.selection.eq(n)){if(ob&&oN&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter"))))return;let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),l&&r.setMeta("composition",l),e.dispatch(r)}return}let c=e.state.doc.resolve(t),d=c.sharedDepth(n);t=c.before(d+1),n=e.state.doc.resolve(n).after(d+1);let u=e.state.selection,p=function(e,t,n){let r,{node:i,fromOffset:s,toOffset:o,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(r=[{node:d,offset:c.anchorOffset}],oi(c)||r.push({node:c.focusNode,offset:c.focusOffset})),ob&&8===e.input.lastKeyCode)for(let e=o;e>s;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if("BR"==t.nodeName&&!n){o=e;break}if(!n||n.size)break}let u=e.state.doc,p=e.someProp("domParser")||iG.fromSchema(e.state.schema),h=u.resolve(a),f=null,m=p.parse(i,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:s,to:o,preserveWhitespace:"pre"!=h.parent.type.whitespace||"full",findPositions:r,ruleFromNode:lg,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+a,head:t+a}}return{doc:m,sel:f,from:a,to:l}}(e,t,n),h=e.state.doc,f=h.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(s=e.state.selection.to,o="end"):(s=e.state.selection.from,o="start"),e.input.lastKeyCode=null;let m=function(e,t,n,r,i){let s=e.findDiffStart(t,n);if(null==s)return null;let{a:o,b:a}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==i){let e=Math.max(0,s-Math.min(o,a));r-=o+e-s}if(o<s&&e.size<t.size){let e=r<=s&&r>=o?s-r:0;(s-=e)&&s<t.size&&lv(t.textBetween(s-1,s+1))&&(s+=e?1:-1),a=s+(a-o),o=s}else if(a<s){let t=r<=s&&r>=a?s-r:0;(s-=t)&&s<e.size&&lv(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(f.content,p.doc.content,p.from,s,o);if(m&&e.input.domChangeCount++,(ov&&e.input.lastIOSEnter>Date.now()-225||oN)&&i.some(e=>1==e.nodeType&&!lb.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!m)if(r&&u instanceof sB&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))m={start:u.from,endA:u.to,endB:u.to};else{if(p.sel){let t=lx(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);l&&n.setMeta("composition",l),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&m.start==m.endB&&e.state.selection instanceof sB&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oh&&of<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),b=p.doc.resolveNoCache(m.endB-p.from),x=h.resolve(m.start),y=g.sameParent(b)&&g.parent.inlineContent&&x.end()>=m.endA;if((ov&&e.input.lastIOSEnter>Date.now()-225&&(!y||i.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!y&&g.pos<p.doc.content.size&&(!g.sameParent(b)||!g.parent.inlineContent)&&g.pos<b.pos&&!/\S/.test(p.doc.textBetween(g.pos,b.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.start&&function(e,t,n,r,i){if(n-t<=i.pos-r.pos||ly(r,!0,!1)<i.pos)return!1;let s=e.resolve(t);if(!r.parent.isTextblock){let e=s.nodeAfter;return null!=e&&n==t+e.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=e.resolve(ly(s,!0,!0));return!(!o.parent.isTextblock||o.pos>n||ly(o,!0,!1)<n)&&r.parent.content.cut(r.parentOffset).eq(o.parent.content)}(h,m.start,m.endA,g,b)&&e.someProp("handleKeyDown",t=>t(e,oo(8,"Backspace")))){oN&&ob&&e.domObserver.suppressSelectionUpdates();return}ob&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),oN&&!y&&g.start()!=b.start()&&0==b.parentOffset&&g.depth==b.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,b=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oo(13,"Enter"))})},20));let v=m.start,w=m.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=lx(e,n.doc,p.sel);t&&!(ob&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oh&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==b.pos){oh&&of<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(m.start).marksAcross(h.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.endB&&(a=function(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,s=r,o,a,l;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)s=n[e].removeFromSet(s);if(1==i.length&&0==s.length)a=i[0],o="add",l=e=>e.mark(a.addToSet(e.marks));else{if(0!=i.length||1!=s.length)return null;a=s[0],o="remove",l=e=>e.mark(a.removeFromSet(e.marks))}let c=[];for(let e=0;e<t.childCount;e++)c.push(l(t.child(e)));if(iu.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,b.parentOffset),x.parent.content.cut(x.parentOffset,m.endA-x.start())))){let t=k(e.state.tr);"add"==a.type?t.addMark(v,w,a.mark):t.removeMark(v,w,a.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==b.index()-!b.textOffset){let t=g.parent.textBetween(g.parentOffset,b.parentOffset),n=()=>k(e.state.tr.insertText(t,v,w));e.someProp("handleTextInput",r=>r(e,v,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())})(this,e,t,n,r)),this.domObserver.start(),function(e){for(let t in a_){let n=a_[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}(e,t)||az(e,t)||!e.editable&&t.type in aD||n(e,t)},aR[t]?{passive:!0}:void 0)}oy&&e.dom.addEventListener("input",()=>null),aP(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;for(let t in this._props={},e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&aP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(lj),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];for(let n in t.state=this.state,e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n,r,i;let s=this.state,o=!1,a=!1;e.storedMarks&&this.composing&&(aK(this),a=!0),this.state=e;let l=s.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=lC(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&aP(this),this.editable=lS(this),lN(this);let c=ll(this),d=lk(this),u=s.plugins==e.plugins||s.doc.eq(e.doc)?e.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",p=o||!this.docView.matchesNode(e.doc,d,c);(p||!e.selection.eq(s.selection))&&(a=!0);let h="preserve"==u&&a&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let s=(r.left+r.right)/2,o=i+1;o<Math.min(innerHeight,r.bottom);o+=5){let r=e.root.elementFromPoint(s,o);if(!r||r==e.dom||!e.dom.contains(r))continue;let a=r.getBoundingClientRect();if(a.top>=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:oM(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oh||ob)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&(r=s.selection,i=e.selection,a=Math.min(r.$anchor.sharedDepth(r.head),i.$anchor.sharedDepth(i.head)),r.$anchor.start(a)!=i.$anchor.start(a));if(p){let t=ob?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=on(e=e.childNodes[t-1])}else{if(!e.parentNode||or(e))return null;t=s5(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),r=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||or(e))return null;t=s5(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}(this)),(o||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=oG(e.doc,d,c,this.dom,this)),!t||this.trackWrites&&this.dom.contains(this.trackWrites)||(l=!0)}l||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&(t=this.docView.domFromPos(this.state.selection.anchor,0),n=this.domSelectionRange(),s8(t.node,t.offset,n.anchorNode,n.anchorOffset)))?ae(this,l):(as(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null==(n=this.dragging)?void 0:n.node)&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;oA(n,0==r?0:r-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof sH){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&oE(this,t.getBoundingClientRect(),e)}else oE(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(e&&e.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new aY(e.slice,e.move,r<0?void 0:sH.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(null!=n&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(null!=i&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let s=i[n].props[e];if(null!=s&&(r=t?t(s):s))return r}}hasFocus(){if(oh){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(oT)return e.focus(oT);let t=oM(e);e.focus(null==oT?{get preventScroll(){return oT={preventScroll:!0},!0}}:void 0),oT||(oT=!1,oA(t,0))}(this.dom),ae(this),this.domObserver.start()}get root(){let e=this._root;if(null==e){for(let e=this.dom.parentNode;e;e=e.parentNode)if(9==e.nodeType||11==e.nodeType&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return function(e,t){var n;let r,i,s=e.dom.ownerDocument,o,a=0,l=function(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(on(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(on(r.startContainer),r.startOffset)}}}(s,t.left,t.top);l&&({node:o,offset:a}=l);let c=(e.root.elementFromPoint?e.root:s).elementFromPoint(t.left,t.top);if(!c||!e.dom.contains(1!=c.nodeType?c.parentNode:c)){let n=e.dom.getBoundingClientRect();if(!oO(t,n)||!(c=function e(t,n,r){let i=t.childNodes.length;if(i&&r.top<r.bottom)for(let s=Math.max(0,Math.min(i-1,Math.floor(i*(n.top-r.top)/(r.bottom-r.top))-2)),o=s;;){let r=t.childNodes[o];if(1==r.nodeType){let t=r.getClientRects();for(let i=0;i<t.length;i++){let s=t[i];if(oO(n,s))return e(r,n,s)}}if((o=(o+1)%i)==s)break}return t}(e.dom,t,n)))return null}if(oy)for(let e=c;o&&e;e=s4(e))e.draggable&&(o=void 0);if(c=(r=(n=c).parentNode)&&/^li$/i.test(r.nodeName)&&t.left<n.getBoundingClientRect().left?r:n,o){let n;if(om&&1==o.nodeType&&(a=Math.min(a,o.childNodes.length))<o.childNodes.length){let e=o.childNodes[a],n;"IMG"==e.nodeName&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&a++}oS&&a&&1==o.nodeType&&1==(n=o.childNodes[a-1]).nodeType&&"false"==n.contentEditable&&n.getBoundingClientRect().top>=t.top&&a--,o==e.dom&&a==o.childNodes.length-1&&1==o.lastChild.nodeType&&t.top>o.lastChild.getBoundingClientRect().bottom?i=e.state.doc.content.size:(0==a||1!=o.nodeType||"BR"!=o.childNodes[a-1].nodeName)&&(i=function(e,t,n,r){let i=-1;for(let n=t,s=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!s&&o.left>r.left||o.top>r.top?i=t.posBefore:(!s&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),s=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,o,a,t))}null==i&&(i=function(e,t,n){let{node:r,offset:i}=function e(t,n){let r,i,s,o=2e8,a,l=0,c=n.top,d=n.top;for(let e=t.firstChild,u=0;e;e=e.nextSibling,u++){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=s9(e).getClientRects()}for(let p=0;p<t.length;p++){let h=t[p];if(h.top<=c&&h.bottom>=d){c=Math.max(h.bottom,c),d=Math.min(h.top,d);let t=h.left>n.left?h.left-n.left:h.right<n.left?n.left-h.right:0;if(t<o){s=e,o=t,a=t&&3==s.nodeType?{left:h.right<n.left?h.right:h.left,top:n.top}:n,1==e.nodeType&&t&&(l=u+ +(n.left>=(h.left+h.right)/2));continue}}else h.top>n.top&&!r&&h.left<=n.left&&h.right>=n.left&&(r=e,i={left:Math.max(h.left,Math.min(h.right,n.left)),top:h.top});!s&&(n.left>=h.right&&n.top>=h.top||n.left>=h.left&&n.top>=h.bottom)&&(l=u+1)}}return(!s&&r&&(s=r,a=i,o=0),s&&3==s.nodeType)?function(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let s=0;s<n;s++){r.setEnd(e,s+1),r.setStart(e,s);let n=oD(r,1);if(n.top!=n.bottom&&oO(t,n)){i={node:e,offset:s+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}(s,a):!s||o&&1==s.nodeType?{node:t,offset:l}:e(s,a)}(t,n),s=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();s=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,s)}(e,c,t));let d=e.docView.nearestDesc(c,!0);return{pos:i,inside:d?d.posAtStart-d.border:-1}}(this,e)}coordsAtPos(e,t=1){return oI(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return function(e,t,n){let r,i;return oB==t&&oF==n?oH:(oB=t,oF=n,oH="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,oz(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=oI(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=s9(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&("up"==n?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=i==r.parent.content.size,o=e.domSelection();return o?o$.test(r.parent.textContent)&&o.modify?oz(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:s,anchorOffset:a}=e.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",n,"character");let c=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&i==u;try{o.collapse(s,a),t&&(t!=s||i!=a)&&o.extend&&o.extend(t,i)}catch(e){}return null!=l&&(o.caretBidiLevel=l),p}):"left"==n||"backward"==n?!i:s:r.pos==r.start()||r.pos==r.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return aZ(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return aZ(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ak(this,e)}destroy(){if(this.docView){for(let e in this.domObserver.stop(),this.input.eventHandlers)this.dom.removeEventListener(e,this.input.eventHandlers[e]);clearTimeout(this.input.composingTimeout),clearTimeout(this.input.lastIOSEnterFallbackTimeout),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],ll(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,s7()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!az(this,e)&&a_[e.type]&&(this.editable||!(e.type in aD))&&a_[e.type](this,e)}domSelectionRange(){let e=this.domSelection();return e?oy&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){let n;if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return lm(e,n)}function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",r,!0),n?lm(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function lk(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[a4.node(0,e.state.doc.content.size,t)]}function lN(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:a4.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function lS(e){return!e.someProp("editable",t=>!1===t(e.state))}function lC(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function lj(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError("Plugins passed directly to the view must not have a state component")}lw.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var lE={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},lM={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},lA="u">typeof navigator&&/Mac/.test(navigator.platform),lT="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),lO=0;lO<10;lO++)lE[48+lO]=lE[96+lO]=String(lO);for(var lO=1;lO<=24;lO++)lE[lO+111]="F"+lO;for(var lO=65;lO<=90;lO++)lE[lO]=String.fromCharCode(lO+32),lM[lO]=String.fromCharCode(lO);for(var l_ in lE)lM.hasOwnProperty(l_)||(lM[l_]=lE[l_]);let lD="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lR="u">typeof navigator&&/Win/.test(navigator.platform);function lI(e,t,n=!0){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n&&t.shiftKey&&(e="Shift-"+e),e}function lL(e){let t=function(e){let t=Object.create(null);for(let n in e)t[function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"==o&&(o=" ");for(let e=0;e<s.length-1;e++){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))lD?i=!0:n=!0;else throw Error("Unrecognized modifier name: "+o)}return t&&(o="Alt-"+o),n&&(o="Ctrl-"+o),i&&(o="Meta-"+o),r&&(o="Shift-"+o),o}(n)]=e[n];return t}(e);return function(e,n){var r;let i=("Esc"==(r=!(lA&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||lT&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?lM:lE)[n.keyCode]||n.key||"Unidentified")&&(r="Escape"),"Del"==r&&(r="Delete"),"Left"==r&&(r="ArrowLeft"),"Up"==r&&(r="ArrowUp"),"Right"==r&&(r="ArrowRight"),"Down"==r&&(r="ArrowDown"),r),s,o=t[lI(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[lI(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(lR&&n.ctrlKey&&n.altKey)&&(s=lE[n.keyCode])&&s!=i){let r=t[lI(s,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}if("u">typeof WeakMap){let e=new WeakMap;t=t=>e.get(t),n=(t,n)=>(e.set(t,n),n)}else{let e=[],r=0;t=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},n=(t,n)=>(10==r&&(r=0),e[r++]=t,e[r++]=n)}var lP=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,s=r+1,o=i+1;for(let e=1;s<this.width&&this.map[t+e]==n;e++)s++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:s,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:s,bottom:o}=this.findCell(e);return"horiz"==t?(n<0?0==r:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?0==s:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:s}=this.findCell(e),{left:o,right:a,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let s=r*this.width+i,o=this.map[s];!n[o]&&(n[o]=!0,i==e.left&&i&&this.map[s-1]==o||r==e.top&&r&&this.map[s-this.width]==o||t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let s=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?s-1:this.map[n]}i=s}}static get(e){return t(e)||n(e,function(e){if("table"!=e.type.spec.tableRole)throw RangeError("Not a table node: "+e.type.name);let t=function(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),s=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(s+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);s+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=s:t!=s&&(t=Math.max(t,s))}return t}(e),n=e.childCount,r=[],i=0,s=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let a=0,l=0;a<n;a++){let c=e.child(a);l++;for(let e=0;;e++){for(;i<r.length&&0!=r[i];)i++;if(e==c.childCount)break;let d=c.child(e),{colspan:u,rowspan:p,colwidth:h}=d.attrs;for(let e=0;e<p;e++){if(e+a>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:l,n:p-e});break}let c=i+e*t;for(let e=0;e<u;e++){0==r[c+e]?r[c+e]=l:(s||(s=[])).push({type:"collision",row:a,pos:l,n:u-e});let n=h&&h[e];if(n){let r=(c+e)%t*2,i=o[r];null==i||i!=n&&1==o[r+1]?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=u,l+=d.nodeSize}let d=(a+1)*t,u=0;for(;i<d;)0==r[i++]&&u++;u&&(s||(s=[])).push({type:"missing",row:a,n:u}),l++}(0===t||0===n)&&(s||(s=[])).push({type:"zero_sized"});let a=new lP(t,n,r,s),l=!1;for(let e=0;!l&&e<o.length;e+=2)null!=o[e]&&o[e+1]<n&&(l=!0);return l&&function(e,t,n){e.problems||(e.problems=[]);let r={};for(let i=0;i<e.map.length;i++){let s=e.map[i];if(r[s])continue;r[s]=!0;let o=n.nodeAt(s);if(!o)throw RangeError(`No cell with offset ${s} found`);let a=null,l=o.attrs;for(let n=0;n<l.colspan;n++){let r=t[(i+n)%e.width*2];null==r||l.colwidth&&l.colwidth[n]==r||((a||(a=function(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}(l)))[n]=r)}a&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}(a,o,e),a}(e))}};function lz(e){let t=e.cached.tableNodeTypes;if(!t)for(let n in t=e.cached.tableNodeTypes={},e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}return t}let l$=new s3("selectingCells");function lB(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function lF(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function lH(e){let t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;let n=lB(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function lU(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function lV(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function lW(e,t,n){let r=e.node(-1),i=lP.get(r),s=e.start(-1),o=i.nextCell(e.pos-s,t,n);return null==o?null:e.node(0).resolve(s+o)}function lq(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function lK(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}var lG=class e extends sL{constructor(e,t=e){const n=e.node(-1),r=lP.get(n),i=e.start(-1),s=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),a=r.cellsInRect(s).filter(e=>e!=t.pos-i);a.unshift(t.pos-i);const l=a.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new sP(o.resolve(r),o.resolve(r+t.content.size))});super(l[0].$from,l[0].$to,l),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(lU(r)&&lU(i)&&lV(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return sB.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=lP.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},s=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let s=n*t.width+r.left,a=r.left;a<r.right;a++,s++){let n=t.map[s];if(i[n])continue;i[n]=!0;let a=t.findCell(n),l=e.nodeAt(n);if(!l)throw RangeError(`No cell with offset ${n} found`);let c=r.left-a.left,d=a.right-r.right;if(c>0||d>0){let e=l.attrs;if(c>0&&(e=lq(e,0,c)),d>0&&(e=lq(e,e.colspan-d,d)),a.left<r.left){if(!(l=l.type.createAndFill(e)))throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else l=l.type.create(e,l.content)}if(a.top<r.top||a.bottom>r.bottom){let e={...l.attrs,rowspan:Math.min(a.bottom,r.bottom)-Math.max(a.top,r.top)};l=a.top<r.top?l.type.createAndFill(e):l.type.create(e,l.content)}o.push(l)}s.push(e.child(n).copy(iu.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new ix(iu.from(o),1,1)}replace(e,t=ix.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n);e.replace(a.map(s.pos),a.map(o.pos),i?ix.empty:t)}let i=sL.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new ix(iu.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=lP.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);return!(Math.min(e,t)>0)&&Math.max(e+this.$anchorCell.nodeAfter.attrs.rowspan,t+this.$headCell.nodeAfter.attrs.rowspan)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=lP.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.top<=a.top?(o.top>0&&(t=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(t=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=lP.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);return!(Math.min(r,i)>0)&&Math.max(r+this.$anchorCell.nodeAfter.attrs.colspan,i+this.$headCell.nodeAfter.attrs.colspan)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=lP.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.left<=a.left?(o.left>0&&(t=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(t=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new lJ(this.$anchorCell.pos,this.$headCell.pos)}};lG.prototype.visible=!1,sL.jsonID("cell",lG);var lJ=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){let t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&lV(t,n)?new lG(t,n):sL.near(n,1)}};function lZ(e){if(!(e.selection instanceof lG))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(a4.node(n,n+e.nodeSize,{class:"selectedCell"}))}),a7.create(e.doc,t)}let lX=new s3("fix-tables");function lY(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=lP.get(t);if(!o.problems)return r;r||(r=e.tr);let a=[];for(let e=0;e<o.height;e++)a.push(0);for(let e=0;e<o.problems.length;e++){let i=o.problems[e];if("collision"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;let s=e.attrs;for(let e=0;e<s.rowspan;e++)a[i.row+e]+=i.n;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,lq(s,s.colspan-i.n,i.n))}else if("missing"==i.type)a[i.row]+=i.n;else if("overlong_rowspan"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-i.n})}else if("colwidth mismatch"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,colwidth:i.colwidth})}else if("zero_sized"==i.type){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}for(let e=0;e<a.length;e++)a[e]&&(null==i&&(i=e),s=e);for(let l=0,c=n+1;l<o.height;l++){let n=t.child(l),o=c+n.nodeSize,d=a[l];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<d;n++){let n=lz(e.schema)[t].createAndFill();n&&a.push(n)}let u=(0==l||i==l-1)&&s==l?c+1:o-1;r.insert(r.mapping.map(u),a)}c=o}return r.setMeta(lX,{fixTables:!0})}(e,t,r,n))};return t?t.doc!=e.doc&&function e(t,n,r,i){let s=t.childCount,o=n.childCount;n:for(let a=0,l=0;a<o;a++){let o=n.child(a);for(let e=l,n=Math.min(s,a+3);e<n;e++)if(t.child(e)==o){l=e+1,r+=o.nodeSize;continue n}i(o,r),l<s&&t.child(l).sameMarkup(o)?e(t.child(l),o,r+1,i):o.nodesBetween(0,o.content.size,i,r+1),r+=o.nodeSize}}(t.doc,e.doc,0,r):e.doc.descendants(r),n}function lQ(e){let t=lP.get(e),n=[],r=t.height,i=t.width;for(let s=0;s<r;s++){let r=[];for(let n=0;n<i;n++){let o=s*i+n,a=t.map[o];if(s>0){let e=o-i;if(a===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(a===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(a))}n.push(r)}return n}function l0(e,t){let n=[],r=lP.get(e),i=r.height,s=r.width;for(let o=0;o<i;o++){let i=e.child(o),a=[];for(let n=0;n<s;n++){let i=t[o][n];if(!i)continue;let s=r.map[o*r.width+n],l=e.nodeAt(s);if(!l)continue;let c=l.type.createChecked(i.attrs,i.content,i.marks);a.push(c)}let l=i.type.createChecked(i.attrs,a,i.marks);n.push(l)}return e.type.createChecked(e.attrs,n,e.marks)}function l1(e,t,n,r){let i,s=t[0]>n[0]?-1:1,o=e.splice(t[0],t.length),a=+(o.length%2==0);return i=-1===r&&1===s?n[0]-1:1===r&&-1===s?n[n.length-1]-a+1:-1===s?n[0]:n[n.length-1]-a,e.splice(i,0,...o),e}function l2(e){var t=e;for(let e=t.depth;e>=0;e-=1){let n=t.node(e);if((e=>"table"===e.type.spec.tableRole)(n))return{node:n,pos:0===e?0:t.before(e),start:t.start(e),depth:e}}return null}function l3(e,t){let n=l2(t.$from);if(!n)return;let r=lP.get(n.node);if(!(e<0)&&!(e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function l5(e,t){let n=l2(t.$from);if(!n)return;let r=lP.get(n.node);if(!(e<0)&&!(e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function l4(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l3(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=l3(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=l3(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l3(i,e.selection),l=l5(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=l3(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function l6(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l5(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=l5(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=l5(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l5(i,e.selection),l=l3(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=l5(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function l9(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function l7(e){let t=e.selection,n=lH(e),r=n.node(-1),i=n.start(-1),s=lP.get(r);return{...t instanceof lG?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function l8(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=lz(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0})(t,r,i+s)&&(s=0==i||i==t.width?null:0);for(let o=0;o<t.height;o++){let a=o*t.width+i;if(i>0&&i<t.width&&t.map[a-1]==t.map[a]){let s=t.map[a],l=r.nodeAt(s);e.setNodeMarkup(e.mapping.map(n+s),null,lK(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?lz(r.type.schema).cell:r.nodeAt(t.map[a+s]).type,c=t.positionAt(o,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function ce(e,{map:t,tableStart:n,table:r},i){let s=n;for(let e=0;e<i;e++)s+=r.child(e).nodeSize;let o=[],a=i>0?-1:0;(function(e,t,n){var r;let i=lz(t.type.schema).header_cell;for(let s=0;s<e.width;s++)if((null==(r=t.nodeAt(e.map[s+n*e.width]))?void 0:r.type)!=i)return!1;return!0})(t,r,i+a)&&(a=0==i||i==t.height?null:0);for(let s=0,c=t.width*i;s<t.width;s++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),s+=o.colspan-1}else{var l;let e=null==a?lz(r.type.schema).cell:null==(l=r.nodeAt(t.map[c+a*t.width]))?void 0:l.type,n=null==e?void 0:e.createAndFill();n&&o.push(n)}return e.insert(s,lz(r.type.schema).row.create(null,o)),e}function ct(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cn(e,t){let n=e.selection;if(!(n instanceof lG)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=l7(e),{map:i}=r;if(function({width:e,height:t,map:n},r){let i=r.top*e+r.left,s=i,o=(r.bottom-1)*e+r.left,a=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[s]==n[s-1]||r.right<e&&n[a]==n[a+1])return!0;s+=e,a+=e}for(let s=r.left;s<r.right;s++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}(i,r))return!1;if(t){let n,s,o=e.tr,a={},l=iu.empty;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let c=i.map[e*i.width+t],d=r.table.nodeAt(c);if(!a[c]&&d)if(a[c]=!0,null==n)n=c,s=d;else{ct(d)||(l=l.append(d.content));let e=o.mapping.map(c+r.tableStart);o.delete(e,e+d.nodeSize)}}if(null==n||null==s)return!0;if(o.setNodeMarkup(n+r.tableStart,null,{...lK(s.attrs,s.attrs.colspan,r.right-r.left-s.attrs.colspan),rowspan:r.bottom-r.top}),l.size>0){let e=n+1+s.content.size,t=ct(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new lG(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cr(e,t){var n;let r=lz(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof lG){if(s.$anchorCell.pos!=s.$headCell.pos)return!1;r=s.$anchorCell.nodeAfter,i=s.$anchorCell.pos}else{var o;if(!(r=function(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(s.$from)))return!1;i=null==(o=lB(s.$from))?void 0:o.pos}if(null==r||null==i||1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(t){let o,a=r.attrs,l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});let d=l7(e),u=e.tr;for(let e=0;e<d.right-d.left;e++)l.push(c?{...a,colwidth:c&&c[e]?[c[e]]:null}:a);for(let e=d.top;e<d.bottom;e++){let t=d.map.positionAt(e,d.left,d.table);e==d.top&&(t+=r.nodeSize);for(let i=d.left,s=0;i<d.right;i++,s++)(i!=d.left||e!=d.top)&&u.insert(o=u.mapping.map(t+d.tableStart,1),n({node:r,row:e,col:i}).createAndFill(l[s]))}u.setNodeMarkup(i,n({node:r,row:d.top,col:d.left}),l[0]),s instanceof lG&&u.setSelection(new lG(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function ci(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function cs(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=i.map.cellsInRect("column"==e?{left:i.left,top:0,right:i.right,bottom:i.map.height}:"row"==e?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)a[e].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[e],r.cell,a[e].attrs);if(0===s.steps.length)for(let e=0;e<o.length;e++)s.setNodeMarkup(i.tableStart+o[e],r.header_cell,a[e].attrs);n(s)}return!0};return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=ci("row",i,r),a=ci("column",i,r),l=+("column"===e?!!o:"row"===e&&!!a),c="column"==e?{left:0,top:l,right:1,bottom:i.map.height}:"row"==e?{left:l,top:0,right:i.map.width,bottom:1}:i,d="column"==e?a?r.cell:r.header_cell:"row"==e?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(c).forEach(e=>{let t=e+i.tableStart,n=s.doc.nodeAt(t);n&&s.setNodeMarkup(t,d,n.attrs)}),n(s)}return!0}}cs("row",{useDeprecatedLogic:!0}),cs("column",{useDeprecatedLogic:!0});let co=cs("cell",{useDeprecatedLogic:!0});function ca(e){return function(t,n){if(!lF(t))return!1;let r=function(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}(lH(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(sB.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cl(e,t){let n=e.selection;if(!(n instanceof lG))return!1;if(t){let r=e.tr,i=lz(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new ix(i,0,0))}),r.docChanged&&t(r)}return!0}function cc(e,t){let n=e.createAndFill();return new sR(n).replace(0,n.content.size,t).doc}function cd(e,t,n,r,i,s,o,a){if(0==o||o==t.height)return!1;let l=!1;for(let c=i;c<s;c++){let i=o*t.width+c,s=t.map[i];if(t.map[i-t.width]==s){l=!0;let i=n.nodeAt(s),{top:d,left:u}=t.findCell(s);e.setNodeMarkup(e.mapping.slice(a).map(s+r),null,{...i.attrs,rowspan:o-d}),e.insert(e.mapping.slice(a).map(t.positionAt(o,u,n)),i.type.createAndFill({...i.attrs,rowspan:d+i.attrs.rowspan-o})),c+=i.attrs.colspan-1}}return l}function cu(e,t,n,r,i,s,o,a){if(0==o||o==t.width)return!1;let l=!1;for(let c=i;c<s;c++){let i=c*t.width+o,s=t.map[i];if(t.map[i-1]==s){l=!0;let i=n.nodeAt(s),d=t.colCount(s),u=e.mapping.slice(a).map(s+r);e.setNodeMarkup(u,null,lq(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(lq(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cp(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=lP.get(s),{top:a,left:l}=r,c=l+i.width,d=a+i.height,u=e.tr,p=0;function h(){if(!(s=n?u.doc.nodeAt(n-1):u.doc))throw Error("No table found");o=lP.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=lz(e.doc.type.schema);if(i>t.width)for(let s=0,c=0;s<t.height;s++){let d,u=n.child(s);c+=u.nodeSize;let p=[];d=null==u.lastChild||u.lastChild.type==l.cell?o||(o=l.cell.createAndFill()):a||(a=l.header_cell.createAndFill());for(let e=t.width;e<i;e++)p.push(d);e.insert(e.mapping.slice(0).map(c-1+r),p)}if(s>t.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=!(e>=t.width)&&n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?a||(a=l.header_cell.createAndFill()):o||(o=l.cell.createAndFill()))}let d=l.row.create(null,iu.from(c)),u=[];for(let e=t.height;e<s;e++)u.push(d);e.insert(e.mapping.slice(0).map(r+n.nodeSize-2),u)}return!!(o||a)})(u,o,s,n,c,d)&&h(),cd(u,o,s,n,l,c,a,p)&&h(),cd(u,o,s,n,l,c,d,p)&&h(),cu(u,o,s,n,a,d,l,p)&&h(),cu(u,o,s,n,a,d,c,p)&&h();for(let e=a;e<d;e++){let t=o.positionAt(e,l,s),r=o.positionAt(e,c,s);u.replace(u.mapping.slice(p).map(t+n),u.mapping.slice(p).map(r+n),new ix(i.rows[e-a],0,0))}h(),u.setSelection(new lG(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let ch=lL({ArrowLeft:cm("horiz",-1),ArrowRight:cm("horiz",1),ArrowUp:cm("vert",-1),ArrowDown:cm("vert",1),"Shift-ArrowLeft":cg("horiz",-1),"Shift-ArrowRight":cg("horiz",1),"Shift-ArrowUp":cg("vert",-1),"Shift-ArrowDown":cg("vert",1),Backspace:cl,"Mod-Backspace":cl,Delete:cl,"Mod-Delete":cl});function cf(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cm(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof lG)return cf(n,r,sL.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cv(i,e,t);if(null==o)return!1;if("horiz"==e)return cf(n,r,sL.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=lW(s,e,t);return i=a?sL.near(a,1):t<0?sL.near(n.doc.resolve(s.before(-1)),-1):sL.near(n.doc.resolve(s.after(-1)),1),cf(n,r,i)}}}function cg(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof lG)s=o;else{let r=cv(i,e,t);if(null==r)return!1;s=new lG(n.doc.resolve(r))}let a=lW(s.$headCell,e,t);return!!a&&cf(n,r,new lG(s.$anchorCell,a))}}function cb(e,t){let n=lB(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new lG(n))),!0)}function cx(e,t,n){if(!lF(e.state))return!1;let r=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;1==t.childCount&&(n>0&&r>0||"table"==t.child(0).type.spec.tableRole);)n--,r--,t=t.child(0).content;let i=t.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if("row"==s)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,s=e?0:Math.max(0,n-1),l=e<t.childCount-1?0:Math.max(0,r-1);(s||l)&&(i=cc(lz(o).row,new ix(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cc(lz(o).row,new ix(t,n,r)).content:t)}return function(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:s}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+s}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(iu.empty),n[i]<r){let s=lz(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iu.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof lG){r||(r={width:1,height:1,rows:[iu.from(cc(lz(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=lP.get(t).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=function({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let s=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let a=s.child(i%s.childCount);n+a.attrs.colspan>r&&(a=a.type.createChecked(lq(a.attrs,a.attrs.colspan,n+a.attrs.colspan-r),a.content)),o.push(a),n+=a.attrs.colspan;for(let n=1;n<a.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+a.attrs.colspan}i.push(iu.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,s=0;r<i;r++,s++){let o=[],a=n[s%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(iu.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cp(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=lH(e.state),n=t.start(-1);return cp(e.state,e.dispatch,n,lP.get(t.node(-1)).findCell(t.pos-n),r),!0}}function cy(e,t){var n;let r;if(0!=t.button||t.ctrlKey||t.metaKey)return;let i=cw(e,t.target);if(t.shiftKey&&e.state.selection instanceof lG)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=lB(e.state.selection.$anchor))&&(null==(n=ck(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=ck(e,n),i=null==l$.getState(e.state);if(!r||!lV(t,r))if(!i)return;else r=t;let s=new lG(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(l$,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=l$.getState(e.state)&&e.dispatch(e.state.tr.setMeta(l$,-1))}function a(n){let r,a=l$.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(cw(e,n.target)!=i&&!(r=ck(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cv(e,t,n){if(!(e.state.selection instanceof sB))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))break;if("cell"==s.type.spec.tableRole||"header_cell"==s.type.spec.tableRole){let s=r.before(i),o="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(o)?s:null}}return null}function cw(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function ck(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&lB(e.state.doc.resolve(r))||lB(e.state.doc.resolve(i))}var cN=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),cS(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,cS(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function cS(e,t,n,r,i,s){let o=0,a=!0,l=t.firstChild,c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){let{colspan:d,colwidth:u}=c.child(e).attrs;for(let e=0;e<d;e++,n++){let c=i==n?s:u&&u[e],d=c?c+"px":"";if(o+=c||r,c||(a=!1),l)l.style.width!=d&&(l.style.width=d),l=l.nextSibling;else{let e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;l;){var d;let e=l.nextSibling;null==(d=l.parentNode)||d.removeChild(l),l=e}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}let cC=new s3("tableColumnResizing");var cj=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(cC);if(n&&null!=n.setHandle)return new e(n.setHandle,!1);if(n&&void 0!==n.setDragging)return new e(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&t.docChanged){let n=t.mapping.map(this.activeHandle,-1);return lU(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function cE(e,t,n,r){let i=e.posAtCoords({left:t.clientX+("right"==n?-r:r),top:t.clientY});if(!i)return -1;let{pos:s}=i,o=lB(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=lP.get(o.node(-1)),l=o.start(-1),c=a.map.indexOf(o.pos-l);return c%a.width==0?-1:l+a.map[c-1]}function cM(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function cA(e,t){e.dispatch(e.state.tr.setMeta(cC,{setHandle:t}))}function cT(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=lP.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,l=e.domAtPos(i.start(-1)).node;for(;l&&"TABLE"!=l.nodeName;)l=l.parentNode;l&&cS(s,l.firstChild,l,r,a,n)}var cO=f,c_=e.i(3909);let cD=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function cR(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let cI=(e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);if(!i){let n=r.blockRange(),i=n&&sh(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(cJ(e,i,t,-1))return!0;if(0==r.parent.content.size&&(cP(s,"end")||sH.isSelectable(s)))for(let n=r.depth;;n--){let o=sN(e.doc,r.before(n),r.after(n),ix.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(cP(s,"end")?sL.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):sH.create(n.doc,i.pos-s.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||r.node(n-1).childCount>1)break}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0)};function cL(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let s=t.nodeAfter,o=t.pos+1;for(;!s.isTextblock;o++){if(s.type.spec.isolating)return!1;let e=s.firstChild;if(!e)return!1;s=e}let a=sN(e.doc,i,o,ix.empty);if(!a||a.from!=i||a instanceof sc&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(sB.create(t.doc,i)),n(t.scrollIntoView())}return!0}function cP(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)break}return!1}let cz=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;s=c$(r)}let o=s&&s.nodeBefore;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function c$(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}function cB(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let cF=(e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);if(!i)return!1;let s=i.nodeAfter;if(cJ(e,i,t,1))return!0;if(0==r.parent.content.size&&(cP(s,"start")||sH.isSelectable(s))){let n=sN(e.doc,r.before(),r.after(),ix.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(cP(s,"start")?sL.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):sH.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0)},cH=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;s=cU(r)}let o=s&&s.nodeAfter;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos)).scrollIntoView()),!0)};function cU(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}let cV=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!!n.parent.type.spec.code&&!!n.sameParent(r)&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function cW(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}let cq=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),o=cW(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(sL.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},cK=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof sV||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=cW(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,s.createAndFill());o.setSelection(sB.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},cG=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(sx(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&sh(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function cJ(e,t,n,r){let i,s,o,a=t.nodeBefore,l=t.nodeAfter,c,d,u=a.type.spec.isolating||l.type.spec.isolating;if(!u&&(i=t.nodeBefore,s=t.nodeAfter,o=t.index(),i&&s&&i.type.compatibleContent(s.type)&&(!i.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-i.nodeSize,t.pos).scrollIntoView()),!0):!!t.parent.canReplace(o,o+1)&&!!(s.isTextblock||sy(e.doc,t.pos))&&(n&&n(e.tr.join(t.pos).scrollIntoView()),!0))))return!0;let p=!u&&t.parent.canReplace(t.index(),t.index()+1);if(p&&(c=(d=a.contentMatchAt(a.childCount)).findWrapping(l.type))&&d.matchType(c[0]||l.type).validEnd){if(n){let r=t.pos+l.nodeSize,i=iu.empty;for(let e=c.length-1;e>=0;e--)i=iu.from(c[e].create(null,i));i=iu.from(a.copy(i));let s=e.tr.step(new sd(t.pos-1,r,t.pos,r,new ix(i,1,0),c.length,!0)),o=s.doc.resolve(r+2*c.length);o.nodeAfter&&o.nodeAfter.type==a.type&&sy(s.doc,o.pos)&&s.join(o.pos),n(s.scrollIntoView())}return!0}let h=l.type.spec.isolating||r>0&&u?null:sL.findFrom(t,1),f=h&&h.$from.blockRange(h.$to),m=f&&sh(f);if(null!=m&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(p&&cP(l,"start",!0)&&cP(a,"end")){let r=a,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let s=l,o=1;for(;!s.isTextblock;s=s.firstChild)o++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=iu.empty;for(let e=i.length-1;e>=0;e--)r=iu.from(i[e].copy(r));n(e.tr.step(new sd(t.pos-i.length,t.pos+l.nodeSize,t.pos+o,t.pos+l.nodeSize-o,new ix(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function cZ(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return!!i.node(s).isTextblock&&(n&&n(t.tr.setSelection(sB.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let cX=cZ(-1),cY=cZ(1);function cQ(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(s,o,(r,s)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(s),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(s,o,e,t)}r(i.scrollIntoView())}return!0}}function c0(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}let c1=c0(cD,cI,cz),c2=c0(cD,cF,cH),c3={Enter:c0(cV,cK,cG,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof sH&&e.selection.node.isBlock)return!!n.parentOffset&&!!sx(e.doc,n.pos)&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let i=[],s,o,a=!1,l=!1;for(let e=n.depth;;e--){if(n.node(e).isBlock){let t;a=n.end(e)==n.pos+(n.depth-e),l=n.start(e)==n.pos-(n.depth-e),o=cW(n.node(e-1).contentMatchAt(n.indexAfter(e-1)));i.unshift(t||(a&&o?{type:o}:null)),s=e;break}if(1==e)return!1;i.unshift(null)}let c=e.tr;(e.selection instanceof sB||e.selection instanceof sV)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=sx(c.doc,d,i.length,i);if(u||(i[0]=o?{type:o}:null,u=sx(c.doc,d,i.length,i)),!u)return!1;if(c.split(d,i.length,i),!a&&l&&n.node(s).type!=o){let e=c.mapping.map(n.before(s)),t=c.doc.resolve(e);o&&n.node(s-1).canReplaceWith(t.index(),t.index()+1,o)&&c.setNodeMarkup(c.mapping.map(n.before(s)),o)}return t&&t(c.scrollIntoView()),!0}),"Mod-Enter":cq,Backspace:c1,"Mod-Backspace":c1,"Shift-Backspace":c1,Delete:c2,"Mod-Delete":c2,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new sV(e.doc))),!0)},c5={"Ctrl-h":c3.Backspace,"Alt-Backspace":c3["Mod-Backspace"],"Ctrl-d":c3.Delete,"Ctrl-Alt-Backspace":c3["Mod-Delete"],"Alt-Delete":c3["Mod-Delete"],"Alt-d":c3["Mod-Delete"],"Ctrl-a":cX,"Ctrl-e":cY};for(let e in c3)c5[e]=c3[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var c4=Object.defineProperty,c6=(e,t)=>{for(var n in t)c4(e,n,{get:t[n],enumerable:!0})};function c9(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}var c7=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(s);return i.getMeta("preventDispatch")||this.hasCustomState||r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o=[],a=!!e,l=e||i.tr,c=()=>(a||!t||l.getMeta("preventDispatch")||this.hasCustomState||s.dispatch(l),o.every(e=>!0===e)),d={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(l,t),i=n(...e)(r);return o.push(i),d}])),run:c};return d}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o={tr:e,editor:r,view:s,state:c9({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},c8={};c6(c8,{blur:()=>de,clearContent:()=>dt,clearNodes:()=>dn,command:()=>dr,createParagraphNear:()=>di,cut:()=>ds,deleteCurrentNode:()=>da,deleteNode:()=>dc,deleteRange:()=>dd,deleteSelection:()=>dp,enter:()=>dh,exitCode:()=>df,extendMarkRange:()=>dw,first:()=>dk,focus:()=>dM,forEach:()=>dA,insertContent:()=>dT,insertContentAt:()=>dR,joinBackward:()=>dP,joinDown:()=>dL,joinForward:()=>dz,joinItemBackward:()=>d$,joinItemForward:()=>dB,joinTextblockBackward:()=>dF,joinTextblockForward:()=>dH,joinUp:()=>dI,keyboardShortcut:()=>dV,lift:()=>dq,liftEmptyBlock:()=>dK,liftListItem:()=>dG,newlineInCode:()=>dJ,resetAttributes:()=>dY,scrollIntoView:()=>dQ,selectAll:()=>d0,selectNodeBackward:()=>d1,selectNodeForward:()=>d2,selectParentNode:()=>d3,selectTextblockEnd:()=>d5,selectTextblockStart:()=>d4,setContent:()=>d9,setMark:()=>uI,setMeta:()=>uL,setNode:()=>uP,setNodeSelection:()=>uz,setTextDirection:()=>u$,setTextSelection:()=>uB,sinkListItem:()=>uF,splitBlock:()=>uU,splitListItem:()=>uV,toggleList:()=>uK,toggleMark:()=>uG,toggleNode:()=>uJ,toggleWrap:()=>uZ,undoInputRule:()=>uX,unsetAllMarks:()=>uY,unsetMark:()=>uQ,unsetTextDirection:()=>u0,updateAttributes:()=>u1,wrapIn:()=>u2,wrapInList:()=>u3});var de=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dt=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dn=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return!n||(i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,s=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),a=s.blockRange(o);if(!a)return;let l=sh(a);if(e.type.isTextblock){let{defaultType:e}=s.parent.contentMatchAt(s.index());t.setNodeMarkup(a.start,e)}(l||0===l)&&t.lift(a,l)})}),!0)},dr=e=>t=>e(t),di=()=>({state:e,dispatch:t})=>cK(e,t),ds=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,s=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,s.content),r.setSelection(new sB(r.doc.resolve(Math.max(o-1,0)))),!0},da=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;n-=1)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function dl(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var dc=e=>({tr:t,state:n,dispatch:r})=>{let i=dl(e,n.schema),s=t.selection.$anchor;for(let e=s.depth;e>0;e-=1)if(s.node(e).type===i){if(r){let n=s.before(e),r=s.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},dd=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},du=(e,t,n)=>{var r;return!e.parent.isInline||"left"===n&&e.pos>e.start()||"right"===n&&e.pos<e.end()?e.pos:(r=t.nodes[e.parent.type.name].spec).content&&/^text(\*|\+)/.test(r.content)?"left"===n?e.start()-1:e.end()+1:e.pos},dp=()=>({state:e,dispatch:t})=>{var n;let{$from:r,$to:i}=e.selection;if(e.selection.empty)return!1;let{from:s,to:o}={from:du(r,n=e.schema,"left"),to:du(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dh=()=>({commands:e})=>e.keyboardShortcut("Enter"),df=()=>({state:e,dispatch:t})=>cq(e,t);function dm(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dg(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dm(t[r])?t[r].test(e[r]):t[r]===e[r])}function db(e,t,n={}){return e.find(e=>e.type===t&&dg(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dx(e,t,n={}){return!!db(e,t,n)}function dy(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!db([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,o=i+1,a=s+r.node.nodeSize;for(;i>0&&dx([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&dx([...e.parent.child(o).marks],t,n);)a+=e.parent.child(o).nodeSize,o+=1;return{from:s,to:a}}function dv(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var dw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dv(e,r.schema),{doc:o,selection:a}=n,{$from:l,from:c,to:d}=a;if(i){let e=dy(l,s,t);if(e&&e.from<=c&&e.to>=d){let t=sB.create(o,e.from,e.to);n.setSelection(t)}}return!0},dk=e=>t=>{let n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function dN(e){return e instanceof sB}function dS(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function dC(e,t=null){if(!t)return null;let n=sL.atStart(e),r=sL.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?sB.create(e,dS(0,i,s),dS(e.content.size,i,s)):sB.create(e,dS(t,i,s),dS(t,i,s))}function dj(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function dE(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var dM=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(dE()||dj())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!dE()&&!dj()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{!n.isDestroyed&&(r.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&null===e||!1===e)return!0}catch{return!1}if(s&&null===e&&!dN(n.state.selection))return o(),!0;let a=dC(i.doc,e)||n.state.selection,l=n.state.selection.eq(a);return s&&(l||i.setSelection(a),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},dA=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),dT=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),dO=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){let r=t[n];3===r.nodeType&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):1===r.nodeType&&dO(r)}return e};function d_(e){if("u"<typeof window)throw Error("[tiptap error]: there is no window object available, so this function cannot be used");let t=`<body>${e}</body>`;return dO(new window.DOMParser().parseFromString(t,"text/html").body)}function dD(e,t,n){if(e instanceof iO||e instanceof iu)return e;n={slice:!0,parseOptions:{},...n};let r="object"==typeof e&&null!==e,i="string"==typeof e;if(r)try{if(Array.isArray(e)&&e.length>0)return iu.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error("[tiptap error]: Invalid JSON content",{cause:r});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),dD("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new iq({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(r=!0,i="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?iG.fromSchema(s).parseSlice(d_(e),n.parseOptions):iG.fromSchema(s).parse(d_(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=iG.fromSchema(t);return n.slice?r.parseSlice(d_(e),n.parseOptions).content:r.parse(d_(e),n.parseOptions)}return dD("",t,n)}var dR=(e,t,n)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){let i,a;n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l=e=>{s.emit("contentError",{editor:s,error:e,disableCollaboration:()=>{"collaboration"in s.storage&&"object"==typeof s.storage.collaboration&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:null!=(o=n.errorOnInvalidContent)?o:s.options.enableContentCheck})}catch(e){return l(e),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},p=!0,h=!0;if((!("type"in i)?i:[i]).forEach(e=>{e.check(),p=!!p&&e.isText&&0===e.marks.length,h=!!h&&e.isBlock}),d===u&&h){let{parent:e}=r.doc.resolve(d);!e.isTextblock||e.type.spec.code||e.childCount||(d-=1,u+=1)}if(p){if(Array.isArray(t))a=t.map(e=>e.text||"").join("");else if(t instanceof iu){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),a=e}else a="object"==typeof t&&t&&t.text?t.text:t;r.insertText(a,d,u)}else{a=i;let e=r.doc.resolve(d),t=e.node(),n=0===e.parentOffset,s=t.isText||t.isTextblock,o=t.content.size>0;n&&s&&o&&h&&(d=Math.max(0,d-1)),r.replaceWith(d,u,a)}n.updateSelection&&function(e,t){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof sc||r instanceof sd))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(sL.near(e.doc.resolve(s),-1))}(r,r.steps.length-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:a}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:a})}return!0},dI=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof sH,i;if(r){if(n.node.isTextblock||!sy(e.doc,n.from))return!1;i=n.from}else if(null==(i=sw(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(sH.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),dL=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof sH){if(n.node.isTextblock||!sy(e.doc,n.to))return!1;r=n.to}else if(null==(r=sw(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),dP=()=>({state:e,dispatch:t})=>cI(e,t),dz=()=>({state:e,dispatch:t})=>cF(e,t),d$=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dB=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dF=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);return!!i&&cL(e,i,t)})(e,t),dH=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);return!!i&&cL(e,i,t)})(e,t);function dU(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var dV=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let s=(function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"===o&&(o=" ");for(let e=0;e<s.length-1;e+=1){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))dE()||dU()?i=!0:n=!0;else throw Error(`Unrecognized modifier name: ${o}`)}return t&&(o=`Alt-${o}`),n&&(o=`Ctrl-${o}`),i&&(o=`Meta-${o}`),r&&(o=`Shift-${o}`),o})(e).split(/-(?!$)/),o=s.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),a=new KeyboardEvent("keydown",{key:"Space"===o?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,a))});return null==l||l.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function dW(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dl(t,e.schema):null,a=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),s=Math.min(i,t+e.nodeSize);a.push({node:e,from:n,to:s})});let l=i-r,c=a.filter(e=>!o||o.name===e.node.type.name).filter(e=>dg(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var dq=(e,t={})=>({state:n,dispatch:r})=>{let i=dl(e,n.schema);return!!dW(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sh(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},dK=()=>({state:e,dispatch:t})=>cG(e,t),dG=e=>({state:t,dispatch:n})=>{var r;return(r=dl(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);return!!s&&(!t||(n.node(s.depth-1).type==r?function(e,t,n,r){let i=e.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new sd(s-1,o,s,o,new ix(iu.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new iA(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sh(r);if(null==a)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(s,-1)-1);return sy(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),t(i.scrollIntoView()),!0}(e,t,r,s):function(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,s=n.startIndex;t>s;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let s=r.doc.resolve(n.start),o=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=s.node(-1),d=s.index(-1);if(!c.canReplace(d+ +!a,d+1,o.content.append(l?iu.empty:iu.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sd(u-!!a,p+ +!!l,u+1,p-1,new ix((a?iu.empty:iu.from(i.copy(iu.empty))).append(l?iu.empty:iu.from(i.copy(iu.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},dJ=()=>({state:e,dispatch:t})=>cV(e,t);function dZ(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function dX(e,t){let n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var dY=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,dX(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(s=>{o===s.type&&(l=!0,i&&n.addMark(r,r+e.nodeSize,o.create(dX(s.attrs,t))))})})}),l},dQ=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),d0=()=>({tr:e,dispatch:t})=>{if(t){let t=new sV(e.doc);e.setSelection(t)}return!0},d1=()=>({state:e,dispatch:t})=>cz(e,t),d2=()=>({state:e,dispatch:t})=>cH(e,t),d3=()=>({state:e,dispatch:t})=>((e,t)=>{let{$from:n,to:r}=e.selection,i,s=n.sharedDepth(r);return 0!=s&&(i=n.before(s),t&&t(e.tr.setSelection(sH.create(e.doc,i))),!0)})(e,t),d5=()=>({state:e,dispatch:t})=>cY(e,t),d4=()=>({state:e,dispatch:t})=>cX(e,t);function d6(e,t,n={},r={}){return dD(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var d9=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:s,dispatch:o,commands:a})=>{let{doc:l}=s;if("full"!==r.preserveWhitespace){let a=d6(e,i.schema,r,{errorOnInvalidContent:null!=t?t:i.options.enableContentCheck});return o&&s.replaceWith(0,l.content.size,a).setMeta("preventUpdate",!n),!0}return o&&s.setMeta("preventUpdate",!n),a.insertContentAt({from:0,to:l.content.size},e,{parseOptions:r,errorOnInvalidContent:null!=t?t:i.options.enableContentCheck})};function d7(e,t){let n=dv(t,e.schema),{from:r,to:i,empty:s}=e.selection,o=[];s?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let a=o.find(e=>e.type.name===n.name);return a?{...a.attrs}:{}}function d8(e,t){let n=new sR(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function ue(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function ut(e,t){for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function un(e){return t=>ut(t.$from,e)}function ur(e,t,n){return void 0===e.config[t]&&e.parent?ur(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?ur(e.parent,t,n):null}):e.config[t]}function ui(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=ur(e,"addExtensions",t);return n?[e,...ui(n())]:e}).flat(10)}function us(e,t){let n=i3.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uo(e){return"function"==typeof e}function ua(e,t,...n){return uo(e)?t?e.bind(t)(...n):e(...n):e}function ul(e){let t=e.filter(e=>"extension"===e.type);return{baseExtensions:t,nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function uc(e){let t=[],{nodeExtensions:n,markExtensions:r}=ul(e),i=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>"text"!==e.name).map(e=>e.name),a=r.map(e=>e.name),l=[...o,...a];return e.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage,extensions:i},r=ur(e,"addGlobalAttributes",n);r&&r().forEach(e=>{(Array.isArray(e.types)?e.types:"*"===e.types?l:"nodes"===e.types?o:"marks"===e.types?a:[]).forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...s,...r}})})})})}),i.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage},r=ur(e,"addAttributes",n);r&&Object.entries(r()).forEach(([n,r])=>{let i={...s,...r};"function"==typeof(null==i?void 0:i.default)&&(i.default=i.default()),(null==i?void 0:i.isRequired)&&(null==i?void 0:i.default)===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function ud(e){let t=[],n=function(e){let t=[],n="",r=!1,i=!1,s=0,o=e.length;for(let a=0;a<o;a+=1){let o=e[a];if("'"===o&&!i){r=!r,n+=o;continue}if('"'===o&&!r){i=!i,n+=o;continue}if(!r&&!i){if("("===o){s+=1,n+=o;continue}if(")"===o&&s>0){s-=1,n+=o;continue}if(";"===o&&0===s){t.push(n),n="";continue}}n+=o}return n&&t.push(n),t}(e||""),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(":");if(-1===i)continue;let s=r.slice(0,i).trim(),o=r.slice(i+1).trim();s&&o&&t.push([s,o])}return t}function uu(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if("class"===e){let r=t?String(t).split(" "):[],i=n[e]?n[e].split(" "):[],s=r.filter(e=>!i.includes(e));n[e]=[...i,...s].join(" ")}else if("style"===e){let r=new Map([...ud(n[e]),...ud(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function up(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>uu(e,t),{})}function uh(e,t){return"style"in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===r)return!1;let i=t.reduce((e,t)=>{var r;let i=t.attribute.parseHTML?t.attribute.parseHTML(n):"string"!=typeof(r=n.getAttribute(t.name))?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):"true"===r||"false"!==r&&r;return null==i?e:{...e,[t.name]:i}},{});return{...r,...i}}}}function uf(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>!("attrs"===e&&function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function um(e){var t,n;let r={};return!(null==(t=null==e?void 0:e.attribute)?void 0:t.isRequired)&&"default"in((null==e?void 0:e.attribute)||{})&&(r.default=e.attribute.default),(null==(n=null==e?void 0:e.attribute)?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function ug(e){return e.sort((e,t)=>{let n=ur(e,"priority")||100,r=ur(t,"priority")||100;return n>r?-1:+(n<r)})}function ub(e){var t;let n=ug(ui(e)),r=Array.from(new Set((t=n.map(e=>e.name)).filter((e,n)=>t.indexOf(e)!==n)));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(e=>`'${e}'`).join(", ")}]. This can lead to issues.`),n}function ux(e,t,n){let{from:r,to:i}=t,{blockSeparator:s="\n\n",textSerializers:o={}}=n||{},a="";return e.nodesBetween(r,i,(e,n,l,c)=>{var d;e.isBlock&&n>r&&(a+=s);let u=null==o?void 0:o[e.type.name];if(u)return l&&(a+=u({node:e,pos:n,parent:l,index:c,range:t})),!1;e.isText&&(a+=null==(d=null==e?void 0:e.text)?void 0:d.slice(Math.max(r,n)-n,i-n))}),a}function uy(e,t){let n={from:0,to:e.content.size};return ux(e,n,t)}function uv(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function uw(e,t){let n=dZ("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dl(t,e.schema),{from:r,to:i}=e.selection,s=[];e.doc.nodesBetween(r,i,e=>{s.push(e)});let o=s.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}(e,t):"mark"===n?d7(e,t):{}}function uk(e){let t,{mapping:n,steps:r}=e,i=[];return n.maps.forEach((e,t)=>{let s=[];if(e.ranges.length)e.forEach((e,t)=>{s.push({from:e,to:t})});else{let{from:e,to:n}=r[t];if(void 0===e||void 0===n)return;s.push({from:e,to:n})}s.forEach(({from:e,to:r})=>{let s=n.slice(t).map(e,-1),o=n.slice(t).map(r),a=n.invert().map(s,-1),l=n.invert().map(o);i.push({oldRange:{from:a,to:l},newRange:{from:s,to:o}})})}),1===(t=function(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return!Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=!0)})}(i)).length?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function uN(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=dy(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&(null==e?void 0:e.nodeSize)!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}function uS(e,t){return t.nodes[e]||t.marks[e]||null}function uC(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return!!r&&r.attribute.keepOnSplit}))}function uj(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dv(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dg(e.attrs,n,{strict:!1}));let o=0,a=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(s&&e.inlineContent&&!e.type.allowsMarkType(s))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),l=Math.min(i,t+e.nodeSize);o+=l-n,a.push(...e.marks.map(e=>({mark:e,from:n,to:l})))})}),0===o)return!1;let l=a.filter(e=>!s||s.name===e.mark.type.name).filter(e=>dg(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=a.filter(e=>!s||e.mark.type!==s&&e.mark.type.excludes(s)).reduce((e,t)=>e+t.to-t.from,0);return(l>0?l+c:l)>=o}function uE(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function uM(e,t){let{nodeExtensions:n}=ul(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=ua(ur(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function uA(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return!/\S/.test(null!=(r=e.text)?r:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let r=!0;return e.content.forEach(e=>{!1!==r&&(uA(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function uT(e){return e instanceof sH}var uO=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function u_(e,t){let n=t.mapping.mapResult(e.position);return{position:new uO(n.pos),mapResult:n}}function uD(e){return new uO(e)}function uR(e,t,n){let r=e.state.doc.content.size,i=dS(t,0,r),s=dS(n,0,r),o=e.coordsAtPos(i),a=e.coordsAtPos(s,-1),l=Math.min(o.top,a.top),c=Math.max(o.bottom,a.bottom),d=Math.min(o.left,a.left),u=Math.max(o.right,a.right),p={top:l,bottom:c,left:d,right:u,width:u-d,height:c-l,x:d,y:l};return{...p,toJSON:()=>p}}var uI=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dv(e,r.schema);if(i)if(o){let e=d7(r,l);n.addStoredMark(l.create({...e,...t}))}else a.forEach(e=>{let i=e.$from.pos,s=e.$to.pos;r.doc.nodesBetween(i,s,(e,r)=>{let o=Math.max(r,i),a=Math.min(r+e.nodeSize,s);e.marks.find(e=>e.type===l)?e.marks.forEach(e=>{l===e.type&&n.addMark(o,a,l.create({...e.attrs,...t}))}):n.addMark(o,a,l.create(t))})});return function(e,t,n){var r;let{selection:i}=t,s=null;if(dN(i)&&(s=i.$cursor),s){let t=null!=(r=e.storedMarks)?r:s.marks();return s.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:o}=i;return o.some(({$from:t,$to:r})=>{let i=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),s=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&s}return!i}),i})}(r,n,l)},uL=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),uP=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dl(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!cQ(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>cQ(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},uz=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=dS(e,0,n.content.size),i=sH.create(n,r);t.setSelection(i)}return!0},u$=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s,o,{selection:a}=r;return"number"==typeof t?(s=t,o=t):t&&"from"in t&&"to"in t?(s=t.from,o=t.to):(s=a.from,o=a.to),i&&n.doc.nodesBetween(s,o,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},uB=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=sB.atStart(n).from,o=sB.atEnd(n).to,a=dS(r,s,o),l=dS(i,s,o),c=sB.create(n,a,l);t.setSelection(c)}return!0},uF=e=>({state:t,dispatch:n})=>{var r;return(r=dl(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(0==o)return!1;let a=s.parent,l=a.child(o-1);if(l.type!=r)return!1;if(t){let n=l.lastChild&&l.lastChild.type==a.type,i=iu.from(n?r.create():null),o=new ix(iu.from(r.create(null,iu.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sd(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function uH(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(r)}}var uU=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=uC(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof sH&&s.node.isBlock)return!!a.parentOffset&&!!sx(o,a.pos)&&(r&&(e&&uH(n,i.extensionManager.splittableMarks),t.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;let d=l.parentOffset===l.parent.content.size,u=0===a.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(a.node(-1).contentMatchAt(a.indexAfter(-1))),p=d&&u?[{type:u,attrs:c}]:void 0,h=sx(t.doc,t.mapping.map(a.pos),1,p);if(!p&&!h&&sx(t.doc,t.mapping.map(a.pos),1,u?[{type:u}]:void 0)&&(h=!0,p=u?[{type:u,attrs:c}]:void 0),r){if(h&&(s instanceof sB&&t.deleteSelection(),t.split(t.mapping.map(a.pos),1,p),u&&!d&&!a.parentOffset&&a.parent.type!==u)){let e=t.mapping.map(a.before()),n=t.doc.resolve(e);a.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(a.before()),u)}e&&uH(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},uV=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dl(e,r.schema),{$from:l,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||l.depth<2||!l.sameParent(c))return!1;let u=l.node(-1);if(u.type!==a)return!1;let p=s.extensionManager.attributes;if(0===l.parent.content.size&&l.node(-1).childCount===l.indexAfter(-1)){if(2===l.depth||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(i){let e=iu.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iu.from(l.node(t).copy(e));let i=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,s={...uC(p,l.node().type.name,l.node().attrs),...t},c=(null==(o=a.contentMatch.defaultType)?void 0:o.createAndFill(s))||void 0;e=e.append(iu.from(a.createAndFill(null,c)||void 0));let d=l.before(l.depth-(r-1));n.replace(d,l.after(-i),new ix(e,4-r,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(sB.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,f={...uC(p,u.type.name,u.attrs),...t},m={...uC(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:f},{type:h,attrs:m}]:[{type:a,attrs:f}];if(!sx(n.doc,l.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=s.extensionManager,a=t||e.$to.parentOffset&&e.$from.marks();if(n.split(l.pos,2,g).scrollIntoView(),!a||!i)return!0;let c=a.filter(e=>o.includes(e.type.name));n.ensureMarks(c)}return!0},uW=(e,t)=>{let n=un(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sy(e.doc,n.pos))||(e.join(n.pos),!0)},uq=(e,t)=>{let n=un(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sy(e.doc,r))||(e.join(r),!0)},uK=(e,t,n,r={})=>({editor:i,tr:s,state:o,dispatch:a,chain:l,commands:c,can:d})=>{let{extensions:u,splittableMarks:p}=i.extensionManager,h=dl(e,o.schema),f=dl(t,o.schema),{selection:m,storedMarks:g}=o,{$from:b,$to:x}=m,y=b.blockRange(x),v=g||m.$to.parentOffset&&m.$from.marks();if(!y)return!1;let w=un(e=>uM(e.type.name,u))(m),k=0===m.from&&m.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&uM(S.type.name,u)?{node:S,pos:0,depth:0}:null,j=null!=w?w:C,E=!!w&&y.depth>=1&&y.depth-w.depth<=1,M=!!C;if((E||M)&&j){if(j.node.type===h)return k&&M?l().command(({tr:e,dispatch:t})=>{let n=function(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return sB.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(f).run():c.liftListItem(f);if(uM(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>uW(s,h)).command(()=>uq(s,h)).run()}return n&&v&&a?l().command(()=>{let e=d().wrapInList(h,r),t=v.filter(e=>p.includes(e.type.name));return s.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run()},uG=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dv(e,r.schema);return uj(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},uJ=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dl(e,r.schema),a=dl(t,r.schema),l=dW(r,o,n);return(r.selection.$anchor.sameParent(r.selection.$head)&&(s=r.selection.$anchor.parent.attrs),l)?i.setNode(a,s):i.setNode(o,{...s,...n})},uZ=(e,t={})=>({state:n,commands:r})=>{let i=dl(e,n.schema);return dW(n,i,t)?r.lift(i):r.wrapIn(i,t)},uX=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i,s=n[r];if(s.spec.isInputRules&&(i=s.getState(e))){if(t){let t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){let n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},uY=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return!!r||(t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0)},uQ=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dv(e,r.schema),{$from:c,empty:d,ranges:u}=a;if(!i)return!0;if(d&&o){let{from:e,to:t}=a,r=null==(s=c.marks().find(e=>e.type===l))?void 0:s.attrs,i=dy(c,l,r);i&&(e=i.from,t=i.to),n.removeMark(e,t,l)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,l)});return n.removeStoredMark(l),!0},u0=e=>({tr:t,state:n,dispatch:r})=>{let i,s,{selection:o}=n;return"number"==typeof e?(i=e,s=e):e&&"from"in e&&"to"in e?(i=e.from,s=e.to):(i=o.from,s=o.to),r&&t.doc.nodesBetween(i,s,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},u1=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{let a,c,d,u,p=e.$from.pos,h=e.$to.pos;n.selection.empty?r.doc.nodesBetween(p,h,(e,t)=>{s&&s===e.type&&(l=!0,d=Math.max(t,p),u=Math.min(t+e.nodeSize,h),a=t,c=e)}):r.doc.nodesBetween(p,h,(e,r)=>{r<p&&s&&s===e.type&&(l=!0,d=Math.max(r,p),u=Math.min(r+e.nodeSize,h),a=r,c=e),r>=p&&r<=h&&(s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(s=>{if(o===s.type&&(l=!0,i)){let i=Math.max(r,p),a=Math.min(r+e.nodeSize,h);n.addMark(i,a,o.create({...s.attrs,...t}))}}))}),c&&(void 0!==a&&i&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),o&&c.marks.length&&c.marks.forEach(e=>{o===e.type&&i&&n.addMark(d,u,o.create({...e.attrs,...t}))}))}),l},u2=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s),a=o&&sf(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u3=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s);if(!o)return!1;let a=r?n.tr:null;return!!function(e,t,n,r=null){let i=!1,s=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=o.resolve(t.start-2);s=new iA(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new iA(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sf(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iu.empty;for(let e=n.length-1;e>=0;e--)s=iu.from(n[e].type.create(n[e].attrs,s));e.step(new sd(t.start-2*!!r,t.end,t.start,t.end,new ix(s,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let a=n.length-o,l=t.start+n.length-2*!!r,c=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&sx(e.doc,l,a)&&(e.split(l,a),l+=2*a),l+=c.child(n).nodeSize}(e,t,a,i,n),!0)}(a,o,e,t)&&(r&&r(a.scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u5=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},u4=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function u6(e){var t;let{editor:n,from:r,to:i,text:s,rules:o,plugin:a}=e,{view:l}=n;if(l.composing)return!1;let c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(null==(t=c.nodeBefore||c.nodeAfter)?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1,u=((e,t=500)=>{let n="",r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,s)=>{var o,a;let l=(null==(a=(o=e.type.spec).toText)?void 0:a.call(o,{node:e,pos:t,parent:i,index:s}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?l:l.slice(0,Math.max(0,r-t))}),n})(c)+s;return o.forEach(e=>{if(d)return;let t=((e,t)=>{if(dm(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r})(u,e.find);if(!t)return;let o=l.state.tr,c=c9({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:f,can:m}=new c7({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:f,can:m})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function u9(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var u7=class{constructor(e={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...ua(ur(this,"addOptions",{name:this.name}))}}get storage(){return{...ua(ur(this,"addStorage",{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>(function e(t,n){let r={...t};return u9(t)&&u9(n)&&Object.keys(n).forEach(i=>{u9(n[i])&&u9(t[i])?r[i]=e(t[i],n[i]):r[i]=n[i]}),r})(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name="name"in e?e.name:t.parent.name,t}},u8=class e extends u7{constructor(){super(...arguments),this.type="mark"}static create(t={}){return new e("function"==typeof t?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;let s=i.find(e=>(null==e?void 0:e.type.name)===t.name);return s&&n.removeStoredMark(s),n.insertText(" ",r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pe=class{constructor(e){this.find=e.find,this.handler=e.handler}},pt=null,pn=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=ub(e),this.schema=function(e,t){var n;let r=uc(e),{nodeExtensions:i,markExtensions:s}=ul(e),o=null==(n=i.find(e=>ur(e,"topNode")))?void 0:n.name;return new iq({topNode:o,nodes:Object.fromEntries(i.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uf({...e.reduce((e,t)=>{let r=ur(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:ua(ur(n,"content",s)),marks:ua(ur(n,"marks",s)),group:ua(ur(n,"group",s)),inline:ua(ur(n,"inline",s)),atom:ua(ur(n,"atom",s)),selectable:ua(ur(n,"selectable",s)),draggable:ua(ur(n,"draggable",s)),code:ua(ur(n,"code",s)),whitespace:ua(ur(n,"whitespace",s)),linebreakReplacement:ua(ur(n,"linebreakReplacement",s)),defining:ua(ur(n,"defining",s)),isolating:ua(ur(n,"isolating",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:up(e,i)}));let c=ur(n,"renderText",s);return c&&(o.toText=c),[n.name,o]})),marks:Object.fromEntries(s.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uf({...e.reduce((e,t)=>{let r=ur(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:ua(ur(n,"inclusive",s)),excludes:ua(ur(n,"excludes",s)),group:ua(ur(n,"group",s)),spanning:ua(ur(n,"spanning",s)),code:ua(ur(n,"code",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:up(e,i)})),[n.name,o]}))})}(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:uS(t.name,this.schema)},r=ur(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return ug([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:uS(t.name,this.schema)},r=[],i=ur(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&ur(t,"exitable",n)&&(s.ArrowRight=()=>u8.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));s={...s,...t}}let o=new s0({props:{handleKeyDown:lL(s)}});r.push(o);let a=ur(t,"addInputRules",n);if(uE(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new s0({state:{init:()=>null,apply(e,i,s){let o=e.getMeta(r);if(o)return o;let a=e.getMeta("applyInputRules");return a&&setTimeout(()=>{let{text:e}=a;"string"==typeof e||(e=us(iu.from(e),s.schema));let{from:i}=a,o=i+e.length;u6({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>u6({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&u6({editor:t,from:i.pos,to:i.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if("Enter"!==i.key)return!1;let{$cursor:s}=e.state.selection;return!!s&&u6({editor:t,from:s.pos,to:s.pos,text:"\n",rules:n,plugin:r})}},isInputRules:!0});return r}({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let l=ur(t,"addPasteRules",n);if(uE(t,e.options.enablePasteRules)&&l){let t=l();if(t&&t.length){let n=function(e){let t,{editor:n,rules:r}=e,i=null,s=!1,o=!1,a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}let l=({state:e,from:r,to:i,rule:s,pasteEvt:o})=>{let l=e.tr;if(function(e){let{editor:t,state:n,from:r,to:i,rule:s,pasteEvent:o,dropEvent:a}=e,{commands:l,chain:c,can:d}=new c7({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,f,m,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let b=null!=(g=null!=(m=null==(f=e.content)?void 0:f.size)?m:e.nodeSize)?g:0,x=Math.max(r,t),y=Math.min(i,t+b);x>=y||((e,t,n)=>{if(dm(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),n.push(t.replaceWith)),n}):[]})(e.isText?e.text||"":e.textBetween(x-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=x+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},p=s.handler({state:n,range:i,match:e,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});u.push(p)})}),u.every(e=>null!==e)}({editor:n,state:c9({state:e,transaction:l}),from:Math.max(r-1,0),to:i.b-1,rule:s,pasteEvent:o,dropEvent:t})&&l.steps.length){try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}return a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null,l}};return r.map(e=>new s0({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pt=n)},r=()=>{pt&&(pt=null)};return window.addEventListener("dragstart",t),window.addEventListener("dragend",r),{destroy(){window.removeEventListener("dragstart",t),window.removeEventListener("dragend",r)}}},props:{handleDOMEvents:{drop:(e,n)=>{if(o=i===e.dom.parentElement,t=n,!o){let e=pt;(null==e?void 0:e.isEditable)&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;let r=null==(n=t.clipboardData)?void 0:n.getData("text/html");return a=t,s=!!(null==r?void 0:r.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,r)=>{let i=t[0],c="paste"===i.getMeta("uiEvent")&&!s,d="drop"===i.getMeta("uiEvent")&&!o,u=i.getMeta("applyPasteRules"),p=!!u;if(!c&&!d&&!p)return;if(p){var h,f;let t,{text:n}=u;"string"==typeof n||(n=us(iu.from(n),r.schema));let{from:i}=u,s=i+n.length;return l({rule:e,state:r,from:i,to:{b:s},pasteEvt:(h=n,null==(f=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||f.setData("text/html",h),t)})}let m=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof m&&g&&m!==g.b)return l({rule:e,state:r,from:m,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=ur(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uc(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(e,"addNodeView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dl(t.name,this.schema)},i=ur(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=up(r,n);return s({node:r,view:i,getPos:o,decorations:a,innerDecorations:l,editor:e,extension:t,HTMLAttributes:c})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return ug([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return ug([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"transformPastedHTML",r);return i?(t,n)=>{let s=e(t,n);return i.call(r,s)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(e,"addMarkView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dv(t.name,this.schema)},i=ur(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=up(r,n);return i()({mark:r,view:s,inline:o,editor:e,extension:t,HTMLAttributes:a,updateAttributes:t=>{!function(e,t,n={}){let{state:r}=t,{doc:i,tr:s}=r;i.descendants((t,r)=>{let i=s.mapping.map(r),o=s.mapping.map(r)+t.nodeSize,a=null;if(t.marks.forEach(t=>{if(t!==e)return!1;a=t}),!a)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==a.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});s.removeMark(i,o,e.type),s.addMark(i,o,t)}}),s.docChanged&&t.view.dispatch(s)}(r,e,t)}})}]:[]}))}destroy(){this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{var t;let n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:uS(e.name,this.schema)};"mark"===e.type&&(null==(t=ua(ur(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=ur(e,"onBeforeCreate",n),i=ur(e,"onCreate",n),s=ur(e,"onUpdate",n),o=ur(e,"onSelectionUpdate",n),a=ur(e,"onTransaction",n),l=ur(e,"onFocus",n),c=ur(e,"onBlur",n),d=ur(e,"onDestroy",n);r&&this.editor.on("beforeCreate",r),i&&this.editor.on("create",i),s&&this.editor.on("update",s),o&&this.editor.on("selectionUpdate",o),a&&this.editor.on("transaction",a),l&&this.editor.on("focus",l),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}};pn.resolve=ub,pn.sort=ug,pn.flatten=ui,c6({},{ClipboardTextSerializer:()=>pi,Commands:()=>ps,Delete:()=>po,Drop:()=>pa,Editable:()=>pl,FocusEvents:()=>pd,Keymap:()=>pu,Paste:()=>pp,Tabindex:()=>ph,TextDirection:()=>pf,focusEventsPluginKey:()=>pc});var pr=class e extends u7{constructor(){super(...arguments),this.type="extension"}static create(t={}){return new e("function"==typeof t?t():t)}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pi=pr.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:s}=i,o=Math.min(...s.map(e=>e.$from.pos)),a=Math.max(...s.map(e=>e.$to.pos)),l=uv(n);return ux(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),ps=pr.create({name:"commands",addCommands:()=>({...c8})}),po=pr.create({name:"delete",onUpdate({transaction:e,appendedTransactions:t}){var n,r,i;let s=()=>{var n,r,i,s;if(null!=(s=null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.filterTransaction)?void 0:i.call(r,e))?s:e.getMeta("y-sync$"))return;let o=d8(e.before,[e,...t]);uk(o).forEach(t=>{o.mapping.mapResult(t.oldRange.from).deletedAfter&&o.mapping.mapResult(t.oldRange.to).deletedBefore&&o.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let i=r+n.nodeSize-2,s=t.oldRange.from<=r&&i<=t.oldRange.to;this.editor.emit("delete",{type:"node",node:n,from:r,to:i,newFrom:o.mapping.map(r),newTo:o.mapping.map(i),deletedRange:t.oldRange,newRange:t.newRange,partial:!s,editor:this.editor,transaction:e,combinedTransform:o})})});let a=o.mapping;o.steps.forEach((t,n)=>{var r,i;if(t instanceof so){let s=a.slice(n).map(t.from,-1),l=a.slice(n).map(t.to),c=a.invert().map(s,-1),d=a.invert().map(l),u=s>0&&(null==(r=o.doc.nodeAt(s-1))?void 0:r.marks.some(e=>e.eq(t.mark))),p=null==(i=o.doc.nodeAt(l))?void 0:i.marks.some(e=>e.eq(t.mark));this.editor.emit("delete",{type:"mark",mark:t.mark,from:t.from,to:t.to,deletedRange:{from:c,to:d},newRange:{from:s,to:l},partial:!!(p||u),editor:this.editor,transaction:e,combinedTransform:o})}})};null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.async)||i?setTimeout(s,0):s()}}),pa=pr.create({name:"drop",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pl=pr.create({name:"editable",addProseMirrorPlugins(){return[new s0({key:new s3("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pc=new s3("focusEvents"),pd=pr.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new s0({key:pc,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),pu=pr.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:s}=n,{pos:o,parent:a}=s,l=s.parent.isTextblock&&o>0?t.doc.resolve(o-1):s,c=l.parent.type.spec.isolating,d=s.pos-s.parentOffset,u=c&&1===l.parent.childCount?d===s.pos:sL.atStart(r).from===o;return!!i&&!!a.type.isTextblock&&!a.textContent.length&&!!u&&(!u||"paragraph"!==s.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return dE()||dU()?i:r},addProseMirrorPlugins(){return[new s0({key:new s3("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventClearDocument"));if(!r||i)return;let{empty:s,from:o,to:a}=t.selection,l=sL.atStart(t.doc).from,c=sL.atEnd(t.doc).to;if(s||o!==l||a!==c||!uA(n.doc))return;let d=n.tr,u=c9({state:n,transaction:d}),{commands:p}=new c7({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pp=pr.create({name:"paste",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),ph=pr.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pf=pr.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=ul(this.extensions);return[{types:e.filter(e=>"text"!==e.name).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute("dir");return t&&("ltr"===t||"rtl"===t||"auto"===t)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new s0({key:new s3("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pm=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!=(e=this.actualDepth)?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return void console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(0===this.depth)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,o=n.isInline,a=this.pos+r+ +!s;if(a<0||a>this.resolvedPos.doc.nodeSize-2)return;let l=this.resolvedPos.doc.resolve(a);if(!i&&!o&&l.depth<=this.depth)return;let c=new e(l,this.editor,i,i||o?n:null);i&&(c.actualDepth=this.depth+1),t.push(c)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||0===this.children.length)return r;let i=Object.keys(t);return this.children.forEach(s=>{n&&r.length>0||(s.node.type.name===e&&i.every(e=>t[e]===s.node.attrs[e])&&r.push(s),n&&r.length>0||(r=r.concat(s.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},pg=`.ProseMirror {
22
22
  position: relative;
23
23
  }
24
24
 
@@ -167,4 +167,4 @@ body.exp-focus-cocoon button[aria-label="Expand outline"] {
167
167
  }
168
168
  `;function vy({scrollContainerRef:e}){return(0,f.useEffect)(()=>{let t=e.current;if(!t)return;let n=new Set,r=new WeakMap,i=null,s=0,o=e=>{e.classList.remove("exp-anchor-flash");let t=r.get(e);t&&(e.removeEventListener("animationend",t),r.delete(e)),n.delete(e)},a=()=>{let e,s;i=null;let a=(()=>{let e=t.getBoundingClientRect().top,n=null,r=1/0;for(let i of t.querySelectorAll(".tiptap > :is(h1,h2,h3,h4,h5,h6)")){let t=Math.abs(i.getBoundingClientRect().top-e-48);t<=14&&t<r&&(n=i,r=t)}return n})();a&&((e=r.get(a))&&(a.removeEventListener("animationend",e),r.delete(a)),a.classList.remove("exp-anchor-flash"),a.offsetWidth,a.classList.add("exp-anchor-flash"),n.add(a),s=()=>o(a),r.set(a,s),a.addEventListener("animationend",s,{once:!0}))},l=()=>{s||(s=requestAnimationFrame(()=>{s=0,i&&clearTimeout(i),i=setTimeout(a,140)}))};return t.addEventListener("scroll",l,{passive:!0}),()=>{for(let e of(t.removeEventListener("scroll",l),s&&cancelAnimationFrame(s),i&&clearTimeout(i),n))o(e)}},[e]),(0,s.jsx)("style",{children:vx})}function vv(e,t){try{let{node:n}=e.view.domAtPos(t+1);if(n.nodeType===Node.ELEMENT_NODE)return n.closest("h1,h2,h3,h4,h5,h6")??n;return n.parentElement?.closest("h1,h2,h3,h4,h5,h6")??null}catch{return null}}function vw(e){let t=e?.querySelector(".tiptap");if(t)for(let e of Array.from(t.children))e.style.display=""}function vk({editor:e,scrollContainerRef:t}){let n=t1(e=>e.currentPath),[r,i]=(0,f.useState)(!1),[o,a]=(0,f.useState)(new Set),[l,c]=(0,f.useState)(null),[d,u]=(0,f.useState)([]),p=n?`wiki-collapsed:${n}`:"wiki-collapsed:shared",h=t.current;return((0,f.useEffect)(()=>{i(!0)},[]),(0,f.useEffect)(()=>{try{let e=localStorage.getItem(p);if(!e){a(new Set),c(p);return}let t=JSON.parse(e);if(Array.isArray(t)){a(new Set(t.filter(e=>"string"==typeof e))),c(p);return}a(new Set),c(p)}catch{a(new Set),c(p)}},[p]),(0,f.useEffect)(()=>{if(l===p)try{localStorage.setItem(p,JSON.stringify(Array.from(o)))}catch{}},[o,l,p]),(0,f.useEffect)(()=>{if(!e||!r||!h||l!==p){vw(h??null),u([]);return}let t=null,n=0,i=null,s=()=>{let t,n,r,i,s,a,l=(t=[],n=new Map,r=h.getBoundingClientRect(),i=h.querySelector(".tiptap"),a=(s=i?.getBoundingClientRect())?s.right-r.left+h.scrollLeft:r.width,e.state.doc.forEach((i,s)=>{if("heading"!==i.type.name)return;let o=i.textContent,l=i.attrs.level,c=o.toLowerCase().replace(/\s+/g,"-").replace(/[^\w-]/g,"")||"heading",d=(n.get(c)??0)+1;n.set(c,d);let u=1===d?c:`${c}-${d}`,p=vv(e,s);if(!(p instanceof HTMLElement))return;let f=p.offsetTop+p.offsetHeight/2,m=p.offsetLeft;try{let e=document.createRange();e.selectNodeContents(p);let t=e.getBoundingClientRect(),n=p.getBoundingClientRect(),i=0===t.width&&0===t.height?n:t;f=i.top-r.top+h.scrollTop+.6*i.height,m=i.right-r.left+h.scrollLeft+8}catch{let e=p.getBoundingClientRect();f=e.top-r.top+h.scrollTop+e.height/2,m=e.right-r.left+h.scrollLeft+8}t.push({level:l,text:o,pos:s,uid:u,centerY:f,endLeft:m,rootRight:a})}),t);u(l);let c=h.querySelector(".tiptap");if(c)for(let t of(vw(h),l)){if(!o.has(t.uid))continue;let n=vv(e,t.pos);if(!n||!c.contains(n))continue;let r=n.nextElementSibling;for(;r&&r.parentElement===c;){let e=function(e){if(!e)return null;let t=e.tagName.match(/^H([1-6])$/);return t?Number(t[1]):null}(r);if(null!==e&&e<=t.level)break;r.style.display="none",r=r.nextElementSibling}}},a=()=>{t&&clearTimeout(t),t=setTimeout(s,250)};return s(),n=requestAnimationFrame(s),e.on("update",a),"u">typeof ResizeObserver?(i=new ResizeObserver(s)).observe(h):window.addEventListener("resize",s,{passive:!0}),()=>{t&&clearTimeout(t),cancelAnimationFrame(n),e.off("update",a),window.removeEventListener("resize",s),i?.disconnect(),vw(h)}},[o,e,h,l,r,p]),r&&h)?(0,tv.createPortal)((0,s.jsx)("div",{"aria-hidden":!0,className:"absolute inset-0 h-0 pointer-events-none z-20",children:d.map(e=>{let t=o.has(e.uid),n=e.endLeft+20;return(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{type:"button","aria-label":`${t?"Expand":"Collapse"} section: ${e.text}`,"aria-pressed":t,title:e.text,onClick:()=>{a(t=>{let n=new Set(t);return n.has(e.uid)?n.delete(e.uid):n.add(e.uid),n})},className:"pointer-events-auto absolute flex h-4 w-4 -translate-y-1/2 items-center justify-center rounded border border-border/70 bg-background/90 text-muted-foreground shadow-sm backdrop-blur transition-colors hover:bg-accent hover:text-foreground",style:{top:e.centerY,left:e.endLeft},children:t?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"})}),t&&e.rootRight-n>8?(0,s.jsx)("span",{"aria-hidden":!0,className:"absolute -translate-y-1/2 border-t border-dashed border-border/70",style:{top:e.centerY,left:n,width:e.rootRight-n}}):null]},e.uid)})}),h):null}function vN(e){return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(vf,{...e}),(0,s.jsx)(vm,{...e}),(0,s.jsx)(vb,{...e}),(0,s.jsx)(vy,{...e}),(0,s.jsx)(vk,{...e})]})}let vS=(0,o.default)("link-2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]),vC=(0,o.default)("unlink",[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]),vj=new Map,vE=new Map,vM=(0,eN.create)((e,t)=>({path:null,backlinks:[],loading:!1,cacheVersion:0,fetch:async n=>{let r;if(!n)return;let i=(r=vj.get(n))?Date.now()-r.loadedAt>6e4?(vj.delete(n),null):r.data:null;if(i)return void e({path:n,backlinks:i,loading:!1});e({path:n,backlinks:[],loading:!0});let s=vE.get(n);if(s){try{let r=await s.promise;if(t().path!==n)return;e({backlinks:r,loading:!1})}catch{t().path===n&&e({loading:!1})}return}let o=new AbortController,a=(async()=>{let e=await (0,tE.wsFetch)(`/api/wiki/backlinks?path=${encodeURIComponent(n)}`,{signal:o.signal});return e.ok?(await e.json()).backlinks??[]:[]})().finally(()=>{vE.delete(n)});vE.set(n,{promise:a,controller:o});try{let r=await a;if(o.signal.aborted)return;if(vj.delete(n),vj.set(n,{data:r,loadedAt:Date.now()}),vj.size>30){let e=vj.keys().next().value;void 0!==e&&vj.delete(e)}if(t().path!==n)return;e({backlinks:r,loading:!1})}catch(r){if("AbortError"===r.name||t().path!==n)return;e({backlinks:[],loading:!1})}},cancel:()=>{let{path:n}=t();n&&vE.get(n)?.controller.abort(),t().loading&&e({loading:!1})},invalidateAll:()=>{vj.clear(),e({cacheVersion:t().cacheVersion+1})}})),vA="kb-backlinks-collapsed";function vT({currentPath:e}){let[t,n]=(0,f.useState)(!1),r=fd(e=>e.has),i=vM(e=>e.path),o=vM(e=>e.backlinks),a=vM(e=>e.loading),l=vM(e=>e.cacheVersion),c=i===e?o:[];return((0,f.useEffect)(()=>{"1"===localStorage.getItem(vA)&&n(!0)},[]),(0,f.useEffect)(()=>{if(t||!e)return;let n=setTimeout(()=>{vM.getState().fetch(e)},200);return()=>{clearTimeout(n),vM.getState().cancel()}},[e,t,l]),t||a||0!==c.length)?(0,s.jsx)("div",{className:"max-w-[var(--editor-max-w,48rem)] mx-auto px-4 sm:px-8 pb-8 pt-1",children:(0,s.jsxs)("div",{className:"border-t border-border/60 pt-4",children:[(0,s.jsxs)("button",{onClick:()=>{let e=!t;n(e);try{localStorage.setItem(vA,e?"1":"0")}catch{}},className:"flex items-center gap-1.5 text-[11px] text-muted-foreground/60 hover:text-muted-foreground transition-colors mb-2","aria-expanded":!t,children:[t?(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)(b,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)(vS,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"font-medium",children:"Linked from"}),c.length>0&&(0,s.jsxs)("span",{className:"opacity-50 tabular-nums",children:["(",c.length,")"]}),a&&(0,s.jsx)("span",{className:"opacity-40 ml-1",children:"…"})]}),!t&&c.length>0&&(0,s.jsx)("ul",{className:"flex flex-col gap-1.5",children:c.map(e=>{var t,n;let i,o=r(((t=e.path).split("/").pop()??t).replace(/\.md$/i,""));return(0,s.jsxs)("li",{className:"flex flex-col",children:[(0,s.jsxs)("button",{onClick:()=>o&&t1.getState().loadPage(e.path),className:o?"text-left text-[12px] text-primary/70 hover:text-primary hover:underline underline-offset-2 truncate transition-colors flex items-center gap-1":"text-left text-[12px] text-muted-foreground/40 truncate cursor-default flex items-center gap-1",title:o?e.path:`${e.path} (file not found)`,children:[!o&&(0,s.jsx)(vC,{className:"h-2.5 w-2.5 shrink-0 text-muted-foreground/30"}),(i=(n=e.path).replace(/\.md$/i,"").split("/")).length>1?i.slice(-2).join(" / "):i[0]??n]}),e.snippet&&(0,s.jsx)("p",{className:o?"text-[10.5px] text-muted-foreground/50 line-clamp-1 mt-0.5":"text-[10.5px] text-muted-foreground/25 line-clamp-1 mt-0.5",children:e.snippet})]},e.path)})})]})}):null}let vO=(0,o.default)("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),v_=(0,o.default)("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),vD=(0,o.default)("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),vR=(0,o.default)("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]),vI=(0,o.default)("columns-3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),vL=(0,o.default)("panel-top",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}]]),vP=(0,o.default)("rows-3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);function vz({label:e,icon:t,disabled:n,active:r,danger:i,onAction:o}){return(0,s.jsx)("button",{type:"button","aria-label":e,title:e,disabled:n,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.preventDefault(),o()},className:(0,eh.cn)("h-7 w-7 inline-flex items-center justify-center rounded text-foreground/80 hover:bg-accent transition-colors disabled:pointer-events-none disabled:opacity-35",r&&"bg-accent text-foreground",i&&"text-destructive hover:bg-destructive/10"),children:(0,s.jsx)(t,{className:"h-3.5 w-3.5"})})}function v$(){return(0,s.jsx)("div",{className:"mx-1 h-5 w-px bg-border"})}function vB({editor:e}){if(!e)return null;let t=()=>{if(!lF(e.state))return null;try{return l7(e.state)}catch{return null}},n=t=>{t()&&(e.commands.focus(),e.commands.fixTables())},r=n=>{let r=t();if(!r)return;let i=r.top,s=i+n;if(!(s<0)&&!(s>=r.map.height)){var o;(o={from:i,to:s},(e,t)=>{let{from:n,to:r,select:i=!0,pos:s=e.selection.from}=o,a=e.tr;return!!function(e){var t,n,r,i,s;let o,{tr:a,originIndex:l,targetIndex:c,select:d,pos:u}=e,p=l2(a.doc.resolve(u));if(!p)return!1;let h=null==(t=l6(a,l))?void 0:t.indexes,f=null==(n=l6(a,c))?void 0:n.indexes;if(!h||!f||h.includes(c))return!1;let m=(r=p.node,i=h,s=f,o=lQ(r),l0(r,o=l1(o,i,s,0)));if(a.replaceWith(p.pos,p.pos+p.node.nodeSize,m),!d)return!0;let g=lP.get(m),b=p.start,x=g.positionAt(c,g.width-1,m),y=a.doc.resolve(b+x),v=g.positionAt(c,0,m),w=a.doc.resolve(b+v);return a.setSelection(lG.rowSelection(y,w)),!0}({tr:a,originIndex:n,targetIndex:r,select:i,pos:s})&&(null==t||t(a),!0)})(e.state,e.view.dispatch),e.commands.focus()}},i=n=>{let r=t();if(!r)return;let i=r.left,s=i+n;if(!(s<0)&&!(s>=r.map.width)){var o;(o={from:i,to:s},(e,t)=>{let{from:n,to:r,select:i=!0,pos:s=e.selection.from}=o,a=e.tr;return!!function(e){var t,n,r,i,s;let o,{tr:a,originIndex:l,targetIndex:c,select:d,pos:u}=e,p=l2(a.doc.resolve(u));if(!p)return!1;let h=null==(t=l4(a,l))?void 0:t.indexes,f=null==(n=l4(a,c))?void 0:n.indexes;if(!h||!f||h.includes(c))return!1;let m=(r=p.node,i=h,s=f,o=l9(lQ(r)),l0(r,o=l9(o=l1(o,i,s,0))));if(a.replaceWith(p.pos,p.pos+p.node.nodeSize,m),!d)return!0;let g=lP.get(m),b=p.start,x=g.positionAt(g.height-1,c,m),y=a.doc.resolve(b+x),v=g.positionAt(0,c,m),w=a.doc.resolve(b+v);return a.setSelection(lG.colSelection(y,w)),!0}({tr:a,originIndex:n,targetIndex:r,select:i,pos:s})&&(null==t||t(a),!0)})(e.state,e.view.dispatch),e.commands.focus()}},o=t(),a=!!o&&o.top>0,l=!!o&&o.top<o.map.height-1,c=!!o&&o.left>0,d=!!o&&o.left<o.map.width-1;return(0,s.jsxs)(fT,{editor:e,pluginKey:"tableMenu",options:{placement:"top",offset:10},shouldShow:({editor:e})=>e.isActive("table"),className:"flex items-center gap-0.5 rounded-md border border-border bg-popover px-1 py-1 shadow-lg",children:[(0,s.jsx)(vz,{label:"Select cell text",icon:vs,onAction:()=>{let t=lB(e.state.selection.$from),n=t?.nodeAfter;t&&n&&e.chain().focus().setTextSelection({from:t.pos+1,to:t.pos+n.nodeSize-1}).run()}}),(0,s.jsx)(v$,{}),(0,s.jsx)(vz,{label:"Add row above",icon:vP,onAction:()=>n(()=>e.chain().focus().addRowBefore().run())}),(0,s.jsx)(vz,{label:"Add row below",icon:vO,onAction:()=>n(()=>e.chain().focus().addRowAfter().run())}),(0,s.jsx)(vz,{label:"Move row up",icon:vR,disabled:!a,onAction:()=>r(-1)}),(0,s.jsx)(vz,{label:"Move row down",icon:vO,disabled:!l,onAction:()=>r(1)}),(0,s.jsx)(vz,{label:"Delete row",icon:ts,danger:!0,onAction:()=>n(()=>e.chain().focus().deleteRow().run())}),(0,s.jsx)(v$,{}),(0,s.jsx)(vz,{label:"Add column before",icon:vI,onAction:()=>n(()=>e.chain().focus().addColumnBefore().run())}),(0,s.jsx)(vz,{label:"Add column after",icon:vD,onAction:()=>n(()=>e.chain().focus().addColumnAfter().run())}),(0,s.jsx)(vz,{label:"Move column left",icon:v_,disabled:!c,onAction:()=>i(-1)}),(0,s.jsx)(vz,{label:"Move column right",icon:vD,disabled:!d,onAction:()=>i(1)}),(0,s.jsx)(vz,{label:"Delete column",icon:ts,danger:!0,onAction:()=>n(()=>e.chain().focus().deleteColumn().run())}),(0,s.jsx)(v$,{}),(0,s.jsx)(vz,{label:"Toggle header row",icon:vL,onAction:()=>n(()=>e.chain().focus().toggleHeaderRow().run())}),(0,s.jsx)(vz,{label:"Toggle header column",icon:n5,onAction:()=>n(()=>e.chain().focus().toggleHeaderColumn().run())}),(0,s.jsx)(v$,{}),(0,s.jsx)(vz,{label:"Delete table",icon:ts,danger:!0,onAction:()=>e.chain().focus().deleteTable().run()})]})}let vF=["entities","concepts","comparisons"],vH=/^[a-z0-9-]+$/;function vU({editor:e,onCreateRequest:t}){let[n,r]=(0,f.useState)(!1),[i,o]=(0,f.useState)(""),[a,l]=(0,f.useState)(0),[c,d]=(0,f.useState)({top:0,left:0}),u=(0,f.useRef)(null),p=(0,f.useRef)(0),h=fd(e=>e.slugs),m=fd(e=>e.slugDir),g=fd(e=>e.has),b=Array.from(h).sort().filter(e=>!i||e.includes(i.toLowerCase())).slice(0,20),x=i.length>0&&vH.test(i)&&!g(i),y=b.length+ +!!x,v=(0,f.useCallback)(()=>{r(!1),o(""),l(0)},[]),w=(0,f.useCallback)(t=>{if(!e)return;let{from:n}=e.state.selection,r=p.current-2,i=e.state.schema.marks.wikiLink;if(!i)return;let s=i.create({slug:t,alias:null,anchor:null}),o=e.state.schema.text(t,[s]),a=e.state.tr.replaceWith(r,n,o);e.view.dispatch(a),e.commands.focus(),v()},[e,v]),k=(0,f.useCallback)(async n=>{if(e){if(n<b.length)w(b[n]??"");else if(x){let e=await t(i);e.ok?w(e.slug):v()}}},[e,b,x,i,w,t,v]);return((0,f.useEffect)(()=>{if(!e)return;let t=t=>{if(!n){if("["===t.key){let{from:t}=e.state.selection;if("["!==e.state.doc.textBetween(Math.max(0,t-1),t)||e.state.doc.resolve(t).marks().some(e=>"wikiLink"===e.type.name))return;let n=e.view.coordsAtPos(t),i=e.view.dom.getBoundingClientRect();d({top:n.bottom-i.top+4,left:n.left-i.left}),p.current=t+1,r(!0),o(""),l(0)}return}"ArrowDown"===t.key?(t.preventDefault(),l(e=>y>0?(e+1)%y:0)):"ArrowUp"===t.key?(t.preventDefault(),l(e=>y>0?(e-1+y)%y:0)):"Enter"===t.key?(t.preventDefault(),t.stopPropagation(),y>0&&k(a)):"Escape"===t.key||"]"===t.key?v():"Backspace"===t.key?0===i.length?v():(o(e=>e.slice(0,-1)),l(0)):1!==t.key.length||t.metaKey||t.ctrlKey||(o(e=>e+t.key),l(0))};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e,n,i,a,y,v,k]),(0,f.useEffect)(()=>{if(!n)return;let e=e=>{u.current&&!u.current.contains(e.target)&&v()};return window.addEventListener("mousedown",e),()=>window.removeEventListener("mousedown",e)},[n,v]),n&&0!==y)?(0,s.jsxs)("div",{ref:u,className:"absolute z-50 w-[280px] bg-popover border border-border rounded-lg shadow-lg py-1 overflow-hidden max-h-[300px] overflow-y-auto",style:{top:c.top,left:c.left},children:[b.map((e,t)=>{let n=m.get(e);return(0,s.jsxs)("button",{type:"button",onMouseDown:e=>{e.preventDefault(),k(t)},onMouseEnter:()=>l(t),className:(0,eh.cn)("flex items-center justify-between w-full px-3 py-1.5 text-left text-sm transition-colors",t===a?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:[(0,s.jsx)("span",{className:"truncate",children:e}),n&&(0,s.jsx)("span",{className:"ml-2 shrink-0 text-[10px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:n})]},e)}),x&&(0,s.jsx)("button",{type:"button",onMouseDown:e=>{e.preventDefault(),k(b.length)},onMouseEnter:()=>l(b.length),className:(0,eh.cn)("flex items-center w-full px-3 py-1.5 text-left text-sm transition-colors",b.length===a?"bg-accent text-accent-foreground":"hover:bg-accent/50"),children:(0,s.jsxs)("span",{className:"text-muted-foreground",children:["+ Create new “",i,"”"]})})]}):null}let vV=(0,tS.cva)("inline-flex items-center rounded-sm border px-2.5 py-0.5 text-xs font-normal transition-colors focus:outline-none focus:ring-2 focus:ring-ring",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow-e-1",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground shadow-e-1",outline:"text-foreground",accent:"border-transparent bg-accent text-accent-foreground"}},defaultVariants:{variant:"default"}});function vW({className:e,variant:t,...n}){return(0,s.jsx)("div",{className:(0,eh.cn)(vV({variant:t}),e),...n})}let vq=new Set(["title","type","status","created","updated","date","tags","sources","private","supersedes","superseded_by"]);function vK({data:e}){let[t,n]=(0,f.useState)(!1),r=Object.keys(e);if(0===r.length)return null;let i="string"==typeof e.title?e.title:null,o="string"==typeof e.type?e.type:null,a="string"==typeof e.status?e.status:null,l="string"==typeof e.created?e.created:null,c="string"==typeof e.updated?e.updated:null,d=!0===e.private,u=Array.isArray(e.tags)?e.tags:[],p=Array.isArray(e.sources)?e.sources:[],h="string"==typeof e.superseded_by?e.superseded_by:null,m=r.filter(e=>!vq.has(e));return(0,s.jsxs)("div",{className:"mb-6 rounded-sm border bg-card/40 px-4 py-3 text-xs",children:[i&&(0,s.jsx)("div",{className:"mb-2 text-base font-normal text-foreground",children:i}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 text-muted-foreground",children:[o&&(0,s.jsx)(vW,{variant:"outline",className:"font-normal",children:o}),a&&(0,s.jsx)(vW,{variant:"outline",className:"font-normal",children:a}),d&&(0,s.jsx)(vW,{variant:"outline",className:"border-warning-ink/40 font-normal text-warning-ink",children:"private"}),h&&(0,s.jsxs)(vW,{variant:"outline",className:"border-destructive/40 font-normal text-destructive",children:["superseded → ",h]}),l&&(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"opacity-60",children:"created"})," ",(0,s.jsx)("span",{className:"text-foreground/80",children:l})]}),c&&c!==l&&(0,s.jsxs)("span",{children:[(0,s.jsx)("span",{className:"opacity-60",children:"updated"})," ",(0,s.jsx)("span",{className:"text-foreground/80",children:c})]})]}),u.length>0&&(0,s.jsx)("div",{className:"mt-2 flex flex-wrap gap-1",children:u.map(e=>(0,s.jsxs)(vW,{variant:"secondary",className:"font-normal text-[11px]",children:["#",e]},e))}),p.length>0&&(0,s.jsxs)("div",{className:"mt-2",children:[(0,s.jsx)("span",{className:"opacity-60",children:"sources:"})," ",(0,s.jsx)("span",{className:"text-foreground/80",children:p.join(", ")})]}),m.length>0&&(0,s.jsxs)("div",{className:"mt-2 border-t pt-2",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>n(e=>!e),className:"flex items-center gap-1 text-muted-foreground hover:text-foreground",children:[t?(0,s.jsx)(b,{className:"h-3 w-3"}):(0,s.jsx)(e3.ChevronRight,{className:"h-3 w-3"}),(0,s.jsxs)("span",{children:[m.length," more field",1===m.length?"":"s"]})]}),t&&(0,s.jsx)("dl",{className:"mt-1.5 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-0.5",children:m.map(t=>(0,s.jsxs)(f.Fragment,{children:[(0,s.jsx)("dt",{className:"opacity-60",children:t}),(0,s.jsx)("dd",{className:"text-foreground/80 break-words",children:function e(t){if(null==t)return"";if("string"==typeof t)return t;if("number"==typeof t||"boolean"==typeof t)return String(t);if(Array.isArray(t))return t.map(e).join(", ");try{return JSON.stringify(t)}catch{return String(t)}}(e[t])})]},t))})]})]})}function vG({containerRef:e,onComment:t,align:n="center"}){let[r,i]=(0,f.useState)(null);return((0,f.useEffect)(()=>{function t(){let t=window.getSelection();if(!t||t.isCollapsed||0===t.rangeCount)return void i(null);let r=t.getRangeAt(0),s=e.current;if(!s||!s.contains(r.commonAncestorContainer))return void i(null);let o=r.getBoundingClientRect();if(0===o.width&&0===o.height)return void i(null);if("left"===n){let e=s.getBoundingClientRect();i({top:o.top,left:e.left+8})}else i({top:o.top-38,left:o.left+o.width/2})}return document.addEventListener("selectionchange",t),()=>document.removeEventListener("selectionchange",t)},[e,n]),r)?(0,s.jsxs)("button",{type:"button",style:{position:"fixed",top:r.top,left:r.left,transform:"left"===n?void 0:"translateX(-50%)",zIndex:50},className:"flex items-center gap-1 px-2 py-1 bg-popover border border-border rounded-sm shadow-lg text-[12px] text-foreground/80 hover:text-foreground hover:bg-accent transition-colors",onMouseDown:e=>e.preventDefault(),onClick:()=>{t(),i(null)},"aria-label":"Add comment",title:"Add comment",children:[(0,s.jsx)(fP,{className:"w-3.5 h-3.5"}),(0,s.jsx)("span",{children:"Comment"})]}):null}async function vJ(e,t){let n=new FormData;n.append("file",t);try{let r=await (0,tE.wsFetch)(`/api/upload/${e}`,{method:"POST",body:n});if(!r.ok)return ey(`Upload failed: ${t.name}`),null;let i=await r.json();return i.url?(0,tE.withWs)(i.url):i.url}catch{return ey(`Upload failed: ${t.name}`),null}}function vZ({mode:e}={}){let{currentPath:t,content:n,saveStatus:r,frontmatter:i,isLoading:o,loadStatus:a,createMissingPage:l,editMode:c,setEditMode:d}=t1(),p=e??c,h="viewing"===p,b="suggesting"===p,x=(0,f.useMemo)(()=>h?function(e){let t=fl.exec(e);if(!t)return{data:{},body:e};let n=t[1],r=e.slice(t[0].length),i=n.split(/\r?\n/).find(e=>""!==e.trim())??"";if(/^\s*(#{1,6}\s|<|>|-\s|\*\s|\d+\.\s)/.test(i))return{data:{},body:e};let s={},o=n.split(/\r?\n/),a=0;for(;a<o.length;){let e=o[a];if(!e||/^\s*#/.test(e)){a+=1;continue}let t=/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/.exec(e);if(!t){a+=1;continue}let n=t[1],r=t[2];if(""===r.trim()){let e=[],t=a+1;for(;t<o.length&&/^\s+-\s+/.test(o[t]);){let n=/^\s+-\s+(.*)$/.exec(o[t]);n&&e.push(fc(n[1])),t+=1}if(e.length>0){s[n]=e,a=t;continue}s[n]="",a+=1;continue}s[n]=fc(r),a+=1}return 0===Object.keys(s).length?{data:{},body:e}:{data:s,body:r}}(n):{data:{},body:n},[n,h]),y=(0,rF.useViewWidthStore)(e=>rF.VIEW_WIDTH_CSS[e.width]),w=(0,rF.useViewWidthStore)(e=>rF.VIEW_ALIGN_ML[e.align]),k=h?"rtl"===x.data.dir:i?.dir==="rtl",{open:N,clearMessages:S}=tO(),{open:C,Dialog:j}=function(){let[e,t]=(0,f.useState)(!1),[n,r]=(0,f.useState)({slug:"",dir:"entities",title:""}),[i,o]=(0,f.useState)(!1),a=(0,f.useRef)(null),l=(0,f.useCallback)(e=>(r({slug:e,dir:"entities",title:e.split("-").filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}),t(!0),new Promise(e=>{a.current=e})),[]),c=(0,f.useCallback)(()=>{t(!1),a.current?.({ok:!1,slug:n.slug}),a.current=null},[n.slug]),d=(0,f.useCallback)(async()=>{let{slug:e,dir:r,title:i}=n;o(!0);try{let n=await (0,tE.wsFetch)("/api/wiki/page",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,dir:r,title:i.trim()||void 0})});if(n.ok||409===n.status){let n=fd.getState();n.invalidate(),n.load(),t(!1),a.current?.({ok:!0,slug:e,dir:r}),a.current=null}else{let e=await n.json().catch(()=>({})),t=null!==e&&"object"==typeof e&&"error"in e&&"string"==typeof e.error?e.error:"Failed to create page";ey(t)}}catch{ey("Failed to create page")}finally{o(!1)}},[n]);return{open:l,Dialog:(0,s.jsx)(B,{open:e,onOpenChange:e=>{e||c()},children:(0,s.jsxs)(eX,{children:[(0,s.jsx)(eY,{children:(0,s.jsx)(e0,{children:"Create wiki page"})}),(0,s.jsxs)("div",{className:"space-y-4 py-2",children:[(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(tj,{htmlFor:"wiki-create-slug",children:"Slug"}),(0,s.jsx)(ta.Input,{id:"wiki-create-slug",value:n.slug,readOnly:!0,className:"bg-muted cursor-default select-all"})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(tj,{children:"Directory"}),(0,s.jsx)("div",{className:"flex gap-4",children:vF.map(e=>(0,s.jsxs)("label",{className:"flex items-center gap-1.5 text-sm cursor-pointer",children:[(0,s.jsx)("input",{type:"radio",name:"wiki-create-dir",value:e,checked:n.dir===e,onChange:()=>r(t=>({...t,dir:e})),className:"accent-primary"}),e]},e))})]}),(0,s.jsxs)("div",{className:"space-y-1.5",children:[(0,s.jsx)(tj,{htmlFor:"wiki-create-title",children:"Title (optional)"}),(0,s.jsx)(ta.Input,{id:"wiki-create-title",value:n.title,onChange:e=>r(t=>({...t,title:e.target.value})),placeholder:"Humanized title..."})]})]}),(0,s.jsxs)(eQ,{children:[(0,s.jsx)(v.Button,{variant:"outline",onClick:c,disabled:i,children:"Cancel"}),(0,s.jsx)(v.Button,{onClick:()=>void d(),disabled:i,children:i?"Creating...":"Create"})]})]})})}}(),E=(0,f.useRef)(C);E.current=C;let M=(0,f.useRef)(!1),A=(0,f.useRef)(h);A.current=h;let T=(0,f.useRef)(null),[O,_]=(0,f.useState)(!1),[D,R]=(0,f.useState)("");(0,f.useEffect)(()=>{fd.getState().load()},[]),(0,f.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>{fp.getState().loadSidecar(t)},200);return()=>clearTimeout(e)},[t]),function({path:e,mode:t,enabled:n=!0}){let r="viewing"===t;(0,f.useEffect)(()=>{if(!n||!e||r||!/\.(md|markdown)$/i.test(e))return;let t=t=>{(0,tE.wsFetch)("/api/wiki/presence",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,action:t}),keepalive:"close"===t}).catch(()=>{})},i=!1,s=null,o=()=>{i&&"hidden"===document.visibilityState&&t("heartbeat")},a=setTimeout(()=>{i=!0,t("open"),s=setInterval(()=>t("heartbeat"),3e4),document.addEventListener("visibilitychange",o)},200);return()=>{clearTimeout(a),s&&clearInterval(s),document.removeEventListener("visibilitychange",o),i&&t("close")}},[n,e,r])}({path:t,mode:p,enabled:!0}),function({path:e,isViewingRef:t,enabled:n=!0}){let r=(0,f.useMemo)(()=>{if(!e)return"";let t=e.lastIndexOf("/");return -1===t?"":e.slice(0,t)},[e]),i=(0,tE.getActiveWorkspaceId)(),s=(0,tE.getEphemeralRoot)();(0,f.useEffect)(()=>{if(!n||(0,ev.isLite)()||!e)return;let i=e=>{fp.getState().loadSnapshot(e).then(()=>fp.getState().loadSidecar(e)),t.current&&t1.getState().loadPage(e)},s=r?`/api/wiki/watch?dir=${encodeURIComponent(r)}`:"/api/wiki/watch",o=new EventSource((0,tE.withWs)(s));return o.onmessage=e=>{try{let t=JSON.parse(e.data),n=t1.getState().currentPath;if(!n)return;if("rescan"===t.type)return void i(n);("change"===t.type||"add"===t.type)&&t.path===n&&i(n)}catch{}},()=>{o.close()}},[e,r,n,i,s,t])}({path:t,isViewingRef:A});let[I,L]=(0,f.useState)(null),P=(0,f.useRef)(null),[z,$]=(0,f.useState)(new Map),F=fp(e=>t?e.byPath[t]?.snapshotBlocks:void 0),H=fp(e=>t?e.byPath[t]?.sidecar?.suggestions:void 0),U=fp(e=>t?e.byPath[t]?.snapshotRevision??0:0),V=fp(e=>t?e.byPath[t]?.sidecar?.comments:void 0),W=(0,f.useMemo)(()=>F??[],[F]),q=(0,f.useMemo)(()=>V??[],[V]),K=(0,f.useMemo)(()=>H?.filter(e=>"pending"===e.status)??[],[H]),G=(0,f.useMemo)(()=>{let e={};for(let t of q)t.ref&&(e[t.ref]??=[]).push(t);return e},[q]),[J,Z]=(0,f.useState)(null),[X,Y]=(0,f.useState)(null),Q=(0,f.useCallback)(()=>{if(!T.current)return null;let e=T.current.view,{from:t}=e.state.selection,n=t1.getState().currentPath??"",r=fp.getState().byPath[n]?.snapshotBlocks??[],i=e.state.doc.resolve(t),s=i.depth>0?i.index(0):0,o=P.current?.querySelector(".ProseMirror"),a=(o?Array.from(o.children):[])[s]??null,l=r[s],c=l?.ref??a?.getAttribute("data-block-ref")??null,d=l?.markdown??"";if(!c&&a){let n=e.domAtPos(t),r=n.node.nodeType===Node.ELEMENT_NODE?n.node:n.node.parentElement,i=r?.closest("[data-block-ref]")??null;c=i?.getAttribute("data-block-ref")??null}return c&&a?{blockRef:c,blockEl:a,markdown:d}:null},[]),ee=(0,f.useCallback)(()=>{let e=Q();if(!e)return;let t=e.blockEl.getBoundingClientRect();Y({blockRef:e.blockRef,markdown:e.markdown,anchor:{top:t.bottom+4,left:t.left}})},[Q]),et=(0,f.useCallback)(()=>{let e=Q();e&&Z({blockRef:e.blockRef,el:e.blockEl})},[Q]),{markDirty:en,flush:er,onSelectionUpdate:ei}=function({path:e,editorRef:t,scrollContainerRef:n,isLoadingRef:r,isViewingRef:i,enabled:s=!0}){let o=(0,f.useRef)(!1),a=(0,f.useRef)(!1),l=(0,f.useRef)(null),c=(0,f.useCallback)(async()=>{if(a.current||!s||i.current||"suggesting"!==t1.getState().editMode||!o.current)return;let l=t.current,c=e??t1.getState().currentPath;if(!l||!c)return;let d=n.current?.querySelector(".ProseMirror");if(!d)return;let u=Array.from(d.children),p=fp.getState().byPath[c]?.snapshotBlocks??[];if(0!==p.length){a.current=!0,o.current=!1;try{let e=()=>fp.getState().byPath[c]?.snapshotRevision??0,t=async()=>{await fp.getState().loadSnapshot(c),await fp.getState().loadSidecar(c)},n=Math.max(u.length,p.length),i=!1;for(let r=0;r<n;r++){let n=u[r],s=p[r],o=n?fa(n.outerHTML,c).trim():null;if(s&&null!==o){if(yT(o)!==yT(s.markdown)){let n=await yA({path:c,ref:s.ref,kind:"replace",markdown:o,getRevision:e,refresh:t});i=i||n}}else if(s&&null===o){let n=await yA({path:c,ref:s.ref,kind:"delete",getRevision:e,refresh:t});i=i||n}else if(!s&&null!==o&&o.length>0){let n=p[p.length-1]?.ref;if(n){let r=await yA({path:c,ref:n,kind:"insertAfter",markdown:o,getRevision:e,refresh:t});i=i||r}}}if(i){await t();let e=(fp.getState().byPath[c]?.snapshotBlocks??p).map(e=>e.markdown).join("\n\n");r.current=!0;let n=await (0,hC.markdownToHtml)(e,c);l.commands.setContent(n),setTimeout(()=>{r.current=!1},50)}}finally{a.current=!1}}},[s,e,t,n,r,i]),d=(0,f.useCallback)(()=>{!s||i.current||"suggesting"===t1.getState().editMode&&(o.current=!0)},[s,i]),u=(0,f.useCallback)(e=>{if("suggesting"!==t1.getState().editMode)return;let{from:t}=e.state.selection,n=e.state.doc.resolve(t),r=n.depth>0?n.index(0):0,i=l.current;l.current=r,null!==i&&i!==r&&o.current&&c()},[c]);return{markDirty:d,flush:c,onSelectionUpdate:u}}({path:t,editorRef:T,scrollContainerRef:P,isLoadingRef:M,isViewingRef:A});(0,f.useEffect)(()=>{if(!t)return;let e=setTimeout(()=>{fp.getState().loadSnapshot(t)},200);return()=>clearTimeout(e)},[t]),(0,f.useEffect)(()=>{if(!t||0===W.length||!P.current)return;let e=P.current,n=e.querySelector(".ProseMirror");if(!n)return;let r=Array.from(n.children),i=e.getBoundingClientRect(),s=new Map;for(let t=0;t<Math.min(r.length,W.length);t++){let n=r[t],o=W[t];n.setAttribute("data-block-ref",o.ref);let a=n.getBoundingClientRect();s.set(o.ref,{top:a.top-i.top+e.scrollTop,left:a.left-i.left,width:a.width,bottom:a.bottom-i.top+e.scrollTop})}$(s)},[t,W]);let es=function(e={},t=[]){let n=(0,cO.useRef)(e);n.current=e;let[r]=(0,cO.useState)(()=>new hc(n)),i=(0,c_.useSyncExternalStore)(r.subscribe,r.getEditor,r.getServerSnapshot);return(0,cO.useDebugValue)(i),(0,cO.useEffect)(r.onRender(t)),!function(e){var t;let[n]=(0,cO.useState)(()=>new ho(e.editor)),r=(0,he.useSyncExternalStoreWithSelector)(n.subscribe,n.getSnapshot,n.getServerSnapshot,e.selector,null!=(t=e.equalityFn)?t:p7);hs(()=>n.watch(e.editor),[e.editor,n]),(0,cO.useDebugValue)(r)}({editor:i,selector:({transactionNumber:t})=>!1===e.shouldRerenderOnTransaction||void 0===e.shouldRerenderOnTransaction?null:e.immediatelyRender&&0===t?0:t+1}),i}({extensions:yC,content:"",editable:!h,onUpdate:(0,f.useCallback)(({editor:e})=>{if(M.current||A.current||!e)return;en();let t=fa(e.getHTML(),t1.getState().currentPath??void 0);t1.getState().updateContent(t)},[]),onBlur:()=>{er()},onSelectionUpdate:({editor:e})=>{ei(e)},editorProps:{attributes:{class:"focus:outline-none min-h-[calc(100vh-12rem)] px-4 sm:px-8 py-6 max-w-[var(--editor-max-w,48rem)] ml-[var(--editor-ml,auto)] mr-auto"},handleKeyDown:(e,t)=>{if((t.metaKey||t.ctrlKey)&&"a"===t.key.toLowerCase()&&lF(e.state)){let n=lB(e.state.selection.$from),r=n?.nodeAfter;if(!n||!r)return!1;let i=n.pos+1,s=n.pos+r.nodeSize-1;return(e.state.selection.from!==i||e.state.selection.to!==s)&&(t.preventDefault(),es?.chain().focus().setTextSelection({from:i,to:s}).run(),!0)}return!1},handleClick:(e,t,n)=>{let r=n.target.closest("a");if(!r)return!1;let i=r.getAttribute("href");if(!i)return!1;if("true"===r.dataset.wikiLink){n.preventDefault(),n.stopPropagation();let e=r.dataset.slug??"",t=r.dataset.anchor??null;if(!e)return!0;let i=fd.getState();if(i.has(e)){let n=i.getDir(e),r=null===n||"root"===n?`${e}.md`:`${n}/${e}.md`;t1.getState().loadPage(r),t&&setTimeout(()=>{document.querySelector(`[id="${t}"]`)?.scrollIntoView({behavior:"smooth"})},200)}else{if(A.current)return!0;E.current(e).then(e=>{if(e.ok){let t=e.dir??"entities",n=`${t}/${e.slug}.md`;t1.getState().loadPage(n)}})}return!0}if(/^https?:\/\//.test(i)||i.startsWith("/api/")||i.startsWith("mailto:")||i.startsWith("tel:"))return!1;n.preventDefault(),n.stopPropagation();let s=function(e,t,n){var r;let i;if(!e||/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("/api/"))return null;let s=e.indexOf("#"),o=s>=0?yE(e.slice(0,s)):yE(e);if(!o)return null;yj.test(o);let a=o.replace(yj,""),l=a.startsWith("/"),c=a.startsWith("./")||a.startsWith("../");if(!l&&!c&&!o.includes("/")&&!o.includes(".")&&n?.has(a)){let e=n.getDir(a);return null===e||"root"===e?`${a}.md`:`${e}/${a}.md`}if(l)i=a.replace(/^\/+/,"");else{let e=t?.includes("/")?t.slice(0,t.lastIndexOf("/")):"";i=e?`${e}/${a.replace(/^\.\/+/,"")}`:a.replace(/^\.\/+/,"")}let d=function(e){let t=e.split("/").filter(e=>e.length>0&&"."!==e),n=[];for(let e of t)if(".."===e){if(0===n.length)return null;n.pop()}else n.push(e);return n.join("/")}(i);return null===d||""===d?null:(r=d.split("/").pop()??d,/\.[^./]+$/.test(r))?d:`${d}.md`}(i,t1.getState().currentPath,fd.getState());if(s){t1.getState().loadPage(s);let e=i.includes("#")?i.slice(i.indexOf("#")+1):"";e&&setTimeout(()=>{document.querySelector(`[id="${e}"]`)?.scrollIntoView({behavior:"smooth"})},200)}return!0},handlePaste:(e,t)=>{if(A.current)return!1;let n=t.clipboardData?.files,r=t1.getState().currentPath;if(n&&n.length>0&&r){for(let e of Array.from(n))vJ(r,e).then(t=>{t&&es&&(e.type.startsWith("image/")?es.chain().focus().setImage({src:t,alt:e.name}).run():es.chain().focus().insertContent(`<a href="${t}">${e.name}</a>`).run())});return!0}return!1},handleDrop:(e,t)=>{if(A.current)return!1;let n=t.dataTransfer?.files;if(!n||0===n.length)return!1;let r=t1.getState().currentPath;if(!r)return!1;for(let e of(t.preventDefault(),Array.from(n)))vJ(r,e).then(t=>{t&&es&&(e.type.startsWith("image/")?es.chain().focus().setImage({src:t,alt:e.name}).run():es.chain().focus().insertContent(`<a href="${t}">${e.name}</a>`).run())});return!0}},immediatelyRender:!1});T.current=es,(0,f.useEffect)(()=>{es?.setEditable(!h),h&&_(!1)},[es,h]);let eo=(0,f.useRef)(null),ea=(0,f.useRef)(null),[el,ec]=(0,f.useState)(null);(0,f.useEffect)(()=>{if(!es||null===t||t1.getState().isDirty&&t===eo.current||o&&""===n)return;let e=x.body,r=`${t} ${e}`;if(ea.current===r){el!==t&&ec(t);return}eo.current=t;let i=!1;return(async()=>{M.current=!0;let n=await (0,hC.markdownToHtml)(e,h?{pagePath:t,sanitize:!0}:t);if(i||t1.getState().currentPath!==t){M.current=!1;return}es.commands.setContent(n),ea.current=r,ec(t),setTimeout(()=>{M.current=!1},50)})(),()=>{i=!0}},[es,n,t,o,el,x.body,h]),(0,f.useEffect)(()=>{if(!h||!el)return;let e=P.current;e&&e.querySelectorAll('input[type="checkbox"]').forEach(e=>{e.disabled=!0})},[h,el,x.body]);let ed=null!==t&&(o||el!==t),[eu,ep]=(0,f.useState)(!1);if((0,f.useEffect)(()=>{if(!ed)return void ep(!1);let e=setTimeout(()=>ep(!0),150);return()=>clearTimeout(e)},[ed]),null===t)return(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,s.jsxs)("div",{className:"text-center space-y-3",children:[(0,s.jsx)("p",{className:"text-lg font-medium tracking-[-0.02em]",children:"No page selected"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground/70",children:"Select a page from the sidebar or create a new one"})]})});if("missing"===a){let e=(t.split("/").pop()||t).replace(/[-_]+/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,s.jsx)("div",{className:"max-w-3xl mx-auto px-6 py-10 space-y-6",children:(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsx)("p",{className:"text-lg font-medium tracking-[-0.02em] text-foreground",children:e}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground/80",children:"This page doesn't exist yet."}),(0,s.jsxs)("button",{onClick:()=>void l(e),className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-[13px] font-medium text-primary-foreground hover:bg-primary/90 transition-colors",children:[(0,s.jsx)(ni,{className:"h-3.5 w-3.5"}),"Create page"]})]})})})}let eh=async()=>{if(O){if(t1.getState().updateContent(D),es){M.current=!0;let e=await (0,hC.markdownToHtml)(D,t??void 0);es.commands.setContent(e),setTimeout(()=>{M.current=!1},50)}_(!1)}else R(t1.getState().content),_(!0)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[!h&&(0,s.jsxs)("div",{className:"flex items-center min-w-0",children:[(0,s.jsx)("div",{className:"flex-1 min-w-0",children:!O&&(0,s.jsx)(ms,{editor:es})}),(0,s.jsxs)("button",{onClick:eh,className:`flex items-center gap-1.5 px-3 py-1 mr-2 text-[11px] rounded-md transition-colors border border-border ${O?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"}`,children:[(0,s.jsx)(r7,{className:"h-3 w-3"}),O?"Preview":"Markdown"]})]}),O?(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",dir:k?"rtl":void 0,children:(0,s.jsx)("textarea",{value:D,onChange:e=>R(e.target.value),className:"w-full h-full min-h-[calc(100vh-12rem)] bg-transparent font-mono text-[13px] leading-relaxed resize-none focus:outline-none",spellCheck:!1})}):(0,s.jsxs)("div",{className:"flex-1 relative",dir:k?"rtl":void 0,children:[b&&(0,s.jsx)("div",{className:"absolute top-0 inset-x-0 z-20 flex items-center justify-center gap-2 px-3 py-1 bg-primary/10 border-b border-primary/20 text-[11px] text-primary pointer-events-none",children:"Suggesting mode · your edits become suggestions for review"}),(0,s.jsx)(vu,{editor:es,scrollContainerRef:P}),(0,s.jsx)(vN,{editor:es,scrollContainerRef:P}),(0,s.jsxs)("div",{ref:P,className:`absolute inset-0 overflow-y-auto ${b?"pt-7":""}`,style:{"--editor-max-w":y,"--editor-ml":w},"data-editor-scroll":!0,children:[(0,s.jsxs)("div",{"aria-hidden":"true",className:"relative pointer-events-none",style:{height:0},children:[Object.entries(G).map(([e,t])=>{let n=z.get(e);return n?(0,s.jsx)("div",{style:{pointerEvents:"auto"},children:(0,s.jsx)(y_,{anchorKey:e,anchorLabel:e,comments:t,top:n.top+4,left:Math.max(0,n.left-20),onClick:()=>{let t=P.current?.querySelector(`[data-block-ref="${e}"]`);t&&Z({blockRef:e,el:t})}})},`pip-${e}`):null}),t&&K.map(e=>{let n=z.get(e.ref),r=W.find(t=>t.ref===e.ref);if(!n||!r)return null;let i="insertAfter"===e.kind?n.bottom+4:"insertBefore"===e.kind?Math.max(0,n.top-80):n.top;return(0,s.jsx)("div",{style:{pointerEvents:"auto"},children:(0,s.jsx)(y7,{path:t,suggestion:e,currentMarkdown:r.markdown,baseRevision:U,getLatestRevision:()=>fp.getState().byPath[t]?.snapshotRevision??0,top:i,left:n.left,width:n.width,onSettled:()=>{fp.getState().loadSidecar(t),fp.getState().loadSnapshot(t)},readOnly:h})},`sug-${e.id}`)})]}),J&&t&&(0,s.jsx)(y4,{path:t,anchorKey:J.blockRef,anchorRef:J.blockRef,anchorLabel:J.blockRef,comments:G[J.blockRef]??[],anchorEl:J.el,onClose:()=>Z(null),readOnly:h}),X&&t&&(0,s.jsx)(vt,{path:t,blockRef:X.blockRef,currentMarkdown:X.markdown,anchor:X.anchor,onClose:()=>Y(null)}),h&&Object.keys(x.data).length>0&&(0,s.jsx)("div",{className:"max-w-[var(--editor-max-w,48rem)] ml-[var(--editor-ml,auto)] mr-auto px-4 sm:px-8 pt-6",children:(0,s.jsx)(vK,{data:x.data})}),(0,s.jsx)(hi,{editor:es}),t&&/\.(md|markdown)$/i.test(t)&&(0,s.jsx)(vT,{currentPath:t}),(0,s.jsx)("div",{"aria-hidden":"true",className:"contents",onMouseOver:e=>{let t=e.target.closest(".proof-span");t&&t!==I&&L(t)},onMouseOut:e=>{let t=e.relatedTarget;t?.closest(".proof-span")||L(null)}}),t&&(0,s.jsx)(y6,{targetEl:I,path:t,onClose:()=>L(null),onComment:()=>{if(!I)return;let e=I.closest("[data-block-ref]");if(!e)return;let t=e.getAttribute("data-block-ref");t&&Z({blockRef:t,el:e})}}),!h&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(fV,{editor:es,onSuggestEdit:ee,onComment:et}),(0,s.jsx)(vB,{editor:es}),(0,s.jsx)(vl,{editor:es}),(0,s.jsx)(vU,{editor:es,onCreateRequest:E.current})]}),h&&(0,s.jsx)(vG,{containerRef:P,onComment:et}),(0,s.jsxs)("div",{className:"max-w-[var(--editor-max-w,48rem)] ml-[var(--editor-ml,auto)] mr-auto px-8 pb-8 flex items-center gap-4",children:[(0,s.jsxs)("button",{onClick:()=>{S(),N()},className:"group flex items-center gap-2 text-[13px] text-muted-foreground/50 hover:text-muted-foreground transition-colors cursor-pointer",children:[(0,s.jsx)(hS,{className:"h-3.5 w-3.5 group-hover:text-primary transition-colors"}),(0,s.jsx)("span",{children:"Edit with AI"})]}),!h&&(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground/30 select-none",children:[(0,s.jsx)("kbd",{className:"rounded px-1 py-0.5 font-mono text-[10px] ring-1 ring-foreground/10",children:"/"})," ","for commands"]})]})]}),eu&&(0,s.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 backdrop-blur-md z-20 pointer-events-none","aria-hidden":"true",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground/70"})})]}),!h&&(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-1 border-t border-border text-xs text-muted-foreground/60",children:[(0,s.jsxs)("span",{className:"text-[10.5px] text-muted-foreground/30 select-none hidden sm:block",children:[(0,s.jsx)("kbd",{className:"rounded px-1 font-mono text-[9.5px] ring-1 ring-foreground/10",children:"⌘S"})," ","save",(0,s.jsx)("span",{className:"mx-1.5 opacity-40",children:"·"}),(0,s.jsx)("kbd",{className:"rounded px-1 font-mono text-[9.5px] ring-1 ring-foreground/10",children:"/"})," ","commands"]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-[10.5px]",role:"radiogroup","aria-label":"Edit mode",children:[(0,s.jsx)("button",{type:"button",role:"radio","aria-checked":"editing"===c,onClick:()=>d("editing"),className:`px-2 py-0.5 transition-colors ${"editing"===c?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"}`,children:"Editing"}),(0,s.jsx)("button",{type:"button",role:"radio","aria-checked":"suggesting"===c,onClick:()=>d("suggesting"),className:`px-2 py-0.5 transition-colors ${"suggesting"===c?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"}`,children:"Suggesting"})]}),(0,s.jsxs)("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10.5px] transition-all duration-300 ${"idle"===r?"opacity-0 pointer-events-none":"opacity-100"} ${"saving"===r?"bg-muted text-muted-foreground":"saved"===r?"bg-success/10 text-success":"error"===r?"bg-destructive/10 text-destructive":""}`,children:["saving"===r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u.Loader2,{className:"h-2.5 w-2.5 animate-spin"}),"Saving…"]}),"saved"===r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-2.5 w-2.5"}),"Saved"]}),"error"===r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(m.AlertCircle,{className:"h-2.5 w-2.5"}),"Save failed"]})]})]})]})]}),j]})}function vX({path:e}){let t=(0,tE.withWs)(`/api/assets/${e}`),n=e.split("/").pop()||e,r=n.includes(".")?n.split(".").pop()?.toUpperCase():"",i=async()=>{try{await (0,tE.wsFetch)("/api/system/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}catch{}};return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(io.ViewerToolbar,{path:e,badge:r||void 0}),(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,s.jsxs)("div",{className:"flex flex-col items-center gap-4 text-center max-w-sm",children:[(0,s.jsx)("div",{className:"flex size-16 items-center justify-center rounded-2xl bg-muted",children:(0,s.jsx)(nr,{className:"size-8 text-muted-foreground/50"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:n}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"This file type can't be previewed in Cabinet."})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-2",onClick:i,children:[(0,s.jsx)(e4,{className:"h-4 w-4"}),"Open in Finder"]}),(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>{let e=document.createElement("a");e.href=t,e.download=n,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-4 w-4"}),"Download"]})]})]})})]})}let vY=(0,o.default)("file-warning",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function vQ({path:e,size:t,onOpen:n}){let r=(0,tE.withWs)(`/api/assets/${e}`),i=e.split("/").pop()||e,o=i.includes(".")?i.split(".").pop()?.toUpperCase():"",a=async()=>{try{await (0,tE.wsFetch)("/api/system/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}catch{}};return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(io.ViewerToolbar,{path:e,badge:o||void 0}),(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,s.jsxs)("div",{className:"flex flex-col items-center gap-4 text-center max-w-sm",children:[(0,s.jsx)("div",{className:"flex size-16 items-center justify-center rounded-2xl bg-amber-500/10",children:(0,s.jsx)(vY,{className:"size-8 text-amber-500"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:i}),(0,s.jsxs)("p",{className:"text-xs text-muted-foreground",children:["This file is ",t>=0x40000000?`${(t/0x40000000).toFixed(1)} GB`:t>=1048576?`${(t/1048576).toFixed(1)} MB`:t>=1024?`${Math.round(t/1024)} KB`:`${t} B`,". Opening it in the viewer may freeze the tab while it loads and renders."]})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[(0,s.jsx)(v.Button,{variant:"default",size:"sm",className:"gap-2",onClick:n,children:"Open anyway"}),(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>window.open(r,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-4 w-4"}),"Raw"]}),(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>{let e=document.createElement("a");e.href=r,e.download=i,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-4 w-4"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-2",onClick:a,children:[(0,s.jsx)(e4,{className:"h-4 w-4"}),"Open in Finder"]})]})]})})]})}function v0({path:e,title:t}){let n=(0,tE.withWs)(`/api/assets/${e}`),r=e.split("/").pop()||e,i=r.includes(".")?r.split(".").pop()?.toUpperCase():"IMG";return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:i,children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=n,e.download=r,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(n,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-auto flex items-center justify-center bg-[#1a1a1a] p-8",children:(0,s.jsx)("img",{src:n,alt:t,className:"max-w-full max-h-full object-contain rounded-md shadow-lg",style:{imageRendering:"auto"}})})]})}function v1({path:e,type:t}){let n=(0,tE.withWs)(`/api/assets/${e}`),r=e.split("/").pop()||e,i=r.includes(".")?r.split(".").pop()?.toUpperCase():t.toUpperCase();return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:i,children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=n,e.download=r,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(n,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-auto flex items-center justify-center bg-[#1a1a1a] p-8",children:"video"===t?(0,s.jsx)("video",{src:n,controls:!0,className:"max-w-full max-h-full rounded-md shadow-lg",children:"Your browser does not support the video element."}):(0,s.jsxs)("div",{className:"w-full max-w-lg space-y-4",children:[(0,s.jsx)("div",{className:"text-center text-muted-foreground text-sm",children:r}),(0,s.jsx)("audio",{src:n,controls:!0,className:"w-full",children:"Your browser does not support the audio element."})]})})]})}function v2({path:t,title:n}){let[r,i]=(0,f.useState)(""),[o,a]=(0,f.useState)(""),[l,c]=(0,f.useState)(""),[d,u]=(0,f.useState)(!0),[p,h]=(0,f.useState)(!1),[m,b]=(0,f.useState)(!1),x=(0,f.useRef)(0),y=(0,tE.withWs)(`/api/assets/${t}`);t.split("/").pop();let w=(0,f.useCallback)(async()=>{u(!0),c("");try{let t=await (0,tE.wsFetch)(y);if(!t.ok)throw Error("Failed to fetch file");let n=await t.text();i(n);let r=(await e.A(890793)).default;r.initialize({startOnLoad:!1,theme:document.documentElement.classList.contains("dark")?"dark":"default",securityLevel:"loose",suppressErrorRendering:!0}),await r.parse(n.trim());let s=`mermaid-${++x.current}`,{svg:o}=await r.render(s,n.trim());a(o)}catch(e){document.querySelectorAll('[id^="dmermaid-"], [id^="d"]:has(> .error-icon)').forEach(e=>e.remove()),c(e instanceof Error?e.message:"Failed to render diagram")}finally{u(!1)}},[y]);return(0,f.useEffect)(()=>{w()},[w]),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:t,badge:"MERMAID",children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:`h-7 gap-1.5 text-xs ${p?"bg-muted":""}`,onClick:()=>h(e=>!e),children:[p?(0,s.jsx)(rW.Eye,{className:"h-3.5 w-3.5"}):(0,s.jsx)(r7,{className:"h-3.5 w-3.5"}),p?"Diagram":"Code"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{navigator.clipboard.writeText(r),b(!0),setTimeout(()=>b(!1),2e3)},children:[m?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"}),m?"Copied":"Copy"]}),o&&(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{if(!o)return;let e=new Blob([o],{type:"image/svg+xml"}),t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=`${n}.svg`,r.click(),URL.revokeObjectURL(t)},children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"SVG"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-auto",children:d?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Rendering diagram..."}):p?(0,s.jsx)("pre",{className:"p-4 text-[13px] leading-relaxed font-mono bg-[#1e1e1e]",children:(0,s.jsx)("code",{children:r.split("\n").map((e,t)=>(0,s.jsxs)("div",{className:"flex",children:[(0,s.jsx)("span",{className:"inline-block w-12 pr-4 text-right text-[#858585] select-none shrink-0",children:t+1}),(0,s.jsx)("span",{className:"text-[#d4d4d4] flex-1",children:e||"\n"})]},t))})}):l?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-sm p-8",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,s.jsx)("div",{className:"h-10 w-10 rounded-full bg-red-500/10 flex items-center justify-center",children:(0,s.jsx)(r7,{className:"h-5 w-5 text-red-500"})}),(0,s.jsx)("p",{className:"text-red-500 font-medium",children:"Diagram syntax error"})]}),(0,s.jsx)("pre",{className:"text-muted-foreground text-xs max-w-lg text-left bg-muted rounded-md p-3 overflow-auto whitespace-pre-wrap",children:l}),(0,s.jsx)(v.Button,{variant:"outline",size:"sm",onClick:()=>h(!0),children:"View source to fix"})]}):(0,s.jsx)(yu,{svg:o,className:"w-full h-full"})})]})}var v3=e.i(790070),v5="[0-9](_*[0-9])*",v4=`\\.(${v5})`,v6="[0-9a-fA-F](_*[0-9a-fA-F])*",v9={className:"number",variants:[{begin:`(\\b(${v5})((${v4})|\\.)?|(${v4}))[eE][+-]?(${v5})[fFdD]?\\b`},{begin:`\\b(${v5})((${v4})[fFdD]?\\b|\\.([fFdD]\\b)?)`},{begin:`(${v4})[fFdD]?\\b`},{begin:`\\b(${v5})[fFdD]\\b`},{begin:`\\b0[xX]((${v6})\\.?|(${v6})?\\.(${v6}))[pP][+-]?(${v5})[fFdD]?\\b`},{begin:"\\b(0|[1-9](_*[0-9])*)[lL]?\\b"},{begin:`\\b0[xX](${v6})[lL]?\\b`},{begin:"\\b0(_*[0-7])*[lL]?\\b"},{begin:"\\b0[bB][01](_*[01])*[lL]?\\b"}],relevance:0},v7="[0-9](_*[0-9])*",v8=`\\.(${v7})`,we="[0-9a-fA-F](_*[0-9a-fA-F])*",wt={className:"number",variants:[{begin:`(\\b(${v7})((${v8})|\\.)?|(${v8}))[eE][+-]?(${v7})[fFdD]?\\b`},{begin:`\\b(${v7})((${v8})[fFdD]?\\b|\\.([fFdD]\\b)?)`},{begin:`(${v8})[fFdD]?\\b`},{begin:`\\b(${v7})[fFdD]\\b`},{begin:`\\b0[xX]((${we})\\.?|(${we})?\\.(${we}))[pP][+-]?(${v7})[fFdD]?\\b`},{begin:"\\b(0|[1-9](_*[0-9])*)[lL]?\\b"},{begin:`\\b0[xX](${we})[lL]?\\b`},{begin:"\\b0(_*[0-7])*[lL]?\\b"},{begin:"\\b0[bB][01](_*[01])*[lL]?\\b"}],relevance:0};let wn=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video","defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],wr=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),wi=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),ws=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),wo=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse(),wa=wi.concat(ws).sort().reverse(),wl=["a","abbr","address","article","aside","audio","b","blockquote","body","button","canvas","caption","cite","code","dd","del","details","dfn","div","dl","dt","em","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","html","i","iframe","img","input","ins","kbd","label","legend","li","main","mark","menu","nav","object","ol","optgroup","option","p","picture","q","quote","samp","section","select","source","span","strong","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","tr","ul","var","video","defs","g","marker","mask","pattern","svg","switch","symbol","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feImage","feMerge","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence","linearGradient","radialGradient","stop","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","textPath","tspan","foreignObject","clipPath"],wc=["any-hover","any-pointer","aspect-ratio","color","color-gamut","color-index","device-aspect-ratio","device-height","device-width","display-mode","forced-colors","grid","height","hover","inverted-colors","monochrome","orientation","overflow-block","overflow-inline","pointer","prefers-color-scheme","prefers-contrast","prefers-reduced-motion","prefers-reduced-transparency","resolution","scan","scripting","update","width","min-width","max-width","min-height","max-height"].sort().reverse(),wd=["active","any-link","blank","checked","current","default","defined","dir","disabled","drop","empty","enabled","first","first-child","first-of-type","fullscreen","future","focus","focus-visible","focus-within","has","host","host-context","hover","indeterminate","in-range","invalid","is","lang","last-child","last-of-type","left","link","local-link","not","nth-child","nth-col","nth-last-child","nth-last-col","nth-last-of-type","nth-of-type","only-child","only-of-type","optional","out-of-range","past","placeholder-shown","read-only","read-write","required","right","root","scope","target","target-within","user-invalid","valid","visited","where"].sort().reverse(),wu=["after","backdrop","before","cue","cue-region","first-letter","first-line","grammar-error","marker","part","placeholder","selection","slotted","spelling-error"].sort().reverse(),wp=["accent-color","align-content","align-items","align-self","alignment-baseline","all","anchor-name","animation","animation-composition","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-range","animation-range-end","animation-range-start","animation-timeline","animation-timing-function","appearance","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","baseline-shift","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-align","box-decoration-break","box-direction","box-flex","box-flex-group","box-lines","box-ordinal-group","box-orient","box-pack","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","contain-intrinsic-block-size","contain-intrinsic-height","contain-intrinsic-inline-size","contain-intrinsic-size","contain-intrinsic-width","container","container-name","container-type","content","content-visibility","counter-increment","counter-reset","counter-set","cue","cue-after","cue-before","cursor","cx","cy","direction","display","dominant-baseline","empty-cells","enable-background","field-sizing","fill","fill-opacity","fill-rule","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","flood-color","flood-opacity","flow","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-palette","font-size","font-size-adjust","font-smooth","font-smoothing","font-stretch","font-style","font-synthesis","font-synthesis-position","font-synthesis-small-caps","font-synthesis-style","font-synthesis-weight","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-emoji","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","glyph-orientation-horizontal","glyph-orientation-vertical","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-gap","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphenate-character","hyphenate-limit-chars","hyphens","icon","image-orientation","image-rendering","image-resolution","ime-mode","initial-letter","initial-letter-align","inline-size","inset","inset-area","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","kerning","left","letter-spacing","lighting-color","line-break","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marker","marker-end","marker-mid","marker-start","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-depth","math-shift","math-style","max-block-size","max-height","max-inline-size","max-width","min-block-size","min-height","min-inline-size","min-width","mix-blend-mode","nav-down","nav-index","nav-left","nav-right","nav-up","none","normal","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overlay","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","paint-order","pause","pause-after","pause-before","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","position-anchor","position-visibility","print-color-adjust","quotes","r","resize","rest","rest-after","rest-before","right","rotate","row-gap","ruby-align","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scroll-timeline","scroll-timeline-axis","scroll-timeline-name","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","shape-rendering","speak","speak-as","src","stop-color","stop-opacity","stroke","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-width","tab-size","table-layout","text-align","text-align-all","text-align-last","text-anchor","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","text-wrap","text-wrap-mode","text-wrap-style","timeline-scope","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-behavior","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","user-modify","user-select","vector-effect","vertical-align","view-timeline","view-timeline-axis","view-timeline-inset","view-timeline-name","view-transition-name","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","white-space","white-space-collapse","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","x","y","z-index","zoom"].sort().reverse();function wh(e){return e?"string"==typeof e?e:e.source:null}function wf(e){return wm("(?=",e,")")}function wm(...e){return e.map(e=>wh(e)).join("")}function wg(...e){let t;return"("+(("object"==typeof(t=e[e.length-1])&&t.constructor===Object?(e.splice(e.length-1,1),t):{}).capture?"":"?:")+e.map(e=>wh(e)).join("|")+")"}let wb=e=>wm(/\b/,e,/\w$/.test(e)?/\b/:/\B/),wx=["Protocol","Type"].map(wb),wy=["init","self"].map(wb),wv=["Any","Self"],ww=["actor","any","associatedtype","async","await",/as\?/,/as!/,"as","borrowing","break","case","catch","class","consume","consuming","continue","convenience","copy","default","defer","deinit","didSet","distributed","do","dynamic","each","else","enum","extension","fallthrough",/fileprivate\(set\)/,"fileprivate","final","for","func","get","guard","if","import","indirect","infix",/init\?/,/init!/,"inout",/internal\(set\)/,"internal","in","is","isolated","nonisolated","lazy","let","macro","mutating","nonmutating",/open\(set\)/,"open","operator","optional","override","package","postfix","precedencegroup","prefix",/private\(set\)/,"private","protocol",/public\(set\)/,"public","repeat","required","rethrows","return","set","some","static","struct","subscript","super","switch","throws","throw",/try\?/,/try!/,"try","typealias",/unowned\(safe\)/,/unowned\(unsafe\)/,"unowned","var","weak","where","while","willSet"],wk=["false","nil","true"],wN=["assignment","associativity","higherThan","left","lowerThan","none","right"],wS=["#colorLiteral","#column","#dsohandle","#else","#elseif","#endif","#error","#file","#fileID","#fileLiteral","#filePath","#function","#if","#imageLiteral","#keyPath","#line","#selector","#sourceLocation","#warning"],wC=["abs","all","any","assert","assertionFailure","debugPrint","dump","fatalError","getVaList","isKnownUniquelyReferenced","max","min","numericCast","pointwiseMax","pointwiseMin","precondition","preconditionFailure","print","readLine","repeatElement","sequence","stride","swap","swift_unboxFromSwiftValueWithType","transcode","type","unsafeBitCast","unsafeDowncast","withExtendedLifetime","withUnsafeMutablePointer","withUnsafePointer","withVaList","withoutActuallyEscaping","zip"],wj=wg(/[/=\-+!*%<>&|^~?]/,/[\u00A1-\u00A7]/,/[\u00A9\u00AB]/,/[\u00AC\u00AE]/,/[\u00B0\u00B1]/,/[\u00B6\u00BB\u00BF\u00D7\u00F7]/,/[\u2016-\u2017]/,/[\u2020-\u2027]/,/[\u2030-\u203E]/,/[\u2041-\u2053]/,/[\u2055-\u205E]/,/[\u2190-\u23FF]/,/[\u2500-\u2775]/,/[\u2794-\u2BFF]/,/[\u2E00-\u2E7F]/,/[\u3001-\u3003]/,/[\u3008-\u3020]/,/[\u3030]/),wE=wg(wj,/[\u0300-\u036F]/,/[\u1DC0-\u1DFF]/,/[\u20D0-\u20FF]/,/[\uFE00-\uFE0F]/,/[\uFE20-\uFE2F]/),wM=wm(wj,wE,"*"),wA=wg(/[a-zA-Z_]/,/[\u00A8\u00AA\u00AD\u00AF\u00B2-\u00B5\u00B7-\u00BA]/,/[\u00BC-\u00BE\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]/,/[\u0100-\u02FF\u0370-\u167F\u1681-\u180D\u180F-\u1DBF]/,/[\u1E00-\u1FFF]/,/[\u200B-\u200D\u202A-\u202E\u203F-\u2040\u2054\u2060-\u206F]/,/[\u2070-\u20CF\u2100-\u218F\u2460-\u24FF\u2776-\u2793]/,/[\u2C00-\u2DFF\u2E80-\u2FFF]/,/[\u3004-\u3007\u3021-\u302F\u3031-\u303F\u3040-\uD7FF]/,/[\uF900-\uFD3D\uFD40-\uFDCF\uFDF0-\uFE1F\uFE30-\uFE44]/,/[\uFE47-\uFEFE\uFF00-\uFFFD]/),wT=wg(wA,/\d/,/[\u0300-\u036F\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/),wO=wm(wA,wT,"*"),w_=wm(/[A-Z]/,wT,"*"),wD=["attached","autoclosure",wm(/convention\(/,wg("swift","block","c"),/\)/),"discardableResult","dynamicCallable","dynamicMemberLookup","escaping","freestanding","frozen","GKInspectable","IBAction","IBDesignable","IBInspectable","IBOutlet","IBSegueAction","inlinable","main","nonobjc","NSApplicationMain","NSCopying","NSManaged",wm(/objc\(/,wO,/\)/),"objc","objcMembers","propertyWrapper","requires_stored_property_inits","resultBuilder","Sendable","testable","UIApplicationMain","unchecked","unknown","usableFromInline","warn_unqualified_access"],wR=["iOS","iOSApplicationExtension","macOS","macOSApplicationExtension","macCatalyst","macCatalystApplicationExtension","watchOS","watchOSApplicationExtension","tvOS","tvOSApplicationExtension","swift"],wI={arduino:function(e){let t,n,r,i,s,o,a,l,c,d,u,p,h,f,m,g,b=(t=e.regex,n=e.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),i="[a-zA-Z_]\\w*::",s="(?!struct)("+(r="decltype\\(auto\\)")+"|"+t.optional(i)+"[a-zA-Z_]\\w*"+t.optional("<[^<>]+>")+")",o={className:"type",begin:"\\b[a-z\\d_]*_t\\b"},a={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",end:"'",illegal:"."},e.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},l={className:"number",variants:[{begin:"[+-]?(?:(?:[0-9](?:'?[0-9])*\\.(?:[0-9](?:'?[0-9])*)?|\\.[0-9](?:'?[0-9])*)(?:[Ee][+-]?[0-9](?:'?[0-9])*)?|[0-9](?:'?[0-9])*[Ee][+-]?[0-9](?:'?[0-9])*|0[Xx](?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*(?:\\.(?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)?)?|\\.[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)[Pp][+-]?[0-9](?:'?[0-9])*)(?:[Ff](?:16|32|64|128)?|(BF|bf)16|[Ll]|)"},{begin:"[+-]?\\b(?:0[Bb][01](?:'?[01])*|0[Xx][0-9A-Fa-f](?:'?[0-9A-Fa-f])*|0(?:'?[0-7])*|[1-9](?:'?[0-9])*)(?:[Uu](?:LL?|ll?)|[Uu][Zz]?|(?:LL?|ll?)[Uu]?|[Zz][Uu]|)"}],relevance:0},c={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(a,{className:"string"}),{className:"string",begin:/<.*?>/},n,e.C_BLOCK_COMMENT_MODE]},d={className:"title",begin:t.optional(i)+e.IDENT_RE,relevance:0},u=t.optional(i)+e.IDENT_RE+"\\s*\\(",m={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:p={type:["bool","char","char16_t","char32_t","char8_t","double","float","int","long","short","void","wchar_t","unsigned","signed","const","static"],keyword:["alignas","alignof","and","and_eq","asm","atomic_cancel","atomic_commit","atomic_noexcept","auto","bitand","bitor","break","case","catch","class","co_await","co_return","co_yield","compl","concept","const_cast|10","consteval","constexpr","constinit","continue","decltype","default","delete","do","dynamic_cast|10","else","enum","explicit","export","extern","false","final","for","friend","goto","if","import","inline","module","mutable","namespace","new","noexcept","not","not_eq","nullptr","operator","or","or_eq","override","private","protected","public","reflexpr","register","reinterpret_cast|10","requires","return","sizeof","static_assert","static_cast|10","struct","switch","synchronized","template","this","thread_local","throw","transaction_safe","transaction_safe_dynamic","true","try","typedef","typeid","typename","union","using","virtual","volatile","while","xor","xor_eq"],literal:["NULL","false","nullopt","nullptr","true"],built_in:["_Pragma"],_type_hints:["any","auto_ptr","barrier","binary_semaphore","bitset","complex","condition_variable","condition_variable_any","counting_semaphore","deque","false_type","flat_map","flat_set","future","imaginary","initializer_list","istringstream","jthread","latch","lock_guard","multimap","multiset","mutex","optional","ostringstream","packaged_task","pair","promise","priority_queue","queue","recursive_mutex","recursive_timed_mutex","scoped_lock","set","shared_future","shared_lock","shared_mutex","shared_timed_mutex","shared_ptr","stack","string_view","stringstream","timed_mutex","thread","true_type","tuple","unique_lock","unique_ptr","unordered_map","unordered_multimap","unordered_multiset","unordered_set","variant","vector","weak_ptr","wstring","wstring_view"]},contains:(f=[h={className:"function.dispatch",relevance:0,keywords:{_hint:["abort","abs","acos","apply","as_const","asin","atan","atan2","calloc","ceil","cerr","cin","clog","cos","cosh","cout","declval","endl","exchange","exit","exp","fabs","floor","fmod","forward","fprintf","fputs","free","frexp","fscanf","future","invoke","isalnum","isalpha","iscntrl","isdigit","isgraph","islower","isprint","ispunct","isspace","isupper","isxdigit","labs","launder","ldexp","log","log10","make_pair","make_shared","make_shared_for_overwrite","make_tuple","make_unique","malloc","memchr","memcmp","memcpy","memset","modf","move","pow","printf","putchar","puts","realloc","scanf","sin","sinh","snprintf","sprintf","sqrt","sscanf","std","stderr","stdin","stdout","strcat","strchr","strcmp","strcpy","strcspn","strlen","strncat","strncmp","strncpy","strpbrk","strrchr","strspn","strstr","swap","tan","tanh","terminate","to_underlying","tolower","toupper","vfprintf","visit","vprintf","vsprintf"]},begin:t.concat(/\b/,/(?!decltype)/,/(?!if)/,/(?!for)/,/(?!switch)/,/(?!while)/,e.IDENT_RE,t.lookahead(/(<[^<>]+>|)\s*\(/))},c,o,n,e.C_BLOCK_COMMENT_MODE,l,a]).concat([{begin:/\(/,end:/\)/,keywords:p,contains:f.concat(["self"]),relevance:0}]),relevance:0},g={className:"function",begin:"("+s+"[\\*&\\s]+)+"+u,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:p,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:p,relevance:0},{begin:u,returnBegin:!0,contains:[d],relevance:0},{begin:/::/,relevance:0},{begin:/:/,endsWithParent:!0,contains:[a,l]},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:[n,e.C_BLOCK_COMMENT_MODE,a,l,o,{begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:["self",n,e.C_BLOCK_COMMENT_MODE,a,l,o]}]},o,n,e.C_BLOCK_COMMENT_MODE,c]},{name:"C++",aliases:["cc","c++","h++","hpp","hh","hxx","cxx"],keywords:p,illegal:"</",classNameAliases:{"function.dispatch":"built_in"},contains:[].concat(m,g,h,f,[c,{begin:"\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function|flat_map|flat_set)\\s*<(?!<)",end:">",keywords:p,contains:["self",o]},{begin:e.IDENT_RE+"::",keywords:p},{match:[/\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,/\s+/,/\w+/],className:{1:"keyword",3:"title.class"}}])}),x=b.keywords;return x.type=[...x.type,"boolean","byte","word","String"],x.literal=[...x.literal,"DIGITAL_MESSAGE","FIRMATA_STRING","ANALOG_MESSAGE","REPORT_DIGITAL","REPORT_ANALOG","INPUT_PULLUP","SET_PIN_MODE","INTERNAL2V56","SYSTEM_RESET","LED_BUILTIN","INTERNAL1V1","SYSEX_START","INTERNAL","EXTERNAL","DEFAULT","OUTPUT","INPUT","HIGH","LOW"],x.built_in=[...x.built_in,"KeyboardController","MouseController","SoftwareSerial","EthernetServer","EthernetClient","LiquidCrystal","RobotControl","GSMVoiceCall","EthernetUDP","EsploraTFT","HttpClient","RobotMotor","WiFiClient","GSMScanner","FileSystem","Scheduler","GSMServer","YunClient","YunServer","IPAddress","GSMClient","GSMModem","Keyboard","Ethernet","Console","GSMBand","Esplora","Stepper","Process","WiFiUDP","GSM_SMS","Mailbox","USBHost","Firmata","PImage","Client","Server","GSMPIN","FileIO","Bridge","Serial","EEPROM","Stream","Mouse","Audio","Servo","File","Task","GPRS","WiFi","Wire","TFT","GSM","SPI","SD"],x._hints=["setup","loop","runShellCommandAsynchronously","analogWriteResolution","retrieveCallingNumber","printFirmwareVersion","analogReadResolution","sendDigitalPortPair","noListenOnLocalhost","readJoystickButton","setFirmwareVersion","readJoystickSwitch","scrollDisplayRight","getVoiceCallStatus","scrollDisplayLeft","writeMicroseconds","delayMicroseconds","beginTransmission","getSignalStrength","runAsynchronously","getAsynchronously","listenOnLocalhost","getCurrentCarrier","readAccelerometer","messageAvailable","sendDigitalPorts","lineFollowConfig","countryNameWrite","runShellCommand","readStringUntil","rewindDirectory","readTemperature","setClockDivider","readLightSensor","endTransmission","analogReference","detachInterrupt","countryNameRead","attachInterrupt","encryptionType","readBytesUntil","robotNameWrite","readMicrophone","robotNameRead","cityNameWrite","userNameWrite","readJoystickY","readJoystickX","mouseReleased","openNextFile","scanNetworks","noInterrupts","digitalWrite","beginSpeaker","mousePressed","isActionDone","mouseDragged","displayLogos","noAutoscroll","addParameter","remoteNumber","getModifiers","keyboardRead","userNameRead","waitContinue","processInput","parseCommand","printVersion","readNetworks","writeMessage","blinkVersion","cityNameRead","readMessage","setDataMode","parsePacket","isListening","setBitOrder","beginPacket","isDirectory","motorsWrite","drawCompass","digitalRead","clearScreen","serialEvent","rightToLeft","setTextSize","leftToRight","requestFrom","keyReleased","compassRead","analogWrite","interrupts","WiFiServer","disconnect","playMelody","parseFloat","autoscroll","getPINUsed","setPINUsed","setTimeout","sendAnalog","readSlider","analogRead","beginWrite","createChar","motorsStop","keyPressed","tempoWrite","readButton","subnetMask","debugPrint","macAddress","writeGreen","randomSeed","attachGPRS","readString","sendString","remotePort","releaseAll","mouseMoved","background","getXChange","getYChange","answerCall","getResult","voiceCall","endPacket","constrain","getSocket","writeJSON","getButton","available","connected","findUntil","readBytes","exitValue","readGreen","writeBlue","startLoop","IPAddress","isPressed","sendSysex","pauseMode","gatewayIP","setCursor","getOemKey","tuneWrite","noDisplay","loadImage","switchPIN","onRequest","onReceive","changePIN","playFile","noBuffer","parseInt","overflow","checkPIN","knobRead","beginTFT","bitClear","updateIR","bitWrite","position","writeRGB","highByte","writeRed","setSpeed","readBlue","noStroke","remoteIP","transfer","shutdown","hangCall","beginSMS","endWrite","attached","maintain","noCursor","checkReg","checkPUK","shiftOut","isValid","shiftIn","pulseIn","connect","println","localIP","pinMode","getIMEI","display","noBlink","process","getBand","running","beginSD","drawBMP","lowByte","setBand","release","bitRead","prepare","pointTo","readRed","setMode","noFill","remove","listen","stroke","detach","attach","noTone","exists","buffer","height","bitSet","circle","config","cursor","random","IRread","setDNS","endSMS","getKey","micros","millis","begin","print","write","ready","flush","width","isPIN","blink","clear","press","mkdir","rmdir","close","point","yield","image","BSSID","click","delay","read","text","move","peek","beep","rect","line","open","seek","fill","size","turn","stop","home","find","step","tone","sqrt","RSSI","SSID","end","bit","tan","cos","sin","pow","map","abs","max","min","get","run","put"],b.name="Arduino",b.aliases=["ino"],b.supersetOf="cpp",b},bash:xv,c:function(e){let t=e.regex,n=e.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),r="decltype\\(auto\\)",i="[a-zA-Z_]\\w*::",s="("+r+"|"+t.optional(i)+"[a-zA-Z_]\\w*"+t.optional("<[^<>]+>")+")",o={className:"type",variants:[{begin:"\\b[a-z\\d_]*_t\\b"},{match:/\batomic_[a-z]{3,6}\b/}]},a={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",end:"'",illegal:"."},e.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},l={className:"number",variants:[{match:/\b(0b[01']+)/},{match:/(-?)\b([\d']+(\.[\d']*)?|\.[\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)/},{match:/(-?)\b(0[xX][a-fA-F0-9]+(?:'[a-fA-F0-9]+)*(?:\.[a-fA-F0-9]*(?:'[a-fA-F0-9]*)*)?(?:[pP][-+]?[0-9]+)?(l|L)?(u|U)?)/},{match:/(-?)\b\d+(?:'\d+)*(?:\.\d*(?:'\d*)*)?(?:[eE][-+]?\d+)?/}],relevance:0},c={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef elifdef elifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(a,{className:"string"}),{className:"string",begin:/<.*?>/},n,e.C_BLOCK_COMMENT_MODE]},d={className:"title",begin:t.optional(i)+e.IDENT_RE,relevance:0},u=t.optional(i)+e.IDENT_RE+"\\s*\\(",p={keyword:["asm","auto","break","case","continue","default","do","else","enum","extern","for","fortran","goto","if","inline","register","restrict","return","sizeof","typeof","typeof_unqual","struct","switch","typedef","union","volatile","while","_Alignas","_Alignof","_Atomic","_Generic","_Noreturn","_Static_assert","_Thread_local","alignas","alignof","noreturn","static_assert","thread_local","_Pragma"],type:["float","double","signed","unsigned","int","short","long","char","void","_Bool","_BitInt","_Complex","_Imaginary","_Decimal32","_Decimal64","_Decimal96","_Decimal128","_Decimal64x","_Decimal128x","_Float16","_Float32","_Float64","_Float128","_Float32x","_Float64x","_Float128x","const","static","constexpr","complex","bool","imaginary"],literal:"true false NULL",built_in:"std string wstring cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set pair bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap priority_queue make_pair array shared_ptr abort terminate abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf future isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr"},h=[c,o,n,e.C_BLOCK_COMMENT_MODE,l,a],f={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:p,contains:h.concat([{begin:/\(/,end:/\)/,keywords:p,contains:h.concat(["self"]),relevance:0}]),relevance:0},m={begin:"("+s+"[\\*&\\s]+)+"+u,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:p,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:p,relevance:0},{begin:u,returnBegin:!0,contains:[e.inherit(d,{className:"title.function"})],relevance:0},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:[n,e.C_BLOCK_COMMENT_MODE,a,l,o,{begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:["self",n,e.C_BLOCK_COMMENT_MODE,a,l,o]}]},o,n,e.C_BLOCK_COMMENT_MODE,c]};return{name:"C",aliases:["h"],keywords:p,disableAutodetect:!0,illegal:"</",contains:[].concat(f,m,h,[c,{begin:e.IDENT_RE+"::",keywords:p},{className:"class",beginKeywords:"enum class struct union",end:/[{;:<>=]/,contains:[{beginKeywords:"final class struct"},e.TITLE_MODE]}]),exports:{preprocessor:c,strings:a,keywords:p}}},cpp:function(e){let t=e.regex,n=e.COMMENT("//","$",{contains:[{begin:/\\\n/}]}),r="decltype\\(auto\\)",i="[a-zA-Z_]\\w*::",s="(?!struct)("+r+"|"+t.optional(i)+"[a-zA-Z_]\\w*"+t.optional("<[^<>]+>")+")",o={className:"type",begin:"\\b[a-z\\d_]*_t\\b"},a={className:"string",variants:[{begin:'(u8?|U|L)?"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]},{begin:"(u8?|U|L)?'(\\\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4,8}|[0-7]{3}|\\S)|.)",end:"'",illegal:"."},e.END_SAME_AS_BEGIN({begin:/(?:u8?|U|L)?R"([^()\\ ]{0,16})\(/,end:/\)([^()\\ ]{0,16})"/})]},l={className:"number",variants:[{begin:"[+-]?(?:(?:[0-9](?:'?[0-9])*\\.(?:[0-9](?:'?[0-9])*)?|\\.[0-9](?:'?[0-9])*)(?:[Ee][+-]?[0-9](?:'?[0-9])*)?|[0-9](?:'?[0-9])*[Ee][+-]?[0-9](?:'?[0-9])*|0[Xx](?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*(?:\\.(?:[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)?)?|\\.[0-9A-Fa-f](?:'?[0-9A-Fa-f])*)[Pp][+-]?[0-9](?:'?[0-9])*)(?:[Ff](?:16|32|64|128)?|(BF|bf)16|[Ll]|)"},{begin:"[+-]?\\b(?:0[Bb][01](?:'?[01])*|0[Xx][0-9A-Fa-f](?:'?[0-9A-Fa-f])*|0(?:'?[0-7])*|[1-9](?:'?[0-9])*)(?:[Uu](?:LL?|ll?)|[Uu][Zz]?|(?:LL?|ll?)[Uu]?|[Zz][Uu]|)"}],relevance:0},c={className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma _Pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(a,{className:"string"}),{className:"string",begin:/<.*?>/},n,e.C_BLOCK_COMMENT_MODE]},d={className:"title",begin:t.optional(i)+e.IDENT_RE,relevance:0},u=t.optional(i)+e.IDENT_RE+"\\s*\\(",p={type:["bool","char","char16_t","char32_t","char8_t","double","float","int","long","short","void","wchar_t","unsigned","signed","const","static"],keyword:["alignas","alignof","and","and_eq","asm","atomic_cancel","atomic_commit","atomic_noexcept","auto","bitand","bitor","break","case","catch","class","co_await","co_return","co_yield","compl","concept","const_cast|10","consteval","constexpr","constinit","continue","decltype","default","delete","do","dynamic_cast|10","else","enum","explicit","export","extern","false","final","for","friend","goto","if","import","inline","module","mutable","namespace","new","noexcept","not","not_eq","nullptr","operator","or","or_eq","override","private","protected","public","reflexpr","register","reinterpret_cast|10","requires","return","sizeof","static_assert","static_cast|10","struct","switch","synchronized","template","this","thread_local","throw","transaction_safe","transaction_safe_dynamic","true","try","typedef","typeid","typename","union","using","virtual","volatile","while","xor","xor_eq"],literal:["NULL","false","nullopt","nullptr","true"],built_in:["_Pragma"],_type_hints:["any","auto_ptr","barrier","binary_semaphore","bitset","complex","condition_variable","condition_variable_any","counting_semaphore","deque","false_type","flat_map","flat_set","future","imaginary","initializer_list","istringstream","jthread","latch","lock_guard","multimap","multiset","mutex","optional","ostringstream","packaged_task","pair","promise","priority_queue","queue","recursive_mutex","recursive_timed_mutex","scoped_lock","set","shared_future","shared_lock","shared_mutex","shared_timed_mutex","shared_ptr","stack","string_view","stringstream","timed_mutex","thread","true_type","tuple","unique_lock","unique_ptr","unordered_map","unordered_multimap","unordered_multiset","unordered_set","variant","vector","weak_ptr","wstring","wstring_view"]},h={className:"function.dispatch",relevance:0,keywords:{_hint:["abort","abs","acos","apply","as_const","asin","atan","atan2","calloc","ceil","cerr","cin","clog","cos","cosh","cout","declval","endl","exchange","exit","exp","fabs","floor","fmod","forward","fprintf","fputs","free","frexp","fscanf","future","invoke","isalnum","isalpha","iscntrl","isdigit","isgraph","islower","isprint","ispunct","isspace","isupper","isxdigit","labs","launder","ldexp","log","log10","make_pair","make_shared","make_shared_for_overwrite","make_tuple","make_unique","malloc","memchr","memcmp","memcpy","memset","modf","move","pow","printf","putchar","puts","realloc","scanf","sin","sinh","snprintf","sprintf","sqrt","sscanf","std","stderr","stdin","stdout","strcat","strchr","strcmp","strcpy","strcspn","strlen","strncat","strncmp","strncpy","strpbrk","strrchr","strspn","strstr","swap","tan","tanh","terminate","to_underlying","tolower","toupper","vfprintf","visit","vprintf","vsprintf"]},begin:t.concat(/\b/,/(?!decltype)/,/(?!if)/,/(?!for)/,/(?!switch)/,/(?!while)/,e.IDENT_RE,t.lookahead(/(<[^<>]+>|)\s*\(/))},f=[h,c,o,n,e.C_BLOCK_COMMENT_MODE,l,a],m={variants:[{begin:/=/,end:/;/},{begin:/\(/,end:/\)/},{beginKeywords:"new throw return else",end:/;/}],keywords:p,contains:f.concat([{begin:/\(/,end:/\)/,keywords:p,contains:f.concat(["self"]),relevance:0}]),relevance:0},g={className:"function",begin:"("+s+"[\\*&\\s]+)+"+u,returnBegin:!0,end:/[{;=]/,excludeEnd:!0,keywords:p,illegal:/[^\w\s\*&:<>.]/,contains:[{begin:r,keywords:p,relevance:0},{begin:u,returnBegin:!0,contains:[d],relevance:0},{begin:/::/,relevance:0},{begin:/:/,endsWithParent:!0,contains:[a,l]},{relevance:0,match:/,/},{className:"params",begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:[n,e.C_BLOCK_COMMENT_MODE,a,l,o,{begin:/\(/,end:/\)/,keywords:p,relevance:0,contains:["self",n,e.C_BLOCK_COMMENT_MODE,a,l,o]}]},o,n,e.C_BLOCK_COMMENT_MODE,c]};return{name:"C++",aliases:["cc","c++","h++","hpp","hh","hxx","cxx"],keywords:p,illegal:"</",classNameAliases:{"function.dispatch":"built_in"},contains:[].concat(m,g,h,f,[c,{begin:"\\b(deque|list|queue|priority_queue|pair|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array|tuple|optional|variant|function|flat_map|flat_set)\\s*<(?!<)",end:">",keywords:p,contains:["self",o]},{begin:e.IDENT_RE+"::",keywords:p},{match:[/\b(?:enum(?:\s+(?:class|struct))?|class|struct|union)/,/\s+/,/\w+/],className:{1:"keyword",3:"title.class"}}])}},csharp:function(e){let t={keyword:["abstract","as","base","break","case","catch","class","const","continue","do","else","event","explicit","extern","finally","fixed","for","foreach","goto","if","implicit","in","interface","internal","is","lock","namespace","new","operator","out","override","params","private","protected","public","readonly","record","ref","return","scoped","sealed","sizeof","stackalloc","static","struct","switch","this","throw","try","typeof","unchecked","unsafe","using","virtual","void","volatile","while"].concat(["add","alias","and","ascending","args","async","await","by","descending","dynamic","equals","file","from","get","global","group","init","into","join","let","nameof","not","notnull","on","or","orderby","partial","record","remove","required","scoped","select","set","unmanaged","value|0","var","when","where","with","yield"]),built_in:["bool","byte","char","decimal","delegate","double","dynamic","enum","float","int","long","nint","nuint","object","sbyte","short","string","ulong","uint","ushort"],literal:["default","false","null","true"]},n=e.inherit(e.TITLE_MODE,{begin:"[a-zA-Z](\\.?\\w)*"}),r={className:"number",variants:[{begin:"\\b(0b[01']+)"},{begin:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{begin:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],relevance:0},i={className:"string",begin:'@"',end:'"',contains:[{begin:'""'}]},s=e.inherit(i,{illegal:/\n/}),o={className:"subst",begin:/\{/,end:/\}/,keywords:t},a=e.inherit(o,{illegal:/\n/}),l={className:"string",begin:/\$"/,end:'"',illegal:/\n/,contains:[{begin:/\{\{/},{begin:/\}\}/},e.BACKSLASH_ESCAPE,a]},c={className:"string",begin:/\$@"/,end:'"',contains:[{begin:/\{\{/},{begin:/\}\}/},{begin:'""'},o]},d=e.inherit(c,{illegal:/\n/,contains:[{begin:/\{\{/},{begin:/\}\}/},{begin:'""'},a]});o.contains=[c,l,i,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,r,e.C_BLOCK_COMMENT_MODE],a.contains=[d,l,s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,r,e.inherit(e.C_BLOCK_COMMENT_MODE,{illegal:/\n/})];let u={variants:[{className:"string",begin:/"""("*)(?!")(.|\n)*?"""\1/,relevance:1},c,l,i,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},p={begin:"<",end:">",contains:[{beginKeywords:"in out"},n]},h=e.IDENT_RE+"(<"+e.IDENT_RE+"(\\s*,\\s*"+e.IDENT_RE+")*>)?(\\[\\])?",f={begin:"@"+e.IDENT_RE,relevance:0};return{name:"C#",aliases:["cs","c#"],keywords:t,illegal:/::/,contains:[e.COMMENT("///","$",{returnBegin:!0,contains:[{className:"doctag",variants:[{begin:"///",relevance:0},{begin:"<!--|-->"},{begin:"</?",end:">"}]}]}),e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"meta",begin:"#",end:"$",keywords:{keyword:"if else elif endif define undef warning error line region endregion pragma checksum"}},u,r,{beginKeywords:"class interface",relevance:0,end:/[{;=]/,illegal:/[^\s:,]/,contains:[{beginKeywords:"where class"},n,p,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"namespace",relevance:0,end:/[{;=]/,illegal:/[^\s:]/,contains:[n,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"record",relevance:0,end:/[{;=]/,illegal:/[^\s:]/,contains:[n,p,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"meta",begin:"^\\s*\\[(?=[\\w])",excludeBegin:!0,end:"\\]",excludeEnd:!0,contains:[{className:"string",begin:/"/,end:/"/}]},{beginKeywords:"new return throw await else",relevance:0},{className:"function",begin:"("+h+"\\s+)+"+e.IDENT_RE+"\\s*(<[^=]+>\\s*)?\\(",returnBegin:!0,end:/\s*[{;=]/,excludeEnd:!0,keywords:t,contains:[{beginKeywords:"public private protected static internal protected abstract async extern override unsafe virtual new sealed partial",relevance:0},{begin:e.IDENT_RE+"\\s*(<[^=]+>\\s*)?\\(",returnBegin:!0,contains:[e.TITLE_MODE,p],relevance:0},{match:/\(\)/},{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:t,relevance:0,contains:[u,r,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},f]}},css:xj,diff:function(e){let t=e.regex;return{name:"Diff",aliases:["patch"],contains:[{className:"meta",relevance:10,match:t.either(/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,/^\*\*\* +\d+,\d+ +\*\*\*\*$/,/^--- +\d+,\d+ +----$/)},{className:"comment",variants:[{begin:t.either(/Index: /,/^index/,/={3,}/,/^-{3}/,/^\*{3} /,/^\+{3}/,/^diff --git/),end:/$/},{match:/^\*{15}$/}]},{className:"addition",begin:/^\+/,end:/$/},{className:"deletion",begin:/^-/,end:/$/},{className:"addition",begin:/^!/,end:/$/}]}},go:xE,graphql:function(e){let t=e.regex;return{name:"GraphQL",aliases:["gql"],case_insensitive:!0,disableAutodetect:!1,keywords:{keyword:["query","mutation","subscription","type","input","schema","directive","interface","union","scalar","fragment","enum","on"],literal:["true","false","null"]},contains:[e.HASH_COMMENT_MODE,e.QUOTE_STRING_MODE,e.NUMBER_MODE,{scope:"punctuation",match:/[.]{3}/,relevance:0},{scope:"punctuation",begin:/[\!\(\)\:\=\[\]\{\|\}]{1}/,relevance:0},{scope:"variable",begin:/\$/,end:/\W/,excludeEnd:!0,relevance:0},{scope:"meta",match:/@\w+/,excludeEnd:!0},{scope:"symbol",begin:t.concat(/[_A-Za-z][_0-9A-Za-z]*/,t.lookahead(/\s*:/)),relevance:0}],illegal:[/[;<']/,/BEGIN/]}},ini:function(e){let t=e.regex,n={className:"number",relevance:0,variants:[{begin:/([+-]+)?[\d]+_[\d_]+/},{begin:e.NUMBER_RE}]},r=e.COMMENT();r.variants=[{begin:/;/,end:/$/},{begin:/#/,end:/$/}];let i={className:"variable",variants:[{begin:/\$[\w\d"][\w\d_]*/},{begin:/\$\{(.*?)\}/}]},s={className:"literal",begin:/\bon|off|true|false|yes|no\b/},o={className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{begin:"'''",end:"'''",relevance:10},{begin:'"""',end:'"""',relevance:10},{begin:'"',end:'"'},{begin:"'",end:"'"}]},a=t.either(/[A-Za-z0-9_-]+/,/"(\\"|[^"])*"/,/'[^']*'/);return{name:"TOML, also INI",aliases:["toml"],case_insensitive:!0,illegal:/\S/,contains:[r,{className:"section",begin:/\[+/,end:/\]+/},{begin:t.concat(a,"(\\s*\\.\\s*",a,")*",t.lookahead(/\s*=\s*[^#\s]/)),className:"attr",starts:{end:/$/,contains:[r,{begin:/\[/,end:/\]/,contains:[r,s,i,o,n,"self"],relevance:0},s,i,o,n]}}]}},java:function(e){let t=e.regex,n="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",r=n+function e(t,n,r){return -1===r?"":t.replace(n,i=>e(t,n,r-1))}("(?:<"+n+"~~~(?:\\s*,\\s*"+n+"~~~)*>)?",/~~~/g,2),i={keyword:["synchronized","abstract","private","var","static","if","const ","for","while","strictfp","finally","protected","import","native","final","void","enum","else","break","transient","catch","instanceof","volatile","case","assert","package","default","public","try","switch","continue","throws","protected","public","private","module","requires","exports","do","sealed","yield","permits","goto","when"],literal:["false","true","null"],type:["char","boolean","long","float","int","byte","short","double"],built_in:["super","this"]},s={className:"meta",begin:"@"+n,contains:[{begin:/\(/,end:/\)/,contains:["self"]}]},o={className:"params",begin:/\(/,end:/\)/,keywords:i,relevance:0,contains:[e.C_BLOCK_COMMENT_MODE],endsParent:!0};return{name:"Java",aliases:["jsp"],keywords:i,illegal:/<\/|#/,contains:[e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{begin:/\w+@/,relevance:0},{className:"doctag",begin:"@[A-Za-z]+"}]}),{begin:/import java\.[a-z]+\./,keywords:"import",relevance:2},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{begin:/"""/,end:/"""/,className:"string",contains:[e.BACKSLASH_ESCAPE]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{match:[/\b(?:class|interface|enum|extends|implements|new)/,/\s+/,n],className:{1:"keyword",3:"title.class"}},{match:/non-sealed/,scope:"keyword"},{begin:[t.concat(/(?!else)/,n),/\s+/,n,/\s+/,/=(?!=)/],className:{1:"type",3:"variable",5:"operator"}},{begin:[/record/,/\s+/,n],className:{1:"keyword",3:"title.class"},contains:[o,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"new throw return else",relevance:0},{begin:["(?:"+r+"\\s+)",e.UNDERSCORE_IDENT_RE,/\s*(?=\()/],className:{2:"title.function"},keywords:i,contains:[{className:"params",begin:/\(/,end:/\)/,keywords:i,relevance:0,contains:[s,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,v9,e.C_BLOCK_COMMENT_MODE]},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},v9,s]}},javascript:xL,json:xP,kotlin:function(e){let t={keyword:"abstract as val var vararg get set class object open private protected public noinline crossinline dynamic final enum if else do while for when throw try catch finally import package is in fun override companion reified inline lateinit init interface annotation data sealed internal infix operator out by constructor super tailrec where const inner suspend typealias external expect actual",built_in:"Byte Short Char Int Long Boolean Float Double Void Unit Nothing",literal:"true false null"},n={className:"symbol",begin:e.UNDERSCORE_IDENT_RE+"@"},r={className:"subst",begin:/\$\{/,end:/\}/,contains:[e.C_NUMBER_MODE]},i={className:"variable",begin:"\\$"+e.UNDERSCORE_IDENT_RE},s={className:"string",variants:[{begin:'"""',end:'"""(?=[^"])',contains:[i,r]},{begin:"'",end:"'",illegal:/\n/,contains:[e.BACKSLASH_ESCAPE]},{begin:'"',end:'"',illegal:/\n/,contains:[e.BACKSLASH_ESCAPE,i,r]}]};r.contains.push(s);let o={className:"meta",begin:"@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*"+e.UNDERSCORE_IDENT_RE+")?"},a={className:"meta",begin:"@"+e.UNDERSCORE_IDENT_RE,contains:[{begin:/\(/,end:/\)/,contains:[e.inherit(s,{className:"string"}),"self"]}]},l=e.COMMENT("/\\*","\\*/",{contains:[e.C_BLOCK_COMMENT_MODE]}),c={variants:[{className:"type",begin:e.UNDERSCORE_IDENT_RE},{begin:/\(/,end:/\)/,contains:[]}]};return c.variants[1].contains=[c],c.variants[1].contains=[c],{name:"Kotlin",aliases:["kt","kts"],keywords:t,contains:[e.COMMENT("/\\*\\*","\\*/",{relevance:0,contains:[{className:"doctag",begin:"@[A-Za-z]+"}]}),e.C_LINE_COMMENT_MODE,l,{className:"keyword",begin:/\b(break|continue|return|this)\b/,starts:{contains:[{className:"symbol",begin:/@\w+/}]}},n,o,a,{className:"function",beginKeywords:"fun",end:"[(]|$",returnBegin:!0,excludeEnd:!0,keywords:t,relevance:5,contains:[{begin:e.UNDERSCORE_IDENT_RE+"\\s*\\(",returnBegin:!0,relevance:0,contains:[e.UNDERSCORE_TITLE_MODE]},{className:"type",begin:/</,end:/>/,keywords:"reified",relevance:0},{className:"params",begin:/\(/,end:/\)/,endsParent:!0,keywords:t,relevance:0,contains:[{begin:/:/,end:/[=,\/]/,endsWithParent:!0,contains:[c,e.C_LINE_COMMENT_MODE,l],relevance:0},e.C_LINE_COMMENT_MODE,l,o,a,s,e.C_NUMBER_MODE]},l]},{begin:[/class|interface|trait/,/\s+/,e.UNDERSCORE_IDENT_RE],beginScope:{3:"title.class"},keywords:"class interface trait",end:/[:\{(]|$/,excludeEnd:!0,illegal:"extends implements",contains:[{beginKeywords:"public protected internal private constructor"},e.UNDERSCORE_TITLE_MODE,{className:"type",begin:/</,end:/>/,excludeBegin:!0,excludeEnd:!0,relevance:0},{className:"type",begin:/[,:]\s*/,end:/[<\(,){\s]|$/,excludeBegin:!0,returnEnd:!0},o,a]},s,{className:"meta",begin:"^#!/usr/bin/env",end:"$",illegal:"\n"},wt]}},less:function(e){let t={IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:e.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:e.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}},n="[\\w-]+",r="("+n+"|@\\{"+n+"\\})",i=[],s=[],o=function(e){return{className:"string",begin:"~?"+e+".*?"+e}},a=function(e,t,n){return{className:e,begin:t,relevance:n}},l={$pattern:/[a-z-]+/,keyword:"and or not only",attribute:wr.join(" ")};s.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,o("'"),o('"'),t.CSS_NUMBER_MODE,{begin:"(url|data-uri)\\(",starts:{className:"string",end:"[\\)\\n]",excludeEnd:!0}},t.HEXCOLOR,{begin:"\\(",end:"\\)",contains:s,keywords:l,relevance:0},a("variable","@@?"+n,10),a("variable","@\\{"+n+"\\}"),a("built_in","~?`[^`]*?`"),{className:"attribute",begin:n+"\\s*:",end:":",returnBegin:!0,excludeEnd:!0},t.IMPORTANT,{beginKeywords:"and not"},t.FUNCTION_DISPATCH);let c=s.concat({begin:/\{/,end:/\}/,contains:i}),d={beginKeywords:"when",endsWithParent:!0,contains:[{beginKeywords:"and not"}].concat(s)},u={begin:r+"\\s*:",returnBegin:!0,end:/[;}]/,relevance:0,contains:[{begin:/-(webkit|moz|ms|o)-/},t.CSS_VARIABLE,{className:"attribute",begin:"\\b("+wo.join("|")+")\\b",end:/(?=:)/,starts:{endsWithParent:!0,illegal:"[<=$]",relevance:0,contains:s}}]},p={variants:[{begin:"[\\.#:&\\[>]",end:"[;{}]"},{begin:r,end:/\{/}],returnBegin:!0,returnEnd:!0,illegal:"[<='$\"]",relevance:0,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,d,a("keyword","all\\b"),a("variable","@\\{"+n+"\\}"),{begin:"\\b("+wn.join("|")+")\\b",className:"selector-tag"},t.CSS_NUMBER_MODE,a("selector-tag",r,0),a("selector-id","#"+r),a("selector-class","\\."+r,0),a("selector-tag","&",0),t.ATTRIBUTE_SELECTOR_MODE,{className:"selector-pseudo",begin:":("+wi.join("|")+")"},{className:"selector-pseudo",begin:":(:)?("+ws.join("|")+")"},{begin:/\(/,end:/\)/,relevance:0,contains:c},{begin:"!important"},t.FUNCTION_DISPATCH]},h={begin:n+":(:)?"+`(${wa.join("|")})`,returnBegin:!0,contains:[p]};return i.push(e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,{className:"keyword",begin:"@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b",starts:{end:"[;{}]",keywords:l,returnEnd:!0,contains:s,relevance:0}},{className:"variable",variants:[{begin:"@"+n+"\\s*:",relevance:15},{begin:"@"+n}],starts:{end:"[;}]",returnEnd:!0,contains:c}},h,u,p,d,t.FUNCTION_DISPATCH),{name:"Less",case_insensitive:!0,illegal:"[=>'/<($\"]",contains:i}},lua:function(e){let t="\\[=*\\[",n="\\]=*\\]",r={begin:t,end:n,contains:["self"]},i=[e.COMMENT("--(?!"+t+")","$"),e.COMMENT("--"+t,n,{contains:[r],relevance:10})];return{name:"Lua",aliases:["pluto"],keywords:{$pattern:e.UNDERSCORE_IDENT_RE,literal:"true false nil",keyword:"and break do else elseif end for goto if in local not or repeat return then until while",built_in:"_G _ENV _VERSION __index __newindex __mode __call __metatable __tostring __len __gc __add __sub __mul __div __mod __pow __concat __unm __eq __lt __le assert collectgarbage dofile error getfenv getmetatable ipairs load loadfile loadstring module next pairs pcall print rawequal rawget rawset require select setfenv setmetatable tonumber tostring type unpack xpcall arg self coroutine resume yield status wrap create running debug getupvalue debug sethook getmetatable gethook setmetatable setlocal traceback setfenv getinfo setupvalue getlocal getregistry getfenv io lines write close flush open output type read stderr stdin input stdout popen tmpfile math log max acos huge ldexp pi cos tanh pow deg tan cosh sinh random randomseed frexp ceil floor rad abs sqrt modf asin min mod fmod log10 atan2 exp sin atan os exit setlocale date getenv difftime remove time clock tmpname rename execute package preload loadlib loaded loaders cpath config path seeall string sub upper len gfind rep find match char dump gmatch reverse byte format gsub lower table setn insert getn foreachi maxn foreach concat sort remove"},contains:i.concat([{className:"function",beginKeywords:"function",end:"\\)",contains:[e.inherit(e.TITLE_MODE,{begin:"([_a-zA-Z]\\w*\\.)*([_a-zA-Z]\\w*:)?[_a-zA-Z]\\w*"}),{className:"params",begin:"\\(",endsWithParent:!0,contains:i}].concat(i)},e.C_NUMBER_MODE,e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,{className:"string",begin:t,end:n,contains:[r],relevance:5}])}},makefile:function(e){let t={className:"variable",variants:[{begin:"\\$\\("+e.UNDERSCORE_IDENT_RE+"\\)",contains:[e.BACKSLASH_ESCAPE]},{begin:/\$[@%<?\^\+\*]/}]},n={className:"string",begin:/"/,end:/"/,contains:[e.BACKSLASH_ESCAPE,t]},r={begin:"^"+e.UNDERSCORE_IDENT_RE+"\\s*(?=[:+?]?=)"};return{name:"Makefile",aliases:["mk","mak","make"],keywords:{$pattern:/[\w-]+/,keyword:"define endef undefine ifdef ifndef ifeq ifneq else endif include -include sinclude override export unexport private vpath"},contains:[e.HASH_COMMENT_MODE,t,n,{className:"variable",begin:/\$\([\w-]+\s/,end:/\)/,keywords:{built_in:"subst patsubst strip findstring filter filter-out sort word wordlist firstword lastword dir notdir suffix basename addsuffix addprefix join wildcard realpath abspath error warning shell origin flavor foreach if or and call eval file value"},contains:[t,n]},r,{className:"meta",begin:/^\.PHONY:/,end:/$/,keywords:{$pattern:/[\.\w]+/,keyword:".PHONY"}},{className:"section",begin:/^[^\s]+:/,end:/$/,contains:[t]}]}},markdown:xz,objectivec:function(e){let t=/[a-zA-Z@][a-zA-Z0-9_]*/,n={$pattern:t,keyword:["@interface","@class","@protocol","@implementation"]};return{name:"Objective-C",aliases:["mm","objc","obj-c","obj-c++","objective-c++"],keywords:{"variable.language":["this","super"],$pattern:t,keyword:["while","export","sizeof","typedef","const","struct","for","union","volatile","static","mutable","if","do","return","goto","enum","else","break","extern","asm","case","default","register","explicit","typename","switch","continue","inline","readonly","assign","readwrite","self","@synchronized","id","typeof","nonatomic","IBOutlet","IBAction","strong","weak","copy","in","out","inout","bycopy","byref","oneway","__strong","__weak","__block","__autoreleasing","@private","@protected","@public","@try","@property","@end","@throw","@catch","@finally","@autoreleasepool","@synthesize","@dynamic","@selector","@optional","@required","@encode","@package","@import","@defs","@compatibility_alias","__bridge","__bridge_transfer","__bridge_retained","__bridge_retain","__covariant","__contravariant","__kindof","_Nonnull","_Nullable","_Null_unspecified","__FUNCTION__","__PRETTY_FUNCTION__","__attribute__","getter","setter","retain","unsafe_unretained","nonnull","nullable","null_unspecified","null_resettable","class","instancetype","NS_DESIGNATED_INITIALIZER","NS_UNAVAILABLE","NS_REQUIRES_SUPER","NS_RETURNS_INNER_POINTER","NS_INLINE","NS_AVAILABLE","NS_DEPRECATED","NS_ENUM","NS_OPTIONS","NS_SWIFT_UNAVAILABLE","NS_ASSUME_NONNULL_BEGIN","NS_ASSUME_NONNULL_END","NS_REFINED_FOR_SWIFT","NS_SWIFT_NAME","NS_SWIFT_NOTHROW","NS_DURING","NS_HANDLER","NS_ENDHANDLER","NS_VALUERETURN","NS_VOIDRETURN"],literal:["false","true","FALSE","TRUE","nil","YES","NO","NULL"],built_in:["dispatch_once_t","dispatch_queue_t","dispatch_sync","dispatch_async","dispatch_once"],type:["int","float","char","unsigned","signed","short","long","double","wchar_t","unichar","void","bool","BOOL","id|0","_Bool"]},illegal:"</",contains:[{className:"built_in",begin:"\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.C_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,{className:"string",variants:[{begin:'@"',end:'"',illegal:"\\n",contains:[e.BACKSLASH_ESCAPE]}]},{className:"meta",begin:/#\s*[a-z]+\b/,end:/$/,keywords:{keyword:"if else elif endif define undef warning error line pragma ifdef ifndef include"},contains:[{begin:/\\\n/,relevance:0},e.inherit(e.QUOTE_STRING_MODE,{className:"string"}),{className:"string",begin:/<.*?>/,end:/$/,illegal:"\\n"},e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{className:"class",begin:"("+n.keyword.join("|")+")\\b",end:/(\{|$)/,excludeEnd:!0,keywords:n,contains:[e.UNDERSCORE_TITLE_MODE]},{begin:"\\."+e.UNDERSCORE_IDENT_RE,relevance:0}]}},perl:function(e){let t=e.regex,n=/[dualxmsipngr]{0,12}/,r={$pattern:/[\w.]+/,keyword:"abs accept alarm and atan2 bind binmode bless break caller chdir chmod chomp chop chown chr chroot class close closedir connect continue cos crypt dbmclose dbmopen defined delete die do dump each else elsif endgrent endhostent endnetent endprotoent endpwent endservent eof eval exec exists exit exp fcntl field fileno flock for foreach fork format formline getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr getnetbyname getnetent getpeername getpgrp getpriority getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid getservbyname getservbyport getservent getsockname getsockopt given glob gmtime goto grep gt hex if index int ioctl join keys kill last lc lcfirst length link listen local localtime log lstat lt ma map method mkdir msgctl msgget msgrcv msgsnd my ne next no not oct open opendir or ord our pack package pipe pop pos print printf prototype push q|0 qq quotemeta qw qx rand read readdir readline readlink readpipe recv redo ref rename require reset return reverse rewinddir rindex rmdir say scalar seek seekdir select semctl semget semop send setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent setservent setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split sprintf sqrt srand stat state study sub substr symlink syscall sysopen sysread sysseek system syswrite tell telldir tie tied time times tr truncate uc ucfirst umask undef unless unlink unpack unshift untie until use utime values vec wait waitpid wantarray warn when while write x|0 xor y|0"},i={className:"subst",begin:"[$@]\\{",end:"\\}",keywords:r},s={begin:/->\{/,end:/\}/},o={scope:"attr",match:/\s+:\s*\w+(\s*\(.*?\))?/},a={scope:"variable",variants:[{begin:/\$\d/},{begin:t.concat(/[$%@](?!")(\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,"(?![A-Za-z])(?![@$%])")},{begin:/[$%@](?!")[^\s\w{=]|\$=/,relevance:0}],contains:[o]},l={className:"number",variants:[{match:/0?\.[0-9][0-9_]+\b/},{match:/\bv?(0|[1-9][0-9_]*(\.[0-9_]+)?|[1-9][0-9_]*)\b/},{match:/\b0[0-7][0-7_]*\b/},{match:/\b0x[0-9a-fA-F][0-9a-fA-F_]*\b/},{match:/\b0b[0-1][0-1_]*\b/}],relevance:0},c=[e.BACKSLASH_ESCAPE,i,a],d=[/!/,/\//,/\|/,/\?/,/'/,/"/,/#/],u=(e,r,i="\\1")=>{let s="\\1"===i?i:t.concat(i,r);return t.concat(t.concat("(?:",e,")"),r,/(?:\\.|[^\\\/])*?/,s,/(?:\\.|[^\\\/])*?/,i,n)},p=(e,r,i)=>t.concat(t.concat("(?:",e,")"),r,/(?:\\.|[^\\\/])*?/,i,n),h=[a,e.HASH_COMMENT_MODE,e.COMMENT(/^=\w/,/=cut/,{endsWithParent:!0}),s,{className:"string",contains:c,variants:[{begin:"q[qwxr]?\\s*\\(",end:"\\)",relevance:5},{begin:"q[qwxr]?\\s*\\[",end:"\\]",relevance:5},{begin:"q[qwxr]?\\s*\\{",end:"\\}",relevance:5},{begin:"q[qwxr]?\\s*\\|",end:"\\|",relevance:5},{begin:"q[qwxr]?\\s*<",end:">",relevance:5},{begin:"qw\\s+q",end:"q",relevance:5},{begin:"'",end:"'",contains:[e.BACKSLASH_ESCAPE]},{begin:'"',end:'"'},{begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE]},{begin:/\{\w+\}/,relevance:0},{begin:"-?\\w+\\s*=>",relevance:0}]},l,{begin:"(\\/\\/|"+e.RE_STARTERS_RE+"|\\b(split|return|print|reverse|grep)\\b)\\s*",keywords:"split return print reverse grep",relevance:0,contains:[e.HASH_COMMENT_MODE,{className:"regexp",variants:[{begin:u("s|tr|y",t.either(...d,{capture:!0}))},{begin:u("s|tr|y","\\(","\\)")},{begin:u("s|tr|y","\\[","\\]")},{begin:u("s|tr|y","\\{","\\}")}],relevance:2},{className:"regexp",variants:[{begin:/(m|qr)\/\//,relevance:0},{begin:p("(?:m|qr)?",/\//,/\//)},{begin:p("m|qr",t.either(...d,{capture:!0}),/\1/)},{begin:p("m|qr",/\(/,/\)/)},{begin:p("m|qr",/\[/,/\]/)},{begin:p("m|qr",/\{/,/\}/)}]}]},{className:"function",beginKeywords:"sub method",end:"(\\s*\\(.*?\\))?[;{]",excludeEnd:!0,relevance:5,contains:[e.TITLE_MODE,o]},{className:"class",beginKeywords:"class",end:"[;{]",excludeEnd:!0,relevance:5,contains:[e.TITLE_MODE,o,l]},{begin:"-\\w\\b",relevance:0},{begin:"^__DATA__$",end:"^__END__$",subLanguage:"mojolicious",contains:[{begin:"^@@.*",end:"$",className:"comment"}]}];return i.contains=h,s.contains=h,{name:"Perl",aliases:["pl","pm"],keywords:r,contains:h}},php:function(e){let t,n=e.regex,r=/(?![A-Za-z0-9])(?![$])/,i=n.concat(/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/,r),s=n.concat(/(\\?[A-Z][a-z0-9_\x7f-\xff]+|\\?[A-Z]+(?=[A-Z][a-z0-9_\x7f-\xff])){1,}/,r),o=n.concat(/[A-Z]+/,r),a={scope:"variable",match:"\\$+"+i},l={scope:"subst",variants:[{begin:/\$\w+/},{begin:/\{\$/,end:/\}/}]},c=e.inherit(e.APOS_STRING_MODE,{illegal:null}),d=e.inherit(e.QUOTE_STRING_MODE,{illegal:null,contains:e.QUOTE_STRING_MODE.contains.concat(l)}),u={begin:/<<<[ \t]*(?:(\w+)|"(\w+)")\n/,end:/[ \t]*(\w+)\b/,contains:e.QUOTE_STRING_MODE.contains.concat(l),"on:begin":(e,t)=>{t.data._beginMatch=e[1]||e[2]},"on:end":(e,t)=>{t.data._beginMatch!==e[1]&&t.ignoreMatch()}},p=e.END_SAME_AS_BEGIN({begin:/<<<[ \t]*'(\w+)'\n/,end:/[ \t]*(\w+)\b/}),h="[ \n]",f={scope:"string",variants:[d,c,u,p]},m={scope:"number",variants:[{begin:"\\b0[bB][01]+(?:_[01]+)*\\b"},{begin:"\\b0[oO][0-7]+(?:_[0-7]+)*\\b"},{begin:"\\b0[xX][\\da-fA-F]+(?:_[\\da-fA-F]+)*\\b"},{begin:"(?:\\b\\d+(?:_\\d+)*(\\.(?:\\d+(?:_\\d+)*))?|\\B\\.\\d+)(?:[eE][+-]?\\d+)?"}],relevance:0},g=["false","null","true"],b=["__CLASS__","__DIR__","__FILE__","__FUNCTION__","__COMPILER_HALT_OFFSET__","__LINE__","__METHOD__","__NAMESPACE__","__TRAIT__","die","echo","exit","include","include_once","print","require","require_once","array","abstract","and","as","binary","bool","boolean","break","callable","case","catch","class","clone","const","continue","declare","default","do","double","else","elseif","empty","enddeclare","endfor","endforeach","endif","endswitch","endwhile","enum","eval","extends","final","finally","float","for","foreach","from","global","goto","if","implements","instanceof","insteadof","int","integer","interface","isset","iterable","list","match|0","mixed","new","never","object","or","private","protected","public","readonly","real","return","string","switch","throw","trait","try","unset","use","var","void","while","xor","yield"],x=["Error|0","AppendIterator","ArgumentCountError","ArithmeticError","ArrayIterator","ArrayObject","AssertionError","BadFunctionCallException","BadMethodCallException","CachingIterator","CallbackFilterIterator","CompileError","Countable","DirectoryIterator","DivisionByZeroError","DomainException","EmptyIterator","ErrorException","Exception","FilesystemIterator","FilterIterator","GlobIterator","InfiniteIterator","InvalidArgumentException","IteratorIterator","LengthException","LimitIterator","LogicException","MultipleIterator","NoRewindIterator","OutOfBoundsException","OutOfRangeException","OuterIterator","OverflowException","ParentIterator","ParseError","RangeException","RecursiveArrayIterator","RecursiveCachingIterator","RecursiveCallbackFilterIterator","RecursiveDirectoryIterator","RecursiveFilterIterator","RecursiveIterator","RecursiveIteratorIterator","RecursiveRegexIterator","RecursiveTreeIterator","RegexIterator","RuntimeException","SeekableIterator","SplDoublyLinkedList","SplFileInfo","SplFileObject","SplFixedArray","SplHeap","SplMaxHeap","SplMinHeap","SplObjectStorage","SplObserver","SplPriorityQueue","SplQueue","SplStack","SplSubject","SplTempFileObject","TypeError","UnderflowException","UnexpectedValueException","UnhandledMatchError","ArrayAccess","BackedEnum","Closure","Fiber","Generator","Iterator","IteratorAggregate","Serializable","Stringable","Throwable","Traversable","UnitEnum","WeakReference","WeakMap","Directory","__PHP_Incomplete_Class","parent","php_user_filter","self","static","stdClass"],y={keyword:b,literal:(t=[],g.forEach(e=>{t.push(e),e.toLowerCase()===e?t.push(e.toUpperCase()):t.push(e.toLowerCase())}),t),built_in:x},v=e=>e.map(e=>e.replace(/\|\d+$/,"")),w={variants:[{match:[/new/,n.concat(h,"+"),n.concat("(?!",v(x).join("\\b|"),"\\b)"),s],scope:{1:"keyword",4:"title.class"}}]},k=n.concat(i,"\\b(?!\\()"),N={variants:[{match:[n.concat(/::/,n.lookahead(/(?!class\b)/)),k],scope:{2:"variable.constant"}},{match:[/::/,/class/],scope:{2:"variable.language"}},{match:[s,n.concat(/::/,n.lookahead(/(?!class\b)/)),k],scope:{1:"title.class",3:"variable.constant"}},{match:[s,n.concat("::",n.lookahead(/(?!class\b)/))],scope:{1:"title.class"}},{match:[s,/::/,/class/],scope:{1:"title.class",3:"variable.language"}}]},S={scope:"attr",match:n.concat(i,n.lookahead(":"),n.lookahead(/(?!::)/))},C={relevance:0,begin:/\(/,end:/\)/,keywords:y,contains:[S,a,N,e.C_BLOCK_COMMENT_MODE,f,m,w]},j={relevance:0,match:[/\b/,n.concat("(?!fn\\b|function\\b|",v(b).join("\\b|"),"|",v(x).join("\\b|"),"\\b)"),i,n.concat(h,"*"),n.lookahead(/(?=\()/)],scope:{3:"title.function.invoke"},contains:[C]};C.contains.push(j);let E=[S,N,e.C_BLOCK_COMMENT_MODE,f,m,w],M={begin:n.concat(/#\[\s*\\?/,n.either(s,o)),beginScope:"meta",end:/]/,endScope:"meta",keywords:{literal:g,keyword:["new","array"]},contains:[{begin:/\[/,end:/]/,keywords:{literal:g,keyword:["new","array"]},contains:["self",...E]},...E,{scope:"meta",variants:[{match:s},{match:o}]}]};return{case_insensitive:!1,keywords:y,contains:[M,e.HASH_COMMENT_MODE,e.COMMENT("//","$"),e.COMMENT("/\\*","\\*/",{contains:[{scope:"doctag",match:"@[A-Za-z]+"}]}),{match:/__halt_compiler\(\);/,keywords:"__halt_compiler",starts:{scope:"comment",end:e.MATCH_NOTHING_RE,contains:[{match:/\?>/,scope:"meta",endsParent:!0}]}},{scope:"meta",variants:[{begin:/<\?php/,relevance:10},{begin:/<\?=/},{begin:/<\?/,relevance:.1},{begin:/\?>/}]},{scope:"variable.language",match:/\$this\b/},a,j,N,{match:[/const/,/\s/,i],scope:{1:"keyword",3:"variable.constant"}},w,{scope:"function",relevance:0,beginKeywords:"fn function",end:/[;{]/,excludeEnd:!0,illegal:"[$%\\[]",contains:[{beginKeywords:"use"},e.UNDERSCORE_TITLE_MODE,{begin:"=>",endsParent:!0},{scope:"params",begin:"\\(",end:"\\)",excludeBegin:!0,excludeEnd:!0,keywords:y,contains:["self",M,a,N,e.C_BLOCK_COMMENT_MODE,f,m]}]},{scope:"class",variants:[{beginKeywords:"enum",illegal:/[($"]/},{beginKeywords:"class interface trait",illegal:/[:($"]/}],relevance:0,end:/\{/,excludeEnd:!0,contains:[{beginKeywords:"extends implements"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"namespace",relevance:0,end:";",illegal:/[.']/,contains:[e.inherit(e.UNDERSCORE_TITLE_MODE,{scope:"title.class"})]},{beginKeywords:"use",relevance:0,end:";",contains:[{match:/\b(as|const|function)\b/,scope:"keyword"},e.UNDERSCORE_TITLE_MODE]},f,m]}},"php-template":function(e){return{name:"PHP template",subLanguage:"xml",contains:[{begin:/<\?(php|=)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},e.inherit(e.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]}]}},plaintext:function(e){return{name:"Plain text",aliases:["text","txt"],disableAutodetect:!0}},python:x$,"python-repl":function(e){return{aliases:["pycon"],contains:[{className:"meta.prompt",starts:{end:/ |$/,starts:{end:"$",subLanguage:"python"}},variants:[{begin:/^>>>(?=[ ]|$)/},{begin:/^\.\.\.(?=[ ]|$)/}]}]}},r:function(e){let t=e.regex,n=/(?:(?:[a-zA-Z]|\.[._a-zA-Z])[._a-zA-Z0-9]*)|\.(?!\d)/,r=t.either(/0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*[pP][+-]?\d+i?/,/0[xX][0-9a-fA-F]+(?:[pP][+-]?\d+)?[Li]?/,/(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?[Li]?/),i=/[=!<>:]=|\|\||&&|:::?|<-|<<-|->>|->|\|>|[-+*\/?!$&|:<=>@^~]|\*\*/,s=t.either(/[()]/,/[{}]/,/\[\[/,/[[\]]/,/\\/,/,/);return{name:"R",keywords:{$pattern:n,keyword:"function if in break next repeat else for while",literal:"NULL NA TRUE FALSE Inf NaN NA_integer_|10 NA_real_|10 NA_character_|10 NA_complex_|10",built_in:"LETTERS letters month.abb month.name pi T F abs acos acosh all any anyNA Arg as.call as.character as.complex as.double as.environment as.integer as.logical as.null.default as.numeric as.raw asin asinh atan atanh attr attributes baseenv browser c call ceiling class Conj cos cosh cospi cummax cummin cumprod cumsum digamma dim dimnames emptyenv exp expression floor forceAndCall gamma gc.time globalenv Im interactive invisible is.array is.atomic is.call is.character is.complex is.double is.environment is.expression is.finite is.function is.infinite is.integer is.language is.list is.logical is.matrix is.na is.name is.nan is.null is.numeric is.object is.pairlist is.raw is.recursive is.single is.symbol lazyLoadDBfetch length lgamma list log max min missing Mod names nargs nzchar oldClass on.exit pos.to.env proc.time prod quote range Re rep retracemem return round seq_along seq_len seq.int sign signif sin sinh sinpi sqrt standardGeneric substitute sum switch tan tanh tanpi tracemem trigamma trunc unclass untracemem UseMethod xtfrm"},contains:[e.COMMENT(/#'/,/$/,{contains:[{scope:"doctag",match:/@examples/,starts:{end:t.lookahead(t.either(/\n^#'\s*(?=@[a-zA-Z]+)/,/\n^(?!#')/)),endsParent:!0}},{scope:"doctag",begin:"@param",end:/$/,contains:[{scope:"variable",variants:[{match:n},{match:/`(?:\\.|[^`\\])+`/}],endsParent:!0}]},{scope:"doctag",match:/@[a-zA-Z]+/},{scope:"keyword",match:/\\[a-zA-Z]+/}]}),e.HASH_COMMENT_MODE,{scope:"string",contains:[e.BACKSLASH_ESCAPE],variants:[e.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\(/,end:/\)(-*)"/}),e.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\{/,end:/\}(-*)"/}),e.END_SAME_AS_BEGIN({begin:/[rR]"(-*)\[/,end:/\](-*)"/}),e.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\(/,end:/\)(-*)'/}),e.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\{/,end:/\}(-*)'/}),e.END_SAME_AS_BEGIN({begin:/[rR]'(-*)\[/,end:/\](-*)'/}),{begin:'"',end:'"',relevance:0},{begin:"'",end:"'",relevance:0}]},{relevance:0,variants:[{scope:{1:"operator",2:"number"},match:[i,r]},{scope:{1:"operator",2:"number"},match:[/%[^%]*%/,r]},{scope:{1:"punctuation",2:"number"},match:[s,r]},{scope:{2:"number"},match:[/[^a-zA-Z0-9._]|^/,r]}]},{scope:{3:"operator"},match:[n,/\s+/,/<-/,/\s+/]},{scope:"operator",relevance:0,variants:[{match:i},{match:/%[^%]*%/}]},{scope:"punctuation",relevance:0,match:s},{begin:"`",end:"`",contains:[{begin:/\\./}]}]}},ruby:function(e){let t=e.regex,n="([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)",r=t.either(/\b([A-Z]+[a-z0-9]+)+/,/\b([A-Z]+[a-z0-9]+)+[A-Z]+/),i=t.concat(r,/(::\w+)*/),s={"variable.constant":["__FILE__","__LINE__","__ENCODING__"],"variable.language":["self","super"],keyword:["alias","and","begin","BEGIN","break","case","class","defined","do","else","elsif","end","END","ensure","for","if","in","module","next","not","or","redo","require","rescue","retry","return","then","undef","unless","until","when","while","yield","include","extend","prepend","public","private","protected","raise","throw"],built_in:["proc","lambda","attr_accessor","attr_reader","attr_writer","define_method","private_constant","module_function"],literal:["true","false","nil"]},o={className:"doctag",begin:"@[A-Za-z]+"},a={begin:"#<",end:">"},l=[e.COMMENT("#","$",{contains:[o]}),e.COMMENT("^=begin","^=end",{contains:[o],relevance:10}),e.COMMENT("^__END__",e.MATCH_NOTHING_RE)],c={className:"subst",begin:/#\{/,end:/\}/,keywords:s},d={className:"string",contains:[e.BACKSLASH_ESCAPE,c],variants:[{begin:/'/,end:/'/},{begin:/"/,end:/"/},{begin:/`/,end:/`/},{begin:/%[qQwWx]?\(/,end:/\)/},{begin:/%[qQwWx]?\[/,end:/\]/},{begin:/%[qQwWx]?\{/,end:/\}/},{begin:/%[qQwWx]?</,end:/>/},{begin:/%[qQwWx]?\//,end:/\//},{begin:/%[qQwWx]?%/,end:/%/},{begin:/%[qQwWx]?-/,end:/-/},{begin:/%[qQwWx]?\|/,end:/\|/},{begin:/\B\?(\\\d{1,3})/},{begin:/\B\?(\\x[A-Fa-f0-9]{1,2})/},{begin:/\B\?(\\u\{?[A-Fa-f0-9]{1,6}\}?)/},{begin:/\B\?(\\M-\\C-|\\M-\\c|\\c\\M-|\\M-|\\C-\\M-)[\x20-\x7e]/},{begin:/\B\?\\(c|C-)[\x20-\x7e]/},{begin:/\B\?\\?\S/},{begin:t.concat(/<<[-~]?'?/,t.lookahead(/(\w+)(?=\W)[^\n]*\n(?:[^\n]*\n)*?\s*\1\b/)),contains:[e.END_SAME_AS_BEGIN({begin:/(\w+)/,end:/(\w+)/,contains:[e.BACKSLASH_ESCAPE,c]})]}]},u="[0-9](_?[0-9])*",p={className:"number",relevance:0,variants:[{begin:`\\b([1-9](_?[0-9])*|0)(\\.(${u}))?([eE][+-]?(${u})|r)?i?\\b`},{begin:"\\b0[dD][0-9](_?[0-9])*r?i?\\b"},{begin:"\\b0[bB][0-1](_?[0-1])*r?i?\\b"},{begin:"\\b0[oO][0-7](_?[0-7])*r?i?\\b"},{begin:"\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*r?i?\\b"},{begin:"\\b0(_?[0-7])+r?i?\\b"}]},h={variants:[{match:/\(\)/},{className:"params",begin:/\(/,end:/(?=\))/,excludeBegin:!0,endsParent:!0,keywords:s}]},f=[d,{variants:[{match:[/class\s+/,i,/\s+<\s+/,i]},{match:[/\b(class|module)\s+/,i]}],scope:{2:"title.class",4:"title.class.inherited"},keywords:s},{match:[/(include|extend)\s+/,i],scope:{2:"title.class"},keywords:s},{relevance:0,match:[i,/\.new[. (]/],scope:{1:"title.class"}},{relevance:0,match:/\b[A-Z][A-Z_0-9]+\b/,className:"variable.constant"},{relevance:0,match:r,scope:"title.class"},{match:[/def/,/\s+/,n],scope:{1:"keyword",3:"title.function"},contains:[h]},{begin:e.IDENT_RE+"::"},{className:"symbol",begin:e.UNDERSCORE_IDENT_RE+"(!|\\?)?:",relevance:0},{className:"symbol",begin:":(?!\\s)",contains:[d,{begin:n}],relevance:0},p,{className:"variable",begin:"(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])(?![A-Za-z])(?![@$?'])"},{className:"params",begin:/\|(?!=)/,end:/\|/,excludeBegin:!0,excludeEnd:!0,relevance:0,keywords:s},{begin:"("+e.RE_STARTERS_RE+"|unless)\\s*",keywords:"unless",contains:[{className:"regexp",contains:[e.BACKSLASH_ESCAPE,c],illegal:/\n/,variants:[{begin:"/",end:"/[a-z]*"},{begin:/%r\{/,end:/\}[a-z]*/},{begin:"%r\\(",end:"\\)[a-z]*"},{begin:"%r!",end:"![a-z]*"},{begin:"%r\\[",end:"\\][a-z]*"}]}].concat(a,l),relevance:0}].concat(a,l);c.contains=f,h.contains=f;let m=[{begin:/^\s*=>/,starts:{end:"$",contains:f}},{className:"meta.prompt",begin:"^([>?]>|[\\w#]+\\(\\w+\\):\\d+:\\d+[>*]|(\\w+-)?\\d+\\.\\d+\\.\\d+(p\\d+)?[^\\d][^>]+>)(?=[ ])",starts:{end:"$",keywords:s,contains:f}}];return l.unshift(a),{name:"Ruby",aliases:["rb","gemspec","podspec","thor","irb"],keywords:s,illegal:/\/\*/,contains:[e.SHEBANG({binary:"ruby"})].concat(m).concat(l).concat(f)}},rust:xB,scss:function(e){let t={IMPORTANT:{scope:"meta",begin:"!important"},BLOCK_COMMENT:e.C_BLOCK_COMMENT_MODE,HEXCOLOR:{scope:"number",begin:/#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/},FUNCTION_DISPATCH:{className:"built_in",begin:/[\w-]+(?=\()/},ATTRIBUTE_SELECTOR_MODE:{scope:"selector-attr",begin:/\[/,end:/\]/,illegal:"$",contains:[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]},CSS_NUMBER_MODE:{scope:"number",begin:e.NUMBER_RE+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",relevance:0},CSS_VARIABLE:{className:"attr",begin:/--[A-Za-z_][A-Za-z0-9_-]*/}},n="@[a-z-]+",r={className:"variable",begin:"(\\$[a-zA-Z-][a-zA-Z0-9_-]*)\\b",relevance:0};return{name:"SCSS",case_insensitive:!0,illegal:"[=/|']",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,t.CSS_NUMBER_MODE,{className:"selector-id",begin:"#[A-Za-z0-9_-]+",relevance:0},{className:"selector-class",begin:"\\.[A-Za-z0-9_-]+",relevance:0},t.ATTRIBUTE_SELECTOR_MODE,{className:"selector-tag",begin:"\\b("+wl.join("|")+")\\b",relevance:0},{className:"selector-pseudo",begin:":("+wd.join("|")+")"},{className:"selector-pseudo",begin:":(:)?("+wu.join("|")+")"},r,{begin:/\(/,end:/\)/,contains:[t.CSS_NUMBER_MODE]},t.CSS_VARIABLE,{className:"attribute",begin:"\\b("+wp.join("|")+")\\b"},{begin:"\\b(whitespace|wait|w-resize|visible|vertical-text|vertical-ideographic|uppercase|upper-roman|upper-alpha|underline|transparent|top|thin|thick|text|text-top|text-bottom|tb-rl|table-header-group|table-footer-group|sw-resize|super|strict|static|square|solid|small-caps|separate|se-resize|scroll|s-resize|rtl|row-resize|ridge|right|repeat|repeat-y|repeat-x|relative|progress|pointer|overline|outside|outset|oblique|nowrap|not-allowed|normal|none|nw-resize|no-repeat|no-drop|newspaper|ne-resize|n-resize|move|middle|medium|ltr|lr-tb|lowercase|lower-roman|lower-alpha|loose|list-item|line|line-through|line-edge|lighter|left|keep-all|justify|italic|inter-word|inter-ideograph|inside|inset|inline|inline-block|inherit|inactive|ideograph-space|ideograph-parenthesis|ideograph-numeric|ideograph-alpha|horizontal|hidden|help|hand|groove|fixed|ellipsis|e-resize|double|dotted|distribute|distribute-space|distribute-letter|distribute-all-lines|disc|disabled|default|decimal|dashed|crosshair|collapse|col-resize|circle|char|center|capitalize|break-word|break-all|bottom|both|bolder|bold|block|bidi-override|below|baseline|auto|always|all-scroll|absolute|table|table-cell)\\b"},{begin:/:/,end:/[;}{]/,relevance:0,contains:[t.BLOCK_COMMENT,r,t.HEXCOLOR,t.CSS_NUMBER_MODE,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,t.IMPORTANT,t.FUNCTION_DISPATCH]},{begin:"@(page|font-face)",keywords:{$pattern:n,keyword:"@page @font-face"}},{begin:"@",end:"[{;]",returnBegin:!0,keywords:{$pattern:/[a-z-]+/,keyword:"and or not only",attribute:wc.join(" ")},contains:[{begin:n,className:"keyword"},{begin:/[a-z-]+(?=:)/,className:"attribute"},r,e.QUOTE_STRING_MODE,e.APOS_STRING_MODE,t.HEXCOLOR,t.CSS_NUMBER_MODE]},t.FUNCTION_DISPATCH]}},shell:xF,sql:xH,swift:function(e){let t={match:/\s+/,relevance:0},n=e.COMMENT("/\\*","\\*/",{contains:["self"]}),r=[e.C_LINE_COMMENT_MODE,n],i={match:[/\./,wg(...wx,...wy)],className:{2:"keyword"}},s={match:wm(/\./,wg(...ww)),relevance:0},o=ww.filter(e=>"string"==typeof e).concat(["_|0"]),a={variants:[{className:"keyword",match:wg(...ww.filter(e=>"string"!=typeof e).concat(wv).map(wb),...wy)}]},l={$pattern:wg(/\b\w+/,/#\w+/),keyword:o.concat(wS),literal:wk},c=[i,s,a],d=[{match:wm(/\./,wg(...wC)),relevance:0},{className:"built_in",match:wm(/\b/,wg(...wC),/(?=\()/)}],u={match:/->/,relevance:0},p=[u,{className:"operator",relevance:0,variants:[{match:wM},{match:`\\.(\\.|${wE})+`}]}],h="([0-9]_*)+",f="([0-9a-fA-F]_*)+",m={className:"number",relevance:0,variants:[{match:`\\b(${h})(\\.(${h}))?([eE][+-]?(${h}))?\\b`},{match:`\\b0x(${f})(\\.(${f}))?([pP][+-]?(${h}))?\\b`},{match:/\b0o([0-7]_*)+\b/},{match:/\b0b([01]_*)+\b/}]},g=(e="")=>({className:"subst",variants:[{match:wm(/\\/,e,/[0\\tnr"']/)},{match:wm(/\\/,e,/u\{[0-9a-fA-F]{1,8}\}/)}]}),b=(e="")=>({className:"subst",label:"interpol",begin:wm(/\\/,e,/\(/),end:/\)/}),x=(e="")=>({begin:wm(e,/"""/),end:wm(/"""/,e),contains:[g(e),((e="")=>({className:"subst",match:wm(/\\/,e,/[\t ]*(?:[\r\n]|\r\n)/)}))(e),b(e)]}),y=(e="")=>({begin:wm(e,/"/),end:wm(/"/,e),contains:[g(e),b(e)]}),v={className:"string",variants:[x(),x("#"),x("##"),x("###"),y(),y("#"),y("##"),y("###")]},w=[e.BACKSLASH_ESCAPE,{begin:/\[/,end:/\]/,relevance:0,contains:[e.BACKSLASH_ESCAPE]}],k=e=>{let t=wm(e,/\//),n=wm(/\//,e);return{begin:t,end:n,contains:[...w,{scope:"comment",begin:`#(?!.*${n})`,end:/$/}]}},N={scope:"regexp",variants:[k("###"),k("##"),k("#"),{begin:/\/[^\s](?=[^/\n]*\/)/,end:/\//,contains:w}]},S={match:wm(/`/,wO,/`/)},C=[S,{className:"variable",match:/\$\d+/},{className:"variable",match:`\\$${wT}+`}],j=[{match:/(@|#(un)?)available/,scope:"keyword",starts:{contains:[{begin:/\(/,end:/\)/,keywords:wR,contains:[...p,m,v]}]}},{scope:"keyword",match:wm(/@/,wg(...wD),wf(wg(/\(/,/\s+/)))},{scope:"meta",match:wm(/@/,wO)}],E={match:wf(/\b[A-Z]/),relevance:0,contains:[{className:"type",match:wm(/(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)/,wT,"+")},{className:"type",match:w_,relevance:0},{match:/[?!]+/,relevance:0},{match:/\.\.\./,relevance:0},{match:wm(/\s+&\s+/,wf(w_)),relevance:0}]},M={begin:/</,end:/>/,keywords:l,contains:[...r,...c,...j,u,E]};E.contains.push(M);let A={begin:/\(/,end:/\)/,relevance:0,keywords:l,contains:["self",{match:wm(wO,/\s*:/),keywords:"_|0",relevance:0},...r,N,...c,...d,...p,m,v,...C,...j,E]},T={begin:/</,end:/>/,keywords:"repeat each",contains:[...r,E]},O={begin:/\(/,end:/\)/,keywords:l,contains:[{begin:wg(wf(wm(wO,/\s*:/)),wf(wm(wO,/\s+/,wO,/\s*:/))),end:/:/,relevance:0,contains:[{className:"keyword",match:/\b_\b/},{className:"params",match:wO}]},...r,...c,...p,m,v,...j,E,A],endsParent:!0,illegal:/["']/},_={match:[/(func|macro)/,/\s+/,wg(S.match,wO,wM)],className:{1:"keyword",3:"title.function"},contains:[T,O,t],illegal:[/\[/,/%/]},D={begin:[/precedencegroup/,/\s+/,w_],className:{1:"keyword",3:"title"},contains:[E],keywords:[...wN,...wk],end:/}/},R={begin:[/(struct|protocol|class|extension|enum|actor)/,/\s+/,wO,/\s*/],beginScope:{1:"keyword",3:"title.class"},keywords:l,contains:[T,...c,{begin:/:/,end:/\{/,keywords:l,contains:[{scope:"title.class.inherited",match:w_},...c],relevance:0}]};for(let e of v.variants){let t=e.contains.find(e=>"interpol"===e.label);t.keywords=l;let n=[...c,...d,...p,m,v,...C];t.contains=[...n,{begin:/\(/,end:/\)/,contains:["self",...n]}]}return{name:"Swift",keywords:l,contains:[...r,_,{match:[/\b(?:subscript|init[?!]?)/,/\s*(?=[<(])/],className:{1:"keyword"},contains:[T,O,t],illegal:/\[|%/},{match:[/class\b/,/\s+/,/func\b/,/\s+/,/\b[A-Za-z_][A-Za-z0-9_]*\b/],scope:{1:"keyword",3:"keyword",5:"title.function"}},{match:[/class\b/,/\s+/,/var\b/],scope:{1:"keyword",3:"keyword"}},R,{match:[/operator/,/\s+/,wM],className:{1:"keyword",3:"title"}},D,{beginKeywords:"import",end:/$/,contains:[...r],relevance:0},N,...c,...d,...p,m,v,...C,...j,E,A]}},typescript:xX,vbnet:function(e){let t=e.regex,n=/\d{1,2}\/\d{1,2}\/\d{4}/,r=/\d{4}-\d{1,2}-\d{1,2}/,i=/(\d|1[012])(:\d+){0,2} *(AM|PM)/,s=/\d{1,2}(:\d{1,2}){1,2}/,o={className:"literal",variants:[{begin:t.concat(/# */,t.either(r,n),/ *#/)},{begin:t.concat(/# */,s,/ *#/)},{begin:t.concat(/# */,i,/ *#/)},{begin:t.concat(/# */,t.either(r,n),/ +/,t.either(i,s),/ *#/)}]},a=e.COMMENT(/'''/,/$/,{contains:[{className:"doctag",begin:/<\/?/,end:/>/}]}),l=e.COMMENT(null,/$/,{variants:[{begin:/'/},{begin:/([\t ]|^)REM(?=\s)/}]});return{name:"Visual Basic .NET",aliases:["vb"],case_insensitive:!0,classNameAliases:{label:"symbol"},keywords:{keyword:"addhandler alias aggregate ansi as async assembly auto binary by byref byval call case catch class compare const continue custom declare default delegate dim distinct do each equals else elseif end enum erase error event exit explicit finally for friend from function get global goto group handles if implements imports in inherits interface into iterator join key let lib loop me mid module mustinherit mustoverride mybase myclass namespace narrowing new next notinheritable notoverridable of off on operator option optional order overloads overridable overrides paramarray partial preserve private property protected public raiseevent readonly redim removehandler resume return select set shadows shared skip static step stop structure strict sub synclock take text then throw to try unicode until using when where while widening with withevents writeonly yield",built_in:"addressof and andalso await directcast gettype getxmlnamespace is isfalse isnot istrue like mod nameof new not or orelse trycast typeof xor cbool cbyte cchar cdate cdbl cdec cint clng cobj csbyte cshort csng cstr cuint culng cushort",type:"boolean byte char date decimal double integer long object sbyte short single string uinteger ulong ushort",literal:"true false nothing"},illegal:"//|\\{|\\}|endif|gosub|variant|wend|^\\$ ",contains:[{className:"string",begin:/"(""|[^/n])"C\b/},{className:"string",begin:/"/,end:/"/,illegal:/\n/,contains:[{begin:/""/}]},o,{className:"number",relevance:0,variants:[{begin:/\b\d[\d_]*((\.[\d_]+(E[+-]?[\d_]+)?)|(E[+-]?[\d_]+))[RFD@!#]?/},{begin:/\b\d[\d_]*((U?[SIL])|[%&])?/},{begin:/&H[\dA-F_]+((U?[SIL])|[%&])?/},{begin:/&O[0-7_]+((U?[SIL])|[%&])?/},{begin:/&B[01_]+((U?[SIL])|[%&])?/}]},{className:"label",begin:/^\w+:/},a,l,{className:"meta",begin:/[\t ]*#(const|disable|else|elseif|enable|end|externalsource|if|region)\b/,end:/$/,keywords:{keyword:"const disable else elseif enable end externalsource if region then"},contains:[l]}]}},wasm:function(e){e.regex;let t=e.COMMENT(/\(;/,/;\)/);return t.contains.push("self"),{name:"WebAssembly",keywords:{$pattern:/[\w.]+/,keyword:["anyfunc","block","br","br_if","br_table","call","call_indirect","data","drop","elem","else","end","export","func","global.get","global.set","local.get","local.set","local.tee","get_global","get_local","global","if","import","local","loop","memory","memory.grow","memory.size","module","mut","nop","offset","param","result","return","select","set_global","set_local","start","table","tee_local","then","type","unreachable"]},contains:[e.COMMENT(/;;/,/$/),t,{match:[/(?:offset|align)/,/\s*/,/=/],className:{1:"keyword",3:"operator"}},{className:"variable",begin:/\$[\w_]+/},{match:/(\((?!;)|\))+/,className:"punctuation",relevance:0},{begin:[/(?:func|call|call_indirect)/,/\s+/,/\$[^\s)]+/],className:{1:"keyword",3:"title.function"}},e.QUOTE_STRING_MODE,{match:/(i32|i64|f32|f64)(?!\.)/,className:"type"},{className:"keyword",match:/\b(f32|f64|i32|i64)(?:\.(?:abs|add|and|ceil|clz|const|convert_[su]\/i(?:32|64)|copysign|ctz|demote\/f64|div(?:_[su])?|eqz?|extend_[su]\/i32|floor|ge(?:_[su])?|gt(?:_[su])?|le(?:_[su])?|load(?:(?:8|16|32)_[su])?|lt(?:_[su])?|max|min|mul|nearest|neg?|or|popcnt|promote\/f32|reinterpret\/[fi](?:32|64)|rem_[su]|rot[lr]|shl|shr_[su]|store(?:8|16|32)?|sqrt|sub|trunc(?:_[su]\/f(?:32|64))?|wrap\/i64|xor))\b/},{className:"number",relevance:0,match:/[+-]?\b(?:\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?|0x[\da-fA-F](?:_?[\da-fA-F])*(?:\.[\da-fA-F](?:_?[\da-fA-D])*)?(?:[pP][+-]?\d(?:_?\d)*)?)\b|\binf\b|\bnan(?::0x[\da-fA-F](?:_?[\da-fA-D])*)?\b/}]}},xml:xY,yaml:xQ},wL=x3(wI);function wP(e){return Array.isArray(e)?e.join(""):e??""}let wz=/\x1b\[[0-9;]*[A-Za-z]/g;function w$(e){return e.replace(wz,"")}function wB({output:e}){if("stream"===e.output_type){let t=w$(wP(e.text)),n="stderr"===e.name;return(0,s.jsx)("pre",{className:`whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md ${n?"bg-[rgba(139,46,62,0.06)] text-[#8B2E3E]":"bg-[#F5EEDC] text-[#2A221B]"}`,children:t})}if("error"===e.output_type){let t=e.traceback.map(w$).join("\n");return(0,s.jsxs)("pre",{className:"whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md bg-[rgba(139,46,62,0.08)] text-[#8B2E3E] border border-[rgba(139,46,62,0.18)]",children:[(0,s.jsxs)("span",{className:"font-semibold",children:[e.ename,": ",e.evalue]}),t?`
169
169
 
170
- ${t}`:""]})}let t=e.data||{};if(t["image/png"]){let e=`data:image/png;base64,${wP(t["image/png"]).replace(/\s/g,"")}`;return(0,s.jsx)("img",{src:e,alt:"output",className:"max-w-full rounded-md bg-card p-2"})}if(t["image/jpeg"]){let e=`data:image/jpeg;base64,${wP(t["image/jpeg"]).replace(/\s/g,"")}`;return(0,s.jsx)("img",{src:e,alt:"output",className:"max-w-full rounded-md bg-card p-2"})}if(t["image/svg+xml"]){let e=wP(t["image/svg+xml"]);return(0,s.jsx)("div",{className:"max-w-full rounded-md bg-card p-2 overflow-auto",dangerouslySetInnerHTML:{__html:e}})}if(t["text/html"]){let e=wP(t["text/html"]);return(0,s.jsx)("iframe",{srcDoc:`<!doctype html><html><head><base target="_blank"><style>body{margin:0;padding:8px;font-family:-apple-system,BlinkMacSystemFont,Inter,system-ui,sans-serif;background:#FFF9E9;color:#2A221B;font-size:13px}table{border-collapse:collapse}th,td{border:1px solid #D4C4B0;padding:4px 8px;text-align:left}thead{background:#EFE5CC}</style></head><body>${e}</body></html>`,sandbox:"allow-scripts",className:"w-full bg-[#FFF9E9] rounded-md border border-[#E8DDC5]",style:{height:360}})}return t["text/plain"]?(0,s.jsx)("pre",{className:"whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md bg-[#F5EEDC] text-[#2A221B]",children:w$(wP(t["text/plain"]))}):null}function wF({cell:e,language:t}){let n=wP(e.source),r=(0,f.useMemo)(()=>(function(e,t){try{let n=t?wL.highlight(t,e):wL.highlightAuto(e);return(0,v3.toHtml)(n)}catch{return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}})(n,t),[n,t]),i=e.execution_count??" ",o=(e.outputs?.length??0)>0;return(0,s.jsxs)("div",{className:"grid grid-cols-[60px_1fr] gap-3 mb-5",children:[(0,s.jsxs)("div",{className:"text-right pt-3 select-none font-mono text-[11px] text-[#8B5E3C]",children:["In [",i,"]:"]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("pre",{className:"whitespace-pre overflow-x-auto font-mono text-[13px] leading-relaxed px-4 py-3 rounded-md bg-[#FFF9E9] border border-[#E8DDC5] text-[#2A221B]",children:(0,s.jsx)("code",{dangerouslySetInnerHTML:{__html:r}})}),o&&(0,s.jsxs)("div",{className:"mt-2 grid grid-cols-[60px_1fr] gap-3",children:[(0,s.jsxs)("div",{className:"text-right pt-3 select-none font-mono text-[11px] text-[#8B2E3E]",children:["Out[",i,"]:"]}),(0,s.jsx)("div",{className:"space-y-2",children:e.outputs?.map((e,t)=>(0,s.jsx)(wB,{output:e},t))})]})]})]})}function wH({cell:e}){let[t,n]=(0,f.useState)("");return(0,f.useEffect)(()=>{let t=!1;return(0,hC.markdownToHtml)(wP(e.source)).then(e=>{t||n(e)}),()=>{t=!0}},[e.source]),(0,s.jsx)("div",{className:"prose prose-sm max-w-none mb-5 px-1 [&_h1]:font-serif [&_h2]:font-serif [&_h3]:font-serif [&_a]:text-[#8B5E3C] [&_a:hover]:underline [&_code]:bg-[#F5EEDC] [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-[#8B2E3E]",dangerouslySetInnerHTML:{__html:t}})}function wU({cell:e}){return(0,s.jsx)("pre",{className:"whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md bg-[#F5EEDC] text-[#2A221B] mb-5",children:wP(e.source)})}function wV({path:e}){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(!0),[o,a]=(0,f.useState)(null),[l,c]=(0,f.useState)(!1),d=(0,tE.withWs)(`/api/assets/${e}`),u=e.split("/").pop()||e,p=(0,f.useCallback)(async()=>{i(!0),a(null);try{let e=await (0,tE.wsFetch)(d);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();n(t)}catch(e){a(e instanceof Error?e.message:"Failed to load notebook")}finally{i(!1)}},[d]);(0,f.useEffect)(()=>{p()},[p]);let h=t?.metadata?.language_info?.name||t?.metadata?.kernelspec?.name||"python",b=t?.cells?.length??0,x=t?.cells?.filter(e=>"code"===e.cell_type).length??0,y=t?.cells?.some(e=>"code"===e.cell_type&&(e.outputs?.length??0)>0)??!1;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:"IPYNB",sublabel:`${b} cells \xb7 ${x} code \xb7 ${h}`,children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{navigator.clipboard.writeText(`jupyter lab ${e}`),c(!0),setTimeout(()=>c(!1),2e3)},title:"Copy: jupyter lab <path>",children:[l?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"}),l?"Copied":"Copy run cmd"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=d,e.download=u,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(d,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Raw JSON"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-auto bg-[#F5EEDC]",children:r?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-[#7A6B5D] text-sm",children:"Loading notebook…"}):o?(0,s.jsxs)("div",{className:"flex items-center justify-center h-full text-[#8B2E3E] text-sm gap-2",children:[(0,s.jsx)(m.AlertCircle,{className:"h-4 w-4"})," ",o]}):t?(0,s.jsxs)("div",{className:"max-w-[1100px] mx-auto py-8 px-6",children:[!y&&x>0&&(0,s.jsxs)("div",{className:"mb-6 rounded-md border border-[#E8DDC5] bg-[#FFF9E9] px-4 py-3 text-[13px] text-[#7A6B5D]",children:[(0,s.jsx)("span",{className:"font-semibold text-[#0c0a09]",children:"This notebook hasn't been run yet."})," ","Code and markdown cells display below; outputs appear once the author runs the notebook in Jupyter (or you do, then re-save)."]}),t.cells?.map((e,t)=>"markdown"===e.cell_type?(0,s.jsx)(wH,{cell:e},t):"raw"===e.cell_type?(0,s.jsx)(wU,{cell:e},t):(0,s.jsx)(wF,{cell:e,language:h},t))]}):null})]})}function wW({path:e,extLabel:t,external:n,hideFinder:r}){let i=(0,tE.withWs)(`/api/assets/${e}`),o=e.split("/").pop()||e,a=async()=>{try{await (0,tE.wsFetch)("/api/system/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}catch{}};return(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:t||void 0,children:[n&&(0,s.jsxs)("a",{href:n.href,target:"_blank",rel:"noreferrer noopener",className:"inline-flex items-center gap-1.5 text-[11px] h-7 px-2.5 rounded-md border border-border hover:bg-accent transition-colors",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),n.label]}),!r&&(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-1.5 text-[11px] h-7",onClick:a,title:"Open in Finder",children:[(0,s.jsx)(e4,{className:"h-3.5 w-3.5"}),"Reveal"]}),!r&&(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-1.5 text-[11px] h-7",onClick:()=>{let e=document.createElement("a");e.href=i,e.download=o,e.click()},title:"Download original",children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]})]})}function wq({path:t,title:n}){let r=(0,f.useRef)(null),[i,o]=(0,f.useState)(!0),[a,l]=(0,f.useState)(null);return(0,f.useEffect)(()=>{let n=!1,i=r.current;if(i)return i.innerHTML="",(async()=>{o(!0),l(null);try{let[{renderAsync:r},s]=await Promise.all([e.A(410052),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!s.ok)throw Error(`Failed to load file (${s.status})`);let a=await s.blob();if(n)return;await r(a,i,void 0,{className:"docx-rendered",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,experimental:!0,useBase64URL:!0}),n||o(!1)}catch(e){n||(l(e instanceof Error?e.message:"Failed to render document"),o(!1))}})(),()=>{n=!0}},[t]),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"DOCX"}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto bg-muted/30",children:[i&&!a&&(0,s.jsxs)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Rendering document…"]}),a&&(0,s.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),(0,s.jsx)("div",{ref:r,className:"docx-viewer-body mx-auto max-w-5xl py-6 px-4"})]})]})}function wK({path:t,title:n}){let r=(0,f.useRef)(null),[i,o]=(0,f.useState)(!0),[a,l]=(0,f.useState)(null);return(0,f.useEffect)(()=>{let n=!1,i=r.current;if(!i)return;i.innerHTML="";let s=null;return(async()=>{o(!0),l(null);try{let[{init:r},a]=await Promise.all([e.A(355350),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!a.ok)throw Error(`Failed to load file (${a.status})`);let l=await a.arrayBuffer();if(n)return;let c=i.clientWidth||960,d=Math.round(9*c/16);s=r(i,{width:c,height:d,mode:"list"}),await s.preview(l),n||o(!1)}catch(e){n||(l(e instanceof Error?e.message:"Failed to render presentation"),o(!1))}})(),()=>{n=!0;try{s?.destroy?.()}catch{}}},[t]),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"PPTX"}),(0,s.jsxs)("div",{className:"flex-1 overflow-auto bg-muted/30 py-4",children:[i&&!a&&(0,s.jsxs)("div",{className:"h-[60vh] flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Rendering slides…"]}),a&&(0,s.jsx)("div",{className:"h-[60vh] flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),(0,s.jsx)("div",{ref:r,className:"pptx-viewer-body mx-auto max-w-5xl px-4"})]})]})}function wG({path:t,title:n}){let[r,i]=(0,f.useState)(null),[o,a]=(0,f.useState)(0),[l,c]=(0,f.useState)(!0),[d,p]=(0,f.useState)(null),h=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!r||!h.current)return;let e=r[o];if(!e||null!==e.html)return;let{wb:t,toHtml:n}=h.current,s=n(t.Sheets[e.name]);i(e=>{if(!e)return e;let t=[...e];return t[o]={...t[o],html:s.html,rows:s.rows,truncated:s.truncated},t})},[r,o]),(0,f.useEffect)(()=>{let n=!1;return c(!0),p(null),i(null),(async()=>{try{let[r,s]=await Promise.all([e.A(432302),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!s.ok)throw Error(`Failed to load file (${s.status})`);let o=await s.arrayBuffer();if(n)return;let l=r.read(o,{type:"array",cellDates:!0,cellStyles:!0});if(n)return;h.current={wb:l,toHtml:e=>{let t=e["!ref"],n=t?r.utils.decode_range(t):null,i=n?n.e.r-n.s.r+1:0;if(!n||i<=2e3)return{html:r.utils.sheet_to_html(e,{editable:!1}),rows:i,truncated:!1};let s={...e,"!ref":r.utils.encode_range({s:n.s,e:{r:n.s.r+2e3-1,c:n.e.c}})};return{html:r.utils.sheet_to_html(s,{editable:!1}),rows:i,truncated:!0}}},i(l.SheetNames.map(e=>({name:e,html:null,rows:0,truncated:!1}))),a(0),c(!1)}catch(e){n||(p(e instanceof Error?e.message:"Failed to parse spreadsheet"),c(!1))}})(),()=>{n=!0}},[t]);let m=(0,f.useMemo)(()=>r?.[o]??null,[r,o]);return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"XLSX"}),r&&r.length>1&&(0,s.jsx)("div",{className:"flex items-center gap-0.5 border-b border-border bg-muted/40 px-2 overflow-x-auto scrollbar-none",children:r.map((e,t)=>(0,s.jsx)("button",{type:"button",onClick:()=>a(t),className:(0,eh.cn)("px-3 py-1.5 text-[12px] rounded-t whitespace-nowrap transition-colors",t===o?"bg-background text-foreground font-medium border-t border-x border-border -mb-px":"text-muted-foreground hover:text-foreground"),children:e.name},e.name+t))}),(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[l&&!d&&(0,s.jsxs)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Parsing spreadsheet…"]}),d&&(0,s.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:d}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),m?.truncated&&(0,s.jsxs)("div",{className:"px-3 py-2 text-[11px] text-amber-600 dark:text-amber-400 border-b border-border",children:["Large sheet (",m.rows.toLocaleString()," rows). Showing first"," ",2e3.toLocaleString()," for performance. Download the file to see everything."]}),m?.html!=null&&(0,s.jsx)("div",{className:"xlsx-sheet p-3 text-[12px]",dangerouslySetInnerHTML:{__html:m.html}})]})]})}let wJ=(0,o.default)("wrap-text",[["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}],["path",{d:"M3 12h15a3 3 0 1 1 0 6h-4",key:"1cl7v7"}],["path",{d:"M3 18h7",key:"sq21v6"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]),wZ=x3(wI);function wX(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function wY(e){return`${e.lineStart}:${e.lineEnd}:${e.textHash}`}function wQ(e){return`L${e.lineStart}-${e.lineEnd}`}async function w0(e){return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e)))).map(e=>e.toString(16).padStart(2,"0")).join("").slice(0,12)}let w1={".js":"javascript",".cjs":"javascript",".mjs":"javascript",".ts":"typescript",".tsx":"typescript",".jsx":"javascript",".py":"python",".rb":"ruby",".php":"php",".sh":"bash",".bash":"bash",".zsh":"bash",".ps1":"powershell",".css":"css",".scss":"scss",".html":"xml",".json":"json",".jsonc":"json",".yaml":"yaml",".yml":"yaml",".toml":"ini",".ini":"ini",".xml":"xml",".sql":"sql",".graphql":"graphql",".gql":"graphql",".go":"go",".rs":"rust",".swift":"swift",".java":"java",".kt":"kotlin",".kts":"kotlin",".c":"c",".cpp":"cpp",".h":"c",".env":"bash",".txt":"",".text":"",".log":"",".rst":"",".mdx":"markdown"};function w2({path:e}){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(0),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!0),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(!1),[m,b]=(0,f.useState)(2e3),[x,y]=(0,f.useState)(new Map),[w,k]=(0,f.useState)(null),N=(0,f.useRef)(null),S=(0,tE.withWs)(`/api/assets/${e}`),C=e.split("/").pop()||e,j=w1[C.includes(".")?`.${C.split(".").pop()?.toLowerCase()}`:""]??"",E=fp(t=>t.byPath[e]?.sidecar??null),M=E?.comments??[],A=(0,f.useMemo)(()=>t?t.replace(/\r\n/g,"\n").split("\n"):[],[t]),T=(0,f.useCallback)(async()=>{c(!0),a(!1),n(null),i(0);try{let e=await (0,tE.wsFetch)(S);if(e.ok){let t=new Uint8Array(await e.arrayBuffer());!function(e){let t=Math.min(e.length,8192);if(0===t)return!1;let n=0;for(let r=0;r<t;r++){let t=e[r];if(0===t)return!0;(t<9||t>13&&t<32)&&n++}return n/t>.3}(t)?(i(t.length),n(new TextDecoder("utf-8").decode(t))):a(!0)}}catch{}finally{c(!1)}},[S]);(0,f.useEffect)(()=>{T(),fp.getState().loadSidecar(e),b(2e3),k(null)},[T,e]);let O=(0,f.useMemo)(()=>A.length,[A]),_=r>2097152||O>5e3,D=(0,f.useMemo)(()=>{if(!t)return[];if(_)return A.map(wX);try{let e=j?wZ.highlight(j,t):wZ.highlightAuto(t);return(0,v3.toHtml)(e).split("\n")}catch{return A.map(wX)}},[t,j,_,A]),R=_?D.slice(0,m):D,I=_&&m<D.length,L=(0,f.useMemo)(()=>{let e={};for(let t of M){if(!t.lineAnchor)continue;let n=wY(t.lineAnchor);(e[n]??=[]).push(t)}return e},[M]);(0,f.useEffect)(()=>{if(!t||o||l||!N.current)return void y(new Map);let e=N.current,n=e.getBoundingClientRect(),r=Array.from(e.querySelectorAll("[data-line]")),i=new Map;for(let t of r){let r=Number(t.dataset.line);if(!Number.isFinite(r))continue;let s=t.getBoundingClientRect();i.set(r,{top:s.top-n.top+e.scrollTop,left:s.left-n.left,width:s.width,bottom:s.bottom-n.top+e.scrollTop})}y(i)},[t,o,l,m,d,D]);let P=(0,f.useCallback)(()=>{let e=N.current,t=window.getSelection();if(!e||!t||t.isCollapsed||0===t.rangeCount)return;let n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return;let r=e=>{let t=e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null;return t?.closest("[data-line]")??null},i=r(n.startContainer),s=r(n.endContainer);if(!i||!s)return;let o=Number(i.dataset.line),a=Number(s.dataset.line);if(!Number.isFinite(o)||!Number.isFinite(a))return;let l=Math.min(o,a),c=Math.max(o,a),d=A.slice(l-1,c).join("\n");(async()=>{let e={lineStart:l,lineEnd:c,textHash:await w0(d)};k({anchorKey:wY(e),anchorLabel:wQ(e),lineAnchor:e,anchorEl:i})})()},[A]),z=(0,f.useCallback)((e,t)=>{k({anchorKey:wY(e),anchorLabel:wQ(e),lineAnchor:e,anchorEl:t})},[]);return o?(0,s.jsx)(vX,{path:e,title:C}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:C.includes(".")?C.split(".").pop()?.toUpperCase()??"TEXT":"TEXT",children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:`h-7 gap-1.5 text-xs ${d?"bg-muted":""}`,onClick:()=>u(e=>!e),title:d?"Disable line wrap":"Enable line wrap",children:[(0,s.jsx)(wJ,{className:"h-3.5 w-3.5"}),"Wrap"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{t&&(navigator.clipboard.writeText(t),h(!0),setTimeout(()=>h(!1),2e3))},title:"Copy file contents",children:[p?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"}),p?"Copied":"Copy"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=S,e.download=C,e.click()},title:"Download file",children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(S,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Raw"]})]}),(0,s.jsxs)("div",{ref:N,className:"relative flex-1 overflow-auto source-viewer-code bg-background",children:[!l&&t&&!o&&(0,s.jsx)(vG,{containerRef:N,onComment:P,align:"left"}),(0,s.jsx)("div",{className:"relative pointer-events-none",style:{height:0},children:Object.entries(L).map(([e,t])=>{let n=t[0]?.lineAnchor;if(!n)return null;let r=x.get(n.lineStart);return r?(0,s.jsx)("div",{style:{pointerEvents:"auto"},children:(0,s.jsx)(y_,{anchorKey:e,anchorLabel:wQ(n),comments:t,top:r.top+4,left:Math.max(0,r.left-20),onClick:()=>{let e=N.current?.querySelector(`[data-line="${n.lineStart}"]`);e&&z(n,e)}})},`pip-${e}`):null})}),l?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Loading..."}):(0,s.jsxs)(s.Fragment,{children:[_&&(0,s.jsxs)("div",{className:"px-4 py-2 text-[11px] text-amber-700 dark:text-amber-300 bg-amber-500/15 border-b border-amber-500/30 font-sans",children:["Large file (",(r/1048576).toFixed(1)," MB, ",D.length.toLocaleString()," lines). Syntax highlighting disabled for performance. Use Raw or Download for the full file."]}),(0,s.jsx)("div",{className:"text-[13px] leading-relaxed font-mono min-w-max",children:R.map((e,t)=>{let n=w?.lineAnchor,r=n&&t+1>=n.lineStart&&t+1<=n.lineEnd;return(0,s.jsxs)("div",{"data-line":t+1,className:`flex ${r?"bg-amber-400/25":"hover:bg-foreground/5"}`,children:[(0,s.jsx)("span",{className:"w-12 shrink-0 pr-4 text-right text-muted-foreground select-none sticky left-0 bg-muted",children:t+1}),(0,s.jsx)("span",{className:`text-foreground pl-2 ${d?"whitespace-pre-wrap break-all":"whitespace-pre"}`,dangerouslySetInnerHTML:{__html:e||" "}})]},t)})}),I&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-t border-border font-sans",children:[(0,s.jsxs)("button",{onClick:()=>b(e=>e+2e3),className:"text-[11px] text-foreground hover:text-foreground px-2.5 py-1 rounded bg-foreground/10 hover:bg-foreground/20 transition-colors",children:["Show ",Math.min(2e3,D.length-m).toLocaleString()," more"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[m.toLocaleString()," / ",D.length.toLocaleString()," lines"]})]})]}),w&&(0,s.jsx)(y4,{path:e,anchorKey:w.anchorKey,anchorLabel:w.anchorLabel,lineAnchor:w.lineAnchor,comments:L[w.anchorKey]??[],anchorEl:w.anchorEl,onClose:()=>k(null)})]})]})}var w3=e.i(727551),w5=e.i(496366);function w4({path:e,title:t,src:n,fullscreen:r,onExit:i,scriptsEnabled:o,onToggleScripts:a}){let[l,c]=(0,f.useState)(!1),d=o??l,u=(0,tE.withWs)(n??`/api/assets/${e}/index.html`),p=r&&i?(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:i,title:"Exit app",children:[(0,s.jsx)(v_,{className:"h-3.5 w-3.5"}),"Exit app"]}):null;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:r?"App":void 0,showBreadcrumb:!r,leading:r?(0,s.jsxs)(s.Fragment,{children:[p,(0,s.jsx)("span",{className:"truncate text-[13px] font-medium text-foreground",children:t})]}):null,children:[(0,s.jsx)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:a??(()=>c(e=>!e)),title:d?"Disable scripts (recommended for untrusted content)":"Enable scripts",children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(w5.Ban,{className:"h-3.5 w-3.5"}),"Disable scripts"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(w3.Play,{className:"h-3.5 w-3.5"}),"Enable scripts"]})}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(u,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]})]}),(0,s.jsx)("iframe",{src:u,className:"flex-1 w-full border-0 bg-card",title:t,sandbox:d?"allow-scripts allow-forms allow-popups allow-top-navigation-by-user-activation":"allow-forms allow-popups allow-top-navigation-by-user-activation"})]})}let w6=(0,o.default)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),w9={stopped:"Stopped",installing:"Installing dependencies…",starting:"Starting…",running:"Running",error:"Error"};function w7({path:e,title:t}){let[n,r]=(0,f.useState)("stopped"),[i,o]=(0,f.useState)(null),[a,l]=(0,f.useState)([]),[c,d]=(0,f.useState)(null),[p,h]=(0,f.useState)(!1),[g,x]=(0,f.useState)(0),[y,w]=(0,f.useState)([]),[k,N]=(0,f.useState)(null),S=(0,f.useRef)(null),C=(0,f.useRef)(null),j=(0,tE.withWs)(`/api/app-proxy/${e}/`),E=()=>{S.current&&(clearInterval(S.current),S.current=null)},M=(0,f.useCallback)(async()=>{try{let t=await (0,tE.wsFetch)(`/api/wiki/app?path=${encodeURIComponent(e)}`);if(!t.ok)return;let n=await t.json();r(n.status),l(n.logs??[]),n.scripts&&w(n.scripts),void 0!==n.defaultScript&&N(n.defaultScript),n.port&&o(n.port),n.error&&d(n.error),("running"===n.status||"stopped"===n.status||"error"===n.status)&&E()}catch{}},[e]);(0,f.useEffect)(()=>("installing"===n||"starting"===n?S.current||(S.current=setInterval(M,800)):E(),E),[n,M]),(0,f.useEffect)(()=>{C.current?.scrollIntoView({behavior:"smooth"})},[a]),(0,f.useEffect)(()=>{M()},[M]);let A=async t=>{d(null),l([]),r("starting");try{let n=await (0,tE.wsFetch)("/api/wiki/app",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,script:t})}),i=await n.json();if(!n.ok||i.error){r("error"),d(i.error??"Failed to start");return}i.port&&o(i.port),await M()}catch(e){r("error"),d(String(e))}},T=async()=>{await (0,tE.wsFetch)("/api/wiki/app",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),r("stopped"),o(null)},O=async()=>{await T(),await A(),x(e=>e+1)},_=y.filter(e=>e!==k);return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:"Node app",children:["running"===n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>x(e=>e+1),children:[(0,s.jsx)(tR,{className:"h-3.5 w-3.5"}),"Refresh"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(j,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:O,children:[(0,s.jsx)(tR,{className:"h-3.5 w-3.5"}),"Restart"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs text-destructive hover:text-destructive",onClick:T,children:[(0,s.jsx)(w6,{className:"h-3.5 w-3.5"}),"Stop"]})]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>h(e=>!e),children:[(0,s.jsx)(no,{className:"h-3.5 w-3.5"}),"Logs"]})]}),p&&(0,s.jsxs)("div",{className:"border-b bg-black/90 text-green-400 font-mono text-xs h-40 overflow-auto p-2 shrink-0",children:[0===a.length?(0,s.jsx)("span",{className:"text-muted-foreground",children:"No output yet."}):a.map((e,t)=>(0,s.jsx)("div",{className:"whitespace-pre-wrap leading-5",children:e},t)),(0,s.jsx)("div",{ref:C})]}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:["stopped"===n&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:[(0,s.jsxs)("div",{className:"text-center space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:t}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Node.js app — will be started on a local port"})]}),(0,s.jsxs)("div",{className:"inline-flex items-stretch overflow-hidden rounded-full bg-primary text-primary-foreground shadow-e-1",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>A(),className:"inline-flex items-center gap-2 px-4 py-2.5 text-sm font-medium transition-colors hover:bg-primary-foreground/10 focus-visible:outline-none",children:[(0,s.jsx)(w3.Play,{className:"h-4 w-4"}),"Launch app",k&&(0,s.jsxs)("span",{className:"opacity-70",children:["(",k,")"]})]}),_.length>0&&(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)("button",{type:"button",className:"inline-flex items-center justify-center border-l border-l-primary-foreground/20 px-2 transition-colors hover:bg-primary-foreground/10 focus-visible:outline-none","aria-label":"Choose script to launch",children:(0,s.jsx)(b,{className:"h-4 w-4"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",children:[(0,s.jsx)(ek.DropdownMenuLabel,{children:"Run script"}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),y.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onSelect:()=>A(e),className:"gap-2 font-mono text-xs",children:[(0,s.jsx)(w3.Play,{className:"h-3.5 w-3.5"}),e,e===k&&(0,s.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"default"})]},e))]})]})]})]}),("installing"===n||"starting"===n)&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3",children:[(0,s.jsx)(u.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:w9[n]}),i&&(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60",children:["port ",i]}),(0,s.jsxs)(v.Button,{onClick:T,variant:"outline",size:"sm",className:"gap-2",children:[(0,s.jsx)(w6,{className:"h-3.5 w-3.5"}),"Cancel"]})]}),"error"===n&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-6",children:[(0,s.jsx)(m.AlertCircle,{className:"h-8 w-8 text-destructive"}),(0,s.jsxs)("div",{className:"text-center space-y-1 max-w-md",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Failed to start app"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground break-words",children:c??"Unknown error"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(v.Button,{onClick:T,variant:"ghost",className:"gap-2",children:"Back"}),(0,s.jsxs)(v.Button,{onClick:O,variant:"outline",className:"gap-2",children:[(0,s.jsx)(tR,{className:"h-4 w-4"}),"Try again"]})]})]}),"running"===n&&(0,s.jsx)("iframe",{src:j,className:"flex-1 w-full border-0 bg-card",title:t,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-top-navigation-by-user-activation"},g)]})]})}let w8=(0,ii.default)(()=>e.A(810497).then(e=>e.PdfViewer),{loadableGenerated:{modules:[904378]},ssr:!1});function ke(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}let kt=new Set(["image","media","pdf","fallback","app","node-app","html"]);function kn({openFile:e,fileContent:t,fileLoading:n,editing:r,setEditing:i,editContent:o,setEditContent:a,saving:p,saveError:m,onSave:b,gitFileInfo:x,showHistory:y,historyLoading:w,historyCommits:k,selectedDiffSha:N,diffContent:S,diffLoading:C,onToggleHistory:j,onSelectDiff:E,gateBypassPath:M,onBypassGate:A,onRefresh:T,onShare:O,onClose:_,renderCopyMenu:D,appKey:R,setAppKey:I,appFullscreen:L,setAppFullscreen:P,viewerKey:z,setViewerKey:$,htmlSourceMode:B,setHtmlSourceMode:F,widthAwareViewer:H,viewWidth:U,viewAlign:V,setViewWidth:W,setViewAlign:q,contentWidthClass:K,contentAlignClass:G,isMobile:J,sidebarCollapsed:Z}){let[X,Y]=(0,f.useState)(null),[Q,ee]=(0,f.useState)(null),[et,en]=(0,f.useState)(!1);(0,f.useEffect)(()=>{en(!1)},[e.path]);let er=nF(e.name,e.nodeType),ei=!kt.has(er)&&(e.size??0)>5242880&&M!==e.path;if("node-app"===er)return(0,s.jsx)(w7,{path:e.path,title:e.name});let es="html"===er?(0,tE.withWs)(`/api/assets/${e.path}`):void 0;return"app"===er||"html"===er?L?(0,s.jsx)(w4,{scriptsEnabled:et,onToggleScripts:()=>en(e=>!e),path:e.path,title:e.name,src:es,fullscreen:!0,onExit:()=>P(!1)}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,s.jsxs)("div",{className:(0,eh.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 ",!J&&Z&&"pl-11"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)("span",{className:"hidden md:inline-flex",children:(0,s.jsx)("span",{className:"",children:(0,s.jsx)(c,{className:"h-4 w-4 shrink-0 text-foreground/70"})})}),(0,s.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:e.path,children:e.path}),(0,s.jsx)("div",{ref:e=>{e&&ee(e)},className:"flex items-center gap-1 shrink-0"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)("div",{ref:e=>{e&&Y(e)},className:"flex items-center gap-1 shrink-0"}),D(e,(0,s.jsxs)(s.Fragment,{children:["html"===er&&!r&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>F(!B),children:[B?(0,s.jsx)(c,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(r7,{className:"mr-2 h-3.5 w-3.5"}),B?"Show preview":"Show source"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>I(e=>e+1),children:[(0,s.jsx)(tR,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>P(!0),children:[(0,s.jsx)(r8,{className:"mr-2 h-3.5 w-3.5"}),"Open fullscreen"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:O,children:[(0,s.jsx)(it,{className:"mr-2 h-3.5 w-3.5"}),"Share"]})]})),"html"===er&&!r&&null!==t&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{i(!0),a(t)},children:(0,s.jsx)(ie,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:_,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]})]}),r&&"html"===er?(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,s.jsx)("textarea",{value:o,onChange:e=>a(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,s.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[m&&(0,s.jsx)("span",{className:"text-xs text-destructive mr-auto",children:m}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",className:"gap-1",onClick:b,disabled:p,children:[p&&(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):B&&"html"===er?(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)(w2,{path:e.path,title:e.name})})}):(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)(w4,{scriptsEnabled:et,onToggleScripts:()=>en(e=>!e),path:e.path,title:e.name,src:es},R)})})]}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,s.jsxs)("div",{className:(0,eh.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 ",!J&&Z&&"pl-11"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)("span",{className:"hidden md:inline-flex",children:(0,s.jsx)("span",{className:"",children:nW(e.name)?(0,s.jsx)(d.Image,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):nU(e.name)?(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,s.jsx)(nr,{className:"h-4 w-4 shrink-0 text-foreground/60"})})}),(0,s.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:e.path,children:e.path}),(0,s.jsx)("div",{ref:e=>{e&&ee(e)},className:"flex items-center gap-1 shrink-0"}),x&&(0,s.jsxs)("span",{className:"hidden md:flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 ml-1",children:[(0,s.jsx)(ir,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate max-w-[100px]",children:x.author}),(0,s.jsx)("span",{title:new Date(x.date).toLocaleString(),className:"shrink-0",children:ke(x.date)})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)("div",{ref:e=>{e&&Y(e)},className:"flex items-center gap-1 shrink-0"}),D(e,(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:j,children:[(0,s.jsx)(rK,{className:"mr-2 h-3.5 w-3.5"}),y?"Hide history":"File history"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:O,children:[(0,s.jsx)(it,{className:"mr-2 h-3.5 w-3.5"}),"Share"]}),!r&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:T,disabled:n,children:[n?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tR,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),H&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsx)(ek.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Width"}),rF.VIEW_WIDTH_ORDER.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>W(e),className:"flex items-center justify-between text-xs",children:[rF.VIEW_WIDTH_LABEL[e],e===U&&(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5"})]},e)),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsx)(ek.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Alignment"}),rF.VIEW_ALIGN_ORDER.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>q(e),className:"flex items-center justify-between text-xs",children:[rF.VIEW_ALIGN_LABEL[e],e===V&&(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5"})]},e))]})]})),nU(e.name)&&!r&&(null!==t||nV(e.name))&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{i(!0),a(t??"")},children:(0,s.jsx)(ie,{className:"h-3.5 w-3.5"})}),nU(e.name)&&r&&nV(e.name)&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>i(!1),children:(0,s.jsx)(rW.Eye,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:_,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]})]}),y&&(0,s.jsxs)("div",{className:"border-b bg-muted/30 shrink-0 max-h-[40vh] overflow-auto",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-1.5 border-b",children:[(0,s.jsx)("span",{className:"text-xs font-semibold text-muted-foreground",children:"History"}),(0,s.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:j,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),w?(0,s.jsx)("div",{className:"flex justify-center py-4",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===k.length?(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,s.jsx)("div",{children:k.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{type:"button",className:(0,eh.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",N===e.sha&&"bg-muted"),onClick:()=>E(e.sha),children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"text-[11px] font-mono text-muted-foreground shrink-0",children:e.shortSha}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",children:e.message}),(0,s.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:e.author}),(0,s.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",title:new Date(e.date).toLocaleString(),children:ke(e.date)})]})}),N===e.sha&&(0,s.jsx)("div",{className:"border-t",children:C?(0,s.jsx)("div",{className:"flex justify-center py-3",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==S?(0,s.jsx)("pre",{className:"overflow-auto px-4 py-2 text-[11px] font-mono leading-relaxed whitespace-pre text-foreground/80 max-h-60",children:S}):null})]},e.sha))})]}),ei?(0,s.jsx)(vQ,{path:e.path,size:e.size??0,onOpen:A}):r?(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:nV(e.name)?(0,s.jsx)(vZ,{}):(0,s.jsx)("textarea",{value:o,onChange:e=>a(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):nV(e.name)?(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,s.jsx)(vZ,{mode:"viewing"})}):"csv"===er||"pdf"===er||"mermaid"===er||"notebook"===er||"image"===er||"media"===er||"docx"===er||"xlsx"===er||"pptx"===er||"source"===er||"fallback"===er?(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===er?(0,s.jsx)(ic,{path:e.path,title:e.name}):"pdf"===er?(0,s.jsx)(w8,{path:e.path,title:e.name}):"mermaid"===er?(0,s.jsx)(v2,{path:e.path,title:e.name}):"notebook"===er?(0,s.jsx)(wV,{path:e.path,title:e.name}):"image"===er?(0,s.jsx)(v0,{path:e.path,title:e.name}):"media"===er?(0,s.jsx)(v1,{path:e.path,title:e.name,type:["mp4","webm","mov","m4v"].includes(nB(e.name))?"video":"audio"}):"docx"===er?(0,s.jsx)(wq,{path:e.path,title:e.name}):"xlsx"===er?(0,s.jsx)(wG,{path:e.path,title:e.name}):"pptx"===er?(0,s.jsx)(wK,{path:e.path,title:e.name}):"source"===er?(0,s.jsx)(w2,{path:e.path,title:e.name}):(0,s.jsx)(vX,{path:e.path,title:e.name})},z)})}):(0,s.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,s.jsx)("div",{className:(0,eh.cn)("w-full",G,K),children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):null!==t?(0,s.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:t}):nU(e.name)?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),r&&!nV(e.name)&&(0,s.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[m&&(0,s.jsx)("span",{className:"text-xs text-destructive mr-auto",children:m}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",className:"gap-1",onClick:b,disabled:p,children:[p&&(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]})}function kr(e="(max-width: 767px)"){let[t,n]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[e]),t}function ki(e){return e?`wiki-recent-files-${e}`:"wiki-recent-files"}function ks(e){try{let t=localStorage.getItem(ki(e));return t?JSON.parse(t):[]}catch{return[]}}let ko=(0,eN.create)(e=>({recents:[],loadForWorkspace:t=>{e({recents:ks(t)})},push:(t,n)=>{let r=ks(n).filter(e=>e.path!==t.path),i=[t,...r].slice(0,15);localStorage.setItem(ki(n),JSON.stringify(i)),e({recents:i})}})),ka=new Map,kl=new Map;async function kc(e){let t=await (0,tE.wsFetch)(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1,git:t.git})):[]}async function kd(e){let t=ka.get(e);if(t)return ka.delete(e),t;let n=kl.get(e);if(n){let t=await n;return ka.delete(e),t}return null}function ku(e,t,n){return e.map(e=>e.path===t?n(e):e.children?{...e,children:ku(e.children,t,n)}:e)}function kp(e){let t=[];for(let n of e)("dir"===n.type||"app"===n.type||"node-app"===n.type)&&n.expanded&&n.children&&(t.push(n.path),t.push(...kp(n.children)));return t}function kh(e){return e.split("/").pop()??e}e.s(["default",0,function(){let e=function(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,s]=(0,f.useState)(()=>(0,tE.getActiveWorkspaceId)()),[o,a]=(0,f.useState)([]),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(null),[b,x]=(0,f.useState)({}),[y,v]=(0,f.useState)(null),[w,k]=(0,f.useState)(null),[N,S]=(0,f.useState)(null),[C,j]=(0,f.useState)(null),E=(0,f.useCallback)(async()=>{let e=(0,tE.getEphemeralRoot)();if(e){a([]),c(!1),t(!0),r(e),s(`root:${e}`);return}try{let e=await fetch((0,ev.apiUrl)("/api/system/workspaces"));if(!e.ok)throw Error("Failed");let n=await e.json();if(a(n.workspaces),c(n.isAdmin),n.workspaces.length>0){t(!0);let e=new URLSearchParams(window.location.search).get("ws"),i=e?n.workspaces.find(t=>t.id===e):null,o=i??[...n.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(s(o.id),r(o.rootDir),!i){let e=new URL(location.href);e.searchParams.set("ws",o.id),history.replaceState(null,"",e.toString())}}else t(!1)}catch{t(!1)}},[]);(0,f.useEffect)(()=>{E()},[E]);let M=(0,f.useCallback)(async e=>{if(e===i)return;try{await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/open`),{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),fd.getState().invalidate(),vM.getState().invalidateAll();let n=o.find(t=>t.id===e);n&&r(n.rootDir),s(e)},[i,o]),A=(0,f.useCallback)(async e=>{if(p)try{if(!(await fetch((0,ev.apiUrl)(`/api/system/workspaces/${p}`),{method:"DELETE"})).ok)throw Error("Failed");if(p===i){let n=o.filter(e=>e.id!==p);if(n.length>0){let t=[...n].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await e(t.id)}else t(!1)}await E()}catch{}finally{h(null)}},[p,i,o,E]),T=(0,f.useCallback)(async e=>{if(!m){g(e);try{let t=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/refresh`),{method:"POST"});if(!t.ok){let e=await t.json();ey(e.error??"Refresh failed");return}await E()}catch{ey("Refresh failed")}finally{g(null)}}},[m,E]),O=(0,f.useCallback)(async e=>{if(!b[e])try{let t=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/branch`));if(!t.ok)return;let n=await t.json();x(t=>({...t,[e]:n.branches??[]}))}catch{}},[b]),_=(0,f.useCallback)(async(e,t)=>{if(!y){v(e),k(t);try{let n=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/branch`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!n.ok){let e=await n.json();ey(e.error??"Branch switch failed");return}ex(`Switched to ${t}`),S(null),j(null),await E()}catch{ey("Branch switch failed")}finally{v(null),k(null)}}},[y,E]);return{rootConfigured:e,rootPath:n,activeWorkspaceId:i,workspaces:o,isWsAdmin:l,addingWorkspace:d,setAddingWorkspace:u,setRootConfigured:t,setActiveWorkspaceId:s,deletingWorkspaceId:p,setDeletingWorkspaceId:h,refreshingWsId:m,wsBranches:b,switchingBranch:y,switchingBranchName:w,branchPickerWsId:N,setBranchPickerWsId:S,wsBranchPos:C,setWsBranchPos:j,loadWorkspaces:E,switchWorkspace:M,handleDeleteWorkspace:A,handleRefreshWorkspace:T,loadWsBranches:O,handleSwitchBranch:_}}(),t=(0,f.useRef)(()=>{}),n=function({activeWorkspaceId:e,rootConfigured:t,onExternalChange:n}){let[r,i]=(0,f.useState)([]),[s,o]=(0,f.useState)(!1),[a,l]=(0,f.useState)(!1),c=(0,f.useRef)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)({}),[m,g]=(0,f.useState)({}),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)(null),[w,k]=(0,f.useState)(null),[N,S]=(0,f.useState)(null);(0,f.useEffect)(()=>{i([]),o(!1),c.current=!1,h({}),g({}),x(null),v(null),k(null),S(null)},[e]),(0,f.useEffect)(()=>{!e||s||c.current||(c.current=!0,l(!0),kc("").then(e=>{i(e),o(!0),l(!1)}).catch(()=>{c.current=!1,l(!1)}))},[s,e]);let C=(0,f.useCallback)(async e=>{let t=await kc(e);""===e?i(e=>{let n=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=n.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):i(n=>ku(n,e,e=>({...e,children:t,expanded:!0})))},[]),j=(0,f.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let n=[],r="";for(let e=0;e<t.length-1;e++)r=r?`${r}/${t[e]}`:t[e],n.push({prefix:r,children:await kc(r)});i(e=>{let t=e;for(let{prefix:e,children:r}of n)t=ku(t,e,e=>({...e,children:r,expanded:!0}));return t})},[]),E=(0,f.useCallback)(async()=>{u(!0);try{let e=kp(r),t=await kc("");for(let n of(i(t),e)){let e=await kc(n);i(t=>ku(t,n,t=>({...t,children:e,expanded:!0})))}}finally{u(!1)}},[r]),M=(0,f.useCallback)(async e=>{if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)i(t=>ku(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await kd(e.path);if(t)return void i(n=>ku(n,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));i(t=>ku(t,e.path,e=>({...e,loading:!0})));let n=await kc(e.path);i(t=>ku(t,e.path,e=>({...e,loading:!1,children:n,expanded:!0})))}else i(t=>ku(t,e.path,e=>({...e,expanded:!0})))},[]),A=(0,f.useCallback)(e=>{"file"===e.type?(e.name.endsWith(".md")||e.name.endsWith(".markdown"))&&tJ(e.path):function(e){if(ka.has(e)||kl.has(e))return;let t=kc(e).then(t=>(ka.set(e,t),t)).finally(()=>kl.delete(e));kl.set(e,t),t.catch(()=>{})}(e.path)},[]),T=(0,f.useRef)([]);(0,f.useEffect)(()=>{T.current=kp(r)},[r]);let O=(0,f.useMemo)(()=>kp(r).filter(e=>""!==e).slice(0,24).join("\n"),[r]),[_,D]=(0,f.useState)("");(0,f.useEffect)(()=>{let e=setTimeout(()=>D(O),300);return()=>clearTimeout(e)},[O]);let R=(0,f.useRef)(n);(0,f.useEffect)(()=>{R.current=n},[n]),(0,f.useEffect)(()=>{if(!t||(0,ev.isLite)()||!e)return;let n=new Map;function r(e){n.has(e)&&clearTimeout(n.get(e)),n.set(e,setTimeout(()=>{n.delete(e),C(e)},300))}let i=(_?_.split("\n"):[]).map(e=>`dir=${encodeURIComponent(e)}`).join("&"),s=new EventSource((0,tE.withWs)(i?`/api/wiki/watch?${i}`:"/api/wiki/watch"));return s.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let{type:i,path:s}=t;if("rescan"===i){for(let e of(vM.getState().invalidateAll(),r(""),T.current))r(e);return}("add"===i||"change"===i||"unlink"===i)&&vM.getState().invalidateAll();let o=s.split("/");if(r(o.length>1?o.slice(0,-1).join("/"):""),"change"===i){let e=`__file__${s}`;n.has(e)&&clearTimeout(n.get(e)),n.set(e,setTimeout(()=>{n.delete(e),R.current?.(s)},400))}},()=>{for(let e of(s.close(),n.values()))clearTimeout(e)}},[t,C,e,_]);let I=(0,f.useCallback)(async e=>{if(!p[e]&&!m[e]){g(t=>({...t,[e]:!0}));try{let t=await (0,tE.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(!t.ok)return void ey("Could not load branches");let n=await t.json();h(t=>({...t,[e]:n.branches}))}catch{ey("Could not load branches")}finally{g(t=>({...t,[e]:!1}))}}},[p,m]),L=(0,f.useCallback)(async(e,t,n)=>{if(!b){x(t);try{let r=await (0,tE.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===r.status)return void ey("Repository has uncommitted changes");if(!r.ok){let e=await r.json();ey(e.error??"Checkout failed");return}let i=await r.json();ex(`Switched to ${i.branch}`),k(null),S(null),h(t=>{let n={...t};return delete n[e],n}),await C(n)}catch{ey("Checkout failed")}finally{x(null)}}},[b,C]),P=(0,f.useCallback)(async(e,t)=>{if(!y){v(e);try{let n=await (0,tE.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!n.ok){let e=await n.json();ey(e.message??e.error??"Pull failed");return}let r=await n.json();ex(`Pulled ${e} (${r.branch} @ ${r.sha.slice(0,7)})`),await C(t)}catch{ey("Pull failed")}finally{v(null)}}},[y,C]);return{roots:r,rootLoaded:s,rootLoading:a,refreshingTree:d,refreshTree:E,reloadDir:C,revealPath:j,toggleFolder:M,prefetch:A,nodeBranches:p,branchesLoading:m,checkingOutBranch:b,pullingRepo:y,branchDropdownNode:w,setBranchDropdownNode:k,branchDropdownPos:N,setBranchDropdownPos:S,loadBranches:I,handleCheckout:L,handleGitPull:P}}({activeWorkspaceId:e.activeWorkspaceId,rootConfigured:e.rootConfigured,onExternalChange:(0,f.useCallback)(e=>t.current(e),[])}),r=function({activeWorkspaceId:e,rootPath:t,isMobile:n,setSidebarCollapsed:r,treeApi:i}){let[s,o]=(0,f.useState)(null),[a,l]=(0,f.useState)(null),[c,d]=(0,f.useState)(!1),[u,p]=(0,f.useState)(0),[h,m]=(0,f.useState)(0),[g,b]=(0,f.useState)(null),[x,y]=(0,f.useState)(0),[v,w]=(0,f.useState)(!1),[k,N]=(0,f.useState)(!1),[S,C]=(0,f.useState)(""),[j,E]=(0,f.useState)(!1),[M,A]=(0,f.useState)(!1),[T,O]=(0,f.useState)(null),_=(0,f.useRef)(null),D=(0,f.useRef)(!1);(0,f.useEffect)(()=>{_.current=s},[s]),(0,f.useEffect)(()=>{D.current=k},[k]);let R=(0,f.useMemo)(()=>s?nF(s.name,s.nodeType):null,[s]),I=(0,f.useCallback)(()=>{N(!1),E(!1),O(null),b(null),y(0),l(null)},[]),L=(0,f.useCallback)(async(e,t)=>{var n;if(["editor","text"].includes(t)||nU((n=e).split("/").pop()??n)){w(!0);try{let t=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();b(e.content),y(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}w(!1)}},[]),P=(0,f.useCallback)(async t=>{if("file"===t.type&&ko.getState().push({path:t.path,name:t.name},e),o({path:t.path,name:t.name,size:t.size,nodeType:"app"===t.type?"app":"node-app"===t.type?"node-app":"file"}),I(),"file"===t.type&&nV(t.name)){w(!0);try{await t1.getState().loadPage(t.path)}finally{w(!1)}return}let n=nF(t.name,t.type);await L(t.path,n)},[e,I,L]),z=(0,f.useCallback)(()=>{o(null),b(null),N(!1),E(!1),O(null)},[]),$=(0,f.useCallback)(()=>{o(null),b(null),N(!1),E(!1),O(null),y(0)},[]),B=(0,f.useCallback)(e=>{let t=e.split("/").pop()??e;i.revealPath(e),P({path:e,name:t,type:"file",modifiedAt:""})},[P,i]),F=(0,f.useCallback)(async e=>{let t=e.path.split("/").slice(0,-1).join("/"),s=(await kc(t)).find(t=>t.path===e.path);if(s){if("dir"===s.type){await i.revealPath(e.path),await i.toggleFolder(s);return}if("app"===s.type||"node-app"===s.type){await i.revealPath(s.path),P({path:s.path,name:s.name,type:s.type,modifiedAt:s.modifiedAt}),await i.toggleFolder(s),n&&r(!0);return}P({path:s.path,name:s.name,type:s.type,modifiedAt:s.modifiedAt}),n&&r(!0)}},[n,P,r,i]),H=(0,f.useCallback)(async e=>{if(!e)return void o(null);let n=(0,tE.toRootRelative)(e,(0,tE.getEphemeralRoot)()??t);if(null===n||!(e=n))return;let r=e.split("/"),s=r[r.length-1],a=r.slice(0,-1).join("/"),l=(await kc(a)).find(t=>t.path===e);l&&(await i.revealPath(e),P({path:e,name:s,type:l.type,modifiedAt:l.modifiedAt}))},[P,t,i]);(0,f.useEffect)(()=>{let e=new URL(window.location.href);s?e.searchParams.set("path",s.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[s]),(0,f.useEffect)(()=>{let e=()=>{H(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[H]);let[U,V]=(0,f.useState)(!1);(0,f.useEffect)(()=>{V("1"===new URLSearchParams(window.location.search).get("embed"))},[]),(0,f.useEffect)(()=>{if(!U)return;let e=e=>{e.origin!==window.location.origin?console.warn(`[wiki-viewer] ignored postMessage from untrusted parent origin ${e.origin}.`):e.data&&"open-file"===e.data.type&&"string"==typeof e.data.path&&H(e.data.path)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[U,H]);let W=(0,f.useRef)(new URLSearchParams(window.location.search).get("path")??new URLSearchParams(window.location.search).get("file")),q=(0,f.useRef)(!1),[K,G]=(0,f.useState)(!1),J=(0,f.useCallback)(()=>G(!0),[]);(0,f.useEffect)(()=>{q.current||K&&(q.current=!0,H(W.current))},[K,H]),(0,f.useEffect)(()=>{s&&nV(s.name)&&t1.getState().currentPath!==s.path&&t1.getState().loadPage(s.path)},[s]);let Z=(0,f.useCallback)(async()=>{let e=_.current;if(e){if(nV(e.name)){w(!0);try{await t1.getState().loadPage(e.path)}finally{w(!1)}return}if(["editor","text"].includes(nF(e.name,e.nodeType))||nU(e.name)){w(!0);try{let t=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();b(e.content),y(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}w(!1)}}},[]),X=(0,f.useCallback)(()=>{m(e=>e+1),Z()},[Z]),Y=(0,f.useCallback)(e=>{let t=_.current;t&&t.path===e&&!D.current&&Z()},[Z]),Q=(0,f.useCallback)(async()=>{let e=_.current;if(!e)return;A(!0),O(null);let t=await (0,tE.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e.path,content:S,baseRevision:x})});if(t.ok){let e=await t.json();"number"==typeof e.revision&&y(e.revision),b(S),N(!1)}else O((await t.json()).error??"Save failed");A(!1)},[S,x]);async function ee(e){let t=_.current;if(t?.path===e&&null!==g)return g;if(t1.getState().currentPath===e)return t1.getState().content;let n=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!n.ok)throw Error("Cannot copy content");return(await n.json()).content}return{openFile:s,openFileViewerKind:R,fileContent:g,fileRevision:x,fileLoading:v,editing:k,setEditing:N,editContent:S,setEditContent:C,htmlSourceMode:j,setHtmlSourceMode:E,saving:M,saveError:T,appFullscreen:c,setAppFullscreen:d,appKey:u,setAppKey:p,viewerKey:h,setViewerKey:m,gateBypassPath:a,bypassGate:()=>l(_.current?.path??null),openViewer:P,openFromSearch:B,openFavoriteEntry:F,navigateToPath:H,handleSave:Q,refreshViewer:Z,handleRefresh:X,closeFile:z,clearFile:$,onExternalChange:Y,markRootLoaded:J,copyPath:e=>{navigator.clipboard.writeText(e),ex("Path copied")},copyWikiLink:e=>{let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),ex("Wiki link copied")},copyUrl:t=>{let n=new URL(location.href);n.searchParams.set("path",t),e&&n.searchParams.set("ws",e),navigator.clipboard.writeText(n.toString()),ex("URL copied")},copyRawContent:async function(e){try{let t=await ee(e);await navigator.clipboard.writeText(t),ex("Raw content copied")}catch{ey("Could not copy file content")}},copyFormattedContent:async function(e,t){try{let n=await ee(e);if(!nV(t)){await navigator.clipboard.writeText(n),ex("Content copied");return}let r=await (0,hC.markdownToHtml)(n,{pagePath:e,sanitize:!0});"ClipboardItem"in window&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([r],{type:"text/html"}),"text/plain":new Blob([n],{type:"text/plain"})})]):await navigator.clipboard.writeText(n),ex("Formatted content copied")}catch{ey("Could not copy formatted content")}}}}({activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isMobile:kr(),setSidebarCollapsed:e=>g.current(e),treeApi:{revealPath:n.revealPath,toggleFolder:n.toggleFolder}});(0,f.useEffect)(()=>{t.current=r.onExternalChange},[r.onExternalChange]);let i=kr(),[o,m]=(0,f.useState)(!1),g=(0,f.useRef)(()=>{});g.current=m;let[b,x]=(0,f.useState)({settingsOpen:!1,shareDialogOpen:!1}),[y,w]=(0,f.useState)(!1),[k,N]=(0,f.useState)({path:null,isDir:!1}),S=function({reloadDir:e}){let[t,n]=(0,f.useState)(!1),[r,i]=(0,f.useState)(null),s=(0,f.useRef)(null),o=(0,f.useRef)(""),a=(0,f.useCallback)(async(t,r)=>{void 0!==r&&(o.current=r);let a=Array.from(t);if(a.length){n(!0),i(null);try{for(let e of a){let t=new FormData;t.append("file",e),t.append("dir",o.current);let n=await (0,tE.wsFetch)("/api/wiki/upload",{method:"POST",body:t});if(!n.ok){let e=await n.json();i(e.error??"Upload failed"),ey(e.error??"Upload failed");break}}await e(o.current)}catch{i("Upload failed.")}finally{n(!1),s.current&&(s.current.value="")}}},[e]);return{uploading:t,uploadError:r,fileInputRef:s,triggerUpload:function(e){o.current=e,s.current?.click()},doUpload:a}}({reloadDir:n.reloadDir}),C=function(e){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(!1),[s,o]=(0,f.useState)([]),[a,l]=(0,f.useState)(!1),[c,d]=(0,f.useState)(null),[u,p]=(0,f.useState)(null),[h,m]=(0,f.useState)(!1),g=e?.path;(0,f.useEffect)(()=>{i(!1),o([]),d(null),p(null)},[g]),(0,f.useEffect)(()=>{if(!g)return void n(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,tE.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(g)}`);if(e)return;if(!t.ok)return void n(null);let r=await t.json();e||n(r.info)}catch{e||n(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[g]);let b=(0,f.useCallback)(async()=>{if(!e)return;let t=e.path;i(!0),l(!0),o([]),d(null),p(null);try{let n=await (0,tE.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(t)}`);if(!n.ok)return void ey("Could not load history");let r=await n.json();e.path===t&&o(r.commits)}catch{ey("Could not load history")}finally{l(!1)}},[e]),x=(0,f.useCallback)(async t=>{if(!e)return;if(c===t){d(null),p(null);return}let n=e.path;d(t),m(!0),p(null);try{let r=await (0,tE.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(n)}&sha=${encodeURIComponent(t)}`);if(!r.ok)return void ey("Could not load diff");let i=await r.json();e.path===n&&c===t&&p(i.diff)}catch{ey("Could not load diff")}finally{m(!1)}},[e,c]);return{gitFileInfo:t,showHistory:r,setShowHistory:i,historyLoading:a,historyCommits:s,selectedDiffSha:c,setSelectedDiffSha:d,loadHistory:b,diffContent:u,diffLoading:h,selectDiff:x}}(r.openFile),j=n0(e=>e.favorites),E=ko(e=>e.recents),M=tO(e=>e.activity),A=(0,f.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let n of M)n.at>=e&&n.path&&n.by?.startsWith("ai:")&&t.add(n.path);return t},[M]);async function T(){if(!k.path)return;await fetch((0,tE.withWs)("/api/wiki"),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:k.path})}),(r.openFile?.path===k.path||r.openFile?.path.startsWith(`${k.path}/`))&&r.closeFile();let e=kh(k.path).includes("/")?k.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),N({path:null,isDir:!1})}(0,f.useEffect)(()=>{let e=new URLSearchParams(window.location.search);w("1"===e.get("embed")&&"1"!==e.get("chrome"))},[]),(0,f.useEffect)(()=>{i&&m(!0)},[i]),(0,f.useEffect)(()=>{fd.getState().load()},[]),(0,f.useEffect)(()=>{let e=()=>{tO.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,f.useEffect)(()=>{ko.getState().loadForWorkspace(e.activeWorkspaceId),n0.getState().loadForWorkspace(e.activeWorkspaceId)},[e.activeWorkspaceId]),(0,f.useEffect)(()=>{let e=[...j.map(e=>e.path),...E.slice(0,8).map(e=>e.path)].filter((e,t,n)=>nV(e)&&n.indexOf(e)===t).slice(0,12);if(0===e.length)return;let t=("requestIdleCallback"in window?e=>window.requestIdleCallback(e):e=>window.setTimeout(e,400))(()=>{for(let t of e)tJ(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[j,E]),(0,f.useEffect)(()=>{r.clearFile()},[e.activeWorkspaceId,r.clearFile]),(0,f.useEffect)(()=>{n.rootLoaded&&r.markRootLoaded()},[n.rootLoaded,r.markRootLoaded]);let O=(0,rF.useViewWidthStore)(e=>e.width),_=(0,rF.useViewWidthStore)(e=>e.align),D=(0,rF.useViewWidthStore)(e=>e.setWidth),R=(0,rF.useViewWidthStore)(e=>e.setAlign),I=null===r.openFileViewerKind||"editor"===r.openFileViewerKind||"text"===r.openFileViewerKind||"source"===r.openFileViewerKind||"notebook"===r.openFileViewerKind||"fallback"===r.openFileViewerKind,L=I?rF.VIEW_WIDTH_CLASS[O]:"",P=I?rF.VIEW_ALIGN_CLASS[_]:"",z=(0,f.useCallback)((t,n)=>(0,s.jsx)(n1,{doc:r,node:t,extraItems:n,activeWorkspaceId:e.activeWorkspaceId}),[r,e.activeWorkspaceId]);return(0,s.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===e.rootConfigured&&(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===e.rootConfigured&&(0,s.jsx)(tn,{onSelect:t=>{let n=new URL(location.href);n.searchParams.set("ws",t),n.searchParams.delete("path"),history.replaceState(null,"",n.toString()),e.setRootConfigured(!0),e.setActiveWorkspaceId(t),e.loadWorkspaces()}}),!0===e.rootConfigured&&e.addingWorkspace&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,s.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>e.setAddingWorkspace(!1),children:[(0,s.jsx)(h,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,s.jsx)(tn,{onSelect:t=>{e.setAddingWorkspace(!1),e.loadWorkspaces(),e.switchWorkspace(t)}})]}),!0===e.rootConfigured&&!e.addingWorkspace&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r9,{workspace:e,doc:r,fileTree:n,upload:S,isMobile:i,hideChrome:y,sidebarCollapsed:o,setSidebarCollapsed:m,favorites:j,recents:E,activePaths:A,setDeleting:N,setDialogs:x}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[!y&&o&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"hidden md:flex absolute left-2 top-2 z-10 h-7 w-7 p-0",title:"Show sidebar",onClick:()=>m(!1),children:(0,s.jsx)(p,{className:"h-3.5 w-3.5"})}),!y&&(0,s.jsxs)("div",{className:"md:hidden flex h-11 shrink-0 items-center justify-between gap-2 border-b bg-muted px-1",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{m(!1),tO.getState().close()},children:(0,s.jsx)(p,{className:"h-4 w-4"})}),(0,s.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 text-xs font-semibold tracking-tight text-muted-foreground",title:r.openFile?.path,children:[r.openFile&&(0,s.jsx)("span",{className:"shrink-0",children:"app"===r.openFileViewerKind||"html"===r.openFileViewerKind?(0,s.jsx)(c,{className:"h-4 w-4 text-foreground/70"}):nW(r.openFile.name)?(0,s.jsx)(d.Image,{className:"h-4 w-4 text-sunshine-700"}):nU(r.openFile.name)?(0,s.jsx)(l.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,s.jsx)(l.FileText,{className:"h-4 w-4 text-foreground/60"})}),(0,s.jsx)("span",{className:"truncate",children:r.openFile?r.openFile.name:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{tO.getState().open(),m(!0)},children:(0,s.jsx)(a,{className:"h-4 w-4"})})]}),r.openFile?(0,s.jsx)(kn,{openFile:r.openFile,fileContent:r.fileContent,fileRevision:r.fileRevision,fileLoading:r.fileLoading,editing:r.editing,setEditing:r.setEditing,editContent:r.editContent,setEditContent:r.setEditContent,saving:r.saving,saveError:r.saveError,onSave:r.handleSave,gitFileInfo:C.gitFileInfo,showHistory:C.showHistory,historyLoading:C.historyLoading,historyCommits:C.historyCommits,selectedDiffSha:C.selectedDiffSha,diffContent:C.diffContent,diffLoading:C.diffLoading,onToggleHistory:()=>C.setShowHistory(e=>!e),onSelectDiff:C.selectDiff,gateBypassPath:r.gateBypassPath,onBypassGate:r.bypassGate,onRefresh:r.handleRefresh,onShare:()=>x(e=>({...e,shareDialogOpen:!0})),onClose:()=>{r.closeFile()},renderCopyMenu:z,appKey:r.appKey,setAppKey:r.setAppKey,appFullscreen:r.appFullscreen,setAppFullscreen:r.setAppFullscreen,viewerKey:r.viewerKey,setViewerKey:r.setViewerKey,htmlSourceMode:r.htmlSourceMode,setHtmlSourceMode:r.setHtmlSourceMode,widthAwareViewer:I,viewWidth:O,viewAlign:_,setViewWidth:D,setViewAlign:R,contentWidthClass:L,contentAlignClass:P,isMobile:i,sidebarCollapsed:o}):(0,s.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,s.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,s.jsx)(l.FileText,{className:"h-8 w-8 text-muted-foreground"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,s.jsx)(tM,{open:b.shareDialogOpen,onOpenChange:e=>x(t=>({...t,shareDialogOpen:e})),filePath:r.openFile?.path??""}),!(0,ev.isLite)()&&(0,s.jsx)(eJ,{open:b.settingsOpen,onOpenChange:e=>x(t=>({...t,settingsOpen:e}))}),(0,s.jsx)(t8,{currentPath:r.openFile?.path}),(0,s.jsx)("input",{ref:S.fileInputRef,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&S.doUpload(e.target.files)}}),(0,s.jsx)(e2,{open:!!k.path,onOpenChange:e=>{e||N({path:null,isDir:!1})},title:k.isDir?"Delete folder?":"Delete file?",description:k.isDir?`"${kh(k.path??"")}" and all its contents will be permanently deleted.`:`"${kh(k.path??"")}" will be permanently removed.`,onConfirm:T}),(0,s.jsx)(e2,{open:!!e.deletingWorkspaceId,onOpenChange:t=>{t||e.setDeletingWorkspaceId(null)},title:"Delete workspace?",description:`"${e.workspaces.find(t=>t.id===e.deletingWorkspaceId)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:()=>void e.handleDeleteWorkspace(async t=>{await e.switchWorkspace(t),r.clearFile()})})]})]},e.activeWorkspaceId??"none")}],952683)}]);
170
+ ${t}`:""]})}let t=e.data||{};if(t["image/png"]){let e=`data:image/png;base64,${wP(t["image/png"]).replace(/\s/g,"")}`;return(0,s.jsx)("img",{src:e,alt:"output",className:"max-w-full rounded-md bg-card p-2"})}if(t["image/jpeg"]){let e=`data:image/jpeg;base64,${wP(t["image/jpeg"]).replace(/\s/g,"")}`;return(0,s.jsx)("img",{src:e,alt:"output",className:"max-w-full rounded-md bg-card p-2"})}if(t["image/svg+xml"]){let e=wP(t["image/svg+xml"]);return(0,s.jsx)("div",{className:"max-w-full rounded-md bg-card p-2 overflow-auto",dangerouslySetInnerHTML:{__html:e}})}if(t["text/html"]){let e=wP(t["text/html"]);return(0,s.jsx)("iframe",{srcDoc:`<!doctype html><html><head><base target="_blank"><style>body{margin:0;padding:8px;font-family:-apple-system,BlinkMacSystemFont,Inter,system-ui,sans-serif;background:#FFF9E9;color:#2A221B;font-size:13px}table{border-collapse:collapse}th,td{border:1px solid #D4C4B0;padding:4px 8px;text-align:left}thead{background:#EFE5CC}</style></head><body>${e}</body></html>`,sandbox:"allow-scripts",className:"w-full bg-[#FFF9E9] rounded-md border border-[#E8DDC5]",style:{height:360}})}return t["text/plain"]?(0,s.jsx)("pre",{className:"whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md bg-[#F5EEDC] text-[#2A221B]",children:w$(wP(t["text/plain"]))}):null}function wF({cell:e,language:t}){let n=wP(e.source),r=(0,f.useMemo)(()=>(function(e,t){try{let n=t?wL.highlight(t,e):wL.highlightAuto(e);return(0,v3.toHtml)(n)}catch{return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}})(n,t),[n,t]),i=e.execution_count??" ",o=(e.outputs?.length??0)>0;return(0,s.jsxs)("div",{className:"grid grid-cols-[60px_1fr] gap-3 mb-5",children:[(0,s.jsxs)("div",{className:"text-right pt-3 select-none font-mono text-[11px] text-[#8B5E3C]",children:["In [",i,"]:"]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("pre",{className:"whitespace-pre overflow-x-auto font-mono text-[13px] leading-relaxed px-4 py-3 rounded-md bg-[#FFF9E9] border border-[#E8DDC5] text-[#2A221B]",children:(0,s.jsx)("code",{dangerouslySetInnerHTML:{__html:r}})}),o&&(0,s.jsxs)("div",{className:"mt-2 grid grid-cols-[60px_1fr] gap-3",children:[(0,s.jsxs)("div",{className:"text-right pt-3 select-none font-mono text-[11px] text-[#8B2E3E]",children:["Out[",i,"]:"]}),(0,s.jsx)("div",{className:"space-y-2",children:e.outputs?.map((e,t)=>(0,s.jsx)(wB,{output:e},t))})]})]})]})}function wH({cell:e}){let[t,n]=(0,f.useState)("");return(0,f.useEffect)(()=>{let t=!1;return(0,hC.markdownToHtml)(wP(e.source)).then(e=>{t||n(e)}),()=>{t=!0}},[e.source]),(0,s.jsx)("div",{className:"prose prose-sm max-w-none mb-5 px-1 [&_h1]:font-serif [&_h2]:font-serif [&_h3]:font-serif [&_a]:text-[#8B5E3C] [&_a:hover]:underline [&_code]:bg-[#F5EEDC] [&_code]:px-1.5 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-[#8B2E3E]",dangerouslySetInnerHTML:{__html:t}})}function wU({cell:e}){return(0,s.jsx)("pre",{className:"whitespace-pre-wrap font-mono text-[12.5px] leading-relaxed px-4 py-3 rounded-md bg-[#F5EEDC] text-[#2A221B] mb-5",children:wP(e.source)})}function wV({path:e}){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(!0),[o,a]=(0,f.useState)(null),[l,c]=(0,f.useState)(!1),d=(0,tE.withWs)(`/api/assets/${e}`),u=e.split("/").pop()||e,p=(0,f.useCallback)(async()=>{i(!0),a(null);try{let e=await (0,tE.wsFetch)(d);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();n(t)}catch(e){a(e instanceof Error?e.message:"Failed to load notebook")}finally{i(!1)}},[d]);(0,f.useEffect)(()=>{p()},[p]);let h=t?.metadata?.language_info?.name||t?.metadata?.kernelspec?.name||"python",b=t?.cells?.length??0,x=t?.cells?.filter(e=>"code"===e.cell_type).length??0,y=t?.cells?.some(e=>"code"===e.cell_type&&(e.outputs?.length??0)>0)??!1;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:"IPYNB",sublabel:`${b} cells \xb7 ${x} code \xb7 ${h}`,children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{navigator.clipboard.writeText(`jupyter lab ${e}`),c(!0),setTimeout(()=>c(!1),2e3)},title:"Copy: jupyter lab <path>",children:[l?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"}),l?"Copied":"Copy run cmd"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=d,e.download=u,e.click()},children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(d,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Raw JSON"]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-auto bg-[#F5EEDC]",children:r?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-[#7A6B5D] text-sm",children:"Loading notebook…"}):o?(0,s.jsxs)("div",{className:"flex items-center justify-center h-full text-[#8B2E3E] text-sm gap-2",children:[(0,s.jsx)(m.AlertCircle,{className:"h-4 w-4"})," ",o]}):t?(0,s.jsxs)("div",{className:"max-w-[1100px] mx-auto py-8 px-6",children:[!y&&x>0&&(0,s.jsxs)("div",{className:"mb-6 rounded-md border border-[#E8DDC5] bg-[#FFF9E9] px-4 py-3 text-[13px] text-[#7A6B5D]",children:[(0,s.jsx)("span",{className:"font-semibold text-[#0c0a09]",children:"This notebook hasn't been run yet."})," ","Code and markdown cells display below; outputs appear once the author runs the notebook in Jupyter (or you do, then re-save)."]}),t.cells?.map((e,t)=>"markdown"===e.cell_type?(0,s.jsx)(wH,{cell:e},t):"raw"===e.cell_type?(0,s.jsx)(wU,{cell:e},t):(0,s.jsx)(wF,{cell:e,language:h},t))]}):null})]})}function wW({path:e,extLabel:t,external:n,hideFinder:r}){let i=(0,tE.withWs)(`/api/assets/${e}`),o=e.split("/").pop()||e,a=async()=>{try{await (0,tE.wsFetch)("/api/system/reveal",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})})}catch{}};return(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:t||void 0,children:[n&&(0,s.jsxs)("a",{href:n.href,target:"_blank",rel:"noreferrer noopener",className:"inline-flex items-center gap-1.5 text-[11px] h-7 px-2.5 rounded-md border border-border hover:bg-accent transition-colors",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),n.label]}),!r&&(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-1.5 text-[11px] h-7",onClick:a,title:"Open in Finder",children:[(0,s.jsx)(e4,{className:"h-3.5 w-3.5"}),"Reveal"]}),!r&&(0,s.jsxs)(v.Button,{variant:"outline",size:"sm",className:"gap-1.5 text-[11px] h-7",onClick:()=>{let e=document.createElement("a");e.href=i,e.download=o,e.click()},title:"Download original",children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]})]})}function wq({path:t,title:n}){let r=(0,f.useRef)(null),[i,o]=(0,f.useState)(!0),[a,l]=(0,f.useState)(null);return(0,f.useEffect)(()=>{let n=!1,i=r.current;if(i)return i.innerHTML="",(async()=>{o(!0),l(null);try{let[{renderAsync:r},s]=await Promise.all([e.A(410052),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!s.ok)throw Error(`Failed to load file (${s.status})`);let a=await s.blob();if(n)return;await r(a,i,void 0,{className:"docx-rendered",inWrapper:!0,ignoreWidth:!1,ignoreHeight:!1,breakPages:!0,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,experimental:!0,useBase64URL:!0}),n||o(!1)}catch(e){n||(l(e instanceof Error?e.message:"Failed to render document"),o(!1))}})(),()=>{n=!0}},[t]),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"DOCX"}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto bg-muted/30",children:[i&&!a&&(0,s.jsxs)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Rendering document…"]}),a&&(0,s.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),(0,s.jsx)("div",{ref:r,className:"docx-viewer-body mx-auto max-w-5xl py-6 px-4"})]})]})}function wK({path:t,title:n}){let r=(0,f.useRef)(null),[i,o]=(0,f.useState)(!0),[a,l]=(0,f.useState)(null);return(0,f.useEffect)(()=>{let n=!1,i=r.current;if(!i)return;i.innerHTML="";let s=null;return(async()=>{o(!0),l(null);try{let[{init:r},a]=await Promise.all([e.A(355350),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!a.ok)throw Error(`Failed to load file (${a.status})`);let l=await a.arrayBuffer();if(n)return;let c=i.clientWidth||960,d=Math.round(9*c/16);s=r(i,{width:c,height:d,mode:"list"}),await s.preview(l),n||o(!1)}catch(e){n||(l(e instanceof Error?e.message:"Failed to render presentation"),o(!1))}})(),()=>{n=!0;try{s?.destroy?.()}catch{}}},[t]),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"PPTX"}),(0,s.jsxs)("div",{className:"flex-1 overflow-auto bg-muted/30 py-4",children:[i&&!a&&(0,s.jsxs)("div",{className:"h-[60vh] flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Rendering slides…"]}),a&&(0,s.jsx)("div",{className:"h-[60vh] flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:a}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),(0,s.jsx)("div",{ref:r,className:"pptx-viewer-body mx-auto max-w-5xl px-4"})]})]})}function wG({path:t,title:n}){let[r,i]=(0,f.useState)(null),[o,a]=(0,f.useState)(0),[l,c]=(0,f.useState)(!0),[d,p]=(0,f.useState)(null),h=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(!r||!h.current)return;let e=r[o];if(!e||null!==e.html)return;let{wb:t,toHtml:n}=h.current,s=n(t.Sheets[e.name]);i(e=>{if(!e)return e;let t=[...e];return t[o]={...t[o],html:s.html,rows:s.rows,truncated:s.truncated},t})},[r,o]),(0,f.useEffect)(()=>{let n=!1;return c(!0),p(null),i(null),(async()=>{try{let[r,s]=await Promise.all([e.A(432302),(0,tE.wsFetch)(`/api/assets/${t}`)]);if(n)return;if(!s.ok)throw Error(`Failed to load file (${s.status})`);let o=await s.arrayBuffer();if(n)return;let l=r.read(o,{type:"array",cellDates:!0,cellStyles:!0});if(n)return;h.current={wb:l,toHtml:e=>{let t=e["!ref"],n=t?r.utils.decode_range(t):null,i=n?n.e.r-n.s.r+1:0;if(!n||i<=2e3)return{html:r.utils.sheet_to_html(e,{editable:!1}),rows:i,truncated:!1};let s={...e,"!ref":r.utils.encode_range({s:n.s,e:{r:n.s.r+2e3-1,c:n.e.c}})};return{html:r.utils.sheet_to_html(s,{editable:!1}),rows:i,truncated:!0}}},i(l.SheetNames.map(e=>({name:e,html:null,rows:0,truncated:!1}))),a(0),c(!1)}catch(e){n||(p(e instanceof Error?e.message:"Failed to parse spreadsheet"),c(!1))}})(),()=>{n=!0}},[t]);let m=(0,f.useMemo)(()=>r?.[o]??null,[r,o]);return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsx)(wW,{path:t,title:n,extLabel:"XLSX"}),r&&r.length>1&&(0,s.jsx)("div",{className:"flex items-center gap-0.5 border-b border-border bg-muted/40 px-2 overflow-x-auto scrollbar-none",children:r.map((e,t)=>(0,s.jsx)("button",{type:"button",onClick:()=>a(t),className:(0,eh.cn)("px-3 py-1.5 text-[12px] rounded-t whitespace-nowrap transition-colors",t===o?"bg-background text-foreground font-medium border-t border-x border-border -mb-px":"text-muted-foreground hover:text-foreground"),children:e.name},e.name+t))}),(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[l&&!d&&(0,s.jsxs)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin mr-2"}),"Parsing spreadsheet…"]}),d&&(0,s.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center space-y-2",children:[(0,s.jsx)("p",{className:"text-sm text-destructive",children:d}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Try downloading the file and opening it externally."})]})}),m?.truncated&&(0,s.jsxs)("div",{className:"px-3 py-2 text-[11px] text-amber-600 dark:text-amber-400 border-b border-border",children:["Large sheet (",m.rows.toLocaleString()," rows). Showing first"," ",2e3.toLocaleString()," for performance. Download the file to see everything."]}),m?.html!=null&&(0,s.jsx)("div",{className:"xlsx-sheet p-3 text-[12px]",dangerouslySetInnerHTML:{__html:m.html}})]})]})}let wJ=(0,o.default)("wrap-text",[["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}],["path",{d:"M3 12h15a3 3 0 1 1 0 6h-4",key:"1cl7v7"}],["path",{d:"M3 18h7",key:"sq21v6"}],["path",{d:"M3 6h18",key:"d0wm0j"}]]),wZ=x3(wI);function wX(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function wY(e){return`${e.lineStart}:${e.lineEnd}:${e.textHash}`}function wQ(e){return`L${e.lineStart}-${e.lineEnd}`}async function w0(e){return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e)))).map(e=>e.toString(16).padStart(2,"0")).join("").slice(0,12)}let w1={".js":"javascript",".cjs":"javascript",".mjs":"javascript",".ts":"typescript",".tsx":"typescript",".jsx":"javascript",".py":"python",".rb":"ruby",".php":"php",".sh":"bash",".bash":"bash",".zsh":"bash",".ps1":"powershell",".css":"css",".scss":"scss",".html":"xml",".json":"json",".jsonc":"json",".yaml":"yaml",".yml":"yaml",".toml":"ini",".ini":"ini",".xml":"xml",".sql":"sql",".graphql":"graphql",".gql":"graphql",".go":"go",".rs":"rust",".swift":"swift",".java":"java",".kt":"kotlin",".kts":"kotlin",".c":"c",".cpp":"cpp",".h":"c",".env":"bash",".txt":"",".text":"",".log":"",".rst":"",".mdx":"markdown"};function w2({path:e}){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(0),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!0),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(!1),[m,b]=(0,f.useState)(2e3),[x,y]=(0,f.useState)(new Map),[w,k]=(0,f.useState)(null),N=(0,f.useRef)(null),S=(0,tE.withWs)(`/api/assets/${e}`),C=e.split("/").pop()||e,j=w1[C.includes(".")?`.${C.split(".").pop()?.toLowerCase()}`:""]??"",E=fp(t=>t.byPath[e]?.sidecar??null),M=E?.comments??[],A=(0,f.useMemo)(()=>t?t.replace(/\r\n/g,"\n").split("\n"):[],[t]),T=(0,f.useCallback)(async()=>{c(!0),a(!1),n(null),i(0);try{let e=await (0,tE.wsFetch)(S);if(e.ok){let t=new Uint8Array(await e.arrayBuffer());!function(e){let t=Math.min(e.length,8192);if(0===t)return!1;let n=0;for(let r=0;r<t;r++){let t=e[r];if(0===t)return!0;(t<9||t>13&&t<32)&&n++}return n/t>.3}(t)?(i(t.length),n(new TextDecoder("utf-8").decode(t))):a(!0)}}catch{}finally{c(!1)}},[S]);(0,f.useEffect)(()=>{T(),fp.getState().loadSidecar(e),b(2e3),k(null)},[T,e]);let O=(0,f.useMemo)(()=>A.length,[A]),_=r>2097152||O>5e3,D=(0,f.useMemo)(()=>{if(!t)return[];if(_)return A.map(wX);try{let e=j?wZ.highlight(j,t):wZ.highlightAuto(t);return(0,v3.toHtml)(e).split("\n")}catch{return A.map(wX)}},[t,j,_,A]),R=_?D.slice(0,m):D,I=_&&m<D.length,L=(0,f.useMemo)(()=>{let e={};for(let t of M){if(!t.lineAnchor)continue;let n=wY(t.lineAnchor);(e[n]??=[]).push(t)}return e},[M]);(0,f.useEffect)(()=>{if(!t||o||l||!N.current)return void y(new Map);let e=N.current,n=e.getBoundingClientRect(),r=Array.from(e.querySelectorAll("[data-line]")),i=new Map;for(let t of r){let r=Number(t.dataset.line);if(!Number.isFinite(r))continue;let s=t.getBoundingClientRect();i.set(r,{top:s.top-n.top+e.scrollTop,left:s.left-n.left,width:s.width,bottom:s.bottom-n.top+e.scrollTop})}y(i)},[t,o,l,m,d,D]);let P=(0,f.useCallback)(()=>{let e=N.current,t=window.getSelection();if(!e||!t||t.isCollapsed||0===t.rangeCount)return;let n=t.getRangeAt(0);if(!e.contains(n.commonAncestorContainer))return;let r=e=>{let t=e?e.nodeType===Node.ELEMENT_NODE?e:e.parentElement:null;return t?.closest("[data-line]")??null},i=r(n.startContainer),s=r(n.endContainer);if(!i||!s)return;let o=Number(i.dataset.line),a=Number(s.dataset.line);if(!Number.isFinite(o)||!Number.isFinite(a))return;let l=Math.min(o,a),c=Math.max(o,a),d=A.slice(l-1,c).join("\n");(async()=>{let e={lineStart:l,lineEnd:c,textHash:await w0(d)};k({anchorKey:wY(e),anchorLabel:wQ(e),lineAnchor:e,anchorEl:i})})()},[A]),z=(0,f.useCallback)((e,t)=>{k({anchorKey:wY(e),anchorLabel:wQ(e),lineAnchor:e,anchorEl:t})},[]);return o?(0,s.jsx)(vX,{path:e,title:C}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:C.includes(".")?C.split(".").pop()?.toUpperCase()??"TEXT":"TEXT",children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:`h-7 gap-1.5 text-xs ${d?"bg-muted":""}`,onClick:()=>u(e=>!e),title:d?"Disable line wrap":"Enable line wrap",children:[(0,s.jsx)(wJ,{className:"h-3.5 w-3.5"}),"Wrap"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{t&&(navigator.clipboard.writeText(t),h(!0),setTimeout(()=>h(!1),2e3))},title:"Copy file contents",children:[p?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"}),p?"Copied":"Copy"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>{let e=document.createElement("a");e.href=S,e.download=C,e.click()},title:"Download file",children:[(0,s.jsx)(ne.Download,{className:"h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(S,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Raw"]})]}),(0,s.jsxs)("div",{ref:N,className:"relative flex-1 overflow-auto source-viewer-code bg-background",children:[!l&&t&&!o&&(0,s.jsx)(vG,{containerRef:N,onComment:P,align:"left"}),(0,s.jsx)("div",{className:"relative pointer-events-none",style:{height:0},children:Object.entries(L).map(([e,t])=>{let n=t[0]?.lineAnchor;if(!n)return null;let r=x.get(n.lineStart);return r?(0,s.jsx)("div",{style:{pointerEvents:"auto"},children:(0,s.jsx)(y_,{anchorKey:e,anchorLabel:wQ(n),comments:t,top:r.top+4,left:Math.max(0,r.left-20),onClick:()=>{let e=N.current?.querySelector(`[data-line="${n.lineStart}"]`);e&&z(n,e)}})},`pip-${e}`):null})}),l?(0,s.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:"Loading..."}):(0,s.jsxs)(s.Fragment,{children:[_&&(0,s.jsxs)("div",{className:"px-4 py-2 text-[11px] text-amber-700 dark:text-amber-300 bg-amber-500/15 border-b border-amber-500/30 font-sans",children:["Large file (",(r/1048576).toFixed(1)," MB, ",D.length.toLocaleString()," lines). Syntax highlighting disabled for performance. Use Raw or Download for the full file."]}),(0,s.jsx)("div",{className:"leading-relaxed font-mono min-w-max",style:{fontSize:"calc(13px * var(--font-scale-code, 1))"},children:R.map((e,t)=>{let n=w?.lineAnchor,r=n&&t+1>=n.lineStart&&t+1<=n.lineEnd;return(0,s.jsxs)("div",{"data-line":t+1,className:`flex ${r?"bg-amber-400/25":"hover:bg-foreground/5"}`,children:[(0,s.jsx)("span",{className:"w-12 shrink-0 pr-4 text-right text-muted-foreground select-none sticky left-0 bg-muted",children:t+1}),(0,s.jsx)("span",{className:`text-foreground pl-2 ${d?"whitespace-pre-wrap break-all":"whitespace-pre"}`,dangerouslySetInnerHTML:{__html:e||" "}})]},t)})}),I&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-t border-border font-sans",children:[(0,s.jsxs)("button",{onClick:()=>b(e=>e+2e3),className:"text-[11px] text-foreground hover:text-foreground px-2.5 py-1 rounded bg-foreground/10 hover:bg-foreground/20 transition-colors",children:["Show ",Math.min(2e3,D.length-m).toLocaleString()," more"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[m.toLocaleString()," / ",D.length.toLocaleString()," lines"]})]})]}),w&&(0,s.jsx)(y4,{path:e,anchorKey:w.anchorKey,anchorLabel:w.anchorLabel,lineAnchor:w.lineAnchor,comments:L[w.anchorKey]??[],anchorEl:w.anchorEl,onClose:()=>k(null)})]})]})}var w3=e.i(727551),w5=e.i(496366);function w4({path:e,title:t,src:n,fullscreen:r,onExit:i,scriptsEnabled:o,onToggleScripts:a}){let[l,c]=(0,f.useState)(!1),d=o??l,u=(0,tE.withWs)(n??`/api/assets/${e}/index.html`),p=r&&i?(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:i,title:"Exit app",children:[(0,s.jsx)(v_,{className:"h-3.5 w-3.5"}),"Exit app"]}):null;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:r?"App":void 0,showBreadcrumb:!r,leading:r?(0,s.jsxs)(s.Fragment,{children:[p,(0,s.jsx)("span",{className:"truncate text-[13px] font-medium text-foreground",children:t})]}):null,children:[(0,s.jsx)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:a??(()=>c(e=>!e)),title:d?"Disable scripts (recommended for untrusted content)":"Enable scripts",children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(w5.Ban,{className:"h-3.5 w-3.5"}),"Disable scripts"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(w3.Play,{className:"h-3.5 w-3.5"}),"Enable scripts"]})}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(u,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]})]}),(0,s.jsx)("iframe",{src:u,className:"flex-1 w-full border-0 bg-card",title:t,sandbox:d?"allow-scripts allow-forms allow-popups allow-top-navigation-by-user-activation":"allow-forms allow-popups allow-top-navigation-by-user-activation"})]})}let w6=(0,o.default)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),w9={stopped:"Stopped",installing:"Installing dependencies…",starting:"Starting…",running:"Running",error:"Error"};function w7({path:e,title:t}){let[n,r]=(0,f.useState)("stopped"),[i,o]=(0,f.useState)(null),[a,l]=(0,f.useState)([]),[c,d]=(0,f.useState)(null),[p,h]=(0,f.useState)(!1),[g,x]=(0,f.useState)(0),[y,w]=(0,f.useState)([]),[k,N]=(0,f.useState)(null),S=(0,f.useRef)(null),C=(0,f.useRef)(null),j=(0,tE.withWs)(`/api/app-proxy/${e}/`),E=()=>{S.current&&(clearInterval(S.current),S.current=null)},M=(0,f.useCallback)(async()=>{try{let t=await (0,tE.wsFetch)(`/api/wiki/app?path=${encodeURIComponent(e)}`);if(!t.ok)return;let n=await t.json();r(n.status),l(n.logs??[]),n.scripts&&w(n.scripts),void 0!==n.defaultScript&&N(n.defaultScript),n.port&&o(n.port),n.error&&d(n.error),("running"===n.status||"stopped"===n.status||"error"===n.status)&&E()}catch{}},[e]);(0,f.useEffect)(()=>("installing"===n||"starting"===n?S.current||(S.current=setInterval(M,800)):E(),E),[n,M]),(0,f.useEffect)(()=>{C.current?.scrollIntoView({behavior:"smooth"})},[a]),(0,f.useEffect)(()=>{M()},[M]);let A=async t=>{d(null),l([]),r("starting");try{let n=await (0,tE.wsFetch)("/api/wiki/app",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,script:t})}),i=await n.json();if(!n.ok||i.error){r("error"),d(i.error??"Failed to start");return}i.port&&o(i.port),await M()}catch(e){r("error"),d(String(e))}},T=async()=>{await (0,tE.wsFetch)("/api/wiki/app",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}),r("stopped"),o(null)},O=async()=>{await T(),await A(),x(e=>e+1)},_=y.filter(e=>e!==k);return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.ViewerToolbar,{path:e,badge:"Node app",children:["running"===n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>x(e=>e+1),children:[(0,s.jsx)(tR,{className:"h-3.5 w-3.5"}),"Refresh"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>window.open(j,"_blank"),children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:O,children:[(0,s.jsx)(tR,{className:"h-3.5 w-3.5"}),"Restart"]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs text-destructive hover:text-destructive",onClick:T,children:[(0,s.jsx)(w6,{className:"h-3.5 w-3.5"}),"Stop"]})]}),(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:()=>h(e=>!e),children:[(0,s.jsx)(no,{className:"h-3.5 w-3.5"}),"Logs"]})]}),p&&(0,s.jsxs)("div",{className:"border-b bg-black/90 text-green-400 font-mono text-xs h-40 overflow-auto p-2 shrink-0",children:[0===a.length?(0,s.jsx)("span",{className:"text-muted-foreground",children:"No output yet."}):a.map((e,t)=>(0,s.jsx)("div",{className:"whitespace-pre-wrap leading-5",children:e},t)),(0,s.jsx)("div",{ref:C})]}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:["stopped"===n&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-4",children:[(0,s.jsxs)("div",{className:"text-center space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:t}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Node.js app — will be started on a local port"})]}),(0,s.jsxs)("div",{className:"inline-flex items-stretch overflow-hidden rounded-full bg-primary text-primary-foreground shadow-e-1",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>A(),className:"inline-flex items-center gap-2 px-4 py-2.5 text-sm font-medium transition-colors hover:bg-primary-foreground/10 focus-visible:outline-none",children:[(0,s.jsx)(w3.Play,{className:"h-4 w-4"}),"Launch app",k&&(0,s.jsxs)("span",{className:"opacity-70",children:["(",k,")"]})]}),_.length>0&&(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)("button",{type:"button",className:"inline-flex items-center justify-center border-l border-l-primary-foreground/20 px-2 transition-colors hover:bg-primary-foreground/10 focus-visible:outline-none","aria-label":"Choose script to launch",children:(0,s.jsx)(b,{className:"h-4 w-4"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",children:[(0,s.jsx)(ek.DropdownMenuLabel,{children:"Run script"}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),y.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onSelect:()=>A(e),className:"gap-2 font-mono text-xs",children:[(0,s.jsx)(w3.Play,{className:"h-3.5 w-3.5"}),e,e===k&&(0,s.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground",children:"default"})]},e))]})]})]})]}),("installing"===n||"starting"===n)&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3",children:[(0,s.jsx)(u.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:w9[n]}),i&&(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60",children:["port ",i]}),(0,s.jsxs)(v.Button,{onClick:T,variant:"outline",size:"sm",className:"gap-2",children:[(0,s.jsx)(w6,{className:"h-3.5 w-3.5"}),"Cancel"]})]}),"error"===n&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-6",children:[(0,s.jsx)(m.AlertCircle,{className:"h-8 w-8 text-destructive"}),(0,s.jsxs)("div",{className:"text-center space-y-1 max-w-md",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-destructive",children:"Failed to start app"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground break-words",children:c??"Unknown error"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(v.Button,{onClick:T,variant:"ghost",className:"gap-2",children:"Back"}),(0,s.jsxs)(v.Button,{onClick:O,variant:"outline",className:"gap-2",children:[(0,s.jsx)(tR,{className:"h-4 w-4"}),"Try again"]})]})]}),"running"===n&&(0,s.jsx)("iframe",{src:j,className:"flex-1 w-full border-0 bg-card",title:t,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-modals allow-top-navigation-by-user-activation"},g)]})]})}let w8=(0,ii.default)(()=>e.A(810497).then(e=>e.PdfViewer),{loadableGenerated:{modules:[904378]},ssr:!1});function ke(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}let kt=new Set(["image","media","pdf","fallback","app","node-app","html"]);function kn({openFile:e,fileContent:t,fileLoading:n,editing:r,setEditing:i,editContent:o,setEditContent:a,saving:p,saveError:m,onSave:b,gitFileInfo:x,showHistory:y,historyLoading:w,historyCommits:k,selectedDiffSha:N,diffContent:S,diffLoading:C,onToggleHistory:j,onSelectDiff:E,gateBypassPath:M,onBypassGate:A,onRefresh:T,onShare:O,onClose:_,renderCopyMenu:D,appKey:R,setAppKey:I,appFullscreen:L,setAppFullscreen:P,viewerKey:z,setViewerKey:$,htmlSourceMode:B,setHtmlSourceMode:F,widthAwareViewer:H,viewWidth:U,viewAlign:V,setViewWidth:W,setViewAlign:q,contentWidthClass:K,contentAlignClass:G,isMobile:J,sidebarCollapsed:Z}){let[X,Y]=(0,f.useState)(null),[Q,ee]=(0,f.useState)(null),[et,en]=(0,f.useState)(!1);(0,f.useEffect)(()=>{en(!1)},[e.path]);let er=nF(e.name,e.nodeType),ei=!kt.has(er)&&(e.size??0)>5242880&&M!==e.path;if("node-app"===er)return(0,s.jsx)(w7,{path:e.path,title:e.name});let es="html"===er?(0,tE.withWs)(`/api/assets/${e.path}`):void 0;return"app"===er||"html"===er?L?(0,s.jsx)(w4,{scriptsEnabled:et,onToggleScripts:()=>en(e=>!e),path:e.path,title:e.name,src:es,fullscreen:!0,onExit:()=>P(!1)}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,s.jsxs)("div",{className:(0,eh.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 ",!J&&Z&&"pl-11"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)("span",{className:"hidden md:inline-flex",children:(0,s.jsx)("span",{className:"",children:(0,s.jsx)(c,{className:"h-4 w-4 shrink-0 text-foreground/70"})})}),(0,s.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:e.path,children:e.path}),(0,s.jsx)("div",{ref:e=>{e&&ee(e)},className:"flex items-center gap-1 shrink-0"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)("div",{ref:e=>{e&&Y(e)},className:"flex items-center gap-1 shrink-0"}),D(e,(0,s.jsxs)(s.Fragment,{children:["html"===er&&!r&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>F(!B),children:[B?(0,s.jsx)(c,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(r7,{className:"mr-2 h-3.5 w-3.5"}),B?"Show preview":"Show source"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>I(e=>e+1),children:[(0,s.jsx)(tR,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>P(!0),children:[(0,s.jsx)(r8,{className:"mr-2 h-3.5 w-3.5"}),"Open fullscreen"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:O,children:[(0,s.jsx)(it,{className:"mr-2 h-3.5 w-3.5"}),"Share"]})]})),"html"===er&&!r&&null!==t&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{i(!0),a(t)},children:(0,s.jsx)(ie,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:_,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]})]}),r&&"html"===er?(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,s.jsx)("textarea",{value:o,onChange:e=>a(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,s.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[m&&(0,s.jsx)("span",{className:"text-xs text-destructive mr-auto",children:m}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",className:"gap-1",onClick:b,disabled:p,children:[p&&(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):B&&"html"===er?(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)(w2,{path:e.path,title:e.name})})}):(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)(w4,{scriptsEnabled:et,onToggleScripts:()=>en(e=>!e),path:e.path,title:e.name,src:es},R)})})]}):(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,s.jsxs)("div",{className:(0,eh.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 ",!J&&Z&&"pl-11"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,s.jsx)("span",{className:"hidden md:inline-flex",children:(0,s.jsx)("span",{className:"",children:nW(e.name)?(0,s.jsx)(d.Image,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):nU(e.name)?(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,s.jsx)(nr,{className:"h-4 w-4 shrink-0 text-foreground/60"})})}),(0,s.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:e.path,children:e.path}),(0,s.jsx)("div",{ref:e=>{e&&ee(e)},className:"flex items-center gap-1 shrink-0"}),x&&(0,s.jsxs)("span",{className:"hidden md:flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 ml-1",children:[(0,s.jsx)(ir,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate max-w-[100px]",children:x.author}),(0,s.jsx)("span",{title:new Date(x.date).toLocaleString(),className:"shrink-0",children:ke(x.date)})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[(0,s.jsx)("div",{ref:e=>{e&&Y(e)},className:"flex items-center gap-1 shrink-0"}),D(e,(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:j,children:[(0,s.jsx)(rK,{className:"mr-2 h-3.5 w-3.5"}),y?"Hide history":"File history"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:O,children:[(0,s.jsx)(it,{className:"mr-2 h-3.5 w-3.5"}),"Share"]}),!r&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:T,disabled:n,children:[n?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tR,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),H&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsx)(ek.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Width"}),rF.VIEW_WIDTH_ORDER.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>W(e),className:"flex items-center justify-between text-xs",children:[rF.VIEW_WIDTH_LABEL[e],e===U&&(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5"})]},e)),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsx)(ek.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Alignment"}),rF.VIEW_ALIGN_ORDER.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>q(e),className:"flex items-center justify-between text-xs",children:[rF.VIEW_ALIGN_LABEL[e],e===V&&(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5"})]},e))]})]})),nU(e.name)&&!r&&(null!==t||nV(e.name))&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{i(!0),a(t??"")},children:(0,s.jsx)(ie,{className:"h-3.5 w-3.5"})}),nU(e.name)&&r&&nV(e.name)&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>i(!1),children:(0,s.jsx)(rW.Eye,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:_,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]})]}),y&&(0,s.jsxs)("div",{className:"border-b bg-muted/30 shrink-0 max-h-[40vh] overflow-auto",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-1.5 border-b",children:[(0,s.jsx)("span",{className:"text-xs font-semibold text-muted-foreground",children:"History"}),(0,s.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:j,children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),w?(0,s.jsx)("div",{className:"flex justify-center py-4",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===k.length?(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,s.jsx)("div",{children:k.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsx)("button",{type:"button",className:(0,eh.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",N===e.sha&&"bg-muted"),onClick:()=>E(e.sha),children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"text-[11px] font-mono text-muted-foreground shrink-0",children:e.shortSha}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",children:e.message}),(0,s.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:e.author}),(0,s.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",title:new Date(e.date).toLocaleString(),children:ke(e.date)})]})}),N===e.sha&&(0,s.jsx)("div",{className:"border-t",children:C?(0,s.jsx)("div",{className:"flex justify-center py-3",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==S?(0,s.jsx)("pre",{className:"overflow-auto px-4 py-2 text-[11px] font-mono leading-relaxed whitespace-pre text-foreground/80 max-h-60",children:S}):null})]},e.sha))})]}),ei?(0,s.jsx)(vQ,{path:e.path,size:e.size??0,onOpen:A}):r?(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:nV(e.name)?(0,s.jsx)(vZ,{}):(0,s.jsx)("textarea",{value:o,onChange:e=>a(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):nV(e.name)?(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,s.jsx)(vZ,{mode:"viewing"})}):"csv"===er||"pdf"===er||"mermaid"===er||"notebook"===er||"image"===er||"media"===er||"docx"===er||"xlsx"===er||"pptx"===er||"source"===er||"fallback"===er?(0,s.jsx)(io.ViewerToolbarBadgeSlotContext.Provider,{value:Q,children:(0,s.jsx)(io.ViewerToolbarSlotContext.Provider,{value:X,children:(0,s.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===er?(0,s.jsx)(ic,{path:e.path,title:e.name}):"pdf"===er?(0,s.jsx)(w8,{path:e.path,title:e.name}):"mermaid"===er?(0,s.jsx)(v2,{path:e.path,title:e.name}):"notebook"===er?(0,s.jsx)(wV,{path:e.path,title:e.name}):"image"===er?(0,s.jsx)(v0,{path:e.path,title:e.name}):"media"===er?(0,s.jsx)(v1,{path:e.path,title:e.name,type:["mp4","webm","mov","m4v"].includes(nB(e.name))?"video":"audio"}):"docx"===er?(0,s.jsx)(wq,{path:e.path,title:e.name}):"xlsx"===er?(0,s.jsx)(wG,{path:e.path,title:e.name}):"pptx"===er?(0,s.jsx)(wK,{path:e.path,title:e.name}):"source"===er?(0,s.jsx)(w2,{path:e.path,title:e.name}):(0,s.jsx)(vX,{path:e.path,title:e.name})},z)})}):(0,s.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,s.jsx)("div",{className:(0,eh.cn)("w-full",G,K),children:n?(0,s.jsx)("div",{className:"flex justify-center py-8",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):null!==t?(0,s.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:t}):nU(e.name)?(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),r&&!nV(e.name)&&(0,s.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[m&&(0,s.jsx)("span",{className:"text-xs text-destructive mr-auto",children:m}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",onClick:()=>i(!1),children:"Cancel"}),(0,s.jsxs)(v.Button,{size:"sm",className:"gap-1",onClick:b,disabled:p,children:[p&&(0,s.jsx)(u.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]})}function kr(e="(max-width: 767px)"){let[t,n]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[e]),t}function ki(e){return e?`wiki-recent-files-${e}`:"wiki-recent-files"}function ks(e){try{let t=localStorage.getItem(ki(e));return t?JSON.parse(t):[]}catch{return[]}}let ko=(0,eN.create)(e=>({recents:[],loadForWorkspace:t=>{e({recents:ks(t)})},push:(t,n)=>{let r=ks(n).filter(e=>e.path!==t.path),i=[t,...r].slice(0,15);localStorage.setItem(ki(n),JSON.stringify(i)),e({recents:i})}})),ka=new Map,kl=new Map;async function kc(e){let t=await (0,tE.wsFetch)(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1,git:t.git})):[]}async function kd(e){let t=ka.get(e);if(t)return ka.delete(e),t;let n=kl.get(e);if(n){let t=await n;return ka.delete(e),t}return null}function ku(e,t,n){return e.map(e=>e.path===t?n(e):e.children?{...e,children:ku(e.children,t,n)}:e)}function kp(e){let t=[];for(let n of e)("dir"===n.type||"app"===n.type||"node-app"===n.type)&&n.expanded&&n.children&&(t.push(n.path),t.push(...kp(n.children)));return t}function kh(e){return e.split("/").pop()??e}e.s(["default",0,function(){let e=function(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,s]=(0,f.useState)(()=>(0,tE.getActiveWorkspaceId)()),[o,a]=(0,f.useState)([]),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(null),[b,x]=(0,f.useState)({}),[y,v]=(0,f.useState)(null),[w,k]=(0,f.useState)(null),[N,S]=(0,f.useState)(null),[C,j]=(0,f.useState)(null),E=(0,f.useCallback)(async()=>{let e=(0,tE.getEphemeralRoot)();if(e){a([]),c(!1),t(!0),r(e),s(`root:${e}`);return}try{let e=await fetch((0,ev.apiUrl)("/api/system/workspaces"));if(!e.ok)throw Error("Failed");let n=await e.json();if(a(n.workspaces),c(n.isAdmin),n.workspaces.length>0){t(!0);let e=new URLSearchParams(window.location.search).get("ws"),i=e?n.workspaces.find(t=>t.id===e):null,o=i??[...n.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(s(o.id),r(o.rootDir),!i){let e=new URL(location.href);e.searchParams.set("ws",o.id),history.replaceState(null,"",e.toString())}}else t(!1)}catch{t(!1)}},[]);(0,f.useEffect)(()=>{E()},[E]);let M=(0,f.useCallback)(async e=>{if(e===i)return;try{await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/open`),{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),fd.getState().invalidate(),vM.getState().invalidateAll();let n=o.find(t=>t.id===e);n&&r(n.rootDir),s(e)},[i,o]),A=(0,f.useCallback)(async e=>{if(p)try{if(!(await fetch((0,ev.apiUrl)(`/api/system/workspaces/${p}`),{method:"DELETE"})).ok)throw Error("Failed");if(p===i){let n=o.filter(e=>e.id!==p);if(n.length>0){let t=[...n].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await e(t.id)}else t(!1)}await E()}catch{}finally{h(null)}},[p,i,o,E]),T=(0,f.useCallback)(async e=>{if(!m){g(e);try{let t=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/refresh`),{method:"POST"});if(!t.ok){let e=await t.json();ey(e.error??"Refresh failed");return}await E()}catch{ey("Refresh failed")}finally{g(null)}}},[m,E]),O=(0,f.useCallback)(async e=>{if(!b[e])try{let t=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/branch`));if(!t.ok)return;let n=await t.json();x(t=>({...t,[e]:n.branches??[]}))}catch{}},[b]),_=(0,f.useCallback)(async(e,t)=>{if(!y){v(e),k(t);try{let n=await fetch((0,ev.apiUrl)(`/api/system/workspaces/${e}/branch`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!n.ok){let e=await n.json();ey(e.error??"Branch switch failed");return}ex(`Switched to ${t}`),S(null),j(null),await E()}catch{ey("Branch switch failed")}finally{v(null),k(null)}}},[y,E]);return{rootConfigured:e,rootPath:n,activeWorkspaceId:i,workspaces:o,isWsAdmin:l,addingWorkspace:d,setAddingWorkspace:u,setRootConfigured:t,setActiveWorkspaceId:s,deletingWorkspaceId:p,setDeletingWorkspaceId:h,refreshingWsId:m,wsBranches:b,switchingBranch:y,switchingBranchName:w,branchPickerWsId:N,setBranchPickerWsId:S,wsBranchPos:C,setWsBranchPos:j,loadWorkspaces:E,switchWorkspace:M,handleDeleteWorkspace:A,handleRefreshWorkspace:T,loadWsBranches:O,handleSwitchBranch:_}}(),t=(0,f.useRef)(()=>{}),n=function({activeWorkspaceId:e,rootConfigured:t,onExternalChange:n}){let[r,i]=(0,f.useState)([]),[s,o]=(0,f.useState)(!1),[a,l]=(0,f.useState)(!1),c=(0,f.useRef)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)({}),[m,g]=(0,f.useState)({}),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)(null),[w,k]=(0,f.useState)(null),[N,S]=(0,f.useState)(null);(0,f.useEffect)(()=>{i([]),o(!1),c.current=!1,h({}),g({}),x(null),v(null),k(null),S(null)},[e]),(0,f.useEffect)(()=>{!e||s||c.current||(c.current=!0,l(!0),kc("").then(e=>{i(e),o(!0),l(!1)}).catch(()=>{c.current=!1,l(!1)}))},[s,e]);let C=(0,f.useCallback)(async e=>{let t=await kc(e);""===e?i(e=>{let n=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=n.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):i(n=>ku(n,e,e=>({...e,children:t,expanded:!0})))},[]),j=(0,f.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let n=[],r="";for(let e=0;e<t.length-1;e++)r=r?`${r}/${t[e]}`:t[e],n.push({prefix:r,children:await kc(r)});i(e=>{let t=e;for(let{prefix:e,children:r}of n)t=ku(t,e,e=>({...e,children:r,expanded:!0}));return t})},[]),E=(0,f.useCallback)(async()=>{u(!0);try{let e=kp(r),t=await kc("");for(let n of(i(t),e)){let e=await kc(n);i(t=>ku(t,n,t=>({...t,children:e,expanded:!0})))}}finally{u(!1)}},[r]),M=(0,f.useCallback)(async e=>{if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)i(t=>ku(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await kd(e.path);if(t)return void i(n=>ku(n,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));i(t=>ku(t,e.path,e=>({...e,loading:!0})));let n=await kc(e.path);i(t=>ku(t,e.path,e=>({...e,loading:!1,children:n,expanded:!0})))}else i(t=>ku(t,e.path,e=>({...e,expanded:!0})))},[]),A=(0,f.useCallback)(e=>{"file"===e.type?(e.name.endsWith(".md")||e.name.endsWith(".markdown"))&&tJ(e.path):function(e){if(ka.has(e)||kl.has(e))return;let t=kc(e).then(t=>(ka.set(e,t),t)).finally(()=>kl.delete(e));kl.set(e,t),t.catch(()=>{})}(e.path)},[]),T=(0,f.useRef)([]);(0,f.useEffect)(()=>{T.current=kp(r)},[r]);let O=(0,f.useMemo)(()=>kp(r).filter(e=>""!==e).slice(0,24).join("\n"),[r]),[_,D]=(0,f.useState)("");(0,f.useEffect)(()=>{let e=setTimeout(()=>D(O),300);return()=>clearTimeout(e)},[O]);let R=(0,f.useRef)(n);(0,f.useEffect)(()=>{R.current=n},[n]),(0,f.useEffect)(()=>{if(!t||(0,ev.isLite)()||!e)return;let n=new Map;function r(e){n.has(e)&&clearTimeout(n.get(e)),n.set(e,setTimeout(()=>{n.delete(e),C(e)},300))}let i=(_?_.split("\n"):[]).map(e=>`dir=${encodeURIComponent(e)}`).join("&"),s=new EventSource((0,tE.withWs)(i?`/api/wiki/watch?${i}`:"/api/wiki/watch"));return s.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}let{type:i,path:s}=t;if("rescan"===i){for(let e of(vM.getState().invalidateAll(),r(""),T.current))r(e);return}("add"===i||"change"===i||"unlink"===i)&&vM.getState().invalidateAll();let o=s.split("/");if(r(o.length>1?o.slice(0,-1).join("/"):""),"change"===i){let e=`__file__${s}`;n.has(e)&&clearTimeout(n.get(e)),n.set(e,setTimeout(()=>{n.delete(e),R.current?.(s)},400))}},()=>{for(let e of(s.close(),n.values()))clearTimeout(e)}},[t,C,e,_]);let I=(0,f.useCallback)(async e=>{if(!p[e]&&!m[e]){g(t=>({...t,[e]:!0}));try{let t=await (0,tE.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(!t.ok)return void ey("Could not load branches");let n=await t.json();h(t=>({...t,[e]:n.branches}))}catch{ey("Could not load branches")}finally{g(t=>({...t,[e]:!1}))}}},[p,m]),L=(0,f.useCallback)(async(e,t,n)=>{if(!b){x(t);try{let r=await (0,tE.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===r.status)return void ey("Repository has uncommitted changes");if(!r.ok){let e=await r.json();ey(e.error??"Checkout failed");return}let i=await r.json();ex(`Switched to ${i.branch}`),k(null),S(null),h(t=>{let n={...t};return delete n[e],n}),await C(n)}catch{ey("Checkout failed")}finally{x(null)}}},[b,C]),P=(0,f.useCallback)(async(e,t)=>{if(!y){v(e);try{let n=await (0,tE.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!n.ok){let e=await n.json();ey(e.message??e.error??"Pull failed");return}let r=await n.json();ex(`Pulled ${e} (${r.branch} @ ${r.sha.slice(0,7)})`),await C(t)}catch{ey("Pull failed")}finally{v(null)}}},[y,C]);return{roots:r,rootLoaded:s,rootLoading:a,refreshingTree:d,refreshTree:E,reloadDir:C,revealPath:j,toggleFolder:M,prefetch:A,nodeBranches:p,branchesLoading:m,checkingOutBranch:b,pullingRepo:y,branchDropdownNode:w,setBranchDropdownNode:k,branchDropdownPos:N,setBranchDropdownPos:S,loadBranches:I,handleCheckout:L,handleGitPull:P}}({activeWorkspaceId:e.activeWorkspaceId,rootConfigured:e.rootConfigured,onExternalChange:(0,f.useCallback)(e=>t.current(e),[])}),r=function({activeWorkspaceId:e,rootPath:t,isMobile:n,setSidebarCollapsed:r,treeApi:i}){let[s,o]=(0,f.useState)(null),[a,l]=(0,f.useState)(null),[c,d]=(0,f.useState)(!1),[u,p]=(0,f.useState)(0),[h,m]=(0,f.useState)(0),[g,b]=(0,f.useState)(null),[x,y]=(0,f.useState)(0),[v,w]=(0,f.useState)(!1),[k,N]=(0,f.useState)(!1),[S,C]=(0,f.useState)(""),[j,E]=(0,f.useState)(!1),[M,A]=(0,f.useState)(!1),[T,O]=(0,f.useState)(null),_=(0,f.useRef)(null),D=(0,f.useRef)(!1);(0,f.useEffect)(()=>{_.current=s},[s]),(0,f.useEffect)(()=>{D.current=k},[k]);let R=(0,f.useMemo)(()=>s?nF(s.name,s.nodeType):null,[s]),I=(0,f.useCallback)(()=>{N(!1),E(!1),O(null),b(null),y(0),l(null)},[]),L=(0,f.useCallback)(async(e,t)=>{var n;if(["editor","text"].includes(t)||nU((n=e).split("/").pop()??n)){w(!0);try{let t=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(t.ok){let e=await t.json();b(e.content),y(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}w(!1)}},[]),P=(0,f.useCallback)(async t=>{if("file"===t.type&&ko.getState().push({path:t.path,name:t.name},e),o({path:t.path,name:t.name,size:t.size,nodeType:"app"===t.type?"app":"node-app"===t.type?"node-app":"file"}),I(),"file"===t.type&&nV(t.name)){w(!0);try{await t1.getState().loadPage(t.path)}finally{w(!1)}return}let n=nF(t.name,t.type);await L(t.path,n)},[e,I,L]),z=(0,f.useCallback)(()=>{o(null),b(null),N(!1),E(!1),O(null)},[]),$=(0,f.useCallback)(()=>{o(null),b(null),N(!1),E(!1),O(null),y(0)},[]),B=(0,f.useCallback)(e=>{let t=e.split("/").pop()??e;i.revealPath(e),P({path:e,name:t,type:"file",modifiedAt:""})},[P,i]),F=(0,f.useCallback)(async e=>{let t=e.path.split("/").slice(0,-1).join("/"),s=(await kc(t)).find(t=>t.path===e.path);if(s){if("dir"===s.type){await i.revealPath(e.path),await i.toggleFolder(s);return}if("app"===s.type||"node-app"===s.type){await i.revealPath(s.path),P({path:s.path,name:s.name,type:s.type,modifiedAt:s.modifiedAt}),await i.toggleFolder(s),n&&r(!0);return}P({path:s.path,name:s.name,type:s.type,modifiedAt:s.modifiedAt}),n&&r(!0)}},[n,P,r,i]),H=(0,f.useCallback)(async e=>{if(!e)return void o(null);let n=(0,tE.toRootRelative)(e,(0,tE.getEphemeralRoot)()??t);if(null===n||!(e=n))return;let r=e.split("/"),s=r[r.length-1],a=r.slice(0,-1).join("/"),l=(await kc(a)).find(t=>t.path===e);l&&(await i.revealPath(e),P({path:e,name:s,type:l.type,modifiedAt:l.modifiedAt}))},[P,t,i]);(0,f.useEffect)(()=>{let e=new URL(window.location.href);s?e.searchParams.set("path",s.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[s]),(0,f.useEffect)(()=>{let e=()=>{H(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[H]);let[U,V]=(0,f.useState)(!1);(0,f.useEffect)(()=>{V("1"===new URLSearchParams(window.location.search).get("embed"))},[]),(0,f.useEffect)(()=>{if(!U)return;let e=e=>{e.origin!==window.location.origin?console.warn(`[wiki-viewer] ignored postMessage from untrusted parent origin ${e.origin}.`):e.data&&"open-file"===e.data.type&&"string"==typeof e.data.path&&H(e.data.path)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[U,H]);let W=(0,f.useRef)(new URLSearchParams(window.location.search).get("path")??new URLSearchParams(window.location.search).get("file")),q=(0,f.useRef)(!1),[K,G]=(0,f.useState)(!1),J=(0,f.useCallback)(()=>G(!0),[]);(0,f.useEffect)(()=>{q.current||K&&(q.current=!0,H(W.current))},[K,H]),(0,f.useEffect)(()=>{s&&nV(s.name)&&t1.getState().currentPath!==s.path&&t1.getState().loadPage(s.path)},[s]);let Z=(0,f.useCallback)(async()=>{let e=_.current;if(e){if(nV(e.name)){w(!0);try{await t1.getState().loadPage(e.path)}finally{w(!1)}return}if(["editor","text"].includes(nF(e.name,e.nodeType))||nU(e.name)){w(!0);try{let t=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();b(e.content),y(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}w(!1)}}},[]),X=(0,f.useCallback)(()=>{m(e=>e+1),Z()},[Z]),Y=(0,f.useCallback)(e=>{let t=_.current;t&&t.path===e&&!D.current&&Z()},[Z]),Q=(0,f.useCallback)(async()=>{let e=_.current;if(!e)return;A(!0),O(null);let t=await (0,tE.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e.path,content:S,baseRevision:x})});if(t.ok){let e=await t.json();"number"==typeof e.revision&&y(e.revision),b(S),N(!1)}else O((await t.json()).error??"Save failed");A(!1)},[S,x]);async function ee(e){let t=_.current;if(t?.path===e&&null!==g)return g;if(t1.getState().currentPath===e)return t1.getState().content;let n=await (0,tE.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!n.ok)throw Error("Cannot copy content");return(await n.json()).content}return{openFile:s,openFileViewerKind:R,fileContent:g,fileRevision:x,fileLoading:v,editing:k,setEditing:N,editContent:S,setEditContent:C,htmlSourceMode:j,setHtmlSourceMode:E,saving:M,saveError:T,appFullscreen:c,setAppFullscreen:d,appKey:u,setAppKey:p,viewerKey:h,setViewerKey:m,gateBypassPath:a,bypassGate:()=>l(_.current?.path??null),openViewer:P,openFromSearch:B,openFavoriteEntry:F,navigateToPath:H,handleSave:Q,refreshViewer:Z,handleRefresh:X,closeFile:z,clearFile:$,onExternalChange:Y,markRootLoaded:J,copyPath:e=>{navigator.clipboard.writeText(e),ex("Path copied")},copyWikiLink:e=>{let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),ex("Wiki link copied")},copyUrl:t=>{let n=new URL(location.href);n.searchParams.set("path",t),e&&n.searchParams.set("ws",e),navigator.clipboard.writeText(n.toString()),ex("URL copied")},copyRawContent:async function(e){try{let t=await ee(e);await navigator.clipboard.writeText(t),ex("Raw content copied")}catch{ey("Could not copy file content")}},copyFormattedContent:async function(e,t){try{let n=await ee(e);if(!nV(t)){await navigator.clipboard.writeText(n),ex("Content copied");return}let r=await (0,hC.markdownToHtml)(n,{pagePath:e,sanitize:!0});"ClipboardItem"in window&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([r],{type:"text/html"}),"text/plain":new Blob([n],{type:"text/plain"})})]):await navigator.clipboard.writeText(n),ex("Formatted content copied")}catch{ey("Could not copy formatted content")}}}}({activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isMobile:kr(),setSidebarCollapsed:e=>g.current(e),treeApi:{revealPath:n.revealPath,toggleFolder:n.toggleFolder}});(0,f.useEffect)(()=>{t.current=r.onExternalChange},[r.onExternalChange]);let i=kr(),[o,m]=(0,f.useState)(!1),g=(0,f.useRef)(()=>{});g.current=m;let[b,x]=(0,f.useState)({settingsOpen:!1,shareDialogOpen:!1}),[y,w]=(0,f.useState)(!1),[k,N]=(0,f.useState)({path:null,isDir:!1}),S=function({reloadDir:e}){let[t,n]=(0,f.useState)(!1),[r,i]=(0,f.useState)(null),s=(0,f.useRef)(null),o=(0,f.useRef)(""),a=(0,f.useCallback)(async(t,r)=>{void 0!==r&&(o.current=r);let a=Array.from(t);if(a.length){n(!0),i(null);try{for(let e of a){let t=new FormData;t.append("file",e),t.append("dir",o.current);let n=await (0,tE.wsFetch)("/api/wiki/upload",{method:"POST",body:t});if(!n.ok){let e=await n.json();i(e.error??"Upload failed"),ey(e.error??"Upload failed");break}}await e(o.current)}catch{i("Upload failed.")}finally{n(!1),s.current&&(s.current.value="")}}},[e]);return{uploading:t,uploadError:r,fileInputRef:s,triggerUpload:function(e){o.current=e,s.current?.click()},doUpload:a}}({reloadDir:n.reloadDir}),C=function(e){let[t,n]=(0,f.useState)(null),[r,i]=(0,f.useState)(!1),[s,o]=(0,f.useState)([]),[a,l]=(0,f.useState)(!1),[c,d]=(0,f.useState)(null),[u,p]=(0,f.useState)(null),[h,m]=(0,f.useState)(!1),g=e?.path;(0,f.useEffect)(()=>{i(!1),o([]),d(null),p(null)},[g]),(0,f.useEffect)(()=>{if(!g)return void n(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,tE.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(g)}`);if(e)return;if(!t.ok)return void n(null);let r=await t.json();e||n(r.info)}catch{e||n(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[g]);let b=(0,f.useCallback)(async()=>{if(!e)return;let t=e.path;i(!0),l(!0),o([]),d(null),p(null);try{let n=await (0,tE.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(t)}`);if(!n.ok)return void ey("Could not load history");let r=await n.json();e.path===t&&o(r.commits)}catch{ey("Could not load history")}finally{l(!1)}},[e]),x=(0,f.useCallback)(async t=>{if(!e)return;if(c===t){d(null),p(null);return}let n=e.path;d(t),m(!0),p(null);try{let r=await (0,tE.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(n)}&sha=${encodeURIComponent(t)}`);if(!r.ok)return void ey("Could not load diff");let i=await r.json();e.path===n&&c===t&&p(i.diff)}catch{ey("Could not load diff")}finally{m(!1)}},[e,c]);return{gitFileInfo:t,showHistory:r,setShowHistory:i,historyLoading:a,historyCommits:s,selectedDiffSha:c,setSelectedDiffSha:d,loadHistory:b,diffContent:u,diffLoading:h,selectDiff:x}}(r.openFile),j=n0(e=>e.favorites),E=ko(e=>e.recents),M=tO(e=>e.activity),A=(0,f.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let n of M)n.at>=e&&n.path&&n.by?.startsWith("ai:")&&t.add(n.path);return t},[M]);async function T(){if(!k.path)return;await fetch((0,tE.withWs)("/api/wiki"),{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:k.path})}),(r.openFile?.path===k.path||r.openFile?.path.startsWith(`${k.path}/`))&&r.closeFile();let e=kh(k.path).includes("/")?k.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),N({path:null,isDir:!1})}(0,f.useEffect)(()=>{let e=new URLSearchParams(window.location.search);w("1"===e.get("embed")&&"1"!==e.get("chrome"))},[]),(0,f.useEffect)(()=>{i&&m(!0)},[i]),(0,f.useEffect)(()=>{fd.getState().load()},[]),(0,f.useEffect)(()=>{let e=()=>{tO.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,f.useEffect)(()=>{ko.getState().loadForWorkspace(e.activeWorkspaceId),n0.getState().loadForWorkspace(e.activeWorkspaceId)},[e.activeWorkspaceId]),(0,f.useEffect)(()=>{let e=[...j.map(e=>e.path),...E.slice(0,8).map(e=>e.path)].filter((e,t,n)=>nV(e)&&n.indexOf(e)===t).slice(0,12);if(0===e.length)return;let t=("requestIdleCallback"in window?e=>window.requestIdleCallback(e):e=>window.setTimeout(e,400))(()=>{for(let t of e)tJ(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[j,E]),(0,f.useEffect)(()=>{r.clearFile()},[e.activeWorkspaceId,r.clearFile]),(0,f.useEffect)(()=>{n.rootLoaded&&r.markRootLoaded()},[n.rootLoaded,r.markRootLoaded]);let O=(0,rF.useViewWidthStore)(e=>e.width),_=(0,rF.useViewWidthStore)(e=>e.align),D=(0,rF.useViewWidthStore)(e=>e.setWidth),R=(0,rF.useViewWidthStore)(e=>e.setAlign),I=null===r.openFileViewerKind||"editor"===r.openFileViewerKind||"text"===r.openFileViewerKind||"source"===r.openFileViewerKind||"notebook"===r.openFileViewerKind||"fallback"===r.openFileViewerKind,L=I?rF.VIEW_WIDTH_CLASS[O]:"",P=I?rF.VIEW_ALIGN_CLASS[_]:"",z=(0,f.useCallback)((t,n)=>(0,s.jsx)(n1,{doc:r,node:t,extraItems:n,activeWorkspaceId:e.activeWorkspaceId}),[r,e.activeWorkspaceId]);return(0,s.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===e.rootConfigured&&(0,s.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===e.rootConfigured&&(0,s.jsx)(tn,{onSelect:t=>{let n=new URL(location.href);n.searchParams.set("ws",t),n.searchParams.delete("path"),history.replaceState(null,"",n.toString()),e.setRootConfigured(!0),e.setActiveWorkspaceId(t),e.loadWorkspaces()}}),!0===e.rootConfigured&&e.addingWorkspace&&(0,s.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,s.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>e.setAddingWorkspace(!1),children:[(0,s.jsx)(h,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,s.jsx)(tn,{onSelect:t=>{e.setAddingWorkspace(!1),e.loadWorkspaces(),e.switchWorkspace(t)}})]}),!0===e.rootConfigured&&!e.addingWorkspace&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r9,{workspace:e,doc:r,fileTree:n,upload:S,isMobile:i,hideChrome:y,sidebarCollapsed:o,setSidebarCollapsed:m,favorites:j,recents:E,activePaths:A,setDeleting:N,setDialogs:x}),(0,s.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[!y&&o&&(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"hidden md:flex absolute left-2 top-2 z-10 h-7 w-7 p-0",title:"Show sidebar",onClick:()=>m(!1),children:(0,s.jsx)(p,{className:"h-3.5 w-3.5"})}),!y&&(0,s.jsxs)("div",{className:"md:hidden flex h-11 shrink-0 items-center justify-between gap-2 border-b bg-muted px-1",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{m(!1),tO.getState().close()},children:(0,s.jsx)(p,{className:"h-4 w-4"})}),(0,s.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 text-xs font-semibold tracking-tight text-muted-foreground",title:r.openFile?.path,children:[r.openFile&&(0,s.jsx)("span",{className:"shrink-0",children:"app"===r.openFileViewerKind||"html"===r.openFileViewerKind?(0,s.jsx)(c,{className:"h-4 w-4 text-foreground/70"}):nW(r.openFile.name)?(0,s.jsx)(d.Image,{className:"h-4 w-4 text-sunshine-700"}):nU(r.openFile.name)?(0,s.jsx)(l.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,s.jsx)(l.FileText,{className:"h-4 w-4 text-foreground/60"})}),(0,s.jsx)("span",{className:"truncate",children:r.openFile?r.openFile.name:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{tO.getState().open(),m(!0)},children:(0,s.jsx)(a,{className:"h-4 w-4"})})]}),r.openFile?(0,s.jsx)(kn,{openFile:r.openFile,fileContent:r.fileContent,fileRevision:r.fileRevision,fileLoading:r.fileLoading,editing:r.editing,setEditing:r.setEditing,editContent:r.editContent,setEditContent:r.setEditContent,saving:r.saving,saveError:r.saveError,onSave:r.handleSave,gitFileInfo:C.gitFileInfo,showHistory:C.showHistory,historyLoading:C.historyLoading,historyCommits:C.historyCommits,selectedDiffSha:C.selectedDiffSha,diffContent:C.diffContent,diffLoading:C.diffLoading,onToggleHistory:()=>C.setShowHistory(e=>!e),onSelectDiff:C.selectDiff,gateBypassPath:r.gateBypassPath,onBypassGate:r.bypassGate,onRefresh:r.handleRefresh,onShare:()=>x(e=>({...e,shareDialogOpen:!0})),onClose:()=>{r.closeFile()},renderCopyMenu:z,appKey:r.appKey,setAppKey:r.setAppKey,appFullscreen:r.appFullscreen,setAppFullscreen:r.setAppFullscreen,viewerKey:r.viewerKey,setViewerKey:r.setViewerKey,htmlSourceMode:r.htmlSourceMode,setHtmlSourceMode:r.setHtmlSourceMode,widthAwareViewer:I,viewWidth:O,viewAlign:_,setViewWidth:D,setViewAlign:R,contentWidthClass:L,contentAlignClass:P,isMobile:i,sidebarCollapsed:o}):(0,s.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,s.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,s.jsx)(l.FileText,{className:"h-8 w-8 text-muted-foreground"}),(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,s.jsx)(tM,{open:b.shareDialogOpen,onOpenChange:e=>x(t=>({...t,shareDialogOpen:e})),filePath:r.openFile?.path??""}),!(0,ev.isLite)()&&(0,s.jsx)(eJ,{open:b.settingsOpen,onOpenChange:e=>x(t=>({...t,settingsOpen:e}))}),(0,s.jsx)(t8,{currentPath:r.openFile?.path}),(0,s.jsx)("input",{ref:S.fileInputRef,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&S.doUpload(e.target.files)}}),(0,s.jsx)(e2,{open:!!k.path,onOpenChange:e=>{e||N({path:null,isDir:!1})},title:k.isDir?"Delete folder?":"Delete file?",description:k.isDir?`"${kh(k.path??"")}" and all its contents will be permanently deleted.`:`"${kh(k.path??"")}" will be permanently removed.`,onConfirm:T}),(0,s.jsx)(e2,{open:!!e.deletingWorkspaceId,onOpenChange:t=>{t||e.setDeletingWorkspaceId(null)},title:"Delete workspace?",description:`"${e.workspaces.find(t=>t.id===e.deletingWorkspaceId)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:()=>void e.handleDeleteWorkspace(async t=>{await e.switchWorkspace(t),r.clearFile()})})]})]},e.activeWorkspaceId??"none")}],952683)}]);