@panphora/clayjs 1.16.0 → 1.17.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 (283) 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 +7917 -5621
  11. package/dist/m/attrs/refetch-on-save-ZUE7PSCI.js +1 -0
  12. package/dist/m/attrs/save-freeze-MYNVXREN.js +1 -0
  13. package/dist/m/c-2YYDMLNZ.js +1 -0
  14. package/dist/m/c-336SGU5W.js +1 -0
  15. package/dist/m/c-3H6BZDNJ.js +6 -0
  16. package/dist/m/{c-LR4CGEPT.js → c-3RUU4TPX.js} +1 -1
  17. package/dist/m/c-3XIRD4NU.js +1 -0
  18. package/dist/m/c-4DFEJ2PO.js +3 -0
  19. package/dist/m/c-56QRZTZH.js +1 -0
  20. package/dist/m/c-5J4E7O4Y.js +4 -0
  21. package/dist/m/c-5LKDWQTL.js +19 -0
  22. package/dist/m/c-5QWQ7A5L.js +1 -0
  23. package/dist/m/c-5RJFTLSF.js +1 -0
  24. package/dist/m/c-6AZOGAPE.js +1 -0
  25. package/dist/m/{c-Y6USGTS5.js → c-6CRUUXOX.js} +5 -5
  26. package/dist/m/{c-54RCDCBU.js → c-6KEVEQ7L.js} +1 -1
  27. package/dist/m/{c-LTGMXXKO.js → c-6NC5I2TV.js} +1 -1
  28. package/dist/m/{c-YDH7Q3NY.js → c-74MGYWZF.js} +1 -1
  29. package/dist/m/{c-Z36J63PP.js → c-7OLLJPWP.js} +1 -1
  30. package/dist/m/c-A3E3NIMC.js +1 -0
  31. package/dist/m/{c-5R4PTRG2.js → c-AMSNPOCX.js} +1 -1
  32. package/dist/m/c-B3JM5ZXC.js +1 -0
  33. package/dist/m/c-BPF2NSPV.js +1 -0
  34. package/dist/m/c-BQ6LOBEE.js +1 -0
  35. package/dist/m/c-CJ3A7ZKE.js +1 -0
  36. package/dist/m/c-CQHPGKX2.js +1 -0
  37. package/dist/m/c-DCXOXBF3.js +1 -0
  38. package/dist/m/c-DFS4XZJV.js +2 -0
  39. package/dist/m/{c-F3CKJTJS.js → c-DNENWY4O.js} +1 -1
  40. package/dist/m/c-E4LIR5X5.js +1 -0
  41. package/dist/m/c-EVCQ3BKA.js +1 -0
  42. package/dist/m/{c-5Y6TNX5W.js → c-EZU56NQV.js} +2 -2
  43. package/dist/m/c-FDNHHZY5.js +1 -0
  44. package/dist/m/{c-SWRJFCNN.js → c-FRLHSY7E.js} +1 -1
  45. package/dist/m/c-FROJUZMV.js +1 -0
  46. package/dist/m/c-G2JPKCTP.js +1 -0
  47. package/dist/m/c-GB6TU7WV.js +1 -0
  48. package/dist/m/{c-GB3JTV6E.js → c-GFJJEBTU.js} +1 -1
  49. package/dist/m/{c-J7CA54IP.js → c-GSFIGKOP.js} +1 -1
  50. package/dist/m/{c-OYTFP5QN.js → c-GY422N3Q.js} +1 -1
  51. package/dist/m/c-HAWFNBYG.js +1 -0
  52. package/dist/m/{c-33HUYEDI.js → c-HDDEEL77.js} +1 -1
  53. package/dist/m/c-HFKUVACH.js +1 -0
  54. package/dist/m/c-HHDFCNHV.js +1 -0
  55. package/dist/m/c-I2ZATQCD.js +2 -0
  56. package/dist/m/c-IEM4NTCS.js +1 -0
  57. package/dist/m/c-IW6GGOU2.js +1 -0
  58. package/dist/m/{c-SGCCC4FW.js → c-JDCX26UP.js} +2 -2
  59. package/dist/m/c-JRKY44DK.js +1 -0
  60. package/dist/m/c-JU3NK25H.js +1 -0
  61. package/dist/m/{c-VFX45IZQ.js → c-KAU6E43D.js} +1 -1
  62. package/dist/m/c-KBS3UV6B.js +1 -0
  63. package/dist/m/c-KGVGROZT.js +1 -0
  64. package/dist/m/{c-YG2NJYS6.js → c-KQ6TYJAP.js} +2 -2
  65. package/dist/m/{c-2JL6E75N.js → c-KU3ZFADW.js} +1 -1
  66. package/dist/m/c-LWLBHLVC.js +3 -0
  67. package/dist/m/c-M2L47S2X.js +7 -0
  68. package/dist/m/c-MFP2ZWD4.js +1 -0
  69. package/dist/m/{c-4YSCRICO.js → c-MKSQ4Y57.js} +1 -1
  70. package/dist/m/{c-2M73252O.js → c-NUFFJVVJ.js} +1 -1
  71. package/dist/m/c-NUHSPT5P.js +1 -0
  72. package/dist/m/c-O72HVYSA.js +1 -0
  73. package/dist/m/c-OW5QIGG3.js +1 -0
  74. package/dist/m/c-PGRCK73F.js +1 -0
  75. package/dist/m/{c-4DRMS4QG.js → c-PS5ARVWR.js} +1 -1
  76. package/dist/m/c-Q622NS2Y.js +1 -0
  77. package/dist/m/c-Q7NQD65V.js +1 -0
  78. package/dist/m/c-QH63LQOS.js +1 -0
  79. package/dist/m/{c-TQZ2JYHD.js → c-QICP2YR5.js} +1 -1
  80. package/dist/m/{c-7VGZ7RU5.js → c-QJ4OM3G6.js} +1 -1
  81. package/dist/m/{c-MMUIUUZG.js → c-R3L7ZJGB.js} +1 -1
  82. package/dist/m/c-R7IWVINQ.js +1 -0
  83. package/dist/m/{c-HVYXIS72.js → c-RSMOODDU.js} +1 -1
  84. package/dist/m/{c-KKWLDOPM.js → c-RYUXUUBX.js} +1 -1
  85. package/dist/m/c-S4ZEH46B.js +9 -0
  86. package/dist/m/c-SDAXDM2D.js +1 -0
  87. package/dist/m/c-SMBZG5X4.js +1 -0
  88. package/dist/m/{c-UXBMRDZB.js → c-SMGU7RT3.js} +1 -1
  89. package/dist/m/c-SPIORRYS.js +1 -0
  90. package/dist/m/c-SWLRT66R.js +1 -0
  91. package/dist/m/c-SZGYW5HT.js +1 -0
  92. package/dist/m/c-TCJTVAFN.js +1 -0
  93. package/dist/m/{c-HRDCD3WN.js → c-TJ6WOJL3.js} +1 -1
  94. package/dist/m/c-TYLXX4NF.js +21 -0
  95. package/dist/m/c-U62OB4BT.js +1 -0
  96. package/dist/m/{c-NMJRXKPC.js → c-U6YWUAR3.js} +1 -1
  97. package/dist/m/c-UDCSU5G5.js +2 -0
  98. package/dist/m/{c-NZMNXVF6.js → c-UDUUJPFZ.js} +1 -1
  99. package/dist/m/c-VE6ZMYMC.js +1 -0
  100. package/dist/m/c-VG5XIN4T.js +1 -0
  101. package/dist/m/c-VHM5XQHK.js +1 -0
  102. package/dist/m/c-VI5RMSVY.js +1 -0
  103. package/dist/m/c-VRZN56XY.js +1 -0
  104. package/dist/m/c-W5MCHEGA.js +1 -0
  105. package/dist/m/c-WDC5GVKU.js +1 -0
  106. package/dist/m/c-WWXIDH4O.js +28 -0
  107. package/dist/m/{c-QIX5BJYN.js → c-XCNTK76U.js} +1 -1
  108. package/dist/m/c-XMS6DPBR.js +1 -0
  109. package/dist/m/c-Y5HBBIQ4.js +1 -0
  110. package/dist/m/{c-5M4YEKCX.js → c-ZVPVXTJF.js} +1 -1
  111. package/dist/m/c-ZVRKXKM7.js +1 -0
  112. package/dist/m/{c-HT33EQRN.js → c-ZWIOJGMT.js} +1 -1
  113. package/dist/m/core/admin-attrs-QHOKPJ7W.js +1 -0
  114. package/dist/m/core/autosave-HRYGUWV6.js +1 -0
  115. package/dist/m/core/conflict-notice-6MROJN2L.js +1 -0
  116. package/dist/m/core/host-permission-FNXVEFNE.js +1 -0
  117. package/dist/m/core/is-edit-mode-KTWA3O5N.js +1 -0
  118. package/dist/m/core/{persist-HKHA66IY.js → persist-JFYRHMRJ.js} +1 -1
  119. package/dist/m/core/recovery-FLTCC2OC.js +1 -0
  120. package/dist/m/core/save-HQZ4S667.js +1 -0
  121. package/dist/m/core/save-core-KGQWFUNH.js +1 -0
  122. package/dist/m/core/snapshot-EGQZNT45.js +1 -0
  123. package/dist/m/core/unsaved-warning-IDJLD66H.js +1 -0
  124. package/dist/m/events/index-RN2JNGBV.js +1 -0
  125. package/dist/m/internals/index-PVXGPUDA.js +1 -0
  126. package/dist/m/lib/cache-bust-MUMFXZK6.js +1 -0
  127. package/dist/m/loader-S4I7GKXR.js +1 -0
  128. package/dist/m/manifest-4C419D67.js +1 -0
  129. package/dist/m/manifest-edit-B077F288.js +1 -0
  130. package/dist/m/manifest.json +1555 -1058
  131. package/dist/m/options/options-EJMS3K24.js +1 -0
  132. package/dist/m/page/{editor-XUTB2HB2.js → editor-NNJA4OKD.js} +21 -8
  133. package/dist/m/plugins/{ai-edit-ZQ4CGWIP.js → ai-edit-QN4PMMNL.js} +1 -1
  134. package/dist/m/plugins/demo-RM5IR6AO.js +1 -0
  135. package/dist/m/plugins/indicator-URDBBOQO.js +1 -0
  136. package/dist/m/plugins/live-HFWD4OIH.js +1 -0
  137. package/dist/m/plugins/{menu-HCKO3DSP.js → menu-3HIEQSI6.js} +2 -2
  138. package/dist/m/plugins/page-JOKB6XPR.js +2 -0
  139. package/dist/m/plugins/page-view-NXOJHNW6.js +1 -0
  140. package/dist/m/plugins/people-SGPJKANK.js +1 -0
  141. package/dist/m/plugins/{richclay-RC3L2F6X.js → richclay-NRQDSWX6.js} +2 -2
  142. package/dist/m/plugins/sortable-GWT4PWDV.js +1 -0
  143. package/dist/m/plugins/source-4ZRSAIYM.js +1 -0
  144. package/dist/m/plugins/undo-VDA5P7FH.js +1 -0
  145. package/dist/m/plugins/{upgrade-ZNYODP5Y.js → upgrade-W7FG5VFG.js} +1 -1
  146. package/dist/m/plugins/upload-WLYKK6TL.js +1 -0
  147. package/dist/m/plugins/visitor-drafts-LIDY7NH6.js +21 -0
  148. package/dist/m/plugins/visitor-drafts-owner-ZXCKBZE7.js +1 -0
  149. package/dist/m/plugins/wire-4N6GYAF6.js +1 -0
  150. package/dist/m/{reader-core-ILWLXVMP.js → reader-core-DXYCURFF.js} +2 -2
  151. package/dist/m/sync/live-sync-J7VMYTKS.js +1 -0
  152. package/dist/m/ui/{index-EVHKMKBL.js → index-3JLVI27O.js} +1 -1
  153. package/dist/offline-manifest.json +857 -623
  154. package/dist/page/themes/light-1.css +25 -1
  155. package/dist/server/core.cjs +115 -24
  156. package/package.json +1 -1
  157. package/src/core/boot-phase.js +2 -1
  158. package/src/core/conflict-download.js +3 -29
  159. package/src/core/download.js +32 -0
  160. package/src/core/host-meta.js +18 -0
  161. package/src/core/save-core.js +8 -4
  162. package/src/core/save.js +4 -4
  163. package/src/core/snapshot.js +39 -1
  164. package/src/lib/autosave-scheduler.js +3 -4
  165. package/src/page/blocks.js +34 -1
  166. package/src/page/board-views.js +2 -16
  167. package/src/page/chart-tables.js +11 -0
  168. package/src/page/chart.js +6 -10
  169. package/src/page/checkpoint-proof.js +289 -0
  170. package/src/page/chrome.js +24 -6
  171. package/src/page/document-title-dom.js +12 -0
  172. package/src/page/document-title-runtime.js +15 -1
  173. package/src/page/document-title.js +4 -1
  174. package/src/page/editor.js +77 -12
  175. package/src/page/emoji-data.js +162 -0
  176. package/src/page/features/board.js +12 -3
  177. package/src/page/features/chart.js +11 -0
  178. package/src/page/features/dates.js +180 -0
  179. package/src/page/features/emoji.js +187 -0
  180. package/src/page/features/mentions.js +188 -0
  181. package/src/page/features/registry.js +6 -1
  182. package/src/page/features/table.js +2 -2
  183. package/src/page/format-command.js +9 -0
  184. package/src/page/format-host.js +54 -0
  185. package/src/page/format-native-commands.js +142 -0
  186. package/src/page/format-native.js +42 -0
  187. package/src/page/inline.js +32 -8
  188. package/src/page/items.js +15 -3
  189. package/src/page/markdown.js +26 -2
  190. package/src/page/mention-picker.js +99 -0
  191. package/src/page/merge.js +1 -1
  192. package/src/page/projection.js +58 -15
  193. package/src/page/save-projection.js +39 -0
  194. package/src/page/save-states.js +1 -1
  195. package/src/page/schema.js +33 -0
  196. package/src/page/themes/content.css +25 -1
  197. package/src/page/themes/light-1.css +25 -1
  198. package/src/page/view-hooks.js +32 -0
  199. package/src/page/ybind/binding.js +31 -4
  200. package/src/page/ybind/marks.js +2 -1
  201. package/src/page/ybind/provider.js +13 -2
  202. package/src/page/ybind/recovery-replay.js +362 -4
  203. package/src/plugins/live.js +37 -1
  204. package/src/plugins/page.js +117 -3
  205. package/src/plugins/visitor-drafts/intro.js +2 -1
  206. package/src/server/checkpoint/index.js +2 -2
  207. package/src/sync/saved-stream.js +17 -8
  208. package/dist/m/attrs/refetch-on-save-NWPPXOCZ.js +0 -1
  209. package/dist/m/attrs/save-freeze-FUP4Q4X3.js +0 -1
  210. package/dist/m/c-35NBGMZB.js +0 -1
  211. package/dist/m/c-3IQRECYS.js +0 -1
  212. package/dist/m/c-4B6H4G5V.js +0 -1
  213. package/dist/m/c-4FFHZM32.js +0 -1
  214. package/dist/m/c-66O32MV3.js +0 -28
  215. package/dist/m/c-7O6AFR65.js +0 -1
  216. package/dist/m/c-ANQTJ3B5.js +0 -2
  217. package/dist/m/c-AYVOREBE.js +0 -1
  218. package/dist/m/c-B2ZXPOS3.js +0 -3
  219. package/dist/m/c-BMIZKMPV.js +0 -1
  220. package/dist/m/c-CJZSLMVQ.js +0 -1
  221. package/dist/m/c-DBE6ORSI.js +0 -1
  222. package/dist/m/c-EDHUR4MX.js +0 -1
  223. package/dist/m/c-EY6UOM54.js +0 -1
  224. package/dist/m/c-F7Y6FLPY.js +0 -1
  225. package/dist/m/c-FA4DZVTC.js +0 -1
  226. package/dist/m/c-G2BUZITR.js +0 -1
  227. package/dist/m/c-GBGWXTX4.js +0 -1
  228. package/dist/m/c-GHBCCVG4.js +0 -1
  229. package/dist/m/c-IB52R237.js +0 -1
  230. package/dist/m/c-IKWNE4R4.js +0 -1
  231. package/dist/m/c-IU3IYEU6.js +0 -1
  232. package/dist/m/c-IZ2EBRAJ.js +0 -1
  233. package/dist/m/c-KR4UW4KW.js +0 -1
  234. package/dist/m/c-KY3VJGUA.js +0 -8
  235. package/dist/m/c-LXENEBV7.js +0 -1
  236. package/dist/m/c-PPOSCAQD.js +0 -1
  237. package/dist/m/c-QQHEX6HA.js +0 -1
  238. package/dist/m/c-R7RMANJI.js +0 -9
  239. package/dist/m/c-RI4NT75Y.js +0 -1
  240. package/dist/m/c-RUJKSUQW.js +0 -1
  241. package/dist/m/c-T4VO4OCB.js +0 -1
  242. package/dist/m/c-TR6RMDQ7.js +0 -3
  243. package/dist/m/c-UKHTLWUW.js +0 -1
  244. package/dist/m/c-UNN7LWCT.js +0 -1
  245. package/dist/m/c-V7PZZRG7.js +0 -1
  246. package/dist/m/c-VL52ADDR.js +0 -1
  247. package/dist/m/c-WWDBYXLK.js +0 -1
  248. package/dist/m/c-XNNW2CWK.js +0 -1
  249. package/dist/m/c-Z4VRC7GU.js +0 -7
  250. package/dist/m/c-Z6K52OLP.js +0 -19
  251. package/dist/m/c-ZDY2MDAA.js +0 -21
  252. package/dist/m/core/admin-attrs-VGNLAUDK.js +0 -1
  253. package/dist/m/core/autosave-E4PEFPZ6.js +0 -1
  254. package/dist/m/core/conflict-notice-VQ6Y64PH.js +0 -1
  255. package/dist/m/core/host-permission-XN3K2IW3.js +0 -1
  256. package/dist/m/core/is-edit-mode-JXHDVGUL.js +0 -1
  257. package/dist/m/core/recovery-TBBSICE2.js +0 -1
  258. package/dist/m/core/save-WUCHTQBE.js +0 -1
  259. package/dist/m/core/save-core-FJVHT5M3.js +0 -1
  260. package/dist/m/core/snapshot-F3SWDZMM.js +0 -1
  261. package/dist/m/core/unsaved-warning-STKBHE6G.js +0 -1
  262. package/dist/m/events/index-23DPTUT4.js +0 -1
  263. package/dist/m/internals/index-WOVAP3RU.js +0 -1
  264. package/dist/m/lib/cache-bust-CGWT6ZJI.js +0 -1
  265. package/dist/m/loader-HXX6YNH5.js +0 -1
  266. package/dist/m/manifest-F22DEDAC.js +0 -1
  267. package/dist/m/manifest-edit-C3C7376B.js +0 -1
  268. package/dist/m/options/options-2LH76JQ3.js +0 -1
  269. package/dist/m/plugins/demo-ZIBFAA3R.js +0 -1
  270. package/dist/m/plugins/indicator-PV4YW2ID.js +0 -1
  271. package/dist/m/plugins/live-NUTTXSBS.js +0 -1
  272. package/dist/m/plugins/page-KSUH7G6J.js +0 -2
  273. package/dist/m/plugins/page-view-W73OW7WI.js +0 -1
  274. package/dist/m/plugins/people-AJJ32YCG.js +0 -1
  275. package/dist/m/plugins/sortable-YRMQX3ZU.js +0 -1
  276. package/dist/m/plugins/source-KHK5UUSK.js +0 -1
  277. package/dist/m/plugins/undo-OF2L3CXU.js +0 -1
  278. package/dist/m/plugins/upload-XSGNILUY.js +0 -1
  279. package/dist/m/plugins/visitor-drafts-XK5GW55Q.js +0 -21
  280. package/dist/m/plugins/visitor-drafts-owner-KSSH75EV.js +0 -1
  281. package/dist/m/plugins/wire-ZWVWKF76.js +0 -1
  282. package/dist/m/sync/live-sync-4AUVXVJU.js +0 -1
  283. /package/dist/m/plugins/{richclay-RC3L2F6X.js.LEGAL.txt → richclay-NRQDSWX6.js.LEGAL.txt} +0 -0
@@ -0,0 +1 @@
1
+ import{a as P}from"./c-SWLRT66R.js";import{b as h,c as y,d as A,e as E,h as F}from"./c-SDAXDM2D.js";import"./c-TQEMVJCS.js";import"./c-VHNSBD2M.js";var x="This document uses a newer page format; update the editor in the other tabs to keep writing",G=s=>({status:"upgrade-required",code:y,required:s,minimum:s,message:x});function N({host:s,capability:w=1,supported:T=()=>!0,installed:f=()=>null,revision:d=()=>null,lane:g=null}={}){if(!s||typeof s.activate!="function")throw new TypeError("format-gate: a host adapter is required");let t=0,o=null,c=!1,n=!1;function l(e){return t=Math.max(t,A(e)),F(t),t}async function v(){try{let e=await s.read();l(e?.floor??E(e?.html))}catch{}return t}async function _(){try{let e=await s.capabilities();return Array.isArray(e)?e:[]}catch{return[]}}async function M(){try{return await T()!==!1}catch{return!1}}async function R(){if(n)return{status:"disposed",retry:!1};if(!await M())return{status:"unsupported-host",code:"page-format-unsupported",extension:h};if(await v(),t>=1)return{status:"active",floor:t};let e=await _(),r=P({floor:t,required:1,capability:w,admitted:e});if(!r.ok)return G(r.minimum);let u={revision:d(),installed:f()},i;try{i=await s.activate({floor:1,capability:w,revision:u.revision,installed:u.installed})}catch(O){return{status:"failed",code:"page-format-activation-failed",error:O,retry:!0}}return!i||i.accepted!==!0?i?.code===y?G(1):{status:"failed",code:i?.code??"page-format-activation-failed",retry:!0}:n?(l(1),{status:"disposed",retry:!1}):(l(1),c=!0,await p(i.receipt??null),{status:"active",floor:t,receipt:i.receipt??null})}async function p(e){if(!g||!c)return!1;try{let r=await g.switchTo({floor:1,receipt:e});if(r&&r.status==="switched")return c=!1,!0}catch{}return!1}function m(){return n?Promise.resolve({status:"disposed",retry:!1}):t>=1?p(null).then(()=>({status:"active",floor:t})):(o||(o=R().finally(()=>{o=null})),o)}return{get floor(){return t},get disposed(){return n},note:l,read:v,activate:m,async run(e){let r={revision:d(),installed:f()},u=await m();return u.status!=="active"?u:n?{status:"disposed",retry:!1}:d()!==r.revision||f()!==r.installed?{status:"retry",code:"format-gate-stale",retry:!0}:{status:"applied",floor:t,result:await e?.apply?.(r)}},async retry(){return n?{status:"disposed",retry:!1}:await p(null)?{status:"active",floor:t}:m()},dispose(){return n=!0,c=!1,{status:"disposed"}}}}export{N as createFormatGate};
@@ -1 +1 @@
1
- import{b as $}from"./c-HVYXIS72.js";import{a as k,b as B,c as L}from"./c-4Q2XTQ2N.js";import{A as M}from"./c-TR6RMDQ7.js";import{B as P,E as R,b as O,m as q}from"./c-66O32MV3.js";import"./c-3GJ4SDE2.js";import{a as N}from"./c-LRPUO2MX.js";import"./c-VHNSBD2M.js";var K=16384,G=p=>new TextEncoder().encode(JSON.stringify(p)).length,I=class extends Error{constructor(s,n=s){super(n),this.name="ToolRequestError",this.code=s}};function V(p){let s=N(p);for(Array.isArray(s.tables)||(s.tables=[]),Array.isArray(s.outline)||(s.outline=[]);G(s)>K;){let n=[...s.tables].reverse().find(i=>Array.isArray(i.rows)&&i.rows.length);if(n)n.rows.pop();else if(s.outline.length)s.outline.pop();else break}if(G(s)>K)throw new I("context-too-large");return s}function J({transport:p,newId:s}){let n=null,i=a=>{!a||a.discarded||a.done||(a.discarded=!0,n===a&&(n=null),p.cancel(a.requestId),a.resolve({requestId:a.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(a,r,t=null){let m=V(r);n&&i(n);let c=s(),l={requestId:c,discarded:!1,done:!1};l.promise=new Promise(o=>{l.resolve=o}),n=l;let y={protocol:"page-tool/1",requestId:c,prompt:a,context:m,target:t};l.request=y;let v=o=>{if(!(l.discarded||l.done||o?.requestId!==c))if(l.done=!0,n===l&&(n=null),o?.artifact!==void 0){let d=k(o.artifact),C=B(o.state),w=d.ok?C.ok?null:C:d;l.resolve(w?{requestId:c,code:w.code,message:w.code}:o)}else l.resolve(typeof o?.code=="string"?o:{requestId:c,code:"invalid-result",message:"invalid-result"})};try{Promise.resolve(p.request(y)).then(v,o=>v({requestId:c,code:"transport-error",message:String(o?.message??o)}))}catch(o){v({requestId:c,code:"transport-error",message:String(o?.message??o)})}return l},discard:i,async wait(a,{signal:r}={}){if(r?.aborted)throw new DOMException("Aborted","AbortError");let t,m=await(r?Promise.race([a.promise,new Promise((c,l)=>{t=()=>l(new DOMException("Aborted","AbortError")),r.addEventListener("abort",t,{once:!0})})]).finally(()=>r.removeEventListener("abort",t)):a.promise);if(m?.code)throw new I(m.code,m.message);return m}}}var{Selection:X}=O;function W(p,s){let n=null;return p.forEach((i,a,r)=>{i.attrs.id===s&&(n={node:i,at:a,index:r})}),n}function j(p,s,n){let i=p.state,a=W(i.doc,n?.hostId)??(()=>{let w=Math.min(i.selection.$head.index(0),i.doc.childCount-1),f=0;for(let g=0;g<w;g++)f+=i.doc.child(g).nodeSize;return{node:i.doc.child(w),at:f,index:w}})(),{node:r,at:t,index:m}=a,c=i.doc.maybeChild(m+1),l=r.isTextblock&&(r.content.size===0||n?.hostId===r.attrs.id&&r.textContent===n.slashText),y=l?r.attrs.pos:P(r.attrs.pos,c?.attrs.pos??null),v=q.nodes.tool.create({id:s.id,pos:y,parent:r.attrs.parent??null,artifact:s.artifact,rev:s.rev,state:s.state}),o=l?t:t+r.nodeSize,d=i.tr;if(!l&&n?.hostId===r.attrs.id&&n.slashText&&n.slashOffset>=0){let w=t+1+n.slashOffset,f=w+n.slashText.length;f<=t+r.nodeSize-1&&i.doc.textBetween(w,f)===n.slashText&&d.delete(w,f)}let C=d.mapping.map(o);d.replaceWith(C,l?d.mapping.map(t+r.nodeSize):C,v),d.setSelection(X.near(d.doc.resolve(Math.min(C+v.nodeSize,d.doc.content.size)))),p.dispatch(M(d).scrollIntoView())}function ie({getView:p,store:s,transport:n,acceptState:i=()=>globalThis.clay?.save?.flush?.(),newId:a=R}){let r=n?J({transport:n,newId:()=>a("request")}):null,t=null,m=0,c=()=>{m++,t&&(r?.discard(t.pending),t.preview?.dispose(),t.previewHost?.dispose(),t.element.remove(),t=null)};return{open:({target:y=null,remove:v=null}={})=>{c();let o=p();if(!o)return;let d=o.state.selection,w={hostId:o.state.doc.child(Math.min(d.$head.index(0),o.state.doc.childCount-1))?.attrs.id,slashText:v?o.state.doc.textBetween(v.from,v.to):null,slashOffset:v&&d.$head.depth?v.from-d.$head.before(1)-1:null},f=o.dom.ownerDocument,g=f.createElement("section");g.className="page-ai-panel",g.contentEditable="false",g.setAttribute("role","dialog"),g.setAttribute("aria-label",y?"Revise tool":"Make a tool with AI");let E=f.createElement("textarea");E.setAttribute("aria-label","Describe the tool"),E.placeholder=y?"What should change?":"Describe the tool you want";let A=f.createElement("p");A.className="page-ai-status";let S=f.createElement("div");S.className="page-ai-preview";let T=f.createElement("div");T.className="page-ai-actions",g.append(E,A,S,T),o.dom.parentElement.append(g),t={element:g,input:E,status:A,previewRoot:S,actions:T,target:y,bookmark:w,candidate:null,pending:null,preview:null,previewHost:null,kept:!1,busy:!1};let x=(e,u)=>{let h=f.createElement("button");h.type="button",h.textContent=e,h.addEventListener("click",u),T.append(h)},z=()=>{t&&(t.preview?.dispose(),t.previewHost?.dispose(),t.preview=null,t.previewHost=null,t.previewRoot.replaceChildren(),t.input.hidden=!1,t.actions.replaceChildren(),x("Generate",D),x("Cancel",c),t.input.focus())},_=()=>{let e=t;e.input.hidden=!0,e.status.textContent="",e.previewHost=L({mode:"view"}),e.preview=e.previewHost.mount(e.previewRoot,{id:"preview",rev:"preview",artifact:e.candidate.artifact,seed:e.candidate.state}),e.actions.replaceChildren(),x("Keep",H),x("Revise",z),x("Discard",c)},D=async()=>{let e=t;if(!e||e.busy||!e.input.value.trim())return;if(!r){e.status.textContent="Tool generation is unavailable";return}e.busy=!0,e.status.textContent="Making your tool\u2026",e.actions.replaceChildren(),x("Cancel",c);let u=++m,h=r.request(e.input.value.trim(),$(o.state.doc,f.title),e.target);e.pending=h;try{let b=await r.wait(h);if(t!==e||u!==m)return;e.candidate={artifact:b.artifact,state:b.state,id:null,rev:null},_()}catch(b){if(t!==e||u!==m)return;e.status.textContent=b.message,e.actions.replaceChildren(),x("Generate",D),x("Cancel",c)}finally{e.busy=!1}},H=async()=>{let e=t;if(!e?.candidate||e.busy||e.kept)return;e.busy=!0;let u=e.candidate;u.id??=e.target?.toolId??a("b"),u.rev??=a("rev");try{if(!s)throw new Error("This document can't save tool state");await s.set([u.id,u.rev],u.state);let h=await i();if(h?.ok!==!0&&!["saved","clean"].includes(h?.state))throw new Error(h?.msg??h?.message??"Tool state was not saved");if(t!==e||e.kept)return;if(e.target){let b=W(o.state.doc,e.target.toolId);if(b?.node.type!==q.nodes.tool||b.node.attrs.rev!==e.target.rev){e.status.textContent="This tool changed while you were revising. Keep as a new tool, or discard.",e.target=null,u.id=null,u.rev=null,e.actions.replaceChildren(),x("Keep as new tool",H),x("Discard",c);return}o.dispatch(M(o.state.tr.setNodeMarkup(b.at,null,{...b.node.attrs,artifact:u.artifact,rev:u.rev})))}else j(o,u,e.bookmark);e.kept=!0,c()}catch(h){t===e&&(e.status.textContent=h.message)}finally{e.busy=!1}};return z(),g},dispose:c}}export{ie as createAiTool};
1
+ import{b as $}from"./c-RSMOODDU.js";import{a as k,b as B,c as L}from"./c-4Q2XTQ2N.js";import{A as M}from"./c-5J4E7O4Y.js";import{F as P,I as R,b as O,m as q}from"./c-WWXIDH4O.js";import"./c-3GJ4SDE2.js";import{a as N}from"./c-LRPUO2MX.js";import"./c-VHNSBD2M.js";var K=16384,G=p=>new TextEncoder().encode(JSON.stringify(p)).length,I=class extends Error{constructor(s,n=s){super(n),this.name="ToolRequestError",this.code=s}};function V(p){let s=N(p);for(Array.isArray(s.tables)||(s.tables=[]),Array.isArray(s.outline)||(s.outline=[]);G(s)>K;){let n=[...s.tables].reverse().find(i=>Array.isArray(i.rows)&&i.rows.length);if(n)n.rows.pop();else if(s.outline.length)s.outline.pop();else break}if(G(s)>K)throw new I("context-too-large");return s}function J({transport:p,newId:s}){let n=null,i=a=>{!a||a.discarded||a.done||(a.discarded=!0,n===a&&(n=null),p.cancel(a.requestId),a.resolve({requestId:a.requestId,code:"discarded",message:"Candidate discarded"}))};return{request(a,r,t=null){let m=V(r);n&&i(n);let c=s(),l={requestId:c,discarded:!1,done:!1};l.promise=new Promise(o=>{l.resolve=o}),n=l;let y={protocol:"page-tool/1",requestId:c,prompt:a,context:m,target:t};l.request=y;let v=o=>{if(!(l.discarded||l.done||o?.requestId!==c))if(l.done=!0,n===l&&(n=null),o?.artifact!==void 0){let d=k(o.artifact),C=B(o.state),w=d.ok?C.ok?null:C:d;l.resolve(w?{requestId:c,code:w.code,message:w.code}:o)}else l.resolve(typeof o?.code=="string"?o:{requestId:c,code:"invalid-result",message:"invalid-result"})};try{Promise.resolve(p.request(y)).then(v,o=>v({requestId:c,code:"transport-error",message:String(o?.message??o)}))}catch(o){v({requestId:c,code:"transport-error",message:String(o?.message??o)})}return l},discard:i,async wait(a,{signal:r}={}){if(r?.aborted)throw new DOMException("Aborted","AbortError");let t,m=await(r?Promise.race([a.promise,new Promise((c,l)=>{t=()=>l(new DOMException("Aborted","AbortError")),r.addEventListener("abort",t,{once:!0})})]).finally(()=>r.removeEventListener("abort",t)):a.promise);if(m?.code)throw new I(m.code,m.message);return m}}}var{Selection:X}=O;function W(p,s){let n=null;return p.forEach((i,a,r)=>{i.attrs.id===s&&(n={node:i,at:a,index:r})}),n}function j(p,s,n){let i=p.state,a=W(i.doc,n?.hostId)??(()=>{let w=Math.min(i.selection.$head.index(0),i.doc.childCount-1),f=0;for(let g=0;g<w;g++)f+=i.doc.child(g).nodeSize;return{node:i.doc.child(w),at:f,index:w}})(),{node:r,at:t,index:m}=a,c=i.doc.maybeChild(m+1),l=r.isTextblock&&(r.content.size===0||n?.hostId===r.attrs.id&&r.textContent===n.slashText),y=l?r.attrs.pos:P(r.attrs.pos,c?.attrs.pos??null),v=q.nodes.tool.create({id:s.id,pos:y,parent:r.attrs.parent??null,artifact:s.artifact,rev:s.rev,state:s.state}),o=l?t:t+r.nodeSize,d=i.tr;if(!l&&n?.hostId===r.attrs.id&&n.slashText&&n.slashOffset>=0){let w=t+1+n.slashOffset,f=w+n.slashText.length;f<=t+r.nodeSize-1&&i.doc.textBetween(w,f)===n.slashText&&d.delete(w,f)}let C=d.mapping.map(o);d.replaceWith(C,l?d.mapping.map(t+r.nodeSize):C,v),d.setSelection(X.near(d.doc.resolve(Math.min(C+v.nodeSize,d.doc.content.size)))),p.dispatch(M(d).scrollIntoView())}function ie({getView:p,store:s,transport:n,acceptState:i=()=>globalThis.clay?.save?.flush?.(),newId:a=R}){let r=n?J({transport:n,newId:()=>a("request")}):null,t=null,m=0,c=()=>{m++,t&&(r?.discard(t.pending),t.preview?.dispose(),t.previewHost?.dispose(),t.element.remove(),t=null)};return{open:({target:y=null,remove:v=null}={})=>{c();let o=p();if(!o)return;let d=o.state.selection,w={hostId:o.state.doc.child(Math.min(d.$head.index(0),o.state.doc.childCount-1))?.attrs.id,slashText:v?o.state.doc.textBetween(v.from,v.to):null,slashOffset:v&&d.$head.depth?v.from-d.$head.before(1)-1:null},f=o.dom.ownerDocument,g=f.createElement("section");g.className="page-ai-panel",g.contentEditable="false",g.setAttribute("role","dialog"),g.setAttribute("aria-label",y?"Revise tool":"Make a tool with AI");let E=f.createElement("textarea");E.setAttribute("aria-label","Describe the tool"),E.placeholder=y?"What should change?":"Describe the tool you want";let A=f.createElement("p");A.className="page-ai-status";let S=f.createElement("div");S.className="page-ai-preview";let T=f.createElement("div");T.className="page-ai-actions",g.append(E,A,S,T),o.dom.parentElement.append(g),t={element:g,input:E,status:A,previewRoot:S,actions:T,target:y,bookmark:w,candidate:null,pending:null,preview:null,previewHost:null,kept:!1,busy:!1};let x=(e,u)=>{let h=f.createElement("button");h.type="button",h.textContent=e,h.addEventListener("click",u),T.append(h)},z=()=>{t&&(t.preview?.dispose(),t.previewHost?.dispose(),t.preview=null,t.previewHost=null,t.previewRoot.replaceChildren(),t.input.hidden=!1,t.actions.replaceChildren(),x("Generate",D),x("Cancel",c),t.input.focus())},_=()=>{let e=t;e.input.hidden=!0,e.status.textContent="",e.previewHost=L({mode:"view"}),e.preview=e.previewHost.mount(e.previewRoot,{id:"preview",rev:"preview",artifact:e.candidate.artifact,seed:e.candidate.state}),e.actions.replaceChildren(),x("Keep",H),x("Revise",z),x("Discard",c)},D=async()=>{let e=t;if(!e||e.busy||!e.input.value.trim())return;if(!r){e.status.textContent="Tool generation is unavailable";return}e.busy=!0,e.status.textContent="Making your tool\u2026",e.actions.replaceChildren(),x("Cancel",c);let u=++m,h=r.request(e.input.value.trim(),$(o.state.doc,f.title),e.target);e.pending=h;try{let b=await r.wait(h);if(t!==e||u!==m)return;e.candidate={artifact:b.artifact,state:b.state,id:null,rev:null},_()}catch(b){if(t!==e||u!==m)return;e.status.textContent=b.message,e.actions.replaceChildren(),x("Generate",D),x("Cancel",c)}finally{e.busy=!1}},H=async()=>{let e=t;if(!e?.candidate||e.busy||e.kept)return;e.busy=!0;let u=e.candidate;u.id??=e.target?.toolId??a("b"),u.rev??=a("rev");try{if(!s)throw new Error("This document can't save tool state");await s.set([u.id,u.rev],u.state);let h=await i();if(h?.ok!==!0&&!["saved","clean"].includes(h?.state))throw new Error(h?.msg??h?.message??"Tool state was not saved");if(t!==e||e.kept)return;if(e.target){let b=W(o.state.doc,e.target.toolId);if(b?.node.type!==q.nodes.tool||b.node.attrs.rev!==e.target.rev){e.status.textContent="This tool changed while you were revising. Keep as a new tool, or discard.",e.target=null,u.id=null,u.rev=null,e.actions.replaceChildren(),x("Keep as new tool",H),x("Discard",c);return}o.dispatch(M(o.state.tr.setNodeMarkup(b.at,null,{...b.node.attrs,artifact:u.artifact,rev:u.rev})))}else j(o,u,e.bookmark);e.kept=!0,c()}catch(h){t===e&&(e.status.textContent=h.message)}finally{e.busy=!1}};return z(),g},dispose:c}}export{ie as createAiTool};
@@ -1 +1 @@
1
- import{a as r}from"./c-WYFDLITL.js";import{a as p}from"./c-HT33EQRN.js";import{i as u}from"./c-7O6AFR65.js";import{n as d,o as l}from"./c-DCFSEJZG.js";var n=0,g=0,c=!1,m=!1,y=!1,i=!1;function o(){!u||i||(i=!0,queueMicrotask(()=>{if(i=!1,typeof document>"u")return;let e=C();if(e===y)return;y=e;let t=document.documentElement;e?t.setAttribute("unsaved","true"):t.removeAttribute("unsaved"),document.dispatchEvent(new CustomEvent(e?"clay:dirty":"clay:clean"))}))}var T=`input${r}, textarea${r}, select${r}`,h=`${d}, ${l}`,a=new WeakMap;function v(){let e=[];for(let t of document.querySelectorAll(T))t.closest(h)||e.push(t);return e}function E(e){let t=e.target;!t||t.nodeType!==1||(t.matches("input, textarea, select")||t.isContentEditable)&&(t.closest(h)||(n++,o()))}function x(){m||(m=!0,p.onAnyChange({omitChangeDetails:!0,require:"dirty"},()=>{c||(n++,o())}),document.addEventListener("input",E,!0),document.addEventListener("change",E,!0))}function L(){c=!0}function k(){c=!1}function f(e){return e instanceof HTMLSelectElement?Array.from(e.selectedOptions,t=>t.value).join("\0"):e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")?e.checked?"1":"0":e.value}function M(e){return e instanceof HTMLSelectElement?Array.from(e.options).every(t=>t.selected===t.defaultSelected):e instanceof HTMLInputElement?e.type==="checkbox"||e.type==="radio"?e.checked===e.defaultChecked:e.value===e.defaultValue:e instanceof HTMLTextAreaElement?e.hasAttribute("data-value")?e.value===e.getAttribute("data-value"):e.value===e.defaultValue:!0}function S(){for(let e of v()){let t=f(e);if(a.get(e)!==t){if(M(e)){a.set(e,t);continue}return!0}}return!1}function C(){return n>g||S()}function D(){return n}function O(){let e=[];for(let t of v())e.push([t,f(t)]);return{gen:n,probe:e}}function b(){n++,o()}function H(e){if(e){n===e.gen&&(g=e.gen);for(let[t,s]of e.probe)f(t)===s&&a.set(t,s);o()}}typeof document<"u"&&u&&x();typeof window<"u"&&(window.clay=window.clay||{},window.clay.markDirty=b);export{x as a,L as b,k as c,C as d,D as e,O as f,b as g,H as h};
1
+ import{a as r}from"./c-WYFDLITL.js";import{a as p}from"./c-ZWIOJGMT.js";import{e as u}from"./c-OW5QIGG3.js";import{n as d,o as l}from"./c-DCFSEJZG.js";var n=0,g=0,c=!1,m=!1,y=!1,i=!1;function o(){!u||i||(i=!0,queueMicrotask(()=>{if(i=!1,typeof document>"u")return;let e=C();if(e===y)return;y=e;let t=document.documentElement;e?t.setAttribute("unsaved","true"):t.removeAttribute("unsaved"),document.dispatchEvent(new CustomEvent(e?"clay:dirty":"clay:clean"))}))}var T=`input${r}, textarea${r}, select${r}`,h=`${d}, ${l}`,a=new WeakMap;function v(){let e=[];for(let t of document.querySelectorAll(T))t.closest(h)||e.push(t);return e}function E(e){let t=e.target;!t||t.nodeType!==1||(t.matches("input, textarea, select")||t.isContentEditable)&&(t.closest(h)||(n++,o()))}function x(){m||(m=!0,p.onAnyChange({omitChangeDetails:!0,require:"dirty"},()=>{c||(n++,o())}),document.addEventListener("input",E,!0),document.addEventListener("change",E,!0))}function L(){c=!0}function k(){c=!1}function f(e){return e instanceof HTMLSelectElement?Array.from(e.selectedOptions,t=>t.value).join("\0"):e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")?e.checked?"1":"0":e.value}function M(e){return e instanceof HTMLSelectElement?Array.from(e.options).every(t=>t.selected===t.defaultSelected):e instanceof HTMLInputElement?e.type==="checkbox"||e.type==="radio"?e.checked===e.defaultChecked:e.value===e.defaultValue:e instanceof HTMLTextAreaElement?e.hasAttribute("data-value")?e.value===e.getAttribute("data-value"):e.value===e.defaultValue:!0}function S(){for(let e of v()){let t=f(e);if(a.get(e)!==t){if(M(e)){a.set(e,t);continue}return!0}}return!1}function C(){return n>g||S()}function D(){return n}function O(){let e=[];for(let t of v())e.push([t,f(t)]);return{gen:n,probe:e}}function b(){n++,o()}function H(e){if(e){n===e.gen&&(g=e.gen);for(let[t,s]of e.probe)f(t)===s&&a.set(t,s);o()}}typeof document<"u"&&u&&x();typeof window<"u"&&(window.clay=window.clay||{},window.clay.markDirty=b);export{x as a,L as b,k as c,C as d,D as e,O as f,b as g,H as h};
@@ -1,2 +1,2 @@
1
- import{a as u}from"./c-33HUYEDI.js";import{A as M}from"./c-TR6RMDQ7.js";import{b,d as x,m as v}from"./c-66O32MV3.js";import"./c-VHNSBD2M.js";var{Plugin:R}=b,{Decoration:D}=x;var O=[["","Plain text"],["javascript","JavaScript"],["typescript","TypeScript"],["jsx","JSX"],["tsx","TSX"],["json","JSON"],["html","HTML"],["css","CSS"],["python","Python"],["shellscript","Shell"],["sql","SQL"],["go","Go"],["rust","Rust"],["java","Java"],["c","C"],["cpp","C++"],["csharp","C#"],["ruby","Ruby"],["php","PHP"],["yaml","YAML"],["markdown","Markdown"],["diff","Diff"],["swift","Swift"],["kotlin","Kotlin"],["xml","XML"]],L=new Set(O.map(([s])=>s)),T={js:"javascript",mjs:"javascript",ts:"typescript",py:"python",sh:"shellscript",bash:"shellscript",shell:"shellscript",zsh:"shellscript",rb:"ruby",yml:"yaml",md:"markdown",htm:"html",golang:"go",rs:"rust","c++":"cpp",cs:"csharp","c#":"csharp",kt:"kotlin"},m=s=>{let t=String(s??"").trim().toLowerCase(),e=T[t]??t;return L.has(e)?e:""},n=s=>({color:s}),C={name:"page",appearance:"light",cssVariables:{prefix:"--page-code-token-"},style:{syntax:{comment:n("comment"),keyword:n("keyword"),operator:n("keyword"),preproc:n("keyword"),"punctuation.special":n("keyword"),string:n("string-expression"),"string.escape":n("constant"),"string.regex":n("constant"),"string.special":n("constant"),number:n("constant"),boolean:n("constant"),constant:n("constant"),type:n("constant"),property:n("constant"),enum:n("constant"),variant:n("constant"),namespace:n("constant"),label:n("constant"),function:n("function"),constructor:n("function"),selector:n("function"),attribute:n("function"),"variable.parameter":n("parameter"),tag:n("string-expression"),link_uri:n("link"),link_text:n("link"),"diff.plus":n("string-expression"),"diff.minus":n("keyword"),title:{font_weight:700},emphasis:{font_style:"italic"},"emphasis.strong":{font_weight:700}}}},E=null;async function P(s,t){E??=import("./c-3OWDMNJR.js");let{codeToTokens:e}=await E;return e(s,{lang:t,theme:C}).tokens}var _="var(--page-code-token-foreground)",A=s=>{let t=[];return s.color&&s.color!==_&&t.push(`color: ${s.color}`),s.fontStyle&1&&t.push("font-style: italic"),s.fontStyle&2&&t.push("font-weight: 600"),s.fontStyle&4&&t.push("text-decoration: underline"),t.join("; ")},H=200,y=class{constructor(t,e,i){this.view=t,this.run=e,this.delay=i,this.cache=new Map,this.pending=new Set,this.visible=new Set,this.targets=new Map,this.timer=0;let c=t.dom.ownerDocument.defaultView.IntersectionObserver;this.io=c?new c(a=>{for(let o of a){let r=o.target.dataset.id;this.targets.get(r)===o.target&&this.visible[o.isIntersecting?"add":"delete"](r)}this.schedule(0)},{rootMargin:"200px 0px"}):null,this.schedule(0)}update(t,e){(!e||t.state.doc!==e.doc)&&this.schedule(this.delay)}schedule(t){clearTimeout(this.timer),this.timer=setTimeout(()=>this.pass(),t)}pass(){let{view:t}=this;if(t.isDestroyed)return;let e=[],i=new Map,c=u.getState(t.state);t.state.doc.forEach((o,r)=>{if(o.type!==v.nodes.code_block)return;let p=o.attrs.id,d=t.nodeDOM(r);d&&i.set(p,d);let g=m(o.attrs.lang);if(!g)return;let k=o.textContent,l=`${g}
1
+ import{a as u}from"./c-HDDEEL77.js";import{A as M}from"./c-5J4E7O4Y.js";import{b,d as x,m as v}from"./c-WWXIDH4O.js";import"./c-VHNSBD2M.js";var{Plugin:R}=b,{Decoration:D}=x;var O=[["","Plain text"],["javascript","JavaScript"],["typescript","TypeScript"],["jsx","JSX"],["tsx","TSX"],["json","JSON"],["html","HTML"],["css","CSS"],["python","Python"],["shellscript","Shell"],["sql","SQL"],["go","Go"],["rust","Rust"],["java","Java"],["c","C"],["cpp","C++"],["csharp","C#"],["ruby","Ruby"],["php","PHP"],["yaml","YAML"],["markdown","Markdown"],["diff","Diff"],["swift","Swift"],["kotlin","Kotlin"],["xml","XML"]],L=new Set(O.map(([s])=>s)),T={js:"javascript",mjs:"javascript",ts:"typescript",py:"python",sh:"shellscript",bash:"shellscript",shell:"shellscript",zsh:"shellscript",rb:"ruby",yml:"yaml",md:"markdown",htm:"html",golang:"go",rs:"rust","c++":"cpp",cs:"csharp","c#":"csharp",kt:"kotlin"},m=s=>{let t=String(s??"").trim().toLowerCase(),e=T[t]??t;return L.has(e)?e:""},n=s=>({color:s}),C={name:"page",appearance:"light",cssVariables:{prefix:"--page-code-token-"},style:{syntax:{comment:n("comment"),keyword:n("keyword"),operator:n("keyword"),preproc:n("keyword"),"punctuation.special":n("keyword"),string:n("string-expression"),"string.escape":n("constant"),"string.regex":n("constant"),"string.special":n("constant"),number:n("constant"),boolean:n("constant"),constant:n("constant"),type:n("constant"),property:n("constant"),enum:n("constant"),variant:n("constant"),namespace:n("constant"),label:n("constant"),function:n("function"),constructor:n("function"),selector:n("function"),attribute:n("function"),"variable.parameter":n("parameter"),tag:n("string-expression"),link_uri:n("link"),link_text:n("link"),"diff.plus":n("string-expression"),"diff.minus":n("keyword"),title:{font_weight:700},emphasis:{font_style:"italic"},"emphasis.strong":{font_weight:700}}}},E=null;async function P(s,t){E??=import("./c-3OWDMNJR.js");let{codeToTokens:e}=await E;return e(s,{lang:t,theme:C}).tokens}var _="var(--page-code-token-foreground)",A=s=>{let t=[];return s.color&&s.color!==_&&t.push(`color: ${s.color}`),s.fontStyle&1&&t.push("font-style: italic"),s.fontStyle&2&&t.push("font-weight: 600"),s.fontStyle&4&&t.push("text-decoration: underline"),t.join("; ")},H=200,y=class{constructor(t,e,i){this.view=t,this.run=e,this.delay=i,this.cache=new Map,this.pending=new Set,this.visible=new Set,this.targets=new Map,this.timer=0;let c=t.dom.ownerDocument.defaultView.IntersectionObserver;this.io=c?new c(a=>{for(let o of a){let r=o.target.dataset.id;this.targets.get(r)===o.target&&this.visible[o.isIntersecting?"add":"delete"](r)}this.schedule(0)},{rootMargin:"200px 0px"}):null,this.schedule(0)}update(t,e){(!e||t.state.doc!==e.doc)&&this.schedule(this.delay)}schedule(t){clearTimeout(this.timer),this.timer=setTimeout(()=>this.pass(),t)}pass(){let{view:t}=this;if(t.isDestroyed)return;let e=[],i=new Map,c=u.getState(t.state);t.state.doc.forEach((o,r)=>{if(o.type!==v.nodes.code_block)return;let p=o.attrs.id,d=t.nodeDOM(r);d&&i.set(p,d);let g=m(o.attrs.lang);if(!g)return;let k=o.textContent,l=`${g}
2
2
  ${k}`,w=this.cache.get(l);if(w)for(let h of w){let S=A(h);S&&h.content&&e.push(D.inline(r+1+h.offset,r+1+h.offset+h.content.length,{style:S}))}else{if(e.push(...c.find(r,r+o.nodeSize)),this.io&&!this.visible.has(p)||this.pending.has(l))return;this.pending.add(l),this.run(k,g).then(h=>h.flat(),()=>[]).then(h=>{this.pending.delete(l),this.cache.set(l,h),this.cache.size>H&&this.cache.delete(this.cache.keys().next().value),this.schedule(0)})}}),this.track(i);let a=o=>o.map(r=>`${r.from}:${r.to}:${r.type.attrs.style}`).join("|");a(e)!==a(u.getState(t.state).find())&&t.dispatch(t.state.tr.setMeta(u,e).setMeta("addToHistory",!1))}track(t){if(this.io){for(let[e,i]of this.targets)t.get(e)!==i&&(this.io.unobserve(i),this.targets.delete(e),this.visible.delete(e));for(let[e,i]of t)this.targets.get(e)!==i&&(this.targets.set(e,i),this.io.observe(i))}}destroy(){clearTimeout(this.timer),this.io?.disconnect()}};function j(s,{tokenize:t=P,delay:e=300}={}){let i=new y(s,t,e),c=s.dispatch.bind(s),a=s.state.doc,o=p=>{if(c(p),s.state.doc===a)return;let d={doc:a};a=s.state.doc,i.update(s,d)};s.dispatch=o;let r=i.destroy.bind(i);return i.destroy=()=>{s.dispatch===o&&(s.dispatch=c),r()},i}var f=class{constructor(t,e,i){this.node=t,this.view=e,this.getPos=i;let c=e.dom.ownerDocument;this.dom=c.createElement("pre"),this.contentDOM=c.createElement("code"),this.select=c.createElement("select"),this.select.className="page-code-lang",this.select.contentEditable="false",this.select.setAttribute("aria-label","Code language");for(let[a,o]of O)this.select.append(new Option(o,a));this.select.addEventListener("change",()=>this.setLang(this.select.value)),this.dom.append(this.select,this.contentDOM),this.render(t)}render(t){this.node=t,this.dom.dataset.id=t.attrs.id??"";let e=m(t.attrs.lang);e?this.dom.dataset.lang=e:delete this.dom.dataset.lang,this.select.value=e}setLang(t){let e=this.getPos();e==null||t===m(this.node.attrs.lang)||(this.view.dispatch(M(this.view.state.tr.setNodeMarkup(e,null,{...this.node.attrs,lang:t}))),this.view.focus())}update(t){return t.type!==this.node.type?!1:(this.render(t),!0)}stopEvent(t){return this.select.contains(t.target)}ignoreMutation(t){return t.type!=="selection"&&this.select.contains(t.target)}};function X({view:s=null,highlight:t={}}={}){let e=s?j(s,t):null;return{id:"code",nodeViews:{code_block:(i,c,a)=>new f(i,c,a)},css:null,dispose(){e?.destroy()}}}export{X as createFeature};
@@ -0,0 +1 @@
1
+ import{F as j,G as P,M as V,n as l,o as T,q as I,u as $,x as B}from"./c-4DFEJ2PO.js";import{C as J,D as k,E as v,F as K,M as R,N as b,o as w,s as _,t as E,u as U,v as D,w as O}from"./c-6CRUUXOX.js";import{$ as Y,_ as F,ca as M,ia as N,ja as x,m as h,r as C,w as A}from"./c-WWXIDH4O.js";var y=t=>t&&typeof t=="object"?JSON.parse(JSON.stringify(t)):t,p=t=>{throw new l("unsupported-content",t)},H=t=>{if(t._map){for(let e of t._map.values())if(!e.deleted)return!0}for(let e=t._start;e;e=e.right)if(!e.deleted)return!0;return!1},f=t=>{throw new l("invalid-content",t)},G={span:["length","sourceClient","sourceClock"],alias:["sourceClient","sourceClock"],boundary:["blockId","kind","recoveryOf"]},Q=["copy","removed","restore"],u=t=>Number.isSafeInteger(t)&&t>=0,W=t=>t!==null&&typeof t=="object"&&!Array.isArray(t),S=(t,e)=>`${t}.${e}`,q=t=>JSON.stringify([t.blockId,t.kind,t.recoveryOf??null]),X=(t,e)=>{try{return C({[b(t)]:e}),!0}catch{return!1}};function Z(t){t.flow._map.size&&p("The page flow must contain text and block markers");for(let e=t.flow._start;e;e=e.right){if(e.deleted)continue;let r=e.content;if(!(r instanceof D)){if(r instanceof U){r.value!==null&&!Object.hasOwn(h.marks,b(r.key))&&!X(r.key,r.value)&&p(`Unsupported page mark: ${r.key}`);continue}if(r instanceof E){let o=r.embed;if(o&&Object.keys(o).length===1&&(typeof o.b=="string"&&o.b||o.br===1))continue}p("Unsupported content in the page flow")}}for(let[e,r]of t.attrs)r instanceof _||p(`Unsupported attributes for page block: ${e}`)}var m=(t,e)=>{let r=typeof e=="string"?j(e):e;if(!r)return!1;let o;try{o=w(t.ydoc.store,r)}catch{return!1}return o instanceof O&&o.parent===t.flow&&o.id.clock<=r.clock&&r.clock<o.id.clock+o.length},ee=t=>t.charCodeAt(0)===91?JSON.parse(t)[1]:t;function te(t){let e;try{e=P(t.gone,{strict:!0})}catch(o){throw o instanceof B?new l("invalid-content",o.message):o}for(let o of e.textDeletes){let a=w(t.ydoc.store,{client:o.client,clock:o.clock});if(!(a instanceof O)||a.parent!==t.flow||a.id.clock>o.clock||o.clock+o.length>a.id.clock+a.length)throw new l("invalid-content",`Invalid text-delete record: ${o.key}`)}let r=o=>{throw new l("invalid-content",o)};for(let o of e.removals)m(t,o.source)||r(`Invalid removal source: ${o.key}`),o.end!==null&&!m(t,o.end)&&r(`Invalid removal end: ${o.key}`);for(let o of e.restores){m(t,o.sourceKey)||r(`Invalid restore source: ${o.key}`);for(let a of o.covers)m(t,ee(a))||r(`Invalid restore cover: ${o.key}`)}for(let o of e.copyActive)m(t,o)||r(`Invalid copy-active record: ${o}`);for(let o of e.attrs.keys())m(t,o)||r(`Invalid attribute override: ${o}`)}function oe(t){let e=new Map,r=new Map,o=(s,n,c)=>{W(s)||f(`Invalid origin record: ${c}`);for(let i of Object.keys(s))n.includes(i)||f(`Unsupported origin field ${i} in ${c}`)};for(let[s,n]of t.origins){(typeof s!="string"||s.charCodeAt(0)!==91)&&f(`Malformed origin key: ${s}`);let c=null;try{c=JSON.parse(s)}catch{f(`Malformed origin key: ${s}`)}(!Array.isArray(c)||typeof c[0]!="string")&&f(`Malformed origin key: ${s}`);let i=c[0];if(i==="author"){(c.length!==2||!u(c[1]))&&f(`Malformed origin key: ${s}`),(typeof n!="string"||!n)&&f(`Invalid author record: ${s}`);continue}if(Object.hasOwn(G,i)||p(`Unsupported origin record: ${s}`),(c.length!==3||!u(c[1])||!u(c[2]))&&f(`Malformed origin key: ${s}`),o(n,G[i],s),i==="span"){(!Number.isSafeInteger(n.length)||n.length<1||!u(n.sourceClient)||!u(n.sourceClock)||!u(n.sourceClock+n.length-1))&&f(`Invalid span record: ${s}`);continue}if(i==="alias"){(!u(n.sourceClient)||!u(n.sourceClock))&&f(`Invalid alias record: ${s}`),e.set(S(c[1],c[2]),{client:n.sourceClient,clock:n.sourceClock});continue}(typeof n.blockId!="string"||!n.blockId||!Q.includes(n.kind))&&f(`Invalid boundary record: ${s}`),n.recoveryOf!==void 0&&!j(n.recoveryOf)&&f(`Invalid boundary record: ${s}`),r.set(S(c[1],c[2]),n)}let a=new Map;for(let[s,n]of r){let c=s,i=new Set;for(;!i.has(c);){i.add(c);let g=e.get(c);if(!g)break;c=S(g.client,g.clock)}i.has(c)&&e.has(c)&&f(`Cyclic boundary alias: ${s}`);let d=a.get(c);d&&q(d)!==q(n)&&f(`Conflicting boundary values: ${s}`),a.set(c,n)}}function L(t){let e="",r=[];for(let a of t.runs)if(!a.hole)if(a.br)t.t==="code_block"&&p("A code block cannot contain a hard-break atom"),e+=F,r.push(Y);else{e+=a.text;let s=A([...a.marks].sort((n,c)=>n.type.rank-c.type.rank));for(let n=0;n<a.text.length;n++)r.push(s)}let o={c:e};return r.some(Boolean)&&(o.m=N(r)),o}var z=(t,e)=>t.fields?Object.entries(t.fields):e?e.entries():[];function ne(t,e,r){let o=t.attrs.get(e.baseId),a={t:e.t,pos:String(r+1).padStart(8,"0")};for(let[s,n]of z(e,o))s!=="t"&&s!=="pos"&&(a[s]=y(n));return Object.assign(a,L(e))}function re(t,e,r){if(!Object.hasOwn(M,e.t))return(typeof e.t!="string"||!e.t||e.t==="opaque_block")&&p(`Unsupported page block type: ${e.t}`),ne(t,e,r);let o=h.nodes[e.t],a=t.attrs.get(e.baseId),s=e.t==="table"&&!e.fields?I(t.tableFields,e.baseId,{cols:a?.get("cols"),rows:a?.get("rows")}):null,n={t:e.t,pos:String(r+1).padStart(8,"0")};for(let i of k(o)){if(e.t==="board"&&(i==="columns"||i==="cards"))continue;let d=e.fields?e.fields[i]:s&&(i==="cols"||i==="rows")?s[i]:a?.has(i)?a.get(i):v(o,i);K(d,v(o,i))||(n[i]=y(d))}e.t==="table"&&(n.rows=y((e.fields?e.fields.rows:s.rows)??{})),e.t==="board"&&Object.assign(n,e.fields?{columns:y(e.fields.columns??{}),cards:y(e.fields.cards??{})}:$(t.boardFields,e.baseId));let c=new Set(k(o));for(let[i,d]of z(e,a))i==="t"||i==="pos"||c.has(i)||Object.hasOwn(n,i)||(n[i]=y(d));return o.isTextblock&&Object.assign(n,L(e)),n}function ie(t){let e=T(t,{strict:!0});try{for(let[n,c]of e.share)!J.includes(n)&&H(c)&&p(`Unsupported page root: ${n}`);let r=R(e);Z(r),$(r.boardFields),I(r.tableFields),te(r),oe(r);let o=V(r).visible,a=new Set(o.filter(n=>!n.implicit).map(n=>n.id)),s=new Set;return Object.fromEntries(o.map((n,c)=>{let i=n.id;if(s.has(i)||n.implicit&&a.has(i)){let d=2;do i=`${n.id}~${d++}`;while(s.has(i)||a.has(i))}return s.add(i),[i,re(r,n,c)]}))}catch(r){throw r instanceof l?r:new l("invalid-content",`Invalid Yjs page content: ${r.message}`)}finally{e.destroy()}}function we(t){if(t.some(e=>!e||typeof e!="object"||Array.isArray(e)))throw new l("invalid-value","Expected a page data object");if(!t.some(e=>Object.hasOwn(e,"y")||Object.hasOwn(e,"v")))return x(t);if(t.length!==1||Object.hasOwn(t[0],"blocks")||Object.hasOwn(t[0],"deleted"))throw new l("invalid-value","A Yjs page must have one page tag without hybrid block data");return ie(t[0])}export{ie as a,we as b};
@@ -1 +1 @@
1
- import{H as a,ga as i,m as s,y as c}from"./c-66O32MV3.js";function b(r){let e=[],o="";return r.forEach(t=>{if(t.type===s.nodes.heading&&(o=t.textContent),t.type!==s.nodes.table)return;let l=i({[t.attrs.id]:a(t)})[0],m=l.rows.map(n=>({...n,cells:Object.fromEntries(Object.entries(n.cells).map(([p,f])=>[p,c(f)]))}));e.push({id:l.id,name:o||`Table ${e.length+1}`,cols:l.cols,rows:m})}),e}function j(r,e){let o=[];return r.forEach(t=>{t.type===s.nodes.heading&&o.push({level:t.attrs.level,text:t.textContent})}),{title:e,outline:o,tables:b(r)}}export{b as a,j as b};
1
+ import{C as c,L as a,ka as i,m as s}from"./c-WWXIDH4O.js";function b(r){let e=[],o="";return r.forEach(t=>{if(t.type===s.nodes.heading&&(o=t.textContent),t.type!==s.nodes.table)return;let l=i({[t.attrs.id]:a(t)})[0],m=l.rows.map(n=>({...n,cells:Object.fromEntries(Object.entries(n.cells).map(([p,f])=>[p,c(f)]))}));e.push({id:l.id,name:o||`Table ${e.length+1}`,cols:l.cols,rows:m})}),e}function j(r,e){let o=[];return r.forEach(t=>{t.type===s.nodes.heading&&o.push({level:t.attrs.level,text:t.textContent})}),{title:e,outline:o,tables:b(r)}}export{b as a,j as b};
@@ -1 +1 @@
1
- import{a as r}from"./c-VKEDWYDF.js";import{i as o}from"./c-7O6AFR65.js";import{k as c}from"./c-35NBGMZB.js";var l="[editmode\\:resource]:is(style, link, script)",u='[editmode\\:resource]:is(style, link, script)[type^="inert/"]',i="inert/";function s(e){let t=e.getAttribute("type");return t&&t.startsWith(i)?!1:(e.setAttribute("type",i+(t||"")),!0)}function m(e){let t=e.getAttribute("type").slice(i.length);t?e.setAttribute("type",t):e.removeAttribute("type")}function d(){c(e=>{e.querySelectorAll(l).forEach(s)})}function f(){o&&r(()=>{a()})}function a(e=document){let t=(e.ownerDocument||e)===document;e.querySelectorAll(u).forEach(n=>{m(n),t&&n.replaceWith(n.cloneNode(!0))})}function R(){document.querySelectorAll(l).forEach(e=>{s(e)&&e.replaceWith(e.cloneNode(!0))})}function b(){d(),f()}export{l as a,a as b,R as c,b as d};
1
+ import{a as r}from"./c-VKEDWYDF.js";import{e as o}from"./c-OW5QIGG3.js";import{m as c}from"./c-SPIORRYS.js";var l="[editmode\\:resource]:is(style, link, script)",u='[editmode\\:resource]:is(style, link, script)[type^="inert/"]',i="inert/";function s(e){let t=e.getAttribute("type");return t&&t.startsWith(i)?!1:(e.setAttribute("type",i+(t||"")),!0)}function m(e){let t=e.getAttribute("type").slice(i.length);t?e.setAttribute("type",t):e.removeAttribute("type")}function d(){c(e=>{e.querySelectorAll(l).forEach(s)})}function f(){o&&r(()=>{a()})}function a(e=document){let t=(e.ownerDocument||e)===document;e.querySelectorAll(u).forEach(n=>{m(n),t&&n.replaceWith(n.cloneNode(!0))})}function R(){document.querySelectorAll(l).forEach(e=>{s(e)&&e.replaceWith(e.cloneNode(!0))})}function b(){d(),f()}export{l as a,a as b,R as c,b as d};
@@ -0,0 +1,9 @@
1
+ import{a as Re}from"./c-TCCA5BZN.js";import{a as Q,b as Qe,c as et,d as tt,e as gt,f as mt,g as nt,h as qn,i as Be,j as yt,k as V,l as rt,m as Nt,n as ot,o as Sn}from"./c-LRPUO2MX.js";import{b as $t}from"./c-A7LS5UZW.js";import{d as An}from"./c-5V3MOVJT.js";import{e as bn}from"./c-LZJPNR2W.js";import{E as Rt,J as wn,f as yn,q as vn}from"./c-TCJTVAFN.js";import{a as Tt}from"./c-2SPVQSHC.js";import{e as dn,f as pn,g as hn,h as gn,i as mn}from"./c-LWLBHLVC.js";import{a as Mt}from"./c-TQEMVJCS.js";import{a as Ot,c as fn}from"./c-DCXOXBF3.js";import{e as ht,j as cn}from"./c-VRZN56XY.js";import{e as He}from"./c-OW5QIGG3.js";import{f as an,k as un}from"./c-SPIORRYS.js";var gr=/^[A-Za-z0-9_-]{1,64}$/,mr=/^[1-9]\d{0,15}$/;var It=e=>mr.test(e)&&Number.isSafeInteger(Number(e));function Fe(...e){let t=new Map;for(let r of e)for(let[o,n]of r??[])t.has(o)||t.set(o,[]),t.get(o).push(...n.map(([i,a])=>[i,a]));return[...t].sort(([r],[o])=>r<o?-1:r>o?1:0).map(([r,o])=>{let n=[];for(let[i,a]of o.sort((d,m)=>d[0]-m[0])){let d=n[n.length-1];d&&i<=d[1]+1?d[1]=Math.max(d[1],a):n.push([i,a])}return[r,n]}).filter(([,r])=>r.length)}var xn=e=>e.reduce((t,[,r])=>t+r.length,0),We=(e,t)=>!!e?.some(([r,o])=>r<=t&&t<=o),st=(e,t,r)=>We(e?.find(([o])=>o===t)?.[1],r),yr=([e,t])=>[[e,[[t,t]]]],vt=e=>e?.v===2?e.frames:e?[[e.client,[[1,e.n]]]]:[],On=e=>e?.v===2?Fe(e.ancestors,yr(e.capture)):[];function kn(e){if(!e)return[];let t=[],r=0;for(let o of e.split(";")){let n=o.split(":");if(n.length!==2||!gr.test(n[0])||!n[1])return null;let i=[];for(let a of n[1].split(",")){if(++r>256)return null;let d=a.split("-");if(d.length>2||!d.every(It))return null;let m=Number(d[0]),q=Number(d[1]??d[0]);if(q<m)return null;i.push([m,q])}t.push([n[0],i])}return Fe(t)}function En(e){return Fe(e).map(([t,r])=>`${t}:${r.map(([o,n])=>o===n?String(o):`${o}-${n}`).join(",")}`).join(";")}function it(e){if(typeof e!="string"||e.length>32768)return null;if(!e.startsWith("v2|")){let a=/^([A-Za-z0-9_-]{1,64}):([1-9]\d{0,15})$/.exec(e);return a&&It(a[2])?{client:a[1],n:Number(a[2])}:null}let t=e.split("|");if(t.length!==4)return null;let r=kn(t[1]),o=kn(t[2]),n=/^([A-Za-z0-9_-]{1,64}):([1-9]\d{0,15})$/.exec(t[3]);if(!r||!o||!n||!It(n[2])||xn(r)+xn(o)+1>256)return null;let i=[n[1],Number(n[2])];return st(o,...i)?null:{v:2,frames:r,ancestors:o,capture:i}}function Mn(e){let t=`v2|${En(e.frames)}|${En(e.ancestors)}|${e.capture[0]}:${e.capture[1]}`;return it(t)?t:null}var vr=new Set(["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"]),wr=/^(0|[1-9]\d*)$/,Ne=e=>e!==null&&typeof e=="object",Ue=e=>Array.isArray(e)?"a list":"an object";function $e(e,t){let r=e;for(let o of t){if(!Ne(r))return;Array.isArray(r)?r=r[Number(o)]:r=Object.prototype.hasOwnProperty.call(r,o)?r[o]:void 0}return r}var wt=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),br=(e,t)=>V(e)===V(t);function Tn(e,t){let r=[];try{for(let o of t){let n=mt(e,o);n&&(r.push(n),e=n.root)}return r}catch{return Pt(r),null}}function Pt(e){let t;for(let r=e.length-1;r>=0;r--)t=nt(e[r]);return t}function qr(e,t,r){let o=[];for(let n of e){if(n.at===null||Array.isArray(n.at))return null;let i=o.find(a=>a.path.length===n.path.length&&Be(a.path,n.path));if(i){if(i.removed&&n.kind!=="remove")return null;n.kind==="remove"&&(i.removed=!0);continue}if(o.some(a=>Be(a.path,n.path)))return null;o.push({path:n.path,at:n.at,key:n.key,had:n.kind!=="add",old:n.old,removed:n.kind==="remove"})}for(let n of o){if(n.has=wt(n.at,n.key),n.had&&n.has&&n.removed||(n.into=$e(r,n.path.slice(0,-1)),!Ne(n.into)||Array.isArray(n.into)||wt(n.into,n.key)!==n.had))return null;let i=n.path.slice(0,-1);for(let a of t){let d=a.op.path;if(Be(n.path,d)||a.op.op==="del"&&d.length<=n.path.length&&Be(d.slice(0,-1),n.path)&&Array.isArray($e(r,d.slice(0,-1))))return null;if(!n.had&&n.has&&d.length>i.length&&Be(i,d)){let m=d[i.length];if(d.length===i.length+1&&a.op.op==="del"||!wt(n.at,String(m)))return null}}}return o}function Sr(e,t){if(t.op==="set"){let r=$e(e,t.path);if(Ne(r)&&Ne(t.value)&&Array.isArray(r)===Array.isArray(t.value)){yt(r,Q(t.value));return}}tt(e,t)}function Ct({name:e,value:t,ephemeral:r=!1}){if(!Ne(t))throw new TypeError(`clay.live("${e}"): the tag must hold a JSON object or list`);let o=Q(t),n=Q(t),i=!0,a=[],d=1,m=null,q="file",g=new Set,C=new Set,F=new Set,P=new Set,_=new Set,U=new WeakMap;function O(f,y){let v={source:f,ops:y};for(let k of[...g])try{k(v)}catch(L){console.error(`clay.live("${e}"): a change listener threw`,L)}}function B(){let f=Q(o),y=[];for(let v of a)try{et(f,v.op),f=tt(f,v.op),y.push(v)}catch{}a=y,yt(n,f),i=!0}function X(f){for(let y of[...F])try{y(f)}catch(v){console.error(`clay.live("${e}"): a rebase listener threw`,v)}}function T(f,{source:y="remote",confirmed:v=0,through:k,drop:L,dropIds:W,frame:ue=null,room:oe=null,cause:re=null}={}){if(!Ne(f)||Ue(f)!==Ue(n))return console.warn(`clay.live("${e}"): ignored an incoming value that is not ${Ue(n)}`),!1;let he=V(n),ge=o;if(o=Q(f),L)a=a.filter(te=>te.id<L[0]||te.id>L[1]);else if(W){let te=new Set(W);a=a.filter(we=>!te.has(we.id))}else a=k===void 0?a.slice(v):a.filter(te=>te.id>k);return B(),X({source:y,frame:ue,room:oe,cause:re,prev:ge,before:te=>$e(ge,te),next:o}),V(n)!==he&&O(y,null),!0}function ee(f){let y=Q(o);for(let v=f.length-1;v>=0;v--){let k=f[v];nt({...k,at:$e(y,k.path.slice(0,-1))})}return y}function w(f){for(let y of[...C])try{y(f)}catch(v){console.error(`clay.live("${e}"): a transport threw`,v)}O("local",f)}function J(f){let y=f.map(Qe);for(let v of y)if(v.path.length===0&&Ue(v.value)!==Ue(n))throw new TypeError(`clay.live("${e}"): the whole value must stay ${Ue(n)}`);y.length===1?et(n,y[0]):gt(Q(n),y);for(let v of y)Sr(n,v);a.push(...y.map(v=>({id:d++,op:v}))),m?m.push(...y):w(y)}function D(f,y){let v=U.get(f);v||U.set(f,v=new Map);let k=JSON.stringify(y),L=v.get(k);return L||(L=new Proxy(f,de(y)),v.set(k,L)),L}function de(f){return{get(y,v){if(Array.isArray(y)&&vr.has(v))return(...L)=>{let W=Q(y),ue=Array.prototype[v].apply(W,L);return J([{op:"set",path:f,value:W}]),ue===W?D(y,f):ue};let k=y[v];return typeof v=="symbol"||!Ne(k)||!Object.prototype.hasOwnProperty.call(y,v)?k:D(k,[...f,Array.isArray(y)?Number(v):v])},set(y,v,k){if(typeof v=="symbol")throw new TypeError(`clay.live("${e}"): symbol keys are not JSON`);if(Array.isArray(y)){if(v==="length"){let L=Q(y);return L.length=k,J([{op:"set",path:f,value:L}]),!0}if(!wr.test(v))throw new TypeError(`clay.live("${e}"): "${v}" is not a list index`);return J([{op:"set",path:[...f,Number(v)],value:k}]),!0}return J([{op:"set",path:[...f,v],value:k}]),!0},deleteProperty(y,v){if(typeof v=="symbol")return!0;if(Array.isArray(y))throw new TypeError(`clay.live("${e}"): remove a list item with splice`);return J([{op:"del",path:[...f,v]}]),!0},defineProperty(){throw new TypeError(`clay.live("${e}"): assign values instead of defining properties`)},setPrototypeOf(){return!1},preventExtensions(){return!1}}}let Y=D(n,[]),ae,pe=new Promise(f=>{ae=f}),z=Object.freeze({name:e,ephemeral:r,ready:pe,get data(){return Y},get status(){return{mode:q}},set(f,y){J([{op:"set",path:f,value:y}])},delete(f){J([{op:"del",path:f}])},add(f,y=1){J([{op:"add",path:f,n:y}])},update(f){if(typeof f!="function")throw new TypeError(`clay.live("${e}"): update() takes a function`);if(m)return f(Y);m=[];let y=a.length,v=d,k;try{if(k=f(Y),k&&typeof k.then=="function")throw new TypeError(`clay.live("${e}"): update() runs synchronously; do async work before calling it`)}catch(W){throw m=null,a.length=y,d=v,B(),W}let L=qn(m);return m=null,a.length=y,d=v,a.push(...L.map(W=>({id:d++,op:W}))),L.length&&w(L),k},on(f,y){if(f!=="change")throw new TypeError(`clay.live("${e}"): the only event is "change"`);if(typeof y!="function")throw new TypeError(`clay.live("${e}"): on() takes a function`);return g.add(y),()=>g.delete(y)},off(f,y){g.delete(y)},toJSON(){return Q(n)}});return ae(z),{handle:z,name:e,ephemeral:r,get value(){return n},get authoritative(){return o},get pending(){return a.map(f=>f.op)},pendingEntries(){return a.map(f=>({id:f.id,op:f.op}))},get mark(){return d-1},setMode(f){q=f},onLocal(f){return C.add(f),()=>C.delete(f)},confirm(f){let y=a.filter(v=>v.id<=f);if(y.length){try{o=gt(Q(o),y.map(v=>v.op))}catch{o=Q(n),i=!1}a=a.filter(v=>v.id>f);for(let v of[...P])try{v({through:f})}catch(k){console.error(`clay.live("${e}"): a confirmation listener threw`,k)}}},onConfirm(f){return P.add(f),()=>P.delete(f)},rebase:T,checkOps(f){let y;try{y=f.map(Qe)}catch{return null}let v=Tn(o,y);return v?(Pt(v),y):null},rebaseOps(f,{source:y="remote",confirmed:v=0,through:k,frame:L=null,room:W=null,cause:ue=null}={}){let oe=Tn(o,f);if(!oe)return!1;let re=k===void 0?a.slice(v):a.filter($=>$.id>k),he=a.length-re.length,ge=oe.some($=>$.at===null),te=i&&!ge&&he===f.length&&f.every(($,Z)=>br($,a[Z].op)),we=i&&!te&&he===0?qr(oe,re,n):null;if(!te&&!we)return Pt(oe),T(gt(Q(o),f),{source:y,confirmed:v,through:k,frame:L,room:W,cause:ue});a=re;let _e=!1;for(let $ of we??[]){let Z=$.into;if($.has){let je=$.at[$.key];(!$.had||V($.old)!==V(je))&&(_e=!0);let s=$.had?Z[$.key]:void 0,p=Q(je),A=Ne(s)&&Ne(p)&&Array.isArray(s)===Array.isArray(p);Object.defineProperty(Z,$.key,{value:A?yt(s,p):p,enumerable:!0,writable:!0,configurable:!0})}else $.had&&(_e=!0,delete Z[$.key])}let be=null,Oe=()=>be??=ee(oe),ce=oe.some($=>Array.isArray($.at)&&$.kind!=="put");return X({source:y,frame:L,room:W,cause:ue,get prev(){return Oe()},before:$=>{if(ce)return $e(Oe(),$);for(let Z of oe)if(Be(Z.path,$))return Z.path.length>$.length?$e(Oe(),$):$e(Z.old,$.slice(Z.path.length));return $e(o,$)},next:o}),_e&&O(y,null),!0},onRebase(f){return F.add(f),()=>F.delete(f)},onDelivery(f){return _.add(f),()=>_.delete(f)},deliver(f){for(let y of[..._])try{y(f)}catch(v){console.error(`clay.live("${e}"): a delivery listener threw`,v)}}}}function Rn({needsSave:e,blocked:t,save:r,saveNow:o,now:n=()=>Date.now(),setTimer:i=setTimeout,clearTimer:a=clearTimeout}){let d=null,m=null,q=!1,g=!1,C=0;function F(O){let B=O&&!O.ok&&O.msgType==="skipped";return C=O?.ok||B?0:n()+8e3,B?1e3:8e3}function P(O){d=O,m!==null&&a(m),m=i(U,Math.max(0,O-n()))}function _(){m!==null&&a(m),m=null,d=null}async function U(){if(m=null,d=null,!e())return;if(t()){P(n()+1e3);return}q=!0;let O=null;try{O=await r()}catch{O=null}finally{q=!1}let B=F(O);e()&&P(n()+B)}return{changed(){d===null&&!q&&P(n()+8e3)},flush(){q||!e()||t()||(_(),q=!0,g=!0,Promise.resolve().then(o).catch(()=>null).then(O=>{q=!1,g=!1;let B=F(O);e()&&P(n()+B)}))},soon(){if(q)return;let O=Math.max(n(),C);(d===null||O<d)&&P(O)},within(O){if(q)return;let B=Math.max(n()+O,C);(d===null||B<d)&&P(B)},get flushing(){return g},get deadline(){return d}}}var Ar=40,$n=128,lt=500,xr=1e4,kr=63*1024,Nn=15*1024,Er=/^page(\.[0-9]+)?$/,Or=512,_t=8e3,Mr=new Set([401,403]),Tr=new Set([401,403,404]),Rr=new TextEncoder,bt=e=>Rr.encode(JSON.stringify(e)).length,In=e=>e===0||e===408||e===429||e>=500,Pn=e=>e===429||e===503;function Lt({transport:e,entries:t,onEpoch:r=()=>{},onLeave:o=()=>{},onWriter:n=()=>{},onApplied:i=()=>{},onLanded:a=()=>{},onCheckpoint:d=()=>{},held:m=()=>!1,heldIds:q=()=>[],hold:g=()=>!0,taken:C=()=>{},onStop:F=()=>{},now:P=()=>Date.now(),setTimer:_=setTimeout,clearTimer:U=clearTimeout}){let O=null,B=!1,X=!1,T=null,ee=null,w=null,J=0,D=0,de=null,Y=new Set,ae=[],pe=!1,z=!1,f=!1,y=null,v=-1/0,k=0,L=null,W=null,ue=lt,oe=kr,re=lt,he=0,ge,te=0,we=!1,_e=0,be=!1,Oe=null,ce=new Map,Me=new Set,$=(l,c)=>t.get(l)?.store.deliver?.({code:null,n:null,seq:null,through:null,retryAfter:null,client:O,...c});function Z(l){let c=ce.get(l);return c||ce.set(l,c={n:0,unsent:[],awaiting:[],framed:0}),c}function je(l,c){!l.adopted||c.through<l.adopted.through||(c.adopted=l.adopted.rev,l.adopted=null)}function s(l,c){let u=t.get(l)?.store;return u?u.pendingEntries().filter(h=>h.id>c.framed):[]}function p(l,c){let u=t.get(l)?.store;if(!u)return;let h=new Set(u.pendingEntries().map(S=>S.id));c.awaiting=c.awaiting.filter(S=>S===y||!S.entries||S.entries.some(x=>h.has(x.id)))}let A=l=>l.refused===!0&&!l.uncertain;function M(l,c,u=!0){let h=t.get(l)?.store;for(let S of c.awaiting)S===y&&(S.undecided=!0);u&&(be=!0),c.out=!0,o(l,{epoch:T,seq:D}),c.unsent=[],h?.setMode("file"),i()}function b(){if(L!==null||f||z)return;let l=P(),c=Math.max(0,v+Ar-l,k-l);L=_(()=>{L=null,se()},c)}function N(){for(let[l,c]of ce){if(!Y.has(l)||m(l))continue;let u=c.awaiting.find(h=>!h.sent);if(u)return{name:l,lane:c,frame:u}}for(let[l,c]of ce){if(!c.unsent.length||!Y.has(l)||m(l))continue;let u=bt({name:l,n:c.n+1,ops:[],epoch:T}),h=0;for(;h<c.unsent.length&&h<$n;){let I=bt(c.unsent[h].op)+1;if(h&&u+I>oe)break;u+=I,h++}let S=c.unsent.splice(0,h),x={n:++c.n,ops:S.map(I=>I.op),entries:S,first:S[0].id,through:S[S.length-1].id,seq:null,sent:!1,receiptGeneration:ee,pageGeneration:w};return je(c,x),c.framed=Math.max(c.framed,x.through),c.awaiting.push(x),{name:l,lane:c,frame:x}}return null}async function se(){if(f||z||!B||!X||ge===null)return;let l=N();if(!l)return;let{name:c,lane:u,frame:h}=l;ce.delete(c),ce.set(c,u);let S=T;h.epoch=S,h.client=O,h.sentOn=he,h.sent=!0,$(c,{phase:"sent",n:h.n,first:h.first,through:h.through}),h.refused=!1,f=!0,y=h,v=P();let x;try{x=await e.send(O,{name:c,n:h.n,ops:h.ops,epoch:S,...ge!==void 0&&{conn:ge},...h.receiptGeneration!==null&&{receiptGeneration:h.receiptGeneration},...h.pageGeneration!==null&&Er.test(c)&&{pageGeneration:h.pageGeneration},...h.adopted&&{adopted:h.adopted}})}catch{x=null}f=!1,y=null,!z&&(h.undecided?xe(c,u,h,x||{status:0}):S===T&&u.awaiting.includes(h)&&De(c,u,h,x||{status:0}),b())}function xe(l,c,u,{status:h,body:S}){if(delete u.undecided,!c.awaiting.includes(u))return;if((S?.stale===!0||Pn(h)||h>=400&&h<500&&!In(h))&&!u.uncertain){u.refused=!0,u.sent=!1,u.seq=null,u.epoch!==T&&(u.receiptGeneration=ee),u.epoch!==T&&(u.pageGeneration=w);return}if(!Y.has(l)){h>=200&&h<300&&Number.isInteger(S?.seq)&&!S?.stale?u.seq=S.seq:(u.uncertain=!0,u.uncertainSince??=u.sentOn);return}c.awaiting.splice(c.awaiting.indexOf(u),1);let I=t.get(l)?.store;I?.rebase(I.authoritative,{source:"state",through:u.through,cause:"decided"})}function Ve(){for(let[l,c]of ce){if(!Y.has(l))continue;let u;for(;c.awaiting.length&&c.awaiting[0].seq!==null&&c.awaiting[0].seq<=D;)u=c.awaiting.shift().through;if(u===void 0)continue;let h=t.get(l)?.store;h?.rebase(h.authoritative,{source:"state",through:u,cause:"settled"})}}function De(l,c,u,{status:h,body:S,retryAfter:x}){if(h>=200&&h<300){if(ue=lt,S?.stale){u.sent=!1,u.refused=!0,S.epoch!==T?ne():b();return}if(S?.epoch&&S.epoch!==T){ne();return}u.seq=Number.isInteger(S?.seq)?S.seq:null,$(l,{phase:"landed",n:u.n,seq:u.seq,through:u.through}),Ve();return}if(In(h)){if(u.sent=!1,$(l,{phase:"retry",code:S?.code??(h===0?"offline":h===429?"rate-limited":"server"),n:u.n,through:u.through,retryAfter:x??null}),Pn(h)?u.refused=!0:(u.uncertain=!0,u.uncertainSince??=u.sentOn),h===503&&S?.code==="not-connected"){ge=null,ne();return}if(h===503&&S?.code==="busy"){$(l,{phase:"left",code:"busy",n:u.n,through:u.through}),console.warn(`clay.live("${l}"): the room is full, so it stays at save speed for now`),Y.delete(l),M(l,c),_(ne,(x>0?x:60)*1e3);return}if(u.uncertain&&u.sentOn!==he){ne();return}k=P()+(x>0?x*1e3:ue),ue=Math.min(ue*2,_t);return}if(Mr.has(h)){$(l,{phase:"refused",code:"revoked",n:u.n,through:u.through}),u.uncertain||(u.refused=!0),Et();return}let I=S?.error||S?.code||`status ${h}`;if(h===404){$(l,{phase:"left",code:"no-store",n:u.n,through:u.through}),console.warn(`clay.live("${l}"): the room has no such store, so it stays at save speed (${I})`),u.refused=!0,Y.delete(l),M(l,c,!1);return}if(c.awaiting.splice(c.awaiting.indexOf(u),1),h===413&&!S?.code&&u.entries?.length>1&&oe>Nn){oe=Nn,console.warn(`clay.live("${l}"): the host takes smaller updates, so they go in frames of ${oe} bytes`),c.unsent.unshift(...u.entries),u.adopted&&(c.adopted={rev:u.adopted,through:u.through}),c.framed=u.first-1;return}let G=t.get(l)?.store,me=S?.code??(h===413&&u.entries?.length===1?"too-large":"refused");$(l,{phase:"refused",code:me,n:u.n,from:u.first,through:u.through,...S?.code==="receipt-expired"&&{ops:u.ops}}),console.warn(`clay.live("${l}"): the host refused an update, so it was undone (${I})`),G?.rebase(G.authoritative,{source:"state",drop:u.first===void 0?void 0:[u.first,u.through],through:u.first===void 0?u.through:void 0,cause:"refused"}),S?.code==="receipt-expired"&&ne()}function pt(l){D=l.seq;let c=t.get(l.name)?.store;if(!c||Me.has(l.name))return;if(!Y.has(l.name)){be=!0;return}let u=c.checkOps(l.ops);if(!u){ne();return}let h,S=l.from===O;if(S){let x=Z(l.name),I=x.awaiting.findIndex(G=>G.n===l.n);I>=0&&(h=x.awaiting[I].through,$(l.name,{phase:"echoed",n:l.n,seq:l.seq,through:h}),x.awaiting.splice(0,I+1))}c.rebaseOps(u,{source:S?"state":"remote",through:h,frame:{seq:l.seq,from:l.from,n:l.n,ops:l.ops}}),t.get(l.name).last=l.seq,i(),l.checkpoint===!0&&d(),Ve()}function Xe(l){if(!(z||!l||!Number.isInteger(l.seq))){if(!X){ae.push(l),ae.length>Or&&ae.shift();return}if(l.epoch!==T){ae.push(l),ne();return}if(!(l.seq<=D)){if(l.seq!==D+1){ae.push(l),ne();return}pt(l)}}}function ke(l,c){let u=c.seen?c.seen[O]??0:null,h=[],S=[];for(let x of l)u!==null&&x.n<=u||We(c.saved,x.n)?S.push(...x.entries.map(I=>I.id)):x.sent&&x===y?(x.undecided=!0,h.push(x)):A(x)?h.push(x):S.push(...x.entries.map(I=>I.id));return{resend:h,dropIds:S}}function Ge(l,c,u,h){let S=q(l);if(!S.length)return!1;if(!h){let x=new Set;for(let I of c.awaiting)if(We(u.saved,I.n))for(let G of I.entries??[])x.add(G.id);if(S.every(I=>x.has(I)))return!1}return g(l,S)?!0:(p(l,c),!1)}function nn(l,c=0){if(z||!l||typeof l.epoch!="string")return;if(te++,l.epoch===T&&Number.isInteger(l.seq)&&l.seq<D){rn();return}let u=l.epoch!==T;J=Number.isInteger(l.provenanceVersion)?l.provenanceVersion:0,ee=Number.isSafeInteger(l.receiptGeneration)?l.receiptGeneration:null;let h=w;w=typeof l.pageTransition?.id=="string"?l.pageTransition.id:null;let S=w!==h,x=!1;be=!1,T=l.epoch,D=Number.isInteger(l.seq)?l.seq:0,de=l.writer??null,"conn"in l&&(ge=l.conn);let I=l.stores||{};Y=new Set(Object.keys(I));for(let H of Me)Y.delete(H);let G=!1,me=!1;for(let[H,ye]of t){if(Me.has(H))continue;let K=I[H],j=Z(H);p(H,j);let pr=j.room;if(j.room=!!K,!K){j.out||(pr&&S&&$(H,{phase:"left",code:"no-store"}),M(H,j,!1)),j.after!==void 0&&c>=j.after&&(j.after=void 0,j.deferred=!1,C(H));continue}let on=j.after!==void 0&&c<j.after;if(on||Ge(H,j,K,u||j.stale===!0)){Y.delete(H),j.deferred=!0,u&&(j.stale=!0),on&&(me=!0),G=!0;continue}let sn=u||j.stale===!0;j.deferred=!1,j.stale=!1,j.after=void 0;let hr=ye.store.handle.status.mode==="file";j.out=!1,ye.store.setMode("fast"),ye.last=Number.isInteger(K.last)?K.last:0,ye.landed=Number.isInteger(K.landed)?K.landed:0;let ln=[];if(!sn&&ee!==null){let Te=K.seen?.[O];j.awaiting=j.awaiting.filter(ie=>We(K.saved,ie.n)||Te!==void 0&&ie.n<=Te||ie.seq!==null&&ie.seq<=D||(ie.receiptGeneration??0)===ee?!0:(ln.push(...ie.entries.map(le=>le.id)),$(H,{phase:"refused",code:"receipt-expired",n:ie.n,from:ie.first,through:ie.through,ops:ie.ops}),console.warn(`clay.live("${H}"): the room retired an update receipt, so the update was not replayed. Check the saved value before restoring it.`),!1))}if(sn){let{resend:Te,dropIds:ie}=ke(j.awaiting,K);for(let qe of Te)qe.undecided||(qe.sent=!1,qe.seq=null,qe.receiptGeneration=ee,qe.pageGeneration=w);j.awaiting=Te,ye.store.rebase(K.value,{source:"state",dropIds:ie,room:{seq:D,fresh:!0,moves:l.moves?.[H]??null,floor:Number.isInteger(K.floor)?K.floor:null}}),j.unsent=s(H,j)}else{let Te=K.seen?K.seen[O]:void 0,ie=[],qe=[...ln];for(let le of j.awaiting)We(K.saved,le.n)?qe.push(...le.entries.map(Ze=>Ze.id)):le===y?ie.push(le):le.seq!==null&&le.seq<=D||Te!==void 0&&le.n<=Te?qe.push(...le.entries.map(Ze=>Ze.id)):le.seq!==null?ie.push(le):!le.uncertain||Te!==void 0||le.uncertainSince===he?(le.sent=!1,ie.push(le)):qe.push(...le.entries.map(Ze=>Ze.id));j.awaiting=ie,ye.store.rebase(K.value,{source:"state",dropIds:qe,room:{seq:D,fresh:!1,moves:l.moves?.[H]??null,floor:Number.isInteger(K.floor)?K.floor:null}}),hr&&(j.unsent=s(H,j),x=!0)}C(H)}G&&(be=!0),(u||x)&&r(T),i(),n(),rn(),me&&ne()}function rn(){X=!0;let l=ae.filter(c=>c.epoch===T&&c.seq>D).sort((c,u)=>c.seq-u.seq);ae=[];for(let c of l)Xe(c);b()}async function ne(){if(z)return;if(pe){we=!0;return}pe=!0,we=!1,X=!1;let l={connection:he,stateCount:te,read:++_e},c=null,u=typeof AbortController=="function"?new AbortController:null,h=new Promise(S=>{W=_(()=>{W=null,u?.abort(),S(null)},xr)});try{c=await Promise.race([e.fetchState(O,T!==null&&D>0&&!be?{epoch:T,seq:D}:null,u?{signal:u.signal}:{}),h])}catch{}if(W!==null&&U(W),W=null,pe=!1,!z){if(l.connection!==he||we){B&&ne();return}if(l.stateCount!==te){if(X)return;c=null}if(c&&typeof c.epoch=="string"){re=lt,nn(c,l.read);return}if(c&&Tr.has(c.status)){Et();return}if(c&&c.status===503){let S=c.code==="busy";for(let[x,I]of t)I.store.handle.status.mode==="fast"&&($(x,{phase:"left",code:S?"busy":"unavailable"}),console.warn(`clay.live("${x}"): the host has no room for this document now, so it stays at save speed for now`),M(x,Z(x)));if(Y=new Set,!B)return;S||c.retryAfter>0?(re=lt,_(ne,(c.retryAfter>0?c.retryAfter:60)*1e3)):(_(ne,re),re=Math.min(re*2,_t));return}B&&(_(ne,re),re=Math.min(re*2,_t))}}function Et(){if(!z){z=!0,L!==null&&U(L),L=null,W!==null&&U(W),W=null,Oe?.();for(let[l,c]of t){let u=ce.get(l);u?.out||(u?M(l,u):(o(l,{epoch:T,seq:D}),c.store.setMode("file")))}F()}}let dr={open(l){O=l.clientId,B=!0,he++,ne()},close(){B=!1,he++,X=!1,ae=[]},frame:Xe,state(l){be&&l&&!("moves"in l)?ne():nn(l)},writer(l){if(!(!l||l.epoch!==T)){if(de=l.writer??null,l.landed&&typeof l.landed=="object"){te++;for(let[c,u]of Object.entries(l.landed)){let h=t.get(c);h&&Number.isInteger(u)&&(h.landed=u,$(c,{phase:"checkpointed",seq:u}))}a()}n()}}};return{start(){!Oe&&!z&&(Oe=e.start(dr))},local(l,c,u){if(z||T===null||!Y.has(l))return;let h=Z(l),S=u-c.length+1;c.forEach((x,I)=>h.unsent.push({id:S+I,op:x})),b()},abandon(l){if(Me.has(l))return;Me.add(l),Y.delete(l);let c=Z(l);c.awaiting=c.awaiting.filter(u=>u===y),c.unsent=[],c.adopted=null},adopted(l,c,u){if(z||!Y.has(l))return;let h=Z(l),S=h.awaiting.find(x=>!x.sent&&x.through>=u);S?S.adopted=c:h.adopted={rev:c,through:u}},release(l,{read:c=!1}={}){if(z)return;let u=Z(l);if(u.deferred||c){u.after=_e+1,T!==null&&B&&ne();return}T!==null&&Y.has(l)&&(p(l,u),u.unsent=s(l,u),b())},framed(l){return ce.get(l)?.n??0},pendingFrames(l,c,{reserve:u=!1}={}){let h=ce.get(l);if(u&&h&&O&&T===c?.epoch){let G=s(l,h);for(;G.length;){let me=bt({name:l,n:h.n+1,ops:[],epoch:T}),H=0;for(;H<G.length&&H<$n;){let j=bt(G[H].op)+1;if(H&&me+j>oe)break;me+=j,H++}let ye=G.splice(0,H),K={n:++h.n,ops:ye.map(j=>j.op),entries:ye,first:ye[0].id,through:ye[ye.length-1].id,seq:null,sent:!1,refused:!0,epoch:T,client:O,receiptGeneration:ee,pageGeneration:w};je(h,K),h.awaiting.push(K),h.framed=K.through}h.unsent=[]}let S=new Set(t.get(l)?.store.pendingEntries().map(G=>G.id)??[]),x=[],I=!0;for(let G of h?.awaiting??[]){let me=G.entries.filter(H=>S.has(H.id));if(me.length){if(me.length!==G.entries.length||G.epoch!==c?.epoch||!G.client){I=!1;continue}x=Fe(x,[[G.client,[[G.n,G.n]]]])}}return{frames:x,complete:I}},captured(l,c,u){let h=ce.get(l);if(!h||!c||c.epoch!==T)return[];let S=vt(u),x=[];return h.awaiting=h.awaiting.filter(I=>{let G=I.epoch===c.epoch&&(st(S,I.client,I.n)||I.seq!==null&&I.seq<=c.seq);return G&&x.push(...I.entries.map(me=>me.id)),!G}),x},refresh(){T!==null&&B&&ne()},storeOpened(){T!==null&&B&&ne()},roomBound(l){return!z&&ce.get(l)?.room===!0},isWriter(){return de!==null&&de===O},get status(){return{connected:B,synced:X,epoch:T,seq:D,writer:de,clientId:O,stopped:z,provenanceVersion:J,receiptGeneration:ee}},stop:Et}}var Je=[0,1e4,3e4],$r=6e3,Nr=2;async function Ir(e){let t=globalThis.crypto&&globalThis.crypto.subtle;if(!t)return null;try{let r=new TextEncoder().encode(String(e)),o=await t.digest("SHA-256",r),n=new Uint8Array(o),i="";for(let a=0;a<n.length;a+=1)i+=n[a].toString(16).padStart(2,"0");return i}catch{return null}}function Pr(e){let t=[];for(let r of e||[]){let o=r&&r.saveId;if(typeof o=="string"&&o&&!t.includes(o)&&t.push(o),t.length>=Nr)break}return t}function Cr(e,t,r){return!!(e&&typeof e=="object"&&e.saveId===t&&e.requestHash===r&&e.status==="applied")}function Cn({query:e,digest:t=Ir,now:r=()=>Date.now(),setTimer:o=setTimeout,clearTimer:n=clearTimeout}={}){function i({captureId:a,html:d,attempts:m,initialOutcome:q,startedAt:g,onApplied:C,onUnknown:F}){let P=g+45e3,_=Pr(m),U=new Set,O=new Set,B=d,X=null,T=!1;function ee(f,y){try{typeof f=="function"&&f(y)}catch(v){console.error("clayjs: save-history callback failed:",v)}}function w(){T=!0,B=null;for(let f of U)n(f);U.clear();for(let f of O)f.abort();O.clear()}function J(f,y){T||(w(),ee(C,{captureId:a,saveId:f,requestHash:y}))}function D(f){T||(w(),ee(F,{captureId:a,reason:f}))}function de(f,y){let v=null;return v=o(()=>{v!==null&&U.delete(v),f()},Math.max(0,y)),U.add(v),v}function Y(f){f!==null&&(n(f),U.delete(f))}async function ae(f){if(T)return;let y=P-r();if(y<=0)return;let v=new AbortController;O.add(v);let k=de(()=>v.abort(),Math.min($r,y)),L=null;try{L=await e({saveId:f,requestHash:X,signal:v.signal})}catch{L=null}finally{Y(k),O.delete(v)}T||Cr(L,f,X)&&J(f,X)}function pe(){if(!T&&!(r()>=P))for(let f of _)ae(f)}async function z(){let f=null;try{f=await t(B)}catch{f=null}if(B=null,T)return;if(typeof f!="string"||!f){D("unavailable");return}if(X=f,q&&typeof q=="object"&&q.status==="applied"&&q.requestHash===X&&_.includes(q.saveId)){J(q.saveId,X);return}let y=r()-g;if(y>=45e3){D("expired");return}let v=-1;for(let k=0;k<Je.length;k+=1)Je[k]<=y&&(v=k);if(v<0){for(let k=0;k<Je.length;k+=1)de(pe,g+Je[k]-r());return}pe();for(let k=v+1;k<Je.length;k+=1)de(pe,g+Je[k]-r())}return de(()=>D("expired"),P-r()),z(),{cancel(){w()}}}return{start:i}}var _r="/_/sync/data";function Ln(){return new URL(_r,window.location.origin)}async function Lr(e,t){let r=Ln();r.searchParams.set("client-id",e);try{let o=await fetch(r.href,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","Document-URL":window.location.href,[Mt]:String(1)},body:JSON.stringify(t)}),n=null;try{n=await o.json()}catch{}let i=Number(o.headers?.get?.("Retry-After"))||0;return{status:o.status,body:n,retryAfter:i}}catch{return{status:0,body:null,retryAfter:0}}}async function jr(e,t=null,{signal:r}={}){let o=Ln();e&&o.searchParams.set("client-id",e),t&&typeof t.epoch=="string"&&Number.isInteger(t.seq)&&o.searchParams.set("since",`${t.epoch}:${t.seq}`);try{let n=await fetch(o.href,{credentials:"same-origin",cache:"no-store",headers:{"Document-URL":window.location.href,[Mt]:String(1)},signal:r});if(!n.ok){let a=null;try{a=await n.json()}catch{}return{status:n.status,code:a?.code??null,retryAfter:Number(n.headers?.get?.("Retry-After"))||0}}let i=await n.json();return i&&typeof i.epoch=="string"&&i.conn===null?null:i}catch{return null}}function jn(){return{start(e){return bn({open(t){t.lane==="live"&&e.open(t)},close:()=>e.close(),event(t,r){t==="data"?e.frame(r):t==="data-state"?e.state(r):t==="data-writer"&&e.writer(r)}})},send:Lr,fetchState:jr}}function Bn(e,t){return!t||!Number.isInteger(t.seq)?null:t.seq>=(e.last??0)?[]:t.seq<(e.floor??0)?null:e.log.filter(r=>r.seq>t.seq).map(r=>({seq:r.seq,ops:r.ops}))}var Br=4,Fr=2e3,Dr=500,Gr=1024,Hr=256*1024;function Fn(e,t){let r=[],o=()=>{for(let n=r.length-1;n>=0;n--)nt(r[n])};try{for(let n of t){let i=mt(e,n);i&&(r.push(i),e=i.root)}}catch(n){throw o(),n}return{value:e,undo:o}}var Wr=new TextEncoder,Dn="page-format:1";function Hn(){return typeof BroadcastChannel=="function"&&typeof navigator<"u"&&typeof navigator.locks?.request=="function"}function Gn(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function Wn({seed:e,key:t="clay-live:"+window.location.pathname,channel:r=null,floor:o=0}){let n=Gn(),i=o>=1?1:0,a=i?`${t}:${Dn}`:t,d=null,m=null,q=null,g=null,C=!1,F=null,P=!1,_=null,U=0,O=0,B=new Map,X=new Map,T=new Set,ee=new Map,w={epoch:null,seq:0,sequencer:null,closedBy:null,stale:!1,seen:new Map,stores:new Map};function J(s){d?.post(s)}function D(s,p){for(p.bytes=Wr.encode(JSON.stringify(p.ops)).length,s.log.push(p),s.logBytes+=p.bytes;s.log.length>Gr||s.logBytes>Hr;){let A=s.log.shift();s.logBytes-=A.bytes,s.floor=A.seq}}function de(s){let p=w.stores.get(s.name);p&&(p.value=Fn(p.value,s.ops).value,p.last=s.seq,p.ephemeral||D(p,{seq:s.seq,ops:s.ops})),w.seq=s.seq;let A=s.name+`
2
+ `+s.from;(w.seen.get(A)??0)<s.n&&w.seen.set(A,s.n)}function Y(s){let p={};for(let[A,M]of w.seen){let b=A.indexOf(`
3
+ `);A.slice(0,b)===s&&(p[A.slice(b+1)]=M)}return p}let ae=s=>s.behind||s.landed===null?-1:s.landed;function pe(s){let p={},A={};for(let[b,N]of w.stores)p[b]={value:Q(N.value),ephemeral:N.ephemeral,seen:Y(b),last:N.last,landed:ae(N)},A[b]={log:N.log,last:N.last,landed:N.landed,floor:N.floor,behind:N.behind,file:N.file,inFile:N.inFile};let M={epoch:g.epoch,seq:g.seq,writer:n,stores:p,mirror:{seen:[...w.seen],stores:A}};if(s!==void 0){let b=s&&s.epoch===w.epoch&&Number.isInteger(s.seq)?s.seq:0,N={};for(let[se,xe]of w.stores)N[se]=Bn(xe,{seq:b});M.moves=N}return M}function z(s,p){return s?.file?p.seq!=null&&s.file.seq!=null?p.seq<=s.file.seq:s.file.hash===rt(V(Re(p.text))):!1}function f(){for(let[s,p]of ee)try{z(w.stores.get(s),p)&&ee.delete(s)}catch{ee.delete(s)}}function y(s){if(g||!s||typeof s.epoch!="string"||!Number.isInteger(s.seq)||!s.mirror||T.has(s.epoch)||s.epoch===w.epoch&&s.seq<w.seq)return!1;w.epoch!==null&&s.epoch!==w.epoch&&T.add(w.epoch);let p=new Map;for(let[A,M]of Object.entries(s.stores||{})){let b=s.mirror.stores?.[A]||{},N=Array.isArray(b.log)?b.log:[];p.set(A,{value:Q(M.value),ephemeral:M.ephemeral===!0,log:N,logBytes:N.reduce((se,xe)=>se+(xe.bytes||0),0),last:Number.isInteger(b.last)?b.last:0,landed:Number.isInteger(b.landed)?b.landed:null,floor:Number.isInteger(b.floor)?b.floor:0,behind:b.behind===!0,file:b.file||null,inFile:Array.isArray(b.inFile)?[...b.inFile]:[]})}return w={epoch:s.epoch,seq:s.seq,sequencer:s.writer??null,closedBy:null,stale:!1,seen:new Map(s.mirror.seen||[]),stores:p},f(),O+=1,!0}function v(){let s=pe();J({type:"data-state",state:s}),q.state(s)}function k(){w.epoch!==null&&T.add(w.epoch),w.epoch=Gn(),w.seq=0;for(let s of w.stores.values())s.log=[],s.logBytes=0,s.last=0,s.landed=null,s.floor=0,s.behind=!0,s.file=null,s.inFile=[]}function L({fresh:s}){let p=w.epoch===null;p&&k();for(let[M,b]of e())w.stores.has(M)||w.stores.set(M,{value:Q(b.value),ephemeral:b.ephemeral,log:[],logBytes:0,last:0,landed:0,floor:0,behind:!1,file:null,inFile:[]});w.stale=!1,w.sequencer=n,w.closedBy=null;let A=new Map;for(let[M,b]of w.seen)A.set(M,{n:b,seq:0});g={epoch:w.epoch,seq:w.seq,lastN:A};for(let[M,b]of ee){let N=w.stores.get(M);if(!(!N||N.ephemeral)){try{if(z(N,b))continue}catch{continue}we(M,b)}}ee.clear(),s&&!p&&(k(),g.epoch=w.epoch,g.seq=0),O+=1,v()}function W(){k(),g.epoch=w.epoch,g.seq=0,O+=1,v()}function ue(){g&&(J({type:"closed",from:n,state:pe()}),g=null,F?.(),F=null)}function oe(s){return w.closedBy!==null&&(s===null||w.closedBy===s)?Promise.resolve(!0):new Promise(p=>{let A=setTimeout(()=>{_=null,p(!1)},Dr);_={sequencer:s,resolve(M){clearTimeout(A),_=null,p(M)}}})}function re(){P||C||(P=!0,navigator.locks.request(a,async()=>{if(C)return;let s=await oe(w.sequencer);if(!C)return L({fresh:w.epoch===null||!s}),new Promise(p=>{F=p})}).catch(()=>{}).finally(()=>{P=!1}))}function he(s,p){if(!p||typeof p.name!="string"||!Number.isInteger(p.n)||p.n<1||!Array.isArray(p.ops)||!p.ops.length)return{status:400,body:{error:"bad-frame"},retryAfter:0};let A=w.stores.get(p.name);if(!A)return{status:404,body:{error:"unknown-store"},retryAfter:0};let M=p.name+`
4
+ `+s,b=g.lastN.get(M);if(b&&p.n<=b.n)return{status:200,body:{duplicate:!0,seq:b.seq,epoch:g.epoch},retryAfter:0};let N;try{N=p.ops.map(Qe),Fn(A.value,N).undo()}catch(xe){return{status:422,body:{error:xe.message},retryAfter:0}}g.seq+=1,g.lastN.set(M,{n:p.n,seq:g.seq});let se={epoch:g.epoch,seq:g.seq,name:p.name,ops:N,from:s,n:p.n};return de(se),J({type:"data",data:se}),q.frame(Q(se)),{status:200,body:{seq:g.seq,epoch:g.epoch},retryAfter:0}}function ge(s){if(!g||!s.length)return;let p={};for(let A of s){let M=w.stores.get(A);M&&(p[A]=ae(M))}q.writer({epoch:g.epoch,writer:n,landed:p})}function te(s,p){let A=w.stores.get(s);return!A||A.ephemeral||!p||p.epoch!==w.epoch||!Number.isInteger(p.seq)||!A.behind&&A.landed!==null&&p.seq<=A.landed?!1:(A.landed=p.seq,A.behind=!1,!0)}function we(s,{text:p,at:A,seq:M}){let b=w.stores.get(s);if(!b||b.ephemeral)return null;let N;try{N=Q(Re(p))}catch{return null}if(N===null||typeof N!="object"||Array.isArray(N)!==Array.isArray(b.value))return null;let se={seq:M??null,hash:rt(V(N))},xe=!!A&&A.epoch===w.epoch&&A.seq<=g.seq,Ve=xe&&A.hash===se.hash,De=xe?A.seq:b.behind?null:b.landed;if(De===null||De<b.floor){let ke=!b.behind;return b.behind=!0,b.file=se,{changed:!1,moved:ke}}let pt=b.log.filter(ke=>ke.seq>De&&(Ve||!b.inFile.includes(ke.seq)));Ve&&(b.inFile=[]);for(let ke of pt)for(let Ge of ke.ops)try{et(N,Ge),N=tt(N,Ge)}catch{}let Xe=!1;if(V(N)!==V(b.value)){let ke=Sn(b.value,N);b.value=N,g.seq+=1,w.seq=g.seq,b.last=g.seq,D(b,{seq:g.seq,ops:ke}),b.inFile=[...b.inFile.filter(Ge=>Ge>b.floor),g.seq],Xe=!0}return b.landed=pt.length?De:b.last,b.behind=!1,b.file=se,{changed:Xe,moved:!0}}function _e(s){let p=!1,A=[];for(let[M,b]of s){let N=w.stores.get(M);if(!N||N.ephemeral)continue;if(!g){ee.set(M,b);continue}let se=we(M,b);se&&(se.changed?p=!0:se.moved&&A.push(M))}p?v():ge(A)}function be(s){return new Promise(p=>{let A=++U,M=setTimeout(()=>{B.delete(A),X.delete(A),p(null)},Fr);s.type==="post"&&X.set(A,w.sequencer),B.set(A,b=>{clearTimeout(M),B.delete(A),X.delete(A),p(b)}),J({...s,from:n,rid:A})})}function Oe(s){if(!(!s||typeof s.name!="string"||typeof s.epoch!="string"||!Number.isInteger(s.seq))&&!(g||T.has(s.epoch))){if(s.epoch!==w.epoch)w.stale=!0;else if(!w.stale&&s.seq===w.seq+1)try{de(s)}catch{w.stale=!0}else s.seq>w.seq&&(w.stale=!0);q.frame(s)}}function ce(s,p){if(!(typeof s!="string"||!p)){y(p)&&(w.closedBy=s,q.state(p));for(let[A,M]of X)M===s&&B.get(A)?.(null);_&&(_.sequencer===null||_.sequencer===s)&&_.resolve(w.closedBy===s)}}function Me({data:s}){if(!(C||!s||s.v!==Br)){if(g&&(s.type==="data"&&s.data?.epoch===g.epoch||(s.type==="data-state"||s.type==="closed")&&s.state?.epoch===g.epoch&&s.state.writer!==n)){W();return}if(!g&&s.type==="data-state"&&s.state?.epoch===w.epoch&&s.state.writer!==w.sequencer&&Number.isInteger(s.state.seq)&&s.state.seq<w.seq){J({type:"forked",epoch:w.epoch,to:s.state.writer});return}if(s.type==="forked"){g&&s.epoch===g.epoch&&s.to===n&&W();return}s.type==="data"?Oe(s.data):s.type==="data-state"?y(s.state)&&q.state(s.state):s.type==="closed"?ce(s.from,s.state):s.type==="landed"?typeof s.name=="string"&&te(s.name,s.at)&&ge([s.name]):s.type==="answer"?s.to===n&&B.get(s.rid)?.(s.result):g&&s.type==="post"?s.epoch===g.epoch&&J({type:"answer",to:s.from,rid:s.rid,result:he(s.from,s.frame)}):g&&s.type==="state-request"&&J({type:"answer",to:s.from,rid:s.rid,result:pe(s.since)})}}function $(){ue()}function Z(s){!s.persisted||C||g||P||(w.sequencer=null,w.closedBy=null,re(),q.close(),q.open({clientId:n,lane:"live"}))}function je(s,{covered:p=!1}={}){let A=s>=1?1:0,M={floor:i,scope:a};return A<=i?{status:"already",...M}:C||!d?{status:"refused",code:"lane-stopped",...M}:r?{status:"refused",code:"shared-channel",...M}:p?(ue(),m?.(),a=A?`${t}:${Dn}`:t,i=A,d=$t(a),m=d.subscribe("durable",b=>Me({data:b})),w.sequencer=w.closedBy=null,P=!1,re(),q.close(),q.open({clientId:n,lane:"live"}),{status:"switched",floor:i,scope:a}):{status:"refused",code:"uncovered",...M}}return{clientId:n,get scope(){return a},get floor(){return i},switchScope:je,start(s){return q=s,d=r??$t(a),m=d.subscribe("durable",p=>Me({data:p})),window.addEventListener("pagehide",$),window.addEventListener("pageshow",Z),re(),q.open({clientId:n,lane:"live"}),()=>{ue(),C=!0,_?.resolve(!1),window.removeEventListener("pagehide",$),window.removeEventListener("pageshow",Z);for(let p of B.values())p(null);m?.(),m=null,d=null}},async send(s,p){return g?he(n,p):await be({type:"post",frame:p,epoch:w.epoch})||{status:0,body:null,retryAfter:0}},async fetchState(s,p=null){if(g)return pe(p);let A=O,M=await be({type:"state-request",since:p});return g?pe(p):A!==O||!y(M)?null:M},fileFrame(s){C||_e(s)},landed(s,p){C||!p||(te(s,p)&&ge([s]),J({type:"landed",name:s,at:{epoch:p.epoch,seq:p.seq}}))},get isSequencer(){return g!==null}}}var Jr=/^[A-Za-z0-9_.:-]{1,64}$/,R=new Map,Zn="save_"+[...crypto.getRandomValues(new Uint32Array(4))].map(e=>e.toString(16).padStart(8,"0")).join(""),Bt=0,Yr=0,zr=45e3;function Ut(e){let t=ot(e.getAttribute("live-at"));if(!t||t.hash!==mo(e.textContent))return null;let r=e.getAttribute("live-by"),o=r===null?null:it(r);return r!==null&&!o?null:o&&o.v!==2?{disk:!0}:{epoch:t.epoch,seq:t.seq,frames:vt(o),ancestors:On(o)}}function Kr(e,t){let r=e.leftAt;if(!r||r.disk)return null;let o=E?.pendingFrames(e.store.name,r,{reserve:t})??{frames:[],complete:!0};if(!o.complete)return null;let n=Fe(r.frames??[],o.frames),i=r.ancestors??[],a=V(e.store.value),d=JSON.stringify([r.epoch,r.seq,n,i,e.store.mark,a]);if(e.capture?.key===d)return e.capture.value;let m={v:2,frames:n,ancestors:i,capture:[Zn,Bt+1]},q=Mn(m),g=q?{at:Nt(r.epoch,r.seq,a),by:q}:null;return e.capture={key:d,value:g},g}var Le=new Map,Ie=null,Se=null,Ee=null,Vr=Cn({query:e=>cn?.(e)??null}),Ae=new Map;function Qn(e){if(!e.captureOps.size)return;let t=new Set(e.store.pendingEntries().map(r=>r.id));for(let[r,o]of e.captureOps)o.ids=o.ids.filter(n=>t.has(n)),o.ids.length||e.captureOps.delete(r);[...e.captureOps.values()].some(r=>r.ended)||ft(e)}var er=(e,t)=>Ie===null||!pn()?!1:Le.get(Ie)?.get(e)?.key===t;function ut(e){let t=R.get(e);if(!t||!t.captureOps.size)return[];let r=new Set(t.store.pendingEntries().map(n=>n.id)),o=new Set;for(let[n,i]of t.captureOps)if(!(!i.ended&&!er(e,n)))for(let a of i.ids)r.has(a)&&o.add(a);return[...o]}function Jt(e){for(let[t,r]of e.captureOps)if(r.ended)return[t,r];return null}Tt({id:"live:held",isPending:()=>[...R.values()].some(e=>Jt(e))});var Un=e=>[...e.captureOps].some(([t,r])=>!r.ended&&er(e.store.name,t));function Xr({op:e,path:t,n:r,value:o}){let n=t.length?t.join("."):"the whole value",i=e==="add"?`${n} + ${r}`:e==="del"?`${n} removed`:`${n} = ${JSON.stringify(o)}`;return i.length>60?`${i.slice(0,57)}...`:i}function Yt(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{e.timer=null,ze(e)},zr)}function ft(e){clearTimeout(e.timer),e.timer=null}function ze(e,{read:t=!0}={}){let r=e.store.name,o=ut(r);if(ft(e),e.withheld=!1,e.reading=!1,nr(e),o.length){let n=e.store.pendingEntries().filter(m=>o.includes(m.id)).map(m=>m.op);e.store.handle.status.mode==="file"&&(e.leftAt=null),e.store.rebase(e.store.authoritative,{source:"state",dropIds:o});let i=n.slice(0,5).map(Xr).join("; "),a=n.length>5?` and ${n.length-5} more`:"",d=`A save of "${r}" ended without an answer, so ${n.length===1?"this edit was":"these edits were"} not sent again: ${i}${a}. Check the value, and redo ${n.length===1?"it":"any"} if missing.`;console.warn(`clay.live("${r}"): ${d}`,n),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-uncertain",ops:n,message:d}}))}t&&E?.release(r,{read:E.roomBound(r)})}function ct(e){Qn(e);let t=e.store.name;if(e.recovery&&!eo(e)&&nr(e),!(!e.withheld||e.reading||ut(t).length)){if(!E?.roomBound(t)){e.withheld=!1,ft(e);return}e.reading=!0,Yt(e),E.release(t,{read:!0})}}function Zr(e){let t=R.get(e);t&&(zt(t),!(!t.withheld&&!t.reading)&&(t.withheld=!1,t.reading=!1,[...t.captureOps.values()].some(r=>r.ended)||ft(t)))}function Qr(){for(let e of R.values())if(e.recovery||e.historicalRefreshPending)return!0;return!1}function eo(e){let t=new Set(e.store.pendingEntries().map(o=>o.id));return e.recovery.targets.find(({name:o})=>o===e.store.name)?.ids.some(o=>t.has(o))??!1}function to(e){if(!Ee||Ee.captureId!==e||typeof Ee.html!="string")return null;let t=[];for(let[r,o]of Ee.qualified)!R.get(r)||!o.length||t.push({name:r,ids:[...o],saved:Ee.saved.get(r)});return t.length?{captureId:e,html:Ee.html,targets:t}:null}function qt(){Ee&&(Ee.html=null)}function no(e,t){tr(e);let r=e.store.name;e.refreshTimer=setTimeout(()=>{if(e.refreshTimer=null,!e.historicalRefreshPending)return;let o=`The save of "${r}" that ended without an answer did happen, but the value the file holds now must load before newer edits can be saved.`;console.warn(`clay.live("${r}"): ${o}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:r,code:"save-history-refresh-required",message:o}}))},Math.max(0,t-Date.now()))}function zt(e){e.historicalRefreshPending&&(e.historicalRefreshPending=!1,tr(e))}function tr(e){e.refreshTimer!==null&&(clearTimeout(e.refreshTimer),e.refreshTimer=null)}function nr(e){let t=e.recovery;t&&(e.recovery=null,!t.targets.some(r=>R.get(r.name)?.recovery===t)&&(Ae.delete(t.captureId),t.run?.cancel()))}function rr(e){if(e==null)return;let t=Ae.get(e);if(t){Ae.delete(e);for(let r of t.targets){let o=R.get(r.name);o&&o.recovery===t&&(o.recovery=null)}t.run?.cancel()}}function ro(e,{result:t,attempts:r,startedAt:o}){let{captureId:n,html:i}=e,a={captureId:n,deadline:o+45e3,targets:e.targets,run:null};Ae.set(n,a);for(let d of e.targets){let m=R.get(d.name);ft(m),m.recovery=a}ht("save-history").then(d=>{if(Ae.get(n)===a){if(e.html=null,!d)return Jn(n);a.run=Vr.start({captureId:n,html:i,attempts:r,initialOutcome:t?.saveOutcome??null,startedAt:o,onApplied:({saveId:m,requestHash:q})=>oo(n,m,q),onUnknown:({reason:m})=>so(n,m)})}},()=>{e.html=null,Jn(n)})}function oo(e,t,r){let o=Ae.get(e);if(o){Ae.delete(e);for(let n of o.targets){let i=R.get(n.name);if(!i||i.recovery!==o)continue;i.recovery=null,i.historicalRefreshPending=!0;let a=new Set(i.store.pendingEntries().map(m=>m.id)),d=n.ids.filter(m=>a.has(m));if(i.store.rebase(JSON.parse(n.saved),{source:"state",dropIds:d}),!E){zt(i);continue}E.release(i.store.name,{read:!0}),no(i,o.deadline)}}}function Jn(e){let t=Ae.get(e);if(t){Ae.delete(e);for(let r of t.targets){let o=R.get(r.name);if(!(!o||o.recovery!==t)){if(o.recovery=null,!E?.roomBound(o.store.name)){ze(o,{read:!1});continue}o.withheld=!0,o.reading=!0,Yt(o),E.release(o.store.name,{read:!0})}}}}function so(e,t){let r=Ae.get(e);if(r){Ae.delete(e);for(let o of r.targets){let n=R.get(o.name);!n||n.recovery!==r||(n.recovery=null,ze(n))}}}function io(e,t,r){let o=e.captureOps.get(t),n=e.store.name;if(!o){e.store.handle.status.mode==="file"&&(e.leftAt=null);return}if(o.ended=!0,r?.has(n)){e.withheld=!0,e.reading=!0;return}if(!E?.roomBound(n)){ze(e,{read:!1});return}e.withheld=!0,e.reading=!0,Yt(e),E.release(n,{read:!0})}function Ft(e){if(Array.isArray(e))return e.map(Ft);if(e===null||typeof e!="object")return e;let t={};for(let r of Object.keys(e).sort())t[r]=Ft(e[r]);return t}function Kt(e){try{return JSON.stringify(Ft(Re(e)))}catch{return null}}var fe=null,dt=()=>!fe||fe.admitted;function lo(){if(!He||!dt())return!1;for(let e of R.values())if(!e.store.ephemeral){if(e.store.handle.status.mode==="fast"){if(E?.isWriter()&&e.landed<e.last)return!0}else if(e.store.pending.length>0)return!0}return!1}var Dt=new Set;function or(){for(let e of[...Dt])e()}var ve=Rn({needsSave:lo,blocked:()=>!dt()||!wn()||vn()||yn()||Qr(),save:()=>Rt().finally(or),saveNow:()=>dn(!0,()=>Rt())}),E=null,Gt=!1,Ht=0,St=null,Vt=!1,Pe=null,Xt=!1;function Zt(){return[...R.values()].filter(e=>!e.store.ephemeral)}function sr(){if(!fe||fe.admitted||!E||E.status.stopped)return!1;for(let e of Zt())if(e.store.handle.status.mode==="fast"&&e.store.pending.length>0)return!0;return!1}async function ir({timeoutMs:e=5e3}={}){let t=Date.now()+e,r=()=>{for(let o of Zt())o.store.handle.status.mode==="fast"&&o.store.pending.length>0&&E?.release(o.store.name)};for(r();sr();){if(Date.now()>=t)return{ok:!1,code:"timeout"};await new Promise(o=>setTimeout(o,5)),r()}return{ok:!0}}Tt({id:"live:writer",isPending:sr,flush:ir});function ao(){for(let e of R.values()){e.framesSince=!1;let t=e.store.pendingEntries().map(r=>r.id);t.length&&e.store.rebase(e.store.authoritative,{source:"state",dropIds:t})}}function uo(){let e=E;E=null,Gt=!1,Ht++,St=null,Pe=null,Vt=!1,At=null,Qt=null,at=null,Ye=null,e?.stop()}function ss(){return{id:"clay:live",order:200,prepare(e={}){if(e.initial===!0)return fe||(fe={admitted:!0}),zn(fe,{adopted:!0});lr();let t={admitted:!1,wantsLane:!0};return fe=t,ao(),xt(),zn(t)}}}function Yn(){for(let e of Zt())e.store.pending.length>0&&E?.release(e.store.name)}function zn(e,{adopted:t=!1}={}){return{enable(){t||fe!==e||(e.admitted=!0,xt(),Yn())},quiesce(){if(fe===e)return e.admitted=!1,ir()},resume(){fe===e&&(e.admitted=!0,Yn())},dispose(){fe===e&&(fe=null,uo())}}}var At=null,Qt=null,at=null,Ye=null;function lr(){At=new Promise(e=>{at=e}),Qt=new Promise(e=>{Ye=e})}function en(){return At||lr(),{laneReady:At,writerReady:Qt}}function is(){return en().laneReady}function ls(){return en().writerReady}function Kn(){for(let e of R.values())if(!e.store.ephemeral&&e.store.handle.status.mode==="fast"&&e.landed===-1){ve.soon();return}ve.changed()}function jt(e,t){e.store.rebase(e.store.authoritative,{source:"state",through:t})}function tn(e,t,r=null){if(e)for(let[o,n]of e){let i=R.get(o);!i||n.mode!=="file"||(t||n.maybeLanded?io(i,n.key,r):(i.captureOps.delete(n.key),ct(i)),i.store.handle.status.mode==="fast"&&E?.release(o))}}function Ke(e){let t=Le.get(e);return Le.delete(e),Ie===e&&(Ie=null),Se===e&&(Se=null),t}function ar(e,t=null){let r=t??Ie??Se;r!==null&&tn(Ke(r),e)}function co(e,t){let r=e?.code,o=r==="page-converting"||r==="page-capacity";return r==="save-already-applied"||e?.hadTimeout===!0||t!==!1&&!o&&!(e?.status>=400&&e?.status<500)}function Vn(e){return{transport:e,entries:R,onWriter:()=>{ve.changed(),E&&E.status.writer!==null&&Ye?.(E)},onApplied:Kn,onLanded:()=>{Kn(),or()},onCheckpoint:()=>ve.soon(),onLeave:(t,r)=>{let o=R.get(t);o?.store.handle.status.mode==="fast"&&(o.leftAt={...r,frames:[],ancestors:[]})},held:t=>ut(t).length>0,heldIds:ut,hold:t=>{let r=R.get(t);return r?r.recovery?!0:Un(r)?(r.withheld=!0,!0):(ze(r,{read:!1}),!1):!1},taken:Zr,onStop:()=>{for(let t of R.values())zt(t),!t.recovery&&(Un(t)||ze(t,{read:!1}))}}}function fo(){let e=new Map;for(let[t,r]of Ce(document,{warn:!1})){let o=R.get(t);if(o){e.set(t,{value:o.store.authoritative,ephemeral:o.store.ephemeral});continue}try{let n=Re(r.element.textContent);n!==null&&typeof n=="object"&&e.set(t,{value:n,ephemeral:r.ephemeral})}catch{}}return e}function xt(){if(en(),Gt||!(fe?fe.admitted||fe.wantsLane:He))return;Gt=!0;let e=++Ht;ht("live-data").then(async t=>{let r=t&&await ht("live-provenance");if(e===Ht){if(St=t,Vt=r,t)E=Lt(Vn(jn()));else if(Hn())Pe=Wn({seed:fo,floor:document.querySelector('meta[name="clay-page-format"]')?.getAttribute("content")}),E=Lt(Vn(Pe));else{at?.(null),Ye?.(null);return}for(let o of Ce(document,{warn:!1}).keys())if(!R.has(o))try{cr(o)}catch{}for(let[o,n]of R)n.historicalRefreshPending&&E.release(o,{read:!0});E.start(),at?.(E),E.status.writer!==null&&Ye?.(E)}}).catch(()=>{at?.(null),Ye?.(null)})}function po(e){let t=(e||"").split(";")[0].trim().toLowerCase();return t==="application/json"||t.endsWith("+json")}function Ce(e=document,{warn:t=!0}={}){let r=new Map,o=new Set;for(let n of e.querySelectorAll('script[merge][clay~="live"]')){if(n.hasAttribute("src")||!po(n.getAttribute("type")))continue;let i=n.getAttribute("merge");if(Jr.test(i)){if(r.has(i)){o.add(i);continue}r.set(i,{name:i,ephemeral:n.getAttribute("clay").split(/\s+/).includes("ephemeral"),element:n})}}for(let n of o)t&&console.warn(`clay.live: more than one live tag is named "${n}", so none of them is live`),r.delete(n);return r}function kt(e){return new DOMParser().parseFromString(e,"text/html")}function ho(e){let t=e.store.handle.status.mode==="fast",r=t?e.store.authoritative:e.store.value,o=t&&/^page(\.[0-9]+)?$/.test(e.store.name)?An(r):r;return e.layout==="lines"?go(o):e.layout==="pretty"?JSON.stringify(o,null,2).replace(/</g,"\\u003c"):V(o)}var Xn=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function go(e){return Xn(e)?`{${Object.entries(e).map(([r,o])=>!Xn(o)||!Object.keys(o).length?`${V(r)}:${V(o)}`:`${V(r)}:{
5
+ ${Object.entries(o).map(([n,i])=>`${V(n)}:${V(i)}`).join(`,
6
+ `)}
7
+ }`).join(`,
8
+ `)}}`:V(e)}function mo(e){try{return rt(V(Re(e)))}catch{return null}}function yo(e,t,r,o){let n;try{n=Re(t)}catch{return}e.store.rebase(n,{source:r,...o?.length&&{dropIds:o}})&&(e.framesSince=!0)}function ur(e,t,{layout:r="line",leftAt:o=null,staged:n=null}={}){let i={store:t,layout:r,framesSince:!1,last:0,landed:0,leftAt:o,captureOps:new Map,withheld:!1,reading:!1,timer:null,recovery:null,historicalRefreshPending:!1,refreshTimer:null,staged:n};return R.set(e,i),t.onDelivery(a=>{a.code==="receipt-expired"&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:a.code,ops:a.ops,message:"The room retired an update receipt. Check the saved value before restoring this update."}})),a.phase==="refused"&&a.code==="too-large"&&!/^page(\.[0-9]+)?$/.test(e)&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:"op-too-large",message:"That change was too large to share, so it was undone."}})),a.phase==="left"&&a.code==="no-store"&&/^page(\.[0-9]+)?$/.test(e)&&document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:e,code:"unknown-store",message:`The room has no "${e}" store, so the page it holds is not the one this tab is editing.`}}))}),t.onRebase(a=>{ct(i),t.handle.status.mode==="file"&&["undone","refused","decided"].includes(a.cause)&&(i.leftAt=null)}),t.ephemeral||t.onLocal(()=>ve.changed()),t.onLocal(a=>{!i.staged&&dt()&&E?.local(e,a,t.mark)}),t.handle.on("change",()=>{!t.ephemeral&&t.handle.status.mode==="fast"&&ve.changed()}),n||(E?.storeOpened(e),xt()),i}function cr(e){let t=R.get(e);if(t)return t.store.handle;let r=Ce().get(e);if(!r)throw new Error(`clay.live: this page has no <script type="application/json" merge="${e}" clay="live"> tag`);let o=r.element.textContent,n;try{n=Re(o)}catch(m){throw new SyntaxError(`clay.live("${e}"): the tag's JSON does not parse: ${m.message}`)}let i=Ct({name:e,value:n,ephemeral:r.ephemeral}),a=r.element.getAttribute("live-format")==="lines"?"lines":o.includes(`
9
+ `)?"pretty":"line";return ur(e,i,{layout:a,leftAt:Ut(r.element)}).store.handle}function as(e,{value:t,represented:r=null,signal:o=null}={}){let n=R.get(e);if(n&&!n.staged)throw new Error(`clay.live("${e}"): the store is open in a room`);let i=n??ur(e,Ct({name:e,value:t,ephemeral:!1}),{staged:{represented:r,signal:o}});return{handle:i.store.handle,isPending:()=>!!i.staged&&i.store.pending.length>0,flush:(a={})=>vo(i,a),dispose(){i.staged&&R.get(e)===i&&R.delete(e)},close(){R.get(e)===i&&R.delete(e)}}}async function vo(e,{timeoutMs:t=1e4}={}){let r=e.staged;if(!r||!e.store.pending.length)return{ok:!0};if(r.conflict)return{ok:!1,code:r.conflict};let o=r.represented?.etag||null,n=Ot();if(o&&n&&o!==n)return{ok:!1,code:"stale-document"};o&&!n&&fn(o);let i=await xo({timeoutMs:t});return i.ok?{ok:!0}:{ok:!1,code:r.conflict??i.code??null}}function wo(e){e.staged&&(e.staged=null,e.tagless=!0,E?.storeOpened(e.store.name),xt())}un((e,{forSave:t,requestRefresh:r})=>{if(!R.size)return;let o=Ce(e,{warn:!1});for(let n of R.values()){if(n.store.ephemeral)continue;let i=o.get(n.store.name);if(!i&&(n.staged||n.tagless)){let m=e.querySelector("article[data-page]");if(!m)continue;let q=m.ownerDocument.createElement("script");q.setAttribute("type","application/json"),q.setAttribute("merge",n.store.name),q.setAttribute("clay","live"),m.parentNode.insertBefore(q,m),i={name:n.store.name,ephemeral:!1,element:q}}if(!i)continue;if(t&&(n.recovery||n.historicalRefreshPending)){let m=n.historicalRefreshPending;m&&r&&E?.release(n.store.name,{read:!0});let q=m?"save-history-refresh-required":"save-history-pending",g=m?`clay.live("${n.store.name}"): the earlier save happened, but the current value must load before newer edits can be saved. Your edits are still in this tab.`:`clay.live("${n.store.name}"): a save ended without an answer, so the saved value must be checked before this one is sent. Your edits are still in this tab.`;throw console.warn(`clay.live("${n.store.name}"): ${g}`),m||document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:n.store.name,code:q,message:g}})),Object.assign(new Error(g),{code:q})}let a=t&&n.store.handle.status.mode==="file"?Jt(n)?.[1]:null;if(a){i.element.textContent=a.text;for(let[m,q]of[["live-at",a.at],["live-by",a.by]])q===null?i.element.removeAttribute(m):i.element.setAttribute(m,q);continue}let d=ho(n);if(i.element.textContent=d,n.store.handle.status.mode==="fast"&&E)i.element.setAttribute("live-at",Nt(E.status.epoch,E.status.seq,V(n.store.authoritative))),i.element.removeAttribute("live-by");else{let m=n.store.pending.length>0||n.leftAt&&!n.leftAt.disk,q=St===null&&n.leftAt&&!n.leftAt.disk;if(t&&m&&(q||St&&!Vt)){let C="This host must update its live data protocol before this save can be sent. Your edits are still in this tab.";throw console.warn(`clay.live("${n.store.name}"): ${C}`),document.dispatchEvent(new CustomEvent("clay:live-notice",{detail:{name:n.store.name,code:"provenance-unsupported",message:C}})),E?.refresh(),Object.assign(new Error(C),{code:"provenance-unsupported"})}let g=Kr(n,t);g?(i.element.setAttribute("live-at",g.at),i.element.setAttribute("live-by",g.by)):(i.element.removeAttribute("live-at"),i.element.removeAttribute("live-by"))}}});document.addEventListener("clay:snapshot-ready",e=>{if(e.detail?.forSave!==!0||!R.size)return;let t=e.detail.captureId??null,r=Ce(e.detail.documentElement,{warn:!1}),o=new Map;for(let n of R.values()){if(n.store.ephemeral)continue;let i=r.get(n.store.name);if(!i)continue;let a=n.store.handle.status.mode==="fast"&&E?"fast":"file",d=a==="fast"?{epoch:E.status.epoch,seq:E.status.seq}:null,m=a==="file"?Ut(i.element):null,q=it(i.element.getAttribute("live-by")),g=a==="file"?Jt(n):null,C=n.store.pendingEntries().map(O=>O.id),F=g?g[1].ids.filter(O=>C.includes(O)):a==="file"?C:[],P=a==="file"&&q?.v===2?q.capture:null,_=F.length?g?g[0]:P?JSON.stringify(P):`anonymous:${++Yr}`:null,U=g?g[1].mark:n.store.mark;o.set(n.store.name,{mode:a,mark:U,canonical:Kt(i.element.textContent),at:d,lineage:m,by:i.element.getAttribute("live-by"),key:_,maybeLanded:!!g,ids:F}),m&&!m.disk&&n.leftAt&&(n.leftAt={...n.leftAt,ancestors:m.ancestors}),P&&P[0]===Zn&&(Bt=Math.max(Bt,P[1])),_&&(n.captureOps.set(_,{capture:P,ids:F,ended:!1,mark:U,text:i.element.textContent,at:i.element.getAttribute("live-at"),by:i.element.getAttribute("live-by")}),Qn(n)),n.framesSince=!1,a==="fast"&&Xt&&ve.flushing&&Pe?.landed(n.store.name,d)}Se!==null&&Se!==Ie&&tn(Ke(Se),!1),t!==null&&(Le.set(t,o),Se=t)});document.addEventListener("clay:save-conflict",e=>{ar(e.detail?.hadTimeout===!0,e.detail?.captureId)});for(let e of["clay:save-error","clay:save-offline"])document.addEventListener(e,t=>{let r=t.detail?.status,o=t.detail?.code,n=o==="page-converting"||o==="page-capacity";ar(o==="save-already-applied"||t.detail?.hadTimeout===!0||t.detail?.sent!==!1&&!n&&!(r>=400&&r<500),t.detail?.captureId)});function fr(e,t){if(!t||typeof e!="string")return;let r=Ce(kt(e),{warn:!1});for(let[o,n]of t){let i=R.get(o);if(!i)continue;let a=r.get(o),d=i.store.handle.status.mode;if(!a||Kt(a.element.textContent)!==n.canonical){n.mode==="file"&&(E?.roomBound(o)&&jt(i,n.mark),d==="fast"&&E?.release(o),ct(i));continue}if(n.mode==="fast"){n.at&&Pe?.landed(o,n.at);continue}d==="fast"?(jt(i,n.mark),Pe?.fileFrame(new Map([[o,{text:a.element.textContent,at:ot(a.element.getAttribute("live-at")),seq:null}]])),E?.release(o),E?.refresh()):i.framesSince?(!i.leftAt||i.leftAt.disk||E?.roomBound(o))&&jt(i,n.mark):(i.store.confirm(n.mark),i.leftAt=n.lineage&&a.element.getAttribute("live-by")===n.by?n.lineage:{disk:!0},wo(i)),ct(i)}}function bo(e,t,r){let o=Ce(kt(r),{warn:!1}),n=new Map,i=new Map;for(let[a,d]of t){if(d.qualifiedIds=null,d.mode!=="file"||d.key===null)continue;let m=R.get(a);if(!m)continue;let q=o.get(a);if(!q||Kt(q.element.textContent)!==d.canonical)continue;let g=m.captureOps.get(d.key);if(!g||q.element.getAttribute("live-at")!==g.at||q.element.getAttribute("live-by")!==d.by)continue;let C=new Set(m.store.pendingEntries().map(_=>_.id)),F=new Set(g.ids),P=d.ids.filter(_=>C.has(_)&&F.has(_));P.length&&(d.qualifiedIds=P,n.set(a,P),i.set(a,d.canonical))}Ee={captureId:e,qualified:n,saved:i,html:r}}gn(({captureId:e,html:t})=>{if(e==null)return;let r=Le.get(e);r&&(Ie=e,Se===e&&(Se=null),bo(e,r,t))});mn(({captureId:e,result:t,attempts:r,sent:o})=>{if(e==null||t?.ok)return;let n=Le.get(e);if(!n)return;let i=[...n.keys()].map(m=>R.get(m)).find(m=>m?.staged);if(i&&t.code==="page-nothing-to-write"){i.store.confirm(i.store.mark),Ke(e),qt(),ct(i);return}i&&t.code==="page-lineage-stale"&&(i.staged.conflict="conflict"),Ke(e);let a=co(t,o),d=a?to(e):null;qt(),tn(n,a,d?new Set(d.targets.map(m=>m.name)):null),d&&ro(d,{result:t,attempts:r,startedAt:Date.now()})});var Wt=null;function us(e){Wt=e}function qo(e,t){if(!Wt)return;let r=an(e);if(!r)return;let o=null;try{o=kt(t).querySelector("article[data-page]")?.innerHTML??null}catch{o=null}let n=Ot();Promise.resolve().then(()=>Wt({capture:String(e),state:r,article:o,etag:n})).catch(()=>{})}function So(e,t){let r=t?.captureId;if(r==null)return;qo(r,e);let o=Le.get(r);o&&(Ke(r),qt(),rr(r),fr(e,o))}hn(So);function cs(e){let t=Se??Ie,r=t===null?null:Ke(t);qt(),rr(t),fr(e,r)}function fs(){return Ee}function Ao(e,t=null){if(typeof e!="string"||!e)return;let r=Ce(kt(e),{warn:!1});if(!r.size)return;if(Pe){let n=new Map;for(let[i,a]of r)a.ephemeral||n.set(i,{text:a.element.textContent,at:ot(a.element.getAttribute("live-at")),seq:Number.isInteger(t)?t:null});Pe.fileFrame(n)}let o=Ce(document,{warn:!1});for(let[n,i]of r){let a=i.element.textContent,d=R.get(n),m=i.element.getAttribute("live-at"),q=i.element.getAttribute("live-by"),g=o.get(n)?.element;if(d&&!d.store.ephemeral&&d.store.handle.status.mode==="file"&&m!==null&&q===null&&(d.withheld||ut(n).length)){d.withheld=!0;continue}let C=[];if(d&&d.store.handle.status.mode==="file"){let F=Ut(i.element),P=F&&!F.disk&&(!E?.status.epoch||F.epoch===E.status.epoch);if(P?C=E?.captured(n,F,it(q))??[]:F?.disk&&(C=E?.captured(n,ot(m),null)??[]),F&&!F.disk)for(let[_,U]of d.captureOps)U.capture&&st(F.ancestors,...U.capture)&&(C.push(...U.ids),d.captureOps.delete(_));d.leftAt=P||F?.disk?F:null}if(g&&(!d||d.store.handle.status.mode==="file")&&(m===null?g.removeAttribute("live-at"):g.getAttribute("live-at")!==m&&g.setAttribute("live-at",m),q===null?g.removeAttribute("live-by"):g.getAttribute("live-by")!==q&&g.setAttribute("live-by",q)),d&&!d.store.ephemeral){if(d.staged)continue;d.store.handle.status.mode==="file"&&yo(d,a,"remote",C);continue}g&&g.textContent!==a&&(g.textContent=a)}}document.addEventListener("clay:sync-applied",e=>Ao(e.detail?.html,e.detail?.seq));document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&He&&dt()&&ve.flush()});window.addEventListener("pagehide",()=>{if(Xt=!0,!He||!dt())return;let e=Se??Ie,t=ve.flushing&&e!==null?Le.get(e):null;if(t)for(let[r,o]of t)o.mode==="fast"&&o.at&&Pe?.landed(r,o.at);ve.flush()});window.addEventListener("pageshow",()=>{Xt=!1});function ds(e){return R.get(e)?.store||null}function ps(e,t){let r=R.get(e);r&&r.store===t&&!r.staged&&R.delete(e)}function hs(){return[...R.values()].map(e=>e.store)}function gs(){return E}function ms(e){ve.within(e)}function xo({timeoutMs:e=1e4}={}){let t=new Map;for(let[o,n]of R)n.store.ephemeral||t.set(o,n.store.handle.status.mode==="fast"?n.last??0:null);let r=()=>[...t].every(([o,n])=>{let i=R.get(o);return i?n===null||i.store.handle.status.mode!=="fast"?i.store.pending.length===0:(i.landed??0)>=n:!0});return r()?Promise.resolve({ok:!0}):new Promise(o=>{let n=d=>{clearTimeout(a),Dt.delete(i),o(d)},i=()=>{r()&&n({ok:!0})},a=setTimeout(()=>n({ok:!1,code:"timeout"}),e);Dt.add(i),He&&(!E||E.isWriter())&&ve.soon()})}var ys=cr;export{zr as a,ir as b,ss as c,is as d,ls as e,Ce as f,go as g,cr as h,as as i,us as j,cs as k,fs as l,Ao as m,ds as n,ps as o,hs as p,gs as q,ms as r,xo as s,ys as t};
@@ -0,0 +1 @@
1
+ var f="clay-page-format",F="page-format-v1",m="page-format-upgrade-required",o=e=>Number.isSafeInteger(e)&&e>0?e:0,s=e=>/<meta\b[^>]*\bname\s*=\s*["']?clay-page-format["']?[^>]*>/i.exec(e);function E(e){return typeof e=="number"?o(e):typeof e!="string"||!/^\s*\d+\s*$/.test(e)?0:o(Number(e))}function p(e){if(typeof e!="string")return 0;let n=s(e);if(!n)return 0;let t=/\bcontent\s*=\s*["']?(\d+)/i.exec(n[0]);return t?o(Number(t[1])):0}function b(e,n){let t=o(n);if(typeof e!="string"||!t)return e;let r=s(e);if(r&&p(r[0])===t)return e;let a=`<meta name="${f}" content="${t}">`;if(r)return e.slice(0,r.index)+a+e.slice(r.index+r[0].length);let c=/<\/head\s*>/i.exec(e)||/<body\b/i.exec(e);return c?e.slice(0,c.index)+a+e.slice(c.index):a+e}var i=0,d=()=>i;function P(e){return i=Math.max(i,o(e)),i}export{f as a,F as b,m as c,E as d,p as e,b as f,d as g,P as h};
@@ -0,0 +1 @@
1
+ import{e as a,f as b,g as c}from"./c-GFJJEBTU.js";import"./c-BWFVSBDF.js";import"./c-VRZN56XY.js";import"./c-OW5QIGG3.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-DCFSEJZG.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";export{a as PresenceStore,c as default,b as presence};
@@ -1,4 +1,4 @@
1
- import{a as ke}from"./c-XNNW2CWK.js";import{a as we}from"./c-AQLFEATB.js";import{a as xe}from"./c-2SPVQSHC.js";import{d as be}from"./c-AYVOREBE.js";import"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Qe=/^[a-z][a-z0-9+.-]*:/i,Xe=["noindex","nofollow"],Ze=["ogTitle","ogDescription","ogImage","ogImageAlt","siteName"],y=e=>e==null?"":String(e),E=e=>y(e).trim()!=="",F=e=>e.head||e.querySelector("head"),A=(e,o,t)=>Array.from(F(e).querySelectorAll("meta")).filter(i=>y(i.getAttribute(o)).trim().toLowerCase()===t),J=(e,o)=>Array.from(F(e).querySelectorAll("link")).filter(t=>y(t.getAttribute("rel")).trim().toLowerCase().split(/\s+/).includes(o)),Q=e=>Array.from(F(e).querySelectorAll("title")),Z=e=>A(e,"name","robots"),x=e=>e.remove();function j(e,o,t){let i=e.createElement("meta");return i.setAttribute(o,t),F(e).appendChild(i),i}function et(e,o){let t=e.createElement("link");return t.setAttribute("rel",o),F(e).appendChild(t),t}function X(e,o,t,i){(A(e,o,t)[0]||j(e,o,t)).setAttribute("content",i)}function v(e,o,{trim:t=!1}={}){let i=c=>A(c,e,o);return{find:i,read(c){let l=i(c)[0];return l?y(l.getAttribute("content")):""},write(c,l){let p=i(c),u=y(l);if(!E(u)){p.forEach(x);return}(p[0]||j(c,e,o)).setAttribute("content",t?u.trim():u),p.slice(1).forEach(x)}}}var Ee=e=>y(e.getAttribute("content")).split(",").map(o=>o.trim()).filter(Boolean);function tt(e,o){let t=Z(e),i=(t[0]?Ee(t[0]):[]).filter(u=>!Xe.includes(u.toLowerCase())),c=[];o.index===!1&&c.push("noindex"),o.follow===!1&&c.push("nofollow");let l=c.concat(i);if(!l.length){t.forEach(x);return}(t[0]||j(e,"name","robots")).setAttribute("content",l.join(", ")),t.slice(1).forEach(x)}function ve(e){let o=e==="noindex"?"index":"follow",t=o==="index"?"follow":"index";return{find:Z,read(i){let c=Z(i)[0];return c?!Ee(c).some(l=>l.toLowerCase()===e):!0},write(i,c){let l={index:!0,follow:!0};l[o]=!!c,l[t]=b[t].read(i),tt(i,l)}}}var ot={find:Q,read(e){let o=Q(e)[0];return o?y(o.textContent):""},write(e,o){let t=Q(e),i=y(o);if(!E(i)){t.forEach(x);return}let c=t[0]||e.createElement("title");t.length||F(e).appendChild(c),c.textContent=i,t.slice(1).forEach(x)}},nt={find(e){let o=e.documentElement;return o&&o.hasAttribute("lang")?[o]:[]},read(e){let o=e.documentElement;return o&&o.hasAttribute("lang")?y(o.getAttribute("lang")):""},write(e,o){let t=e.documentElement;if(!t)return;let i=y(o);if(!E(i)){t.removeAttribute("lang");return}t.setAttribute("lang",i.trim())}},rt={find:e=>J(e,"canonical"),read(e){let o=J(e,"canonical")[0];return o?y(o.getAttribute("href")):""},write(e,o){let t=J(e,"canonical"),i=y(o);if(!E(i)){t.forEach(x);return}(t[0]||et(e,"canonical")).setAttribute("href",i.trim()),t.slice(1).forEach(x)}},N="clay-seo-title-mode",it={find:e=>A(e,"name",N),read(e){return A(e,"name",N).some(t=>y(t.getAttribute("content")).trim().toLowerCase()==="custom")?"custom":"derived"},write(e,o){let t=A(e,"name",N);if(y(o).trim().toLowerCase()!=="custom"){t.forEach(x);return}(t[0]||j(e,"name",N)).setAttribute("content","custom"),t.slice(1).forEach(x)}},b={title:ot,description:v("name","description"),lang:nt,canonical:rt,index:ve("noindex"),follow:ve("nofollow"),ogTitle:v("property","og:title"),ogDescription:v("property","og:description"),ogImage:v("property","og:image",{trim:!0}),ogImageAlt:v("property","og:image:alt"),siteName:v("property","og:site_name"),twitterSite:v("name","twitter:site"),titleMode:it},Ae=Object.fromEntries(Object.keys(b).map(e=>[e,{read:b[e].read,write:b[e].write}]));function Le(e){let o=e.hostname.toLowerCase();return o==="localhost"||o.endsWith(".localhost")||o==="127.0.0.1"}function ee(e){try{return new URL(e)}catch{return null}}function te(e){return e.protocol==="http:"||e.protocol==="https:"}function Se(e){let o=e.location&&e.location.href||e.URL||e.baseURI||"",t=ee(o);return!t||!te(t)||Le(t)?"":t.origin+t.pathname}function Ce(e){let o=y(e).trim();if(!o)return"";let t=ee(o);return!t||!te(t)?"Enter a full http: or https: address.":Le(t)?"A localhost address cannot be a canonical URL.":""}function at(e,o){let t=y(e).trim();if(!t)return"";if(Qe.test(t)){let i=ee(t);return!i||!te(i)?"Use an http: or https: image address.":""}if(o)try{new URL(t,o)}catch{return"Use an http: or https: image address."}return""}function Ie(e,o){let t=("canonical"in o?y(o.canonical).trim():b.canonical.read(e)).trim();return t&&!Ce(t)?t:""}function ct(e,o){let t=Ze.some(l=>l in o&&E(o[l])),i="canonical"in o&&E(o.canonical);if(!t&&!i&&!("ogImage"in o))return;if(t||i){A(e,"property","og:type").length||X(e,"property","og:type","website");let l=Ie(e,o)||Se(e);l&&X(e,"property","og:url",l)}let c="ogImage"in o?o.ogImage:b.ogImage.read(e);X(e,"name","twitter:card",E(c)?"summary_large_image":"summary")}function _(e){let o={},t={};for(let i of Object.keys(b)){let c=b[i];o[i]=c.read(e),t[i]=c.find(e).length>0}return{values:o,present:t}}function Fe(e,o){let t=o||{},i=Object.keys(b).filter(u=>u in t),c={};if(i.includes("canonical")){let u=Ce(t.canonical);u&&(c.canonical=u)}if(i.includes("ogImage")){let u=Ie(e,t)||Se(e),g=at(t.ogImage,u);g&&(c.ogImage=g)}if(Object.keys(c).length)return{normalized:[],errors:c};let l=[],p=new Set;for(let u of i){let g=b[u].find;g(e).length>1&&!p.has(g)&&(p.add(g),l.push(u))}for(let u of i)b[u].write(e,t[u]);return ct(e,t),{normalized:l,errors:{}}}var Ue="clay-seo-style",Te="reopen-seo",Oe="SEO settings",De=/^[a-z][a-z0-9+.-]*:/i,st="This site is hidden from search engines in your account settings, so this page stays hidden whatever you choose here.",lt="Uploaded images are public to anyone with the link.",dt="Paste the address of an image on the web.",ut=[{legend:"Basics",fields:[{key:"title",label:"Title",kind:"text"},{key:"description",label:"Description",kind:"textarea"},{key:"lang",label:"Language",kind:"text"},{key:"canonical",label:"Canonical URL",kind:"text"}]},{legend:"Search",fields:[{key:"index",label:"Show in search results",kind:"checkbox"},{key:"follow",label:"Let search engines follow links",kind:"checkbox"}]},{legend:"Link preview",fields:[{key:"ogTitle",label:"Preview title",kind:"text"},{key:"ogDescription",label:"Preview description",kind:"textarea"},{key:"ogImage",label:"Preview image",kind:"text"},{key:"ogImageAlt",label:"Image alt text",kind:"text"},{key:"siteName",label:"Site name",kind:"text"}]},{legend:"Social card",fields:[{key:"twitterSite",label:"Handle",kind:"text"}]}],pt=`.clay-seo {
1
+ import{b as ke}from"./c-HAWFNBYG.js";import{a as we}from"./c-AQLFEATB.js";import{a as xe}from"./c-2SPVQSHC.js";import{d as be}from"./c-VRZN56XY.js";import"./c-OW5QIGG3.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var Qe=/^[a-z][a-z0-9+.-]*:/i,Xe=["noindex","nofollow"],Ze=["ogTitle","ogDescription","ogImage","ogImageAlt","siteName"],y=e=>e==null?"":String(e),E=e=>y(e).trim()!=="",F=e=>e.head||e.querySelector("head"),A=(e,o,t)=>Array.from(F(e).querySelectorAll("meta")).filter(i=>y(i.getAttribute(o)).trim().toLowerCase()===t),J=(e,o)=>Array.from(F(e).querySelectorAll("link")).filter(t=>y(t.getAttribute("rel")).trim().toLowerCase().split(/\s+/).includes(o)),Q=e=>Array.from(F(e).querySelectorAll("title")),Z=e=>A(e,"name","robots"),x=e=>e.remove();function j(e,o,t){let i=e.createElement("meta");return i.setAttribute(o,t),F(e).appendChild(i),i}function et(e,o){let t=e.createElement("link");return t.setAttribute("rel",o),F(e).appendChild(t),t}function X(e,o,t,i){(A(e,o,t)[0]||j(e,o,t)).setAttribute("content",i)}function v(e,o,{trim:t=!1}={}){let i=c=>A(c,e,o);return{find:i,read(c){let l=i(c)[0];return l?y(l.getAttribute("content")):""},write(c,l){let p=i(c),u=y(l);if(!E(u)){p.forEach(x);return}(p[0]||j(c,e,o)).setAttribute("content",t?u.trim():u),p.slice(1).forEach(x)}}}var Ee=e=>y(e.getAttribute("content")).split(",").map(o=>o.trim()).filter(Boolean);function tt(e,o){let t=Z(e),i=(t[0]?Ee(t[0]):[]).filter(u=>!Xe.includes(u.toLowerCase())),c=[];o.index===!1&&c.push("noindex"),o.follow===!1&&c.push("nofollow");let l=c.concat(i);if(!l.length){t.forEach(x);return}(t[0]||j(e,"name","robots")).setAttribute("content",l.join(", ")),t.slice(1).forEach(x)}function ve(e){let o=e==="noindex"?"index":"follow",t=o==="index"?"follow":"index";return{find:Z,read(i){let c=Z(i)[0];return c?!Ee(c).some(l=>l.toLowerCase()===e):!0},write(i,c){let l={index:!0,follow:!0};l[o]=!!c,l[t]=b[t].read(i),tt(i,l)}}}var ot={find:Q,read(e){let o=Q(e)[0];return o?y(o.textContent):""},write(e,o){let t=Q(e),i=y(o);if(!E(i)){t.forEach(x);return}let c=t[0]||e.createElement("title");t.length||F(e).appendChild(c),c.textContent=i,t.slice(1).forEach(x)}},nt={find(e){let o=e.documentElement;return o&&o.hasAttribute("lang")?[o]:[]},read(e){let o=e.documentElement;return o&&o.hasAttribute("lang")?y(o.getAttribute("lang")):""},write(e,o){let t=e.documentElement;if(!t)return;let i=y(o);if(!E(i)){t.removeAttribute("lang");return}t.setAttribute("lang",i.trim())}},rt={find:e=>J(e,"canonical"),read(e){let o=J(e,"canonical")[0];return o?y(o.getAttribute("href")):""},write(e,o){let t=J(e,"canonical"),i=y(o);if(!E(i)){t.forEach(x);return}(t[0]||et(e,"canonical")).setAttribute("href",i.trim()),t.slice(1).forEach(x)}},N="clay-seo-title-mode",it={find:e=>A(e,"name",N),read(e){return A(e,"name",N).some(t=>y(t.getAttribute("content")).trim().toLowerCase()==="custom")?"custom":"derived"},write(e,o){let t=A(e,"name",N);if(y(o).trim().toLowerCase()!=="custom"){t.forEach(x);return}(t[0]||j(e,"name",N)).setAttribute("content","custom"),t.slice(1).forEach(x)}},b={title:ot,description:v("name","description"),lang:nt,canonical:rt,index:ve("noindex"),follow:ve("nofollow"),ogTitle:v("property","og:title"),ogDescription:v("property","og:description"),ogImage:v("property","og:image",{trim:!0}),ogImageAlt:v("property","og:image:alt"),siteName:v("property","og:site_name"),twitterSite:v("name","twitter:site"),titleMode:it},Ae=Object.fromEntries(Object.keys(b).map(e=>[e,{read:b[e].read,write:b[e].write}]));function Le(e){let o=e.hostname.toLowerCase();return o==="localhost"||o.endsWith(".localhost")||o==="127.0.0.1"}function ee(e){try{return new URL(e)}catch{return null}}function te(e){return e.protocol==="http:"||e.protocol==="https:"}function Se(e){let o=e.location&&e.location.href||e.URL||e.baseURI||"",t=ee(o);return!t||!te(t)||Le(t)?"":t.origin+t.pathname}function Ce(e){let o=y(e).trim();if(!o)return"";let t=ee(o);return!t||!te(t)?"Enter a full http: or https: address.":Le(t)?"A localhost address cannot be a canonical URL.":""}function at(e,o){let t=y(e).trim();if(!t)return"";if(Qe.test(t)){let i=ee(t);return!i||!te(i)?"Use an http: or https: image address.":""}if(o)try{new URL(t,o)}catch{return"Use an http: or https: image address."}return""}function Ie(e,o){let t=("canonical"in o?y(o.canonical).trim():b.canonical.read(e)).trim();return t&&!Ce(t)?t:""}function ct(e,o){let t=Ze.some(l=>l in o&&E(o[l])),i="canonical"in o&&E(o.canonical);if(!t&&!i&&!("ogImage"in o))return;if(t||i){A(e,"property","og:type").length||X(e,"property","og:type","website");let l=Ie(e,o)||Se(e);l&&X(e,"property","og:url",l)}let c="ogImage"in o?o.ogImage:b.ogImage.read(e);X(e,"name","twitter:card",E(c)?"summary_large_image":"summary")}function _(e){let o={},t={};for(let i of Object.keys(b)){let c=b[i];o[i]=c.read(e),t[i]=c.find(e).length>0}return{values:o,present:t}}function Fe(e,o){let t=o||{},i=Object.keys(b).filter(u=>u in t),c={};if(i.includes("canonical")){let u=Ce(t.canonical);u&&(c.canonical=u)}if(i.includes("ogImage")){let u=Ie(e,t)||Se(e),g=at(t.ogImage,u);g&&(c.ogImage=g)}if(Object.keys(c).length)return{normalized:[],errors:c};let l=[],p=new Set;for(let u of i){let g=b[u].find;g(e).length>1&&!p.has(g)&&(p.add(g),l.push(u))}for(let u of i)b[u].write(e,t[u]);return ct(e,t),{normalized:l,errors:{}}}var Ue="clay-seo-style",Te="reopen-seo",Oe="SEO settings",De=/^[a-z][a-z0-9+.-]*:/i,st="This site is hidden from search engines in your account settings, so this page stays hidden whatever you choose here.",lt="Uploaded images are public to anyone with the link.",dt="Paste the address of an image on the web.",ut=[{legend:"Basics",fields:[{key:"title",label:"Title",kind:"text"},{key:"description",label:"Description",kind:"textarea"},{key:"lang",label:"Language",kind:"text"},{key:"canonical",label:"Canonical URL",kind:"text"}]},{legend:"Search",fields:[{key:"index",label:"Show in search results",kind:"checkbox"},{key:"follow",label:"Let search engines follow links",kind:"checkbox"}]},{legend:"Link preview",fields:[{key:"ogTitle",label:"Preview title",kind:"text"},{key:"ogDescription",label:"Preview description",kind:"textarea"},{key:"ogImage",label:"Preview image",kind:"text"},{key:"ogImageAlt",label:"Image alt text",kind:"text"},{key:"siteName",label:"Site name",kind:"text"}]},{legend:"Social card",fields:[{key:"twitterSite",label:"Handle",kind:"text"}]}],pt=`.clay-seo {
2
2
  position: fixed;
3
3
  top: 0;
4
4
  right: 0;
@@ -0,0 +1 @@
1
+ import{a as Y}from"./c-XQXZAO7N.js";import{e as z}from"./c-S7LK4KUE.js";import{c as I}from"./c-VG5XIN4T.js";import{b as N,i as H,o as F}from"./c-HA6INT6J.js";import{c as D,h as A,j as T,k as x,n as S,o as L}from"./c-DCFSEJZG.js";var $=[],f=[],U=new WeakMap,E=null,R=0;function ne(){return R}function j(e){return U.get(e)||null}var b=new WeakMap,m=null;function ce(){return m}function le(e){m&&e&&(m.artifact=e)}var _=null,k=new Map;function ae(e){_=e}function se(e){return e==null?null:k.get(e)??null}function ue(e){return e&&b.get(e)||null}function ie(e){e&&(b.delete(e),k.delete(e.captureId))}function B(e){let t=o=>{if(o.hasAttribute("onbeforesave")||o.hasAttribute("onbeforesnapshot"))return!0;let n=o.localName==="template"&&o.content?o.content:o;for(let a of n.children)if(t(a))return!0;return!1};return e.nodeType===1?t(e):!1}function l(e){for(let t of e.querySelectorAll(L))t.remove()}function d(e,t){for(let o of e.querySelectorAll(`[${t}]`))if(l(e),!(o!==e&&!e.contains(o)))try{new Function(o.getAttribute(t)).call(o)}catch(n){console.error(`[${t}] handler failed:`,n)}}var O=null;function fe(e){O=e}function pe(e){return O?.(e),e}function de(e){$.push(e)}function he(e){E=e}var K="http://www.w3.org/1999/xhtml";function V(e){let t=[],o=r=>{for(let c of r.childNodes)if(c.nodeType===1){if(c.localName==="noscript"&&c.namespaceURI===K){let u=Array.from(c.childNodes);u.length&&u.every(h=>h.nodeType===3)&&t.push([c,u]);continue}o(c.localName==="template"&&c.content?c.content:c)}};if(o(e),!t.length)return"<!DOCTYPE html>"+e.outerHTML;let n=Math.random().toString(36).slice(2),a=t.map(([r,c],u)=>{let h=`\uE000clay-noscript-${n}-${u}\uE000`;return r.replaceChildren(r.ownerDocument.createTextNode(h)),[h,c.map(C=>C.data).join("")]}),s;try{s="<!DOCTYPE html>"+e.outerHTML}finally{for(let[r,c]of t)r.replaceChildren(...c)}for(let[r,c]of a)s=s.split(r).join(c);return s}function w(e,t=null){if(t&&_){let a=null;try{a=_(e)}catch{}a&&k.set(t.captureId,a)}let o=V(e);if(!E)return o;let n=m;m=t;try{return E(e,o)}catch(a){return console.error("clayjs: save renderer failed, sending the full serialization",a),o}finally{m=n}}function me(e){f.push(e)}function y(e,t=!0){let o=window.__preventOnclone;window.__preventOnclone=!0;try{return e.cloneNode(t)}finally{window.__preventOnclone=o}}function p({flushUndo:e=!0,authored:t=!0,forSave:o=!1,requestRefresh:n=!1,context:a=null}={}){e&&typeof window<"u"&&window.clay?.undo?.flush&&window.clay.undo.flush();let r=Y(document.documentElement,{capability:"snapshot",provenance:U}).root;for(let c of $)l(r),c(r,{original:j,forSave:o,requestRefresh:n});return z(r),O?.(r),l(r),a&&(a.authoredHandlers=B(r)),t&&d(r,"onbeforesnapshot"),l(r),D(r),F(r),N(r),r}function g(e,{authored:t=!0}={}){l(e),t&&d(e,"onbeforesave");for(let o of f)l(e),o(e);l(e);for(let o of e.querySelectorAll(A))o.remove();return M(e),e}function M(e){for(let t of e.querySelectorAll("[sap-error]"))t.removeAttribute("sap-error")}function W({flushUndo:e=!0,authored:t=!0}={}){return g(p({flushUndo:e,authored:t}),{authored:t})}var G=["style","class"];function v(e){I(e);for(let t of G){e.getAttribute(t)===""&&e.removeAttribute(t);for(let o of e.querySelectorAll(`[${t}=""]`))o.removeAttribute(t)}return"<!DOCTYPE html>"+e.outerHTML}function ye({flushUndo:e=!0}={}){let t=p({flushUndo:e});d(t,"onbeforesave");for(let o of t.querySelectorAll(T))o.remove();for(let o of f)l(t),o(t);return l(t),v(t)}function ve({flushUndo:e=!0}={}){let t=p({flushUndo:e});d(t,"onbeforesave");for(let o of t.querySelectorAll(S))o.remove();for(let o of f)l(t),o(t);return l(t),v(t)}function Se({flushUndo:e=!0}={}){let t=p({flushUndo:e});d(t,"onbeforesave");let o=t.querySelector(x)?y(t):null;for(let s of t.querySelectorAll(T))s.remove();for(let s of f)l(t),s(t);l(t);let n=v(t),a=n;if(o){for(let s of o.querySelectorAll(S))s.remove();for(let s of f)l(o),s(o);l(o),a=v(o)}return{forComparison:n,forDirty:a}}function Ce({emitForSync:e=!0,flushUndo:t=!0,requestRefresh:o=!1,forRequest:n=!1}={}){if(!Number.isSafeInteger(R+1))throw new Error("Save capture identity exhausted");let a=++R,s=n?{captureId:a,authoredHandlers:!1,artifact:null}:null,r=p({flushUndo:t,forSave:e,requestRefresh:o,context:s});e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:r,forSave:!0,captureId:a}})),d(r,"onbeforesave");let c=y(r),u=r.querySelector(x)?y(r):null;for(let i of f)l(r),i(r);l(r);for(let i of r.querySelectorAll(A))i.remove();M(r);let h=w(r,s);for(let i of c.querySelectorAll(T))i.remove();for(let i of f)l(c),i(c);l(c);let C=v(c),P=C;if(u){for(let i of u.querySelectorAll(S))i.remove();for(let i of f)l(u),i(u);l(u),P=v(u)}let q={forSave:h,forComparison:C,forDirty:P,captureId:a};return s&&s.artifact&&b.set(q,s.artifact),q}function Ae(){let e=p({flushUndo:!1});d(e,"onbeforesave");let t=y(e),o=new WeakMap;(function n(a,s){o.set(a,s);let r=a.children,c=s.children;for(let u=0;u<r.length;u++)n(r[u],c[u])})(t,e);for(let n of f)l(e),n(e);l(e);for(let n of e.querySelectorAll(A))n.remove();M(e);for(let n of t.querySelectorAll(S))n.remove();for(let n of f)l(t),n(t);return l(t),{saveClone:e,compareClone:t,pairMap:o}}function X({emitForSync:e=!0}={}){let t=p();return e&&document.dispatchEvent(new CustomEvent("clay:snapshot-ready",{detail:{documentElement:t}})),w(g(t))}function Te(e){let t=y(e,!1);for(let a of H)t.removeAttribute(a);let o=t.outerHTML,n=`</${t.localName}>`;return"<!DOCTYPE html>"+o.slice(0,o.length-n.length)+e.innerHTML+n}function we(){return p().querySelector("body").innerHTML}function ge({transform:e=null,flushUndo:t=!0}={}){if(!e&&t)return X({emitForSync:!1});let o=p({flushUndo:t});if(e){let n=e(o);if(n&&typeof n.then=="function")throw new TypeError("getHTML: the transform must be synchronous")}return w(g(o))}function xe(e,{prepared:t=!1}={}){let o=y(e);return V(t?o:g(o,{authored:!1}))}function Ee(){return w(W({flushUndo:!1,authored:!1}))}export{ne as a,j as b,ce as c,le as d,ae as e,se as f,ue as g,ie as h,fe as i,pe as j,de as k,he as l,me as m,p as n,W as o,ye as p,ve as q,Se as r,Ce as s,Ae as t,X as u,Te as v,we as w,ge as x,xe as y,Ee as z};
@@ -0,0 +1 @@
1
+ import{d as t}from"./c-SDAXDM2D.js";var s=r=>Number.isSafeInteger(r)&&r>0?r:0;function b({floor:r=0,required:f=0,capability:l=0,admitted:c=[]}={}){let o=s(r),e=Math.max(s(f),o),i=n=>({ok:!1,activate:!1,floor:o,required:e,minimum:n});if(t(l)<e)return i(e);let a=e>o;return a&&c.some(n=>t(n)<e)?i(e):{ok:!0,activate:a,floor:e,required:e}}export{b as a};
@@ -0,0 +1 @@
1
+ import"./c-VHNSBD2M.js";var e={Smileys:[["\u{1F600}","grinning","face smile happy"],["\u{1F603}","grinning big eyes","face smile happy"],["\u{1F604}","grinning smiling eyes","face laugh happy"],["\u{1F601}","beaming","face grin happy"],["\u{1F606}","laughing","face happy haha"],["\u{1F605}","sweat smile","face relief nervous"],["\u{1F602}","joy","face tears laugh lol"],["\u{1F642}","slight smile","face ok"],["\u{1F643}","upside down","face silly"],["\u{1F609}","wink","face flirt"],["\u{1F60A}","blush","face smile warm"],["\u{1F607}","halo","face angel innocent"],["\u{1F970}","smiling hearts","face love"],["\u{1F60D}","heart eyes","face love crush"],["\u{1F929}","star struck","face wow excited"],["\u{1F60E}","cool","face sunglasses"],["\u{1F914}","thinking","face hmm question"],["\u{1F610}","neutral","face flat"],["\u{1F634}","sleeping","face tired zzz"],["\u{1F622}","crying","face sad tear"],["\u{1F62D}","sobbing","face sad tears"],["\u{1F621}","angry","face mad red"],["\u{1F631}","scream","face fear shock"],["\u{1F92F}","exploding head","face mind blown"],["\u{1F973}","party face","celebration birthday"],["\u{1F637}","mask","face sick medical"],["\u{1F912}","thermometer","face sick ill"]],"Gestures and people":[["\u{1F44B}","wave","hand hello hi bye"],["\u{1F44B}\u{1F3FD}","wave medium skin tone","hand hello hi"],["\u{1F44D}","thumbs up","yes like approve"],["\u{1F44D}\u{1F3FF}","thumbs up dark skin tone","yes like approve"],["\u{1F44E}","thumbs down","no dislike"],["\u{1F44F}","clapping","hands applause bravo"],["\u{1F64C}","raised hands","hooray praise"],["\u{1F64F}","folded hands","please thanks pray"],["\u{1F4AA}","flexed arm","strong muscle"],["\u{1F91D}","handshake","deal agreement"],["\u{1F468}\u200D\u{1F469}\u200D\u{1F467}\u200D\u{1F466}","family","people children parents"],["\u{1F9D1}\u200D\u{1F4BB}","technologist","person laptop work code"],["\u{1F3C3}","runner","person sport hurry"],["\u{1F9D8}","lotus","person meditation yoga"]],"Animals and nature":[["\u{1F436}","dog","animal pet puppy"],["\u{1F431}","cat","animal pet kitten"],["\u{1F42D}","mouse","animal rodent"],["\u{1F430}","rabbit","animal bunny"],["\u{1F98A}","fox","animal"],["\u{1F43B}","bear","animal"],["\u{1F43C}","panda","animal"],["\u{1F428}","koala","animal"],["\u{1F42F}","tiger","animal"],["\u{1F981}","lion","animal"],["\u{1F42E}","cow","animal"],["\u{1F437}","pig","animal"],["\u{1F438}","frog","animal"],["\u{1F435}","monkey","animal"],["\u{1F414}","chicken","animal bird"],["\u{1F427}","penguin","animal bird"],["\u{1F426}","bird","animal"],["\u{1F984}","unicorn","animal magic"],["\u{1F41D}","bee","animal insect honey"],["\u{1F98B}","butterfly","animal insect"],["\u{1F338}","cherry blossom","flower plant spring"],["\u{1F33B}","sunflower","flower plant summer"],["\u{1F308}","rainbow","weather sky"],["\u{1F332}","evergreen tree","plant forest"],["\u{1F335}","cactus","plant desert"],["\u{1F341}","maple leaf","plant autumn"]],"Food and drink":[["\u2615","coffee","drink cup hot"],["\u{1F375}","tea","drink cup green"],["\u{1F37A}","beer","drink mug"],["\u{1F377}","wine","drink glass"],["\u{1F34E}","apple","fruit food red"],["\u{1F34C}","banana","fruit food"],["\u{1F347}","grapes","fruit food"],["\u{1F353}","strawberry","fruit food"],["\u{1F351}","peach","fruit food"],["\u{1F355}","pizza","food slice"],["\u{1F354}","burger","food"],["\u{1F35F}","fries","food"],["\u{1F32E}","taco","food"],["\u{1F363}","sushi","food fish"],["\u{1F35C}","noodles","food ramen"],["\u{1F370}","cake","food dessert"],["\u{1F36A}","cookie","food sweet"],["\u{1F36B}","chocolate","food sweet"],["\u{1F951}","avocado","food fruit"],["\u{1F955}","carrot","food vegetable"],["\u{1F35E}","bread","food loaf"]],"Travel and places":[["\u2708\uFE0F","airplane","travel flight"],["\u{1F697}","car","travel drive"],["\u{1F6B2}","bicycle","travel bike"],["\u{1F682}","train","travel locomotive"],["\u{1F680}","rocket","travel launch space"],["\u26F5","sailboat","travel boat"],["\u{1F3E0}","house","place home"],["\u{1F3E2}","office","place building work"],["\u{1F5FD}","statue of liberty","place new york"],["\u{1F5FC}","tower","place tokyo"],["\u{1F3D4}","mountain","place snow"],["\u{1F3D6}","beach","place holiday sea"],["\u{1F30D}","globe","world earth"],["\u{1F5FA}","map","place world"],["\u{1F6A6}","traffic light","place street"]],Objects:[["\u{1F4A1}","bulb","idea light"],["\u{1F525}","fire","hot flame"],["\u2B50","star","favourite rating"],["\u{1F4AF}","hundred","score perfect"],["\u2705","check","done yes"],["\u274C","cross","no wrong"],["\u26A0\uFE0F","warning","caution alert"],["\u{1F4CC}","pushpin","pin note"],["\u{1F4CE}","paperclip","attach"],["\u{1F4C5}","calendar","date schedule"],["\u{1F4C8}","chart up","graph growth"],["\u{1F4C9}","chart down","graph loss"],["\u{1F4B0}","money bag","cash"],["\u{1F511}","key","access"],["\u{1F512}","lock","secure private"],["\u{1F514}","bell","notify alert"],["\u{1F389}","party popper","celebrate"],["\u{1F381}","gift","present"],["\u{1F3C6}","trophy","win award"],["\u{1F3AF}","target","goal aim"],["\u23F0","alarm clock","time"],["\u231B","hourglass","time wait"]],Symbols:[["\u2764\uFE0F","red heart","love"],["\u{1F494}","broken heart","love sad"],["\u2728","sparkles","magic new"],["1\uFE0F\u20E3","keycap one","number"],["2\uFE0F\u20E3","keycap two","number"],["#\uFE0F\u20E3","keycap hash","number channel"],["\u{1F1EB}\u{1F1F7}","flag france","country"],["\u{1F1FA}\u{1F1F8}","flag united states","country"],["\u{1F1EF}\u{1F1F5}","flag japan","country"],["\u267B\uFE0F","recycle","reuse"],["\u27A1\uFE0F","arrow right","direction next"],["\u2B05\uFE0F","arrow left","direction back"],["\u{1F501}","repeat","loop again"],["\u{1F500}","shuffle","random"],["\u{1F197}","ok button","yes"]]};export{e as EMOJI};
@@ -0,0 +1 @@
1
+ import{a as wt}from"./c-GQ6F6IDK.js";import{c as _}from"./c-2SPVQSHC.js";import{b as Ne}from"./c-5VYOWDTI.js";import{a as Mt,d as J,e as Ie,f as B,h as D}from"./c-QJ4OM3G6.js";import{a as Re,b as _t}from"./c-MKSQ4Y57.js";import{a as Dt}from"./c-UGHH4MB3.js";import{a as St}from"./c-ZWIOJGMT.js";import{a as Tt,e as xt,f as T,j as Ct,r as Le,t as Pt}from"./c-LWLBHLVC.js";import{a as Oe,c as At,g as Et,h as ke}from"./c-DCXOXBF3.js";import{a as Pe,f as Me,h as z}from"./c-IJUK2GPW.js";import{b as q,e as h}from"./c-OW5QIGG3.js";import{i as mt,k as vt}from"./c-N7JPUPGC.js";import{h as fe,m as De,o as yt,q as F,r as le,s as _e}from"./c-SPIORRYS.js";import{d as ht}from"./c-VG5XIN4T.js";import{a as ue}from"./c-2YYDMLNZ.js";import{d as lt,e as ct,g as dt,h as pt}from"./c-HA6INT6J.js";import{k as gt}from"./c-DCFSEJZG.js";var Yt="clay:debug:autosave";function ce(){try{return localStorage.getItem(Yt)==="true"}catch{return!1}}function de(){return import("./c-CFHW5AMY.js").catch(e=>(console.warn("[autosave-debug] Failed to load the debug logger:",e),null))}function pe(e,t){ce()&&de().then(n=>n?.logSaveCheck(e,t))}function Z(e,t=""){ce()&&de().then(n=>n?.logBaseline(e,t))}function Ot(e,t){ce()&&de().then(n=>n?.logUnloadDiffSync(e,t))}function kt(){ce()&&de().then(e=>e?.preloadIfEnabled())}var O=Number.NEGATIVE_INFINITY;function jt({firstDirtyAt:e=O,lastActivityAt:t=O,finishedAt:n=O,costMs:o=0}={}){let r=e??O,u=t??O,a=n??O,s=Math.min(3e4,Math.max(1200,4*o)),f=Math.max(u,a)+1500,m=Math.max(r+1e4,a+s);return Math.max(a+1200,Math.min(f,m))}function Lt({now:e=()=>Date.now(),setTimer:t=(r,u)=>setTimeout(r,u),clearTimer:n=r=>clearTimeout(r),run:o=()=>{}}={}){let r=null,u=null,a=O,s=0,f=null,m=null,l=!1,d=!1;function g(){return jt({firstDirtyAt:r,lastActivityAt:u,finishedAt:a,costMs:s})}function c(){if(!l||d)return;let p=g();if(f!==null){if(m===p)return;n(f)}m=p,f=t(y,Math.max(0,p-e()))}function y(){if(f=null,m=null,!(!l||d)){if(e()<g()){c();return}j()}}function j(){l=!1,d=!0,r=null,u=null;let p;try{p=o()}catch{U();return}Promise.resolve(p).then(U,U)}function U(){d=!1,a=e(),l&&c()}function b({at:p=e()}={}){r===null&&(r=p),u=p,l=!0,c()}function i(){l=!0,c()}function S(p){p>0&&(s=Math.max(p,s*.8))}return{noteActivity:b,request:i,noteCost:S,dueAt:g,costEstimate:()=>s,pending:()=>l||d,running:()=>d}}De(e=>{for(let t of pt)e.removeAttribute(t)});De(e=>{for(let t of[...lt,...ct,...dt])e.removeAttribute(t)});var E=null;function w(e,t="",n="",o=null){E&&(clearTimeout(E),E=null),document.documentElement.setAttribute("savestatus",e);let r=new CustomEvent(`clay:save-${e}`,{detail:{msg:t,msgType:n,timestamp:Date.now(),...o||{}}});document.dispatchEvent(r)}function ze(){E&&(clearTimeout(E),E=null),document.documentElement.setAttribute("savestatus","offline")}function bt(){E=setTimeout(()=>{w("saving")},500)}window.addEventListener("offline",()=>{ze()});window.addEventListener("online",()=>{document.documentElement.getAttribute("savestatus")==="offline"&&M().then(e=>{e.msgType==="skipped"&&document.documentElement.getAttribute("savestatus")==="offline"&&document.documentElement.setAttribute("savestatus","saved")})});var k=!1,C="",A="",Fe=0,$=new Set,L=!1,G=!1,K=!1,I=0,Be=!1;function zt(){I++}function qt(){I!==0&&(I--,!(I>0)&&(oe&&(oe=!1,Q=setTimeout(it,0)),Be&&(Be=!1,xe())))}function Jt(){return I>0}var H=0,se=!1,he=!1,Se=!1;function Ee(e=null){return H===0||un(e)}function Je(){return se}function Zt(){if(se)return!0;try{let e=F({flushUndo:!1});return ft(e)?!1:e!==A}catch{return!0}}function en(){let e="idle",t=0;return{get phase(){return e},get open(){return e==="open"},changedWhileClosed(){return e==="quiesced"&&Ie()!==t},start(){e==="idle"&&(e="open")},quiesce(){e==="open"&&(e="quiesced",t=Ie(),H++)},resume(){e==="quiesced"&&(e="open",H--,!(H>0)&&(hn(),Rt()))},stop(){if(e==="stopped")return;let n=e==="quiesced";(n||e==="open")&&Zt()&&(Se=!0),e="stopped",n&&(H--,H===0&&Rt())}}}var It=!1,te=null,He=null,Ge=!1;function sr(e=Y){if(!te||te.generation!==e)return null;let{bytes:t,etag:n}=te;return{bytes:t,etag:n}}function ar({represented:e}={}){let t=B(),{forComparison:n,forDirty:o}=le(),r=typeof e?.etag=="string"&&e.etag?e.etag:null;return!(Ge&&r!==null&&r!==He)&&Se&&(n!==C||o!==A)?{ok:!1,code:"pending-input"}:(Se=!1,re(n,o),R=n,V=!1,st=!0,He=r,Ge=!0,D(t),document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:baseline-settled")),{ok:!0})}var Ze=Promise.resolve(!1),ye=!1,tn=()=>(ye=!0,Et().catch(()=>!1).then(e=>(ye=!1,e)));function ur(){return{id:"clay:save",order:10,prepare(e={}){let t=en();return e.initial===!0&&t.start(),{enable(){Ze=tn();let n=e.represented?.etag;typeof n=="string"&&n&&At(n),e.initial!==!0&&(nn(),t.start())},quiesce:()=>t.quiesce(),resume:()=>t.resume(),dispose:()=>t.stop()}}}}function nn(){It||(It=!0,Mt(),Pe(),Vt(),$t())}var P=0,Ke=!1,we=!1,et="Waiting for the AI edit to be kept or reverted",W=new Map;function fr(e=et){P++,W.set(e,(W.get(e)||0)+1)}function lr({replay:e=!0,reason:t=et}={}){let n=W.get(t)||0;if(n===0||(n===1?W.delete(t):W.set(t,n-1),P--,P>0))return;let o=Ke,r=we;Ke=!1,we=!1,e&&(o?M():r&&xe())}function cr(){return P>0}function tt(){return P===0?null:W.keys().next().value||et}function Ft(e,t){if(P===0)return!1;Ke=!0,z();let n=v(tt());return e(n),t(n),!0}var N=!1,ne=null;function rn(e){ne=e??null,!N&&(N=!0,zt())}function on(){N&&(N=!1,ne=null,qt())}function We(){return N}function dr(e){if(!N||ne&&e!==ne)return;N=!1,ne=null,!Ne()&&J()||(document.documentElement.getAttribute("savestatus")==="conflict"&&document.documentElement.setAttribute("savestatus","saved"),document.dispatchEvent(new CustomEvent("clay:save-conflict-resolved",{detail:{timestamp:Date.now()}}))),document.dispatchEvent(new CustomEvent("clay:save-conflict-released",{detail:{etag:e??null}})),qt()}function v(e){return{ok:!1,msg:e,msgType:"skipped",code:null,etag:null}}function nt(e){return(J()||_())&&(se=!0),v(e)}var rt=new Set,Y=0;function pr(){return Y}function mr(e){typeof e=="number"&&(Y=e)}function sn(e=Y){let t=Object.freeze({generation:e});return rt.add(t),t}function an(e){rt.delete(e)}function un(e){return!!e&&rt.has(e)&&e.generation===Y}function ge(e,t){e!=null&&_t({captureId:e,ok:t.ok===!0,etag:t.etag??null})}function Bt(e,t,n,o,r,u=null,a=null,s=!1){if(ge(a,e),e.ok)se=!1,re(t,n),Gt=u,te={bytes:u,etag:Oe(),generation:Y},He=te.etag,Ge=!0,Se=!1,k=!1,D(r),w("saved",e.msg||"Saved",e.msgType,{etag:e.etag??null,captureId:a}),Z(o,`${C.length} chars`),on();else if(e.msgType==="conflict"){if(s){E&&(clearTimeout(E),E=null),document.documentElement.setAttribute("savestatus","saved");return}rn(e.conflictEtag),w("conflict",e.msg,e.msgType,{hadTimeout:e.hadTimeout===!0,changedBy:e.changedBy??null,afterTimeout:e.afterTimeout===!0,etag:e.conflictEtag??null,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a})}else if(e.msgType!=="skipped"){let f={status:e.status??null,hadTimeout:e.hadTimeout===!0,code:e.code??null,reason:e.reason??null,retryAfter:e.retryAfter??null,captureId:a};navigator.onLine?w("error",e.msg,"",f):w("offline",e.msg,"",f)}}function Ht(){if(!(!L&&!G)&&!Ct()){if(L){L=!1,G=!1,M();return}G=!1,Ye.request()}}function vr(){return k}function gr(e){k=e}function hr(){return C}function ot(){return A}var Gt=null;function Sr(){return Gt}function re(e,t){C=e,A=t,Fe++}function yr(e){re(e,e)}var ee=()=>typeof performance<"u"&&performance.now?performance.now():Date.now();function Te(e,t=()=>{}){return ye?Ze.then(()=>Te(e,t)):X?ie.then(()=>Qe(e,t)):Qe(e,t)}function Qe({kind:e,permit:t=null},n=()=>{}){let o=e==="explicit";return new Promise(r=>{if(!h&&!window.clay?.testMode){o&&z();let i=v("Not in edit mode");return n(i),r(i)}if(!Ee(t)){o||(he=!0);let i=nt("Save session is quiesced");return n(i),r(i)}if(o){if(Ft(n,r))return;if(T()){L=!0;let i=v("Save already in progress");return n(i),r(i)}}else{if(P>0){we=!0;let i=v(tt());return n(i),r(i)}if(T()&&!V&&K){G=!0;let i=v("Save already in progress");return n(i),r(i)}if(!V&&!J()){let i=v("No changes to save");return n(i),r(i)}}let u=window.clay?.source?.ensureForSave?.();if(u)return u.then(()=>r(Qe({kind:e,permit:t},n)));let a=o?gn():[],s=i=>a.forEach(S=>S(i));!navigator.onLine&&ze();let m=ee(),l,d,g,c,y,j=B();try{l=_e({requestRefresh:!0,forRequest:!0}),{forSave:d,forComparison:g,forDirty:c,captureId:y}=l}catch(i){console.error(`${o?"savePage":"savePageThrottled"}: captureForSaveAndComparison failed`,i),o?(z(),w("error",i.message,"",{sent:!1,code:i.code??null})):w("error",i.message);let S={msg:i.message,msgType:"error",code:o?i.code??null:null,etag:null};typeof n=="function"&&n(S),r(S),s(S);return}let U=ee()-m;if(Re({captureId:y,html:d}),o){if(k=c!==A,pe("savePage dirty check",!k),!k){z(),D(j),fe(l);let i=v("No changes to save");ge(y,i),n(i),r(i),s(i);return}}else{let i=!V||g!==R,S=g!==C;if(pe("throttled vs baseline",!i),pe("throttled vs lastSave",!S),!(i&&S)){let p=!1;try{p=!S&&(!document.querySelector(gt)||J()&&c===A)}catch(Xt){console.error("savePageThrottled: dirty domain check failed",Xt)}p&&D(j),Ye.noteCost(U),fe(l);let ae=v("No changes to save");ge(y,ae),n(ae),r(ae);return}if(k=!0,T()){L=!0,fe(l);let p=v("Save already in progress");ge(y,p),n(p),r(p);return}}bt();let b={forComparison:g,forDirty:c};$.add(b),K=!0,Le(d,y,i=>{K=!1,$.delete(b);let S=ee();Bt(i,b.forComparison,b.forDirty,"updated after save",j,d,y),o||Ye.noteCost(U+(ee()-S)),typeof n=="function"&&n(i),r(i),s(i),Ht()},{capture:l})})}function M(e=()=>{}){return Te({kind:"explicit"},e)}function fn(e,t=()=>{}){return Te({kind:"explicit",permit:e},t)}function Ae(e=()=>{},{quietConflict:t=!1,pageFormatFloor:n=0}={}){return ye?Ze.then(()=>Ae(e,{quietConflict:t,pageFormatFloor:n})):new Promise(o=>{if(!h&&!window.clay?.testMode){let c=v("Not in edit mode");return e(c),o(c)}if(!Ee()){let c=nt("Save session is quiesced");return e(c),o(c)}if(Ft(e,o))return;if(T()){L=!0;let c=v("Save already in progress");return e(c),o(c)}let r=window.clay?.source?.ensureForSave?.();if(r)return r.then(()=>o(Ae(e,{quietConflict:t,pageFormatFloor:n})));!navigator.onLine&&ze();let a,s,f,m,l,d=B();try{a=_e({requestRefresh:!0,forRequest:!0}),{forSave:s,forComparison:f,forDirty:m,captureId:l}=a}catch(c){console.error("savePageForce: captureForSaveAndComparison failed",c),w("error",c.message,"",{sent:!1,code:c.code??null});let y={msg:c.message,msgType:"error",code:c.code??null,etag:null};return typeof e=="function"&&e(y),o(y)}Re({captureId:l,html:s}),bt();let g={forComparison:f,forDirty:m};$.add(g),K=!0,Le(s,l,c=>{K=!1,$.delete(g),Bt(c,g.forComparison,g.forDirty,"updated after force save",d,s,l,t),typeof e=="function"&&e(c),o(c),Ht()},{capture:a,pageFormatFloor:n})})}function ln(e){let t=["clay:save-saved","clay:save-error","clay:save-offline","clay:save-conflict"];return new Promise((n,o)=>{let r=null,u=()=>{clearTimeout(r);for(let f of t)document.removeEventListener(f,a)},a=()=>{u(),n()},s=e-Date.now();if(s<=0){o(Object.assign(new Error("Save timed out."),{state:"failed"}));return}r=setTimeout(()=>{u(),o(Object.assign(new Error("Save timed out."),{state:"failed"}))},s);for(let f of t)document.addEventListener(f,a)})}function x(e,t){return Object.assign(new Error(e),{state:t})}function cn(e,t){return new Promise((n,o)=>{let r=t-Date.now();if(r<=0)return o(x("Save timed out.","failed"));let u=setTimeout(()=>{document.removeEventListener(e,a),o(x("Save timed out.","failed"))},r),a=()=>{clearTimeout(u),n()};document.addEventListener(e,a,{once:!0})})}async function wr({keepalive:e=!1,timeoutMs:t=15e3,permit:n=null}={}){if(!h)return{state:"view",etag:null};let o=Date.now()+t,r=n||sn(),u=null,a=new Promise((s,f)=>{u=setTimeout(()=>f(x("Save timed out.","failed")),Math.max(0,t))});try{return await Promise.race([dn(e,o,r),a])}catch(s){throw s&&typeof s.state=="string"?s:x(s?.message||"Save failed","failed")}finally{clearTimeout(u),n||an(r)}}async function dn(e,t,n){Kt()||await cn("clay:baseline-settled",t);let o=!1,r=null;for(let u=0;u<4;u++){if(T()&&await ln(t),We())throw x("This document has a conflict to resolve.","conflict");let a=B();if(!je()){if(D(a),_())throw x("This document has unsaved work a save cannot write.","blocked");return{state:o?"saved":"clean",etag:r??Oe()}}let s=await xt(e,()=>fn(n));if(s.msgType!=="skipped"){if(!s.ok)throw x(s.msg||"Save failed",s.msgType==="conflict"||We()?"conflict":"failed");o=!0,r=s.etag??null}}throw x("The document kept changing while saving.","failed")}async function Ar(e=()=>{}){return await ke({fresh:!0}),Ae(e)}function Er(e){!h||q||Pt(e,t=>{t.ok?window.location.reload():t.msgType==="skipped"?w("error",t.msg||"Template not saved"):w("error",t.msg||"Failed to save template")})}var pn=wt(e=>Te({kind:"automatic"},e),1200),mn=250,vn=1e3,Q=null,Nt=0,Ve=[],$e=[],oe=!1,gn=()=>{let e=$e;return $e=[],e};function it(){if(Q=null,I>0||!Ee()){oe=!0;return}let e=Ve;if(Ve=[],T()){$e.push(...e),M();return}M().then(t=>e.forEach(n=>n(t)))}function Tr(){let e=Date.now();return Q===null?Nt=e:clearTimeout(Q),new Promise(t=>{Ve.push(t),Q=setTimeout(it,Math.max(0,Math.min(mn,Nt+vn-e)))})}function hn(){he&&(he=!1,xe())}function Rt(){oe&&(oe=!1,Q=setTimeout(it,0))}var R="",V=!0,st=!1;function Kt(){return st}var Ue=!1,Sn=250,yn=1250,be=null,Wt="clay:paint-heal:"+location.pathname;function Qt(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t+e.charCodeAt(n)|0;return String(t>>>0)}function wn(e){try{return localStorage.getItem(Wt)===Qt(e)}catch{return!1}}function An(e){try{localStorage.setItem(Wt,Qt(e))}catch{}}function En(){return ht(yt({flushUndo:!1}))}function xr(e){!h||q||(clearTimeout(be),be=setTimeout(async()=>{be=null,X&&await ie;let t=typeof e=="function"?e():e;t==null||!Ne()||!Kt()||We()||Jt()||F({flushUndo:!1})===A&&t!==En()&&(wn(t)||(An(t),Ae(()=>{},{quietConflict:!0})))},Sn+Math.random()*yn))}var me=null,qe=null,X=0,ie=Promise.resolve(),at=!1,ut=[];function Tn(){return qe??=import("./c-CZUSOB7V.js").catch(e=>(qe=null,console.error("style-comparisons failed to load",e),null)),qe}async function xn(e){try{if(me||(me=(await Tn())?.styleComparisonStripper??null),!me)return;let t=me(e);C=t(C),A=t(A),R=t(R);for(let n of $)n.forComparison=t(n.forComparison),n.forDirty=t(n.forDirty)}catch(t){console.error("style adoption failed",t)}finally{X--,ut.shift()}}var ve=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;");function Cn(e){if(e.name!==void 0){let n=[`data-name="${ve(e.name)}"`];return e.legacyId!==void 0&&n.push(`id="${ve(e.legacyId)}"`),n}let t=[ve(e.href)];try{let{pathname:n}=new URL(e.href);n&&t.push(ve(n))}catch{}return t}function Pn(e){let t=[C,A,R];for(let n of $)t.push(n.forComparison,n.forDirty);return t.some(n=>n&&e.some(o=>o&&n.includes(o)))}function Mn(e,t){let n=[];for(let{markers:u,tag:a}of t)for(let s of u)for(let f=e.indexOf(s);f>=0;f=e.indexOf(s,f+s.length)){let m=e.lastIndexOf("<",f);if(m<0||e.slice(m+1,m+1+a.length).toLowerCase()!==a)continue;let l=a==="style"?e.indexOf("</style",f):f;if(l<0)continue;let d=e.indexOf(">",l);d>=0&&n.push([m,d+1])}n.sort((u,a)=>u[0]-a[0]);let o="",r=0;for(let[u,a]of n)u<r||(o+=e.slice(r,u),r=a);return o+e.slice(r)}Dt(e=>{let t=Cn(e);Pn(t)&&(X||(at=!1),X++,ut.push({markers:t,tag:e.name!==void 0?"style":"link"}),ie=ie.then(()=>xn(e)))});function Cr(){return ie}function ft(e){return!X||at||_()||T()||L||G||se||typeof e!="string"?!1:e===Mn(A,ut)}var Dn=500,_n=3e3,On=1e4,Xe=null;function kn(){ue.holdSettle=!1,Xe&&Xe()}function Ut(){if(!h)return;let e=!1,t=null,{forComparison:n,forDirty:o}=le();re(n,o);let r=Fe;R=n,Z("immediate capture",`${n.length} chars`);let u=["keydown","pointerdown","drop","input","change","paste"],a=new Set(["Shift","Control","Alt","Meta"]),s=l=>{l.type==="keydown"&&a.has(l.key)||(at=!0,e||(Ue=!0))};u.forEach(l=>document.addEventListener(l,s,!0));let f=()=>{if(!e){if(e=!0,t&&t(),!Ue&&Fe===r){let l=B(),{forComparison:d,forDirty:g}=le();re(d,g),R=d,D(l),Z("settled capture",`${d.length} chars`)}else Z("settled skipped",Ue?"user edited":"save occurred during settle");V=!1,document.documentElement.setAttribute("savestatus","saved"),st=!0,document.dispatchEvent(new CustomEvent("clay:baseline-settled"))}};Xe=f;let m=()=>{ue.holdSettle||f()};t=St.onAnyChange({debounce:Dn,omitChangeDetails:!0,require:"autosave"},m),setTimeout(()=>{e||m()},_n),setTimeout(()=>{!e&&ue.holdSettle&&kn()},On)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Ut):Ut();function xe(e=()=>{}){if(!h){let t=v("Not in edit mode");return e(t),Promise.resolve(t)}if(P>0){we=!0;let t=v(tt());return e(t),Promise.resolve(t)}if(!Ee()){he=!0;let t=nt("Save session is quiesced");return e(t),Promise.resolve(t)}if(I>0){Be=!0;let t=v("Autosave suspended");return e(t),Promise.resolve(t)}if(!V&&K){G=!0;let t=v("Save already in progress");return e(t),Promise.resolve(t)}return pn(e).catch(t=>{let n={ok:!1,msg:t?.message||"Save failed",msgType:"error",code:null,etag:null};return w("error",n.msg),n})}var Ye=Lt({now:ee,run:()=>xe()});function Vt(){document.addEventListener("keydown",function(e){if((window.navigator.platform.match("Mac")?e.metaKey:e.ctrlKey)&&e.keyCode==83){if(!h)return;e.preventDefault(),e.isTrusted&&Me(),M()}})}function $t(){document.addEventListener("click",e=>{e.target.closest("[trigger-save]")&&(e.isTrusted&&Me(),M())})}function Ln(){h&&(ke(),Tt(),Pe(),Vt(),$t())}Ln();var Pr=M;var Ce=!1;function Nr({isCurrent:e,reload:t}){return e()?(Ce=!0,setTimeout(()=>{Ce=!1},1e3),t(),!0):!1}kt();function In(){return Je()?!0:h?_()?!0:q?vt():window.clay?.demo?!1:je():!1}function je(){if(!h)return!1;try{let e=F();return ft(e)?!1:e!==ot()}catch{return!0}}window.addEventListener("beforeunload",e=>{if(!h&&!Je())return;if(Ce){Ce=!1;return}if(!((!q||mt())&&!In())&&(e.preventDefault(),e.returnValue="",!window.clay?.demo&&!_()))try{let n=F(),o=ot();n!==o&&Ot(n,o)}catch{}});export{Nr as a,In as b,je as c,zt as d,qt as e,Jt as f,Ee as g,Je as h,en as i,sr as j,ar as k,ur as l,fr as m,lr as n,cr as o,tt as p,We as q,dr as r,pr as s,mr as t,sn as u,an as v,vr as w,gr as x,hr as y,ot as z,Sr as A,re as B,yr as C,M as D,Ae as E,wr as F,Ar as G,Er as H,Tr as I,Kt as J,En as K,xr as L,Cr as M,ft as N,kn as O,xe as P,Ye as Q,Vt as R,$t as S,Ln as T,Pr as U};
@@ -1,4 +1,4 @@
1
- import{a as h,b as u,c as w,d as g}from"./c-BTDI4Y23.js";import{f as y}from"./c-7O6AFR65.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var l={draft:"You're seeing a private draft, like a visitor.",draftAction:"Edit the original",edit:"You're editing the original. Visitors get these changes.",editAction:"Back to my draft",close:"Hide this note"},E=`.clay-owner {
1
+ import{a as h,b as u,c as w,d as g}from"./c-BTDI4Y23.js";import{b as y}from"./c-OW5QIGG3.js";import"./c-BPF2NSPV.js";import"./c-P7KNDG34.js";import"./c-CYWLPPUS.js";import"./c-N7JPUPGC.js";import"./c-HA6INT6J.js";import"./c-WRBKEJD4.js";import"./c-VHNSBD2M.js";var l={draft:"You're seeing a private draft, like a visitor.",draftAction:"Edit the original",edit:"You're editing the original. Visitors get these changes.",editAction:"Back to my draft",close:"Hide this note"},E=`.clay-owner {
2
2
  --hcp-ground: #FDF8F0;
3
3
  --hcp-surface: #FFFCF6;
4
4
  --hcp-sunk: #F4ECDF;