@agentdocumentformat/cli 0.8.3 → 0.8.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 (129) hide show
  1. package/README.md +55 -4
  2. package/dist/adf.mjs +16 -13
  3. package/dist/chunks/{App-UHLJRFZJ.mjs → App-XOPHZTGN.mjs} +336 -296
  4. package/dist/chunks/{auth-manager-TBNKCJ45.mjs → auth-manager-2YHTYI3C.mjs} +2 -1
  5. package/dist/chunks/{build-QF5W473T.mjs → build-BFOCXM5S.mjs} +1 -1
  6. package/dist/chunks/{chunk-RHBGCOS3.mjs → chunk-22ZGZFOV.mjs} +5 -16
  7. package/dist/chunks/chunk-26RK7T5L.mjs +20 -0
  8. package/dist/chunks/{chunk-KCIRFUZH.mjs → chunk-2WIFHJV2.mjs} +2 -2
  9. package/dist/chunks/{chunk-D7A77SNL.mjs → chunk-3FWPIWYM.mjs} +1 -1
  10. package/dist/chunks/chunk-4T745GJA.mjs +431 -0
  11. package/dist/chunks/{chunk-WPT3FAFX.mjs → chunk-7ADDKFT5.mjs} +3 -30
  12. package/dist/chunks/chunk-A53XYNJL.mjs +26 -0
  13. package/dist/chunks/{chunk-MZRXFWPQ.mjs → chunk-AN6USKYQ.mjs} +40 -8
  14. package/dist/chunks/{chunk-2Z7X3UUR.mjs → chunk-DHO5Z6HP.mjs} +14 -12
  15. package/dist/chunks/{chunk-F5ELW46V.mjs → chunk-GJYMGPH4.mjs} +1 -0
  16. package/dist/chunks/chunk-HONGRUAE.mjs +175 -0
  17. package/dist/chunks/{chunk-AEAJDCVK.mjs → chunk-IM5JKLXO.mjs} +1 -1
  18. package/dist/chunks/chunk-J2N63ZUD.mjs +12 -0
  19. package/dist/chunks/{chunk-FUQRYTGX.mjs → chunk-JK6K2BMV.mjs} +9 -35
  20. package/dist/chunks/{chunk-75DC5EWN.mjs → chunk-KBXC5EHK.mjs} +1 -0
  21. package/dist/chunks/chunk-NRTRTR7C.mjs +43 -0
  22. package/dist/chunks/{chunk-BS3USVEA.mjs → chunk-P4G5ZEBI.mjs} +1 -1
  23. package/dist/chunks/{chunk-E7LC6SHP.mjs → chunk-RIAB37IS.mjs} +4 -2
  24. package/dist/chunks/{chunk-LVF2DRBR.mjs → chunk-TBMQOM7Y.mjs} +247 -610
  25. package/dist/chunks/{chunk-SOSPQPEN.mjs → chunk-TDRQG5UO.mjs} +1 -162
  26. package/dist/chunks/{chunk-OHTB4UW4.mjs → chunk-TPA2ITKV.mjs} +32 -18
  27. package/dist/chunks/{chunk-BHY7QDCM.mjs → chunk-UBWWGUMU.mjs} +1 -0
  28. package/dist/chunks/{chunk-3AT7IIP7.mjs → chunk-WZ6S3SQP.mjs} +1 -1
  29. package/dist/chunks/chunk-X6R32YVE.mjs +43 -0
  30. package/dist/chunks/chunk-XJWGENZ5.mjs +5903 -0
  31. package/dist/chunks/{chunk-F3WSCAJD.mjs → chunk-XP4U4A2W.mjs} +1 -1
  32. package/dist/chunks/chunk-XS46KYYY.mjs +31 -0
  33. package/dist/chunks/{chunk-HBOFZRUS.mjs → chunk-XZQVDY3U.mjs} +9 -1
  34. package/dist/chunks/chunk-ZECGH3LT.mjs +88 -0
  35. package/dist/chunks/{claude-subscription-EB4LAAVV.mjs → claude-subscription-42L4YM5L.mjs} +4 -3
  36. package/dist/chunks/{cli-UVIJAGRZ.mjs → cli-JPRYEY4J.mjs} +22 -7
  37. package/dist/chunks/{commands-KOMPXJZS.mjs → commands-TZW2FSXG.mjs} +5 -2
  38. package/dist/chunks/context-AZOIJOUG.mjs +5933 -0
  39. package/dist/chunks/{daemon-YHD7PUQI.mjs → daemon-DK3KUDZJ.mjs} +3362 -6724
  40. package/dist/chunks/{daemon-control-MKN7G5M3.mjs → daemon-control-U4OGCAAJ.mjs} +4 -4
  41. package/dist/chunks/{devtools-H7CI2ZVG.mjs → devtools-AUZWFIPL.mjs} +1 -1
  42. package/dist/chunks/firewall-service-7RGJN4LD.mjs +163 -0
  43. package/dist/chunks/{open-3OR6WT4T.mjs → open-T3VGLWGF.mjs} +6 -5
  44. package/dist/chunks/{pipeline-executor-DRYEEFDR.mjs → pipeline-executor-MHRI7ODL.mjs} +6 -3
  45. package/dist/chunks/{remote-access-cli-GLEEP7DI.mjs → remote-access-cli-EFVCXFOY.mjs} +22 -6
  46. package/dist/chunks/{store-D2WLXEY2.mjs → store-37YHXFJ6.mjs} +4 -3
  47. package/dist/chunks/{tui-ZEI2NAQV.mjs → tui-NJKGFAKU.mjs} +12 -11
  48. package/dist/chunks/web-F4XHDGUX.mjs +149 -0
  49. package/dist/chunks/{whatsapp-YJFFVN4Q.mjs → whatsapp-J7PX7TKT.mjs} +1 -1
  50. package/package.json +4 -3
  51. package/web/assets/EditorPanel-5ZGWvexa.js +161 -0
  52. package/web/assets/MeshGraphView-BZV40eAE.css +1 -0
  53. package/web/assets/MeshGraphView-Vp2R5TLK.js +23 -0
  54. package/web/assets/SettingsPage-_uHkBERV.js +6 -0
  55. package/web/assets/agent-window-B8X7FV4_.js +3 -0
  56. package/web/assets/agent.store-BHweGGTh.js +1 -0
  57. package/web/assets/app.store-j_-OuVPe.js +1 -0
  58. package/web/assets/core-DVezgdzc.js +12 -0
  59. package/web/assets/css-Z72CF80r.js +1 -0
  60. package/web/assets/diff-D97Zzqfu.js +1 -0
  61. package/web/assets/document.store-CMD3_OM0.js +1 -0
  62. package/web/assets/edit-recovery-Ce8tPQZl.js +3 -0
  63. package/web/assets/engine-javascript-CuxHA8oH.js +141 -0
  64. package/web/assets/github-dark-dimmed-DH5Ifo-i.js +1 -0
  65. package/web/assets/github-light-DAi9KRSo.js +1 -0
  66. package/web/assets/go-C27-OAKa.js +1 -0
  67. package/web/assets/html-BlS82ilI.js +1 -0
  68. package/web/assets/index-B5Eot_tL.js +1 -0
  69. package/web/assets/index-B5FYMbFc.js +3 -0
  70. package/web/assets/index-BQIEMvvt.js +2 -0
  71. package/web/assets/index-C_gf4L3q.js +1 -0
  72. package/web/assets/index-Ca6bEWGu.js +1 -0
  73. package/web/assets/index-CuTaWSEs.css +1 -0
  74. package/web/assets/index-DBFkrLao.js +1 -0
  75. package/web/assets/index-DF1leTEa.js +11 -0
  76. package/web/assets/index-DS9H-PJI.js +1 -0
  77. package/web/assets/index-DkhbLs9K.js +6 -0
  78. package/web/assets/index-KNnHrO8-.js +13 -0
  79. package/web/assets/index-nM_Q5x7Q.js +1 -0
  80. package/web/assets/inter-tight-cyrillic-ext-wght-italic-BJqtfpQe.woff2 +0 -0
  81. package/web/assets/inter-tight-cyrillic-ext-wght-normal-okcGN4Nq.woff2 +0 -0
  82. package/web/assets/inter-tight-cyrillic-wght-italic-HmhN1gQv.woff2 +0 -0
  83. package/web/assets/inter-tight-cyrillic-wght-normal-BS41q_Tv.woff2 +0 -0
  84. package/web/assets/inter-tight-greek-ext-wght-italic-B_3RbJza.woff2 +0 -0
  85. package/web/assets/inter-tight-greek-ext-wght-normal-DQgQPNk4.woff2 +0 -0
  86. package/web/assets/inter-tight-greek-wght-italic-Bb1BGCmL.woff2 +0 -0
  87. package/web/assets/inter-tight-greek-wght-normal-sS1B39LI.woff2 +0 -0
  88. package/web/assets/inter-tight-latin-ext-wght-italic-DYqsmiDd.woff2 +0 -0
  89. package/web/assets/inter-tight-latin-ext-wght-normal-B4u9PlvR.woff2 +0 -0
  90. package/web/assets/inter-tight-latin-wght-italic-DiXukCDG.woff2 +0 -0
  91. package/web/assets/inter-tight-latin-wght-normal-DX-nOvPD.woff2 +0 -0
  92. package/web/assets/inter-tight-vietnamese-wght-italic-CiVF0Juh.woff2 +0 -0
  93. package/web/assets/inter-tight-vietnamese-wght-normal-TKKdAiBA.woff2 +0 -0
  94. package/web/assets/javascript-wDzz0qaB.js +1 -0
  95. package/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  96. package/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  97. package/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  98. package/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  99. package/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  100. package/web/assets/json-Cp-IABpG.js +1 -0
  101. package/web/assets/jsx-g9-lgVsj.js +1 -0
  102. package/web/assets/main-Zf3qnQYd.css +1 -0
  103. package/web/assets/main-o2ocfqUC.js +319 -0
  104. package/web/assets/markdown-Cvjx9yec.js +1 -0
  105. package/web/assets/message-queue.store-ke_rFZAb.js +2 -0
  106. package/web/assets/module-RjUF93sV.js +716 -0
  107. package/web/assets/native-48B9X9Wg.js +1 -0
  108. package/web/assets/orbital-render.worker-BovOTauk.js +1 -0
  109. package/web/assets/python-B6aJPvgy.js +1 -0
  110. package/web/assets/react-D-F9gHrJ.js +1 -0
  111. package/web/assets/rust-DPvrY3IQ.js +1 -0
  112. package/web/assets/shellscript-Yzrsuije.js +1 -0
  113. package/web/assets/sql-DkvoVjww.js +1 -0
  114. package/web/assets/stix-two-text-cyrillic-wght-italic-BzL1BdzR.woff2 +0 -0
  115. package/web/assets/stix-two-text-cyrillic-wght-normal-CcrOj1MU.woff2 +0 -0
  116. package/web/assets/stix-two-text-greek-wght-italic-glgrbyRu.woff2 +0 -0
  117. package/web/assets/stix-two-text-greek-wght-normal-DAdwyhkq.woff2 +0 -0
  118. package/web/assets/stix-two-text-latin-ext-wght-italic--XhV508b.woff2 +0 -0
  119. package/web/assets/stix-two-text-latin-ext-wght-normal-BUpo8gM0.woff2 +0 -0
  120. package/web/assets/stix-two-text-latin-wght-italic-BDl6bBME.woff2 +0 -0
  121. package/web/assets/stix-two-text-latin-wght-normal-BTZaHlTl.woff2 +0 -0
  122. package/web/assets/stix-two-text-vietnamese-wght-italic-B1jFRJrJ.woff2 +0 -0
  123. package/web/assets/stix-two-text-vietnamese-wght-normal-CfS0RdBA.woff2 +0 -0
  124. package/web/assets/tsx-COt5Ahok.js +1 -0
  125. package/web/assets/typescript-BPQ3VLAy.js +1 -0
  126. package/web/assets/window-kind-mxlpdE1l.js +1 -0
  127. package/web/assets/with-selector-Ot-ZoUn0.js +1 -0
  128. package/web/assets/yaml-Buea-lGh.js +1 -0
  129. package/web/index.html +15 -0
@@ -0,0 +1,161 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-KNnHrO8-.js","assets/index-C_gf4L3q.js","assets/index-DF1leTEa.js","assets/index-CuTaWSEs.css","assets/edit-recovery-Ce8tPQZl.js","assets/react-D-F9gHrJ.js","assets/agent.store-BHweGGTh.js","assets/document.store-CMD3_OM0.js","assets/window-kind-mxlpdE1l.js","assets/app.store-j_-OuVPe.js","assets/main-o2ocfqUC.js","assets/message-queue.store-ke_rFZAb.js","assets/agent-window-B8X7FV4_.js","assets/main-Zf3qnQYd.css","assets/with-selector-Ot-ZoUn0.js","assets/index-B5FYMbFc.js","assets/index-DBFkrLao.js","assets/index-nM_Q5x7Q.js","assets/index-DS9H-PJI.js","assets/index-B5Eot_tL.js","assets/index-BQIEMvvt.js","assets/index-Ca6bEWGu.js","assets/index-DkhbLs9K.js"])))=>i.map(i=>d[i]);
2
+ import{j as S,a as M,R as En,m as hw,_ as tt}from"./index-DF1leTEa.js";import{u as ve,i as Ba}from"./edit-recovery-Ce8tPQZl.js";import{useDocumentStore as dt}from"./document.store-CMD3_OM0.js";import{u as tn,s as uw}from"./app.store-j_-OuVPe.js";import{a as $f,u as Vf}from"./agent.store-BHweGGTh.js";import{T as fw,f as bg,s as xg,o as wg,a as kg,b as vg,c as Sg,h as Cg,i as Mg,d as Tg,R as dw,r as Ag,e as pw,g as mw,j as gw,k as yw,l as bw,m as xw,n as ww,p as kw,q as vw,D as Sw,t as Cw,u as Mw,A as Tw,v as Aw,C as Ew,E as Ow,I as Rw,w as Dw,x as Nw}from"./main-o2ocfqUC.js";import{r as Iw,w as Lw}from"./with-selector-Ot-ZoUn0.js";import{o as Qi,u as Pw}from"./agent-window-B8X7FV4_.js";const Wf="group relative z-10 flex items-center gap-1.5 px-3 text-xs font-medium whitespace-nowrap transition-colors focus-visible:[outline-offset:-2px]",jf="bg-surface-1 text-[var(--adf-ui-text)] shadow-[inset_0_2px_0_0_var(--adf-ui-text-subtle)]",_f="text-[var(--adf-ui-text-muted)] hover:bg-neutral-500/10 hover:text-[var(--adf-ui-text)]",Js="w-4 h-4 flex items-center justify-center rounded-sm hover:bg-neutral-500/20";function Uf(){return S.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 8 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[S.jsx("line",{x1:"1",y1:"1",x2:"7",y2:"7"}),S.jsx("line",{x1:"7",y1:"1",x2:"1",y2:"7"})]})}function za({tabs:n,activeTabPath:e,onSelect:t,onClose:i,onReload:r,chatTab:s}){const o=tn(a=>a.computerMatchTab),l=tn(a=>a.setComputerMatchTab);return n.length===0&&!s?null:S.jsxs("div",{className:"relative flex h-9 items-stretch bg-surface-0 shrink-0",children:[S.jsx("span",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 bottom-0 h-px bg-hairline"}),s&&S.jsxs(S.Fragment,{children:[S.jsxs("button",{type:"button",onClick:s.onSelect,title:"Loops — the agent's chat",className:`${Wf} shrink-0 ${s.active?jf:_f}`,children:[S.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:S.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),S.jsx("span",{children:"Loops"}),S.jsx("span",{"aria-hidden":!0,className:`w-1.5 h-1.5 rounded-full shrink-0 ${s.unread&&!s.active?"bg-blue-500":"bg-transparent"}`}),S.jsx("span",{onClick:a=>{a.stopPropagation(),s.onClose()},title:"Close — put the chat back in the side panel",className:`ml-1 ${Js} ${s.active?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]}),S.jsx("span",{"aria-hidden":!0,className:"relative z-10 w-px shrink-0 self-stretch bg-hairline"})]}),S.jsx("div",{className:"scrollbar-none flex flex-1 min-w-0 items-stretch overflow-x-auto overflow-y-hidden",children:n.map(a=>{const c=a.path===e,h=a.kind==="browser",u=h?"Computer":a.path.split("/").pop()??a.path,f=h&&a.browserMeta?a.browserMeta.hostPort!=null?`Agent computer — http://127.0.0.1:${a.browserMeta.hostPort}`:"Agent computer — not ready":a.path;return S.jsxs("button",{onClick:()=>t(a.path),onMouseDown:d=>{d.button===1&&(d.preventDefault(),i(a.path))},className:`${Wf} shrink-0 border-r border-hairline ${c?jf:_f}`,children:[S.jsx("span",{className:"truncate max-w-[150px]",title:f,children:u}),h&&S.jsx(fw,{tip:o?"Match tab size is on: the agent's screen resizes to fill this tab. Click to keep the agent's size and scale it to fit.":"Match tab size: resize the agent's screen to fill this tab. Off, the screen keeps the size the agent set, scaled to fit.",children:S.jsx("span",{onClick:d=>{d.stopPropagation(),l(!o)},"aria-pressed":o,className:`${Js} ${o?"opacity-100 text-[var(--adf-ui-accent)]":c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("polyline",{points:"15 3 21 3 21 9"}),S.jsx("polyline",{points:"9 21 3 21 3 15"}),S.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),S.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})})}),h&&r&&S.jsx("span",{onClick:d=>{d.stopPropagation(),r(a.path)},title:"Reload viewer",className:`${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M21 12a9 9 0 1 1-2.64-6.36"}),S.jsx("polyline",{points:"21 3 21 9 15 9"})]})}),S.jsx("span",{className:`w-1.5 h-1.5 rounded-full shrink-0 ${a.isDirty?"bg-[var(--adf-ui-text-muted)]":"bg-transparent"}`}),S.jsx("span",{onClick:d=>{d.stopPropagation(),i(a.path)},className:`ml-1 ${Js} ${c?"opacity-60 hover:opacity-100":"opacity-0 group-hover:opacity-60 hover:!opacity-100"}`,children:S.jsx(Uf,{})})]},a.path)})})]})}var Eg=Iw();function Fe(n){this.content=n}Fe.prototype={constructor:Fe,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var i=t&&t!=n?this.remove(t):this,r=i.find(n),s=i.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new Fe(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Fe(t)},addToStart:function(n,e){return new Fe([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Fe(t)},addBefore:function(n,e,t){var i=this.remove(e),r=i.content.slice(),s=i.find(n);return r.splice(s==-1?r.length:s,0,e,t),new Fe(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Fe.from(n),n.size?new Fe(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Fe.from(n),n.size?new Fe(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Fe.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};Fe.from=function(n){if(n instanceof Fe)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Fe(e)};function Og(n,e,t){for(let i=0;;i++){if(i==n.childCount||i==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(i),s=e.child(i);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let o=0;r.text[o]==s.text[o];o++)t++;return t}if(r.content.size||s.content.size){let o=Og(r.content,s.content,t+1);if(o!=null)return o}t+=r.nodeSize}}function Rg(n,e,t,i){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:i};let o=n.child(--r),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,i-=a;continue}if(!o.sameMarkup(l))return{a:t,b:i};if(o.isText&&o.text!=l.text){let c=0,h=Math.min(o.text.length,l.text.length);for(;c<h&&o.text[o.text.length-c-1]==l.text[l.text.length-c-1];)c++,t--,i--;return{a:t,b:i}}if(o.content.size||l.content.size){let c=Rg(o.content,l.content,t-1,i-1);if(c)return c}t-=a,i-=a}}class A{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let i=0;i<e.length;i++)this.size+=e[i].nodeSize}nodesBetween(e,t,i,r=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&i(a,r+l,s||null,o)!==!1&&a.content.size){let h=l+1;a.nodesBetween(Math.max(0,e-h),Math.min(a.content.size,t-h),i,r+h)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,i,r){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&i&&(o?o=!1:s+=i),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,i=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(i)&&(r[r.length-1]=t.withText(t.text+i.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new A(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let i=[],r=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),i.push(l),r+=l.nodeSize),o=a}return new A(i,r)}cutByIndex(e,t){return e==t?A.empty:e==0&&t==this.content.length?this:new A(this.content.slice(e,t))}replaceChild(e,t){let i=this.content[e];if(i==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-i.nodeSize;return r[e]=t,new A(r,s)}addToStart(e){return new A([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new A(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 new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,i=0;t<this.content.length;t++){let r=this.content[t];e(r,i,t),i+=r.nodeSize}}findDiffStart(e,t=0){return Og(this,e,t)}findDiffEnd(e,t=this.size,i=e.size){return Rg(this,e,t,i)}findIndex(e){if(e==0)return Gs(0,e);if(e==this.size)return Gs(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,i=0;;t++){let r=this.child(t),s=i+r.nodeSize;if(s>=e)return s==e?Gs(t+1,s):Gs(t,i);i=s}}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 A.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new A(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return A.empty;let t,i=0;for(let r=0;r<e.length;r++){let s=e[r];i+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new A(t||e,i)}static from(e){if(!e)return A.empty;if(e instanceof A)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new A([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}A.empty=new A([],0);const Ha={index:0,offset:0};function Gs(n,e){return Ha.index=n,Ha.offset=e,Ha}function Ko(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!Ko(n[i],e[i]))return!1}else{for(let i in n)if(!(i in e)||!Ko(n[i],e[i]))return!1;for(let i in e)if(!(i in n))return!1}return!0}let ae=class Fc{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,i=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!i&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),i=!0),t&&t.push(s)}}return t||(t=e.slice()),i||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&&Ko(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let i=e.marks[t.type];if(!i)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=i.create(t.attrs);return i.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(!e[i].eq(t[i]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return Fc.none;if(e instanceof Fc)return[e];let t=e.slice();return t.sort((i,r)=>i.type.rank-r.type.rank),t}};ae.none=[];class Jo extends Error{}class I{constructor(e,t,i){this.content=e,this.openStart=t,this.openEnd=i}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let i=Ng(this.content,e+this.openStart,t);return i&&new I(i,this.openStart,this.openEnd)}removeBetween(e,t){return new I(Dg(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 I.empty;let i=t.openStart||0,r=t.openEnd||0;if(typeof i!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new I(A.fromJSON(e,t.content),i,r)}static maxOpen(e,t=!0){let i=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)i++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new I(e,i,r)}}I.empty=new I(A.empty,0,0);function Dg(n,e,t){let{index:i,offset:r}=n.findIndex(e),s=n.maybeChild(i),{index:o,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(i!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(i,s.copy(Dg(s.content,e-r-1,t-r-1)))}function Ng(n,e,t,i){let{index:r,offset:s}=n.findIndex(e),o=n.maybeChild(r);if(s==e||o.isText)return i&&!i.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Ng(o.content,e-s-1,t,o);return l&&n.replaceChild(r,o.copy(l))}function Bw(n,e,t){if(t.openStart>n.depth)throw new Jo("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Jo("Inconsistent open depths");return Ig(n,e,t,0)}function Ig(n,e,t,i){let r=n.index(i),s=n.node(i);if(r==e.index(i)&&i<n.depth-t.openStart){let o=Ig(n,e,t,i+1);return s.copy(s.content.replaceChild(r,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==i&&e.depth==i){let o=n.parent,l=o.content;return ki(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=zw(t,n);return ki(s,Pg(n,o,l,e,i))}else return ki(s,Go(n,e,i))}function Lg(n,e){if(!e.type.compatibleContent(n.type))throw new Jo("Cannot join "+e.type.name+" onto "+n.type.name)}function $c(n,e,t){let i=n.node(t);return Lg(i,e.node(t)),i}function wi(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Jr(n,e,t,i){let r=(e||n).node(t),s=0,o=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(wi(n.nodeAfter,i),s++));for(let l=s;l<o;l++)wi(r.child(l),i);e&&e.depth==t&&e.textOffset&&wi(e.nodeBefore,i)}function ki(n,e){return n.type.checkContent(e),n.copy(e)}function Pg(n,e,t,i,r){let s=n.depth>r&&$c(n,e,r+1),o=i.depth>r&&$c(t,i,r+1),l=[];return Jr(null,n,r,l),s&&o&&e.index(r)==t.index(r)?(Lg(s,o),wi(ki(s,Pg(n,e,t,i,r+1)),l)):(s&&wi(ki(s,Go(n,e,r+1)),l),Jr(e,t,r,l),o&&wi(ki(o,Go(t,i,r+1)),l)),Jr(i,null,r,l),new A(l)}function Go(n,e,t){let i=[];if(Jr(null,n,t,i),n.depth>t){let r=$c(n,e,t+1);wi(ki(r,Go(n,e,t+1)),i)}return Jr(e,null,t,i),new A(i)}function zw(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(A.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class us{constructor(e,t,i){this.pos=e,this.path=t,this.parentOffset=i,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let i=this.pos-this.path[this.path.length-1],r=e.child(t);return i?e.child(t).cut(i):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):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let i=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=i.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return ae.none;if(this.textOffset)return e.child(t).marks;let i=e.maybeChild(t-1),r=e.maybeChild(t);if(!i){let l=i;i=r,r=l}let s=i.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!r||!s[o].isInSet(r.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let i=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<i.length;s++)i[s].type.spec.inclusive===!1&&(!r||!i[s].isInSet(r.marks))&&(i=i[s--].removeFromSet(i));return i}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 i=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);i>=0;i--)if(e.pos<=this.end(i)&&(!t||t(this.node(i))))return new Yo(this,e,i);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 new RangeError("Position "+t+" out of range");let i=[],r=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(i.push(o,l,r+a),!c||(o=o.child(l),o.isText))break;s=c-1,r+=a+1}return new us(t,i,s)}static resolveCached(e,t){let i=qf.get(e);if(i)for(let s=0;s<i.elts.length;s++){let o=i.elts[s];if(o.pos==t)return o}else qf.set(e,i=new Hw);let r=i.elts[i.i]=us.resolve(e,t);return i.i=(i.i+1)%Fw,r}}class Hw{constructor(){this.elts=[],this.i=0}}const Fw=12,qf=new WeakMap;class Yo{constructor(e,t,i){this.$from=e,this.$to=t,this.depth=i}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)}}const $w=Object.create(null);class Wt{constructor(e,t,i,r=ae.none){this.type=e,this.attrs=t,this.marks=r,this.content=i||A.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,i,r=0){this.content.nodesBetween(e,t,i,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,i,r){return this.content.textBetween(e,t,i,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,i){return this.type==e&&Ko(this.attrs,t||e.defaultAttrs||$w)&&ae.sameSet(this.marks,i||ae.none)}copy(e=null){return e==this.content?this:new Wt(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Wt(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,i=!1){if(e==t)return I.empty;let r=this.resolve(e),s=this.resolve(t),o=i?0:r.sharedDepth(t),l=r.start(o),c=r.node(o).content.cut(r.pos-l,s.pos-l);return new I(c,r.depth-o,s.depth-o)}replace(e,t,i){return Bw(this.resolve(e),this.resolve(t),i)}nodeAt(e){for(let t=this;;){let{index:i,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(i),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:i}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:i}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:i}=this.content.findIndex(e);if(i<e)return{node:this.content.child(t),index:t,offset:i};let r=this.content.child(t-1);return{node:r,index:t-1,offset:i-r.nodeSize}}resolve(e){return us.resolveCached(this,e)}resolveNoCache(e){return us.resolve(this,e)}rangeHasMark(e,t,i){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(i.isInSet(s.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()+")"),Bg(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,i=A.empty,r=0,s=i.childCount){let o=this.contentMatchAt(e).matchFragment(i,r,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=r;a<s;a++)if(!this.type.allowsMarks(i.child(a).marks))return!1;return!0}canReplaceWith(e,t,i,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(i),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}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=ae.none;for(let t=0;t<this.marks.length;t++){let i=this.marks[t];i.type.checkAttrs(i.attrs),e=i.addToSet(e)}if(!ae.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let i;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");i=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,i)}let r=A.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,i);return s.type.checkAttrs(s.attrs),s}}Wt.prototype.text=void 0;let Vw=class Vc extends Wt{constructor(e,t,i,r){if(super(e,t,null,r),!i)throw new RangeError("Empty text nodes are not allowed");this.text=i}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Bg(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 Vc(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Vc(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Bg(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Ti{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let i=new Ww(e,t);if(i.next==null)return Ti.empty;let r=zg(i);i.next&&i.err("Unexpected trailing text");let s=Gw(Jw(r));return Yw(s,i),s}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,i=e.childCount){let r=this;for(let s=t;r&&s<i;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&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 i=0;i<e.next.length;i++)if(this.next[t].type==e.next[i].type)return!0;return!1}fillBefore(e,t=!1,i=0){let r=[this];function s(o,l){let a=o.matchFragment(e,i);if(a&&(!t||a.validEnd))return A.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:h,next:u}=o.next[c];if(!(h.isText||h.hasRequiredAttrs())&&r.indexOf(u)==-1){r.push(u);let f=s(u,l.concat(h));if(f)return f}}return null}return s(this,[])}findWrapping(e){for(let i=0;i<this.wrapCache.length;i+=2)if(this.wrapCache[i]==e)return this.wrapCache[i+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),i=[{match:this,type:null,via:null}];for(;i.length;){let r=i.shift(),s=r.match;if(s.matchType(e)){let o=[];for(let l=r;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||a.validEnd)&&(i.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(i){e.push(i);for(let r=0;r<i.next.length;r++)e.indexOf(i.next[r].next)==-1&&t(i.next[r].next)}return t(this),e.map((i,r)=>{let s=r+(i.validEnd?"*":" ")+" ";for(let o=0;o<i.next.length;o++)s+=(o?", ":"")+i.next[o].type.name+"->"+e.indexOf(i.next[o].next);return s}).join(`
3
+ `)}}Ti.empty=new Ti(!0);class Ww{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function zg(n){let e=[];do e.push(jw(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function jw(n){let e=[];do e.push(_w(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function _w(n){let e=Kw(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Uw(n,e);else break;return e}function Kf(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Uw(n,e){let t=Kf(n),i=t;return n.eat(",")&&(n.next!="}"?i=Kf(n):i=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:i,expr:e}}function qw(n,e){let t=n.nodeTypes,i=t[e];if(i)return[i];let r=[];for(let s in t){let o=t[s];o.isInGroup(e)&&r.push(o)}return r.length==0&&n.err("No node type or group '"+e+"' found"),r}function Kw(n){if(n.eat("(")){let e=zg(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=qw(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Jw(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function i(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function r(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;r(c,l=t())}else if(o.type=="star"){let a=t();return i(l,a),r(s(o.expr,a),a),[i(a)]}else if(o.type=="plus"){let a=t();return r(s(o.expr,l),a),r(s(o.expr,a),a),[i(a)]}else{if(o.type=="opt")return[i(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let h=t();r(s(o.expr,a),h),a=h}if(o.max==-1)r(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let h=t();i(a,h),r(s(o.expr,a),h),a=h}return[i(a)]}else{if(o.type=="name")return[i(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Hg(n,e){return e-n}function Jf(n,e){let t=[];return i(e),t.sort(Hg);function i(r){let s=n[r];if(s.length==1&&!s[0].term)return i(s[0].to);t.push(r);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&i(a)}}}function Gw(n){let e=Object.create(null);return t(Jf(n,0));function t(i){let r=[];i.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let h=0;h<r.length;h++)r[h][0]==l&&(c=r[h][1]);Jf(n,a).forEach(h=>{c||r.push([l,c=[]]),c.indexOf(h)==-1&&c.push(h)})})});let s=e[i.join(",")]=new Ti(i.indexOf(n.length-1)>-1);for(let o=0;o<r.length;o++){let l=r[o][1].sort(Hg);s.next.push({type:r[o][0],next:e[l.join(",")]||t(l)})}return s}}function Yw(n,e){for(let t=0,i=[n];t<i.length;t++){let r=i[t],s=!r.validEnd,o=[];for(let l=0;l<r.next.length;l++){let{type:a,next:c}=r.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),i.indexOf(c)==-1&&i.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Fg(n){let e=Object.create(null);for(let t in n){let i=n[t];if(!i.hasDefault)return null;e[t]=i.default}return e}function $g(n,e){let t=Object.create(null);for(let i in n){let r=e&&e[i];if(r===void 0){let s=n[i];if(s.hasDefault)r=s.default;else throw new RangeError("No value supplied for attribute "+i)}t[i]=r}return t}function Vg(n,e,t,i){for(let r in e)if(!(r in n))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${r}`);for(let r in n){let s=n[r];s.validate&&s.validate(e[r])}}function Wg(n,e){let t=Object.create(null);if(e)for(let i in e)t[i]=new Qw(n,i,e[i]);return t}let Gf=class jg{constructor(e,t,i){this.name=e,this.schema=t,this.spec=i,this.markSet=null,this.groups=i.group?i.group.split(" "):[],this.attrs=Wg(e,i.attrs),this.defaultAttrs=Fg(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(i.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Ti.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:$g(this.attrs,e)}create(e=null,t,i){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Wt(this,this.computeAttrs(e),A.from(t),ae.setFrom(i))}createChecked(e=null,t,i){return t=A.from(t),this.checkContent(t),new Wt(this,this.computeAttrs(e),t,ae.setFrom(i))}createAndFill(e=null,t,i){if(e=this.computeAttrs(e),t=A.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(A.empty,!0);return s?new Wt(this,e,t.append(s),ae.setFrom(i)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let i=0;i<e.childCount;i++)if(!this.allowsMarks(e.child(i).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Vg(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let i=0;i<e.length;i++)this.allowsMarkType(e[i].type)?t&&t.push(e[i]):t||(t=e.slice(0,i));return t?t.length?t:ae.none:e}static compile(e,t){let i=Object.create(null);e.forEach((s,o)=>i[s]=new jg(s,t,o));let r=t.spec.topNode||"doc";if(!i[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!i.text)throw new RangeError("Every schema needs a 'text' type");for(let s in i.text.attrs)throw new RangeError("The text node type should not have attributes");return i}};function Xw(n,e,t){let i=t.split("|");return r=>{let s=r===null?"null":typeof r;if(i.indexOf(s)<0)throw new RangeError(`Expected value of type ${i} for attribute ${e} on type ${n}, got ${s}`)}}class Qw{constructor(e,t,i){this.hasDefault=Object.prototype.hasOwnProperty.call(i,"default"),this.default=i.default,this.validate=typeof i.validate=="string"?Xw(e,t,i.validate):i.validate}get isRequired(){return!this.hasDefault}}class ia{constructor(e,t,i,r){this.name=e,this.rank=t,this.schema=i,this.spec=r,this.attrs=Wg(e,r.attrs),this.excluded=null;let s=Fg(this.attrs);this.instance=s?new ae(this,s):null}create(e=null){return!e&&this.instance?this.instance:new ae(this,$g(this.attrs,e))}static compile(e,t){let i=Object.create(null),r=0;return e.forEach((s,o)=>i[s]=new ia(s,r++,t,o)),i}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){Vg(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class _g{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=Fe.from(e.nodes),t.marks=Fe.from(e.marks||{}),this.nodes=Gf.compile(this.spec.nodes,this),this.marks=ia.compile(this.spec.marks,this);let i=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=i[o]||(i[o]=Ti.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Yf(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Yf(this,o.split(" "))}this.nodeFromJSON=r=>Wt.fromJSON(this,r),this.markFromJSON=r=>ae.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,i,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Gf){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,i,r)}text(e,t){let i=this.nodes.text;return new Vw(i,i.defaultAttrs,e,ae.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function Yf(n,e){let t=[];for(let i=0;i<e.length;i++){let r=e[i],s=n.marks[r],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(r=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(r)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[i]+"'")}return t}function Zw(n){return n.tag!=null}function ek(n){return n.style!=null}class Sn{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let i=this.matchedStyles=[];t.forEach(r=>{if(Zw(r))this.tags.push(r);else if(ek(r)){let s=/[^=]*/.exec(r.style)[0];i.indexOf(s)<0&&i.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let i=new Qf(this,t,!1);return i.addAll(e,ae.none,t.from,t.to),i.finish()}parseSlice(e,t={}){let i=new Qf(this,t,!0);return i.addAll(e,ae.none,t.from,t.to),I.maxOpen(i.finish())}matchTag(e,t,i){for(let r=i?this.tags.indexOf(i)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(ik(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let o=s.getAttrs(e);if(o===!1)continue;s.attrs=o||void 0}return s}}}matchStyle(e,t,i,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let o=this.styles[s],l=o.style;if(!(l.indexOf(e)!=0||o.context&&!i.matchesContext(o.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let a=o.getAttrs(t);if(a===!1)continue;o.attrs=a||void 0}return o}}}static schemaRules(e){let t=[];function i(r){let s=r.priority==null?50:r.priority,o=0;for(;o<t.length;o++){let l=t[o];if((l.priority==null?50:l.priority)<s)break}t.splice(o,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(o=>{i(o=Zf(o)),o.mark||o.ignore||o.clearMark||(o.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(o=>{i(o=Zf(o)),o.node||o.ignore||o.mark||(o.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Sn(e,Sn.schemaRules(e)))}}const Ug={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},tk={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},qg={ol:!0,ul:!0},fs=1,Wc=2,Gr=4;function Xf(n,e,t){return e!=null?(e?fs:0)|(e==="full"?Wc:0):n&&n.whitespace=="pre"?fs|Wc:t&~Gr}class Ys{constructor(e,t,i,r,s,o){this.type=e,this.attrs=t,this.marks=i,this.solid=r,this.options=o,this.content=[],this.activeMarks=ae.none,this.match=s||(o&Gr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(A.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let i=this.type.contentMatch,r;return(r=i.findWrapping(e.type))?(this.match=i,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&fs)){let i=this.content[this.content.length-1],r;if(i&&i.isText&&(r=/[ \t\r\n\u000c]+$/.exec(i.text))){let s=i;i.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=A.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(A.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&&!Ug.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}let Qf=class{constructor(e,t,i){this.parser=e,this.options=t,this.isOpen=i,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,o=Xf(null,t.preserveWhitespace,0)|(i?Gr:0);r?s=new Ys(r.type,r.attrs,ae.none,!0,t.topMatch||r.type.contentMatch,o):i?s=new Ys(null,null,ae.none,!0,null,o):s=new Ys(e.schema.topNodeType,null,ae.none,!0,null,o),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let i=e.nodeValue,r=this.top,s=r.options&Wc?"full":this.localPreserveWS||(r.options&fs)>0,{schema:o}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(i)){if(s)if(s==="full")i=i.replace(/\r\n?/g,`
4
+ `);else if(o.linebreakReplacement&&/[\r\n]/.test(i)&&this.top.findWrapping(o.linebreakReplacement.create())){let l=i.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(o.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(o.text(l[a]),t,!/\S/.test(l[a]));i=""}else i=i.replace(/\r?\n|\r/g," ");else if(i=i.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(i)&&this.open==this.nodes.length-1){let l=r.content[r.content.length-1],a=e.previousSibling;(!l||a&&a.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(i=i.slice(1))}i&&this.insertNode(o.text(i),t,!/\S/.test(i)),this.findInText(e)}else this.findInside(e)}addElement(e,t,i){let r=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),l;qg.hasOwnProperty(o)&&this.parser.normalizeLists&&nk(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,i));e:if(a?a.ignore:tk.hasOwnProperty(o))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 c,h=this.needsBlock;if(Ug.hasOwnProperty(o))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),c=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let u=a&&a.skip?t:this.readStyles(e,t);u&&this.addAll(e,u),c&&this.sync(s),this.needsBlock=h}else{let c=this.readStyles(e,t);c&&this.addElementByRule(e,a,c,a.consuming===!1?l:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
5
+ `),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let i=e.style;if(i&&i.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],o=i.getPropertyValue(s);if(o)for(let l=void 0;;){let a=this.parser.matchStyle(s,o,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(c=>!a.clearMark(c)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;else break}}return t}addElementByRule(e,t,i,r){let s,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),i,e.nodeName=="BR")||this.leafFallback(e,i);else{let a=this.enter(o,t.attrs||null,i,t.preserveWhitespace);a&&(s=!0,i=a)}else{let a=this.parser.schema.marks[t.mark];i=i.concat(a.create(t.attrs))}let l=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,i,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(a=>this.insertNode(a,i,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,i),this.findAround(e,a,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,i,r){let s=i||0;for(let o=i?e.childNodes[i]:e.firstChild,l=r==null?null:e.childNodes[r];o!=l;o=o.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(o,t);this.findAtPoint(e,s)}findPlace(e,t,i){let r,s;for(let o=this.open,l=0;o>=0;o--){let a=this.nodes[o],c=a.findWrapping(e);if(c&&(!r||r.length>c.length+l)&&(r=c,s=a,!c.length))break;if(a.solid){if(i)break;l+=2}}if(!r)return null;this.sync(s);for(let o=0;o<r.length;o++)t=this.enterInner(r[o],null,t,!1);return t}insertNode(e,t,i){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,i);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let o=ae.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):ed(l.type,e.type))&&(o=l.addToSet(o));return s.content.push(e.mark(o)),!0}return!1}enter(e,t,i,r){let s=this.findPlace(e.create(t),i,!1);return s&&(s=this.enterInner(e,t,i,!0,r)),s}enterInner(e,t,i,r=!1,s){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let l=Xf(e,s,o.options);o.options&Gr&&o.content.length==0&&(l|=Gr);let a=ae.none;return i=i.filter(c=>(o.type?o.type.allowsMarkType(c.type):ed(c.type,e))?(a=c.addToSet(a),!1):!0),this.nodes.push(new Ys(e,t,a,r,null,l)),this.open++,i}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=fs)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let i=this.nodes[t].content;for(let r=i.length-1;r>=0;r--)e+=i[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let i=0;i<this.find.length;i++)this.find[i].node==e&&this.find[i].offset==t&&(this.find[i].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,i){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(i?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("/"),i=this.options.context,r=!this.isOpen&&(!i||i.parent.type==this.nodes[0].type),s=-(i?i.depth+1:0)+(r?0:1),o=(l,a)=>{for(;l>=0;l--){let c=t[l];if(c==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(o(l-1,a))return!0;return!1}else{let h=a>0||a==0&&r?this.nodes[a].type:i&&a>=s?i.node(a-s).type:null;if(!h||h.name!=c&&!h.isInGroup(c))return!1;a--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(i&&i.isTextblock&&i.defaultAttrs)return i}for(let t in this.parser.schema.nodes){let i=this.parser.schema.nodes[t];if(i.isTextblock&&i.defaultAttrs)return i}}};function nk(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let i=e.nodeType==1?e.nodeName.toLowerCase():null;i&&qg.hasOwnProperty(i)&&t?(t.appendChild(e),e=t):i=="li"?t=e:i&&(t=null)}}function ik(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Zf(n){let e={};for(let t in n)e[t]=n[t];return e}function ed(n,e){let t=e.schema.nodes;for(let i in t){let r=t[i];if(!r.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let a=0;a<l.edgeCount;a++){let{type:c,next:h}=l.edge(a);if(c==e||s.indexOf(h)<0&&o(h))return!0}};if(o(r.contentMatch))return!0}}class Bi{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},i){i||(i=Fa(t).createDocumentFragment());let r=i,s=[];return e.forEach(o=>{if(s.length||o.marks.length){let l=0,a=0;for(;l<s.length&&a<o.marks.length;){let c=o.marks[a];if(!this.marks[c.type.name]){a++;continue}if(!c.eq(s[l][0])||c.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<o.marks.length;){let c=o.marks[a++],h=this.serializeMark(c,o.isInline,t);h&&(s.push([c,r]),r.appendChild(h.dom),r=h.contentDOM||h.dom)}}r.appendChild(this.serializeNodeInner(o,t))}),i}serializeNodeInner(e,t){let{dom:i,contentDOM:r}=Io(Fa(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return i}serializeNode(e,t={}){let i=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(i),i=s.dom)}return i}serializeMark(e,t,i={}){let r=this.marks[e.type.name];return r&&Io(Fa(i),r(e,t),null,e.attrs)}static renderSpec(e,t,i=null,r){return Io(e,t,i,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Bi(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=td(e.nodes);return t.text||(t.text=i=>i.text),t}static marksFromSchema(e){return td(e.marks)}}function td(n){let e={};for(let t in n){let i=n[t].spec.toDOM;i&&(e[t]=i)}return e}function Fa(n){return n.document||window.document}const nd=new WeakMap;function rk(n){let e=nd.get(n);return e===void 0&&nd.set(n,e=sk(n)),e}function sk(n){let e=null;function t(i){if(i&&typeof i=="object")if(Array.isArray(i))if(typeof i[0]=="string")e||(e=[]),e.push(i);else for(let r=0;r<i.length;r++)t(i[r]);else for(let r in i)t(i[r])}return t(n),e}function Io(n,e,t,i){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(i&&(s=rk(i))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let o=r.indexOf(" ");o>0&&(t=r.slice(0,o),r=r.slice(o+1));let l,a=t?n.createElementNS(t,r):n.createElement(r),c=e[1],h=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){h=2;for(let u in c)if(c[u]!=null){let f=u.indexOf(" ");f>0?a.setAttributeNS(u.slice(0,f),u.slice(f+1),c[u]):u=="style"&&a.style?a.style.cssText=c[u]:a.setAttribute(u,c[u])}}for(let u=h;u<e.length;u++){let f=e[u];if(f===0){if(u<e.length-1||u>h)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:d,contentDOM:p}=Io(n,f,t,i);if(a.appendChild(d),p){if(l)throw new RangeError("Multiple content holes");l=p}}}return{dom:a,contentDOM:l}}const Kg=65535,Jg=Math.pow(2,16);function ok(n,e){return n+e*Jg}function id(n){return n&Kg}function lk(n){return(n-(n&Kg))/Jg}const Gg=1,Yg=2,Lo=4,Xg=8;class jc{constructor(e,t,i){this.pos=e,this.delInfo=t,this.recover=i}get deleted(){return(this.delInfo&Xg)>0}get deletedBefore(){return(this.delInfo&(Gg|Lo))>0}get deletedAfter(){return(this.delInfo&(Yg|Lo))>0}get deletedAcross(){return(this.delInfo&Lo)>0}}class yt{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&yt.empty)return yt.empty}recover(e){let t=0,i=id(e);if(!this.inverted)for(let r=0;r<i;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[i*3]+t+lk(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,i){let r=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let c=this.ranges[l+s],h=this.ranges[l+o],u=a+c;if(e<=u){let f=c?e==a?-1:e==u?1:t:t,d=a+r+(f<0?0:h);if(i)return d;let p=e==(t<0?a:u)?null:ok(l/3,e-a),m=e==a?Yg:e==u?Gg:Lo;return(t<0?e!=a:e!=u)&&(m|=Xg),new jc(d,m,p)}r+=h-c}return i?e+r:new jc(e+r,0,null)}touches(e,t){let i=0,r=id(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],h=a+c;if(e<=h&&l==r*3)return!0;i+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,i=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let o=this.ranges[r],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[r+t],h=this.ranges[r+i];e(l,l+c,a,a+h),s+=h-c}}invert(){return new yt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?yt.empty:new yt(e<0?[0,-e,0]:[0,0,e])}}yt.empty=new yt([]);class ds{constructor(e,t,i=0,r=e?e.length:0){this.mirror=t,this.from=i,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new ds(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),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,i=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?i+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,i=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?i-r-1:void 0)}}invert(){let e=new ds;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let i=this.from;i<this.to;i++)e=this._maps[i].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,i){let r=0;for(let s=this.from;s<this.to;s++){let o=this._maps[s],l=o.mapResult(e,t);if(l.recover!=null){let a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return i?e:new jc(e,r,null)}}const $a=Object.create(null);class Ge{getMap(){return yt.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let i=$a[t.stepType];if(!i)throw new RangeError(`No step type ${t.stepType} defined`);return i.fromJSON(e,t)}static jsonID(e,t){if(e in $a)throw new RangeError("Duplicate use of step JSON ID "+e);return $a[e]=t,t.prototype.jsonID=e,t}}class Se{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new Se(e,null)}static fail(e){return new Se(null,e)}static fromReplace(e,t,i,r){try{return Se.ok(e.replace(t,i,r))}catch(s){if(s instanceof Jo)return Se.fail(s.message);throw s}}}function fu(n,e,t){let i=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(fu(s.content,e,s))),s.isInline&&(s=e(s,t,r)),i.push(s)}return A.fromArray(i)}class _n extends Ge{constructor(e,t,i){super(),this.from=e,this.to=t,this.mark=i}apply(e){let t=e.slice(this.from,this.to),i=e.resolve(this.from),r=i.node(i.sharedDepth(this.to)),s=new I(fu(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),r),t.openStart,t.openEnd);return Se.fromReplace(e,this.from,this.to,s)}invert(){return new Ft(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deleted&&i.deleted||t.pos>=i.pos?null:new _n(t.pos,i.pos,this.mark)}merge(e){return e instanceof _n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new _n(t.from,t.to,e.markFromJSON(t.mark))}}Ge.jsonID("addMark",_n);class Ft extends Ge{constructor(e,t,i){super(),this.from=e,this.to=t,this.mark=i}apply(e){let t=e.slice(this.from,this.to),i=new I(fu(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return Se.fromReplace(e,this.from,this.to,i)}invert(){return new _n(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deleted&&i.deleted||t.pos>=i.pos?null:new Ft(t.pos,i.pos,this.mark)}merge(e){return e instanceof Ft&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ft(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new Ft(t.from,t.to,e.markFromJSON(t.mark))}}Ge.jsonID("removeMark",Ft);class Un extends Ge{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Se.fail("No node at mark step's position");let i=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Se.fromReplace(e,this.pos,this.pos+1,new I(A.from(i),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let i=this.mark.addToSet(t.marks);if(i.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(i))return new Un(this.pos,t.marks[r]);return new Un(this.pos,this.mark)}}return new Ai(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Un(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Un(t.pos,e.markFromJSON(t.mark))}}Ge.jsonID("addNodeMark",Un);class Ai extends Ge{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Se.fail("No node at mark step's position");let i=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return Se.fromReplace(e,this.pos,this.pos+1,new I(A.from(i),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Un(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ai(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Ai(t.pos,e.markFromJSON(t.mark))}}Ge.jsonID("removeNodeMark",Ai);class Ne extends Ge{constructor(e,t,i,r=!1){super(),this.from=e,this.to=t,this.slice=i,this.structure=r}apply(e){return this.structure&&_c(e,this.from,this.to)?Se.fail("Structure replace would overwrite content"):Se.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new yt([this.from,this.to-this.from,this.slice.size])}invert(e){return new Ne(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),i=e.mapResult(this.to,-1);return t.deletedAcross&&i.deletedAcross?null:new Ne(t.pos,Math.max(t.pos,i.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Ne)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?I.empty:new I(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Ne(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?I.empty:new I(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Ne(e.from,this.to,t,this.structure)}else return null}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(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Ne(t.from,t.to,I.fromJSON(e,t.slice),!!t.structure)}}Ge.jsonID("replace",Ne);class Be extends Ge{constructor(e,t,i,r,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=i,this.gapTo=r,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(_c(e,this.from,this.gapFrom)||_c(e,this.gapTo,this.to)))return Se.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return Se.fail("Gap is not a flat range");let i=this.slice.insertAt(this.insert,t.content);return i?Se.fromReplace(e,this.from,this.to,i):Se.fail("Content does not fit in gap")}getMap(){return new yt([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 Be(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),i=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?i.pos:e.map(this.gapTo,1);return t.deletedAcross&&i.deletedAcross||r<t.pos||s>i.pos?null:new Be(t.pos,i.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Be(t.from,t.to,t.gapFrom,t.gapTo,I.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ge.jsonID("replaceAround",Be);function _c(n,e,t){let i=n.resolve(e),r=t-e,s=i.depth;for(;r>0&&s>0&&i.indexAfter(s)==i.node(s).childCount;)s--,r--;if(r>0){let o=i.node(s).maybeChild(i.indexAfter(s));for(;r>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,r--}}return!1}function ak(n,e,t,i){let r=[],s=[],o,l;n.doc.nodesBetween(e,t,(a,c,h)=>{if(!a.isInline)return;let u=a.marks;if(!i.isInSet(u)&&h.type.allowsMarkType(i.type)){let f=Math.max(c,e),d=Math.min(c+a.nodeSize,t),p=i.addToSet(u);for(let m=0;m<u.length;m++)u[m].isInSet(p)||(o&&o.to==f&&o.mark.eq(u[m])?o.to=d:r.push(o=new Ft(f,d,u[m])));l&&l.to==f?l.to=d:s.push(l=new _n(f,d,i))}}),r.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function ck(n,e,t,i){let r=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let a=null;if(i instanceof ia){let c=o.marks,h;for(;h=i.isInSet(c);)(a||(a=[])).push(h),c=h.removeFromSet(c)}else i?i.isInSet(o.marks)&&(a=[i]):a=o.marks;if(a&&a.length){let c=Math.min(l+o.nodeSize,t);for(let h=0;h<a.length;h++){let u=a[h],f;for(let d=0;d<r.length;d++){let p=r[d];p.step==s-1&&u.eq(r[d].style)&&(f=p)}f?(f.to=c,f.step=s):r.push({style:u,from:Math.max(l,e),to:c,step:s})}}}),r.forEach(o=>n.step(new Ft(o.from,o.to,o.style)))}function du(n,e,t,i=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),o=[],l=e+1;for(let a=0;a<s.childCount;a++){let c=s.child(a),h=l+c.nodeSize,u=i.matchType(c.type);if(!u)o.push(new Ne(l,h,I.empty));else{i=u;for(let f=0;f<c.marks.length;f++)t.allowsMarkType(c.marks[f].type)||n.step(new Ft(l,h,c.marks[f]));if(r&&c.isText&&t.whitespace!="pre"){let f,d=/\r?\n|\r/g,p;for(;f=d.exec(c.text);)p||(p=new I(A.from(t.schema.text(" ",t.allowedMarks(c.marks))),0,0)),o.push(new Ne(l+f.index,l+f.index+f[0].length,p))}}l=h}if(!i.validEnd){let a=i.fillBefore(A.empty,!0);n.replace(l,l,new I(a,0,0))}for(let a=o.length-1;a>=0;a--)n.step(o[a])}function hk(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Sr(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let i=n.depth,r=0,s=0;;--i){let o=n.$from.node(i),l=n.$from.index(i)+r,a=n.$to.indexAfter(i)-s;if(i<n.depth&&o.canReplace(l,a,t))return i;if(i==0||o.type.spec.isolating||!hk(o,l,a))break;l&&(r=1),a<o.childCount&&(s=1)}return null}function uk(n,e,t){let{$from:i,$to:r,depth:s}=e,o=i.before(s+1),l=r.after(s+1),a=o,c=l,h=A.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.index(p)>0?(m=!0,h=A.from(i.node(p).copy(h)),u++):a--;let f=A.empty,d=0;for(let p=s,m=!1;p>t;p--)m||r.after(p+1)<r.end(p)?(m=!0,f=A.from(r.node(p).copy(f)),d++):c++;n.step(new Be(a,c,o,l,new I(h.append(f),u,d),h.size-u,!0))}function pu(n,e,t=null,i=n){let r=fk(n,e),s=r&&dk(i,e);return s?r.map(rd).concat({type:e,attrs:t}).concat(s.map(rd)):null}function rd(n){return{type:n,attrs:null}}function fk(n,e){let{parent:t,startIndex:i,endIndex:r}=n,s=t.contentMatchAt(i).findWrapping(e);if(!s)return null;let o=s.length?s[0]:e;return t.canReplaceWith(i,r,o)?s:null}function dk(n,e){let{parent:t,startIndex:i,endIndex:r}=n,s=t.child(i),o=e.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:e).contentMatch;for(let c=i;a&&c<r;c++)a=a.matchType(t.child(c).type);return!a||!a.validEnd?null:o}function pk(n,e,t){let i=A.empty;for(let o=t.length-1;o>=0;o--){if(i.size){let l=t[o].type.contentMatch.matchFragment(i);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}i=A.from(t[o].type.create(t[o].attrs,i))}let r=e.start,s=e.end;n.step(new Be(r,s,r,s,new I(i,0,0),t.length,!0))}function mk(n,e,t,i,r){if(!i.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{let a=typeof r=="function"?r(o):r;if(o.isTextblock&&!o.hasMarkup(i,a)&&gk(n.doc,n.mapping.slice(s).map(l),i)){let c=null;if(i.schema.linebreakReplacement){let d=i.whitespace=="pre",p=!!i.contentMatch.matchType(i.schema.linebreakReplacement);d&&!p?c=!1:!d&&p&&(c=!0)}c===!1&&Zg(n,o,l,s),du(n,n.mapping.slice(s).map(l,1),i,void 0,c===null);let h=n.mapping.slice(s),u=h.map(l,1),f=h.map(l+o.nodeSize,1);return n.step(new Be(u,f,u+1,f-1,new I(A.from(i.create(a,null,o.marks)),0,0),1,!0)),c===!0&&Qg(n,o,l,s),!1}})}function Qg(n,e,t,i){e.forEach((r,s)=>{if(r.isText){let o,l=/\r?\n|\r/g;for(;o=l.exec(r.text);){let a=n.mapping.slice(i).map(t+1+s+o.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function Zg(n,e,t,i){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let o=n.mapping.slice(i).map(t+1+s);n.replaceWith(o,o+1,e.type.schema.text(`
6
+ `))}})}function gk(n,e,t){let i=n.resolve(e),r=i.index();return i.parent.canReplaceWith(r,r+1,t)}function yk(n,e,t,i,r){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(i,null,r||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new Be(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new I(A.from(o),0,0),1,!0))}function Cn(n,e,t=1,i){let r=n.resolve(e),s=r.depth-t,o=i&&i[i.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!o.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let c=r.depth-1,h=t-2;c>s;c--,h--){let u=r.node(c),f=r.index(c);if(u.type.spec.isolating)return!1;let d=u.content.cutByIndex(f,u.childCount),p=i&&i[h+1];p&&(d=d.replaceChild(0,p.type.create(p.attrs)));let m=i&&i[h]||u;if(!u.canReplace(f+1,u.childCount)||!m.type.validContent(d))return!1}let l=r.indexAfter(s),a=i&&i[0];return r.node(s).canReplaceWith(l,l,a?a.type:r.node(s+1).type)}function bk(n,e,t=1,i){let r=n.doc.resolve(e),s=A.empty,o=A.empty;for(let l=r.depth,a=r.depth-t,c=t-1;l>a;l--,c--){s=A.from(r.node(l).copy(s));let h=i&&i[c];o=A.from(h?h.type.create(h.attrs,o):r.node(l).copy(o))}n.step(new Ne(e,e,new I(s.append(o),t,t),!0))}function si(n,e){let t=n.resolve(e),i=t.index();return e0(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(i,i+1)}function xk(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:i}=n.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),o=s.type==i?n.type.schema.nodes.text:s.type;if(t=t.matchType(o),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function e0(n,e){return!!(n&&e&&!n.isLeaf&&xk(n,e))}function ra(n,e,t=-1){let i=n.resolve(e);for(let r=i.depth;;r--){let s,o,l=i.index(r);if(r==i.depth?(s=i.nodeBefore,o=i.nodeAfter):t>0?(s=i.node(r+1),l++,o=i.node(r).maybeChild(l)):(s=i.node(r).maybeChild(l-1),o=i.node(r+1)),s&&!s.isTextblock&&e0(s,o)&&i.node(r).canReplace(l,l+1))return e;if(r==0)break;e=t<0?i.before(r):i.after(r)}}function wk(n,e,t){let i=null,{linebreakReplacement:r}=n.doc.type.schema,s=n.doc.resolve(e-t),o=s.node().type;if(r&&o.inlineContent){let h=o.whitespace=="pre",u=!!o.contentMatch.matchType(r);h&&!u?i=!1:!h&&u&&(i=!0)}let l=n.steps.length;if(i===!1){let h=n.doc.resolve(e+t);Zg(n,h.node(),h.before(),l)}o.inlineContent&&du(n,e+t-1,o,s.node().contentMatchAt(s.index()),i==null);let a=n.mapping.slice(l),c=a.map(e-t);if(n.step(new Ne(c,a.map(e+t,-1),I.empty,!0)),i===!0){let h=n.doc.resolve(c);Qg(n,h.node(),h.before(),n.steps.length)}return n}function kk(n,e,t){let i=n.resolve(e);if(i.parent.canReplaceWith(i.index(),i.index(),t))return e;if(i.parentOffset==0)for(let r=i.depth-1;r>=0;r--){let s=i.index(r);if(i.node(r).canReplaceWith(s,s,t))return i.before(r+1);if(s>0)return null}if(i.parentOffset==i.parent.content.size)for(let r=i.depth-1;r>=0;r--){let s=i.indexAfter(r);if(i.node(r).canReplaceWith(s,s,t))return i.after(r+1);if(s<i.node(r).childCount)return null}return null}function t0(n,e,t){let i=n.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let o=i.depth;o>=0;o--){let l=o==i.depth?0:i.pos<=(i.start(o+1)+i.end(o+1))/2?-1:1,a=i.index(o)+(l>0?1:0),c=i.node(o),h=!1;if(s==1)h=c.canReplace(a,a,r);else{let u=c.contentMatchAt(a).findWrapping(r.firstChild.type);h=u&&c.canReplaceWith(a,a,u[0])}if(h)return l==0?i.pos:l<0?i.before(o+1):i.after(o+1)}return null}function sa(n,e,t=e,i=I.empty){if(e==t&&!i.size)return null;let r=n.resolve(e),s=n.resolve(t);return n0(r,s,i)?new Ne(e,t,i):new vk(r,s,i).fit()}function n0(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class vk{constructor(e,t,i){this.$from=e,this.$to=t,this.unplaced=i,this.frontier=[],this.placed=A.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=A.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let c=this.findFittable();c?this.placeNodes(c):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,i=this.$from,r=this.close(e<0?this.$to:i.doc.resolve(e));if(!r)return null;let s=this.placed,o=i.depth,l=r.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let a=new I(s,o,l);return e>-1?new Be(i.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||i.pos!=this.$to.pos?new Ne(i.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,i=0,r=this.unplaced.openEnd;i<e;i++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=i){e=i;break}t=s.content}for(let t=1;t<=2;t++)for(let i=t==1?e:this.unplaced.openStart;i>=0;i--){let r,s=null;i?(s=Va(this.unplaced.content,i-1).firstChild,r=s.content):r=this.unplaced.content;let o=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:a,match:c}=this.frontier[l],h,u=null;if(t==1&&(o?c.matchType(o.type)||(u=c.fillBefore(A.from(o),!1)):s&&a.compatibleContent(s.type)))return{sliceDepth:i,frontierDepth:l,parent:s,inject:u};if(t==2&&o&&(h=c.findWrapping(o.type)))return{sliceDepth:i,frontierDepth:l,parent:s,wrap:h};if(s&&c.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:i}=this.unplaced,r=Va(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new I(e,t+1,Math.max(i,r.size+t>=e.size-i?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:i}=this.unplaced,r=Va(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new I(zr(e,t-1,1),t-1,s?t-1:i)}else this.unplaced=new I(zr(e,t,1),t,i)}placeNodes({sliceDepth:e,frontierDepth:t,parent:i,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m<s.length;m++)this.openFrontierNode(s[m]);let o=this.unplaced,l=i?i.content:o.content,a=o.openStart-e,c=0,h=[],{match:u,type:f}=this.frontier[t];if(r){for(let m=0;m<r.childCount;m++)h.push(r.child(m));u=u.matchFragment(r)}let d=l.size+e-(o.content.size-o.openEnd);for(;c<l.childCount;){let m=l.child(c),g=u.matchType(m.type);if(!g)break;c++,(c>1||a==0||m.content.size)&&(u=g,h.push(i0(m.mark(f.allowedMarks(m.marks)),c==1?a:0,c==l.childCount?d:-1)))}let p=c==l.childCount;p||(d=-1),this.placed=Hr(this.placed,t,A.from(h)),this.frontier[t].match=u,p&&d<0&&i&&i.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m<d;m++){let y=g.lastChild;this.frontier.push({type:y.type,match:y.contentMatchAt(y.childCount)}),g=y.content}this.unplaced=p?e==0?I.empty:new I(zr(o.content,e-1,1),e-1,d<0?o.openEnd:e-1):new I(zr(o.content,e,c),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!Wa(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:i}=this.$to,r=this.$to.after(i);for(;i>1&&r==this.$to.end(--i);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:i,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=Wa(e,t,r,i,s);if(o){for(let l=t-1;l>=0;l--){let{match:a,type:c}=this.frontier[l],h=Wa(e,l,c,a,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Hr(this.placed,t.depth,t.fit)),e=t.move;for(let i=t.depth+1;i<=e.depth;i++){let r=e.node(i),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(i));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,i){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Hr(this.placed,this.depth,A.from(e.create(t,i))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(A.empty,!0);t.childCount&&(this.placed=Hr(this.placed,this.frontier.length,t))}}function zr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(zr(n.firstChild.content,e-1,t)))}function Hr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Hr(n.lastChild.content,e-1,t)))}function Va(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function i0(n,e,t){if(e<=0)return n;let i=n.content;return e>1&&(i=i.replaceChild(0,i0(i.firstChild,e-1,i.childCount==1?t-1:0))),e>0&&(i=n.type.contentMatch.fillBefore(i).append(i),t<=0&&(i=i.append(n.type.contentMatch.matchFragment(i).fillBefore(A.empty,!0)))),n.copy(i)}function Wa(n,e,t,i,r){let s=n.node(e),o=r?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=i.fillBefore(s.content,!0,o);return l&&!Sk(t,s.content,o)?l:null}function Sk(n,e,t){for(let i=t;i<e.childCount;i++)if(!n.allowsMarks(e.child(i).marks))return!0;return!1}function Ck(n){return n.spec.defining||n.spec.definingForContent}function Mk(n,e,t,i){if(!i.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if(n0(r,s,i))return n.step(new Ne(e,t,i));let o=s0(r,s);o[o.length-1]==0&&o.pop();let l=-(r.depth+1);o.unshift(l);for(let f=r.depth,d=r.pos-1;f>0;f--,d--){let p=r.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:r.before(f)==d&&o.splice(1,0,-f)}let a=o.indexOf(l),c=[],h=i.openStart;for(let f=i.content,d=0;;d++){let p=f.firstChild;if(c.push(p),d==i.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let d=c[f],p=Ck(d.type);if(p&&!d.sameMarkup(r.node(Math.abs(l)-1)))h=f;else if(p||!d.type.isTextblock)break}for(let f=i.openStart;f>=0;f--){let d=(f+h+1)%(i.openStart+1),p=c[d];if(p)for(let m=0;m<o.length;m++){let g=o[(m+a)%o.length],y=!0;g<0&&(y=!1,g=-g);let b=r.node(g-1),x=r.index(g-1);if(b.canReplaceWith(x,x,p.type,p.marks))return n.replace(r.before(g),y?s.after(g):t,new I(r0(i.content,0,i.openStart,d),d,i.openEnd))}}let u=n.steps.length;for(let f=o.length-1;f>=0&&(n.replace(e,t,i),!(n.steps.length>u));f--){let d=o[f];d<0||(e=r.before(d),t=s.after(d))}}function r0(n,e,t,i,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(r0(s.content,e+1,t,i,s)))}if(e>i){let s=r.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(A.empty,!0))}return n}function Tk(n,e,t,i){if(!i.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=kk(n.doc,e,i.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new I(A.from(i),0,0))}function Ak(n,e,t){let i=n.doc.resolve(e),r=n.doc.resolve(t),s=s0(i,r);for(let o=0;o<s.length;o++){let l=s[o],a=o==s.length-1;if(a&&l==0||i.node(l).type.contentMatch.validEnd)return n.delete(i.start(l),r.end(l));if(l>0&&(a||i.node(l-1).canReplace(i.index(l-1),r.indexAfter(l-1))))return n.delete(i.before(l),r.after(l))}for(let o=1;o<=i.depth&&o<=r.depth;o++)if(e-i.start(o)==i.depth-o&&t>i.end(o)&&r.end(o)-t!=r.depth-o&&i.start(o-1)==r.start(o-1)&&i.node(o-1).canReplace(i.index(o-1),r.index(o-1)))return n.delete(i.before(o),t);n.delete(e,t)}function s0(n,e){let t=[],i=Math.min(n.depth,e.depth);for(let r=i;r>=0;r--){let s=n.start(r);if(s<n.pos-(n.depth-r)||e.end(r)>e.pos+(e.depth-r)||n.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==n.depth&&r==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class Zi extends Ge{constructor(e,t,i){super(),this.pos=e,this.attr=t,this.value=i}apply(e){let t=e.nodeAt(this.pos);if(!t)return Se.fail("No node at attribute step's position");let i=Object.create(null);for(let s in t.attrs)i[s]=t.attrs[s];i[this.attr]=this.value;let r=t.type.create(i,null,t.marks);return Se.fromReplace(e,this.pos,this.pos+1,new I(A.from(r),0,t.isLeaf?0:1))}getMap(){return yt.empty}invert(e){return new Zi(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 Zi(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Zi(t.pos,t.attr,t.value)}}Ge.jsonID("attr",Zi);class ps extends Ge{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let i=e.type.create(t,e.content,e.marks);return Se.ok(i)}getMap(){return yt.empty}invert(e){return new ps(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new ps(t.attr,t.value)}}Ge.jsonID("docAttr",ps);let ar=class extends Error{};ar=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ar.prototype=Object.create(Error.prototype);ar.prototype.constructor=ar;ar.prototype.name="TransformError";class mu{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new ds}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new ar(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 i=0;i<this.mapping.maps.length;i++){let r=this.mapping.maps[i];i&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,o,l,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}return e==1e9?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,i=I.empty){let r=sa(this.doc,e,t,i);return r&&this.step(r),this}replaceWith(e,t,i){return this.replace(e,t,new I(A.from(i),0,0))}delete(e,t){return this.replace(e,t,I.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,i){return Mk(this,e,t,i),this}replaceRangeWith(e,t,i){return Tk(this,e,t,i),this}deleteRange(e,t){return Ak(this,e,t),this}lift(e,t){return uk(this,e,t),this}join(e,t=1){return wk(this,e,t),this}wrap(e,t){return pk(this,e,t),this}setBlockType(e,t=e,i,r=null){return mk(this,e,t,i,r),this}setNodeMarkup(e,t,i=null,r){return yk(this,e,t,i,r),this}setNodeAttribute(e,t,i){return this.step(new Zi(e,t,i)),this}setDocAttribute(e,t){return this.step(new ps(e,t)),this}addNodeMark(e,t){return this.step(new Un(e,t)),this}removeNodeMark(e,t){let i=this.doc.nodeAt(e);if(!i)throw new RangeError("No node at position "+e);if(t instanceof ae)t.isInSet(i.marks)&&this.step(new Ai(e,t));else{let r=i.marks,s,o=[];for(;s=t.isInSet(r);)o.push(new Ai(e,s)),r=s.removeFromSet(r);for(let l=o.length-1;l>=0;l--)this.step(o[l])}return this}split(e,t=1,i){return bk(this,e,t,i),this}addMark(e,t,i){return ak(this,e,t,i),this}removeMark(e,t,i){return ck(this,e,t,i),this}clearIncompatible(e,t,i){return du(this,e,t,i),this}}const ja=Object.create(null);class U{constructor(e,t,i){this.$anchor=e,this.$head=t,this.ranges=i||[new o0(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=I.empty){let i=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=i,i=i.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],h=e.mapping.slice(s);e.replaceRange(h.map(a.pos),h.map(c.pos),l?I.empty:t),l==0&&ld(e,s,(i?i.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let i=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:o,$to:l}=r[s],a=e.mapping.slice(i),c=a.map(o.pos),h=a.map(l.pos);s?e.deleteRange(c,h):(e.replaceRangeWith(c,h,t),ld(e,i,t.isInline?-1:1))}}static findFrom(e,t,i=!1){let r=e.parent.inlineContent?new _(e):ji(e.node(0),e.parent,e.pos,e.index(),t,i);if(r)return r;for(let s=e.depth-1;s>=0;s--){let o=t<0?ji(e.node(0),e.node(s),e.before(s+1),e.index(s),t,i):ji(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,i);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new wt(e.node(0))}static atStart(e){return ji(e,e,0,0,1)||new wt(e)}static atEnd(e){return ji(e,e,e.content.size,e.childCount,-1)||new wt(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let i=ja[t.type];if(!i)throw new RangeError(`No selection type ${t.type} defined`);return i.fromJSON(e,t)}static jsonID(e,t){if(e in ja)throw new RangeError("Duplicate use of selection JSON ID "+e);return ja[e]=t,t.prototype.jsonID=e,t}getBookmark(){return _.between(this.$anchor,this.$head).getBookmark()}}U.prototype.visible=!0;let o0=class{constructor(e,t){this.$from=e,this.$to=t}},sd=!1;function od(n){!sd&&!n.parent.inlineContent&&(sd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class _ extends U{constructor(e,t=e){od(e),od(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let i=e.resolve(t.map(this.head));if(!i.parent.inlineContent)return U.near(i);let r=e.resolve(t.map(this.anchor));return new _(r.parent.inlineContent?r:i,i)}replace(e,t=I.empty){if(super.replace(e,t),t==I.empty){let i=this.$from.marksAcross(this.$to);i&&e.ensureMarks(i)}}eq(e){return e instanceof _&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new oa(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new _(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,i=t){let r=e.resolve(t);return new this(r,i==t?r:e.resolve(i))}static between(e,t,i){let r=e.pos-t.pos;if((!i||r)&&(i=r>=0?1:-1),!t.parent.inlineContent){let s=U.findFrom(t,i,!0)||U.findFrom(t,-i,!0);if(s)t=s.$head;else return U.near(t,i)}return e.parent.inlineContent||(r==0?e=t:(e=(U.findFrom(e,-i,!0)||U.findFrom(e,i,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new _(e,t)}}U.jsonID("text",_);class oa{constructor(e,t){this.anchor=e,this.head=t}map(e){return new oa(e.map(this.anchor),e.map(this.head))}resolve(e){return _.between(e.resolve(this.anchor),e.resolve(this.head))}}class W extends U{constructor(e){let t=e.nodeAfter,i=e.node(0).resolve(e.pos+t.nodeSize);super(e,i),this.node=t}map(e,t){let{deleted:i,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return i?U.near(s):new W(s)}content(){return new I(A.from(this.node),0,0)}eq(e){return e instanceof W&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new gu(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new W(e.resolve(t.anchor))}static create(e,t){return new W(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}W.prototype.visible=!1;U.jsonID("node",W);class gu{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:i}=e.mapResult(this.anchor);return t?new oa(i,i):new gu(i)}resolve(e){let t=e.resolve(this.anchor),i=t.nodeAfter;return i&&W.isSelectable(i)?new W(t):U.near(t)}}class wt extends U{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=I.empty){if(t==I.empty){e.delete(0,e.doc.content.size);let i=U.atStart(e.doc);i.eq(e.selection)||e.setSelection(i)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new wt(e)}map(e){return new wt(e)}eq(e){return e instanceof wt}getBookmark(){return Ek}}U.jsonID("all",wt);const Ek={map(){return this},resolve(n){return new wt(n)}};function ji(n,e,t,i,r,s=!1){if(e.inlineContent)return _.create(n,t);for(let o=i-(r>0?0:1);r>0?o<e.childCount:o>=0;o+=r){let l=e.child(o);if(l.isAtom){if(!s&&W.isSelectable(l))return W.create(n,t-(r<0?l.nodeSize:0))}else{let a=ji(n,l,t+r,r<0?l.childCount:0,r,s);if(a)return a}t+=l.nodeSize*r}return null}function ld(n,e,t){let i=n.steps.length-1;if(i<e)return;let r=n.steps[i];if(!(r instanceof Ne||r instanceof Be))return;let s=n.mapping.maps[i],o;s.forEach((l,a,c,h)=>{o==null&&(o=h)}),n.setSelection(U.near(n.doc.resolve(o),t))}const ad=1,Xs=2,cd=4;let Ok=class extends mu{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 new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|ad)&~Xs,this.storedMarks=null,this}get selectionSet(){return(this.updated&ad)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Xs,this}ensureMarks(e){return ae.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Xs)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Xs,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let i=this.selection;return t&&(e=e.mark(this.storedMarks||(i.empty?i.$from.marks():i.$from.marksAcross(i.$to)||ae.none))),i.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,i){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(i==null&&(i=t),!e)return this.deleteRange(t,i);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=i==t?o.marks():o.marksAcross(this.doc.resolve(i))}return this.replaceRangeWith(t,i,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(U.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=cd,this}get scrolledIntoView(){return(this.updated&cd)>0}};function hd(n,e){return!e||!n?n:n.bind(e)}class Fr{constructor(e,t,i){this.name=e,this.init=hd(t.init,i),this.apply=hd(t.apply,i)}}const Rk=[new Fr("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Fr("selection",{init(n,e){return n.selection||U.atStart(e.doc)},apply(n){return n.selection}}),new Fr("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,i){return i.selection.$cursor?n.storedMarks:null}}),new Fr("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];let _a=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Rk.slice(),t&&t.forEach(i=>{if(this.pluginsByKey[i.key])throw new RangeError("Adding different instances of a keyed plugin ("+i.key+")");this.plugins.push(i),this.pluginsByKey[i.key]=i,i.spec.state&&this.fields.push(new Fr(i.key,i.spec.state,i))})}},Dk=class $r{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 i=0;i<this.config.plugins.length;i++)if(i!=t){let r=this.config.plugins[i];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],i=this.applyInner(e),r=null;for(;;){let s=!1;for(let o=0;o<this.config.plugins.length;o++){let l=this.config.plugins[o];if(l.spec.appendTransaction){let a=r?r[o].n:0,c=r?r[o].state:this,h=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):t,c,i);if(h&&i.filterTransaction(h,o)){if(h.setMeta("appendedTransaction",e),!r){r=[];for(let u=0;u<this.config.plugins.length;u++)r.push(u<o?{state:i,n:t.length}:{state:this,n:0})}t.push(h),i=i.applyInner(h),s=!0}r&&(r[o]={state:i,n:t.length})}}if(!s)return{state:i,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new $r(this.config),i=this.config.fields;for(let r=0;r<i.length;r++){let s=i[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Ok(this)}static create(e){let t=new _a(e.doc?e.doc.type.schema:e.schema,e.plugins),i=new $r(t);for(let r=0;r<t.fields.length;r++)i[t.fields[r].name]=t.fields[r].init(e,i);return i}reconfigure(e){let t=new _a(this.schema,e.plugins),i=t.fields,r=new $r(t);for(let s=0;s<i.length;s++){let o=i[s].name;r[o]=this.hasOwnProperty(o)?this[o]:i[s].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(i=>i.toJSON())),e&&typeof e=="object")for(let i in e){if(i=="doc"||i=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[i],s=r.spec.state;s&&s.toJSON&&(t[i]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,i){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new _a(e.schema,e.plugins),s=new $r(r);return r.fields.forEach(o=>{if(o.name=="doc")s.doc=Wt.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=U.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(i)for(let l in i){let a=i[l],c=a.spec.state;if(a.key==o.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=c.fromJSON.call(a,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function l0(n,e,t){for(let i in n){let r=n[i];r instanceof Function?r=r.bind(e):i=="handleDOMEvents"&&(r=l0(r,e,{})),t[i]=r}return t}class se{constructor(e){this.spec=e,this.props={},e.props&&l0(e.props,this,this.props),this.key=e.key?e.key.key:a0("plugin")}getState(e){return e[this.key]}}const Ua=Object.create(null);function a0(n){return n in Ua?n+"$"+ ++Ua[n]:(Ua[n]=0,n+"$")}class me{constructor(e="key"){this.key=a0(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const yu=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function c0(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const h0=(n,e,t)=>{let i=c0(n,t);if(!i)return!1;let r=bu(i);if(!r){let o=i.blockRange(),l=o&&Sr(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(x0(n,r,e,-1))return!0;if(i.parent.content.size==0&&(cr(s,"end")||W.isSelectable(s)))for(let o=i.depth;;o--){let l=sa(n.doc,i.before(o),i.after(o),I.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=n.tr.step(l);a.setSelection(cr(s,"end")?U.findFrom(a.doc.resolve(a.mapping.map(r.pos,-1)),-1):W.create(a.doc,r.pos-s.nodeSize)),e(a.scrollIntoView())}return!0}if(o==1||i.node(o-1).childCount>1)break}return s.isAtom&&r.depth==i.depth-1?(e&&e(n.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},Nk=(n,e,t)=>{let i=c0(n,t);if(!i)return!1;let r=bu(i);return r?u0(n,r,e):!1},Ik=(n,e,t)=>{let i=d0(n,t);if(!i)return!1;let r=xu(i);return r?u0(n,r,e):!1};function u0(n,e,t){let i=e.nodeBefore,r=i,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let h=r.lastChild;if(!h)return!1;r=h}let o=e.nodeAfter,l=o,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let h=l.firstChild;if(!h)return!1;l=h}let c=sa(n.doc,s,a,I.empty);if(!c||c.from!=s||c instanceof Ne&&c.slice.size>=a-s)return!1;if(t){let h=n.tr.step(c);h.setSelection(_.create(h.doc,s)),t(h.scrollIntoView())}return!0}function cr(n,e,t=!1){for(let i=n;i;i=e=="start"?i.firstChild:i.lastChild){if(i.isTextblock)return!0;if(t&&i.childCount!=1)return!1}return!1}const f0=(n,e,t)=>{let{$head:i,empty:r}=n.selection,s=i;if(!r)return!1;if(i.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):i.parentOffset>0)return!1;s=bu(i)}let o=s&&s.nodeBefore;return!o||!W.isSelectable(o)?!1:(e&&e(n.tr.setSelection(W.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function bu(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function d0(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const p0=(n,e,t)=>{let i=d0(n,t);if(!i)return!1;let r=xu(i);if(!r)return!1;let s=r.nodeAfter;if(x0(n,r,e,1))return!0;if(i.parent.content.size==0&&(cr(s,"start")||W.isSelectable(s))){let o=sa(n.doc,i.before(),i.after(),I.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=n.tr.step(o);l.setSelection(cr(s,"start")?U.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):W.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==i.depth-1?(e&&e(n.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},m0=(n,e,t)=>{let{$head:i,empty:r}=n.selection,s=i;if(!r)return!1;if(i.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):i.parentOffset<i.parent.content.size)return!1;s=xu(i)}let o=s&&s.nodeAfter;return!o||!W.isSelectable(o)?!1:(e&&e(n.tr.setSelection(W.create(n.doc,s.pos)).scrollIntoView()),!0)};function xu(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const Lk=(n,e)=>{let t=n.selection,i=t instanceof W,r;if(i){if(t.node.isTextblock||!si(n.doc,t.from))return!1;r=t.from}else if(r=ra(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);i&&s.setSelection(W.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Pk=(n,e)=>{let t=n.selection,i;if(t instanceof W){if(t.node.isTextblock||!si(n.doc,t.to))return!1;i=t.to}else if(i=ra(n.doc,t.to,1),i==null)return!1;return e&&e(n.tr.join(i).scrollIntoView()),!0},Bk=(n,e)=>{let{$from:t,$to:i}=n.selection,r=t.blockRange(i),s=r&&Sr(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},g0=(n,e)=>{let{$head:t,$anchor:i}=n.selection;return!t.parent.type.spec.code||!t.sameParent(i)?!1:(e&&e(n.tr.insertText(`
7
+ `).scrollIntoView()),!0)};function wu(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const zk=(n,e)=>{let{$head:t,$anchor:i}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(i))return!1;let r=t.node(-1),s=t.indexAfter(-1),o=wu(r.contentMatchAt(s));if(!o||!r.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,o.createAndFill());a.setSelection(U.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},y0=(n,e)=>{let t=n.selection,{$from:i,$to:r}=t;if(t instanceof wt||i.parent.inlineContent||r.parent.inlineContent)return!1;let s=wu(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!i.parentOffset&&r.index()<r.parent.childCount?i:r).pos,l=n.tr.insert(o,s.createAndFill());l.setSelection(_.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},b0=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Cn(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let i=t.blockRange(),r=i&&Sr(i);return r==null?!1:(e&&e(n.tr.lift(i,r).scrollIntoView()),!0)};function Hk(n){return(e,t)=>{let{$from:i,$to:r}=e.selection;if(e.selection instanceof W&&e.selection.node.isBlock)return!i.parentOffset||!Cn(e.doc,i.pos)?!1:(t&&t(e.tr.split(i.pos).scrollIntoView()),!0);if(!i.depth)return!1;let s=[],o,l,a=!1,c=!1;for(let d=i.depth;;d--)if(i.node(d).isBlock){a=i.end(d)==i.pos+(i.depth-d),c=i.start(d)==i.pos-(i.depth-d),l=wu(i.node(d-1).contentMatchAt(i.indexAfter(d-1))),s.unshift(a&&l?{type:l}:null),o=d;break}else{if(d==1)return!1;s.unshift(null)}let h=e.tr;(e.selection instanceof _||e.selection instanceof wt)&&h.deleteSelection();let u=h.mapping.map(i.pos),f=Cn(h.doc,u,s.length,s);if(f||(s[0]=l?{type:l}:null,f=Cn(h.doc,u,s.length,s)),!f)return!1;if(h.split(u,s.length,s),!a&&c&&i.node(o).type!=l){let d=h.mapping.map(i.before(o)),p=h.doc.resolve(d);l&&i.node(o-1).canReplaceWith(p.index(),p.index()+1,l)&&h.setNodeMarkup(h.mapping.map(i.before(o)),l)}return t&&t(h.scrollIntoView()),!0}}const Fk=Hk(),$k=(n,e)=>{let{$from:t,to:i}=n.selection,r,s=t.sharedDepth(i);return s==0?!1:(r=t.before(s),e&&e(n.tr.setSelection(W.create(n.doc,r))),!0)};function Vk(n,e,t){let i=e.nodeBefore,r=e.nodeAfter,s=e.index();return!i||!r||!i.type.compatibleContent(r.type)?!1:!i.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-i.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||si(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function x0(n,e,t,i){let r=e.nodeBefore,s=e.nodeAfter,o,l,a=r.type.spec.isolating||s.type.spec.isolating;if(!a&&Vk(n,e,t))return!0;let c=!a&&e.parent.canReplace(e.index(),e.index()+1);if(c&&(o=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let d=e.pos+s.nodeSize,p=A.empty;for(let y=o.length-1;y>=0;y--)p=A.from(o[y].create(null,p));p=A.from(r.copy(p));let m=n.tr.step(new Be(e.pos-1,d,e.pos,d,new I(p,1,0),o.length,!0)),g=m.doc.resolve(d+2*o.length);g.nodeAfter&&g.nodeAfter.type==r.type&&si(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||i>0&&a?null:U.findFrom(e,1),u=h&&h.$from.blockRange(h.$to),f=u&&Sr(u);if(f!=null&&f>=e.depth)return t&&t(n.tr.lift(u,f).scrollIntoView()),!0;if(c&&cr(s,"start",!0)&&cr(r,"end")){let d=r,p=[];for(;p.push(d),!d.isTextblock;)d=d.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(d.canReplace(d.childCount,d.childCount,m.content)){if(t){let y=A.empty;for(let x=p.length-1;x>=0;x--)y=A.from(p[x].copy(y));let b=n.tr.step(new Be(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new I(y,p.length,0),0,!0));t(b.scrollIntoView())}return!0}}return!1}function w0(n){return function(e,t){let i=e.selection,r=n<0?i.$from:i.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(_.create(e.doc,n<0?r.start(s):r.end(s)))),!0):!1}}const Wk=w0(-1),jk=w0(1);function _k(n,e=null){return function(t,i){let{$from:r,$to:s}=t.selection,o=r.blockRange(s),l=o&&pu(o,n,e);return l?(i&&i(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function ud(n,e=null){return function(t,i){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(a,c)=>{if(r)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.type==n)r=!0;else{let h=t.doc.resolve(c),u=h.index();r=h.parent.canReplaceWith(u,u+1,n)}})}if(!r)return!1;if(i){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:a}}=t.selection.ranges[o];s.setBlockType(l,a,n,e)}i(s.scrollIntoView())}return!0}}function ku(...n){return function(e,t,i){for(let r=0;r<n.length;r++)if(n[r](e,t,i))return!0;return!1}}ku(yu,h0,f0);ku(yu,p0,m0);ku(g0,y0,b0,Fk);typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Uk(n,e=null){return function(t,i){let{$from:r,$to:s}=t.selection,o=r.blockRange(s);if(!o)return!1;let l=i?t.tr:null;return qk(l,o,n,e)?(i&&i(l.scrollIntoView()),!0):!1}}function qk(n,e,t,i=null){let r=!1,s=e,o=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let a=o.resolve(e.start-2);s=new Yo(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new Yo(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=pu(s,t,i,e);return l?(n&&Kk(n,e,l,r,t),!0):!1}function Kk(n,e,t,i,r){let s=A.empty;for(let h=t.length-1;h>=0;h--)s=A.from(t[h].type.create(t[h].attrs,s));n.step(new Be(e.start-(i?2:0),e.end,e.start,e.end,new I(s,0,0),t.length,!0));let o=0;for(let h=0;h<t.length;h++)t[h].type==r&&(o=h+1);let l=t.length-o,a=e.start+t.length-(i?2:0),c=e.parent;for(let h=e.startIndex,u=e.endIndex,f=!0;h<u;h++,f=!1)!f&&Cn(n.doc,a,l)&&(n.split(a,l),a+=2*l),a+=c.child(h).nodeSize;return n}function Jk(n){return function(e,t){let{$from:i,$to:r}=e.selection,s=i.blockRange(r,o=>o.childCount>0&&o.firstChild.type==n);return s?t?i.node(s.depth-1).type==n?Gk(e,t,n,s):Yk(e,t,s):!0:!1}}function Gk(n,e,t,i){let r=n.tr,s=i.end,o=i.$to.end(i.depth);s<o&&(r.step(new Be(s-1,o,s,o,new I(A.from(t.create(null,i.parent.copy())),1,0),1,!0)),i=new Yo(r.doc.resolve(i.$from.pos),r.doc.resolve(o),i.depth));const l=Sr(i);if(l==null)return!1;r.lift(i,l);let a=r.doc.resolve(r.mapping.map(s,-1)-1);return si(r.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&r.join(a.pos),e(r.scrollIntoView()),!0}function Yk(n,e,t){let i=n.tr,r=t.parent;for(let d=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)d-=r.child(p).nodeSize,i.delete(d-1,d+1);let s=i.doc.resolve(t.start),o=s.nodeAfter;if(i.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,a=t.endIndex==r.childCount,c=s.node(-1),h=s.index(-1);if(!c.canReplace(h+(l?0:1),h+1,o.content.append(a?A.empty:A.from(r))))return!1;let u=s.pos,f=u+o.nodeSize;return i.step(new Be(u-(l?1:0),f+(a?1:0),u+1,f-1,new I((l?A.empty:A.from(r.copy(A.empty))).append(a?A.empty:A.from(r.copy(A.empty))),l?0:1,a?0:1),l?0:1)),e(i.scrollIntoView()),!0}function Xk(n){return function(e,t){let{$from:i,$to:r}=e.selection,s=i.blockRange(r,c=>c.childCount>0&&c.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,a=l.child(o-1);if(a.type!=n)return!1;if(t){let c=a.lastChild&&a.lastChild.type==l.type,h=A.from(c?n.create():null),u=new I(A.from(n.create(null,A.from(l.type.create(null,h)))),c?3:1,0),f=s.start,d=s.end;t(e.tr.step(new Be(f-(c?3:1),d,f,d,u,1,!0)).scrollIntoView())}return!0}}const Ve=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},hr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Uc=null;const xn=function(n,e,t){let i=Uc||(Uc=document.createRange());return i.setEnd(n,t??n.nodeValue.length),i.setStart(n,e||0),i},Qk=function(){Uc=null},Ei=function(n,e,t,i){return t&&(fd(n,e,t,i,-1)||fd(n,e,t,i,1))},Zk=/^(img|br|input|textarea|hr)$/i;function fd(n,e,t,i,r){for(var s;;){if(n==t&&e==i)return!0;if(e==(r<0?0:Tt(n))){let o=n.parentNode;if(!o||o.nodeType!=1||Bs(n)||Zk.test(n.nodeName)||n.contentEditable=="false")return!1;e=Ve(n)+(r<0?0:1),n=o}else if(n.nodeType==1){let o=n.childNodes[e+(r<0?-1:0)];if(o.nodeType==1&&o.contentEditable=="false")if(!((s=o.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else n=o,e=r<0?Tt(n):0}else return!1}}function Tt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function ev(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Tt(n)}else if(n.parentNode&&!Bs(n))e=Ve(n),n=n.parentNode;else return null}}function tv(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!Bs(n))e=Ve(n)+1,n=n.parentNode;else return null}}function nv(n,e,t){for(let i=e==0,r=e==Tt(n);i||r;){if(n==t)return!0;let s=Ve(n);if(n=n.parentNode,!n)return!1;i=i&&s==0,r=r&&s==Tt(n)}}function Bs(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const la=function(n){return n.focusNode&&Ei(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function fi(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function iv(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function rv(n,e,t){if(n.caretPositionFromPoint)try{let i=n.caretPositionFromPoint(e,t);if(i)return{node:i.offsetNode,offset:Math.min(Tt(i.offsetNode),i.offset)}}catch{}if(n.caretRangeFromPoint){let i=n.caretRangeFromPoint(e,t);if(i)return{node:i.startContainer,offset:Math.min(Tt(i.startContainer),i.startOffset)}}}const un=typeof navigator<"u"?navigator:null,dd=typeof document<"u"?document:null,oi=un&&un.userAgent||"",qc=/Edge\/(\d+)/.exec(oi),k0=/MSIE \d/.exec(oi),Kc=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oi),ot=!!(k0||Kc||qc),Gn=k0?document.documentMode:Kc?+Kc[1]:qc?+qc[1]:0,Dt=!ot&&/gecko\/(\d+)/i.test(oi);Dt&&+(/Firefox\/(\d+)/.exec(oi)||[0,0])[1];const Jc=!ot&&/Chrome\/(\d+)/.exec(oi),Le=!!Jc,v0=Jc?+Jc[1]:0,je=!ot&&!!un&&/Apple Computer/.test(un.vendor),ur=je&&(/Mobile\/\w+/.test(oi)||!!un&&un.maxTouchPoints>2),Ct=ur||(un?/Mac/.test(un.platform):!1),S0=un?/Win/.test(un.platform):!1,kn=/Android \d/.test(oi),zs=!!dd&&"webkitFontSmoothing"in dd.documentElement.style,sv=zs?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function ov(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function pn(n,e){return typeof n=="number"?n:n[e]}function lv(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,i=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*i}}function pd(n,e,t){let i=n.someProp("scrollThreshold")||0,r=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;){if(o.nodeType!=1){o=hr(o);continue}let l=o,a=l==s.body,c=a?ov(s):lv(l),h=0,u=0;if(e.top<c.top+pn(i,"top")?u=-(c.top-e.top+pn(r,"top")):e.bottom>c.bottom-pn(i,"bottom")&&(u=e.bottom-e.top>c.bottom-c.top?e.top+pn(r,"top")-c.top:e.bottom-c.bottom+pn(r,"bottom")),e.left<c.left+pn(i,"left")?h=-(c.left-e.left+pn(r,"left")):e.right>c.right-pn(i,"right")&&(h=e.right-c.right+pn(r,"right")),h||u)if(a)s.defaultView.scrollBy(h,u);else{let d=l.scrollLeft,p=l.scrollTop;u&&(l.scrollTop+=u),h&&(l.scrollLeft+=h);let m=l.scrollLeft-d,g=l.scrollTop-p;e={left:e.left-m,top:e.top-g,right:e.right-m,bottom:e.bottom-g}}let f=a?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(f))break;o=f=="absolute"?o.offsetParent:hr(o)}}function av(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),i,r;for(let s=(e.left+e.right)/2,o=t+1;o<Math.min(innerHeight,e.bottom);o+=5){let l=n.root.elementFromPoint(s,o);if(!l||l==n.dom||!n.dom.contains(l))continue;let a=l.getBoundingClientRect();if(a.top>=t-20){i=l,r=a.top;break}}return{refDOM:i,refTop:r,stack:C0(n.dom)}}function C0(n){let e=[],t=n.ownerDocument;for(let i=n;i&&(e.push({dom:i,top:i.scrollTop,left:i.scrollLeft}),n!=t);i=hr(i));return e}function cv({refDOM:n,refTop:e,stack:t}){let i=n?n.getBoundingClientRect().top:0;M0(t,i==0?0:i-e)}function M0(n,e){for(let t=0;t<n.length;t++){let{dom:i,top:r,left:s}=n[t];i.scrollTop!=r+e&&(i.scrollTop=r+e),i.scrollLeft!=s&&(i.scrollLeft=s)}}let Vi=null;function hv(n){if(n.setActive)return n.setActive();if(Vi)return n.focus(Vi);let e=C0(n);n.focus(Vi==null?{get preventScroll(){return Vi={preventScroll:!0},!0}}:void 0),Vi||(Vi=!1,M0(e,0))}function T0(n,e){let t,i=2e8,r,s=0,o=e.top,l=e.top,a,c;for(let h=n.firstChild,u=0;h;h=h.nextSibling,u++){let f;if(h.nodeType==1)f=h.getClientRects();else if(h.nodeType==3)f=xn(h).getClientRects();else continue;for(let d=0;d<f.length;d++){let p=f[d];if(p.top<=o&&p.bottom>=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right<e.left?e.left-p.right:0;if(m<i){t=h,i=m,r=m&&t.nodeType==3?{left:p.right<e.left?p.right:p.left,top:e.top}:e,h.nodeType==1&&m&&(s=u+(e.left>=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!a&&p.left<=e.left&&p.right>=e.left&&(a=h,c={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=u+1)}}return!t&&a&&(t=a,r=c,i=0),t&&t.nodeType==3?uv(t,r):!t||i&&t.nodeType==1?{node:n,offset:s}:T0(t,r)}function uv(n,e){let t=n.nodeValue.length,i=document.createRange(),r;for(let s=0;s<t;s++){i.setEnd(n,s+1),i.setStart(n,s);let o=Ln(i,1);if(o.top!=o.bottom&&vu(e,o)){r={node:n,offset:s+(e.left>=(o.left+o.right)/2?1:0)};break}}return i.detach(),r||{node:n,offset:0}}function vu(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function fv(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function dv(n,e,t){let{node:i,offset:r}=T0(e,t),s=-1;if(i.nodeType==1&&!i.firstChild){let o=i.getBoundingClientRect();s=o.left!=o.right&&t.left>(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(i,r,s)}function pv(n,e,t,i){let r=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!o&&a.left>i.left||a.top>i.top?r=l.posBefore:(!o&&a.right<i.left||a.bottom<i.top)&&(r=l.posAfter),o=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?i.top<(a.top+a.bottom)/2:i.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:n.docView.posFromDOM(e,t,-1)}function A0(n,e,t){let i=n.childNodes.length;if(i&&t.top<t.bottom)for(let r=Math.max(0,Math.min(i-1,Math.floor(i*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let o=n.childNodes[s];if(o.nodeType==1){let l=o.getClientRects();for(let a=0;a<l.length;a++){let c=l[a];if(vu(e,c))return A0(o,e,c)}}if((s=(s+1)%i)==r)break}return n}function mv(n,e){let t=n.dom.ownerDocument,i,r=0,s=rv(t,e.left,e.top);s&&({node:i,offset:r}=s);let o=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!o||!n.dom.contains(o.nodeType!=1?o.parentNode:o)){let c=n.dom.getBoundingClientRect();if(!vu(e,c)||(o=A0(n.dom,e,c),!o))return null}if(je)for(let c=o;i&&c;c=hr(c))c.draggable&&(i=void 0);if(o=fv(o,e),i){if(Dt&&i.nodeType==1&&(r=Math.min(r,i.childNodes.length),r<i.childNodes.length)){let h=i.childNodes[r],u;h.nodeName=="IMG"&&(u=h.getBoundingClientRect()).right<=e.left&&u.bottom>e.top&&r++}let c;zs&&r&&i.nodeType==1&&(c=i.childNodes[r-1]).nodeType==1&&c.contentEditable=="false"&&c.getBoundingClientRect().top>=e.top&&r--,i==n.dom&&r==i.childNodes.length-1&&i.lastChild.nodeType==1&&e.top>i.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(r==0||i.nodeType!=1||i.childNodes[r-1].nodeName!="BR")&&(l=pv(n,i,r,e))}l==null&&(l=dv(n,o,e));let a=n.docView.nearestDesc(o,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function md(n){return n.top<n.bottom||n.left<n.right}function Ln(n,e){let t=n.getClientRects();if(t.length){let i=t[e<0?0:t.length-1];if(md(i))return i}return Array.prototype.find.call(t,md)||n.getBoundingClientRect()}const gv=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function E0(n,e,t){let{node:i,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),o=zs||Dt;if(i.nodeType==3)if(o&&(gv.test(i.nodeValue)||(t<0?!r:r==i.nodeValue.length))){let a=Ln(xn(i,r,r),t);if(Dt&&r&&/\s/.test(i.nodeValue[r-1])&&r<i.nodeValue.length){let c=Ln(xn(i,r-1,r-1),-1);if(c.top==a.top){let h=Ln(xn(i,r,r+1),-1);if(h.top!=a.top)return Er(h,h.left<c.left)}}return a}else{let a=r,c=r,h=t<0?1:-1;return t<0&&!r?(c++,h=-1):t>=0&&r==i.nodeValue.length?(a--,h=1):t<0?a--:c++,Er(Ln(xn(i,a,c),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Tt(i))){let a=i.childNodes[r-1];if(a.nodeType==1)return qa(a.getBoundingClientRect(),!1)}if(s==null&&r<Tt(i)){let a=i.childNodes[r];if(a.nodeType==1)return qa(a.getBoundingClientRect(),!0)}return qa(i.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Tt(i))){let a=i.childNodes[r-1],c=a.nodeType==3?xn(a,Tt(a)-(o?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(c)return Er(Ln(c,1),!1)}if(s==null&&r<Tt(i)){let a=i.childNodes[r];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let c=a?a.nodeType==3?xn(a,0,o?0:1):a.nodeType==1?a:null:null;if(c)return Er(Ln(c,-1),!0)}return Er(Ln(i.nodeType==3?xn(i):i,-t),t>=0)}function Er(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function qa(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function O0(n,e,t){let i=n.state,r=n.root.activeElement;i!=e&&n.updateState(e),r!=n.dom&&n.focus();try{return t()}finally{i!=e&&n.updateState(i),r!=n.dom&&r&&r.focus()}}function yv(n,e,t){let i=e.selection,r=t=="up"?i.$from:i.$to;return O0(n,e,()=>{let{node:s}=n.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=E0(n,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=xn(l,0,l.nodeValue.length).getClientRects();else continue;for(let c=0;c<a.length;c++){let h=a[c];if(h.bottom>h.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}const bv=/[\u0590-\u08ac]/;function xv(n,e,t){let{$head:i}=e.selection;if(!i.parent.isTextblock)return!1;let r=i.parentOffset,s=!r,o=r==i.parent.content.size,l=n.domSelection();return l?!bv.test(i.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:O0(n,e,()=>{let{focusNode:a,focusOffset:c,anchorNode:h,anchorOffset:u}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let d=i.depth?n.docView.domAfterPos(i.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!d.contains(p.nodeType==1?p:p.parentNode)||a==p&&c==m;try{l.collapse(h,u),a&&(a!=h||c!=u)&&l.extend&&l.extend(a,c)}catch{}return f!=null&&(l.caretBidiLevel=f),g}):i.pos==i.start()||i.pos==i.end()}let gd=null,yd=null,bd=!1;function wv(n,e,t){return gd==e&&yd==t?bd:(gd=e,yd=t,bd=t=="up"||t=="down"?yv(n,e,t):xv(n,e,t))}const Nt=0,xd=1,pi=2,fn=3;class Hs{constructor(e,t,i,r){this.parent=e,this.children=t,this.dom=i,this.contentDOM=r,this.dirty=Nt,i.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,i){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,i=this.posAtStart;;t++){let r=this.children[t];if(r==e)return i;i+=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,i){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(i<0){let s,o;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(o)+o.size:this.posAtStart}else{let s,o;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((o=s.pmViewDesc)&&o.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(o):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Ve(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??i>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let i=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),o;if(s&&(!t||s.node))if(i&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))i=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let i=t;i;i=i.parent)if(i==this)return t}posFromDOM(e,t,i){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,i)}return-1}descAt(e){for(let t=0,i=0;t<this.children.length;t++){let r=this.children[t],s=i+r.size;if(i==e&&s!=i){for(;!r.border&&r.children.length;)for(let o=0;o<r.children.length;o++){let l=r.children[o];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-i-r.border);i=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let i=0,r=0;for(let s=0;i<this.children.length;i++){let o=this.children[i],l=s+o.size;if(l>e||o instanceof D0){r=e-s;break}s=l}if(r)return this.children[i].domFromPos(r-this.children[i].border,t);for(let s;i&&!(s=this.children[i-1]).size&&s instanceof R0&&s.side>=0;i--);if(t<=0){let s,o=!0;for(;s=i?this.children[i-1]:null,!(!s||s.dom.parentNode==this.contentDOM);i--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?Ve(s.dom)+1:0}}else{let s,o=!0;for(;s=i<this.children.length?this.children[i]:null,!(!s||s.dom.parentNode==this.contentDOM);i++,o=!1);return s&&o&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?Ve(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,i=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let o=i,l=0;;l++){let a=this.children[l],c=o+a.size;if(r==-1&&e<=c){let h=o+a.border;if(e>=h&&t<=c-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,h);e=o;for(let u=l;u>0;u--){let f=this.children[u-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){r=Ve(f.dom)+1;break}e-=f.size}r==-1&&(r=0)}if(r>-1&&(c>t||l==this.children.length-1)){t=c;for(let h=l+1;h<this.children.length;h++){let u=this.children[h];if(u.size&&u.dom.parentNode==this.contentDOM&&!u.emptyChildAt(-1)){s=Ve(u.dom);break}t+=u.size}s==-1&&(s=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:i}=this.domFromPos(e,0);if(t.nodeType!=1||i==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[i]}setSelection(e,t,i,r=!1){let s=Math.min(e,t),o=Math.max(e,t);for(let d=0,p=0;d<this.children.length;d++){let m=this.children[d],g=p+m.size;if(s>p&&o<g)return m.setSelection(e-p-m.border,t-p-m.border,i,r);p=g}let l=this.domFromPos(e,e?-1:1),a=t==e?l:this.domFromPos(t,t?-1:1),c=i.root.getSelection(),h=i.domSelectionRange(),u=!1;if((Dt||je)&&e==t){let{node:d,offset:p}=l;if(d.nodeType==3){if(u=!!(p&&d.nodeValue[p-1]==`
8
+ `),u&&p==d.nodeValue.length)for(let m=d,g;m;m=m.parentNode){if(g=m.nextSibling){g.nodeName=="BR"&&(l=a={node:g.parentNode,offset:Ve(g)+1});break}let y=m.pmViewDesc;if(y&&y.node&&y.node.isBlock)break}}else{let m=d.childNodes[p-1];u=m&&(m.nodeName=="BR"||m.contentEditable=="false")}}if(Dt&&h.focusNode&&h.focusNode!=a.node&&h.focusNode.nodeType==1){let d=h.focusNode.childNodes[h.focusOffset];d&&d.contentEditable=="false"&&(r=!0)}if(!(r||u&&je)&&Ei(l.node,l.offset,h.anchorNode,h.anchorOffset)&&Ei(a.node,a.offset,h.focusNode,h.focusOffset))return;let f=!1;if((c.extend||e==t)&&!(u&&Dt)){c.collapse(l.node,l.offset);try{e!=t&&c.extend(a.node,a.offset),f=!0}catch{}}if(!f){if(e>t){let p=l;l=a,a=p}let d=document.createRange();d.setEnd(a.node,a.offset),d.setStart(l.node,l.offset),c.removeAllRanges(),c.addRange(d)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let i=0,r=0;r<this.children.length;r++){let s=this.children[r],o=i+s.size;if(i==o?e<=o&&t>=i:e<o&&t>i){let l=i+s.border,a=o-s.border;if(e>=l&&t<=a){this.dirty=e==i||t==o?pi:xd,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=fn:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?pi:fn}i=o}this.dirty=pi}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let i=e==1?pi:xd;t.dirty<i&&(t.dirty=i)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class R0 extends Hs{constructor(e,t,i,r){let s,o=t.type.toDOM;if(typeof o=="function"&&(o=o(i,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Nt&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class kv extends Hs{constructor(e,t,i,r){super(e,[],t,null),this.textDOM=i,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 e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Oi extends Hs{constructor(e,t,i,r,s){super(e,[],i,r),this.mark=t,this.spec=s}static create(e,t,i,r){let s=r.nodeViews[t.type.name],o=s&&s(t,r,i);return(!o||!o.dom)&&(o=Bi.renderSpec(document,t.type.spec.toDOM(t,i),null,t.attrs)),new Oi(e,t,o.dom,o.contentDOM||o.dom,o)}parseRule(){return this.dirty&fn||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=fn&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Nt){let i=this.parent;for(;!i.node;)i=i.parent;i.dirty<this.dirty&&(i.dirty=this.dirty),this.dirty=Nt}}slice(e,t,i){let r=Oi.create(this.parent,this.mark,!0,i),s=this.children,o=this.size;t<o&&(s=Yc(s,t,o,i)),e>0&&(s=Yc(s,0,e,i));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Yn extends Hs{constructor(e,t,i,r,s,o,l,a,c){super(e,[],s,o),this.node=t,this.outerDeco=i,this.innerDeco=r,this.nodeDOM=l}static create(e,t,i,r,s,o){let l=s.nodeViews[t.type.name],a,c=l&&l(t,s,()=>{if(!a)return o;if(a.parent)return a.parent.posBeforeChild(a)},i,r),h=c&&c.dom,u=c&&c.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:u}=Bi.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!u&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=L0(h,i,t),c?a=new vv(e,t,i,r,h,u||null,f,c,s,o+1):t.isText?new aa(e,t,i,r,h,f,s):new Yn(e,t,i,r,h,u||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let i=this.children[t];if(this.dom.contains(i.dom.parentNode)){e.contentElement=i.dom.parentNode;break}}e.contentElement||(e.getContent=()=>A.empty)}return e}matchesNode(e,t,i){return this.dirty==Nt&&e.eq(this.node)&&Xo(t,this.outerDeco)&&i.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let i=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,a=new Cv(this,o&&o.node,e);Av(this.node,this.innerDeco,(c,h,u)=>{c.spec.marks?a.syncToMarks(c.spec.marks,i,e,h):c.type.side>=0&&!u&&a.syncToMarks(h==this.node.childCount?ae.none:this.node.child(h).marks,i,e,h),a.placeWidget(c,e,r)},(c,h,u,f)=>{a.syncToMarks(c.marks,i,e,f);let d;a.findNodeMatch(c,h,u,f)||l&&e.state.selection.from>r&&e.state.selection.to<r+c.nodeSize&&(d=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(c,h,u,d,e)||a.updateNextNode(c,h,u,e,f,r)||a.addNode(c,h,u,e,r),r+=c.nodeSize}),a.syncToMarks([],i,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==pi)&&(o&&this.protectLocalComposition(e,o),N0(this.contentDOM,this.children,e),ur&&Ev(this.dom))}localCompositionInfo(e,t){let{from:i,to:r}=e.state.selection;if(!(e.state.selection instanceof _)||i<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Ov(this.node.content,o,i-t,r-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:i,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new kv(this,s,t,r);e.input.compositionNodes.push(o),this.children=Yc(this.children,i,i+r.length,e,o)}update(e,t,i,r){return this.dirty==fn||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,i,r),!0)}updateInner(e,t,i,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=i,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Nt}updateOuterDeco(e){if(Xo(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,i=this.dom;this.dom=I0(this.dom,this.nodeDOM,Gc(this.outerDeco,this.node,t),Gc(e,this.node,t)),this.dom!=i&&(i.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function wd(n,e,t,i,r){L0(i,e,n);let s=new Yn(void 0,n,e,t,i,i,i,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class aa extends Yn{constructor(e,t,i,r,s,o,l){super(e,t,i,r,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,i,r){return this.dirty==fn||this.dirty!=Nt&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Nt||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=Nt,!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,i){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,i)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,i){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new aa(this.parent,r,this.outerDeco,this.innerDeco,s,s,i)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=fn)}get domAtom(){return!1}isText(e){return this.node.text==e}}class D0 extends Hs{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Nt&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class vv extends Yn{constructor(e,t,i,r,s,o,l,a,c,h){super(e,t,i,r,s,o,l,c,h),this.spec=a}update(e,t,i,r){if(this.dirty==fn)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,i);return s&&this.updateInner(e,t,i,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,i,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,i,r){this.spec.setSelection?this.spec.setSelection(e,t,i.root):super.setSelection(e,t,i,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function N0(n,e,t){let i=n.firstChild,r=!1;for(let s=0;s<e.length;s++){let o=e[s],l=o.dom;if(l.parentNode==n){for(;l!=i;)i=kd(i),r=!0;i=i.nextSibling}else r=!0,n.insertBefore(l,i);if(o instanceof Oi){let a=i?i.previousSibling:n.lastChild;N0(o.contentDOM,o.children,t),i=a?a.nextSibling:n.firstChild}}for(;i;)i=kd(i),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Yr=function(n){n&&(this.nodeName=n)};Yr.prototype=Object.create(null);const mi=[new Yr];function Gc(n,e,t){if(n.length==0)return mi;let i=t?mi[0]:new Yr,r=[i];for(let s=0;s<n.length;s++){let o=n[s].type.attrs;if(o){o.nodeName&&r.push(i=new Yr(o.nodeName));for(let l in o){let a=o[l];a!=null&&(t&&r.length==1&&r.push(i=new Yr(e.isInline?"span":"div")),l=="class"?i.class=(i.class?i.class+" ":"")+a:l=="style"?i.style=(i.style?i.style+";":"")+a:l!="nodeName"&&(i[l]=a))}}}return r}function I0(n,e,t,i){if(t==mi&&i==mi)return e;let r=e;for(let s=0;s<i.length;s++){let o=i[s],l=t[s];if(s){let a;l&&l.nodeName==o.nodeName&&r!=n&&(a=r.parentNode)&&a.nodeName.toLowerCase()==o.nodeName||(a=document.createElement(o.nodeName),a.pmIsDeco=!0,a.appendChild(r),l=mi[0]),r=a}Sv(r,l||mi[0],o)}return r}function Sv(n,e,t){for(let i in e)i!="class"&&i!="style"&&i!="nodeName"&&!(i in t)&&n.removeAttribute(i);for(let i in t)i!="class"&&i!="style"&&i!="nodeName"&&t[i]!=e[i]&&n.setAttribute(i,t[i]);if(e.class!=t.class){let i=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<i.length;s++)r.indexOf(i[s])==-1&&n.classList.remove(i[s]);for(let s=0;s<r.length;s++)i.indexOf(r[s])==-1&&n.classList.add(r[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let i=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=i.exec(e.style);)n.style.removeProperty(r[1])}t.style&&(n.style.cssText+=t.style)}}function L0(n,e,t){return I0(n,n,mi,Gc(e,t,n.nodeType!=1))}function Xo(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function kd(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Cv{constructor(e,t,i){this.lock=t,this.view=i,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Mv(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let i=e;i<t;i++)this.top.children[i].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,i,r){let s=0,o=this.stack.length>>1,l=Math.min(o,e.length);for(;s<l&&(s==o-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<o;)this.destroyRest(),this.top.dirty=Nt,this.index=this.stack.pop(),this.top=this.stack.pop(),o--;for(;o<e.length;){this.stack.push(this.top,this.index+1);let a=-1,c=this.top.children.length;r<this.preMatch.index&&(c=Math.min(this.index+3,c));for(let h=this.index;h<c;h++){let u=this.top.children[h];if(u.matchesMark(e[o])&&!this.isLocked(u.dom)){a=h;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let h=Oi.create(this.top,e[o],t,i);this.top.children.splice(this.index,0,h),this.top=h,this.changed=!0}this.index=0,o++}}findNodeMatch(e,t,i,r){let s=-1,o;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,i))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,a=Math.min(this.top.children.length,l+5);l<a;l++){let c=this.top.children[l];if(c.matchesNode(e,t,i)&&!this.preMatch.matched.has(c)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,i,r,s){let o=this.top.children[r];return o.dirty==fn&&o.dom==o.contentDOM&&(o.dirty=pi),o.update(e,t,i,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let i=e.pmViewDesc;if(i){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==i)return r}return-1}e=t}}updateNextNode(e,t,i,r,s,o){for(let l=this.index;l<this.top.children.length;l++){let a=this.top.children[l];if(a instanceof Yn){let c=this.preMatch.matched.get(a);if(c!=null&&c!=s)return!1;let h=a.dom,u,f=this.isLocked(h)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=fn&&Xo(t,a.outerDeco));if(!f&&a.update(e,t,i,r))return this.destroyBetween(this.index,l),a.dom!=h&&(this.changed=!0),this.index++,!0;if(!f&&(u=this.recreateWrapper(a,e,t,i,r,o)))return this.destroyBetween(this.index,l),this.top.children[this.index]=u,u.contentDOM&&(u.dirty=pi,u.updateChildren(r,o+1),u.dirty=Nt),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,i,r,s,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!Xo(i,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Yn.create(this.top,t,i,r,s,o);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,i,r,s){let o=Yn.create(this.top,e,t,i,r,s);o.contentDOM&&o.updateChildren(r,s+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,i){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 s=new R0(this.top,e,t,i);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Oi;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof aa)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((je||Le)&&e&&e.dom.contentEditable=="false"&&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 i=document.createElement(e);e=="IMG"&&(i.className="ProseMirror-separator",i.alt=""),e=="BR"&&(i.className="ProseMirror-trailingBreak");let r=new D0(this.top,[],i,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||e.nodeType==1&&e.contains(this.lock.parentNode))}}function Mv(n,e){let t=e,i=t.children.length,r=n.childCount,s=new Map,o=[];e:for(;r>0;){let l;for(;;)if(i){let c=t.children[i-1];if(c instanceof Oi)t=c,i=c.children.length;else{l=c,i--;break}}else{if(t==e)break e;i=t.parent.children.indexOf(t),t=t.parent}let a=l.node;if(a){if(a!=n.child(r-1))break;--r,s.set(l,r),o.push(l)}}return{index:r,matched:s,matches:o.reverse()}}function Tv(n,e){return n.type.side-e.type.side}function Av(n,e,t,i){let r=e.locals(n),s=0;if(r.length==0){for(let c=0;c<n.childCount;c++){let h=n.child(c);i(h,r,e.forChild(s,h),c),s+=h.nodeSize}return}let o=0,l=[],a=null;for(let c=0;;){let h,u;for(;o<r.length&&r[o].to==s;){let g=r[o++];g.widget&&(h?(u||(u=[h])).push(g):h=g)}if(h)if(u){u.sort(Tv);for(let g=0;g<u.length;g++)t(u[g],c,!!a)}else t(h,c,!!a);let f,d;if(a)d=-1,f=a,a=null;else if(c<n.childCount)d=c,f=n.child(c++);else break;for(let g=0;g<l.length;g++)l[g].to<=s&&l.splice(g--,1);for(;o<r.length&&r[o].from<=s&&r[o].to>s;)l.push(r[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o<r.length&&r[o].from<g&&(g=r[o].from);for(let y=0;y<l.length;y++)l[y].to<g&&(g=l[y].to);g<p&&(a=f.cut(g-s),f=f.cut(0,g-s),p=g,d=-1)}else for(;o<r.length&&r[o].to<p;)o++;let m=f.isInline&&!f.isLeaf?l.filter(g=>!g.inline):l.slice();i(f,m,e.forChild(s,f),d),s=p}}function Ev(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Ov(n,e,t,i){for(let r=0,s=0;r<n.childCount&&s<=i;){let o=n.child(r++),l=s;if(s+=o.nodeSize,!o.isText)continue;let a=o.text;for(;r<n.childCount;){let c=n.child(r++);if(s+=c.nodeSize,!c.isText)break;a+=c.text}if(s>=t){if(s>=i&&a.slice(i-e.length-l,i-l)==e)return i-e.length;let c=l<i?a.lastIndexOf(e,i-l-1):-1;if(c>=0&&c+e.length+l>=t)return l+c;if(t==i&&a.length>=i+e.length-l&&a.slice(i-l,i-l+e.length)==e)return i}}return-1}function Yc(n,e,t,i,r){let s=[];for(let o=0,l=0;o<n.length;o++){let a=n[o],c=l,h=l+=a.size;c>=t||h<=e?s.push(a):(c<e&&s.push(a.slice(0,e-c,i)),r&&(s.push(r),r=void 0),h>t&&s.push(a.slice(t-c,a.size,i)))}return s}function Su(n,e=null){let t=n.domSelectionRange(),i=n.state.doc;if(!t.focusNode)return null;let r=n.docView.nearestDesc(t.focusNode),s=r&&r.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=i.resolve(o),a,c;if(la(t)){for(a=o;r&&!r.node;)r=r.parent;let u=r.node;if(r&&u.isAtom&&W.isSelectable(u)&&r.parent&&!(u.isInline&&nv(t.focusNode,t.focusOffset,r.dom))){let f=r.posBefore;c=new W(o==f?l:i.resolve(f))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let u=o,f=o;for(let d=0;d<t.rangeCount;d++){let p=t.getRangeAt(d);u=Math.min(u,n.docView.posFromDOM(p.startContainer,p.startOffset,1)),f=Math.max(f,n.docView.posFromDOM(p.endContainer,p.endOffset,-1))}if(u<0)return null;[a,o]=f==n.state.selection.anchor?[f,u]:[u,f],l=i.resolve(o)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let h=i.resolve(a);if(!c){let u=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;c=Cu(n,h,l,u)}return c}function P0(n){return n.editable?n.hasFocus():z0(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function Mn(n,e=!1){let t=n.state.selection;if(B0(n,t),!!P0(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Le){let i=n.domSelectionRange(),r=n.domObserver.currentSelection;if(i.anchorNode&&r.anchorNode&&Ei(i.anchorNode,i.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Dv(n);else{let{anchor:i,head:r}=t,s,o;vd&&!(t instanceof _)&&(t.$from.parent.inlineContent||(s=Sd(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(o=Sd(n,t.to))),n.docView.setSelection(i,r,n,e),vd&&(s&&Cd(s),o&&Cd(o)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Rv(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const vd=je||Le&&v0<63;function Sd(n,e){let{node:t,offset:i}=n.docView.domFromPos(e,0),r=i<t.childNodes.length?t.childNodes[i]:null,s=i?t.childNodes[i-1]:null;if(je&&r&&r.contentEditable=="false")return Ka(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return Ka(r);if(s)return Ka(s)}}function Ka(n){return n.contentEditable="true",je&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Cd(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Rv(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),i=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=i||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!P0(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Dv(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,i=t.nodeName=="IMG";i?e.collapse(t.parentNode,Ve(t)+1):e.collapse(t,0),!i&&!n.state.selection.visible&&ot&&Gn<=11&&(t.disabled=!0,t.disabled=!1)}function B0(n,e){if(e instanceof W){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(Md(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else Md(n)}function Md(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function Cu(n,e,t,i){return n.someProp("createSelectionBetween",r=>r(n,e,t))||_.between(e,t,i)}function Td(n){return n.editable&&!n.hasFocus()?!1:z0(n)}function z0(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Nv(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Ei(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Xc(n,e){let{$anchor:t,$head:i}=n.selection,r=e>0?t.max(i):t.min(i),s=r.parent.inlineContent?r.depth?n.doc.resolve(e>0?r.after():r.before()):null:r;return s&&U.findFrom(s,e)}function Pn(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Ad(n,e,t){let i=n.state.selection;if(i instanceof _)if(t.indexOf("s")>-1){let{$head:r}=i,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return Pn(n,new _(i.$anchor,o))}else if(i.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=Xc(n.state,e);return r&&r instanceof W?Pn(n,r):!1}else if(!(Ct&&t.indexOf("m")>-1)){let r=i.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?W.isSelectable(s)?Pn(n,new W(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):zs?Pn(n,new _(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(i instanceof W&&i.node.isInline)return Pn(n,new _(e>0?i.$to:i.$from));{let r=Xc(n.state,e);return r?Pn(n,r):!1}}}function Qo(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Wi(n,e){return e<0?Iv(n):Lv(n)}function Iv(n){let e=n.domSelectionRange(),t=e.focusNode,i=e.focusOffset;if(!t)return;let r,s,o=!1;for(Dt&&t.nodeType==1&&i<Qo(t)&&Xr(t.childNodes[i],-1)&&(o=!0);;)if(i>0){if(t.nodeType!=1)break;{let l=t.childNodes[i-1];if(Xr(l,-1))r=t,s=--i;else if(l.nodeType==3)t=l,i=t.nodeValue.length;else break}}else{if(H0(t))break;{let l=t.previousSibling;for(;l&&Xr(l,-1);)r=t.parentNode,s=Ve(l),l=l.previousSibling;if(l)t=l,i=Qo(t);else{if(t=t.parentNode,t==n.dom)break;i=0}}}o?Qc(n,t,i):r&&Qc(n,r,s)}function Lv(n){let e=n.domSelectionRange(),t=e.focusNode,i=e.focusOffset;if(!t)return;let r=Qo(t),s,o;for(;;)if(i<r){if(t.nodeType!=1)break;let l=t.childNodes[i];if(Xr(l,1))s=t,o=++i;else break}else{if(H0(t))break;{let l=t.nextSibling;for(;l&&Xr(l,1);)s=l.parentNode,o=Ve(l)+1,l=l.nextSibling;if(l)t=l,i=0,r=Qo(t);else{if(t=t.parentNode,t==n.dom)break;i=r=0}}}s&&Qc(n,s,o)}function H0(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function Pv(n,e){for(;n&&e==n.childNodes.length&&!Bs(n);)e=Ve(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function Bv(n,e){for(;n&&!e&&!Bs(n);)e=Ve(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function Qc(n,e,t){if(e.nodeType!=3){let s,o;(o=Pv(e,t))?(e=o,t=0):(s=Bv(e,t))&&(e=s,t=s.nodeValue.length)}let i=n.domSelection();if(!i)return;if(la(i)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),i.removeAllRanges(),i.addRange(s)}else i.extend&&i.extend(e,t);n.domObserver.setCurSelection();let{state:r}=n;setTimeout(()=>{n.state==r&&Mn(n)},50)}function Ed(n,e){let t=n.state.doc.resolve(e);if(!(Le||S0)&&t.parent.inlineContent){let r=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>r.top&&o<r.bottom&&Math.abs(s.left-r.left)>1)return s.left<r.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),o=(s.top+s.bottom)/2;if(o>r.top&&o<r.bottom&&Math.abs(s.left-r.left)>1)return s.left>r.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Od(n,e,t){let i=n.state.selection;if(i instanceof _&&!i.empty||t.indexOf("s")>-1||Ct&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=i;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Xc(n.state,e);if(o&&o instanceof W)return Pn(n,o)}if(!r.parent.inlineContent){let o=e<0?r:s,l=i instanceof wt?U.near(o,e):U.findFrom(o,e);return l?Pn(n,l):!1}return!1}function Rd(n,e){if(!(n.state.selection instanceof _))return!0;let{$head:t,$anchor:i,empty:r}=n.state.selection;if(!t.sameParent(i))return!0;if(!r)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function Dd(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function zv(n){if(!je||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let i=e.firstChild;Dd(n,i,"true"),setTimeout(()=>Dd(n,i,"false"),20)}return!1}function Hv(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Fv(n,e){let t=e.keyCode,i=Hv(e);if(t==8||Ct&&t==72&&i=="c")return Rd(n,-1)||Wi(n,-1);if(t==46&&!e.shiftKey||Ct&&t==68&&i=="c")return Rd(n,1)||Wi(n,1);if(t==13||t==27)return!0;if(t==37||Ct&&t==66&&i=="c"){let r=t==37?Ed(n,n.state.selection.from)=="ltr"?-1:1:-1;return Ad(n,r,i)||Wi(n,r)}else if(t==39||Ct&&t==70&&i=="c"){let r=t==39?Ed(n,n.state.selection.from)=="ltr"?1:-1:1;return Ad(n,r,i)||Wi(n,r)}else{if(t==38||Ct&&t==80&&i=="c")return Od(n,-1,i)||Wi(n,-1);if(t==40||Ct&&t==78&&i=="c")return zv(n)||Od(n,1,i)||Wi(n,1);if(i==(Ct?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Mu(n,e){n.someProp("transformCopied",d=>{e=d(e,n)});let t=[],{content:i,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&i.childCount==1&&i.firstChild.childCount==1;){r--,s--;let d=i.firstChild;t.push(d.type.name,d.attrs!=d.type.defaultAttrs?d.attrs:null),i=d.content}let o=n.someProp("clipboardSerializer")||Bi.fromSchema(n.state.schema),l=_0(),a=l.createElement("div");a.appendChild(o.serializeFragment(i,{document:l}));let c=a.firstChild,h,u=0;for(;c&&c.nodeType==1&&(h=j0[c.nodeName.toLowerCase()]);){for(let d=h.length-1;d>=0;d--){let p=l.createElement(h[d]);for(;a.firstChild;)p.appendChild(a.firstChild);a.appendChild(p),u++}c=a.firstChild}c&&c.nodeType==1&&c.setAttribute("data-pm-slice",`${r} ${s}${u?` -${u}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",d=>d(e,n))||e.content.textBetween(0,e.content.size,`
9
+
10
+ `);return{dom:a,text:f,slice:e}}function F0(n,e,t,i,r){let s=r.parent.type.spec.code,o,l;if(!t&&!e)return null;let a=!!e&&(i||s||!t);if(a){if(n.someProp("transformPastedText",f=>{e=f(e,s||i,n)}),s)return l=new I(A.from(n.state.schema.text(e.replace(/\r\n?/g,`
11
+ `))),0,0),n.someProp("transformPasted",f=>{l=f(l,n,!0)}),l;let u=n.someProp("clipboardTextParser",f=>f(e,r,i,n));if(u)l=u;else{let f=r.marks(),{schema:d}=n.state,p=Bi.fromSchema(d);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(d.text(m,f)))})}}else n.someProp("transformPastedHTML",u=>{t=u(t,n)}),o=jv(t),zs&&_v(o);let c=o&&o.querySelector("[data-pm-slice]"),h=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let u=+h[3];u>0;u--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Sn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(a||h),context:r,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!$v.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=Uv(Nd(l,+h[1],+h[2]),h[4]);else if(l=I.maxOpen(Vv(l.content,r),!0),l.openStart||l.openEnd){let u=0,f=0;for(let d=l.content.firstChild;u<l.openStart&&!d.type.spec.isolating;u++,d=d.firstChild);for(let d=l.content.lastChild;f<l.openEnd&&!d.type.spec.isolating;f++,d=d.lastChild);l=Nd(l,u,f)}return n.someProp("transformPasted",u=>{l=u(l,n,a)}),l}const $v=/^(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 Vv(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let a=r.findWrapping(l.type),c;if(!a)return o=null;if(c=o.length&&s.length&&V0(a,s,l,o[o.length-1],0))o[o.length-1]=c;else{o.length&&(o[o.length-1]=W0(o[o.length-1],s.length));let h=$0(l,a);o.push(h),r=r.matchType(h.type),s=a}}),o)return A.from(o)}return n}function $0(n,e,t=0){for(let i=e.length-1;i>=t;i--)n=e[i].create(null,A.from(n));return n}function V0(n,e,t,i,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=V0(n,e,t,i.lastChild,r+1);if(s)return i.copy(i.content.replaceChild(i.childCount-1,s));if(i.contentMatchAt(i.childCount).matchType(r==n.length-1?t.type:n[r+1]))return i.copy(i.content.append(A.from($0(t,n,r+1))))}}function W0(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,W0(n.lastChild,e-1)),i=n.contentMatchAt(n.childCount).fillBefore(A.empty,!0);return n.copy(t.append(i))}function Zc(n,e,t,i,r,s){let o=e<0?n.firstChild:n.lastChild,l=o.content;return n.childCount>1&&(s=0),r<i-1&&(l=Zc(l,e,t,i,r+1,s)),r>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(A.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function Nd(n,e,t){return e<n.openStart&&(n=new I(Zc(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new I(Zc(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const j0={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let Id=null;function _0(){return Id||(Id=document.implementation.createHTMLDocument("title"))}let Ja=null;function Wv(n){let e=window.trustedTypes;return e?(Ja||(Ja=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Ja.createHTML(n)):n}function jv(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_0().createElement("div"),i=/<([a-z][^>\s]+)/i.exec(n),r;if((r=i&&j0[i[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=Wv(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function _v(n){let e=n.querySelectorAll(Le?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let i=e[t];i.childNodes.length==1&&i.textContent==" "&&i.parentNode&&i.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),i)}}function Uv(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,i;try{i=JSON.parse(e)}catch{return n}let{content:r,openStart:s,openEnd:o}=n;for(let l=i.length-2;l>=0;l-=2){let a=t.nodes[i[l]];if(!a||a.hasRequiredAttrs())break;r=A.from(a.create(i[l+1],r)),s++,o++}return new I(r,s,o)}const Ze={},et={},qv={touchstart:!0,touchmove:!0};let Kv=class{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 Jv(n){for(let e in Ze){let t=Ze[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=i=>{Yv(n,i)&&!Tu(n,i)&&(n.editable||!(i.type in et))&&t(n,i)},qv[e]?{passive:!0}:void 0)}je&&n.dom.addEventListener("input",()=>null),eh(n)}function qn(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Gv(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function eh(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=i=>Tu(n,i))})}function Tu(n,e){return n.someProp("handleDOMEvents",t=>{let i=t[e.type];return i?i(n,e)||e.defaultPrevented:!1})}function Yv(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Xv(n,e){!Tu(n,e)&&Ze[e.type]&&(n.editable||!(e.type in et))&&Ze[e.type](n,e)}et.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!q0(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(kn&&Le&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),ur&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let i=Date.now();n.input.lastIOSEnter=i,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==i&&(n.someProp("handleKeyDown",r=>r(n,fi(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",i=>i(n,t))||Fv(n,t)?t.preventDefault():qn(n,"key")};et.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};et.keypress=(n,e)=>{let t=e;if(q0(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Ct&&t.metaKey)return;if(n.someProp("handleKeyPress",r=>r(n,t))){t.preventDefault();return}let i=n.state.selection;if(!(i instanceof _)||!i.$from.sameParent(i.$to)){let r=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!n.someProp("handleTextInput",o=>o(n,i.$from.pos,i.$to.pos,r,s))&&n.dispatch(s()),t.preventDefault()}};function ca(n){return{left:n.clientX,top:n.clientY}}function Qv(n,e){let t=e.x-n.clientX,i=e.y-n.clientY;return t*t+i*i<100}function Au(n,e,t,i,r){if(i==-1)return!1;let s=n.state.doc.resolve(i);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),r,!0):l(n,t,s.node(o),s.before(o),r,!1)))return!0;return!1}function er(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let i=n.state.tr.setSelection(e);i.setMeta("pointer",!0),n.dispatch(i)}function Zv(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),i=t.nodeAfter;return i&&i.isAtom&&W.isSelectable(i)?(er(n,new W(t)),!0):!1}function eS(n,e){if(e==-1)return!1;let t=n.state.selection,i,r;t instanceof W&&(i=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(W.isSelectable(l)){i&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(o);break}}return r!=null?(er(n,W.create(n.state.doc,r)),!0):!1}function tS(n,e,t,i,r){return Au(n,"handleClickOn",e,t,i)||n.someProp("handleClick",s=>s(n,e,i))||(r?eS(n,t):Zv(n,t))}function nS(n,e,t,i){return Au(n,"handleDoubleClickOn",e,t,i)||n.someProp("handleDoubleClick",r=>r(n,e,i))}function iS(n,e,t,i){return Au(n,"handleTripleClickOn",e,t,i)||n.someProp("handleTripleClick",r=>r(n,e,i))||rS(n,t,i)}function rS(n,e,t){if(t.button!=0)return!1;let i=n.state.doc;if(e==-1)return i.inlineContent?(er(n,_.create(i,0,i.content.size)),!0):!1;let r=i.resolve(e);for(let s=r.depth+1;s>0;s--){let o=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(o.inlineContent)er(n,_.create(i,l+1,l+1+o.content.size));else if(W.isSelectable(o))er(n,W.create(i,l));else continue;return!0}}function Eu(n){return Zo(n)}const U0=Ct?"metaKey":"ctrlKey";Ze.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let i=Eu(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&Qv(t,n.input.lastClick)&&!t[U0]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button};let o=n.posAtCoords(ca(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new sS(n,o,t,!!i)):(s=="doubleClick"?nS:iS)(n,o.pos,o.inside,t)?t.preventDefault():qn(n,"pointer"))};class sS{constructor(e,t,i,r){this.view=e,this.pos=t,this.event=i,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!i[U0],this.allowDefault=i.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}const l=r?null:i.target,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:c}=e.state;(i.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||c instanceof W&&c.from<=o&&c.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Dt&&!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)),qn(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(()=>Mn(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ca(e))),this.updateAllowDefault(e),this.allowDefault||!t?qn(this.view,"pointer"):tS(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||je&&this.mightDrag&&!this.mightDrag.node.isAtom||Le&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(er(this.view,U.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):qn(this.view,"pointer")}move(e){this.updateAllowDefault(e),qn(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}Ze.touchstart=n=>{n.input.lastTouch=Date.now(),Eu(n),qn(n,"pointer")};Ze.touchmove=n=>{n.input.lastTouch=Date.now(),qn(n,"pointer")};Ze.contextmenu=n=>Eu(n);function q0(n,e){return n.composing?!0:je&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const oS=kn?5e3:-1;et.compositionstart=et.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof _&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(i=>i.type.spec.inclusive===!1)||Le&&S0&&lS(n)))n.markCursor=n.state.storedMarks||t.marks(),Zo(n,!0),n.markCursor=null;else if(Zo(n,!e.selection.empty),Dt&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let i=n.domSelectionRange();for(let r=i.focusNode,s=i.focusOffset;r&&r.nodeType==1&&s!=0;){let o=s<0?r.lastChild:r.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else r=o,s=-1}}n.input.composing=!0}K0(n,oS)};function lS(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let i=e.childNodes[t];return i.nodeType==1&&i.contentEditable=="false"}et.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,K0(n,20))};function K0(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Zo(n),e))}function J0(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=cS());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function aS(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=ev(e.focusNode,e.focusOffset),i=tv(e.focusNode,e.focusOffset);if(t&&i&&t!=i){let r=i.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||i==s)return s;if(!r||!r.isText(i.nodeValue))return i;if(n.input.compositionNode==i){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return i}}return t||i}function cS(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Zo(n,e=!1){if(!(kn&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),J0(n),e||n.docView&&n.docView.dirty){let t=Su(n),i=n.state.selection;return t&&!t.eq(i)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!i.$from.node(i.$from.sharedDepth(i.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function hS(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let i=getSelection(),r=document.createRange();r.selectNodeContents(e),n.dom.blur(),i.removeAllRanges(),i.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const ms=ot&&Gn<15||ur&&sv<604;Ze.copy=et.cut=(n,e)=>{let t=e,i=n.state.selection,r=t.type=="cut";if(i.empty)return;let s=ms?null:t.clipboardData,o=i.content(),{dom:l,text:a}=Mu(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):hS(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function uS(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function fS(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,i=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(i.contentEditable="true"),i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus();let r=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),i.parentNode&&i.parentNode.removeChild(i),t?gs(n,i.value,null,r,e):gs(n,i.textContent,i.innerHTML,r,e)},50)}function gs(n,e,t,i,r){let s=F0(n,e,t,i,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,r,s||I.empty)))return!0;if(!s)return!1;let o=uS(s),l=o?n.state.tr.replaceSelectionWith(o,i):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function G0(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}et.paste=(n,e)=>{let t=e;if(n.composing&&!kn)return;let i=ms?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;i&&gs(n,G0(i),i.getData("text/html"),r,t)?t.preventDefault():fS(n,t)};class Y0{constructor(e,t,i){this.slice=e,this.move=t,this.node=i}}const dS=Ct?"altKey":"ctrlKey";function X0(n,e){let t=n.someProp("dragCopies",i=>!i(e));return t??!e[dS]}Ze.dragstart=(n,e)=>{let t=e,i=n.input.mouseDown;if(i&&i.done(),!t.dataTransfer)return;let r=n.state.selection,s=r.empty?null:n.posAtCoords(ca(t)),o;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof W?r.to-1:r.to))){if(i&&i.mightDrag)o=W.create(n.state.doc,i.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let u=n.docView.nearestDesc(t.target,!0);u&&u.node.type.spec.draggable&&u!=n.docView&&(o=W.create(n.state.doc,u.posBefore))}}let l=(o||n.state.selection).content(),{dom:a,text:c,slice:h}=Mu(n,l);(!t.dataTransfer.files.length||!Le||v0>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(ms?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",ms||t.dataTransfer.setData("text/plain",c),n.dragging=new Y0(h,X0(n,t),o)};Ze.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};et.dragover=et.dragenter=(n,e)=>e.preventDefault();et.drop=(n,e)=>{try{pS(n,e,n.dragging)}finally{n.dragging=null}};function pS(n,e,t){if(!e.dataTransfer)return;let i=n.posAtCoords(ca(e));if(!i)return;let r=n.state.doc.resolve(i.pos),s=t&&t.slice;s?n.someProp("transformPasted",d=>{s=d(s,n,!1)}):s=F0(n,G0(e.dataTransfer),ms?null:e.dataTransfer.getData("text/html"),!1,r);let o=!!(t&&X0(n,e));if(n.someProp("handleDrop",d=>d(n,e,s||I.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?t0(n.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let a=n.state.tr;if(o){let{node:d}=t;d?d.replace(a):a.deleteSelection()}let c=a.mapping.map(l),h=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,u=a.doc;if(h?a.replaceRangeWith(c,c,s.content.firstChild):a.replaceRange(c,c,s),a.doc.eq(u))return;let f=a.doc.resolve(c);if(h&&W.isSelectable(s.content.firstChild)&&f.nodeAfter&&f.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new W(f));else{let d=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((p,m,g,y)=>d=y),a.setSelection(Cu(n,f,a.doc.resolve(d)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Ze.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Mn(n)},20))};Ze.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};Ze.beforeinput=(n,e)=>{if(Le&&kn&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:i}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=i||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,fi(8,"Backspace")))))return;let{$cursor:r}=n.state.selection;r&&r.pos>0&&n.dispatch(n.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let n in et)Ze[n]=et[n];function ys(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}let Ld=class Q0{constructor(e,t){this.toDOM=e,this.spec=t||vi,this.side=this.spec.side||0}map(e,t,i,r){let{pos:s,deleted:o}=e.mapResult(t.from+r,this.side<0?-1:1);return o?null:new kt(s-i,s-i,this)}valid(){return!0}eq(e){return this==e||e instanceof Q0&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ys(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}};class Xn{constructor(e,t){this.attrs=e,this.spec=t||vi}map(e,t,i,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-i,o=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-i;return s>=o?null:new kt(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Xn&&ys(this.attrs,e.attrs)&&ys(this.spec,e.spec)}static is(e){return e.type instanceof Xn}destroy(){}}let mS=class Z0{constructor(e,t){this.attrs=e,this.spec=t||vi}map(e,t,i,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let o=e.mapResult(t.to+r,-1);return o.deleted||o.pos<=s.pos?null:new kt(s.pos-i,o.pos-i,this)}valid(e,t){let{index:i,offset:r}=e.content.findIndex(t.from),s;return r==t.from&&!(s=e.child(i)).isText&&r+s.nodeSize==t.to}eq(e){return this==e||e instanceof Z0&&ys(this.attrs,e.attrs)&&ys(this.spec,e.spec)}destroy(){}},kt=class Vr{constructor(e,t,i){this.from=e,this.to=t,this.type=i}copy(e,t){return new Vr(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,i){return this.type.map(e,this,t,i)}static widget(e,t,i){return new Vr(e,e,new Ld(t,i))}static inline(e,t,i,r){return new Vr(e,t,new Xn(i,r))}static node(e,t,i,r){return new Vr(e,t,new mS(i,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Xn}get widget(){return this.type instanceof Ld}};const _i=[],vi={};class ue{constructor(e,t){this.local=e.length?e:_i,this.children=t.length?t:_i}static create(e,t){return t.length?el(t,e,0,vi):_e}find(e,t,i){let r=[];return this.findInner(e??0,t??1e9,r,0,i),r}findInner(e,t,i,r,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&i.push(l.copy(l.from+r,l.to+r))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,i,r+l,s)}}map(e,t,i){return this==_e||e.maps.length==0?this:this.mapInner(e,t,0,0,i||vi)}mapInner(e,t,i,r,s){let o;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,i,r);a&&a.type.valid(t,a)?(o||(o=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?gS(this.children,o||[],e,t,i,r,s):o?new ue(o.sort(Si),_i):_e}add(e,t){return t.length?this==_e?ue.create(e,t):this.addInner(e,t,0):this}addInner(e,t,i){let r,s=0;e.forEach((l,a)=>{let c=a+i,h;if(h=ty(t,l,c)){for(r||(r=this.children.slice());s<r.length&&r[s]<a;)s+=3;r[s]==a?r[s+2]=r[s+2].addInner(l,h,c+1):r.splice(s,0,a,a+l.nodeSize,el(h,l,c+1,vi)),s+=3}});let o=ey(s?ny(t):t,-i);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new ue(o.length?this.local.concat(o).sort(Si):this.local,r||this.children)}remove(e){return e.length==0||this==_e?this:this.removeInner(e,0)}removeInner(e,t){let i=this.children,r=this.local;for(let s=0;s<i.length;s+=3){let o,l=i[s]+t,a=i[s+1]+t;for(let h=0,u;h<e.length;h++)(u=e[h])&&u.from>l&&u.to<a&&(e[h]=null,(o||(o=[])).push(u));if(!o)continue;i==this.children&&(i=this.children.slice());let c=i[s+2].removeInner(o,l+1);c!=_e?i[s+2]=c:(i.splice(s,3),s-=3)}if(r.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<r.length;l++)r[l].eq(o,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return i==this.children&&r==this.local?this:r.length||i.length?new ue(r,i):_e}forChild(e,t){if(this==_e)return this;if(t.isLeaf)return ue.empty;let i,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(i=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let a=this.local[l];if(a.from<o&&a.to>s&&a.type instanceof Xn){let c=Math.max(s,a.from)-s,h=Math.min(o,a.to)-s;c<h&&(r||(r=[])).push(a.copy(c,h))}}if(r){let l=new ue(r.sort(Si),_i);return i?new $n([l,i]):l}return i||_e}eq(e){if(this==e)return!0;if(!(e instanceof ue)||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 Ou(this.localsInner(e))}localsInner(e){if(this==_e)return _i;if(e.inlineContent||!this.local.some(Xn.is))return this.local;let t=[];for(let i=0;i<this.local.length;i++)this.local[i].type instanceof Xn||t.push(this.local[i]);return t}forEachSet(e){e(this)}}ue.empty=new ue([],[]);ue.removeOverlap=Ou;const _e=ue.empty;class $n{constructor(e){this.members=e}map(e,t){const i=this.members.map(r=>r.map(e,t,vi));return $n.from(i)}forChild(e,t){if(t.isLeaf)return ue.empty;let i=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=_e&&(s instanceof $n?i=i.concat(s.members):i.push(s))}return $n.from(i)}eq(e){if(!(e instanceof $n)||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,i=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{i&&(t=t.slice(),i=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?Ou(i?t:t.sort(Si)):_i}static from(e){switch(e.length){case 0:return _e;case 1:return e[0];default:return new $n(e.every(t=>t instanceof ue)?e:e.reduce((t,i)=>t.concat(i instanceof ue?i:i.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function gS(n,e,t,i,r,s,o){let l=n.slice();for(let c=0,h=s;c<t.maps.length;c++){let u=0;t.maps[c].forEach((f,d,p,m)=>{let g=m-p-(d-f);for(let y=0;y<l.length;y+=3){let b=l[y+1];if(b<0||f>b+h-u)continue;let x=l[y]+h-u;d>=x?l[y+1]=f<=x?-2:-1:f>=h&&g&&(l[y]+=g,l[y+1]+=g)}u+=g}),h=t.maps[c].map(h,-1)}let a=!1;for(let c=0;c<l.length;c+=3)if(l[c+1]<0){if(l[c+1]==-2){a=!0,l[c+1]=-1;continue}let h=t.map(n[c]+s),u=h-r;if(u<0||u>=i.content.size){a=!0;continue}let f=t.map(n[c+1]+s,-1),d=f-r,{index:p,offset:m}=i.content.findIndex(u),g=i.maybeChild(p);if(g&&m==u&&m+g.nodeSize==d){let y=l[c+2].mapInner(t,g,h+1,n[c]+s+1,o);y!=_e?(l[c]=u,l[c+1]=d,l[c+2]=y):(l[c+1]=-2,a=!0)}else a=!0}if(a){let c=yS(l,n,e,t,r,s,o),h=el(c,i,0,o);e=h.local;for(let u=0;u<l.length;u+=3)l[u+1]<0&&(l.splice(u,3),u-=3);for(let u=0,f=0;u<h.children.length;u+=3){let d=h.children[u];for(;f<l.length&&l[f]<d;)f+=3;l.splice(f,0,h.children[u],h.children[u+1],h.children[u+2])}}return new ue(e.sort(Si),l)}function ey(n,e){if(!e||!n.length)return n;let t=[];for(let i=0;i<n.length;i++){let r=n[i];t.push(new kt(r.from+e,r.to+e,r.type))}return t}function yS(n,e,t,i,r,s,o){function l(a,c){for(let h=0;h<a.local.length;h++){let u=a.local[h].map(i,r,c);u?t.push(u):o.onRemove&&o.onRemove(a.local[h].spec)}for(let h=0;h<a.children.length;h+=3)l(a.children[h+2],a.children[h]+c+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+s+1);return t}function ty(n,e,t){if(e.isLeaf)return null;let i=t+e.nodeSize,r=null;for(let s=0,o;s<n.length;s++)(o=n[s])&&o.from>t&&o.to<i&&((r||(r=[])).push(o),n[s]=null);return r}function ny(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function el(n,e,t,i){let r=[],s=!1;e.forEach((l,a)=>{let c=ty(n,l,a+t);if(c){s=!0;let h=el(c,l,t+a+1,i);h!=_e&&r.push(a,a+l.nodeSize,h)}});let o=ey(s?ny(n):n,-t).sort(Si);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(i.onRemove&&i.onRemove(o[l].spec),o.splice(l--,1));return o.length||r.length?new ue(o,r):_e}function Si(n,e){return n.from-e.from||n.to-e.to}function Ou(n){let e=n;for(let t=0;t<e.length-1;t++){let i=e[t];if(i.from!=i.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==i.from){s.to!=i.to&&(e==n&&(e=n.slice()),e[r]=s.copy(s.from,i.to),Pd(e,r+1,s.copy(i.to,s.to)));continue}else{s.from<i.to&&(e==n&&(e=n.slice()),e[t]=i.copy(i.from,s.from),Pd(e,r,i.copy(s.from,i.to)));break}}}return e}function Pd(n,e,t){for(;e<n.length&&Si(t,n[e])>0;)e++;n.splice(e,0,t)}function Ga(n){let e=[];return n.someProp("decorations",t=>{let i=t(n.state);i&&i!=_e&&e.push(i)}),n.cursorWrapper&&e.push(ue.create(n.state.doc,[n.cursorWrapper.deco])),$n.from(e)}const bS={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},xS=ot&&Gn<=11;class wS{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}}let kS=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new wS,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(i=>{for(let r=0;r<i.length;r++)this.queue.push(i[r]);ot&&Gn<=11&&i.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():je&&e.composing&&i.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),xS&&(this.onCharData=i=>{this.queue.push({target:i.target,type:"characterData",oldValue:i.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,bS)),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(Td(this.view)){if(this.suppressingSelectionUpdates)return Mn(this.view);if(ot&&Gn<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Ei(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,i;for(let s=e.focusNode;s;s=hr(s))t.add(s);for(let s=e.anchorNode;s;s=hr(s))if(t.has(s)){i=s;break}let r=i&&this.view.docView.nearestDesc(i);if(r&&r.ignoreMutation({type:"selection",target:i.nodeType==3?i.parentNode:i}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let i=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(i)&&Td(e)&&!this.ignoreSelectionChange(i),s=-1,o=-1,l=!1,a=[];if(e.editable)for(let h=0;h<t.length;h++){let u=this.registerMutation(t[h],a);u&&(s=s<0?u.from:Math.min(u.from,s),o=o<0?u.to:Math.max(u.to,o),u.typeOver&&(l=!0))}if(Dt&&a.length){let h=a.filter(u=>u.nodeName=="BR");if(h.length==2){let[u,f]=h;u.parentNode&&u.parentNode.parentNode==f.parentNode?f.remove():u.remove()}else{let{focusNode:u}=this.currentSelection;for(let f of h){let d=f.parentNode;d&&d.nodeName=="LI"&&(!u||CS(e,u)!=d)&&f.remove()}}}else if((Le||je)&&a.some(h=>h.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let h of a)if(h.nodeName=="BR"&&h.parentNode){let u=h.nextSibling;u&&u.nodeType==1&&u.contentEditable=="false"&&h.parentNode.removeChild(h)}}let c=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&la(i)&&(c=Su(e))&&c.eq(U.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Mn(e),this.currentSelection.set(i),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,o),vS(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,MS(e,a)),this.handleDOMChange(s,o,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(i)||Mn(e),this.currentSelection.set(i))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let i=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(i==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!i||i.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;h<e.addedNodes.length;h++){let u=e.addedNodes[h];t.push(u),u.nodeType==3&&(this.lastChangedTextNode=u)}if(i.contentDOM&&i.contentDOM!=i.dom&&!i.contentDOM.contains(e.target))return{from:i.posBefore,to:i.posAfter};let r=e.previousSibling,s=e.nextSibling;if(ot&&Gn<=11&&e.addedNodes.length)for(let h=0;h<e.addedNodes.length;h++){let{previousSibling:u,nextSibling:f}=e.addedNodes[h];(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(r=u),(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(s=f)}let o=r&&r.parentNode==e.target?Ve(r)+1:0,l=i.localPosFromDOM(e.target,o,-1),a=s&&s.parentNode==e.target?Ve(s):e.target.childNodes.length,c=i.localPosFromDOM(e.target,a,1);return{from:l,to:c}}else return e.type=="attributes"?{from:i.posAtStart-i.border,to:i.posAtEnd+i.border}:(this.lastChangedTextNode=e.target,{from:i.posAtStart,to:i.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},Bd=new WeakMap,zd=!1;function vS(n){if(!Bd.has(n)&&(Bd.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Dt,zd)return;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."),zd=!0}}function Hd(n,e){let t=e.startContainer,i=e.startOffset,r=e.endContainer,s=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return Ei(o.node,o.offset,r,s)&&([t,i,r,s]=[r,s,t,i]),{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:s}}function SS(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return Hd(n,r)}let t;function i(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",i,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",i,!0),t?Hd(n,t):null}function CS(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let i=n.docView.nearestDesc(t,!0);if(i&&i.node.isBlock)return t}return null}function MS(n,e){var t;let{focusNode:i,focusOffset:r}=n.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;for(;;){let a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),i==s&&n.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function TS(n,e,t){let{node:i,fromOffset:r,toOffset:s,from:o,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),c,h=a.anchorNode;if(h&&n.dom.contains(h.nodeType==1?h:h.parentNode)&&(c=[{node:h,offset:a.anchorOffset}],la(a)||c.push({node:a.focusNode,offset:a.focusOffset})),Le&&n.input.lastKeyCode===8)for(let g=s;g>r;g--){let y=i.childNodes[g-1],b=y.pmViewDesc;if(y.nodeName=="BR"&&!b){s=g;break}if(!b||b.size)break}let u=n.state.doc,f=n.someProp("domParser")||Sn.fromSchema(n.state.schema),d=u.resolve(o),p=null,m=f.parse(i,{topNode:d.parent,topMatch:d.parent.contentMatchAt(d.index()),topOpen:!0,from:r,to:s,preserveWhitespace:d.parent.type.whitespace=="pre"?"full":!0,findPositions:c,ruleFromNode:AS,context:d});if(c&&c[0].pos!=null){let g=c[0].pos,y=c[1]&&c[1].pos;y==null&&(y=g),p={anchor:g+o,head:y+o}}return{doc:m,sel:p,from:o,to:l}}function AS(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(je&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||je&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const ES=/^(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 OS(n,e,t,i,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let v=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,D=Su(n,v);if(D&&!n.state.selection.eq(D)){if(Le&&kn&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",J=>J(n,fi(13,"Enter"))))return;let L=n.state.tr.setSelection(D);v=="pointer"?L.setMeta("pointer",!0):v=="key"&&L.scrollIntoView(),s&&L.setMeta("composition",s),n.dispatch(L)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let a=n.state.selection,c=TS(n,e,t),h=n.state.doc,u=h.slice(c.from,c.to),f,d;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(f=n.state.selection.to,d="end"):(f=n.state.selection.from,d="start"),n.input.lastKeyCode=null;let p=NS(u.content,c.doc.content,c.from,f,d);if(p&&n.input.domChangeCount++,(ur&&n.input.lastIOSEnter>Date.now()-225||kn)&&r.some(v=>v.nodeType==1&&!ES.test(v.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",v=>v(n,fi(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(i&&a instanceof _&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(c.sel&&c.sel.anchor!=c.sel.head))p={start:a.from,endA:a.to,endB:a.to};else{if(c.sel){let v=Fd(n,n.state.doc,c.sel);if(v&&!v.eq(n.state.selection)){let D=n.state.tr.setSelection(v);s&&D.setMeta("composition",s),n.dispatch(D)}}return}n.state.selection.from<n.state.selection.to&&p.start==p.endB&&n.state.selection instanceof _&&(p.start>n.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=c.from?p.start=n.state.selection.from:p.endA<n.state.selection.to&&p.endA>=n.state.selection.to-2&&n.state.selection.to<=c.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),ot&&Gn<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>c.from&&c.doc.textBetween(p.start-c.from-1,p.start-c.from+1)=="  "&&(p.start--,p.endA--,p.endB--);let m=c.doc.resolveNoCache(p.start-c.from),g=c.doc.resolveNoCache(p.endB-c.from),y=h.resolve(p.start),b=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((ur&&n.input.lastIOSEnter>Date.now()-225&&(!b||r.some(v=>v.nodeName=="DIV"||v.nodeName=="P"))||!b&&m.pos<c.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(c.doc.textBetween(m.pos,g.pos,"","")))&&n.someProp("handleKeyDown",v=>v(n,fi(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&DS(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",v=>v(n,fi(8,"Backspace")))){kn&&Le&&n.domObserver.suppressSelectionUpdates();return}Le&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),kn&&!b&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&c.sel&&c.sel.anchor==c.sel.head&&c.sel.head==p.endA&&(p.endB-=2,g=c.doc.resolveNoCache(p.endB-c.from),setTimeout(()=>{n.someProp("handleKeyDown",function(v){return v(n,fi(13,"Enter"))})},20));let x=p.start,k=p.endA,w=v=>{let D=v||n.state.tr.replace(x,k,c.doc.slice(p.start-c.from,p.endB-c.from));if(c.sel){let L=Fd(n,D.doc,c.sel);L&&!(Le&&n.composing&&L.empty&&(p.start!=p.endB||n.input.lastChromeDelete<Date.now()-100)&&(L.head==x||L.head==D.mapping.map(k)-1)||ot&&L.empty&&L.head==x)&&D.setSelection(L)}return s&&D.setMeta("composition",s),D.scrollIntoView()},C;if(b)if(m.pos==g.pos){ot&&Gn<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Mn(n),20));let v=w(n.state.tr.delete(x,k)),D=h.resolve(p.start).marksAcross(h.resolve(p.endA));D&&v.ensureMarks(D),n.dispatch(v)}else if(p.endA==p.endB&&(C=RS(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let v=w(n.state.tr);C.type=="add"?v.addMark(x,k,C.mark):v.removeMark(x,k,C.mark),n.dispatch(v)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let v=m.parent.textBetween(m.parentOffset,g.parentOffset),D=()=>w(n.state.tr.insertText(v,x,k));n.someProp("handleTextInput",L=>L(n,x,k,v,D))||n.dispatch(D())}else n.dispatch(w());else n.dispatch(w())}function Fd(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Cu(n,e.resolve(t.anchor),e.resolve(t.head))}function RS(n,e){let t=n.firstChild.marks,i=e.firstChild.marks,r=t,s=i,o,l,a;for(let h=0;h<i.length;h++)r=i[h].removeFromSet(r);for(let h=0;h<t.length;h++)s=t[h].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],o="add",a=h=>h.mark(l.addToSet(h.marks));else if(r.length==0&&s.length==1)l=s[0],o="remove",a=h=>h.mark(l.removeFromSet(h.marks));else return null;let c=[];for(let h=0;h<e.childCount;h++)c.push(a(e.child(h)));if(A.from(c).eq(n))return{mark:l,type:o}}function DS(n,e,t,i,r){if(t-e<=r.pos-i.pos||Ya(i,!0,!1)<r.pos)return!1;let s=n.resolve(e);if(!i.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=n.resolve(Ya(s,!0,!0));return!o.parent.isTextblock||o.pos>t||Ya(o,!0,!1)<t?!1:i.parent.content.cut(i.parentOffset).eq(o.parent.content)}function Ya(n,e,t){let i=n.depth,r=e?n.end():n.pos;for(;i>0&&(e||n.indexAfter(i)==n.node(i).childCount);)i--,r++,e=!1;if(t){let s=n.node(i).maybeChild(n.indexAfter(i));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function NS(n,e,t,i,r){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(r=="end"){let a=Math.max(0,s-Math.min(o,l));i-=o+a-s}if(o<s&&n.size<e.size){let a=i<=s&&i>=o?s-i:0;s-=a,s&&s<e.size&&$d(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-o),o=s}else if(l<s){let a=i<=s&&i>=l?s-i:0;s-=a,s&&s<n.size&&$d(n.textBetween(s-1,s+1))&&(s+=a?1:-1),o=s+(o-l),l=s}return{start:s,endA:o,endB:l}}function $d(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}let iy=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Kv,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Ud),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=jd(this),Wd(this),this.nodeViews=_d(this),this.docView=wd(this.state.doc,Vd(this),Ga(this),this.dom,this),this.domObserver=new kS(this,(i,r,s,o)=>OS(this,i,r,s,o)),this.domObserver.start(),Jv(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&eh(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Ud),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let i in this._props)t[i]=this._props[i];t.state=this.state;for(let i in e)t[i]=e[i];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var i;let r=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(J0(this),o=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let d=_d(this);LS(d,this.nodeViews)&&(this.nodeViews=d,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&eh(this),this.editable=jd(this),Wd(this);let a=Ga(this),c=Vd(this),h=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",u=s||!this.docView.matchesNode(e.doc,c,a);(u||!e.selection.eq(r.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&av(this);if(o){this.domObserver.stop();let d=u&&(ot||Le)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&IS(r.selection,e.selection);if(u){let p=Le?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=aS(this)),(s||!this.docView.update(e.doc,c,a,this))&&(this.docView.updateOuterDeco(c),this.docView.destroy(),this.docView=wd(e.doc,c,a,this.dom,this)),p&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(d=!0)}d||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Nv(this))?Mn(this,d):(B0(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((i=this.dragging)===null||i===void 0)&&i.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&cv(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof W){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&pd(this,t.getBoundingClientRect(),e)}else pd(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let i=this.directPlugins[t];i.spec.view&&this.pluginViews.push(i.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let i=this.state.plugins[t];i.spec.view&&this.pluginViews.push(i.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let i=this.pluginViews[t];i.update&&i.update(this,e)}}updateDraggedNode(e,t){let i=e.node,r=-1;if(this.state.doc.nodeAt(i.from)==i.node)r=i.from;else{let s=i.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==i.node&&(r=s)}this.dragging=new Y0(e.slice,e.move,r<0?void 0:W.create(this.state.doc,r))}someProp(e,t){let i=this._props&&this._props[e],r;if(i!=null&&(r=t?t(i):i))return r;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(ot){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(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&hv(this.dom),Mn(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return mv(this,e)}coordsAtPos(e,t=1){return E0(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,i=-1){let r=this.docView.posFromDOM(e,t,i);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return wv(this,t||this.state,e)}pasteHTML(e,t){return gs(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return gs(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Mu(this,e)}destroy(){this.docView&&(Gv(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ga(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Qk())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Xv(this,e)}domSelectionRange(){let e=this.domSelection();return e?je&&this.root.nodeType===11&&iv(this.dom.ownerDocument)==this.dom&&SS(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};iy.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Vd(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let i in t)i=="class"?e.class+=" "+t[i]:i=="style"?e.style=(e.style?e.style+";":"")+t[i]:!e[i]&&i!="contenteditable"&&i!="nodeName"&&(e[i]=String(t[i]))}),e.translate||(e.translate="no"),[kt.node(0,n.state.doc.content.size,e)]}function Wd(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:kt.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function jd(n){return!n.someProp("editable",e=>e(n.state)===!1)}function IS(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function _d(n){let e=Object.create(null);function t(i){for(let r in i)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=i[r])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function LS(n,e){let t=0,i=0;for(let r in n){if(n[r]!=e[r])return!0;t++}for(let r in e)i++;return t!=i}function Ud(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var On={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},bs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},PS=typeof navigator<"u"&&/Mac/.test(navigator.platform),BS=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var We=0;We<10;We++)On[48+We]=On[96+We]=String(We);for(var We=1;We<=24;We++)On[We+111]="F"+We;for(var We=65;We<=90;We++)On[We]=String.fromCharCode(We+32),bs[We]=String.fromCharCode(We);for(var Xa in On)bs.hasOwnProperty(Xa)||(bs[Xa]=On[Xa]);function ry(n){var e=PS&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||BS&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?bs:On)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const zS=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),HS=typeof navigator<"u"&&/Win/.test(navigator.platform);function FS(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let i,r,s,o;for(let l=0;l<e.length-1;l++){let a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))i=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))zS?o=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return i&&(t="Alt-"+t),r&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function $S(n){let e=Object.create(null);for(let t in n)e[FS(t)]=n[t];return e}function Qa(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function VS(n){return new se({props:{handleKeyDown:Ru(n)}})}function Ru(n){let e=$S(n);return function(t,i){let r=ry(i),s,o=e[Qa(r,i)];if(o&&o(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(i.shiftKey){let l=e[Qa(r,i,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((i.altKey||i.metaKey||i.ctrlKey)&&!(HS&&i.ctrlKey&&i.altKey)&&(s=On[i.keyCode])&&s!=r){let l=e[Qa(s,i)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var WS=Object.defineProperty,Du=(n,e)=>{for(var t in e)WS(n,t,{get:e[t],enumerable:!0})};function ha(n){const{state:e,transaction:t}=n;let{selection:i}=t,{doc:r}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return i},get doc(){return r},get tr(){return i=t.selection,r=t.doc,s=t.storedMarks,t}}}var ua=class{constructor(n){this.editor=n.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=n.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:n,editor:e,state:t}=this,{view:i}=e,{tr:r}=t,s=this.buildProps(r);return Object.fromEntries(Object.entries(n).map(([o,l])=>[o,(...c)=>{const h=l(...c)(s);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&i.dispatch(r),h}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(n,e=!0){const{rawCommands:t,editor:i,state:r}=this,{view:s}=i,o=[],l=!!n,a=n||r.tr,c=()=>(!l&&e&&!a.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(a),o.every(u=>u===!0)),h={...Object.fromEntries(Object.entries(t).map(([u,f])=>[u,(...p)=>{const m=this.buildProps(a,e),g=f(...p)(m);return o.push(g),h}])),run:c};return h}createCan(n){const{rawCommands:e,state:t}=this,i=!1,r=n||t.tr,s=this.buildProps(r,i);return{...Object.fromEntries(Object.entries(e).map(([l,a])=>[l,(...c)=>a(...c)({...s,dispatch:void 0})])),chain:()=>this.createChain(r,i)}}buildProps(n,e=!0){const{rawCommands:t,editor:i,state:r}=this,{view:s}=i,o={tr:n,editor:i,view:s,state:ha({state:r,transaction:n}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(n,e),can:()=>this.createCan(n),get commands(){return Object.fromEntries(Object.entries(t).map(([l,a])=>[l,(...c)=>a(...c)(o)]))}};return o}},Bt={};Du(Bt,{blur:()=>jS,clearContent:()=>_S,clearNodes:()=>US,command:()=>qS,createParagraphNear:()=>KS,cut:()=>JS,deleteCurrentNode:()=>GS,deleteNode:()=>YS,deleteRange:()=>XS,deleteSelection:()=>QS,enter:()=>ZS,exitCode:()=>eC,extendMarkRange:()=>tC,first:()=>nC,focus:()=>rC,forEach:()=>sC,insertContent:()=>oC,insertContentAt:()=>cC,joinBackward:()=>fC,joinDown:()=>uC,joinForward:()=>dC,joinItemBackward:()=>pC,joinItemForward:()=>mC,joinTextblockBackward:()=>gC,joinTextblockForward:()=>yC,joinUp:()=>hC,keyboardShortcut:()=>xC,lift:()=>wC,liftEmptyBlock:()=>kC,liftListItem:()=>vC,newlineInCode:()=>SC,resetAttributes:()=>CC,scrollIntoView:()=>MC,selectAll:()=>TC,selectNodeBackward:()=>AC,selectNodeForward:()=>EC,selectParentNode:()=>OC,selectTextblockEnd:()=>RC,selectTextblockStart:()=>DC,setContent:()=>NC,setMark:()=>XC,setMeta:()=>QC,setNode:()=>ZC,setNodeSelection:()=>eM,setTextDirection:()=>tM,setTextSelection:()=>nM,sinkListItem:()=>iM,splitBlock:()=>rM,splitListItem:()=>sM,toggleList:()=>oM,toggleMark:()=>lM,toggleNode:()=>aM,toggleWrap:()=>cM,undoInputRule:()=>hM,unsetAllMarks:()=>uM,unsetMark:()=>fM,unsetTextDirection:()=>dM,updateAttributes:()=>pM,wrapIn:()=>mM,wrapInList:()=>gM});var jS=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window?.getSelection())==null||t.removeAllRanges())}),!0),_S=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),US=()=>({state:n,tr:e,dispatch:t})=>{const{selection:i}=e,{ranges:r}=i;return t&&r.forEach(({$from:s,$to:o})=>{n.doc.nodesBetween(s.pos,o.pos,(l,a)=>{if(l.type.isText)return;const{doc:c,mapping:h}=e,u=c.resolve(h.map(a)),f=c.resolve(h.map(a+l.nodeSize)),d=u.blockRange(f);if(!d)return;const p=Sr(d);if(l.type.isTextblock){const{defaultType:m}=u.parent.contentMatchAt(u.index());e.setNodeMarkup(d.start,m)}(p||p===0)&&e.lift(d,p)})}),!0},qS=n=>e=>n(e),KS=()=>({state:n,dispatch:e})=>y0(n,e),JS=(n,e)=>({editor:t,tr:i})=>{const{state:r}=t,s=r.doc.slice(n.from,n.to);i.deleteRange(n.from,n.to);const o=i.mapping.map(e);return i.insert(o,s.content),i.setSelection(new _(i.doc.resolve(Math.max(o-1,0)))),!0},GS=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,i=t.$anchor.node();if(i.content.size>0)return!1;const r=n.selection.$anchor;for(let s=r.depth;s>0;s-=1)if(r.node(s).type===i.type){if(e){const l=r.before(s),a=r.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1};function Ae(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}var YS=n=>({tr:e,state:t,dispatch:i})=>{const r=Ae(n,t.schema),s=e.selection.$anchor;for(let o=s.depth;o>0;o-=1)if(s.node(o).type===r){if(i){const a=s.before(o),c=s.after(o);e.delete(a,c).scrollIntoView()}return!0}return!1},XS=n=>({tr:e,dispatch:t})=>{const{from:i,to:r}=n;return t&&e.delete(i,r),!0},QS=()=>({state:n,dispatch:e})=>yu(n,e),ZS=()=>({commands:n})=>n.keyboardShortcut("Enter"),eC=()=>({state:n,dispatch:e})=>zk(n,e);function Nu(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function tl(n,e,t={strict:!0}){const i=Object.keys(e);return i.length?i.every(r=>t.strict?e[r]===n[r]:Nu(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function sy(n,e,t={}){return n.find(i=>i.type===e&&tl(Object.fromEntries(Object.keys(t).map(r=>[r,i.attrs[r]])),t))}function qd(n,e,t={}){return!!sy(n,e,t)}function Iu(n,e,t){var i;if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if((!r.node||!r.node.marks.some(h=>h.type===e))&&(r=n.parent.childBefore(n.parentOffset)),!r.node||!r.node.marks.some(h=>h.type===e)||(t=t||((i=r.node.marks[0])==null?void 0:i.attrs),!sy([...r.node.marks],e,t)))return;let o=r.index,l=n.start()+r.offset,a=o+1,c=l+r.node.nodeSize;for(;o>0&&qd([...n.parent.child(o-1).marks],e,t);)o-=1,l-=n.parent.child(o).nodeSize;for(;a<n.parent.childCount&&qd([...n.parent.child(a).marks],e,t);)c+=n.parent.child(a).nodeSize,a+=1;return{from:l,to:c}}function Dn(n,e){if(typeof n=="string"){if(!e.marks[n])throw Error(`There is no mark type named '${n}'. Maybe you forgot to add the extension?`);return e.marks[n]}return n}var tC=(n,e={})=>({tr:t,state:i,dispatch:r})=>{const s=Dn(n,i.schema),{doc:o,selection:l}=t,{$from:a,from:c,to:h}=l;if(r){const u=Iu(a,s,e);if(u&&u.from<=c&&u.to>=h){const f=_.create(o,u.from,u.to);t.setSelection(f)}}return!0},nC=n=>e=>{const t=typeof n=="function"?n(e):n;for(let i=0;i<t.length;i+=1)if(t[i](e))return!0;return!1};function Lu(n){return n instanceof _}function vn(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function oy(n,e=null){if(!e)return null;const t=U.atStart(n),i=U.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return i;const r=t.from,s=i.to;return e==="all"?_.create(n,vn(0,r,s),vn(n.content.size,r,s)):_.create(n,vn(e,r,s),vn(e,r,s))}function Kd(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function nl(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function iC(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var rC=(n=null,e={})=>({editor:t,view:i,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const o=()=>{(nl()||Kd())&&i.dom.focus(),iC()&&!nl()&&!Kd()&&i.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{t.isDestroyed||(i.focus(),e?.scrollIntoView&&t.commands.scrollIntoView())})};try{if(i.hasFocus()&&n===null||n===!1)return!0}catch{return!1}if(s&&n===null&&!Lu(t.state.selection))return o(),!0;const l=oy(r.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),o()),!0},sC=(n,e)=>t=>n.every((i,r)=>e(i,{...t,index:r})),oC=(n,e)=>({tr:t,commands:i})=>i.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),ly=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const i=e[t];i.nodeType===3&&i.nodeValue&&/^(\n\s\s|\n)$/.test(i.nodeValue)?n.removeChild(i):i.nodeType===1&&ly(i)}return n};function Wr(n){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return ly(t)}function xs(n,e,t){if(n instanceof Wt||n instanceof A)return n;t={slice:!0,parseOptions:{},...t};const i=typeof n=="object"&&n!==null,r=typeof n=="string";if(i)try{if(Array.isArray(n)&&n.length>0)return A.fromArray(n.map(l=>e.nodeFromJSON(l)));const o=e.nodeFromJSON(n);return t.errorOnInvalidContent&&o.check(),o}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),xs("",e,t)}if(r){if(t.errorOnInvalidContent){let o=!1,l="";const a=new _g({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:c=>(o=!0,l=typeof c=="string"?c:c.outerHTML,null)}]}})});if(t.slice?Sn.fromSchema(a).parseSlice(Wr(n),t.parseOptions):Sn.fromSchema(a).parse(Wr(n),t.parseOptions),t.errorOnInvalidContent&&o)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Sn.fromSchema(e);return t.slice?s.parseSlice(Wr(n),t.parseOptions).content:s.parse(Wr(n),t.parseOptions)}return xs("",e,t)}function lC(n,e,t){const i=n.steps.length-1;if(i<e)return;const r=n.steps[i];if(!(r instanceof Ne||r instanceof Be))return;const s=n.mapping.maps[i];let o=0;s.forEach((l,a,c,h)=>{o===0&&(o=h)}),n.setSelection(U.near(n.doc.resolve(o),t))}var aC=n=>!("type"in n),cC=(n,e,t)=>({tr:i,dispatch:r,editor:s})=>{var o;if(r){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;const a=g=>{s.emit("contentError",{editor:s,error:g,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...t.parseOptions};if(!t.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{xs(e,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(g){a(g)}try{l=xs(e,s.schema,{parseOptions:c,errorOnInvalidContent:(o=t.errorOnInvalidContent)!=null?o:s.options.enableContentCheck})}catch(g){return a(g),!1}let{from:h,to:u}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},f=!0,d=!0;if((aC(l)?l:[l]).forEach(g=>{g.check(),f=f?g.isText&&g.marks.length===0:!1,d=d?g.isBlock:!1}),h===u&&d){const{parent:g}=i.doc.resolve(h);g.isTextblock&&!g.type.spec.code&&!g.childCount&&(h-=1,u+=1)}let m;if(f){if(Array.isArray(e))m=e.map(g=>g.text||"").join("");else if(e instanceof A){let g="";e.forEach(y=>{y.text&&(g+=y.text)}),m=g}else typeof e=="object"&&e&&e.text?m=e.text:m=e;i.insertText(m,h,u)}else{m=l;const g=i.doc.resolve(h),y=g.node(),b=g.parentOffset===0,x=y.isText||y.isTextblock,k=y.content.size>0;b&&x&&k&&(h=Math.max(0,h-1)),i.replaceWith(h,u,m)}t.updateSelection&&lC(i,i.steps.length-1,-1),t.applyInputRules&&i.setMeta("applyInputRules",{from:h,text:m}),t.applyPasteRules&&i.setMeta("applyPasteRules",{from:h,text:m})}return!0},hC=()=>({state:n,dispatch:e})=>Lk(n,e),uC=()=>({state:n,dispatch:e})=>Pk(n,e),fC=()=>({state:n,dispatch:e})=>h0(n,e),dC=()=>({state:n,dispatch:e})=>p0(n,e),pC=()=>({state:n,dispatch:e,tr:t})=>{try{const i=ra(n.doc,n.selection.$from.pos,-1);return i==null?!1:(t.join(i,2),e&&e(t),!0)}catch{return!1}},mC=()=>({state:n,dispatch:e,tr:t})=>{try{const i=ra(n.doc,n.selection.$from.pos,1);return i==null?!1:(t.join(i,2),e&&e(t),!0)}catch{return!1}},gC=()=>({state:n,dispatch:e})=>Nk(n,e),yC=()=>({state:n,dispatch:e})=>Ik(n,e);function ay(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function bC(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let i,r,s,o;for(let l=0;l<e.length-1;l+=1){const a=e[l];if(/^(cmd|meta|m)$/i.test(a))o=!0;else if(/^a(lt)?$/i.test(a))i=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))nl()||ay()?o=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${a}`)}return i&&(t=`Alt-${t}`),r&&(t=`Ctrl-${t}`),o&&(t=`Meta-${t}`),s&&(t=`Shift-${t}`),t}var xC=n=>({editor:e,view:t,tr:i,dispatch:r})=>{const s=bC(n).split(/-(?!$)/),o=s.find(c=>!["Alt","Ctrl","Meta","Shift"].includes(c)),l=new KeyboardEvent("keydown",{key:o==="Space"?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",c=>c(t,l))});return a?.steps.forEach(c=>{const h=c.map(i.mapping);h&&r&&i.maybeStep(h)}),!0};function Zn(n,e,t={}){const{from:i,to:r,empty:s}=n.selection,o=e?Ae(e,n.schema):null,l=[];n.doc.nodesBetween(i,r,(u,f)=>{if(u.isText)return;const d=Math.max(i,f),p=Math.min(r,f+u.nodeSize);l.push({node:u,from:d,to:p})});const a=r-i,c=l.filter(u=>o?o.name===u.node.type.name:!0).filter(u=>tl(u.node.attrs,t,{strict:!1}));return s?!!c.length:c.reduce((u,f)=>u+f.to-f.from,0)>=a}var wC=(n,e={})=>({state:t,dispatch:i})=>{const r=Ae(n,t.schema);return Zn(t,r,e)?Bk(t,i):!1},kC=()=>({state:n,dispatch:e})=>b0(n,e),vC=n=>({state:e,dispatch:t})=>{const i=Ae(n,e.schema);return Jk(i)(e,t)},SC=()=>({state:n,dispatch:e})=>g0(n,e);function fa(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function Jd(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((i,r)=>(t.includes(r)||(i[r]=n[r]),i),{})}var CC=(n,e)=>({tr:t,state:i,dispatch:r})=>{let s=null,o=null;const l=fa(typeof n=="string"?n:n.name,i.schema);if(!l)return!1;l==="node"&&(s=Ae(n,i.schema)),l==="mark"&&(o=Dn(n,i.schema));let a=!1;return t.selection.ranges.forEach(c=>{i.doc.nodesBetween(c.$from.pos,c.$to.pos,(h,u)=>{s&&s===h.type&&(a=!0,r&&t.setNodeMarkup(u,void 0,Jd(h.attrs,e))),o&&h.marks.length&&h.marks.forEach(f=>{o===f.type&&(a=!0,r&&t.addMark(u,u+h.nodeSize,o.create(Jd(f.attrs,e))))})})}),a},MC=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),TC=()=>({tr:n,dispatch:e})=>{if(e){const t=new wt(n.doc);n.setSelection(t)}return!0},AC=()=>({state:n,dispatch:e})=>f0(n,e),EC=()=>({state:n,dispatch:e})=>m0(n,e),OC=()=>({state:n,dispatch:e})=>$k(n,e),RC=()=>({state:n,dispatch:e})=>jk(n,e),DC=()=>({state:n,dispatch:e})=>Wk(n,e);function th(n,e,t={},i={}){return xs(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:i.errorOnInvalidContent})}var NC=(n,{errorOnInvalidContent:e,emitUpdate:t=!0,parseOptions:i={}}={})=>({editor:r,tr:s,dispatch:o,commands:l})=>{const{doc:a}=s;if(i.preserveWhitespace!=="full"){const c=th(n,r.schema,i,{errorOnInvalidContent:e??r.options.enableContentCheck});return o&&s.replaceWith(0,a.content.size,c).setMeta("preventUpdate",!t),!0}return o&&s.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:a.content.size},n,{parseOptions:i,errorOnInvalidContent:e??r.options.enableContentCheck})};function cy(n,e){const t=Dn(e,n.schema),{from:i,to:r,empty:s}=n.selection,o=[];s?(n.storedMarks&&o.push(...n.storedMarks),o.push(...n.selection.$head.marks())):n.doc.nodesBetween(i,r,a=>{o.push(...a.marks)});const l=o.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function hy(n,e){const t=new mu(n);return e.forEach(i=>{i.steps.forEach(r=>{t.step(r)})}),t}function IC(n){for(let e=0;e<n.edgeCount;e+=1){const{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function LC(n,e,t){const i=[];return n.nodesBetween(e.from,e.to,(r,s)=>{t(r)&&i.push({node:r,pos:s})}),i}function uy(n,e){for(let t=n.depth;t>0;t-=1){const i=n.node(t);if(e(i))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:i}}}function da(n){return e=>uy(e.$from,n)}function H(n,e,t){return n.config[e]===void 0&&n.parent?H(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?H(n.parent,e,t):null}):n.config[e]}function pa(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},i=H(e,"addExtensions",t);return i?[e,...pa(i())]:e}).flat(10)}function Pu(n,e){const t=Bi.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function fy(n){return typeof n=="function"}function re(n,e=void 0,...t){return fy(n)?e?n.bind(e)(...t):n(...t):n}function PC(n={}){return Object.keys(n).length===0&&n.constructor===Object}function fr(n){const e=n.filter(r=>r.type==="extension"),t=n.filter(r=>r.type==="node"),i=n.filter(r=>r.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:i}}function dy(n){const e=[],{nodeExtensions:t,markExtensions:i}=fr(n),r=[...t,...i],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=t.filter(c=>c.name!=="text").map(c=>c.name),l=i.map(c=>c.name),a=[...o,...l];return n.forEach(c=>{const h={name:c.name,options:c.options,storage:c.storage,extensions:r},u=H(c,"addGlobalAttributes",h);if(!u)return;u().forEach(d=>{let p;Array.isArray(d.types)?p=d.types:d.types==="*"?p=a:d.types==="nodes"?p=o:d.types==="marks"?p=l:p=[],p.forEach(m=>{Object.entries(d.attributes).forEach(([g,y])=>{e.push({type:m,name:g,attribute:{...s,...y}})})})})}),r.forEach(c=>{const h={name:c.name,options:c.options,storage:c.storage},u=H(c,"addAttributes",h);if(!u)return;const f=u();Object.entries(f).forEach(([d,p])=>{const m={...s,...p};typeof m?.default=="function"&&(m.default=m.default()),m?.isRequired&&m?.default===void 0&&delete m.default,e.push({type:c.name,name:d,attribute:m})})}),e}function pe(...n){return n.filter(e=>!!e).reduce((e,t)=>{const i={...e};return Object.entries(t).forEach(([r,s])=>{if(!i[r]){i[r]=s;return}if(r==="class"){const l=s?String(s).split(" "):[],a=i[r]?i[r].split(" "):[],c=l.filter(h=>!a.includes(h));i[r]=[...a,...c].join(" ")}else if(r==="style"){const l=s?s.split(";").map(h=>h.trim()).filter(Boolean):[],a=i[r]?i[r].split(";").map(h=>h.trim()).filter(Boolean):[],c=new Map;a.forEach(h=>{const[u,f]=h.split(":").map(d=>d.trim());c.set(u,f)}),l.forEach(h=>{const[u,f]=h.split(":").map(d=>d.trim());c.set(u,f)}),i[r]=Array.from(c.entries()).map(([h,u])=>`${h}: ${u}`).join("; ")}else i[r]=s}),i},{})}function ws(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,i)=>pe(t,i),{})}function BC(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function Gd(n,e){return"style"in n?n:{...n,getAttrs:t=>{const i=n.getAttrs?n.getAttrs(t):n.attrs;if(i===!1)return!1;const r=e.reduce((s,o)=>{const l=o.attribute.parseHTML?o.attribute.parseHTML(t):BC(t.getAttribute(o.name));return l==null?s:{...s,[o.name]:l}},{});return{...i,...r}}}}function Yd(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&PC(t)?!1:t!=null))}function Xd(n){var e,t;const i={};return!((e=n?.attribute)!=null&&e.isRequired)&&"default"in(n?.attribute||{})&&(i.default=n.attribute.default),((t=n?.attribute)==null?void 0:t.validate)!==void 0&&(i.validate=n.attribute.validate),[n.name,i]}function py(n,e){var t;const i=dy(n),{nodeExtensions:r,markExtensions:s}=fr(n),o=(t=r.find(c=>H(c,"topNode")))==null?void 0:t.name,l=Object.fromEntries(r.map(c=>{const h=i.filter(y=>y.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((y,b)=>{const x=H(b,"extendNodeSchema",u);return{...y,...x?x(c):{}}},{}),d=Yd({...f,content:re(H(c,"content",u)),marks:re(H(c,"marks",u)),group:re(H(c,"group",u)),inline:re(H(c,"inline",u)),atom:re(H(c,"atom",u)),selectable:re(H(c,"selectable",u)),draggable:re(H(c,"draggable",u)),code:re(H(c,"code",u)),whitespace:re(H(c,"whitespace",u)),linebreakReplacement:re(H(c,"linebreakReplacement",u)),defining:re(H(c,"defining",u)),isolating:re(H(c,"isolating",u)),attrs:Object.fromEntries(h.map(Xd))}),p=re(H(c,"parseHTML",u));p&&(d.parseDOM=p.map(y=>Gd(y,h)));const m=H(c,"renderHTML",u);m&&(d.toDOM=y=>m({node:y,HTMLAttributes:ws(y,h)}));const g=H(c,"renderText",u);return g&&(d.toText=g),[c.name,d]})),a=Object.fromEntries(s.map(c=>{const h=i.filter(g=>g.type===c.name),u={name:c.name,options:c.options,storage:c.storage,editor:e},f=n.reduce((g,y)=>{const b=H(y,"extendMarkSchema",u);return{...g,...b?b(c):{}}},{}),d=Yd({...f,inclusive:re(H(c,"inclusive",u)),excludes:re(H(c,"excludes",u)),group:re(H(c,"group",u)),spanning:re(H(c,"spanning",u)),code:re(H(c,"code",u)),attrs:Object.fromEntries(h.map(Xd))}),p=re(H(c,"parseHTML",u));p&&(d.parseDOM=p.map(g=>Gd(g,h)));const m=H(c,"renderHTML",u);return m&&(d.toDOM=g=>m({mark:g,HTMLAttributes:ws(g,h)})),[c.name,d]}));return new _g({topNode:o,nodes:l,marks:a})}function zC(n){const e=n.filter((t,i)=>n.indexOf(t)!==i);return Array.from(new Set(e))}function Qr(n){return n.sort((t,i)=>{const r=H(t,"priority")||100,s=H(i,"priority")||100;return r>s?-1:r<s?1:0})}function Bu(n){const e=Qr(pa(n)),t=zC(e.map(i=>i.name));return t.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${t.map(i=>`'${i}'`).join(", ")}]. This can lead to issues.`),e}function HC(n,e){const t=Bu(n);return py(t,e)}function FC(n,e){const t=HC(e),i=Wr(n);return Sn.fromSchema(t).parse(i).toJSON()}function my(n,e,t){const{from:i,to:r}=e,{blockSeparator:s=`
12
+
13
+ `,textSerializers:o={}}=t||{};let l="";return n.nodesBetween(i,r,(a,c,h,u)=>{var f;a.isBlock&&c>i&&(l+=s);const d=o?.[a.type.name];if(d)return h&&(l+=d({node:a,pos:c,parent:h,index:u,range:e})),!1;a.isText&&(l+=(f=a?.text)==null?void 0:f.slice(Math.max(i,c)-c,r-c))}),l}function gy(n,e){const t={from:0,to:n.content.size};return my(n,t,e)}function zu(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function $C(n,e){const t=Ae(e,n.schema),{from:i,to:r}=n.selection,s=[];n.doc.nodesBetween(i,r,l=>{s.push(l)});const o=s.reverse().find(l=>l.type.name===t.name);return o?{...o.attrs}:{}}function yy(n,e){const t=fa(typeof e=="string"?e:e.name,n.schema);return t==="node"?$C(n,e):t==="mark"?cy(n,e):{}}function VC(n,e=JSON.stringify){const t={};return n.filter(i=>{const r=e(i);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function WC(n){const e=VC(n);return e.length===1?e:e.filter((t,i)=>!e.filter((s,o)=>o!==i).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function by(n){const{mapping:e,steps:t}=n,i=[];return e.maps.forEach((r,s)=>{const o=[];if(r.ranges.length)r.forEach((l,a)=>{o.push({from:l,to:a})});else{const{from:l,to:a}=t[s];if(l===void 0||a===void 0)return;o.push({from:l,to:a})}o.forEach(({from:l,to:a})=>{const c=e.slice(s).map(l,-1),h=e.slice(s).map(a),u=e.invert().map(c,-1),f=e.invert().map(h);i.push({oldRange:{from:u,to:f},newRange:{from:c,to:h}})})}),WC(i)}function Hu(n,e,t){const i=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),o=Iu(s,r.type);o&&i.push({mark:r,...o})}):t.nodesBetween(n,e,(r,s)=>{!r||r?.nodeSize===void 0||i.push(...r.marks.map(o=>({from:s,to:s+r.nodeSize,mark:o})))}),i}var jC=(n,e,t,i=20)=>{const r=n.doc.resolve(t);let s=i,o=null;for(;s>0&&o===null;){const l=r.node(s);l?.type.name===e?o=l:s-=1}return[o,s]};function Or(n,e){return e.nodes[n]||e.marks[n]||null}function Po(n,e,t){return Object.fromEntries(Object.entries(t).filter(([i])=>{const r=n.find(s=>s.type===e&&s.name===i);return r?r.attribute.keepOnSplit:!1}))}var _C=(n,e=500)=>{let t="";const i=n.parentOffset;return n.parent.nodesBetween(Math.max(0,i-e),i,(r,s,o,l)=>{var a,c;const h=((c=(a=r.type.spec).toText)==null?void 0:c.call(a,{node:r,pos:s,parent:o,index:l}))||r.textContent||"%leaf%";t+=r.isAtom&&!r.isText?h:h.slice(0,Math.max(0,i-s))}),t};function nh(n,e,t={}){const{empty:i,ranges:r}=n.selection,s=e?Dn(e,n.schema):null;if(i)return!!(n.storedMarks||n.selection.$from.marks()).filter(u=>s?s.name===u.type.name:!0).find(u=>tl(u.attrs,t,{strict:!1}));let o=0;const l=[];if(r.forEach(({$from:u,$to:f})=>{const d=u.pos,p=f.pos;n.doc.nodesBetween(d,p,(m,g)=>{if(s&&m.inlineContent&&!m.type.allowsMarkType(s))return!1;if(!m.isText&&!m.marks.length)return;const y=Math.max(d,g),b=Math.min(p,g+m.nodeSize),x=b-y;o+=x,l.push(...m.marks.map(k=>({mark:k,from:y,to:b})))})}),o===0)return!1;const a=l.filter(u=>s?s.name===u.mark.type.name:!0).filter(u=>tl(u.mark.attrs,t,{strict:!1})).reduce((u,f)=>u+f.to-f.from,0),c=l.filter(u=>s?u.mark.type!==s&&u.mark.type.excludes(s):!0).reduce((u,f)=>u+f.to-f.from,0);return(a>0?a+c:a)>=o}function UC(n,e,t={}){if(!e)return Zn(n,null,t)||nh(n,null,t);const i=fa(e,n.schema);return i==="node"?Zn(n,e,t):i==="mark"?nh(n,e,t):!1}var qC=(n,e)=>{const{$from:t,$to:i,$anchor:r}=n.selection;if(e){const s=da(l=>l.type.name===e)(n.selection);if(!s)return!1;const o=n.doc.resolve(s.pos+1);return r.pos+1===o.end()}return!(i.parentOffset<i.parent.nodeSize-2||t.pos!==i.pos)},KC=n=>{const{$from:e,$to:t}=n.selection;return!(e.parentOffset>0||e.pos!==t.pos)};function Qd(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Zd(n,e){const{nodeExtensions:t}=fr(e),i=t.find(o=>o.name===n);if(!i)return!1;const r={name:i.name,options:i.options,storage:i.storage},s=re(H(i,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function ma(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var i;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((i=n.text)!=null?i:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let r=!0;return n.content.forEach(s=>{r!==!1&&(ma(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function xy(n){return n instanceof W}var wy=class ky{constructor(e){this.position=e}static fromJSON(e){return new ky(e.position)}toJSON(){return{position:this.position}}};function JC(n,e){const t=e.mapping.mapResult(n.position);return{position:new wy(t.pos),mapResult:t}}function GC(n){return new wy(n)}function vy(n,e,t){const r=n.state.doc.content.size,s=vn(e,0,r),o=vn(t,0,r),l=n.coordsAtPos(s),a=n.coordsAtPos(o,-1),c=Math.min(l.top,a.top),h=Math.max(l.bottom,a.bottom),u=Math.min(l.left,a.left),f=Math.max(l.right,a.right),d=f-u,p=h-c,y={top:c,bottom:h,left:u,right:f,width:d,height:p,x:u,y:c};return{...y,toJSON:()=>y}}function YC(n,e,t){var i;const{selection:r}=e;let s=null;if(Lu(r)&&(s=r.$cursor),s){const l=(i=n.storedMarks)!=null?i:s.marks();return s.parent.type.allowsMarkType(t)&&(!!t.isInSet(l)||!l.some(c=>c.type.excludes(t)))}const{ranges:o}=r;return o.some(({$from:l,$to:a})=>{let c=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(h,u,f)=>{if(c)return!1;if(h.isInline){const d=!f||f.type.allowsMarkType(t),p=!!t.isInSet(h.marks)||!h.marks.some(m=>m.type.excludes(t));c=d&&p}return!c}),c})}var XC=(n,e={})=>({tr:t,state:i,dispatch:r})=>{const{selection:s}=t,{empty:o,ranges:l}=s,a=Dn(n,i.schema);if(r)if(o){const c=cy(i,a);t.addStoredMark(a.create({...c,...e}))}else l.forEach(c=>{const h=c.$from.pos,u=c.$to.pos;i.doc.nodesBetween(h,u,(f,d)=>{const p=Math.max(d,h),m=Math.min(d+f.nodeSize,u);f.marks.find(y=>y.type===a)?f.marks.forEach(y=>{a===y.type&&t.addMark(p,m,a.create({...y.attrs,...e}))}):t.addMark(p,m,a.create(e))})});return YC(i,t,a)},QC=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),ZC=(n,e={})=>({state:t,dispatch:i,chain:r})=>{const s=Ae(n,t.schema);let o;return t.selection.$anchor.sameParent(t.selection.$head)&&(o=t.selection.$anchor.parent.attrs),s.isTextblock?r().command(({commands:l})=>ud(s,{...o,...e})(t)?!0:l.clearNodes()).command(({state:l})=>ud(s,{...o,...e})(l,i)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},eM=n=>({tr:e,dispatch:t})=>{if(t){const{doc:i}=e,r=vn(n,0,i.content.size),s=W.create(i,r);e.setSelection(s)}return!0},tM=(n,e)=>({tr:t,state:i,dispatch:r})=>{const{selection:s}=i;let o,l;return typeof e=="number"?(o=e,l=e):e&&"from"in e&&"to"in e?(o=e.from,l=e.to):(o=s.from,l=s.to),r&&t.doc.nodesBetween(o,l,(a,c)=>{a.isText||t.setNodeMarkup(c,void 0,{...a.attrs,dir:n})}),!0},nM=n=>({tr:e,dispatch:t})=>{if(t){const{doc:i}=e,{from:r,to:s}=typeof n=="number"?{from:n,to:n}:n,o=_.atStart(i).from,l=_.atEnd(i).to,a=vn(r,o,l),c=vn(s,o,l),h=_.create(i,a,c);e.setSelection(h)}return!0},iM=n=>({state:e,dispatch:t})=>{const i=Ae(n,e.schema);return Xk(i)(e,t)};function ep(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const i=t.filter(r=>e?.includes(r.type.name));n.tr.ensureMarks(i)}}var rM=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:i,editor:r})=>{const{selection:s,doc:o}=e,{$from:l,$to:a}=s,c=r.extensionManager.attributes,h=Po(c,l.node().type.name,l.node().attrs);if(s instanceof W&&s.node.isBlock)return!l.parentOffset||!Cn(o,l.pos)?!1:(i&&(n&&ep(t,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const u=a.parentOffset===a.parent.content.size,f=l.depth===0?void 0:IC(l.node(-1).contentMatchAt(l.indexAfter(-1)));let d=u&&f?[{type:f,attrs:h}]:void 0,p=Cn(e.doc,e.mapping.map(l.pos),1,d);if(!d&&!p&&Cn(e.doc,e.mapping.map(l.pos),1,f?[{type:f}]:void 0)&&(p=!0,d=f?[{type:f,attrs:h}]:void 0),i){if(p&&(s instanceof _&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,d),f&&!u&&!l.parentOffset&&l.parent.type!==f)){const m=e.mapping.map(l.before()),g=e.doc.resolve(m);l.node(-1).canReplaceWith(g.index(),g.index()+1,f)&&e.setNodeMarkup(e.mapping.map(l.before()),f)}n&&ep(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return p},sM=(n,e={})=>({tr:t,state:i,dispatch:r,editor:s})=>{var o;const l=Ae(n,i.schema),{$from:a,$to:c}=i.selection,h=i.selection.node;if(h&&h.isBlock||a.depth<2||!a.sameParent(c))return!1;const u=a.node(-1);if(u.type!==l)return!1;const f=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let y=A.empty;const b=a.index(-1)?1:a.index(-2)?2:3;for(let D=a.depth-b;D>=a.depth-3;D-=1)y=A.from(a.node(D).copy(y));const x=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,k={...Po(f,a.node().type.name,a.node().attrs),...e},w=((o=l.contentMatch.defaultType)==null?void 0:o.createAndFill(k))||void 0;y=y.append(A.from(l.createAndFill(null,w)||void 0));const C=a.before(a.depth-(b-1));t.replace(C,a.after(-x),new I(y,4-b,0));let v=-1;t.doc.nodesBetween(C,t.doc.content.size,(D,L)=>{if(v>-1)return!1;D.isTextblock&&D.content.size===0&&(v=L+1)}),v>-1&&t.setSelection(_.near(t.doc.resolve(v))),t.scrollIntoView()}return!0}const d=c.pos===a.end()?u.contentMatchAt(0).defaultType:null,p={...Po(f,u.type.name,u.attrs),...e},m={...Po(f,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,c.pos);const g=d?[{type:l,attrs:p},{type:d,attrs:m}]:[{type:l,attrs:p}];if(!Cn(t.doc,a.pos,2))return!1;if(r){const{selection:y,storedMarks:b}=i,{splittableMarks:x}=s.extensionManager,k=b||y.$to.parentOffset&&y.$from.marks();if(t.split(a.pos,2,g).scrollIntoView(),!k||!r)return!0;const w=k.filter(C=>x.includes(C.type.name));t.ensureMarks(w)}return!0},Za=(n,e)=>{const t=da(o=>o.type===e)(n.selection);if(!t)return!0;const i=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(i===void 0)return!0;const r=n.doc.nodeAt(i);return t.node.type===r?.type&&si(n.doc,t.pos)&&n.join(t.pos),!0},ec=(n,e)=>{const t=da(o=>o.type===e)(n.selection);if(!t)return!0;const i=n.doc.resolve(t.start).after(t.depth);if(i===void 0)return!0;const r=n.doc.nodeAt(i);return t.node.type===r?.type&&si(n.doc,i)&&n.join(i),!0},oM=(n,e,t,i={})=>({editor:r,tr:s,state:o,dispatch:l,chain:a,commands:c,can:h})=>{const{extensions:u,splittableMarks:f}=r.extensionManager,d=Ae(n,o.schema),p=Ae(e,o.schema),{selection:m,storedMarks:g}=o,{$from:y,$to:b}=m,x=y.blockRange(b),k=g||m.$to.parentOffset&&m.$from.marks();if(!x)return!1;const w=da(C=>Zd(C.type.name,u))(m);if(x.depth>=1&&w&&x.depth-w.depth<=1){if(w.node.type===d)return c.liftListItem(p);if(Zd(w.node.type.name,u)&&d.validContent(w.node.content)&&l)return a().command(()=>(s.setNodeMarkup(w.pos,d),!0)).command(()=>Za(s,d)).command(()=>ec(s,d)).run()}return!t||!k||!l?a().command(()=>h().wrapInList(d,i)?!0:c.clearNodes()).wrapInList(d,i).command(()=>Za(s,d)).command(()=>ec(s,d)).run():a().command(()=>{const C=h().wrapInList(d,i),v=k.filter(D=>f.includes(D.type.name));return s.ensureMarks(v),C?!0:c.clearNodes()}).wrapInList(d,i).command(()=>Za(s,d)).command(()=>ec(s,d)).run()},lM=(n,e={},t={})=>({state:i,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,o=Dn(n,i.schema);return nh(i,o,e)?r.unsetMark(o,{extendEmptyMarkRange:s}):r.setMark(o,e)},aM=(n,e,t={})=>({state:i,commands:r})=>{const s=Ae(n,i.schema),o=Ae(e,i.schema),l=Zn(i,s,t);let a;return i.selection.$anchor.sameParent(i.selection.$head)&&(a=i.selection.$anchor.parent.attrs),l?r.setNode(o,a):r.setNode(s,{...a,...t})},cM=(n,e={})=>({state:t,commands:i})=>{const r=Ae(n,t.schema);return Zn(t,r,e)?i.lift(r):i.wrapIn(r,e)},hM=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let i=0;i<t.length;i+=1){const r=t[i];let s;if(r.spec.isInputRules&&(s=r.getState(n))){if(e){const o=n.tr,l=s.transform;for(let a=l.steps.length-1;a>=0;a-=1)o.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,a))}else o.delete(s.from,s.to)}return!0}}return!1},uM=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:i,ranges:r}=t;return i||e&&r.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},fM=(n,e={})=>({tr:t,state:i,dispatch:r})=>{var s;const{extendEmptyMarkRange:o=!1}=e,{selection:l}=t,a=Dn(n,i.schema),{$from:c,empty:h,ranges:u}=l;if(!r)return!0;if(h&&o){let{from:f,to:d}=l;const p=(s=c.marks().find(g=>g.type===a))==null?void 0:s.attrs,m=Iu(c,a,p);m&&(f=m.from,d=m.to),t.removeMark(f,d,a)}else u.forEach(f=>{t.removeMark(f.$from.pos,f.$to.pos,a)});return t.removeStoredMark(a),!0},dM=n=>({tr:e,state:t,dispatch:i})=>{const{selection:r}=t;let s,o;return typeof n=="number"?(s=n,o=n):n&&"from"in n&&"to"in n?(s=n.from,o=n.to):(s=r.from,o=r.to),i&&e.doc.nodesBetween(s,o,(l,a)=>{if(l.isText)return;const c={...l.attrs};delete c.dir,e.setNodeMarkup(a,void 0,c)}),!0},pM=(n,e={})=>({tr:t,state:i,dispatch:r})=>{let s=null,o=null;const l=fa(typeof n=="string"?n:n.name,i.schema);if(!l)return!1;l==="node"&&(s=Ae(n,i.schema)),l==="mark"&&(o=Dn(n,i.schema));let a=!1;return t.selection.ranges.forEach(c=>{const h=c.$from.pos,u=c.$to.pos;let f,d,p,m;t.selection.empty?i.doc.nodesBetween(h,u,(g,y)=>{s&&s===g.type&&(a=!0,p=Math.max(y,h),m=Math.min(y+g.nodeSize,u),f=y,d=g)}):i.doc.nodesBetween(h,u,(g,y)=>{y<h&&s&&s===g.type&&(a=!0,p=Math.max(y,h),m=Math.min(y+g.nodeSize,u),f=y,d=g),y>=h&&y<=u&&(s&&s===g.type&&(a=!0,r&&t.setNodeMarkup(y,void 0,{...g.attrs,...e})),o&&g.marks.length&&g.marks.forEach(b=>{if(o===b.type&&(a=!0,r)){const x=Math.max(y,h),k=Math.min(y+g.nodeSize,u);t.addMark(x,k,o.create({...b.attrs,...e}))}}))}),d&&(f!==void 0&&r&&t.setNodeMarkup(f,void 0,{...d.attrs,...e}),o&&d.marks.length&&d.marks.forEach(g=>{o===g.type&&r&&t.addMark(p,m,o.create({...g.attrs,...e}))}))}),a},mM=(n,e={})=>({state:t,dispatch:i})=>{const r=Ae(n,t.schema);return _k(r,e)(t,i)},gM=(n,e={})=>({state:t,dispatch:i})=>{const r=Ae(n,t.schema);return Uk(r,e)(t,i)},yM=class{constructor(){this.callbacks={}}on(n,e){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(e),this}emit(n,...e){const t=this.callbacks[n];return t&&t.forEach(i=>i.apply(this,e)),this}off(n,e){const t=this.callbacks[n];return t&&(e?this.callbacks[n]=t.filter(i=>i!==e):delete this.callbacks[n]),this}once(n,e){const t=(...i)=>{this.off(n,t),e.apply(this,i)};return this.on(n,t)}removeAllListeners(){this.callbacks={}}},ga=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},bM=(n,e)=>{if(Nu(e))return e.exec(n);const t=e(n);if(!t)return null;const i=[t.text];return i.index=t.index,i.input=n,i.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),i.push(t.replaceWith)),i};function Qs(n){var e;const{editor:t,from:i,to:r,text:s,rules:o,plugin:l}=n,{view:a}=t;if(a.composing)return!1;const c=a.state.doc.resolve(i);if(c.parent.type.spec.code||(e=c.nodeBefore||c.nodeAfter)!=null&&e.marks.find(f=>f.type.spec.code))return!1;let h=!1;const u=_C(c)+s;return o.forEach(f=>{if(h)return;const d=bM(u,f.find);if(!d)return;const p=a.state.tr,m=ha({state:a.state,transaction:p}),g={from:i-(d[0].length-s.length),to:r},{commands:y,chain:b,can:x}=new ua({editor:t,state:m});f.handler({state:m,range:g,match:d,commands:y,chain:b,can:x})===null||!p.steps.length||(f.undoable&&p.setMeta(l,{transform:p,from:i,to:r,text:s}),a.dispatch(p),h=!0)}),h}function xM(n){const{editor:e,rules:t}=n,i=new se({state:{init(){return null},apply(r,s,o){const l=r.getMeta(i);if(l)return l;const a=r.getMeta("applyInputRules");return a&&setTimeout(()=>{let{text:h}=a;typeof h=="string"?h=h:h=Pu(A.from(h),o.schema);const{from:u}=a,f=u+h.length;Qs({editor:e,from:u,to:f,text:h,rules:t,plugin:i})}),r.selectionSet||r.docChanged?null:s}},props:{handleTextInput(r,s,o,l){return Qs({editor:e,from:s,to:o,text:l,rules:t,plugin:i})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&Qs({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:i})}),!1)},handleKeyDown(r,s){if(s.key!=="Enter")return!1;const{$cursor:o}=r.state.selection;return o?Qs({editor:e,from:o.pos,to:o.pos,text:`
14
+ `,rules:t,plugin:i}):!1}},isInputRules:!0});return i}function wM(n){return Object.prototype.toString.call(n).slice(8,-1)}function Zs(n){return wM(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Sy(n,e){const t={...n};return Zs(n)&&Zs(e)&&Object.keys(e).forEach(i=>{Zs(e[i])&&Zs(n[i])?t[i]=Sy(n[i],e[i]):t[i]=e[i]}),t}var Fu=class{constructor(n={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...n},this.name=this.config.name}get options(){return{...re(H(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...re(H(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Sy(this.options,n)});return e.name=this.name,e.parent=this.parent,e}extend(n={}){const e=new this.constructor({...this.config,...n});return e.parent=this,this.child=e,e.name="name"in n?n.name:e.parent.name,e}},zi=class Cy extends Fu{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new Cy(t)}static handleExit({editor:e,mark:t}){const{tr:i}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){const o=r.marks();if(!!!o.find(c=>c?.type.name===t.name))return!1;const a=o.find(c=>c?.type.name===t.name);return a&&i.removeStoredMark(a),i.insertText(" ",r.pos),e.view.dispatch(i),!0}return!1}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function kM(n){return typeof n=="number"}var vM=class{constructor(n){this.find=n.find,this.handler=n.handler}},SM=(n,e,t)=>{if(Nu(e))return[...n.matchAll(e)];const i=e(n,t);return i?i.map(r=>{const s=[r.text];return s.index=r.index,s.input=n,s.data=r.data,r.replaceWith&&(r.text.includes(r.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(r.replaceWith)),s}):[]};function CM(n){const{editor:e,state:t,from:i,to:r,rule:s,pasteEvent:o,dropEvent:l}=n,{commands:a,chain:c,can:h}=new ua({editor:e,state:t}),u=[];return t.doc.nodesBetween(i,r,(d,p)=>{var m,g,y,b,x;if((g=(m=d.type)==null?void 0:m.spec)!=null&&g.code||!(d.isText||d.isTextblock||d.isInline))return;const k=(x=(b=(y=d.content)==null?void 0:y.size)!=null?b:d.nodeSize)!=null?x:0,w=Math.max(i,p),C=Math.min(r,p+k);if(w>=C)return;const v=d.isText?d.text||"":d.textBetween(w-p,C-p,void 0,"");SM(v,s.find,o).forEach(L=>{if(L.index===void 0)return;const J=w+L.index+1,j=J+L[0].length,$={from:t.tr.mapping.map(J),to:t.tr.mapping.map(j)},te=s.handler({state:t,range:$,match:L,commands:a,chain:c,can:h,pasteEvent:o,dropEvent:l});u.push(te)})}),u.every(d=>d!==null)}var eo=null,MM=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function TM(n){const{editor:e,rules:t}=n;let i=null,r=!1,s=!1,o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const a=({state:h,from:u,to:f,rule:d,pasteEvt:p})=>{const m=h.tr,g=ha({state:h,transaction:m});if(!(!CM({editor:e,state:g,from:Math.max(u-1,0),to:f.b-1,rule:d,pasteEvent:p,dropEvent:l})||!m.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return o=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,m}};return t.map(h=>new se({view(u){const f=p=>{var m;i=(m=u.dom.parentElement)!=null&&m.contains(p.target)?u.dom.parentElement:null,i&&(eo=e)},d=()=>{eo&&(eo=null)};return window.addEventListener("dragstart",f),window.addEventListener("dragend",d),{destroy(){window.removeEventListener("dragstart",f),window.removeEventListener("dragend",d)}}},props:{handleDOMEvents:{drop:(u,f)=>{if(s=i===u.dom.parentElement,l=f,!s){const d=eo;d?.isEditable&&setTimeout(()=>{const p=d.state.selection;p&&d.commands.deleteRange({from:p.from,to:p.to})},10)}return!1},paste:(u,f)=>{var d;const p=(d=f.clipboardData)==null?void 0:d.getData("text/html");return o=f,r=!!p?.includes("data-pm-slice"),!1}}},appendTransaction:(u,f,d)=>{const p=u[0],m=p.getMeta("uiEvent")==="paste"&&!r,g=p.getMeta("uiEvent")==="drop"&&!s,y=p.getMeta("applyPasteRules"),b=!!y;if(!m&&!g&&!b)return;if(b){let{text:w}=y;typeof w=="string"?w=w:w=Pu(A.from(w),d.schema);const{from:C}=y,v=C+w.length,D=MM(w);return a({rule:h,state:d,from:C,to:{b:v},pasteEvt:D})}const x=f.doc.content.findDiffStart(d.doc.content),k=f.doc.content.findDiffEnd(d.doc.content);if(!(!kM(x)||!k||x===k.b))return a({rule:h,state:d,from:x,to:k,pasteEvt:o})}}))}var ya=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Bu(n),this.schema=py(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((n,e)=>{const t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Or(e.name,this.schema)},i=H(e,"addCommands",t);return i?{...n,...i()}:n},{})}get plugins(){const{editor:n}=this;return Qr([...this.extensions].reverse()).flatMap(i=>{const r={name:i.name,options:i.options,storage:this.editor.extensionStorage[i.name],editor:n,type:Or(i.name,this.schema)},s=[],o=H(i,"addKeyboardShortcuts",r);let l={};if(i.type==="mark"&&H(i,"exitable",r)&&(l.ArrowRight=()=>zi.handleExit({editor:n,mark:i})),o){const f=Object.fromEntries(Object.entries(o()).map(([d,p])=>[d,()=>p({editor:n})]));l={...l,...f}}const a=VS(l);s.push(a);const c=H(i,"addInputRules",r);if(Qd(i,n.options.enableInputRules)&&c){const f=c();if(f&&f.length){const d=xM({editor:n,rules:f}),p=Array.isArray(d)?d:[d];s.push(...p)}}const h=H(i,"addPasteRules",r);if(Qd(i,n.options.enablePasteRules)&&h){const f=h();if(f&&f.length){const d=TM({editor:n,rules:f});s.push(...d)}}const u=H(i,"addProseMirrorPlugins",r);if(u){const f=u();s.push(...f)}return s})}get attributes(){return dy(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=fr(this.extensions);return Object.fromEntries(e.filter(t=>!!H(t,"addNodeView")).map(t=>{const i=this.attributes.filter(a=>a.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Ae(t.name,this.schema)},s=H(t,"addNodeView",r);if(!s)return[];const o=s();if(!o)return[];const l=(a,c,h,u,f)=>{const d=ws(a,i);return o({node:a,view:c,getPos:h,decorations:u,innerDecorations:f,editor:n,extension:t,HTMLAttributes:d})};return[t.name,l]}))}dispatchTransaction(n){const{editor:e}=this;return Qr([...this.extensions].reverse()).reduceRight((i,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Or(r.name,this.schema)},o=H(r,"dispatchTransaction",s);return o?l=>{o.call(s,{transaction:l,next:i})}:i},n)}transformPastedHTML(n){const{editor:e}=this;return Qr([...this.extensions]).reduce((i,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Or(r.name,this.schema)},o=H(r,"transformPastedHTML",s);return o?(l,a)=>{const c=i(l,a);return o.call(s,c)}:i},n||(i=>i))}get markViews(){const{editor:n}=this,{markExtensions:e}=fr(this.extensions);return Object.fromEntries(e.filter(t=>!!H(t,"addMarkView")).map(t=>{const i=this.attributes.filter(l=>l.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Dn(t.name,this.schema)},s=H(t,"addMarkView",r);if(!s)return[];const o=(l,a,c)=>{const h=ws(l,i);return s()({mark:l,view:a,inline:c,editor:n,extension:t,HTMLAttributes:h,updateAttributes:u=>{VM(l,n,u)}})};return[t.name,o]}))}setupExtensions(){const n=this.extensions;this.editor.extensionStorage=Object.fromEntries(n.map(e=>[e.name,e.storage])),n.forEach(e=>{var t;const i={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Or(e.name,this.schema)};e.type==="mark"&&((t=re(H(e,"keepOnSplit",i)))==null||t)&&this.splittableMarks.push(e.name);const r=H(e,"onBeforeCreate",i),s=H(e,"onCreate",i),o=H(e,"onUpdate",i),l=H(e,"onSelectionUpdate",i),a=H(e,"onTransaction",i),c=H(e,"onFocus",i),h=H(e,"onBlur",i),u=H(e,"onDestroy",i);r&&this.editor.on("beforeCreate",r),s&&this.editor.on("create",s),o&&this.editor.on("update",o),l&&this.editor.on("selectionUpdate",l),a&&this.editor.on("transaction",a),c&&this.editor.on("focus",c),h&&this.editor.on("blur",h),u&&this.editor.on("destroy",u)})}};ya.resolve=Bu;ya.sort=Qr;ya.flatten=pa;var AM={};Du(AM,{ClipboardTextSerializer:()=>Ty,Commands:()=>Ay,Delete:()=>Ey,Drop:()=>Oy,Editable:()=>Ry,FocusEvents:()=>Ny,Keymap:()=>Iy,Paste:()=>Ly,Tabindex:()=>Py,TextDirection:()=>By,focusEventsPluginKey:()=>Dy});var fe=class My extends Fu{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new My(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},Ty=fe.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new se({key:new me("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:i,selection:r}=e,{ranges:s}=r,o=Math.min(...s.map(h=>h.$from.pos)),l=Math.max(...s.map(h=>h.$to.pos)),a=zu(t);return my(i,{from:o,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),Ay=fe.create({name:"commands",addCommands(){return{...Bt}}}),Ey=fe.create({name:"delete",onUpdate({transaction:n,appendedTransactions:e}){var t,i,r;const s=()=>{var o,l,a,c;if((c=(a=(l=(o=this.editor.options.coreExtensionOptions)==null?void 0:o.delete)==null?void 0:l.filterTransaction)==null?void 0:a.call(l,n))!=null?c:n.getMeta("y-sync$"))return;const h=hy(n.before,[n,...e]);by(h).forEach(d=>{h.mapping.mapResult(d.oldRange.from).deletedAfter&&h.mapping.mapResult(d.oldRange.to).deletedBefore&&h.before.nodesBetween(d.oldRange.from,d.oldRange.to,(p,m)=>{const g=m+p.nodeSize-2,y=d.oldRange.from<=m&&g<=d.oldRange.to;this.editor.emit("delete",{type:"node",node:p,from:m,to:g,newFrom:h.mapping.map(m),newTo:h.mapping.map(g),deletedRange:d.oldRange,newRange:d.newRange,partial:!y,editor:this.editor,transaction:n,combinedTransform:h})})});const f=h.mapping;h.steps.forEach((d,p)=>{var m,g;if(d instanceof Ft){const y=f.slice(p).map(d.from,-1),b=f.slice(p).map(d.to),x=f.invert().map(y,-1),k=f.invert().map(b),w=(m=h.doc.nodeAt(y-1))==null?void 0:m.marks.some(v=>v.eq(d.mark)),C=(g=h.doc.nodeAt(b))==null?void 0:g.marks.some(v=>v.eq(d.mark));this.editor.emit("delete",{type:"mark",mark:d.mark,from:d.from,to:d.to,deletedRange:{from:x,to:k},newRange:{from:y,to:b},partial:!!(C||w),editor:this.editor,transaction:n,combinedTransform:h})}})};(r=(i=(t=this.editor.options.coreExtensionOptions)==null?void 0:t.delete)==null?void 0:i.async)==null||r?setTimeout(s,0):s()}}),Oy=fe.create({name:"drop",addProseMirrorPlugins(){return[new se({key:new me("tiptapDrop"),props:{handleDrop:(n,e,t,i)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:i})}}})]}}),Ry=fe.create({name:"editable",addProseMirrorPlugins(){return[new se({key:new me("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Dy=new me("focusEvents"),Ny=fe.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new se({key:Dy,props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const i=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(i),!1},blur:(e,t)=>{n.isFocused=!1;const i=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(i),!1}}}})]}}),Iy=fe.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:o})=>[()=>o.undoInputRule(),()=>o.command(({tr:l})=>{const{selection:a,doc:c}=l,{empty:h,$anchor:u}=a,{pos:f,parent:d}=u,p=u.parent.isTextblock&&f>0?l.doc.resolve(f-1):u,m=p.parent.type.spec.isolating,g=u.pos-u.parentOffset,y=m&&p.parent.childCount===1?g===u.pos:U.atStart(c).from===f;return!h||!d.type.isTextblock||d.textContent.length||!y||y&&u.parent.type.name==="paragraph"?!1:o.clearNodes()}),()=>o.deleteSelection(),()=>o.joinBackward(),()=>o.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:o})=>[()=>o.deleteSelection(),()=>o.deleteCurrentNode(),()=>o.joinForward(),()=>o.selectNodeForward()]),i={Enter:()=>this.editor.commands.first(({commands:o})=>[()=>o.newlineInCode(),()=>o.createParagraphNear(),()=>o.liftEmptyBlock(),()=>o.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},r={...i},s={...i,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return nl()||ay()?s:r},addProseMirrorPlugins(){return[new se({key:new me("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(m=>m.getMeta("composition")))return;const i=n.some(m=>m.docChanged)&&!e.doc.eq(t.doc),r=n.some(m=>m.getMeta("preventClearDocument"));if(!i||r)return;const{empty:s,from:o,to:l}=e.selection,a=U.atStart(e.doc).from,c=U.atEnd(e.doc).to;if(s||!(o===a&&l===c)||!ma(t.doc))return;const f=t.tr,d=ha({state:t,transaction:f}),{commands:p}=new ua({editor:this.editor,state:d});if(p.clearNodes(),!!f.steps.length)return f}})]}}),Ly=fe.create({name:"paste",addProseMirrorPlugins(){return[new se({key:new me("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),Py=fe.create({name:"tabindex",addProseMirrorPlugins(){return[new se({key:new me("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),By=fe.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=fr(this.extensions);return[{types:n.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const t=e.getAttribute("dir");return t&&(t==="ltr"||t==="rtl"||t==="auto")?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new se({key:new me("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),EM=class jr{constructor(e,t,i=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=i,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(e=this.actualDepth)!=null?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,i=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,i=this.to-1}this.editor.commands.insertContentAt({from:t,to:i},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?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new jr(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new jr(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new jr(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,i)=>{const r=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,o=t.isInline,l=this.pos+i+(s?0:1);if(l<0||l>this.resolvedPos.doc.nodeSize-2)return;const a=this.resolvedPos.doc.resolve(l);if(!r&&!o&&a.depth<=this.depth)return;const c=new jr(a,this.editor,r,r||o?t:null);r&&(c.actualDepth=this.depth+1),e.push(c)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let i=null,r=this.parent;for(;r&&!i;){if(r.node.type.name===e)if(Object.keys(t).length>0){const s=r.node.attrs,o=Object.keys(t);for(let l=0;l<o.length;l+=1){const a=o[l];if(s[a]!==t[a])break}}else i=r;r=r.parent}return i}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},i=!1){let r=[];if(!this.children||this.children.length===0)return r;const s=Object.keys(t);return this.children.forEach(o=>{i&&r.length>0||(o.node.type.name===e&&s.every(a=>t[a]===o.node.attrs[a])&&r.push(o),!(i&&r.length>0)&&(r=r.concat(o.querySelectorAll(e,t,i))))}),r}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},OM=`.ProseMirror {
15
+ position: relative;
16
+ }
17
+
18
+ .ProseMirror {
19
+ word-wrap: break-word;
20
+ white-space: pre-wrap;
21
+ white-space: break-spaces;
22
+ -webkit-font-variant-ligatures: none;
23
+ font-variant-ligatures: none;
24
+ font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
25
+ }
26
+
27
+ .ProseMirror [contenteditable="false"] {
28
+ white-space: normal;
29
+ }
30
+
31
+ .ProseMirror [contenteditable="false"] [contenteditable="true"] {
32
+ white-space: pre-wrap;
33
+ }
34
+
35
+ .ProseMirror pre {
36
+ white-space: pre-wrap;
37
+ }
38
+
39
+ img.ProseMirror-separator {
40
+ display: inline !important;
41
+ border: none !important;
42
+ margin: 0 !important;
43
+ width: 0 !important;
44
+ height: 0 !important;
45
+ }
46
+
47
+ .ProseMirror-gapcursor {
48
+ display: none;
49
+ pointer-events: none;
50
+ position: absolute;
51
+ margin: 0;
52
+ }
53
+
54
+ .ProseMirror-gapcursor:after {
55
+ content: "";
56
+ display: block;
57
+ position: absolute;
58
+ top: -2px;
59
+ width: 20px;
60
+ border-top: 1px solid black;
61
+ animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
62
+ }
63
+
64
+ @keyframes ProseMirror-cursor-blink {
65
+ to {
66
+ visibility: hidden;
67
+ }
68
+ }
69
+
70
+ .ProseMirror-hideselection *::selection {
71
+ background: transparent;
72
+ }
73
+
74
+ .ProseMirror-hideselection *::-moz-selection {
75
+ background: transparent;
76
+ }
77
+
78
+ .ProseMirror-hideselection * {
79
+ caret-color: transparent;
80
+ }
81
+
82
+ .ProseMirror-focused .ProseMirror-gapcursor {
83
+ display: block;
84
+ }`;function RM(n,e,t){const i=document.querySelector("style[data-tiptap-style]");if(i!==null)return i;const r=document.createElement("style");return e&&r.setAttribute("nonce",e),r.setAttribute("data-tiptap-style",""),r.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(r),r}var DM=class extends yM{constructor(n={}){super(),this.css=null,this.className="tiptap",this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<"u"?document.createElement("div"):null,content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:i})=>{throw i},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:JC,createMappablePosition:GC},this.setOptions(n),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("mount",this.options.onMount),this.on("unmount",this.options.onUnmount),this.on("contentError",this.options.onContentError),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:i,slice:r,moved:s})=>this.options.onDrop(i,r,s)),this.on("paste",({event:i,slice:r})=>this.options.onPaste(i,r)),this.on("delete",this.options.onDelete);const e=this.createDoc(),t=oy(e,this.options.autofocus);this.editorState=Dk.create({doc:e,schema:this.schema,selection:t||void 0}),this.options.element&&this.mount(this.options.element)}mount(n){if(typeof document>"u")throw new Error("[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.");this.createView(n),this.emit("mount",{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){const n=this.editorView.dom;n?.editor&&delete n.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove=="function"?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(n){console.warn("Failed to remove CSS element:",n)}this.css=null,this.emit("unmount",{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<"u"&&(this.css=RM(OM,this.options.injectNonce))}setOptions(n={}){this.options={...this.options,...n},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(n,e=!0){this.setOptions({editable:n}),e&&this.emit("update",{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:n=>{this.editorState=n},dispatch:n=>{this.dispatchTransaction(n)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(n,e)=>{if(this.editorView)return this.editorView[e];if(e==="state")return this.editorState;if(e in n)return Reflect.get(n,e);throw new Error(`[tiptap error]: The editor view is not available. Cannot access view['${e}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(n,e){const t=fy(e)?e(n,[...this.state.plugins]):[...this.state.plugins,n],i=this.state.reconfigure({plugins:t});return this.view.updateState(i),i}unregisterPlugin(n){if(this.isDestroyed)return;const e=this.state.plugins;let t=e;if([].concat(n).forEach(r=>{const s=typeof r=="string"?`${r}$`:r.key;t=t.filter(o=>!o.key.startsWith(s))}),e.length===t.length)return;const i=this.state.reconfigure({plugins:t});return this.view.updateState(i),i}createExtensionManager(){var n,e;const i=[...this.options.enableCoreExtensions?[Ry,Ty.configure({blockSeparator:(e=(n=this.options.coreExtensionOptions)==null?void 0:n.clipboardTextSerializer)==null?void 0:e.blockSeparator}),Ay,Ny,Iy,Py,Oy,Ly,Ey,By.configure({direction:this.options.textDirection})].filter(r=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[r.name]!==!1:!0):[],...this.options.extensions].filter(r=>["extension","node","mark"].includes(r?.type));this.extensionManager=new ya(i,this)}createCommandManager(){this.commandManager=new ua({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let n;try{n=th(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(e){if(!(e instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(e.message))throw e;this.emit("contentError",{editor:this,error:e,disableCollaboration:()=>{"collaboration"in this.storage&&typeof this.storage.collaboration=="object"&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(t=>t.name!=="collaboration"),this.createExtensionManager()}}),n=th(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return n}createView(n){const{editorProps:e,enableExtensionDispatchTransaction:t}=this.options,i=e.dispatchTransaction||this.dispatchTransaction.bind(this),r=t?this.extensionManager.dispatchTransaction(i):i,s=e.transformPastedHTML,o=this.extensionManager.transformPastedHTML(s);this.editorView=new iy(n,{...e,attributes:{role:"textbox",...e?.attributes},dispatchTransaction:r,transformPastedHTML:o,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});const l=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(l),this.prependClass(),this.injectCSS();const a=this.view.dom;a.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(n){this.isCapturingTransaction=!0,n(),this.isCapturingTransaction=!1;const e=this.capturedTransaction;return this.capturedTransaction=null,e}dispatchTransaction(n){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=n;return}n.steps.forEach(c=>{var h;return(h=this.capturedTransaction)==null?void 0:h.step(c)});return}const{state:e,transactions:t}=this.state.applyTransaction(n),i=!this.state.selection.eq(e.selection),r=t.includes(n),s=this.state;if(this.emit("beforeTransaction",{editor:this,transaction:n,nextState:e}),!r)return;this.view.updateState(e),this.emit("transaction",{editor:this,transaction:n,appendedTransactions:t.slice(1)}),i&&this.emit("selectionUpdate",{editor:this,transaction:n});const o=t.findLast(c=>c.getMeta("focus")||c.getMeta("blur")),l=o?.getMeta("focus"),a=o?.getMeta("blur");l&&this.emit("focus",{editor:this,event:l.event,transaction:o}),a&&this.emit("blur",{editor:this,event:a.event,transaction:o}),!(n.getMeta("preventUpdate")||!t.some(c=>c.docChanged)||s.doc.eq(e.doc))&&this.emit("update",{editor:this,transaction:n,appendedTransactions:t.slice(1)})}getAttributes(n){return yy(this.state,n)}isActive(n,e){const t=typeof n=="string"?n:null,i=typeof n=="string"?e:n;return UC(this.state,t,i)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Pu(this.state.doc.content,this.schema)}getText(n){const{blockSeparator:e=`
85
+
86
+ `,textSerializers:t={}}=n||{};return gy(this.state.doc,{blockSeparator:e,textSerializers:{...zu(this.schema),...t}})}get isEmpty(){return ma(this.state.doc)}destroy(){this.emit("destroy"),this.unmount(),this.removeAllListeners()}get isDestroyed(){var n,e;return(e=(n=this.editorView)==null?void 0:n.isDestroyed)!=null?e:!0}$node(n,e){var t;return((t=this.$doc)==null?void 0:t.querySelector(n,e))||null}$nodes(n,e){var t;return((t=this.$doc)==null?void 0:t.querySelectorAll(n,e))||null}$pos(n){const e=this.state.doc.resolve(n);return new EM(e,this)}get $doc(){return this.$pos(0)}};function dr(n){return new ga({find:n.find,handler:({state:e,range:t,match:i})=>{const r=re(n.getAttributes,void 0,i);if(r===!1||r===null)return null;const{tr:s}=e,o=i[i.length-1],l=i[0];if(o){const a=l.search(/\S/),c=t.from+l.indexOf(o),h=c+o.length;if(Hu(t.from,t.to,e.doc).filter(d=>d.mark.type.excluded.find(m=>m===n.type&&m!==d.mark.type)).filter(d=>d.to>c).length)return null;h<t.to&&s.delete(h,t.to),c>t.from&&s.delete(t.from+a,c);const f=t.from+a+o.length;s.addMark(t.from+a,f,n.type.create(r||{})),s.removeStoredMark(n.type)}},undoable:n.undoable})}function zy(n){return new ga({find:n.find,handler:({state:e,range:t,match:i})=>{const r=re(n.getAttributes,void 0,i)||{},{tr:s}=e,o=t.from;let l=t.to;const a=n.type.create(r);if(i[1]){const c=i[0].lastIndexOf(i[1]);let h=o+c;h>l?h=l:l=h+i[1].length;const u=i[0][i[0].length-1];s.insertText(u,o+i[0].length-1),s.replaceWith(h,l,a)}else if(i[0]){const c=n.type.isInline?o:o-1;s.insert(c,n.type.create(r)).delete(s.mapping.map(o),s.mapping.map(l))}s.scrollIntoView()},undoable:n.undoable})}function ih(n){return new ga({find:n.find,handler:({state:e,range:t,match:i})=>{const r=e.doc.resolve(t.from),s=re(n.getAttributes,void 0,i)||{};if(!r.node(-1).canReplaceWith(r.index(-1),r.indexAfter(-1),n.type))return null;e.tr.delete(t.from,t.to).setBlockType(t.from,t.from,n.type,s)},undoable:n.undoable})}function pr(n){return new ga({find:n.find,handler:({state:e,range:t,match:i,chain:r})=>{const s=re(n.getAttributes,void 0,i)||{},o=e.tr.delete(t.from,t.to),a=o.doc.resolve(t.from).blockRange(),c=a&&pu(a,n.type,s);if(!c)return null;if(o.wrap(a,c),n.keepMarks&&n.editor){const{selection:u,storedMarks:f}=e,{splittableMarks:d}=n.editor.extensionManager,p=f||u.$to.parentOffset&&u.$from.marks();if(p){const m=p.filter(g=>d.includes(g.type.name));o.ensureMarks(m)}}if(n.keepAttributes){const u=n.type.name==="bulletList"||n.type.name==="orderedList"?"listItem":"taskList";r().updateAttributes(u,s).run()}const h=o.doc.resolve(t.from-1).nodeBefore;h&&h.type===n.type&&si(o.doc,t.from-1)&&(!n.joinPredicate||n.joinPredicate(i,h))&&o.join(t.from-1)},undoable:n.undoable})}var NM=n=>"touches"in n,IM=class{constructor(n){this.directions=["bottom-left","bottom-right","top-left","top-right"],this.minSize={height:8,width:8},this.preserveAspectRatio=!1,this.classNames={container:"",wrapper:"",handle:"",resizing:""},this.initialWidth=0,this.initialHeight=0,this.aspectRatio=1,this.isResizing=!1,this.activeHandle=null,this.startX=0,this.startY=0,this.startWidth=0,this.startHeight=0,this.isShiftKeyPressed=!1,this.lastEditableState=void 0,this.handleMap=new Map,this.handleMouseMove=l=>{if(!this.isResizing||!this.activeHandle)return;const a=l.clientX-this.startX,c=l.clientY-this.startY;this.handleResize(a,c)},this.handleTouchMove=l=>{if(!this.isResizing||!this.activeHandle)return;const a=l.touches[0];if(!a)return;const c=a.clientX-this.startX,h=a.clientY-this.startY;this.handleResize(c,h)},this.handleMouseUp=()=>{if(!this.isResizing)return;const l=this.element.offsetWidth,a=this.element.offsetHeight;this.onCommit(l,a),this.isResizing=!1,this.activeHandle=null,this.container.dataset.resizeState="false",this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp)},this.handleKeyDown=l=>{l.key==="Shift"&&(this.isShiftKeyPressed=!0)},this.handleKeyUp=l=>{l.key==="Shift"&&(this.isShiftKeyPressed=!1)};var e,t,i,r,s,o;this.node=n.node,this.editor=n.editor,this.element=n.element,this.contentElement=n.contentElement,this.getPos=n.getPos,this.onResize=n.onResize,this.onCommit=n.onCommit,this.onUpdate=n.onUpdate,(e=n.options)!=null&&e.min&&(this.minSize={...this.minSize,...n.options.min}),(t=n.options)!=null&&t.max&&(this.maxSize=n.options.max),(i=n?.options)!=null&&i.directions&&(this.directions=n.options.directions),(r=n.options)!=null&&r.preserveAspectRatio&&(this.preserveAspectRatio=n.options.preserveAspectRatio),(s=n.options)!=null&&s.className&&(this.classNames={container:n.options.className.container||"",wrapper:n.options.className.wrapper||"",handle:n.options.className.handle||"",resizing:n.options.className.resizing||""}),(o=n.options)!=null&&o.createCustomHandle&&(this.createCustomHandle=n.options.createCustomHandle),this.wrapper=this.createWrapper(),this.container=this.createContainer(),this.applyInitialSize(),this.attachHandles(),this.editor.on("update",this.handleEditorUpdate.bind(this))}get dom(){return this.container}get contentDOM(){var n;return(n=this.contentElement)!=null?n:null}handleEditorUpdate(){const n=this.editor.isEditable;n!==this.lastEditableState&&(this.lastEditableState=n,n?n&&this.handleMap.size===0&&this.attachHandles():this.removeHandles())}update(n,e,t){return n.type!==this.node.type?!1:(this.node=n,this.onUpdate?this.onUpdate(n,e,t):!0)}destroy(){this.isResizing&&(this.container.dataset.resizeState="false",this.classNames.resizing&&this.container.classList.remove(this.classNames.resizing),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.removeEventListener("keydown",this.handleKeyDown),document.removeEventListener("keyup",this.handleKeyUp),this.isResizing=!1,this.activeHandle=null),this.editor.off("update",this.handleEditorUpdate.bind(this)),this.container.remove()}createContainer(){const n=document.createElement("div");return n.dataset.resizeContainer="",n.dataset.node=this.node.type.name,n.style.display="flex",this.classNames.container&&(n.className=this.classNames.container),n.appendChild(this.wrapper),n}createWrapper(){const n=document.createElement("div");return n.style.position="relative",n.style.display="block",n.dataset.resizeWrapper="",this.classNames.wrapper&&(n.className=this.classNames.wrapper),n.appendChild(this.element),n}createHandle(n){const e=document.createElement("div");return e.dataset.resizeHandle=n,e.style.position="absolute",this.classNames.handle&&(e.className=this.classNames.handle),e}positionHandle(n,e){const t=e.includes("top"),i=e.includes("bottom"),r=e.includes("left"),s=e.includes("right");t&&(n.style.top="0"),i&&(n.style.bottom="0"),r&&(n.style.left="0"),s&&(n.style.right="0"),(e==="top"||e==="bottom")&&(n.style.left="0",n.style.right="0"),(e==="left"||e==="right")&&(n.style.top="0",n.style.bottom="0")}attachHandles(){this.directions.forEach(n=>{let e;this.createCustomHandle?e=this.createCustomHandle(n):e=this.createHandle(n),e instanceof HTMLElement||(console.warn(`[ResizableNodeView] createCustomHandle("${n}") did not return an HTMLElement. Falling back to default handle.`),e=this.createHandle(n)),this.createCustomHandle||this.positionHandle(e,n),e.addEventListener("mousedown",t=>this.handleResizeStart(t,n)),e.addEventListener("touchstart",t=>this.handleResizeStart(t,n)),this.handleMap.set(n,e),this.wrapper.appendChild(e)})}removeHandles(){this.handleMap.forEach(n=>n.remove()),this.handleMap.clear()}applyInitialSize(){const n=this.node.attrs.width,e=this.node.attrs.height;n?(this.element.style.width=`${n}px`,this.initialWidth=n):this.initialWidth=this.element.offsetWidth,e?(this.element.style.height=`${e}px`,this.initialHeight=e):this.initialHeight=this.element.offsetHeight,this.initialWidth>0&&this.initialHeight>0&&(this.aspectRatio=this.initialWidth/this.initialHeight)}handleResizeStart(n,e){n.preventDefault(),n.stopPropagation(),this.isResizing=!0,this.activeHandle=e,NM(n)?(this.startX=n.touches[0].clientX,this.startY=n.touches[0].clientY):(this.startX=n.clientX,this.startY=n.clientY),this.startWidth=this.element.offsetWidth,this.startHeight=this.element.offsetHeight,this.startWidth>0&&this.startHeight>0&&(this.aspectRatio=this.startWidth/this.startHeight),this.getPos(),this.container.dataset.resizeState="true",this.classNames.resizing&&this.container.classList.add(this.classNames.resizing),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("touchmove",this.handleTouchMove),document.addEventListener("mouseup",this.handleMouseUp),document.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keyup",this.handleKeyUp)}handleResize(n,e){if(!this.activeHandle)return;const t=this.preserveAspectRatio||this.isShiftKeyPressed,{width:i,height:r}=this.calculateNewDimensions(this.activeHandle,n,e),s=this.applyConstraints(i,r,t);this.element.style.width=`${s.width}px`,this.element.style.height=`${s.height}px`,this.onResize&&this.onResize(s.width,s.height)}calculateNewDimensions(n,e,t){let i=this.startWidth,r=this.startHeight;const s=n.includes("right"),o=n.includes("left"),l=n.includes("bottom"),a=n.includes("top");return s?i=this.startWidth+e:o&&(i=this.startWidth-e),l?r=this.startHeight+t:a&&(r=this.startHeight-t),(n==="right"||n==="left")&&(i=this.startWidth+(s?e:-e)),(n==="top"||n==="bottom")&&(r=this.startHeight+(l?t:-t)),this.preserveAspectRatio||this.isShiftKeyPressed?this.applyAspectRatio(i,r,n):{width:i,height:r}}applyConstraints(n,e,t){var i,r,s,o;if(!t){let c=Math.max(this.minSize.width,n),h=Math.max(this.minSize.height,e);return(i=this.maxSize)!=null&&i.width&&(c=Math.min(this.maxSize.width,c)),(r=this.maxSize)!=null&&r.height&&(h=Math.min(this.maxSize.height,h)),{width:c,height:h}}let l=n,a=e;return l<this.minSize.width&&(l=this.minSize.width,a=l/this.aspectRatio),a<this.minSize.height&&(a=this.minSize.height,l=a*this.aspectRatio),(s=this.maxSize)!=null&&s.width&&l>this.maxSize.width&&(l=this.maxSize.width,a=l/this.aspectRatio),(o=this.maxSize)!=null&&o.height&&a>this.maxSize.height&&(a=this.maxSize.height,l=a*this.aspectRatio),{width:l,height:a}}applyAspectRatio(n,e,t){const i=t==="left"||t==="right",r=t==="top"||t==="bottom";return i?{width:n,height:n/this.aspectRatio}:r?{width:e*this.aspectRatio,height:e}:{width:n,height:n/this.aspectRatio}}};function LM(n,e){const{selection:t}=n,{$from:i}=t;if(t instanceof W){const s=i.index();return i.parent.canReplaceWith(s,s+1,e)}let r=i.depth;for(;r>=0;){const s=i.index(r);if(i.node(r).contentMatchAt(s).matchType(e))return!0;r-=1}return!1}var PM={};Du(PM,{createAtomBlockMarkdownSpec:()=>BM,createBlockMarkdownSpec:()=>zM,createInlineMarkdownSpec:()=>$M,parseAttributes:()=>$u,parseIndentedBlocks:()=>rh,renderNestedMarkdownContent:()=>Wu,serializeAttributes:()=>Vu});function $u(n){if(!n?.trim())return{};const e={},t=[],i=n.replace(/["']([^"']*)["']/g,c=>(t.push(c),`__QUOTED_${t.length-1}__`)),r=i.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);if(r){const c=r.map(h=>h.trim().slice(1));e.class=c.join(" ")}const s=i.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);s&&(e.id=s[1]);const o=/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;Array.from(i.matchAll(o)).forEach(([,c,h])=>{var u;const f=parseInt(((u=h.match(/__QUOTED_(\d+)__/))==null?void 0:u[1])||"0",10),d=t[f];d&&(e[c]=d.slice(1,-1))});const a=i.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,"").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,"").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,"").trim();return a&&a.split(/\s+/).filter(Boolean).forEach(h=>{h.match(/^[a-zA-Z][\w-]*$/)&&(e[h]=!0)}),e}function Vu(n){if(!n||Object.keys(n).length===0)return"";const e=[];return n.class&&String(n.class).split(/\s+/).filter(Boolean).forEach(i=>e.push(`.${i}`)),n.id&&e.push(`#${n.id}`),Object.entries(n).forEach(([t,i])=>{t==="class"||t==="id"||(i===!0?e.push(t):i!==!1&&i!=null&&e.push(`${t}="${String(i)}"`))}),e.join(" ")}function BM(n){const{nodeName:e,name:t,parseAttributes:i=$u,serializeAttributes:r=Vu,defaultAttributes:s={},requiredAttributes:o=[],allowedAttributes:l}=n,a=t||e,c=h=>{if(!l)return h;const u={};return l.forEach(f=>{f in h&&(u[f]=h[f])}),u};return{parseMarkdown:(h,u)=>{const f={...s,...h.attributes};return u.createNode(e,f,[])},markdownTokenizer:{name:e,level:"block",start(h){var u;const f=new RegExp(`^:::${a}(?:\\s|$)`,"m"),d=(u=h.match(f))==null?void 0:u.index;return d!==void 0?d:-1},tokenize(h,u,f){const d=new RegExp(`^:::${a}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),p=h.match(d);if(!p)return;const m=p[1]||"",g=i(m);if(!o.find(b=>!(b in g)))return{type:e,raw:p[0],attributes:g}}},renderMarkdown:h=>{const u=c(h.attrs||{}),f=r(u),d=f?` {${f}}`:"";return`:::${a}${d} :::`}}}function zM(n){const{nodeName:e,name:t,getContent:i,parseAttributes:r=$u,serializeAttributes:s=Vu,defaultAttributes:o={},content:l="block",allowedAttributes:a}=n,c=t||e,h=u=>{if(!a)return u;const f={};return a.forEach(d=>{d in u&&(f[d]=u[d])}),f};return{parseMarkdown:(u,f)=>{let d;if(i){const m=i(u);d=typeof m=="string"?[{type:"text",text:m}]:m}else l==="block"?d=f.parseChildren(u.tokens||[]):d=f.parseInline(u.tokens||[]);const p={...o,...u.attributes};return f.createNode(e,p,d)},markdownTokenizer:{name:e,level:"block",start(u){var f;const d=new RegExp(`^:::${c}`,"m"),p=(f=u.match(d))==null?void 0:f.index;return p!==void 0?p:-1},tokenize(u,f,d){var p;const m=new RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),g=u.match(m);if(!g)return;const[y,b=""]=g,x=r(b);let k=1;const w=y.length;let C="";const v=/^:::([\w-]*)(\s.*)?/gm,D=u.slice(w);for(v.lastIndex=0;;){const L=v.exec(D);if(L===null)break;const J=L.index,j=L[1];if(!((p=L[2])!=null&&p.endsWith(":::"))){if(j)k+=1;else if(k-=1,k===0){const $=D.slice(0,J);C=$.trim();const te=u.slice(0,w+J+L[0].length);let G=[];if(C)if(l==="block")for(G=d.blockTokens($),G.forEach(Z=>{Z.text&&(!Z.tokens||Z.tokens.length===0)&&(Z.tokens=d.inlineTokens(Z.text))});G.length>0;){const Z=G[G.length-1];if(Z.type==="paragraph"&&(!Z.text||Z.text.trim()===""))G.pop();else break}else G=d.inlineTokens(C);return{type:e,raw:te,attributes:x,content:C,tokens:G}}}}}},renderMarkdown:(u,f)=>{const d=h(u.attrs||{}),p=s(d),m=p?` {${p}}`:"",g=f.renderChildren(u.content||[],`
87
+
88
+ `);return`:::${c}${m}
89
+
90
+ ${g}
91
+
92
+ :::`}}}function HM(n){if(!n.trim())return{};const e={},t=/(\w+)=(?:"([^"]*)"|'([^']*)')/g;let i=t.exec(n);for(;i!==null;){const[,r,s,o]=i;e[r]=s||o,i=t.exec(n)}return e}function FM(n){return Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(" ")}function $M(n){const{nodeName:e,name:t,getContent:i,parseAttributes:r=HM,serializeAttributes:s=FM,defaultAttributes:o={},selfClosing:l=!1,allowedAttributes:a}=n,c=t||e,h=f=>{if(!a)return f;const d={};return a.forEach(p=>{const m=typeof p=="string"?p:p.name,g=typeof p=="string"?void 0:p.skipIfDefault;if(m in f){const y=f[m];if(g!==void 0&&y===g)return;d[m]=y}}),d},u=c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return{parseMarkdown:(f,d)=>{const p={...o,...f.attributes};if(l)return d.createNode(e,p);const m=i?i(f):f.content||"";return m?d.createNode(e,p,[d.createTextNode(m)]):d.createNode(e,p,[])},markdownTokenizer:{name:e,level:"inline",start(f){const d=l?new RegExp(`\\[${u}\\s*[^\\]]*\\]`):new RegExp(`\\[${u}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${u}\\]`),p=f.match(d),m=p?.index;return m!==void 0?m:-1},tokenize(f,d,p){const m=l?new RegExp(`^\\[${u}\\s*([^\\]]*)\\]`):new RegExp(`^\\[${u}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${u}\\]`),g=f.match(m);if(!g)return;let y="",b="";if(l){const[,k]=g;b=k}else{const[,k,w]=g;b=k,y=w||""}const x=r(b.trim());return{type:e,raw:g[0],content:y.trim(),attributes:x}}},renderMarkdown:f=>{let d="";i?d=i(f):f.content&&f.content.length>0&&(d=f.content.filter(y=>y.type==="text").map(y=>y.text).join(""));const p=h(f.attrs||{}),m=s(p),g=m?` ${m}`:"";return l?`[${c}${g}]`:`[${c}${g}]${d}[/${c}]`}}}function rh(n,e,t){var i,r,s,o;const l=n.split(`
93
+ `),a=[];let c="",h=0;const u=e.baseIndentSize||2;for(;h<l.length;){const f=l[h],d=f.match(e.itemPattern);if(!d){if(a.length>0)break;if(f.trim()===""){h+=1,c=`${c}${f}
94
+ `;continue}else return}const p=e.extractItemData(d),{indentLevel:m,mainContent:g}=p;c=`${c}${f}
95
+ `;const y=[g];for(h+=1;h<l.length;){const w=l[h];if(w.trim()===""){const v=l.slice(h+1).findIndex(J=>J.trim()!=="");if(v===-1)break;if((((r=(i=l[h+1+v].match(/^(\s*)/))==null?void 0:i[1])==null?void 0:r.length)||0)>m){y.push(w),c=`${c}${w}
96
+ `,h+=1;continue}else break}if((((o=(s=w.match(/^(\s*)/))==null?void 0:s[1])==null?void 0:o.length)||0)>m)y.push(w),c=`${c}${w}
97
+ `,h+=1;else break}let b;const x=y.slice(1);if(x.length>0){const w=x.map(C=>C.slice(m+u)).join(`
98
+ `);w.trim()&&(e.customNestedParser?b=e.customNestedParser(w):b=t.blockTokens(w))}const k=e.createToken(p,b);a.push(k)}if(a.length!==0)return{items:a,raw:c}}function Wu(n,e,t,i){if(!n||!Array.isArray(n.content))return"";const r=typeof t=="function"?t(i):t,[s,...o]=n.content,l=e.renderChildren([s]),a=[`${r}${l}`];return o&&o.length>0&&o.forEach(c=>{const h=e.renderChildren([c]);if(h){const u=h.split(`
99
+ `).map(f=>f?e.indent(f):"").join(`
100
+ `);a.push(u)}}),a.join(`
101
+ `)}function VM(n,e,t={}){const{state:i}=e,{doc:r,tr:s}=i,o=n;r.descendants((l,a)=>{const c=s.mapping.map(a),h=s.mapping.map(a)+l.nodeSize;let u=null;if(l.marks.forEach(d=>{if(d!==o)return!1;u=d}),!u)return;let f=!1;if(Object.keys(t).forEach(d=>{t[d]!==u.attrs[d]&&(f=!0)}),f){const d=n.type.create({...n.attrs,...t});s.removeMark(c,h,n.type),s.addMark(c,h,d)}}),s.docChanged&&e.view.dispatch(s)}var He=class Hy extends Fu{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new Hy(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function Ri(n){return new vM({find:n.find,handler:({state:e,range:t,match:i,pasteEvent:r})=>{const s=re(n.getAttributes,void 0,i,r);if(s===!1||s===null)return null;const{tr:o}=e,l=i[i.length-1],a=i[0];let c=t.to;if(l){const h=a.search(/\S/),u=t.from+a.indexOf(l),f=u+l.length;if(Hu(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(g=>g===n.type&&g!==p.mark.type)).filter(p=>p.to>u).length)return null;f<t.to&&o.delete(f,t.to),u>t.from&&o.delete(t.from+h,u),c=t.from+h+l.length,o.addMark(t.from+h,c,n.type.create(s||{})),o.removeStoredMark(n.type)}}})}const{getOwnPropertyNames:WM,getOwnPropertySymbols:jM}=Object,{hasOwnProperty:_M}=Object.prototype;function tc(n,e){return function(i,r,s){return n(i,r,s)&&e(i,r,s)}}function to(n){return function(t,i,r){if(!t||!i||typeof t!="object"||typeof i!="object")return n(t,i,r);const{cache:s}=r,o=s.get(t),l=s.get(i);if(o&&l)return o===i&&l===t;s.set(t,i),s.set(i,t);const a=n(t,i,r);return s.delete(t),s.delete(i),a}}function UM(n){return n?.[Symbol.toStringTag]}function tp(n){return WM(n).concat(jM(n))}const qM=Object.hasOwn||((n,e)=>_M.call(n,e));function Hi(n,e){return n===e||!n&&!e&&n!==n&&e!==e}const KM="__v",JM="__o",GM="_owner",{getOwnPropertyDescriptor:np,keys:ip}=Object;function YM(n,e){return n.byteLength===e.byteLength&&il(new Uint8Array(n),new Uint8Array(e))}function XM(n,e,t){let i=n.length;if(e.length!==i)return!1;for(;i-- >0;)if(!t.equals(n[i],e[i],i,i,n,e,t))return!1;return!0}function QM(n,e){return n.byteLength===e.byteLength&&il(new Uint8Array(n.buffer,n.byteOffset,n.byteLength),new Uint8Array(e.buffer,e.byteOffset,e.byteLength))}function ZM(n,e){return Hi(n.getTime(),e.getTime())}function eT(n,e){return n.name===e.name&&n.message===e.message&&n.cause===e.cause&&n.stack===e.stack}function tT(n,e){return n===e}function rp(n,e,t){const i=n.size;if(i!==e.size)return!1;if(!i)return!0;const r=new Array(i),s=n.entries();let o,l,a=0;for(;(o=s.next())&&!o.done;){const c=e.entries();let h=!1,u=0;for(;(l=c.next())&&!l.done;){if(r[u]){u++;continue}const f=o.value,d=l.value;if(t.equals(f[0],d[0],a,u,n,e,t)&&t.equals(f[1],d[1],f[0],d[0],n,e,t)){h=r[u]=!0;break}u++}if(!h)return!1;a++}return!0}const nT=Hi;function iT(n,e,t){const i=ip(n);let r=i.length;if(ip(e).length!==r)return!1;for(;r-- >0;)if(!Fy(n,e,t,i[r]))return!1;return!0}function Rr(n,e,t){const i=tp(n);let r=i.length;if(tp(e).length!==r)return!1;let s,o,l;for(;r-- >0;)if(s=i[r],!Fy(n,e,t,s)||(o=np(n,s),l=np(e,s),(o||l)&&(!o||!l||o.configurable!==l.configurable||o.enumerable!==l.enumerable||o.writable!==l.writable)))return!1;return!0}function rT(n,e){return Hi(n.valueOf(),e.valueOf())}function sT(n,e){return n.source===e.source&&n.flags===e.flags}function sp(n,e,t){const i=n.size;if(i!==e.size)return!1;if(!i)return!0;const r=new Array(i),s=n.values();let o,l;for(;(o=s.next())&&!o.done;){const a=e.values();let c=!1,h=0;for(;(l=a.next())&&!l.done;){if(!r[h]&&t.equals(o.value,l.value,o.value,l.value,n,e,t)){c=r[h]=!0;break}h++}if(!c)return!1}return!0}function il(n,e){let t=n.byteLength;if(e.byteLength!==t||n.byteOffset!==e.byteOffset)return!1;for(;t-- >0;)if(n[t]!==e[t])return!1;return!0}function oT(n,e){return n.hostname===e.hostname&&n.pathname===e.pathname&&n.protocol===e.protocol&&n.port===e.port&&n.hash===e.hash&&n.username===e.username&&n.password===e.password}function Fy(n,e,t,i){return(i===GM||i===JM||i===KM)&&(n.$$typeof||e.$$typeof)?!0:qM(e,i)&&t.equals(n[i],e[i],i,i,n,e,t)}const lT="[object ArrayBuffer]",aT="[object Arguments]",cT="[object Boolean]",hT="[object DataView]",uT="[object Date]",fT="[object Error]",dT="[object Map]",pT="[object Number]",mT="[object Object]",gT="[object RegExp]",yT="[object Set]",bT="[object String]",xT={"[object Int8Array]":!0,"[object Uint8Array]":!0,"[object Uint8ClampedArray]":!0,"[object Int16Array]":!0,"[object Uint16Array]":!0,"[object Int32Array]":!0,"[object Uint32Array]":!0,"[object Float16Array]":!0,"[object Float32Array]":!0,"[object Float64Array]":!0,"[object BigInt64Array]":!0,"[object BigUint64Array]":!0},wT="[object URL]",kT=Object.prototype.toString;function vT({areArrayBuffersEqual:n,areArraysEqual:e,areDataViewsEqual:t,areDatesEqual:i,areErrorsEqual:r,areFunctionsEqual:s,areMapsEqual:o,areNumbersEqual:l,areObjectsEqual:a,arePrimitiveWrappersEqual:c,areRegExpsEqual:h,areSetsEqual:u,areTypedArraysEqual:f,areUrlsEqual:d,unknownTagComparators:p}){return function(g,y,b){if(g===y)return!0;if(g==null||y==null)return!1;const x=typeof g;if(x!==typeof y)return!1;if(x!=="object")return x==="number"?l(g,y,b):x==="function"?s(g,y,b):!1;const k=g.constructor;if(k!==y.constructor)return!1;if(k===Object)return a(g,y,b);if(Array.isArray(g))return e(g,y,b);if(k===Date)return i(g,y,b);if(k===RegExp)return h(g,y,b);if(k===Map)return o(g,y,b);if(k===Set)return u(g,y,b);const w=kT.call(g);if(w===uT)return i(g,y,b);if(w===gT)return h(g,y,b);if(w===dT)return o(g,y,b);if(w===yT)return u(g,y,b);if(w===mT)return typeof g.then!="function"&&typeof y.then!="function"&&a(g,y,b);if(w===wT)return d(g,y,b);if(w===fT)return r(g,y,b);if(w===aT)return a(g,y,b);if(xT[w])return f(g,y,b);if(w===lT)return n(g,y,b);if(w===hT)return t(g,y,b);if(w===cT||w===pT||w===bT)return c(g,y,b);if(p){let C=p[w];if(!C){const v=UM(g);v&&(C=p[v])}if(C)return C(g,y,b)}return!1}}function ST({circular:n,createCustomConfig:e,strict:t}){let i={areArrayBuffersEqual:YM,areArraysEqual:t?Rr:XM,areDataViewsEqual:QM,areDatesEqual:ZM,areErrorsEqual:eT,areFunctionsEqual:tT,areMapsEqual:t?tc(rp,Rr):rp,areNumbersEqual:nT,areObjectsEqual:t?Rr:iT,arePrimitiveWrappersEqual:rT,areRegExpsEqual:sT,areSetsEqual:t?tc(sp,Rr):sp,areTypedArraysEqual:t?tc(il,Rr):il,areUrlsEqual:oT,unknownTagComparators:void 0};if(e&&(i=Object.assign({},i,e(i))),n){const r=to(i.areArraysEqual),s=to(i.areMapsEqual),o=to(i.areObjectsEqual),l=to(i.areSetsEqual);i=Object.assign({},i,{areArraysEqual:r,areMapsEqual:s,areObjectsEqual:o,areSetsEqual:l})}return i}function CT(n){return function(e,t,i,r,s,o,l){return n(e,t,l)}}function MT({circular:n,comparator:e,createState:t,equals:i,strict:r}){if(t)return function(l,a){const{cache:c=n?new WeakMap:void 0,meta:h}=t();return e(l,a,{cache:c,equals:i,meta:h,strict:r})};if(n)return function(l,a){return e(l,a,{cache:new WeakMap,equals:i,meta:void 0,strict:r})};const s={cache:void 0,equals:i,meta:void 0,strict:r};return function(l,a){return e(l,a,s)}}const TT=li();li({strict:!0});li({circular:!0});li({circular:!0,strict:!0});li({createInternalComparator:()=>Hi});li({strict:!0,createInternalComparator:()=>Hi});li({circular:!0,createInternalComparator:()=>Hi});li({circular:!0,createInternalComparator:()=>Hi,strict:!0});function li(n={}){const{circular:e=!1,createInternalComparator:t,createState:i,strict:r=!1}=n,s=ST(n),o=vT(s),l=t?t(o):CT(o);return MT({circular:e,comparator:o,createState:i,equals:l,strict:r})}let sh,oh;if(typeof WeakMap<"u"){let n=new WeakMap;sh=e=>n.get(e),oh=(e,t)=>(n.set(e,t),t)}else{const n=[];let t=0;sh=i=>{for(let r=0;r<n.length;r+=2)if(n[r]==i)return n[r+1]},oh=(i,r)=>(t==10&&(t=0),n[t++]=i,n[t++]=r)}var we=class{constructor(n,e,t,i){this.width=n,this.height=e,this.map=t,this.problems=i}findCell(n){for(let e=0;e<this.map.length;e++){const t=this.map[e];if(t!=n)continue;const i=e%this.width,r=e/this.width|0;let s=i+1,o=r+1;for(let l=1;s<this.width&&this.map[e+l]==t;l++)s++;for(let l=1;o<this.height&&this.map[e+this.width*l]==t;l++)o++;return{left:i,top:r,right:s,bottom:o}}throw new RangeError(`No cell with offset ${n} found`)}colCount(n){for(let e=0;e<this.map.length;e++)if(this.map[e]==n)return e%this.width;throw new RangeError(`No cell with offset ${n} found`)}nextCell(n,e,t){const{left:i,right:r,top:s,bottom:o}=this.findCell(n);return e=="horiz"?(t<0?i==0:r==this.width)?null:this.map[s*this.width+(t<0?i-1:r)]:(t<0?s==0:o==this.height)?null:this.map[i+this.width*(t<0?s-1:o)]}rectBetween(n,e){const{left:t,right:i,top:r,bottom:s}=this.findCell(n),{left:o,right:l,top:a,bottom:c}=this.findCell(e);return{left:Math.min(t,o),top:Math.min(r,a),right:Math.max(i,l),bottom:Math.max(s,c)}}cellsInRect(n){const e=[],t={};for(let i=n.top;i<n.bottom;i++)for(let r=n.left;r<n.right;r++){const s=i*this.width+r,o=this.map[s];t[o]||(t[o]=!0,!(r==n.left&&r&&this.map[s-1]==o||i==n.top&&i&&this.map[s-this.width]==o)&&e.push(o))}return e}positionAt(n,e,t){for(let i=0,r=0;;i++){const s=r+t.child(i).nodeSize;if(i==n){let o=e+n*this.width;const l=(n+1)*this.width;for(;o<l&&this.map[o]<r;)o++;return o==l?s-1:this.map[o]}r=s}}static get(n){return sh(n)||oh(n,AT(n))}};function AT(n){if(n.type.spec.tableRole!="table")throw new RangeError("Not a table node: "+n.type.name);const e=ET(n),t=n.childCount,i=[];let r=0,s=null;const o=[];for(let c=0,h=e*t;c<h;c++)i[c]=0;for(let c=0,h=0;c<t;c++){const u=n.child(c);h++;for(let p=0;;p++){for(;r<i.length&&i[r]!=0;)r++;if(p==u.childCount)break;const m=u.child(p),{colspan:g,rowspan:y,colwidth:b}=m.attrs;for(let x=0;x<y;x++){if(x+c>=t){(s||(s=[])).push({type:"overlong_rowspan",pos:h,n:y-x});break}const k=r+x*e;for(let w=0;w<g;w++){i[k+w]==0?i[k+w]=h:(s||(s=[])).push({type:"collision",row:c,pos:h,n:g-w});const C=b&&b[w];if(C){const v=(k+w)%e*2,D=o[v];D==null||D!=C&&o[v+1]==1?(o[v]=C,o[v+1]=1):D==C&&o[v+1]++}}}r+=g,h+=m.nodeSize}const f=(c+1)*e;let d=0;for(;r<f;)i[r++]==0&&d++;d&&(s||(s=[])).push({type:"missing",row:c,n:d}),h++}(e===0||t===0)&&(s||(s=[])).push({type:"zero_sized"});const l=new we(e,t,i,s);let a=!1;for(let c=0;!a&&c<o.length;c+=2)o[c]!=null&&o[c+1]<t&&(a=!0);return a&&OT(l,o,n),l}function ET(n){let e=-1,t=!1;for(let i=0;i<n.childCount;i++){const r=n.child(i);let s=0;if(t)for(let o=0;o<i;o++){const l=n.child(o);for(let a=0;a<l.childCount;a++){const c=l.child(a);o+c.attrs.rowspan>i&&(s+=c.attrs.colspan)}}for(let o=0;o<r.childCount;o++){const l=r.child(o);s+=l.attrs.colspan,l.attrs.rowspan>1&&(t=!0)}e==-1?e=s:e!=s&&(e=Math.max(e,s))}return e}function OT(n,e,t){n.problems||(n.problems=[]);const i={};for(let r=0;r<n.map.length;r++){const s=n.map[r];if(i[s])continue;i[s]=!0;const o=t.nodeAt(s);if(!o)throw new RangeError(`No cell with offset ${s} found`);let l=null;const a=o.attrs;for(let c=0;c<a.colspan;c++){const h=e[(r+c)%n.width*2];h!=null&&(!a.colwidth||a.colwidth[c]!=h)&&((l||(l=RT(a)))[c]=h)}l&&n.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:l})}}function RT(n){if(n.colwidth)return n.colwidth.slice();const e=[];for(let t=0;t<n.colspan;t++)e.push(0);return e}function Je(n){let e=n.cached.tableNodeTypes;if(!e){e=n.cached.tableNodeTypes={};for(const t in n.nodes){const i=n.nodes[t],r=i.spec.tableRole;r&&(e[r]=i)}}return e}const Vn=new me("selectingCells");function Di(n){for(let e=n.depth-1;e>0;e--)if(n.node(e).type.spec.tableRole=="row")return n.node(0).resolve(n.before(e+1));return null}function DT(n){for(let e=n.depth;e>0;e--){const t=n.node(e).type.spec.tableRole;if(t==="cell"||t==="header_cell")return n.node(e)}return null}function _t(n){const e=n.selection.$head;for(let t=e.depth;t>0;t--)if(e.node(t).type.spec.tableRole=="row")return!0;return!1}function ba(n){const e=n.selection;if("$anchorCell"in e&&e.$anchorCell)return e.$anchorCell.pos>e.$headCell.pos?e.$anchorCell:e.$headCell;if("node"in e&&e.node&&e.node.type.spec.tableRole=="cell")return e.$anchor;const t=Di(e.$head)||NT(e.$head);if(t)return t;throw new RangeError(`No cell found around position ${e.head}`)}function NT(n){for(let e=n.nodeAfter,t=n.pos;e;e=e.firstChild,t++){const i=e.type.spec.tableRole;if(i=="cell"||i=="header_cell")return n.doc.resolve(t)}for(let e=n.nodeBefore,t=n.pos;e;e=e.lastChild,t--){const i=e.type.spec.tableRole;if(i=="cell"||i=="header_cell")return n.doc.resolve(t-e.nodeSize)}}function lh(n){return n.parent.type.spec.tableRole=="row"&&!!n.nodeAfter}function IT(n){return n.node(0).resolve(n.pos+n.nodeAfter.nodeSize)}function ju(n,e){return n.depth==e.depth&&n.pos>=e.start(-1)&&n.pos<=e.end(-1)}function $y(n,e,t){const i=n.node(-1),r=we.get(i),s=n.start(-1),o=r.nextCell(n.pos-s,e,t);return o==null?null:n.node(0).resolve(s+o)}function Ni(n,e,t=1){const i={...n,colspan:n.colspan-t};return i.colwidth&&(i.colwidth=i.colwidth.slice(),i.colwidth.splice(e,t),i.colwidth.some(r=>r>0)||(i.colwidth=null)),i}function Vy(n,e,t=1){const i={...n,colspan:n.colspan+t};if(i.colwidth){i.colwidth=i.colwidth.slice();for(let r=0;r<t;r++)i.colwidth.splice(e,0,0)}return i}function LT(n,e,t){const i=Je(e.type.schema).header_cell;for(let r=0;r<n.height;r++)if(e.nodeAt(n.map[t+r*n.width]).type!=i)return!1;return!0}var ce=class yn extends U{constructor(e,t=e){const i=e.node(-1),r=we.get(i),s=e.start(-1),o=r.rectBetween(e.pos-s,t.pos-s),l=e.node(0),a=r.cellsInRect(o).filter(h=>h!=t.pos-s);a.unshift(t.pos-s);const c=a.map(h=>{const u=i.nodeAt(h);if(!u)throw new RangeError(`No cell with offset ${h} found`);const f=s+h+1;return new o0(l.resolve(f),l.resolve(f+u.content.size))});super(c[0].$from,c[0].$to,c),this.$anchorCell=e,this.$headCell=t}map(e,t){const i=e.resolve(t.map(this.$anchorCell.pos)),r=e.resolve(t.map(this.$headCell.pos));if(lh(i)&&lh(r)&&ju(i,r)){const s=this.$anchorCell.node(-1)!=i.node(-1);return s&&this.isRowSelection()?yn.rowSelection(i,r):s&&this.isColSelection()?yn.colSelection(i,r):new yn(i,r)}return _.between(i,r)}content(){const e=this.$anchorCell.node(-1),t=we.get(e),i=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-i,this.$headCell.pos-i),s={},o=[];for(let a=r.top;a<r.bottom;a++){const c=[];for(let h=a*t.width+r.left,u=r.left;u<r.right;u++,h++){const f=t.map[h];if(s[f])continue;s[f]=!0;const d=t.findCell(f);let p=e.nodeAt(f);if(!p)throw new RangeError(`No cell with offset ${f} found`);const m=r.left-d.left,g=d.right-r.right;if(m>0||g>0){let y=p.attrs;if(m>0&&(y=Ni(y,0,m)),g>0&&(y=Ni(y,y.colspan-g,g)),d.left<r.left){if(p=p.type.createAndFill(y),!p)throw new RangeError(`Could not create cell with attrs ${JSON.stringify(y)}`)}else p=p.type.create(y,p.content)}if(d.top<r.top||d.bottom>r.bottom){const y={...p.attrs,rowspan:Math.min(d.bottom,r.bottom)-Math.max(d.top,r.top)};d.top<r.top?p=p.type.createAndFill(y):p=p.type.create(y,p.content)}c.push(p)}o.push(e.child(a).copy(A.from(c)))}const l=this.isColSelection()&&this.isRowSelection()?e:o;return new I(A.from(l),1,1)}replace(e,t=I.empty){const i=e.steps.length,r=this.ranges;for(let o=0;o<r.length;o++){const{$from:l,$to:a}=r[o],c=e.mapping.slice(i);e.replace(c.map(l.pos),c.map(a.pos),o?I.empty:t)}const s=U.findFrom(e.doc.resolve(e.mapping.slice(i).map(this.to)),-1);s&&e.setSelection(s)}replaceWith(e,t){this.replace(e,new I(A.from(t),0,0))}forEachCell(e){const t=this.$anchorCell.node(-1),i=we.get(t),r=this.$anchorCell.start(-1),s=i.cellsInRect(i.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let o=0;o<s.length;o++)e(t.nodeAt(s[o]),r+s[o])}isColSelection(){const e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);if(Math.min(e,t)>0)return!1;const i=e+this.$anchorCell.nodeAfter.attrs.rowspan,r=t+this.$headCell.nodeAfter.attrs.rowspan;return Math.max(i,r)==this.$headCell.node(-1).childCount}static colSelection(e,t=e){const i=e.node(-1),r=we.get(i),s=e.start(-1),o=r.findCell(e.pos-s),l=r.findCell(t.pos-s),a=e.node(0);return o.top<=l.top?(o.top>0&&(e=a.resolve(s+r.map[o.left])),l.bottom<r.height&&(t=a.resolve(s+r.map[r.width*(r.height-1)+l.right-1]))):(l.top>0&&(t=a.resolve(s+r.map[l.left])),o.bottom<r.height&&(e=a.resolve(s+r.map[r.width*(r.height-1)+o.right-1]))),new yn(e,t)}isRowSelection(){const e=this.$anchorCell.node(-1),t=we.get(e),i=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-i),s=t.colCount(this.$headCell.pos-i);if(Math.min(r,s)>0)return!1;const o=r+this.$anchorCell.nodeAfter.attrs.colspan,l=s+this.$headCell.nodeAfter.attrs.colspan;return Math.max(o,l)==t.width}eq(e){return e instanceof yn&&e.$anchorCell.pos==this.$anchorCell.pos&&e.$headCell.pos==this.$headCell.pos}static rowSelection(e,t=e){const i=e.node(-1),r=we.get(i),s=e.start(-1),o=r.findCell(e.pos-s),l=r.findCell(t.pos-s),a=e.node(0);return o.left<=l.left?(o.left>0&&(e=a.resolve(s+r.map[o.top*r.width])),l.right<r.width&&(t=a.resolve(s+r.map[r.width*(l.top+1)-1]))):(l.left>0&&(t=a.resolve(s+r.map[l.top*r.width])),o.right<r.width&&(e=a.resolve(s+r.map[r.width*(o.top+1)-1]))),new yn(e,t)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(e,t){return new yn(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,i=t){return new yn(e.resolve(t),e.resolve(i))}getBookmark(){return new PT(this.$anchorCell.pos,this.$headCell.pos)}};ce.prototype.visible=!1;U.jsonID("cell",ce);var PT=class Wy{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Wy(e.map(this.anchor),e.map(this.head))}resolve(e){const t=e.resolve(this.anchor),i=e.resolve(this.head);return t.parent.type.spec.tableRole=="row"&&i.parent.type.spec.tableRole=="row"&&t.index()<t.parent.childCount&&i.index()<i.parent.childCount&&ju(t,i)?new ce(t,i):U.near(i,1)}};function BT(n){if(!(n.selection instanceof ce))return null;const e=[];return n.selection.forEachCell((t,i)=>{e.push(kt.node(i,i+t.nodeSize,{class:"selectedCell"}))}),ue.create(n.doc,e)}function zT({$from:n,$to:e}){if(n.pos==e.pos||n.pos<e.pos-6)return!1;let t=n.pos,i=e.pos,r=n.depth;for(;r>=0&&!(n.after(r+1)<n.end(r));r--,t++);for(let s=e.depth;s>=0&&!(e.before(s+1)>e.start(s));s--,i--);return t==i&&/row|table/.test(n.node(r).type.spec.tableRole)}function HT({$from:n,$to:e}){let t,i;for(let r=n.depth;r>0;r--){const s=n.node(r);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){t=s;break}}for(let r=e.depth;r>0;r--){const s=e.node(r);if(s.type.spec.tableRole==="cell"||s.type.spec.tableRole==="header_cell"){i=s;break}}return t!==i&&e.parentOffset===0}function FT(n,e,t){const i=(e||n).selection,r=(e||n).doc;let s,o;if(i instanceof W&&(o=i.node.type.spec.tableRole)){if(o=="cell"||o=="header_cell")s=ce.create(r,i.from);else if(o=="row"){const l=r.resolve(i.from+1);s=ce.rowSelection(l,l)}else if(!t){const l=we.get(i.node),a=i.from+1,c=a+l.map[l.width*l.height-1];s=ce.create(r,a+1,c)}}else i instanceof _&&zT(i)?s=_.create(r,i.from):i instanceof _&&HT(i)&&(s=_.create(r,i.$from.start(),i.$from.end()));return s&&(e||(e=n.tr)).setSelection(s),e}const $T=new me("fix-tables");function jy(n,e,t,i){const r=n.childCount,s=e.childCount;e:for(let o=0,l=0;o<s;o++){const a=e.child(o);for(let c=l,h=Math.min(r,o+3);c<h;c++)if(n.child(c)==a){l=c+1,t+=a.nodeSize;continue e}i(a,t),l<r&&n.child(l).sameMarkup(a)?jy(n.child(l),a,t+1,i):a.nodesBetween(0,a.content.size,i,t+1),t+=a.nodeSize}}function _y(n,e){let t;const i=(r,s)=>{r.type.spec.tableRole=="table"&&(t=VT(n,r,s,t))};return e?e.doc!=n.doc&&jy(e.doc,n.doc,0,i):n.doc.descendants(i),t}function VT(n,e,t,i){const r=we.get(e);if(!r.problems)return i;i||(i=n.tr);const s=[];for(let a=0;a<r.height;a++)s.push(0);for(let a=0;a<r.problems.length;a++){const c=r.problems[a];if(c.type=="collision"){const h=e.nodeAt(c.pos);if(!h)continue;const u=h.attrs;for(let f=0;f<u.rowspan;f++)s[c.row+f]+=c.n;i.setNodeMarkup(i.mapping.map(t+1+c.pos),null,Ni(u,u.colspan-c.n,c.n))}else if(c.type=="missing")s[c.row]+=c.n;else if(c.type=="overlong_rowspan"){const h=e.nodeAt(c.pos);if(!h)continue;i.setNodeMarkup(i.mapping.map(t+1+c.pos),null,{...h.attrs,rowspan:h.attrs.rowspan-c.n})}else if(c.type=="colwidth mismatch"){const h=e.nodeAt(c.pos);if(!h)continue;i.setNodeMarkup(i.mapping.map(t+1+c.pos),null,{...h.attrs,colwidth:c.colwidth})}else if(c.type=="zero_sized"){const h=i.mapping.map(t);i.delete(h,h+e.nodeSize)}}let o,l;for(let a=0;a<s.length;a++)s[a]&&(o==null&&(o=a),l=a);for(let a=0,c=t+1;a<r.height;a++){const h=e.child(a),u=c+h.nodeSize,f=s[a];if(f>0){let d="cell";h.firstChild&&(d=h.firstChild.type.spec.tableRole);const p=[];for(let g=0;g<f;g++){const y=Je(n.schema)[d].createAndFill();y&&p.push(y)}const m=(a==0||o==a-1)&&l==a?c+1:u-1;i.insert(i.mapping.map(m),p)}c=u}return i.setMeta($T,{fixTables:!0})}function dn(n){const e=n.selection,t=ba(n),i=t.node(-1),r=t.start(-1),s=we.get(i);return{...e instanceof ce?s.rectBetween(e.$anchorCell.pos-r,e.$headCell.pos-r):s.findCell(t.pos-r),tableStart:r,map:s,table:i}}function Uy(n,{map:e,tableStart:t,table:i},r){let s=r>0?-1:0;LT(e,i,r+s)&&(s=r==0||r==e.width?null:0);for(let o=0;o<e.height;o++){const l=o*e.width+r;if(r>0&&r<e.width&&e.map[l-1]==e.map[l]){const a=e.map[l],c=i.nodeAt(a);n.setNodeMarkup(n.mapping.map(t+a),null,Vy(c.attrs,r-e.colCount(a))),o+=c.attrs.rowspan-1}else{const a=s==null?Je(i.type.schema).cell:i.nodeAt(e.map[l+s]).type,c=e.positionAt(o,r,i);n.insert(n.mapping.map(t+c),a.createAndFill())}}return n}function WT(n,e){if(!_t(n))return!1;if(e){const t=dn(n);e(Uy(n.tr,t,t.left))}return!0}function jT(n,e){if(!_t(n))return!1;if(e){const t=dn(n);e(Uy(n.tr,t,t.right))}return!0}function _T(n,{map:e,table:t,tableStart:i},r){const s=n.mapping.maps.length;for(let o=0;o<e.height;){const l=o*e.width+r,a=e.map[l],c=t.nodeAt(a),h=c.attrs;if(r>0&&e.map[l-1]==a||r<e.width-1&&e.map[l+1]==a)n.setNodeMarkup(n.mapping.slice(s).map(i+a),null,Ni(h,r-e.colCount(a)));else{const u=n.mapping.slice(s).map(i+a);n.delete(u,u+c.nodeSize)}o+=h.rowspan}}function UT(n,e){if(!_t(n))return!1;if(e){const t=dn(n),i=n.tr;if(t.left==0&&t.right==t.map.width)return!1;for(let r=t.right-1;_T(i,t,r),r!=t.left;r--){const s=t.tableStart?i.doc.nodeAt(t.tableStart-1):i.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=we.get(s)}e(i)}return!0}function qT(n,e,t){var i;const r=Je(e.type.schema).header_cell;for(let s=0;s<n.width;s++)if(((i=e.nodeAt(n.map[s+t*n.width]))===null||i===void 0?void 0:i.type)!=r)return!1;return!0}function qy(n,{map:e,tableStart:t,table:i},r){let s=t;for(let c=0;c<r;c++)s+=i.child(c).nodeSize;const o=[];let l=r>0?-1:0;qT(e,i,r+l)&&(l=r==0||r==e.height?null:0);for(let c=0,h=e.width*r;c<e.width;c++,h++)if(r>0&&r<e.height&&e.map[h]==e.map[h-e.width]){const u=e.map[h],f=i.nodeAt(u).attrs;n.setNodeMarkup(t+u,null,{...f,rowspan:f.rowspan+1}),c+=f.colspan-1}else{var a;const u=l==null?Je(i.type.schema).cell:(a=i.nodeAt(e.map[h+l*e.width]))===null||a===void 0?void 0:a.type,f=u?.createAndFill();f&&o.push(f)}return n.insert(s,Je(i.type.schema).row.create(null,o)),n}function KT(n,e){if(!_t(n))return!1;if(e){const t=dn(n);e(qy(n.tr,t,t.top))}return!0}function JT(n,e){if(!_t(n))return!1;if(e){const t=dn(n);e(qy(n.tr,t,t.bottom))}return!0}function GT(n,{map:e,table:t,tableStart:i},r){let s=0;for(let c=0;c<r;c++)s+=t.child(c).nodeSize;const o=s+t.child(r).nodeSize,l=n.mapping.maps.length;n.delete(s+i,o+i);const a=new Set;for(let c=0,h=r*e.width;c<e.width;c++,h++){const u=e.map[h];if(!a.has(u)){if(a.add(u),r>0&&u==e.map[h-e.width]){const f=t.nodeAt(u).attrs;n.setNodeMarkup(n.mapping.slice(l).map(u+i),null,{...f,rowspan:f.rowspan-1}),c+=f.colspan-1}else if(r<e.height&&u==e.map[h+e.width]){const f=t.nodeAt(u),d=f.attrs,p=f.type.create({...d,rowspan:f.attrs.rowspan-1},f.content),m=e.positionAt(r+1,c,t);n.insert(n.mapping.slice(l).map(i+m),p),c+=d.colspan-1}}}}function YT(n,e){if(!_t(n))return!1;if(e){const t=dn(n),i=n.tr;if(t.top==0&&t.bottom==t.map.height)return!1;for(let r=t.bottom-1;GT(i,t,r),r!=t.top;r--){const s=t.tableStart?i.doc.nodeAt(t.tableStart-1):i.doc;if(!s)throw new RangeError("No table found");t.table=s,t.map=we.get(t.table)}e(i)}return!0}function op(n){const e=n.content;return e.childCount==1&&e.child(0).isTextblock&&e.child(0).childCount==0}function XT({width:n,height:e,map:t},i){let r=i.top*n+i.left,s=r,o=(i.bottom-1)*n+i.left,l=r+(i.right-i.left-1);for(let a=i.top;a<i.bottom;a++){if(i.left>0&&t[s]==t[s-1]||i.right<n&&t[l]==t[l+1])return!0;s+=n,l+=n}for(let a=i.left;a<i.right;a++){if(i.top>0&&t[r]==t[r-n]||i.bottom<e&&t[o]==t[o+n])return!0;r++,o++}return!1}function lp(n,e){const t=n.selection;if(!(t instanceof ce)||t.$anchorCell.pos==t.$headCell.pos)return!1;const i=dn(n),{map:r}=i;if(XT(r,i))return!1;if(e){const s=n.tr,o={};let l=A.empty,a,c;for(let h=i.top;h<i.bottom;h++)for(let u=i.left;u<i.right;u++){const f=r.map[h*r.width+u],d=i.table.nodeAt(f);if(!(o[f]||!d))if(o[f]=!0,a==null)a=f,c=d;else{op(d)||(l=l.append(d.content));const p=s.mapping.map(f+i.tableStart);s.delete(p,p+d.nodeSize)}}if(a==null||c==null)return!0;if(s.setNodeMarkup(a+i.tableStart,null,{...Vy(c.attrs,c.attrs.colspan,i.right-i.left-c.attrs.colspan),rowspan:i.bottom-i.top}),l.size>0){const h=a+1+c.content.size,u=op(c)?a+1:h;s.replaceWith(u+i.tableStart,h+i.tableStart,l)}s.setSelection(new ce(s.doc.resolve(a+i.tableStart))),e(s)}return!0}function ap(n,e){const t=Je(n.schema);return QT(({node:i})=>t[i.type.spec.tableRole])(n,e)}function QT(n){return(e,t)=>{const i=e.selection;let r,s;if(i instanceof ce){if(i.$anchorCell.pos!=i.$headCell.pos)return!1;r=i.$anchorCell.nodeAfter,s=i.$anchorCell.pos}else{var o;if(r=DT(i.$from),!r)return!1;s=(o=Di(i.$from))===null||o===void 0?void 0:o.pos}if(r==null||s==null||r.attrs.colspan==1&&r.attrs.rowspan==1)return!1;if(t){let l=r.attrs;const a=[],c=l.colwidth;l.rowspan>1&&(l={...l,rowspan:1}),l.colspan>1&&(l={...l,colspan:1});const h=dn(e),u=e.tr;for(let d=0;d<h.right-h.left;d++)a.push(c?{...l,colwidth:c&&c[d]?[c[d]]:null}:l);let f;for(let d=h.top;d<h.bottom;d++){let p=h.map.positionAt(d,h.left,h.table);d==h.top&&(p+=r.nodeSize);for(let m=h.left,g=0;m<h.right;m++,g++)m==h.left&&d==h.top||u.insert(f=u.mapping.map(p+h.tableStart,1),n({node:r,row:d,col:m}).createAndFill(a[g]))}u.setNodeMarkup(s,n({node:r,row:h.top,col:h.left}),a[0]),i instanceof ce&&u.setSelection(new ce(u.doc.resolve(i.$anchorCell.pos),f?u.doc.resolve(f):void 0)),t(u)}return!0}}function ZT(n,e){return function(t,i){if(!_t(t))return!1;const r=ba(t);if(r.nodeAfter.attrs[n]===e)return!1;if(i){const s=t.tr;t.selection instanceof ce?t.selection.forEachCell((o,l)=>{o.attrs[n]!==e&&s.setNodeMarkup(l,null,{...o.attrs,[n]:e})}):s.setNodeMarkup(r.pos,null,{...r.nodeAfter.attrs,[n]:e}),i(s)}return!0}}function eA(n){return function(e,t){if(!_t(e))return!1;if(t){const i=Je(e.schema),r=dn(e),s=e.tr,o=r.map.cellsInRect(n=="column"?{left:r.left,top:0,right:r.right,bottom:r.map.height}:n=="row"?{left:0,top:r.top,right:r.map.width,bottom:r.bottom}:r),l=o.map(a=>r.table.nodeAt(a));for(let a=0;a<o.length;a++)l[a].type==i.header_cell&&s.setNodeMarkup(r.tableStart+o[a],i.cell,l[a].attrs);if(s.steps.length===0)for(let a=0;a<o.length;a++)s.setNodeMarkup(r.tableStart+o[a],i.header_cell,l[a].attrs);t(s)}return!0}}function cp(n,e,t){const i=e.map.cellsInRect({left:0,top:0,right:n=="row"?e.map.width:1,bottom:n=="column"?e.map.height:1});for(let r=0;r<i.length;r++){const s=e.table.nodeAt(i[r]);if(s&&s.type!==t.header_cell)return!1}return!0}function ks(n,e){return e=e||{useDeprecatedLogic:!1},e.useDeprecatedLogic?eA(n):function(t,i){if(!_t(t))return!1;if(i){const r=Je(t.schema),s=dn(t),o=t.tr,l=cp("row",s,r),a=cp("column",s,r),c=(n==="column"?l:n==="row"&&a)?1:0,h=n=="column"?{left:0,top:c,right:1,bottom:s.map.height}:n=="row"?{left:c,top:0,right:s.map.width,bottom:1}:s,u=n=="column"?a?r.cell:r.header_cell:n=="row"?l?r.cell:r.header_cell:r.cell;s.map.cellsInRect(h).forEach(f=>{const d=f+s.tableStart,p=o.doc.nodeAt(d);p&&o.setNodeMarkup(d,u,p.attrs)}),i(o)}return!0}}ks("row",{useDeprecatedLogic:!0});ks("column",{useDeprecatedLogic:!0});const tA=ks("cell",{useDeprecatedLogic:!0});function nA(n,e){if(e<0){const t=n.nodeBefore;if(t)return n.pos-t.nodeSize;for(let i=n.index(-1)-1,r=n.before();i>=0;i--){const s=n.node(-1).child(i),o=s.lastChild;if(o)return r-1-o.nodeSize;r-=s.nodeSize}}else{if(n.index()<n.parent.childCount-1)return n.pos+n.nodeAfter.nodeSize;const t=n.node(-1);for(let i=n.indexAfter(-1),r=n.after();i<t.childCount;i++){const s=t.child(i);if(s.childCount)return r+1;r+=s.nodeSize}}return null}function hp(n){return function(e,t){if(!_t(e))return!1;const i=nA(ba(e),n);if(i==null)return!1;if(t){const r=e.doc.resolve(i);t(e.tr.setSelection(_.between(r,IT(r))).scrollIntoView())}return!0}}function iA(n,e){const t=n.selection.$anchor;for(let i=t.depth;i>0;i--)if(t.node(i).type.spec.tableRole=="table")return e&&e(n.tr.delete(t.before(i),t.after(i)).scrollIntoView()),!0;return!1}function no(n,e){const t=n.selection;if(!(t instanceof ce))return!1;if(e){const i=n.tr,r=Je(n.schema).cell.createAndFill().content;t.forEachCell((s,o)=>{s.content.eq(r)||i.replace(i.mapping.map(o+1),i.mapping.map(o+s.nodeSize-1),new I(r,0,0))}),i.docChanged&&e(i)}return!0}function rA(n){if(n.size===0)return null;let{content:e,openStart:t,openEnd:i}=n;for(;e.childCount==1&&(t>0&&i>0||e.child(0).type.spec.tableRole=="table");)t--,i--,e=e.child(0).content;const r=e.child(0),s=r.type.spec.tableRole,o=r.type.schema,l=[];if(s=="row")for(let a=0;a<e.childCount;a++){let c=e.child(a).content;const h=a?0:Math.max(0,t-1),u=a<e.childCount-1?0:Math.max(0,i-1);(h||u)&&(c=ah(Je(o).row,new I(c,h,u)).content),l.push(c)}else if(s=="cell"||s=="header_cell")l.push(t||i?ah(Je(o).row,new I(e,t,i)).content:e);else return null;return sA(o,l)}function sA(n,e){const t=[];for(let r=0;r<e.length;r++){const s=e[r];for(let o=s.childCount-1;o>=0;o--){const{rowspan:l,colspan:a}=s.child(o).attrs;for(let c=r;c<r+l;c++)t[c]=(t[c]||0)+a}}let i=0;for(let r=0;r<t.length;r++)i=Math.max(i,t[r]);for(let r=0;r<t.length;r++)if(r>=e.length&&e.push(A.empty),t[r]<i){const s=Je(n).cell.createAndFill(),o=[];for(let l=t[r];l<i;l++)o.push(s);e[r]=e[r].append(A.from(o))}return{height:e.length,width:i,rows:e}}function ah(n,e){const t=n.createAndFill();return new mu(t).replace(0,t.content.size,e).doc}function oA({width:n,height:e,rows:t},i,r){if(n!=i){const s=[],o=[];for(let l=0;l<t.length;l++){const a=t[l],c=[];for(let h=s[l]||0,u=0;h<i;u++){let f=a.child(u%a.childCount);h+f.attrs.colspan>i&&(f=f.type.createChecked(Ni(f.attrs,f.attrs.colspan,h+f.attrs.colspan-i),f.content)),c.push(f),h+=f.attrs.colspan;for(let d=1;d<f.attrs.rowspan;d++)s[l+d]=(s[l+d]||0)+f.attrs.colspan}o.push(A.from(c))}t=o,n=i}if(e!=r){const s=[];for(let o=0,l=0;o<r;o++,l++){const a=[],c=t[l%e];for(let h=0;h<c.childCount;h++){let u=c.child(h);o+u.attrs.rowspan>r&&(u=u.type.create({...u.attrs,rowspan:Math.max(1,r-u.attrs.rowspan)},u.content)),a.push(u)}s.push(A.from(a))}t=s,e=r}return{width:n,height:e,rows:t}}function lA(n,e,t,i,r,s,o){const l=n.doc.type.schema,a=Je(l);let c,h;if(r>e.width)for(let u=0,f=0;u<e.height;u++){const d=t.child(u);f+=d.nodeSize;const p=[];let m;d.lastChild==null||d.lastChild.type==a.cell?m=c||(c=a.cell.createAndFill()):m=h||(h=a.header_cell.createAndFill());for(let g=e.width;g<r;g++)p.push(m);n.insert(n.mapping.slice(o).map(f-1+i),p)}if(s>e.height){const u=[];for(let p=0,m=(e.height-1)*e.width;p<Math.max(e.width,r);p++){const g=p>=e.width?!1:t.nodeAt(e.map[m+p]).type==a.header_cell;u.push(g?h||(h=a.header_cell.createAndFill()):c||(c=a.cell.createAndFill()))}const f=a.row.create(null,A.from(u)),d=[];for(let p=e.height;p<s;p++)d.push(f);n.insert(n.mapping.slice(o).map(i+t.nodeSize-2),d)}return!!(c||h)}function up(n,e,t,i,r,s,o,l){if(o==0||o==e.height)return!1;let a=!1;for(let c=r;c<s;c++){const h=o*e.width+c,u=e.map[h];if(e.map[h-e.width]==u){a=!0;const f=t.nodeAt(u),{top:d,left:p}=e.findCell(u);n.setNodeMarkup(n.mapping.slice(l).map(u+i),null,{...f.attrs,rowspan:o-d}),n.insert(n.mapping.slice(l).map(e.positionAt(o,p,t)),f.type.createAndFill({...f.attrs,rowspan:d+f.attrs.rowspan-o})),c+=f.attrs.colspan-1}}return a}function fp(n,e,t,i,r,s,o,l){if(o==0||o==e.width)return!1;let a=!1;for(let c=r;c<s;c++){const h=c*e.width+o,u=e.map[h];if(e.map[h-1]==u){a=!0;const f=t.nodeAt(u),d=e.colCount(u),p=n.mapping.slice(l).map(u+i);n.setNodeMarkup(p,null,Ni(f.attrs,o-d,f.attrs.colspan-(o-d))),n.insert(p+f.nodeSize,f.type.createAndFill(Ni(f.attrs,0,o-d))),c+=f.attrs.rowspan-1}}return a}function dp(n,e,t,i,r){let s=t?n.doc.nodeAt(t-1):n.doc;if(!s)throw new Error("No table found");let o=we.get(s);const{top:l,left:a}=i,c=a+r.width,h=l+r.height,u=n.tr;let f=0;function d(){if(s=t?u.doc.nodeAt(t-1):u.doc,!s)throw new Error("No table found");o=we.get(s),f=u.mapping.maps.length}lA(u,o,s,t,c,h,f)&&d(),up(u,o,s,t,a,c,l,f)&&d(),up(u,o,s,t,a,c,h,f)&&d(),fp(u,o,s,t,l,h,a,f)&&d(),fp(u,o,s,t,l,h,c,f)&&d();for(let p=l;p<h;p++){const m=o.positionAt(p,a,s),g=o.positionAt(p,c,s);u.replace(u.mapping.slice(f).map(m+t),u.mapping.slice(f).map(g+t),new I(r.rows[p-l],0,0))}d(),u.setSelection(new ce(u.doc.resolve(t+o.positionAt(l,a,s)),u.doc.resolve(t+o.positionAt(h-1,c-1,s)))),e(u)}const aA=Ru({ArrowLeft:io("horiz",-1),ArrowRight:io("horiz",1),ArrowUp:io("vert",-1),ArrowDown:io("vert",1),"Shift-ArrowLeft":ro("horiz",-1),"Shift-ArrowRight":ro("horiz",1),"Shift-ArrowUp":ro("vert",-1),"Shift-ArrowDown":ro("vert",1),Backspace:no,"Mod-Backspace":no,Delete:no,"Mod-Delete":no});function Bo(n,e,t){return t.eq(n.selection)?!1:(e&&e(n.tr.setSelection(t).scrollIntoView()),!0)}function io(n,e){return(t,i,r)=>{if(!r)return!1;const s=t.selection;if(s instanceof ce)return Bo(t,i,U.near(s.$headCell,e));if(n!="horiz"&&!s.empty)return!1;const o=Ky(r,n,e);if(o==null)return!1;if(n=="horiz")return Bo(t,i,U.near(t.doc.resolve(s.head+e),e));{const l=t.doc.resolve(o),a=$y(l,n,e);let c;return a?c=U.near(a,1):e<0?c=U.near(t.doc.resolve(l.before(-1)),-1):c=U.near(t.doc.resolve(l.after(-1)),1),Bo(t,i,c)}}}function ro(n,e){return(t,i,r)=>{if(!r)return!1;const s=t.selection;let o;if(s instanceof ce)o=s;else{const a=Ky(r,n,e);if(a==null)return!1;o=new ce(t.doc.resolve(a))}const l=$y(o.$headCell,n,e);return l?Bo(t,i,new ce(o.$anchorCell,l)):!1}}function cA(n,e){const t=n.state.doc,i=Di(t.resolve(e));return i?(n.dispatch(n.state.tr.setSelection(new ce(i))),!0):!1}function hA(n,e,t){if(!_t(n.state))return!1;let i=rA(t);const r=n.state.selection;if(r instanceof ce){i||(i={width:1,height:1,rows:[A.from(ah(Je(n.state.schema).cell,t))]});const s=r.$anchorCell.node(-1),o=r.$anchorCell.start(-1),l=we.get(s).rectBetween(r.$anchorCell.pos-o,r.$headCell.pos-o);return i=oA(i,l.right-l.left,l.bottom-l.top),dp(n.state,n.dispatch,o,l,i),!0}else if(i){const s=ba(n.state),o=s.start(-1);return dp(n.state,n.dispatch,o,we.get(s.node(-1)).findCell(s.pos-o),i),!0}else return!1}function uA(n,e){var t;if(e.button!=0||e.ctrlKey||e.metaKey)return;const i=pp(n,e.target);let r;if(e.shiftKey&&n.state.selection instanceof ce)s(n.state.selection.$anchorCell,e),e.preventDefault();else if(e.shiftKey&&i&&(r=Di(n.state.selection.$anchor))!=null&&((t=nc(n,e))===null||t===void 0?void 0:t.pos)!=r.pos)s(r,e),e.preventDefault();else if(!i)return;function s(a,c){let h=nc(n,c);const u=Vn.getState(n.state)==null;if(!h||!ju(a,h))if(u)h=a;else return;const f=new ce(a,h);if(u||!n.state.selection.eq(f)){const d=n.state.tr.setSelection(f);u&&d.setMeta(Vn,a.pos),n.dispatch(d)}}function o(){n.root.removeEventListener("mouseup",o),n.root.removeEventListener("dragstart",o),n.root.removeEventListener("mousemove",l),Vn.getState(n.state)!=null&&n.dispatch(n.state.tr.setMeta(Vn,-1))}function l(a){const c=a,h=Vn.getState(n.state);let u;if(h!=null)u=n.state.doc.resolve(h);else if(pp(n,c.target)!=i&&(u=nc(n,e),!u))return o();u&&s(u,c)}n.root.addEventListener("mouseup",o),n.root.addEventListener("dragstart",o),n.root.addEventListener("mousemove",l)}function Ky(n,e,t){if(!(n.state.selection instanceof _))return null;const{$head:i}=n.state.selection;for(let r=i.depth-1;r>=0;r--){const s=i.node(r);if((t<0?i.index(r):i.indexAfter(r))!=(t<0?0:s.childCount))return null;if(s.type.spec.tableRole=="cell"||s.type.spec.tableRole=="header_cell"){const o=i.before(r),l=e=="vert"?t>0?"down":"up":t>0?"right":"left";return n.endOfTextblock(l)?o:null}}return null}function pp(n,e){for(;e&&e!=n.dom;e=e.parentNode)if(e.nodeName=="TD"||e.nodeName=="TH")return e;return null}function nc(n,e){const t=n.posAtCoords({left:e.clientX,top:e.clientY});if(!t)return null;let{inside:i,pos:r}=t;return i>=0&&Di(n.state.doc.resolve(i))||Di(n.state.doc.resolve(r))}var fA=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")),ch(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type!=this.node.type?!1:(this.node=e,ch(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return e.type=="attributes"&&(e.target==this.table||this.colgroup.contains(e.target))}};function ch(n,e,t,i,r,s){let o=0,l=!0,a=e.firstChild;const c=n.firstChild;if(c){for(let u=0,f=0;u<c.childCount;u++){const{colspan:d,colwidth:p}=c.child(u).attrs;for(let m=0;m<d;m++,f++){const g=r==f?s:p&&p[m],y=g?g+"px":"";if(o+=g||i,g||(l=!1),a)a.style.width!=y&&(a.style.width=y),a=a.nextSibling;else{const b=document.createElement("col");b.style.width=y,e.appendChild(b)}}}for(;a;){var h;const u=a.nextSibling;(h=a.parentNode)===null||h===void 0||h.removeChild(a),a=u}l?(t.style.width=o+"px",t.style.minWidth=""):(t.style.width="",t.style.minWidth=o+"px")}}const bt=new me("tableColumnResizing");function dA({handleWidth:n=5,cellMinWidth:e=25,defaultCellMinWidth:t=100,View:i=fA,lastColumnResizable:r=!0}={}){const s=new se({key:bt,state:{init(o,l){var a;const c=(a=s.spec)===null||a===void 0||(a=a.props)===null||a===void 0?void 0:a.nodeViews,h=Je(l.schema).table.name;return i&&c&&(c[h]=(u,f)=>new i(u,t,f)),new pA(-1,!1)},apply(o,l){return l.apply(o)}},props:{attributes:o=>{const l=bt.getState(o);return l&&l.activeHandle>-1?{class:"resize-cursor"}:{}},handleDOMEvents:{mousemove:(o,l)=>{mA(o,l,n,r)},mouseleave:o=>{gA(o)},mousedown:(o,l)=>{yA(o,l,e,t)}},decorations:o=>{const l=bt.getState(o);if(l&&l.activeHandle>-1)return vA(o,l.activeHandle)},nodeViews:{}}});return s}var pA=class zo{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(e){const t=this,i=e.getMeta(bt);if(i&&i.setHandle!=null)return new zo(i.setHandle,!1);if(i&&i.setDragging!==void 0)return new zo(t.activeHandle,i.setDragging);if(t.activeHandle>-1&&e.docChanged){let r=e.mapping.map(t.activeHandle,-1);return lh(e.doc.resolve(r))||(r=-1),new zo(r,t.dragging)}return t}};function mA(n,e,t,i){if(!n.editable)return;const r=bt.getState(n.state);if(r&&!r.dragging){const s=xA(e.target);let o=-1;if(s){const{left:l,right:a}=s.getBoundingClientRect();e.clientX-l<=t?o=mp(n,e,"left",t):a-e.clientX<=t&&(o=mp(n,e,"right",t))}if(o!=r.activeHandle){if(!i&&o!==-1){const l=n.state.doc.resolve(o),a=l.node(-1),c=we.get(a),h=l.start(-1);if(c.colCount(l.pos-h)+l.nodeAfter.attrs.colspan-1==c.width-1)return}Jy(n,o)}}}function gA(n){if(!n.editable)return;const e=bt.getState(n.state);e&&e.activeHandle>-1&&!e.dragging&&Jy(n,-1)}function yA(n,e,t,i){var r;if(!n.editable)return!1;const s=(r=n.dom.ownerDocument.defaultView)!==null&&r!==void 0?r:window,o=bt.getState(n.state);if(!o||o.activeHandle==-1||o.dragging)return!1;const l=n.state.doc.nodeAt(o.activeHandle),a=bA(n,o.activeHandle,l.attrs);n.dispatch(n.state.tr.setMeta(bt,{setDragging:{startX:e.clientX,startWidth:a}}));function c(u){s.removeEventListener("mouseup",c),s.removeEventListener("mousemove",h);const f=bt.getState(n.state);f?.dragging&&(wA(n,f.activeHandle,gp(f.dragging,u,t)),n.dispatch(n.state.tr.setMeta(bt,{setDragging:null})))}function h(u){if(!u.which)return c(u);const f=bt.getState(n.state);if(f&&f.dragging){const d=gp(f.dragging,u,t);yp(n,f.activeHandle,d,i)}}return yp(n,o.activeHandle,a,i),s.addEventListener("mouseup",c),s.addEventListener("mousemove",h),e.preventDefault(),!0}function bA(n,e,{colspan:t,colwidth:i}){const r=i&&i[i.length-1];if(r)return r;const s=n.domAtPos(e);let o=s.node.childNodes[s.offset].offsetWidth,l=t;if(i)for(let a=0;a<t;a++)i[a]&&(o-=i[a],l--);return o/l}function xA(n){for(;n&&n.nodeName!="TD"&&n.nodeName!="TH";)n=n.classList&&n.classList.contains("ProseMirror")?null:n.parentNode;return n}function mp(n,e,t,i){const r=t=="right"?-i:i,s=n.posAtCoords({left:e.clientX+r,top:e.clientY});if(!s)return-1;const{pos:o}=s,l=Di(n.state.doc.resolve(o));if(!l)return-1;if(t=="right")return l.pos;const a=we.get(l.node(-1)),c=l.start(-1),h=a.map.indexOf(l.pos-c);return h%a.width==0?-1:c+a.map[h-1]}function gp(n,e,t){const i=e.clientX-n.startX;return Math.max(t,n.startWidth+i)}function Jy(n,e){n.dispatch(n.state.tr.setMeta(bt,{setHandle:e}))}function wA(n,e,t){const i=n.state.doc.resolve(e),r=i.node(-1),s=we.get(r),o=i.start(-1),l=s.colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,a=n.state.tr;for(let c=0;c<s.height;c++){const h=c*s.width+l;if(c&&s.map[h]==s.map[h-s.width])continue;const u=s.map[h],f=r.nodeAt(u).attrs,d=f.colspan==1?0:l-s.colCount(u);if(f.colwidth&&f.colwidth[d]==t)continue;const p=f.colwidth?f.colwidth.slice():kA(f.colspan);p[d]=t,a.setNodeMarkup(o+u,null,{...f,colwidth:p})}a.docChanged&&n.dispatch(a)}function yp(n,e,t,i){const r=n.state.doc.resolve(e),s=r.node(-1),o=r.start(-1),l=we.get(s).colCount(r.pos-o)+r.nodeAfter.attrs.colspan-1;let a=n.domAtPos(r.start(-1)).node;for(;a&&a.nodeName!="TABLE";)a=a.parentNode;a&&ch(s,a.firstChild,a,i,l,t)}function kA(n){return Array(n).fill(0)}function vA(n,e){const t=[],i=n.doc.resolve(e),r=i.node(-1);if(!r)return ue.empty;const s=we.get(r),o=i.start(-1),l=s.colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1;for(let c=0;c<s.height;c++){const h=l+c*s.width;if((l==s.width-1||s.map[h]!=s.map[h+1])&&(c==0||s.map[h]!=s.map[h-s.width])){var a;const u=s.map[h],f=o+u+r.nodeAt(u).nodeSize-1,d=document.createElement("div");d.className="column-resize-handle",!((a=bt.getState(n))===null||a===void 0)&&a.dragging&&t.push(kt.node(o+u,o+u+r.nodeAt(u).nodeSize,{class:"column-resize-dragging"})),t.push(kt.widget(f,d))}}return ue.create(n.doc,t)}function SA({allowTableNodeSelection:n=!1}={}){return new se({key:Vn,state:{init(){return null},apply(e,t){const i=e.getMeta(Vn);if(i!=null)return i==-1?null:i;if(t==null||!e.docChanged)return t;const{deleted:r,pos:s}=e.mapping.mapResult(t);return r?null:s}},props:{decorations:BT,handleDOMEvents:{mousedown:uA},createSelectionBetween(e){return Vn.getState(e.state)!=null?e.state.selection:null},handleTripleClick:cA,handleKeyDown:aA,handlePaste:hA},appendTransaction(e,t,i){return FT(i,_y(i,t),n)}})}function CA(n,e){const t=Math.min(n.top,e.top),i=Math.max(n.bottom,e.bottom),r=Math.min(n.left,e.left),o=Math.max(n.right,e.right)-r,l=i-t,a=r,c=t;return new DOMRect(a,c,o,l)}var MA=class{constructor({editor:n,element:e,view:t,updateDelay:i=250,resizeDelay:r=60,shouldShow:s,appendTo:o,getReferencedVirtualElement:l,options:a}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.floatingUIOptions={strategy:"absolute",placement:"top",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1,onShow:void 0,onHide:void 0,onUpdate:void 0,onDestroy:void 0},this.shouldShow=({view:h,state:u,from:f,to:d})=>{const{doc:p,selection:m}=u,{empty:g}=m,y=!p.textBetween(f,d).length&&Lu(u.selection),b=this.element.contains(document.activeElement);return!(!(h.hasFocus()||b)||g||y||!this.editor.isEditable)},this.mousedownHandler=()=>{this.preventHide=!0},this.dragstartHandler=()=>{this.hide()},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:h})=>{var u;if(this.editor.isDestroyed){this.destroy();return}if(this.preventHide){this.preventHide=!1;return}h?.relatedTarget&&((u=this.element.parentNode)!=null&&u.contains(h.relatedTarget))||h?.relatedTarget!==this.editor.view.dom&&this.hide()},this.handleDebouncedUpdate=(h,u)=>{const f=!u?.selection.eq(h.state.selection),d=!u?.doc.eq(h.state.doc);!f&&!d||(this.updateDebounceTimer&&clearTimeout(this.updateDebounceTimer),this.updateDebounceTimer=window.setTimeout(()=>{this.updateHandler(h,f,d,u)},this.updateDelay))},this.updateHandler=(h,u,f,d)=>{const{composing:p}=h;if(p||!u&&!f)return;if(!this.getShouldShow(d)){this.hide();return}this.updatePosition(),this.show()},this.transactionHandler=({transaction:h})=>{const u=h.getMeta("bubbleMenu");u==="updatePosition"?this.updatePosition():u&&typeof u=="object"&&u.type==="updateOptions"&&this.updateOptions(u.options)};var c;this.editor=n,this.element=e,this.view=t,this.updateDelay=i,this.resizeDelay=r,this.appendTo=o,this.scrollTarget=(c=a?.scrollTarget)!=null?c:window,this.getReferencedVirtualElement=l,this.floatingUIOptions={...this.floatingUIOptions,...a},this.element.tabIndex=0,s&&(this.shouldShow=s),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.addEventListener("dragstart",this.dragstartHandler),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(t,t.state),this.getShouldShow()&&(this.show(),this.updatePosition())}get middlewares(){const n=[];return this.floatingUIOptions.flip&&n.push(bg(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&n.push(xg(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&n.push(wg(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&n.push(kg(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&n.push(vg(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&n.push(Sg(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&n.push(Cg(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&n.push(Mg(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),n}get virtualElement(){var n,e,t;const{selection:i}=this.editor.state,r=(n=this.getReferencedVirtualElement)==null?void 0:n.call(this);if(r)return r;if(!((t=(e=this.view)==null?void 0:e.dom)!=null&&t.parentNode))return;const s=vy(this.view,i.from,i.to);let o={getBoundingClientRect:()=>s,getClientRects:()=>[s]};if(i instanceof W){let l=this.view.nodeDOM(i.from);const a=l.dataset.nodeViewWrapper?l:l.querySelector("[data-node-view-wrapper]");a&&(l=a),l&&(o={getBoundingClientRect:()=>l.getBoundingClientRect(),getClientRects:()=>[l.getBoundingClientRect()]})}if(i instanceof ce){const{$anchorCell:l,$headCell:a}=i,c=l?l.pos:a.pos,h=a?a.pos:l.pos,u=this.view.nodeDOM(c),f=this.view.nodeDOM(h);if(!u||!f)return;const d=u===f?u.getBoundingClientRect():CA(u.getBoundingClientRect(),f.getBoundingClientRect());o={getBoundingClientRect:()=>d,getClientRects:()=>[d]}}return o}updatePosition(){const n=this.virtualElement;n&&Tg(n,this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:e,y:t,strategy:i,middlewareData:r})=>{var s,o;if((s=r.hide)!=null&&s.referenceHidden||(o=r.hide)!=null&&o.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=i,this.element.style.left=`${e}px`,this.element.style.top=`${t}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(n,e){const{state:t}=n,i=t.selection.from!==t.selection.to;if(this.updateDelay>0&&i){this.handleDebouncedUpdate(n,e);return}const r=!e?.selection.eq(n.state.selection),s=!e?.doc.eq(n.state.doc);this.updateHandler(n,r,s,e)}getShouldShow(n){var e;const{state:t}=this.view,{selection:i}=t,{ranges:r}=i,s=Math.min(...r.map(a=>a.$from.pos)),o=Math.max(...r.map(a=>a.$to.pos));return((e=this.shouldShow)==null?void 0:e.call(this,{editor:this.editor,element:this.element,view:this.view,state:t,oldState:n,from:s,to:o}))||!1}show(){var n;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const e=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(n=e??this.view.dom.parentElement)==null||n.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}updateOptions(n){var e;if(n.updateDelay!==void 0&&(this.updateDelay=n.updateDelay),n.resizeDelay!==void 0&&(this.resizeDelay=n.resizeDelay),n.appendTo!==void 0&&(this.appendTo=n.appendTo),n.getReferencedVirtualElement!==void 0&&(this.getReferencedVirtualElement=n.getReferencedVirtualElement),n.shouldShow!==void 0&&n.shouldShow&&(this.shouldShow=n.shouldShow),n.options!==void 0){const t=(e=n.options.scrollTarget)!=null?e:window;t!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=t,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...n.options}}}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.view.dom.removeEventListener("dragstart",this.dragstartHandler),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Gy=n=>new se({key:typeof n.pluginKey=="string"?new me(n.pluginKey):n.pluginKey,view:e=>new MA({view:e,...n})});fe.create({name:"bubbleMenu",addOptions(){return{element:null,pluginKey:"bubbleMenu",updateDelay:void 0,appendTo:void 0,shouldShow:null}},addProseMirrorPlugins(){return this.options.element?[Gy({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,options:this.options.options,appendTo:this.options.appendTo,getReferencedVirtualElement:this.options.getReferencedVirtualElement,shouldShow:this.options.shouldShow})]:[]}});var TA=class{constructor({editor:n,element:e,view:t,updateDelay:i=250,resizeDelay:r=60,options:s,appendTo:o,shouldShow:l}){this.preventHide=!1,this.isVisible=!1,this.scrollTarget=window,this.shouldShow=({view:c,state:h})=>{const{selection:u}=h,{$anchor:f,empty:d}=u,p=f.depth===1,m=f.parent.isTextblock&&!f.parent.type.spec.code&&!f.parent.textContent&&f.parent.childCount===0&&!this.getTextContent(f.parent);return!(!c.hasFocus()||!d||!p||!m||!this.editor.isEditable)},this.floatingUIOptions={strategy:"absolute",placement:"right",offset:8,flip:{},shift:{},arrow:!1,size:!1,autoPlacement:!1,hide:!1,inline:!1},this.updateHandler=(c,h,u,f)=>{const{composing:d}=c;if(d||!h&&!u)return;if(!this.getShouldShow(f)){this.hide();return}this.updatePosition(),this.show()},this.mousedownHandler=()=>{this.preventHide=!0},this.focusHandler=()=>{setTimeout(()=>this.update(this.editor.view))},this.blurHandler=({event:c})=>{var h;if(this.preventHide){this.preventHide=!1;return}c?.relatedTarget&&((h=this.element.parentNode)!=null&&h.contains(c.relatedTarget))||c?.relatedTarget!==this.editor.view.dom&&this.hide()},this.transactionHandler=({transaction:c})=>{const h=c.getMeta("floatingMenu");h==="updatePosition"?this.updatePosition():h&&typeof h=="object"&&h.type==="updateOptions"&&this.updateOptions(h.options)},this.resizeHandler=()=>{this.resizeDebounceTimer&&clearTimeout(this.resizeDebounceTimer),this.resizeDebounceTimer=window.setTimeout(()=>{this.updatePosition()},this.resizeDelay)};var a;this.editor=n,this.element=e,this.view=t,this.updateDelay=i,this.resizeDelay=r,this.appendTo=o,this.scrollTarget=(a=s?.scrollTarget)!=null?a:window,this.floatingUIOptions={...this.floatingUIOptions,...s},this.element.tabIndex=0,l&&(this.shouldShow=l),this.element.addEventListener("mousedown",this.mousedownHandler,{capture:!0}),this.editor.on("focus",this.focusHandler),this.editor.on("blur",this.blurHandler),this.editor.on("transaction",this.transactionHandler),window.addEventListener("resize",this.resizeHandler),this.scrollTarget.addEventListener("scroll",this.resizeHandler),this.update(t,t.state),this.getShouldShow()&&(this.show(),this.updatePosition())}getTextContent(n){return gy(n,{textSerializers:zu(this.editor.schema)})}get middlewares(){const n=[];return this.floatingUIOptions.flip&&n.push(bg(typeof this.floatingUIOptions.flip!="boolean"?this.floatingUIOptions.flip:void 0)),this.floatingUIOptions.shift&&n.push(xg(typeof this.floatingUIOptions.shift!="boolean"?this.floatingUIOptions.shift:void 0)),this.floatingUIOptions.offset&&n.push(wg(typeof this.floatingUIOptions.offset!="boolean"?this.floatingUIOptions.offset:void 0)),this.floatingUIOptions.arrow&&n.push(kg(this.floatingUIOptions.arrow)),this.floatingUIOptions.size&&n.push(vg(typeof this.floatingUIOptions.size!="boolean"?this.floatingUIOptions.size:void 0)),this.floatingUIOptions.autoPlacement&&n.push(Sg(typeof this.floatingUIOptions.autoPlacement!="boolean"?this.floatingUIOptions.autoPlacement:void 0)),this.floatingUIOptions.hide&&n.push(Cg(typeof this.floatingUIOptions.hide!="boolean"?this.floatingUIOptions.hide:void 0)),this.floatingUIOptions.inline&&n.push(Mg(typeof this.floatingUIOptions.inline!="boolean"?this.floatingUIOptions.inline:void 0)),n}getShouldShow(n){var e;const{state:t}=this.view,{selection:i}=t,{ranges:r}=i,s=Math.min(...r.map(a=>a.$from.pos)),o=Math.max(...r.map(a=>a.$to.pos));return(e=this.shouldShow)==null?void 0:e.call(this,{editor:this.editor,view:this.view,state:t,oldState:n,from:s,to:o})}updateOptions(n){var e;if(n.updateDelay!==void 0&&(this.updateDelay=n.updateDelay),n.resizeDelay!==void 0&&(this.resizeDelay=n.resizeDelay),n.appendTo!==void 0&&(this.appendTo=n.appendTo),n.shouldShow!==void 0&&n.shouldShow&&(this.shouldShow=n.shouldShow),n.options!==void 0){const t=(e=n.options.scrollTarget)!=null?e:window;t!==this.scrollTarget&&(this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.scrollTarget=t,this.scrollTarget.addEventListener("scroll",this.resizeHandler)),this.floatingUIOptions={...this.floatingUIOptions,...n.options}}}updatePosition(){const{selection:n}=this.editor.state,e=vy(this.view,n.from,n.to);Tg({getBoundingClientRect:()=>e,getClientRects:()=>[e]},this.element,{placement:this.floatingUIOptions.placement,strategy:this.floatingUIOptions.strategy,middleware:this.middlewares}).then(({x:i,y:r,strategy:s,middlewareData:o})=>{var l,a;if((l=o.hide)!=null&&l.referenceHidden||(a=o.hide)!=null&&a.escaped){this.element.style.visibility="hidden";return}this.element.style.visibility="visible",this.element.style.width="max-content",this.element.style.position=s,this.element.style.left=`${i}px`,this.element.style.top=`${r}px`,this.isVisible&&this.floatingUIOptions.onUpdate&&this.floatingUIOptions.onUpdate()})}update(n,e){const t=!e?.selection.eq(n.state.selection),i=!e?.doc.eq(n.state.doc);this.updateHandler(n,t,i,e)}show(){var n;if(this.isVisible)return;this.element.style.visibility="visible",this.element.style.opacity="1";const e=typeof this.appendTo=="function"?this.appendTo():this.appendTo;(n=e??this.view.dom.parentElement)==null||n.appendChild(this.element),this.floatingUIOptions.onShow&&this.floatingUIOptions.onShow(),this.isVisible=!0}hide(){this.isVisible&&(this.element.style.visibility="hidden",this.element.style.opacity="0",this.element.remove(),this.floatingUIOptions.onHide&&this.floatingUIOptions.onHide(),this.isVisible=!1)}destroy(){this.hide(),this.element.removeEventListener("mousedown",this.mousedownHandler,{capture:!0}),window.removeEventListener("resize",this.resizeHandler),this.scrollTarget.removeEventListener("scroll",this.resizeHandler),this.editor.off("focus",this.focusHandler),this.editor.off("blur",this.blurHandler),this.editor.off("transaction",this.transactionHandler),this.floatingUIOptions.onDestroy&&this.floatingUIOptions.onDestroy()}},Yy=n=>new se({key:typeof n.pluginKey=="string"?new me(n.pluginKey):n.pluginKey,view:e=>new TA({view:e,...n})});fe.create({name:"floatingMenu",addOptions(){return{element:null,options:{},pluginKey:"floatingMenu",updateDelay:void 0,resizeDelay:void 0,appendTo:void 0,shouldShow:null}},addCommands(){return{updateFloatingMenuPosition:()=>({tr:n,dispatch:e})=>(e&&n.setMeta("floatingMenu","updatePosition"),!0)}},addProseMirrorPlugins(){return this.options.element?[Yy({pluginKey:this.options.pluginKey,editor:this.editor,element:this.options.element,updateDelay:this.options.updateDelay,resizeDelay:this.options.resizeDelay,options:this.options.options,appendTo:this.options.appendTo,shouldShow:this.options.shouldShow})]:[]}});var AA=(...n)=>e=>{n.forEach(t=>{typeof t=="function"?t(e):t&&(t.current=e)})},EA=({contentComponent:n})=>{const e=Eg.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getServerSnapshot);return S.jsx(S.Fragment,{children:Object.values(e)})};function OA(){const n=new Set;let e={};return{subscribe(t){return n.add(t),()=>{n.delete(t)}},getSnapshot(){return e},getServerSnapshot(){return e},setRenderer(t,i){e={...e,[t]:dw.createPortal(i.reactElement,i.element,t)},n.forEach(r=>r())},removeRenderer(t){const i={...e};delete i[t],e=i,n.forEach(r=>r())}}}var RA=class extends En.Component{constructor(n){var e;super(n),this.editorContentRef=En.createRef(),this.initialized=!1,this.state={hasContentComponentInitialized:!!((e=n.editor)!=null&&e.contentComponent)}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){var n;const e=this.props.editor;if(e&&!e.isDestroyed&&((n=e.view.dom)!=null&&n.parentNode)){if(e.contentComponent)return;const t=this.editorContentRef.current;t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t}),e.contentComponent=OA(),this.state.hasContentComponentInitialized||(this.unsubscribeToContentComponent=e.contentComponent.subscribe(()=>{this.setState(i=>i.hasContentComponentInitialized?i:{hasContentComponentInitialized:!0}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent()})),e.createNodeViews(),this.initialized=!0}}componentWillUnmount(){var n;const e=this.props.editor;if(e){this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),this.unsubscribeToContentComponent&&this.unsubscribeToContentComponent(),e.contentComponent=null;try{if(!((n=e.view.dom)!=null&&n.parentNode))return;const t=document.createElement("div");t.append(...e.view.dom.parentNode.childNodes),e.setOptions({element:t})}catch{}}}render(){const{editor:n,innerRef:e,...t}=this.props;return S.jsxs(S.Fragment,{children:[S.jsx("div",{ref:AA(e,this.editorContentRef),...t}),n?.contentComponent&&S.jsx(EA,{contentComponent:n.contentComponent})]})}},DA=M.forwardRef((n,e)=>{const t=En.useMemo(()=>Math.floor(Math.random()*4294967295).toString(),[n.editor]);return En.createElement(RA,{key:t,innerRef:e,...n})}),Xy=En.memo(DA),NA=typeof window<"u"?M.useLayoutEffect:M.useEffect,IA=class{constructor(n){this.transactionNumber=0,this.lastTransactionNumber=0,this.subscribers=new Set,this.editor=n,this.lastSnapshot={editor:n,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(n){return this.subscribers.add(n),()=>{this.subscribers.delete(n)}}watch(n){if(this.editor=n,this.editor){const e=()=>{this.transactionNumber+=1,this.subscribers.forEach(i=>i())},t=this.editor;return t.on("transaction",e),()=>{t.off("transaction",e)}}}};function LA(n){var e;const[t]=M.useState(()=>new IA(n.editor)),i=Lw.useSyncExternalStoreWithSelector(t.subscribe,t.getSnapshot,t.getServerSnapshot,n.selector,(e=n.equalityFn)!=null?e:TT);return NA(()=>t.watch(n.editor),[n.editor,t]),M.useDebugValue(i),i}var PA=!1,hh=typeof window>"u",BA=hh||!!(typeof window<"u"&&window.next),zA=class Qy{constructor(e){this.editor=null,this.subscriptions=new Set,this.isComponentMounted=!1,this.previousDeps=null,this.instanceId="",this.options=e,this.subscriptions=new Set,this.setEditor(this.getInitialEditor()),this.scheduleDestroy(),this.getEditor=this.getEditor.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.refreshEditorInstance=this.refreshEditorInstance.bind(this),this.scheduleDestroy=this.scheduleDestroy.bind(this),this.onRender=this.onRender.bind(this),this.createEditor=this.createEditor.bind(this)}setEditor(e){this.editor=e,this.instanceId=Math.random().toString(36).slice(2,9),this.subscriptions.forEach(t=>t())}getInitialEditor(){return this.options.current.immediatelyRender===void 0?hh||BA?null:this.createEditor():(this.options.current.immediatelyRender,this.options.current.immediatelyRender?this.createEditor():null)}createEditor(){const e={...this.options.current,onBeforeCreate:(...i)=>{var r,s;return(s=(r=this.options.current).onBeforeCreate)==null?void 0:s.call(r,...i)},onBlur:(...i)=>{var r,s;return(s=(r=this.options.current).onBlur)==null?void 0:s.call(r,...i)},onCreate:(...i)=>{var r,s;return(s=(r=this.options.current).onCreate)==null?void 0:s.call(r,...i)},onDestroy:(...i)=>{var r,s;return(s=(r=this.options.current).onDestroy)==null?void 0:s.call(r,...i)},onFocus:(...i)=>{var r,s;return(s=(r=this.options.current).onFocus)==null?void 0:s.call(r,...i)},onSelectionUpdate:(...i)=>{var r,s;return(s=(r=this.options.current).onSelectionUpdate)==null?void 0:s.call(r,...i)},onTransaction:(...i)=>{var r,s;return(s=(r=this.options.current).onTransaction)==null?void 0:s.call(r,...i)},onUpdate:(...i)=>{var r,s;return(s=(r=this.options.current).onUpdate)==null?void 0:s.call(r,...i)},onContentError:(...i)=>{var r,s;return(s=(r=this.options.current).onContentError)==null?void 0:s.call(r,...i)},onDrop:(...i)=>{var r,s;return(s=(r=this.options.current).onDrop)==null?void 0:s.call(r,...i)},onPaste:(...i)=>{var r,s;return(s=(r=this.options.current).onPaste)==null?void 0:s.call(r,...i)},onDelete:(...i)=>{var r,s;return(s=(r=this.options.current).onDelete)==null?void 0:s.call(r,...i)}};return new DM(e)}getEditor(){return this.editor}getServerSnapshot(){return null}subscribe(e){return this.subscriptions.add(e),()=>{this.subscriptions.delete(e)}}static compareOptions(e,t){return Object.keys(e).every(i=>["onCreate","onBeforeCreate","onDestroy","onUpdate","onTransaction","onFocus","onBlur","onSelectionUpdate","onContentError","onDrop","onPaste"].includes(i)?!0:i==="extensions"&&e.extensions&&t.extensions?e.extensions.length!==t.extensions.length?!1:e.extensions.every((r,s)=>{var o;return r===((o=t.extensions)==null?void 0:o[s])}):e[i]===t[i])}onRender(e){return()=>(this.isComponentMounted=!0,clearTimeout(this.scheduledDestructionTimeout),this.editor&&!this.editor.isDestroyed&&e.length===0?Qy.compareOptions(this.options.current,this.editor.options)||this.editor.setOptions({...this.options.current,editable:this.editor.isEditable}):this.refreshEditorInstance(e),()=>{this.isComponentMounted=!1,this.scheduleDestroy()})}refreshEditorInstance(e){if(this.editor&&!this.editor.isDestroyed){if(this.previousDeps===null){this.previousDeps=e;return}if(this.previousDeps.length===e.length&&this.previousDeps.every((i,r)=>i===e[r]))return}this.editor&&!this.editor.isDestroyed&&this.editor.destroy(),this.setEditor(this.createEditor()),this.previousDeps=e}scheduleDestroy(){const e=this.instanceId,t=this.editor;this.scheduledDestructionTimeout=setTimeout(()=>{if(this.isComponentMounted&&this.instanceId===e){t&&t.setOptions(this.options.current);return}t&&!t.isDestroyed&&(t.destroy(),this.instanceId===e&&this.setEditor(null))},1)}};function HA(n={},e=[]){const t=M.useRef(n);t.current=n;const[i]=M.useState(()=>new zA(t)),r=Eg.useSyncExternalStore(i.subscribe,i.getEditor,i.getServerSnapshot);return M.useDebugValue(r),M.useEffect(i.onRender(e)),LA({editor:r,selector:({transactionNumber:s})=>n.shouldRerenderOnTransaction===!1||n.shouldRerenderOnTransaction===void 0?null:n.immediatelyRender&&s===0?0:s+1}),r}var _u=M.createContext({editor:null});_u.Consumer;var Zy=()=>M.useContext(_u),FA=M.createContext({onDragStart:()=>{},nodeViewContentChildren:void 0,nodeViewContentRef:()=>{}}),$A=()=>M.useContext(FA);En.forwardRef((n,e)=>{const{onDragStart:t}=$A(),i=n.as||"div";return S.jsx(i,{...n,ref:e,"data-node-view-wrapper":"",onDragStart:t,style:{whiteSpace:"normal",...n.style}})});En.createContext({markViewContentRef:()=>{}});var VA=En.forwardRef(({pluginKey:n="bubbleMenu",editor:e,updateDelay:t,resizeDelay:i,appendTo:r,shouldShow:s=null,getReferencedVirtualElement:o,options:l,children:a,...c},h)=>{const u=M.useRef(document.createElement("div"));typeof h=="function"?h(u.current):h&&(h.current=u.current);const{editor:f}=Zy(),d=e||f,p={updateDelay:t,resizeDelay:i,appendTo:r,pluginKey:n,shouldShow:s,getReferencedVirtualElement:o,options:l},m=M.useRef(p);m.current=p;const[g,y]=M.useState(!1),b=M.useRef(!0);return M.useEffect(()=>{if(d?.isDestroyed)return;if(!d){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}const x=u.current;x.style.visibility="hidden",x.style.position="absolute";const k=Gy({...m.current,editor:d,element:x});d.registerPlugin(k);const w=m.current.pluginKey;return b.current=!0,y(!0),()=>{y(!1),d.unregisterPlugin(w),window.requestAnimationFrame(()=>{x.parentNode&&x.parentNode.removeChild(x)})}},[d]),M.useEffect(()=>{if(!(!g||!d||d.isDestroyed)){if(b.current){b.current=!1;return}d.view.dispatch(d.state.tr.setMeta("bubbleMenu",{type:"updateOptions",options:m.current}))}},[g,d,t,i,s,l,r,o]),Ag.createPortal(S.jsx("div",{...c,children:a}),u.current)}),WA=En.forwardRef(({pluginKey:n="floatingMenu",editor:e,updateDelay:t,resizeDelay:i,appendTo:r,shouldShow:s=null,options:o,children:l,...a},c)=>{const h=M.useRef(document.createElement("div"));typeof c=="function"?c(h.current):c&&(c.current=h.current);const{editor:u}=Zy(),f=e||u,d={updateDelay:t,resizeDelay:i,appendTo:r,pluginKey:n,shouldShow:s,options:o},p=M.useRef(d);p.current=d;const[m,g]=M.useState(!1),y=M.useRef(!0);return M.useEffect(()=>{if(f?.isDestroyed)return;if(!f){console.warn("FloatingMenu component is not rendered inside of an editor component or does not have editor prop.");return}const b=h.current;b.style.visibility="hidden",b.style.position="absolute";const x=Yy({...p.current,editor:f,element:b});f.registerPlugin(x);const k=p.current.pluginKey;return y.current=!0,g(!0),()=>{g(!1),f.unregisterPlugin(k),window.requestAnimationFrame(()=>{b.parentNode&&b.parentNode.removeChild(b)})}},[f]),M.useEffect(()=>{if(!(!m||!f||f.isDestroyed)){if(y.current){y.current=!1;return}f.view.dispatch(f.state.tr.setMeta("floatingMenu",{type:"updateOptions",options:p.current}))}},[m,f,t,i,s,o,r]),Ag.createPortal(S.jsx("div",{...a,children:l}),h.current)}),Uu=M.createContext({editor:null,isReady:!1});Uu.displayName="TiptapContext";var xa=()=>M.useContext(Uu);function eb({instance:n,children:e}){var t;const[i,r]=M.useState((t=n?.isInitialized)!=null?t:!1);M.useEffect(()=>{if(!n){r(!1);return}if(n.isInitialized){r(!0);return}const l=()=>{r(!0)};return n.on("create",l),()=>{n.off("create",l)}},[n]);const s=M.useMemo(()=>({editor:n,isReady:i}),[n,i]),o=M.useMemo(()=>({editor:n}),[n]);return S.jsx(_u.Provider,{value:o,children:S.jsx(Uu.Provider,{value:s,children:e})})}eb.displayName="Tiptap";function tb({...n}){const{editor:e}=xa();return S.jsx(Xy,{editor:e,...n})}tb.displayName="Tiptap.Content";function nb({children:n}){const{isReady:e}=xa();return e?null:n}nb.displayName="Tiptap.Loading";function ib({children:n,...e}){const{editor:t}=xa();return t?S.jsx(VA,{editor:t,...e,children:n}):null}ib.displayName="Tiptap.BubbleMenu";function rb({children:n,...e}){const{editor:t}=xa();return t?S.jsx(WA,{...e,editor:t,children:n}):null}rb.displayName="Tiptap.FloatingMenu";Object.assign(eb,{Content:tb,Loading:nb,BubbleMenu:ib,FloatingMenu:rb});var rl=(n,e)=>{if(n==="slot")return 0;if(n instanceof Function)return n(e);const{children:t,...i}=e??{};if(n==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[n,i,t]},jA=/^\s*>\s$/,_A=He.create({name:"blockquote",addOptions(){return{HTMLAttributes:{}}},content:"block+",group:"block",defining:!0,parseHTML(){return[{tag:"blockquote"}]},renderHTML({HTMLAttributes:n}){return rl("blockquote",{...pe(this.options.HTMLAttributes,n),children:rl("slot",{})})},parseMarkdown:(n,e)=>e.createNode("blockquote",void 0,e.parseChildren(n.tokens||[])),renderMarkdown:(n,e)=>{if(!n.content)return"";const t=">",i=[];return n.content.forEach(r=>{const l=e.renderChildren([r]).split(`
102
+ `).map(a=>a.trim()===""?t:`${t} ${a}`);i.push(l.join(`
103
+ `))}),i.join(`
104
+ ${t}
105
+ `)},addCommands(){return{setBlockquote:()=>({commands:n})=>n.wrapIn(this.name),toggleBlockquote:()=>({commands:n})=>n.toggleWrap(this.name),unsetBlockquote:()=>({commands:n})=>n.lift(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-b":()=>this.editor.commands.toggleBlockquote()}},addInputRules(){return[pr({find:jA,type:this.type})]}}),UA=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,qA=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,KA=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,JA=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,GA=zi.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return rl("strong",{...pe(this.options.HTMLAttributes,n),children:rl("slot",{})})},markdownTokenName:"strong",parseMarkdown:(n,e)=>e.applyMark("bold",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`**${e.renderChildren(n)}**`,addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[dr({find:UA,type:this.type}),dr({find:KA,type:this.type})]},addPasteRules(){return[Ri({find:qA,type:this.type}),Ri({find:JA,type:this.type})]}}),YA=/(^|[^`])`([^`]+)`(?!`)$/,XA=/(^|[^`])`([^`]+)`(?!`)/g,QA=zi.create({name:"code",addOptions(){return{HTMLAttributes:{}}},excludes:"_",code:!0,exitable:!0,parseHTML(){return[{tag:"code"}]},renderHTML({HTMLAttributes:n}){return["code",pe(this.options.HTMLAttributes,n),0]},markdownTokenName:"codespan",parseMarkdown:(n,e)=>e.applyMark("code",[{type:"text",text:n.text||""}]),renderMarkdown:(n,e)=>n.content?`\`${e.renderChildren(n.content)}\``:"",addCommands(){return{setCode:()=>({commands:n})=>n.setMark(this.name),toggleCode:()=>({commands:n})=>n.toggleMark(this.name),unsetCode:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-e":()=>this.editor.commands.toggleCode()}},addInputRules(){return[dr({find:YA,type:this.type})]},addPasteRules(){return[Ri({find:XA,type:this.type})]}}),ic=4,ZA=/^```([a-z]+)?[\s\n]$/,eE=/^~~~([a-z]+)?[\s\n]$/,tE=He.create({name:"codeBlock",addOptions(){return{languageClassPrefix:"language-",exitOnTripleEnter:!0,exitOnArrowDown:!0,defaultLanguage:null,enableTabIndentation:!1,tabSize:ic,HTMLAttributes:{}}},content:"text*",marks:"",group:"block",code:!0,defining:!0,addAttributes(){return{language:{default:this.options.defaultLanguage,parseHTML:n=>{var e;const{languageClassPrefix:t}=this.options;if(!t)return null;const s=[...((e=n.firstElementChild)==null?void 0:e.classList)||[]].filter(o=>o.startsWith(t)).map(o=>o.replace(t,""))[0];return s||null},rendered:!1}}},parseHTML(){return[{tag:"pre",preserveWhitespace:"full"}]},renderHTML({node:n,HTMLAttributes:e}){return["pre",pe(this.options.HTMLAttributes,e),["code",{class:n.attrs.language?this.options.languageClassPrefix+n.attrs.language:null},0]]},markdownTokenName:"code",parseMarkdown:(n,e)=>{var t;return((t=n.raw)==null?void 0:t.startsWith("```"))===!1&&n.codeBlockStyle!=="indented"?[]:e.createNode("codeBlock",{language:n.lang||null},n.text?[e.createTextNode(n.text)]:[])},renderMarkdown:(n,e)=>{var t;let i="";const r=((t=n.attrs)==null?void 0:t.language)||"";return n.content?i=[`\`\`\`${r}`,e.renderChildren(n.content),"```"].join(`
106
+ `):i=`\`\`\`${r}
107
+
108
+ \`\`\``,i},addCommands(){return{setCodeBlock:n=>({commands:e})=>e.setNode(this.name,n),toggleCodeBlock:n=>({commands:e})=>e.toggleNode(this.name,"paragraph",n)}},addKeyboardShortcuts(){return{"Mod-Alt-c":()=>this.editor.commands.toggleCodeBlock(),Backspace:()=>{const{empty:n,$anchor:e}=this.editor.state.selection,t=e.pos===1;return!n||e.parent.type.name!==this.name?!1:t||!e.parent.textContent.length?this.editor.commands.clearNodes():!1},Tab:({editor:n})=>{var e;if(!this.options.enableTabIndentation)return!1;const t=(e=this.options.tabSize)!=null?e:ic,{state:i}=n,{selection:r}=i,{$from:s,empty:o}=r;if(s.parent.type!==this.type)return!1;const l=" ".repeat(t);return o?n.commands.insertContent(l):n.commands.command(({tr:a})=>{const{from:c,to:h}=r,d=i.doc.textBetween(c,h,`
109
+ `,`
110
+ `).split(`
111
+ `).map(p=>l+p).join(`
112
+ `);return a.replaceWith(c,h,i.schema.text(d)),!0})},"Shift-Tab":({editor:n})=>{var e;if(!this.options.enableTabIndentation)return!1;const t=(e=this.options.tabSize)!=null?e:ic,{state:i}=n,{selection:r}=i,{$from:s,empty:o}=r;return s.parent.type!==this.type?!1:o?n.commands.command(({tr:l})=>{var a;const{pos:c}=s,h=s.start(),u=s.end(),d=i.doc.textBetween(h,u,`
113
+ `,`
114
+ `).split(`
115
+ `);let p=0,m=0;const g=c-h;for(let C=0;C<d.length;C+=1){if(m+d[C].length>=g){p=C;break}m+=d[C].length+1}const b=((a=d[p].match(/^ */))==null?void 0:a[0])||"",x=Math.min(b.length,t);if(x===0)return!0;let k=h;for(let C=0;C<p;C+=1)k+=d[C].length+1;return l.delete(k,k+x),c-k<=x&&l.setSelection(_.create(l.doc,k)),!0}):n.commands.command(({tr:l})=>{const{from:a,to:c}=r,f=i.doc.textBetween(a,c,`
116
+ `,`
117
+ `).split(`
118
+ `).map(d=>{var p;const m=((p=d.match(/^ */))==null?void 0:p[0])||"",g=Math.min(m.length,t);return d.slice(g)}).join(`
119
+ `);return l.replaceWith(a,c,i.schema.text(f)),!0})},Enter:({editor:n})=>{if(!this.options.exitOnTripleEnter)return!1;const{state:e}=n,{selection:t}=e,{$from:i,empty:r}=t;if(!r||i.parent.type!==this.type)return!1;const s=i.parentOffset===i.parent.nodeSize-2,o=i.parent.textContent.endsWith(`
120
+
121
+ `);return!s||!o?!1:n.chain().command(({tr:l})=>(l.delete(i.pos-2,i.pos),!0)).exitCode().run()},ArrowDown:({editor:n})=>{if(!this.options.exitOnArrowDown)return!1;const{state:e}=n,{selection:t,doc:i}=e,{$from:r,empty:s}=t;if(!s||r.parent.type!==this.type||!(r.parentOffset===r.parent.nodeSize-2))return!1;const l=r.after();return l===void 0?!1:i.nodeAt(l)?n.commands.command(({tr:c})=>(c.setSelection(U.near(i.resolve(l))),!0)):n.commands.exitCode()}}},addInputRules(){return[ih({find:ZA,type:this.type,getAttributes:n=>({language:n[1]})}),ih({find:eE,type:this.type,getAttributes:n=>({language:n[1]})})]},addProseMirrorPlugins(){return[new se({key:new me("codeBlockVSCodeHandler"),props:{handlePaste:(n,e)=>{if(!e.clipboardData||this.editor.isActive(this.type.name))return!1;const t=e.clipboardData.getData("text/plain"),i=e.clipboardData.getData("vscode-editor-data"),r=i?JSON.parse(i):void 0,s=r?.mode;if(!t||!s)return!1;const{tr:o,schema:l}=n.state,a=l.text(t.replace(/\r\n?/g,`
122
+ `));return o.replaceSelectionWith(this.type.create({language:s},a)),o.selection.$from.parent.type!==this.type&&o.setSelection(_.near(o.doc.resolve(Math.max(0,o.selection.from-2)))),o.setMeta("paste",!0),n.dispatch(o),!0}}})]}}),nE=He.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
123
+
124
+ `):""}),iE=He.create({name:"hardBreak",markdownTokenName:"br",addOptions(){return{keepMarks:!0,HTMLAttributes:{}}},inline:!0,group:"inline",selectable:!1,linebreakReplacement:!0,parseHTML(){return[{tag:"br"}]},renderHTML({HTMLAttributes:n}){return["br",pe(this.options.HTMLAttributes,n)]},renderText(){return`
125
+ `},renderMarkdown:()=>`
126
+ `,parseMarkdown:()=>({type:"hardBreak"}),addCommands(){return{setHardBreak:()=>({commands:n,chain:e,state:t,editor:i})=>n.first([()=>n.exitCode(),()=>n.command(()=>{const{selection:r,storedMarks:s}=t;if(r.$from.parent.type.spec.isolating)return!1;const{keepMarks:o}=this.options,{splittableMarks:l}=i.extensionManager,a=s||r.$to.parentOffset&&r.$from.marks();return e().insertContent({type:this.name}).command(({tr:c,dispatch:h})=>{if(h&&a&&o){const u=a.filter(f=>l.includes(f.type.name));c.ensureMarks(u)}return!0}).run()})])}},addKeyboardShortcuts(){return{"Mod-Enter":()=>this.editor.commands.setHardBreak(),"Shift-Enter":()=>this.editor.commands.setHardBreak()}}}),rE=He.create({name:"heading",addOptions(){return{levels:[1,2,3,4,5,6],HTMLAttributes:{}}},content:"inline*",group:"block",defining:!0,addAttributes(){return{level:{default:1,rendered:!1}}},parseHTML(){return this.options.levels.map(n=>({tag:`h${n}`,attrs:{level:n}}))},renderHTML({node:n,HTMLAttributes:e}){return[`h${this.options.levels.includes(n.attrs.level)?n.attrs.level:this.options.levels[0]}`,pe(this.options.HTMLAttributes,e),0]},parseMarkdown:(n,e)=>e.createNode("heading",{level:n.depth||1},e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>{var t;const i=(t=n.attrs)!=null&&t.level?parseInt(n.attrs.level,10):1,r="#".repeat(i);return n.content?`${r} ${e.renderChildren(n.content)}`:""},addCommands(){return{setHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.setNode(this.name,n):!1,toggleHeading:n=>({commands:e})=>this.options.levels.includes(n.level)?e.toggleNode(this.name,"paragraph",n):!1}},addKeyboardShortcuts(){return this.options.levels.reduce((n,e)=>({...n,[`Mod-Alt-${e}`]:()=>this.editor.commands.toggleHeading({level:e})}),{})},addInputRules(){return this.options.levels.map(n=>ih({find:new RegExp(`^(#{${Math.min(...this.options.levels)},${n}})\\s$`),type:this.type,getAttributes:{level:n}}))}}),sE=He.create({name:"horizontalRule",addOptions(){return{HTMLAttributes:{},nextNodeType:"paragraph"}},group:"block",parseHTML(){return[{tag:"hr"}]},renderHTML({HTMLAttributes:n}){return["hr",pe(this.options.HTMLAttributes,n)]},markdownTokenName:"hr",parseMarkdown:(n,e)=>e.createNode("horizontalRule"),renderMarkdown:()=>"---",addCommands(){return{setHorizontalRule:()=>({chain:n,state:e})=>{if(!LM(e,e.schema.nodes[this.name]))return!1;const{selection:t}=e,{$to:i}=t,r=n();return xy(t)?r.insertContentAt(i.pos,{type:this.name}):r.insertContent({type:this.name}),r.command(({state:s,tr:o,dispatch:l})=>{if(l){const{$to:a}=o.selection,c=a.end();if(a.nodeAfter)a.nodeAfter.isTextblock?o.setSelection(_.create(o.doc,a.pos+1)):a.nodeAfter.isBlock?o.setSelection(W.create(o.doc,a.pos)):o.setSelection(_.create(o.doc,a.pos));else{const h=s.schema.nodes[this.options.nextNodeType]||a.parent.type.contentMatch.defaultType,u=h?.create();u&&(o.insert(c,u),o.setSelection(_.create(o.doc,c+1)))}o.scrollIntoView()}return!0}).run()}}},addInputRules(){return[zy({find:/^(?:---|—-|___\s|\*\*\*\s)$/,type:this.type})]}}),oE=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,lE=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,aE=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,cE=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,hE=zi.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",pe(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(n,e)=>e.applyMark("italic",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`*${e.renderChildren(n)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[dr({find:oE,type:this.type}),dr({find:aE,type:this.type})]},addPasteRules(){return[Ri({find:lE,type:this.type}),Ri({find:cE,type:this.type})]}});const uE="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",fE="ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2",uh="numeric",fh="ascii",dh="alpha",Zr="asciinumeric",_r="alphanumeric",ph="domain",sb="emoji",dE="scheme",pE="slashscheme",rc="whitespace";function mE(n,e){return n in e||(e[n]=[]),e[n]}function gi(n,e,t){e[uh]&&(e[Zr]=!0,e[_r]=!0),e[fh]&&(e[Zr]=!0,e[dh]=!0),e[Zr]&&(e[_r]=!0),e[dh]&&(e[_r]=!0),e[_r]&&(e[ph]=!0),e[sb]&&(e[ph]=!0);for(const i in e){const r=mE(i,t);r.indexOf(n)<0&&r.push(n)}}function gE(n,e){const t={};for(const i in e)e[i].indexOf(n)>=0&&(t[i]=!0);return t}function nt(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}nt.groups={};nt.prototype={accepts(){return!!this.t},go(n){const e=this,t=e.j[n];if(t)return t;for(let i=0;i<e.jr.length;i++){const r=e.jr[i][0],s=e.jr[i][1];if(s&&r.test(n))return s}return e.jd},has(n,e=!1){return e?n in this.j:!!this.go(n)},ta(n,e,t,i){for(let r=0;r<n.length;r++)this.tt(n[r],e,t,i)},tr(n,e,t,i){i=i||nt.groups;let r;return e&&e.j?r=e:(r=new nt(e),t&&i&&gi(e,t,i)),this.jr.push([n,r]),r},ts(n,e,t,i){let r=this;const s=n.length;if(!s)return r;for(let o=0;o<s-1;o++)r=r.tt(n[o]);return r.tt(n[s-1],e,t,i)},tt(n,e,t,i){i=i||nt.groups;const r=this;if(e&&e.j)return r.j[n]=e,e;const s=e;let o,l=r.go(n);if(l?(o=new nt,Object.assign(o.j,l.j),o.jr.push.apply(o.jr,l.jr),o.jd=l.jd,o.t=l.t):o=new nt,s){if(i)if(o.t&&typeof o.t=="string"){const a=Object.assign(gE(o.t,i),t);gi(s,a,i)}else t&&gi(s,t,i);o.t=s}return r.j[n]=o,o}};const K=(n,e,t,i,r)=>n.ta(e,t,i,r),be=(n,e,t,i,r)=>n.tr(e,t,i,r),bp=(n,e,t,i,r)=>n.ts(e,t,i,r),R=(n,e,t,i,r)=>n.tt(e,t,i,r),bn="WORD",mh="UWORD",ob="ASCIINUMERICAL",lb="ALPHANUMERICAL",vs="LOCALHOST",gh="TLD",yh="UTLD",Ho="SCHEME",Ui="SLASH_SCHEME",qu="NUM",bh="WS",Ku="NL",es="OPENBRACE",ts="CLOSEBRACE",sl="OPENBRACKET",ol="CLOSEBRACKET",ll="OPENPAREN",al="CLOSEPAREN",cl="OPENANGLEBRACKET",hl="CLOSEANGLEBRACKET",ul="FULLWIDTHLEFTPAREN",fl="FULLWIDTHRIGHTPAREN",dl="LEFTCORNERBRACKET",pl="RIGHTCORNERBRACKET",ml="LEFTWHITECORNERBRACKET",gl="RIGHTWHITECORNERBRACKET",yl="FULLWIDTHLESSTHAN",bl="FULLWIDTHGREATERTHAN",xl="AMPERSAND",wl="APOSTROPHE",kl="ASTERISK",Bn="AT",vl="BACKSLASH",Sl="BACKTICK",Cl="CARET",Wn="COLON",Ju="COMMA",Ml="DOLLAR",Qt="DOT",Tl="EQUALS",Gu="EXCLAMATION",St="HYPHEN",ns="PERCENT",Al="PIPE",El="PLUS",Ol="POUND",is="QUERY",Yu="QUOTE",ab="FULLWIDTHMIDDLEDOT",Xu="SEMI",Zt="SLASH",rs="TILDE",Rl="UNDERSCORE",cb="EMOJI",Dl="SYM";var hb=Object.freeze({__proto__:null,ALPHANUMERICAL:lb,AMPERSAND:xl,APOSTROPHE:wl,ASCIINUMERICAL:ob,ASTERISK:kl,AT:Bn,BACKSLASH:vl,BACKTICK:Sl,CARET:Cl,CLOSEANGLEBRACKET:hl,CLOSEBRACE:ts,CLOSEBRACKET:ol,CLOSEPAREN:al,COLON:Wn,COMMA:Ju,DOLLAR:Ml,DOT:Qt,EMOJI:cb,EQUALS:Tl,EXCLAMATION:Gu,FULLWIDTHGREATERTHAN:bl,FULLWIDTHLEFTPAREN:ul,FULLWIDTHLESSTHAN:yl,FULLWIDTHMIDDLEDOT:ab,FULLWIDTHRIGHTPAREN:fl,HYPHEN:St,LEFTCORNERBRACKET:dl,LEFTWHITECORNERBRACKET:ml,LOCALHOST:vs,NL:Ku,NUM:qu,OPENANGLEBRACKET:cl,OPENBRACE:es,OPENBRACKET:sl,OPENPAREN:ll,PERCENT:ns,PIPE:Al,PLUS:El,POUND:Ol,QUERY:is,QUOTE:Yu,RIGHTCORNERBRACKET:pl,RIGHTWHITECORNERBRACKET:gl,SCHEME:Ho,SEMI:Xu,SLASH:Zt,SLASH_SCHEME:Ui,SYM:Dl,TILDE:rs,TLD:gh,UNDERSCORE:Rl,UTLD:yh,UWORD:mh,WORD:bn,WS:bh});const mn=/[a-z]/,Dr=new RegExp("\\p{L}","u"),sc=new RegExp("\\p{Emoji}","u"),gn=/\d/,oc=/\s/,xp="\r",lc=`
127
+ `,yE="️",bE="‍",ac="";let so=null,oo=null;function xE(n=[]){const e={};nt.groups=e;const t=new nt;so==null&&(so=wp(uE)),oo==null&&(oo=wp(fE)),R(t,"'",wl),R(t,"{",es),R(t,"}",ts),R(t,"[",sl),R(t,"]",ol),R(t,"(",ll),R(t,")",al),R(t,"<",cl),R(t,">",hl),R(t,"(",ul),R(t,")",fl),R(t,"「",dl),R(t,"」",pl),R(t,"『",ml),R(t,"』",gl),R(t,"<",yl),R(t,">",bl),R(t,"&",xl),R(t,"*",kl),R(t,"@",Bn),R(t,"`",Sl),R(t,"^",Cl),R(t,":",Wn),R(t,",",Ju),R(t,"$",Ml),R(t,".",Qt),R(t,"=",Tl),R(t,"!",Gu),R(t,"-",St),R(t,"%",ns),R(t,"|",Al),R(t,"+",El),R(t,"#",Ol),R(t,"?",is),R(t,'"',Yu),R(t,"/",Zt),R(t,";",Xu),R(t,"~",rs),R(t,"_",Rl),R(t,"\\",vl),R(t,"・",ab);const i=be(t,gn,qu,{[uh]:!0});be(i,gn,i);const r=be(i,mn,ob,{[Zr]:!0}),s=be(i,Dr,lb,{[_r]:!0}),o=be(t,mn,bn,{[fh]:!0});be(o,gn,r),be(o,mn,o),be(r,gn,r),be(r,mn,r);const l=be(t,Dr,mh,{[dh]:!0});be(l,mn),be(l,gn,s),be(l,Dr,l),be(s,gn,s),be(s,mn),be(s,Dr,s);const a=R(t,lc,Ku,{[rc]:!0}),c=R(t,xp,bh,{[rc]:!0}),h=be(t,oc,bh,{[rc]:!0});R(t,ac,h),R(c,lc,a),R(c,ac,h),be(c,oc,h),R(h,xp),R(h,lc),be(h,oc,h),R(h,ac,h);const u=be(t,sc,cb,{[sb]:!0});R(u,"#"),be(u,sc,u),R(u,yE,u);const f=R(u,bE);R(f,"#"),be(f,sc,u);const d=[[mn,o],[gn,r]],p=[[mn,null],[Dr,l],[gn,s]];for(let m=0;m<so.length;m++)In(t,so[m],gh,bn,d);for(let m=0;m<oo.length;m++)In(t,oo[m],yh,mh,p);gi(gh,{tld:!0,ascii:!0},e),gi(yh,{utld:!0,alpha:!0},e),In(t,"file",Ho,bn,d),In(t,"mailto",Ho,bn,d),In(t,"http",Ui,bn,d),In(t,"https",Ui,bn,d),In(t,"ftp",Ui,bn,d),In(t,"ftps",Ui,bn,d),gi(Ho,{scheme:!0,ascii:!0},e),gi(Ui,{slashscheme:!0,ascii:!0},e),n=n.sort((m,g)=>m[0]>g[0]?1:-1);for(let m=0;m<n.length;m++){const g=n[m][0],b=n[m][1]?{[dE]:!0}:{[pE]:!0};g.indexOf("-")>=0?b[ph]=!0:mn.test(g)?gn.test(g)?b[Zr]=!0:b[fh]=!0:b[uh]=!0,bp(t,g,g,b)}return bp(t,"localhost",vs,{ascii:!0}),t.jd=new nt(Dl),{start:t,tokens:Object.assign({groups:e},hb)}}function ub(n,e){const t=wE(e.replace(/[A-Z]/g,l=>l.toLowerCase())),i=t.length,r=[];let s=0,o=0;for(;o<i;){let l=n,a=null,c=0,h=null,u=-1,f=-1;for(;o<i&&(a=l.go(t[o]));)l=a,l.accepts()?(u=0,f=0,h=l):u>=0&&(u+=t[o].length,f++),c+=t[o].length,s+=t[o].length,o++;s-=u,o-=f,c-=u,r.push({t:h.t,v:e.slice(s-c,s),s:s-c,e:s})}return r}function wE(n){const e=[],t=n.length;let i=0;for(;i<t;){let r=n.charCodeAt(i),s,o=r<55296||r>56319||i+1===t||(s=n.charCodeAt(i+1))<56320||s>57343?n[i]:n.slice(i,i+2);e.push(o),i+=o.length}return e}function In(n,e,t,i,r){let s;const o=e.length;for(let l=0;l<o-1;l++){const a=e[l];n.j[a]?s=n.j[a]:(s=new nt(i),s.jr=r.slice(),n.j[a]=s),n=s}return s=new nt(t),s.jr=r.slice(),n.j[e[o-1]]=s,s}function wp(n){const e=[],t=[];let i=0,r="0123456789";for(;i<n.length;){let s=0;for(;r.indexOf(n[i+s])>=0;)s++;if(s>0){e.push(t.join(""));for(let o=parseInt(n.substring(i,i+s),10);o>0;o--)t.pop();i+=s}else t.push(n[i]),i++}return e}const Ss={defaultProtocol:"http",events:null,format:kp,formatHref:kp,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function Qu(n,e=null){let t=Object.assign({},Ss);n&&(t=Object.assign(t,n instanceof Qu?n.o:n));const i=t.ignoreTags,r=[];for(let s=0;s<i.length;s++)r.push(i[s].toUpperCase());this.o=t,e&&(this.defaultRender=e),this.ignoreTags=r}Qu.prototype={o:Ss,ignoreTags:[],defaultRender(n){return n},check(n){return this.get("validate",n.toString(),n)},get(n,e,t){const i=e!=null;let r=this.o[n];return r&&(typeof r=="object"?(r=t.t in r?r[t.t]:Ss[n],typeof r=="function"&&i&&(r=r(e,t))):typeof r=="function"&&i&&(r=r(e,t.t,t)),r)},getObj(n,e,t){let i=this.o[n];return typeof i=="function"&&e!=null&&(i=i(e,t.t,t)),i},render(n){const e=n.render(this);return(this.get("render",null,n)||this.defaultRender)(e,n.t,n)}};function kp(n){return n}function fb(n,e){this.t="token",this.v=n,this.tk=e}fb.prototype={isLink:!1,toString(){return this.v},toHref(n){return this.toString()},toFormattedString(n){const e=this.toString(),t=n.get("truncate",e,this),i=n.get("format",e,this);return t&&i.length>t?i.substring(0,t)+"…":i},toFormattedHref(n){return n.get("formatHref",this.toHref(n.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(n=Ss.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(n),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(n){return{type:this.t,value:this.toFormattedString(n),isLink:this.isLink,href:this.toFormattedHref(n),start:this.startIndex(),end:this.endIndex()}},validate(n){return n.get("validate",this.toString(),this)},render(n){const e=this,t=this.toHref(n.get("defaultProtocol")),i=n.get("formatHref",t,this),r=n.get("tagName",t,e),s=this.toFormattedString(n),o={},l=n.get("className",t,e),a=n.get("target",t,e),c=n.get("rel",t,e),h=n.getObj("attributes",t,e),u=n.getObj("events",t,e);return o.href=i,l&&(o.class=l),a&&(o.target=a),c&&(o.rel=c),h&&Object.assign(o,h),{tagName:r,attributes:o,content:s,eventListeners:u}}};function wa(n,e){class t extends fb{constructor(r,s){super(r,s),this.t=n}}for(const i in e)t.prototype[i]=e[i];return t.t=n,t}const vp=wa("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),Sp=wa("text"),kE=wa("nl"),lo=wa("url",{isLink:!0,toHref(n=Ss.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==vs&&n[1].t===Wn}}),vt=n=>new nt(n);function vE({groups:n}){const e=n.domain.concat([xl,kl,Bn,vl,Sl,Cl,Ml,Tl,St,qu,ns,Al,El,Ol,Zt,Dl,rs,Rl]),t=[wl,Wn,Ju,Qt,Gu,ns,is,Yu,Xu,cl,hl,es,ts,ol,sl,ll,al,ul,fl,dl,pl,ml,gl,yl,bl],i=[xl,wl,kl,vl,Sl,Cl,Ml,Tl,St,es,ts,ns,Al,El,Ol,is,Zt,Dl,rs,Rl],r=vt(),s=R(r,rs);K(s,i,s),K(s,n.domain,s);const o=vt(),l=vt(),a=vt();K(r,n.domain,o),K(r,n.scheme,l),K(r,n.slashscheme,a),K(o,i,s),K(o,n.domain,o);const c=R(o,Bn);R(s,Bn,c),R(l,Bn,c),R(a,Bn,c);const h=R(s,Qt);K(h,i,s),K(h,n.domain,s);const u=vt();K(c,n.domain,u),K(u,n.domain,u);const f=R(u,Qt);K(f,n.domain,u);const d=vt(vp);K(f,n.tld,d),K(f,n.utld,d),R(c,vs,d);const p=R(u,St);R(p,St,p),K(p,n.domain,u),K(d,n.domain,u),R(d,Qt,f),R(d,St,p);const m=R(d,Wn);K(m,n.numeric,vp);const g=R(o,St),y=R(o,Qt);R(g,St,g),K(g,n.domain,o),K(y,i,s),K(y,n.domain,o);const b=vt(lo);K(y,n.tld,b),K(y,n.utld,b),K(b,n.domain,o),K(b,i,s),R(b,Qt,y),R(b,St,g),R(b,Bn,c);const x=R(b,Wn),k=vt(lo);K(x,n.numeric,k);const w=vt(lo),C=vt();K(w,e,w),K(w,t,C),K(C,e,w),K(C,t,C),R(b,Zt,w),R(k,Zt,w);const v=R(l,Wn),D=R(a,Wn),L=R(D,Zt),J=R(L,Zt);K(l,n.domain,o),R(l,Qt,y),R(l,St,g),K(a,n.domain,o),R(a,Qt,y),R(a,St,g),K(v,n.domain,w),R(v,Zt,w),R(v,is,w),K(J,n.domain,w),K(J,e,w),R(J,Zt,w);const j=[[es,ts],[sl,ol],[ll,al],[cl,hl],[ul,fl],[dl,pl],[ml,gl],[yl,bl]];for(let $=0;$<j.length;$++){const[te,G]=j[$],Z=R(w,te);R(C,te,Z),R(Z,G,w);const Oe=vt(lo);K(Z,e,Oe);const ft=vt();K(Z,t),K(Oe,e,Oe),K(Oe,t,ft),K(ft,e,Oe),K(ft,t,ft),R(Oe,G,w),R(ft,G,w)}return R(r,vs,b),R(r,Ku,kE),{start:r,tokens:hb}}function SE(n,e,t){let i=t.length,r=0,s=[],o=[];for(;r<i;){let l=n,a=null,c=null,h=0,u=null,f=-1;for(;r<i&&!(a=l.go(t[r].t));)o.push(t[r++]);for(;r<i&&(c=a||l.go(t[r].t));)a=null,l=c,l.accepts()?(f=0,u=l):f>=0&&f++,r++,h++;if(f<0)r-=h,r<i&&(o.push(t[r]),r++);else{o.length>0&&(s.push(cc(Sp,e,o)),o=[]),r-=f,h-=f;const d=u.t,p=t.slice(r-h,r);s.push(cc(d,e,p))}}return o.length>0&&s.push(cc(Sp,e,o)),s}function cc(n,e,t){const i=t[0].s,r=t[t.length-1].e,s=e.slice(i,r);return new n(s,t)}const CE=typeof console<"u"&&console&&console.warn||(()=>{}),ME="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",de={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function TE(){return nt.groups={},de.scanner=null,de.parser=null,de.tokenQueue=[],de.pluginQueue=[],de.customSchemes=[],de.initialized=!1,de}function Cp(n,e=!1){if(de.initialized&&CE(`linkifyjs: already initialized - will not register custom scheme "${n}" ${ME}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
128
+ 1. Must only contain digits, lowercase ASCII letters or "-"
129
+ 2. Cannot start or end with "-"
130
+ 3. "-" cannot repeat`);de.customSchemes.push([n,e])}function AE(){de.scanner=xE(de.customSchemes);for(let n=0;n<de.tokenQueue.length;n++)de.tokenQueue[n][1]({scanner:de.scanner});de.parser=vE(de.scanner.tokens);for(let n=0;n<de.pluginQueue.length;n++)de.pluginQueue[n][1]({scanner:de.scanner,parser:de.parser});return de.initialized=!0,de}function Zu(n){return de.initialized||AE(),SE(de.parser.start,n,ub(de.scanner.start,n))}Zu.scan=ub;function db(n,e=null,t=null){if(e&&typeof e=="object"){if(t)throw Error(`linkifyjs: Invalid link type ${e}; must be a string`);t=e,e=null}const i=new Qu(t),r=Zu(n),s=[];for(let o=0;o<r.length;o++){const l=r[o];l.isLink&&(!e||l.t===e)&&i.check(l)&&s.push(l.toFormattedObject(i))}return s}var ef="[\0-   ᠎ -\u2029  ]",EE=new RegExp(ef),OE=new RegExp(`${ef}$`),RE=new RegExp(ef,"g");function DE(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function NE(n){return new se({key:new me("autolink"),appendTransaction:(e,t,i)=>{const r=e.some(c=>c.docChanged)&&!t.doc.eq(i.doc),s=e.some(c=>c.getMeta("preventAutolink"));if(!r||s)return;const{tr:o}=i,l=hy(t.doc,[...e]);if(by(l).forEach(({newRange:c})=>{const h=LC(i.doc,c,d=>d.isTextblock);let u,f;if(h.length>1)u=h[0],f=i.doc.textBetween(u.pos,u.pos+u.node.nodeSize,void 0," ");else if(h.length){const d=i.doc.textBetween(c.from,c.to," "," ");if(!OE.test(d))return;u=h[0],f=i.doc.textBetween(u.pos,c.to,void 0," ")}if(u&&f){const d=f.split(EE).filter(Boolean);if(d.length<=0)return!1;const p=d[d.length-1],m=u.pos+f.lastIndexOf(p);if(!p)return!1;const g=Zu(p).map(y=>y.toObject(n.defaultProtocol));if(!DE(g))return!1;g.filter(y=>y.isLink).map(y=>({...y,from:m+y.start+1,to:m+y.end+1})).filter(y=>i.schema.marks.code?!i.doc.rangeHasMark(y.from,y.to,i.schema.marks.code):!0).filter(y=>n.validate(y.value)).filter(y=>n.shouldAutoLink(y.value)).forEach(y=>{Hu(y.from,y.to,i.doc).some(b=>b.mark.type===n.type)||o.addMark(y.from,y.to,n.type.create({href:y.href}))})}}),!!o.steps.length)return o}})}function IE(n){return new se({key:new me("handleClickLink"),props:{handleClick:(e,t,i)=>{var r,s;if(i.button!==0||!e.editable)return!1;let o=null;if(i.target instanceof HTMLAnchorElement)o=i.target;else{const a=i.target;if(!a)return!1;const c=n.editor.view.dom;o=a.closest("a"),o&&!c.contains(o)&&(o=null)}if(!o)return!1;let l=!1;if(n.enableClickSelection&&(l=n.editor.commands.extendMarkRange(n.type.name)),n.openOnClick){const a=yy(e.state,n.type.name),c=(r=o.href)!=null?r:a.href,h=(s=o.target)!=null?s:a.target;c&&(window.open(c,h),l=!0)}return l}}})}function LE(n){return new se({key:new me("handlePasteLink"),props:{handlePaste:(e,t,i)=>{const{shouldAutoLink:r}=n,{state:s}=e,{selection:o}=s,{empty:l}=o;if(l)return!1;let a="";i.content.forEach(h=>{a+=h.textContent});const c=db(a,{defaultProtocol:n.defaultProtocol}).find(h=>h.isLink&&h.value===a);return!a||!c||r!==void 0&&!r(c.value)?!1:n.editor.commands.setMark(n.type,{href:c.href})}}})}function ci(n,e){const t=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(i=>{const r=typeof i=="string"?i:i.scheme;r&&t.push(r)}),!n||n.replace(RE,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var PE=zi.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(n=>{if(typeof n=="string"){Cp(n);return}Cp(n.scheme,n.optionalSlashes)})},onDestroy(){TE()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(n,e)=>!!ci(n,e.protocols),validate:n=>!!n,shouldAutoLink:n=>{const e=/^[a-z][a-z0-9+.-]*:\/\//i.test(n),t=/^[a-z][a-z0-9+.-]*:/i.test(n);if(e||t&&!n.includes("@"))return!0;const r=(n.includes("@")?n.split("@").pop():n).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(n){return n.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class}}},parseHTML(){return[{tag:"a[href]",getAttrs:n=>{const e=n.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!ci(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:n}){return this.options.isAllowedUri(n.href,{defaultValidate:e=>!!ci(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",pe(this.options.HTMLAttributes,n),0]:["a",pe(this.options.HTMLAttributes,{...n,href:""}),0]},markdownTokenName:"link",parseMarkdown:(n,e)=>e.applyMark("link",e.parseInline(n.tokens||[]),{href:n.href,title:n.title||null}),renderMarkdown:(n,e)=>{var t;const i=((t=n.attrs)==null?void 0:t.href)||"";return`[${e.renderChildren(n)}](${i})`},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:i=>!!ci(i,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,n).setMeta("preventAutolink",!0).run():!1},toggleLink:n=>({chain:e})=>{const{href:t}=n||{};return t&&!this.options.isAllowedUri(t,{defaultValidate:i=>!!ci(i,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[Ri({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:i}=this.options,r=db(n).filter(s=>s.isLink&&this.options.isAllowedUri(s.value,{defaultValidate:o=>!!ci(o,t),protocols:t,defaultProtocol:i}));r.length&&r.forEach(s=>{this.options.shouldAutoLink(s.value)&&e.push({text:s.value,data:{href:s.href},index:s.start})})}return e},type:this.type,getAttributes:n=>{var e;return{href:(e=n.data)==null?void 0:e.href}}})]},addProseMirrorPlugins(){const n=[],{protocols:e,defaultProtocol:t}=this.options;return this.options.autolink&&n.push(NE({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:i=>this.options.isAllowedUri(i,{defaultValidate:r=>!!ci(r,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),n.push(IE({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(LE({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}}),BE=Object.defineProperty,zE=(n,e)=>{for(var t in e)BE(n,t,{get:e[t],enumerable:!0})},HE="listItem",Mp="textStyle",Tp=/^\s*([-+*])\s$/,pb=He.create({name:"bulletList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:"ul"}]},renderHTML({HTMLAttributes:n}){return["ul",pe(this.options.HTMLAttributes,n),0]},markdownTokenName:"list",parseMarkdown:(n,e)=>n.type!=="list"||n.ordered?[]:{type:"bulletList",content:n.items?e.parseChildren(n.items):[]},renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
131
+ `):"",markdownOptions:{indentsContent:!0},addCommands(){return{toggleBulletList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(HE,this.editor.getAttributes(Mp)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-8":()=>this.editor.commands.toggleBulletList()}},addInputRules(){let n=pr({find:Tp,type:this.type});return(this.options.keepMarks||this.options.keepAttributes)&&(n=pr({find:Tp,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:()=>this.editor.getAttributes(Mp),editor:this.editor})),[n]}}),mb=He.create({name:"listItem",addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList"}},content:"paragraph block*",defining:!0,parseHTML(){return[{tag:"li"}]},renderHTML({HTMLAttributes:n}){return["li",pe(this.options.HTMLAttributes,n),0]},markdownTokenName:"list_item",parseMarkdown:(n,e)=>{if(n.type!=="list_item")return[];let t=[];if(n.tokens&&n.tokens.length>0)if(n.tokens.some(r=>r.type==="paragraph"))t=e.parseChildren(n.tokens);else{const r=n.tokens[0];if(r&&r.type==="text"&&r.tokens&&r.tokens.length>0){if(t=[{type:"paragraph",content:e.parseInline(r.tokens)}],n.tokens.length>1){const o=n.tokens.slice(1),l=e.parseChildren(o);t.push(...l)}}else t=e.parseChildren(n.tokens)}return t.length===0&&(t=[{type:"paragraph",content:[]}]),{type:"listItem",content:t}},renderMarkdown:(n,e,t)=>Wu(n,e,i=>{var r,s;return i.parentType==="bulletList"?"- ":i.parentType==="orderedList"?`${(((s=(r=i.meta)==null?void 0:r.parentAttrs)==null?void 0:s.start)||1)+i.index}. `:"- "},t),addKeyboardShortcuts(){return{Enter:()=>this.editor.commands.splitListItem(this.name),Tab:()=>this.editor.commands.sinkListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)}}}),FE={};zE(FE,{findListItemPos:()=>Fs,getNextListDepth:()=>tf,handleBackspace:()=>xh,handleDelete:()=>wh,hasListBefore:()=>gb,hasListItemAfter:()=>$E,hasListItemBefore:()=>yb,listItemHasSubList:()=>bb,nextListIsDeeper:()=>xb,nextListIsHigher:()=>wb});var Fs=(n,e)=>{const{$from:t}=e.selection,i=Ae(n,e.schema);let r=null,s=t.depth,o=t.pos,l=null;for(;s>0&&l===null;)r=t.node(s),r.type===i?l=s:(s-=1,o-=1);return l===null?null:{$pos:e.doc.resolve(o),depth:l}},tf=(n,e)=>{const t=Fs(n,e);if(!t)return!1;const[,i]=jC(e,n,t.$pos.pos+4);return i},gb=(n,e,t)=>{const{$anchor:i}=n.selection,r=Math.max(0,i.pos-2),s=n.doc.resolve(r).node();return!(!s||!t.includes(s.type.name))},yb=(n,e)=>{var t;const{$anchor:i}=e.selection,r=e.doc.resolve(i.pos-2);return!(r.index()===0||((t=r.nodeBefore)==null?void 0:t.type.name)!==n)},bb=(n,e,t)=>{if(!t)return!1;const i=Ae(n,e.schema);let r=!1;return t.descendants(s=>{s.type===i&&(r=!0)}),r},xh=(n,e,t)=>{if(n.commands.undoInputRule())return!0;if(n.state.selection.from!==n.state.selection.to)return!1;if(!Zn(n.state,e)&&gb(n.state,e,t)){const{$anchor:l}=n.state.selection,a=n.state.doc.resolve(l.before()-1),c=[];a.node().descendants((f,d)=>{f.type.name===e&&c.push({node:f,pos:d})});const h=c.at(-1);if(!h)return!1;const u=n.state.doc.resolve(a.start()+h.pos+1);return n.chain().cut({from:l.start()-1,to:l.end()+1},u.end()).joinForward().run()}if(!Zn(n.state,e)||!KC(n.state))return!1;const i=Fs(e,n.state);if(!i)return!1;const s=n.state.doc.resolve(i.$pos.pos-2).node(i.depth),o=bb(e,n.state,s);return yb(e,n.state)&&!o?n.commands.joinItemBackward():n.chain().liftListItem(e).run()},xb=(n,e)=>{const t=tf(n,e),i=Fs(n,e);return!i||!t?!1:t>i.depth},wb=(n,e)=>{const t=tf(n,e),i=Fs(n,e);return!i||!t?!1:t<i.depth},wh=(n,e)=>{if(!Zn(n.state,e)||!qC(n.state,e))return!1;const{selection:t}=n.state,{$from:i,$to:r}=t;return!t.empty&&i.sameParent(r)?!1:xb(e,n.state)?n.chain().focus(n.state.selection.from+4).lift(e).joinBackward().run():wb(e,n.state)?n.chain().joinForward().joinBackward().run():n.commands.joinItemForward()},$E=(n,e)=>{var t;const{$anchor:i}=e.selection,r=e.doc.resolve(i.pos-i.parentOffset-2);return!(r.index()===r.parent.childCount-1||((t=r.nodeAfter)==null?void 0:t.type.name)!==n)},kb=fe.create({name:"listKeymap",addOptions(){return{listTypes:[{itemName:"listItem",wrapperNames:["bulletList","orderedList"]},{itemName:"taskItem",wrapperNames:["taskList"]}]}},addKeyboardShortcuts(){return{Delete:({editor:n})=>{let e=!1;return this.options.listTypes.forEach(({itemName:t})=>{n.state.schema.nodes[t]!==void 0&&wh(n,t)&&(e=!0)}),e},"Mod-Delete":({editor:n})=>{let e=!1;return this.options.listTypes.forEach(({itemName:t})=>{n.state.schema.nodes[t]!==void 0&&wh(n,t)&&(e=!0)}),e},Backspace:({editor:n})=>{let e=!1;return this.options.listTypes.forEach(({itemName:t,wrapperNames:i})=>{n.state.schema.nodes[t]!==void 0&&xh(n,t,i)&&(e=!0)}),e},"Mod-Backspace":({editor:n})=>{let e=!1;return this.options.listTypes.forEach(({itemName:t,wrapperNames:i})=>{n.state.schema.nodes[t]!==void 0&&xh(n,t,i)&&(e=!0)}),e}}}}),Ap=/^(\s*)(\d+)\.\s+(.*)$/,VE=/^\s/;function WE(n){const e=[];let t=0,i=0;for(;t<n.length;){const r=n[t],s=r.match(Ap);if(!s)break;const[,o,l,a]=s,c=o.length;let h=a,u=t+1;const f=[r];for(;u<n.length;){const d=n[u];if(d.match(Ap))break;if(d.trim()==="")f.push(d),h+=`
132
+ `,u+=1;else if(d.match(VE))f.push(d),h+=`
133
+ ${d.slice(c+2)}`,u+=1;else break}e.push({indent:c,number:parseInt(l,10),content:h.trim(),raw:f.join(`
134
+ `)}),i=u,t=u}return[e,i]}function vb(n,e,t){var i;const r=[];let s=0;for(;s<n.length;){const o=n[s];if(o.indent===e){const l=o.content.split(`
135
+ `),a=((i=l[0])==null?void 0:i.trim())||"",c=[];a&&c.push({type:"paragraph",raw:a,tokens:t.inlineTokens(a)});const h=l.slice(1).join(`
136
+ `).trim();if(h){const d=t.blockTokens(h);c.push(...d)}let u=s+1;const f=[];for(;u<n.length&&n[u].indent>e;)f.push(n[u]),u+=1;if(f.length>0){const d=Math.min(...f.map(m=>m.indent)),p=vb(f,d,t);c.push({type:"list",ordered:!0,start:f[0].number,items:p,raw:f.map(m=>m.raw).join(`
137
+ `)})}r.push({type:"list_item",raw:o.raw,tokens:c}),s=u}else s+=1}return r}function jE(n,e){return n.map(t=>{if(t.type!=="list_item")return e.parseChildren([t])[0];const i=[];return t.tokens&&t.tokens.length>0&&t.tokens.forEach(r=>{if(r.type==="paragraph"||r.type==="list"||r.type==="blockquote"||r.type==="code")i.push(...e.parseChildren([r]));else if(r.type==="text"&&r.tokens){const s=e.parseChildren([r]);i.push({type:"paragraph",content:s})}else{const s=e.parseChildren([r]);s.length>0&&i.push(...s)}}),{type:"listItem",content:i}})}var _E="listItem",Ep="textStyle",Op=/^(\d+)\.\s$/,Sb=He.create({name:"orderedList",addOptions(){return{itemTypeName:"listItem",HTMLAttributes:{},keepMarks:!1,keepAttributes:!1}},group:"block list",content(){return`${this.options.itemTypeName}+`},addAttributes(){return{start:{default:1,parseHTML:n=>n.hasAttribute("start")?parseInt(n.getAttribute("start")||"",10):1},type:{default:null,parseHTML:n=>n.getAttribute("type")}}},parseHTML(){return[{tag:"ol"}]},renderHTML({HTMLAttributes:n}){const{start:e,...t}=n;return e===1?["ol",pe(this.options.HTMLAttributes,t),0]:["ol",pe(this.options.HTMLAttributes,n),0]},markdownTokenName:"list",parseMarkdown:(n,e)=>{if(n.type!=="list"||!n.ordered)return[];const t=n.start||1,i=n.items?jE(n.items,e):[];return t!==1?{type:"orderedList",attrs:{start:t},content:i}:{type:"orderedList",content:i}},renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
138
+ `):"",markdownTokenizer:{name:"orderedList",level:"block",start:n=>{const e=n.match(/^(\s*)(\d+)\.\s+/),t=e?.index;return t!==void 0?t:-1},tokenize:(n,e,t)=>{var i;const r=n.split(`
139
+ `),[s,o]=WE(r);if(s.length===0)return;const l=vb(s,0,t);return l.length===0?void 0:{type:"list",ordered:!0,start:((i=s[0])==null?void 0:i.number)||1,items:l,raw:r.slice(0,o).join(`
140
+ `)}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleOrderedList:()=>({commands:n,chain:e})=>this.options.keepAttributes?e().toggleList(this.name,this.options.itemTypeName,this.options.keepMarks).updateAttributes(_E,this.editor.getAttributes(Ep)).run():n.toggleList(this.name,this.options.itemTypeName,this.options.keepMarks)}},addKeyboardShortcuts(){return{"Mod-Shift-7":()=>this.editor.commands.toggleOrderedList()}},addInputRules(){let n=pr({find:Op,type:this.type,getAttributes:e=>({start:+e[1]}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1]});return(this.options.keepMarks||this.options.keepAttributes)&&(n=pr({find:Op,type:this.type,keepMarks:this.options.keepMarks,keepAttributes:this.options.keepAttributes,getAttributes:e=>({start:+e[1],...this.editor.getAttributes(Ep)}),joinPredicate:(e,t)=>t.childCount+t.attrs.start===+e[1],editor:this.editor})),[n]}}),UE=/^\s*(\[([( |x])?\])\s$/,qE=He.create({name:"taskItem",addOptions(){return{nested:!1,HTMLAttributes:{},taskListTypeName:"taskList",a11y:void 0}},content(){return this.options.nested?"paragraph block*":"paragraph+"},defining:!0,addAttributes(){return{checked:{default:!1,keepOnSplit:!1,parseHTML:n=>{const e=n.getAttribute("data-checked");return e===""||e==="true"},renderHTML:n=>({"data-checked":n.checked})}}},parseHTML(){return[{tag:`li[data-type="${this.name}"]`,priority:51}]},renderHTML({node:n,HTMLAttributes:e}){return["li",pe(this.options.HTMLAttributes,e,{"data-type":this.name}),["label",["input",{type:"checkbox",checked:n.attrs.checked?"checked":null}],["span"]],["div",0]]},parseMarkdown:(n,e)=>{const t=[];if(n.tokens&&n.tokens.length>0?t.push(e.createNode("paragraph",{},e.parseInline(n.tokens))):n.text?t.push(e.createNode("paragraph",{},[e.createNode("text",{text:n.text})])):t.push(e.createNode("paragraph",{},[])),n.nestedTokens&&n.nestedTokens.length>0){const i=e.parseChildren(n.nestedTokens);t.push(...i)}return e.createNode("taskItem",{checked:n.checked||!1},t)},renderMarkdown:(n,e)=>{var t;const r=`- [${(t=n.attrs)!=null&&t.checked?"x":" "}] `;return Wu(n,e,r)},addKeyboardShortcuts(){const n={Enter:()=>this.editor.commands.splitListItem(this.name),"Shift-Tab":()=>this.editor.commands.liftListItem(this.name)};return this.options.nested?{...n,Tab:()=>this.editor.commands.sinkListItem(this.name)}:n},addNodeView(){return({node:n,HTMLAttributes:e,getPos:t,editor:i})=>{const r=document.createElement("li"),s=document.createElement("label"),o=document.createElement("span"),l=document.createElement("input"),a=document.createElement("div"),c=u=>{var f,d;l.ariaLabel=((d=(f=this.options.a11y)==null?void 0:f.checkboxLabel)==null?void 0:d.call(f,u,l.checked))||`Task item checkbox for ${u.textContent||"empty task item"}`};c(n),s.contentEditable="false",l.type="checkbox",l.addEventListener("mousedown",u=>u.preventDefault()),l.addEventListener("change",u=>{if(!i.isEditable&&!this.options.onReadOnlyChecked){l.checked=!l.checked;return}const{checked:f}=u.target;i.isEditable&&typeof t=="function"&&i.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:d})=>{const p=t();if(typeof p!="number")return!1;const m=d.doc.nodeAt(p);return d.setNodeMarkup(p,void 0,{...m?.attrs,checked:f}),!0}).run(),!i.isEditable&&this.options.onReadOnlyChecked&&(this.options.onReadOnlyChecked(n,f)||(l.checked=!l.checked))}),Object.entries(this.options.HTMLAttributes).forEach(([u,f])=>{r.setAttribute(u,f)}),r.dataset.checked=n.attrs.checked,l.checked=n.attrs.checked,s.append(l,o),r.append(s,a),Object.entries(e).forEach(([u,f])=>{r.setAttribute(u,f)});let h=new Set(Object.keys(e));return{dom:r,contentDOM:a,update:u=>{if(u.type!==this.type)return!1;r.dataset.checked=u.attrs.checked,l.checked=u.attrs.checked,c(u);const f=i.extensionManager.attributes,d=ws(u,f),p=new Set(Object.keys(d)),m=this.options.HTMLAttributes;return h.forEach(g=>{p.has(g)||(g in m?r.setAttribute(g,m[g]):r.removeAttribute(g))}),Object.entries(d).forEach(([g,y])=>{y==null?g in m?r.setAttribute(g,m[g]):r.removeAttribute(g):r.setAttribute(g,y)}),h=p,!0}}}},addInputRules(){return[pr({find:UE,type:this.type,getAttributes:n=>({checked:n[n.length-1]==="x"})})]}}),KE=He.create({name:"taskList",addOptions(){return{itemTypeName:"taskItem",HTMLAttributes:{}}},group:"block list",content(){return`${this.options.itemTypeName}+`},parseHTML(){return[{tag:`ul[data-type="${this.name}"]`,priority:51}]},renderHTML({HTMLAttributes:n}){return["ul",pe(this.options.HTMLAttributes,n,{"data-type":this.name}),0]},parseMarkdown:(n,e)=>e.createNode("taskList",{},e.parseChildren(n.items||[])),renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
141
+ `):"",markdownTokenizer:{name:"taskList",level:"block",start(n){var e;const t=(e=n.match(/^\s*[-+*]\s+\[([ xX])\]\s+/))==null?void 0:e.index;return t!==void 0?t:-1},tokenize(n,e,t){const i=s=>{const o=rh(s,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:l=>({indentLevel:l[1].length,mainContent:l[4],checked:l[3].toLowerCase()==="x"}),createToken:(l,a)=>({type:"taskItem",raw:"",mainContent:l.mainContent,indentLevel:l.indentLevel,checked:l.checked,text:l.mainContent,tokens:t.inlineTokens(l.mainContent),nestedTokens:a}),customNestedParser:i},t);return o?[{type:"taskList",raw:o.raw,items:o.items}]:t.blockTokens(s)},r=rh(n,{itemPattern:/^(\s*)([-+*])\s+\[([ xX])\]\s+(.*)$/,extractItemData:s=>({indentLevel:s[1].length,mainContent:s[4],checked:s[3].toLowerCase()==="x"}),createToken:(s,o)=>({type:"taskItem",raw:"",mainContent:s.mainContent,indentLevel:s.indentLevel,checked:s.checked,text:s.mainContent,tokens:t.inlineTokens(s.mainContent),nestedTokens:o}),customNestedParser:i},t);if(r)return{type:"taskList",raw:r.raw,items:r.items}}},markdownOptions:{indentsContent:!0},addCommands(){return{toggleTaskList:()=>({commands:n})=>n.toggleList(this.name,this.options.itemTypeName)}},addKeyboardShortcuts(){return{"Mod-Shift-9":()=>this.editor.commands.toggleTaskList()}}});fe.create({name:"listKit",addExtensions(){const n=[];return this.options.bulletList!==!1&&n.push(pb.configure(this.options.bulletList)),this.options.listItem!==!1&&n.push(mb.configure(this.options.listItem)),this.options.listKeymap!==!1&&n.push(kb.configure(this.options.listKeymap)),this.options.orderedList!==!1&&n.push(Sb.configure(this.options.orderedList)),this.options.taskItem!==!1&&n.push(qE.configure(this.options.taskItem)),this.options.taskList!==!1&&n.push(KE.configure(this.options.taskList)),n}});var Rp="&nbsp;",JE=" ",GE=He.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",pe(this.options.HTMLAttributes,n),0]},parseMarkdown:(n,e)=>{const t=n.tokens||[];if(t.length===1&&t[0].type==="image")return e.parseChildren([t[0]]);const i=e.parseInline(t);return i.length===1&&i[0].type==="text"&&(i[0].text===Rp||i[0].text===JE)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,i)},renderMarkdown:(n,e)=>{if(!n)return"";const t=Array.isArray(n.content)?n.content:[];return t.length===0?Rp:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),YE=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))$/,XE=/(?:^|\s)(~~(?!\s+~~)((?:[^~]+))~~(?!\s+~~))/g,QE=zi.create({name:"strike",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"s"},{tag:"del"},{tag:"strike"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("line-through")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["s",pe(this.options.HTMLAttributes,n),0]},markdownTokenName:"del",parseMarkdown:(n,e)=>e.applyMark("strike",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`~~${e.renderChildren(n)}~~`,addCommands(){return{setStrike:()=>({commands:n})=>n.setMark(this.name),toggleStrike:()=>({commands:n})=>n.toggleMark(this.name),unsetStrike:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-Shift-s":()=>this.editor.commands.toggleStrike()}},addInputRules(){return[dr({find:YE,type:this.type})]},addPasteRules(){return[Ri({find:XE,type:this.type})]}}),ZE=He.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),eO=zi.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["u",pe(this.options.HTMLAttributes,n),0]},parseMarkdown(n,e){return e.applyMark(this.name||"underline",e.parseInline(n.tokens||[]))},renderMarkdown(n,e){return`++${e.renderChildren(n)}++`},markdownTokenizer:{name:"underline",level:"inline",start(n){return n.indexOf("++")},tokenize(n,e,t){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(n);if(!r)return;const s=r[2].trim();return{type:"underline",raw:r[0],text:s,tokens:t.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:n})=>n.setMark(this.name),toggleUnderline:()=>({commands:n})=>n.toggleMark(this.name),unsetUnderline:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}});function tO(n={}){return new se({view(e){return new nO(e,n)}})}class nO{constructor(e,t){var i;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(i=t.width)!==null&&i!==void 0?i:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let s=o=>{this[r](o)};return e.dom.addEventListener(r,s),{name:r,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,i,r=this.editorView.dom,s=r.getBoundingClientRect(),o=s.width/r.offsetWidth,l=s.height/r.offsetHeight;if(t){let u=e.nodeBefore,f=e.nodeAfter;if(u||f){let d=this.editorView.nodeDOM(this.cursorPos-(u?u.nodeSize:0));if(d){let p=d.getBoundingClientRect(),m=u?p.bottom:p.top;u&&f&&(m=(m+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let g=this.width/2*l;i={left:p.left,right:p.right,top:m-g,bottom:m+g}}}}if(!i){let u=this.editorView.coordsAtPos(this.cursorPos),f=this.width/2*o;i={left:u.left-f,right:u.left+f,top:u.top,bottom:u.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let c,h;if(!a||a==document.body&&getComputedStyle(a).position=="static")c=-pageXOffset,h=-pageYOffset;else{let u=a.getBoundingClientRect(),f=u.width/a.offsetWidth,d=u.height/a.offsetHeight;c=u.left-a.scrollLeft*f,h=u.top-a.scrollTop*d}this.element.style.left=(i.left-c)/o+"px",this.element.style.top=(i.top-h)/l+"px",this.element.style.width=(i.right-i.left)/o+"px",this.element.style.height=(i.bottom-i.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),i=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=i&&i.type.spec.disableDropCursor,s=typeof r=="function"?r(this.editorView,t,e):r;if(t&&!s){let o=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=t0(this.editorView.state.doc,o,this.editorView.dragging.slice);l!=null&&(o=l)}this.setCursor(o),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class xe extends U{constructor(e){super(e,e)}map(e,t){let i=e.resolve(t.map(this.head));return xe.valid(i)?new xe(i):U.near(i)}content(){return I.empty}eq(e){return e instanceof xe&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new xe(e.resolve(t.pos))}getBookmark(){return new nf(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!iO(e)||!rO(e))return!1;let i=t.type.spec.allowGapCursor;if(i!=null)return i;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,i=!1){e:for(;;){if(!i&&xe.valid(e))return e;let r=e.pos,s=null;for(let o=e.depth;;o--){let l=e.node(o);if(t>0?e.indexAfter(o)<l.childCount:e.index(o)>0){s=l.child(t>0?e.indexAfter(o):e.index(o)-1);break}else if(o==0)return null;r+=t;let a=e.doc.resolve(r);if(xe.valid(a))return a}for(;;){let o=t>0?s.firstChild:s.lastChild;if(!o){if(s.isAtom&&!s.isText&&!W.isSelectable(s)){e=e.doc.resolve(r+s.nodeSize*t),i=!1;continue e}break}s=o,r+=t;let l=e.doc.resolve(r);if(xe.valid(l))return l}return null}}}xe.prototype.visible=!1;xe.findFrom=xe.findGapCursorFrom;U.jsonID("gapcursor",xe);class nf{constructor(e){this.pos=e}map(e){return new nf(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return xe.valid(t)?new xe(t):U.near(t)}}function Cb(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function iO(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),i=n.node(e);if(t==0){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(t-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||Cb(r.type))return!0;if(r.inlineContent)return!1}}return!0}function rO(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),i=n.node(e);if(t==i.childCount){if(i.type.spec.isolating)return!0;continue}for(let r=i.child(t);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||Cb(r.type))return!0;if(r.inlineContent)return!1}}return!0}function sO(){return new se({props:{decorations:cO,createSelectionBetween(n,e,t){return e.pos==t.pos&&xe.valid(t)?new xe(t):null},handleClick:lO,handleKeyDown:oO,handleDOMEvents:{beforeinput:aO}}})}const oO=Ru({ArrowLeft:ao("horiz",-1),ArrowRight:ao("horiz",1),ArrowUp:ao("vert",-1),ArrowDown:ao("vert",1)});function ao(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(i,r,s){let o=i.selection,l=e>0?o.$to:o.$from,a=o.empty;if(o instanceof _){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=i.doc.resolve(e>0?l.after():l.before())}let c=xe.findGapCursorFrom(l,e,a);return c?(r&&r(i.tr.setSelection(new xe(c))),!0):!1}}function lO(n,e,t){if(!n||!n.editable)return!1;let i=n.state.doc.resolve(e);if(!xe.valid(i))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&W.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new xe(i))),!0)}function aO(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof xe))return!1;let{$from:t}=n.state.selection,i=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!i)return!1;let r=A.empty;for(let o=i.length-1;o>=0;o--)r=A.from(i[o].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new I(r,0,0));return s.setSelection(_.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function cO(n){if(!(n.selection instanceof xe))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",ue.create(n.doc,[kt.widget(n.selection.head,e,{key:"gapcursor"})])}var Nl=200,ze=function(){};ze.prototype.append=function(e){return e.length?(e=ze.from(e),!this.length&&e||e.length<Nl&&this.leafAppend(e)||this.length<Nl&&e.leafPrepend(this)||this.appendInner(e)):this};ze.prototype.prepend=function(e){return e.length?ze.from(e).append(this):this};ze.prototype.appendInner=function(e){return new hO(this,e)};ze.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ze.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ze.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ze.prototype.forEach=function(e,t,i){t===void 0&&(t=0),i===void 0&&(i=this.length),t<=i?this.forEachInner(e,t,i,0):this.forEachInvertedInner(e,t,i,0)};ze.prototype.map=function(e,t,i){t===void 0&&(t=0),i===void 0&&(i=this.length);var r=[];return this.forEach(function(s,o){return r.push(e(s,o))},t,i),r};ze.from=function(e){return e instanceof ze?e:e&&e.length?new Mb(e):ze.empty};var Mb=(function(n){function e(i){n.call(this),this.values=i}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,s){return r==0&&s==this.length?this:new e(this.values.slice(r,s))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,s,o,l){for(var a=s;a<o;a++)if(r(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,o,l){for(var a=s-1;a>=o;a--)if(r(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=Nl)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=Nl)return new e(r.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e})(ze);ze.empty=new Mb([]);var hO=(function(n){function e(t,i){n.call(this),this.left=t,this.right=i,this.length=t.length+i.length,this.depth=Math.max(t.depth,i.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(i){return i<this.left.length?this.left.get(i):this.right.get(i-this.left.length)},e.prototype.forEachInner=function(i,r,s,o){var l=this.left.length;if(r<l&&this.left.forEachInner(i,r,Math.min(s,l),o)===!1||s>l&&this.right.forEachInner(i,Math.max(r-l,0),Math.min(this.length,s)-l,o+l)===!1)return!1},e.prototype.forEachInvertedInner=function(i,r,s,o){var l=this.left.length;if(r>l&&this.right.forEachInvertedInner(i,r-l,Math.max(s,l)-l,o+l)===!1||s<l&&this.left.forEachInvertedInner(i,Math.min(r,l),s,o)===!1)return!1},e.prototype.sliceInner=function(i,r){if(i==0&&r==this.length)return this;var s=this.left.length;return r<=s?this.left.slice(i,r):i>=s?this.right.slice(i-s,r-s):this.left.slice(i,s).append(this.right.slice(0,r-s))},e.prototype.leafAppend=function(i){var r=this.right.leafAppend(i);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(i){var r=this.left.leafPrepend(i);if(r)return new e(r,this.right)},e.prototype.appendInner=function(i){return this.left.depth>=Math.max(this.right.depth,i.depth)+1?new e(this.left,new e(this.right,i)):new e(this,i)},e})(ze);const uO=500;class zt{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let i=this.items.length;for(;;i--)if(this.items.get(i-1).selection){--i;break}let r,s;t&&(r=this.remapping(i,this.items.length),s=r.maps.length);let o=e.tr,l,a,c=[],h=[];return this.items.forEach((u,f)=>{if(!u.step){r||(r=this.remapping(i,f+1),s=r.maps.length),s--,h.push(u);return}if(r){h.push(new en(u.map));let d=u.step.map(r.slice(s)),p;d&&o.maybeStep(d).doc&&(p=o.mapping.maps[o.mapping.maps.length-1],c.push(new en(p,void 0,void 0,c.length+h.length))),s--,p&&r.appendMap(p,s)}else o.maybeStep(u.step);if(u.selection)return l=r?u.selection.map(r.slice(s)):u.selection,a=new zt(this.items.slice(0,i).append(h.reverse().concat(c)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:o,selection:l}}addTransform(e,t,i,r){let s=[],o=this.eventCount,l=this.items,a=!r&&l.length?l.get(l.length-1):null;for(let h=0;h<e.steps.length;h++){let u=e.steps[h].invert(e.docs[h]),f=new en(e.mapping.maps[h],u,t),d;(d=a&&a.merge(f))&&(f=d,h?s.pop():l=l.slice(0,l.length-1)),s.push(f),t&&(o++,t=void 0),r||(a=f)}let c=o-i.depth;return c>dO&&(l=fO(l,c),o-=c),new zt(l.append(s),o)}remapping(e,t){let i=new ds;return this.items.forEach((r,s)=>{let o=r.mirrorOffset!=null&&s-r.mirrorOffset>=e?i.maps.length-r.mirrorOffset:void 0;i.appendMap(r.map,o)},e,t),i}addMaps(e){return this.eventCount==0?this:new zt(this.items.append(e.map(t=>new en(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let i=[],r=Math.max(0,this.items.length-t),s=e.mapping,o=e.steps.length,l=this.eventCount;this.items.forEach(f=>{f.selection&&l--},r);let a=t;this.items.forEach(f=>{let d=s.getMirror(--a);if(d==null)return;o=Math.min(o,d);let p=s.maps[d];if(f.step){let m=e.steps[d].invert(e.docs[d]),g=f.selection&&f.selection.map(s.slice(a+1,d));g&&l++,i.push(new en(p,m,g))}else i.push(new en(p))},r);let c=[];for(let f=t;f<o;f++)c.push(new en(s.maps[f]));let h=this.items.slice(0,r).append(c).append(i),u=new zt(h,l);return u.emptyItemCount()>uO&&(u=u.compress(this.items.length-i.length)),u}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),i=t.maps.length,r=[],s=0;return this.items.forEach((o,l)=>{if(l>=e)r.push(o),o.selection&&s++;else if(o.step){let a=o.step.map(t.slice(i)),c=a&&a.getMap();if(i--,c&&t.appendMap(c,i),a){let h=o.selection&&o.selection.map(t.slice(i));h&&s++;let u=new en(c.invert(),a,h),f,d=r.length-1;(f=r.length&&r[d].merge(u))?r[d]=f:r.push(u)}}else o.map&&i--},this.items.length,0),new zt(ze.from(r.reverse()),s)}}zt.empty=new zt(ze.empty,0);function fO(n,e){let t;return n.forEach((i,r)=>{if(i.selection&&e--==0)return t=r,!1}),n.slice(t)}class en{constructor(e,t,i,r){this.map=e,this.step=t,this.selection=i,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new en(t.getMap().invert(),t,this.selection)}}}let zn=class{constructor(e,t,i,r,s){this.done=e,this.undone=t,this.prevRanges=i,this.prevTime=r,this.prevComposition=s}};const dO=20;function pO(n,e,t,i){let r=t.getMeta(Ci),s;if(r)return r.historyState;t.getMeta(yO)&&(n=new zn(n.done,n.undone,null,0,-1));let o=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(o&&o.getMeta(Ci))return o.getMeta(Ci).redo?new zn(n.done.addTransform(t,void 0,i,Fo(e)),n.undone,Dp(t.mapping.maps),n.prevTime,n.prevComposition):new zn(n.done,n.undone.addTransform(t,void 0,i,Fo(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(o&&o.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!o&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-i.newGroupDelay||!mO(t,n.prevRanges)),c=o?hc(n.prevRanges,t.mapping):Dp(t.mapping.maps);return new zn(n.done.addTransform(t,a?e.selection.getBookmark():void 0,i,Fo(e)),zt.empty,c,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new zn(n.done.rebased(t,s),n.undone.rebased(t,s),hc(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new zn(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),hc(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function mO(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((i,r)=>{for(let s=0;s<e.length;s+=2)i<=e[s+1]&&r>=e[s]&&(t=!0)}),t}function Dp(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((i,r,s,o)=>e.push(s,o));return e}function hc(n,e){if(!n)return null;let t=[];for(let i=0;i<n.length;i+=2){let r=e.map(n[i],1),s=e.map(n[i+1],-1);r<=s&&t.push(r,s)}return t}function gO(n,e,t){let i=Fo(e),r=Ci.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,i);if(!s)return null;let o=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),r,i),a=new zn(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(o).setMeta(Ci,{redo:t,historyState:a})}let uc=!1,Np=null;function Fo(n){let e=n.plugins;if(Np!=e){uc=!1,Np=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){uc=!0;break}}return uc}const Ci=new me("history"),yO=new me("closeHistory");function bO(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new se({key:Ci,state:{init(){return new zn(zt.empty,zt.empty,null,0,-1)},apply(e,t,i){return pO(t,i,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let i=t.inputType,r=i=="historyUndo"?Ab:i=="historyRedo"?Eb:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function Tb(n,e){return(t,i)=>{let r=Ci.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(i){let s=gO(r,t,n);s&&i(e?s.scrollIntoView():s)}return!0}}const Ab=Tb(!1,!0),Eb=Tb(!0,!0);fe.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:n=>n.length,wordCounter:n=>n.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=n=>{const e=n?.node||this.editor.state.doc;if((n?.mode||this.options.mode)==="textSize"){const i=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(i)}return e.nodeSize},this.storage.words=n=>{const e=n?.node||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let n=!1;return[new se({key:new me("characterCount"),appendTransaction:(e,t,i)=>{if(n)return;const r=this.options.limit;if(r==null||r===0){n=!0;return}const s=this.storage.characters({node:i.doc});if(s>r){const o=s-r,l=0,a=o;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const c=i.tr.deleteRange(l,a);return n=!0,c}n=!0},filterTransaction:(e,t)=>{const i=this.options.limit;if(!e.docChanged||i===0||i===null||i===void 0)return!0;const r=this.storage.characters({node:t.doc}),s=this.storage.characters({node:e.doc});if(s<=i||r>i&&s>i&&s<=r)return!0;if(r>i&&s>i&&s>r||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,a=s-i,c=l-a,h=l;return e.deleteRange(c,h),!(this.storage.characters({node:e.doc})>i)}})]}});var xO=fe.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[tO(this.options)]}});fe.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new se({key:new me("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:i}=this.editor,{anchor:r}=e,s=[];if(!t||!i)return ue.create(n,[]);let o=0;this.options.mode==="deepest"&&n.descendants((a,c)=>{if(a.isText)return;if(!(r>=c&&r<=c+a.nodeSize-1))return!1;o+=1});let l=0;return n.descendants((a,c)=>{if(a.isText||!(r>=c&&r<=c+a.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&o-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";s.push(kt.node(c,c+a.nodeSize,{class:this.options.className}))}),ue.create(n,s)}}})]}});var wO=fe.create({name:"gapCursor",addProseMirrorPlugins(){return[sO()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=re(H(n,"allowGapCursor",t)))!=null?e:null}}}),Ip="placeholder";function kO(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}var vO=fe.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Ip,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${kO(this.options.dataAttribute)}`:`data-${Ip}`;return[new se({key:new me("placeholder"),props:{decorations:({doc:e,selection:t})=>{const i=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(!i)return null;const o=this.editor.isEmpty;return e.descendants((l,a)=>{const c=r>=a&&r<=a+l.nodeSize,h=!l.isLeaf&&ma(l);if((c||!this.options.showOnlyCurrent)&&h){const u=[this.options.emptyNodeClass];o&&u.push(this.options.emptyEditorClass);const f=kt.node(a,a+l.nodeSize,{class:u.join(" "),[n]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:a,hasAnchor:c}):this.options.placeholder});s.push(f)}return this.options.includeChildren}),ue.create(e,s)}}})]}});fe.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new se({key:new me("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||xy(t.selection)||n.view.dragging?null:ue.create(t.doc,[kt.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Lp({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||e?.type===n}var SO=fe.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new me(this.name),t=this.options.node||((n=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:n.name)||"paragraph",i=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(t).includes(r.name));return[new se({key:e,appendTransaction:(r,s,o)=>{const{doc:l,tr:a,schema:c}=o,h=e.getState(o),u=l.content.size,f=c.nodes[t];if(h)return a.insert(u,f.create())},state:{init:(r,s)=>{const o=s.tr.doc.lastChild;return!Lp({node:o,types:i})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const o=r.doc.lastChild;return!Lp({node:o,types:i})}}})]}}),CO=fe.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Ab(n,e),redo:()=>({state:n,dispatch:e})=>Eb(n,e)}},addProseMirrorPlugins(){return[bO(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}}),MO=fe.create({name:"starterKit",addExtensions(){var n,e,t,i;const r=[];return this.options.bold!==!1&&r.push(GA.configure(this.options.bold)),this.options.blockquote!==!1&&r.push(_A.configure(this.options.blockquote)),this.options.bulletList!==!1&&r.push(pb.configure(this.options.bulletList)),this.options.code!==!1&&r.push(QA.configure(this.options.code)),this.options.codeBlock!==!1&&r.push(tE.configure(this.options.codeBlock)),this.options.document!==!1&&r.push(nE.configure(this.options.document)),this.options.dropcursor!==!1&&r.push(xO.configure(this.options.dropcursor)),this.options.gapcursor!==!1&&r.push(wO.configure(this.options.gapcursor)),this.options.hardBreak!==!1&&r.push(iE.configure(this.options.hardBreak)),this.options.heading!==!1&&r.push(rE.configure(this.options.heading)),this.options.undoRedo!==!1&&r.push(CO.configure(this.options.undoRedo)),this.options.horizontalRule!==!1&&r.push(sE.configure(this.options.horizontalRule)),this.options.italic!==!1&&r.push(hE.configure(this.options.italic)),this.options.listItem!==!1&&r.push(mb.configure(this.options.listItem)),this.options.listKeymap!==!1&&r.push(kb.configure((n=this.options)==null?void 0:n.listKeymap)),this.options.link!==!1&&r.push(PE.configure((e=this.options)==null?void 0:e.link)),this.options.orderedList!==!1&&r.push(Sb.configure(this.options.orderedList)),this.options.paragraph!==!1&&r.push(GE.configure(this.options.paragraph)),this.options.strike!==!1&&r.push(QE.configure(this.options.strike)),this.options.text!==!1&&r.push(ZE.configure(this.options.text)),this.options.underline!==!1&&r.push(eO.configure((t=this.options)==null?void 0:t.underline)),this.options.trailingNode!==!1&&r.push(SO.configure((i=this.options)==null?void 0:i.trailingNode)),r}}),TO=MO,AO=vO,EO=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,OO=He.create({name:"image",addOptions(){return{inline:!1,allowBase64:!1,HTMLAttributes:{},resize:!1}},inline(){return this.options.inline},group(){return this.options.inline?"inline":"block"},draggable:!0,addAttributes(){return{src:{default:null},alt:{default:null},title:{default:null},width:{default:null},height:{default:null}}},parseHTML(){return[{tag:this.options.allowBase64?"img[src]":'img[src]:not([src^="data:"])'}]},renderHTML({HTMLAttributes:n}){return["img",pe(this.options.HTMLAttributes,n)]},parseMarkdown:(n,e)=>e.createNode("image",{src:n.href,title:n.title,alt:n.text}),renderMarkdown:n=>{var e,t,i,r,s,o;const l=(t=(e=n.attrs)==null?void 0:e.src)!=null?t:"",a=(r=(i=n.attrs)==null?void 0:i.alt)!=null?r:"",c=(o=(s=n.attrs)==null?void 0:s.title)!=null?o:"";return c?`![${a}](${l} "${c}")`:`![${a}](${l})`},addNodeView(){if(!this.options.resize||!this.options.resize.enabled||typeof document>"u")return null;const{directions:n,minWidth:e,minHeight:t,alwaysPreserveAspectRatio:i}=this.options.resize;return({node:r,getPos:s,HTMLAttributes:o,editor:l})=>{const a=document.createElement("img");Object.entries(o).forEach(([u,f])=>{if(f!=null)switch(u){case"width":case"height":break;default:a.setAttribute(u,f);break}}),a.src=o.src;const c=new IM({element:a,editor:l,node:r,getPos:s,onResize:(u,f)=>{a.style.width=`${u}px`,a.style.height=`${f}px`},onCommit:(u,f)=>{const d=s();d!==void 0&&this.editor.chain().setNodeSelection(d).updateAttributes(this.name,{width:u,height:f}).run()},onUpdate:(u,f,d)=>u.type===r.type,options:{directions:n,min:{width:e,height:t},preserveAspectRatio:i===!0}}),h=c.dom;return h.style.visibility="hidden",h.style.pointerEvents="none",a.onload=()=>{h.style.visibility="",h.style.pointerEvents=""},c}},addCommands(){return{setImage:n=>({commands:e})=>e.insertContent({type:this.name,attrs:n})}},addInputRules(){return[zy({find:EO,type:this.type,getAttributes:n=>{const[,,e,t,i]=n;return{src:t,alt:e,title:i}}})]}}),RO=OO;function DO(n,e){const i=e.split(`
142
+ `).flatMap(r=>[r,""]).map(r=>`${n}${r}`).join(`
143
+ `);return i.slice(0,i.length-1)}function NO(n,e){const t=[];return Array.from(n.keys()).forEach(i=>{(!e||!e.marks||!e.marks.map(r=>r.type).includes(i))&&t.push(i)}),t}function IO(n,e){const t=[];return Array.from(e.entries()).forEach(([i,r])=>{n.has(i)||t.push({type:i,mark:r})}),t}function LO(n,e,t,i){const r=!t,s=t&&t.type==="text"&&(!t.marks||t.marks.length===0),o=t&&t.type==="text"&&t.marks&&!i(e,new Map(t.marks.map(a=>[a.type,a]))),l=[];if(r||s||o)if(t&&t.type==="text"&&t.marks){const a=new Map(t.marks.map(c=>[c.type,c]));Array.from(n.keys()).forEach(c=>{a.has(c)||l.push(c)})}else(r||s)&&l.push(...Array.from(n.keys()));return l}function PO(n,e){let t="";return Array.from(n.keys()).reverse().forEach(i=>{const r=n.get(i),s=e(i,r);s&&(t=s+t)}),n.clear(),t}function BO(n,e,t){let i="";return Array.from(n.entries()).forEach(([r,s])=>{const o=t(r,s);o&&(i+=o),e.set(r,s)}),i}function fc(n){const t=(n.raw||n.text||"").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);return t?{isTask:!0,checked:t[2].toLowerCase()==="x",indentLevel:t[1].length}:{isTask:!1,indentLevel:0}}function co(n,e){return typeof n!="string"?"json":e}var zO=class{constructor(n){this.baseExtensions=[],this.extensions=[],this.lastParseResult=null;var e,t,i,r,s;this.markedInstance=(e=n?.marked)!=null?e:pw,this.lexer=new this.markedInstance.Lexer,this.indentStyle=(i=(t=n?.indentation)==null?void 0:t.style)!=null?i:"space",this.indentSize=(s=(r=n?.indentation)==null?void 0:r.size)!=null?s:2,this.baseExtensions=n?.extensions||[],n?.markedOptions&&typeof this.markedInstance.setOptions=="function"&&this.markedInstance.setOptions(n.markedOptions),this.registry=new Map,this.nodeTypeRegistry=new Map,n?.extensions&&(this.baseExtensions=n.extensions,pa(n.extensions).forEach(l=>this.registerExtension(l,!1))),this.lexer=new this.markedInstance.Lexer}get instance(){return this.markedInstance}get indentCharacter(){return this.indentStyle==="space"?" ":" "}get indentString(){return this.indentCharacter.repeat(this.indentSize)}hasMarked(){return!!this.markedInstance}registerExtension(n,e=!0){var t,i;this.extensions.push(n);const r=n.name,s=H(n,"markdownTokenName")||r,o=H(n,"parseMarkdown"),l=H(n,"renderMarkdown"),a=H(n,"markdownTokenizer"),c=(t=H(n,"markdownOptions"))!=null?t:null,h=(i=c?.indentsContent)!=null?i:!1,u={tokenName:s,nodeName:r,parseMarkdown:o,renderMarkdown:l,isIndenting:h,tokenizer:a};if(s&&o){const f=this.registry.get(s)||[];f.push(u),this.registry.set(s,f)}if(l){const f=this.nodeTypeRegistry.get(r)||[];f.push(u),this.nodeTypeRegistry.set(r,f)}a&&this.hasMarked()&&(this.registerTokenizer(a),e&&(this.lexer=new this.markedInstance.Lexer))}registerTokenizer(n){if(!this.hasMarked())return;const{name:e,start:t,level:i="inline",tokenize:r}=n,l={inlineTokens:h=>this.lexer.inlineTokens(h),blockTokens:h=>this.lexer.blockTokens(h)};let a;t?a=typeof t=="function"?t:h=>h.indexOf(t):a=h=>{const u=r(h,[],l);return u&&u.raw?h.indexOf(u.raw):-1};const c={name:e,level:i,start:a,tokenizer:(h,u)=>{const f=r(h,u,l);if(f&&f.type)return{...f,type:f.type||e,raw:f.raw||"",tokens:f.tokens||[]}},childTokens:[]};this.markedInstance.use({extensions:[c]})}getHandlersForToken(n){try{return this.registry.get(n)||[]}catch{return[]}}getHandlerForToken(n){const e=this.getHandlersForToken(n);if(e.length>0)return e[0];const t=this.getHandlersForNodeType(n);return t.length>0?t[0]:void 0}getHandlersForNodeType(n){try{return this.nodeTypeRegistry.get(n)||[]}catch{return[]}}serialize(n){return n?Array.isArray(n)?this.renderNodes(n,n):this.renderNodes(n,n):""}parse(n){if(!this.hasMarked())throw new Error("No marked instance available for parsing");const e=this.markedInstance.lexer(n);return{type:"doc",content:this.parseTokens(e)}}parseTokens(n){return n.map(e=>this.parseToken(e)).filter(e=>e!==null).flatMap(e=>Array.isArray(e)?e:[e])}parseToken(n){if(!n.type)return null;if(n.type==="list")return this.parseListToken(n);const e=this.getHandlersForToken(n.type),t=this.createParseHelpers();if(e.find(r=>{if(!r.parseMarkdown)return!1;const s=r.parseMarkdown(n,t),o=this.normalizeParseResult(s);return o&&(!Array.isArray(o)||o.length>0)?(this.lastParseResult=o,!0):!1})&&this.lastParseResult){const r=this.lastParseResult;return this.lastParseResult=null,r}return this.parseFallbackToken(n)}parseListToken(n){if(!n.items||n.items.length===0)return this.parseTokenWithHandlers(n);const e=n.items.some(l=>fc(l).isTask),t=n.items.some(l=>!fc(l).isTask);if(!e||!t||this.getHandlersForToken("taskList").length===0)return this.parseTokenWithHandlers(n);const i=[];let r=[],s=null;for(let l=0;l<n.items.length;l+=1){const a=n.items[l],{isTask:c,checked:h,indentLevel:u}=fc(a);let f=a;if(c){const m=(a.raw||a.text||"").split(`
144
+ `),g=m[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/),y=g?g[2]:"";let b=[];if(m.length>1&&m.slice(1).join(`
145
+ `).trim()){const k=m.slice(1),w=k.filter(C=>C.trim());if(w.length>0){const C=Math.min(...w.map(L=>L.length-L.trimStart().length)),D=k.map(L=>L.trim()?L.slice(C):"").join(`
146
+ `).trim();D&&(b=this.markedInstance.lexer(`${D}
147
+ `))}}f={type:"taskItem",raw:"",mainContent:y,indentLevel:u,checked:h??!1,text:y,tokens:this.lexer.inlineTokens(y),nestedTokens:b}}const d=c?"taskList":"list";s!==d?(r.length>0&&i.push({type:s,items:r}),r=[f],s=d):r.push(f)}r.length>0&&i.push({type:s,items:r});const o=[];for(let l=0;l<i.length;l+=1){const a=i[l],c={...n,type:a.type,items:a.items},h=this.parseToken(c);h&&(Array.isArray(h)?o.push(...h):o.push(h))}return o.length>0?o:null}parseTokenWithHandlers(n){if(!n.type)return null;const e=this.getHandlersForToken(n.type),t=this.createParseHelpers();if(e.find(r=>{if(!r.parseMarkdown)return!1;const s=r.parseMarkdown(n,t),o=this.normalizeParseResult(s);return o&&(!Array.isArray(o)||o.length>0)?(this.lastParseResult=o,!0):!1})&&this.lastParseResult){const r=this.lastParseResult;return this.lastParseResult=null,r}return this.parseFallbackToken(n)}createParseHelpers(){return{parseInline:n=>this.parseInlineTokens(n),parseChildren:n=>this.parseTokens(n),createTextNode:(n,e)=>({type:"text",text:n,marks:e||void 0}),createNode:(n,e,t)=>{const i={type:n,attrs:e||void 0,content:t||void 0};return(!e||Object.keys(e).length===0)&&delete i.attrs,i},applyMark:(n,e,t)=>({mark:n,content:e,attrs:t&&Object.keys(t).length>0?t:void 0})}}escapeRegex(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}parseInlineTokens(n){var e,t,i,r;const s=[];for(let o=0;o<n.length;o+=1){const l=n[o];if(l.type==="text")s.push({type:"text",text:l.text||""});else if(l.type==="html"){const a=((t=(e=l.raw)!=null?e:l.text)!=null?t:"").toString(),c=/^<\/[\s]*[\w-]+/i.test(a),h=a.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);if(!c&&h&&!/\/>$/.test(a)){const f=h[1],d=this.escapeRegex(f),p=new RegExp(`^<\\/\\s*${d}\\b`,"i");let m=-1;const g=[a];for(let y=o+1;y<n.length;y+=1){const b=n[y],x=((r=(i=b.raw)!=null?i:b.text)!=null?r:"").toString();if(g.push(x),b.type==="html"&&p.test(x)){m=y;break}}if(m!==-1){const y=g.join(""),b={type:"html",raw:y,text:y,block:!1},x=this.parseHTMLToken(b);if(x){const k=this.normalizeParseResult(x);Array.isArray(k)?s.push(...k):k&&s.push(k)}o=m;continue}}const u=this.parseHTMLToken(l);if(u){const f=this.normalizeParseResult(u);Array.isArray(f)?s.push(...f):f&&s.push(f)}}else if(l.type){const a=this.getHandlerForToken(l.type);if(a&&a.parseMarkdown){const c=this.createParseHelpers(),h=a.parseMarkdown(l,c);if(this.isMarkResult(h)){const u=this.applyMarkToContent(h.mark,h.content,h.attrs);s.push(...u)}else{const u=this.normalizeParseResult(h);Array.isArray(u)?s.push(...u):u&&s.push(u)}}else l.tokens&&s.push(...this.parseInlineTokens(l.tokens))}}return s}applyMarkToContent(n,e,t){return e.map(i=>{if(i.type==="text"){const r=i.marks||[],s=t?{type:n,attrs:t}:{type:n};return{...i,marks:[...r,s]}}return{...i,content:i.content?this.applyMarkToContent(n,i.content,t):void 0}})}isMarkResult(n){return n&&typeof n=="object"&&"mark"in n}normalizeParseResult(n){return n?this.isMarkResult(n)?n.content:n:null}parseFallbackToken(n){switch(n.type){case"paragraph":return{type:"paragraph",content:n.tokens?this.parseInlineTokens(n.tokens):[]};case"heading":return{type:"heading",attrs:{level:n.depth||1},content:n.tokens?this.parseInlineTokens(n.tokens):[]};case"text":return{type:"text",text:n.text||""};case"html":return this.parseHTMLToken(n);case"space":return null;default:return n.tokens?this.parseTokens(n.tokens):null}}parseHTMLToken(n){const e=n.text||n.raw||"";if(!e.trim())return null;if(typeof window>"u")return n.block?{type:"paragraph",content:[{type:"text",text:e}]}:{type:"text",text:e};try{const t=FC(e,this.baseExtensions);return t.type==="doc"&&t.content?n.block?t.content:t.content.length===1&&t.content[0].type==="paragraph"&&t.content[0].content?t.content[0].content:t.content:t}catch(t){throw new Error(`Failed to parse HTML in markdown: ${t}`)}}renderNodeToMarkdown(n,e,t=0,i=0){var r;if(n.type==="text")return n.text||"";if(!n.type)return"";const s=this.getHandlerForToken(n.type);if(!s)return"";const o={renderChildren:(c,h)=>{const u=s.isIndenting?i+1:i;return!Array.isArray(c)&&c.content?this.renderNodes(c.content,n,h||"",t,u):this.renderNodes(c,n,h||"",t,u)},indent:c=>this.indentString+c,wrapInBlock:DO},l={index:t,level:i,parentType:e?.type,meta:{parentAttrs:e?.attrs}};return((r=s.renderMarkdown)==null?void 0:r.call(s,n,o,l))||""}renderNodes(n,e,t="",i=0,r=0){return Array.isArray(n)?this.renderNodesWithMarkBoundaries(n,e,t,r):n.type?this.renderNodeToMarkdown(n,e,i,r):""}renderNodesWithMarkBoundaries(n,e,t="",i=0){const r=[],s=new Map;return n.forEach((o,l)=>{const a=l<n.length-1?n[l+1]:null;if(o.type)if(o.type==="text"){let c=o.text||"";const h=new Map((o.marks||[]).map(y=>[y.type,y])),u=IO(s,h),f=NO(h,a);let d="";if(f.length>0){const y=c.match(/(\s+)$/);y&&(d=y[1],c=c.slice(0,-d.length))}f.forEach(y=>{const b=h.get(y),x=this.getMarkClosing(y,b);x&&(c+=x),s.has(y)&&s.delete(y)});let p="";if(u.length>0){const y=c.match(/^(\s+)/);y&&(p=y[1],c=c.slice(p.length))}u.forEach(({type:y,mark:b})=>{const x=this.getMarkOpening(y,b);x&&(c=x+c),f.includes(y)||s.set(y,b)}),c=p+c;const m=LO(s,h,a,this.markSetsEqual.bind(this));let g="";if(m.length>0){const y=c.match(/(\s+)$/);y&&(g=y[1],c=c.slice(0,-g.length))}m.forEach(y=>{const b=s.get(y),x=this.getMarkClosing(y,b);x&&(c+=x),s.delete(y)}),c+=g,c+=d,r.push(c)}else{const c=new Map(s),h=PO(s,this.getMarkClosing.bind(this)),u=this.renderNodeToMarkdown(o,e,l,i),f=o.type==="hardBreak"?"":BO(c,s,this.getMarkOpening.bind(this));r.push(h+u+f)}}),r.join(t)}getMarkOpening(n,e){const t=this.getHandlersForNodeType(n),i=t.length>0?t[0]:void 0;if(!i||!i.renderMarkdown)return"";const r="__TIPTAP_MARKDOWN_PLACEHOLDER__",s={type:n,attrs:e.attrs||{},content:[{type:"text",text:r}]};try{const o=i.renderMarkdown(s,{renderChildren:()=>r,indent:a=>a,wrapInBlock:(a,c)=>a+c},{index:0,level:0,parentType:"text",meta:{}}),l=o.indexOf(r);return l>=0?o.substring(0,l):""}catch(o){throw new Error(`Failed to get mark opening for ${n}: ${o}`)}}getMarkClosing(n,e){const t=this.getHandlersForNodeType(n),i=t.length>0?t[0]:void 0;if(!i||!i.renderMarkdown)return"";const r="__TIPTAP_MARKDOWN_PLACEHOLDER__",s={type:n,attrs:e.attrs||{},content:[{type:"text",text:r}]};try{const o=i.renderMarkdown(s,{renderChildren:()=>r,indent:c=>c,wrapInBlock:(c,h)=>c+h},{index:0,level:0,parentType:"text",meta:{}}),l=o.indexOf(r),a=l+r.length;return l>=0?o.substring(a):""}catch(o){throw new Error(`Failed to get mark closing for ${n}: ${o}`)}}markSetsEqual(n,e){return n.size!==e.size?!1:Array.from(n.keys()).every(t=>e.has(t))}},Pp=zO,HO=fe.create({name:"markdown",addOptions(){return{indentation:{style:"space",size:2},marked:void 0,markedOptions:{}}},addCommands(){return{setContent:(n,e)=>{if(!e?.contentType||co(n,e?.contentType)!=="markdown"||!this.editor.markdown)return Bt.setContent(n,e);const i=this.editor.markdown.parse(n);return Bt.setContent(i,e)},insertContent:(n,e)=>{if(!e?.contentType||co(n,e?.contentType)!=="markdown"||!this.editor.markdown)return Bt.insertContent(n,e);const i=this.editor.markdown.parse(n);return Bt.insertContent(i,e)},insertContentAt:(n,e,t)=>{if(!t?.contentType||co(e,t?.contentType)!=="markdown"||!this.editor.markdown)return Bt.insertContentAt(n,e,t);const r=this.editor.markdown.parse(e);return Bt.insertContentAt(n,r,t)}}},addStorage(){return{manager:new Pp({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:[]})}},onBeforeCreate(){if(this.editor.markdown){console.error("[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior.");return}if(this.storage.manager=new Pp({indentation:this.options.indentation,marked:this.options.marked,markedOptions:this.options.markedOptions,extensions:this.editor.extensionManager.baseExtensions}),this.editor.markdown=this.storage.manager,this.editor.getMarkdown=()=>this.storage.manager.serialize(this.editor.getJSON()),!this.editor.options.contentType||co(this.editor.options.content,this.editor.options.contentType)!=="markdown")return;if(!this.editor.markdown)throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.');if(this.editor.options.content===void 0||typeof this.editor.options.content!="string")throw new Error('[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.');const e=this.editor.markdown.parse(this.editor.options.content);this.editor.options.content=e}}),FO=He.create({name:"tableCell",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{var e,t;const i=n.getAttribute("colwidth"),r=i?i.split(",").map(s=>parseInt(s,10)):null;if(!r){const s=(e=n.closest("table"))==null?void 0:e.querySelectorAll("colgroup > col"),o=Array.from(((t=n.parentElement)==null?void 0:t.children)||[]).indexOf(n);if(o&&o>-1&&s&&s[o]){const l=s[o].getAttribute("width");return l?[parseInt(l,10)]:null}}return r}}}},tableRole:"cell",isolating:!0,parseHTML(){return[{tag:"td"}]},renderHTML({HTMLAttributes:n}){return["td",pe(this.options.HTMLAttributes,n),0]}}),$O=He.create({name:"tableHeader",addOptions(){return{HTMLAttributes:{}}},content:"block+",addAttributes(){return{colspan:{default:1},rowspan:{default:1},colwidth:{default:null,parseHTML:n=>{const e=n.getAttribute("colwidth");return e?e.split(",").map(i=>parseInt(i,10)):null}}}},tableRole:"header_cell",isolating:!0,parseHTML(){return[{tag:"th"}]},renderHTML({HTMLAttributes:n}){return["th",pe(this.options.HTMLAttributes,n),0]}}),VO=He.create({name:"tableRow",addOptions(){return{HTMLAttributes:{}}},content:"(tableCell | tableHeader)*",tableRole:"row",parseHTML(){return[{tag:"tr"}]},renderHTML({HTMLAttributes:n}){return["tr",pe(this.options.HTMLAttributes,n),0]}});function kh(n,e){return e?["width",`${Math.max(e,n)}px`]:["min-width",`${n}px`]}function Bp(n,e,t,i,r,s){var o;let l=0,a=!0,c=e.firstChild;const h=n.firstChild;if(h!==null)for(let f=0,d=0;f<h.childCount;f+=1){const{colspan:p,colwidth:m}=h.child(f).attrs;for(let g=0;g<p;g+=1,d+=1){const y=r===d?s:m&&m[g],b=y?`${y}px`:"";if(l+=y||i,y||(a=!1),c){if(c.style.width!==b){const[x,k]=kh(i,y);c.style.setProperty(x,k)}c=c.nextSibling}else{const x=document.createElement("col"),[k,w]=kh(i,y);x.style.setProperty(k,w),e.appendChild(x)}}}for(;c;){const f=c.nextSibling;(o=c.parentNode)==null||o.removeChild(c),c=f}const u=n.attrs.style&&typeof n.attrs.style=="string"&&/\bwidth\s*:/i.test(n.attrs.style);a&&!u?(t.style.width=`${l}px`,t.style.minWidth=""):(t.style.width="",t.style.minWidth=`${l}px`)}var WO=class{constructor(n,e){this.node=n,this.cellMinWidth=e,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),n.attrs.style&&(this.table.style.cssText=n.attrs.style),this.colgroup=this.table.appendChild(document.createElement("colgroup")),Bp(n,this.colgroup,this.table,e),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(n){return n.type!==this.node.type?!1:(this.node=n,Bp(n,this.colgroup,this.table,this.cellMinWidth),!0)}ignoreMutation(n){const e=n.target,t=this.dom.contains(e),i=this.contentDOM.contains(e);return!!(t&&!i&&(n.type==="attributes"||n.type==="childList"||n.type==="characterData"))}};function jO(n,e,t,i){let r=0,s=!0;const o=[],l=n.firstChild;if(!l)return{};for(let u=0,f=0;u<l.childCount;u+=1){const{colspan:d,colwidth:p}=l.child(u).attrs;for(let m=0;m<d;m+=1,f+=1){const g=t===f?i:p&&p[m];r+=g||e,g||(s=!1);const[y,b]=kh(e,g);o.push(["col",{style:`${y}: ${b}`}])}}const a=s?`${r}px`:"",c=s?"":`${r}px`;return{colgroup:["colgroup",{},...o],tableWidth:a,tableMinWidth:c}}function zp(n,e){return n.createAndFill()}function _O(n){if(n.cached.tableNodeTypes)return n.cached.tableNodeTypes;const e={};return Object.keys(n.nodes).forEach(t=>{const i=n.nodes[t];i.spec.tableRole&&(e[i.spec.tableRole]=i)}),n.cached.tableNodeTypes=e,e}function UO(n,e,t,i,r){const s=_O(n),o=[],l=[];for(let c=0;c<t;c+=1){const h=zp(s.cell);if(h&&l.push(h),i){const u=zp(s.header_cell);u&&o.push(u)}}const a=[];for(let c=0;c<e;c+=1)a.push(s.row.createChecked(null,i&&c===0?o:l));return s.table.createChecked(null,a)}function qO(n){return n instanceof ce}var ho=({editor:n})=>{const{selection:e}=n.state;if(!qO(e))return!1;let t=0;const i=uy(e.ranges[0].$from,s=>s.type.name==="table");return i?.node.descendants(s=>{if(s.type.name==="table")return!1;["tableCell","tableHeader"].includes(s.type.name)&&(t+=1)}),t===e.ranges.length?(n.commands.deleteTable(),!0):!1},KO="";function JO(n){return(n||"").replace(/\s+/g," ").trim()}function GO(n,e,t={}){var i;const r=(i=t.cellLineSeparator)!=null?i:KO;if(!n||!n.content||n.content.length===0)return"";const s=[];n.content.forEach(p=>{const m=[];p.content&&p.content.forEach(g=>{let y="";g.content&&Array.isArray(g.content)&&g.content.length>1?y=g.content.map(w=>e.renderChildren(w)).join(r):y=g.content?e.renderChildren(g.content):"";const b=JO(y),x=g.type==="tableHeader";m.push({text:b,isHeader:x})}),s.push(m)});const o=s.reduce((p,m)=>Math.max(p,m.length),0);if(o===0)return"";const l=new Array(o).fill(0);s.forEach(p=>{var m;for(let g=0;g<o;g+=1){const b=(((m=p[g])==null?void 0:m.text)||"").length;b>l[g]&&(l[g]=b),l[g]<3&&(l[g]=3)}});const a=(p,m)=>p+" ".repeat(Math.max(0,m-p.length)),c=s[0],h=c.some(p=>p.isHeader);let u=`
148
+ `;const f=new Array(o).fill(0).map((p,m)=>h&&c[m]&&c[m].text||"");return u+=`| ${f.map((p,m)=>a(p,l[m])).join(" | ")} |
149
+ `,u+=`| ${l.map(p=>"-".repeat(Math.max(3,p))).join(" | ")} |
150
+ `,(h?s.slice(1):s).forEach(p=>{u+=`| ${new Array(o).fill(0).map((m,g)=>a(p[g]&&p[g].text||"",l[g])).join(" | ")} |
151
+ `}),u}var YO=GO,XO=He.create({name:"table",addOptions(){return{HTMLAttributes:{},resizable:!1,renderWrapper:!1,handleWidth:5,cellMinWidth:25,View:WO,lastColumnResizable:!0,allowTableNodeSelection:!1}},content:"tableRow+",tableRole:"table",isolating:!0,group:"block",parseHTML(){return[{tag:"table"}]},renderHTML({node:n,HTMLAttributes:e}){const{colgroup:t,tableWidth:i,tableMinWidth:r}=jO(n,this.options.cellMinWidth),s=e.style;function o(){return s||(i?`width: ${i}`:`min-width: ${r}`)}const l=["table",pe(this.options.HTMLAttributes,e,{style:o()}),t,["tbody",0]];return this.options.renderWrapper?["div",{class:"tableWrapper"},l]:l},parseMarkdown:(n,e)=>{const t=[];if(n.header){const i=[];n.header.forEach(r=>{i.push(e.createNode("tableHeader",{},[{type:"paragraph",content:e.parseInline(r.tokens)}]))}),t.push(e.createNode("tableRow",{},i))}return n.rows&&n.rows.forEach(i=>{const r=[];i.forEach(s=>{r.push(e.createNode("tableCell",{},[{type:"paragraph",content:e.parseInline(s.tokens)}]))}),t.push(e.createNode("tableRow",{},r))}),e.createNode("table",void 0,t)},renderMarkdown:(n,e)=>YO(n,e),addCommands(){return{insertTable:({rows:n=3,cols:e=3,withHeaderRow:t=!0}={})=>({tr:i,dispatch:r,editor:s})=>{const o=UO(s.schema,n,e,t);if(r){const l=i.selection.from+1;i.replaceSelectionWith(o).scrollIntoView().setSelection(_.near(i.doc.resolve(l)))}return!0},addColumnBefore:()=>({state:n,dispatch:e})=>WT(n,e),addColumnAfter:()=>({state:n,dispatch:e})=>jT(n,e),deleteColumn:()=>({state:n,dispatch:e})=>UT(n,e),addRowBefore:()=>({state:n,dispatch:e})=>KT(n,e),addRowAfter:()=>({state:n,dispatch:e})=>JT(n,e),deleteRow:()=>({state:n,dispatch:e})=>YT(n,e),deleteTable:()=>({state:n,dispatch:e})=>iA(n,e),mergeCells:()=>({state:n,dispatch:e})=>lp(n,e),splitCell:()=>({state:n,dispatch:e})=>ap(n,e),toggleHeaderColumn:()=>({state:n,dispatch:e})=>ks("column")(n,e),toggleHeaderRow:()=>({state:n,dispatch:e})=>ks("row")(n,e),toggleHeaderCell:()=>({state:n,dispatch:e})=>tA(n,e),mergeOrSplit:()=>({state:n,dispatch:e})=>lp(n,e)?!0:ap(n,e),setCellAttribute:(n,e)=>({state:t,dispatch:i})=>ZT(n,e)(t,i),goToNextCell:()=>({state:n,dispatch:e})=>hp(1)(n,e),goToPreviousCell:()=>({state:n,dispatch:e})=>hp(-1)(n,e),fixTables:()=>({state:n,dispatch:e})=>(e&&_y(n),!0),setCellSelection:n=>({tr:e,dispatch:t})=>{if(t){const i=ce.create(e.doc,n.anchorCell,n.headCell);e.setSelection(i)}return!0}}},addKeyboardShortcuts(){return{Tab:()=>this.editor.commands.goToNextCell()?!0:this.editor.can().addRowAfter()?this.editor.chain().addRowAfter().goToNextCell().run():!1,"Shift-Tab":()=>this.editor.commands.goToPreviousCell(),Backspace:ho,"Mod-Backspace":ho,Delete:ho,"Mod-Delete":ho}},addProseMirrorPlugins(){return[...this.options.resizable&&this.editor.isEditable?[dA({handleWidth:this.options.handleWidth,cellMinWidth:this.options.cellMinWidth,defaultCellMinWidth:this.options.cellMinWidth,View:this.options.View,lastColumnResizable:this.options.lastColumnResizable})]:[],SA({allowTableNodeSelection:this.options.allowTableNodeSelection})]},extendNodeSchema(n){const e={name:n.name,options:n.options,storage:n.storage};return{tableRole:re(H(n,"tableRole",e))}}}),QO=fe.create({name:"tableKit",addExtensions(){const n=[];return this.options.table!==!1&&n.push(XO.configure(this.options.table)),this.options.tableCell!==!1&&n.push(FO.configure(this.options.tableCell)),this.options.tableHeader!==!1&&n.push($O.configure(this.options.tableHeader)),this.options.tableRow!==!1&&n.push(VO.configure(this.options.tableRow)),n}});function ZO(n){return n.startsWith("adf-file://")?"adf-file://"+n.slice(11).replace(/ /g,"%20"):n}const eR=RO.extend({addAttributes(){return{...this.parent?.(),src:{default:null,parseHTML:n=>n.getAttribute("data-adf-src")||n.getAttribute("src"),renderHTML:n=>({src:hw(n.src||""),...n.src?.startsWith("adf-file://")?{"data-adf-src":n.src}:{}})}}},renderMarkdown:n=>{const e=ZO(n.attrs?.src??""),t=n.attrs?.alt??"",i=n.attrs?.title??"",r=n.attrs?.width,s=n.attrs?.height;if(r||s){const o=[`<img src="${e}"`];return t&&o.push(`alt="${t}"`),i&&o.push(`title="${i}"`),r&&o.push(`width="${r}"`),s&&o.push(`height="${s}"`),o.join(" ")+">"}return i?`![${t}](${e} "${i}")`:`![${t}](${e})`}}).configure({allowBase64:!0,resize:{enabled:!0,alwaysPreserveAspectRatio:!0,minWidth:50,minHeight:50}}),tR=fe.create({name:"adfLinkClickHandler",addProseMirrorPlugins(){return[new se({key:new me("adfLinkClick"),props:{handleDoubleClick(n,e,t){const i=t.target.closest("a[href]");if(!i)return!1;const r=i.getAttribute("href");return r?mw(r)?(t.preventDefault(),gw(r),!0):r.startsWith("http://")||r.startsWith("https://")?(t.preventDefault(),window.open(r,"_blank"),!0):!1:!1}}})]}});function nR(){return[TO,QO.configure({table:{resizable:!1}}),eR,AO.configure({placeholder:"Start writing..."}),HO,tR]}function iR({editor:n,rawMode:e,onToggleRawMode:t}){const[,i]=M.useState(0);M.useEffect(()=>{if(!n)return;const l=()=>i(a=>a+1);return n.on("transaction",l),()=>{n.off("transaction",l)}},[n]);const r=l=>`px-2 py-1 text-sm rounded ${l?"bg-neutral-200 text-neutral-900 dark:bg-neutral-600 dark:text-neutral-100":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-100 dark:hover:bg-neutral-700"}`,s=t?S.jsx("button",{onClick:t,className:r(!!e),title:e?"Switch to rich editor":"View raw markdown",children:e?"Rich":"Raw"}):null;if(!n)return S.jsx("div",{className:"border-b border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800",children:S.jsx("div",{className:"flex items-center justify-end px-4 py-1.5",children:s})});const o=n.isActive("table");return S.jsxs("div",{className:"border-b border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800",children:[S.jsxs("div",{className:"flex items-center gap-1 px-4 py-1.5",children:[S.jsx("button",{onClick:()=>n.chain().focus().toggleBold().run(),className:r(n.isActive("bold")),title:"Bold",children:S.jsx("strong",{children:"B"})}),S.jsx("button",{onClick:()=>n.chain().focus().toggleItalic().run(),className:r(n.isActive("italic")),title:"Italic",children:S.jsx("em",{children:"I"})}),S.jsx("button",{onClick:()=>n.chain().focus().toggleStrike().run(),className:r(n.isActive("strike")),title:"Strikethrough",children:S.jsx("s",{children:"S"})}),S.jsx("div",{className:"w-px h-4 bg-neutral-200 dark:bg-neutral-600 mx-1"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleHeading({level:1}).run(),className:r(n.isActive("heading",{level:1})),title:"Heading 1",children:"H1"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleHeading({level:2}).run(),className:r(n.isActive("heading",{level:2})),title:"Heading 2",children:"H2"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleHeading({level:3}).run(),className:r(n.isActive("heading",{level:3})),title:"Heading 3",children:"H3"}),S.jsx("div",{className:"w-px h-4 bg-neutral-200 dark:bg-neutral-600 mx-1"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleBulletList().run(),className:r(n.isActive("bulletList")),title:"Bullet List",children:"List"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleOrderedList().run(),className:r(n.isActive("orderedList")),title:"Ordered List",children:"1. List"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleBlockquote().run(),className:r(n.isActive("blockquote")),title:"Quote",children:"Quote"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleCodeBlock().run(),className:r(n.isActive("codeBlock")),title:"Code Block",children:"Code"}),S.jsx("div",{className:"w-px h-4 bg-neutral-200 dark:bg-neutral-600 mx-1"}),S.jsx("button",{onClick:()=>n.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),className:r(n.isActive("table")),title:"Insert Table",children:"Table"}),s&&S.jsxs(S.Fragment,{children:[S.jsx("div",{className:"flex-1"}),s]})]}),o&&S.jsxs("div",{className:"flex items-center gap-1 px-4 py-1 border-t border-neutral-100 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:[S.jsx("span",{className:"text-[10px] text-[var(--adf-ui-text-subtle)] font-medium uppercase tracking-wider mr-1",children:"Table"}),S.jsx("button",{onClick:()=>n.chain().focus().addColumnBefore().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Add column before",children:"+ Col Before"}),S.jsx("button",{onClick:()=>n.chain().focus().addColumnAfter().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Add column after",children:"+ Col After"}),S.jsx("button",{onClick:()=>n.chain().focus().deleteColumn().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-red-500 hover:bg-red-50 dark:hover:bg-red-900/30",title:"Delete column",children:"- Col"}),S.jsx("div",{className:"w-px h-3 bg-neutral-200 dark:bg-neutral-600 mx-0.5"}),S.jsx("button",{onClick:()=>n.chain().focus().addRowBefore().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Add row before",children:"+ Row Before"}),S.jsx("button",{onClick:()=>n.chain().focus().addRowAfter().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Add row after",children:"+ Row After"}),S.jsx("button",{onClick:()=>n.chain().focus().deleteRow().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-red-500 hover:bg-red-50 dark:hover:bg-red-900/30",title:"Delete row",children:"- Row"}),S.jsx("div",{className:"w-px h-3 bg-neutral-200 dark:bg-neutral-600 mx-0.5"}),S.jsx("button",{onClick:()=>n.chain().focus().toggleHeaderRow().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-neutral-600 dark:text-neutral-300 hover:bg-neutral-200 dark:hover:bg-neutral-700",title:"Toggle header row",children:"Header"}),S.jsx("button",{onClick:()=>n.chain().focus().deleteTable().run(),className:"px-1.5 py-0.5 text-[11px] rounded text-red-500 hover:bg-red-50 dark:hover:bg-red-900/30",title:"Delete entire table",children:"Delete Table"})]})]})}let vh=[],Ob=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?Ob:vh).push(t=t+n[e])})();function rR(n){if(n<768)return!1;for(let e=0,t=vh.length;;){let i=e+t>>1;if(n<vh[i])t=i;else if(n>=Ob[i])e=i+1;else return!0;if(e==t)return!1}}function Hp(n){return n>=127462&&n<=127487}const Fp=8205;function sR(n,e,t=!0,i=!0){return(t?Rb:oR)(n,e,i)}function Rb(n,e,t){if(e==n.length)return e;e&&Db(n.charCodeAt(e))&&Nb(n.charCodeAt(e-1))&&e--;let i=dc(n,e);for(e+=$p(i);e<n.length;){let r=dc(n,e);if(i==Fp||r==Fp||t&&rR(r))e+=$p(r),i=r;else if(Hp(r)){let s=0,o=e-2;for(;o>=0&&Hp(dc(n,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function oR(n,e,t){for(;e>0;){let i=Rb(n,e-2,t);if(i<e)return i;e--}return 0}function dc(n,e){let t=n.charCodeAt(e);if(!Nb(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Db(i)?(t-55296<<10)+(i-56320)+65536:t}function Db(n){return n>=56320&&n<57344}function Nb(n){return n>=55296&&n<56320}function $p(n){return n<65536?1:2}class ne{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=mr(this,e,t);let r=[];return this.decompose(0,e,r,2),i.length&&i.decompose(0,i.length,r,3),this.decompose(t,this.length,r,1),nn.from(r,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=mr(this,e,t);let i=[];return this.decompose(e,t,i,0),nn.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),r=new ss(this),s=new ss(e);for(let o=t,l=t;;){if(r.next(o),s.next(o),o=0,r.lineBreak!=s.lineBreak||r.done!=s.done||r.value!=s.value)return!1;if(l+=r.value.length,r.done||l>=i)return!0}}iter(e=1){return new ss(this,e)}iterRange(e,t=this.length){return new Ib(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let r=this.line(e).from;i=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new Lb(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?ne.empty:e.length<=32?new ke(e):nn.from(ke.split(e,[]))}}class ke extends ne{constructor(e,t=lR(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,r){for(let s=0;;s++){let o=this.text[s],l=r+o.length;if((t?i:l)>=e)return new aR(r,l,i,o);r=l+1,i++}}decompose(e,t,i,r){let s=e<=0&&t>=this.length?this:new ke(Vp(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(r&1){let o=i.pop(),l=$o(s.text,o.text.slice(),0,s.length);if(l.length<=32)i.push(new ke(l,o.length+s.length));else{let a=l.length>>1;i.push(new ke(l.slice(0,a)),new ke(l.slice(a)))}}else i.push(s)}replace(e,t,i){if(!(i instanceof ke))return super.replace(e,t,i);[e,t]=mr(this,e,t);let r=$o(this.text,$o(i.text,Vp(this.text,0,e)),t),s=this.length+i.length-(t-e);return r.length<=32?new ke(r,s):nn.from(ke.split(r,[]),s)}sliceString(e,t=this.length,i=`
152
+ `){[e,t]=mr(this,e,t);let r="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let l=this.text[o],a=s+l.length;s>e&&o&&(r+=i),e<a&&t>s&&(r+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],r=-1;for(let s of e)i.push(s),r+=s.length+1,i.length==32&&(t.push(new ke(i,r)),i=[],r=-1);return r>-1&&t.push(new ke(i,r)),t}}class nn extends ne{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,r){for(let s=0;;s++){let o=this.children[s],l=r+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,r);r=l+1,i=a+1}}decompose(e,t,i,r){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let l=this.children[s],a=o+l.length;if(e<=a&&t>=o){let c=r&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!c?i.push(l):l.decompose(e-o,t-o,i,c)}o=a+1}}replace(e,t,i){if([e,t]=mr(this,e,t),i.lines<this.lines)for(let r=0,s=0;r<this.children.length;r++){let o=this.children[r],l=s+o.length;if(e>=s&&t<=l){let a=o.replace(e-s,t-s,i),c=this.lines-o.lines+a.lines;if(a.lines<c>>4&&a.lines>c>>6){let h=this.children.slice();return h[r]=a,new nn(h,this.length-(t-e)+i.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
153
+ `){[e,t]=mr(this,e,t);let r="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let l=this.children[s],a=o+l.length;o>e&&s&&(r+=i),e<a&&t>o&&(r+=l.sliceString(e-o,t-o,i)),o=a+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof nn))return 0;let i=0,[r,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;r+=t,s+=t){if(r==o||s==l)return i;let a=this.children[r],c=e.children[s];if(a!=c)return i+a.scanIdentical(c,t);i+=a.length+1}}static from(e,t=e.reduce((i,r)=>i+r.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new ke(d,t)}let r=Math.max(32,i>>5),s=r<<1,o=r>>1,l=[],a=0,c=-1,h=[];function u(d){let p;if(d.lines>s&&d instanceof nn)for(let m of d.children)u(m);else d.lines>o&&(a>o||!a)?(f(),l.push(d)):d instanceof ke&&a&&(p=h[h.length-1])instanceof ke&&d.lines+p.lines<=32?(a+=d.lines,c+=d.length+1,h[h.length-1]=new ke(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>r&&f(),a+=d.lines,c+=d.length+1,h.push(d))}function f(){a!=0&&(l.push(h.length==1?h[0]:nn.from(h,c)),c=-1,a=h.length=0)}for(let d of e)u(d);return f(),l.length==1?l[0]:new nn(l,t)}}ne.empty=new ke([""],0);function lR(n){let e=-1;for(let t of n)e+=t.length+1;return e}function $o(n,e,t=0,i=1e9){for(let r=0,s=0,o=!0;s<n.length&&r<=i;s++){let l=n[s],a=r+l.length;a>=t&&(a>i&&(l=l.slice(0,i-r)),r<t&&(l=l.slice(t-r)),o?(e[e.length-1]+=l,o=!1):e.push(l)),r=a+1}return e}function Vp(n,e,t){return $o(n,[""],e,t)}class ss{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ke?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,r=this.nodes[i],s=this.offsets[i],o=s>>1,l=r instanceof ke?r.text.length:r.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
154
+ `,this;e--}else if(r instanceof ke){let a=r.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=r.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ke?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Ib{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ss(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=i?r:t<0?r.slice(r.length-i):r.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class Lb{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(ne.prototype[Symbol.iterator]=function(){return this.iter()},ss.prototype[Symbol.iterator]=Ib.prototype[Symbol.iterator]=Lb.prototype[Symbol.iterator]=function(){return this});class aR{constructor(e,t,i,r){this.from=e,this.to=t,this.number=i,this.text=r}get length(){return this.to-this.from}}function mr(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Pe(n,e,t=!0,i=!0){return sR(n,e,t,i)}function cR(n){return n>=56320&&n<57344}function hR(n){return n>=55296&&n<56320}function gt(n,e){let t=n.charCodeAt(e);if(!hR(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return cR(i)?(t-55296<<10)+(i-56320)+65536:t}function rf(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function rn(n){return n<65536?1:2}const Sh=/\r\n?|\n/;var qe=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(qe||(qe={}));class hn{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,r=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(i,r,s),r+=s):r+=o,i+=s}}iterChangedRanges(e,t=!1){Ch(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],r=this.sections[t++];r<0?e.push(i,r):e.push(r,i)}return new hn(e)}composeDesc(e){return this.empty?e:e.empty?this:Pb(this,e)}mapDesc(e,t=!1){return e.empty?this:Mh(this,e,t)}mapPos(e,t=-1,i=qe.Simple){let r=0,s=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],c=r+l;if(a<0){if(c>e)return s+(e-r);s+=l}else{if(i!=qe.Simple&&c>=e&&(i==qe.TrackDel&&r<e&&c>e||i==qe.TrackBefore&&r<e||i==qe.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!l)return e==r||t<0?s:s+a;s+=a}r=c}if(e>r)throw new RangeError(`Position ${e} is out of range for changeset of length ${r}`);return s}touchesRange(e,t=e){for(let i=0,r=0;i<this.sections.length&&r<=t;){let s=this.sections[i++],o=this.sections[i++],l=r+s;if(o>=0&&r<=t&&l>=e)return r<e&&l>t?"cover":!0;r=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],r=this.sections[t++];e+=(e?" ":"")+i+(r>=0?":"+r:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new hn(e)}static create(e){return new hn(e)}}class Ee extends hn{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Ch(this,(t,i,r,s,o)=>e=e.replace(r,r+(i-t),o),!1),e}mapDesc(e,t=!1){return Mh(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let r=0,s=0;r<t.length;r+=2){let o=t[r],l=t[r+1];if(l>=0){t[r]=l,t[r+1]=o;let a=r>>1;for(;i.length<a;)i.push(ne.empty);i.push(o?e.slice(s,s+o):ne.empty)}s+=o}return new Ee(t,i)}compose(e){return this.empty?e:e.empty?this:Pb(this,e,!0)}map(e,t=!1){return e.empty?this:Mh(this,e,t,!0)}iterChanges(e,t=!1){Ch(this,e,t)}get desc(){return hn.create(this.sections)}filter(e){let t=[],i=[],r=[],s=new Cs(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&s.len==0;){if(s.done)break e;let h=Math.min(s.len,a-l);Ue(r,h,-1);let u=s.ins==-1?-1:s.off==0?s.ins:0;Ue(t,h,u),u>0&&Kn(i,t,s.text),s.forward(h),l+=h}let c=e[o++];for(;l<c;){if(s.done)break e;let h=Math.min(s.len,c-l);Ue(t,h,-1),Ue(r,h,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(h),l+=h}}return{changes:new Ee(t,i),filtered:hn.create(r)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],r=this.sections[t+1];r<0?e.push(i):r==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let r=[],s=[],o=0,l=null;function a(h=!1){if(!h&&!r.length)return;o<t&&Ue(r,t-o,-1);let u=new Ee(r,s);l=l?l.compose(u.map(l)):u,r=[],s=[],o=0}function c(h){if(Array.isArray(h))for(let u of h)c(u);else if(h instanceof Ee){if(h.length!=t)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:u,to:f=u,insert:d}=h;if(u>f||u<0||f>t)throw new RangeError(`Invalid change range ${u} to ${f} (in doc of length ${t})`);let p=d?typeof d=="string"?ne.of(d.split(i||Sh)):d:ne.empty,m=p.length;if(u==f&&m==0)return;u<o&&a(),u>o&&Ue(r,u-o,-1),Ue(r,f-u,m),Kn(s,r,p),o=f}}return c(e),a(!l),l}static empty(e){return new Ee(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let r=0;r<e.length;r++){let s=e[r];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;i.length<r;)i.push(ne.empty);i[r]=ne.of(s.slice(1)),t.push(s[0],i[r].length)}}}return new Ee(t,i)}static createSet(e,t){return new Ee(e,t)}}function Ue(n,e,t,i=!1){if(e==0&&t<=0)return;let r=n.length-2;r>=0&&t<=0&&t==n[r+1]?n[r]+=e:r>=0&&e==0&&n[r]==0?n[r+1]+=t:i?(n[r]+=e,n[r+1]+=t):n.push(e,t)}function Kn(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(ne.empty);n.push(t)}}function Ch(n,e,t){let i=n.inserted;for(let r=0,s=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)r+=l,s+=l;else{let c=r,h=s,u=ne.empty;for(;c+=l,h+=a,a&&i&&(u=u.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(r,c,s,h,u),r=c,s=h}}}function Mh(n,e,t,i=!1){let r=[],s=i?[]:null,o=new Cs(n),l=new Cs(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let c=Math.min(o.len,l.len);Ue(r,c,-1),o.forward(c),l.forward(c)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let c=l.len;for(Ue(r,l.ins,-1);c;){let h=Math.min(o.len,c);o.ins>=0&&a<o.i&&o.len<=h&&(Ue(r,0,o.ins),s&&Kn(s,r,o.text),a=o.i),o.forward(h),c-=h}l.next()}else if(o.ins>=0){let c=0,h=o.len;for(;h;)if(l.ins==-1){let u=Math.min(h,l.len);c+=u,h-=u,l.forward(u)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;Ue(r,c,a<o.i?o.ins:0),s&&a<o.i&&Kn(s,r,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return s?Ee.createSet(r,s):hn.create(r);throw new Error("Mismatched change set lengths")}}}function Pb(n,e,t=!1){let i=[],r=t?[]:null,s=new Cs(n),o=new Cs(e);for(let l=!1;;){if(s.done&&o.done)return r?Ee.createSet(i,r):hn.create(i);if(s.ins==0)Ue(i,s.len,0,l),s.next();else if(o.len==0&&!o.done)Ue(i,0,o.ins,l),r&&Kn(r,i,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,o.len),c=i.length;if(s.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;Ue(i,a,h,l),r&&h&&Kn(r,i,o.text)}else o.ins==-1?(Ue(i,s.off?0:s.len,a,l),r&&Kn(r,i,s.textBit(a))):(Ue(i,s.off?0:s.len,o.off?0:o.ins,l),r&&!o.off&&Kn(r,i,o.text));l=(s.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>c),s.forward2(a),o.forward(a)}}}}class Cs{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?ne.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?ne.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class yi{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,r;return this.empty?i=r=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),r=e.mapPos(this.to,-1)),i==this.from&&r==this.to?this:new yi(i,r,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return T.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return T.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return T.range(e.anchor,e.head)}static create(e,t,i){return new yi(e,t,i)}}class T{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:T.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new T([this.main],0)}addRange(e,t=!0){return T.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,T.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new T(e.ranges.map(t=>yi.fromJSON(t)),e.main)}static single(e,t=e){return new T([T.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,r=0;r<e.length;r++){let s=e[r];if(s.empty?s.from<=i:s.from<i)return T.normalized(e.slice(),t);i=s.to}return new T(e,t)}static cursor(e,t=0,i,r){return yi.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(r??16777215)<<6)}static range(e,t,i,r){let s=(i??16777215)<<6|(r==null?7:Math.min(6,r));return t<e?yi.create(t,e,48|s):yi.create(e,t,(t>e?8:0)|s)}static normalized(e,t=0){let i=e[t];e.sort((r,s)=>r.from-s.from),t=e.indexOf(i);for(let r=1;r<e.length;r++){let s=e[r],o=e[r-1];if(s.empty?s.from<=o.to:s.from<o.to){let l=o.from,a=Math.max(s.to,o.to);r<=t&&t--,e.splice(--r,2,s.anchor>s.head?T.range(a,l):T.range(l,a))}}return new T(e,t)}}function Bb(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let sf=0;class z{constructor(e,t,i,r,s){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=r,this.id=sf++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new z(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:of),!!e.static,e.enables)}of(e){return new Vo([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Vo(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Vo(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function of(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class Vo{constructor(e,t,i,r){this.dependencies=e,this.facet=t,this.type=i,this.value=r,this.id=sf++}dynamicSlot(e){var t;let i=this.value,r=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,c=!1,h=[];for(let u of this.dependencies)u=="doc"?a=!0:u=="selection"?c=!0:(((t=e[u.id])!==null&&t!==void 0?t:1)&1)==0&&h.push(e[u.id]);return{create(u){return u.values[o]=i(u),1},update(u,f){if(a&&f.docChanged||c&&(f.docChanged||f.selection)||Th(u,h)){let d=i(u);if(l?!Wp(d,u.values[o],r):!r(d,u.values[o]))return u.values[o]=d,1}return 0},reconfigure:(u,f)=>{let d,p=f.config.address[s];if(p!=null){let m=Ll(f,p);if(this.dependencies.every(g=>g instanceof z?f.facet(g)===u.facet(g):g instanceof ut?f.field(g,!1)==u.field(g,!1):!0)||(l?Wp(d=i(u),m,r):r(d=i(u),m)))return u.values[o]=m,0}else d=i(u);return u.values[o]=d,1}}}}function Wp(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function Th(n,e){let t=!1;for(let i of e)ls(n,i)&1&&(t=!0);return t}function uR(n,e,t){let i=t.map(a=>n[a.id]),r=t.map(a=>a.type),s=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let c=[];for(let h=0;h<i.length;h++){let u=Ll(a,i[h]);if(r[h]==2)for(let f of u)c.push(f);else c.push(u)}return e.combine(c)}return{create(a){for(let c of i)ls(a,c);return a.values[o]=l(a),1},update(a,c){if(!Th(a,s))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,c){let h=Th(a,i),u=c.config.facets[e.id],f=c.facet(e);if(u&&!h&&of(t,u))return a.values[o]=f,0;let d=l(a);return e.compare(d,f)?(a.values[o]=f,0):(a.values[o]=d,1)}}}const uo=z.define({static:!0});class ut{constructor(e,t,i,r,s){this.id=e,this.createF=t,this.updateF=i,this.compareF=r,this.spec=s,this.provides=void 0}static define(e){let t=new ut(sf++,e.create,e.update,e.compare||((i,r)=>i===r),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(uo).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,r)=>{let s=i.values[t],o=this.updateF(s,r);return this.compareF(s,o)?0:(i.values[t]=o,1)},reconfigure:(i,r)=>{let s=i.facet(uo),o=r.facet(uo),l;return(l=s.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):r.config.address[this.id]!=null?(i.values[t]=r.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,uo.of({field:this,create:e})]}get extension(){return this}}const di={lowest:4,low:3,default:2,high:1,highest:0};function Nr(n){return e=>new zb(e,n)}const Fi={highest:Nr(di.highest),high:Nr(di.high),default:Nr(di.default),low:Nr(di.low),lowest:Nr(di.lowest)};class zb{constructor(e,t){this.inner=e,this.prec=t}}class Jn{of(e){return new Ah(this,e)}reconfigure(e){return Jn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Ah{constructor(e,t){this.compartment=e,this.inner=t}}class Il{constructor(e,t,i,r,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=r,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let r=[],s=Object.create(null),o=new Map;for(let f of fR(e,t,o))f instanceof ut?r.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],c=[];for(let f of r)l[f.id]=c.length<<1,c.push(d=>f.slot(d));let h=i?.config.facets;for(let f in s){let d=s[f],p=d[0].facet,m=h&&h[f]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,of(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(y=>y.value));a.push(i&&p.compare(g,i.facet(p))?i.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=c.length<<1,c.push(y=>g.dynamicSlot(y)));l[p.id]=c.length<<1,c.push(g=>uR(g,p,d))}}let u=c.map(f=>f(l));return new Il(e,o,u,l,a,s)}}function fR(n,e,t){let i=[[],[],[],[],[]],r=new Map;function s(o,l){let a=r.get(o);if(a!=null){if(a<=l)return;let c=i[a].indexOf(o);c>-1&&i[a].splice(c,1),o instanceof Ah&&t.delete(o.compartment)}if(r.set(o,l),Array.isArray(o))for(let c of o)s(c,l);else if(o instanceof Ah){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let c=e.get(o.compartment)||o.inner;t.set(o.compartment,c),s(c,l)}else if(o instanceof zb)s(o.inner,o.prec);else if(o instanceof ut)i[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof Vo)i[l].push(o),o.facet.extensions&&s(o.facet.extensions,di.default);else{let c=o.extension;if(!c)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(c,l)}}return s(n,di.default),i.reduce((o,l)=>o.concat(l))}function ls(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let r=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|r}function Ll(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const Hb=z.define(),Eh=z.define({combine:n=>n.some(e=>e),static:!0}),Fb=z.define({combine:n=>n.length?n[0]:void 0,static:!0}),$b=z.define(),Vb=z.define(),Wb=z.define(),jb=z.define({combine:n=>n.length?n[0]:!1});class Nn{constructor(e,t){this.type=e,this.value=t}static define(){return new dR}}class dR{of(e){return new Nn(this,e)}}class pR{constructor(e){this.map=e}of(e){return new Q(this,e)}}class Q{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new Q(this.type,t)}is(e){return this.type==e}static define(e={}){return new pR(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let r of e){let s=r.map(t);s&&i.push(s)}return i}}Q.reconfigure=Q.define();Q.appendConfig=Q.define();class Ce{constructor(e,t,i,r,s,o){this.startState=e,this.changes=t,this.selection=i,this.effects=r,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Bb(i,t.newLength),s.some(l=>l.type==Ce.time)||(this.annotations=s.concat(Ce.time.of(Date.now())))}static create(e,t,i,r,s,o){return new Ce(e,t,i,r,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Ce.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Ce.time=Nn.define();Ce.userEvent=Nn.define();Ce.addToHistory=Nn.define();Ce.remote=Nn.define();function mR(n,e){let t=[];for(let i=0,r=0;;){let s,o;if(i<n.length&&(r==e.length||e[r]>=n[i]))s=n[i++],o=n[i++];else if(r<e.length)s=e[r++],o=e[r++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function _b(n,e,t){var i;let r,s,o;return t?(r=e.changes,s=Ee.empty(e.changes.length),o=n.changes.compose(e.changes)):(r=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(r)),{changes:o,selection:e.selection?e.selection.map(s):(i=n.selection)===null||i===void 0?void 0:i.map(r),effects:Q.mapEffects(n.effects,r).concat(Q.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Oh(n,e,t){let i=e.selection,r=tr(e.annotations);return e.userEvent&&(r=r.concat(Ce.userEvent.of(e.userEvent))),{changes:e.changes instanceof Ee?e.changes:Ee.of(e.changes||[],t,n.facet(Fb)),selection:i&&(i instanceof T?i:T.single(i.anchor,i.head)),effects:tr(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function Ub(n,e,t){let i=Oh(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;i=_b(i,Oh(n,e[s],o?i.changes.newLength:n.doc.length),o)}let r=Ce.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return yR(t?gR(r):r)}function gR(n){let e=n.startState,t=!0;for(let r of e.facet($b)){let s=r(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:mR(t,s))}if(t!==!0){let r,s;if(t===!1)s=n.changes.invertedDesc,r=Ee.empty(e.doc.length);else{let o=n.changes.filter(t);r=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}n=Ce.create(e,r,n.selection&&n.selection.map(s),Q.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let i=e.facet(Vb);for(let r=i.length-1;r>=0;r--){let s=i[r](n);s instanceof Ce?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof Ce?n=s[0]:n=Ub(e,tr(s),!1)}return n}function yR(n){let e=n.startState,t=e.facet(Wb),i=n;for(let r=t.length-1;r>=0;r--){let s=t[r](n);s&&Object.keys(s).length&&(i=_b(i,Oh(e,s,n.changes.newLength),!0))}return i==n?n:Ce.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const bR=[];function tr(n){return n==null?bR:Array.isArray(n)?n:[n]}var ge=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(ge||(ge={}));const xR=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Rh;try{Rh=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function wR(n){if(Rh)return Rh.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||xR.test(t)))return!0}return!1}function kR(n){return e=>{if(!/\S/.test(e))return ge.Space;if(wR(e))return ge.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return ge.Word;return ge.Other}}class ee{constructor(e,t,i,r,s,o){this.config=e,this.doc=t,this.selection=i,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)ls(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return ls(this,i),Ll(this,i)}update(...e){return Ub(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:r}=t;for(let l of e.effects)l.is(Jn.reconfigure)?(t&&(r=new Map,t.compartments.forEach((a,c)=>r.set(c,a)),t=null),r.set(l.value.compartment,l.value.extension)):l.is(Q.reconfigure)?(t=null,i=l.value):l.is(Q.appendConfig)&&(t=null,i=tr(i).concat(l.value));let s;t?s=e.startState.values.slice():(t=Il.resolve(i,r,this),s=new ee(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,c)=>c.reconfigure(a,this),null).values);let o=e.startState.facet(Eh)?e.newSelection:e.newSelection.asSingle();new ee(t,e.newDoc,o,s,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:T.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),r=this.changes(i.changes),s=[i.range],o=tr(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),c=this.changes(a.changes),h=c.map(r);for(let f=0;f<l;f++)s[f]=s[f].map(h);let u=r.mapDesc(c,!0);s.push(a.range.map(u)),r=r.compose(h),o=Q.mapEffects(o,h).concat(Q.mapEffects(tr(a.effects),u))}return{changes:r,selection:T.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Ee?e:Ee.of(e,this.doc.length,this.facet(ee.lineSeparator))}toText(e){return ne.of(e.split(this.facet(ee.lineSeparator)||Sh))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(ls(this,t),Ll(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let r=e[i];r instanceof ut&&this.config.address[r.id]!=null&&(t[i]=r.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let r=[];if(i){for(let s in i)if(Object.prototype.hasOwnProperty.call(e,s)){let o=i[s],l=e[s];r.push(o.init(a=>o.spec.fromJSON(l,a)))}}return ee.create({doc:e.doc,selection:T.fromJSON(e.selection),extensions:t.extensions?r.concat([t.extensions]):r})}static create(e={}){let t=Il.resolve(e.extensions||[],new Map),i=e.doc instanceof ne?e.doc:ne.of((e.doc||"").split(t.staticFacet(ee.lineSeparator)||Sh)),r=e.selection?e.selection instanceof T?e.selection:T.single(e.selection.anchor,e.selection.head):T.single(0);return Bb(r,i.length),t.staticFacet(Eh)||(r=r.asSingle()),new ee(t,i,r,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(ee.tabSize)}get lineBreak(){return this.facet(ee.lineSeparator)||`
155
+ `}get readOnly(){return this.facet(jb)}phrase(e,...t){for(let i of this.facet(ee.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,r)=>{if(r=="$")return"$";let s=+(r||1);return!s||s>t.length?i:t[s-1]})),e}languageDataAt(e,t,i=-1){let r=[];for(let s of this.facet(Hb))for(let o of s(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&r.push(o[e]);return r}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return kR(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:r}=this.doc.lineAt(e),s=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=Pe(t,o,!1);if(s(t.slice(a,o))!=ge.Word)break;o=a}for(;l<r;){let a=Pe(t,l);if(s(t.slice(l,a))!=ge.Word)break;l=a}return o==l?null:T.range(o+i,l+i)}}ee.allowMultipleSelections=Eh;ee.tabSize=z.define({combine:n=>n.length?n[0]:4});ee.lineSeparator=Fb;ee.readOnly=jb;ee.phrases=z.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(r=>n[r]==e[r])}});ee.languageData=Hb;ee.changeFilter=$b;ee.transactionFilter=Vb;ee.transactionExtender=Wb;Jn.reconfigure=Q.define();function Cr(n,e,t={}){let i={};for(let r of n)for(let s of Object.keys(r)){let o=r[s],l=i[s];if(l===void 0)i[s]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,s))i[s]=t[s](l,o);else throw new Error("Config merge conflict for field "+s)}for(let r in e)i[r]===void 0&&(i[r]=e[r]);return i}class ei{eq(e){return this==e}range(e,t=e){return Dh.create(e,t,this)}}ei.prototype.startSide=ei.prototype.endSide=0;ei.prototype.point=!1;ei.prototype.mapMode=qe.TrackDel;function lf(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let Dh=class qb{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new qb(e,t,i)}};function Nh(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class af{constructor(e,t,i,r){this.from=e,this.to=t,this.value=i,this.maxPoint=r}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,r=0){let s=i?this.to:this.from;for(let o=r,l=s.length;;){if(o==l)return o;let a=o+l>>1,c=s[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return c>=0?o:l;c>=0?l=a:o=a+1}}between(e,t,i,r){for(let s=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,s);s<o;s++)if(r(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t){let i=[],r=[],s=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let c=this.value[a],h=this.from[a]+e,u=this.to[a]+e,f,d;if(h==u){let p=t.mapPos(h,c.startSide,c.mapMode);if(p==null||(f=d=p,c.startSide!=c.endSide&&(d=t.mapPos(h,c.endSide),d<f)))continue}else if(f=t.mapPos(h,c.startSide),d=t.mapPos(u,c.endSide),f>d||f==d&&c.startSide>0&&c.endSide<=0)continue;(d-f||c.endSide-c.startSide)<0||(o<0&&(o=f),c.point&&(l=Math.max(l,d-f)),i.push(c),r.push(f-o),s.push(d-o))}return{mapped:i.length?new af(r,s,i,l):null,pos:o}}}class X{constructor(e,t,i,r){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=r}static create(e,t,i,r){return new X(e,t,i,r)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:r=0,filterTo:s=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(Nh)),this.isEmpty)return t.length?X.of(t):this;let l=new Kb(this,null,-1).goto(0),a=0,c=[],h=new gr;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let u=t[a++];h.addInner(u.from,u.to,u.value)||c.push(u)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||r>this.chunkEnd(l.chunkIndex)||s<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||r>l.to||s<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||c.push(Dh.create(l.from,l.to,l.value))),l.next());return h.finishInner(this.nextLayer.isEmpty&&!c.length?X.empty:this.nextLayer.update({add:c,filter:o,filterFrom:r,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],r=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],c=e.touchesRange(l,l+a.length);if(c===!1)r=Math.max(r,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(c===!0){let{mapped:h,pos:u}=a.map(l,e);h&&(r=Math.max(r,h.maxPoint),t.push(h),i.push(u))}}let s=this.nextLayer.map(e);return t.length==0?s:new X(i,t,s||X.empty,r)}between(e,t,i){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let s=this.chunkPos[r],o=this.chunk[r];if(t>=s&&e<=s+o.length&&o.between(s,e-s,t-s,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return Ms.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ms.from(e).goto(t)}static compare(e,t,i,r,s=-1){let o=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=s),l=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=s),a=jp(o,l,i),c=new Ir(o,a,s),h=new Ir(l,a,s);i.iterGaps((u,f,d)=>_p(c,u,h,f,d,r)),i.empty&&i.length==0&&_p(c,0,h,0,0,r)}static eq(e,t,i=0,r){r==null&&(r=999999999);let s=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(s.length!=o.length)return!1;if(!s.length)return!0;let l=jp(s,o),a=new Ir(s,l,0).goto(i),c=new Ir(o,l,0).goto(i);for(;;){if(a.to!=c.to||!Ih(a.active,c.active)||a.point&&(!c.point||!lf(a.point,c.point)))return!1;if(a.to>r)return!0;a.next(),c.next()}}static spans(e,t,i,r,s=-1){let o=new Ir(e,null,s).goto(t),l=t,a=o.openStart;for(;;){let c=Math.min(o.to,i);if(o.point){let h=o.activeForPoint(o.to),u=o.pointFrom<t?h.length+1:o.point.startSide<0?h.length:Math.min(h.length,a);r.point(l,c,o.point,h,u,o.pointRank),a=Math.min(o.openEnd(c),h.length)}else c>l&&(r.span(l,c,o.active,a),a=o.openEnd(c));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new gr;for(let r of e instanceof Dh?[e]:t?vR(e):e)i.add(r.from,r.to,r.value);return i.finish()}static join(e){if(!e.length)return X.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let r=e[i];r!=X.empty;r=r.nextLayer)t=new X(r.chunkPos,r.chunk,t,Math.max(r.maxPoint,t.maxPoint));return t}}X.empty=new X([],[],null,-1);function vR(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(Nh(e,i)>0)return n.slice().sort(Nh);e=i}return n}X.empty.nextLayer=X.empty;class gr{finishChunk(e){this.chunks.push(new af(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new gr)).add(e,t,i)}addInner(e,t,i){let r=e-this.lastTo||i.startSide-this.last.endSide;if(r<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return r<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(X.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=X.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function jp(n,e,t){let i=new Map;for(let s of n)for(let o=0;o<s.chunk.length;o++)s.chunk[o].maxPoint<=0&&i.set(s.chunk[o],s.chunkPos[o]);let r=new Set;for(let s of e)for(let o=0;o<s.chunk.length;o++){let l=i.get(s.chunk[o]);l!=null&&(t?t.mapPos(l):l)==s.chunkPos[o]&&!t?.touchesRange(l,l+s.chunk[o].length)&&r.add(s.chunk[o])}return r}class Kb{constructor(e,t,i,r=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let r=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(r)||this.layer.chunkEnd(this.chunkIndex)<e||r.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Ms{constructor(e){this.heap=e}static from(e,t=null,i=-1){let r=[];for(let s=0;s<e.length;s++)for(let o=e[s];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&r.push(new Kb(o,t,i,s));return r.length==1?r[0]:new Ms(r)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)pc(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)pc(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),pc(this.heap,0)}}}function pc(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let r=n[i];if(i+1<n.length&&r.compare(n[i+1])>=0&&(r=n[i+1],i++),t.compare(r)<0)break;n[i]=t,n[e]=r,e=i}}class Ir{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ms.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){fo(this.active,e),fo(this.activeTo,e),fo(this.activeRank,e),this.minActive=Up(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:r,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||r-this.activeTo[t])>0;)t++;po(this.active,t,i),po(this.activeTo,t,r),po(this.activeRank,t,s),e&&po(e,t,this.cursor.from),this.minActive=Up(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&fo(i,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let r=i.length-1;r>=0&&i[r]<e;r--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function _p(n,e,t,i,r,s){n.goto(e),t.goto(i);let o=i+r,l=i,a=i-e,c=!!s.boundChange;for(let h=!1;;){let u=n.to+a-t.to,f=u||n.endSide-t.endSide,d=f<0?n.to+a:t.to,p=Math.min(d,o);if(n.point||t.point?(n.point&&t.point&&lf(n.point,t.point)&&Ih(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(l,p,n.point,t.point),h=!1):(h&&s.boundChange(l),p>l&&!Ih(n.active,t.active)&&s.compareRange(l,p,n.active,t.active),c&&p<o&&(u||n.openEnd(d)!=t.openEnd(d))&&(h=!0)),d>o)break;l=d,f<=0&&n.next(),f>=0&&t.next()}}function Ih(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!lf(n[t],e[t]))return!1;return!0}function fo(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function po(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function Up(n,e){let t=-1,i=1e9;for(let r=0;r<e.length;r++)(e[r]-i||n[r].endSide-n[t].endSide)<0&&(t=r,i=e[r]);return t}function ka(n,e,t=n.length){let i=0;for(let r=0;r<t&&r<n.length;)n.charCodeAt(r)==9?(i+=e-i%e,r++):(i++,r=Pe(n,r));return i}function SR(n,e,t,i){for(let r=0,s=0;;){if(s>=e)return r;if(r==n.length)break;s+=n.charCodeAt(r)==9?t-s%t:1,r=Pe(n,r)}return n.length}const Lh="ͼ",qp=typeof Symbol>"u"?"__"+Lh:Symbol.for(Lh),Ph=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Kp=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class ti{constructor(e,t){this.rules=[];let{finish:i}=t||{};function r(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function s(o,l,a,c){let h=[],u=/^@(\w+)\b/.exec(o[0]),f=u&&u[1]=="keyframes";if(u&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))s(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!u)throw new RangeError("The value of a property ("+d+") should be a primitive value.");s(r(d),p,h,f)}else p!=null&&h.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(h.length||f)&&a.push((i&&!u&&!c?o.map(i):o).join(", ")+" {"+h.join(" ")+"}")}for(let o in e)s(r(o),e[o],this.rules)}getRules(){return this.rules.join(`
156
+ `)}static newName(){let e=Kp[qp]||1;return Kp[qp]=e+1,Lh+e.toString(36)}static mount(e,t,i){let r=e[Ph],s=i&&i.nonce;r?s&&r.setNonce(s):r=new CR(e,s),r.mount(Array.isArray(t)?t:[t],e)}}let Jp=new Map;class CR{constructor(e,t){let i=e.ownerDocument||e,r=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let s=Jp.get(i);if(s)return e[Ph]=s;this.sheet=new r.CSSStyleSheet,Jp.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[Ph]=this}mount(e,t){let i=this.sheet,r=0,s=0;for(let o=0;o<e.length;o++){let l=e[o],a=this.modules.indexOf(l);if(a<s&&a>-1&&(this.modules.splice(a,1),s--,a=-1),a==-1){if(this.modules.splice(s++,0,l),i)for(let c=0;c<l.rules.length;c++)i.insertRule(l.rules[c],r++)}else{for(;s<a;)r+=this.modules[s++].rules.length;r+=l.rules.length,s++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+`
157
+ `;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}function De(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var r=t[i];typeof r=="string"?n.setAttribute(i,r):r!=null&&(n[i]=r)}e++}for(;e<arguments.length;e++)Jb(n,arguments[e]);return n}function Jb(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)Jb(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}let Xe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Bh=typeof document<"u"?document:{documentElement:{style:{}}};const zh=/Edge\/(\d+)/.exec(Xe.userAgent),Gb=/MSIE \d/.test(Xe.userAgent),Hh=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Xe.userAgent),va=!!(Gb||Hh||zh),Gp=!va&&/gecko\/(\d+)/i.test(Xe.userAgent),mc=!va&&/Chrome\/(\d+)/.exec(Xe.userAgent),MR="webkitFontSmoothing"in Bh.documentElement.style,Fh=!va&&/Apple Computer/.test(Xe.vendor),Yp=Fh&&(/Mobile\/\w+/.test(Xe.userAgent)||Xe.maxTouchPoints>2);var P={mac:Yp||/Mac/.test(Xe.platform),windows:/Win/.test(Xe.platform),linux:/Linux|X11/.test(Xe.platform),ie:va,ie_version:Gb?Bh.documentMode||6:Hh?+Hh[1]:zh?+zh[1]:0,gecko:Gp,gecko_version:Gp?+(/Firefox\/(\d+)/.exec(Xe.userAgent)||[0,0])[1]:0,chrome:!!mc,chrome_version:mc?+mc[1]:0,ios:Yp,android:/Android\b/.test(Xe.userAgent),webkit_version:MR?+(/\bAppleWebKit\/(\d+)/.exec(Xe.userAgent)||[0,0])[1]:0,safari:Fh,safari_version:Fh?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Xe.userAgent)||[0,0])[1]:0,tabSize:Bh.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function cf(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const Pl=Object.create(null);function hf(n,e,t){if(n==e)return!0;n||(n=Pl),e||(e=Pl);let i=Object.keys(n),r=Object.keys(e);if(i.length-0!=r.length-0)return!1;for(let s of i)if(s!=t&&(r.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function TR(n,e){for(let t=n.attributes.length-1;t>=0;t--){let i=n.attributes[t].name;e[i]==null&&n.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?n.style.cssText=i:n.getAttribute(t)!=i&&n.setAttribute(t,i)}}function Xp(n,e,t){let i=!1;if(e)for(let r in e)t&&r in t||(i=!0,r=="style"?n.style.cssText="":n.removeAttribute(r));if(t)for(let r in t)e&&e[r]==t[r]||(i=!0,r=="style"?n.style.cssText=t[r]:n.setAttribute(r,t[r]));return i}function AR(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class $s{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var lt=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(lt||(lt={}));class q extends ei{constructor(e,t,i,r){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=r}get heightRelevant(){return!1}static mark(e){return new Vs(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Ii(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,r;if(e.isBlockGap)i=-5e8,r=4e8;else{let{start:s,end:o}=Yb(e,t);i=(s?t?-3e8:-1:5e8)-1,r=(o?t?2e8:1:-6e8)+1}return new Ii(e,i,r,t,e.widget||null,!0)}static line(e){return new Ws(e)}static set(e,t=!1){return X.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}q.none=X.empty;class Vs extends q{constructor(e){let{start:t,end:i}=Yb(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?cf(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||Pl}eq(e){return this==e||e instanceof Vs&&this.tagName==e.tagName&&hf(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Vs.prototype.point=!1;class Ws extends q{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ws&&this.spec.class==e.spec.class&&hf(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Ws.prototype.mapMode=qe.TrackBefore;Ws.prototype.point=!0;class Ii extends q{constructor(e,t,i,r,s,o){super(t,i,s,e),this.block=r,this.isReplace=o,this.mapMode=r?t<=0?qe.TrackBefore:qe.TrackAfter:qe.TrackDel}get type(){return this.startSide!=this.endSide?lt.WidgetRange:this.startSide<=0?lt.WidgetBefore:lt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof Ii&&ER(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}Ii.prototype.point=!0;function Yb(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function ER(n,e){return n==e||!!(n&&e&&n.compare(e))}function nr(n,e,t,i=0){let r=t.length-1;r>=0&&t[r]+i>=n?t[r]=Math.max(t[r],e):t.push(n,e)}class Ts extends ei{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof Ts&&this.tagName==e.tagName&&hf(this.attributes,e.attributes)}static create(e){return new Ts(e.tagName,e.attributes||Pl)}static set(e,t=!1){return X.of(e,t)}}Ts.prototype.startSide=Ts.prototype.endSide=-1;function As(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function $h(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function as(n,e){if(!e.anchorNode)return!1;try{return $h(n,e.anchorNode)}catch{return!1}}function Wo(n){return n.nodeType==3?Es(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function cs(n,e,t,i){return t?Qp(n,e,t,i,-1)||Qp(n,e,t,i,1):!1}function ni(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Bl(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Qp(n,e,t,i,r){for(;;){if(n==t&&e==i)return!0;if(e==(r<0?0:Rn(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=ni(n)+(r<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(r<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=r<0?Rn(n):0}else return!1}}function Rn(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function zl(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function OR(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Xb(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function RR(n,e,t,i,r,s,o,l){let a=n.ownerDocument,c=a.defaultView||window;for(let h=n,u=!1;h&&!u;)if(h.nodeType==1){let f,d=h==a.body,p=1,m=1;if(d)f=OR(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(u=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let b=h.getBoundingClientRect();({scaleX:p,scaleY:m}=Xb(h,b)),f={left:b.left,right:b.left+h.clientWidth*p,top:b.top,bottom:b.top+h.clientHeight*m}}let g=0,y=0;if(r=="nearest")e.top<f.top?(y=e.top-(f.top+o),t>0&&e.bottom>f.bottom+y&&(y=e.bottom-f.bottom+o)):e.bottom>f.bottom&&(y=e.bottom-f.bottom+o,t<0&&e.top-y<f.top&&(y=e.top-(f.top+o)));else{let b=e.bottom-e.top,x=f.bottom-f.top;y=(r=="center"&&b<=x?e.top+b/2-x/2:r=="start"||r=="center"&&t<0?e.top-o:e.bottom-x+o)-f.top}if(i=="nearest"?e.left<f.left?(g=e.left-(f.left+s),t>0&&e.right>f.right+g&&(g=e.right-f.right+s)):e.right>f.right&&(g=e.right-f.right+s,t<0&&e.left<f.left+g&&(g=e.left-(f.left+s))):g=(i=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:i=="start"==l?e.left-s:e.right-(f.right-f.left)+s)-f.left,g||y)if(d)c.scrollBy(g,y);else{let b=0,x=0;if(y){let k=h.scrollTop;h.scrollTop+=y/m,x=(h.scrollTop-k)*m}if(g){let k=h.scrollLeft;h.scrollLeft+=g/p,b=(h.scrollLeft-k)*p}e={left:e.left-b,top:e.top-x,right:e.right-b,bottom:e.bottom-x},b&&Math.abs(b-g)<1&&(i="nearest"),x&&Math.abs(x-y)<1&&(r="nearest")}if(d)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function DR(n){let e=n.ownerDocument,t,i;for(let r=n.parentNode;r&&!(r==e.body||t&&i);)if(r.nodeType==1)!i&&r.scrollHeight>r.clientHeight&&(i=r),!t&&r.scrollWidth>r.clientWidth&&(t=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:t,y:i}}class NR{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Rn(t):0),i,Math.min(e.focusOffset,i?Rn(i):0))}set(e,t,i,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=r}}let ui=null;P.safari&&P.safari_version>=26&&(ui=!1);function Qb(n){if(n.setActive)return n.setActive();if(ui)return n.focus(ui);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(ui==null?{get preventScroll(){return ui={preventScroll:!0},!0}}:void 0),!ui){ui=!1;for(let t=0;t<e.length;){let i=e[t++],r=e[t++],s=e[t++];i.scrollTop!=r&&(i.scrollTop=r),i.scrollLeft!=s&&(i.scrollLeft=s)}}}let Zp;function Es(n,e,t=e){let i=Zp||(Zp=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function ir(n,e,t,i){let r={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=i);let s=new KeyboardEvent("keydown",r);s.synthetic=!0,n.dispatchEvent(s);let o=new KeyboardEvent("keyup",r);return o.synthetic=!0,n.dispatchEvent(o),s.defaultPrevented||o.defaultPrevented}function IR(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function LR(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Rn(t));;)if(i){if(t.nodeType!=1)return!1;let r=t.childNodes[i-1];r.contentEditable=="false"?i--:(t=r,i=Rn(t))}else{if(t==n)return!0;i=ni(t),t=t.parentNode}}function Zb(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function ex(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=Rn(t)}else if(t.parentNode&&!Bl(t))i=ni(t),t=t.parentNode;else return null}}function tx(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Bl(t))i=ni(t)+1,t=t.parentNode;else return null}}class $t{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new $t(e.parentNode,ni(e),t)}static after(e,t){return new $t(e.parentNode,ni(e)+1,t)}}var ye=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(ye||(ye={}));const Li=ye.LTR,uf=ye.RTL;function nx(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const PR=nx("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),BR=nx("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Vh=Object.create(null),Jt=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Vh[e]=t,Vh[t]=-e}function ix(n){return n<=247?PR[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?BR[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const zR=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class on{get dir(){return this.level%2?uf:Li}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,r){let s=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(s<0||(r!=0?r<0?l.from<t:l.to>t:e[s].level>l.level))&&(s=o)}}if(s<0)throw new RangeError("Index out of range");return s}}function rx(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],r=e[t];if(i.from!=r.from||i.to!=r.to||i.direction!=r.direction||!rx(i.inner,r.inner))return!1}return!0}const oe=[];function HR(n,e,t,i,r){for(let s=0;s<=i.length;s++){let o=s?i[s-1].to:e,l=s<i.length?i[s].from:t,a=s?256:r;for(let c=o,h=a,u=a;c<l;c++){let f=ix(n.charCodeAt(c));f==512?f=h:f==8&&u==4&&(f=16),oe[c]=f==4?2:f,f&7&&(u=f),h=f}for(let c=o,h=a,u=a;c<l;c++){let f=oe[c];if(f==128)c<l-1&&h==oe[c+1]&&h&24?f=oe[c]=h:oe[c]=256;else if(f==64){let d=c+1;for(;d<l&&oe[d]==64;)d++;let p=c&&h==8||d<t&&oe[d]==8?u==1?1:8:256;for(let m=c;m<d;m++)oe[m]=p;c=d-1}else f==8&&u==1&&(oe[c]=1);h=f,f&7&&(u=f)}}}function FR(n,e,t,i,r){let s=r==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:e,h=o<i.length?i[o].from:t;for(let u=c,f,d,p;u<h;u++)if(d=Vh[f=n.charCodeAt(u)])if(d<0){for(let m=l-3;m>=0;m-=3)if(Jt[m+1]==-d){let g=Jt[m+2],y=g&2?r:g&4?g&1?s:r:0;y&&(oe[u]=oe[Jt[m]]=y),l=m;break}}else{if(Jt.length==189)break;Jt[l++]=u,Jt[l++]=f,Jt[l++]=a}else if((p=oe[u])==2||p==1){let m=p==r;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=Jt[g+2];if(y&2)break;if(m)Jt[g+2]|=2;else{if(y&4)break;Jt[g+2]|=4}}}}}function $R(n,e,t,i){for(let r=0,s=i;r<=t.length;r++){let o=r?t[r-1].to:n,l=r<t.length?t[r].from:e;for(let a=o;a<l;){let c=oe[a];if(c==256){let h=a+1;for(;;)if(h==l){if(r==t.length)break;h=t[r++].to,l=r<t.length?t[r].from:e}else if(oe[h]==256)h++;else break;let u=s==1,f=(h<e?oe[h]:i)==1,d=u==f?u?1:2:i;for(let p=h,m=r,g=m?t[m-1].to:n;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:n),oe[--p]=d;a=h}else s=c,a++}}}function Wh(n,e,t,i,r,s,o){let l=i%2?2:1;if(i%2==r%2)for(let a=e,c=0;a<t;){let h=!0,u=!1;if(c==s.length||a<s[c].from){let m=oe[a];m!=l&&(h=!1,u=m==16)}let f=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c<s.length&&p==s[c].from){if(u)break e;let m=s[c];if(!h)for(let g=m.to,y=c+1;;){if(g==t)break e;if(y<s.length&&s[y].from==g)g=s[y++].to;else{if(oe[g]==l)break e;break}}if(c++,f)f.push(m);else{m.from>a&&o.push(new on(a,m.from,d));let g=m.direction==Li!=!(d%2);jh(n,g?i+1:i,r,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(h?oe[p]!=l:oe[p]==l))break;p++}f?Wh(n,a,p,i+1,r,f,o):a<p&&o.push(new on(a,p,d)),a=p}else for(let a=t,c=s.length;a>e;){let h=!0,u=!1;if(!c||a>s[c-1].to){let m=oe[a-1];m!=l&&(h=!1,u=m==16)}let f=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c&&p==s[c-1].to){if(u)break e;let m=s[--c];if(!h)for(let g=m.from,y=c;;){if(g==e)break e;if(y&&s[y-1].to==g)g=s[--y].from;else{if(oe[g-1]==l)break e;break}}if(f)f.push(m);else{m.to<a&&o.push(new on(m.to,a,d));let g=m.direction==Li!=!(d%2);jh(n,g?i+1:i,r,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(h?oe[p-1]!=l:oe[p-1]==l))break;p--}f?Wh(n,p,a,i+1,r,f,o):p<a&&o.push(new on(p,a,d)),a=p}}function jh(n,e,t,i,r,s,o){let l=e%2?2:1;HR(n,r,s,i,l),FR(n,r,s,i,l),$R(r,s,i,l),Wh(n,r,s,e,t,i,o)}function VR(n,e,t){if(!n)return[new on(0,0,e==uf?1:0)];if(e==Li&&!t.length&&!zR.test(n))return sx(n.length);if(t.length)for(;n.length>oe.length;)oe[oe.length]=256;let i=[],r=e==Li?0:1;return jh(n,r,r,t,0,n.length,i),i}function sx(n){return[new on(0,n,0)]}let ox="";function WR(n,e,t,i,r){var s;let o=i.head-n.from,l=on.find(e,o,(s=i.bidiLevel)!==null&&s!==void 0?s:-1,i.assoc),a=e[l],c=a.side(r,t);if(o==c){let f=l+=r?1:-1;if(f<0||f>=e.length)return null;a=e[l=f],o=a.side(!r,t),c=a.side(r,t)}let h=Pe(n.text,o,a.forward(r,t));(h<a.from||h>a.to)&&(h=c),ox=n.text.slice(Math.min(o,h),Math.max(o,h));let u=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];return u&&h==c&&u.level+(r?0:1)<a.level?T.cursor(u.side(!r,t)+n.from,u.forward(r,t)?1:-1,u.level):T.cursor(h+n.from,a.forward(r,t)?-1:1,a.level)}function jR(n,e,t){for(let i=e;i<t;i++){let r=ix(n.charCodeAt(i));if(r==1)return Li;if(r==2||r==4)return uf}return Li}const lx=z.define(),ax=z.define(),cx=z.define(),hx=z.define(),_h=z.define(),ux=z.define(),fx=z.define(),ff=z.define(),df=z.define(),dx=z.define({combine:n=>n.some(e=>e)}),_R=z.define({combine:n=>n.some(e=>e)}),px=z.define();class rr{constructor(e,t="nearest",i="nearest",r=5,s=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=r,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new rr(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new rr(T.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const mo=Q.define({map:(n,e)=>n.map(e)}),mx=Q.define();function xt(n,e,t){let i=n.facet(hx);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const wn=z.define({combine:n=>n.length?n[0]:!0});let UR=0;const Ji=z.define({combine(n){return n.filter((e,t)=>{for(let i=0;i<t;i++)if(n[i].plugin==e.plugin)return!1;return!0})}});class at{constructor(e,t,i,r,s){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=r,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Ji.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ji.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:r,provide:s,decorations:o}=t||{};return new at(UR++,e,i,r,l=>{let a=[];return o&&a.push(Sa.of(c=>{let h=c.plugin(l);return h?o(h):q.none})),s&&a.push(s(l)),a})}static fromClass(e,t){return at.define((i,r)=>new e(i,r),t)}}class gc{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(xt(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){xt(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){xt(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const gx=z.define(),pf=z.define(),Sa=z.define(),yx=z.define(),mf=z.define(),js=z.define(),bx=z.define();function em(n,e){let t=n.state.facet(bx);if(!t.length)return t;let i=t.map(s=>s instanceof Function?s(n):s),r=[];return X.spans(i,e.from,e.to,{point(){},span(s,o,l,a){let c=s-e.from,h=o-e.from,u=r;for(let f=l.length-1;f>=0;f--,a--){let d=l[f].spec.bidiIsolate,p;if(d==null&&(d=jR(e.text,c,h)),a>0&&u.length&&(p=u[u.length-1]).to==c&&p.direction==d)p.to=h,u=p.inner;else{let m={from:c,to:h,direction:d,inner:[]};u.push(m),u=m.inner}}}}),r}const xx=z.define();function gf(n){let e=0,t=0,i=0,r=0;for(let s of n.state.facet(xx)){let o=s(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:e,right:t,top:i,bottom:r}}const Ur=z.define();class At{constructor(e,t,i,r){this.fromA=e,this.toA=t,this.fromB=i,this.toB=r}join(e){return new At(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>i.toA)){if(r.toA<i.fromA)break;i=i.join(r),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let r=0,s=0,o=0;;){let l=r<e.length?e[r].fromB:1e9,a=s<t.length?t[s]:1e9,c=Math.min(l,a);if(c==1e9)break;let h=c+o,u=c,f=h;for(;;)if(s<t.length&&t[s]<=u){let d=t[s+1];s+=2,u=Math.max(u,d);for(let p=r;p<e.length&&e[p].fromB<=u;p++)o=e[p].toA-e[p].toB;f=Math.max(f,d+o)}else if(r<e.length&&e[r].fromB<=u){let d=e[r++];u=Math.max(u,d.toB),f=Math.max(f,d.toA),o=d.toA-d.toB}else break;i.push(new At(h,f,c,u))}return i}}class Hl{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Ee.empty(this.startState.doc.length);for(let s of i)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,l,a)=>r.push(new At(s,o,l,a))),this.changedRanges=r}static create(e,t,i){return new Hl(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const qR=[];class Te{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return qR}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&TR(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let r of this.children){if(r==e)return i;i+=r.length+r.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=ni(this.dom),r=this.length?e>0:t>0;return new $t(this.parent.dom,i+(r?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof Ma)return e;return null}static get(e){return e.cmTile}}class Ca extends Te{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,r,s=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,r=i?i.nextSibling:t.firstChild,s&&r!=l.dom&&(s.written=!0),l.dom.parentNode==t)for(;r&&r!=l.dom;)r=tm(r);else t.insertBefore(l.dom,r);i=l.dom}for(r=i?i.nextSibling:t.firstChild,s&&r&&(s.written=!0);r;)r=tm(r);this.length=o}}function tm(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Ma extends Ca{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Te.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,r=0,s=0;;)if(r==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&s++,r=t.pop()}else{let o=i.children[r++];if(o instanceof Tn)t.push(r),i=o,r=0;else{let l=s+o.length,a=e(o,s);if(a!==void 0)return a;s=l+o.breakAfter}}}resolveBlock(e,t){let i,r=-1,s,o=-1;if(this.blockTiles((l,a)=>{let c=a+l.length;if(e>=a&&e<=c){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<e||e==c&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,r=e-a),(c>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!s||!l.isWidget()&&s.isWidget())&&(s=l,o=e-a)}}),!i&&!s)throw new Error("No tile at position "+e);return i&&t<0||!s?{tile:i,offset:r}:{tile:s,offset:o}}}class Tn extends Ca{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new Tn(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class yr extends Ca{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let r=new yr(t||document.createElement("div"),e);return(!t||!i)&&(r.flags|=4),r}get domAttrs(){return this.attrs}resolveInline(e,t,i){let r=null,s=-1,o=null,l=-1;function a(h,u){for(let f=0,d=0;f<h.children.length&&d<=u;f++){let p=h.children[f],m=d+p.length;m>=u&&(p.isComposite()?a(p,u-d):(!o||o.isHidden&&(t>0||i&&JR(o,p)))&&(m>u||p.flags&32)?(o=p,l=u-d):(d<u||p.flags&16&&!p.isHidden)&&(r=p,s=u-d)),d=m}}a(this,e);let c=(t<0?r:o)||r||o;return c?{tile:c,offset:c==r?s:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):KR(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:r,offset:s}=i;if(this.dom.contains(r.dom))return r.isText()?new $t(r.dom,Math.min(r.dom.nodeValue.length,s)):r.domPosFor(s,r.flags&16?1:r.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new $t(a.dom,0);a==i.tile&&(l=!0)}}return new $t(this.dom,0)}}function KR(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Wo(e);return t[t.length-1]||null}function JR(n,e){let t=n.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class rt extends Ca{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new rt(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class bi extends Te{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let r=e,s=e,o=0;e==0&&t<0||e==i&&t>=0?P.chrome||P.gecko||(e?(r--,o=1):s<i&&(s++,o=-1)):t<0?r--:s<i&&s++;let l=Es(this.dom,r,s).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return P.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?zl(a,o<0):a||null}static of(e,t){let i=new bi(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class Pi extends Te{constructor(e,t,i,r){super(e,t,r),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(i)return zl(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),o=null;if(!s.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?s.length-1:0;o=s[a],!(e>0?a==0:a==s.length-1||o.top<o.bottom);a+=l?-1:1);return zl(o,!l)}}get overrideDOMText(){if(!this.length)return ne.empty;let{root:e}=this;if(!e)return ne.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,r,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new Pi(s,i,e,r)}}class Fl extends Te{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return ne.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class GR{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:r,index:s,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(r.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(s==r.children.length){if(!e&&!l.length)break;i&&i.leave(r),o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++}else{let a=r.children[s],c=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!c,s++,e-=a.length):(l.push({tile:r,index:s}),r=a,s=0,i&&a.isComposite()&&i.enter(a))}else if(s==r.length)o=!!r.breakAfter,{tile:r,index:s}=l.pop(),s++;else if(e){let a=Math.min(e,r.length-s);i&&i.skip(r,s,s+a),e-=a,s+=a}else break;return this.tile=r,this.index=s,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class YR{constructor(e,t,i,r){this.from=e,this.to=t,this.wrapper=i,this.rank=r}}class XR{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,r){var s;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new bi(l.dom,l.text+e);a.parent=o}else o.append(r||bi.of(e,(s=this.cache.find(bi))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?yc(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=i;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],c=r.lastChild;if(c instanceof rt&&c.mark.eq(a.mark))c.dom!=a.dom&&c.setDOM(yc(a.dom)),r=c;else{if(this.cache.reused.get(a)){let u=Te.get(a.dom);u&&u.setDOM(yc(a.dom))}let h=rt.of(a.mark,a.dom);r.append(h),r=h}this.cache.reused.set(a,2)}let s=Te.get(e.text);s&&this.cache.reused.set(s,2);let o=new bi(e.text,e.text.nodeValue);o.flags|=8,r.append(o)}addInlineWidget(e,t,i){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let s=this.ensureMarks(t,i);!r&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=wx);let r=yr.start(e,t||((i=this.cache.find(yr))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=r)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let r=this.curLine;for(let s=e.length-1;s>=0;s--){let o=e[s],l;if(t>0&&(l=r.lastChild)&&l instanceof rt&&l.mark.eq(o))r=l,t--;else{let a=rt.of(o,(i=this.cache.find(rt,c=>c.mark.eq(o)))===null||i===void 0?void 0:i.dom);r.append(a),r=a,t=0}}return r}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!nm(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(P.ios&&nm(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(bc,0,32)||new Pi(bc.toDOM(),0,bc,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new YR(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let r=t.lastChild;if(i.from<this.pos&&r instanceof Tn&&r.wrapper.eq(i.wrapper))t=r;else{let s=Tn.of(i.wrapper,(e=this.cache.find(Tn,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(Fl,void 0,1);return i&&(i.flags=t),i||new Fl(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class QR{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:r,lineBreak:s,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=r;let l=this.textOff=Math.min(e,r.length);return s?null:r.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const $l=[Pi,yr,bi,rt,Fl,Tn,Ma];for(let n=0;n<$l.length;n++)$l[n].bucket=n;class ZR{constructor(e){this.view=e,this.buckets=$l.map(()=>[]),this.index=$l.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let r=e.bucket,s=this.buckets[r],o=this.index[r];for(let l=s.length-1;l>=0;l--){let a=(l+o)%s.length,c=s[a];if((!t||t(c))&&!this.reused.has(c))return s.splice(a,1),a<o&&this.index[r]--,this.reused.set(c,i),c}return null}findWidget(e,t,i){let r=this.buckets[0];if(r.length)for(let s=0,o=0;;s++){if(s==r.length){if(o)return null;o=1,s=0}let l=r[s];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view)))return r.splice(s,1),s<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new Pi(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class eD{constructor(e,t,i,r,s){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new ZR(e),this.text=new QR(e.state.doc),this.builder=new XR(this.cache,new Ma(e,e.contentDOM),X.iter(i)),this.cache.reused.set(t,2),this.old=new GR(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let r=0,s=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>r){let c=a-r;this.preserve(c,!o,!l),r=a,s+=c}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(s,l.toB)),s=l.toB,r=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let r=iD(this.old),s=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let c=a>0||l<o.length?Pi.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);c.flags&256?(c.flags&=-2,this.builder.addBlockWidget(c)):(this.builder.ensureLine(null),this.builder.addInlineWidget(c,r,s),s=r.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length?this.builder.addText(o.text,r,s,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),r,s)),s=r.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Fl)this.cache.add(o);else if(o instanceof rt)this.builder.ensureLine(null),this.builder.addMark(o,r,s),this.cache.reused.set(o,1),s=r.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof rt&&r.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?r.length&&(r.length=s=0):o instanceof rt&&(r.shift(),s=Math.min(s,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,r=this.builder,s=0,o=X.spans(this.decorations,e,t,{point:(l,a,c,h,u,f)=>{if(c instanceof Ii){if(this.disallowBlockEffectsFor[f]){if(c.block)throw new RangeError("Block decorations may not be specified via plugins");if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=h.length,u>h.length)r.continueWidget(a-l);else{let d=c.widget||(c.block?br.block:br.inline),p=tD(c),m=this.cache.findWidget(d,a-l,p)||Pi.of(d,this.view,a-l,p);c.block?(c.startSide>0&&r.addLineStartIfNotCovered(i),r.addBlockWidget(m)):(r.ensureLine(i),r.addInlineWidget(m,h,u))}i=null}else i=nD(i,c);a>l&&this.text.skip(a-l)},span:(l,a,c,h)=>{for(let u=l;u<a;){let f=this.text.next(Math.min(512,a-u));f==null?(r.addLineStartIfNotCovered(i),r.addBreak(),u++):(r.ensureLine(i),r.addText(f,c,u==l?h:c.length),u+=f.length),i=null}}});r.addLineStartIfNotCovered(i),this.openWidget=o>s,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let r=e.parentNode;;r=r.parentNode){let s=Te.get(r);if(r==this.view.contentDOM)break;s instanceof rt?t.push(s):s?.isLine()?i=s:s instanceof Tn||(r.nodeName=="DIV"&&!i&&r!=this.view.contentDOM?i=new yr(r,wx):i||t.push(rt.of(new Vs({tagName:r.nodeName.toLowerCase(),attributes:AR(r)}),r)))}return{line:i,marks:t}}}function nm(n,e){let t=i=>{for(let r of i.children)if((e?r.isText():r.length)||t(r))return!0;return!1};return t(n)}function tD(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const wx={class:"cm-line"};function nD(n,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(n||(n={class:"cm-line"}),t&&cf(t,n),i&&(n.class+=" "+i)),n}function iD(n){let e=[];for(let t=n.parents.length;t>1;t--){let i=t==n.parents.length?n.tile:n.parents[t].tile;i instanceof rt&&e.push(i.mark)}return e}function yc(n){let e=Te.get(n);return e&&e.setDOM(n.cloneNode()),n}class br extends $s{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}br.inline=new br("span");br.block=new br("div");const bc=new class extends $s{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class im{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=q.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new Ma(e,e.contentDOM),this.updateInner([new At(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:h,toA:u})=>u<this.minWidthFrom||h>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let r=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?r=this.domChanged.newSel.head:!fD(e.changes,this.hasComposition)&&!e.selectionSet&&(r=e.state.selection.main.head));let s=r>-1?sD(this.view,e.changes,r):null;if(this.domChanged=null,this.hasComposition){let{from:h,to:u}=this.hasComposition;i=new At(h,u,e.changes.mapPos(h,-1),e.changes.mapPos(u,1)).addToSet(i.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(P.ie||P.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=aD(o,this.decorations,e.changes);a.length&&(i=At.extendWithRanges(i,a));let c=hD(l,this.blockWrappers,e.changes);return c.length&&(i=At.extendWithRanges(i,c)),s&&!i.some(h=>h.fromA<=s.range.fromA&&h.toA>=s.range.toA)&&(i=s.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>{if(t||e.length){let o=this.tile,l=new eD(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);this.tile=l.run(e,t),Uh(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=P.chrome||P.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||i.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof xc&&r.push(s.dom);i.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(mx)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,r=this.view.root.activeElement,s=r==i,o=!s&&!(this.view.state.facet(wn)||i.tabIndex>-1)&&as(i,this.view.observer.selectionRange)&&!(r&&i.contains(r));if(!(s||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,c,h;if(a.empty?h=c=this.inlineDOMNearPos(a.anchor,a.assoc||1):(h=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),c=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),P.gecko&&a.empty&&!this.hasComposition&&rD(c)){let f=document.createTextNode("");this.view.observer.ignore(()=>c.node.insertBefore(f,c.node.childNodes[c.offset]||null)),c=h=new $t(f,0),l=!0}let u=this.view.observer.selectionRange;(l||!u.focusNode||(!cs(c.node,c.offset,u.anchorNode,u.anchorOffset)||!cs(h.node,h.offset,u.focusNode,u.focusOffset))&&!this.suppressWidgetCursorChange(u,a))&&(this.view.observer.ignore(()=>{P.android&&P.chrome&&i.contains(u.focusNode)&&uD(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let f=As(this.view.root);if(f)if(a.empty){if(P.gecko){let d=oD(c.node,c.offset);if(d&&d!=3){let p=(d==1?ex:tx)(c.node,c.offset);p&&(c=new $t(p.node,p.offset))}}f.collapse(c.node,c.offset),a.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=a.bidiLevel)}else if(f.extend){f.collapse(c.node,c.offset);try{f.extend(h.node,h.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([c,h]=[h,c]),d.setEnd(h.node,h.offset),d.setStart(c.node,c.offset),f.removeAllRanges(),f.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(c,h)),this.impreciseAnchor=c.precise?null:new $t(u.anchorNode,u.anchorOffset),this.impreciseHead=h.precise?null:new $t(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&cs(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=As(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(h.node,h.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&i.collapse(r,s)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=i.posAtStart;if(i.isComposite()){let s;if(e==i.dom)s=i.dom.childNodes[t];else{let o=Rn(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?s=e:s=e.nextSibling}if(s==i.dom.firstChild)return r;for(;s&&!Te.get(s);)s=s.nextSibling;if(!s)return r+i.length;for(let o=0,l=r;;o++){let a=i.children[o];if(a.dom==s)return l;l+=a.length+a.breakAfter}}else return i.isText()?e==i.dom?r+t:r+(t?i.length:0):r}domAtPos(e,t){let{tile:i,offset:r}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(r,t)}inlineDOMNearPos(e,t){let i,r=-1,s=!1,o,l=-1,a=!1;return this.tile.blockTiles((c,h)=>{if(c.isWidget()){if(c.flags&32&&h>=e)return!0;c.flags&16&&(s=!0)}else{let u=h+c.length;if(h<=e&&(i=c,r=e-h,s=u<e),u>=e&&!o&&(o=c,l=e-h,a=h>e),h>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(s&&o?i=null:a&&i&&(o=null),i&&t<0||!o?i.domIn(r,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:r}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof xc?null:i.coordsInWidget(r,t,!0):i.coordsIn(r,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(s,o){if(s.isComposite())for(let l of s.children){if(l.length>=o){let a=r(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(s.isText()&&o<s.length){let l=Pe(s.text,o);if(l==o)return null;let a=Es(s.dom,o,l).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(c==a.length-1||h.top<h.bottom&&h.left<h.right)return h}}return null}return r(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:r}=e,s=this.view.contentDOM.clientWidth,o=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==ye.LTR,c=0,h=(u,f,d)=>{for(let p=0;p<u.children.length&&!(f>r);p++){let m=u.children[p],g=f+m.length,y=m.dom.getBoundingClientRect(),{height:b}=y;if(d&&!p&&(c+=y.top-d.top),m instanceof Tn)g>i&&h(m,f,y);else if(f>=i&&(c>0&&t.push(-c),t.push(b+c),c=0,o)){let x=m.dom.lastChild,k=x?Wo(x):[];if(k.length){let w=k[k.length-1],C=a?w.right-y.left:y.right-w.left;C>l&&(l=C,this.minWidth=s,this.minWidthFrom=f,this.minWidthTo=g)}}d&&p==u.children.length-1&&(c+=d.bottom-y.bottom),f=g+m.breakAfter}};return h(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?ye.RTL:ye.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let c of o.children){if(!c.isText()||/[^ -~]/.test(c.text))return;let h=Wo(c.dom);if(h.length!=1)return;l+=h[0].width,a=h[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),i,r,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Wo(t.firstChild)[0];i=t.getBoundingClientRect().height,r=o&&o.width?o.width/27:7,s=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:r,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(q.replace({widget:new xc(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!s)break;i=s.to+1}return q.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Sa).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),i=!1,r=this.view.state.facet(mf).map((s,o)=>{let l=typeof s=="function";return l&&(i=!0),l?s(this.view):s});for(r.length&&(this.dynamicDecorationMap[e++]=i,t.push(X.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(yx).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){if(e.isSnapshot){let c=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=c.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let c of this.view.state.facet(px))try{if(c(this.view,e.range,e))return!0}catch(h){xt(this.view.state,h,"scroll handler")}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),r;if(!i)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,r.left),top:Math.min(i.top,r.top),right:Math.max(i.right,r.right),bottom:Math.max(i.bottom,r.bottom)});let s=gf(this.view),o={left:i.left-s.left,top:i.top-s.top,right:i.right+s.right,bottom:i.bottom+s.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;if(RR(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==ye.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(i.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||i.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let c=this.view.docView.lineAt(t.head,1);c&&c.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Uh(this.tile)}}function Uh(n,e){let t=e?.get(n);if(t!=1){t==null&&n.destroy();for(let i of n.children)Uh(i,e)}}function rD(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function kx(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=ex(t.focusNode,t.focusOffset),r=tx(t.focusNode,t.focusOffset),s=i||r;if(r&&i&&r.node!=i.node){let l=Te.get(r.node);if(!l||l.isText()&&l.text!=r.node.nodeValue)s=r;else if(n.docView.lastCompositionAfterCursor){let a=Te.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(s=r)}}if(n.docView.lastCompositionAfterCursor=s!=i,!s)return null;let o=e-s.offset;return{from:o,to:o+s.node.nodeValue.length,node:s.node}}function sD(n,e,t){let i=kx(n,t);if(!i)return null;let{node:r,from:s,to:o}=i,l=r.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc;return{range:new At(a.mapPos(s),a.mapPos(o),s,o),text:r}}function oD(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let lD=class{constructor(){this.changes=[]}compareRange(e,t){nr(e,t,this.changes)}comparePoint(e,t){nr(e,t,this.changes)}boundChange(e){nr(e,e,this.changes)}};function aD(n,e,t){let i=new lD;return X.compare(n,e,t,i),i.changes}class cD{constructor(){this.changes=[]}compareRange(e,t){nr(e,t,this.changes)}comparePoint(){}boundChange(e){nr(e,e,this.changes)}}function hD(n,e,t){let i=new cD;return X.compare(n,e,t,i),i.changes}function uD(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function fD(n,e){let t=!1;return e&&n.iterChangedRanges((i,r)=>{i<e.to&&r>e.from&&(t=!0)}),t}class xc extends $s{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function dD(n,e,t=1){let i=n.charCategorizer(e),r=n.doc.lineAt(e),s=e-r.from;if(r.length==0)return T.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,l=s;t<0?o=Pe(r.text,s,!1):l=Pe(r.text,s);let a=i(r.text.slice(o,l));for(;o>0;){let c=Pe(r.text,o,!1);if(i(r.text.slice(c,o))!=a)break;o=c}for(;l<r.length;){let c=Pe(r.text,l);if(i(r.text.slice(l,c))!=a)break;l=c}return T.range(o+r.from,l+r.from)}function pD(n,e,t,i,r){let s=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((r-t.top-(n.defaultLineHeight-l)*.5)/l);s+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+SR(o,s,n.state.tabSize)}function mD(n,e,t){let i=n.lineBlockAt(e);if(Array.isArray(i.type)){let r;for(let s of i.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!r||s.type==lt.Text&&(r.type!=s.type||(t<0?s.from<e:s.to>e)))&&(r=s)}}return r||i}return i}function gD(n,e,t,i){let r=mD(n,e.head,e.assoc||-1),s=!i||r.type!=lt.Text||!(n.lineWrapping||r.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(r.from),a=n.posAtCoords({x:t==(l==ye.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(a!=null)return T.cursor(a,t?-1:1)}return T.cursor(t?r.to:r.from,t?-1:1)}function rm(n,e,t,i){let r=n.state.doc.lineAt(e.head),s=n.bidiSpans(r),o=n.textDirectionAt(r.from);for(let l=e,a=null;;){let c=WR(r,s,o,l,t),h=ox;if(!c){if(r.number==(t?n.state.doc.lines:1))return l;h=`
158
+ `,r=n.state.doc.line(r.number+(t?1:-1)),s=n.bidiSpans(r),c=n.visualLineSide(r,!t)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function yD(n,e,t){let i=n.state.charCategorizer(e),r=i(t);return s=>{let o=i(s);return r==ge.Space&&(r=o),r==o}}function bD(n,e,t,i){let r=e.head,s=t?1:-1;if(r==(t?n.state.doc.length:0))return T.cursor(r,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),c=n.coordsAtPos(r,(e.empty?e.assoc:0)||(t?1:-1)),h=n.documentTop;if(c)o==null&&(o=c.left-a.left),l=s<0?c.top:c.bottom;else{let p=n.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(r-p.from))),l=(s<0?p.top:p.bottom)+h}let u=a.left+o,f=i??n.viewState.heightOracle.textHeight>>1,d=qh(n,{x:u,y:l+f*s},!1,s);return T.cursor(d.pos,d.assoc,void 0,o)}function hs(n,e,t){for(;;){let i=0;for(let r of n)r.between(e-1,e+1,(s,o,l)=>{if(e>s&&e<o){let a=i||t||(e-s<o-e?-1:1);e=a<0?s:o,i=a}});if(!i)return e}}function vx(n,e){let t=null;for(let i=0;i<e.ranges.length;i++){let r=e.ranges[i],s=null;if(r.empty){let o=hs(n,r.from,0);o!=r.from&&(s=T.cursor(o,-1))}else{let o=hs(n,r.from,-1),l=hs(n,r.to,1);(o!=r.from||l!=r.to)&&(s=T.range(r.from==r.anchor?o:l,r.from==r.head?o:l))}s&&(t||(t=e.ranges.slice()),t[i]=s)}return t?T.create(t,e.mainIndex):e}function wc(n,e,t){let i=hs(n.state.facet(js).map(r=>r(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:T.cursor(i,i<t.from?1:-1)}class sn{constructor(e,t){this.pos=e,this.assoc=t}}function qh(n,e,t,i){let r=n.contentDOM.getBoundingClientRect(),s=r.top+n.viewState.paddingTop,{x:o,y:l}=e,a=l-s,c;for(;;){if(a<0)return new sn(0,1);if(a>n.viewState.docHeight)return new sn(n.state.doc.length,-1);if(c=n.elementAtHeight(a),i==null)break;if(c.type==lt.Text){if(i<0?c.to<n.viewport.from:c.from>n.viewport.to)break;let f=n.docView.coordsAt(i<0?c.from:c.to,i>0?-1:1);if(f&&(i<0?f.top<=a+s:f.bottom>=a+s))break}let u=n.viewState.heightOracle.textHeight/2;a=i>0?c.bottom+u:c.top-u}if(n.viewport.from>=c.to||n.viewport.to<=c.from){if(t)return null;if(c.type==lt.Text){let u=pD(n,r,c,o,l);return new sn(u,u==c.from?1:-1)}}if(c.type!=lt.Text)return a<(c.top+c.bottom)/2?new sn(c.from,1):new sn(c.to,-1);let h=n.docView.lineAt(c.from,2);return(!h||h.length!=c.length)&&(h=n.docView.lineAt(c.from,-2)),new xD(n,o,l,n.textDirectionAt(c.from)).scanTile(h,c.from)}class xD{constructor(e,t,i,r){this.view=e,this.x=t,this.y=i,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:r}=this.bidiSpansAt(e);return r[on.find(r,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:r}=this.bidiSpansAt(e);return r[on.find(r,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:r}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+r.from<t)}scan(e,t){let i=0,r=e.length-1,s=new Set,o=this.bidiIn(e[0],e[r]),l,a,c=-1,h=1e9,u;e:for(;i<r;){let d=r-i,p=i+r>>1;t:if(s.has(p)){let g=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!s.has(g)){p=g;break t}g++,g==r&&(g=i)}break e}s.add(p);let m=t(p);if(m)for(let g=0;g<m.length;g++){let y=m[g],b=0;if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),b=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),b=-1;else{let x=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,k=Math.abs(x);k<h&&(c=p,h=k,u=y),x&&(b=x<0==(this.baseDir==ye.LTR)?-1:1)}b==-1&&(!o||this.baseDirAt(e[p],1))?r=p:b==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}if(!u){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}let f=(o?this.dirAt(e[c],1):this.baseDir)==ye.LTR;return{i:c,after:this.x>(u.left+u.right)/2==f}}scanText(e,t){let i=[];for(let s=0;s<e.length;s=Pe(e.text,s))i.push(t+s);i.push(t+e.length);let r=this.scan(i,s=>{let o=i[s]-t,l=i[s+1]-t;return Es(e.dom,o,l).getClientRects()});return r.after?new sn(i[r.i+1],-1):new sn(i[r.i],1)}scanTile(e,t){if(!e.length)return new sn(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,a=t;l<e.children.length;l++)i.push(a+=e.children[l].length);let r=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:Es(a.dom,0,a.length)).getClientRects()}),s=e.children[r.i],o=i[r.i];return s.isText()?this.scanText(s,o):s.isComposite()?this.scanTile(s,o):r.after?new sn(i[r.i+1],-1):new sn(o,1)}}const qr="￿";class wD{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(ee.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=qr}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let r=e;;){this.findPointBefore(i,r);let s=this.text.length;this.readNode(r);let o=Te.get(r),l=r.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=Te.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:Bl(r))||Bl(l)&&(r.nodeName!="BR"||o?.isWidget())&&this.text.length>s)&&!vD(l,t)&&this.lineBreak(),r=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,l;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=r.exec(t))&&(s=l.index,o=l[0].length),this.append(t.slice(i,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=s+o}}readNode(e){let t=Te.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let r=i.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(kD(e,i.node,i.offset)?t:0))}}function kD(n,e,t){for(;;){if(!e||t<Rn(e))return!1;if(e==n)return!0;t=ni(e)+1,e=e.parentNode}}function vD(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let i=Te.get(n);if(!i?.isWidget())return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let r=i.overrideDOMText;if(r?.length)return!1}return!0}class sm{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class SD{constructor(e,t,i,r){this.typeOver=r,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=Sx(e.docView.tile,t,i,0))){let l=s||o?[]:MD(e),a=new wD(l,e);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=TD(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=s&&s.node==l.focusNode&&s.offset==l.focusOffset||!$h(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!$h(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=e.viewport;if((P.ios||P.chrome)&&e.state.selection.main.empty&&a!=c&&(h.from>0||h.to<e.state.doc.length)){let u=Math.min(a,c),f=Math.max(a,c),d=h.from-u,p=h.to-f;(d==0||d==1||u==0)&&(p==0||p==-1||f==e.state.doc.length)&&(a=0,c=e.state.doc.length)}e.inputState.composing>-1&&e.state.selection.ranges.length>1?this.newSel=e.state.selection.replaceRange(T.range(c,a)):this.newSel=T.single(c,a)}}}function Sx(n,e,t,i){if(n.isComposite()){let r=-1,s=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<n.children.length;a++){let u=n.children[a],f=c+u.length;if(c<e&&f>t)return Sx(u,e,t,c);if(f>=e&&r==-1&&(r=a,s=c),c>t&&u.dom.parentNode==n.dom){o=a,l=h;break}h=f,c=f+u.breakAfter}return{from:s,to:l<0?i+n.length:l,startDOM:(r?n.children[r-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function Cx(n,e){let t,{newSel:i}=e,r=n.state.selection.main,s=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=r.from,c=null;(s===8||P.android&&e.text.length<l-o)&&(a=r.to,c="end");let h=Mx(n.state.doc.sliceString(o,l,qr),e.text,a-o,c);h&&(P.chrome&&s==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==qr+qr&&h.toB--,t={from:o+h.from,to:o+h.toA,insert:ne.of(e.text.slice(h.from,h.toB).split(qr))})}else i&&(!n.hasFocus&&n.state.facet(wn)||Vl(i,r))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!r.empty&&i&&i.main.empty?t={from:r.from,to:r.to,insert:n.state.doc.slice(r.from,r.to)}:(P.mac||P.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=T.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:ne.of([t.insert.toString().replace("."," ")])}):t&&t.from>=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:n.state.doc.slice(r.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,r.to))}:n.state.doc.lineAt(r.from).to<r.to&&n.docView.lineHasWidget(r.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:n.state.toText(n.inputState.insertingText)}:P.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
159
+ `&&n.lineWrapping&&(i&&(i=T.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:ne.of([" "])}),t)return yf(n,t,i,s);if(i&&!Vl(i,r)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin,l=="select.pointer"&&(i=vx(n.state.facet(js).map(a=>a(n)),i))),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function yf(n,e,t,i=-1){if(P.ios&&n.inputState.flushIOSKey(e))return!0;let r=n.state.selection.main;if(P.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&n.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&ir(n.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>r.head)&&ir(n.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&ir(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=CD(n,e,t));return n.state.facet(ux).some(a=>a(n,e.from,e.to,s,l))||n.dispatch(l()),!0}function CD(n,e,t){let i,r=n.state,s=r.selection.main,o=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let a=e.from<s.from?-1:1,c=a<0?s.from:s.to,h=hs(r.facet(js).map(u=>u(n)),c,a);e.from==h&&(o=h)}if(o>-1)i={changes:e,selection:T.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let a=s.from<e.from?r.sliceDoc(s.from,e.from):"",c=s.to>e.to?r.sliceDoc(e.to,s.to):"";i=r.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+c))}else{let a=r.changes(e),c=t&&t.main.to<=a.newLength?t.main:void 0;if(r.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let h=n.state.sliceDoc(e.from,e.to),u,f=t&&kx(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);u={from:f.from,to:f.to-p}}else u=n.state.doc.lineAt(s.head);let d=s.to-e.to;i=r.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:a,range:c||p.map(a)};let m=p.to-d,g=m-h.length;if(n.state.sliceDoc(g,m)!=h||m>=u.from&&g<=u.to)return{range:p};let y=r.changes({from:g,to:m,insert:e.insert}),b=p.to-s.to;return{changes:y,range:c?T.range(Math.max(0,c.anchor+b),Math.max(0,c.head+b)):p.map(y)}})}else i={changes:a,selection:c&&r.selection.replaceRange(c)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),r.update(i,{userEvent:l,scrollIntoView:!0})}function Mx(n,e,t,i){let r=Math.min(n.length,e.length),s=0;for(;s<r&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==r&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,s-Math.min(o,l));t-=o+a-s}if(o<s&&n.length<e.length){let a=t<=s&&t>=o?s-t:0;s-=a,l=s+(l-o),o=s}else if(l<s){let a=t<=s&&t>=l?s-t:0;s-=a,o=s+(o-l),l=s}return{from:s,toA:o,toB:l}}function MD(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new sm(t,i)),(r!=t||s!=i)&&e.push(new sm(r,s))),e}function TD(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?T.single(t+e,i+e):null}function Vl(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class AD{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,P.safari&&e.contentDOM.addEventListener("input",()=>null),P.gecko&&WD(e.contentDOM.ownerDocument)}handleEvent(e){!PD(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let r of i.observers)r(this.view,t);for(let r of i.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=ED(e),i=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,l=i[s];l&&o!=!l.handlers.length&&(r.removeEventListener(s,this.handleEvent),l=null),l||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in i)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Ax.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),P.android&&P.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return P.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=Tx.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||OD.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,ir(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:P.safari&&!P.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function om(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(r){xt(t.state,r)}}}function ED(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let r=i.spec,s=r&&r.plugin.domEventHandlers,o=r&&r.plugin.domEventObservers;if(s)for(let l in s){let a=s[l];a&&t(l).handlers.push(om(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(om(i.value,a))}}for(let i in jt)t(i).handlers.push(jt[i]);for(let i in It)t(i).observers.push(It[i]);return e}const Tx=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],OD="dthko",Ax=[16,17,18,20,91,92,224,225],go=6;function yo(n){return Math.max(0,n)*.7+8}function RD(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class DD{constructor(e,t,i,r){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=DR(e.contentDOM),this.atoms=e.state.facet(js).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(ee.allowMultipleSelections)&&ND(e,t),this.dragging=LD(e,t)&&Rx(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&RD(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,r=0,s=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=gf(this.view);e.clientX-a.left<=r+go?t=-yo(r-e.clientX):e.clientX+a.right>=o-go&&(t=yo(e.clientX-o)),e.clientY-a.top<=s+go?i=-yo(s-e.clientY):e.clientY+a.bottom>=l-go&&(i=yo(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=vx(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function ND(n,e){let t=n.state.facet(lx);return t.length?t[0](e):P.mac?e.metaKey:e.ctrlKey}function ID(n,e){let t=n.state.facet(ax);return t.length?t[0](e):P.mac?!e.altKey:!e.ctrlKey}function LD(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=As(n.root);if(!i||i.rangeCount==0)return!0;let r=i.getRangeAt(0).getClientRects();for(let s=0;s<r.length;s++){let o=r[s];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function PD(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=Te.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const jt=Object.create(null),It=Object.create(null),Ex=P.ie&&P.ie_version<15||P.ios&&P.webkit_version<604;function BD(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),Ox(n,t.value)},50)}function Ta(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function Ox(n,e){e=Ta(n.state,ff,e);let{state:t}=n,i,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(Kh!=null&&t.selection.ranges.every(a=>a.empty)&&Kh==s.toString()){let a=-1;i=t.changeByRange(c=>{let h=t.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let u=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:u},range:T.cursor(c.from+u.length)}})}else o?i=t.changeByRange(a=>{let c=s.line(r++);return{changes:{from:a.from,to:a.to,insert:c.text},range:T.cursor(a.from+c.length)}}):i=t.replaceSelection(s);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}It.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};jt.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);It.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};It.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};jt.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(cx))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=HD(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new DD(n,e,t,i)),i&&n.observer.ignore(()=>{Qb(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let r=n.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function lm(n,e,t,i){if(i==1)return T.cursor(e,t);if(i==2)return dD(n.state,e,t);{let r=n.docView.lineAt(e,t),s=n.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,l=r?r.posAtEnd:s.to;return l<n.state.doc.length&&l==s.to&&l++,T.range(o,l)}}const zD=P.ie&&P.ie_version<=11;let am=null,cm=0,hm=0;function Rx(n){if(!zD)return n.detail;let e=am,t=hm;return am=n,hm=Date.now(),cm=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(cm+1)%3:1}function HD(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=Rx(e),r=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,l){let a=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),c,h=lm(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let u=lm(n,t.pos,t.assoc,i),f=Math.min(u.from,h.from),d=Math.max(u.to,h.to);h=f<h.from?T.range(f,d):T.range(d,f)}return o?r.replaceRange(r.main.extend(h.from,h.to)):l&&i==1&&r.ranges.length>1&&(c=FD(r,a.pos))?c:l?r.addRange(h):T.create([h])}}}function FD(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:r}=n.ranges[t];if(i<=e&&r>=e)return T.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}jt.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let r=n.docView.tile.nearest(e.target);if(r&&r.isWidget()){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=T.range(s,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Ta(n.state,df,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};jt.dragend=n=>(n.inputState.draggedContent=null,!1);function um(n,e,t,i){if(t=Ta(n.state,ff,t),!t)return;let r=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,o=i&&s&&ID(n,e)?{from:s.from,to:s.to}:null,l={from:r,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}jt.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),r=0,s=()=>{++r==t.length&&um(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=s,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),s()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return um(n,e,i,!0),!0}return!1};jt.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Ex?null:e.clipboardData;return t?(Ox(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(BD(n),!1)};function $D(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function VD(n){let e=[],t=[],i=!1;for(let r of n.selection.ranges)r.empty||(e.push(n.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of n.selection.ranges){let o=n.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),r=o.number}i=!0}return{text:Ta(n,df,e.join(n.lineBreak)),ranges:t,linewise:i}}let Kh=null;jt.copy=jt.cut=(n,e)=>{if(!as(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:r}=VD(n.state);if(!t&&!r)return!1;Kh=r?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let s=Ex?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):($D(n,t),!1)};const Dx=Nn.define();function Nx(n,e){let t=[];for(let i of n.facet(fx)){let r=i(n,e);r&&t.push(r)}return t.length?n.update({effects:t,annotations:Dx.of(!0)}):null}function Ix(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=Nx(n.state,e);t?n.dispatch(t):n.update([])}},10)}It.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Ix(n)};It.blur=n=>{n.observer.clearSelectionRange(),Ix(n)};It.compositionstart=It.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};It.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,P.chrome&&P.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};It.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};jt.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),c=n.posAtDOM(l.endContainer,l.endOffset);return yf(n,{from:a,to:c,insert:n.state.toText(s)},null),!0}}let r;if(P.chrome&&P.android&&(r=Tx.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(r.key,r.keyCode),r.key=="Backspace"||r.key=="Delete")){let s=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return P.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),P.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>It.compositionend(n,e),20),!1};const fm=new Set;function WD(n){fm.has(n)||(fm.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const dm=["pre-wrap","normal","pre-line","break-spaces"];let xr=!1;function pm(){xr=!1}class jD{constructor(e){this.lineWrapping=e,this.doc=ne.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return dm.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let r=e[i];r<0?i++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,i,r,s,o){let l=dm.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=r,this.lineLength=s,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}}class _D{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ht{constructor(e,t,i,r,s){this.from=e,this.length=t,this.top=i,this.height=r,this._content=s}get type(){return typeof this._content=="number"?lt.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Ii?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Ht(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var he=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(he||(he={}));const jo=.001;class Qe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>jo&&(xr=!0),this.height=e)}replace(e,t,i){return Qe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,r){let s=this,o=i.doc;for(let l=r.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:u}=r[l],f=s.lineAt(a,he.ByPosNoHeight,i.setDoc(t),0,0),d=f.to>=c?f:s.lineAt(c,he.ByPosNoHeight,i,0,0);for(u+=d.to-c,c=d.to;l>0&&f.from<=r[l-1].toA;)a=r[l-1].fromA,h=r[l-1].fromB,l--,a<f.from&&(f=s.lineAt(a,he.ByPosNoHeight,i,0,0));h+=f.from-a,a=f.from;let p=bf.build(i.setDoc(o),e,h,u);s=Wl(s,s.replace(a,c,p))}return s.updateHeight(i,0)}static empty(){return new mt(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,r=0,s=0;for(;;)if(t==i)if(r>s*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,r-=l.size}else if(s>r*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,s-=l.size}else break;else if(r<s){let l=e[t++];l&&(r+=l.size)}else{let l=e[--i];l&&(s+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new qD(Qe.of(e.slice(0,t)),o,Qe.of(e.slice(i)))}}function Wl(n,e){return n==e?n:(n.constructor!=e.constructor&&(xr=!0),e)}Qe.prototype.size=1;const UD=q.replace({});class Lx extends Qe{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new Ht(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,r){return this.spaceAbove&&e<i+this.spaceAbove?new Ht(r,0,i,this.spaceAbove,UD):this.mainBlock(i,r)}lineAt(e,t,i,r,s){let o=this.mainBlock(r,s);return this.spaceAbove?this.blockAt(0,i,r,s).join(o):o}forEachLine(e,t,i,r,s,o){e<=s+this.length&&t>=s&&o(this.lineAt(0,he.ByPos,i,r,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}}class mt extends Lx{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new Ht(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let r=i[0];return i.length==1&&(r instanceof mt||r instanceof $e&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof $e?r=new mt(r.length,this.height,this.spaceAbove):r.height=this.height,this.outdated||(r.outdated=!1),r):Qe.of(i)}updateHeight(e,t=0,i=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class $e extends Qe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*s);o=a/s,this.length>s+1&&(l=(this.height-a)/(this.length-s-1))}else o=this.height/s;return{firstLine:i,lastLine:r,perLine:o,perChar:l}}blockAt(e,t,i,r){let{firstLine:s,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let c=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),h=t.doc.lineAt(c),u=l+h.length*a,f=Math.max(i,e-u/2);return new Ht(h.from,h.length,f,u,0)}else{let c=Math.max(0,Math.min(o-s,Math.floor((e-i)/l))),{from:h,length:u}=t.doc.line(s+c);return new Ht(h,u,i+l*c,l,0)}}lineAt(e,t,i,r,s){if(t==he.ByHeight)return this.blockAt(e,i,r,s);if(t==he.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Ht(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,s),c=i.doc.lineAt(e),h=l+c.length*a,u=c.number-o,f=r+l*u+a*(c.from-s-u);return new Ht(c.from,c.length,Math.max(r,Math.min(f,r+this.height-h)),h,0)}forEachLine(e,t,i,r,s,o){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,s);for(let h=e,u=r;h<=t;){let f=i.doc.lineAt(h);if(h==e){let p=f.number-l;u+=a*p+c*(e-s-p)}let d=a+c*f.length;o(new Ht(f.from,f.length,u,d,0)),u+=d,h=f.to+1}}replace(e,t,i){let r=this.length-t;if(r>0){let s=i[i.length-1];s instanceof $e?i[i.length-1]=new $e(s.length+r):i.push(null,new $e(r-1))}if(e>0){let s=i[0];s instanceof $e?i[0]=new $e(e+s.length):i.unshift(new $e(e-1),null)}return Qe.of(i)}decomposeLeft(e,t){t.push(new $e(e-1),null)}decomposeRight(e,t){t.push(null,new $e(this.length-e-1))}updateHeight(e,t=0,i=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],l=Math.max(t,r.from),a=-1;for(r.from>t&&o.push(new $e(r.from-t-1).updateHeight(e,t));l<=s&&r.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let u=r.heights[r.index++],f=0;u<0&&(f=-u,u=r.heights[r.index++]),a==-1?a=u:Math.abs(u-a)>=jo&&(a=-2);let d=new mt(h,u,f);d.outdated=!1,o.push(d),l+=h+1}l<=s&&o.push(null,new $e(s-l).updateHeight(e,l));let c=Qe.of(o);return(a<0||Math.abs(c.height-this.height)>=jo||Math.abs(a-this.heightMetrics(e,t).perLine)>=jo)&&(xr=!0),Wl(this,c)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class qD extends Qe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,r){let s=i+this.left.height;return e<s?this.left.blockAt(e,t,i,r):this.right.blockAt(e,t,s,r+this.left.length+this.break)}lineAt(e,t,i,r,s){let o=r+this.left.height,l=s+this.left.length+this.break,a=t==he.ByHeight?e<o:e<l,c=a?this.left.lineAt(e,t,i,r,s):this.right.lineAt(e,t,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=t==he.ByPosNoHeight?he.ByPosNoHeight:he.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,r,s).join(c)}forEachLine(e,t,i,r,s,o){let l=r+this.left.height,a=s+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,r,s,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let c=this.lineAt(a,he.ByPos,i,r,s);e<c.from&&this.left.forEachLine(e,c.from-1,i,r,s,o),c.to>=e&&c.from<=t&&o(c),t>c.to&&this.right.forEachLine(c.to+1,t,i,l,a,o)}}replace(e,t,i){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,i));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let l of i)s.push(l);if(e>0&&mm(s,o-1),t<this.length){let l=s.length;this.decomposeRight(t,s),mm(s,l)}return Qe.of(s)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,r=i+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?Qe.of(this.break?[e,null,t]:[e,t]):(this.left=Wl(this.left,e),this.right=Wl(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,r){let{left:s,right:o}=this,l=t+s.length+this.break,a=null;return r&&r.from<=t+s.length&&r.more?a=s=s.updateHeight(e,t,i,r):s.updateHeight(e,t,i),r&&r.from<=l+o.length&&r.more?a=o=o.updateHeight(e,l,i,r):o.updateHeight(e,l,i),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function mm(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof $e&&(i=n[e+1])instanceof $e&&n.splice(e-1,3,new $e(t.length+1+i.length))}const KD=5;class bf{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof mt?r.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new mt(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let r=i.widget?i.widget.estimatedHeight:0,s=i.widget?i.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Lx(o,r,i)):(o||s||r>=KD)&&this.addLineDeco(r,s,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new mt(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new $e(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof mt)return e;let t=new mt(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let r=this.ensureLine();r.length+=i,r.collapsed+=i,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof mt)&&!this.isCovered?this.nodes.push(new mt(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let r of this.nodes)r instanceof mt&&r.updateHeight(this.oracle,i),i+=r?r.length:1;return this.nodes}static build(e,t,i,r){let s=new bf(i,e);return X.spans(t,i,r,s,0),s.finish(i)}}function JD(n,e,t){let i=new GD;return X.compare(n,e,t,i,0),i.changes}class GD{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,r){(e<t||i&&i.heightRelevant||r&&r.heightRelevant)&&nr(e,t,this.changes,5)}}function YD(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,r=i.defaultView||window,s=Math.max(0,t.left),o=Math.min(r.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(r.innerHeight,t.bottom);for(let c=n.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,u=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&u.overflow!="visible"){let f=h.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=Math.min(c==n.parentNode?r.innerHeight:a,f.bottom)}c=u.position=="absolute"||u.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function XD(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function QD(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class kc{constructor(e,t,i,r){this.from=e,this.to=t,this.size=i,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let r=e[i],s=t[i];if(r.from!=s.from||r.to!=s.to||r.size!=s.size)return!1}return!0}draw(e,t){return q.replace({widget:new ZD(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class ZD extends $s{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class gm{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=ym,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=ye.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(pf).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new jD(t),this.stateDeco=bm(e),this.heightMap=Qe.empty().applyChanges(this.stateDeco,ne.empty,this.heightOracle.setDoc(e.doc),[new At(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=q.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let r=i?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new bo(s,o))}}return this.viewports=e.sort((i,r)=>i.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?ym:new xf(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Kr(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=bm(this.state);let r=e.changedRanges,s=At.extendWithRanges(r,JD(i,this.stateDeco,e?e.changes:Ee.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);pm(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||xr)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(c||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(_R)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),r=this.heightOracle,s=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?ye.RTL:ye.LTR;let o=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:k,scaleY:w}=Xb(t,l);(k>.005&&Math.abs(this.scaleX-k)>.005||w>.005&&Math.abs(this.scaleY-w)>.005)&&(this.scaleX=k,this.scaleY=w,c|=16,o=a=!0)}let u=(parseInt(i.paddingTop)||0)*this.scaleY,f=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=f)&&(this.paddingTop=u,this.paddingBottom=f,c|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=16);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Zb(e.scrollDOM);let p=(this.printing?QD:YD)(t,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget&&!XD(e.dom))return 0;let b=l.width;if((this.contentDOMWidth!=b||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,c|=16),a){let k=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(k)&&(o=!0),o||r.lineWrapping&&Math.abs(b-this.contentDOMWidth)>r.charWidth){let{lineHeight:w,charWidth:C,textHeight:v}=e.docView.measureTextSize();o=w>0&&r.refresh(s,w,C,v,Math.max(5,b/C),k),o&&(e.docView.minWidth=0,c|=16)}m>0&&g>0?h=Math.max(m,g):m<0&&g<0&&(h=Math.min(m,g)),pm();for(let w of this.viewports){let C=w.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(w);this.heightMap=(o?Qe.empty().applyChanges(this.stateDeco,ne.empty,this.heightOracle,[new At(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new _D(w.from,C))}xr&&(c|=2)}let x=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return x&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||x)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new bo(r.lineAt(o-i*1e3,he.ByHeight,s,0,0).from,r.lineAt(l+(1-i)*1e3,he.ByHeight,s,0,0).to);if(t){let{head:c}=t.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),u=r.lineAt(c,he.ByPos,s,0,0),f;t.y=="center"?f=(u.top+u.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&c<a.from?f=u.top:f=u.bottom-h,a=new bo(r.lineAt(f-1e3/2,he.ByHeight,s,0,0).from,r.lineAt(f+h+1e3/2,he.ByHeight,s,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new bo(this.heightMap.lineAt(i,he.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,he.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,he.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,he.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||r<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||s>=l+Math.max(10,Math.min(i,250)))&&r>o-2*1e3&&s<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let r of e)t.touchesRange(r.from,r.to)||i.push(new kc(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,r=i?1e4:2e3,s=r>>1,o=r<<1;if(this.defaultTextDirection!=ye.LTR&&!i)return[];let l=[],a=(h,u,f,d)=>{if(u-h<s)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>h&&y<u){a(h,y-10,f,d),a(y+10,u,f,d);return}let g=tN(e,y=>y.from>=f.from&&y.to<=f.to&&Math.abs(y.from-h)<s&&Math.abs(y.to-u)<s&&!m.some(b=>y.from<b&&y.to>b));if(!g){if(u<f.to&&t&&i&&t.visibleRanges.some(x=>x.from<=u&&x.to>=u)){let x=t.moveToLineBoundary(T.cursor(u),!1,!0).head;x>h&&(u=x)}let y=this.gapSize(f,h,u,d),b=i||y<2e6?y:2e6;g=new kc(h,u,y,b)}l.push(g)},c=h=>{if(h.length<o||h.type!=lt.Text)return;let u=eN(h.from,h.to,this.stateDeco);if(u.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(f!=null){let b=wo(u,f),x=((this.visibleBottom-this.visibleTop)/2+m)/h.height;g=b-x,y=b+x}else g=(this.visibleTop-h.top-m)/h.height,y=(this.visibleBottom-h.top+m)/h.height;d=xo(u,g),p=xo(u,y)}else{let m=u.total*this.heightOracle.charWidth,g=r*this.heightOracle.charWidth,y=0;if(m>2e6)for(let C of e)C.from>=h.from&&C.from<h.to&&C.size!=C.displaySize&&C.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=C.size-C.displaySize);let b=this.pixelViewport.left+y,x=this.pixelViewport.right+y,k,w;if(f!=null){let C=wo(u,f),v=((x-b)/2+g)/m;k=C-v,w=C+v}else k=(b-g)/m,w=(x+g)/m;d=xo(u,k),p=xo(u,w)}d>h.from&&a(h.from,d,h,u),p<h.to&&a(p,h.to,h,u)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(e,t,i,r){let s=wo(r,i)-wo(r,t);return this.heightOracle.lineWrapping?e.height*s:r.total*this.heightOracle.charWidth*s}updateLineGaps(e){kc.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=q.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];X.spans(t,this.viewport.from,this.viewport.to,{span(s,o){i.push({from:s,to:o})},point(){}},20);let r=0;if(i.length!=this.visibleRanges.length)r=12;else for(let s=0;s<i.length&&!(r&8);s++){let o=this.visibleRanges[s],l=i[s];(o.from!=l.from||o.to!=l.to)&&(r|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(r|=8))}return this.visibleRanges=i,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Kr(this.heightMap.lineAt(e,he.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Kr(this.heightMap.lineAt(this.scaler.fromDOM(e),he.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Kr(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class bo{constructor(e,t){this.from=e,this.to=t}}function eN(n,e,t){let i=[],r=n,s=0;return X.spans(t,n,e,{span(){},point(o,l){o>r&&(i.push({from:r,to:o}),s+=o-r),r=l}},20),r<e&&(i.push({from:r,to:e}),s+=e-r),{total:s,ranges:i}}function xo({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let r=0;;r++){let{from:s,to:o}=e[r],l=o-s;if(i<=l)return s+i;i-=l}}function wo(n,e){let t=0;for(let{from:i,to:r}of n.ranges){if(e<=r){t+=e-i;break}t+=r-i}return t/n.total}function tN(n,e){for(let t of n)if(e(t))return t}const ym={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function bm(n){let e=n.facet(Sa).filter(i=>typeof i!="function"),t=n.facet(mf).filter(i=>typeof i!="function");return t.length&&e.push(X.join(t)),e}class xf{constructor(e,t,i){let r=0,s=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=t.lineAt(l,he.ByPos,e,0,0).top,h=t.lineAt(a,he.ByPos,e,0,0).bottom;return r+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let l of this.viewports)l.domTop=o+(l.top-s)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),s=l.bottom}toDOM(e){for(let t=0,i=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return r+(e-i)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);i=s.bottom,r=s.domBottom}}fromDOM(e){for(let t=0,i=0,r=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return i+(e-r)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);i=s.bottom,r=s.domBottom}}eq(e){return e instanceof xf?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function Kr(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new Ht(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(r=>Kr(r,e)):n._content)}const ko=z.define({combine:n=>n.join(" ")}),Jh=z.define({combine:n=>n.indexOf(!0)>-1}),Gh=ti.newName(),Px=ti.newName(),Bx=ti.newName(),zx={"&light":"."+Px,"&dark":"."+Bx};function Yh(n,e,t){return new ti(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,r=>{if(r=="&")return n;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):n+" "+i}})}const nN=Yh("."+Gh,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},zx),iN={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},vc=P.ie&&P.ie_version<=11;class rN{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new NR,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(P.ie&&P.ie_version<=11||P.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&P.android&&e.constructor.EDIT_CONTEXT!==!1&&!(P.chrome&&P.chrome_version<126)&&(this.editContext=new oN(e),e.state.facet(wn)&&(e.contentDOM.editContext=this.editContext.editContext)),vc&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,r=this.selectionRange;if(i.state.facet(wn)?i.root.activeElement!=this.dom:!as(this.dom,r))return;let s=r.anchorNode&&i.docView.tile.nearest(r.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(P.ie&&P.ie_version<=11||P.android&&P.chrome)&&!i.state.selection.main.empty&&r.focusNode&&cs(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=As(e.root);if(!t)return!1;let i=P.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&sN(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let r=as(this.dom,i);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&LR(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,iN),vc&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),vc&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let r=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&ir(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:r}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),r=this.selectionChanged&&as(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new SD(this.view,e,t,i);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,r=Cx(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!Vl(this.view.state.selection,t.newSel.main))&&this.view.update([]),r}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=xm(t,e.previousSibling||e.target.previousSibling,-1),r=xm(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(wn)!=e.state.facet(wn)&&(e.view.contentDOM.editContext=e.state.facet(wn)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function xm(n,e,t){for(;e;){let i=Te.get(e);if(i&&i.parent==n)return i;let r=e.parentNode;e=r!=n.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function wm(n,e){let t=e.startContainer,i=e.startOffset,r=e.endContainer,s=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return cs(o.node,o.offset,r,s)&&([t,i,r,s]=[r,s,t,i]),{anchorNode:t,anchorOffset:i,focusNode:r,focusOffset:s}}function sN(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return wm(n,r)}let t=null;function i(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?wm(n,t):null}class oN{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let r=e.state.selection.main,{anchor:s,head:o}=r,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let c=a-l>i.text.length;l==this.from&&s<this.from?l=s:a==this.to&&s>this.to&&(a=s);let h=Mx(e.state.sliceDoc(l,a),i.text,(c?r.from:r.to)-l,c?"end":null);if(!h){let f=T.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Vl(f,r)||e.dispatch({selection:f,userEvent:"select"});return}let u={from:h.from+l,to:h.toA+l,insert:ne.of(i.text.slice(h.from,h.toB).split(`
160
+ `))};if((P.mac||P.android)&&u.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(u={from:l,to:a,insert:ne.of([i.text.replace("."," ")])}),this.pendingContextChange=u,!e.state.readOnly){let f=this.to-this.from+(u.to-u.from+u.insert.length);yf(e,u,T.single(this.toEditorPos(i.selectionStart,f),this.toEditorPos(i.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),u.from<u.to&&!u.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let r=[],s=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);s=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||s||new DOMRect,r.push(s)}t.updateCharacterBounds(i.rangeStart,r)},this.handlers.textformatupdate=i=>{let r=[];for(let s of i.getTextFormats()){let o=s.underlineStyle,l=s.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(s.rangeStart),c=this.toEditorPos(s.rangeEnd);if(a<c){let h=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;r.push(q.mark({attributes:{style:h}}).range(a,c))}}}e.dispatch({effects:mx.of(q.set(r))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let r=As(i.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,l,a,c)=>{if(i)return;let h=c.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=h,this.to+=h;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=h,this.to+=h;else if(s<this.to){if(s<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),c.toString()),this.to+=h}t+=h}),r&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(r=>!r.isUserEvent("input.type")&&r.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(i,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class B{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(r=>r.forEach(s=>i(s,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=e.root||IR(e.parent)||document,this.viewState=new gm(e.state||ee.create(e)),e.scrollTo&&e.scrollTo.is(mo)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ji).map(r=>new gc(r));for(let r of this.plugins)r.update(this);this.observer=new rN(this),this.inputState=new AD(this),this.inputState.ensureHandlers(this.plugins),this.docView=new im(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Ce?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,r,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,l=0,a=null;e.some(f=>f.annotation(Dx))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Nx(s,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(h=null)):this.observer.clear(),s.facet(ee.phrases)!=this.state.facet(ee.phrases))return this.setState(s);r=Hl.create(this,s,e),r.flags|=l;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(u&&(u=u.map(f.changes)),f.scrollIntoView){let{main:d}=f.state.selection;u=new rr(d.empty?d:T.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of f.effects)d.is(mo)&&(u=d.value.clip(this.state))}this.viewState.update(r,u),this.bidiCache=jl.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Ur)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(ko)!=r.state.facet(ko)&&(this.viewState.mustMeasureContent=!0),(t||i||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let f of this.state.facet(_h))try{f(r)}catch(d){xt(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!Cx(this,h)&&c.force&&ir(this.contentDOM,c.key,c.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new gm(e),this.plugins=e.facet(Ji).map(i=>new gc(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new im(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ji),i=e.state.facet(Ji);if(t!=i){let r=[];for(let s of i){let o=t.indexOf(s);if(o<0)r.push(new gc(s));else{let l=this.plugins[o];l.mustUpdate=e,r.push(l)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r<this.plugins.length;r++)this.plugins[r].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){xt(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,r=i.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:o}=this.viewState;Math.abs(r-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Zb(i))s=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(r);s=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return xt(this.state,p),km}}),u=Hl.create(this,this.state,[]),f=!1;u.flags|=a,t?t.flags|=a:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),f=this.docView.update(u),f&&this.docViewUpdate());for(let d=0;d<c.length;d++)if(h[d]!=km)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){xt(this.state,p)}if(f&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)-o;if(p>1||p<-1){r=r+p,i.scrollTop=r/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(_h))l(t)}get themeClasses(){return Gh+" "+(this.state.facet(Jh)?Bx:Px)+" "+this.state.facet(ko)}updateAttrs(){let e=vm(this,gx,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(wn)?"true":"false",class:"cm-content",style:`${P.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),vm(this,pf,t);let i=this.observer.ignore(()=>{let r=Xp(this.contentDOM,this.contentAttrs,t),s=Xp(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let r of i.effects)if(r.is(B.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(Ur);let e=this.state.facet(B.cspNonce);ti.mount(this.root,this.styleModules.concat(nN).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return wc(this,e,rm(this,e,t,i))}moveByGroup(e,t){return wc(this,e,rm(this,e,t,i=>yD(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),r=this.textDirectionAt(e.from),s=i[t?i.length-1:0];return T.cursor(s.side(t,r)+e.from,s.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,i=!0){return gD(this,e,t,i)}moveVertically(e,t,i){return wc(this,e,bD(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=qh(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),qh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let r=this.state.doc.lineAt(e),s=this.bidiSpans(r),o=s[on.find(s,e-r.from,-1,t)];return zl(i,o.dir==ye.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(dx)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>lN)return sx(e.length);let t=this.textDirectionAt(e.from),i;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||rx(s.isolates,i=em(this,e))))return s.order;i||(i=em(this,e));let r=VR(e.text,t,i);return this.bidiCache.push(new jl(e.from,e.to,t,i,!0,r)),r}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||P.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Qb(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return mo.of(new rr(typeof e=="number"?T.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return mo.of(new rr(T.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return at.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return at.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ti.newName(),r=[ko.of(i),Ur.of(Yh(`.${i}`,e))];return t&&t.dark&&r.push(Jh.of(!0)),r}static baseTheme(e){return Fi.lowest(Ur.of(Yh("."+Gh,e,zx)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),r=i&&Te.get(i)||Te.get(e);return((t=r?.root)===null||t===void 0?void 0:t.view)||null}}B.styleModule=Ur;B.inputHandler=ux;B.clipboardInputFilter=ff;B.clipboardOutputFilter=df;B.scrollHandler=px;B.focusChangeEffect=fx;B.perLineTextDirection=dx;B.exceptionSink=hx;B.updateListener=_h;B.editable=wn;B.mouseSelectionStyle=cx;B.dragMovesSelection=ax;B.clickAddsSelectionRange=lx;B.decorations=Sa;B.blockWrappers=yx;B.outerDecorations=mf;B.atomicRanges=js;B.bidiIsolatedRanges=bx;B.scrollMargins=xx;B.darkTheme=Jh;B.cspNonce=z.define({combine:n=>n.length?n[0]:""});B.contentAttributes=pf;B.editorAttributes=gx;B.lineWrapping=B.contentAttributes.of({class:"cm-lineWrapping"});B.announce=Q.define();const lN=4096,km={};class jl{constructor(e,t,i,r,s,o){this.from=e,this.to=t,this.dir=i,this.isolates=r,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let i=[],r=e.length?e[e.length-1].dir:ye.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let o=e[s];o.dir==r&&!t.touchesRange(o.from,o.to)&&i.push(new jl(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function vm(n,e,t){for(let i=n.state.facet(e),r=i.length-1;r>=0;r--){let s=i[r],o=typeof s=="function"?s(n):s;o&&cf(o,t)}return t}const aN=P.mac?"mac":P.windows?"win":P.linux?"linux":"key";function cN(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let r,s,o,l;for(let a=0;a<t.length-1;++a){const c=t[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))s=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))e=="mac"?l=!0:s=!0;else throw new Error("Unrecognized modifier name: "+c)}return r&&(i="Alt-"+i),s&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function vo(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const hN=Fi.default(B.domEventHandlers({keydown(n,e){return Fx(Hx(e.state),n,e,"editor")}})),Aa=z.define({enables:hN}),Sm=new WeakMap;function Hx(n){let e=n.facet(Aa),t=Sm.get(e);return t||Sm.set(e,t=dN(e.reduce((i,r)=>i.concat(r),[]))),t}function uN(n,e,t){return Fx(Hx(n.state),e,n,t)}let jn=null;const fN=4e3;function dN(n,e=aN){let t=Object.create(null),i=Object.create(null),r=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,l,a,c,h)=>{var u,f;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>cN(y,e));for(let y=1;y<p.length;y++){let b=p.slice(0,y).join(" ");r(b,!0),d[b]||(d[b]={preventDefault:!0,stopPropagation:!1,run:[x=>{let k=jn={view:x,prefix:b,scope:o};return setTimeout(()=>{jn==k&&(jn=null)},fN),!0}]})}let m=p.join(" ");r(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((f=(u=d._any)===null||u===void 0?void 0:u.run)===null||f===void 0?void 0:f.slice())||[]});a&&g.run.push(a),c&&(g.preventDefault=!0),h&&(g.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=t[c]||(t[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:u}=o;for(let f in h)h[f].run.push(d=>u(d,Xh))}let a=o[e]||o.key;if(a)for(let c of l)s(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Xh=null;function Fx(n,e,t,i){Xh=e;let r=ry(e),s=gt(r,0),o=rn(s)==r.length&&r!=" ",l="",a=!1,c=!1,h=!1;jn&&jn.view==t&&jn.scope==i&&(l=jn.prefix+" ",Ax.indexOf(e.keyCode)<0&&(c=!0,jn=null));let u=new Set,f=g=>{if(g){for(let y of g.run)if(!u.has(y)&&(u.add(y),y(t)))return g.stopPropagation&&(h=!0),!0;g.preventDefault&&(g.stopPropagation&&(h=!0),c=!0)}return!1},d=n[i],p,m;return d&&(f(d[l+vo(r,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(P.windows&&e.ctrlKey&&e.altKey)&&!(P.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=On[e.keyCode])&&p!=r?(f(d[l+vo(p,e,!0)])||e.shiftKey&&(m=bs[e.keyCode])!=r&&m!=p&&f(d[l+vo(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&f(d[l+vo(r,e,!0)])&&(a=!0),!a&&f(d._any)&&(a=!0)),c&&(a=!0),a&&h&&e.stopPropagation(),Xh=null,a}function pN(){return gN}const mN=q.line({class:"cm-activeLine"}),gN=at.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let r=n.lineBlockAt(i.head);r.from>e&&(t.push(mN.range(r.from)),e=r.from)}return q.set(t)}},{decorations:n=>n.decorations}),So="-10000px";class yN{constructor(e,t,i,r){this.facet=t,this.createTooltipView=i,this.removeTooltipView=r,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let s=null;this.tooltipViews=this.tooltips.map(o=>s=i(o,s))}update(e,t){var i;let r=e.state.facet(this.facet),s=r.filter(a=>a);if(r===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<s.length;a++){let c=s[a],h=-1;if(c){for(let u=0;u<this.tooltips.length;u++){let f=this.tooltips[u];f&&f.create==c.create&&(h=u)}if(h<0)o[a]=this.createTooltipView(c,a?o[a-1]:null),l&&(l[a]=!!c.above);else{let u=o[a]=this.tooltipViews[h];l&&(l[a]=t[h]),u.update&&u.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,c)=>t[c]=a),t.length=l.length),this.input=r,this.tooltips=s,this.tooltipViews=o,!0}}function bN(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Sc=z.define({combine:n=>{var e,t,i;return{position:P.ios?"absolute":((e=n.find(r=>r.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(r=>r.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(r=>r.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||bN}}}),Cm=new WeakMap,$x=at.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Sc);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new yN(n,Vx,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Sc);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let r of this.manager.tooltipViews)r.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let r of this.manager.tooltipViews)this.container.appendChild(r.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let r=document.createElement("div");r.className="cm-tooltip-arrow",t.dom.appendChild(r)}return t.dom.style.position=this.position,t.dom.style.top=So,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(P.safari){let o=s.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!s.offsetParent&&s.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(n=s.width/this.parent.offsetWidth,e=s.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),r=gf(this.view);return{visible:{left:i.left+r.left,top:i.top+r.top,right:i.right-r.right,bottom:i.bottom-r.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((s,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(Sc).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:r,scaleY:s}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],c=this.manager.tooltipViews[l],{dom:h}=c,u=n.pos[l],f=n.size[l];if(!u||a.clip!==!1&&(u.bottom<=Math.max(t.top,i.top)||u.top>=Math.min(t.bottom,i.bottom)||u.right<Math.max(t.left,i.left)-.1||u.left>Math.min(t.right,i.right)+.1)){h.style.top=So;continue}let d=a.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=(e=Cm.get(c))!==null&&e!==void 0?e:f.bottom-f.top,y=c.offset||wN,b=this.view.textDirection==ye.LTR,x=f.width>i.right-i.left?b?i.left:i.right-f.width:b?Math.max(i.left,Math.min(u.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,u.left-m+(d?14:0)-y.x),i.right-m),k=this.above[l];!a.strictSide&&(k?u.top-g-p-y.y<i.top:u.bottom+g+p+y.y>i.bottom)&&k==i.bottom-u.bottom>u.top-i.top&&(k=this.above[l]=!k);let w=(k?u.top-i.top:i.bottom-u.bottom)-p;if(w<g&&c.resize!==!1){if(w<this.view.defaultLineHeight){h.style.top=So;continue}Cm.set(c,g),h.style.height=(g=w)/s+"px"}else h.style.height&&(h.style.height="");let C=k?u.top-g-p-y.y:u.bottom+p+y.y,v=x+m;if(c.overlap!==!0)for(let D of o)D.left<v&&D.right>x&&D.top<C+g&&D.bottom>C&&(C=k?D.top-g-2-p:D.bottom+p+2);if(this.position=="absolute"?(h.style.top=(C-n.parent.top)/s+"px",Mm(h,(x-n.parent.left)/r)):(h.style.top=C/s+"px",Mm(h,x/r)),d){let D=u.left+(b?y.x:-y.x)-(x+14-7);d.style.left=D/r+"px"}c.overlap!==!0&&o.push({left:x,top:C,right:v,bottom:C+g}),h.classList.toggle("cm-tooltip-above",k),h.classList.toggle("cm-tooltip-below",!k),c.positioned&&c.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=So}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Mm(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}const xN=B.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),wN={x:0,y:0},Vx=z.define({enables:[$x,xN]});function Wx(n,e){let t=n.plugin($x);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Tm=z.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function jx(n,e){let t=n.plugin(_x),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const _x=at.fromClass(class{constructor(n){this.input=n.state.facet(_l),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Tm);this.top=new Co(n,!0,e.topContainer),this.bottom=new Co(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(Tm);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Co(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Co(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(_l);if(t!=this.input){let i=t.filter(a=>a),r=[],s=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(n.view),l.push(h)):(h=this.panels[c],h.update&&h.update(n)),r.push(h),(h.top?s:o).push(h)}this.specs=i,this.panels=r,this.top.sync(s),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>B.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Co{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Am(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Am(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Am(n){let e=n.nextSibling;return n.remove(),e}const _l=z.define({enables:_x});function kN(n,e){let t,i=new Promise(o=>t=o),r=o=>vN(o,e,t);n.state.field(Cc,!1)?n.dispatch({effects:Ux.of(r)}):n.dispatch({effects:Q.appendConfig.of(Cc.init(()=>[r]))});let s=qx.of(r);return{close:s,result:i.then(o=>((n.win.queueMicrotask||(a=>n.win.setTimeout(a,10)))(()=>{n.state.field(Cc).indexOf(r)>-1&&n.dispatch({effects:s})}),o))}}const Cc=ut.define({create(){return[]},update(n,e){for(let t of e.effects)t.is(Ux)?n=[t.value].concat(n):t.is(qx)&&(n=n.filter(i=>i!=t.value));return n},provide:n=>_l.computeN([n],e=>e.field(n))}),Ux=Q.define(),qx=Q.define();function vN(n,e,t){let i=e.content?e.content(n,()=>o(null)):null;if(!i){if(i=De("form"),e.input){let l=De("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(De("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(De("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let r=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<r.length;l++){let a=r[l];a.addEventListener("keydown",c=>{c.keyCode==27?(c.preventDefault(),o(null)):c.keyCode==13&&(c.preventDefault(),o(a))}),a.addEventListener("submit",c=>{c.preventDefault(),o(a)})}let s=De("div",i,De("button",{onclick:()=>o(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(s.className=e.class),s.classList.add("cm-dialog");function o(l){s.contains(s.ownerDocument.activeElement)&&n.focus(),t(l)}return{dom:s,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=i.querySelector(e.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class ii extends ei{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}ii.prototype.elementClass="";ii.prototype.toDOM=void 0;ii.prototype.mapMode=qe.TrackBefore;ii.prototype.startSide=ii.prototype.endSide=-1;ii.prototype.point=!0;const _o=z.define(),SN=z.define(),Uo=z.define(),Em=z.define({combine:n=>n.some(e=>e)});function CN(n){return[MN]}const MN=at.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Uo).map(e=>new Rm(n,e)),this.fixed=!n.state.facet(Em);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Em)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=X.iter(this.view.state.facet(_o),this.view.viewport.from),i=[],r=this.gutters.map(s=>new TN(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(s.type)){let o=!0;for(let l of s.type)if(l.type==lt.Text&&o){Qh(t,i,l.from);for(let a of r)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of r)a.widget(this.view,l)}else if(s.type==lt.Text){Qh(t,i,s.from);for(let o of r)o.line(this.view,s,i)}else if(s.widget)for(let o of r)o.widget(this.view,s);for(let s of r)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(Uo),t=n.state.facet(Uo),i=n.docChanged||n.heightChanged||n.viewportChanged||!X.eq(n.startState.facet(_o),n.state.facet(_o),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let r of this.gutters)r.update(n)&&(i=!0);else{i=!0;let r=[];for(let s of t){let o=e.indexOf(s);o<0?r.push(new Rm(this.view,s)):(this.gutters[o].update(n),r.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),r.indexOf(s)<0&&s.destroy();for(let s of r)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=r}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>B.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,r=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ye.LTR?{left:i,right:r}:{right:i,left:r}})});function Om(n){return Array.isArray(n)?n:[n]}function Qh(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class TN{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=X.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:r}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==r.elements.length){let l=new Kx(e,o,s,i);r.elements.push(l),r.dom.appendChild(l.dom)}else r.elements[this.i].update(e,o,s,i);this.height=t.bottom,this.i++}line(e,t,i){let r=[];Qh(this.cursor,r,t.from),i.length&&(r=r.concat(i));let s=this.gutter.config.lineMarker(e,t,r);s&&r.unshift(s);let o=this.gutter;r.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,r)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),r=i?[i]:null;for(let s of e.state.facet(SN)){let o=s(e,t.widget,t);o&&(r||(r=[])).push(o)}r&&this.addElement(e,t,r)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Rm{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,r=>{let s=r.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let a=s.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=r.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,r)&&r.preventDefault()});this.markers=Om(t.markers(e)),t.initialSpacer&&(this.spacer=new Kx(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Om(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let r=this.config.updateSpacer(this.spacer.markers[0],e);r!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[r])}let i=e.view.viewport;return!X.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Kx{constructor(e,t,i,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,r)}update(e,t,i,r){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),AN(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let i="cm-gutterElement",r=this.dom.firstChild;for(let s=0,o=0;;){let l=o,a=s<t.length?t[s++]:null,c=!1;if(a){let h=a.elementClass;h&&(i+=" "+h);for(let u=o;u<this.markers.length;u++)if(this.markers[u].compare(a)){l=u,c=!0;break}}else l=this.markers.length;for(;o<l;){let h=this.markers[o++];if(h.toDOM){h.destroy(r);let u=r.nextSibling;r.remove(),r=u}}if(!a)break;a.toDOM&&(c?r=r.nextSibling:this.dom.insertBefore(a.toDOM(e),r)),c&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function AN(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const EN=z.define(),ON=z.define(),Gi=z.define({combine(n){return Cr(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let r in t){let s=i[r],o=t[r];i[r]=s?(l,a,c)=>s(l,a,c)||o(l,a,c):o}return i}})}});class Mc extends ii{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Tc(n,e){return n.state.facet(Gi).formatNumber(e,n.state)}const RN=Uo.compute([Gi],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(EN)},lineMarker(e,t,i){return i.some(r=>r.toDOM)?null:new Mc(Tc(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let r of e.state.facet(ON)){let s=r(e,t,i);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Gi)!=e.state.facet(Gi),initialSpacer(e){return new Mc(Tc(e,Dm(e.state.doc.lines)))},updateSpacer(e,t){let i=Tc(t.view,Dm(t.view.state.doc.lines));return i==e.number?e:new Mc(i)},domEventHandlers:n.facet(Gi).domEventHandlers,side:"before"}));function DN(n={}){return[Gi.of(n),CN(),RN]}function Dm(n){let e=9;for(;e<n;)e=e*10+9;return e}const NN=new class extends ii{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},IN=_o.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let r=n.doc.lineAt(i.head).from;r>t&&(t=r,e.push(NN.range(r)))}return X.of(e)});function LN(){return IN}const PN=1024;let BN=0;class Et{constructor(e,t){this.from=e,this.to=t}}class Y{constructor(e={}){this.id=BN++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=ct.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}Y.closedBy=new Y({deserialize:n=>n.split(" ")});Y.openedBy=new Y({deserialize:n=>n.split(" ")});Y.group=new Y({deserialize:n=>n.split(" ")});Y.isolate=new Y({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});Y.contextHash=new Y({perNode:!0});Y.lookAhead=new Y({perNode:!0});Y.mounted=new Y({perNode:!0});class sr{constructor(e,t,i,r=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=r}static get(e){return e&&e.props&&e.props[Y.mounted.id]}}const zN=Object.create(null);class ct{constructor(e,t,i,r=0){this.name=e,this.props=t,this.id=i,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):zN,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new ct(e.name||"",t,e.id,i);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(r)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return r}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(Y.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let r of i.split(" "))t[r]=e[i];return i=>{for(let r=i.prop(Y.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?i.name:r[s]];if(o)return o}}}}ct.none=new ct("",Object.create(null),0,8);class Jx{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let r=null;for(let s of e){let o=s(i);if(o){r||(r=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in r&&(l=a.combine(r[a.id],l)),r[a.id]=l}}t.push(r?new ct(i.name,r,i.id,i.flags):i)}return new Jx(t)}}const Mo=new WeakMap,Nm=new WeakMap;var le;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(le||(le={}));class Me{constructor(e,t,i,r,s){if(this.type=e,this.children=t,this.positions=i,this.length=r,this.props=null,s&&s.length){this.props=Object.create(null);for(let[o,l]of s)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=sr.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let r=i.toString();r&&(t&&(t+=","),t+=r)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Ul(this.topNode,e)}cursorAt(e,t=0,i=0){let r=Mo.get(this)||this.topNode,s=new Ul(r);return s.moveTo(e,t),Mo.set(this,s._tree),s}get topNode(){return new Ke(this,0,0,null)}resolve(e,t=0){let i=Os(Mo.get(this)||this.topNode,e,t,!1);return Mo.set(this,i),i}resolveInner(e,t=0){let i=Os(Nm.get(this)||this.topNode,e,t,!0);return Nm.set(this,i),i}resolveStack(e,t=0){return $N(this,e,t)}iterate(e){let{enter:t,leave:i,from:r=0,to:s=this.length}=e,o=e.mode||0,l=(o&le.IncludeAnonymous)>0;for(let a=this.cursor(o|le.IncludeAnonymous);;){let c=!1;if(a.from<=s&&a.to>=r&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;c=!0}for(;c&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;c=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:vf(ct.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,r)=>new Me(this.type,t,i,r,this.propValues),e.makeTree||((t,i,r)=>new Me(ct.none,t,i,r)))}static build(e){return VN(e)}}Me.empty=new Me(ct.none,[],[],0);class wf{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new wf(this.buffer,this.index)}}class ri{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ct.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],r=this.set.types[t],s=r.name;if(/\W/.test(s)&&!r.isError&&(s=JSON.stringify(s)),e+=4,i==e)return s;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return s+"("+o.join(",")+")"}findChild(e,t,i,r,s){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Gx(s,r,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let r=this.buffer,s=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){s[a++]=r[l++],s[a++]=r[l++]-i;let c=s[a++]=r[l++]-i;s[a++]=r[l++]-e,o=Math.max(o,c)}return new ri(s,o,this.set)}}function Gx(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Os(n,e,t,i){for(var r;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof Ke&&n.index<0?null:n.parent;if(!o)return n;n=o}let s=i?0:le.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof Ke&&o.index<0&&((r=l.enter(e,t,s))===null||r===void 0?void 0:r.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,s);if(!o)return n;n=o}}class Yx{cursor(e=0){return new Ul(this,e)}getChild(e,t=null,i=null){let r=Im(this,e,t,i);return r.length?r[0]:null}getChildren(e,t=null,i=null){return Im(this,e,t,i)}resolve(e,t=0){return Os(this,e,t,!1)}resolveInner(e,t=0){return Os(this,e,t,!0)}matchContext(e){return Zh(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let r=t.lastChild;if(!r||r.to!=t.to)break;r.type.isError&&r.from==r.to?(i=t,t=r.prevSibling):t=r}return i}get node(){return this}get next(){return this.parent}}class Ke extends Yx{constructor(e,t,i,r){super(),this._tree=e,this.from=t,this.index=i,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,r,s=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,c=t>0?l.length:-1;e!=c;e+=t){let h=l[e],u=a[e]+o.from,f;if(!(!(s&le.EnterBracketed&&h instanceof Me&&(f=sr.get(h))&&!f.overlay&&f.bracketed&&i>=u&&i<=u+h.length)&&!Gx(r,i,u,u+h.length))){if(h instanceof ri){if(s&le.ExcludeBuffers)continue;let d=h.findChild(0,h.buffer.length,t,i-u,r);if(d>-1)return new ln(new HN(o,h,e,u),null,d)}else if(s&le.IncludeAnonymous||!h.type.isAnonymous||kf(h)){let d;if(!(s&le.IgnoreMounts)&&(d=sr.get(h))&&!d.overlay)return new Ke(d.tree,u,e,o);let p=new Ke(h,u,e,o);return s&le.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?h.children.length-1:0,t,i,r,s)}}}if(s&le.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let r;if(!(i&le.IgnoreOverlays)&&(r=sr.get(this._tree))&&r.overlay){let s=e-this.from,o=i&le.EnterBracketed&&r.bracketed;for(let{from:l,to:a}of r.overlay)if((t>0||o?l<=s:l<s)&&(t<0||o?a>=s:a>s))return new Ke(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Im(n,e,t,i){let r=n.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=r.type.is(t),!r.nextSibling())return s}for(;;){if(i!=null&&r.type.is(i))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return i==null?s:[]}}function Zh(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class HN{constructor(e,t,i,r){this.parent=e,this.buffer=t,this.index=i,this.start=r}}class ln extends Yx{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,i);return s<0?null:new ln(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&le.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new ln(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new ln(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new ln(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,r=this.index+4,s=i.buffer[this.index+3];if(s>r){let o=i.buffer[this.index+1];e.push(i.slice(r,s,o)),t.push(0)}return new Me(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Xx(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let o=n[s];(o.from>t.from||o.to<t.to)&&(t=o,e=s)}let i=t instanceof Ke&&t.index<0?null:t.parent,r=n.slice();return i?r[e]=i:r.splice(e,1),new FN(r,t)}class FN{constructor(e,t){this.heads=e,this.node=t}get next(){return Xx(this.heads)}}function $N(n,e,t){let i=n.resolveInner(e,t),r=null;for(let s=i instanceof Ke?i:i.context.parent;s;s=s.parent)if(s.index<0){let o=s.parent;(r||(r=[i])).push(o.resolve(e,t)),s=o}else{let o=sr.get(s.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new Ke(o.tree,o.overlay[0].from+s.from,-1,s);(r||(r=[i])).push(Os(l,e,t,!1))}}return r?Xx(r):i}class Ul{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~le.EnterBracketed,e instanceof Ke)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=i+r.buffer[e+1],this.to=i+r.buffer[e+2],!0}yield(e){return e?e instanceof Ke?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,i);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&le.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&le.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&le.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let r=i<0?0:this.stack[i]+4;if(this.index!=r)return this.yieldBuf(t.findChild(r,this.index,-1,0,4))}else{let r=t.buffer[this.index+3];if(r<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(r)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(r.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:i}=r)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let s=t+e,o=e<0?-1:i._tree.children.length;s!=o;s+=e){let l=i._tree.children[s];if(this.mode&le.IncludeAnonymous||l instanceof ri||!l.type.isAnonymous||kf(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let r=this.index,s=this.stack.length;s>=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,i=s+1;break e}r=this.stack[--s]}for(let r=i;r<this.stack.length;r++)t=new ln(this.buffer,t,this.stack[r]);return this.bufferNode=new ln(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,r=!0}}}matchContext(e){if(!this.buffer)return Zh(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let r=e.length-1,s=this.stack.length-1;r>=0;s--){if(s<0)return Zh(this._tree,e,r);let o=i[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}}function kf(n){return n.children.some(e=>e instanceof ri||!e.type.isAnonymous||kf(e))}function VN(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:r=PN,reused:s=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new wf(t,t.length):t,a=i.types,c=0,h=0;function u(w,C,v,D,L,J){let{id:j,start:$,end:te,size:G}=l,Z=h,Oe=c;if(G<0)if(l.next(),G==-1){let E=s[j];v.push(E),D.push($-w);return}else if(G==-3){c=j;return}else if(G==-4){h=j;return}else throw new RangeError(`Unrecognized record size: ${G}`);let ft=a[j],$i,Kt,Ks=$-w;if(te-$<=r&&(Kt=g(l.pos-C,L))){let E=new Uint16Array(Kt.size-Kt.skip),V=l.pos-Kt.size,F=E.length;for(;l.pos>V;)F=y(Kt.start,E,F);$i=new ri(E,te-Kt.start,i),Ks=Kt.start-w}else{let E=l.pos-G;l.next();let V=[],F=[],ie=j>=o?j:-1,Re=0,Pt=te;for(;l.pos>E;)ie>=0&&l.id==ie&&l.size>=0?(l.end<=Pt-r&&(p(V,F,$,Re,l.end,Pt,ie,Z,Oe),Re=V.length,Pt=l.end),l.next()):J>2500?f($,E,V,F):u($,E,V,F,ie,J+1);if(ie>=0&&Re>0&&Re<V.length&&p(V,F,$,Re,$,Pt,ie,Z,Oe),V.reverse(),F.reverse(),ie>-1&&Re>0){let Ff=d(ft,Oe);$i=vf(ft,V,F,0,V.length,0,te-$,Ff,Ff)}else $i=m(ft,V,F,te-$,Z-te,Oe)}v.push($i),D.push(Ks)}function f(w,C,v,D){let L=[],J=0,j=-1;for(;l.pos>C;){let{id:$,start:te,end:G,size:Z}=l;if(Z>4)l.next();else{if(j>-1&&te<j)break;j<0&&(j=G-r),L.push($,te,G),J++,l.next()}}if(J){let $=new Uint16Array(J*4),te=L[L.length-2];for(let G=L.length-3,Z=0;G>=0;G-=3)$[Z++]=L[G],$[Z++]=L[G+1]-te,$[Z++]=L[G+2]-te,$[Z++]=Z;v.push(new ri($,L[2]-te,i)),D.push(te-w)}}function d(w,C){return(v,D,L)=>{let J=0,j=v.length-1,$,te;if(j>=0&&($=v[j])instanceof Me){if(!j&&$.type==w&&$.length==L)return $;(te=$.prop(Y.lookAhead))&&(J=D[j]+$.length+te)}return m(w,v,D,L,J,C)}}function p(w,C,v,D,L,J,j,$,te){let G=[],Z=[];for(;w.length>D;)G.push(w.pop()),Z.push(C.pop()+v-L);w.push(m(i.types[j],G,Z,J-L,$-J,te)),C.push(L-v)}function m(w,C,v,D,L,J,j){if(J){let $=[Y.contextHash,J];j=j?[$].concat(j):[$]}if(L>25){let $=[Y.lookAhead,L];j=j?[$].concat(j):[$]}return new Me(w,C,v,D,j)}function g(w,C){let v=l.fork(),D=0,L=0,J=0,j=v.end-r,$={size:0,start:0,skip:0};e:for(let te=v.pos-w;v.pos>te;){let G=v.size;if(v.id==C&&G>=0){$.size=D,$.start=L,$.skip=J,J+=4,D+=4,v.next();continue}let Z=v.pos-G;if(G<0||Z<te||v.start<j)break;let Oe=v.id>=o?4:0,ft=v.start;for(v.next();v.pos>Z;){if(v.size<0)if(v.size==-3||v.size==-4)Oe+=4;else break e;else v.id>=o&&(Oe+=4);v.next()}L=ft,D+=G,J+=Oe}return(C<0||D==w)&&($.size=D,$.start=L,$.skip=J),$.size>4?$:void 0}function y(w,C,v){let{id:D,start:L,end:J,size:j}=l;if(l.next(),j>=0&&D<o){let $=v;if(j>4){let te=l.pos-(j-4);for(;l.pos>te;)v=y(w,C,v)}C[--v]=$,C[--v]=J-w,C[--v]=L-w,C[--v]=D}else j==-3?c=D:j==-4&&(h=D);return v}let b=[],x=[];for(;l.pos>0;)u(n.start||0,n.bufferStart||0,b,x,-1,0);let k=(e=n.length)!==null&&e!==void 0?e:b.length?x[0]+b[0].length:0;return new Me(a[n.topID],b.reverse(),x.reverse(),k)}const Lm=new WeakMap;function qo(n,e){if(!n.isAnonymous||e instanceof ri||e.type!=n)return 1;let t=Lm.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof Me)){t=1;break}t+=qo(n,i)}Lm.set(e,t)}return t}function vf(n,e,t,i,r,s,o,l,a){let c=0;for(let p=i;p<r;p++)c+=qo(n,e[p]);let h=Math.ceil(c*1.5/8),u=[],f=[];function d(p,m,g,y,b){for(let x=g;x<y;){let k=x,w=m[x],C=qo(n,p[x]);for(x++;x<y;x++){let v=qo(n,p[x]);if(C+v>=h)break;C+=v}if(x==k+1){if(C>h){let v=p[k];d(v.children,v.positions,0,v.children.length,m[k]+b);continue}u.push(p[k])}else{let v=m[x-1]+p[x-1].length-w;u.push(vf(n,p,m,k,x,w,v,null,a))}f.push(w+b-s)}}return d(e,t,i,r,0),(l||a)(u,f,o)}class nB{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof ln?this.setBuffer(e.context.buffer,e.index,t):e instanceof Ke&&this.map.set(e.tree,t)}get(e){return e instanceof ln?this.getBuffer(e.context.buffer,e.index):e instanceof Ke?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class An{constructor(e,t,i,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=r,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let r=[new An(0,e.length,e,0,!1,i)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,i=128){if(!t.length)return e;let r=[],s=1,o=e.length?e[0]:null;for(let l=0,a=0,c=0;;l++){let h=l<t.length?t[l]:null,u=h?h.fromA:1e9;if(u-a>=i)for(;o&&o.from<u;){let f=o;if(a>=f.from||u<=f.to||c){let d=Math.max(f.from,a)-c,p=Math.min(f.to,u)-c;f=d>=p?null:new An(d,p,f.tree,f.offset+c,l>0,!!h)}if(f&&r.push(f),o.to>u)break;o=s<e.length?e[s++]:null}if(!h)break;a=h.toA,c=h.toA-h.toB}return r}}class WN{startParse(e,t,i){return typeof e=="string"&&(e=new jN(e)),i=i?i.length?i.map(r=>new Et(r.from,r.to)):[new Et(0,0)]:[new Et(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let r=this.startParse(e,t,i);for(;;){let s=r.advance();if(s)return s}}}class jN{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function iB(n){return(e,t,i,r)=>new UN(e,n,t,i,r)}class Pm{constructor(e,t,i,r,s,o){this.parser=e,this.parse=t,this.overlay=i,this.bracketed=r,this.target=s,this.from=o}}function Bm(n){if(!n.length||n.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(n))}class _N{constructor(e,t,i,r,s,o,l,a){this.parser=e,this.predicate=t,this.mounts=i,this.index=r,this.start=s,this.bracketed=o,this.target=l,this.prev=a,this.depth=0,this.ranges=[]}}const eu=new Y({perNode:!0});class UN{constructor(e,t,i,r,s){this.nest=t,this.input=i,this.fragments=r,this.ranges=s,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new Me(i.type,i.children,i.positions,i.length,i.propValues.concat([[eu,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[Y.mounted.id]=new sr(t,e.overlay,e.parser,e.bracketed),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new JN(this.fragments),t=null,i=null,r=new Ul(new Ke(this.baseTree,this.ranges[0].from,0,null),le.IncludeAnonymous|le.IgnoreMounts);e:for(let s,o;;){let l=!0,a;if(this.stoppedAt!=null&&r.from>=this.stoppedAt)l=!1;else if(e.hasNode(r)){if(t){let c=t.mounts.find(h=>h.frag.from<=r.from&&h.frag.to>=r.to&&h.mount.overlay);if(c)for(let h of c.mount.overlay){let u=h.from+c.pos,f=h.to+c.pos;u>=r.from&&f<=r.to&&!t.ranges.some(d=>d.from<f&&d.to>u)&&t.ranges.push({from:u,to:f})}}l=!1}else if(i&&(o=qN(i.ranges,r.from,r.to)))l=o!=2;else if(!r.type.isAnonymous&&(s=this.nest(r,this.input))&&(r.from<r.to||!s.overlay)){r.tree||(KN(r),t&&t.depth++,i&&i.depth++);let c=e.findMounts(r.from,s.parser);if(typeof s.overlay=="function")t=new _N(s.parser,s.overlay,c,this.inner.length,r.from,!!s.bracketed,r.tree,t);else{let h=Fm(this.ranges,s.overlay||(r.from<r.to?[new Et(r.from,r.to)]:[]));h.length&&Bm(h),(h.length||!s.overlay)&&this.inner.push(new Pm(s.parser,h.length?s.parser.startParse(this.input,$m(c,h),h):s.parser.startParse(""),s.overlay?s.overlay.map(u=>new Et(u.from-r.from,u.to-r.from)):null,!!s.bracketed,r.tree,h.length?h[0].from:r.from)),s.overlay?h.length&&(i={ranges:h,depth:0,prev:i}):l=!1}}else if(t&&(a=t.predicate(r))&&(a===!0&&(a=new Et(r.from,r.to)),a.from<a.to)){let c=t.ranges.length-1;c>=0&&t.ranges[c].to==a.from?t.ranges[c]={from:t.ranges[c].from,to:a.to}:t.ranges.push(a)}if(l&&r.firstChild())t&&t.depth++,i&&i.depth++;else for(;!r.nextSibling();){if(!r.parent())break e;if(t&&!--t.depth){let c=Fm(this.ranges,t.ranges);c.length&&(Bm(c),this.inner.splice(t.index,0,new Pm(t.parser,t.parser.startParse(this.input,$m(t.mounts,c),c),t.ranges.map(h=>new Et(h.from-t.start,h.to-t.start)),t.bracketed,t.target,c[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function qN(n,e,t){for(let i of n){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function zm(n,e,t,i,r,s){if(e<t){let o=n.buffer[e+1];i.push(n.slice(e,t,o)),r.push(o-s)}}function KN(n){let{node:e}=n,t=[],i=e.context.buffer;do t.push(n.index),n.parent();while(!n.tree);let r=n.tree,s=r.children.indexOf(i),o=r.children[s],l=o.buffer,a=[s];function c(h,u,f,d,p,m){let g=t[m],y=[],b=[];zm(o,h,g,y,b,d);let x=l[g+1],k=l[g+2];a.push(y.length);let w=m?c(g+4,l[g+3],o.set.types[l[g]],x,k-x,m-1):e.toTree();return y.push(w),b.push(x-d),zm(o,l[g+3],u,y,b,d),new Me(f,y,b,p)}r.children[s]=c(0,l.length,ct.none,0,o.length,t.length-1);for(let h of a){let u=n.tree.children[h],f=n.tree.positions[h];n.yield(new Ke(u,f+n.from,h,n._tree))}}class Hm{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(le.IncludeAnonymous|le.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,le.IgnoreOverlays|le.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof Me)t=t.children[0];else break}return!1}}class JN{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(eu))!==null&&t!==void 0?t:i.to,this.inner=new Hm(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(eu))!==null&&e!==void 0?e:t.to,this.inner=new Hm(t.tree,-t.offset)}}findMounts(e,t){var i;let r=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let o=(i=s.tree)===null||i===void 0?void 0:i.prop(Y.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=s.to)break;a.tree==this.curFrag.tree&&r.push({frag:a,pos:s.from-a.offset,mount:o})}}}return r}}function Fm(n,e){let t=null,i=e;for(let r=1,s=0;r<n.length;r++){let o=n[r-1].to,l=n[r].from;for(;s<i.length;s++){let a=i[s];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[s]=new Et(a.from,o),a.to>l&&t.splice(s+1,0,new Et(l,a.to))):a.to>l?t[s--]=new Et(l,a.to):t.splice(s--,1))}}return i}function GN(n,e,t,i){let r=0,s=0,o=!1,l=!1,a=-1e9,c=[];for(;;){let h=r==n.length?1e9:o?n[r].to:n[r].from,u=s==e.length?1e9:l?e[s].to:e[s].from;if(o!=l){let f=Math.max(a,t),d=Math.min(h,u,i);f<d&&c.push(new Et(f,d))}if(a=Math.min(h,u),a==1e9)break;h==a&&(o?(o=!1,r++):o=!0),u==a&&(l?(l=!1,s++):l=!0)}return c}function $m(n,e){let t=[];for(let{pos:i,mount:r,frag:s}of n){let o=i+(r.overlay?r.overlay[0].from:0),l=o+r.tree.length,a=Math.max(s.from,o),c=Math.min(s.to,l);if(r.overlay){let h=r.overlay.map(f=>new Et(f.from+i,f.to+i)),u=GN(e,h,a,c);for(let f=0,d=a;;f++){let p=f==u.length,m=p?c:u[f].from;if(m>d&&t.push(new An(d,m,r.tree,-o,s.from>=d||s.openStart,s.to<=m||s.openEnd)),p)break;d=u[f].to}}else t.push(new An(a,c,r.tree,-o,s.from>=o||s.openStart,s.to<=l||s.openEnd))}return t}let YN=0;class Mt{constructor(e,t,i,r){this.name=e,this.set=t,this.base=i,this.modified=r,this.id=YN++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof Mt&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let r=new Mt(i,[],null,[]);if(r.set.push(r),t)for(let s of t.set)r.set.push(s);return r}static defineModifier(e){let t=new ql(e);return i=>i.modified.indexOf(t)>-1?i:ql.get(i.base||i,i.modified.concat(t).sort((r,s)=>r.id-s.id))}}let XN=0;class ql{constructor(e){this.name=e,this.instances=[],this.id=XN++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&QN(t,l.modified));if(i)return i;let r=[],s=new Mt(e.name,r,e,t);for(let l of t)l.instances.push(s);let o=ZN(t);for(let l of e.set)if(!l.modified.length)for(let a of o)r.push(ql.get(l,a));return s}}function QN(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function ZN(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,r=e.length;i<r;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function eI(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let r of t.split(" "))if(r){let s=[],o=2,l=r;for(let u=0;;){if(l=="..."&&u>0&&u+3==r.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+r);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),u+=f[0].length,u==r.length)break;let d=r[u++];if(u==r.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+r);l=r.slice(u)}let a=s.length-1,c=s[a];if(!c)throw new RangeError("Invalid path: "+r);let h=new Rs(i,o,a>0?s.slice(0,a):null);e[c]=h.sort(e[c])}}return Qx.add(e)}const Qx=new Y({combine(n,e){let t,i,r;for(;n||e;){if(!n||e&&n.depth<=e.depth?(r=e,e=e.next):(r=n,n=n.next),t&&t.mode==r.mode&&!r.context&&!t.context)continue;let s=new Rs(r.tags,r.mode,r.context);t?t.next=s:i=s,t=s}return i}});class Rs{constructor(e,t,i,r){this.tags=e,this.mode=t,this.context=i,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Rs.empty=new Rs([],2,null);function Zx(n,e){let t=Object.create(null);for(let s of n)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let o of s.tag)t[o.id]=s.class;let{scope:i,all:r=null}=e||{};return{style:s=>{let o=r;for(let l of s)for(let a of l.set){let c=t[a.id];if(c){o=o?o+" "+c:c;break}}return o},scope:i}}function tI(n,e){let t=null;for(let i of n){let r=i.style(e);r&&(t=t?t+" "+r:r)}return t}function nI(n,e,t,i=0,r=n.length){let s=new iI(i,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),i,r,"",s.highlighters),s.flush(r)}class iI{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,r,s){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let c=r,h=rI(e)||Rs.empty,u=tI(s,h.tags);if(u&&(c&&(c+=" "),c+=u,h.mode==1&&(r+=(r?" ":"")+u)),this.startSpan(Math.max(t,l),c),h.opaque)return;let f=e.tree&&e.tree.prop(Y.mounted);if(f&&f.overlay){let d=e.node.enter(f.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let b=g<f.overlay.length?f.overlay[g]:null,x=b?b.from+l:a,k=Math.max(t,y),w=Math.min(i,x);if(k<w&&m)for(;e.from<w&&(this.highlightRange(e,k,w,r,s),this.startSpan(Math.min(w,e.to),c),!(e.to>=x||!e.nextSibling())););if(!b||x>i)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),c))}m&&e.parent()}else if(e.firstChild()){f&&(r="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,r,s),this.startSpan(Math.min(i,e.to),c)}while(e.nextSibling());e.parent()}}}function rI(n){let e=n.type.prop(Qx);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const N=Mt.define,To=N(),Hn=N(),Vm=N(Hn),Wm=N(Hn),Fn=N(),Ao=N(Fn),Ac=N(Fn),Xt=N(),hi=N(Xt),Gt=N(),Yt=N(),tu=N(),Lr=N(tu),Eo=N(),O={comment:To,lineComment:N(To),blockComment:N(To),docComment:N(To),name:Hn,variableName:N(Hn),typeName:Vm,tagName:N(Vm),propertyName:Wm,attributeName:N(Wm),className:N(Hn),labelName:N(Hn),namespace:N(Hn),macroName:N(Hn),literal:Fn,string:Ao,docString:N(Ao),character:N(Ao),attributeValue:N(Ao),number:Ac,integer:N(Ac),float:N(Ac),bool:N(Fn),regexp:N(Fn),escape:N(Fn),color:N(Fn),url:N(Fn),keyword:Gt,self:N(Gt),null:N(Gt),atom:N(Gt),unit:N(Gt),modifier:N(Gt),operatorKeyword:N(Gt),controlKeyword:N(Gt),definitionKeyword:N(Gt),moduleKeyword:N(Gt),operator:Yt,derefOperator:N(Yt),arithmeticOperator:N(Yt),logicOperator:N(Yt),bitwiseOperator:N(Yt),compareOperator:N(Yt),updateOperator:N(Yt),definitionOperator:N(Yt),typeOperator:N(Yt),controlOperator:N(Yt),punctuation:tu,separator:N(tu),bracket:Lr,angleBracket:N(Lr),squareBracket:N(Lr),paren:N(Lr),brace:N(Lr),content:Xt,heading:hi,heading1:N(hi),heading2:N(hi),heading3:N(hi),heading4:N(hi),heading5:N(hi),heading6:N(hi),contentSeparator:N(Xt),list:N(Xt),quote:N(Xt),emphasis:N(Xt),strong:N(Xt),link:N(Xt),monospace:N(Xt),strikethrough:N(Xt),inserted:N(),deleted:N(),changed:N(),invalid:N(),meta:Eo,documentMeta:N(Eo),annotation:N(Eo),processingInstruction:N(Eo),definition:Mt.defineModifier("definition"),constant:Mt.defineModifier("constant"),function:Mt.defineModifier("function"),standard:Mt.defineModifier("standard"),local:Mt.defineModifier("local"),special:Mt.defineModifier("special")};for(let n in O){let e=O[n];e instanceof Mt&&(e.name=n)}Zx([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}]);var Ec;const Yi=new Y;function sI(n){return z.define({combine:n?e=>e.concat(n):void 0})}const oI=new Y;class Vt{constructor(e,t,i=[],r=""){this.data=e,this.name=r,ee.prototype.hasOwnProperty("tree")||Object.defineProperty(ee.prototype,"tree",{get(){return ht(this)}}),this.parser=t,this.extension=[kr.of(this),ee.languageData.of((s,o,l)=>{let a=jm(s,o,l),c=a.type.prop(Yi);if(!c)return[];let h=s.facet(c),u=a.type.prop(oI);if(u){let f=a.resolve(o-a.from,l);for(let d of u)if(d.test(f,s)){let p=s.facet(d.facet);return d.type=="replace"?p:p.concat(h)}}return h})].concat(i)}isActiveAt(e,t,i=-1){return jm(e,t,i).type.prop(Yi)==this.data}findRegions(e){let t=e.facet(kr);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],r=(s,o)=>{if(s.prop(Yi)==this.data){i.push({from:o,to:o+s.length});return}let l=s.prop(Y.mounted);if(l){if(l.tree.prop(Yi)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+s.length});return}else if(l.overlay){let a=i.length;if(r(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<s.children.length;a++){let c=s.children[a];c instanceof Me&&r(c,s.positions[a]+o)}};return r(ht(e),0),i}get allowsNesting(){return!0}}Vt.setState=Q.define();function jm(n,e,t){let i=n.facet(kr),r=ht(n).topNode;if(!i||i.allowsNesting)for(let s=r;s;s=s.enter(e,t,le.ExcludeBuffers|le.EnterBracketed))s.type.isTop&&(r=s);return r}class nu extends Vt{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=sI(e.languageData);return new nu(t,e.parser.configure({props:[Yi.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new nu(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ht(n){let e=n.field(Vt.state,!1);return e?e.tree:Me.empty}class lI{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let Pr=null;class Kl{constructor(e,t,i=[],r,s,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Kl(e,t,[],Me.empty,0,i,[],null)}startParse(){return this.parser.startParse(new lI(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=Me.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let r=Date.now()+e;e=()=>Date.now()>r}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let r=this.parse.advance();if(r)if(this.fragments=this.withoutTempSkipped(An.addTree(r,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=r,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(An.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Pr;Pr=this;try{return e()}finally{Pr=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=_m(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:r,treeLen:s,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,h,u,f)=>a.push({fromA:c,toA:h,fromB:u,toB:f})),i=An.applyChanges(i,a),r=Me.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let h=e.mapPos(c.from,1),u=e.mapPos(c.to,-1);h<u&&l.push({from:h,to:u})}}}return new Kl(this.parser,t,i,r,s,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:r,to:s}=this.skipped[i];r<e.to&&s>e.from&&(this.fragments=_m(this.fragments,r,s),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends WN{createParse(t,i,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=Pr;if(a){for(let c of r)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new Me(ct.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Pr}}function _m(n,e,t){return An.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class wr{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new wr(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Kl.create(e.facet(kr).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new wr(i)}}Vt.state=ut.define({create:wr.init,update(n,e){for(let t of e.effects)if(t.is(Vt.setState))return t.value;return e.startState.facet(kr)!=e.state.facet(kr)?wr.init(e.state):n.apply(e)}});let e1=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(e1=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Oc=typeof navigator<"u"&&(!((Ec=navigator.scheduling)===null||Ec===void 0)&&Ec.isInputPending)?()=>navigator.scheduling.isInputPending():null,aI=at.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Vt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Vt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=e1(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:r}}=this.view,s=i.field(Vt.state);if(s.tree==s.context.tree&&s.context.isDone(r+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Oc?Math.max(25,e.timeRemaining()-5):1e9),l=s.context.treeLen<r&&i.doc.length>r+1e3,a=s.context.work(()=>Oc&&Oc()||Date.now()>o,r+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Vt.setState.of(new wr(s.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>xt(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),kr=z.define({combine(n){return n.length?n[0]:null},enables:n=>[Vt.state,aI,B.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class sB{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class t1{constructor(e,t,i,r,s,o=void 0){this.name=e,this.alias=t,this.extensions=i,this.filename=r,this.loadFunc=s,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new t1(e.name,(e.alias||[]).concat(e.name).map(r=>r.toLowerCase()),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let r of e)if(r.filename&&r.filename.test(t))return r;let i=/\.([^.]+)$/.exec(t);if(i){for(let r of e)if(r.extensions.indexOf(i[1])>-1)return r}return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let r of e)if(r.alias.some(s=>s==t))return r;if(i)for(let r of e)for(let s of r.alias){let o=t.indexOf(s);if(o>-1&&(s.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+s.length])))return r}return null}}const cI=z.define(),Ea=z.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Jl(n){let e=n.facet(Ea);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Ds(n,e){let t="",i=n.tabSize,r=n.facet(Ea)[0];if(r==" "){for(;e>=i;)t+=" ",e-=i;r=" "}for(let s=0;s<e;s++)t+=r;return t}function Sf(n,e){n instanceof ee&&(n=new Oa(n));for(let i of n.state.facet(cI)){let r=i(n,e);if(r!==void 0)return r}let t=ht(n.state);return t.length>=e?uI(n,t,e):null}class Oa{constructor(e,t={}){this.state=e,this.options=t,this.unit=Jl(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:r,simulateDoubleBreak:s}=this.options;return r!=null&&r>=i.from&&r<=i.to?s&&r==e?{text:"",from:e}:(t<0?r<e:r<=e)?{text:i.text.slice(r-i.from),from:r}:{text:i.text.slice(0,r-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:r}=this.lineAt(e,t);return i.slice(e-r,Math.min(i.length,e+100-r))}column(e,t=1){let{text:i,from:r}=this.lineAt(e,t),s=this.countColumn(i,e-r),o=this.options.overrideIndentation?this.options.overrideIndentation(r):-1;return o>-1&&(s+=o-this.countColumn(i,i.search(/\S|$/))),s}countColumn(e,t=e.length){return ka(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:r}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let o=s(r);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const hI=new Y;function uI(n,e,t){let i=e.resolveStack(t),r=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(r!=i.node){let s=[];for(let o=r;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)s.push(o);for(let o=s.length-1;o>=0;o--)i={node:s[o],next:i}}return n1(i,n,t)}function n1(n,e,t){for(let i=n;i;i=i.next){let r=dI(i.node);if(r)return r(Cf.create(e,t,i))}return 0}function fI(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function dI(n){let e=n.type.prop(hI);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(Y.closedBy))){let r=n.lastChild,s=r&&i.indexOf(r.name)>-1;return o=>i1(o,!0,1,void 0,s&&!fI(o)?r.from:void 0)}return n.parent==null?pI:null}function pI(){return 0}class Cf extends Oa{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Cf(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(mI(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return n1(this.context.next,this.base,this.pos)}}function mI(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function gI(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let r=n.options.simulateBreak,s=n.state.doc.lineAt(t.from),o=r==null||r<=s.from?s.to:Math.min(s.to,r);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let c=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function oB({closing:n,align:e=!0,units:t=1}){return i=>i1(i,e,t,n)}function i1(n,e,t,i,r){let s=n.textAfter,o=s.match(/^\s*/)[0].length,l=i&&s.slice(o,o+i.length)==i||r==n.pos+o,a=e?gI(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const lB=n=>n.baseIndent;function aB({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const yI=200;function bI(){return ee.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,r=t.lineAt(i);if(i>r.from+yI)return n;let s=t.sliceString(r.from,i);if(!e.some(c=>c.test(s)))return n;let{state:o}=n,l=-1,a=[];for(let{head:c}of o.selection.ranges){let h=o.doc.lineAt(c);if(h.from==l)continue;l=h.from;let u=Sf(o,h.from);if(u==null)continue;let f=/^\s*/.exec(h.text)[0],d=Ds(o,u);f!=d&&a.push({from:h.from,to:h.from+f.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}const cB=z.define(),hB=new Y;function uB(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}class Ra{constructor(e,t){this.specs=e;let i;function r(l){let a=ti.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const s=typeof t.all=="string"?t.all:t.all?r(t.all):void 0,o=t.scope;this.scope=o instanceof Vt?l=>l.prop(Yi)==o.data:o?l=>l==o:void 0,this.style=Zx(e.map(l=>({tag:l.tag,class:l.class||r(Object.assign({},l,{tag:null}))})),{all:s}).style,this.module=i?new ti(i):null,this.themeType=t.themeType}static define(e,t){return new Ra(e,t||{})}}const iu=z.define(),xI=z.define({combine(n){return n.length?[n[0]]:null}});function Rc(n){let e=n.facet(iu);return e.length?e:n.facet(xI)}function r1(n,e){let t=[kI],i;return n instanceof Ra&&(n.module&&t.push(B.styleModule.of(n.module)),i=n.themeType),i?t.push(iu.computeN([B.darkTheme],r=>r.facet(B.darkTheme)==(i=="dark")?[n]:[])):t.push(iu.of(n)),t}class wI{constructor(e){this.markCache=Object.create(null),this.tree=ht(e.state),this.decorations=this.buildDeco(e,Rc(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=ht(e.state),i=Rc(e.state),r=i!=Rc(e.startState),{viewport:s}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<s.to&&!r&&t.type==this.tree.type&&o>=s.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||r)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return q.none;let i=new gr;for(let{from:r,to:s}of e.visibleRanges)nI(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=q.mark({class:a})))},r,s);return i.finish()}}const kI=Fi.high(at.fromClass(wI,{decorations:n=>n.decorations})),vI=B.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),s1=1e4,o1="()[]{}",l1=z.define({combine(n){return Cr(n,{afterCursor:!0,brackets:o1,maxScanDistance:s1,renderMatch:MI})}}),SI=q.mark({class:"cm-matchingBracket"}),CI=q.mark({class:"cm-nonmatchingBracket"});function MI(n){let e=[],t=n.matched?SI:CI;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const TI=ut.define({create(){return q.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(l1);for(let r of e.state.selection.ranges){if(!r.empty)continue;let s=an(e.state,r.head,-1,i)||r.head>0&&an(e.state,r.head-1,1,i)||i.afterCursor&&(an(e.state,r.head,1,i)||r.head<e.state.doc.length&&an(e.state,r.head+1,-1,i));s&&(t=t.concat(i.renderMatch(s,e.state)))}return q.set(t,!0)},provide:n=>B.decorations.from(n)}),AI=[TI,vI];function EI(n={}){return[l1.of(n),AI]}const OI=new Y;function ru(n,e,t){let i=n.prop(e<0?Y.openedBy:Y.closedBy);if(i)return i;if(n.name.length==1){let r=t.indexOf(n.name);if(r>-1&&r%2==(e<0?1:0))return[t[r+e]]}return null}function su(n){let e=n.type.prop(OI);return e?e(n.node):n}function an(n,e,t,i={}){let r=i.maxScanDistance||s1,s=i.brackets||o1,o=ht(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=ru(a.type,t,s);if(c&&a.from<a.to){let h=su(a);if(h&&(t>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return RI(n,e,t,a,h,c,s)}}return DI(n,e,t,o,l.type,r,s)}function RI(n,e,t,i,r,s,o){let l=i.parent,a={from:r.from,to:r.to},c=0,h=l?.cursor();if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(c==0&&s.indexOf(h.type.name)>-1&&h.from<h.to){let u=su(h);return{start:a,end:u?{from:u.from,to:u.to}:void 0,matched:!0}}else if(ru(h.type,t,o))c++;else if(ru(h.type,-t,o)){if(c==0){let u=su(h);return{start:a,end:u&&u.from<u.to?{from:u.from,to:u.to}:void 0,matched:!1}}c--}}while(t<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function DI(n,e,t,i,r,s,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},h=n.doc.iterRange(e,t>0?n.doc.length:0),u=0;for(let f=0;!h.next().done&&f<=s;){let d=h.value;t<0&&(f+=d.length);let p=e+f*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=r))if(y%2==0==t>0)u++;else{if(u==1)return{start:c,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};u--}}t>0&&(f+=d.length)}return h.done?{start:c,matched:!1}:null}const NI=Object.create(null),Um=[ct.none],qm=[],Km=Object.create(null),II=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])II[n]=LI(NI,e);function Dc(n,e){qm.indexOf(n)>-1||(qm.push(n),console.warn(e))}function LI(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let h=n[c]||O[c];h?typeof h=="function"?a.length?a=a.map(h):Dc(c,`Modifier ${c} used at start of tag`):a.length?Dc(c,`Tag ${c} used as modifier`):a=Array.isArray(h)?h:[h]:Dc(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),r=i+" "+t.map(l=>l.id),s=Km[r];if(s)return s.id;let o=Km[r]=ct.define({id:Um.length,name:i,props:[eI({[i]:t})]});return Um.push(o),o.id}ye.RTL,ye.LTR;const PI=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=Tf(n.state,t.from);return i.line?BI(n):i.block?HI(n):!1};function Mf(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let r=n(e,t);return r?(i(t.update(r)),!0):!1}}const BI=Mf(VI,0),zI=Mf(a1,0),HI=Mf((n,e)=>a1(n,e,$I(e)),0);function Tf(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Br=50;function FI(n,{open:e,close:t},i,r){let s=n.sliceDoc(i-Br,i),o=n.sliceDoc(r,r+Br),l=/\s*$/.exec(s)[0].length,a=/^\s*/.exec(o)[0].length,c=s.length-l;if(s.slice(c-e.length,c)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:r+a,margin:a&&1}};let h,u;r-i<=2*Br?h=u=n.sliceDoc(i,r):(h=n.sliceDoc(i,i+Br),u=n.sliceDoc(r-Br,r));let f=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(u)[0].length,p=u.length-d-t.length;return h.slice(f,f+e.length)==e&&u.slice(p,p+t.length)==t?{open:{pos:i+f+e.length,margin:/\s/.test(h.charAt(f+e.length))?1:0},close:{pos:r-d-t.length,margin:/\s/.test(u.charAt(p-1))?1:0}}:null}function $I(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),r=t.to<=i.to?i:n.doc.lineAt(t.to);r.from>i.from&&r.from==t.to&&(r=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>i.from?e[s].to=r.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:r.to})}return e}function a1(n,e,t=e.selection.ranges){let i=t.map(s=>Tf(e,s.from).block);if(!i.every(s=>s))return null;let r=t.map((s,o)=>FI(e,i[o],s.from,s.to));if(n!=2&&!r.every(s=>s))return{changes:e.changes(t.map((s,o)=>r[o]?[]:[{from:s.from,insert:i[o].open+" "},{from:s.to,insert:" "+i[o].close}]))};if(n!=1&&r.some(s=>s)){let s=[];for(let o=0,l;o<r.length;o++)if(l=r[o]){let a=i[o],{open:c,close:h}=l;s.push({from:c.pos-a.open.length,to:c.pos+c.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:s}}return null}function VI(n,e,t=e.selection.ranges){let i=[],r=-1;e:for(let{from:s,to:o}of t){let l=i.length,a=1e9,c;for(let h=s;h<=o;){let u=e.doc.lineAt(h);if(c==null&&(c=Tf(e,u.from).line,!c))continue e;if(u.from>r&&(s==o||o>u.from)){r=u.from;let f=/^\s*/.exec(u.text)[0].length,d=f==u.length,p=u.text.slice(f,f+c.length)==c?f:-1;f<u.text.length&&f<a&&(a=f),i.push({line:u,comment:p,token:c,indent:f,empty:d,single:!1})}h=u.to+1}if(a<1e9)for(let h=l;h<i.length;h++)i[h].indent<i[h].line.text.length&&(i[h].indent=a);i.length==l+1&&(i[l].single=!0)}if(n!=2&&i.some(s=>s.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:l,token:a,indent:c,empty:h,single:u}of i)(u||!h)&&s.push({from:l.from+c,insert:a+" "});let o=e.changes(s);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(s=>s.comment>=0)){let s=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let c=o.from+l,h=c+a.length;o.text[h-o.from]==" "&&h++,s.push({from:c,to:h})}return{changes:s}}return null}const ou=Nn.define(),WI=Nn.define(),jI=z.define(),c1=z.define({combine(n){return Cr(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,r)=>e(i,r)||t(i,r)})}}),h1=ut.define({create(){return cn.empty},update(n,e){let t=e.state.facet(c1),i=e.annotation(ou);if(i){let a=st.fromTransaction(e,i.selection),c=i.side,h=c==0?n.undone:n.done;return a?h=Gl(h,h.length,t.minDepth,a):h=d1(h,e.startState.selection),new cn(c==0?i.rest:h,c==0?h:i.rest)}let r=e.annotation(WI);if((r=="full"||r=="before")&&(n=n.isolate()),e.annotation(Ce.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let s=st.fromTransaction(e),o=e.annotation(Ce.time),l=e.annotation(Ce.userEvent);return s?n=n.addChanges(s,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(r=="full"||r=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new cn(n.done.map(st.fromJSON),n.undone.map(st.fromJSON))}});function _I(n={}){return[h1,c1.of(n),B.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?u1:e.inputType=="historyRedo"?lu:null;return i?(e.preventDefault(),i(t)):!1}})]}function Da(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let r=t.field(h1,!1);if(!r)return!1;let s=r.pop(n,t,e);return s?(i(s),!0):!1}}const u1=Da(0,!1),lu=Da(1,!1),UI=Da(0,!0),qI=Da(1,!0);class st{constructor(e,t,i,r,s){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=r,this.selectionsAfter=s}setSelAfter(e){return new st(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(e){return new st(e.changes&&Ee.fromJSON(e.changes),[],e.mapped&&hn.fromJSON(e.mapped),e.startSelection&&T.fromJSON(e.startSelection),e.selectionsAfter.map(T.fromJSON))}static fromTransaction(e,t){let i=Ot;for(let r of e.startState.facet(jI)){let s=r(e);s.length&&(i=i.concat(s))}return!i.length&&e.changes.empty?null:new st(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ot)}static selection(e){return new st(void 0,Ot,void 0,void 0,e)}}function Gl(n,e,t,i){let r=e+1>t+20?e-t-1:0,s=n.slice(r,e);return s.push(i),s}function KI(n,e){let t=[],i=!1;return n.iterChangedRanges((r,s)=>t.push(r,s)),e.iterChangedRanges((r,s,o,l)=>{for(let a=0;a<t.length;){let c=t[a++],h=t[a++];l>=c&&o<=h&&(i=!0)}}),i}function JI(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function f1(n,e){return n.length?e.length?n.concat(e):n:e}const Ot=[],GI=200;function d1(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-GI));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Gl(n,n.length-1,1e9,t.setSelAfter(i)))}else return[st.selection([e])]}function YI(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Nc(n,e){if(!n.length)return n;let t=n.length,i=Ot;for(;t;){let r=XI(n[t-1],e,i);if(r.changes&&!r.changes.empty||r.effects.length){let s=n.slice(0,t);return s[t-1]=r,s}else e=r.mapped,t--,i=r.selectionsAfter}return i.length?[st.selection(i)]:Ot}function XI(n,e,t){let i=f1(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Ot,t);if(!n.changes)return st.selection(i);let r=n.changes.map(e),s=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(s):s;return new st(r,Q.mapEffects(n.effects,e),o,n.startSelection.map(s),i)}const QI=/^(input\.type|delete)($|\.)/;class cn{constructor(e,t,i=0,r=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=r}isolate(){return this.prevTime?new cn(this.done,this.undone):this}addChanges(e,t,i,r,s){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||QI.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<r.newGroupDelay&&r.joinToEvent(s,KI(l.changes,e.changes))||i=="input.type.compose")?o=Gl(o,o.length-1,r.minDepth,new st(e.changes.compose(l.changes),f1(Q.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ot)):o=Gl(o,o.length,r.minDepth,e),new cn(o,Ot,t,i)}addSelection(e,t,i,r){let s=this.done.length?this.done[this.done.length-1].selectionsAfter:Ot;return s.length>0&&t-this.prevTime<r&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&JI(s[s.length-1],e)?this:new cn(d1(this.done,e),this.undone,t,i)}addMapping(e){return new cn(Nc(this.done,e),Nc(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let r=e==0?this.done:this.undone;if(r.length==0)return null;let s=r[r.length-1],o=s.selectionsAfter[0]||(s.startSelection?s.startSelection.map(s.changes.invertedDesc,1):t.selection);if(i&&s.selectionsAfter.length)return t.update({selection:s.selectionsAfter[s.selectionsAfter.length-1],annotations:ou.of({side:e,rest:YI(r),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(s.changes){let l=r.length==1?Ot:r.slice(0,r.length-1);return s.mapped&&(l=Nc(l,s.mapped)),t.update({changes:s.changes,selection:s.startSelection,effects:s.effects,annotations:ou.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}cn.empty=new cn(Ot,Ot);const ZI=[{key:"Mod-z",run:u1,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:lu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:lu,preventDefault:!0},{key:"Mod-u",run:UI,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:qI,preventDefault:!0}];function Mr(n,e){return T.create(n.ranges.map(e),n.mainIndex)}function Ut(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function qt({state:n,dispatch:e},t){let i=Mr(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Ut(n,i)),!0)}function Na(n,e){return T.cursor(e?n.to:n.from)}function p1(n,e){return qt(n,t=>t.empty?n.moveByChar(t,e):Na(t,e))}function Ye(n){return n.textDirectionAt(n.state.selection.main.head)==ye.LTR}const m1=n=>p1(n,!Ye(n)),g1=n=>p1(n,Ye(n));function y1(n,e){return qt(n,t=>t.empty?n.moveByGroup(t,e):Na(t,e))}const e2=n=>y1(n,!Ye(n)),t2=n=>y1(n,Ye(n));function n2(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Ia(n,e,t){let i=ht(n).resolveInner(e.head),r=t?Y.closedBy:Y.openedBy;for(let a=e.head;;){let c=t?i.childAfter(a):i.childBefore(a);if(!c)break;n2(n,c,r)?i=c:a=t?c.to:c.from}let s=i.type.prop(r),o,l;return s&&(o=t?an(n,i.from,1):an(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,T.cursor(l,t?-1:1)}const i2=n=>qt(n,e=>Ia(n.state,e,!Ye(n))),r2=n=>qt(n,e=>Ia(n.state,e,Ye(n)));function b1(n,e){return qt(n,t=>{if(!t.empty)return Na(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const x1=n=>b1(n,!1),w1=n=>b1(n,!0);function k1(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,r;if(e){for(let s of n.state.facet(B.scrollMargins)){let o=s(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}r=n.scrollDOM.clientHeight-t-i}else r=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,r-5)}}function v1(n,e){let t=k1(n),{state:i}=n,r=Mr(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):Na(o,e));if(r.eq(i.selection))return!1;let s;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,c=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<c&&(s=B.scrollIntoView(r.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Ut(i,r),{effects:s}),!0}const Jm=n=>v1(n,!1),au=n=>v1(n,!0);function ai(n,e,t){let i=n.lineBlockAt(e.head),r=n.moveToLineBoundary(e,t);if(r.head==e.head&&r.head!=(t?i.to:i.from)&&(r=n.moveToLineBoundary(e,t,!1)),!t&&r.head==i.from&&i.length){let s=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;s&&e.head!=i.from+s&&(r=T.cursor(i.from+s))}return r}const s2=n=>qt(n,e=>ai(n,e,!0)),o2=n=>qt(n,e=>ai(n,e,!1)),l2=n=>qt(n,e=>ai(n,e,!Ye(n))),a2=n=>qt(n,e=>ai(n,e,Ye(n))),c2=n=>qt(n,e=>T.cursor(n.lineBlockAt(e.head).from,1)),h2=n=>qt(n,e=>T.cursor(n.lineBlockAt(e.head).to,-1));function u2(n,e,t){let i=!1,r=Mr(n.selection,s=>{let o=an(n,s.head,-1)||an(n,s.head,1)||s.head>0&&an(n,s.head-1,1)||s.head<n.doc.length&&an(n,s.head+1,-1);if(!o||!o.end)return s;i=!0;let l=o.start.from==s.head?o.end.to:o.end.from;return T.cursor(l)});return i?(e(Ut(n,r)),!0):!1}const f2=({state:n,dispatch:e})=>u2(n,e);function Lt(n,e){let t=Mr(n.state.selection,i=>{let r=e(i);return T.range(i.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ut(n.state,t)),!0)}function S1(n,e){return Lt(n,t=>n.moveByChar(t,e))}const C1=n=>S1(n,!Ye(n)),M1=n=>S1(n,Ye(n));function T1(n,e){return Lt(n,t=>n.moveByGroup(t,e))}const d2=n=>T1(n,!Ye(n)),p2=n=>T1(n,Ye(n)),m2=n=>Lt(n,e=>Ia(n.state,e,!Ye(n))),g2=n=>Lt(n,e=>Ia(n.state,e,Ye(n)));function A1(n,e){return Lt(n,t=>n.moveVertically(t,e))}const E1=n=>A1(n,!1),O1=n=>A1(n,!0);function R1(n,e){return Lt(n,t=>n.moveVertically(t,e,k1(n).height))}const Gm=n=>R1(n,!1),Ym=n=>R1(n,!0),y2=n=>Lt(n,e=>ai(n,e,!0)),b2=n=>Lt(n,e=>ai(n,e,!1)),x2=n=>Lt(n,e=>ai(n,e,!Ye(n))),w2=n=>Lt(n,e=>ai(n,e,Ye(n))),k2=n=>Lt(n,e=>T.cursor(n.lineBlockAt(e.head).from)),v2=n=>Lt(n,e=>T.cursor(n.lineBlockAt(e.head).to)),Xm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:0})),!0),Qm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.doc.length})),!0),Zm=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.selection.main.anchor,head:0})),!0),eg=({state:n,dispatch:e})=>(e(Ut(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),S2=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),C2=({state:n,dispatch:e})=>{let t=La(n).map(({from:i,to:r})=>T.range(i,Math.min(r+1,n.doc.length)));return e(n.update({selection:T.create(t),userEvent:"select"})),!0},M2=({state:n,dispatch:e})=>{let t=Mr(n.selection,i=>{let r=ht(n),s=r.resolveStack(i.from,1);if(i.empty){let o=r.resolveStack(i.from,-1);o.node.from>=s.node.from&&o.node.to<=s.node.to&&(s=o)}for(let o=s;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return T.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ut(n,t)),!0)};function D1(n,e){let{state:t}=n,i=t.selection,r=t.selection.ranges.slice();for(let s of t.selection.ranges){let o=t.doc.lineAt(s.head);if(e?o.to<n.state.doc.length:o.from>0)for(let l=s;;){let a=n.moveVertically(l,e);if(a.head<o.from||a.head>o.to){r.some(c=>c.head==a.head)||r.push(a);break}else{if(a.head==l.head)break;l=a}}}return r.length==i.ranges.length?!1:(n.dispatch(Ut(t,T.create(r,r.length-1))),!0)}const T2=n=>D1(n,!1),A2=n=>D1(n,!0),E2=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=T.create([t.main]):t.main.empty||(i=T.create([T.cursor(t.main.head)])),i?(e(Ut(n,i)),!0):!1};function _s(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,r=i.changeByRange(s=>{let{from:o,to:l}=s;if(o==l){let a=e(s);a<o?(t="delete.backward",a=Oo(n,a,!1)):a>o&&(t="delete.forward",a=Oo(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Oo(n,o,!1),l=Oo(n,l,!0);return o==l?{range:s}:{changes:{from:o,to:l},range:T.cursor(o,o<s.head?-1:1)}});return r.changes.empty?!1:(n.dispatch(i.update(r,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?B.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Oo(n,e,t){if(n instanceof B)for(let i of n.state.facet(B.atomicRanges).map(r=>r(n)))i.between(e,e,(r,s)=>{r<e&&s>e&&(e=t?s:r)});return e}const N1=(n,e,t)=>_s(n,i=>{let r=i.from,{state:s}=n,o=s.doc.lineAt(r),l,a;if(t&&!e&&r>o.from&&r<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,r-o.from))){if(l[l.length-1]==" ")return r-1;let c=ka(l,s.tabSize),h=c%Jl(s)||Jl(s);for(let u=0;u<h&&l[l.length-1-u]==" ";u++)r--;a=r}else a=Pe(o.text,r-o.from,e,e)+o.from,a==r&&o.number!=(e?s.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,r-o.from))&&(a=Pe(o.text,a-o.from,!1,!1)+o.from);return a}),cu=n=>N1(n,!1,!0),I1=n=>N1(n,!0,!1),L1=(n,e)=>_s(n,t=>{let i=t.head,{state:r}=n,s=r.doc.lineAt(i),o=r.charCategorizer(i);for(let l=null;;){if(i==(e?s.to:s.from)){i==t.head&&s.number!=(e?r.doc.lines:1)&&(i+=e?1:-1);break}let a=Pe(s.text,i-s.from,e)+s.from,c=s.text.slice(Math.min(i,a)-s.from,Math.max(i,a)-s.from),h=o(c);if(l!=null&&h!=l)break;(c!=" "||i!=t.head)&&(l=h),i=a}return i}),P1=n=>L1(n,!1),O2=n=>L1(n,!0),R2=n=>_s(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),D2=n=>_s(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),N2=n=>_s(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),I2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:ne.of(["",""])},range:T.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},L2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let r=i.from,s=n.doc.lineAt(r),o=r==s.from?r-1:Pe(s.text,r-s.from,!1)+s.from,l=r==s.to?r+1:Pe(s.text,r-s.from,!0)+s.from;return{changes:{from:o,to:l,insert:n.doc.slice(r,l).append(n.doc.slice(o,r))},range:T.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function La(n){let e=[],t=-1;for(let i of n.selection.ranges){let r=n.doc.lineAt(i.from),s=n.doc.lineAt(i.to);if(!i.empty&&i.to==s.from&&(s=n.doc.lineAt(i.to-1)),t>=r.number){let o=e[e.length-1];o.to=s.to,o.ranges.push(i)}else e.push({from:r.from,to:s.to,ranges:[i]});t=s.number+1}return e}function B1(n,e,t){if(n.readOnly)return!1;let i=[],r=[];for(let s of La(n)){if(t?s.to==n.doc.length:s.from==0)continue;let o=n.doc.lineAt(t?s.to+1:s.from-1),l=o.length+1;if(t){i.push({from:s.to,to:o.to},{from:s.from,insert:o.text+n.lineBreak});for(let a of s.ranges)r.push(T.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:s.from},{from:s.to,insert:n.lineBreak+o.text});for(let a of s.ranges)r.push(T.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:T.create(r,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const P2=({state:n,dispatch:e})=>B1(n,e,!1),B2=({state:n,dispatch:e})=>B1(n,e,!0);function z1(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of La(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});let r=n.changes(i);return e(n.update({changes:r,selection:n.selection.map(r,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const z2=({state:n,dispatch:e})=>z1(n,e,!1),H2=({state:n,dispatch:e})=>z1(n,e,!0),F2=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(La(e).map(({from:r,to:s})=>(r>0?r--:s<e.doc.length&&s++,{from:r,to:s}))),i=Mr(e.selection,r=>{let s;if(n.lineWrapping){let o=n.lineBlockAt(r.head),l=n.coordsAtPos(r.head,r.assoc||1);l&&(s=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(r,!0,s)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function $2(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ht(n).resolveInner(e),i=t.childBefore(e),r=t.childAfter(e),s;return i&&r&&i.to<=e&&r.from>=e&&(s=i.type.prop(Y.closedBy))&&s.indexOf(r.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(r.from).from&&!/\S/.test(n.sliceDoc(i.to,r.from))?{from:i.to,to:r.from}:null}const tg=H1(!1),V2=H1(!0);function H1(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(r=>{let{from:s,to:o}=r,l=e.doc.lineAt(s),a=!n&&s==o&&$2(e,s);n&&(s=o=(o<=l.to?l:e.doc.lineAt(o)).to);let c=new Oa(e,{simulateBreak:s,simulateDoubleBreak:!!a}),h=Sf(c,s);for(h==null&&(h=ka(/^\s*/.exec(e.doc.lineAt(s).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:s,to:o}=a:s>l.from&&s<l.from+100&&!/\S/.test(l.text.slice(0,s))&&(s=l.from);let u=["",Ds(e,h)];return a&&u.push(Ds(e,c.lineIndent(l.from,-1))),{changes:{from:s,to:o,insert:ne.of(u)},range:T.cursor(s+1+u[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Af(n,e){let t=-1;return n.changeByRange(i=>{let r=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,r,i),t=l.number),o=l.to+1}let s=n.changes(r);return{changes:r,range:T.range(s.mapPos(i.anchor,1),s.mapPos(i.head,1))}})}const W2=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Oa(n,{overrideIndentation:s=>{let o=t[s];return o??-1}}),r=Af(n,(s,o,l)=>{let a=Sf(i,s.from);if(a==null)return;/\S/.test(s.text)||(a=0);let c=/^\s*/.exec(s.text)[0],h=Ds(n,a);(c!=h||l.from<s.from+c.length)&&(t[s.from]=a,o.push({from:s.from,to:s.from+c.length,insert:h}))});return r.changes.empty||e(n.update(r,{userEvent:"indent"})),!0},F1=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Af(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Ea)})}),{userEvent:"input.indent"})),!0),$1=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Af(n,(t,i)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let s=ka(r,n.tabSize),o=0,l=Ds(n,Math.max(0,s-Jl(n)));for(;o<r.length&&o<l.length&&r.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+r.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),j2=n=>(n.setTabFocusMode(),!0),_2=[{key:"Ctrl-b",run:m1,shift:C1,preventDefault:!0},{key:"Ctrl-f",run:g1,shift:M1},{key:"Ctrl-p",run:x1,shift:E1},{key:"Ctrl-n",run:w1,shift:O1},{key:"Ctrl-a",run:c2,shift:k2},{key:"Ctrl-e",run:h2,shift:v2},{key:"Ctrl-d",run:I1},{key:"Ctrl-h",run:cu},{key:"Ctrl-k",run:R2},{key:"Ctrl-Alt-h",run:P1},{key:"Ctrl-o",run:I2},{key:"Ctrl-t",run:L2},{key:"Ctrl-v",run:au}],U2=[{key:"ArrowLeft",run:m1,shift:C1,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e2,shift:d2,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:l2,shift:x2,preventDefault:!0},{key:"ArrowRight",run:g1,shift:M1,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t2,shift:p2,preventDefault:!0},{mac:"Cmd-ArrowRight",run:a2,shift:w2,preventDefault:!0},{key:"ArrowUp",run:x1,shift:E1,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Xm,shift:Zm},{mac:"Ctrl-ArrowUp",run:Jm,shift:Gm},{key:"ArrowDown",run:w1,shift:O1,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Qm,shift:eg},{mac:"Ctrl-ArrowDown",run:au,shift:Ym},{key:"PageUp",run:Jm,shift:Gm},{key:"PageDown",run:au,shift:Ym},{key:"Home",run:o2,shift:b2,preventDefault:!0},{key:"Mod-Home",run:Xm,shift:Zm},{key:"End",run:s2,shift:y2,preventDefault:!0},{key:"Mod-End",run:Qm,shift:eg},{key:"Enter",run:tg,shift:tg},{key:"Mod-a",run:S2},{key:"Backspace",run:cu,shift:cu,preventDefault:!0},{key:"Delete",run:I1,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:P1,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:O2,preventDefault:!0},{mac:"Mod-Backspace",run:D2,preventDefault:!0},{mac:"Mod-Delete",run:N2,preventDefault:!0}].concat(_2.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),q2=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:i2,shift:m2},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:r2,shift:g2},{key:"Alt-ArrowUp",run:P2},{key:"Shift-Alt-ArrowUp",run:z2},{key:"Alt-ArrowDown",run:B2},{key:"Shift-Alt-ArrowDown",run:H2},{key:"Mod-Alt-ArrowUp",run:T2},{key:"Mod-Alt-ArrowDown",run:A2},{key:"Escape",run:E2},{key:"Mod-Enter",run:V2},{key:"Alt-l",mac:"Ctrl-l",run:C2},{key:"Mod-i",run:M2,preventDefault:!0},{key:"Mod-[",run:$1},{key:"Mod-]",run:F1},{key:"Mod-Alt-\\",run:W2},{key:"Shift-Mod-k",run:F2},{key:"Shift-Mod-\\",run:f2},{key:"Mod-/",run:PI},{key:"Alt-A",run:zI},{key:"Ctrl-m",mac:"Shift-Alt-m",run:j2}].concat(U2),K2={key:"Tab",run:F1,shift:$1},ng=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class vr{constructor(e,t,i=0,r=e.length,s,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,r),this.bufferStart=i,this.normalize=s?l=>s(ng(l)):ng,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return gt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=rf(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=rn(e);let r=this.normalize(t);if(r.length)for(let s=0,o=i;;s++){let l=r.charCodeAt(s),a=this.match(l,o,this.bufferPos+this.bufferStart);if(s==r.length-1){if(a)return this.value=a,this;break}o==i&&s<t.length&&t.charCodeAt(s)==l&&o++}}}match(e,t,i){let r=null;for(let s=0;s<this.matches.length;s+=2){let o=this.matches[s],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?r={from:this.matches[s+1],to:i}:(this.matches[s]++,l=!0)),l||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:i}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}}typeof Symbol<"u"&&(vr.prototype[Symbol.iterator]=function(){return this});const V1={from:-1,to:-1,match:/.*/.exec("")},Ef="gm"+(/x/.unicode==null?"":"u");class W1{constructor(e,t,i,r=0,s=e.length){if(this.text=e,this.to=s,this.curLine="",this.done=!1,this.value=V1,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new j1(e,t,i,r,s);this.re=new RegExp(t,Ef+(i?.ignoreCase?"i":"")),this.test=i?.test,this.iter=e.iter();let o=e.lineAt(r);this.curLineStart=o.from,this.matchPos=Yl(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,r=i+t[0].length;if(this.matchPos=Yl(this.text,r+(i==r?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<r||i>this.value.to)&&(!this.test||this.test(i,r,t)))return this.value={from:i,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Ic=new WeakMap;class or{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let r=Ic.get(e);if(!r||r.from>=i||r.to<=t){let l=new or(t,e.sliceString(t,i));return Ic.set(e,l),l}if(r.from==t&&r.to==i)return r;let{text:s,from:o}=r;return o>t&&(s=e.sliceString(t,o)+s,o=t),r.to<i&&(s+=e.sliceString(r.to,i)),Ic.set(e,new or(o,s)),new or(t,s.slice(t-o,i-o))}}class j1{constructor(e,t,i,r,s){this.text=e,this.to=s,this.done=!1,this.value=V1,this.matchPos=Yl(e,r),this.re=new RegExp(t,Ef+(i?.ignoreCase?"i":"")),this.test=i?.test,this.flat=or.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,r=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,r,t)))return this.value={from:i,to:r,match:t},this.matchPos=Yl(this.text,r+(i==r?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=or.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(W1.prototype[Symbol.iterator]=j1.prototype[Symbol.iterator]=function(){return this});function J2(n){try{return new RegExp(n,Ef),!0}catch{return!1}}function Yl(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const G2=n=>{let{state:e}=n,t=String(e.doc.lineAt(n.state.selection.main.head).number),{close:i,result:r}=kN(n,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return r.then(s=>{let o=s&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.elements.line.value);if(!o){n.dispatch({effects:i});return}let l=e.doc.lineAt(e.selection.main.head),[,a,c,h,u]=o,f=h?+h.slice(1):0,d=c?+c:l.number;if(c&&u){let g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/e.doc.lines),d=Math.round(e.doc.lines*g)}else c&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=e.doc.line(Math.max(1,Math.min(e.doc.lines,d))),m=T.cursor(p.from+Math.max(0,Math.min(f,p.length)));n.dispatch({effects:[i,B.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},Y2={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},X2=z.define({combine(n){return Cr(n,Y2,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Q2(n){return[iL,nL]}const Z2=q.mark({class:"cm-selectionMatch"}),eL=q.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ig(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=ge.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=ge.Word)}function tL(n,e,t,i){return n(e.sliceDoc(t,t+1))==ge.Word&&n(e.sliceDoc(i-1,i))==ge.Word}const nL=at.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(X2),{state:t}=n,i=t.selection;if(i.ranges.length>1)return q.none;let r=i.main,s,o=null;if(r.empty){if(!e.highlightWordAroundCursor)return q.none;let a=t.wordAt(r.head);if(!a)return q.none;o=t.charCategorizer(r.head),s=t.sliceDoc(a.from,a.to)}else{let a=r.to-r.from;if(a<e.minSelectionLength||a>200)return q.none;if(e.wholeWords){if(s=t.sliceDoc(r.from,r.to),o=t.charCategorizer(r.head),!(ig(o,t,r.from,r.to)&&tL(o,t,r.from,r.to)))return q.none}else if(s=t.sliceDoc(r.from,r.to),!s)return q.none}let l=[];for(let a of n.visibleRanges){let c=new vr(t.doc,s,a.from,a.to);for(;!c.next().done;){let{from:h,to:u}=c.value;if((!o||ig(o,t,h,u))&&(r.empty&&h<=r.from&&u>=r.to?l.push(eL.range(h,u)):(h>=r.to||u<=r.from)&&l.push(Z2.range(h,u)),l.length>e.maxMatches))return q.none}}return q.set(l)}},{decorations:n=>n.decorations}),iL=B.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),rL=({state:n,dispatch:e})=>{let{selection:t}=n,i=T.create(t.ranges.map(r=>n.wordAt(r.head)||T.cursor(r.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function sL(n,e){let{main:t,ranges:i}=n.selection,r=n.wordAt(t.head),s=r&&r.from==t.from&&r.to==t.to;for(let o=!1,l=new vr(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new vr(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(s){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const oL=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(s=>s.from===s.to))return rL({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(s=>n.sliceDoc(s.from,s.to)!=i))return!1;let r=sL(n,i);return r?(e(n.update({selection:n.selection.addRange(T.range(r.from,r.to),!1),effects:B.scrollIntoView(r.to)})),!0):!1},Tr=z.define({combine(n){return Cr(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new wL(e),scrollToMatch:e=>B.scrollIntoView(e)})}});class _1{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||J2(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
161
+ `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new fL(this):new cL(this)}getCursor(e,t=0,i){let r=e.doc?e:ee.create({doc:e});return i==null&&(i=r.doc.length),this.regexp?Ki(this,r,t,i):qi(this,r,t,i)}}class U1{constructor(e){this.spec=e}}function lL(n,e,t){return(i,r,s,o)=>{if(t&&!t(i,r,s,o))return!1;let l=i>=o&&r<=o+s.length?s.slice(i-o,r-o):e.doc.sliceString(i,r);return n(l,e,i,r)}}function qi(n,e,t,i){let r;return n.wholeWord&&(r=aL(e.doc,e.charCategorizer(e.selection.main.head))),n.test&&(r=lL(n.test,e,r)),new vr(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),r)}function aL(n,e){return(t,i,r,s)=>((s>t||s+r.length<i)&&(s=Math.max(0,t-2),r=n.sliceString(s,Math.min(n.length,i+2))),(e(Xl(r,t-s))!=ge.Word||e(Ql(r,t-s))!=ge.Word)&&(e(Ql(r,i-s))!=ge.Word||e(Xl(r,i-s))!=ge.Word))}class cL extends U1{constructor(e){super(e)}nextMatch(e,t,i){let r=qi(this.spec,e,i,e.doc.length).nextOverlapping();if(r.done){let s=Math.min(e.doc.length,t+this.spec.unquoted.length);r=qi(this.spec,e,0,s).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==i?null:r.value}prevMatchInRange(e,t,i){for(let r=i;;){let s=Math.max(t,r-1e4-this.spec.unquoted.length),o=qi(this.spec,e,s,r),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(s==t)return null;r-=1e4}}prevMatch(e,t,i){let r=this.prevMatchInRange(e,0,t);return r||(r=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),r&&(r.from!=t||r.to!=i)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=qi(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=qi(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}function hL(n,e,t){return(i,r,s)=>(!t||t(i,r,s))&&n(s[0],e,i,r)}function Ki(n,e,t,i){let r;return n.wholeWord&&(r=uL(e.charCategorizer(e.selection.main.head))),n.test&&(r=hL(n.test,e,r)),new W1(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:r},t,i)}function Xl(n,e){return n.slice(Pe(n,e,!1),e)}function Ql(n,e){return n.slice(e,Pe(n,e))}function uL(n){return(e,t,i)=>!i[0].length||(n(Xl(i.input,i.index))!=ge.Word||n(Ql(i.input,i.index))!=ge.Word)&&(n(Ql(i.input,i.index+i[0].length))!=ge.Word||n(Xl(i.input,i.index+i[0].length))!=ge.Word)}class fL extends U1{nextMatch(e,t,i){let r=Ki(this.spec,e,i,e.doc.length).next();return r.done&&(r=Ki(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,i){for(let r=1;;r++){let s=Math.max(t,i-r*1e4),o=Ki(this.spec,e,s,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(s==t||l.from>s+10))return l;if(s==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let r=i.length;r>0;r--){let s=+i.slice(0,r);if(s>0&&s<e.match.length)return e.match[s]+i.slice(r)}return t})}matchAll(e,t){let i=Ki(this.spec,e,0,e.doc.length),r=[];for(;!i.next().done;){if(r.length>=t)return null;r.push(i.value)}return r}highlight(e,t,i,r){let s=Ki(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!s.next().done;)r(s.value.from,s.value.to)}}const Ns=Q.define(),Of=Q.define(),Qn=ut.define({create(n){return new Lc(hu(n).create(),null)},update(n,e){for(let t of e.effects)t.is(Ns)?n=new Lc(t.value.create(),n.panel):t.is(Of)&&(n=new Lc(n.query,t.value?Rf:null));return n},provide:n=>_l.from(n,e=>e.panel)});class Lc{constructor(e,t){this.query=e,this.panel=t}}const dL=q.mark({class:"cm-searchMatch"}),pL=q.mark({class:"cm-searchMatch cm-searchMatch-selected"}),mL=at.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(Qn))}update(n){let e=n.state.field(Qn);(e!=n.startState.field(Qn)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return q.none;let{view:t}=this,i=new gr;for(let r=0,s=t.visibleRanges,o=s.length;r<o;r++){let{from:l,to:a}=s[r];for(;r<o-1&&a>s[r+1].from-500;)a=s[++r].to;n.highlight(t.state,l,a,(c,h)=>{let u=t.state.selection.ranges.some(f=>f.from==c&&f.to==h);i.add(c,h,u?pL:dL)})}return i.finish()}},{decorations:n=>n.decorations});function Us(n){return e=>{let t=e.state.field(Qn,!1);return t&&t.query.spec.valid?n(e,t):J1(e)}}const Zl=Us((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let r=T.single(i.from,i.to),s=n.state.facet(Tr);return n.dispatch({selection:r,effects:[Df(n,i),s.scrollToMatch(r.main,n)],userEvent:"select.search"}),K1(n),!0}),ea=Us((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,r=e.prevMatch(t,i,i);if(!r)return!1;let s=T.single(r.from,r.to),o=n.state.facet(Tr);return n.dispatch({selection:s,effects:[Df(n,r),o.scrollToMatch(s.main,n)],userEvent:"select.search"}),K1(n),!0}),gL=Us((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:T.create(t.map(i=>T.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),yL=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:r}=t.main,s=[],o=0;for(let l=new vr(n.doc,n.sliceDoc(i,r));!l.next().done;){if(s.length>1e3)return!1;l.value.from==i&&(o=s.length),s.push(T.range(l.value.from,l.value.to))}return e(n.update({selection:T.create(s,o),userEvent:"select.search.matches"})),!0},rg=Us((n,{query:e})=>{let{state:t}=n,{from:i,to:r}=t.selection.main;if(t.readOnly)return!1;let s=e.nextMatch(t,i,i);if(!s)return!1;let o=s,l=[],a,c,h=[];o.from==i&&o.to==r&&(c=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:c}),o=e.nextMatch(t,o.from,o.to),h.push(B.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+".")));let u=n.state.changes(l);return o&&(a=T.single(o.from,o.to).map(u),h.push(Df(n,o)),h.push(t.facet(Tr).scrollToMatch(a.main,n))),n.dispatch({changes:u,selection:a,effects:h,userEvent:"input.replace"}),!0}),bL=Us((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(r=>{let{from:s,to:o}=r;return{from:s,to:o,insert:e.getReplacement(r)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:B.announce.of(i),userEvent:"input.replace.all"}),!0});function Rf(n){return n.state.facet(Tr).createPanel(n)}function hu(n,e){var t,i,r,s,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let c=n.facet(Tr);return new _1({search:((t=e?.literal)!==null&&t!==void 0?t:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(r=e?.literal)!==null&&r!==void 0?r:c.literal,regexp:(s=e?.regexp)!==null&&s!==void 0?s:c.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function q1(n){let e=jx(n,Rf);return e&&e.dom.querySelector("[main-field]")}function K1(n){let e=q1(n);e&&e==n.root.activeElement&&e.select()}const J1=n=>{let e=n.state.field(Qn,!1);if(e&&e.panel){let t=q1(n);if(t&&t!=n.root.activeElement){let i=hu(n.state,e.query.spec);i.valid&&n.dispatch({effects:Ns.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Of.of(!0),e?Ns.of(hu(n.state,e.query.spec)):Q.appendConfig.of(vL)]});return!0},G1=n=>{let e=n.state.field(Qn,!1);if(!e||!e.panel)return!1;let t=jx(n,Rf);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Of.of(!1)}),!0},xL=[{key:"Mod-f",run:J1,scope:"editor search-panel"},{key:"F3",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Zl,shift:ea,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:G1,scope:"editor search-panel"},{key:"Mod-Shift-l",run:yL},{key:"Mod-Alt-g",run:G2},{key:"Mod-d",run:oL,preventDefault:!0}];class wL{constructor(e){this.view=e;let t=this.query=e.state.field(Qn).query.spec;this.commit=this.commit.bind(this),this.searchField=De("input",{value:t.search,placeholder:pt(e,"Find"),"aria-label":pt(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=De("input",{value:t.replace,placeholder:pt(e,"Replace"),"aria-label":pt(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=De("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=De("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=De("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(r,s,o){return De("button",{class:"cm-button",name:r,onclick:s,type:"button"},o)}this.dom=De("div",{onkeydown:r=>this.keydown(r),class:"cm-search"},[this.searchField,i("next",()=>Zl(e),[pt(e,"next")]),i("prev",()=>ea(e),[pt(e,"previous")]),i("select",()=>gL(e),[pt(e,"all")]),De("label",null,[this.caseField,pt(e,"match case")]),De("label",null,[this.reField,pt(e,"regexp")]),De("label",null,[this.wordField,pt(e,"by word")]),...e.state.readOnly?[]:[De("br"),this.replaceField,i("replace",()=>rg(e),[pt(e,"replace")]),i("replaceAll",()=>bL(e),[pt(e,"replace all")])],De("button",{name:"close",onclick:()=>G1(e),"aria-label":pt(e,"close"),type:"button"},["×"])])}commit(){let e=new _1({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ns.of(e)}))}keydown(e){uN(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?ea:Zl)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),rg(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Ns)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Tr).top}}function pt(n,e){return n.state.phrase(e)}const Ro=30,Do=/[\s\.,:;?!]/;function Df(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),r=n.state.doc.lineAt(t).to,s=Math.max(i.from,e-Ro),o=Math.min(r,t+Ro),l=n.state.sliceDoc(s,o);if(s!=i.from){for(let a=0;a<Ro;a++)if(!Do.test(l[a+1])&&Do.test(l[a])){l=l.slice(a);break}}if(o!=r){for(let a=l.length-1;a>l.length-Ro;a--)if(!Do.test(l[a-1])&&Do.test(l[a])){l=l.slice(0,a);break}}return B.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const kL=B.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),vL=[Qn,Fi.low(mL),kL];class Y1{constructor(e,t,i,r){this.state=e,this.pos=t,this.explicit=i,this.view=r,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ht(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),r=t.text.slice(i-t.from,this.pos-t.from),s=r.search(X1(e,!1));return s<0?null:{from:i+s,to:this.pos,text:r.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function sg(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function SL(n){let e=Object.create(null),t=Object.create(null);for(let{label:r}of n){e[r[0]]=!0;for(let s=1;s<r.length;s++)t[r[s]]=!0}let i=sg(e)+sg(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function CL(n){let e=n.map(r=>typeof r=="string"?{label:r}:r),[t,i]=e.every(r=>/^\w+$/.test(r.label))?[/\w*$/,/\w+$/]:SL(e);return r=>{let s=r.matchBefore(i);return s||r.explicit?{from:s?s.from:r.pos,options:e,validFor:t}:null}}function fB(n,e){return t=>{for(let i=ht(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class og{constructor(e,t,i,r){this.completion=e,this.source=t,this.match=i,this.score=r}}function Mi(n){return n.selection.main.from}function X1(n,e){var t;let{source:i}=n,r=e&&i[0]!="^",s=i[i.length-1]!="$";return!r&&!s?n:new RegExp(`${r?"^":""}(?:${i})${s?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const Nf=Nn.define();function ML(n,e,t,i){let{main:r}=n.selection,s=t-r.from,o=i-r.from;return{...n.changeByRange(l=>{if(l!=r&&t!=i&&n.sliceDoc(l.from+s,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+s,to:i==r.from?l.to:l.from+o,insert:a},range:T.cursor(l.from+s+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const lg=new WeakMap;function TL(n){if(!Array.isArray(n))return n;let e=lg.get(n);return e||lg.set(n,e=CL(n)),e}const ta=Q.define(),Is=Q.define();class AL{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=gt(e,t),r=rn(i);this.chars.push(i);let s=e.slice(t,t+r),o=s.toUpperCase();this.folded.push(gt(o==s?s.toLowerCase():o,0)),t+=r}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:r,precise:s,byWord:o}=this;if(t.length==1){let b=gt(e,0),x=rn(b),k=x==e.length?0:-100;if(b!=t[0])if(b==i[0])k+=-200;else return null;return this.ret(k,[0,x])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,c=0;if(l<0){for(let b=0,x=Math.min(e.length,200);b<x&&c<a;){let k=gt(e,b);(k==t[c]||k==i[c])&&(r[c++]=b),b+=rn(k)}if(c<a)return null}let h=0,u=0,f=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,x=Math.min(e.length,200),k=0;b<x&&u<a;){let w=gt(e,b);l<0&&(h<a&&w==t[h]&&(s[h++]=b),d<a&&(w==t[d]||w==i[d]?(d==0&&(p=b),m=b+1,d++):d=0));let C,v=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(C=rf(w))!=C.toLowerCase()?1:C!=C.toUpperCase()?2:0;(!b||v==1&&g||k==0&&v!=0)&&(t[u]==w||i[u]==w&&(f=!0)?o[u++]=b:o.length&&(y=!1)),k=v,b+=rn(w)}return u==a&&o[0]==0&&y?this.result(-100+(f?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):u==a?this.result(-100+(f?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((r[0]?-700:0)+-200+-1100,r,e)}result(e,t,i){let r=[],s=0;for(let o of t){let l=o+(this.astral?rn(gt(i,o)):1);s&&r[s-1]==o?r[s-1]=l:(r[s++]=o,r[s++]=l)}return this.ret(e-i.length,r)}}class EL{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const Ie=z.define({combine(n){return Cr(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:OL,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>ag(e(i),t(i)),optionClass:(e,t)=>i=>ag(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function ag(n,e){return n?e?n+" "+e:n:e}function OL(n,e,t,i,r,s){let o=n.textDirection==ye.RTL,l=o,a=!1,c="top",h,u,f=e.left-r.left,d=r.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&f<Math.min(p,d)?l=!1:!l&&d<Math.min(p,f)&&(l=!0),p<=(l?f:d))h=Math.max(r.top,Math.min(t.top,r.bottom-m))-e.top,u=Math.min(400,l?f:d);else{a=!0,u=Math.min(400,(o?e.right:r.right-e.left)-30);let b=r.bottom-e.bottom;b>=m||b>e.top?h=t.bottom-e.top:(c="bottom",h=e.bottom-t.top)}let g=(e.bottom-e.top)/s.offsetHeight,y=(e.right-e.left)/s.offsetWidth;return{style:`${c}: ${h/g}px; max-width: ${u/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function RL(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(r=>"cm-completionIcon-"+r)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,r,s){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let c=0;c<s.length;){let h=s[c++],u=s[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(l.slice(h,u))),f.className="cm-completionMatchedText",a=u}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Pc(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let r=Math.floor(e/t);return{from:r*t,to:(r+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class DL{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let r=e.state.field(t),{options:s,selected:o}=r.open,l=e.state.facet(Ie);this.optionContent=RL(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Pc(s.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:c}=e.state.field(t).open;for(let h=a.target,u;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(u=/-(\d+)$/.exec(h.id))&&+u[1]<c.length){this.applyCompletion(e,c[+u[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=e.state.field(this.stateField,!1);c&&c.tooltip&&e.state.facet(Ie).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Is.of(null)})}),this.showOptions(s,r.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),r=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=r){let{options:s,selected:o,disabled:l}=i.open;(!r.open||r.open.options!=s)&&(this.range=Pc(s.length,o,e.state.facet(Ie).maxRenderedOptions),this.showOptions(s,i.id)),this.updateSel(),l!=((t=r.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Pc(t.options.length,t.selected,this.view.state.facet(Ie).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:r}=t.options[t.selected],{info:s}=r;if(!s)return;let o=typeof s=="string"?document.createTextNode(s):s(r);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,r)}).catch(l=>xt(this.view.state,l,"completion info")):(this.addInfoPane(o,r),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:r,destroy:s}=e;i.appendChild(r),this.infoDestroy=s||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,r=this.range.from;i;i=i.nextSibling,r++)i.nodeName!="LI"||!i.id?r--:r==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&IL(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),r=e.getBoundingClientRect(),s=this.space;if(!s){let o=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return r.top>Math.min(s.bottom,t.bottom)-10||r.bottom<Math.max(s.top,t.top)+10?null:this.view.state.facet(Ie).positionInfo(this.view,t,r,i,s,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const r=document.createElement("ul");r.id=t,r.setAttribute("role","listbox"),r.setAttribute("aria-expanded","true"),r.setAttribute("aria-label",this.view.state.phrase("Completions")),r.addEventListener("mousedown",o=>{o.target==r&&o.preventDefault()});let s=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:c}=l;if(c){let f=typeof c=="string"?c:c.name;if(f!=s&&(o>i.from||i.from==0))if(s=f,typeof c!="string"&&c.header)r.appendChild(c.header(c));else{let d=r.appendChild(document.createElement("completion-section"));d.textContent=f}}const h=r.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let u=this.optionClass(l);u&&(h.className=u);for(let f of this.optionContent){let d=f(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&r.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&r.classList.add("cm-completionListIncompleteBottom"),r}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function NL(n,e){return t=>new DL(t,n,e)}function IL(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),r=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/r:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/r)}function cg(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function LL(n,e){let t=[],i=null,r=null,s=h=>{t.push(h);let{section:u}=h.completion;if(u){i||(i=[]);let f=typeof u=="string"?u:u.name;i.some(d=>d.name==f)||i.push(typeof u=="string"?{name:f}:u)}},o=e.facet(Ie);for(let h of n)if(h.hasResult()){let u=h.result.getMatch;if(h.result.filter===!1)for(let f of h.result.options)s(new og(f,h.source,u?u(f):[],1e9-t.length));else{let f=e.sliceDoc(h.from,h.to),d,p=o.filterStrict?new EL(f):new AL(f);for(let m of h.result.options)if(d=p.match(m.label)){let g=m.displayLabel?u?u(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(s(new og(m,h.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;r||(r=Object.create(null)),r[b]=Math.max(y,r[b]||-1e9)}}}}if(i){let h=Object.create(null),u=0,f=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?r[p.name]-r[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(f))u-=1e5,h[d.name]=u;for(let d of t){let{section:p}=d.completion;p&&(d.score+=h[typeof p=="string"?p:p.name])}}let l=[],a=null,c=o.compareCompletions;for(let h of t.sort((u,f)=>f.score-u.score||c(u.completion,f.completion))){let u=h.completion;!a||a.label!=u.label||a.detail!=u.detail||a.type!=null&&u.type!=null&&a.type!=u.type||a.apply!=u.apply||a.boost!=u.boost?l.push(h):cg(h.completion)>cg(a)&&(l[l.length-1]=h),a=h.completion}return l}class Xi{constructor(e,t,i,r,s,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=r,this.selected=s,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Xi(this.options,hg(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,r,s,o){if(r&&!o&&e.some(c=>c.isPending))return r.setDisabled();let l=LL(e,t);if(!l.length)return r&&e.some(c=>c.isPending)?r.setDisabled():null;let a=t.facet(Ie).selectOnOpen?0:-1;if(r&&r.selected!=a&&r.selected!=-1){let c=r.options[r.selected].completion;for(let h=0;h<l.length;h++)if(l[h].completion==c){a=h;break}}return new Xi(l,hg(i,a),{pos:e.reduce((c,h)=>h.hasResult()?Math.min(c,h.from):c,1e8),create:$L,above:s.aboveCursor},r?r.timestamp:Date.now(),a,!1)}map(e){return new Xi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Xi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class na{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new na(HL,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Ie),s=(i.override||t.languageDataAt("autocomplete",Mi(t)).map(TL)).map(a=>(this.active.find(h=>h.source==a)||new Rt(a,this.active.some(h=>h.state!=0)?1:0)).update(e,i));s.length==this.active.length&&s.every((a,c)=>a==this.active[c])&&(s=this.active);let o=this.open,l=e.effects.some(a=>a.is(If));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||s.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!PL(s,this.active)||l?o=Xi.build(s,t,this.id,o,i,l):o&&o.disabled&&!s.some(a=>a.isPending)&&(o=null),!o&&s.every(a=>!a.isPending)&&s.some(a=>a.hasResult())&&(s=s.map(a=>a.hasResult()?new Rt(a.source,0):a));for(let a of e.effects)a.is(Z1)&&(o=o&&o.setSelected(a.value,this.id));return s==this.active&&o==this.open?this:new na(s,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?BL:zL}}function PL(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let r=t==n.length,s=i==e.length;if(r||s)return r==s;if(n[t++].result!=e[i++].result)return!1}}const BL={"aria-autocomplete":"list"},zL={};function hg(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const HL=[];function Q1(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(Nf);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class Rt{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=Q1(e,t),r=this;(i&8||i&16&&this.touches(e))&&(r=new Rt(r.source,0)),i&4&&r.state==0&&(r=new Rt(this.source,1)),r=r.updateFor(e,i);for(let s of e.effects)if(s.is(ta))r=new Rt(r.source,1,s.value);else if(s.is(Is))r=new Rt(r.source,0);else if(s.is(If))for(let o of s.value)o.source==r.source&&(r=o);return r}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Mi(e.state))}}class lr extends Rt{constructor(e,t,i,r,s,o){super(e,3,t),this.limit=i,this.result=r,this.from=s,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let r=this.result;r.map&&!e.changes.empty&&(r=r.map(r,e.changes));let s=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=Mi(e.state);if(l>o||!r||t&2&&(Mi(e.startState)==this.from||l<this.limit))return new Rt(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return FL(r.validFor,e.state,s,o)?new lr(this.source,this.explicit,a,r,s,o):r.update&&(r=r.update(r,s,o,new Y1(e.state,l,!1)))?new lr(this.source,this.explicit,a,r,r.from,(i=r.to)!==null&&i!==void 0?i:Mi(e.state)):new Rt(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new lr(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Rt(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function FL(n,e,t,i){if(!n)return!1;let r=e.sliceDoc(t,i);return typeof n=="function"?n(r,t,i,e):X1(n,!0).test(r)}const If=Q.define({map(n,e){return n.map(t=>t.map(e))}}),Z1=Q.define(),it=ut.define({create(){return na.start()},update(n,e){return n.update(e)},provide:n=>[Vx.from(n,e=>e.tooltip),B.contentAttributes.from(n,e=>e.attrs)]});function Lf(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(it).active.find(r=>r.source==e.source);return i instanceof lr?(typeof t=="string"?n.dispatch({...ML(n.state,t,i.from,i.to),annotations:Nf.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}const $L=NL(it,Lf);function No(n,e="option"){return t=>{let i=t.state.field(it,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(Ie).interactionDelay)return!1;let r=1,s;e=="page"&&(s=Wx(t,i.open.tooltip))&&(r=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+r*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Z1.of(l)}),!0}}const VL=n=>{let e=n.state.field(it,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(Ie).interactionDelay?!1:Lf(n,e.open.options[e.open.selected])},Bc=n=>n.state.field(it,!1)?(n.dispatch({effects:ta.of(!0)}),!0):!1,WL=n=>{let e=n.state.field(it,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Is.of(null)}),!0)};class jL{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const _L=50,UL=1e3,qL=at.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(it).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(it),t=n.state.facet(Ie);if(!n.selectionSet&&!n.docChanged&&n.startState.field(it)==e)return;let i=n.transactions.some(s=>{let o=Q1(s,t);return o&8||(s.selection||s.docChanged)&&!(o&3)});for(let s=0;s<this.running.length;s++){let o=this.running[s];if(i||o.context.abortOnDocChange&&n.docChanged||o.updates.length+n.transactions.length>_L&&Date.now()-o.time>UL){for(let l of o.context.abortListeners)try{l()}catch(a){xt(this.view.state,a)}o.context.abortListeners=null,this.running.splice(s--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(o=>o.is(ta)))&&(this.pendingStart=!0);let r=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(o=>o.active.source==s.source))?setTimeout(()=>this.startUpdate(),r):-1,this.composing!=0)for(let s of n.transactions)s.isUserEvent("input.type")?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(it);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Mi(e),i=new Y1(e,t,n.explicit,this.view),r=new jL(n,i);this.running.push(r),Promise.resolve(n.source(i)).then(s=>{r.context.aborted||(r.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Is.of(null)}),xt(this.view.state,s)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Ie).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Ie),i=this.view.state.field(it);for(let r=0;r<this.running.length;r++){let s=this.running[r];if(s.done===void 0)continue;if(this.running.splice(r--,1),s.done){let l=Mi(s.updates.length?s.updates[0].startState:this.view.state),a=Math.min(l,s.done.from+(s.active.explicit?0:1)),c=new lr(s.active.source,s.active.explicit,a,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:l);for(let h of s.updates)c=c.update(h,t);if(c.hasResult()){e.push(c);continue}}let o=i.active.find(l=>l.source==s.active.source);if(o&&o.isPending)if(s.done==null){let l=new Rt(s.active.source,0);for(let a of s.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:If.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(it,!1);if(e&&e.tooltip&&this.view.state.facet(Ie).closeOnBlur){let t=e.open&&Wx(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Is.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ta.of(!1)}),20),this.composing=0}}}),KL=typeof navigator=="object"&&/Win/.test(navigator.platform),JL=Fi.highest(B.domEventHandlers({keydown(n,e){let t=e.state.field(it,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(KL&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],r=t.active.find(o=>o.source==i.source),s=i.completion.commitCharacters||r.result.commitCharacters;return s&&s.indexOf(n.key)>-1&&Lf(e,i),!1}})),ew=B.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class GL{constructor(e,t,i,r){this.field=e,this.line=t,this.from=i,this.to=r}}class Pf{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,qe.TrackDel),i=e.mapPos(this.to,1,qe.TrackDel);return t==null||i==null?null:new Pf(this.field,t,i)}}class Bf{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],r=[t],s=e.doc.lineAt(t),o=/^\s*/.exec(s.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let u=0;u<h;u++)c+=e.facet(Ea);r.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Pf(a.field,r[a.line]+a.from,r[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],r=[],s;for(let o of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=s[1]?+s[1]:null,a=s[2]||s[3]||"",c=-1,h=a.replace(/\\[{}]/g,u=>u[1]);for(let u=0;u<t.length;u++)(l!=null?t[u].seq==l:h&&t[u].name==h)&&(c=u);if(c<0){let u=0;for(;u<t.length&&(l==null||t[u].seq!=null&&t[u].seq<l);)u++;t.splice(u,0,{seq:l,name:h}),c=u;for(let f of r)f.field>=c&&f.field++}for(let u of r)if(u.line==i.length&&u.from>s.index){let f=s[2]?3+(s[1]||"").length:2;u.from-=f,u.to-=f}r.push(new GL(c,i.length,s.index,s.index+h.length)),o=o.slice(0,s.index)+a+o.slice(s.index+s[0].length)}o=o.replace(/\\([{}])/g,(l,a,c)=>{for(let h of r)h.line==i.length&&h.from>c&&(h.from--,h.to--);return a}),i.push(o)}return new Bf(i,r)}}let YL=q.widget({widget:new class extends $s{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),XL=q.mark({class:"cm-snippetField"});class Ar{constructor(e,t){this.ranges=e,this.active=t,this.deco=q.set(e.map(i=>(i.from==i.to?YL:XL).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let r=i.map(e);if(!r)return null;t.push(r)}return new Ar(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const qs=Q.define({map(n,e){return n&&n.map(e)}}),QL=Q.define(),Ls=ut.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(qs))return t.value;if(t.is(QL)&&n)return new Ar(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>B.decorations.from(n,e=>e?e.deco:q.none)});function zf(n,e){return T.create(n.filter(t=>t.field==e).map(t=>T.range(t.from,t.to)))}function ZL(n){let e=Bf.parse(n);return(t,i,r,s)=>{let{text:o,ranges:l}=e.instantiate(t.state,r),{main:a}=t.state.selection,c={changes:{from:r,to:s==a.from?a.to:s,insert:ne.of(o)},scrollIntoView:!0,annotations:i?[Nf.of(i),Ce.userEvent.of("input.complete")]:void 0};if(l.length&&(c.selection=zf(l,0)),l.some(h=>h.field>0)){let h=new Ar(l,0),u=c.effects=[qs.of(h)];t.state.field(Ls,!1)===void 0&&u.push(Q.appendConfig.of([Ls,rP,sP,ew]))}t.dispatch(t.state.update(c))}}function tw(n){return({state:e,dispatch:t})=>{let i=e.field(Ls,!1);if(!i||n<0&&i.active==0)return!1;let r=i.active+n,s=n>0&&!i.ranges.some(o=>o.field==r+n);return t(e.update({selection:zf(i.ranges,r),effects:qs.of(s?null:new Ar(i.ranges,r)),scrollIntoView:!0})),!0}}const eP=({state:n,dispatch:e})=>n.field(Ls,!1)?(e(n.update({effects:qs.of(null)})),!0):!1,tP=tw(1),nP=tw(-1),iP=[{key:"Tab",run:tP,shift:nP},{key:"Escape",run:eP}],ug=z.define({combine(n){return n.length?n[0]:iP}}),rP=Fi.highest(Aa.compute([ug],n=>n.facet(ug)));function dB(n,e){return{...e,apply:ZL(n)}}const sP=B.domEventHandlers({mousedown(n,e){let t=e.state.field(Ls,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let r=t.ranges.find(s=>s.from<=i&&s.to>=i);return!r||r.field==t.active?!1:(e.dispatch({selection:zf(t.ranges,r.field),effects:qs.of(t.ranges.some(s=>s.field>r.field)?new Ar(t.ranges,r.field):null),scrollIntoView:!0}),!0)}}),Ps={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},xi=Q.define({map(n,e){let t=e.mapPos(n,-1,qe.TrackAfter);return t??void 0}}),Hf=new class extends ei{};Hf.startSide=1;Hf.endSide=-1;const nw=ut.define({create(){return X.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(xi)&&(n=n.update({add:[Hf.range(t.value,t.value+1)]}));return n}});function oP(){return[aP,nw]}const zc="()[]{}<>«»»«[]{}";function iw(n){for(let e=0;e<zc.length;e+=2)if(zc.charCodeAt(e)==n)return zc.charAt(e+1);return rf(n<128?n:n+1)}function rw(n,e){return n.languageDataAt("closeBrackets",e)[0]||Ps}const lP=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),aP=B.inputHandler.of((n,e,t,i)=>{if((lP?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let r=n.state.selection.main;if(i.length>2||i.length==2&&rn(gt(i,0))==1||e!=r.from||t!=r.to)return!1;let s=uP(n.state,i);return s?(n.dispatch(s),!0):!1}),cP=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=rw(n,n.selection.main.head).brackets||Ps.brackets,r=null,s=n.changeByRange(o=>{if(o.empty){let l=fP(n.doc,o.head);for(let a of i)if(a==l&&Pa(n.doc,o.head)==iw(gt(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:T.cursor(o.head-a.length)}}return{range:r=o}});return r||e(n.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!r},hP=[{key:"Backspace",run:cP}];function uP(n,e){let t=rw(n,n.selection.main.head),i=t.brackets||Ps.brackets;for(let r of i){let s=iw(gt(r,0));if(e==r)return s==r?mP(n,r,i.indexOf(r+r+r)>-1,t):dP(n,r,s,t.before||Ps.before);if(e==s&&sw(n,n.selection.main.from))return pP(n,r,s)}return null}function sw(n,e){let t=!1;return n.field(nw).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Pa(n,e){let t=n.sliceString(e,e+2);return t.slice(0,rn(gt(t,0)))}function fP(n,e){let t=n.sliceString(e-2,e);return rn(gt(t,0))==t.length?t:t.slice(1)}function dP(n,e,t,i){let r=null,s=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:xi.of(o.to+e.length),range:T.range(o.anchor+e.length,o.head+e.length)};let l=Pa(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:xi.of(o.head+e.length),range:T.cursor(o.head+e.length)}:{range:r=o}});return r?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function pP(n,e,t){let i=null,r=n.changeByRange(s=>s.empty&&Pa(n.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:T.cursor(s.head+t.length)}:i={range:s});return i?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function mP(n,e,t,i){let r=i.stringPrefixes||Ps.stringPrefixes,s=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:xi.of(l.to+e.length),range:T.range(l.anchor+e.length,l.head+e.length)};let a=l.head,c=Pa(n.doc,a),h;if(c==e){if(fg(n,a))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(sw(n,a)){let f=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+f.length,insert:f},range:T.cursor(a+f.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(h=dg(n,a-2*e.length,r))>-1&&fg(n,h))return{changes:{insert:e+e+e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)};if(n.charCategorizer(a)(c)!=ge.Word&&dg(n,a,r)>-1&&!gP(n,a,e,r))return{changes:{insert:e+e,from:a},effects:xi.of(a+e.length),range:T.cursor(a+e.length)}}return{range:s=l}});return s?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fg(n,e){let t=ht(n).resolveInner(e+1);return t.parent&&t.from==e}function gP(n,e,t,i){let r=ht(n).resolveInner(e,-1),s=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(r.from,Math.min(r.to,r.from+t.length+s)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=r.firstChild;for(;h&&h.from==r.from&&h.to-h.from>t.length+a;){if(n.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let c=r.to==e&&r.parent;if(!c)break;r=c}return!1}function dg(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=ge.Word)return e;for(let r of t){let s=e-r.length;if(n.sliceDoc(s,e)==r&&i(n.sliceDoc(s-1,s))!=ge.Word)return s}return-1}function yP(n={}){return[JL,it,Ie.of(n),qL,xP,ew]}const bP=[{key:"Ctrl-Space",run:Bc},{mac:"Alt-`",run:Bc},{mac:"Alt-i",run:Bc},{key:"Escape",run:WL},{key:"ArrowDown",run:No(!0)},{key:"ArrowUp",run:No(!1)},{key:"PageDown",run:No(!0,"page")},{key:"PageUp",run:No(!1,"page")},{key:"Enter",run:VL}],xP=Fi.highest(Aa.computeN([Ie],n=>n.facet(Ie).defaultKeymap?[bP]:[])),ow="cm-adf-readonly",lw={"&":{backgroundColor:"var(--paper)",color:"var(--ink)"},[`&.${ow}`]:{backgroundColor:"var(--paper-sunken)"},".cm-content":{caretColor:"var(--ink)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--ink)"},".cm-content ::selection, &.cm-focused .cm-selectionBackground, .cm-selectionBackground":{backgroundColor:"var(--selection) !important"},".cm-gutters":{backgroundColor:"transparent",color:"var(--ink-faint)",border:"none"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--ink) 4%, transparent)"},".cm-activeLineGutter":{backgroundColor:"transparent",color:"var(--ink)"},".cm-selectionMatch":{backgroundColor:"var(--tint)"},"&.cm-focused .cm-matchingBracket":{backgroundColor:"var(--tint)",outline:"1px solid var(--rule-strong)"},"&.cm-focused .cm-nonmatchingBracket":{color:"var(--status-deprecated)"},".cm-searchMatch":{backgroundColor:"var(--status-draft-bg)",outline:"1px solid var(--rule-strong)"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"var(--selection)"},".cm-foldPlaceholder":{backgroundColor:"var(--paper-sunken)",border:"1px solid var(--rule)",color:"var(--ink-faint)"},".cm-panels":{backgroundColor:"var(--paper-raised)",color:"var(--ink)"},".cm-panels.cm-panels-top":{borderBottom:"1px solid var(--rule)"},".cm-panels.cm-panels-bottom":{borderTop:"1px solid var(--rule)"},".cm-tooltip":{backgroundColor:"var(--paper-raised)",color:"var(--ink)",border:"1px solid var(--rule-strong)",borderRadius:"3px"},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--tint)",color:"var(--ink)"}},wP={fg:"#24292e",comment:"#6a737d",keyword:"#d73a49",string:"#032f62",constant:"#005cc5",entity:"#6f42c1",tag:"#22863a",variable:"#e36209",regexp:"#22863a",invalid:"#b31d28",inserted:"#22863a",deleted:"#b31d28",heading:"#005cc5"},kP={fg:"#adbac7",comment:"#768390",keyword:"#f47067",string:"#96d0ff",constant:"#6cb6ff",entity:"#dcbdfb",tag:"#8ddb8c",variable:"#f69d50",regexp:"#8ddb8c",invalid:"#ff938a",inserted:"#8ddb8c",deleted:"#ff938a",heading:"#6cb6ff"};function aw(n){return Ra.define([{tag:[O.comment,O.lineComment,O.blockComment,O.docComment],color:n.comment},{tag:[O.keyword,O.operatorKeyword,O.controlKeyword,O.definitionKeyword,O.moduleKeyword,O.modifier,O.operator,O.self],color:n.keyword},{tag:[O.string,O.special(O.string),O.character,O.docString],color:n.string},{tag:[O.regexp,O.escape],color:n.regexp},{tag:[O.number,O.integer,O.float,O.bool,O.null,O.atom,O.unit,O.constant(O.name),O.standard(O.name),O.propertyName,O.meta,O.processingInstruction],color:n.constant},{tag:[O.function(O.variableName),O.function(O.propertyName),O.definition(O.function(O.variableName)),O.typeName,O.className,O.namespace,O.attributeName,O.macroName],color:n.entity},{tag:[O.tagName,O.angleBracket],color:n.tag},{tag:[O.definition(O.variableName),O.labelName],color:n.variable},{tag:[O.variableName,O.punctuation,O.bracket,O.content],color:n.fg},{tag:O.heading,color:n.heading,fontWeight:"600"},{tag:O.strong,fontWeight:"600"},{tag:O.emphasis,fontStyle:"italic"},{tag:O.strikethrough,textDecoration:"line-through"},{tag:[O.link,O.url],color:n.string,textDecoration:"underline"},{tag:O.inserted,color:n.inserted},{tag:O.deleted,color:n.deleted},{tag:O.changed,color:n.variable},{tag:O.invalid,color:n.invalid}])}const pg=[B.theme(lw,{dark:!1}),r1(aw(wP))],mg=[B.theme(lw,{dark:!0}),r1(aw(kP))],vP=B.editorAttributes.of({class:ow}),SP={js:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript()),jsx:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0})),ts:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({typescript:!0})),tsx:()=>tt(()=>import("./index-KNnHrO8-.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.javascript({jsx:!0,typescript:!0})),py:()=>tt(()=>import("./index-B5FYMbFc.js"),__vite__mapDeps([15,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.python()),html:()=>tt(()=>import("./index-DBFkrLao.js"),__vite__mapDeps([16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.html()),css:()=>tt(()=>import("./index-nM_Q5x7Q.js"),__vite__mapDeps([17,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.css()),json:()=>tt(()=>import("./index-DS9H-PJI.js"),__vite__mapDeps([18,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.json()),yaml:()=>tt(()=>import("./index-B5Eot_tL.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),yml:()=>tt(()=>import("./index-B5Eot_tL.js"),__vite__mapDeps([19,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.yaml()),sql:()=>tt(()=>import("./index-BQIEMvvt.js"),__vite__mapDeps([20,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.sql()),xml:()=>tt(()=>import("./index-Ca6bEWGu.js"),__vite__mapDeps([21,1,2,3,4,5,6,7,8,9,10,11,12,13,14])).then(n=>n.xml()),md:()=>tt(()=>import("./index-DkhbLs9K.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown()),markdown:()=>tt(()=>import("./index-DkhbLs9K.js"),__vite__mapDeps([22,16,1,17,2,3,4,5,6,7,8,9,10,11,12,13,14,0])).then(n=>n.markdown())};async function CP(n){const e=SP[n];return e?e():null}const MP=250;function gg(n){return n?[ee.readOnly.of(!0),vP]:ee.readOnly.of(!1)}function cw({filePath:n,content:e,onChange:t,readOnly:i,lineWrap:r=!0,flushRef:s}){const o=M.useRef(null),l=M.useRef(null),a=M.useRef(new Jn),c=M.useRef(new Jn),h=M.useRef(new Jn),u=M.useRef(new Jn),f=M.useRef(!1),d=M.useRef(t);d.current=t;const p=tn(k=>k.theme),m=M.useRef(null),g=M.useRef(!1),y=M.useRef(null),b=M.useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null,g.current=!1},[]),x=M.useCallback(()=>{if(m.current&&clearTimeout(m.current),m.current=null,!g.current)return;g.current=!1;const k=l.current;if(!k)return;const w=k.state.doc.toString();y.current=w,d.current(w)},[]);return M.useEffect(()=>{if(s)return s.current=x,()=>{s.current=null}},[s,x]),M.useEffect(()=>{if(!o.current)return;const k=p==="dark"||p==="system"&&window.matchMedia("(prefers-color-scheme: dark)").matches,w=ee.create({doc:e,extensions:[DN(),pN(),LN(),_I(),EI(),bI(),oP(),yP(),Q2(),Aa.of([...q2,...ZI,...xL,...hP,K2]),a.current.of(k?mg:pg),c.current.of([]),h.current.of(gg(!!i)),u.current.of(r?B.lineWrapping:[]),B.updateListener.of(L=>{!L.docChanged||f.current||(g.current=!0,m.current&&clearTimeout(m.current),m.current=setTimeout(x,MP))})]}),C=new B({state:w,parent:o.current});l.current=C;let v=!1;y.current=e;const D=n.split(".").pop()?.toLowerCase()??"";return CP(D).then(L=>{L&&!v&&C.dispatch({effects:c.current.reconfigure(L)})}),()=>{x(),v=!0,C.destroy(),l.current=null}},[n]),M.useEffect(()=>{const k=l.current;k&&e!==y.current&&(y.current=e,b(),f.current=!0,k.dispatch({changes:{from:0,to:k.state.doc.length,insert:e}}),f.current=!1)},[e,b]),M.useEffect(()=>{const k=l.current;if(!k)return;const w=C=>{l.current===k&&k.dispatch({effects:a.current.reconfigure(C?mg:pg)})};if(p==="system"){const C=window.matchMedia("(prefers-color-scheme: dark)");w(C.matches);const v=D=>{l.current===k&&w(D.matches)};return C.addEventListener("change",v),()=>C.removeEventListener("change",v)}else w(p==="dark")},[p,n]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:h.current.reconfigure(gg(!!i))})},[i]),M.useEffect(()=>{const k=l.current;k&&k.dispatch({effects:u.current.reconfigure(r?B.lineWrapping:[])})},[r]),S.jsx("div",{ref:o,className:"cm-editor-container"})}const Hc=!1,uu=128e3,TP=512e3,AP=250;function EP({content:n,onChange:e,active:t,onEditorChange:i,flushRef:r,shouldGate:s,onRendered:o}){const l=M.useRef(n);l.current=n;const a=M.useRef(e);a.current=e;const c=M.useRef(o);c.current=o;const[h]=M.useState(()=>l.current.length>uu),u=M.useRef(!1),f=M.useRef(!1),d=M.useRef(null),p=M.useRef(null),m=M.useRef(null),g=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null,m.current=null},[]),y=M.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=null;const k=m.current;m.current=null,k?.()},[]);M.useEffect(()=>(r.current=y,()=>{r.current=null,y()}),[r,y]);const b=M.useCallback((k,w)=>{const C=w.replace(/adf-file:\/\/([^\s)>"'\]]+(?:\s[^\s)>"'\]]+)*)/g,(v,D)=>"adf-file://"+D.replace(/ /g,"%20"));try{k.commands.setContent(C,{contentType:"markdown"});const v=k.getHTML()}catch(v){console.error("[MarkdownEditor] setContent failed:",v);try{const D=w.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/\n/g,"<br>");k.commands.setContent(D)}catch(D){console.error("[MarkdownEditor] All setContent methods failed:",D)}}},[]),x=HA({immediatelyRender:!h,extensions:nR(),content:"",onCreate:({editor:k})=>{const w=l.current;w&&(d.current=w,f.current=!0,b(k,w),f.current=!1),c.current()},onUpdate:({editor:k})=>{f.current||(m.current=()=>{if(k.isDestroyed)return;const w=k.getMarkdown();d.current=w,a.current(w)},p.current&&clearTimeout(p.current),p.current=setTimeout(y,AP))},editorProps:{attributes:{class:"tiptap"}}});return M.useEffect(()=>(i(x),()=>i(null)),[x,i]),M.useEffect(()=>{if(!t||!x||x.isDestroyed||n===d.current||s(n))return;d.current=n,g(),u.current=!0;const k=setTimeout(()=>{if(u.current=!1,x.isDestroyed)return;const w=performance.now();f.current=!0,b(x,n||""),f.current=!1,console.log(`[PERF:renderer] MarkdownEditor.setContent: ${(performance.now()-w).toFixed(1)}ms (chars=${n?.length??0})`),c.current()},0);return()=>{u.current=!1,clearTimeout(k)}},[n,t,x,b,g,s]),M.useEffect(()=>{t&&x&&!x.isDestroyed&&!u.current&&o()}),S.jsx(Xy,{editor:x})}function OP({filePath:n,content:e,onChange:t,flushRef:i}){const r=e||"",s=r.length>uu,[o,l]=M.useState(s),[a,c]=M.useState(!s),[h,u]=M.useState(null),[f,d]=M.useState(!1),[p,m]=M.useState(!1),g=M.useRef(null),y=M.useRef(null);M.useEffect(()=>{if(i)return i.current=()=>{g.current?.(),y.current?.()},()=>{i.current=null}},[i]);const b=M.useRef(!1),x=M.useRef(t);x.current=t;const k=M.useCallback(L=>{L&&(b.current=!0,d(!0)),m(!1),c(!0),l(!1)},[]),w=M.useCallback(()=>{if(g.current?.(),y.current?.(),!o){m(!1),l(!0);return}if(r.length>TP){m(!0);return}k(s)},[o,r.length,s,k]),C=M.useCallback(L=>{x.current(L)},[]),v=M.useCallback(L=>L.length<=uu?!1:b.current?(b.current=!1,!1):(l(!0),d(!1),!0),[]),D=M.useCallback(()=>d(!1),[]);return S.jsxs("div",{className:"h-full flex flex-col bg-white dark:bg-neutral-900",children:[S.jsx(iR,{editor:h,rawMode:o,onToggleRawMode:w}),f&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-blue-600 dark:text-blue-300 border-b border-neutral-200 dark:border-neutral-700 bg-blue-50 dark:bg-blue-900/30",children:["Rendering rich text (",Math.round(r.length/1024).toLocaleString()," KB) — the window will be unresponsive until it finishes."]}),p&&S.jsxs("div",{className:"flex items-center gap-2 px-4 py-1 text-[11px] text-neutral-600 dark:text-neutral-300 border-b border-neutral-200 dark:border-neutral-700 bg-amber-50 dark:bg-amber-900/20",children:[S.jsxs("span",{children:["Rendering ",Math.round(r.length/1024).toLocaleString()," KB as rich text will freeze the window for tens of seconds."]}),S.jsx("button",{onClick:()=>k(!0),className:"px-1.5 py-0.5 rounded border border-neutral-300 dark:border-neutral-600 hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Render anyway"}),S.jsx("button",{onClick:()=>m(!1),className:"px-1.5 py-0.5 rounded border border-transparent hover:bg-neutral-100 dark:hover:bg-neutral-700",children:"Cancel"})]}),s&&o&&!f&&!p&&S.jsxs("div",{className:"px-4 py-1 text-[11px] text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/50",children:["Large file (",Math.round(r.length/1024).toLocaleString()," KB) — showing source. Rich text would take tens of seconds to render."]}),S.jsxs("div",{className:o?"flex-1 overflow-hidden":"flex-1 overflow-y-auto",children:[o&&S.jsx(cw,{filePath:n,content:r,onChange:C,flushRef:y}),a&&S.jsx("div",{className:o?"hidden":void 0,children:S.jsx(EP,{content:r,onChange:C,active:!o,onEditorChange:u,flushRef:g,shouldGate:v,onRendered:D})})]})]})}function RP({filePath:n}){const e=n.split("/").pop()??n;return S.jsxs("div",{className:"h-full flex flex-col items-center justify-center gap-3 text-[var(--adf-ui-text-subtle)]",children:[S.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[S.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),S.jsx("polyline",{points:"14 2 14 8 20 8"})]}),S.jsx("span",{className:"text-sm font-medium text-neutral-500 dark:text-neutral-400",children:e}),S.jsx("span",{className:"text-xs",children:"Binary file cannot be edited"})]})}function DP(n){return window.adfApi?.platform==="web"?S.jsx("div",{className:"flex h-full items-center justify-center p-8 text-center text-sm text-[var(--adf-ui-text-muted)]",children:"The live Computer view is available in the desktop app. Your agent’s computer continues running on the daemon."}):S.jsx(NP,{...n})}function NP({meta:n,reloadNonce:e}){const[t,i]=M.useState(()=>({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort})),r=M.useCallback(async()=>{const o=await Qi()?.getBrowserSessionInfo({agentName:n.agentName,agentId:n.agentId});o&&i({phase:o.phase,detail:o.detail,hostPort:o.hostPort})},[n.agentName,n.agentId]);M.useEffect(()=>{i({phase:n.phase??(n.hostPort!=null?"ready":"absent"),detail:n.detail,hostPort:n.hostPort}),n.phase==="ready"&&n.hostPort==null&&r()},[n.phase,n.detail,n.hostPort,r]);const s=Pw();return M.useEffect(()=>{if(Qi()?.onContainerPhase)return Qi().onContainerPhase(o=>{o.containerName===n.containerName&&(o.phase==="ready"?(i(l=>({...l,phase:"ready",detail:void 0})),r()):i({phase:o.phase,detail:o.detail,hostPort:null}))})},[n.containerName,r,s]),t.phase==="ready"&&t.hostPort!=null?S.jsx(IP,{hostPort:t.hostPort,reloadNonce:e}):S.jsx(LP,{agentName:n.agentName,state:t,onRetry:r})}function IP({hostPort:n,reloadNonce:e}){const t=tn(o=>o.computerMatchTab),i=M.useRef(null),r=M.useRef(!1),s=`http://127.0.0.1:${n}/vnc.html?autoconnect=1&resize=${t?"remote":"scale"}&reconnect=1&reconnect_delay=2000&quality=9&compression=0`;return M.useEffect(()=>{const o=i.current;if(!o)return;r.current=!1;const l=()=>{r.current=!0};return o.addEventListener("dom-ready",l),()=>{r.current=!1,o.removeEventListener("dom-ready",l)}},[n]),M.useEffect(()=>{e&&r.current&&i.current?.reload()},[e]),S.jsx("webview",{ref:i,src:s,partition:"agent-browser",className:"h-full w-full"},n)}function LP({agentName:n,state:e,onRetry:t}){const i=tn(h=>h.openSettingsAt),{phase:r,detail:s}=e,o=r==="provisioning"||r==="starting",l=r==="failed",a=l?`${n}'s computer could not be set up`:r==="provisioning"?`Setting up ${n}'s computer`:r==="starting"?`Starting ${n}'s computer`:r==="stopped"?`${n}'s computer is stopped`:r==="ready"?`${n}'s display is not up yet`:`${n} has no computer yet`,c=l?"Nothing is left of the container. Rebuild it from Settings › Compute; the error is shown there too.":r==="provisioning"?`${s??"Installing packages"}. This takes a minute or two on first setup; the desktop appears here when it is ready.`:r==="starting"?"The container is starting; the desktop appears here in a few seconds.":r==="stopped"?"The container starts with the agent. Start the agent, or start the container from Settings › Compute.":r==="ready"?s??"The container is running but its display did not answer yet.":"The container is created the first time the agent starts.";return S.jsx("div",{className:"flex h-full w-full items-center justify-center bg-[var(--adf-ui-canvas)] p-6",children:S.jsxs("div",{className:"max-w-md text-center",children:[S.jsx("div",{className:`mx-auto mb-4 flex size-10 items-center justify-center rounded-full ${l?"bg-[var(--adf-ui-danger-subtle)] text-[var(--adf-ui-danger)]":"bg-[var(--adf-ui-surface)] text-[var(--adf-ui-text-muted)]"} ${o?"animate-pulse":""}`,children:S.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7","aria-hidden":"true",children:[S.jsx("path",{d:"m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"}),S.jsx("path",{d:"m4.5 7.7 7.5 4.2 7.5-4.2M12 12v9"})]})}),S.jsx("h3",{className:"text-sm font-semibold text-[var(--adf-ui-text)]",children:a}),S.jsx("p",{className:"mt-2 text-[12px] text-[var(--adf-ui-text-muted)]",children:c}),l&&s&&S.jsx("p",{className:"mt-3 rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-danger-subtle)] p-3 text-left font-mono text-[10px] text-[var(--adf-ui-text)] break-words",children:s}),S.jsxs("div",{className:"mt-4 flex justify-center gap-2",children:[(l||r==="stopped")&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] bg-[var(--adf-ui-accent)] px-3 py-1.5 text-[11px] font-medium text-[var(--adf-ui-on-accent)] hover:bg-[var(--adf-ui-accent-hover)]",onClick:()=>i("compute"),children:"Open Settings › Compute"}),!o&&S.jsx("button",{className:"rounded-[var(--adf-ui-control-radius)] border border-[var(--adf-ui-border)] px-3 py-1.5 text-[11px] text-[var(--adf-ui-text)] hover:bg-[var(--adf-ui-surface-hover)]",onClick:t,children:"Check again"})]})]})})}const PP=new Set(["md","markdown"]),yg="adf-editor-line-wrap";function BP(n,e,t){const[i,r]=M.useState(!1),s=M.useRef(0);return M.useEffect(()=>{s.current=$f(Vf.getState()),r(!1)},[t,e,n]),M.useEffect(()=>{if(!(!n||e||i))return Vf.subscribe(o=>{$f(o)!==s.current&&r(!0)})},[n,e,i]),i}function zP(){const n=ve(E=>E.tabs),e=ve(E=>E.activeTabPath),t=ve(E=>E.setActiveTab),i=ve(E=>E.closeTab),r=ve(E=>E.updateTabContent),s=ve(E=>E.reloadBrowserTab),o=ve(E=>E.conflictFocusSeq),l=tn(uw),a=tn(E=>E.centerChatTabActive),c=tn(E=>E.setCenterChatTabActive),h=dt(E=>E.filePath),u=dt(E=>E.viewGeneration),f=dt(E=>E.runtimeId),d=l&&a,p=BP(l,d,h),m=M.useCallback(E=>{c(!1),t(E)},[t,c]),g=tn(E=>E.setChatPlacement),y=l?{active:a,unread:p,onSelect:()=>c(!0),onClose:()=>g("side")}:void 0;M.useEffect(()=>ve.subscribe((E,V)=>{E.activeTabPath&&E.activeTabPath!==V.activeTabPath&&E.tabs.length>=V.tabs.length&&!Ba()&&tn.getState().setCenterChatTabActive(!1)}),[]);const b=n.find(E=>E.path===e)??null,x=M.useRef(null),k=M.useRef(null),w=M.useRef(null),[C,v]=M.useState(()=>localStorage.getItem(yg)!=="0"),D=M.useCallback(()=>{v(E=>(localStorage.setItem(yg,E?"0":"1"),!E))},[]),L=M.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=null,k.current=null},[]),J=M.useCallback((E,V)=>{if(x.current&&clearTimeout(x.current),Ba()){k.current=null,x.current=null;return}const F=dt.getState().filePath,ie=yw(),Re=k.current,Pt=Re&&Re.path===E&&Re.owner===F?Re.base:bw(E);k.current={path:E,content:V,owner:F,base:Pt,view:ie},x.current=setTimeout(()=>{k.current=null,x.current=null,j(E,V,F,Pt,ie)},300)},[]),j=M.useCallback((E,V,F,ie,Re)=>xw(E,V,F,ie,Re),[]);M.useEffect(()=>ww(()=>{w.current?.();const E=k.current;if(x.current&&clearTimeout(x.current),x.current=null,k.current=null,E)return j(E.path,E.content,E.owner,E.base,E.view);const V=ve.getState(),F=V.tabs.find(ie=>ie.path===V.activeTabPath);if(F&&F.kind==="file"&&F.isDirty&&!F.conflict)return j(F.path,F.content,dt.getState().filePath)}),[j]),M.useEffect(()=>{kw()},[u,f]);const $=M.useCallback(E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(V?.conflict&&!vw([E]))return;const F=k.current;F?.path===E&&(x.current&&clearTimeout(x.current),x.current=null,k.current=null,V?.conflict||j(F.path,F.content,F.owner,F.base,F.view)),i(E)},[i,j]),te=M.useCallback(async E=>{const V=ve.getState().tabs.find(ie=>ie.path===E);if(!V?.conflict)return;let F;if(V.conflict.content===null){const ie=E==="README.md"?await Qi()?.getDocument():await Qi()?.readInternalFile(E);if(ie?.content==null)return;F={content:ie.content,revision:ie.revision}}if(ve.getState().resolveTabConflict(E,"reload",F),E==="README.md"){const ie=ve.getState().tabs.find(Re=>Re.path===E)?.content;ie!==void 0&&dt.getState().setDocumentContent(ie)}},[]),G=M.useCallback(E=>{const V=ve.getState();V.resolveTabConflict(E,"keep");const F=V.tabs.find(ie=>ie.path===E)?.content;F!==void 0&&(E==="README.md"&&dt.getState().setDocumentContent(F),j(E,F,dt.getState().filePath))},[j]),Z=M.useCallback(E=>{const V=ve.getState().undoExternalReplace(E);V!==null&&(E==="README.md"&&dt.getState().setDocumentContent(V),j(E,V,dt.getState().filePath))},[j]),Oe=M.useCallback((E,V)=>{Ba()||(r(E,V),E==="README.md"&&dt.getState().setDocumentContent(V),J(E,V))},[r,J]);M.useEffect(()=>dt.subscribe((V,F)=>{if(V.documentContent!==F.documentContent){const ie=ve.getState(),Re=ie.tabs.find(Pt=>Pt.path==="README.md");if(Re&&Re.content!==V.documentContent){const Pt=V.documentRevision!==F.documentRevision?{revision:V.documentRevision,writer:V.documentWriter}:void 0;ie.updateTabFromExternal("README.md",V.documentContent,Pt)}}}),[]);const ft=M.useCallback(async()=>{const E=ve.getState();for(const V of Sw){if(V==="README.md"){const F=dt.getState();E.openTab("README.md",F.documentContent,!1,void 0,F.documentRevision);continue}try{const F=await Qi()?.readInternalFile(V);F?.content!=null&&E.openTab(V,F.binary?"":F.content,F.binary,F.mimeType,F.revision)}catch{}}E.setActiveTab("README.md")},[]);if(M.useEffect(()=>ve.subscribe((E,V)=>{const F=E.lastExternalWrite;!F||F===V.lastExternalWrite||k.current?.path===F.path&&L()}),[L]),M.useEffect(()=>()=>{x.current&&clearTimeout(x.current);const E=k.current;k.current=null,E&&j(E.path,E.content,E.owner,E.base,E.view)},[j]),M.useEffect(()=>ve.subscribe(E=>{const V=Cw();V&&Mw(V,E.tabs.filter(F=>F.kind==="file").map(F=>F.path),E.activeTabPath)}),[]),d)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:null,onSelect:m,onClose:$,onReload:s,chatTab:y}),S.jsx("div",{className:"flex-1 min-h-0",children:S.jsx(Tw,{},`center:${h??""}`)})]});if(!b)return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,chatTab:y}),S.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-3",children:[S.jsx("span",{className:"text-[var(--adf-ui-text-subtle)] text-sm",children:"No file open"}),S.jsx("button",{onClick:ft,className:"px-3 py-1.5 text-xs font-medium rounded-md border border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800",children:"Open core files"})]})]});const $i=PP.has(b.extension),Kt=b.kind==="file"&&b.isBinary?Aw(b.path,b.mimeType):null,Ks=b.kind==="file"&&!b.isBinary;return S.jsxs("div",{className:"h-full flex flex-col",children:[S.jsx(za,{tabs:n,activeTabPath:e,onSelect:m,onClose:$,onReload:s,chatTab:y}),b.conflict&&S.jsx(Ew,{what:b.path,writer:b.conflict.writer,focusSeq:o,onReload:()=>{te(b.path)},onKeep:()=>G(b.path),mine:b.content,theirs:b.conflict.content}),!b.conflict&&b.replaced&&S.jsx(Ow,{writer:b.replaced.writer,seq:b.replaced.seq,onUndo:()=>Z(b.path),onDismiss:()=>ve.getState().dismissExternalReplace(b.path)}),S.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[b.kind==="browser"&&b.browserMeta?S.jsx(DP,{meta:b.browserMeta,reloadNonce:b.browserMeta.reloadNonce},b.path):Kt?S.jsx(Rw,{filePath:b.path,mime:Kt},b.path):b.isBinary?S.jsx(RP,{filePath:b.path}):$i?S.jsx(OP,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E)},b.path):S.jsxs("div",{className:"relative h-full",children:[S.jsx(cw,{filePath:b.path,content:b.content,flushRef:w,onChange:E=>Oe(b.path,E),lineWrap:C},b.path),S.jsx("button",{onClick:D,title:C?"Line wrap on — click to disable":"Line wrap off — click to enable","aria-pressed":C,className:`absolute top-1.5 right-4 z-10 px-1.5 py-0.5 rounded text-[10px] font-mono font-medium border transition-colors ${C?"bg-blue-50 dark:bg-blue-900/40 border-blue-300 dark:border-blue-700 text-blue-600 dark:text-blue-300":"bg-white/80 dark:bg-neutral-800/80 border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)] hover:text-neutral-600 dark:hover:text-neutral-300"}`,children:"wrap"})]}),Ks&&S.jsxs("div",{"aria-label":`${b.content.length.toLocaleString()} characters — token count is an estimate`,className:"pointer-events-none absolute bottom-1.5 right-4 z-10 select-none px-1.5 py-0.5 rounded text-[10px] font-mono bg-white/80 dark:bg-neutral-800/80 border border-neutral-200 dark:border-neutral-700 text-[var(--adf-ui-text-subtle)]",children:["~",Dw(Nw(b.content))," tokens"]})]})]})}const pB=Object.freeze(Object.defineProperty({__proto__:null,EditorPanel:zP},Symbol.toStringTag,{value:"Module"}));export{Ea as A,cB as B,Y1 as C,PN as D,B as E,ee as F,Yi as G,t1 as H,le as I,Kl as J,pB as K,nu as L,Jx as N,WN as P,Me as T,ct as a,Y as b,sB as c,aB as d,fB as e,hB as f,CL as g,ht as h,hI as i,T as j,lB as k,oB as l,uB as m,oI as n,dB as o,sI as p,nB as q,iB as r,eI as s,O as t,OI as u,Mt as v,ka as w,Fi as x,Aa as y,Vt as z};