@panphora/clayjs 1.20.0 → 1.22.0

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 (130) hide show
  1. package/dist/all.js +1 -1
  2. package/dist/clay-dom.js +1 -1
  3. package/dist/clay-events.js +1 -1
  4. package/dist/clay-internals.js +1 -1
  5. package/dist/clay-options.js +1 -1
  6. package/dist/clay-router.js +1 -1
  7. package/dist/clay-ui.js +1 -1
  8. package/dist/clay-utils.js +1 -1
  9. package/dist/clay.js +1 -1
  10. package/dist/clay.standalone.js +7865 -8022
  11. package/dist/m/{c-JOH753EJ.js → c-26KVJS6J.js} +1 -1
  12. package/dist/m/{c-ZE46QDIH.js → c-3TLG3OLG.js} +1 -1
  13. package/dist/m/{c-RT3C74GY.js → c-4OGEVKR3.js} +1 -1
  14. package/dist/m/{c-Y33LUUIQ.js → c-4PHDUV3H.js} +1 -1
  15. package/dist/m/{c-SJPD46ZO.js → c-4RFZROCF.js} +4 -4
  16. package/dist/m/{c-XQSXKIKM.js → c-4TWARTLS.js} +1 -1
  17. package/dist/m/{c-S5IEIZCN.js → c-5AQYL27I.js} +1 -1
  18. package/dist/m/{c-OJYM642Q.js → c-5FKRZNJV.js} +1 -1
  19. package/dist/m/{c-CJFDLD43.js → c-6KBKYLPO.js} +1 -1
  20. package/dist/m/{c-DHXPDLW6.js → c-6PBXRWDX.js} +1 -1
  21. package/dist/m/{c-BRLCTNMC.js → c-6RC66MYY.js} +1 -1
  22. package/dist/m/{c-PIVIYLTY.js → c-6UEFPHHE.js} +1 -1
  23. package/dist/m/{c-YQUJ74R3.js → c-BV6FQQXM.js} +1 -1
  24. package/dist/m/{c-YSB6JKV2.js → c-DEAFCHDO.js} +2 -2
  25. package/dist/m/{c-NLZ5AN4L.js → c-DKFSOJCV.js} +1 -1
  26. package/dist/m/c-DP4X4JID.js +1 -0
  27. package/dist/m/{c-LIBE4HPD.js → c-DZBZ57EE.js} +1 -1
  28. package/dist/m/c-ECY5AZMH.js +1 -0
  29. package/dist/m/{c-VAK7SG37.js → c-EUGJVHDD.js} +1 -1
  30. package/dist/m/{c-GPGYKER7.js → c-F5AER2ID.js} +1 -1
  31. package/dist/m/{c-RG6XUZFA.js → c-FAXQU7MQ.js} +1 -1
  32. package/dist/m/{c-XD5MOROJ.js → c-FLBUYV3P.js} +1 -1
  33. package/dist/m/{c-NFR673TL.js → c-FMCPQ4VT.js} +2 -2
  34. package/dist/m/{c-VBLFAQD2.js → c-FNIGX4FI.js} +1 -1
  35. package/dist/m/{c-BTLFLLML.js → c-FWFJUU3T.js} +1 -1
  36. package/dist/m/{c-2VB555FG.js → c-GPTKI7AQ.js} +1 -1
  37. package/dist/m/{c-EZ7B5AZT.js → c-GY4ODHO2.js} +1 -1
  38. package/dist/m/{c-5734MF2P.js → c-H6DXQEH2.js} +1 -1
  39. package/dist/m/{c-Z32V4MHK.js → c-HAVGDXAL.js} +1 -1
  40. package/dist/m/{c-D3E4WJ4M.js → c-HDWZEJHM.js} +49 -32
  41. package/dist/m/{c-W23KVGUO.js → c-HWR6GMGK.js} +1 -1
  42. package/dist/m/{c-BJ7YQ5QZ.js → c-IHUWUKIU.js} +1 -1
  43. package/dist/m/{c-AL4RBJF2.js → c-ILGQ3UXQ.js} +1 -1
  44. package/dist/m/{c-W3K23S72.js → c-IWTTOC2V.js} +1 -1
  45. package/dist/m/c-JFST6QE7.js +1 -0
  46. package/dist/m/{c-FNVQAACK.js → c-KE33W4RE.js} +1 -1
  47. package/dist/m/c-KV7R47FR.js +1 -0
  48. package/dist/m/{c-LPUJXRXW.js → c-L7K5EXU2.js} +1 -1
  49. package/dist/m/{c-3YH6JSIL.js → c-LF6HNVPU.js} +1 -1
  50. package/dist/m/{c-MIL4B2JQ.js → c-MRURHLKV.js} +1 -1
  51. package/dist/m/{c-LQU7TXIH.js → c-N33TPVTL.js} +1 -1
  52. package/dist/m/{c-EOCZ2YVL.js → c-NBNRLZXO.js} +1 -1
  53. package/dist/m/{c-JUE7B4OX.js → c-NLWEZYKJ.js} +1 -1
  54. package/dist/m/{c-DDDOKPI6.js → c-NNNR7OXA.js} +1 -1
  55. package/dist/m/{c-E4IBSAQM.js → c-OI2BYWVV.js} +1 -1
  56. package/dist/m/{c-SBSMJIPC.js → c-P3WATEDR.js} +1 -1
  57. package/dist/m/{c-ZJLU56DV.js → c-PCEMXY2K.js} +1 -1
  58. package/dist/m/{c-3GJ4XARY.js → c-PWBJVHA4.js} +1 -1
  59. package/dist/m/{c-67ILSNPR.js → c-Q5KAQJAG.js} +1 -1
  60. package/dist/m/{c-U5X57T4L.js → c-QHVCUTJV.js} +1 -1
  61. package/dist/m/{c-GKEATME6.js → c-QJFYVCJO.js} +1 -1
  62. package/dist/m/{c-VY6XRBOW.js → c-QTC6VGA4.js} +1 -1
  63. package/dist/m/{c-44B5ODN7.js → c-TMT5TL65.js} +2 -2
  64. package/dist/m/{c-OABVRYOT.js → c-TV7JHSRL.js} +1 -1
  65. package/dist/m/{c-SO63UGPQ.js → c-UWT4CXQ4.js} +1 -1
  66. package/dist/m/{c-EFD6QNTE.js → c-VFES2BP5.js} +1 -1
  67. package/dist/m/{c-UXEVJ63W.js → c-VIW5X35H.js} +1 -1
  68. package/dist/m/{c-EOCKLMKX.js → c-WWE67K5Y.js} +1 -1
  69. package/dist/m/{c-J3BXFTZS.js → c-XDVAZDUE.js} +1 -1
  70. package/dist/m/{c-K76AUL4I.js → c-XZJ5IK6Q.js} +1 -1
  71. package/dist/m/{c-2ZZBC45O.js → c-Z7RJANGO.js} +1 -1
  72. package/dist/m/{c-I2IFKJX2.js → c-ZAHTFCXQ.js} +1 -1
  73. package/dist/m/{c-GVPNDIKJ.js → c-ZKELCT4T.js} +1 -1
  74. package/dist/m/{c-7SXYQCN4.js → c-ZO6VL2SC.js} +1 -1
  75. package/dist/m/{c-M4FSPNQ2.js → c-ZYEJLZEY.js} +1 -1
  76. package/dist/m/core/{autosave-VPORYJSE.js → autosave-GI3WNJYN.js} +1 -1
  77. package/dist/m/core/{conflict-notice-JMAZLVRX.js → conflict-notice-CEI3XY6A.js} +1 -1
  78. package/dist/m/core/{save-AOJBDSOK.js → save-OJ5NSLS7.js} +1 -1
  79. package/dist/m/core/{save-core-IOCMXO5L.js → save-core-DX3RFVO3.js} +1 -1
  80. package/dist/m/core/{unsaved-warning-U5VUJFOE.js → unsaved-warning-HGYH7O4H.js} +1 -1
  81. package/dist/m/internals/{index-HDRANDWE.js → index-V4WC44FU.js} +1 -1
  82. package/dist/m/loader-V6VI46HU.js +1 -0
  83. package/dist/m/{manifest-3AEF5191.js → manifest-83C18DED.js} +1 -1
  84. package/dist/m/{manifest-edit-29A26F22.js → manifest-edit-B28C1985.js} +1 -1
  85. package/dist/m/manifest.json +567 -567
  86. package/dist/m/page/{editor-EY2WAAGB.js → editor-BQEPCJLG.js} +2 -2
  87. package/dist/m/plugins/ai-edit-45A2J6LC.js +6 -0
  88. package/dist/m/plugins/cms-IFTKWF4S.js +2235 -0
  89. package/dist/m/plugins/{derive-FRE5JJQE.js → derive-QVI3LI3A.js} +1 -1
  90. package/dist/m/plugins/{indicator-4VDXWYTD.js → indicator-IPZJ35K6.js} +1 -1
  91. package/dist/m/plugins/{live-5EZN2EYP.js → live-GPQXSXSM.js} +1 -1
  92. package/dist/m/plugins/menu-UN3KRCOF.js +1 -0
  93. package/dist/m/plugins/{page-LVW5DWA4.js → page-BAVLWCP6.js} +2 -2
  94. package/dist/m/plugins/{page-view-5KQ76IJB.js → page-view-P3UGJFDZ.js} +1 -1
  95. package/dist/m/plugins/{people-C7TVBBMR.js → people-Z4RGVQAV.js} +1 -1
  96. package/dist/m/plugins/{quickcrop-BQ5YYFCH.js → quickcrop-E34PUYA3.js} +2 -2
  97. package/dist/m/plugins/{richclay-KLGETK77.js → richclay-S4NVJYIK.js} +2 -2
  98. package/dist/m/plugins/{source-CCEUM3OR.js → source-KVN6YNTY.js} +1 -1
  99. package/dist/m/plugins/{upgrade-NW556WJD.js → upgrade-KTSICB22.js} +1 -1
  100. package/dist/m/plugins/{wire-VRYPY6EJ.js → wire-SYVIBNSE.js} +1 -1
  101. package/dist/m/{reader-core-2GXY7SHY.js → reader-core-RUIFH32Y.js} +2 -2
  102. package/dist/m/sync/{live-sync-SKPMFYOO.js → live-sync-RGQMMWK2.js} +1 -1
  103. package/dist/m/ui/{index-QNIPDHXQ.js → index-EZGLEM5P.js} +1 -1
  104. package/dist/m/vendor/{sap-core.vendor-RN4ZVY4X.js → sap-core.vendor-OA5SKL7Q.js} +1 -1
  105. package/dist/offline-manifest.json +463 -469
  106. package/docs/guide.md +16 -8
  107. package/entries/sap.js +1 -1
  108. package/package.json +2 -2
  109. package/src/loader-logic.js +4 -1
  110. package/src/plugins/ai-edit.js +6 -17
  111. package/src/plugins/cms.js +3 -6
  112. package/src/plugins/menu/style.js +59 -31
  113. package/src/plugins/menu.js +131 -28
  114. package/src/ui/bevel.js +1 -1
  115. package/src/ui/skins/cms.js +1 -1
  116. package/src/ui/skins/quickcrop.js +1 -1
  117. package/src/ui/skins/richclay.js +1 -1
  118. package/src/vendor/hypercms.vendor.js +16 -69
  119. package/src/vendor/sap-core.vendor.js +1 -1
  120. package/dist/m/c-FSWRGBVQ.js +0 -1
  121. package/dist/m/c-HMYWIHFG.js +0 -1
  122. package/dist/m/c-M6FNQCTQ.js +0 -1
  123. package/dist/m/c-WFMRX5RZ.js +0 -1
  124. package/dist/m/loader-DZZLUBVB.js +0 -1
  125. package/dist/m/plugins/ai-edit-J5VLSW5I.js +0 -6
  126. package/dist/m/plugins/cms-LRAOZHT7.js +0 -2293
  127. package/dist/m/plugins/menu-KGWKT6CS.js +0 -1
  128. package/src/ui/skins/cms-toggle.js +0 -15
  129. /package/dist/m/plugins/{quickcrop-BQ5YYFCH.js.LEGAL.txt → quickcrop-E34PUYA3.js.LEGAL.txt} +0 -0
  130. /package/dist/m/plugins/{richclay-KLGETK77.js.LEGAL.txt → richclay-S4NVJYIK.js.LEGAL.txt} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as j,c as re}from"./c-6DNRCPNM.js";import{a as Re}from"./c-Q3XOWZEV.js";import{a as Le}from"./c-4ASQPRQL.js";import{i as Me}from"./c-GVPNDIKJ.js";import{a as Ce}from"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import{a as Ae}from"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import{b as Y,c as Oe,d as Ie,l as ce,t as fe}from"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Et=16384;function Ot(e){let t=new Map,n=e?.onParseError;return{parser:new Re({...e,onParseError:s=>{t.set(s.code,(t.get(s.code)||0)+1),n?.(s)}}),errors:t}}function It(e,t,n,r){let s=Math.min(n+r,t.length);return e.tokenizer.write(t.slice(n,s),s>=t.length),s}function*de(e,t,{chunk:n=Et}={}){let{parser:r,errors:s}=Ot(t),o=0;do o=It(r,e,o,n),o<e.length&&(yield);while(o<e.length);return{document:r.document,errors:s}}var ge=new Set(["script","style","xmp","iframe","noembed","noframes","plaintext","noscript"]),Je=new Set(["textarea","title"]),be=e=>ge.has(e)?"raw":Je.has(e)?"rcdata":"normal",pe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),$e="http://www.w3.org/1999/xhtml",K=1500,Ct=e=>e.replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fe=e=>e.replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/"/g,"&quot;");function Qe(e){return j(ie(e))}function*ie(e){let{document:t,errors:n}=yield*de(e,{sourceCodeLocationInfo:!0});return We(e,t,n)}function We(e,t,n){let r=t.childNodes.find(l=>l.nodeName==="html"),s=t.childNodes.filter(l=>l!==r).map(l=>l.nodeName==="#documentType"?{kind:"doctype",name:l.name||"",publicId:l.publicId||"",systemId:l.systemId||""}:{kind:l.nodeName==="#comment"?"comment":l.nodeName,value:l.data}),o=r?ze(r,null,e):null;return o&&Ve(o,e),{src:e,doc:t,outside:s,root:o,parseErrors:n,relocated:o?me(o):null,movedIn:o?me(o,"movedIn"):null,tailOwner:o?He(o):null}}function ze(e,t,n){let r=e.sourceCodeLocation||null,s=e.nodeName==="#text"?"text":e.nodeName==="#comment"?"comment":"element",o={node:e,parent:t,live:null,kind:s,children:[],from:r?r.startOffset:-1,to:r?r.endOffset:-1};if(s==="text")return o.value=e.value,o;if(s==="comment")return o.value=e.data,o;o.tag=e.tagName,o.located=!!(r&&r.startTag),o.openFrom=o.located?r.startTag.startOffset:-1,o.openTo=o.located?r.startTag.endOffset:-1,o.closeFrom=r&&r.endTag?r.endTag.startOffset:o.located?o.to:-1,o.closeTo=r&&r.endTag?r.endTag.endOffset:o.located?o.to:-1,o.endTagged=!!(r&&r.endTag),o.located&&(o.to<o.openTo&&(o.to=o.openTo),o.closeFrom<o.openTo&&(o.closeFrom=o.closeTo=o.openTo)),o.attrs=[];let l=o.located&&r.startTag.attrs||r&&r.attrs||{};for(let a of e.attrs){let g=a.prefix?a.prefix+":"+a.name:a.name,c=l[g.toLowerCase()];o.attrs.push({name:g,key:g.toLowerCase(),value:a.value,from:c?c.startOffset:-1,to:c?c.endOffset:-1})}let d=e.nodeName==="template"&&e.content?e.content.childNodes:e.childNodes;for(let a of d)a.nodeName!=="#documentType"&&o.children.push(ze(a,o,n));if(!o.located){let a=o.children.filter(p=>p.from>=0),g=a.length?Math.min(...a.map(p=>p.from)):-1,c=a.length?Math.max(...a.map(p=>p.to)):-1;o.openFrom=o.openTo=g,o.closeFrom=o.closeTo=c,o.from=g,o.to=c}return o}function Ve(e,t,n=1/0){if(e.kind!=="element")return;for(let o of e.children){if(o.from>=n&&!(o.kind==="text"&&!/\S/.test(o.value))&&(e.movedIn=!0),o.from>=0&&e.located){let l=Math.max(e.openTo,Math.min(o.to,e.closeFrom)),d=Math.min(Math.max(o.from,e.openTo),l);if(d!==o.from||l!==o.to){if(o.kind==="text"&&!ge.has(e.tag)&&!Je.has(e.tag)){let a=t.slice(l,o.to).replace(/<!--[\s\S]*?-->|<[^>]*>/g,"").replace(/\r\n?/g,`
1
+ import{a as j,c as re}from"./c-6DNRCPNM.js";import{a as Re}from"./c-Q3XOWZEV.js";import{a as Le}from"./c-4ASQPRQL.js";import{i as Me}from"./c-ZKELCT4T.js";import{a as Ce}from"./c-ATKAOH23.js";import"./c-EK63G3CG.js";import{a as Ae}from"./c-NQJRVJ56.js";import"./c-XGH4GS2T.js";import"./c-IJUK2GPW.js";import"./c-3O7OBDCM.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import{b as Y,c as Oe,d as Ie,l as ce,t as fe}from"./c-EGTIAL6P.js";import"./c-XQXZAO7N.js";import"./c-S7LK4KUE.js";import"./c-VG5XIN4T.js";import"./c-2YYDMLNZ.js";import"./c-HA6INT6J.js";import"./c-ICMAOOGK.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Et=16384;function Ot(e){let t=new Map,n=e?.onParseError;return{parser:new Re({...e,onParseError:s=>{t.set(s.code,(t.get(s.code)||0)+1),n?.(s)}}),errors:t}}function It(e,t,n,r){let s=Math.min(n+r,t.length);return e.tokenizer.write(t.slice(n,s),s>=t.length),s}function*de(e,t,{chunk:n=Et}={}){let{parser:r,errors:s}=Ot(t),o=0;do o=It(r,e,o,n),o<e.length&&(yield);while(o<e.length);return{document:r.document,errors:s}}var ge=new Set(["script","style","xmp","iframe","noembed","noframes","plaintext","noscript"]),Je=new Set(["textarea","title"]),be=e=>ge.has(e)?"raw":Je.has(e)?"rcdata":"normal",pe=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),$e="http://www.w3.org/1999/xhtml",K=1500,Ct=e=>e.replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Fe=e=>e.replace(/&/g,"&amp;").replace(/ /g,"&nbsp;").replace(/"/g,"&quot;");function Qe(e){return j(ie(e))}function*ie(e){let{document:t,errors:n}=yield*de(e,{sourceCodeLocationInfo:!0});return We(e,t,n)}function We(e,t,n){let r=t.childNodes.find(l=>l.nodeName==="html"),s=t.childNodes.filter(l=>l!==r).map(l=>l.nodeName==="#documentType"?{kind:"doctype",name:l.name||"",publicId:l.publicId||"",systemId:l.systemId||""}:{kind:l.nodeName==="#comment"?"comment":l.nodeName,value:l.data}),o=r?ze(r,null,e):null;return o&&Ve(o,e),{src:e,doc:t,outside:s,root:o,parseErrors:n,relocated:o?me(o):null,movedIn:o?me(o,"movedIn"):null,tailOwner:o?He(o):null}}function ze(e,t,n){let r=e.sourceCodeLocation||null,s=e.nodeName==="#text"?"text":e.nodeName==="#comment"?"comment":"element",o={node:e,parent:t,live:null,kind:s,children:[],from:r?r.startOffset:-1,to:r?r.endOffset:-1};if(s==="text")return o.value=e.value,o;if(s==="comment")return o.value=e.data,o;o.tag=e.tagName,o.located=!!(r&&r.startTag),o.openFrom=o.located?r.startTag.startOffset:-1,o.openTo=o.located?r.startTag.endOffset:-1,o.closeFrom=r&&r.endTag?r.endTag.startOffset:o.located?o.to:-1,o.closeTo=r&&r.endTag?r.endTag.endOffset:o.located?o.to:-1,o.endTagged=!!(r&&r.endTag),o.located&&(o.to<o.openTo&&(o.to=o.openTo),o.closeFrom<o.openTo&&(o.closeFrom=o.closeTo=o.openTo)),o.attrs=[];let l=o.located&&r.startTag.attrs||r&&r.attrs||{};for(let a of e.attrs){let g=a.prefix?a.prefix+":"+a.name:a.name,c=l[g.toLowerCase()];o.attrs.push({name:g,key:g.toLowerCase(),value:a.value,from:c?c.startOffset:-1,to:c?c.endOffset:-1})}let d=e.nodeName==="template"&&e.content?e.content.childNodes:e.childNodes;for(let a of d)a.nodeName!=="#documentType"&&o.children.push(ze(a,o,n));if(!o.located){let a=o.children.filter(p=>p.from>=0),g=a.length?Math.min(...a.map(p=>p.from)):-1,c=a.length?Math.max(...a.map(p=>p.to)):-1;o.openFrom=o.openTo=g,o.closeFrom=o.closeTo=c,o.from=g,o.to=c}return o}function Ve(e,t,n=1/0){if(e.kind!=="element")return;for(let o of e.children){if(o.from>=n&&!(o.kind==="text"&&!/\S/.test(o.value))&&(e.movedIn=!0),o.from>=0&&e.located){let l=Math.max(e.openTo,Math.min(o.to,e.closeFrom)),d=Math.min(Math.max(o.from,e.openTo),l);if(d!==o.from||l!==o.to){if(o.kind==="text"&&!ge.has(e.tag)&&!Je.has(e.tag)){let a=t.slice(l,o.to).replace(/<!--[\s\S]*?-->|<[^>]*>/g,"").replace(/\r\n?/g,`
2
2
  `);a&&!/\S/.test(a)&&o.value.endsWith(a)&&(o.outsideTail=a)}o.clamped=!0,o.from=d,o.to=l}}o.kind==="element"&&o.located&&!o.endTagged&&o.closeFrom>o.to&&(o.closeFrom=o.closeTo=o.to)}let r=e.located?e.openTo:-1;for(let o of e.children)if(!(o.from<0)){if(o.from<r){e.outOfOrder=!0;break}r=o.to}let s=e.located&&e.endTagged?Math.min(n,e.closeTo):n;for(let o of e.children)Ve(o,t,s)}function me(e,t="outOfOrder"){if(e[t])return e.tag;for(let n of e.children){if(n.kind!=="element")continue;let r=me(n,t);if(r)return r}return null}function He(e){if(e.outsideTail)return e;for(let t of e.children||[]){let n=He(t);if(n)return n}return null}function Z(e,t){if(!e.root)return"source has no <html> element";if(e.root.openFrom<0)return"source has no content inside <html>";if(e.relocated)return"the parser moved content out of <"+e.relocated+">, so source order and tree order disagree";if(e.movedIn)return"the parser moved content written after the end of <"+e.movedIn+"> back inside it, so source order and tree order disagree";let n=Rt(t),r=e.outside.map(At);if(n.length!==r.length)return"outside <html>: "+JSON.stringify(r)+" vs live "+JSON.stringify(n);for(let s=0;s<n.length;s++)if(n[s]!==r[s])return"outside <html>: "+r[s]+" vs live "+n[s];return null}function At(e){return e.kind==="doctype"?"doctype:"+e.name+"|"+e.publicId+"|"+e.systemId:e.kind+":"+e.value}function Rt(e){let t=[];for(let n of e.childNodes)n.nodeType===10?t.push("doctype:"+n.name+"|"+n.publicId+"|"+n.systemId):n.nodeType===8?t.push("comment:"+n.data):n.nodeType!==1&&t.push("#"+n.nodeType+":"+(n.data||""));return t}var ae="\0",Ge={align:0,hashKey:0};function Pe(e,t){for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return e>>>0}function J(e){Ge.hashKey++;let t=2166136261,n=5381;for(let r of e)t=Pe(t,r),n=(Math.imul(n,33)^Pe(t^2654435769,r))>>>0;return t.toString(36)+"."+n.toString(36)}function q(e){let t=e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content?e.content.childNodes:e.childNodes,n=[];for(let r of t)(r.nodeType===1||r.nodeType===3||r.nodeType===8)&&n.push(r);return n}var ye=e=>Array.from(e.attributes,t=>t.name.toLowerCase()+"="+t.value).sort().join(ae),Xe=e=>e.attrs.map(t=>t.key+"="+t.value).sort().join(ae);function Ye(e,t){let n;if(e.nodeType===3)n={tag:"#text",shallow:"t:"+e.data,content:"t:"+e.data,deep:"t:"+e.data};else if(e.nodeType===8)n={tag:"#comment",shallow:"c:"+e.data,content:"c:"+e.data,deep:"c:"+e.data};else{let r=q(e).map(o=>Ye(o,t)),s="e:"+e.localName+"|"+ye(e);n={tag:e.localName,shallow:s,content:"e:"+e.localName+"|"+J(r.map(o=>o.content)),deep:s+"|"+J(r.map(o=>o.deep))}}return t.set(e,n),n}function*Ke(e,t,n){++n.n%K===0&&(yield);let r;if(e.nodeType===3)r={tag:"#text",shallow:"t:"+e.data,content:"t:"+e.data,deep:"t:"+e.data};else if(e.nodeType===8)r={tag:"#comment",shallow:"c:"+e.data,content:"c:"+e.data,deep:"c:"+e.data};else{let s=[];for(let l of q(e))s.push(yield*Ke(l,t,n));let o="e:"+e.localName+"|"+ye(e);r={tag:e.localName,shallow:o,content:"e:"+e.localName+"|"+J(s.map(l=>l.content)),deep:o+"|"+J(s.map(l=>l.deep))}}return t.set(e,r),r}function*Ze(e,t){if(++t.n%K===0&&(yield),e.kind==="text")return e.keys={tag:"#text",shallow:"t:"+e.value,content:"t:"+e.value,deep:"t:"+e.value};if(e.kind==="comment")return e.keys={tag:"#comment",shallow:"c:"+e.value,content:"c:"+e.value,deep:"c:"+e.value};let n=[];for(let s of e.children)n.push(yield*Ze(s,t));let r="e:"+e.tag+"|"+Xe(e);return e.keys={tag:e.tag,shallow:r,content:"e:"+e.tag+"|"+J(n.map(s=>s.content)),deep:r+"|"+J(n.map(s=>s.deep))}}var De=["deep","content","shallow","tag"],Mt=4096;function Lt(e,t){Ge.align++;let n=[],r=e.map((p,y)=>y),s=t.map((p,y)=>y);g(r,s,0);let o=new Set(n.map(p=>p[0])),l=new Set(n.map(p=>p[1])),d=r.filter(p=>!o.has(p)),a=s.filter(p=>!l.has(p));return d.length&&a.length&&g(d,a,0),n.sort((p,y)=>p[0]-y[0]),n;function g(p,y,S){let w=0,h=p.length,v=0,N=y.length;if(w>=h||v>=N)return;if(S>=De.length)return c(p,y);let b=De[S];for(;w<h&&v<N&&e[p[w]][b]===t[y[v]][b];)n.push([p[w],y[v]]),w++,v++;for(;w<h&&v<N&&e[p[h-1]][b]===t[y[N-1]][b];)h--,N--,n.push([p[h],y[N]]);if(w>=h||v>=N)return;let P=new Map,Q=new Map;for(let I=w;I<h;I++){let A=e[p[I]][b];P.set(A,P.has(A)?-1:I)}for(let I=v;I<N;I++){let A=t[y[I]][b];Q.set(A,Q.has(A)?-1:I)}let ne=[];for(let I=w;I<h;I++){let A=e[p[I]][b];if(P.get(A)===I){let D=Q.get(A);D!==void 0&&D>=0&&ne.push([I,D])}}let W=bt(ne);if(!W.length){if((h-w)*(N-v)<=Mt){let I=Ft(e,t,p,y,w,h,v,N,b);if(I.length){let A=w,D=v;for(let[H,G]of I)n.push([p[H],y[G]]),g(p.slice(A,H),y.slice(D,G),S+1),A=H+1,D=G+1;g(p.slice(A,h),y.slice(D,N),S+1);return}}return g(p.slice(w,h),y.slice(v,N),S+1)}let z=w,V=v;for(let[I,A]of W)n.push([p[I],y[A]]),g(p.slice(z,I),y.slice(V,A),S),z=I+1,V=A+1;g(p.slice(z,h),y.slice(V,N),S)}function c(p,y){let S=new Map,w=new Map;for(let h of p){let v=e[h].tag;S.has(v)||S.set(v,[]),S.get(v).push(h)}for(let h of y){let v=t[h].tag;w.has(v)||w.set(v,[]),w.get(v).push(h)}for(let[h,v]of S){let N=w.get(h);N&&N.length===v.length&&h!=="#text"&&h!=="#comment"&&v.forEach((b,P)=>n.push([b,N[P]]))}}}function bt(e){let t=[],n=[],r=new Array(e.length).fill(-1);for(let l=0;l<e.length;l++){let d=e[l][1],a=0,g=t.length;for(;a<g;){let c=a+g>>1;t[c]<d?a=c+1:g=c}t[a]=d,n[a]=l,r[l]=a>0?n[a-1]:-1}let s=[],o=n.length?n[n.length-1]:-1;for(;o>=0;)s.push(e[o]),o=r[o];return s.reverse()}function Ft(e,t,n,r,s,o,l,d,a){let g=o-s,c=d-l,p=(v,N)=>e[n[s+v]][a]===t[r[l+N]][a],y=Array.from({length:g+1},()=>new Uint16Array(c+1));for(let v=g-1;v>=0;v--)for(let N=c-1;N>=0;N--)y[v][N]=p(v,N)?y[v+1][N+1]+1:Math.max(y[v+1][N],y[v][N+1]);let S=[],w=0,h=0;for(;w<g&&h<c;)p(w,h)?(S.push([s+w,l+h]),w++,h++):y[w+1][h]>=y[w][h+1]?w++:h++;return S}function Be(e){return e.nodeType===3?"#text "+JSON.stringify(e.data.slice(0,40)):e.nodeType===8?"#comment":"<"+e.localName+Array.from(e.attributes,t=>" "+t.name+'="'+t.value.slice(0,30)+'"').join("")+">"}function je(e){return e.kind==="text"?"#text "+JSON.stringify(e.value.slice(0,40)):e.kind==="comment"?"#comment":"<"+e.tag+e.attrs.map(t=>" "+t.name+'="'+t.value.slice(0,30)+'"').join("")+">"}function et(e,t,n=r=>r){return j(we(e,t,n))}function*we(e,t,n=r=>r){let r=new WeakMap,s=new Map,o={n:0};yield*Ke(e,s,o),yield*Ze(t.root,o);let l={paired:0,unmatchedLive:[],unmatchedSource:[],attrDiffs:[],textDiffs:0,unresolved:0},d={};return t.gen=d,yield*tt(e,t.root,r,s,l,"html",n,d,o),{map:r,stats:l}}function*tt(e,t,n,r,s,o,l,d,a){++a.n%K===0&&(yield);let g=l(e);if(g?(n.set(g,t),t.gen=d,s.paired++):s.unresolved++,t.kind!=="element"){e.data!==t.value&&s.textDiffs++;return}ye(e)!==Xe(t)&&s.attrDiffs.push({path:o,live:Be(e),source:je(t)});let c=q(e),p=t.children,y=Lt(c.map(h=>r.get(h)),p.map(h=>h.keys)),S=new Set,w=new Set;for(let[h,v]of y)S.add(h),w.add(v),yield*tt(c[h],p[v],n,r,s,o+">"+(c[h].nodeType===1?c[h].localName:"#")+"["+h+"]",l,d,a);for(let h=0;h<c.length;h++)S.has(h)||s.unmatchedLive.push({path:o,node:Be(c[h])});for(let h=0;h<p.length;h++)w.has(h)||s.unmatchedSource.push({path:o,node:je(p[h])})}function*nt(e,t,n=r=>r){if(!t.root)return null;let r=[],s=yield*rt(e,t.root,n,r,{n:0});if(s<0)return null;let o=new WeakMap,l={};t.gen=l;let d=0;for(let[a,g]of r)a&&(o.set(a,g),g.gen=l,d++);return{map:o,stats:{paired:d,unmatchedLive:[],unmatchedSource:[],attrDiffs:[],textDiffs:0,unresolved:s}}}function*rt(e,t,n,r,s){if(++s.n%K===0&&(yield),t.kind==="text"){if(e.nodeType!==3||e.data!==t.value)return-1}else if(t.kind==="comment"){if(e.nodeType!==8||e.data!==t.value)return-1}else if(e.nodeType!==1||e.localName!==t.tag||e.namespaceURI!==t.node.namespaceURI||Pt(e)!==Dt(t.node))return-1;let o=n(e);r.push([o,t]);let l=o?0:1;if(t.kind!=="element")return l;let d=Bt(e),a=t.children;if(d.length!==a.length)return-1;for(let g=0;g<d.length;g++){let c=yield*rt(d[g],a[g],n,r,s);if(c<0)return-1;l+=c}return l}var ot=e=>JSON.stringify(e),Pt=e=>Array.from(e.attributes,t=>ot([t.namespaceURI||"",t.name,t.value])).sort().join(ae),Dt=e=>e.attrs.map(t=>ot([t.namespace||"",t.prefix?t.prefix+":"+t.name:t.name,t.value])).sort().join(ae);function Bt(e){let t=e.nodeType===1&&e.tagName==="TEMPLATE"&&e.content?e.content.childNodes:e.childNodes,n=[];for(let r of t)(r.nodeType===1||r.nodeType===3||r.nodeType===8)&&n.push(r);return n}function st(e,t,n){let r=t.get(e);if(!r||r.gen!==n.gen||r.from<0||r.to<0||r.kind==="element"&&r.located&&n.src.slice(r.openFrom,r.openFrom+r.tag.length+1).toLowerCase()!=="<"+r.tag.toLowerCase())return null;let s=jt(n),o=Ut(s,r.from);return{from:r.from,to:r.to,line:o+1,column:r.from-s[o]+1}}function jt(e){if(!e.lineStarts){let t=[0];for(let n=0;n<e.src.length;n++)e.src.charCodeAt(n)===10&&t.push(n+1);e.lineStarts=t}return e.lineStarts}function Ut(e,t){let n=0,r=e.length-1;for(;n<r;){let s=n+r+1>>1;e[s]<=t?n=s:r=s-1}return n}function it(e,t,n,r,s={}){let o=()=>typeof performance<"u"?performance.now():Date.now(),l=o(),d=n.src,a=[],g=0,c=(u,m)=>{if(!(u>=0&&m>u))return;let f=a.length>g?a[a.length-1]:null;f&&f.text===void 0&&f.to===u?f.to=m:a.push({from:u,to:m})},p=u=>{u&&a.push({text:u})},y=0,S=u=>{if(y)return null;let m=r(u),f=m?t.get(m):null;return f&&f.gen===n.gen?f:null},w=null,h=-1,v=!1,N=n.root;if(c(0,N.openFrom),I(e,N),c(N.closeTo,d.length),n.tailOwner&&h>=0&&!v){for(let u=h;u<a.length;u++)a[u]={text:Q(P(a[u]))};w&&w.tail&&a.splice(w.at,0,{text:w.tail})}return{text:a.map(P).join(""),ms:o()-l};function P(u){return u.text!==void 0?u.text:d.slice(u.from,u.to)}function Q(u){return u.split(/(<!--[\s\S]*?-->|<[^>]*>)/).map((m,f)=>f%2?m:m.replace(/[\t\n\f\r ]+/g,"")).join("")}function ne(){h=a.length,g=a.length,v=!!w&&w.whole&&/^(?:<\/[^>]*>)*$/.test(a.slice(w.at).map(P).join(""))}function W(u,m){if(u.nodeType===3)return V(u,m);if(u.nodeType===8)return z(u);if(u.nodeType===1){if(s.print&&s.print.has(u)){y++;try{I(u,null)}finally{y--}}else I(u,S(u));u.localName==="body"&&u.parentNode===e&&ne()}}function z(u){let m=S(u);m&&m.kind==="comment"&&m.value===u.data&&m.from>=0&&!s.breakText?c(m.from,m.to):p("<!--"+u.data+"-->")}function V(u,m){let f=S(u),x=u.data;s.corrupt==="drop-first-text"&&!s.corrupted&&x.trim()&&(s.corrupted=!0,x=x.slice(1));let T=f&&f.parent&&be(f.parent.tag)===be(m);if(f&&f.kind==="text"&&f.value===x&&f.from>=0&&!s.breakText&&T){c(f.from,f.to),s.doubleCopied!==void 0&&x===s.doubleCopied&&c(f.from,f.to),f.outsideTail&&(w={at:a.length,tail:f.outsideTail,whole:!0},g=a.length);return}let M=null;if(f&&f.kind==="text"&&f.outsideTail){let R=x.endsWith(f.outsideTail);R&&(x=x.slice(0,x.length-f.outsideTail.length)),M={tail:R?f.outsideTail:"",whole:R}}p(ge.has(m)?x:Ct(x)),M&&(w={at:a.length,...M},g=a.length)}function I(u,m){let f=u.localName,x=pe.has(f)&&u.namespaceURI===$e,T=m&&m.kind==="element"&&!s.breakTags?m:null;if(T&&!T.located){if(u.attributes.length===0){if(T.openFrom>=0){X(u,T,f);return}q(u).length&&X(u,null,f);return}if(p(A(u)),x)return;X(u,T.openFrom>=0?T:null,f),p("</"+f+">");return}if(!T){if(p(A(u)),x)return;X(u,null,f),p("</"+f+">");return}H(u,T),!x&&(X(u,T,f),c(T.closeFrom,T.closeTo))}function A(u){let m="<"+u.localName;for(let f of u.attributes)m+=" "+f.name+(f.value===""?"":'="'+Fe(f.value)+'"');return m+">"}function D(u,m){let f=u.attributes;if(f.length!==m.attrs.length)return!1;for(let x=0;x<f.length;x++){let T=m.attrs[x];if(T.from<0||f[x].value!==T.value||f[x].name.toLowerCase()!==T.key)return!1}return!0}function H(u,m){if(D(u,m)){c(m.openFrom,m.openTo);return}let f=new Map;for(let O of u.attributes)f.set(O.name.toLowerCase(),O);let x=new Set,T=m.openFrom;for(let O of m.attrs){if(O.from<0){let _=f.get(O.key);_&&_.value===O.value&&x.add(O.key);continue}let L=f.get(O.key);if(x.add(O.key),!L){c(T,G(T,O.from)),T=O.to;continue}if(L.value===O.value){c(T,O.to),T=O.to;continue}c(T,O.from),p(xt(d.slice(O.from,O.to),L.value)),T=O.to}let M=m.openTo-1,R=m.attrs.reduce((O,L)=>L.to>O?L.to:O,m.openFrom);d[M-1]==="/"&&M-1>=R&&M--,c(T,M);for(let O of u.attributes)x.has(O.name.toLowerCase())||p(" "+O.name+(O.value===""?"":'="'+Fe(O.value)+'"'));c(M,m.openTo)}function G(u,m){let f=m;for(;f>u&&/[ \t\n\r\f]/.test(d[f-1]);)f--;return f}function xt(u,m){let f=u.indexOf("="),x=(f<0?u:u.slice(0,f)).trimEnd(),T=f<0?"":u.slice(f+1).trim(),M=T[0]==="'"?"'":T[0]==='"'?'"':"",R=m.replace(/&/g,"&amp;").replace(/ /g,"&nbsp;");return M==="'"&&!m.includes("'")?x+"='"+R+"'":M===""&&T!==""&&m!==""&&!/[\s"'=<>`]/.test(m)?x+"="+R:x+'="'+R.replace(/"/g,"&quot;")+'"'}function St(u){if(u.nodeType!==1||y||s.print&&s.print.has(u))return null;let m=S(u);return m&&m.kind==="element"&&m.located&&!m.endTagged&&!pe.has(m.tag)&&!s.breakTags?m:null}function ue(u){let m=St(u);if(!m)return null;let f=q(u);return((f.length?ue(f[f.length-1]):null)||[]).concat(m.tag)}function X(u,m,f){let x=q(u),T=null,M=(C,k)=>{T&&!(k>=0&&T.j>=0&&k===T.j+1)&&p(T.tags.map(E=>"</"+E+">").join("")),T=null};if(!m){for(let C of x){M(-1,-1),W(C,f);let k=ue(C);k&&(T={tags:k,j:-1})}return}let R=m.children,O=new Map(R.map((C,k)=>[C,k])),L=x.map(C=>{let k=S(C);return k&&k.parent===m&&k.from>=0?O.get(k):-1}),_=new Set;if(!s.breakText&&!s.breakTags){let C=new Set(L),k=new Map;R.forEach((E,F)=>{C.has(F)||E.from<0||!E.keys||(k.has(E.keys.deep)||k.set(E.keys.deep,[]),k.get(E.keys.deep).push(F))}),k.size&&x.forEach((E,F)=>{if(L[F]>=0||S(E))return;let B=k.get(Ye(E,new Map).deep);B&&B.length&&(L[F]=B.shift(),_.add(F))})}let Se=(C,k)=>{if(!_.has(k))return W(C,f);let E=R[L[k]];c(E.from,E.to),E.outsideTail&&(w={at:a.length,tail:E.outsideTail,whole:!0},g=a.length)},kt=(C,k)=>{if(!_.has(k))return ue(C);let E=R[L[k]];return E.kind==="element"&&E.located&&!E.endTagged&&!pe.has(E.tag)?[E.tag]:null},Nt=new Set(_t(L)),U=m.openTo,ke=-1,Ne=C=>{for(let k=ke+1;k<C;k++){let E=R[k];E.from<0||(c(U,E.from),U=Math.max(U,E.to))}};for(let C=0;C<x.length;C++){let k=x[C],E=kt(k,C);if(Nt.has(C)){let B=L[C],Ee=R[B];M(C,B),Ne(B),c(U,Ee.from),Se(k,C),U=Math.max(U,Ee.to),ke=B,T=E?{tags:E,j:B}:null;continue}let F=S(k);M(C,F&&F.parent===m?O.get(F):-1),Se(k,C),T=E?{tags:E,j:-1}:null}Ne(R.length),c(U,m.closeFrom)}}function _t(e){let t=[],n=[],r=new Array(e.length).fill(-1);for(let l=0;l<e.length;l++){let d=e[l];if(d<0)continue;let a=0,g=t.length;for(;a<g;){let c=a+g>>1;t[c]<d?a=c+1:g=c}t[a]=d,n[a]=l,r[l]=a>0?n[a-1]:-1}let s=[],o=n.length?n[n.length-1]:-1;for(;o>=0;)s.push(o),o=r[o];return s.reverse()}function*at(e,t,n,r=null,s=null){return yield*ve(e,t,n,r,s,!0)}function*ve(e,t,n,r,s,o){let l=new DOMParser,d=l.parseFromString(e,"text/html"),a=qe(d),g=qe(n);if(a.join(`
3
3
  `)!==g.join(`
4
4
  `))return{ok:!1,diff:"document: outside <html> "+JSON.stringify(a)+" vs live "+JSON.stringify(g)};let c=null,p=null;if(r&&(c=[],p=yield*se(d.documentElement,r,"html",c),!p)){let h=yield*Ue(e,s,o);return h.diff?{ok:!1,diff:h.diff}:o?_e({ok:!0,diff:null,oracle:"clone"},h,e,n):{ok:!0,diff:null,oracle:"clone"}}let y=l.parseFromString(t,"text/html"),S=yield*se(d.documentElement,y.documentElement,"html"),w=S?null:yield*Ue(e,s,o);return S?r?{ok:!1,diff:S,at:c}:{ok:!1,diff:S}:w.diff?{ok:!1,diff:w.diff}:o?_e({ok:!0,diff:null,oracle:"today"},w,e,n):{ok:!0,diff:null,oracle:"today"}}function lt(e,t){let n=e;for(let r of t){let s=he(n);if(r>=s.length)return null;n=s[r]}return n}function*Ue(e,t,n){if(!t)return{diff:null};let{document:r,errors:s}=yield*de(e,n?{sourceCodeLocationInfo:!0}:{});for(let[o,l]of s){let d=t.get(o)||0;if(l>d)return{diff:`the render introduced parse errors the source does not have: ${o} ${d} -> ${l}`}}return n?{diff:null,doc:r,parseErrors:s}:{diff:null}}function _e(e,t,n,r){if(!t.doc)return e;let s=We(n,t.doc,t.parseErrors);return Z(s,r)||(e.model=s),e}function qe(e){let t=[];for(let n of e.childNodes)n.nodeType===10?t.push("doctype "+n.name+"|"+n.publicId+"|"+n.systemId):n.nodeType===8?t.push("comment "+n.data):n.nodeType!==1&&t.push("node"+n.nodeType+" "+(n.data||""));return t}function*qt(e,t,n,r){let s=new DOMParser,o=l=>{let d=Array.from(l.childNodes);return d.length&&d.every(a=>a.nodeType===3)?d.map(a=>a.data).join(""):l.innerHTML};return yield*se(s.parseFromString(e.innerHTML,"text/html").body,s.parseFromString(o(t),"text/html").body,n+">#noscript",[],r)}function he(e){let t=e.localName==="template"&&e.content?e.content.childNodes:e.childNodes,n=[];for(let r=0;r<t.length;r++){let s=t[r];(s.nodeType===1||s.nodeType===3||s.nodeType===8)&&n.push(s)}return n}var oe=e=>Array.from(e.attributes,t=>(t.namespaceURI||"")+" "+t.name+"="+JSON.stringify(t.value)).sort().join("; ");function Jt(e,t){let n=e.attributes,r=t.attributes;if(n.length!==r.length)return!1;for(let s=0;s<n.length;s++){let o=n[s],l=r[s];if(o.name!==l.name||o.value!==l.value||o.namespaceURI!==l.namespaceURI)return!1}return!0}function*se(e,t,n,r=[],s={n:0}){if(++s.n%K===0&&(yield),e.nodeType!==t.nodeType)return n+": node type "+e.nodeType+" vs "+t.nodeType;if(e.nodeType===3||e.nodeType===8)return e.data===t.data?null:n+": text "+JSON.stringify(e.data.slice(0,60))+" vs "+JSON.stringify(t.data.slice(0,60));if(e.localName!==t.localName||e.namespaceURI!==t.namespaceURI)return n+": tag "+e.localName+" vs "+t.localName;if(!Jt(e,t)&&oe(e)!==oe(t))return n+": attrs "+oe(e)+" vs "+oe(t);if(e.localName==="noscript"&&e.namespaceURI===$e)return yield*qt(e,t,n,s);let o=he(e),l=he(t);if(o.length!==l.length)return n+": "+o.length+" vs "+l.length+" children";for(let d=0;d<o.length;d++){r.push(d);let a=yield*se(o[d],l[d],n+">"+(o[d].localName||"#")+"["+d+"]",r,s);if(a)return a;r.pop()}return null}var i={installed:!1,refused:null,session:0,model:null,map:null,stats:null,saves:0,reprints:0,lastReprint:null,partialReprints:0,lastPartialReprint:null,lastOutcome:null,lastRenderMs:null,lastBytes:null,timing:{fetch:null,model:null,pair:null,refresh:null},refreshes:0,repairs:0,refreshQueued:!1,pendingBytes:null,refetch:!1,adoptions:0},$t=2,$=()=>typeof performance<"u"?performance.now():Date.now(),dt=4,le=Object.freeze({superseded:!0});function pt(e){return document.hidden||Me()?!1:e>=307200}var mt='<script type="application/json" id="clay-runtime-map"',ht=e=>e.includes(mt)||e.includes("/_/clayjs/");async function gt(e){let t=await fetch(e,{cache:"no-store",redirect:"manual",credentials:"same-origin",headers:{"Clay-Source":"1"}});if(!t.ok)throw new Error(`source fetch: status ${t.status}`);if(t.redirected||t.type==="opaqueredirect")throw new Error("source fetch: redirected");let n=(t.headers.get("content-type")||"").toLowerCase();if(!n.startsWith("text/html"))throw new Error(`source fetch: content-type ${n||"missing"}`);let r=await t.text();if(r.includes(mt))throw new Error("source fetch: projected response");return r}function yt(e){let t=fe({flushUndo:!1,authored:!1});return et(t,e,Y)}function*Qt(e){let t=fe({flushUndo:!1,authored:!1});return yield*we(t,e,Y)}function Wt(e){let t=e.doc&&e.doc.childNodes.find(r=>r.nodeName==="html"),n=t&&Array.isArray(t.attrs)?t.attrs.find(r=>r.name==="documentetag"):null;return n&&n.value?n.value:null}function zt(e){let t=e&&e.represented&&e.represented.etag;if(t)return t;let n=Ae();return n||e===null&&document.documentElement.getAttribute("documentetag")||null}function Vt(e,t){let n=Wt(e),r=zt(t);return!n||!r||n===r?null:`source refused: the fetch answered version ${n} while this page holds ${r}`}async function wt(e,t=null,n=0,r=!0,s=null){let o=i.session,l=$(),d=i.adoptions;i.refused=null;let a=s?s():null,g=a&&typeof a.bytes=="string"&&!ht(a.bytes)?a.bytes:null;try{let c=g!==null?g:await gt(e);if(o!==i.session)return null;let p=$(),y=await Ht({src:c,context:t,render:r,session:o,generation:d,t0:l,t1:p});if(y!==le)return y;if(n<$t)return wt(e,t,n+1,r,s);throw new Error("source refused: a save replaced the file while the fetch was in flight")}catch(c){return o!==i.session||(i.refused=String(c&&c.message?c.message:c),console.info(`clayjs: source map off (${i.refused}); saves use the full serialization`)),null}}function*ut(e){let t=yield*ie(e.src),n=Z(t,document);if(n)throw new Error(`source refused: ${n}`);let r=Vt(t,e.context);if(r)throw new Error(r);if(i.adoptions!==e.generation)return le;let s=$();if(yield,i.session!==e.session)return null;if(i.adoptions!==e.generation)return le;let{map:o,stats:l}=yield*Qt(t);if(i.session!==e.session)return null;if(i.adoptions!==e.generation)return le;let d=$();return i.model=t,i.map=o,i.stats=l,i.timing={fetch:e.t1-e.t0,model:s-e.t1,pair:d-s,refresh:null},i.installed=!0,e.render&&ce(Gt,{steps:vt}),Tt()}async function Ht(e){if(!pt(e.src.length))return j(ut(e));let t={get aborted(){return i.session!==e.session}},n=await re(ut(e),{budgetMs:dt,signal:t});return n&&n.aborted===!0?null:n}function Gt(e,t,n={}){return j(vt(e,t,n))}function*vt(e,t,n={}){if(!i.installed)return t;yield*xe();let r=i.session,s=i.repairs,o=Oe(),l=!!o&&!o.authoredHandlers,d=new Set,a=null;for(let g=0;g<=Yt;g++){let c;try{c=it(e,i.map,i.model,Y,{...n,print:d})}catch(y){return ee("render threw: "+(y&&y.message?y.message:y),t)}let p=l?yield*at(c.text,t,document,e,i.model.parseErrors):yield*ve(c.text,t,document,e,i.model.parseErrors,!1);if(p.ok){let y=ct(r,s);if(y)return ee(y,t);let S=d.size?{text:c.text,scope:"partial",reason:a,printed:d.size}:{text:c.text,scope:null},w=p.model?yield*nt(e,p.model,Y):null,h=ct(r,s);return h?ee(h,t):(i.lastRenderMs=c.ms,i.lastBytes=c.text.length,i.lastOutcome=S,p.model&&Xt(p.model,c.text,o,w),c.text)}if(a===null&&(a=p.diff),!p.at||!Kt(e,lt(e,p.at),d))return ee(a,t)}return ee(a,t)}function ct(e,t){return i.session!==e?"render refused: the session ended while this render ran":i.installed?i.repairs!==t?"render refused: the map was re-paired while this render ran":null:"render refused: the source map was uninstalled while this render ran"}function Xt(e,t,n,r){r&&Ie({captureId:n.captureId,html:t,source:{model:e,map:r.map,stats:r.stats,repairGeneration:i.repairs,outcome:i.lastOutcome}})}var Yt=8;function Kt(e,t,n){let r=t&&t.nodeType===1?t:t&&t.parentNode;for(let s=r;s&&s!==e;s=s.parentNode)if(n.has(s)){n.delete(s),r=s.parentNode;break}return!r||r.nodeType!==1||r===e?!1:(n.add(r),!0)}function ee(e,t){return i.lastOutcome={text:t,scope:"full",reason:e},t}function Zt(e){i.reprints++,i.lastReprint=e,console.warn("clayjs: source map did not verify, saving the full serialization instead:",e),document.dispatchEvent(new CustomEvent("clay:save-reprinted",{detail:{reason:e,scope:"full"}}))}function en(e,t){i.partialReprints++,i.lastPartialReprint=e,console.info(`clayjs: source map printed ${t} element(s) in full to match the page:`,e),document.dispatchEvent(new CustomEvent("clay:save-reprinted",{detail:{reason:e,scope:"partial",printed:t}}))}function tn(e,t){i.adoptions++,i.installed&&(rn(e,t&&t.artifact?t.artifact.source.outcome:null),!nn(e,t)&&(i.pendingBytes=e,Te()))}function nn(e,t){let n=t&&t.artifact;return!n||!n.source||n.html!==e||t.captureId===null||t.captureId===void 0||n.captureId!==t.captureId||n.source.repairGeneration!==i.repairs||i.refreshQueued||i.pendingBytes!==null?!1:(i.model=n.source.model,i.map=n.source.map,i.stats=n.source.stats,!0)}function rn(e,t=null){let n=i.lastOutcome&&i.lastOutcome.text===e?i.lastOutcome:t;!n||n.text!==e||(i.lastOutcome===n&&(i.lastOutcome=null),i.saves++,n.scope==="full"?Zt(n.reason):n.scope==="partial"&&en(n.reason,n.printed))}function on(e){let t=e&&e.detail;t&&t.source==="disk"&&typeof t.html=="string"&&i.adoptions++,i.installed&&(t&&t.source==="disk"&&typeof t.html=="string"&&(ht(t.html)?i.refetch=!0:i.pendingBytes=t.html),Te())}function Te(){i.refreshQueued||(i.refreshQueued=!0,typeof requestIdleCallback=="function"?requestIdleCallback(ft,{timeout:2e3}):setTimeout(ft,0))}function ft(){if(!pt(sn())){te();return}an()}function sn(){return typeof i.pendingBytes=="string"?i.pendingBytes.length:i.model?i.model.src.length:0}async function an(){let e=i.session,t={get aborted(){return i.session!==e}};try{await re(xe(),{budgetMs:dt,signal:t})}catch(n){console.warn("clayjs: source map could not run the queued repair:",n)}!i.refreshQueued||!i.installed||i.session!==e||(i.refreshQueued=!1,Te())}function te(){j(xe())}function*xe(){if(!i.refreshQueued)return;if(!i.installed){i.refreshQueued=!1;return}let e=i.session,t=i.repairs,n=i.adoptions,r=i.pendingBytes,s=i.refetch&&r===null,o=$(),l=i.model;if(r!==null)try{let a=yield*ie(r),g=Z(a,document);if(g)throw new Error(g);l=a}catch(a){console.warn("clayjs: source map kept the previous model, the accepted bytes did not model:",a)}if(yield,!ln(e,t,n))return;let d=null;try{d=yt(l)}catch(a){console.warn("clayjs: source map could not re-pair, continuing on the previous map:",a)}i.refreshQueued=!1,i.pendingBytes=null,s&&(i.refetch=!1),i.repairs++,d&&(i.model=l,i.map=d.map,i.stats=d.stats,i.refreshes++,i.timing.refresh=$()-o),s&&un()}function ln(e,t,n){return i.session===e&&i.installed&&i.repairs===t&&i.adoptions===n}function un(){let e=i.repairs,t=i.adoptions;gt(window.location.href).then(n=>{let r=Qe(n),s=Z(r,document);if(s)throw new Error(s);return r}).then(n=>{if(!(i.repairs!==e||i.adoptions!==t))try{i.repairs++,i.adoptions++;let{map:r,stats:s}=yt(n);i.model=n,i.map=r,i.stats=s,i.refreshes++}catch(r){console.warn("clayjs: source map could not re-pair, continuing on the previous map:",r)}}).catch(n=>{console.warn("clayjs: source map kept the previous model, the accepted bytes did not model:",n)})}function Tt(){let e=i.stats;return{installed:i.installed,refused:i.refused,sourceBytes:i.model?i.model.src.length:null,paired:e?e.paired:0,unresolved:e?e.unresolved:0,unmatchedLive:e?e.unmatchedLive.length:0,unmatchedSource:e?e.unmatchedSource.length:0,attrDiffs:e?e.attrDiffs.length:0,saves:i.saves,reprints:i.reprints,lastReprint:i.lastReprint,partialReprints:i.partialReprints,lastPartialReprint:i.lastPartialReprint,lastRenderMs:i.lastRenderMs,lastBytes:i.lastBytes,refreshes:i.refreshes,timing:i.timing}}function kn(){return te(),i.model?i.model.src:null}function Nn(e){return te(),i.installed&&e?st(e,i.map,i.model):null}function En(){return te(),i.stats?{live:i.stats.unmatchedLive.slice(0,50),source:i.stats.unmatchedSource.slice(0,50)}:null}function On(){return te(),Tt()}var In=()=>i.installed,Cn=()=>i.repairs;function An(){cn()}function cn(){i.session++,i.installed=!1,i.refreshQueued=!1,i.pendingBytes=null,i.refetch=!1,ce(null)}function Rn({context:e=null,latest:t=null}={}){return wt(window.location.href,e,0,!0,t)}Ce(tn);document.addEventListener("clay:sync-applied",on);export{tn as adoptAccepted,In as installed,Nn as locateLive,xe as refreshNowSteps,An as release,Gt as renderSave,vt as renderSaveSteps,Cn as repairGeneration,Rn as start,On as stats,kn as text,En as unpaired};
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g,h}from"./c-VAK7SG37.js";import"./c-VHNSBD2M.js";export{c as FONT_MONO,b as FONT_SANS,f as GLYPHS,h as MEDIA,g as RULES,d as SHADOW,a as SOURCE_SHA256,e as TOKENS};
1
+ import{a,b,c,d,e,f,g,h}from"./c-EUGJVHDD.js";import"./c-VHNSBD2M.js";export{c as FONT_MONO,b as FONT_SANS,f as GLYPHS,h as MEDIA,g as RULES,d as SHADOW,a as SOURCE_SHA256,e as TOKENS};
@@ -1,4 +1,4 @@
1
- import{x as O}from"./c-44B5ODN7.js";import{H as x,I as C,J as $,a as A,m as N}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var g=N.nodes,H=e=>e.attrs.parent??null,_=e=>{let a=new Set;return e.forEach(t=>t.forEach(o=>a.add(o.attrs.col))),C(e.attrs.cols).filter(t=>a.has(t))};function S(e,a){let t=a.ownerDocument,o=t.createElement("thead").appendChild(t.createElement("tr"));for(let s of _(e)){let p=e.attrs.cols[s],r=o.appendChild(t.createElement("th"));r.setAttribute("data-col",s),r.setAttribute("scope","col"),p.kind&&r.setAttribute("data-kind",p.kind),p.width&&(r.setAttribute("data-width",String(p.width)),r.style.width=`${p.width}px`),r.textContent=p.name??""}a.prepend(o.parentNode),e.attrs.sort&&a.setAttribute("data-sort",JSON.stringify(e.attrs.sort))}function v(e,a){let t=[];e.forEach((o,s,p)=>{let r=a[p];if(!r||r.nodeType!==1)return;if(o.type===g.table&&S(o,r),o.type!==g.list_item||H(o)!==null){t=[];return}let f=r.ownerDocument,{indent:d,kind:i}=o.attrs,l=i==="ordered"?"OL":"UL";for(;t.length&&t.at(-1).indent>d;)t.pop();if(t.at(-1)?.indent===d&&t.at(-1).list.tagName!==l&&t.pop(),!t.length||t.at(-1).indent<d){let c=f.createElement(l);t.length?t.at(-1).li.append(c):r.before(c),t.push({indent:d,list:c,li:null})}let u=f.createElement("li");i==="check"&&(u.innerHTML=`<input type="checkbox" disabled${o.attrs.checked?" checked":""}>`),u.append(...r.childNodes),t.at(-1).list.append(u),t.at(-1).li=u,r.remove()})}var T=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function q(e){if(!e.content.firstChild?.type.spec.group?.includes("block"))return null;let a="",t=[],o=!1;return e.content.forEach((s,p,r)=>{let f=s.type===g.list_item,d=s.textBetween(0,s.content.size,`
1
+ import{x as O}from"./c-TMT5TL65.js";import{H as x,I as C,J as $,a as A,m as N}from"./c-QIXT3Q7C.js";import"./c-VHNSBD2M.js";var g=N.nodes,H=e=>e.attrs.parent??null,_=e=>{let a=new Set;return e.forEach(t=>t.forEach(o=>a.add(o.attrs.col))),C(e.attrs.cols).filter(t=>a.has(t))};function S(e,a){let t=a.ownerDocument,o=t.createElement("thead").appendChild(t.createElement("tr"));for(let s of _(e)){let p=e.attrs.cols[s],r=o.appendChild(t.createElement("th"));r.setAttribute("data-col",s),r.setAttribute("scope","col"),p.kind&&r.setAttribute("data-kind",p.kind),p.width&&(r.setAttribute("data-width",String(p.width)),r.style.width=`${p.width}px`),r.textContent=p.name??""}a.prepend(o.parentNode),e.attrs.sort&&a.setAttribute("data-sort",JSON.stringify(e.attrs.sort))}function v(e,a){let t=[];e.forEach((o,s,p)=>{let r=a[p];if(!r||r.nodeType!==1)return;if(o.type===g.table&&S(o,r),o.type!==g.list_item||H(o)!==null){t=[];return}let f=r.ownerDocument,{indent:d,kind:i}=o.attrs,l=i==="ordered"?"OL":"UL";for(;t.length&&t.at(-1).indent>d;)t.pop();if(t.at(-1)?.indent===d&&t.at(-1).list.tagName!==l&&t.pop(),!t.length||t.at(-1).indent<d){let c=f.createElement(l);t.length?t.at(-1).li.append(c):r.before(c),t.push({indent:d,list:c,li:null})}let u=f.createElement("li");i==="check"&&(u.innerHTML=`<input type="checkbox" disabled${o.attrs.checked?" checked":""}>`),u.append(...r.childNodes),t.at(-1).list.append(u),t.at(-1).li=u,r.remove()})}var T=e=>/[\t\n\r"]/.test(e)?`"${e.replace(/"/g,'""')}"`:e;function q(e){if(!e.content.firstChild?.type.spec.group?.includes("block"))return null;let a="",t=[],o=!1;return e.content.forEach((s,p,r)=>{let f=s.type===g.list_item,d=s.textBetween(0,s.content.size,`
2
2
 
3
3
  `);if(f){let{indent:i,kind:l}=s.attrs;for(;t.length&&t.at(-1).indent>i;)t.pop();t.at(-1)?.indent===i&&t.at(-1).kind!==l&&t.pop(),(!t.length||t.at(-1).indent<i)&&t.push({indent:i,kind:l,n:0});let u=t.at(-1),c=l==="ordered"?`${++u.n}.`:l==="check"?`- [${s.attrs.checked?"x":" "}]`:"-";d=`${" ".repeat(t.length-1)}${c} ${d}`}else t=[];if(s.type===g.table){let i=[_(s).map(l=>T(s.attrs.cols[l].name??""))];s.forEach(l=>{let u=[];l.forEach(c=>u.push(T(c.textContent))),i.push(u)}),d=i.map(l=>l.join(" ")).join(`
4
4
  `)}a+=(r?o&&f?`
@@ -1 +1 @@
1
- import"./c-VHNSBD2M.js";var l=(e,n)=>Object.assign(new Error(`clayjs: ${e}`),{code:n}),u=(e,n)=>!e||n.seq===null||e.seq===null||n.seq>e.seq?n:e;function a({stream:e,apply:n,retire:f,yieldArticle:i=()=>!1,reclaimArticle:s=()=>!1}){let t=null,r=!1;e.adopt({onSnapshot:o=>(t=u(t,o),!0)});let d=()=>{let o=t;return t=null,o};return{get represented(){return e.represented},get held(){return t??e.represented},yieldArticle(){return r||!i()?!1:(r=!0,!0)},reclaimArticle(){return!r||!s()?!1:(r=!1,!0)},reconcile(){let o=d();return o&&!n(o)?Promise.reject(l("the switch could not apply the saved file","load-failed")):Promise.resolve()},resume(){e.adopt({onSnapshot:n});let o=d();o&&n(o)},commit(){if(!r){let o=d();if(o&&!n(o))return!1}return e.represented.bytes===null?!1:(e.stop(),f())}}}async function c({stream:e,options:n,apply:f,retire:i,yieldArticle:s=()=>!1,reclaimArticle:t=()=>!1}){if(e)return a({stream:e,apply:f,retire:i,yieldArticle:s,reclaimArticle:t});let r=await import("./sync/live-sync-SKPMFYOO.js").then(({liveSync:d})=>d.prepareHandoff(n));return{get represented(){return r.represented},get held(){return r.held},yieldArticle:s,reclaimArticle:t,reconcile:()=>r.reconcile(),resume:()=>r.resume(),commit:()=>r.commit()&&i()}}async function p(e,{signal:n,deadline:f=15e3}={}){let i=Date.now()+f;for(;e._morphInFlight;){if(n?.aborted)throw e._handoffHeld=!1,l("the switch was cancelled","aborted");if(Date.now()>=i)throw e._handoffHeld=!1,l("the apply did not settle","timeout");await new Promise(t=>setTimeout(t,1))}let s=()=>e._pendingHtml!=null||e._pendingExternal!=null;return{get represented(){return e._represented},get held(){let t=e._represented;return e._pendingHtml!=null&&(t=u(t,{bytes:e._pendingHtml,etag:e._pendingEtag??null,seq:e._pendingSeq??null})),e._pendingExternal&&(t=u(t,{bytes:e._pendingExternal.html,etag:e._pendingExternal.etag??null,seq:e._pendingExternal.seq??null})),t},async reconcile(){if(!(!e._handoff||e.isDestroyed)){for(let t=0;t<8;t++){if(e._morphInFlight){await new Promise(r=>setTimeout(r,1));continue}if(!s())return;await e._runPending()}if(s())throw l("the held frame could not be applied","load-failed")}},resume(){e._handoff&&(e._handoff=null,e._handoffHeld=!1,e._scheduleNextFrame())},commit(){return e._represented.bytes?(e._handoff=null,e._handoffHeld=!1,e.stop(),!0):!1}}}export{p as engineHandoff,c as readerHandoff};
1
+ import"./c-VHNSBD2M.js";var l=(e,n)=>Object.assign(new Error(`clayjs: ${e}`),{code:n}),u=(e,n)=>!e||n.seq===null||e.seq===null||n.seq>e.seq?n:e;function a({stream:e,apply:n,retire:f,yieldArticle:i=()=>!1,reclaimArticle:s=()=>!1}){let t=null,r=!1;e.adopt({onSnapshot:o=>(t=u(t,o),!0)});let d=()=>{let o=t;return t=null,o};return{get represented(){return e.represented},get held(){return t??e.represented},yieldArticle(){return r||!i()?!1:(r=!0,!0)},reclaimArticle(){return!r||!s()?!1:(r=!1,!0)},reconcile(){let o=d();return o&&!n(o)?Promise.reject(l("the switch could not apply the saved file","load-failed")):Promise.resolve()},resume(){e.adopt({onSnapshot:n});let o=d();o&&n(o)},commit(){if(!r){let o=d();if(o&&!n(o))return!1}return e.represented.bytes===null?!1:(e.stop(),f())}}}async function c({stream:e,options:n,apply:f,retire:i,yieldArticle:s=()=>!1,reclaimArticle:t=()=>!1}){if(e)return a({stream:e,apply:f,retire:i,yieldArticle:s,reclaimArticle:t});let r=await import("./sync/live-sync-RGQMMWK2.js").then(({liveSync:d})=>d.prepareHandoff(n));return{get represented(){return r.represented},get held(){return r.held},yieldArticle:s,reclaimArticle:t,reconcile:()=>r.reconcile(),resume:()=>r.resume(),commit:()=>r.commit()&&i()}}async function p(e,{signal:n,deadline:f=15e3}={}){let i=Date.now()+f;for(;e._morphInFlight;){if(n?.aborted)throw e._handoffHeld=!1,l("the switch was cancelled","aborted");if(Date.now()>=i)throw e._handoffHeld=!1,l("the apply did not settle","timeout");await new Promise(t=>setTimeout(t,1))}let s=()=>e._pendingHtml!=null||e._pendingExternal!=null;return{get represented(){return e._represented},get held(){let t=e._represented;return e._pendingHtml!=null&&(t=u(t,{bytes:e._pendingHtml,etag:e._pendingEtag??null,seq:e._pendingSeq??null})),e._pendingExternal&&(t=u(t,{bytes:e._pendingExternal.html,etag:e._pendingExternal.etag??null,seq:e._pendingExternal.seq??null})),t},async reconcile(){if(!(!e._handoff||e.isDestroyed)){for(let t=0;t<8;t++){if(e._morphInFlight){await new Promise(r=>setTimeout(r,1));continue}if(!s())return;await e._runPending()}if(s())throw l("the held frame could not be applied","load-failed")}},resume(){e._handoff&&(e._handoff=null,e._handoffHeld=!1,e._scheduleNextFrame())},commit(){return e._represented.bytes?(e._handoff=null,e._handoffHeld=!1,e.stop(),!0):!1}}}export{p as engineHandoff,c as readerHandoff};
@@ -1,6 +1,6 @@
1
- import{F as mt,K as ot,O as $e,r as Ie,v as Le,w as ft,x as De}from"./c-EXKHPOVC.js";import{a as Ae,d as pt,g as Oe,h as ve}from"./c-L5VFATT6.js";import{f as Pe,o as Re}from"./c-XQSXKIKM.js";import{a as gt,c as Be}from"./c-67ILSNPR.js";import{b as Ne}from"./c-W4JCVLAB.js";import{B as w,C as zt,D as We,E as Ft,F as Ue,G as Ge,a as _e,d as P,e as S,f as He,h as J,i as ze,l as Fe,o as z,r as Ht,t as Ke,u as Ve,x as je,y as qe}from"./c-44B5ODN7.js";import{D as ut,E as Me,F as R,G as A,H as N,I,J as k,K as dt,L as we,O as Y,T as Se,U as ht,V as Nt,W as Te,X as Ee,Y as Ce,b as C,d as Pt,f as at,g as ge,h as Rt,j as be,l as ye,m as g,oa as nt,p as ke,q as xe}from"./c-QIXT3Q7C.js";import{a as H}from"./c-E4IBSAQM.js";var Ye=new WeakMap;function Je(n){let t=Ye.get(n);if(t)return t;t={};for(let[e,o]of I(n.attrs.cols).entries()){let s=[];n.forEach(r=>{e<r.childCount&&s.push(r.child(e).textContent.trim())}),t[o]=Ee(n.attrs.cols[o].kind,s)}return Ye.set(n,t),t}var Cs=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),As=Object.freeze({text:"Text",number:"Number",date:"Date"});var Kt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Oe(e))s[r]=o&&o.has(r)?o.get(r):ve(e,r);return e.name==="board"&&Object.assign(s,Le(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Ie(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Xe=n=>n===void 0?n:JSON.parse(JSON.stringify(n)),qn=(n,t)=>{let e={},o=n.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(e[r]=Xe(s))}),e.t=t.t,e};function Bs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...Xe(d.fields??{})}:qn(n,d);return{b:d,type:g.nodes.opaque_block,fields:a,opaque:!0}}let u=g.nodes[d.t]??g.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Kt(n,d,u)}}},s=t.visible.map(d=>{let u=e?.get(d);return u?{b:d,node:u}:o(d)}),r=new Map(s.map((d,u)=>[d.b.id,u])),i=d=>s[d].node?s[d].node.attrs.parent:s[d].fields.parent,l=d=>(d.b.recovered?n.gone._map.get(mt(d.b.sourceKey,"parent")):n.attrs.get(d.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let d of r.keys()){let u=new Map,a=[],h=d;for(;r.has(h)&&!u.has(h);)u.set(h,a.length),a.push(h),h=i(r.get(h));if(!u.has(h))continue;let f=a.slice(u.get(h)).reduce((b,x)=>{let O=l(s[r.get(b)]),_=l(s[r.get(x)]);return O.clock<_.clock||O.clock===_.clock&&O.client<_.client?b:x}),m=r.get(f);s[m].node&&(s[m]=o(s[m].b)),s[m].fields.parent=null}let c=s.map(({b:d,node:u,type:a,fields:h,opaque:p})=>{if(u)return u;if(p){let b=[];for(let x of d.runs)x.hole||(x.br?b.push(g.nodes.hard_break.create()):b.push(g.text(x.text,x.marks)));return a.create({id:d.id,pos:null,raw:h},b)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return Y(g,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let b of d.runs)b.hole||(b.br?m.push(g.nodes.hard_break.create()):m.push(g.text(b.text,b.marks)));return a.create(f,m)});return c.length?g.nodes.doc.create(null,c):g.nodes.doc.createAndFill()}var E=n=>({status:"refused",code:n}),bt=n=>JSON.parse(JSON.stringify(n)),Wn=["title","owner","due"],Un=/^\d{4}-\d{2}-\d{2}$/,yt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&Un.test(t):t===null||typeof t=="string"&&t.length>0,Gn=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function Qe(n,t){let e=t>0?n[t-1]:null,o=n.slice(t).find(r=>e===null||r>e)??null,s=r=>(e===null||r>e)&&(o===null||r<o);for(let[r,i]of[[e,o],[null,o],[e,null]]){if(r!==null&&!R(r)||i!==null&&!R(i)||r!==null&&i!==null&&r>=i)continue;let l=A(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Vt(n,t,e){let o=n.map(t),s=e>0?o[e-1]:null,r=e;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===e)return{pos:Qe(o,e),rekey:[]};let i=o.slice(r).find(c=>c>s)??null,l=[];for(let c=e,d=s;c<=r;c++)l.push(d=Qe(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var kt=(n,t,e)=>{let{pos:o,rekey:s}=Vt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function qs({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=$e(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Kt(n,a,g.nodes.board);return{columns:bt(h.columns??{}),cards:bt(h.cards??{})}},r=(u,a,h,p)=>{let f=ot(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)De(n,u,a,h);else for(let m of["columns","cards"])nt(a[m])!==nt(h[m])&&n.gone.set(mt(f,m),bt(h[m]))},Ae),t?.stopCapturing(),o(),p},i=(u,a,h=null)=>I(Object.fromEntries(Object.entries(u.cards).filter(([p,f])=>f.col===a&&p!==h))),l=(u,a)=>a===void 0?u.length:a===null?0:u.indexOf(a)+1,c=(u,a)=>a!=null&&!u.includes(a),d=(u,a)=>{let h=s(u);return h?a(h,bt(h)):E("missing-board")};return{read:u=>s(u),removed(u){return s(u)?ot(u)?{columns:{},cards:{}}:ft(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return E("invalid-value");let m=I(p.columns);if(c(m,h))return E("missing-destination");let b=k("c");return f.columns[b]={pos:kt(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:b})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?E("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):E("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return E("missing-column");let m=I(p.columns).filter(O=>O!==a);if(c(m,h))return E("missing-destination");let b=l(m,h),x=I(p.columns);return[...m.slice(0,b),a,...m.slice(b)].every((O,_)=>O===x[_])?{status:"unchanged"}:(f.columns[a].pos=kt(f.columns,m,b),r(u,p,f,{status:"moved"}))}),removeColumn:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.columns,a)?(delete p.columns[a],r(u,h,p,{status:"removed",cards:i(h,a).length})):E("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):E("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(b,x)=>{if(!Object.hasOwn(b.columns,a))return E("missing-column");if(!yt("title",h)||!yt("owner",p)||!yt("due",f))return E("invalid-value");let O=i(b,a);if(c(O,m))return E("missing-destination");let _=k("k");return x.cards[_]={pos:kt(x.cards,O,l(O,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,b,x,{status:"created",id:_})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return E("missing-card");if(!Gn(h)||!Object.keys(h).length||Object.keys(h).some(b=>!Wn.includes(b)))return E("invalid-field");if(Object.entries(h).some(([b,x])=>!yt(b,x)))return E("invalid-value");let m={...p.cards[a]};for(let[b,x]of Object.entries(h))x===null?delete m[b]:m[b]=x;return nt(m)===nt(p.cards[a])?{status:"unchanged"}:(f.cards[a]=m,r(u,p,f,{status:"changed"}))}),moveCard:(u,a,{columnId:h,afterId:p=null}={})=>d(u,(f,m)=>{if(!Object.hasOwn(f.cards,a))return E("missing-card");if(!Object.hasOwn(f.columns,h))return E("missing-column");let b=i(f,h,a);if(c(b,p))return E("missing-destination");let x=l(b,p),O=f.cards[a];if(O.col===h){let _=i(f,h);if([...b.slice(0,x),a,...b.slice(x)].every((ct,jn)=>ct===_[jn]))return{status:"unchanged"}}return m.cards[a]={...O,col:h,pos:kt(m.cards,b,x)},r(u,f,m,{status:"moved"})}),removeCard:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.cards,a)?(delete p.cards[a],r(u,h,p,{status:"removed"})):E("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):E("missing-card")})}}var xt="page-history-intent",Yn=500,Jn=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},Xn=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function qt(n,t,e,o){return{kind:"insert",blockId:Jn(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:Xn(n),at:Date.now()}}function Ys(n,t){return!n||!t||n.kind!==t.kind?!1:t.kind==="compose"?n.id===t.id:n.blockId!==t.blockId||t.at-n.at>Yn?!1:t.kind==="insert"?!t.replaced&&t.from===n.end&&t.marks===n.marks&&!(/\s$/.test(n.text)&&/^\S/.test(t.text)):t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var Qn={deleteContentBackward:-1,deleteContentForward:1},jt=new WeakMap,Zn=1e3,Wt="page-derived";function to(n){let t=jt.get(n)??null;return jt.delete(n),t}function eo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>Zn||n.getMeta(He)||n.steps.length!==1)return null;let e=n.steps[0];if(e.slice?.size!==0||e.from===e.to)return null;let o=n.before.resolve(e.from),s=n.before.resolve(e.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:e.from,to:e.to,at:t.at}}function Js(n,t=null){let e=t?to(t):null,o=n.filter(i=>!i.getMeta(Wt));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(xt)??eo(s,e)}function Xs(){return new C.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(xt,qt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=Qn[t.inputType];return e&&jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function no(n,t){if(!n||!/<table[\s>]/i.test(n))return null;let e=t.defaultView?.DOMParser??globalThis.DOMParser;if(!e)return null;let o=new e().parseFromString(n,"text/html").body,s=[...o.querySelectorAll("table")].filter(d=>!d.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let d of r.querySelectorAll("table, style, script, template, meta, title"))d.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(d=>d.closest("table")===i).map(d=>[...d.children].filter(u=>u.tagName==="TD"||u.tagName==="TH").map(u=>dt(je.parse(u,{topNode:g.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function oo(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=ht(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function Ze(n,t,e=globalThis.document){let o=null;try{o=no(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=oo(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Mt(n,{header:t=n.length>1}={}){let e=Math.max(0,...n.map(a=>a.length));if(!e)return null;let o=t?n[0]:[],s=t?n.slice(1):n,r=Array.from({length:e},()=>k("c")),i=N(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ut(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=N(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[k("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return Y(g,k(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:so,TextSelection:ro}=C,Ut=g.nodes;var on=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Ut.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function V(n,t){if(!t)return null;let e=on(n,t.table);if(!e)return null;let o=[];e.node.forEach(p=>o.push(p.attrs.id));let s=I(e.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let l=Math.min(...r),c=Math.max(...r),d=Math.min(...i),u=Math.max(...i),a=[],h=e.pos+1;return e.node.forEach((p,f,m)=>{if(m>=l&&m<=c){let b=[],x=h+1;p.forEach((O,_,ct)=>{ct>=d&&ct<=u&&b.push({cell:O,pos:x}),x+=O.nodeSize}),a.push(b)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var st=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Ut.table_cell&&o>=3)return{table:e.node(o-2).attrs.id,row:e.node(o-1).attrs.id,col:e.node(o).attrs.col,start:e.start(o)};return null};function wt(n,t,e){let o=st(n.state.doc,t),s=st(n.state.doc,e);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=n.state.tr.setSelection(ro.create(n.state.doc,s.start)).setMeta(S,r);n.dispatch(i);let l=V(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return P(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function fr(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Ut.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,l=(c,d)=>{let u=t+1;for(let a=0;a<c;a++)u+=s.child(a).nodeSize;u++;for(let a=0;a<d;a++)u+=s.child(c).child(a).nodeSize;return u+1};return e==="row"?wt(n,l(o,0),l(o,i)):wt(n,l(0,o),l(r,o))}var io=new Set(["Shift","Control","Alt","Meta","CapsLock"]),lo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function co(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>lo(ut(dt(i)))).join(" ")).join(`
2
- `),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of n.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:l}of r){let c=i.appendChild(t.createElement("td"));c.dataset.col=l.attrs.col,c.append(qe.serializeFragment(l.content,{document:t}))}}return{text:e,html:o.outerHTML}}function tn(n,t){let e=V(n.doc,S.getState(n));if(!e)return!1;if(t){let o=n.tr;for(let s of[...e.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(S,S.getState(n)),t(w(o))}return!0}var en=(n,t,e)=>{let{text:o,html:s}=co(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},ao=(n,t)=>(e,o,s)=>{let r=S.getState(e),i=V(e.doc,r);if(!i||!s)return!1;let l=[],c=I(i.node.attrs.cols);i.node.forEach(a=>l.push(a.attrs.id));let d=Math.max(0,Math.min(l.length-1,l.indexOf(r.head[0])+n)),u=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[1])+t));return o&&o(e.tr.setMeta(S,{...r,head:[l[d],c[u]]})),!0},nn=(n,t)=>{let e=t.target?.closest?.("td");if(!e||!n.dom.contains(e))return null;try{return n.posAtDOM(e,0)}catch{return null}};function mr(){let n=null;return new so({key:S,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(S);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(pt)?null:V(s.doc,e)?e:null}},props:{attributes:t=>S.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>S.getState(t.state)?t.state.selection:null,decorations(t){let e=V(t.doc,S.getState(t));return e?Pt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Pt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!S.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(S,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return tn(o,t.dispatch);if(e.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(s)return ao(...s)(o,t.dispatch,t)}return io.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(S,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&S.getState(t.state)&&t.dispatch(t.state.tr.setMeta(S,null));let o=nn(t,e);if(o===null)return!1;if(e.shiftKey){let c=S.getState(t.state),d=(c&&uo(t.state.doc,c))??t.state.selection.$anchor.pos;return st(t.state.doc,d)?(e.preventDefault(),wt(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=nn(t,c);if(d===null)return;let u=st(t.state.doc,r),a=st(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=S.getState(t.state);u.row===a.row&&u.col===a.col&&!h||h&&h.head[0]===a.row&&h.head[1]===a.col||(c.preventDefault(),wt(t,r,d))},l=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",l),n=null};return n?.(),n=l,s.addEventListener("mouseover",i),s.addEventListener("mouseup",l),!1},copy(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),!0)},cut(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),tn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function uo(n,t){let e=on(n,t.table),o=null;return e?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=e.pos+1+r+1;s.forEach(l=>{l.attrs.col===t.anchor[1]&&(o=i+1),i+=l.nodeSize})}),o}var sn=n=>{let t=V(n.doc,S.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var Gt=new WeakMap;var{Plugin:ho,TextSelection:j}=C,T=g.nodes,Jt=256*1024,B=n=>I(n.attrs.cols),rn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===T.table){let o=t.node(e),s=e<t.depth?t.index(e):0,r=e+1<t.depth?t.index(e+1):0;return{table:o,pos:t.before(e),row:s,cell:r}}return null},rt=(n,t,e,o)=>{let s=n.nodeAt(t);if(!s||!s.childCount)return null;e=Math.max(0,Math.min(e,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(e).childCount-1));let r=t+1;for(let i=0;i<e;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(e).child(i).nodeSize;return r+1},St=(n,t=A())=>T.table_row.create({id:k("r"),pos:t},n.map(e=>T.table_cell.create({col:e}))),L=(n,t,e)=>T.table.create({...n.attrs,...t},e);function D(n,t,e){let o=rn(n);if(!o)return!1;let s=e(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:l=o.cell}=s,c=n.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),d=rt(c.doc,o.pos,i,l);d!==null&&c.setSelection(j.create(c.doc,d)),t(w(c))}return!0}function F(n,t,e,o=null,s=null,r=null){r??=o?n.doc.resolve(o.from).index(0):n.selection.$head.index(0);let i=n.doc.child(r),l=0;for(let h=0;h<r;h++)l+=n.doc.child(h).nodeSize;let c=i.isTextblock&&(i.content.size===0||o?.from===l+1&&o?.to===l+i.nodeSize-1),d=n.doc.maybeChild(r+1),u=c?i.attrs.pos:A(i.attrs.pos,d?.attrs.pos??null),a=e.type.create({...e.attrs,pos:u,parent:i.attrs.parent??null},e.content);if(t){let h=n.tr;o&&h.delete(o.from,o.to);let p=h.mapping.map(l),f=h.doc.child(r),m=c?p:p+f.nodeSize;if(h.replaceWith(m,c?p+f.nodeSize:m,a),s){let b=s.type.create({...s.attrs,pos:A(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,b)}h.setSelection(j.create(h.doc,rt(h.doc,m,0,0))),t(w(h).scrollIntoView())}return!0}function ln(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>k("c")),o=N(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=N(null,null,n).map(l=>St(e,l));return T.table.create({id:k(),cols:s},i)}var Xt=n=>(t,e)=>{let o=rn(t);if(!o||t.selection.$head.parent.type!==T.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return n==="down"?r++:(i+=n,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?n===-1?!0:po(t,e,o,i):(e&&e(t.tr.setSelection(j.create(t.doc,rt(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function po(n,t,e,o){let s=[...e.table.content.content];if(s.push(St(B(e.table),A(s.at(-1).attrs.pos,null))),t){let r=n.tr.replaceWith(e.pos,e.pos+e.table.nodeSize,L(e.table,{sort:null},s));r.setSelection(j.create(r.doc,rt(r.doc,e.pos,s.length-1,o))),t(w(r).scrollIntoView())}return!0}var fo=Xt(1),mo=Xt(-1),go=Xt("down"),bo=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=A(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,St(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Lr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=T.table_row.create(r.attrs,B(e).map(i=>T.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:L(e,{sort:null},s),row:Math.min(o.row,s.length-1)}}),cn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Vt(t,c=>n[c]?.pos??"",e),l={...n,[o]:{...s,pos:r}};for(let[c,d]of i)l[c]={...l[c],pos:d};return l},Dr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=k("c"),c=cn(o.attrs.cols,r,i,l,{name:`Column ${r.length+1}`}),d=o.content.content.map(u=>{let a=[...u.content.content];return a.splice(i,0,T.table_cell.create({col:l})),T.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),$r=(n,t)=>D(n,t,(e,o)=>{let s=B(e);if(s.length<=1)return null;let r={...e.attrs.cols};delete r[s[o.cell]];let i=e.content.content.map(l=>T.table_row.create(l.attrs,l.content.content.filter((c,d)=>d!==o.cell)));return{table:L(e,{cols:r,sort:e.attrs.sort?.col===s[o.cell]?null:e.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),_r=n=>(t,e)=>D(t,e,(o,s)=>{let r=s.row+n;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[l]=i.splice(s.row,1);i.splice(r,0,l);let c=A(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=T.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Br=n=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+n;if(i<0||i>=r.length)return null;let l=[...r],[c]=l.splice(s.cell,1);l.splice(i,0,c);let d=cn(o.attrs.cols,l.filter(a=>a!==c),i,c,o.attrs.cols[c]),u=o.content.content.map(a=>{let h=[...a.content.content],[p]=h.splice(s.cell,1);return h.splice(i,0,p),T.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),yo=48,ko=1200,Pr=160,an=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(ko,Math.max(yo,n))):null,Rr=n=>(t,e)=>D(t,e,o=>{let s=B(o);if(!s.some(i=>o.attrs.cols[i].width))return null;let r={};for(let i of s){let{width:l,...c}=o.attrs.cols[i];r[i]=c}return{table:L(o,{cols:r},o.content),cell:Math.max(0,s.indexOf(n))}}),Nr=(n,t)=>(e,o)=>D(e,o,s=>{let r={...s.attrs.cols},i=!1;for(let[l,c]of Object.entries(n)){let d=an(c);!r[l]||d===null||r[l].width===d||(r[l]={...r[l],width:d},i=!0)}return i?{table:L(s,{cols:r},s.content),cell:B(s).indexOf(t)}:null}),Hr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:an(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:l,...c}=r,d={...s.attrs.cols,[n]:i===null?c:{...r,width:i}};return{table:L(s,{cols:d},s.content),cell:B(s).indexOf(n)}}),zr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!String(t).trim())return null;let r={...s.attrs.cols,[n]:{...s.attrs.cols[n],name:String(t).trim()}};return{table:L(s,{cols:r},s.content)}}),Fr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Te.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[n],l={...s.attrs.cols,[n]:t==="auto"?i:{...s.attrs.cols[n],kind:t}};return{table:L(s,{cols:l,sort:s.attrs.sort?.col===n?null:s.attrs.sort},s.content)}}),Kr=(n,t="asc")=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!["asc","desc"].includes(t))return null;let r=B(s).indexOf(n),i=Je(s)[n],l=[...s.content.content].map((u,a)=>({row:u,previous:a,text:u.child(r).textContent.trim()}));l.sort((u,a)=>{if(!u.text||!a.text)return!u.text&&!a.text?u.previous-a.previous:u.text?-1:1;let h=i==="number"?Nt(u.text):u.text,p=i==="number"?Nt(a.text):a.text;if(h==null||p==null)return h==null&&p==null?u.previous-a.previous:h==null?1:-1;let f=i==="number"?h-p:i==="date"?h<p?-1:h>p?1:0:h.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return f?t==="asc"?f:-f:u.previous-a.previous});let c=N(null,null,l.length),d=l.map(({row:u},a)=>T.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),Yt=(n,t=null)=>(e,o)=>D(e,o,(s,r)=>{let i=B(s),l=t?.row??r.row,c=t?.cell??r.cell,d=[...s.content.content];n.forEach((a,h)=>{let p=l+h;p>=d.length&&d.push(St(i,A(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,b)=>{c+b<i.length&&(f[c+b]=T.table_cell.create({col:i[c+b]},we(g,m)))}),d[p]=T.table_row.create(d[p].attrs,f)});let u=Math.max(1,...n.map(a=>a.length));return{table:L(s,{sort:null},d),row:l+n.length-1,cell:Math.min(c+u-1,i.length-1)}}),xo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function Mo(n,t){let e=t.clipboardData;if(!e||e.files?.length)return!1;let o=n.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=sn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=Ze(e.getData("text/html"),e.getData("text/plain"),n.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Yt(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,n.dispatch);if(s)return Yt(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===T.table_cell)return i.width*i.height<2?!1:Yt(i.grid)(o,n.dispatch);if(i.width*i.height<2||i.own||i.height<2&&!/<table[\s>]/i.test(e.getData("text/html")))return!1;let l=Mt(i.grid,{header:i.height>1});if(!l)return!1;if(xo(l)>Jt)return H("This paste is too large for one table.","error"),!0;let{from:c,to:d,empty:u,$from:a,$to:h}=o.selection;if(!u&&a.index(0)!==h.index(0)){let p=o.tr.deleteSelection();return F(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(j.create(p.doc,f.selection.from)),n.dispatch(w(p).scrollIntoView())},l)}return F(o,n.dispatch,l,u?null:{from:c,to:d})}var Vr=at.keymap({Tab:fo,"Shift-Tab":mo,Enter:go,"Mod-Enter":bo(!0)});function wo(n,t){let e=Gt.get(t.target),o=e?.getPos();if(o==null||t.button||t.shiftKey||!n.editable)return!1;t.preventDefault();let s=t.clientX<e.contentDOM.getBoundingClientRect().left;return n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function jr(){return new ho({props:{handlePaste:Mo,handleDOMEvents:{mousedown:wo},handleClickOn(n,t,e,o,s,r){if(e.type!==T.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&Gt.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(pt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===T.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==T.table||!r.attrs.sort)return;let l=o.get(r.attrs.id),c=r.attrs.sort.col;if(!l)return;let d=h=>Object.fromEntries(h.content.content.map(p=>[p.attrs.id,p.content.content.find(f=>f.attrs.col===c)?.textContent])),u=d(l),a=d(r);(Object.keys(u).length!==Object.keys(a).length||Object.keys(u).some(h=>u[h]!==a[h]||!Object.hasOwn(a,h)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta(Wt,!0):null}})}function qr(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==T.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?g.text(e):[]);return n.dispatch(s.setSelection(j.create(s.doc,t+1+e.length))),!0}function Wr(n,t,e,o){let s=rt(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,s))),!0)}var{TextSelection:So}=C,Qt=g.nodes,To=Object.freeze(["To do","In progress","Done"]),un=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function Zt(n=To){let t=N(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[k("c"),{pos:t[s],name:o}]));return Qt.board.create({id:k(),columns:e,cards:{}})}function dn(n,t,e=Zt(),o=null,s=null){let r=n.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(n.selection.head)).index(0);let i=J(r.doc),l=r.doc.child(s),c=l.isTextblock&&l.content.size===0,d=c?s:i[s].subEnd,u=c?i[s].at:i[d].end,a=i[d+1]?.node.attrs.pos??null,h=l.attrs.parent??null,p=c?l.attrs.pos:un(i[d].node.attrs.pos,a),f=Qt.board.create({...e.attrs,pos:p,parent:h}),m=Qt.paragraph.create({id:k(),pos:un(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(So.create(r.doc,u+f.nodeSize+1)),t&&t(w(r).scrollIntoView()),!0}function hn(n){let t=[];return n.forEach(e=>{e.type===g.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function ni(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===g.nodes.heading&&(e=r.textContent),r.type===g.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var pn=new Set(["page-format-unsupported","unsupported-host"]),Eo="This host can't store that yet, so nothing was added.",Co="That didn't go through. Try again.",Ao="That couldn't be added here.";function fn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:pn.has(t?.code)||pn.has(t?.status)?Eo:t?.retry===!0?Co:Ao;n.isDestroyed||(P(n,e),H(e,"error"))}async function Tt(n,t){if(typeof n.runFormatCommand!="function")return fn(n,{code:"page-format-unsupported"}),{ok:!1,code:"page-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(fn(n,e),{ok:!1,code:e?.code??e?.status??"page-format-refused",retry:e?.retry===!0})}var{TextSelection:it}=C,v=g.nodes,q=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"toggle-h1",label:"Toggle heading 1",description:"Collapsible heading",icon:"H1",type:"toggle",attrs:{open:!0,level:1},aliases:["toggle heading"]},{key:"toggle-h2",label:"Toggle heading 2",description:"Collapsible heading",icon:"H2",type:"toggle",attrs:{open:!0,level:2},aliases:["toggle heading"]},{key:"toggle-h3",label:"Toggle heading 3",description:"Collapsible heading",icon:"H3",type:"toggle",attrs:{open:!0,level:3},aliases:["toggle heading"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"quote",label:"Quote",description:"Set text apart as a quotation",icon:"\u201C",type:"quote",hint:'"',aliases:["blockquote","quotation","cite"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Oo=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"toc",label:"Table of contents",description:"Links to this page's headings",icon:"\u2261",aliases:["toc","contents","outline","index"],insert:"toc"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"},{key:"mention",label:"Mention",description:"Name someone on the page",icon:"@",aliases:["person","people","assign"],command:"mentions"},{key:"date",label:"Date",description:"Today, tomorrow or a calendar day",icon:"\u25A7",aliases:["calendar","today","tomorrow","due"],command:"dates"},{key:"emoji",label:"Emoji",description:"Insert one glyph",icon:"\u263A",aliases:["smiley","glyph","symbol"],command:"emoji"},{key:"import-markdown",label:"Import Markdown\u2026",description:"Turn a Markdown file into blocks",icon:"M\u2193",aliases:["md","markdown","import"],command:"importMarkdown"}],vo={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},te=n=>(Ne.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-WFMRX5RZ.js")),At=[...q,...Oo],gn=(n,t=At)=>hn(n.doc).length?[...t,vo]:t;function Ot(n){let t=n.type.name;return q.find(e=>e.type===t&&(!e.attrs||(t==="heading"||t==="toggle"?(e.attrs.level??null)===(n.attrs.level??null):t==="list_item"?e.attrs.kind===n.attrs.kind:!0)))??q[0]}var ee=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function G(n,t,e){let o=ee(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===v.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,v[e.type],{...r,...e.attrs||{}})}var bn=Object.freeze({status:"refused",code:"unsupported-format"}),Io=xe([]).type,Lo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(ke)&&(t=!0)}),t};function Q(n,t){return!n.isTextblock||n.type===v.opaque_block?!1:!Lo(n)||v[t.type].allowsMarkType(Io)}var yn=n=>n.type==="toggle"&&n.attrs?.level!=null,Et=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ne={ok:!1,code:"stale-target"};function kn(n,t,e){let o=()=>e.map(r=>Et(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ne;if(r.some(l=>!Q(n.state.doc.child(l),t)))return bn;let i=n.state.tr;for(let l of r)G(i,l,t);return n.dispatch(w(i).scrollIntoView()),n.focus(),{ok:!0}};return yn(t)?Tt(n,s):t.type==="quote"?import("./c-VBLFAQD2.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function xn(n,t,e=n.tr){let o=J(e.doc),{to:s}=ze(o,t),r=e.doc.child(t);return e.insert(s,v.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(it.create(e.doc,s+1))}var X=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function oe(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.divider.create({id:r,pos:i,parent:l}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function Do(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return oe(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.divider.create({id:k(),pos:c,parent:d}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function $o(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.toc.create({id:r,pos:i,parent:l,maxLevel:3}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function _o(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return $o(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.toc.create({id:k(),pos:c,parent:d,maxLevel:3}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function Bo(n,t){if(n.length<2||n.length>32)return 1/0;let e=-1,o=0;for(let s of n){let r=t.indexOf(s,e+1);if(r<0)return 1/0;o+=r-e-1,e=r}return o}function Mn(n,t){let e=t.trim().toLowerCase();if(!e)return n;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(c=>c.toLowerCase());if(r===e||i.includes(e))return[0,0];if(r.startsWith(e))return[1,0];if([...r.split(/\s+/),...i].some(c=>c.startsWith(e)))return[2,0];if([r,...i].some(c=>c.includes(e)))return[3,0];if(e.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(c=>c.startsWith(e)))return[4,0];let l=Math.min(...[r,s.key,...s.aliases||[]].map(c=>Bo(e,c.toLowerCase())));return l===1/0?null:[5,l]};return n.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function mn(n,t,e,o){let s=n.state,r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(e);return i.isTextblock&&i.content.size===0&&!Q(i,t)?bn:(t.insert==="divider"?r=Do(s,e,r):i.isTextblock&&i.content.size===0?r=G(r,e,t):(r=xn(s,e,r),r=G(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(w(r).scrollIntoView()),n.focus(),!0)}function Po(n,t,e=null){let o=n.state,s=o.doc.maybeChild(t)?.attrs.id??null,r=e&&{...e,text:o.doc.textBetween(e.from,e.to)};return Tt(n,()=>{let i=n.state;if((s===null?-1:Et(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ne;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=_o(i,Et(c.doc,s),c),n.dispatch(w(c).scrollIntoView()),n.focus(),{ok:!0}})}var Z=(n,t,e)=>import("./page/editor-EY2WAAGB.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Ro(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),Z(n,t,{})}function wn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return Re(n,t.insert==="image"?"image/*":"",Pe(s,e),o);if(t.insert==="csv")return Ct(n,o);if(t.insert==="table")return F(s,n.dispatch,ln(),o,null,e);if(t.insert==="board")return dn(s,n.dispatch,Zt(),o,e);if(t.insert==="chart")return te(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return Po(n,e,o);if(t.command)return Ro(n,t.command,o);if(!yn(t)&&t.type!=="quote")return mn(n,t,e,o);let r=s.doc.maybeChild(e)?.attrs.id??null,i=o&&{...o,text:s.doc.textBetween(o.from,o.to)};return Tt(n,()=>{let l=n.state,c=r===null?-1:Et(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ne:mn(n,t,c,i)})}var{InputRule:ie}=Rt,W=g.nodes,vt=(n,t,e)=>n.doc.rangeHasMark(t,e,g.marks.code)||!!g.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),tt=(n,t,e=["paragraph"],o=!1)=>new ie(n,(s,r,i,l)=>{let c=s.doc.resolve(i);return!s.selection.empty||c.depth!==1||c.parentOffset!==0||!e.includes(c.parent.type.name)||o&&l!==c.end()||vt(s,i,l)?null:w(G(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),No=new ie(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==W.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||vt(n,e,o)?null:w(oe(n.tr,s.index(0)))}),le=`\\s\\(\\[\\{'\u2018\u201C"`,Ho=new RegExp(`[${le}]`),se=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Sn=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,It=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,Tn=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},zo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||Tn(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Ho.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Fo=(n,t,e,o,s)=>{let r=s(t);if(!r||!n.selection.empty||e<0||e>o||o>n.doc.content.size)return null;let i=n.doc.resolve(e),l=n.doc.resolve(o);if(!i.sameParent(l)||!i.parent.inlineContent)return null;let[c,d,u,a]=t;if(vt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!zo(n,p)||Tn(c.slice(0,c.length-a.length))%2)return null;let f=c.length-(o-e);if(f<0)return null;let m=n.tr;f&&m.insertText(c.slice(-f),o,o);let b=p+h.length,x=b+u.length;return m.delete(x,e+c.length),m.delete(p,b),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),w(m)},En=(n,t)=>new ie(n,(e,o,s,r)=>Fo(e,o,s,r,t),{inCodeMark:!1}),et=(n,t,e)=>En(new RegExp(`(^|[${le}])${se(n)}${Sn(se(t))}(${se(t)})$`),()=>e.create()),Ko=En(new RegExp(`(^|[${le}])\\[${Sn("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=be(n[3].slice(2,-1));return t?g.marks.link.create({href:t}):null}),Vo=[et("**","**",g.marks.strong),et("__","__",g.marks.strong),et("*","*",g.marks.em),et("_","_",g.marks.em),et("`","`",g.marks.code),et("~~","~~",g.marks.strike),Ko],re=["paragraph","list_item"],jo=[tt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),tt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},re),tt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},re),tt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),re),tt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),tt(/^```$/,{type:"code_block"},["paragraph"],!0),No,...Vo];function qo(n,t,e,o,s){if(s!==" "||e!==o)return!1;let r=t.state,i=r.doc.resolve(e),l=i.parent;if(i.depth!==1||l.type!==W.paragraph||i.parentOffset!==1||l.textContent!=='"'||!t.editable||typeof t.runFormatCommand!="function")return!1;let c=()=>{t.isDestroyed||t.state.doc!==r.doc||t.dispatch(t.state.tr.insertText(" ",e,o))},d=i.before(1);return import("./c-VBLFAQD2.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Oi=()=>{let n=Rt.inputRules({rules:jo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>qo(n,e,o,s,r)||t(e,o,s,r),n},Wo=/^\s*\|(.*)\|\s*$/;function Uo(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==W.paragraph||e.parentOffset!==e.parent.content.size||vt(n,e.start(),e.end()))return!1;let s=Wo.exec(e.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(l=>l.trim());if(!r.some(Boolean))return!1;let i=Mt([r,r.map(()=>"")],{header:!0});return F(n,t,i,{from:e.start(),to:e.end()})}var vi=()=>at.keymap({Enter:(n,t,e)=>!It(null,e)&&Uo(n,t)});function Ii(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parentOffset!==0)return!1;let s=e.parent;return s.type===W.heading||s.type===W.callout||s.type===W.quote||s.type===W.code_block&&s.content.size===0?(t&&t(w(n.tr.setNodeMarkup(e.before(),W.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:In,PluginKey:Ln,TextSelection:$t,NodeSelection:Go}=C,Dn=g.marks,U=g.nodes,Dt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",$n=n=>{let t=gt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Lt=(n,t)=>n.state.doc.child(t).attrs.id,Yo=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Cn=["aria-haspopup","aria-controls","aria-activedescendant"],Jo="That block is no longer available.",he="This block holds content from a newer version, so it can't be converted here.";function ce(n){let t=n.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:n.innerWidth,height:n.innerHeight}}function Xo(n,t,e,o=0){let s=$,r=Math.min(t,Math.max(0,n.width-s*2));return{left:n.left+(n.width-r)/2,top:Math.max(n.top+s,n.top+n.height-e-o-s),width:r}}function Qo(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function Zo(n){if(!n)return;let t=()=>H("Link copied"),e=()=>H("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(Qo(n)).then(t,e)}var _n=[{key:"up",label:"Move up",icon:"up",hint:`${Dt}\u21E7\u2191`,run:n=>Ht(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Dt}\u21E7\u2193`,run:n=>Ht(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ke(n.state,n.dispatch),n.state.doc===t&&(P(n,"Indent works on list items and inside toggles."),H("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Ve(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Dt}D`,run:n=>Ue(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ft(n.state,n.dispatch)},{key:"turn",label:"Turn into",icon:"turn",hint:"\u203A",only:"text",run:(n,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"link",run:(n,t,e)=>Zo(n.state.doc.child(e).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"alt",only:"image",focus:!1,run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-SO63UGPQ.js").then(s=>s.setImageAttrs(n,o,{width:null}))}},{key:"chart",label:"Chart this table",icon:"chart",only:"table",run:(n,t,e)=>{let o=Yo(n.state.doc,e);return te(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>Ct(n,null,n.state.doc.child(e).attrs.id)}],ts=n=>{if(!(n.selection instanceof z))return[];let t=$n(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===U.image,s=t.length===1&&t[0].node.type===U.table;return _n.filter(r=>r.only==="text"?e:r.only==="image"?o:r.only==="table"?s:!0)},M=n=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,K={plus:M('<path d="M8 3.5v9M3.5 8h9"/>'),grip:M('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:M('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:M('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:M('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:M('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:M('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:M('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:M('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:M('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:M('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>'),gear:M('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),close:M('<path d="M4 4l8 8M12 4l-8 8"/>'),up:M('<path d="M8 13V3.5M4 7.5 8 3.5l4 4"/>'),down:M('<path d="M8 3v9.5M4 8.5l4 4 4-4"/>'),indent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M2.5 6l2.5 2-2.5 2"/>'),outdent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M5 6 2.5 8 5 10"/>'),duplicate:M('<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v5A1.5 1.5 0 0 0 4 9.5h.5"/>'),trash:M('<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5"/>'),turn:M('<path d="M3 5.5h9.5M10 3l2.5 2.5L10 8M13 10.5H3.5M6 8l-2.5 2.5L6 13"/>'),chart:M('<path d="M3 13V3M3 13h10.5M6 10.5V8M9 10.5V5.5M12 10.5V7"/>'),csv:M('<path d="M4 1.5h5L12.5 5v9.5h-8.5zM9 1.5V5h3.5M8 7.5v5M6 10.5l2 2 2-2"/>'),alt:M('<path d="M2.5 12.5 5.5 4l3 8.5M3.6 9.5h3.8M10 12.5V7.5M10 8.5c.4-.7 1.1-1 2-1h.5"/>'),small:M('<rect x="5" y="5" width="6" height="6" rx="1"/>'),medium:M('<rect x="3.5" y="3.5" width="9" height="9" rx="1.2"/>'),full:M('<rect x="1.5" y="3.5" width="13" height="9" rx="1.2"/>')},ae=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Bn=new Set(["strong","em","link"]),es=new Set(["up","down","indent","outdent"]),ns=204,os=52,$=8,Pn=new Set(["bullet","ordered","check"]),ss=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],rs=new Set(["paragraph","heading","list_item"]),lt=n=>{let t=n.selection;if(t instanceof z)return $n(n).map(l=>l.i);let{$from:e,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),n.doc.childCount-1),i=[];for(let l=e.index(0);l<=r;l++)i.push(l);return i},Rn=n=>lt(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==U.code_block}),Nn=(n,t)=>n.type===U.list_item&&n.attrs.kind===t,Hn=(n,t)=>{let e=Rn(n);return e.length>0&&e.every(o=>Nn(n.doc.child(o),t))},is=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===U.hard_break?`
1
+ import{F as mt,K as ot,O as $e,r as Ie,v as Le,w as ft,x as De}from"./c-EXKHPOVC.js";import{a as Ae,d as pt,g as Oe,h as ve}from"./c-L5VFATT6.js";import{f as Pe,o as Re}from"./c-4TWARTLS.js";import{a as gt,c as Be}from"./c-Q5KAQJAG.js";import{b as Ne}from"./c-W4JCVLAB.js";import{B as w,C as zt,D as We,E as Ft,F as Ue,G as Ge,a as _e,d as P,e as S,f as He,h as J,i as ze,l as Fe,o as z,r as Ht,t as Ke,u as Ve,x as je,y as qe}from"./c-TMT5TL65.js";import{D as ut,E as Me,F as R,G as A,H as N,I,J as k,K as dt,L as we,O as Y,T as Se,U as ht,V as Nt,W as Te,X as Ee,Y as Ce,b as C,d as Pt,f as at,g as ge,h as Rt,j as be,l as ye,m as g,oa as nt,p as ke,q as xe}from"./c-QIXT3Q7C.js";import{a as H}from"./c-OI2BYWVV.js";var Ye=new WeakMap;function Je(n){let t=Ye.get(n);if(t)return t;t={};for(let[e,o]of I(n.attrs.cols).entries()){let s=[];n.forEach(r=>{e<r.childCount&&s.push(r.child(e).textContent.trim())}),t[o]=Ee(n.attrs.cols[o].kind,s)}return Ye.set(n,t),t}var Cs=Object.freeze({text:"Aa",number:"#",date:"\u{1F4C5}"}),As=Object.freeze({text:"Text",number:"Number",date:"Date"});var Kt=(n,t,e)=>{let o=n.attrs.get(t.baseId),s={};for(let r of Oe(e))s[r]=o&&o.has(r)?o.get(r):ve(e,r);return e.name==="board"&&Object.assign(s,Le(n.boardFields,t.baseId)),e.name==="table"&&Object.assign(s,Ie(n.tableFields,t.baseId,{cols:s.cols,rows:s.rows})),s},Xe=n=>n===void 0?n:JSON.parse(JSON.stringify(n)),qn=(n,t)=>{let e={},o=n.attrs.get(t.baseId);return o&&o.forEach((s,r)=>{r!=="pos"&&(e[r]=Xe(s))}),e.t=t.t,e};function Bs(n,t,e=null){let o=d=>{if(d.opaque){let a=d.recovered?{...Xe(d.fields??{})}:qn(n,d);return{b:d,type:g.nodes.opaque_block,fields:a,opaque:!0}}let u=g.nodes[d.t]??g.nodes.paragraph;return{b:d,type:u,fields:{...d.fields??Kt(n,d,u)}}},s=t.visible.map(d=>{let u=e?.get(d);return u?{b:d,node:u}:o(d)}),r=new Map(s.map((d,u)=>[d.b.id,u])),i=d=>s[d].node?s[d].node.attrs.parent:s[d].fields.parent,l=d=>(d.b.recovered?n.gone._map.get(mt(d.b.sourceKey,"parent")):n.attrs.get(d.b.baseId)?._map.get("parent"))?.id??{clock:-1,client:-1};for(let d of r.keys()){let u=new Map,a=[],h=d;for(;r.has(h)&&!u.has(h);)u.set(h,a.length),a.push(h),h=i(r.get(h));if(!u.has(h))continue;let f=a.slice(u.get(h)).reduce((b,x)=>{let O=l(s[r.get(b)]),_=l(s[r.get(x)]);return O.clock<_.clock||O.clock===_.clock&&O.client<_.client?b:x}),m=r.get(f);s[m].node&&(s[m]=o(s[m].b)),s[m].fields.parent=null}let c=s.map(({b:d,node:u,type:a,fields:h,opaque:p})=>{if(u)return u;if(p){let b=[];for(let x of d.runs)x.hole||(x.br?b.push(g.nodes.hard_break.create()):b.push(g.text(x.text,x.marks)));return a.create({id:d.id,pos:null,raw:h},b)}let f={id:d.id,pos:null,...h};if(a.name==="table"&&Object.keys(f.rows??{}).length&&Object.keys(f.cols??{}).length)return Y(g,d.id,{t:"table",...f});if(!a.isTextblock)return a.create(f);let m=[];for(let b of d.runs)b.hole||(b.br?m.push(g.nodes.hard_break.create()):m.push(g.text(b.text,b.marks)));return a.create(f,m)});return c.length?g.nodes.doc.create(null,c):g.nodes.doc.createAndFill()}var E=n=>({status:"refused",code:n}),bt=n=>JSON.parse(JSON.stringify(n)),Wn=["title","owner","due"],Un=/^\d{4}-\d{2}-\d{2}$/,yt=(n,t)=>n==="title"?typeof t=="string":n==="due"?t===null||typeof t=="string"&&Un.test(t):t===null||typeof t=="string"&&t.length>0,Gn=n=>n!==null&&typeof n=="object"&&!Array.isArray(n);function Qe(n,t){let e=t>0?n[t-1]:null,o=n.slice(t).find(r=>e===null||r>e)??null,s=r=>(e===null||r>e)&&(o===null||r<o);for(let[r,i]of[[e,o],[null,o],[e,null]]){if(r!==null&&!R(r)||i!==null&&!R(i)||r!==null&&i!==null&&r>=i)continue;let l=A(r,i);if(s(l))return l}return`${n.reduce((r,i)=>i>r?i:r,"")}V`}function Vt(n,t,e){let o=n.map(t),s=e>0?o[e-1]:null,r=e;for(;s!==null&&r<o.length&&o[r]===s;)r++;if(r===e)return{pos:Qe(o,e),rekey:[]};let i=o.slice(r).find(c=>c>s)??null,l=[];for(let c=e,d=s;c<=r;c++)l.push(d=Qe(i===null?[d]:[d,i],1));return{pos:l[0],rekey:n.slice(e,r).map((c,d)=>[c,l[d+1]])}}var kt=(n,t,e)=>{let{pos:o,rekey:s}=Vt(t,r=>n[r].pos,e);for(let[r,i]of s)n[r]={...n[r],pos:i};return o};function qs({pd:n,um:t=null,origins:e=null,render:o=()=>{}}){let s=u=>{if(typeof u!="string")return null;let a=$e(n,e).visible.find(p=>p.id===u);if(!a||a.t!=="board")return null;let h=a.fields??Kt(n,a,g.nodes.board);return{columns:bt(h.columns??{}),cards:bt(h.cards??{})}},r=(u,a,h,p)=>{let f=ot(u);return t?.stopCapturing(),n.ydoc.transact(()=>{if(!f)De(n,u,a,h);else for(let m of["columns","cards"])nt(a[m])!==nt(h[m])&&n.gone.set(mt(f,m),bt(h[m]))},Ae),t?.stopCapturing(),o(),p},i=(u,a,h=null)=>I(Object.fromEntries(Object.entries(u.cards).filter(([p,f])=>f.col===a&&p!==h))),l=(u,a)=>a===void 0?u.length:a===null?0:u.indexOf(a)+1,c=(u,a)=>a!=null&&!u.includes(a),d=(u,a)=>{let h=s(u);return h?a(h,bt(h)):E("missing-board")};return{read:u=>s(u),removed(u){return s(u)?ot(u)?{columns:{},cards:{}}:ft(n.boardFields,u):null},createColumn:(u,{name:a="",afterId:h}={})=>d(u,(p,f)=>{if(typeof a!="string")return E("invalid-value");let m=I(p.columns);if(c(m,h))return E("missing-destination");let b=k("c");return f.columns[b]={pos:kt(f.columns,m,l(m,h)),name:a},r(u,p,f,{status:"created",id:b})}),renameColumn:(u,a,h)=>d(u,(p,f)=>Object.hasOwn(p.columns,a)?typeof h!="string"?E("invalid-value"):p.columns[a].name===h?{status:"unchanged"}:(f.columns[a].name=h,r(u,p,f,{status:"changed"})):E("missing-column")),moveColumn:(u,a,{afterId:h=null}={})=>d(u,(p,f)=>{if(!Object.hasOwn(p.columns,a))return E("missing-column");let m=I(p.columns).filter(O=>O!==a);if(c(m,h))return E("missing-destination");let b=l(m,h),x=I(p.columns);return[...m.slice(0,b),a,...m.slice(b)].every((O,_)=>O===x[_])?{status:"unchanged"}:(f.columns[a].pos=kt(f.columns,m,b),r(u,p,f,{status:"moved"}))}),removeColumn:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.columns,a)?(delete p.columns[a],r(u,h,p,{status:"removed",cards:i(h,a).length})):E("missing-column")),restoreColumn:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.columns,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).columns[a];return f?(p.columns[a]=f,r(u,h,p,{status:"restored"})):E("missing-column")}),createCard:(u,{columnId:a,title:h="",owner:p=null,due:f=null,afterId:m}={})=>d(u,(b,x)=>{if(!Object.hasOwn(b.columns,a))return E("missing-column");if(!yt("title",h)||!yt("owner",p)||!yt("due",f))return E("invalid-value");let O=i(b,a);if(c(O,m))return E("missing-destination");let _=k("k");return x.cards[_]={pos:kt(x.cards,O,l(O,m)),col:a,title:h,...p!==null?{owner:p}:{},...f!==null?{due:f}:{}},r(u,b,x,{status:"created",id:_})}),editCard:(u,a,h)=>d(u,(p,f)=>{if(!Object.hasOwn(p.cards,a))return E("missing-card");if(!Gn(h)||!Object.keys(h).length||Object.keys(h).some(b=>!Wn.includes(b)))return E("invalid-field");if(Object.entries(h).some(([b,x])=>!yt(b,x)))return E("invalid-value");let m={...p.cards[a]};for(let[b,x]of Object.entries(h))x===null?delete m[b]:m[b]=x;return nt(m)===nt(p.cards[a])?{status:"unchanged"}:(f.cards[a]=m,r(u,p,f,{status:"changed"}))}),moveCard:(u,a,{columnId:h,afterId:p=null}={})=>d(u,(f,m)=>{if(!Object.hasOwn(f.cards,a))return E("missing-card");if(!Object.hasOwn(f.columns,h))return E("missing-column");let b=i(f,h,a);if(c(b,p))return E("missing-destination");let x=l(b,p),O=f.cards[a];if(O.col===h){let _=i(f,h);if([...b.slice(0,x),a,...b.slice(x)].every((ct,jn)=>ct===_[jn]))return{status:"unchanged"}}return m.cards[a]={...O,col:h,pos:kt(m.cards,b,x)},r(u,f,m,{status:"moved"})}),removeCard:(u,a)=>d(u,(h,p)=>Object.hasOwn(h.cards,a)?(delete p.cards[a],r(u,h,p,{status:"removed"})):E("missing-card")),restoreCard:(u,a)=>d(u,(h,p)=>{if(Object.hasOwn(h.cards,a))return{status:"unchanged"};let f=ot(u)?null:ft(n.boardFields,u).cards[a];return f?(p.cards[a]=f,r(u,h,p,{status:"restored"})):E("missing-card")})}}var xt="page-history-intent",Yn=500,Jn=(n,t)=>{let e=n.resolve(t);return e.depth?e.node(1).attrs.id:null},Xn=n=>(n.storedMarks??n.selection.$from.marks()).map(t=>`${t.type.name}:${JSON.stringify(t.attrs)}`).sort().join(",");function qt(n,t,e,o){return{kind:"insert",blockId:Jn(n.doc,t),from:t,end:t+o.length,replaced:t!==e,text:o,marks:Xn(n),at:Date.now()}}function Ys(n,t){return!n||!t||n.kind!==t.kind?!1:t.kind==="compose"?n.id===t.id:n.blockId!==t.blockId||t.at-n.at>Yn?!1:t.kind==="insert"?!t.replaced&&t.from===n.end&&t.marks===n.marks&&!(/\s$/.test(n.text)&&/^\S/.test(t.text)):t.direction===n.direction&&(t.direction<0?t.to===n.from:t.from===n.from)}var Qn={deleteContentBackward:-1,deleteContentForward:1},jt=new WeakMap,Zn=1e3,Wt="page-derived";function to(n){let t=jt.get(n)??null;return jt.delete(n),t}function eo(n,t){if(!t||n.before!==t.doc||Date.now()-t.at>Zn||n.getMeta(He)||n.steps.length!==1)return null;let e=n.steps[0];if(e.slice?.size!==0||e.from===e.to)return null;let o=n.before.resolve(e.from),s=n.before.resolve(e.to);return!o.parent.isTextblock||!o.sameParent(s)?null:{kind:"delete",blockId:o.depth?o.node(1).attrs.id:null,direction:t.direction,from:e.from,to:e.to,at:t.at}}function Js(n,t=null){let e=t?to(t):null,o=n.filter(i=>!i.getMeta(Wt));if(o.length!==1)return null;let s=o[0],r=s.getMeta("composition");return r!=null?{kind:"compose",id:r,at:Date.now()}:s.getMeta(xt)??eo(s,e)}function Xs(){return new C.Plugin({props:{handleTextInput(n,t,e,o,s){return n.dispatch(s().setMeta(xt,qt(n.state,t,e,o))),!0},handleDOMEvents:{beforeinput(n,t){let e=Qn[t.inputType];return e&&jt.set(n,{direction:e,at:Date.now(),doc:n.state.doc}),!1}}}})}function no(n,t){if(!n||!/<table[\s>]/i.test(n))return null;let e=t.defaultView?.DOMParser??globalThis.DOMParser;if(!e)return null;let o=new e().parseFromString(n,"text/html").body,s=[...o.querySelectorAll("table")].filter(d=>!d.parentElement.closest("table"));if(s.length!==1)return null;let r=o.cloneNode(!0);for(let d of r.querySelectorAll("table, style, script, template, meta, title"))d.remove();if(r.textContent.trim())return null;let i=s[0];return{grid:[...i.querySelectorAll("tr")].filter(d=>d.closest("table")===i).map(d=>[...d.children].filter(u=>u.tagName==="TD"||u.tagName==="TH").map(u=>dt(je.parse(u,{topNode:g.nodes.table_cell.create()})))).filter(d=>d.length),own:!!i.querySelector("td[data-col]")}}function oo(n){if(!n||!n.includes(" "))return null;let{header:t,rows:e}=ht(n.replace(/\r?\n$/,""),{delimiter:" "});return{grid:[t,...e],own:!1}}function Ze(n,t,e=globalThis.document){let o=null;try{o=no(n,e)}catch{o=null}if(!o&&!/<table[\s>]/i.test(n||""))try{o=oo(t)}catch{o=null}if(!o||!o.grid.length)return null;let s=Math.max(...o.grid.map(r=>r.length));for(let r of o.grid)for(;r.length<s;)r.push("");return{...o,width:s,height:o.grid.length}}function Mt(n,{header:t=n.length>1}={}){let e=Math.max(0,...n.map(a=>a.length));if(!e)return null;let o=t?n[0]:[],s=t?n.slice(1):n,r=Array.from({length:e},()=>k("c")),i=N(null,null,e),l=Object.fromEntries(r.map((a,h)=>[a,{pos:i[h],name:ut(o[h]??"").replace(/\s+/g," ").trim()||`Column ${h+1}`}])),c=s.length?s:[[]],d=N(null,null,c.length),u=Object.fromEntries(c.map((a,h)=>[k("r"),{pos:d[h],cells:Object.fromEntries(r.map((p,f)=>[p,a[f]??""]))}]));return Y(g,k(),{t:"table",pos:null,cols:l,rows:u})}var{Plugin:so,TextSelection:ro}=C,Ut=g.nodes;var on=(n,t)=>{let e=null;return n.forEach((o,s)=>{!e&&o.type===Ut.table&&o.attrs.id===t&&(e={node:o,pos:s})}),e};function V(n,t){if(!t)return null;let e=on(n,t.table);if(!e)return null;let o=[];e.node.forEach(p=>o.push(p.attrs.id));let s=I(e.node.attrs.cols),r=[o.indexOf(t.anchor[0]),o.indexOf(t.head[0])],i=[s.indexOf(t.anchor[1]),s.indexOf(t.head[1])];if(r.includes(-1)||i.includes(-1))return null;let l=Math.min(...r),c=Math.max(...r),d=Math.min(...i),u=Math.max(...i),a=[],h=e.pos+1;return e.node.forEach((p,f,m)=>{if(m>=l&&m<=c){let b=[],x=h+1;p.forEach((O,_,ct)=>{ct>=d&&ct<=u&&b.push({cell:O,pos:x}),x+=O.nodeSize}),a.push(b)}h+=p.nodeSize}),{...e,top:l,bottom:c,left:d,right:u,cells:a}}var st=(n,t)=>{let e=n.resolve(t);for(let o=e.depth;o>0;o--)if(e.node(o).type===Ut.table_cell&&o>=3)return{table:e.node(o-2).attrs.id,row:e.node(o-1).attrs.id,col:e.node(o).attrs.col,start:e.start(o)};return null};function wt(n,t,e){let o=st(n.state.doc,t),s=st(n.state.doc,e);if(!o||!s||o.table!==s.table)return!1;let r={table:o.table,anchor:[o.row,o.col],head:[s.row,s.col]},i=n.state.tr.setSelection(ro.create(n.state.doc,s.start)).setMeta(S,r);n.dispatch(i);let l=V(n.state.doc,r),c=l?(l.bottom-l.top+1)*(l.right-l.left+1):0;return P(n,`${c} ${c===1?"cell":"cells"} selected`),!0}function fr(n,t,e,o){let s=n.state.doc.nodeAt(t);if(s?.type!==Ut.table||!s.childCount)return!1;let r=s.childCount-1,i=s.child(0).childCount-1,l=(c,d)=>{let u=t+1;for(let a=0;a<c;a++)u+=s.child(a).nodeSize;u++;for(let a=0;a<d;a++)u+=s.child(c).child(a).nodeSize;return u+1};return e==="row"?wt(n,l(o,0),l(o,i)):wt(n,l(0,o),l(r,o))}var io=new Set(["Shift","Control","Alt","Meta","CapsLock"]),lo=n=>/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n;function co(n,t){let e=n.cells.map(r=>r.map(({cell:i})=>lo(ut(dt(i)))).join(" ")).join(`
2
+ `),o=t.createElement("table"),s=o.appendChild(t.createElement("tbody"));for(let r of n.cells){let i=s.appendChild(t.createElement("tr"));for(let{cell:l}of r){let c=i.appendChild(t.createElement("td"));c.dataset.col=l.attrs.col,c.append(qe.serializeFragment(l.content,{document:t}))}}return{text:e,html:o.outerHTML}}function tn(n,t){let e=V(n.doc,S.getState(n));if(!e)return!1;if(t){let o=n.tr;for(let s of[...e.cells].reverse())for(let{cell:r,pos:i}of[...s].reverse())r.content.size&&o.delete(i+1,i+r.nodeSize-1);o.setMeta(S,S.getState(n)),t(w(o))}return!0}var en=(n,t,e)=>{let{text:o,html:s}=co(t,e.dom.ownerDocument);n.clipboardData.setData("text/plain",o),n.clipboardData.setData("text/html",s),n.preventDefault()},ao=(n,t)=>(e,o,s)=>{let r=S.getState(e),i=V(e.doc,r);if(!i||!s)return!1;let l=[],c=I(i.node.attrs.cols);i.node.forEach(a=>l.push(a.attrs.id));let d=Math.max(0,Math.min(l.length-1,l.indexOf(r.head[0])+n)),u=Math.max(0,Math.min(c.length-1,c.indexOf(r.head[1])+t));return o&&o(e.tr.setMeta(S,{...r,head:[l[d],c[u]]})),!0},nn=(n,t)=>{let e=t.target?.closest?.("td");if(!e||!n.dom.contains(e))return null;try{return n.posAtDOM(e,0)}catch{return null}};function mr(){let n=null;return new so({key:S,state:{init:()=>null,apply(t,e,o,s){let r=t.getMeta(S);return r!==void 0?r:!e||t.selectionSet||t.docChanged&&!t.getMeta(pt)?null:V(s.doc,e)?e:null}},props:{attributes:t=>S.getState(t)?{class:"has-cell-rect"}:{},createSelectionBetween:t=>S.getState(t.state)?t.state.selection:null,decorations(t){let e=V(t.doc,S.getState(t));return e?Pt.DecorationSet.create(t.doc,e.cells.flat().map(({cell:o,pos:s})=>Pt.Decoration.node(s,s+o.nodeSize,{class:"is-cell-selected"}))):null},handleKeyDown(t,e){let o=t.state;if(!S.getState(o))return!1;if(e.key==="Escape")return t.dispatch(o.tr.setMeta(S,null)),!0;if(e.key==="Backspace"||e.key==="Delete")return tn(o,t.dispatch);if(e.shiftKey){let s={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(s)return ao(...s)(o,t.dispatch,t)}return io.has(e.key)||(e.metaKey||e.ctrlKey)&&(e.key==="a"||e.key==="c"||e.key==="x"||e.key==="v")||t.dispatch(o.tr.setMeta(S,null)),!1},handleDOMEvents:{mousedown(t,e){if(e.button!==0)return!1;!e.shiftKey&&S.getState(t.state)&&t.dispatch(t.state.tr.setMeta(S,null));let o=nn(t,e);if(o===null)return!1;if(e.shiftKey){let c=S.getState(t.state),d=(c&&uo(t.state.doc,c))??t.state.selection.$anchor.pos;return st(t.state.doc,d)?(e.preventDefault(),wt(t,d,o)):!1}let s=t.dom.ownerDocument,r=o,i=c=>{let d=nn(t,c);if(d===null)return;let u=st(t.state.doc,r),a=st(t.state.doc,d);if(!u||!a||u.table!==a.table)return;let h=S.getState(t.state);u.row===a.row&&u.col===a.col&&!h||h&&h.head[0]===a.row&&h.head[1]===a.col||(c.preventDefault(),wt(t,r,d))},l=()=>{s.removeEventListener("mouseover",i),s.removeEventListener("mouseup",l),n=null};return n?.(),n=l,s.addEventListener("mouseover",i),s.addEventListener("mouseup",l),!1},copy(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),!0)},cut(t,e){let o=V(t.state.doc,S.getState(t.state));return!o||!e.clipboardData?!1:(en(e,o,t),tn(t.state,t.dispatch),!0)}}},view:()=>({destroy:()=>n?.()})})}function uo(n,t){let e=on(n,t.table),o=null;return e?.node.forEach((s,r)=>{if(s.attrs.id!==t.anchor[0])return;let i=e.pos+1+r+1;s.forEach(l=>{l.attrs.col===t.anchor[1]&&(o=i+1),i+=l.nodeSize})}),o}var sn=n=>{let t=V(n.doc,S.getState(n));return t?{row:t.top,cell:t.left,rows:t.bottom-t.top+1,cols:t.right-t.left+1}:null};var Gt=new WeakMap;var{Plugin:ho,TextSelection:j}=C,T=g.nodes,Jt=256*1024,B=n=>I(n.attrs.cols),rn=n=>{let t=n.selection.$head;for(let e=t.depth;e>0;e--)if(t.node(e).type===T.table){let o=t.node(e),s=e<t.depth?t.index(e):0,r=e+1<t.depth?t.index(e+1):0;return{table:o,pos:t.before(e),row:s,cell:r}}return null},rt=(n,t,e,o)=>{let s=n.nodeAt(t);if(!s||!s.childCount)return null;e=Math.max(0,Math.min(e,s.childCount-1)),o=Math.max(0,Math.min(o,s.child(e).childCount-1));let r=t+1;for(let i=0;i<e;i++)r+=s.child(i).nodeSize;r++;for(let i=0;i<o;i++)r+=s.child(e).child(i).nodeSize;return r+1},St=(n,t=A())=>T.table_row.create({id:k("r"),pos:t},n.map(e=>T.table_cell.create({col:e}))),L=(n,t,e)=>T.table.create({...n.attrs,...t},e);function D(n,t,e){let o=rn(n);if(!o)return!1;let s=e(o.table,o);if(!s)return!1;if(t){let{table:r,row:i=o.row,cell:l=o.cell}=s,c=n.tr.replaceWith(o.pos,o.pos+o.table.nodeSize,r),d=rt(c.doc,o.pos,i,l);d!==null&&c.setSelection(j.create(c.doc,d)),t(w(c))}return!0}function F(n,t,e,o=null,s=null,r=null){r??=o?n.doc.resolve(o.from).index(0):n.selection.$head.index(0);let i=n.doc.child(r),l=0;for(let h=0;h<r;h++)l+=n.doc.child(h).nodeSize;let c=i.isTextblock&&(i.content.size===0||o?.from===l+1&&o?.to===l+i.nodeSize-1),d=n.doc.maybeChild(r+1),u=c?i.attrs.pos:A(i.attrs.pos,d?.attrs.pos??null),a=e.type.create({...e.attrs,pos:u,parent:i.attrs.parent??null},e.content);if(t){let h=n.tr;o&&h.delete(o.from,o.to);let p=h.mapping.map(l),f=h.doc.child(r),m=c?p:p+f.nodeSize;if(h.replaceWith(m,c?p+f.nodeSize:m,a),s){let b=s.type.create({...s.attrs,pos:A(u,d?.attrs.pos??null),parent:i.attrs.parent??null},s.content);h.insert(m+a.nodeSize,b)}h.setSelection(j.create(h.doc,rt(h.doc,m,0,0))),t(w(h).scrollIntoView())}return!0}function ln(n=3,t=3){if(!Number.isInteger(n)||!Number.isInteger(t)||n<1||t<1)return null;let e=Array.from({length:t},()=>k("c")),o=N(null,null,t),s=Object.fromEntries(e.map((l,c)=>[l,{pos:o[c],name:`Column ${c+1}`}])),i=N(null,null,n).map(l=>St(e,l));return T.table.create({id:k(),cols:s},i)}var Xt=n=>(t,e)=>{let o=rn(t);if(!o||t.selection.$head.parent.type!==T.table_cell)return!1;let s=o.table.child(o.row).childCount,r=o.row,i=o.cell;return n==="down"?r++:(i+=n,i>=s&&(r++,i=0),i<0&&(r--,i=s-1)),r<0?!0:r>=o.table.childCount?n===-1?!0:po(t,e,o,i):(e&&e(t.tr.setSelection(j.create(t.doc,rt(t.doc,o.pos,r,i))).scrollIntoView()),!0)};function po(n,t,e,o){let s=[...e.table.content.content];if(s.push(St(B(e.table),A(s.at(-1).attrs.pos,null))),t){let r=n.tr.replaceWith(e.pos,e.pos+e.table.nodeSize,L(e.table,{sort:null},s));r.setSelection(j.create(r.doc,rt(r.doc,e.pos,s.length-1,o))),t(w(r).scrollIntoView())}return!0}var fo=Xt(1),mo=Xt(-1),go=Xt("down"),bo=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=[...o.content.content],i=s.row+(n?1:0),l=A(r[i-1]?.attrs.pos??null,r[i]?.attrs.pos??null);return r.splice(i,0,St(B(o),l)),{table:L(o,{sort:null},r),row:i}}),Lr=(n,t)=>D(n,t,(e,o)=>{let s=[...e.content.content];if(s.length===1){let r=s[0];s[0]=T.table_row.create(r.attrs,B(e).map(i=>T.table_cell.create({col:i})))}else s.splice(o.row,1);return{table:L(e,{sort:null},s),row:Math.min(o.row,s.length-1)}}),cn=(n,t,e,o,s)=>{let{pos:r,rekey:i}=Vt(t,c=>n[c]?.pos??"",e),l={...n,[o]:{...s,pos:r}};for(let[c,d]of i)l[c]={...l[c],pos:d};return l},Dr=(n=!0)=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+(n?1:0),l=k("c"),c=cn(o.attrs.cols,r,i,l,{name:`Column ${r.length+1}`}),d=o.content.content.map(u=>{let a=[...u.content.content];return a.splice(i,0,T.table_cell.create({col:l})),T.table_row.create(u.attrs,a)});return{table:L(o,{cols:c},d),cell:i}}),$r=(n,t)=>D(n,t,(e,o)=>{let s=B(e);if(s.length<=1)return null;let r={...e.attrs.cols};delete r[s[o.cell]];let i=e.content.content.map(l=>T.table_row.create(l.attrs,l.content.content.filter((c,d)=>d!==o.cell)));return{table:L(e,{cols:r,sort:e.attrs.sort?.col===s[o.cell]?null:e.attrs.sort},i),cell:Math.min(o.cell,s.length-2)}}),_r=n=>(t,e)=>D(t,e,(o,s)=>{let r=s.row+n;if(r<0||r>=o.childCount)return null;let i=[...o.content.content],[l]=i.splice(s.row,1);i.splice(r,0,l);let c=A(i[r-1]?.attrs.pos??null,i[r+1]?.attrs.pos??null);return i[r]=T.table_row.create({...l.attrs,pos:c},l.content),{table:L(o,{sort:null},i),row:r}}),Br=n=>(t,e)=>D(t,e,(o,s)=>{let r=B(o),i=s.cell+n;if(i<0||i>=r.length)return null;let l=[...r],[c]=l.splice(s.cell,1);l.splice(i,0,c);let d=cn(o.attrs.cols,l.filter(a=>a!==c),i,c,o.attrs.cols[c]),u=o.content.content.map(a=>{let h=[...a.content.content],[p]=h.splice(s.cell,1);return h.splice(i,0,p),T.table_row.create(a.attrs,h)});return{table:L(o,{cols:d},u),cell:i}}),yo=48,ko=1200,Pr=160,an=n=>Number.isFinite(n)&&n>0?Math.round(Math.min(ko,Math.max(yo,n))):null,Rr=n=>(t,e)=>D(t,e,o=>{let s=B(o);if(!s.some(i=>o.attrs.cols[i].width))return null;let r={};for(let i of s){let{width:l,...c}=o.attrs.cols[i];r[i]=c}return{table:L(o,{cols:r},o.content),cell:Math.max(0,s.indexOf(n))}}),Nr=(n,t)=>(e,o)=>D(e,o,s=>{let r={...s.attrs.cols},i=!1;for(let[l,c]of Object.entries(n)){let d=an(c);!r[l]||d===null||r[l].width===d||(r[l]={...r[l],width:d},i=!0)}return i?{table:L(s,{cols:r},s.content),cell:B(s).indexOf(t)}:null}),Hr=(n,t)=>(e,o)=>D(e,o,s=>{let r=s.attrs.cols[n];if(!r)return null;let i=t===null?null:an(t);if(t!==null&&i===null||(r.width??null)===i)return null;let{width:l,...c}=r,d={...s.attrs.cols,[n]:i===null?c:{...r,width:i}};return{table:L(s,{cols:d},s.content),cell:B(s).indexOf(n)}}),zr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!String(t).trim())return null;let r={...s.attrs.cols,[n]:{...s.attrs.cols[n],name:String(t).trim()}};return{table:L(s,{cols:r},s.content)}}),Fr=(n,t)=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!(t==="auto"||Te.includes(t)))return null;let{kind:r,...i}=s.attrs.cols[n],l={...s.attrs.cols,[n]:t==="auto"?i:{...s.attrs.cols[n],kind:t}};return{table:L(s,{cols:l,sort:s.attrs.sort?.col===n?null:s.attrs.sort},s.content)}}),Kr=(n,t="asc")=>(e,o)=>D(e,o,s=>{if(!s.attrs.cols[n]||!["asc","desc"].includes(t))return null;let r=B(s).indexOf(n),i=Je(s)[n],l=[...s.content.content].map((u,a)=>({row:u,previous:a,text:u.child(r).textContent.trim()}));l.sort((u,a)=>{if(!u.text||!a.text)return!u.text&&!a.text?u.previous-a.previous:u.text?-1:1;let h=i==="number"?Nt(u.text):u.text,p=i==="number"?Nt(a.text):a.text;if(h==null||p==null)return h==null&&p==null?u.previous-a.previous:h==null?1:-1;let f=i==="number"?h-p:i==="date"?h<p?-1:h>p?1:0:h.localeCompare(p,void 0,{numeric:!0,sensitivity:"base"});return f?t==="asc"?f:-f:u.previous-a.previous});let c=N(null,null,l.length),d=l.map(({row:u},a)=>T.table_row.create({...u.attrs,pos:c[a]},u.content));return{table:L(s,{sort:{col:n,dir:t}},d)}}),Yt=(n,t=null)=>(e,o)=>D(e,o,(s,r)=>{let i=B(s),l=t?.row??r.row,c=t?.cell??r.cell,d=[...s.content.content];n.forEach((a,h)=>{let p=l+h;p>=d.length&&d.push(St(i,A(d.at(-1).attrs.pos,null)));let f=[...d[p].content.content];a.forEach((m,b)=>{c+b<i.length&&(f[c+b]=T.table_cell.create({col:i[c+b]},we(g,m)))}),d[p]=T.table_row.create(d[p].attrs,f)});let u=Math.max(1,...n.map(a=>a.length));return{table:L(s,{sort:null},d),row:l+n.length-1,cell:Math.min(c+u-1,i.length-1)}}),xo=n=>new TextEncoder().encode(JSON.stringify(n.toJSON())).length;function Mo(n,t){let e=t.clipboardData;if(!e||e.files?.length)return!1;let o=n.state;if(o.selection.$from.parent.type.spec.code)return!1;let s=sn(o),r=e.getData("text/plain").replace(/\r?\n$/,""),i=Ze(e.getData("text/html"),e.getData("text/plain"),n.dom.ownerDocument)??(s&&r&&!/[\r\n]/.test(r)?{grid:[[r]],width:1,height:1,own:!1}:null);if(!i)return!1;if(s&&s.rows*s.cols>1&&i.width*i.height===1)return Yt(Array.from({length:s.rows},()=>Array(s.cols).fill(i.grid[0][0])),{row:s.row,cell:s.cell})(o,n.dispatch);if(s)return Yt(i.grid,{row:s.row,cell:s.cell})(o,n.dispatch);if(o.selection.$head.parent.type===T.table_cell)return i.width*i.height<2?!1:Yt(i.grid)(o,n.dispatch);if(i.width*i.height<2||i.own||i.height<2&&!/<table[\s>]/i.test(e.getData("text/html")))return!1;let l=Mt(i.grid,{header:i.height>1});if(!l)return!1;if(xo(l)>Jt)return H("This paste is too large for one table.","error"),!0;let{from:c,to:d,empty:u,$from:a,$to:h}=o.selection;if(!u&&a.index(0)!==h.index(0)){let p=o.tr.deleteSelection();return F(o.apply(p),f=>{for(let m of f.steps)p.step(m);p.setSelection(j.create(p.doc,f.selection.from)),n.dispatch(w(p).scrollIntoView())},l)}return F(o,n.dispatch,l,u?null:{from:c,to:d})}var Vr=at.keymap({Tab:fo,"Shift-Tab":mo,Enter:go,"Mod-Enter":bo(!0)});function wo(n,t){let e=Gt.get(t.target),o=e?.getPos();if(o==null||t.button||t.shiftKey||!n.editable)return!1;t.preventDefault();let s=t.clientX<e.contentDOM.getBoundingClientRect().left;return n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,o+1+(s?0:e.node.content.size)))),n.focus(),e.openDate(),!0}function jr(){return new ho({props:{handlePaste:Mo,handleDOMEvents:{mousedown:wo},handleClickOn(n,t,e,o,s,r){if(e.type!==T.table_cell||!r||s.button)return!1;let i=n.nodeDOM(o),l=i&&Gt.get(i);return l&&l.openDate(),!1}},appendTransaction(n,t,e){if(!n.some(r=>r.docChanged&&!r.getMeta(pt)))return null;let o=new Map;t.doc.forEach(r=>{r.type===T.table&&o.set(r.attrs.id,r)});let s=e.tr;return e.doc.forEach((r,i)=>{if(r.type!==T.table||!r.attrs.sort)return;let l=o.get(r.attrs.id),c=r.attrs.sort.col;if(!l)return;let d=h=>Object.fromEntries(h.content.content.map(p=>[p.attrs.id,p.content.content.find(f=>f.attrs.col===c)?.textContent])),u=d(l),a=d(r);(Object.keys(u).length!==Object.keys(a).length||Object.keys(u).some(h=>u[h]!==a[h]||!Object.hasOwn(a,h)))&&s.setNodeMarkup(i,null,{...r.attrs,sort:null})}),s.docChanged?s.setMeta(Wt,!0):null}})}function qr(n,t,e){let o=n.state.doc.nodeAt(t);if(o?.type!==T.table_cell)return!1;let s=n.state.tr.replaceWith(t+1,t+o.nodeSize-1,e?g.text(e):[]);return n.dispatch(s.setSelection(j.create(s.doc,t+1+e.length))),!0}function Wr(n,t,e,o){let s=rt(n.state.doc,t,e,o);return s===null?!1:(n.dispatch(n.state.tr.setSelection(j.create(n.state.doc,s))),!0)}var{TextSelection:So}=C,Qt=g.nodes,To=Object.freeze(["To do","In progress","Done"]),un=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function Zt(n=To){let t=N(null,null,n.length),e=Object.fromEntries(n.map((o,s)=>[k("c"),{pos:t[s],name:o}]));return Qt.board.create({id:k(),columns:e,cards:{}})}function dn(n,t,e=Zt(),o=null,s=null){let r=n.tr;o&&r.delete(o.from,o.to),s??=r.doc.resolve(r.mapping.map(n.selection.head)).index(0);let i=J(r.doc),l=r.doc.child(s),c=l.isTextblock&&l.content.size===0,d=c?s:i[s].subEnd,u=c?i[s].at:i[d].end,a=i[d+1]?.node.attrs.pos??null,h=l.attrs.parent??null,p=c?l.attrs.pos:un(i[d].node.attrs.pos,a),f=Qt.board.create({...e.attrs,pos:p,parent:h}),m=Qt.paragraph.create({id:k(),pos:un(p,a),parent:h});return r.replaceWith(u,c?i[s].end:u,[f,m]),r.setSelection(So.create(r.doc,u+f.nodeSize+1)),t&&t(w(r).scrollIntoView()),!0}function hn(n){let t=[];return n.forEach(e=>{e.type===g.nodes.table&&I(e.attrs.cols).length>1&&t.push(e)}),t}function ni(n,t){let e="",o=0,s=null;return n.forEach(r=>{s===null&&(r.type===g.nodes.heading&&(e=r.textContent),r.type===g.nodes.table&&(o+=1,r.attrs.id===t&&(s=e||`Table ${o}`),e=""))}),s}var pn=new Set(["page-format-unsupported","unsupported-host"]),Eo="This host can't store that yet, so nothing was added.",Co="That didn't go through. Try again.",Ao="That couldn't be added here.";function fn(n,t){let e=t?.status==="upgrade-required"&&t.message?t.message:pn.has(t?.code)||pn.has(t?.status)?Eo:t?.retry===!0?Co:Ao;n.isDestroyed||(P(n,e),H(e,"error"))}async function Tt(n,t){if(typeof n.runFormatCommand!="function")return fn(n,{code:"page-format-unsupported"}),{ok:!1,code:"page-format-unsupported"};let e=await n.runFormatCommand(t);return e?.status==="applied"?e.result:(fn(n,e),{ok:!1,code:e?.code??e?.status??"page-format-refused",retry:e?.retry===!0})}var{TextSelection:it}=C,v=g.nodes,q=[{key:"text",label:"Text",description:"Plain writing",icon:"T",type:"paragraph",aliases:["p","paragraph","plain"]},{key:"h1",label:"Heading 1",description:"Big section heading",icon:"H1",type:"heading",attrs:{level:1},hint:"#",aliases:["h1","title"]},{key:"h2",label:"Heading 2",description:"Medium section heading",icon:"H2",type:"heading",attrs:{level:2},hint:"##",aliases:["h2","subtitle"]},{key:"h3",label:"Heading 3",description:"Small section heading",icon:"H3",type:"heading",attrs:{level:3},hint:"###",aliases:["h3"]},{key:"bullet",label:"Bulleted list",description:"A simple list",icon:"\u2022",type:"list_item",attrs:{kind:"bullet"},hint:"-",aliases:["ul","bullet","list","unordered"]},{key:"ordered",label:"Numbered list",description:"A list with numbers",icon:"1.",type:"list_item",attrs:{kind:"ordered"},hint:"1.",aliases:["ol","num","numbered","ordered"]},{key:"check",label:"Checklist",description:"Tasks to tick off",icon:"\u2610",type:"list_item",attrs:{kind:"check"},hint:"[]",aliases:["todo","to-do","task","check","checkbox"]},{key:"toggle",label:"Toggle",description:"Hide details under a line",icon:"\u25B8",type:"toggle",attrs:{open:!0},hint:">",aliases:["collapse","details","fold"]},{key:"toggle-h1",label:"Toggle heading 1",description:"Collapsible heading",icon:"H1",type:"toggle",attrs:{open:!0,level:1},aliases:["toggle heading"]},{key:"toggle-h2",label:"Toggle heading 2",description:"Collapsible heading",icon:"H2",type:"toggle",attrs:{open:!0,level:2},aliases:["toggle heading"]},{key:"toggle-h3",label:"Toggle heading 3",description:"Collapsible heading",icon:"H3",type:"toggle",attrs:{open:!0,level:3},aliases:["toggle heading"]},{key:"callout",label:"Callout",description:"Make a note stand out",icon:"!",type:"callout",aliases:["note","aside","info"]},{key:"quote",label:"Quote",description:"Set text apart as a quotation",icon:"\u201C",type:"quote",hint:'"',aliases:["blockquote","quotation","cite"]},{key:"code",label:"Code",description:"Code with highlighting",icon:"</>",type:"code_block",hint:"```",aliases:["pre","snippet"]}],Oo=[{key:"divider",label:"Divider",description:"A line between sections",icon:"\u2014",hint:"---",aliases:["hr","line","separator","rule"],insert:"divider"},{key:"toc",label:"Table of contents",description:"Links to this page's headings",icon:"\u2261",aliases:["toc","contents","outline","index"],insert:"toc"},{key:"image",label:"Image",description:"Upload or paste a picture",icon:"\u25A3",aliases:["img","picture","photo"],insert:"image"},{key:"file",label:"File",description:"Attach any file",icon:"\u2398",aliases:["upload","attachment","pdf"],insert:"file"},{key:"table",label:"Table",description:"Rows and columns, paste from a spreadsheet",icon:"\u25A6",aliases:["grid","spreadsheet"],insert:"table"},{key:"csv",label:"Import CSV\u2026",description:"Turn a CSV file into a table",icon:"\u21E7",aliases:["comma separated","import"],insert:"csv"},{key:"board",label:"Board",description:"Cards in columns, like a kanban",icon:"\u25A5",aliases:["kanban","cards","columns","status"],insert:"board"},{key:"mention",label:"Mention",description:"Name someone on the page",icon:"@",aliases:["person","people","assign"],command:"mentions"},{key:"date",label:"Date",description:"Today, tomorrow or a calendar day",icon:"\u25A7",aliases:["calendar","today","tomorrow","due"],command:"dates"},{key:"emoji",label:"Emoji",description:"Insert one glyph",icon:"\u263A",aliases:["smiley","glyph","symbol"],command:"emoji"},{key:"import-markdown",label:"Import Markdown\u2026",description:"Turn a Markdown file into blocks",icon:"M\u2193",aliases:["md","markdown","import"],command:"importMarkdown"}],vo={key:"chart",label:"Chart",description:"A bar or line chart from a table",icon:"\u{1F4CA}",aliases:["graph","plot","bar","line"],insert:"chart"},te=n=>(Ne.get(n)?.ensure("chart")??Promise.resolve()).catch(()=>{}).then(()=>n.isDestroyed?null:import("./c-JFST6QE7.js")),At=[...q,...Oo],gn=(n,t=At)=>hn(n.doc).length?[...t,vo]:t;function Ot(n){let t=n.type.name;return q.find(e=>e.type===t&&(!e.attrs||(t==="heading"||t==="toggle"?(e.attrs.level??null)===(n.attrs.level??null):t==="list_item"?e.attrs.kind===n.attrs.kind:!0)))??q[0]}var ee=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e};function G(n,t,e){let o=ee(n.doc,t),s=n.doc.child(t),r={id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent};return s.type===v.list_item&&e.type==="list_item"&&(r.indent=s.attrs.indent),n.setBlockType(o+1,o+s.nodeSize-1,v[e.type],{...r,...e.attrs||{}})}var bn=Object.freeze({status:"refused",code:"unsupported-format"}),Io=xe([]).type,Lo=n=>{let t=!1;return n.forEach(e=>{!t&&e.marks.some(ke)&&(t=!0)}),t};function Q(n,t){return!n.isTextblock||n.type===v.opaque_block?!1:!Lo(n)||v[t.type].allowsMarkType(Io)}var yn=n=>n.type==="toggle"&&n.attrs?.level!=null,Et=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e},ne={ok:!1,code:"stale-target"};function kn(n,t,e){let o=()=>e.map(r=>Et(n.state.doc,r)),s=()=>{let r=o();if(r.includes(-1))return ne;if(r.some(l=>!Q(n.state.doc.child(l),t)))return bn;let i=n.state.tr;for(let l of r)G(i,l,t);return n.dispatch(w(i).scrollIntoView()),n.focus(),{ok:!0}};return yn(t)?Tt(n,s):t.type==="quote"?import("./c-FNIGX4FI.js").then(r=>n.isDestroyed?!1:r.gateTurn(n,s)):s()}function xn(n,t,e=n.tr){let o=J(e.doc),{to:s}=ze(o,t),r=e.doc.child(t);return e.insert(s,v.paragraph.create({parent:r.attrs.parent??null})),e.setSelection(it.create(e.doc,s+1))}var X=(n,t)=>R(n)&&(t===null||R(t)&&n<t)?A(n,t):null;function oe(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.divider.create({id:r,pos:i,parent:l}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function Do(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return oe(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.divider.create({id:k(),pos:c,parent:d}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function $o(n,t){let e=ee(n.doc,t),o=n.doc.child(t),s=n.doc.maybeChild(t+1),{id:r,pos:i,parent:l}=o.attrs;return n.replaceWith(e,e+o.nodeSize,[v.toc.create({id:r,pos:i,parent:l,maxLevel:3}),v.paragraph.create({id:k(),pos:X(i,s?s.attrs.pos:null),parent:l})]),n.setSelection(it.create(n.doc,e+2))}function _o(n,t,e=n.tr){let o=e.doc.child(t);if(o.type===v.paragraph&&o.content.size===0)return $o(e,t);let s=J(e.doc),r=s[t].subEnd,i=s[r].end,l=s[r+1]?.node.attrs.pos??null,c=X(s[r].node.attrs.pos,l),d=o.attrs.parent??null;return e.insert(i,[v.toc.create({id:k(),pos:c,parent:d,maxLevel:3}),v.paragraph.create({id:k(),pos:X(c,l),parent:d})]),e.setSelection(it.create(e.doc,i+2))}function Bo(n,t){if(n.length<2||n.length>32)return 1/0;let e=-1,o=0;for(let s of n){let r=t.indexOf(s,e+1);if(r<0)return 1/0;o+=r-e-1,e=r}return o}function Mn(n,t){let e=t.trim().toLowerCase();if(!e)return n;let o=s=>{let r=s.label.toLowerCase(),i=[s.key,...s.aliases||[],...s.hint?[s.hint]:[]].map(c=>c.toLowerCase());if(r===e||i.includes(e))return[0,0];if(r.startsWith(e))return[1,0];if([...r.split(/\s+/),...i].some(c=>c.startsWith(e)))return[2,0];if([r,...i].some(c=>c.includes(e)))return[3,0];if(e.length>=3&&s.description&&s.description.toLowerCase().split(/[^a-z0-9]+/).some(c=>c.startsWith(e)))return[4,0];let l=Math.min(...[r,s.key,...s.aliases||[]].map(c=>Bo(e,c.toLowerCase())));return l===1/0?null:[5,l]};return n.map((s,r)=>({it:s,order:r,rank:o(s)})).filter(s=>s.rank).sort((s,r)=>s.rank[0]-r.rank[0]||s.rank[1]-r.rank[1]||s.order-r.order).map(s=>s.it)}function mn(n,t,e,o){let s=n.state,r=s.tr;o&&r.delete(o.from,o.to);let i=r.doc.child(e);return i.isTextblock&&i.content.size===0&&!Q(i,t)?bn:(t.insert==="divider"?r=Do(s,e,r):i.isTextblock&&i.content.size===0?r=G(r,e,t):(r=xn(s,e,r),r=G(r,r.doc.resolve(r.selection.head).index(0),t)),n.dispatch(w(r).scrollIntoView()),n.focus(),!0)}function Po(n,t,e=null){let o=n.state,s=o.doc.maybeChild(t)?.attrs.id??null,r=e&&{...e,text:o.doc.textBetween(e.from,e.to)};return Tt(n,()=>{let i=n.state;if((s===null?-1:Et(i.doc,s))<0||r&&i.doc.textBetween(r.from,r.to)!==r.text)return ne;let c=r?i.tr.delete(r.from,r.to):i.tr;return c=_o(i,Et(c.doc,s),c),n.dispatch(w(c).scrollIntoView()),n.focus(),{ok:!0}})}var Z=(n,t,e)=>import("./page/editor-BQEPCJLG.js").then(({runPageCommand:o})=>n.isDestroyed?{ok:!1,code:"not-editing"}:o(n,t,e));function Ro(n,t,e){return e&&n.dispatch(n.state.tr.delete(e.from,e.to)),Z(n,t,{})}function wn(n,t,e,o=null){let s=n.state;if(t.insert==="image"||t.insert==="file")return Re(n,t.insert==="image"?"image/*":"",Pe(s,e),o);if(t.insert==="csv")return Ct(n,o);if(t.insert==="table")return F(s,n.dispatch,ln(),o,null,e);if(t.insert==="board")return dn(s,n.dispatch,Zt(),o,e);if(t.insert==="chart")return te(n).then(l=>l&&!n.isDestroyed?l.chartFromSlash(n,e,o):!1);if(t.insert==="toc")return Po(n,e,o);if(t.command)return Ro(n,t.command,o);if(!yn(t)&&t.type!=="quote")return mn(n,t,e,o);let r=s.doc.maybeChild(e)?.attrs.id??null,i=o&&{...o,text:s.doc.textBetween(o.from,o.to)};return Tt(n,()=>{let l=n.state,c=r===null?-1:Et(l.doc,r);return c<0||i&&l.doc.textBetween(i.from,i.to)!==i.text?ne:mn(n,t,c,i)})}var{InputRule:ie}=Rt,W=g.nodes,vt=(n,t,e)=>n.doc.rangeHasMark(t,e,g.marks.code)||!!g.marks.code.isInSet(n.storedMarks||n.selection.$from.marks()),tt=(n,t,e=["paragraph"],o=!1)=>new ie(n,(s,r,i,l)=>{let c=s.doc.resolve(i);return!s.selection.empty||c.depth!==1||c.parentOffset!==0||!e.includes(c.parent.type.name)||o&&l!==c.end()||vt(s,i,l)?null:w(G(s.tr.delete(i,l),c.index(0),typeof t=="function"?t(r):t))}),No=new ie(/^---$/,(n,t,e,o)=>{let s=n.doc.resolve(e);return!n.selection.empty||s.depth!==1||s.parent.type!==W.paragraph||s.parentOffset!==0||s.parent.content.size!==o-e||vt(n,e,o)?null:w(oe(n.tr,s.index(0)))}),le=`\\s\\(\\[\\{'\u2018\u201C"`,Ho=new RegExp(`[${le}]`),se=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Sn=n=>`([^\\s${n}](?:[\\s\\S]*?[^\\s${n}])?)`,It=(n,t)=>!!n?.isComposing||n?.keyCode===229||!!t?.composing,Tn=n=>{let t=0;for(let e=n.length-1;e>=0&&n[e]==="\\";e--)t++;return t},zo=(n,t)=>{let e=n.doc.resolve(t);return!e.parent.inlineContent||Tn(e.parent.textBetween(0,e.parentOffset,null,"\uFFFC"))%2?!1:e.parentOffset===0||Ho.test(e.parent.textBetween(e.parentOffset-1,e.parentOffset))},Fo=(n,t,e,o,s)=>{let r=s(t);if(!r||!n.selection.empty||e<0||e>o||o>n.doc.content.size)return null;let i=n.doc.resolve(e),l=n.doc.resolve(o);if(!i.sameParent(l)||!i.parent.inlineContent)return null;let[c,d,u,a]=t;if(vt(n,e,o))return null;let h=c.slice(d.length,c.length-u.length-a.length),p=e+d.length;if(!zo(n,p)||Tn(c.slice(0,c.length-a.length))%2)return null;let f=c.length-(o-e);if(f<0)return null;let m=n.tr;f&&m.insertText(c.slice(-f),o,o);let b=p+h.length,x=b+u.length;return m.delete(x,e+c.length),m.delete(p,b),m.addMark(p,p+u.length,r),m.removeStoredMark(r.type),w(m)},En=(n,t)=>new ie(n,(e,o,s,r)=>Fo(e,o,s,r,t),{inCodeMark:!1}),et=(n,t,e)=>En(new RegExp(`(^|[${le}])${se(n)}${Sn(se(t))}(${se(t)})$`),()=>e.create()),Ko=En(new RegExp(`(^|[${le}])\\[${Sn("\\[\\]")}(\\]\\([^()\\s]*\\))$`),n=>{let t=be(n[3].slice(2,-1));return t?g.marks.link.create({href:t}):null}),Vo=[et("**","**",g.marks.strong),et("__","__",g.marks.strong),et("*","*",g.marks.em),et("_","_",g.marks.em),et("`","`",g.marks.code),et("~~","~~",g.marks.strike),Ko],re=["paragraph","list_item"],jo=[tt(/^(#{1,3})\s$/,n=>({type:"heading",attrs:{level:n[1].length}})),tt(/^[-*+]\s$/,{type:"list_item",attrs:{kind:"bullet"}},re),tt(/^\d+[.)]\s$/,{type:"list_item",attrs:{kind:"ordered"}},re),tt(/^\[( |x|X)?\]\s$/,n=>({type:"list_item",attrs:{kind:"check",checked:!!n[1]&&n[1]!==" "}}),re),tt(/^>\s$/,{type:"toggle",attrs:{open:!0}}),tt(/^```$/,{type:"code_block"},["paragraph"],!0),No,...Vo];function qo(n,t,e,o,s){if(s!==" "||e!==o)return!1;let r=t.state,i=r.doc.resolve(e),l=i.parent;if(i.depth!==1||l.type!==W.paragraph||i.parentOffset!==1||l.textContent!=='"'||!t.editable||typeof t.runFormatCommand!="function")return!1;let c=()=>{t.isDestroyed||t.state.doc!==r.doc||t.dispatch(t.state.tr.insertText(" ",e,o))},d=i.before(1);return import("./c-FNIGX4FI.js").then(({quoteFromSpace:u})=>u(n,t,{at:d,from:e,to:o},c),c),!0}var Oi=()=>{let n=Rt.inputRules({rules:jo}),t=n.props.handleTextInput;return n.props.handleTextInput=(e,o,s,r)=>qo(n,e,o,s,r)||t(e,o,s,r),n},Wo=/^\s*\|(.*)\|\s*$/;function Uo(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parent.type!==W.paragraph||e.parentOffset!==e.parent.content.size||vt(n,e.start(),e.end()))return!1;let s=Wo.exec(e.parent.textContent);if(!s)return!1;let r=s[1].split("|").map(l=>l.trim());if(!r.some(Boolean))return!1;let i=Mt([r,r.map(()=>"")],{header:!0});return F(n,t,i,{from:e.start(),to:e.end()})}var vi=()=>at.keymap({Enter:(n,t,e)=>!It(null,e)&&Uo(n,t)});function Ii(n,t){let{$from:e,empty:o}=n.selection;if(!o||e.depth!==1||e.parentOffset!==0)return!1;let s=e.parent;return s.type===W.heading||s.type===W.callout||s.type===W.quote||s.type===W.code_block&&s.content.size===0?(t&&t(w(n.tr.setNodeMarkup(e.before(),W.paragraph,{id:s.attrs.id,pos:s.attrs.pos,parent:s.attrs.parent}))),!0):!1}var{Plugin:In,PluginKey:Ln,TextSelection:$t,NodeSelection:Go}=C,Dn=g.marks,U=g.nodes,Dt=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318":"Ctrl+",$n=n=>{let t=gt(n.doc),{lo:e,hi:o}=n.selection.span(n.doc);return t.slice(e,o+1).filter(s=>s.up===t[e].up)},Lt=(n,t)=>n.state.doc.child(t).attrs.id,Yo=(n,t)=>{let e=0;for(let o=0;o<t;o++)e+=n.child(o).nodeSize;return e},Cn=["aria-haspopup","aria-controls","aria-activedescendant"],Jo="That block is no longer available.",he="This block holds content from a newer version, so it can't be converted here.";function ce(n){let t=n.visualViewport;return t?{left:t.offsetLeft,top:t.offsetTop,width:t.width,height:t.height}:{left:0,top:0,width:n.innerWidth,height:n.innerHeight}}function Xo(n,t,e,o=0){let s=$,r=Math.min(t,Math.max(0,n.width-s*2));return{left:n.left+(n.width-r)/2,top:Math.max(n.top+s,n.top+n.height-e-o-s),width:r}}function Qo(n,t=globalThis.location){return`${t.origin}${t.pathname}${t.search}#${encodeURIComponent(n)}`}function Zo(n){if(!n)return;let t=()=>H("Link copied"),e=()=>H("Could not copy the link.","error");if(!globalThis.navigator?.clipboard?.writeText){e();return}globalThis.navigator.clipboard.writeText(Qo(n)).then(t,e)}var _n=[{key:"up",label:"Move up",icon:"up",hint:`${Dt}\u21E7\u2191`,run:n=>Ht(-1)(n.state,n.dispatch)},{key:"down",label:"Move down",icon:"down",hint:`${Dt}\u21E7\u2193`,run:n=>Ht(1)(n.state,n.dispatch)},{key:"indent",label:"Indent",icon:"indent",hint:"Tab",run:n=>{let t=n.state.doc;Ke(n.state,n.dispatch),n.state.doc===t&&(P(n,"Indent works on list items and inside toggles."),H("Indent works on list items and inside toggles."))}},{key:"outdent",label:"Outdent",icon:"outdent",hint:"\u21E7Tab",run:n=>Ve(n.state,n.dispatch)},{key:"duplicate",label:"Duplicate",icon:"duplicate",hint:`${Dt}D`,run:n=>Ue(n.state,n.dispatch)},{key:"delete",label:"Delete",icon:"trash",hint:"Del",run:n=>Ft(n.state,n.dispatch)},{key:"turn",label:"Turn into",icon:"turn",hint:"\u203A",only:"text",run:(n,t)=>t.openMenu("turn",t.plus)},{key:"link",label:"Copy link",icon:"link",run:(n,t,e)=>Zo(n.state.doc.child(e).attrs.id)},{key:"alt",label:"Alt text\u2026",icon:"alt",only:"image",focus:!1,run:(n,t,e)=>{let o=Lt(n,e);return import("./c-UWT4CXQ4.js").then(s=>s.openAltEditor(n,o))}},{key:"small",label:"Small",icon:"small",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-UWT4CXQ4.js").then(s=>s.setImageAttrs(n,o,{width:240}))}},{key:"medium",label:"Medium",icon:"medium",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-UWT4CXQ4.js").then(s=>s.setImageAttrs(n,o,{width:480}))}},{key:"full",label:"Full width",icon:"full",only:"image",run:(n,t,e)=>{let o=Lt(n,e);return import("./c-UWT4CXQ4.js").then(s=>s.setImageAttrs(n,o,{width:null}))}},{key:"chart",label:"Chart this table",icon:"chart",only:"table",run:(n,t,e)=>{let o=Yo(n.state.doc,e);return te(n).then(({insertChartAfterTable:s})=>s(n,o))}},{key:"csv",label:"Import CSV\u2026",icon:"csv",only:"table",focus:!1,run:(n,t,e)=>Ct(n,null,n.state.doc.child(e).attrs.id)}],ts=n=>{if(!(n.selection instanceof z))return[];let t=$n(n),e=t.every(r=>r.node.isTextblock),o=t.length===1&&t[0].node.type===U.image,s=t.length===1&&t[0].node.type===U.table;return _n.filter(r=>r.only==="text"?e:r.only==="image"?o:r.only==="table"?s:!0)},M=n=>`<svg viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${n}</svg>`,K={plus:M('<path d="M8 3.5v9M3.5 8h9"/>'),grip:M('<path stroke-width="2.2" d="M6 3.5h.01M10 3.5h.01M6 8h.01M10 8h.01M6 12.5h.01M10 12.5h.01"/>'),strong:M('<path d="M5 3h4a2.5 2.5 0 0 1 0 5H5zM5 8h4.6a2.5 2.5 0 0 1 0 5H5z"/>'),em:M('<path d="M10 3H6.5M9.5 13H6M9 3l-2 10"/>'),strike:M('<path d="M3 8h10M10.8 5.2C10.5 4 9.4 3.2 8 3.2c-1.7 0-2.8.9-2.8 2.1M5.2 10.8c.3 1.2 1.4 2 2.8 2 1.7 0 2.8-.9 2.8-2.1"/>'),code:M('<path d="M6 4.5 2.5 8 6 11.5M10 4.5 13.5 8 10 11.5"/>'),link:M('<path d="M7 9a2.5 2.5 0 0 0 3.5 0l2-2A2.5 2.5 0 0 0 9 3.5l-.7.7M9 7a2.5 2.5 0 0 0-3.5 0l-2 2A2.5 2.5 0 0 0 7 12.5l.7-.7"/>'),bullet:M('<path d="M6.5 4.5h7M6.5 8h7M6.5 11.5h7"/><path stroke-width="2.4" d="M3 4.5h.01M3 8h.01M3 11.5h.01"/>'),ordered:M('<path d="M7 4.5h6.5M7 8h6.5M7 11.5h6.5M2.5 3.5l1-.5v3M2.5 9.3c.2-.5.6-.8 1.1-.8.6 0 1 .4 1 .9 0 .9-2.1 1.4-2.1 2.6h2.1"/>'),check:M('<rect x="2.5" y="2.5" width="11" height="11" rx="2.5"/><path d="M5.5 8.2l1.8 1.8 3.4-4"/>'),more:M('<path stroke-width="2.2" d="M3 8h.01M8 8h.01M13 8h.01"/>'),gear:M('<g transform="scale(0.6667)" stroke-width="2.25"><path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/><circle cx="12" cy="12" r="3"/></g>'),close:M('<path d="M4 4l8 8M12 4l-8 8"/>'),up:M('<path d="M8 13V3.5M4 7.5 8 3.5l4 4"/>'),down:M('<path d="M8 3v9.5M4 8.5l4 4 4-4"/>'),indent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M2.5 6l2.5 2-2.5 2"/>'),outdent:M('<path d="M2.5 3.5h11M7 8h6.5M2.5 12.5h11M5 6 2.5 8 5 10"/>'),duplicate:M('<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"/><path d="M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v5A1.5 1.5 0 0 0 4 9.5h.5"/>'),trash:M('<path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5"/>'),turn:M('<path d="M3 5.5h9.5M10 3l2.5 2.5L10 8M13 10.5H3.5M6 8l-2.5 2.5L6 13"/>'),chart:M('<path d="M3 13V3M3 13h10.5M6 10.5V8M9 10.5V5.5M12 10.5V7"/>'),csv:M('<path d="M4 1.5h5L12.5 5v9.5h-8.5zM9 1.5V5h3.5M8 7.5v5M6 10.5l2 2 2-2"/>'),alt:M('<path d="M2.5 12.5 5.5 4l3 8.5M3.6 9.5h3.8M10 12.5V7.5M10 8.5c.4-.7 1.1-1 2-1h.5"/>'),small:M('<rect x="5" y="5" width="6" height="6" rx="1"/>'),medium:M('<rect x="3.5" y="3.5" width="9" height="9" rx="1.2"/>'),full:M('<rect x="1.5" y="3.5" width="13" height="9" rx="1.2"/>')},ae=[["strong","Bold"],["em","Italic"],["strike","Strikethrough"],["link","Link"],["bullet","Bulleted list"],["ordered","Numbered list"],["check","Checklist"],["code","Code"]],Bn=new Set(["strong","em","link"]),es=new Set(["up","down","indent","outdent"]),ns=204,os=52,$=8,Pn=new Set(["bullet","ordered","check"]),ss=[["assignees","Checklist assignees"],["dates","Checklist due dates"]],rs=new Set(["paragraph","heading","list_item"]),lt=n=>{let t=n.selection;if(t instanceof z)return $n(n).map(l=>l.i);let{$from:e,$to:o,empty:s}=t,r=Math.min(!s&&o.depth===0?o.index(0)-1:o.index(0),n.doc.childCount-1),i=[];for(let l=e.index(0);l<=r;l++)i.push(l);return i},Rn=n=>lt(n).filter(t=>{let e=n.doc.child(t);return e.isTextblock&&e.type!==U.code_block}),Nn=(n,t)=>n.type===U.list_item&&n.attrs.kind===t,Hn=(n,t)=>{let e=Rn(n);return e.length>0&&e.every(o=>Nn(n.doc.child(o),t))},is=n=>{let t="";return n.forEach(e=>{t+=e.isText?e.text:e.type===U.hard_break?`
3
3
  `:""}),t};function ls(n){let{$from:t,$to:e,empty:o}=n.selection;if(o||!(n.selection instanceof $t)||t.depth!==1||e.depth!==1||t.parentOffset!==0||e.parentOffset!==e.parent.content.size)return null;let s=lt(n);return s.every(r=>rs.has(n.doc.child(r).type.name))?s:null}function cs(n,t){let e=n.doc.child(t[0]),o=n.selection.$from.before(1),s=n.selection.$to.after(1),r=t.map(u=>is(n.doc.child(u))).join(`
4
4
  `),{id:i,pos:l,parent:c}=e.attrs,d=n.tr.replaceWith(o,s,U.code_block.create({id:i,pos:l,parent:c},r?g.text(r):null));return d.setSelection($t.create(d.doc,o+1,o+1+r.length))}function as(n,t){let e=n.tr,o=n.doc.resolve(n.selection.from).before(1),s=0;for(let r of[...t].reverse()){let i=0;for(let h=0;h<r;h++)i+=n.doc.child(h).nodeSize;let l=n.doc.child(r),{id:c,pos:d,parent:u}=l.attrs,a=l.textContent.split(`
5
- `).map((h,p)=>U.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?g.text(h):null));e.replaceWith(i,i+l.nodeSize,a),s||(s=i+a.reduce((h,p)=>h+p.nodeSize,0))}return s=e.mapping.slice(1).map(s),e.setSelection($t.create(e.doc,o+1,s-1))}var zn=n=>{let t=lt(n);return t.length>0&&t.every(e=>n.doc.child(e).type===U.code_block)?t:null};function An(n,t){if(Pn.has(t))return Hn(n,t);if(t==="code"&&zn(n))return!0;let e=Dn[t],{from:o,to:s,empty:r,$from:i}=n.selection;return r?!!e.isInSet(n.storedMarks||i.marks()):n.doc.rangeHasMark(o,s,e)}function us(n,t){let e=n.state,o=Hn(e,t),s=q.find(l=>l.key===(o?"text":t)),r=Rn(e).filter(l=>o||!Nn(e.doc.child(l),t));if(r.some(l=>!Q(e.doc.child(l),s))){P(n,he);return}let i=e.tr;for(let l of r)G(i,l,s);i.docChanged&&n.dispatch(w(i))}var ue=(n,t,e)=>import("./c-VBLFAQD2.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function On(n,t){if(t==="link")return _e(n);let e=n.state,o=t==="code"?zn(e):null,s=t==="code"&&!o?ls(e):null;Pn.has(t)?us(n,t):o?n.dispatch(w(as(e,o)).scrollIntoView()):s&&s.some(r=>!Q(e.doc.child(r),q.find(i=>i.key==="code")))?P(n,he):s?n.dispatch(w(cs(e,s)).scrollIntoView()):ge.toggleMark(Dn[t])(e,n.dispatch),n.focus()}var y=(n,t,e={})=>{let o=document.createElement(n);t&&(o.className=t);for(let[s,r]of Object.entries(e))o.setAttribute(s,r);return o};function vn(n,t){let e=y("button",`page-tool${Bn.has(n)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=K[n],e}var ds=1600,hs=0,ps=new Ln("page-chrome"),pe=new WeakMap,_t=new Ln("page-slash-range"),fs={init:()=>null,apply(n,t){let e=t;if(e&&n.docChanged){let s=n.mapping.map(e.from,1),r=n.mapping.map(e.to,-1);e=s<=r&&n.doc.textBetween(s,r)===e.text?{...e,from:s,to:r}:null}let o=n.getMeta(_t);return o!==void 0&&(e=o),e}},Yi=()=>new In({key:_t,state:fs}),Fn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(_t,t?{...t,text:e}:null))},Kn=n=>{let t=_t.getState(n);return t?{from:t.from,to:t.to}:null};function Ji(n,t,e,{persist:o=!1}={}){let s=pe.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function Xi(n,t,e){let o=pe.get(n),s=o?.menu;return!s||s.anchor!==t||!e||e===t?!1:(s.anchor=e,e.setAttribute("aria-expanded","true"),n.dom.setAttribute("aria-controls",o.menuId),!0)}var de=class{constructor(t,e){this.view=t,this.onAiTool=e,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.remote=!1,this.dock=y("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=K.more,this.settingsBtn=y("button","page-tool page-tool-desk page-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=K.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","page-tool-sep page-tool-desk"),...ae.map(([r,i])=>vn(r,i)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=K.plus,this.grip=y("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=K.grip,this.bubble=y("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","page-tool page-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=K.more,this.bubble.append(this.bubbleTurn,y("span","page-tool-sep"),...ae.map(([r,i])=>vn(r,i)),this.bubbleMore),this.menuId=`page-menu-${++hs}`,this.menuEl=y("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=r=>r.preventDefault();for(let r of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])r.addEventListener("mousedown",o);for(let r of[this.dock,this.bubble])r.addEventListener("click",i=>{let l=i.target.closest("[data-cmd]");l&&On(this.view,l.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.settingsBtn.addEventListener("click",()=>this.toggleSettings()),this.bubbleTurn.addEventListener("click",()=>this.toggleMenu("turn",this.bubbleTurn)),this.bubbleMore.addEventListener("click",()=>this.toggleMenu("more",this.bubbleMore)),this.dock.addEventListener("keydown",r=>this.dockKey(r)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",r=>{r.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Be(t,this.grip,{index:()=>this.gutterIndex(),onClick:r=>this.gripAction(r)});let s=!1;this.scrim.addEventListener("pointerdown",()=>{s=!0}),this.scrim.addEventListener("click",()=>{s&&this.closeMenu(),s=!1}),this.menuEl.addEventListener("click",r=>{let i=r.target.closest(".page-menu-item");i&&this.pick(Number(i.dataset.index))}),this.menuEl.addEventListener("keydown",r=>{this.key(r)&&r.preventDefault()}),this.onMove=r=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),ds),this.trackHover(r)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>{this.scheduleLayout(),this.placeSettings()},this.onDocDown=r=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(i=>i?.contains(r.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(i=>i.contains(r.target))||this.closeMenu())},this.onSettingsKey=r=>{r.key!=="Escape"||!this.settingsOpen||(r.preventDefault(),r.stopPropagation(),this.closeSettings(!0))},document.addEventListener("mousedown",this.onDocDown,!0),document.addEventListener("keydown",this.onSettingsKey,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,e=t.selection,o=e instanceof z||e instanceof Go?e.from:e.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(e=>this.rendered(e));return this.isPhone()?t.filter(e=>e.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let e=this.win?.getComputedStyle?.(t);return!e||e.display!=="none"}setRoving(t){this.roving=t;let e=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&e.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let e=this.dockControls(),o=e.indexOf(t.target);if(o<0)return;t.preventDefault();let s=e[(o+(t.key==="ArrowRight"?1:-1)+e.length)%e.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return lt(t).map(e=>t.doc.child(e).attrs.id)}idIndex(t){let e=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let e=t.anchor;return e&&e!==this.view.dom&&e.isConnected&&(e.tagName==="BUTTON"||e.hasAttribute("tabindex"))?e:this.view.dom}selectCaretBlock(t=null){let e=this.view.state;if(e.selection instanceof z)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(e.tr.setSelection(zt(e.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(e=>e.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let e=this.view,o=e.posAtCoords({left:e.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=e.state.doc,r=gt(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}buildSettings(){if(this.settingsEl)return this.settingsEl;let t=y("div","page-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","page-settings-head"),o=y("span","page-settings-title");o.textContent="Document settings";let s=y("button","page-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=K.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ss.map(([l,c])=>{let d=y("div","page-settings-row"),u=y("span","page-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","page-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","page-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","page-settings-note");return i.textContent="Hidden values stay saved and come back when turned on.",t.append(e,...r,i),this.settingsEl=t,this.shell.append(t),t}flipSetting(t){let e=this.settingSwitches[t],o=e.getAttribute("aria-checked")!=="true";e.setAttribute("aria-checked",String(o)),Promise.resolve().then(()=>this.settingsAPI.set(t,o)).catch(()=>{e.setAttribute("aria-checked",String(!o)),H("That setting could not be saved.","error")})}openSettings(t=this.settingsBtn){if(!this.settingsAPI)return;this.menu&&this.closeMenu();let e=this.buildSettings(),o=this.settingsAPI.read();for(let[s,r]of Object.entries(this.settingSwitches))r.setAttribute("aria-checked",String(o[s]!==!1));this.settingsOpen=!0,this.settingsAnchor=t,t.setAttribute("aria-expanded","true"),e.hidden=!1,this.placeSettings(),e.querySelector(".page-settings-close")?.focus({preventScroll:!0})}closeSettings(t=!1){if(!this.settingsOpen)return;let e=this.settingsAnchor;this.settingsOpen=!1,this.settingsAnchor=null,this.settingsEl&&(this.settingsEl.hidden=!0),e?.setAttribute("aria-expanded","false"),t&&e?.isConnected&&e.focus({preventScroll:!0})}toggleSettings(){this.settingsOpen?this.closeSettings(!0):this.openSettings(this.settingsBtn)}placeSettings(){let t=this.settingsEl;if(!t||t.hidden||!this.settingsAnchor)return;let e=this.settingsAnchor.getBoundingClientRect(),o=t.offsetWidth||264,s=t.offsetHeight||0;if(this.isPhone()){let c=ce(this.win),d=Math.max(c.left+$,Math.min(e.right-o,c.left+c.width-$-o)),u=e.top-6-s;u<c.top+$&&(u=Math.min(e.bottom+6,c.top+c.height-$-s)),t.style.setProperty("--page-pop-x",`${d}px`),t.style.setProperty("--page-pop-y",`${Math.max(c.top+$,u)}px`);return}let r=this.shell.getBoundingClientRect(),i=Math.max(8,Math.min(e.right-r.left-o,Math.max(8,r.width-o-8))),l=e.bottom-r.top+6;l+s>this.win.innerHeight-8&&e.top-r.top-6-s>=8&&(l=e.top-r.top-6-s),t.style.setProperty("--page-pop-x",`${i}px`),t.style.setProperty("--page-pop-y",`${l}px`)}toggleMenu(t,e){this.menu?this.closeMenu():this.openMenu(t,e)}slashKey(t){let e=this.view.state.doc.resolve(t);return`${e.parent.attrs.id}\0${this.view.state.doc.textBetween(e.start(),t-1)}`}openMenu(t,e,o=null,s=null,r=null){this.closeSettings(),this.menu={mode:t,anchor:e,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[],persist:!1},e.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=Cn.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,e]of this.priorAria)e===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,e);this.priorAria=null}else for(let t of Cn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?ae.filter(([s])=>!Bn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>On(i,s)})):[],o=_n.filter(s=>es.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Dt}u`,run:(s,r)=>ue(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ue(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ue(s,r,"highlight")},...t?[{key:"turn",label:"Turn into",icon:"turn",run:(s,r)=>r.openMenu("turn",r.more)}]:[],{key:"insert",label:"Insert",icon:"+",run:(s,r)=>r.openMenu("insert",r.pickedFrom??r.more,null,null,s.state.doc.child(r.blockIndex()).attrs.id)},...o,...t&&this.settingsAPI?[{key:"settings",label:"Document settings",icon:"gear",focus:!1,run:(s,r)=>r.openSettings(r.more)}]:[],{key:"titleIcon",label:"Page icon",icon:"\u263A",run:s=>Z(s,"titleIcon")},{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>Z(s,"titleCover")},{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>Z(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>Z(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return ts(this.view.state);if(t.mode==="more")return this.moreItems();let e=t.mode==="turn"?q:gn(this.view.state,this.onAiTool?[...At,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:At);return Mn(e,t.query)}currentTypes(){let t=this.view.state;return new Set(lt(t).map(e=>Ot(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=gt(o.doc),r=o.selection,i=e!==null&&r instanceof z&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?We(o,s):Fe(s,e,e);this.view.dispatch(o.tr.setSelection(zt(o.doc,l,c,s)));let d=[];for(let u=l;u<=c;u++)d.push(o.doc.child(u).attrs.id);this.openMenu("actions",t,null,d)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let e=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",e?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=y("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=y("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let l=i===t.active,c=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,d=t.mode==="turn"?"menuitemradio":typeof c=="boolean"?"menuitemcheckbox":e?"option":"menuitem",u=y("button",`page-menu-item${l?" is-active":""}`,{type:"button",role:d,tabindex:!e&&l?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...d==="menuitemradio"?{}:{"aria-selected":l?"true":"false"},...typeof c=="boolean"?{"aria-checked":String(c)}:{}}),a=y("span","page-menu-icon");K[r.icon]?a.innerHTML=K[r.icon]:a.textContent=r.icon||"";let h=y("span","page-menu-label");if(h.textContent=r.label,r.description){let p=y("span","page-menu-text"),f=y("span","page-menu-desc");f.textContent=r.description,p.append(h,f),u.append(a,p)}else u.append(a,h);if(r.hint){let p=y("span","page-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.menuEl.replaceChildren(...s),e&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),e||this.menuEl.querySelectorAll("button")[t.active]?.focus({preventScroll:!0})}pick(t){let e=this.menu,o=e?.items[t];if(!o)return;let s=this.view.state,r=e.slashAt!==null&&s.selection.head>=e.slashAt?{from:e.slashAt-1,to:s.selection.head}:null,i=e.mode==="insert"?e.anchorId?[e.anchorId]:[]:e.ids,l=i.some(d=>!d||this.idIndex(d)<0),c=i.length?this.idIndex(i[0]):-1;if(this.pickedFrom=e.anchor,this.closeMenu(),l&&e.mode!=="external"){P(this.view,Jo),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!Q(s.doc.child(this.idIndex(d)),o))){P(this.view,he),this.view.focus();return}kn(this.view,o,i)}else e.mode==="actions"||e.mode==="more"||e.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,c>=0?c:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):wn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(It(t,this.view))return!1;let e=this.menu;if(!e)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof z&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof z)return this.closeMenu(),this.view.focus(),Ft(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return e.items.length&&(e.active=(e.active+(t.key==="ArrowDown"?1:-1)+e.items.length)%e.items.length,this.renderMenu()),!0;if(t.key==="Enter")return e.items.length&&this.pick(e.active),!0;if(t.key==="Tab"&&e.slashAt===null)return this.closeMenu(),!1;if(t.key==="Escape"){let o=this.invoker();return e.slashAt!==null&&(this.dismissedSlash=this.slashKey(e.slashAt)),this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:e}=this.view.state.selection,o=e.start();if(e.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,e.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=y("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=ce(this.win),o=Math.max(0,e.height-$*2),s=Math.min(280,Math.max(0,e.width-$*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let l=Math.min(i,o),c=Math.max(e.left+$,Math.min(t.left,e.left+e.width-$-s)),d=t.top-6-l;return d<e.top+$&&(d=Math.min(t.top+t.height+6,e.top+e.height-$-l)),{left:c,top:d,width:s,maxHeight:o}}measureLayout(){let t=this.view,e=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let a=0;a<r;a++)i+=e.doc.child(a).nodeSize;let l=t.nodeDOM(i),c={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(l&&l.getBoundingClientRect){let a=l.getBoundingClientRect(),h=parseFloat(getComputedStyle(l).lineHeight)||a.height;c.gutter={top:a.top-o.top+Math.min(a.height,h)/2,left:a.left-o.left}}let d=this.isPhone();if(d){let a=ce(this.win),h=this.dock.offsetHeight||os;c.bar={...Xo(a,this.dock.offsetWidth||ns,h,this.safeBottom()),height:h}}else c.desk=!!this.dock.style.left;let u=e.selection;if(!this.bubble.hidden&&!d){let a=t.coordsAtPos(u.from),h=t.coordsAtPos(u.to,-1),p=(Math.min(a.left,h.left)+Math.max(a.right,h.right))/2;c.bubble={x:p-o.left,y:Math.min(a.top,h.top)-o.top}}if(this.menu&&d){let a=this.menuBox(c.bar);c.menu={x:a.left,y:a.top,width:a.width,maxHeight:a.maxHeight}}else if(this.menu){let a=this.menu,h,p;if(a.slashAt!==null){let f=t.coordsAtPos(a.slashAt-1);h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}else{let f=a.anchor===this.plus?l?.getBoundingClientRect?.()??s:a.anchor.getBoundingClientRect();h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}c.menu={x:Math.max(8,Math.min(h-o.left,o.width-280)),y:p-o.top}}return c}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let e of["left","top","width"])this.dock.style.removeProperty(e);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--page-plus-top",`${t.gutter.top}px`),e.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.page?.settings??null}update(t,e){let o=!this.settingsAPI;if(this.settingsBtn.hidden!==o&&(this.settingsBtn.hidden=o),this.view=t,this.menu&&this.menu.slashAt===null&&e&&e.doc!==t.state.doc)if(this.menu.persist&&this.menu.anchor?.isConnected)this.scheduleLayout();else{let c=this.menuEl.contains(document.activeElement);this.closeMenu(),c&&t.focus()}let s=t.state,r=s.doc.child(this.blockIndex());this.turn.textContent=`${Ot(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof $t&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof z),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),!this.menu&&e&&e.doc!==s.doc&&!this.remote&&t.hasFocus()&&s.selection.empty){let c=s.selection.$head;if(c.depth===1&&c.parent.isTextblock&&!c.parent.type.spec.code){let d=s.doc.textBetween(c.start(),c.pos),u=/(?:^|\s)\/([a-z]*)$/i.exec(d),a=u?c.start()+u.index+u[0].indexOf("/")+1:null;u&&this.slashKey(a)!==this.dismissedSlash&&this.openMenu("insert",this.plus,a,null,c.parent.attrs.id)}}this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0),document.removeEventListener("keydown",this.onSettingsKey,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.settingsEl,this.probe])t?.remove()}};function Qi({onAiTool:n=null}={}){let t=null;return new In({key:ps,view(e){return t=new de(e,n),pe.set(e,t),t},filterTransaction(e){return t&&e.docChanged&&(t.remote=!!e.getMeta(Me)),!0},props:{handleKeyDown(e,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(e,o,s,r){if(r!=="/"||!t)return!1;let i=Ge(e,r);i&&(o=e.state.selection.from-1);let l=e.state.doc.resolve(o);if(l.depth!==1||!l.parent.isTextblock||l.parent.type.spec.code||l.parentOffset>0&&!/\s/.test(e.state.doc.textBetween(o-1,o,"",`
6
- `)))return i;i||e.dispatch(e.state.tr.insertText("/",o,s).setMeta(xt,qt(e.state,o,s,"/")));let c=Math.min(e.state.doc.resolve(o).index(0),e.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,e.state.doc.child(c).attrs.id),!0},handleDOMEvents:{keydown(e,o){return It(o,e)},blur(e){return t&&!(t.menu&&[t.bubbleTurn,t.bubbleMore].includes(t.menu.anchor))&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:ms}=C,me=new WeakMap,gs=n=>typeof n.text=="function"?n.text():new Promise((t,e)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>e(o.error),o.readAsText(n)});function Bt(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".page-csv-error");o||(o=e.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function bs(n){let t=0,e=Ce(n,{maxBytes:Jt,newId:()=>k(t++<n.header.length?"c":"r")});if(!Object.keys(e.cols).length)return null;if(!Object.keys(e.rows).length){let o=Object.fromEntries(Object.keys(e.cols).map(s=>[s,""]));e.rows[k("r")]={pos:A(),cells:o}}return{node:Y(g,k(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function ys({kept:n,total:t}){let e=`This file has ${t} rows. The first ${n} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-FSWRGBVQ.js")).consent,s=(await import("./c-HMYWIHFG.js")).default);let r=o(e);s&&(s.yes=`Insert first ${n} rows and attach the file`);try{return await r,!0}catch{return!1}}var ks=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{e<0&&o.type===g.nodes.table&&o.attrs.id===t&&(e=r)}),e},xs=n=>{let t=!0;return n.descendants(e=>(e.isText&&(t=!1),t)),t};function Ms(n,t,e,o){let s=n.state,r=ks(s.doc,e);if(r<0)return F(s,n.dispatch,t,null,o);let i=0;for(let u=0;u<r;u++)i+=s.doc.child(u).nodeSize;let l=s.doc.child(r);if(!xs(l)||o){let u=s.doc.maybeChild(r+1),a=l.attrs.parent??null,h=A(l.attrs.pos,u?.attrs.pos??null),p=t.type.create({...t.attrs,pos:h,parent:a},t.content),f=i+l.nodeSize,m=s.tr.insert(f,p);return o&&m.insert(f+p.nodeSize,o.type.create({...o.attrs,pos:A(h,u?.attrs.pos??null),parent:a},o.content)),m.setSelection(C.TextSelection.create(m.doc,f+3)),n.dispatch(w(m).scrollIntoView()),!0}let c=t.type.create({...t.attrs,id:l.attrs.id,pos:l.attrs.pos,parent:l.attrs.parent},t.content),d=s.tr.replaceWith(i,i+l.nodeSize,c);return d.setSelection(C.TextSelection.create(d.doc,i+3)),n.dispatch(w(d).scrollIntoView()),!0}async function fe(n,t,{upload:e,remove:o=null,table:s=null}={}){try{n.dom.parentElement.querySelector(".page-csv-error")?.remove();let r=ht(await gs(t)),i=bs(r);if(!i)return Bt(n,"Couldn't read this CSV: no columns."),!1;let l=null;if(i.truncated){if(!await ys(i.truncated))return!1;let u=await e?.(t),a=ye(u?.uploads?.[0]?.url);if(!u?.ok||!a)return Bt(n,"Couldn't attach the original CSV."),!1;l=g.nodes.file.create({id:k(),src:a,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(n.isDestroyed)return!1;if(s)return Ms(n,i.node,s,l);let c=o?Kn(n.state):null;return o&&!c&&Ss(n,o.block),F(n.state,n.dispatch,i.node,c,l)}catch(r){return r instanceof Se?Bt(n,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):Bt(n,"Couldn't read this CSV."),!1}}function Ct(n,t=null,e=null){let o=me.get(n);return o?(t&&Fn(n,t),o._remove=t?{...t,block:ws(n.state.doc,t.from)}:null,o._table=e,o.click(),!0):!1}var ws=(n,t)=>n.child(n.resolve(Math.max(0,Math.min(t,n.content.size))).index(0)).attrs.id;function Ss(n,t){let e=n.state,o=null;return e.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(n.dispatch(e.tr.setSelection(C.TextSelection.near(e.doc.resolve(o)))),!0)}var Vn=n=>[...n].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function al({upload:n}){return new ms({view(t){let e=t.dom.ownerDocument.createElement("input");return e.type="file",e.accept=".csv,text/csv",e.hidden=!0,e.className="page-csv-input",t.dom.parentElement.append(e),me.set(t,e),e.addEventListener("change",()=>{let o=e.files?.[0];o&&fe(t,o,{upload:n,remove:e._remove,table:e._table}),e._remove=null,e._table=null,e.value=""}),{destroy(){me.delete(t),e.remove()}}},props:{handlePaste(t,e){let o=Vn(e.clipboardData?.files||[]);return o.length?(e.preventDefault(),fe(t,o[0],{upload:n}),!0):!1},handleDrop(t,e,o,s){let r=Vn(e.dataTransfer?.files||[]);if(s||!r.length)return!1;e.preventDefault();let i=t.posAtCoords({left:e.clientX,top:e.clientY});return i&&t.dispatch(t.state.tr.setSelection(C.TextSelection.near(t.state.doc.resolve(i.pos)))),fe(t,r[0],{upload:n}),!0}}})}export{Bs as a,qs as b,Je as c,Cs as d,As as e,al as f,hn as g,ni as h,Tt as i,It as j,Oi as k,vi as l,Ii as m,fr as n,mr as o,Ys as p,Js as q,Xs as r,te as s,Yi as t,Fn as u,Kn as v,Ji as w,Xi as x,Qi as y,Gt as z,bo as A,Lr as B,Dr as C,$r as D,_r as E,Br as F,yo as G,ko as H,Pr as I,Rr as J,Nr as K,Hr as L,zr as M,Fr as N,Kr as O,Vr as P,jr as Q,qr as R,Wr as S};
5
+ `).map((h,p)=>U.paragraph.create(p===0?{id:c,pos:d,parent:u}:{parent:u},h?g.text(h):null));e.replaceWith(i,i+l.nodeSize,a),s||(s=i+a.reduce((h,p)=>h+p.nodeSize,0))}return s=e.mapping.slice(1).map(s),e.setSelection($t.create(e.doc,o+1,s-1))}var zn=n=>{let t=lt(n);return t.length>0&&t.every(e=>n.doc.child(e).type===U.code_block)?t:null};function An(n,t){if(Pn.has(t))return Hn(n,t);if(t==="code"&&zn(n))return!0;let e=Dn[t],{from:o,to:s,empty:r,$from:i}=n.selection;return r?!!e.isInSet(n.storedMarks||i.marks()):n.doc.rangeHasMark(o,s,e)}function us(n,t){let e=n.state,o=Hn(e,t),s=q.find(l=>l.key===(o?"text":t)),r=Rn(e).filter(l=>o||!Nn(e.doc.child(l),t));if(r.some(l=>!Q(e.doc.child(l),s))){P(n,he);return}let i=e.tr;for(let l of r)G(i,l,s);i.docChanged&&n.dispatch(w(i))}var ue=(n,t,e)=>import("./c-FNIGX4FI.js").then(o=>o.nativeMenu(n,e,t.pickedFrom??t.more));function On(n,t){if(t==="link")return _e(n);let e=n.state,o=t==="code"?zn(e):null,s=t==="code"&&!o?ls(e):null;Pn.has(t)?us(n,t):o?n.dispatch(w(as(e,o)).scrollIntoView()):s&&s.some(r=>!Q(e.doc.child(r),q.find(i=>i.key==="code")))?P(n,he):s?n.dispatch(w(cs(e,s)).scrollIntoView()):ge.toggleMark(Dn[t])(e,n.dispatch),n.focus()}var y=(n,t,e={})=>{let o=document.createElement(n);t&&(o.className=t);for(let[s,r]of Object.entries(e))o.setAttribute(s,r);return o};function vn(n,t){let e=y("button",`page-tool${Bn.has(n)?" page-tool-primary":" page-tool-desk"}`,{type:"button","data-cmd":n,"aria-label":t,title:t});return e.innerHTML=K[n],e}var ds=1600,hs=0,ps=new Ln("page-chrome"),pe=new WeakMap,_t=new Ln("page-slash-range"),fs={init:()=>null,apply(n,t){let e=t;if(e&&n.docChanged){let s=n.mapping.map(e.from,1),r=n.mapping.map(e.to,-1);e=s<=r&&n.doc.textBetween(s,r)===e.text?{...e,from:s,to:r}:null}let o=n.getMeta(_t);return o!==void 0&&(e=o),e}},Yi=()=>new In({key:_t,state:fs}),Fn=(n,t)=>{let e=t?n.state.doc.textBetween(t.from,t.to):null;n.dispatch(n.state.tr.setMeta(_t,t?{...t,text:e}:null))},Kn=n=>{let t=_t.getState(n);return t?{from:t.from,to:t.to}:null};function Ji(n,t,e,{persist:o=!1}={}){let s=pe.get(n);return s?(s.openMenu("external",t),s.menu.externalItems=e,s.menu.persist=o,s.renderMenu(),!0):!1}function Xi(n,t,e){let o=pe.get(n),s=o?.menu;return!s||s.anchor!==t||!e||e===t?!1:(s.anchor=e,e.setAttribute("aria-expanded","true"),n.dom.setAttribute("aria-controls",o.menuId),!0)}var de=class{constructor(t,e){this.view=t,this.onAiTool=e,this.shell=t.dom.parentElement,this.menu=null,this.priorAria=null,this.movedTimer=0,this.hover=null,this.pendingHover=null,this.win=t.dom.ownerDocument.defaultView??globalThis,this.frame=null,this.destroyed=!1,this.probe=null,this.roving=null,this.remote=!1,this.dock=y("div","page-dock",{role:"toolbar","aria-label":"Formatting"}),this.turn=y("button","page-tool page-tool-turn page-tool-desk",{type:"button","aria-haspopup":"menu"}),this.more=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.more.innerHTML=K.more,this.settingsBtn=y("button","page-tool page-tool-desk page-tool-settings",{type:"button","aria-label":"Document settings",title:"Document settings","aria-haspopup":"dialog","aria-expanded":"false"}),this.settingsBtn.innerHTML=K.gear,this.settingsEl=null,this.settingsOpen=!1,this.settingsAnchor=null,this.settingSwitches={},this.dock.append(this.turn,y("span","page-tool-sep page-tool-desk"),...ae.map(([r,i])=>vn(r,i)),this.more),this.dock.insertBefore(this.settingsBtn,this.more),this.settingsBtn.hidden=!this.settingsAPI,this.plus=y("button","page-plus",{type:"button","aria-label":"Add a block",title:"Add a block"}),this.plus.innerHTML=K.plus,this.grip=y("button","page-grip",{type:"button","aria-label":"Block actions",title:"Drag to move, click for actions","aria-haspopup":"menu"}),this.grip.innerHTML=K.grip,this.bubble=y("div","page-bubble",{role:"toolbar","aria-label":"Selection",hidden:""}),this.bubbleTurn=y("button","page-tool page-tool-turn",{type:"button","aria-haspopup":"menu"}),this.bubbleMore=y("button","page-tool page-tool-primary page-tool-more",{type:"button","aria-label":"More",title:"More","aria-haspopup":"menu"}),this.bubbleMore.innerHTML=K.more,this.bubble.append(this.bubbleTurn,y("span","page-tool-sep"),...ae.map(([r,i])=>vn(r,i)),this.bubbleMore),this.menuId=`page-menu-${++hs}`,this.menuEl=y("div","page-menu",{role:"menu",id:this.menuId,hidden:""}),this.scrim=y("div","page-scrim",{hidden:""}),this.shell.insertBefore(this.dock,t.dom),this.shell.append(this.plus,this.grip,this.bubble,this.scrim,this.menuEl);let o=r=>r.preventDefault();for(let r of[this.dock,this.plus,this.grip,this.bubble,this.menuEl])r.addEventListener("mousedown",o);for(let r of[this.dock,this.bubble])r.addEventListener("click",i=>{let l=i.target.closest("[data-cmd]");l&&On(this.view,l.dataset.cmd)});this.turn.addEventListener("click",()=>this.toggleMenu("turn",this.turn)),this.more.addEventListener("click",()=>this.toggleMenu("more",this.more)),this.settingsBtn.addEventListener("click",()=>this.toggleSettings()),this.bubbleTurn.addEventListener("click",()=>this.toggleMenu("turn",this.bubbleTurn)),this.bubbleMore.addEventListener("click",()=>this.toggleMenu("more",this.bubbleMore)),this.dock.addEventListener("keydown",r=>this.dockKey(r)),this.plus.addEventListener("click",()=>this.fromPlus()),this.grip.addEventListener("click",r=>{r.detail===0&&this.gripAction(this.gutterIndex())}),this.drag=new Be(t,this.grip,{index:()=>this.gutterIndex(),onClick:r=>this.gripAction(r)});let s=!1;this.scrim.addEventListener("pointerdown",()=>{s=!0}),this.scrim.addEventListener("click",()=>{s&&this.closeMenu(),s=!1}),this.menuEl.addEventListener("click",r=>{let i=r.target.closest(".page-menu-item");i&&this.pick(Number(i.dataset.index))}),this.menuEl.addEventListener("keydown",r=>{this.key(r)&&r.preventDefault()}),this.onMove=r=>{this.shell.classList.add("is-moved"),clearTimeout(this.movedTimer),this.movedTimer=setTimeout(()=>this.shell.classList.remove("is-moved"),ds),this.trackHover(r)},this.onKey=()=>{clearTimeout(this.movedTimer),this.shell.classList.remove("is-moved"),this.pendingHover=null,this.setHover(null)},this.onLeave=()=>{this.pendingHover=null,this.setHover(null)},this.onResize=()=>{this.scheduleLayout(),this.placeSettings()},this.onDocDown=r=>{this.settingsOpen&&![this.settingsEl,this.settingsAnchor].some(i=>i?.contains(r.target))&&this.closeSettings(),this.menu&&([this.menuEl,this.plus,this.grip,this.turn,this.bubbleTurn,this.bubbleMore].some(i=>i.contains(r.target))||this.closeMenu())},this.onSettingsKey=r=>{r.key!=="Escape"||!this.settingsOpen||(r.preventDefault(),r.stopPropagation(),this.closeSettings(!0))},document.addEventListener("mousedown",this.onDocDown,!0),document.addEventListener("keydown",this.onSettingsKey,!0),this.shell.addEventListener("mousemove",this.onMove),this.shell.addEventListener("mouseleave",this.onLeave),this.shell.addEventListener("keydown",this.onKey),this.win.addEventListener("resize",this.onResize),this.win.addEventListener("scroll",this.onResize,!0),this.win.visualViewport?.addEventListener("resize",this.onResize),this.win.visualViewport?.addEventListener("scroll",this.onResize),this.update(t,null)}blockIndex(){let t=this.view.state,e=t.selection,o=e instanceof z||e instanceof Go?e.from:e.head;return Math.min(t.doc.resolve(o).index(0),t.doc.childCount-1)}isPhone(){return!!this.win?.matchMedia?.("(max-width: 560px)").matches}gutterIndex(){return this.isPhone()?this.blockIndex():(this.settleHover(),Math.min(this.hover??this.blockIndex(),this.view.state.doc.childCount-1))}dockControls(){let t=[...this.dock.querySelectorAll("button")].filter(e=>this.rendered(e));return this.isPhone()?t.filter(e=>e.classList.contains("page-tool-primary")):t}inRoving(t){return!t||!this.dock.contains(t)||this.isPhone()&&!t.classList.contains("page-tool-primary")?!1:this.rendered(t)}rendered(t){if(t.hidden)return!1;let e=this.win?.getComputedStyle?.(t);return!e||e.display!=="none"}setRoving(t){this.roving=t;let e=new Set(this.dockControls());for(let o of this.dock.querySelectorAll("button"))o.tabIndex=o===t&&e.has(o)?0:-1}leaveToToolbar(){queueMicrotask(()=>{this.view.isDestroyed||this.focusToolbar()})}focusToolbar(){let[t]=this.dockControls();return t?(this.setRoving(t),t.focus(),!0):!1}dockKey(t){if(t.key==="Escape"){t.preventDefault(),this.view.focus();return}if(t.key!=="ArrowRight"&&t.key!=="ArrowLeft")return;let e=this.dockControls(),o=e.indexOf(t.target);if(o<0)return;t.preventDefault();let s=e[(o+(t.key==="ArrowRight"?1:-1)+e.length)%e.length];this.setRoving(s),s.focus()}selectionIds(){let t=this.view.state;return lt(t).map(e=>t.doc.child(e).attrs.id)}idIndex(t){let e=-1;return this.view.state.doc.forEach((o,s,r)=>{o.attrs.id===t&&(e=r)}),e}invoker(){let t=this.menu;if(!t||t.slashAt!==null)return this.view.dom;let e=t.anchor;return e&&e!==this.view.dom&&e.isConnected&&(e.tagName==="BUTTON"||e.hasAttribute("tabindex"))?e:this.view.dom}selectCaretBlock(t=null){let e=this.view.state;if(e.selection instanceof z)return;let o=(t??[]).map(r=>this.idIndex(r)).filter(r=>r>=0),s=o.length?o[0]:this.blockIndex();this.view.dispatch(e.tr.setSelection(zt(e.doc,s,o.length?o[o.length-1]:s)))}gripAction(t){this.menu?this.closeMenu():this.openActions(this.grip,t)}trackHover(t){this.menu||this.drag.state||[this.plus,this.grip,this.dock,this.bubble].some(e=>e.contains(t.target))||(this.pendingHover={clientY:t.clientY},this.scheduleLayout())}hoverAt(t){let e=this.view,o=e.posAtCoords({left:e.dom.getBoundingClientRect().left+2,top:t});if(!o)return;let s=e.state.doc,r=gt(s),i=Math.min(s.resolve(o.inside>=0?o.inside:o.pos).index(0),r.length-1);for(;i>0&&r[i].hidden;)i--;this.hover=i}setHover(t){t!==this.hover&&(this.hover=t,this.scheduleLayout())}settleHover(){if(!this.pendingHover)return;let{clientY:t}=this.pendingHover;this.pendingHover=null,this.hoverAt(t)}fromPlus(){this.view.focus();let t=this.gutterIndex();this.openMenu("insert",this.plus,null,null,this.view.state.doc.child(t).attrs.id)}buildSettings(){if(this.settingsEl)return this.settingsEl;let t=y("div","page-settings",{role:"dialog","aria-label":"Document settings",hidden:""}),e=y("div","page-settings-head"),o=y("span","page-settings-title");o.textContent="Document settings";let s=y("button","page-settings-close",{type:"button","aria-label":"Close settings"});s.innerHTML=K.close,s.addEventListener("click",()=>this.closeSettings(!0)),e.append(o,s);let r=ss.map(([l,c])=>{let d=y("div","page-settings-row"),u=y("span","page-settings-name",{id:`${this.menuId}-set-${l}`});u.textContent=c;let a=y("button","page-settings-switch",{type:"button",role:"switch","aria-checked":"true","aria-labelledby":u.id,"data-setting":l});return a.append(y("span","page-settings-knob")),a.addEventListener("click",()=>this.flipSetting(l)),this.settingSwitches[l]=a,d.append(u,a),d}),i=y("div","page-settings-note");return i.textContent="Hidden values stay saved and come back when turned on.",t.append(e,...r,i),this.settingsEl=t,this.shell.append(t),t}flipSetting(t){let e=this.settingSwitches[t],o=e.getAttribute("aria-checked")!=="true";e.setAttribute("aria-checked",String(o)),Promise.resolve().then(()=>this.settingsAPI.set(t,o)).catch(()=>{e.setAttribute("aria-checked",String(!o)),H("That setting could not be saved.","error")})}openSettings(t=this.settingsBtn){if(!this.settingsAPI)return;this.menu&&this.closeMenu();let e=this.buildSettings(),o=this.settingsAPI.read();for(let[s,r]of Object.entries(this.settingSwitches))r.setAttribute("aria-checked",String(o[s]!==!1));this.settingsOpen=!0,this.settingsAnchor=t,t.setAttribute("aria-expanded","true"),e.hidden=!1,this.placeSettings(),e.querySelector(".page-settings-close")?.focus({preventScroll:!0})}closeSettings(t=!1){if(!this.settingsOpen)return;let e=this.settingsAnchor;this.settingsOpen=!1,this.settingsAnchor=null,this.settingsEl&&(this.settingsEl.hidden=!0),e?.setAttribute("aria-expanded","false"),t&&e?.isConnected&&e.focus({preventScroll:!0})}toggleSettings(){this.settingsOpen?this.closeSettings(!0):this.openSettings(this.settingsBtn)}placeSettings(){let t=this.settingsEl;if(!t||t.hidden||!this.settingsAnchor)return;let e=this.settingsAnchor.getBoundingClientRect(),o=t.offsetWidth||264,s=t.offsetHeight||0;if(this.isPhone()){let c=ce(this.win),d=Math.max(c.left+$,Math.min(e.right-o,c.left+c.width-$-o)),u=e.top-6-s;u<c.top+$&&(u=Math.min(e.bottom+6,c.top+c.height-$-s)),t.style.setProperty("--page-pop-x",`${d}px`),t.style.setProperty("--page-pop-y",`${Math.max(c.top+$,u)}px`);return}let r=this.shell.getBoundingClientRect(),i=Math.max(8,Math.min(e.right-r.left-o,Math.max(8,r.width-o-8))),l=e.bottom-r.top+6;l+s>this.win.innerHeight-8&&e.top-r.top-6-s>=8&&(l=e.top-r.top-6-s),t.style.setProperty("--page-pop-x",`${i}px`),t.style.setProperty("--page-pop-y",`${l}px`)}toggleMenu(t,e){this.menu?this.closeMenu():this.openMenu(t,e)}slashKey(t){let e=this.view.state.doc.resolve(t);return`${e.parent.attrs.id}\0${this.view.state.doc.textBetween(e.start(),t-1)}`}openMenu(t,e,o=null,s=null,r=null){this.closeSettings(),this.menu={mode:t,anchor:e,slashAt:o,anchorId:r,ids:s??(t==="insert"?[]:this.selectionIds()),query:"",active:0,items:[],persist:!1},e.setAttribute("aria-expanded","true"),o!==null?(this.priorAria||(this.priorAria=Cn.map(i=>[i,this.view.dom.getAttribute(i)])),this.view.dom.setAttribute("aria-haspopup","listbox")):this.view.dom.setAttribute("aria-haspopup","menu"),this.view.dom.setAttribute("aria-controls",this.menuId),this.renderMenu()}closeMenu(){if(this.menu?.anchor.setAttribute("aria-expanded","false"),this.menu=null,this.menuEl.hidden=!0,this.scrim.hidden=!0,this.priorAria){for(let[t,e]of this.priorAria)e===null?this.view.dom.removeAttribute(t):this.view.dom.setAttribute(t,e);this.priorAria=null}else for(let t of Cn)this.view.dom.removeAttribute(t)}moreItems(){let t=this.isPhone(),e=t?ae.filter(([s])=>!Bn.has(s)).map(([s,r])=>({key:s,label:r,icon:s,run:i=>On(i,s)})):[],o=_n.filter(s=>es.has(s.key)).map(s=>({...s,blocks:!0}));return[...e,{key:"underline",label:"Underline",icon:"U",hint:`${Dt}u`,run:(s,r)=>ue(s,r,"underline")},{key:"text_color",label:"Text color",icon:"A",hint:"\u203A",run:(s,r)=>ue(s,r,"text_color")},{key:"highlight",label:"Highlight",icon:"\u25A0",hint:"\u203A",run:(s,r)=>ue(s,r,"highlight")},...t?[{key:"turn",label:"Turn into",icon:"turn",run:(s,r)=>r.openMenu("turn",r.more)}]:[],{key:"insert",label:"Insert",icon:"+",run:(s,r)=>r.openMenu("insert",r.pickedFrom??r.more,null,null,s.state.doc.child(r.blockIndex()).attrs.id)},...o,...t&&this.settingsAPI?[{key:"settings",label:"Document settings",icon:"gear",focus:!1,run:(s,r)=>r.openSettings(r.more)}]:[],{key:"titleIcon",label:"Page icon",icon:"\u263A",run:s=>Z(s,"titleIcon")},{key:"titleCover",label:"Add cover",icon:"\u25A4",run:s=>Z(s,"titleCover")},{key:"exportHtml",label:"Export reading copy",icon:"\u21E9",run:s=>Z(s,"exportHtml")},{key:"exportMarkdown",label:"Export as Markdown",icon:"M\u21E9",run:s=>Z(s,"exportMarkdown")}]}menuItems(t){if(t.mode==="external")return t.externalItems||[];if(t.mode==="actions")return ts(this.view.state);if(t.mode==="more")return this.moreItems();let e=t.mode==="turn"?q:gn(this.view.state,this.onAiTool?[...At,{key:"ai",label:"Make a tool with AI\u2026",icon:"\u2726",aliases:["tool","generate"],insert:"ai"}]:At);return Mn(e,t.query)}currentTypes(){let t=this.view.state;return new Set(lt(t).map(e=>Ot(t.doc.child(e)).key))}openActions(t=this.plus,e=null){let o=this.view.state,s=gt(o.doc),r=o.selection,i=e!==null&&r instanceof z&&r.span(o.doc).lo<=e&&e<=r.span(o.doc).hi,{lo:l,hi:c}=e===null||i?We(o,s):Fe(s,e,e);this.view.dispatch(o.tr.setSelection(zt(o.doc,l,c,s)));let d=[];for(let u=l;u<=c;u++)d.push(o.doc.child(u).attrs.id);this.openMenu("actions",t,null,d)}renderMenu(){let t=this.menu;t.items=this.menuItems(t),t.active=Math.min(t.active,Math.max(0,t.items.length-1));let e=t.slashAt!==null,o=t.mode==="turn"?this.currentTypes():null;this.menuEl.setAttribute("role",e?"listbox":"menu");let s=[];if(t.mode==="turn"){let r=y("div","page-menu-title");r.textContent=t.query?`Turn into \u201C${t.query}\u201D`:"Turn into",s.push(r)}if(!t.items.length){let r=y("div","page-menu-empty");r.textContent="No matching blocks",s.push(r)}t.items.forEach((r,i)=>{let l=i===t.active,c=o?o.size===1&&r.key===[...o][0]:typeof r.checked=="boolean"?r.checked:null,d=t.mode==="turn"?"menuitemradio":typeof c=="boolean"?"menuitemcheckbox":e?"option":"menuitem",u=y("button",`page-menu-item${l?" is-active":""}`,{type:"button",role:d,tabindex:!e&&l?"0":"-1",id:`${this.menuId}-${i}`,"data-index":String(i),...d==="menuitemradio"?{}:{"aria-selected":l?"true":"false"},...typeof c=="boolean"?{"aria-checked":String(c)}:{}}),a=y("span","page-menu-icon");K[r.icon]?a.innerHTML=K[r.icon]:a.textContent=r.icon||"";let h=y("span","page-menu-label");if(h.textContent=r.label,r.description){let p=y("span","page-menu-text"),f=y("span","page-menu-desc");f.textContent=r.description,p.append(h,f),u.append(a,p)}else u.append(a,h);if(r.hint){let p=y("span","page-menu-hint");p.textContent=r.hint,u.append(p)}s.push(u)}),this.menuEl.replaceChildren(...s),e&&t.items.length?this.view.dom.setAttribute("aria-activedescendant",`${this.menuId}-${t.active}`):this.view.dom.removeAttribute("aria-activedescendant"),this.menuEl.hidden=!1,this.scrim.hidden=!1,this.scheduleLayout(),e||this.menuEl.querySelectorAll("button")[t.active]?.focus({preventScroll:!0})}pick(t){let e=this.menu,o=e?.items[t];if(!o)return;let s=this.view.state,r=e.slashAt!==null&&s.selection.head>=e.slashAt?{from:e.slashAt-1,to:s.selection.head}:null,i=e.mode==="insert"?e.anchorId?[e.anchorId]:[]:e.ids,l=i.some(d=>!d||this.idIndex(d)<0),c=i.length?this.idIndex(i[0]):-1;if(this.pickedFrom=e.anchor,this.closeMenu(),l&&e.mode!=="external"){P(this.view,Jo),this.view.focus();return}if(e.mode==="turn"){if(i.some(d=>!Q(s.doc.child(this.idIndex(d)),o))){P(this.view,he),this.view.focus();return}kn(this.view,o,i)}else e.mode==="actions"||e.mode==="more"||e.mode==="external"?(o.blocks&&this.selectCaretBlock(i),o.run(this.view,this,c>=0?c:this.blockIndex()),!this.menu&&o.focus!==!1&&this.view.focus()):o.insert==="ai"?this.onAiTool(this.view,r):wn(this.view,o,c>=0?c:this.blockIndex(),r)}key(t){if(It(t,this.view))return!1;let e=this.menu;if(!e)return t.key==="Escape"&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&this.view.state.selection instanceof z&&this.leaveToToolbar(),!1;if((t.key==="Backspace"||t.key==="Delete")&&e.mode==="actions"&&this.view.state.selection instanceof z)return this.closeMenu(),this.view.focus(),Ft(this.view.state,this.view.dispatch),!0;if(t.key==="ArrowDown"||t.key==="ArrowUp")return e.items.length&&(e.active=(e.active+(t.key==="ArrowDown"?1:-1)+e.items.length)%e.items.length,this.renderMenu()),!0;if(t.key==="Enter")return e.items.length&&this.pick(e.active),!0;if(t.key==="Tab"&&e.slashAt===null)return this.closeMenu(),!1;if(t.key==="Escape"){let o=this.invoker();return e.slashAt!==null&&(this.dismissedSlash=this.slashKey(e.slashAt)),this.closeMenu(),o===this.view.dom?this.view.focus():o?.focus?.(),!0}return!1}slashQuery(){let t=this.menu;if(!t||t.slashAt===null)return;let{$head:e}=this.view.state.selection,o=e.start();if(e.pos<t.slashAt||t.slashAt<o||this.view.state.doc.textBetween(t.slashAt-1,t.slashAt)!=="/")return this.closeMenu();if(t.query=this.view.state.doc.textBetween(t.slashAt,e.pos),t.active=0,/\s$/.test(t.query)&&!this.menuItems(t).length)return this.closeMenu();this.renderMenu()}scheduleLayout(){this.frame!==null||this.destroyed||(this.frame=this.win.requestAnimationFrame(()=>{if(this.frame=null,this.destroyed)return;let t=this.measureLayout();this.paintLayout(t)}))}safeBottom(){return this.probe||(this.probe=y("div","page-safe-probe"),this.shell.append(this.probe)),parseFloat(this.win.getComputedStyle(this.probe).paddingBottom)||0}menuBox(t){let e=ce(this.win),o=Math.max(0,e.height-$*2),s=Math.min(280,Math.max(0,e.width-$*2)),r=this.menuEl.style.getPropertyValue("--page-pop-max");this.menuEl.style.removeProperty("--page-pop-max");let i=this.menuEl.offsetHeight||0;r&&this.menuEl.style.setProperty("--page-pop-max",r);let l=Math.min(i,o),c=Math.max(e.left+$,Math.min(t.left,e.left+e.width-$-s)),d=t.top-6-l;return d<e.top+$&&(d=Math.min(t.top+t.height+6,e.top+e.height-$-l)),{left:c,top:d,width:s,maxHeight:o}}measureLayout(){let t=this.view,e=t.state;this.settleHover();let o=this.shell.getBoundingClientRect(),s=t.dom.getBoundingClientRect(),r=this.gutterIndex(),i=0;for(let a=0;a<r;a++)i+=e.doc.child(a).nodeSize;let l=t.nodeDOM(i),c={textLeft:s.left-o.left,gutter:null,bubble:null,menu:null,bar:null,desk:!1};if(l&&l.getBoundingClientRect){let a=l.getBoundingClientRect(),h=parseFloat(getComputedStyle(l).lineHeight)||a.height;c.gutter={top:a.top-o.top+Math.min(a.height,h)/2,left:a.left-o.left}}let d=this.isPhone();if(d){let a=ce(this.win),h=this.dock.offsetHeight||os;c.bar={...Xo(a,this.dock.offsetWidth||ns,h,this.safeBottom()),height:h}}else c.desk=!!this.dock.style.left;let u=e.selection;if(!this.bubble.hidden&&!d){let a=t.coordsAtPos(u.from),h=t.coordsAtPos(u.to,-1),p=(Math.min(a.left,h.left)+Math.max(a.right,h.right))/2;c.bubble={x:p-o.left,y:Math.min(a.top,h.top)-o.top}}if(this.menu&&d){let a=this.menuBox(c.bar);c.menu={x:a.left,y:a.top,width:a.width,maxHeight:a.maxHeight}}else if(this.menu){let a=this.menu,h,p;if(a.slashAt!==null){let f=t.coordsAtPos(a.slashAt-1);h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}else{let f=a.anchor===this.plus?l?.getBoundingClientRect?.()??s:a.anchor.getBoundingClientRect();h=f.left,p=f.bottom+6;let m=this.menuEl.offsetHeight;p+m>this.win.innerHeight-8&&f.top-6-m>=8&&(p=f.top-6-m)}c.menu={x:Math.max(8,Math.min(h-o.left,o.width-280)),y:p-o.top}}return c}paintLayout(t){if(t.bar)this.dock.style.left=`${t.bar.left}px`,this.dock.style.top=`${t.bar.top}px`,this.dock.style.width=`${t.bar.width}px`,this.grip.style.setProperty("--page-grip-lift",`${t.bar.height}px`);else{if(t.desk)for(let e of["left","top","width"])this.dock.style.removeProperty(e);this.grip.style.removeProperty("--page-grip-lift")}if(t.gutter)for(let e of[this.plus,this.grip])e.style.setProperty("--page-plus-top",`${t.gutter.top}px`),e.style.setProperty("--page-plus-left",`${t.gutter.left}px`);this.plus.style.setProperty("--page-text-left",`${t.textLeft}px`),t.bubble&&(this.bubble.style.setProperty("--page-pop-x",`${t.bubble.x}px`),this.bubble.style.setProperty("--page-pop-y",`${t.bubble.y}px`)),t.menu&&(this.menuEl.style.setProperty("--page-pop-x",`${t.menu.x}px`),this.menuEl.style.setProperty("--page-pop-y",`${t.menu.y}px`),t.menu.width!==void 0&&(this.menuEl.style.setProperty("--page-pop-width",`${t.menu.width}px`),this.menuEl.style.setProperty("--page-pop-max",`${t.menu.maxHeight}px`)))}get settingsAPI(){return globalThis.clay?.page?.settings??null}update(t,e){let o=!this.settingsAPI;if(this.settingsBtn.hidden!==o&&(this.settingsBtn.hidden=o),this.view=t,this.menu&&this.menu.slashAt===null&&e&&e.doc!==t.state.doc)if(this.menu.persist&&this.menu.anchor?.isConnected)this.scheduleLayout();else{let c=this.menuEl.contains(document.activeElement);this.closeMenu(),c&&t.focus()}let s=t.state,r=s.doc.child(this.blockIndex());this.turn.textContent=`${Ot(r).label} \u25BE`,this.bubbleTurn.textContent=this.turn.textContent;for(let c of this.dock.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));let l=!!this.menu&&[this.bubbleTurn,this.bubbleMore].includes(this.menu.anchor)||!s.selection.empty&&s.selection instanceof $t&&t.hasFocus();if(this.bubble.hidden=!l,l)for(let c of this.bubble.querySelectorAll("[data-cmd]"))c.setAttribute("aria-pressed",String(An(s,c.dataset.cmd)));if(this.grip.classList.toggle("is-on",s.selection instanceof z),this.inRoving(this.roving)||this.setRoving(this.dockControls()[0]),!this.menu&&e&&e.doc!==s.doc&&!this.remote&&t.hasFocus()&&s.selection.empty){let c=s.selection.$head;if(c.depth===1&&c.parent.isTextblock&&!c.parent.type.spec.code){let d=s.doc.textBetween(c.start(),c.pos),u=/(?:^|\s)\/([a-z]*)$/i.exec(d),a=u?c.start()+u.index+u[0].indexOf("/")+1:null;u&&this.slashKey(a)!==this.dismissedSlash&&this.openMenu("insert",this.plus,a,null,c.parent.attrs.id)}}this.slashQuery(),this.scheduleLayout()}destroy(){this.destroyed=!0,this.frame!==null&&this.win.cancelAnimationFrame(this.frame),this.frame=null,clearTimeout(this.movedTimer),this.drag.destroy(),this.shell.removeEventListener("mousemove",this.onMove),this.shell.removeEventListener("mouseleave",this.onLeave),this.shell.removeEventListener("keydown",this.onKey),this.win.removeEventListener("resize",this.onResize),this.win.removeEventListener("scroll",this.onResize,!0),this.win.visualViewport?.removeEventListener("resize",this.onResize),this.win.visualViewport?.removeEventListener("scroll",this.onResize),document.removeEventListener("mousedown",this.onDocDown,!0),document.removeEventListener("keydown",this.onSettingsKey,!0);for(let t of[this.dock,this.plus,this.grip,this.bubble,this.scrim,this.menuEl,this.settingsEl,this.probe])t?.remove()}};function Qi({onAiTool:n=null}={}){let t=null;return new In({key:ps,view(e){return t=new de(e,n),pe.set(e,t),t},filterTransaction(e){return t&&e.docChanged&&(t.remote=!!e.getMeta(Me)),!0},props:{handleKeyDown(e,o){return t?o.key==="/"&&(o.metaKey||o.ctrlKey)&&!o.altKey&&!t.menu?(o.preventDefault(),t.openActions(),!0):t.key(o):!1},handleTextInput(e,o,s,r){if(r!=="/"||!t)return!1;let i=Ge(e,r);i&&(o=e.state.selection.from-1);let l=e.state.doc.resolve(o);if(l.depth!==1||!l.parent.isTextblock||l.parent.type.spec.code||l.parentOffset>0&&!/\s/.test(e.state.doc.textBetween(o-1,o,"",`
6
+ `)))return i;i||e.dispatch(e.state.tr.insertText("/",o,s).setMeta(xt,qt(e.state,o,s,"/")));let c=Math.min(e.state.doc.resolve(o).index(0),e.state.doc.childCount-1);return t.openMenu("insert",t.plus,o+1,null,e.state.doc.child(c).attrs.id),!0},handleDOMEvents:{keydown(e,o){return It(o,e)},blur(e){return t&&!(t.menu&&[t.bubbleTurn,t.bubbleMore].includes(t.menu.anchor))&&(t.bubble.hidden=!0),!1}}}})}var{Plugin:ms}=C,me=new WeakMap,gs=n=>typeof n.text=="function"?n.text():new Promise((t,e)=>{let o=new FileReader;o.onload=()=>t(o.result),o.onerror=()=>e(o.error),o.readAsText(n)});function Bt(n,t){let e=n.dom.ownerDocument,o=n.dom.parentElement.querySelector(".page-csv-error");o||(o=e.createElement("div"),o.className="page-csv-error",o.setAttribute("role","alert"),n.dom.parentElement.append(o)),o.textContent=t}function bs(n){let t=0,e=Ce(n,{maxBytes:Jt,newId:()=>k(t++<n.header.length?"c":"r")});if(!Object.keys(e.cols).length)return null;if(!Object.keys(e.rows).length){let o=Object.fromEntries(Object.keys(e.cols).map(s=>[s,""]));e.rows[k("r")]={pos:A(),cells:o}}return{node:Y(g,k(),{t:"table",pos:null,cols:e.cols,rows:e.rows}),truncated:e.truncated}}async function ys({kept:n,total:t}){let e=`This file has ${t} rows. The first ${n} fit in a table.`,o=globalThis.clay?.confirm,s=globalThis.clay?.modal;o||(o=(await import("./c-ECY5AZMH.js")).consent,s=(await import("./c-DP4X4JID.js")).default);let r=o(e);s&&(s.yes=`Insert first ${n} rows and attach the file`);try{return await r,!0}catch{return!1}}var ks=(n,t)=>{let e=-1;return n.forEach((o,s,r)=>{e<0&&o.type===g.nodes.table&&o.attrs.id===t&&(e=r)}),e},xs=n=>{let t=!0;return n.descendants(e=>(e.isText&&(t=!1),t)),t};function Ms(n,t,e,o){let s=n.state,r=ks(s.doc,e);if(r<0)return F(s,n.dispatch,t,null,o);let i=0;for(let u=0;u<r;u++)i+=s.doc.child(u).nodeSize;let l=s.doc.child(r);if(!xs(l)||o){let u=s.doc.maybeChild(r+1),a=l.attrs.parent??null,h=A(l.attrs.pos,u?.attrs.pos??null),p=t.type.create({...t.attrs,pos:h,parent:a},t.content),f=i+l.nodeSize,m=s.tr.insert(f,p);return o&&m.insert(f+p.nodeSize,o.type.create({...o.attrs,pos:A(h,u?.attrs.pos??null),parent:a},o.content)),m.setSelection(C.TextSelection.create(m.doc,f+3)),n.dispatch(w(m).scrollIntoView()),!0}let c=t.type.create({...t.attrs,id:l.attrs.id,pos:l.attrs.pos,parent:l.attrs.parent},t.content),d=s.tr.replaceWith(i,i+l.nodeSize,c);return d.setSelection(C.TextSelection.create(d.doc,i+3)),n.dispatch(w(d).scrollIntoView()),!0}async function fe(n,t,{upload:e,remove:o=null,table:s=null}={}){try{n.dom.parentElement.querySelector(".page-csv-error")?.remove();let r=ht(await gs(t)),i=bs(r);if(!i)return Bt(n,"Couldn't read this CSV: no columns."),!1;let l=null;if(i.truncated){if(!await ys(i.truncated))return!1;let u=await e?.(t),a=ye(u?.uploads?.[0]?.url);if(!u?.ok||!a)return Bt(n,"Couldn't attach the original CSV."),!1;l=g.nodes.file.create({id:k(),src:a,name:t.name,size:t.size??null,mime:t.type||"text/csv"})}if(n.isDestroyed)return!1;if(s)return Ms(n,i.node,s,l);let c=o?Kn(n.state):null;return o&&!c&&Ss(n,o.block),F(n.state,n.dispatch,i.node,c,l)}catch(r){return r instanceof Se?Bt(n,`Couldn't read this CSV: unclosed quote on line ${r.line}.`):Bt(n,"Couldn't read this CSV."),!1}}function Ct(n,t=null,e=null){let o=me.get(n);return o?(t&&Fn(n,t),o._remove=t?{...t,block:ws(n.state.doc,t.from)}:null,o._table=e,o.click(),!0):!1}var ws=(n,t)=>n.child(n.resolve(Math.max(0,Math.min(t,n.content.size))).index(0)).attrs.id;function Ss(n,t){let e=n.state,o=null;return e.doc.forEach((s,r)=>{o===null&&s.attrs.id===t&&(o=r)}),o===null?!1:(n.dispatch(e.tr.setSelection(C.TextSelection.near(e.doc.resolve(o)))),!0)}var Vn=n=>[...n].filter(t=>/\.csv$/i.test(t.name||"")||/^(text\/csv|application\/csv)$/i.test(t.type||""));function al({upload:n}){return new ms({view(t){let e=t.dom.ownerDocument.createElement("input");return e.type="file",e.accept=".csv,text/csv",e.hidden=!0,e.className="page-csv-input",t.dom.parentElement.append(e),me.set(t,e),e.addEventListener("change",()=>{let o=e.files?.[0];o&&fe(t,o,{upload:n,remove:e._remove,table:e._table}),e._remove=null,e._table=null,e.value=""}),{destroy(){me.delete(t),e.remove()}}},props:{handlePaste(t,e){let o=Vn(e.clipboardData?.files||[]);return o.length?(e.preventDefault(),fe(t,o[0],{upload:n}),!0):!1},handleDrop(t,e,o,s){let r=Vn(e.dataTransfer?.files||[]);if(s||!r.length)return!1;e.preventDefault();let i=t.posAtCoords({left:e.clientX,top:e.clientY});return i&&t.dispatch(t.state.tr.setSelection(C.TextSelection.near(t.state.doc.resolve(i.pos)))),fe(t,r[0],{upload:n}),!0}}})}export{Bs as a,qs as b,Je as c,Cs as d,As as e,al as f,hn as g,ni as h,Tt as i,It as j,Oi as k,vi as l,Ii as m,fr as n,mr as o,Ys as p,Js as q,Xs as r,te as s,Yi as t,Fn as u,Kn as v,Ji as w,Xi as x,Qi as y,Gt as z,bo as A,Lr as B,Dr as C,$r as D,_r as E,Br as F,yo as G,ko as H,Pr as I,Rr as J,Nr as K,Hr as L,zr as M,Fr as N,Kr as O,Vr as P,jr as Q,qr as R,Wr as S};