@heycys/gallery 0.1.2 → 0.2.1

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 (338) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/browser/editor/components/align.mjs +58 -0
  3. package/browser/editor/components/code/index.mjs +1 -1
  4. package/browser/editor/components/embed/page.mjs +1 -1
  5. package/browser/editor/components/file/page.mjs +4 -4
  6. package/browser/editor/components/heading/index.mjs +7 -6
  7. package/browser/editor/components/icon/page.mjs +6 -4
  8. package/browser/editor/components/icons.mjs +5 -2
  9. package/browser/editor/components/image/index.mjs +2 -0
  10. package/browser/editor/components/image/page.mjs +172 -90
  11. package/browser/editor/components/installed/index.mjs +6 -2
  12. package/browser/editor/components/installed/page.mjs +80 -13
  13. package/browser/editor/components/media/icons.mjs +13 -8
  14. package/browser/editor/components/media/page.mjs +5 -3
  15. package/browser/editor/components/media/toolbar.mjs +12 -3
  16. package/browser/editor/components/paragraph/index.mjs +4 -3
  17. package/browser/editor/components/registry.mjs +17 -5
  18. package/browser/editor/components/table/index.mjs +4 -2
  19. package/browser/editor/page/after/index.mjs +288 -0
  20. package/browser/editor/page/align.mjs +91 -0
  21. package/browser/editor/page/beside.mjs +5 -6
  22. package/browser/editor/page/block-menu/index.mjs +6 -3
  23. package/browser/editor/page/blocks.mjs +3 -1
  24. package/browser/editor/page/board/hint.mjs +64 -27
  25. package/browser/editor/page/board/index.mjs +160 -71
  26. package/browser/editor/page/board/motion.mjs +177 -0
  27. package/browser/editor/page/board/settings.mjs +4 -3
  28. package/browser/editor/page/clipboard/import/read.mjs +20 -2
  29. package/browser/editor/page/clipboard/index.mjs +10 -3
  30. package/browser/editor/page/clipboard/own/blocks.mjs +3 -4
  31. package/browser/editor/page/clipboard/own/describe.mjs +6 -2
  32. package/browser/editor/page/commit.mjs +2 -2
  33. package/browser/editor/page/core.mjs +3 -1
  34. package/browser/editor/page/custom-page.mjs +15 -11
  35. package/browser/editor/page/editor.mjs +31 -14
  36. package/browser/editor/page/history.mjs +19 -4
  37. package/browser/editor/page/insert/index.mjs +20 -22
  38. package/browser/editor/page/menu.mjs +15 -7
  39. package/browser/editor/page/page-objects.mjs +3 -7
  40. package/browser/editor/page/present-links.mjs +5 -4
  41. package/browser/editor/page/present-shell.mjs +63 -0
  42. package/browser/editor/page/selection/index.mjs +10 -2
  43. package/browser/editor/page/table/binding.mjs +87 -0
  44. package/browser/editor/page/table/icons.mjs +0 -2
  45. package/browser/editor/page/table/index.mjs +10 -14
  46. package/browser/editor/page/table/views.mjs +5 -52
  47. package/browser/editor/page/table/widths.mjs +82 -10
  48. package/browser/editor/page/typing/index.mjs +44 -12
  49. package/browser/editor/page/typing/leave.mjs +19 -5
  50. package/browser/shared/block-packs.mjs +23 -8
  51. package/browser/shared/component-catalog.mjs +15 -8
  52. package/browser/shared/component-source.mjs +3 -1
  53. package/browser/shared/components/heading.mjs +2 -1
  54. package/browser/shared/components/installed.mjs +1 -1
  55. package/browser/shared/components/page.mjs +2 -0
  56. package/browser/shared/components/paragraph.mjs +8 -1
  57. package/browser/shared/components/table.mjs +1 -0
  58. package/browser/shared/document-copy.mjs +43 -0
  59. package/browser/shared/drafts.mjs +10 -3
  60. package/browser/shared/emoji/icon-value.mjs +2 -2
  61. package/browser/shared/emoji/line-icons.mjs +37 -0
  62. package/browser/shared/extensions.mjs +83 -7
  63. package/browser/shared/http.mjs +9 -0
  64. package/browser/shared/i18n/en.mjs +50 -17
  65. package/browser/shared/outline-shape.mjs +6 -0
  66. package/browser/shared/outline.mjs +165 -12
  67. package/browser/shared/pack-manifest.mjs +12 -1
  68. package/browser/shared/pages.mjs +169 -57
  69. package/browser/shared/pinyin.mjs +92 -0
  70. package/browser/shared/present-step.mjs +17 -0
  71. package/browser/shared/sidebar-head.mjs +70 -0
  72. package/browser/shared/web-links.mjs +5 -0
  73. package/browser/shared/workspace-columns.mjs +11 -7
  74. package/dist/{chunk-N7AZZLGT.mjs → chunk-2GKGEVMR.mjs} +29 -24
  75. package/dist/chunk-2OHANJ6Q.mjs +2 -0
  76. package/dist/{chunk-HYMEEXKN.mjs → chunk-2RKIHJI2.mjs} +1 -1
  77. package/dist/{chunk-742D2WWJ.mjs → chunk-36FIRJIF.mjs} +2 -2
  78. package/dist/{chunk-BPL64HGA.mjs → chunk-3A5I2GJK.mjs} +1 -1
  79. package/dist/{chunk-RFDZXFJF.mjs → chunk-3OFXMN6N.mjs} +1 -1
  80. package/dist/chunk-46ACXOU5.mjs +2 -0
  81. package/dist/{chunk-PUOQ65NC.mjs → chunk-4AMTKWDO.mjs} +1 -1
  82. package/dist/{chunk-VTKNEYT3.mjs → chunk-4DNHHJSL.mjs} +1 -1
  83. package/dist/chunk-5DPABPBI.mjs +2 -0
  84. package/dist/chunk-5IIH335D.mjs +3 -0
  85. package/dist/chunk-5L26JUYA.mjs +2 -0
  86. package/dist/{chunk-3NJACR4W.mjs → chunk-5MEXZ2UF.mjs} +1 -1
  87. package/dist/{chunk-ZHEHPMBK.mjs → chunk-6MPKCH3P.mjs} +1 -1
  88. package/dist/{chunk-C564NU2H.mjs → chunk-74RPP2M2.mjs} +1 -1
  89. package/dist/chunk-7M2BQQGZ.mjs +2 -0
  90. package/dist/{chunk-VXACTLO3.mjs → chunk-7M7UPWU6.mjs} +1 -1
  91. package/dist/{chunk-ZB4H7ZN4.mjs → chunk-7N2LPG33.mjs} +1 -1
  92. package/dist/{chunk-UBBRTJ2R.mjs → chunk-7XDYK3UC.mjs} +1 -1
  93. package/dist/chunk-AEMVZYZQ.mjs +166 -0
  94. package/dist/{chunk-POQSE4C2.mjs → chunk-AFGUR7SY.mjs} +1 -1
  95. package/dist/{chunk-QKXMPUXC.mjs → chunk-AMDGVDNV.mjs} +1 -1
  96. package/dist/{chunk-KTKHRC6H.mjs → chunk-ASAXY2DJ.mjs} +1 -1
  97. package/dist/{chunk-NVRNLK25.mjs → chunk-BYSF5UMM.mjs} +2 -2
  98. package/dist/{chunk-U3SSPL4K.mjs → chunk-CCSGFCLZ.mjs} +1 -1
  99. package/dist/{chunk-NWFBE2YA.mjs → chunk-CG3UHDKH.mjs} +1 -1
  100. package/dist/chunk-CPS4SRPF.mjs +5 -0
  101. package/dist/{chunk-B4P2CM2J.mjs → chunk-CZ5KJSGK.mjs} +1 -1
  102. package/dist/chunk-DAMVDXR3.mjs +2 -0
  103. package/dist/{chunk-NG375ILQ.mjs → chunk-DH6GMDNN.mjs} +1 -1
  104. package/dist/chunk-DHB7UZ7F.mjs +3 -0
  105. package/dist/{chunk-MHW7ZKOU.mjs → chunk-DKR7LFIY.mjs} +1 -1
  106. package/dist/chunk-DLFZJJEE.mjs +2 -0
  107. package/dist/{chunk-6EZ7FNIK.mjs → chunk-F4ZA6JRZ.mjs} +1 -1
  108. package/dist/{chunk-6VTU6KEO.mjs → chunk-FCK6NXON.mjs} +1 -1
  109. package/dist/{chunk-ZWPMCK7P.mjs → chunk-FX42XU6J.mjs} +1 -1
  110. package/dist/chunk-FXQBADMN.mjs +5 -0
  111. package/dist/{chunk-W3BGBJQW.mjs → chunk-G4YP7GVC.mjs} +1 -1
  112. package/dist/{chunk-V6XZ4VIR.mjs → chunk-GWOYMENX.mjs} +1 -1
  113. package/dist/chunk-HATA2W7X.mjs +2 -0
  114. package/dist/{chunk-YI43RG4P.mjs → chunk-HBAUKKQH.mjs} +1 -1
  115. package/dist/{chunk-MAFIGVXY.mjs → chunk-HM4E43VM.mjs} +1 -1
  116. package/dist/{chunk-CRJEG7MT.mjs → chunk-JI6T3A4Y.mjs} +1 -1
  117. package/dist/{chunk-NFMCP2HI.mjs → chunk-JJNRIFND.mjs} +2 -2
  118. package/dist/chunk-JL6R4FG4.mjs +4 -0
  119. package/dist/{chunk-UMHUSOPJ.mjs → chunk-JXLSHVJ2.mjs} +1 -1
  120. package/dist/{chunk-FJYN7RTH.mjs → chunk-KFZBYDIS.mjs} +1 -1
  121. package/dist/{chunk-ZTHICSSF.mjs → chunk-KH24LWAT.mjs} +1 -1
  122. package/dist/{chunk-RKPWLGZ3.mjs → chunk-KUILYI7H.mjs} +1 -1
  123. package/dist/{chunk-RMECZA2K.mjs → chunk-L7W624FD.mjs} +1 -1
  124. package/dist/chunk-LE44MD3O.mjs +4 -0
  125. package/dist/{chunk-4K5KC6V2.mjs → chunk-LV24RY2E.mjs} +1 -1
  126. package/dist/{chunk-43B75J5T.mjs → chunk-MKTX5PGV.mjs} +1 -1
  127. package/dist/{chunk-LKX55H76.mjs → chunk-NAGMRVW4.mjs} +1 -1
  128. package/dist/{chunk-D4CKRD3V.mjs → chunk-NFABH3QW.mjs} +2 -2
  129. package/dist/{chunk-PVER7LSC.mjs → chunk-NIW7F7LU.mjs} +2 -2
  130. package/dist/{chunk-PAREWQGB.mjs → chunk-NWRZXELO.mjs} +1 -1
  131. package/dist/{chunk-OJKMINIU.mjs → chunk-OU3S466R.mjs} +15 -15
  132. package/dist/{chunk-5ZJA7CXT.mjs → chunk-PAFSFVYB.mjs} +1 -1
  133. package/dist/chunk-QCEATQC4.mjs +2 -0
  134. package/dist/{chunk-Y34NR5JL.mjs → chunk-QJ3TFJLQ.mjs} +1 -1
  135. package/dist/{chunk-IA4PSIMD.mjs → chunk-QK3VISCA.mjs} +1 -1
  136. package/dist/{chunk-ZUNVAXLH.mjs → chunk-QXVNUASA.mjs} +1 -1
  137. package/dist/{chunk-GRAXKKG4.mjs → chunk-QZ35UAB4.mjs} +1 -1
  138. package/dist/{chunk-UGWYKHBL.mjs → chunk-S2Y7VI4H.mjs} +2 -2
  139. package/dist/{chunk-OW5NWPOJ.mjs → chunk-SAHS56QM.mjs} +1 -1
  140. package/dist/{chunk-QOUEFUCH.mjs → chunk-SOD23RGL.mjs} +1 -1
  141. package/dist/chunk-TDWJKOLN.mjs +2 -0
  142. package/dist/{chunk-V6RIYQZZ.mjs → chunk-TOE6DPLH.mjs} +1 -1
  143. package/dist/chunk-UGO5N3EI.mjs +15 -0
  144. package/dist/{chunk-Q47PLKIJ.mjs → chunk-UGWMMEJ5.mjs} +1 -1
  145. package/dist/{chunk-NWR2LT5B.mjs → chunk-V5JRSGZF.mjs} +1 -1
  146. package/dist/{chunk-BZ5RAF7L.mjs → chunk-VA3KAQZD.mjs} +1 -1
  147. package/dist/chunk-VG5JEIUQ.mjs +12 -0
  148. package/dist/{chunk-UNOYVIYR.mjs → chunk-VGTMLQWZ.mjs} +1 -1
  149. package/dist/chunk-VKSRM7EY.mjs +22 -0
  150. package/dist/{chunk-YQGT4AB2.mjs → chunk-VNUWREXU.mjs} +1 -1
  151. package/dist/{chunk-AGDILNWB.mjs → chunk-VPVOAJ7X.mjs} +1 -1
  152. package/dist/{chunk-HLYV7RIH.mjs → chunk-WCWYNFDF.mjs} +1 -1
  153. package/dist/chunk-WTEGUPFG.mjs +16 -0
  154. package/dist/{chunk-N76HWBA3.mjs → chunk-XKOHV4H6.mjs} +1 -1
  155. package/dist/{chunk-HMYTM3GT.mjs → chunk-XMKHCUI6.mjs} +1 -1
  156. package/dist/{chunk-OUUP3WKT.mjs → chunk-XQRUG4G3.mjs} +1 -1
  157. package/dist/{chunk-32ZUEFZ7.mjs → chunk-YBB5LWZK.mjs} +1 -1
  158. package/dist/{chunk-SX4LJYT6.mjs → chunk-YFJU3O7G.mjs} +1 -1
  159. package/dist/chunk-YPPJVDQI.mjs +2 -0
  160. package/dist/chunk-ZANMKAWS.mjs +2 -0
  161. package/dist/{chunk-6QBHU4DF.mjs → chunk-ZCP7BTOZ.mjs} +1 -1
  162. package/dist/{chunk-ERLAIBOA.mjs → chunk-ZEY2RLBT.mjs} +2 -2
  163. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-ZO7SFB2E.mjs} +2 -2
  164. package/dist/cli.mjs +1 -1
  165. package/dist/server.mjs +1 -1
  166. package/dist/worker.mjs +1 -1
  167. package/kit/board.css +5 -5
  168. package/kit/code.js +15 -15
  169. package/kit/math.js +1 -1
  170. package/kit/report.css +123 -44
  171. package/kit/runtime.js +45 -7
  172. package/kit/tables.js +2 -0
  173. package/kit/ui.js +2 -0
  174. package/package.json +1 -1
  175. package/packs/gallery/chart-view/kit.js +3 -3
  176. package/packs/gallery/chart-view/writing.md +1 -1
  177. package/packs/gallery/countdown/component.json +1 -1
  178. package/packs/gallery/countdown/kit.js +89 -29
  179. package/packs/gallery/countdown/preview.svg +1 -1
  180. package/packs/gallery/countdown/style.css +88 -100
  181. package/packs/gallery/countdown/writing.md +2 -2
  182. package/packs/gallery/habit/component.json +3 -3
  183. package/packs/gallery/habit/kit.js +114 -75
  184. package/packs/gallery/habit/preview.svg +1 -1
  185. package/packs/gallery/habit/style.css +133 -205
  186. package/packs/gallery/habit/writing.md +2 -2
  187. package/packs/gallery/heatmap/component.json +2 -2
  188. package/packs/gallery/heatmap/kit.js +335 -173
  189. package/packs/gallery/heatmap/preview.svg +1 -1
  190. package/packs/gallery/heatmap/style.css +158 -170
  191. package/packs/gallery/heatmap/writing.md +2 -2
  192. package/packs/gallery/kanban/kit.js +3 -3
  193. package/packs/gallery/kanban/writing.md +1 -1
  194. package/packs/gallery/metric/kit.js +3 -3
  195. package/packs/gallery/metric/writing.md +1 -1
  196. package/packs/gallery/note/component.json +3 -3
  197. package/packs/gallery/note/kit.js +40 -13
  198. package/packs/gallery/note/preview.svg +1 -1
  199. package/packs/gallery/note/style.css +51 -30
  200. package/packs/gallery/note/writing.md +2 -2
  201. package/packs/gallery/recent/component.json +2 -2
  202. package/packs/gallery/recent/kit.js +141 -86
  203. package/packs/gallery/recent/preview.svg +1 -1
  204. package/packs/gallery/recent/style.css +53 -126
  205. package/packs/gallery/recent/writing.md +2 -2
  206. package/packs/gallery/static/component.json +2 -2
  207. package/packs/gallery/static/preview.svg +1 -1
  208. package/packs/gallery/static/style.css +99 -66
  209. package/packs/gallery/static/writing.md +2 -2
  210. package/packs/gallery/stats/component.json +3 -3
  211. package/packs/gallery/stats/kit.js +253 -72
  212. package/packs/gallery/stats/preview.svg +1 -1
  213. package/packs/gallery/stats/style.css +64 -142
  214. package/packs/gallery/stats/writing.md +2 -2
  215. package/packs/gallery/today/component.json +2 -2
  216. package/packs/gallery/today/kit.js +62 -27
  217. package/packs/gallery/today/preview.svg +1 -1
  218. package/packs/gallery/today/style.css +101 -72
  219. package/packs/gallery/today/writing.md +2 -2
  220. package/packs/gallery/todos/component.json +1 -1
  221. package/packs/gallery/todos/kit.js +218 -71
  222. package/packs/gallery/todos/preview.svg +1 -1
  223. package/packs/gallery/todos/style.css +170 -223
  224. package/packs/gallery/todos/writing.md +1 -1
  225. package/packs/gallery/weather/component.json +2 -2
  226. package/packs/gallery/weather/kit.js +165 -90
  227. package/packs/gallery/weather/preview.svg +1 -1
  228. package/packs/gallery/weather/style.css +100 -218
  229. package/packs/gallery/weather/writing.md +1 -1
  230. package/packs/gallery-soft/countdown/component.json +18 -0
  231. package/packs/gallery-soft/countdown/example.html +3 -0
  232. package/packs/gallery-soft/countdown/kit.js +206 -0
  233. package/packs/gallery-soft/countdown/preview.svg +1 -0
  234. package/packs/gallery-soft/countdown/style.css +211 -0
  235. package/packs/gallery-soft/countdown/template.html +3 -0
  236. package/packs/gallery-soft/countdown/writing.md +24 -0
  237. package/packs/gallery-soft/habit/component.json +14 -0
  238. package/packs/gallery-soft/habit/example.html +3 -0
  239. package/packs/gallery-soft/habit/kit.js +366 -0
  240. package/packs/gallery-soft/habit/preview.svg +1 -0
  241. package/packs/gallery-soft/habit/style.css +251 -0
  242. package/packs/gallery-soft/habit/template.html +3 -0
  243. package/packs/gallery-soft/habit/writing.md +23 -0
  244. package/packs/gallery-soft/heatmap/component.json +18 -0
  245. package/packs/gallery-soft/heatmap/example.html +3 -0
  246. package/packs/gallery-soft/heatmap/kit.js +498 -0
  247. package/packs/gallery-soft/heatmap/preview.svg +1 -0
  248. package/packs/gallery-soft/heatmap/style.css +181 -0
  249. package/packs/gallery-soft/heatmap/template.html +3 -0
  250. package/packs/gallery-soft/heatmap/writing.md +23 -0
  251. package/packs/gallery-soft/note/component.json +14 -0
  252. package/packs/gallery-soft/note/example.html +3 -0
  253. package/packs/gallery-soft/note/kit.js +162 -0
  254. package/packs/gallery-soft/note/preview.svg +1 -0
  255. package/packs/gallery-soft/note/style.css +148 -0
  256. package/packs/gallery-soft/note/template.html +3 -0
  257. package/packs/gallery-soft/note/writing.md +20 -0
  258. package/packs/gallery-soft/recent/component.json +13 -0
  259. package/packs/gallery-soft/recent/example.html +1 -0
  260. package/packs/gallery-soft/recent/kit.js +335 -0
  261. package/packs/gallery-soft/recent/preview.svg +1 -0
  262. package/packs/gallery-soft/recent/style.css +160 -0
  263. package/packs/gallery-soft/recent/template.html +1 -0
  264. package/packs/gallery-soft/recent/writing.md +17 -0
  265. package/packs/gallery-soft/static/component.json +13 -0
  266. package/packs/gallery-soft/static/example.html +12 -0
  267. package/packs/gallery-soft/static/preview.svg +1 -0
  268. package/packs/gallery-soft/static/style.css +186 -0
  269. package/packs/gallery-soft/static/template.html +1 -0
  270. package/packs/gallery-soft/static/writing.md +20 -0
  271. package/packs/gallery-soft/stats/component.json +13 -0
  272. package/packs/gallery-soft/stats/example.html +1 -0
  273. package/packs/gallery-soft/stats/kit.js +341 -0
  274. package/packs/gallery-soft/stats/preview.svg +1 -0
  275. package/packs/gallery-soft/stats/style.css +119 -0
  276. package/packs/gallery-soft/stats/template.html +1 -0
  277. package/packs/gallery-soft/stats/writing.md +13 -0
  278. package/packs/gallery-soft/today/component.json +12 -0
  279. package/packs/gallery-soft/today/example.html +1 -0
  280. package/packs/gallery-soft/today/kit.js +222 -0
  281. package/packs/gallery-soft/today/preview.svg +1 -0
  282. package/packs/gallery-soft/today/style.css +178 -0
  283. package/packs/gallery-soft/today/template.html +1 -0
  284. package/packs/gallery-soft/today/writing.md +16 -0
  285. package/packs/gallery-soft/todos/component.json +19 -0
  286. package/packs/gallery-soft/todos/example.html +3 -0
  287. package/packs/gallery-soft/todos/kit.js +527 -0
  288. package/packs/gallery-soft/todos/preview.svg +1 -0
  289. package/packs/gallery-soft/todos/style.css +212 -0
  290. package/packs/gallery-soft/todos/template.html +3 -0
  291. package/packs/gallery-soft/todos/writing.md +32 -0
  292. package/packs/gallery-soft/weather/component.json +19 -0
  293. package/packs/gallery-soft/weather/example.html +3 -0
  294. package/packs/gallery-soft/weather/kit.js +411 -0
  295. package/packs/gallery-soft/weather/preview.svg +1 -0
  296. package/packs/gallery-soft/weather/style.css +185 -0
  297. package/packs/gallery-soft/weather/template.html +3 -0
  298. package/packs/gallery-soft/weather/writing.md +28 -0
  299. package/release.json +10 -10
  300. package/skill/SKILL.md +15 -14
  301. package/skill/references/building-blocks.md +4 -4
  302. package/skill/references/extensions.md +11 -7
  303. package/skill/references/pages-and-data.md +13 -9
  304. package/skill/references/writing-html.md +2 -0
  305. package/web/assets/index-BHC5ZOMh.js +15 -0
  306. package/web/assets/index-xP0uw3a0.css +1 -0
  307. package/web/index.html +2 -2
  308. package/dist/chunk-2NRBY6AJ.mjs +0 -2
  309. package/dist/chunk-35NQ4PLQ.mjs +0 -2
  310. package/dist/chunk-3KJHLHUO.mjs +0 -2
  311. package/dist/chunk-4AV456RQ.mjs +0 -2
  312. package/dist/chunk-5XYHDBJ5.mjs +0 -2
  313. package/dist/chunk-6A53MZYZ.mjs +0 -2
  314. package/dist/chunk-6EXH3ORZ.mjs +0 -166
  315. package/dist/chunk-BVEFGE4B.mjs +0 -2
  316. package/dist/chunk-D4EURAX4.mjs +0 -4
  317. package/dist/chunk-DQCE7TJY.mjs +0 -5
  318. package/dist/chunk-FWNRPMCJ.mjs +0 -12
  319. package/dist/chunk-FWW4CSAZ.mjs +0 -2
  320. package/dist/chunk-GY3FAUVM.mjs +0 -2
  321. package/dist/chunk-JVHHHGEA.mjs +0 -3
  322. package/dist/chunk-L7UP52JO.mjs +0 -2
  323. package/dist/chunk-NAMN3RAF.mjs +0 -2
  324. package/dist/chunk-PZDLJJTJ.mjs +0 -3
  325. package/dist/chunk-SXHBYZST.mjs +0 -16
  326. package/dist/chunk-TEZAWDSQ.mjs +0 -2
  327. package/dist/chunk-UFNYFFKO.mjs +0 -20
  328. package/dist/chunk-UKSHDZZ6.mjs +0 -2
  329. package/dist/chunk-VJPFVNNW.mjs +0 -15
  330. package/dist/chunk-VS3ZMVGX.mjs +0 -5
  331. package/web/assets/index-BK2e_07w.js +0 -13
  332. package/web/assets/index-CWFI83mF.css +0 -1
  333. /package/dist/{chunk-YEY3RSFQ.mjs → chunk-5MMN3N5J.mjs} +0 -0
  334. /package/dist/{chunk-UH4SIXTR.mjs → chunk-74UW7QSL.mjs} +0 -0
  335. /package/dist/{chunk-W7XHE4CT.mjs → chunk-EKGYYOSP.mjs} +0 -0
  336. /package/dist/{chunk-QAIHRH3I.mjs → chunk-KNZJT4ET.mjs} +0 -0
  337. /package/dist/{chunk-A55HN5OK.mjs → chunk-N3DSBH5S.mjs} +0 -0
  338. /package/dist/{chunk-QR6A54KJ.mjs → chunk-ZW2A6GBW.mjs} +0 -0
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{g as n,h as g}from"./chunk-NFMCP2HI.mjs";import{b as m,f as d}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{spawn as P}from"node:child_process";import h from"node:fs/promises";import R from"node:path";import{projectRoot as v,release as k,reportsDirectory as t}from"../browser/shared/paths.mjs";import{answerOf as S,findPreviewServer as x,portIsFree as E,readAnnouncement as G}from"../browser/shared/preview-server.mjs";import{layoutOf as $}from"../browser/shared/workspace.mjs";var b=a=>new Promise(s=>setTimeout(s,a));async function O(a){let{positional:s,values:l}=d({values:["--port"],argv:a});if(s.length>0)throw new m(`gallery serve takes no arguments: ${s[0]}`);let o=l.has("--port")?Number(l.get("--port")):null;if(o!==null&&!(Number.isInteger(o)&&o>0&&o<65536))throw new m(`--port takes a port number: ${l.get("--port")}`);let i=await G({reportsDirectory:t}),f=i?await S(i,t,1e4):"no";f!=="no"&&(console.error(`This workspace's Gallery server runs already: ${n(i.port)} (pid ${i.pid}${f==="busy"?", not answering now":""}). gallery stop stops it; one server serves a workspace.`),process.exit(1));let r=null;if(o!==null)await E(o)||(console.error(`Port ${o} is taken: name another (--port), or leave it out for the first free one.`),process.exit(1)),r=o;else{for(let e of await g())if(await E(e)){r=e;break}r===null&&(console.error("No port from 4317 is free: name one (--port <n>)."),process.exit(1))}if(k){process.env.GALLERY_SERVER_KIND="cli";let{startProductionServer:e}=await import("./chunk-BVEFGE4B.mjs");await e({port:r,kind:"cli"}),await h.writeFile($(t).lastPortFile,`${r}
3
- `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`);return}let{writeSharedAssets:y}=await import("./chunk-NG375ILQ.mjs");await y();let c=P(process.execPath,[R.join(v,"node_modules","vite","bin","vite.js"),"--host","127.0.0.1","--port",String(r),"--strictPort"],{cwd:v,env:{...process.env,GALLERY_WORKSPACE:t,GALLERY_SERVER_KIND:"cli"},stdio:"inherit"});for(let e of["SIGINT","SIGTERM"])process.on(e,()=>c.kill(e));let w=new Promise(e=>c.once("exit",(u,p)=>e(u??(p?1:0))));for(;;){let e=await Promise.race([w.then(p=>({code:p})),b(300).then(()=>null)]);if(e&&process.exit(e.code),(await x({reportsDirectory:t,answering:!0,timeout:2e3}))?.pid===c.pid)break}await h.writeFile($(t).lastPortFile,`${r}
2
+ import{g as n,h as g}from"./chunk-JJNRIFND.mjs";import{b as m,f as d}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{spawn as P}from"node:child_process";import h from"node:fs/promises";import R from"node:path";import{projectRoot as v,release as k,reportsDirectory as t}from"../browser/shared/paths.mjs";import{answerOf as S,findPreviewServer as x,portIsFree as E,readAnnouncement as G}from"../browser/shared/preview-server.mjs";import{layoutOf as $}from"../browser/shared/workspace.mjs";var b=a=>new Promise(s=>setTimeout(s,a));async function O(a){let{positional:s,values:l}=d({values:["--port"],argv:a});if(s.length>0)throw new m(`gallery serve takes no arguments: ${s[0]}`);let o=l.has("--port")?Number(l.get("--port")):null;if(o!==null&&!(Number.isInteger(o)&&o>0&&o<65536))throw new m(`--port takes a port number: ${l.get("--port")}`);let i=await G({reportsDirectory:t}),f=i?await S(i,t,1e4):"no";f!=="no"&&(console.error(`This workspace's Gallery server runs already: ${n(i.port)} (pid ${i.pid}${f==="busy"?", not answering now":""}). gallery stop stops it; one server serves a workspace.`),process.exit(1));let r=null;if(o!==null)await E(o)||(console.error(`Port ${o} is taken: name another (--port), or leave it out for the first free one.`),process.exit(1)),r=o;else{for(let e of await g())if(await E(e)){r=e;break}r===null&&(console.error("No port from 4317 is free: name one (--port <n>)."),process.exit(1))}if(k){process.env.GALLERY_SERVER_KIND="cli";let{startProductionServer:e}=await import("./chunk-DLFZJJEE.mjs");await e({port:r,kind:"cli"}),await h.writeFile($(t).lastPortFile,`${r}
3
+ `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`);return}let{writeSharedAssets:y}=await import("./chunk-DH6GMDNN.mjs");await y();let c=P(process.execPath,[R.join(v,"node_modules","vite","bin","vite.js"),"--host","127.0.0.1","--port",String(r),"--strictPort"],{cwd:v,env:{...process.env,GALLERY_WORKSPACE:t,GALLERY_SERVER_KIND:"cli"},stdio:"inherit"});for(let e of["SIGINT","SIGTERM"])process.on(e,()=>c.kill(e));let w=new Promise(e=>c.once("exit",(u,p)=>e(u??(p?1:0))));for(;;){let e=await Promise.race([w.then(p=>({code:p})),b(300).then(()=>null)]);if(e&&process.exit(e.code),(await x({reportsDirectory:t,answering:!0,timeout:2e3}))?.pid===c.pid)break}await h.writeFile($(t).lastPortFile,`${r}
4
4
  `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`),process.exit(await w)}export{O as run};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as u}from"./chunk-UMHUSOPJ.mjs";import l from"node:fs/promises";import p from"node:path";import{escapeMarkup as g}from"../browser/shared/escape.mjs";import{sha256 as b}from"../browser/shared/files.mjs";import{reportsDirectory as E,starterDirectory as y}from"../browser/shared/paths.mjs";import{listReportSlugs as T,slugPattern as S}from"../browser/shared/reports.mjs";import{documentDirectory as N,documentFiles as $,layoutOf as O,slugTaken as P}from"../browser/shared/workspace.mjs";async function j(t,c){if(!S.test(t))throw new Error(`A document's folder name must be lowercase kebab-case: ${t}`);let n=N(t,c),{html:r,json:i}=$(n),[m,o]=[p.basename(r),p.basename(i)],e,f;try{[e,f]=await Promise.all([l.readFile(r),l.readFile(i,"utf8")])}catch(s){if(s.code!=="ENOENT")throw s;let h=await l.stat(n).then(()=>!0,()=>!1);throw new Error(h?`${n} needs both ${m} and ${o}.`:`${n} does not exist.`)}let a;try{a=JSON.parse(f)}catch(s){throw new Error(`${o} is not valid JSON: ${s.message}`)}if(typeof a.title!="string")throw new Error(`${o} is missing a title.`);for(let s of["description","type"])if(typeof a[s]!="string"||a[s].trim()==="")throw new Error(`${o} is missing a non-empty ${s}.`);if(a.source!==void 0&&typeof a.source!="string")throw new Error(`${o} source must be a string when given.`);return{slug:t,directory:n,htmlPath:r,metadataPath:i,html:e.toString("utf8"),fileSha256:b(e),metadata:a}}async function z(t=[],{directory:c=E,prepare:n=null}={}){let r=t.length>0?[...new Set(t)]:await T(c);if(r.length===0)throw new Error(`No documents in ${p.resolve(c)} yet: gallery new <slug> "<title>" makes one.`);let i=[],m=new Map;for(let o of r)try{let e=await j(o,c);n&&([e.written,e.html]=[u(e.html),n(e)]),i.push(e)}catch(e){m.set(o,[e.message])}return{reports:i,failures:m}}var v=/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/,F=/\n[ \t]*<!-- Starter content:[^\n]*-->\n[ \t]*<section\b[^>]*\sdata-doc-placeholder\b[\s\S]*?<\/section>/;async function M(t,c,n,{directory:r=E,blank:i=!1,lang:m=null,page:o=!1}={}){if(!S.test(t))throw new Error("Slug must be lowercase kebab-case.");if(P(t,r))throw Object.assign(new Error(`"${t}" is taken in ${p.resolve(r)}`),{code:"EEXIST"});let e=o?O(r).preferencesPage:p.resolve(r),f=p.join(e,t),{html:a,metadata:s}=await R(t,c,n,{blank:i,lang:m});await l.mkdir(e,{recursive:!0}),await l.mkdir(f,{recursive:!1});let h=$(f);return await Promise.all([l.writeFile(h.html,a),l.writeFile(h.json,`${JSON.stringify(s,null,2)}
2
+ import{a as u}from"./chunk-JXLSHVJ2.mjs";import l from"node:fs/promises";import p from"node:path";import{escapeMarkup as g}from"../browser/shared/escape.mjs";import{sha256 as b}from"../browser/shared/files.mjs";import{reportsDirectory as E,starterDirectory as y}from"../browser/shared/paths.mjs";import{listReportSlugs as T,slugPattern as S}from"../browser/shared/reports.mjs";import{documentDirectory as N,documentFiles as $,layoutOf as O,slugTaken as P}from"../browser/shared/workspace.mjs";async function j(t,c){if(!S.test(t))throw new Error(`A document's folder name must be lowercase kebab-case: ${t}`);let n=N(t,c),{html:r,json:i}=$(n),[m,o]=[p.basename(r),p.basename(i)],e,f;try{[e,f]=await Promise.all([l.readFile(r),l.readFile(i,"utf8")])}catch(s){if(s.code!=="ENOENT")throw s;let h=await l.stat(n).then(()=>!0,()=>!1);throw new Error(h?`${n} needs both ${m} and ${o}.`:`${n} does not exist.`)}let a;try{a=JSON.parse(f)}catch(s){throw new Error(`${o} is not valid JSON: ${s.message}`)}if(typeof a.title!="string")throw new Error(`${o} is missing a title.`);for(let s of["description","type"])if(typeof a[s]!="string"||a[s].trim()==="")throw new Error(`${o} is missing a non-empty ${s}.`);if(a.source!==void 0&&typeof a.source!="string")throw new Error(`${o} source must be a string when given.`);return{slug:t,directory:n,htmlPath:r,metadataPath:i,html:e.toString("utf8"),fileSha256:b(e),metadata:a}}async function z(t=[],{directory:c=E,prepare:n=null}={}){let r=t.length>0?[...new Set(t)]:await T(c);if(r.length===0)throw new Error(`No documents in ${p.resolve(c)} yet: gallery new <slug> "<title>" makes one.`);let i=[],m=new Map;for(let o of r)try{let e=await j(o,c);n&&([e.written,e.html]=[u(e.html),n(e)]),i.push(e)}catch(e){m.set(o,[e.message])}return{reports:i,failures:m}}var v=/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/,F=/\n[ \t]*<!-- Starter content:[^\n]*-->\n[ \t]*<section\b[^>]*\sdata-doc-placeholder\b[\s\S]*?<\/section>/;async function M(t,c,n,{directory:r=E,blank:i=!1,lang:m=null,page:o=!1}={}){if(!S.test(t))throw new Error("Slug must be lowercase kebab-case.");if(P(t,r))throw Object.assign(new Error(`"${t}" is taken in ${p.resolve(r)}`),{code:"EEXIST"});let e=o?O(r).preferencesPage:p.resolve(r),f=p.join(e,t),{html:a,metadata:s}=await R(t,c,n,{blank:i,lang:m});await l.mkdir(e,{recursive:!0}),await l.mkdir(f,{recursive:!1});let h=$(f);return await Promise.all([l.writeFile(h.html,a),l.writeFile(h.json,`${JSON.stringify(s,null,2)}
3
3
  `)]),{slug:t,directory:f,metadata:s}}async function R(t,c,n,{blank:r=!1,lang:i=null}={}){let m=w=>g(w).replaceAll("'","&#39;"),[o,e]=await Promise.all([l.readFile(p.join(y,"doc.html"),"utf8"),l.readFile(p.join(y,"doc.json"),"utf8")]),f={...JSON.parse(e),title:c,description:n},a=r?o.replace(F,`
4
4
  <p></p>`):o;if(r&&a===o)throw new Error("The starter's placeholder section was not found.");let s=typeof i=="string"&&v.test(i)?a.replace(/(<html\b[^>]*\slang=")[^"]*"/,(w,d)=>`${d}${i}"`):a,h={SLUG:t,TITLE:m(c)};return{html:s.replace(/__REPORT_(SLUG|TITLE)__/g,(w,d)=>h[d]),metadata:f}}export{z as a,M as b,R as c};
@@ -1,20 +1,20 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as Ee,b as Re}from"./chunk-IA4PSIMD.mjs";import{b as Te}from"./chunk-6EZ7FNIK.mjs";import{a as ye,b as je,c as pt,d as Me,e as Ae,f as Ne}from"./chunk-V6RIYQZZ.mjs";import{b as Se,c as ve,e as Oe,g as Ht}from"./chunk-SXHBYZST.mjs";import{a as me}from"./chunk-UMHUSOPJ.mjs";import{a as ge,d as ke,e as be,f as $e,g as xe}from"./chunk-N76HWBA3.mjs";import{e as pe,f as we,g as he,h as Ct}from"./chunk-FJYN7RTH.mjs";import{a as _,m as de}from"./chunk-UBBRTJ2R.mjs";import{g as le,u as ue}from"./chunk-FWNRPMCJ.mjs";var vn=3e4,On=12e4,jn=1500,Fe=1e4,Ie=l=>l.reduce((i,{key:w,tag:u})=>i.set(`${w}
2
+ import{a as Re,b as Ie}from"./chunk-QK3VISCA.mjs";import{b as Ee}from"./chunk-F4ZA6JRZ.mjs";import{a as ge,b as Me,c as pt,d as Ae,e as Ne,f as Te}from"./chunk-TOE6DPLH.mjs";import{b as ve,c as Oe,e as je,g as Ht}from"./chunk-WTEGUPFG.mjs";import{a as pe}from"./chunk-JXLSHVJ2.mjs";import{a as ke,d as be,e as $e,f as xe,g as Se}from"./chunk-XKOHV4H6.mjs";import{e as we,f as he,g as ye,h as Ct}from"./chunk-KFZBYDIS.mjs";import{a as _,m as me}from"./chunk-7XDYK3UC.mjs";import{g as ue,u as de}from"./chunk-VG5JEIUQ.mjs";var On=3e4,jn=12e4,Mn=1500,De=1e4,Fe=l=>l.reduce((i,{key:w,tag:u})=>i.set(`${w}
3
3
  ${u}`,(i.get(`${w}
4
- ${u}`)??0)+1),new Map);function De({now:l=Date.now,hold:i=vn,limit:w=On,quiet:u=jn}={}){let k=new Map,d=new Map,O=new Map,h=new Map,f=new Map;return{wrote(p,b){h.set(p,_(b))},judge(p,{source:b,mtime:I}){if(b===null)return k.delete(p),O.delete(p),{held:!1,signs:[],wait:0,own:!1};let N=_(b),$=f.get(p)?.hash===N?f.get(p).signs:null;$||($=je(b),f.set(p,{hash:N,signs:$}));let Z=l(),W=(J,Q=!1)=>(k.delete(p),d.set(p,Ie($)),O.set(p,b),{held:!1,signs:[],wait:J,own:Q});if(h.get(p)===N)return W(0,!0);let L=d.get(p)??new Map,H=Ie($);if([...H].some(([J,Q])=>Q>(L.get(J)??0))){let J=Math.min(I,Z),Q=k.get(p)??J;k.set(p,Q);let st=Math.min(i-(Z-J),w-(Z-Q));if(st>0)return{held:!0,signs:$.filter(({key:s,tag:g})=>H.get(`${s}
4
+ ${u}`)??0)+1),new Map);function Pe({now:l=Date.now,hold:i=On,limit:w=jn,quiet:u=Mn}={}){let k=new Map,d=new Map,O=new Map,h=new Map,c=new Map;return{wrote(p,b){h.set(p,_(b))},judge(p,{source:b,mtime:I}){if(b===null)return k.delete(p),O.delete(p),{held:!1,signs:[],wait:0,own:!1};let N=_(b),$=c.get(p)?.hash===N?c.get(p).signs:null;$||($=Me(b),c.set(p,{hash:N,signs:$}));let Z=l(),W=(J,Q=!1)=>(k.delete(p),d.set(p,Fe($)),O.set(p,b),{held:!1,signs:[],wait:J,own:Q});if(h.get(p)===N)return W(0,!0);let L=d.get(p)??new Map,H=Fe($);if([...H].some(([J,Q])=>Q>(L.get(J)??0))){let J=Math.min(I,Z),Q=k.get(p)??J;k.set(p,Q);let st=Math.min(i-(Z-J),w-(Z-Q));if(st>0)return{held:!0,signs:$.filter(({key:s,tag:g})=>H.get(`${s}
5
5
  ${g}`)>(L.get(`${s}
6
- ${g}`)??0)),wait:st,own:!1,taken:O.get(p)}}return W(Math.min(u,Math.max(0,u-(Z-I))))}}}import{createHmac as Xn,randomBytes as qt}from"node:crypto";import{existsSync as tr,mkdirSync as er,readFileSync as nr,writeFileSync as rr}from"node:fs";import z from"node:fs/promises";import P from"node:path";import{FILE as or}from"../browser/shared/annotations.mjs";import{escapeTyped as ar}from"../browser/shared/escape.mjs";import{writeAtomic as Ft}from"../browser/shared/files.mjs";import{sendJson as C}from"../browser/shared/http.mjs";import{REQUEST_ID as Qt}from"../browser/shared/ids.mjs";import{UPLOAD_REQUEST_LIMIT as sr}from"../browser/shared/media.mjs";import{reportsDirectory as ir}from"../browser/shared/paths.mjs";import{sameDirectory as cr}from"../browser/shared/preview-server.mjs";import{slugPattern as rt}from"../browser/shared/reports.mjs";import{TODO_MOST as fr}from"../browser/shared/workspace-query.mjs";import{documentDirectory as lr,documentFiles as Mt,isDocumentSource as ur}from"../browser/shared/workspace.mjs";import zt from"node:fs/promises";import Pe from"node:path";import{checkAnnotations as Mn,cleanAnchor as An,cleanItem as Je,FILE as Nn,itemsText as Tn,readItems as En,treeText as _e}from"../browser/shared/annotations.mjs";import{writeAtomic as Rn}from"../browser/shared/files.mjs";import{slugPattern as In}from"../browser/shared/reports.mjs";import{documentDirectory as Le,documentFiles as Fn}from"../browser/shared/workspace.mjs";var Dn=600*1e3,Pn=600*1e3;function Jn(l){let{units:i,boxes:w}=he(l),u=[...i].sort((h,f)=>h.elStart-f.elStart),k=new Map(u.map((h,f)=>[h.id,f])),d=new Map(u.map(h=>[h.id,_e(h.node)])),O={h2:null,h3:null,h4:null};return u.map(h=>{let f=[];for(let N=h;N;N=N.parent===null?null:i[N.parent]){let $=w[N.box];if($?.kind==="panel"&&$.key!==null){let W=i.find(L=>L.kind==="tab"&&L.parent===$.unit&&L.key===$.key);W&&f.unshift({tab:d.get(W.id)})}let Z=$?.unit===null||$?.unit===void 0?null:i[$.unit];if(Z?.tag==="details"&&$.kind==="details"){let W=Z.node.childNodes.find(L=>L.tagName==="summary");W&&f.push({details:_e(W)})}}let p=f.find(N=>N.tab)?.tab,b=f.find(N=>N.details)?.details,I=[p,O.h2,O.h3,O.h4,b].filter(Boolean);return h.tag==="h2"?Object.assign(O,{h2:d.get(h.id),h3:null,h4:null}):h.tag==="h3"?Object.assign(O,{h3:d.get(h.id),h4:null}):h.tag==="h4"&&(O.h4=d.get(h.id)),{id:h.blockId,text:d.get(h.id),parent:h.parent===null?null:k.get(h.parent)??null,where:I,heading:/^h[2-4]$/.test(h.tag)}})}function Ue({reportsDirectory:l,read:i,write:w=Rn,dropped:u=()=>{},now:k=Date.now}){let d=new Map,O=new Map,h=new Map,f=(s,g)=>{let r=h.get(s);if(r?.text===g)return r.units;let a=Jn(g);return h.set(s,{text:g,units:a}),a},p=s=>Pe.join(Le(s,l),Nn),b=s=>typeof s=="string"&&In.test(s);async function I(s){let g=await zt.readFile(p(s),"utf8").catch(()=>null);return{text:g,items:g===null?[]:En(g)}}async function N(s,g,r){let a=Tn(g);return a===r||(a===null?await zt.rm(p(s),{force:!0}):await w(p(s),a)),$(a)}let $=s=>s===null?"":_(s),Z=s=>{let g=d.get(s)??new Map;for(let[r,a]of g)k()-a>Dn&&g.delete(r);return[...g.keys()]},W=(s,g)=>g.forEach(r=>d.get(s)?.delete(r)),L=s=>{let g=O.get(s)??O.set(s,new Map).get(s);for(let[r,a]of g)k()-a>Pn&&g.delete(r);return g};async function H(s,{keep:g=null,items:r=null,before:a=void 0}={}){let S=r?{items:r,text:a}:await I(s),v=await i(s).catch(()=>null);if(!v)return{items:S.items,units:[],places:new Map,version:$(S.text),missing:!0};let D=f(s,v.text),T=L(s),x=Mn(S.items,D,{keep:new Set([...T.keys(),g])});for(let M of T.keys())x.waiting.has(M)||T.delete(M);if(x.dropped.length>0){let M=d.get(s)??d.set(s,new Map).get(s);for(let ot of x.dropped)M.set(ot.id,k())}let A=x.changed||r?await N(s,x.items,S.text):$(S.text);return x.dropped.length>0&&u(s,x.dropped),{items:x.items,units:D,places:x.places,version:A,missing:!1}}let F=(s,{items:g,version:r})=>({ok:!0,version:r,items:g,dropped:Z(s)});async function J(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);return g.missing?[404,{ok:!1,reason:"missing"}]:[200,F(s,g)]}async function Q(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);if(g.missing)return[404,{ok:!1,reason:"missing"}];let r=null,a=Fn(Le(s,l));try{r=JSON.parse(await zt.readFile(a.json,"utf8"))}catch{}let S=await i(s).catch(()=>null),v=/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(S?.text??"")?.[1]?.replace(/<[^>]*>/g,"").trim(),D=typeof r?.title=="string"&&r.title.trim()?r.title.trim():v||s,T=g.units.some(A=>A.heading),x=g.items.map(A=>{let M=g.units[g.places.get(A.id)?.at],ot=M?.where?.length?M.where:M?.heading?[M.text]:[];return{where:ot,top:T&&ot.length===0,blocks:A.anchor.blocks.filter(B=>g.units.some(nt=>nt.id===B)),whole:A.anchor.kind==="blocks",quote:A.anchor.quote,text:A.text}});return[200,{ok:!0,title:D,path:Pe.resolve(a.html),items:x}]}async function st(s){let{slug:g}=s??{};if(!b(g))return[400,{ok:!1,reason:"body"}];if(!await i(g).catch(()=>null))return[404,{ok:!1,reason:"missing"}];let r=await I(g);if(s.anchors&&typeof s.anchors=="object"&&!Array.isArray(s.anchors)){let T=r.items.map(A=>{let M=Object.hasOwn(s.anchors,A.id)?An(s.anchors[A.id]):null;return M&&M.kind===A.anchor.kind?{...A,anchor:M}:A}),x=await N(g,T,r.text);return[200,F(g,{items:T,version:x})]}let a=r.items,S=null,v=null;if(s.put!==void 0){let T=a.find(A=>A.id===s.put?.id),x=Je({...s.put,created:T?.created??s.put?.created});if(!x)return[400,{ok:!1,reason:"item"}];a=T?a.map(A=>A.id===x.id?x:A):[...a,x],S=x.id,T||L(g).set(x.id,k()),W(g,[x.id])}else if(typeof s.remove=="string")a=a.filter(T=>T.id!==s.remove);else if(s.clear===!0)v=a,a=[];else if(Array.isArray(s.restore)){let T=new Map(a.map(M=>[M.id,M])),x=s.restore.map(M=>Je(M,M?.updated)).filter(M=>M&&!(T.get(M.id)?.updated>M.updated)),A=new Set(x.map(M=>M.id));for(let M of A)T.has(M)||L(g).set(M,k());a=[...a.filter(M=>!A.has(M.id)),...x],W(g,[...A])}else return[400,{ok:!1,reason:"body"}];let D=await H(g,{keep:S,items:a,before:r.text});return[200,{...F(g,D),...v?{removed:v}:{}}]}async function q(s){if(!b(s))return;let{text:g}=await I(s);g!==null&&await H(s)}return{list:J,copy:Q,change:st,afterWrite:q}}import wt from"node:fs/promises";import ht from"node:path";import{writeAtomic as We}from"../browser/shared/files.mjs";import{slugPattern as Gt}from"../browser/shared/reports.mjs";var It=1,Ot={seen:"seen.html",base:"base.html",state:"state.json"},_n=4,Ln=1800*1e3;function Be({stateDirectory:l=null,shown:i,folderOf:w,isPage:u=()=>!1,log:k=null,now:d=Date.now,quiet:O=Ln}){let h=new Map,f=r=>ht.join(l,"changes",r),p=Promise.resolve(),b=r=>{let a=p.then(r);return p=a.catch(S=>k?.(`changes: ${S.message}`)),a};async function I(r){if(!l)return h.get(r)?.state??null;try{let a=JSON.parse(await wt.readFile(ht.join(f(r),Ot.state),"utf8"));return a?.v===It&&typeof a.seen=="string"?a:null}catch{return null}}async function N(r,a){return l?wt.readFile(ht.join(f(r),Ot[a]),"utf8").catch(()=>null):h.get(r)?.[a]??null}async function $(r,a,S={}){if(!l){let v=h.get(r)??{};h.set(r,{...v,...S,state:a});return}await wt.mkdir(f(r),{recursive:!0});for(let[v,D]of Object.entries(S))D===null?await wt.rm(ht.join(f(r),Ot[v]),{force:!0}):await We(ht.join(f(r),Ot[v]),D);await We(ht.join(f(r),Ot.state),`${JSON.stringify(a)}
7
- `)}async function Z(r){h.delete(r),l&&await wt.rm(f(r),{recursive:!0,force:!0,maxRetries:3})}let W=async r=>Math.round((await wt.stat(w(r)).catch(()=>null))?.birthtimeMs??0),L=r=>r?.base?`${r.since}|${r.writes}`:null,H=r=>Number.isFinite(r?.draft)&&d()-r.draft<O?r.draft:null,F=(r,a,S,v=H(r))=>[{v:It,born:r?.born??0,seen:a,...v===null?{}:{draft:v}},{seen:S,base:null}];async function J(r){let a=await I(r);if(!a)return null;let S=await W(r);return a.born&&S&&a.born!==S?(await Z(r),null):a}async function Q(r,a){if(typeof a!="string"||!Gt.test(r)||u(r))return!1;let S=_(a),v=await J(r);if(!v)return await $(r,{v:It,born:await W(r),seen:S},{seen:a}),!1;if(v.seen===S)return!1;let D=await N(r,"seen"),T=new Date(d()).toISOString();if(D===null)return await $(r,...F(v,S,a)),!1;let x=i(D),A=i(a);if(!v.base){if(!pt(x,A))return await $(r,...F(v,S,a)),!1;if(H(v)!==null||Me(x))return await $(r,...F(v,S,a,d())),!1;let{draft:B,...nt}=v;return await $(r,{...nt,seen:S,base:_(x),since:T,at:T,writes:1},{seen:a,base:x}),!0}let M=await N(r,"base");if(M===null||!pt(M,A))return await $(r,...F(v,S,a)),!0;let ot=pt(x,A)!==null;return await $(r,{...v,seen:S,...ot?{at:T,writes:v.writes+1}:{}},{seen:a}),ot}async function st(r,a,S,v){if(!Gt.test(r)||u(r))return!1;let D=await J(r),T=_(a);if(!D?.base)return await $(r,...F(D??{born:await W(r)},T,a,v?null:H(D))),!1;let x=await N(r,"base");if(x!==null&&S)try{x=S(x)}catch(A){k?.(`changes: ${r}: the baseline did not take the edit (${A.message})`)}return x===null||!pt(x,i(a))?(await $(r,...F(D,T,a)),!0):(await $(r,{...D,seen:T,base:_(x)},{seen:a,base:x}),!1)}async function q(r,a){if(!Gt.test(r)||u(r))return{ended:!1,moved:!1};let S=typeof a=="string"?await Q(r,a):!1,v=await J(r);if(v?.draft===void 0)return{ended:!1,moved:S};let{draft:D,...T}=v;return await $(r,T),{ended:H(v)!==null,moved:S}}let s=new Map;async function g(r,a){await Q(r,a);let S=i(a),v=_(S),D=await J(r);if(!D?.base)return{pending:!1,version:v};let T=`${r} ${D.base} ${v}`,x=s.get(T);if(x===void 0){let A=await N(r,"base");for(x=A===null?null:pt(A,S),s.set(T,x);s.size>_n;)s.delete(s.keys().next().value)}return x?{pending:!0,version:v,stamp:L(D),since:D.since,writes:D.writes,...x}:{pending:!1,version:v}}return{look:(r,a)=>b(()=>Q(r,a)),wrote:(r,a,S=null,{reader:v=!1}={})=>b(()=>st(r,a,S,v)),endDraft:(r,a=null)=>b(()=>q(r,a)),read:(r,a)=>b(()=>g(r,a)),stamp:r=>b(async()=>L(await J(r))),snapshot:r=>b(async()=>{let a=await J(r);return a?{state:a,seen:await N(r,"seen"),base:await N(r,"base")}:null}),clear:r=>b(async()=>{let a=await J(r);a?.base&&await $(r,{v:It,born:a.born,seen:a.seen},{base:null})}),restore:(r,a)=>b(async()=>{a?.state&&await $(r,a.state,{seen:a.seen,base:a.base})}),forget:r=>b(()=>Z(r)),idle:()=>b(async()=>{})}}import{randomBytes as Un}from"node:crypto";import ct from"node:fs/promises";import yt from"node:path";import{FILE as Wn,readItems as Bn}from"../browser/shared/annotations.mjs";import{writeAtomic as Yn}from"../browser/shared/files.mjs";import{documentDirectory as Zn}from"../browser/shared/workspace.mjs";var Cn=20,Ce=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Ye=80,He=({stateDirectory:l,slug:i})=>yt.join(l,"dropped-annotations",i),ze=l=>({id:l.id,text:l.text,quote:l.anchor?.quote??"",kind:l.anchor?.kind??"text"});async function Ge({stateDirectory:l,reportsDirectory:i,slug:w,time:u,items:k}){let d=He({stateDirectory:l,reportsDirectory:i,slug:w});await ct.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Yn(yt.join(d,`${O}-${Un(4).toString("hex")}.json`),JSON.stringify({time:u,items:k}));let h=(await ct.readdir(d)).filter(f=>Ce.test(f)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Cn)).map(f=>ct.rm(yt.join(d,f),{force:!0})))}async function Vr({stateDirectory:l,reportsDirectory:i,slug:w}){let u=He({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await ct.readdir(u).catch(()=>[])).filter(h=>Ce.test(h)).sort();if(k.length===0)return[];let d=new Set(Bn(await ct.readFile(yt.join(Zn(w,i),Wn),"utf8").catch(()=>"")).map(h=>h.id)),O=[];for(let h of k){let f=yt.join(u,h);try{let p=JSON.parse(await ct.readFile(f,"utf8")),b=Array.isArray(p?.items)?p.items.filter(I=>typeof I?.id=="string"&&!d.has(I.id)):[];typeof p?.time=="string"&&b.length&&O.push({time:p.time,items:b})}catch{}await ct.rm(f,{force:!0}).catch(()=>{})}return O}var Hn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`},Ze=l=>{let i=String(l??"").replace(/\s+/g," ").trim();return JSON.stringify(i.length>Ye?`${i.slice(0,Ye-1)}\u2026`:i)};function Kt(l,{time:i=null,items:w},{today:u=new Date}={}){let k=yt.resolve(l),d=`${w.length} \u6279\u6CE8 (annotation${w.length===1?"":"s"})`;return[`annotations ${k}: ${i?`at ${Hn(i,u)}, `:""}Gallery deleted ${d} whose words are gone from the document (rewritten or deleted):`,...w.map(({id:O,text:h,quote:f,kind:p})=>` ${O} ${Ze(h)} on ${p==="blocks"?"the blocks ":""}${Ze(f)}`)]}function qr(l,i,{today:w=new Date}={}){return i.length?[...i.flatMap(u=>Kt(l,u,{today:w}))," they were the reader's: say in your hand-off which your edit carried out and which you left, and never write them back"]:[]}import{randomBytes as zn}from"node:crypto";import gt from"node:fs/promises";import jt from"node:path";import{writeAtomic as Gn}from"../browser/shared/files.mjs";var Kn=20,Ke=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Qe=({stateDirectory:l,slug:i})=>jt.join(l,"rewrites",i);async function Ve({stateDirectory:l,reportsDirectory:i,slug:w,time:u,changes:k}){let d=Qe({stateDirectory:l,reportsDirectory:i,slug:w});await gt.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Gn(jt.join(d,`${O}-${zn(4).toString("hex")}.json`),JSON.stringify({time:u,changes:k}));let h=(await gt.readdir(d)).filter(f=>Ke.test(f)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Kn)).map(f=>gt.rm(jt.join(d,f),{force:!0})))}async function qe({stateDirectory:l,reportsDirectory:i,slug:w}){let u=Qe({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await gt.readdir(u).catch(()=>[])).filter(O=>Ke.test(O)).sort(),d=[];for(let O of k){let h=jt.join(u,O);try{let f=JSON.parse(await gt.readFile(h,"utf8"));typeof f?.time=="string"&&Array.isArray(f.changes)&&d.push(f)}catch{}await gt.rm(h,{force:!0}).catch(()=>{})}return d}var Qn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`};function oo(l,i,{today:w=new Date}={}){if(!i.length)return[];let u=jt.resolve(l),k=[];for(let{time:d,changes:O}of i){let h=[];for(let{line:f,rule:p,key:b}of[...O].sort((I,N)=>I.line-N.line)){let I=`line ${f} ${p}${b?` ${b}`:""}`;h.includes(I)||h.push(I)}k.push(`preview ${u}: at ${Qn(d,w)}, when the reader edited the page, the preview wrote your natural HTML as the kit's markup: ${h.join(", ")}`),k.push(...O.filter(f=>f.note).map(({line:f,rule:p,note:b})=>` line ${f}, ${p}: ${b}`))}return k.push(" re-read the file before editing it (those lines are the file's as you had left it)"),k}import{todoRef as Vn}from"../browser/shared/workspace-query.mjs";var qn=(l,i)=>l.length===i.length&&l.every((w,u)=>w===i[u]);function Xe(l,i,w,u){let k=Re(i),d=Ee(w,{at:!0}),O=null,h=f=>(O??=pe(w).units).find(p=>p.elStart===f)??null;return u.map(f=>{let p=Vn(f?.ref);if(!p||p.slug!==l||typeof f.done!="boolean")return{reason:"ref"};let b=p.block?d.find(N=>N.block===p.block)??null:null;if(b&&b.text!==p.text)return{reason:"changed"};if(!b){let N=d.filter($=>$.text===p.text&&qn($.path,p.path));if(p.version===k)b=N.find($=>$.nth===p.nth)??null;else{if(N.length>1)return{reason:"ambiguous"};b=N[0]??null}}if(!b)return{reason:"changed"};let I=h(b.at);return I?{unit:I,done:b.done,want:f.done}:{reason:"locked"}})}function tn(l,i){let w=new Map,u=i.map(f=>{if(!f.unit)return!1;let p=w.has(f.unit.id)?w.get(f.unit.id):f.done;return w.set(f.unit.id,f.want),p!==f.want}),k=new Map;for(let f of i)f.unit&&w.get(f.unit.id)!==f.done&&k.set(f.unit.id,f);if(k.size===0)return{commit:null,changed:u};let d=[],O=[],h=new Map;for(let[f,p]of k){let b=`todo${d.length}`,I=p.unit.blockId?{key:b,id:p.unit.blockId}:{key:b,open:f,hash:de(l,p.unit)};d.push({key:b,unit:I,attribute:"data-checked",value:w.get(f)?"":null}),O.push(I),h.set(f,b)}return{commit:{units:d,touch:O,keys:h},changed:u}}import{EMPTY_STYLE as dr,emptyWordsScript as mr,showEmpty as pr}from"../browser/editor/components/placeholder.mjs";import{TOKENS as wr}from"../browser/editor/page/look.mjs";import{MARGIN_STYLE as hr,earlyMarginScript as yr}from"../browser/editor/page/margin.mjs";var Vt=/^[a-f0-9]{16}$/,Xt=2*1024*1024,gr=sr,en=50,nn=/^\d{8}T\d{6}Z-[a-f0-9]{16}\.html$/,kr=30,rn=3,on=200,ft="\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u7A0D\u540E\u518D\u540C\u6B65",br="\u8FD9\u6B21\u7684\u4FEE\u6539\u592A\u5927\uFF0C\u4E00\u6B21\u5B58\u4E0D\u4E0B",$r=250,lt=Symbol("again"),xr="/__gallery/edit/src/editor/page/editor.mjs",Sr=l=>new Promise(i=>setTimeout(i,l));function vr(l,i=Xt){return new Promise((w,u)=>{let k=[],d=0;l.on("data",O=>{d+=O.length,d>i?k.length=0:k.push(O)}),l.on("end",()=>d>i?u(new Error("too-large")):w(Buffer.concat(k).toString("utf8"))),l.on("error",u)})}function Or(l){if(!l)return qt(16).toString("hex");let i=P.join(l,"token");try{let u=nr(i,"utf8").trim();if(/^[a-f0-9]{32}$/.test(u))return u}catch{}let w=qt(16).toString("hex");try{er(l,{recursive:!0,mode:448}),rr(i,w,{mode:384})}catch{}return w}function Uo({reportsDirectory:l=ir,stateDirectory:i=null,write:w=Ft,ids:u=!0,finish:k=p=>p,log:d=null,settling:O={},reviewing:h={},onChanges:f=()=>{}}={}){let p=Or(i),b=De(O),I=O.wait??Fe,N=new Map,$=async(t,n,e,o="reader")=>{let c=await w(t,n,e);if(c!==!1&&ur(P.basename(t))){let y=P.basename(P.dirname(t));b.wrote(y,n),N.set(y,{hash:_(n),by:o})}return c},Z=t=>lr(t,l),W=t=>Mt(Z(t)).html,L=new Map,H=i&&P.join(i,"snapshots"),F=Promise.resolve(),J=Promise.resolve(),Q=async(t,n,e,{by:o="time"}={})=>{let c=(await z.readdir(t)).filter(m=>n.test(m));if(c.length<=e)return;let y=o==="name"?c.sort():(await Promise.all(c.map(async m=>({name:m,time:(await z.stat(P.join(t,m))).mtimeMs})))).sort((m,j)=>m.time-j.time).map(({name:m})=>m);await Promise.all(y.slice(0,y.length-e).map(m=>z.rm(P.join(t,m),{force:!0})))},st=(t,n)=>{H&&(F=F.then(async()=>{let e=P.join(H,`${t}.html`),o=new Date;try{await z.utimes(e,o,o);return}catch{}await z.mkdir(H,{recursive:!0}),await Ft(e,n),await Q(H,/^[a-f0-9]{16}\.html$/,en)}).catch(()=>{}))},q=(t,n)=>{i&&(F=F.then(async()=>{let e=P.join(i,"history",t),o=_(n);if(await z.mkdir(e,{recursive:!0}),(await z.readdir(e)).filter(m=>nn.test(m)).sort().at(-1)?.endsWith(`-${o}.html`))return;let y=new Date().toISOString().replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Ft(P.join(e,`${y}-${o}.html`),n),await Q(e,nn,kr,{by:"name"})}).catch(()=>{}))},s=new Map,g=t=>i&&P.join(i,"receipts",t),r=(t,n,e,o)=>{for(s.set(`${t} ${n}`,{digest:e,answer:o});s.size>on*4;)s.delete(s.keys().next().value);let c=g(t);c&&(F=F.then(async()=>{await z.mkdir(c,{recursive:!0}),await Ft(P.join(c,`${n}.json`),JSON.stringify({digest:e,answer:o})),await Q(c,{test:y=>y.endsWith(".json")&&Qt.test(y.slice(0,-5))},on)}).catch(()=>{}))},a=async(t,n)=>{let e=s.get(`${t} ${n}`);if(e)return e;let o=g(t);if(!o)return null;await F;try{let c=JSON.parse(await z.readFile(P.join(o,`${n}.json`),"utf8"));return typeof c?.digest=="string"&&c.answer?.ok?c:null}catch{return null}},S=new Map,v=(t,n)=>{let e=new Date().toISOString();if(!i)return void S.set(t,[...S.get(t)??[],{time:e,changes:n}].slice(-20));F=F.then(()=>Ve({stateDirectory:i,reportsDirectory:l,slug:t,time:e,changes:n})).catch(()=>{})},D=async t=>{if(!i){let n=S.get(t)??[];return S.delete(t),n}return await F,qe({stateDirectory:i,reportsDirectory:l,slug:t})},T=(t,n)=>{for(L.delete(t),L.set(t,n);L.size>en;)L.delete(L.keys().next().value);st(t,n)},x=async t=>{if(L.has(t))return L.get(t);if(!H||!Vt.test(t))return null;await F;let n=await z.readFile(P.join(H,`${t}.html`),"utf8").catch(()=>null);return n===null||_(n)!==t?null:(T(t,n),n)},A=new Map,M=t=>{let n=A.get(t);if(n)return n;let e=Se(t,{finish:k});for(A.set(t,e);A.size>8;)A.delete(A.keys().next().value);return e},ot=P.join(P.resolve(l),".gallery","pages"),B=Be({...h,stateDirectory:i,shown:t=>M(t).text,folderOf:Z,log:d,isPage:t=>P.resolve(Z(t)).startsWith(ot+P.sep)}),nt=(t,n)=>n.then(e=>{e&&f(t)},e=>d?.(`${t}: the Agent's changes not kept (${e.message})`));async function Dt(t,n=void 0){if(typeof t!="string"||!rt.test(t))return null;let e=W(t),o=n!==void 0?n:await z.readFile(e,"utf8").catch(()=>null);if(o===null)return null;let{text:c,changes:y}=M(o);return{file:e,source:o,text:c,version:_(c),changes:y}}async function it(t){if(typeof t!="string"||!rt.test(t))return{source:null,held:!1,signs:[],wait:0,own:!1};let n=W(t),e=await z.readFile(n,"utf8").catch(()=>null),o=(await z.stat(n).catch(()=>null))?.mtimeMs??0;return{source:e,...b.judge(t,{source:e,mtime:o})}}async function kt(t,n=Date.now()+I){for(;;){let e=await it(t);if(!e.held||Date.now()>=n)return e;await Sr(Math.max(0,Math.min($r,n-Date.now())))}}async function Pt(t,{wait:n=I}={}){let e=await kt(t,Date.now()+n),o=await Dt(t,e.held&&e.taken!==void 0?e.taken:e.source);return o&&{...o,held:e.held===!0}}function an(t,n,{editor:e=xr,kitTags:o=()=>[]}={}){let{html:c,map:y}=ye(n);T(y.version,n);let m=le(l),j=ue(m).map(({assets:Y,...X})=>({...X,kit:o(Y)})),E=`<script type="application/json" id="doc-edit-map" data-doc-dev>${JSON.stringify({slug:t,token:p,...y,components:j,hidden:m.settings.hidden}).replace(/</g,"\\u003c")}</script>
6
+ ${g}`)??0)),wait:st,own:!1,taken:O.get(p)}}return W(Math.min(u,Math.max(0,u-(Z-I))))}}}import{createHmac as tr,randomBytes as qt}from"node:crypto";import{existsSync as er,mkdirSync as nr,readFileSync as rr,writeFileSync as or}from"node:fs";import z from"node:fs/promises";import P from"node:path";import{FILE as ar}from"../browser/shared/annotations.mjs";import{escapeTyped as sr}from"../browser/shared/escape.mjs";import{writeAtomic as Ft}from"../browser/shared/files.mjs";import{sendJson as C}from"../browser/shared/http.mjs";import{REQUEST_ID as Qt}from"../browser/shared/ids.mjs";import{UPLOAD_REQUEST_LIMIT as ir}from"../browser/shared/media.mjs";import{reportsDirectory as cr}from"../browser/shared/paths.mjs";import{sameDirectory as fr}from"../browser/shared/preview-server.mjs";import{slugPattern as rt}from"../browser/shared/reports.mjs";import{TODO_MOST as lr}from"../browser/shared/workspace-query.mjs";import{documentDirectory as ur,documentFiles as Mt,isDocumentSource as dr}from"../browser/shared/workspace.mjs";import zt from"node:fs/promises";import Je from"node:path";import{checkAnnotations as An,cleanAnchor as Nn,cleanItem as _e,FILE as Tn,itemsText as En,readItems as Rn,treeText as Le}from"../browser/shared/annotations.mjs";import{writeAtomic as In}from"../browser/shared/files.mjs";import{slugPattern as Fn}from"../browser/shared/reports.mjs";import{documentDirectory as Ue,documentFiles as Dn}from"../browser/shared/workspace.mjs";var Pn=600*1e3,Jn=600*1e3;function _n(l){let{units:i,boxes:w}=ye(l),u=[...i].sort((h,c)=>h.elStart-c.elStart),k=new Map(u.map((h,c)=>[h.id,c])),d=new Map(u.map(h=>[h.id,Le(h.node)])),O={h2:null,h3:null,h4:null};return u.map(h=>{let c=[];for(let N=h;N;N=N.parent===null?null:i[N.parent]){let $=w[N.box];if($?.kind==="panel"&&$.key!==null){let W=i.find(L=>L.kind==="tab"&&L.parent===$.unit&&L.key===$.key);W&&c.unshift({tab:d.get(W.id)})}let Z=$?.unit===null||$?.unit===void 0?null:i[$.unit];if(Z?.tag==="details"&&$.kind==="details"){let W=Z.node.childNodes.find(L=>L.tagName==="summary");W&&c.push({details:Le(W)})}}let p=c.find(N=>N.tab)?.tab,b=c.find(N=>N.details)?.details,I=[p,O.h2,O.h3,O.h4,b].filter(Boolean);return h.tag==="h2"?Object.assign(O,{h2:d.get(h.id),h3:null,h4:null}):h.tag==="h3"?Object.assign(O,{h3:d.get(h.id),h4:null}):h.tag==="h4"&&(O.h4=d.get(h.id)),{id:h.blockId,text:d.get(h.id),parent:h.parent===null?null:k.get(h.parent)??null,where:I,heading:/^h[2-4]$/.test(h.tag)}})}function We({reportsDirectory:l,read:i,write:w=In,dropped:u=()=>{},now:k=Date.now}){let d=new Map,O=new Map,h=new Map,c=(s,g)=>{let r=h.get(s);if(r?.text===g)return r.units;let a=_n(g);return h.set(s,{text:g,units:a}),a},p=s=>Je.join(Ue(s,l),Tn),b=s=>typeof s=="string"&&Fn.test(s);async function I(s){let g=await zt.readFile(p(s),"utf8").catch(()=>null);return{text:g,items:g===null?[]:Rn(g)}}async function N(s,g,r){let a=En(g);return a===r||(a===null?await zt.rm(p(s),{force:!0}):await w(p(s),a)),$(a)}let $=s=>s===null?"":_(s),Z=s=>{let g=d.get(s)??new Map;for(let[r,a]of g)k()-a>Pn&&g.delete(r);return[...g.keys()]},W=(s,g)=>g.forEach(r=>d.get(s)?.delete(r)),L=s=>{let g=O.get(s)??O.set(s,new Map).get(s);for(let[r,a]of g)k()-a>Jn&&g.delete(r);return g};async function H(s,{keep:g=null,items:r=null,before:a=void 0}={}){let S=r?{items:r,text:a}:await I(s),v=await i(s).catch(()=>null);if(!v)return{items:S.items,units:[],places:new Map,version:$(S.text),missing:!0};let D=c(s,v.text),T=L(s),x=An(S.items,D,{keep:new Set([...T.keys(),g])});for(let M of T.keys())x.waiting.has(M)||T.delete(M);if(x.dropped.length>0){let M=d.get(s)??d.set(s,new Map).get(s);for(let ot of x.dropped)M.set(ot.id,k())}let A=x.changed||r?await N(s,x.items,S.text):$(S.text);return x.dropped.length>0&&u(s,x.dropped),{items:x.items,units:D,places:x.places,version:A,missing:!1}}let F=(s,{items:g,version:r})=>({ok:!0,version:r,items:g,dropped:Z(s)});async function J(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);return g.missing?[404,{ok:!1,reason:"missing"}]:[200,F(s,g)]}async function Q(s){if(!b(s))return[400,{ok:!1,reason:"body"}];let g=await H(s);if(g.missing)return[404,{ok:!1,reason:"missing"}];let r=null,a=Dn(Ue(s,l));try{r=JSON.parse(await zt.readFile(a.json,"utf8"))}catch{}let S=await i(s).catch(()=>null),v=/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(S?.text??"")?.[1]?.replace(/<[^>]*>/g,"").trim(),D=typeof r?.title=="string"&&r.title.trim()?r.title.trim():v||s,T=g.units.some(A=>A.heading),x=g.items.map(A=>{let M=g.units[g.places.get(A.id)?.at],ot=M?.where?.length?M.where:M?.heading?[M.text]:[];return{where:ot,top:T&&ot.length===0,blocks:A.anchor.blocks.filter(B=>g.units.some(nt=>nt.id===B)),whole:A.anchor.kind==="blocks",quote:A.anchor.quote,text:A.text}});return[200,{ok:!0,title:D,path:Je.resolve(a.html),items:x}]}async function st(s){let{slug:g}=s??{};if(!b(g))return[400,{ok:!1,reason:"body"}];if(!await i(g).catch(()=>null))return[404,{ok:!1,reason:"missing"}];let r=await I(g);if(s.anchors&&typeof s.anchors=="object"&&!Array.isArray(s.anchors)){let T=r.items.map(A=>{let M=Object.hasOwn(s.anchors,A.id)?Nn(s.anchors[A.id]):null;return M&&M.kind===A.anchor.kind?{...A,anchor:M}:A}),x=await N(g,T,r.text);return[200,F(g,{items:T,version:x})]}let a=r.items,S=null,v=null;if(s.put!==void 0){let T=a.find(A=>A.id===s.put?.id),x=_e({...s.put,created:T?.created??s.put?.created});if(!x)return[400,{ok:!1,reason:"item"}];a=T?a.map(A=>A.id===x.id?x:A):[...a,x],S=x.id,T||L(g).set(x.id,k()),W(g,[x.id])}else if(typeof s.remove=="string")a=a.filter(T=>T.id!==s.remove);else if(s.clear===!0)v=a,a=[];else if(Array.isArray(s.restore)){let T=new Map(a.map(M=>[M.id,M])),x=s.restore.map(M=>_e(M,M?.updated)).filter(M=>M&&!(T.get(M.id)?.updated>M.updated)),A=new Set(x.map(M=>M.id));for(let M of A)T.has(M)||L(g).set(M,k());a=[...a.filter(M=>!A.has(M.id)),...x],W(g,[...A])}else return[400,{ok:!1,reason:"body"}];let D=await H(g,{keep:S,items:a,before:r.text});return[200,{...F(g,D),...v?{removed:v}:{}}]}async function q(s){if(!b(s))return;let{text:g}=await I(s);g!==null&&await H(s)}return{list:J,copy:Q,change:st,afterWrite:q}}import wt from"node:fs/promises";import ht from"node:path";import{writeAtomic as Be}from"../browser/shared/files.mjs";import{slugPattern as Gt}from"../browser/shared/reports.mjs";var It=1,Ot={seen:"seen.html",base:"base.html",state:"state.json"},Ln=4,Un=1800*1e3;function Ye({stateDirectory:l=null,shown:i,folderOf:w,isPage:u=()=>!1,log:k=null,now:d=Date.now,quiet:O=Un}){let h=new Map,c=r=>ht.join(l,"changes",r),p=Promise.resolve(),b=r=>{let a=p.then(r);return p=a.catch(S=>k?.(`changes: ${S.message}`)),a};async function I(r){if(!l)return h.get(r)?.state??null;try{let a=JSON.parse(await wt.readFile(ht.join(c(r),Ot.state),"utf8"));return a?.v===It&&typeof a.seen=="string"?a:null}catch{return null}}async function N(r,a){return l?wt.readFile(ht.join(c(r),Ot[a]),"utf8").catch(()=>null):h.get(r)?.[a]??null}async function $(r,a,S={}){if(!l){let v=h.get(r)??{};h.set(r,{...v,...S,state:a});return}await wt.mkdir(c(r),{recursive:!0});for(let[v,D]of Object.entries(S))D===null?await wt.rm(ht.join(c(r),Ot[v]),{force:!0}):await Be(ht.join(c(r),Ot[v]),D);await Be(ht.join(c(r),Ot.state),`${JSON.stringify(a)}
7
+ `)}async function Z(r){h.delete(r),l&&await wt.rm(c(r),{recursive:!0,force:!0,maxRetries:3})}let W=async r=>Math.round((await wt.stat(w(r)).catch(()=>null))?.birthtimeMs??0),L=r=>r?.base?`${r.since}|${r.writes}`:null,H=r=>Number.isFinite(r?.draft)&&d()-r.draft<O?r.draft:null,F=(r,a,S,v=H(r))=>[{v:It,born:r?.born??0,seen:a,...v===null?{}:{draft:v}},{seen:S,base:null}];async function J(r){let a=await I(r);if(!a)return null;let S=await W(r);return a.born&&S&&a.born!==S?(await Z(r),null):a}async function Q(r,a){if(typeof a!="string"||!Gt.test(r)||u(r))return!1;let S=_(a),v=await J(r);if(!v)return await $(r,{v:It,born:await W(r),seen:S},{seen:a}),!1;if(v.seen===S)return!1;let D=await N(r,"seen"),T=new Date(d()).toISOString();if(D===null)return await $(r,...F(v,S,a)),!1;let x=i(D),A=i(a);if(!v.base){if(!pt(x,A))return await $(r,...F(v,S,a)),!1;if(H(v)!==null||Ae(x))return await $(r,...F(v,S,a,d())),!1;let{draft:B,...nt}=v;return await $(r,{...nt,seen:S,base:_(x),since:T,at:T,writes:1},{seen:a,base:x}),!0}let M=await N(r,"base");if(M===null||!pt(M,A))return await $(r,...F(v,S,a)),!0;let ot=pt(x,A)!==null;return await $(r,{...v,seen:S,...ot?{at:T,writes:v.writes+1}:{}},{seen:a}),ot}async function st(r,a,S,v){if(!Gt.test(r)||u(r))return!1;let D=await J(r),T=_(a);if(!D?.base)return await $(r,...F(D??{born:await W(r)},T,a,v?null:H(D))),!1;let x=await N(r,"base");if(x!==null&&S)try{x=S(x)}catch(A){k?.(`changes: ${r}: the baseline did not take the edit (${A.message})`)}return x===null||!pt(x,i(a))?(await $(r,...F(D,T,a)),!0):(await $(r,{...D,seen:T,base:_(x)},{seen:a,base:x}),!1)}async function q(r,a){if(!Gt.test(r)||u(r))return{ended:!1,moved:!1};let S=typeof a=="string"?await Q(r,a):!1,v=await J(r);if(v?.draft===void 0)return{ended:!1,moved:S};let{draft:D,...T}=v;return await $(r,T),{ended:H(v)!==null,moved:S}}let s=new Map;async function g(r,a){await Q(r,a);let S=i(a),v=_(S),D=await J(r);if(!D?.base)return{pending:!1,version:v};let T=`${r} ${D.base} ${v}`,x=s.get(T);if(x===void 0){let A=await N(r,"base");for(x=A===null?null:pt(A,S),s.set(T,x);s.size>Ln;)s.delete(s.keys().next().value)}return x?{pending:!0,version:v,stamp:L(D),since:D.since,writes:D.writes,...x}:{pending:!1,version:v}}return{look:(r,a)=>b(()=>Q(r,a)),wrote:(r,a,S=null,{reader:v=!1}={})=>b(()=>st(r,a,S,v)),endDraft:(r,a=null)=>b(()=>q(r,a)),read:(r,a)=>b(()=>g(r,a)),stamp:r=>b(async()=>L(await J(r))),snapshot:r=>b(async()=>{let a=await J(r);return a?{state:a,seen:await N(r,"seen"),base:await N(r,"base")}:null}),clear:r=>b(async()=>{let a=await J(r);a?.base&&await $(r,{v:It,born:a.born,seen:a.seen},{base:null})}),restore:(r,a)=>b(async()=>{a?.state&&await $(r,a.state,{seen:a.seen,base:a.base})}),forget:r=>b(()=>Z(r)),idle:()=>b(async()=>{})}}import{randomBytes as Wn}from"node:crypto";import ct from"node:fs/promises";import yt from"node:path";import{FILE as Bn,readItems as Yn}from"../browser/shared/annotations.mjs";import{writeAtomic as Zn}from"../browser/shared/files.mjs";import{documentDirectory as Cn}from"../browser/shared/workspace.mjs";var Hn=20,He=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Ze=80,ze=({stateDirectory:l,slug:i})=>yt.join(l,"dropped-annotations",i),Ge=l=>({id:l.id,text:l.text,quote:l.anchor?.quote??"",kind:l.anchor?.kind??"text"});async function Ke({stateDirectory:l,reportsDirectory:i,slug:w,time:u,items:k}){let d=ze({stateDirectory:l,reportsDirectory:i,slug:w});await ct.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Zn(yt.join(d,`${O}-${Wn(4).toString("hex")}.json`),JSON.stringify({time:u,items:k}));let h=(await ct.readdir(d)).filter(c=>He.test(c)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Hn)).map(c=>ct.rm(yt.join(d,c),{force:!0})))}async function qr({stateDirectory:l,reportsDirectory:i,slug:w}){let u=ze({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await ct.readdir(u).catch(()=>[])).filter(h=>He.test(h)).sort();if(k.length===0)return[];let d=new Set(Yn(await ct.readFile(yt.join(Cn(w,i),Bn),"utf8").catch(()=>"")).map(h=>h.id)),O=[];for(let h of k){let c=yt.join(u,h);try{let p=JSON.parse(await ct.readFile(c,"utf8")),b=Array.isArray(p?.items)?p.items.filter(I=>typeof I?.id=="string"&&!d.has(I.id)):[];typeof p?.time=="string"&&b.length&&O.push({time:p.time,items:b})}catch{}await ct.rm(c,{force:!0}).catch(()=>{})}return O}var zn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`},Ce=l=>{let i=String(l??"").replace(/\s+/g," ").trim();return JSON.stringify(i.length>Ze?`${i.slice(0,Ze-1)}\u2026`:i)};function Kt(l,{time:i=null,items:w},{today:u=new Date}={}){let k=yt.resolve(l),d=`${w.length} \u6279\u6CE8 (annotation${w.length===1?"":"s"})`;return[`annotations ${k}: ${i?`at ${zn(i,u)}, `:""}Gallery deleted ${d} whose words are gone from the document (rewritten or deleted):`,...w.map(({id:O,text:h,quote:c,kind:p})=>` ${O} ${Ce(h)} on ${p==="blocks"?"the blocks ":""}${Ce(c)}`)]}function Xr(l,i,{today:w=new Date}={}){return i.length?[...i.flatMap(u=>Kt(l,u,{today:w}))," they were the reader's: say in your hand-off which your edit carried out and which you left, and never write them back"]:[]}import{randomBytes as Gn}from"node:crypto";import gt from"node:fs/promises";import jt from"node:path";import{writeAtomic as Kn}from"../browser/shared/files.mjs";var Qn=20,Qe=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Ve=({stateDirectory:l,slug:i})=>jt.join(l,"rewrites",i);async function qe({stateDirectory:l,reportsDirectory:i,slug:w,time:u,changes:k}){let d=Ve({stateDirectory:l,reportsDirectory:i,slug:w});await gt.mkdir(d,{recursive:!0});let O=u.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Kn(jt.join(d,`${O}-${Gn(4).toString("hex")}.json`),JSON.stringify({time:u,changes:k}));let h=(await gt.readdir(d)).filter(c=>Qe.test(c)).sort();await Promise.all(h.slice(0,Math.max(0,h.length-Qn)).map(c=>gt.rm(jt.join(d,c),{force:!0})))}async function Xe({stateDirectory:l,reportsDirectory:i,slug:w}){let u=Ve({stateDirectory:l,reportsDirectory:i,slug:w}),k=(await gt.readdir(u).catch(()=>[])).filter(O=>Qe.test(O)).sort(),d=[];for(let O of k){let h=jt.join(u,O);try{let c=JSON.parse(await gt.readFile(h,"utf8"));typeof c?.time=="string"&&Array.isArray(c.changes)&&d.push(c)}catch{}await gt.rm(h,{force:!0}).catch(()=>{})}return d}var Vn=(l,i=new Date)=>{let w=new Date(l),u=d=>String(d).padStart(2,"0"),k=`${u(w.getHours())}:${u(w.getMinutes())}`;return w.toDateString()===i.toDateString()?k:`${w.getFullYear()}-${u(w.getMonth()+1)}-${u(w.getDate())} ${k}`};function ao(l,i,{today:w=new Date}={}){if(!i.length)return[];let u=jt.resolve(l),k=[];for(let{time:d,changes:O}of i){let h=[];for(let{line:c,rule:p,key:b}of[...O].sort((I,N)=>I.line-N.line)){let I=`line ${c} ${p}${b?` ${b}`:""}`;h.includes(I)||h.push(I)}k.push(`preview ${u}: at ${Vn(d,w)}, when the reader edited the page, the preview wrote your natural HTML as the kit's markup: ${h.join(", ")}`),k.push(...O.filter(c=>c.note).map(({line:c,rule:p,note:b})=>` line ${c}, ${p}: ${b}`))}return k.push(" re-read the file before editing it (those lines are the file's as you had left it)"),k}import{todoRef as qn}from"../browser/shared/workspace-query.mjs";var Xn=(l,i)=>l.length===i.length&&l.every((w,u)=>w===i[u]);function tn(l,i,w,u){let k=Ie(i),d=Re(w,{at:!0}),O=null,h=c=>(O??=we(w).units).find(p=>p.elStart===c)??null;return u.map(c=>{let p=qn(c?.ref);if(!p||p.slug!==l||typeof c.done!="boolean")return{reason:"ref"};let b=p.block?d.find(N=>N.block===p.block)??null:null;if(b&&b.text!==p.text)return{reason:"changed"};if(!b){let N=d.filter($=>$.text===p.text&&Xn($.path,p.path));if(p.version===k)b=N.find($=>$.nth===p.nth)??null;else{if(N.length>1)return{reason:"ambiguous"};b=N[0]??null}}if(!b)return{reason:"changed"};let I=h(b.at);return I?{unit:I,done:b.done,want:c.done}:{reason:"locked"}})}function en(l,i){let w=new Map,u=i.map(c=>{if(!c.unit)return!1;let p=w.has(c.unit.id)?w.get(c.unit.id):c.done;return w.set(c.unit.id,c.want),p!==c.want}),k=new Map;for(let c of i)c.unit&&w.get(c.unit.id)!==c.done&&k.set(c.unit.id,c);if(k.size===0)return{commit:null,changed:u};let d=[],O=[],h=new Map;for(let[c,p]of k){let b=`todo${d.length}`,I=p.unit.blockId?{key:b,id:p.unit.blockId}:{key:b,open:c,hash:me(l,p.unit)};d.push({key:b,unit:I,attribute:"data-checked",value:w.get(c)?"":null}),O.push(I),h.set(c,b)}return{commit:{units:d,touch:O,keys:h},changed:u}}import{EMPTY_STYLE as mr,emptyWordsScript as pr,showEmpty as wr}from"../browser/editor/components/placeholder.mjs";import{TOKENS as hr}from"../browser/editor/page/look.mjs";import{MARGIN_STYLE as yr,earlyMarginScript as gr}from"../browser/editor/page/margin.mjs";var Vt=/^[a-f0-9]{16}$/,Xt=2*1024*1024,kr=ir,nn=50,rn=/^\d{8}T\d{6}Z-[a-f0-9]{16}\.html$/,br=30,on=3,an=200,ft="\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u7A0D\u540E\u518D\u540C\u6B65",$r="\u8FD9\u6B21\u7684\u4FEE\u6539\u592A\u5927\uFF0C\u4E00\u6B21\u5B58\u4E0D\u4E0B",xr=250,lt=Symbol("again"),Sr="/__gallery/edit/src/editor/page/editor.mjs",vr=l=>new Promise(i=>setTimeout(i,l));function Or(l,i=Xt){return new Promise((w,u)=>{let k=[],d=0;l.on("data",O=>{d+=O.length,d>i?k.length=0:k.push(O)}),l.on("end",()=>d>i?u(new Error("too-large")):w(Buffer.concat(k).toString("utf8"))),l.on("error",u)})}function jr(l){if(!l)return qt(16).toString("hex");let i=P.join(l,"token");try{let u=rr(i,"utf8").trim();if(/^[a-f0-9]{32}$/.test(u))return u}catch{}let w=qt(16).toString("hex");try{nr(l,{recursive:!0,mode:448}),or(i,w,{mode:384})}catch{}return w}function Wo({reportsDirectory:l=cr,stateDirectory:i=null,write:w=Ft,ids:u=!0,finish:k=p=>p,log:d=null,settling:O={},reviewing:h={},onChanges:c=()=>{}}={}){let p=jr(i),b=Pe(O),I=O.wait??De,N=new Map,$=async(t,n,e,o="reader")=>{let f=await w(t,n,e);if(f!==!1&&dr(P.basename(t))){let y=P.basename(P.dirname(t));b.wrote(y,n),N.set(y,{hash:_(n),by:o})}return f},Z=t=>ur(t,l),W=t=>Mt(Z(t)).html,L=new Map,H=i&&P.join(i,"snapshots"),F=Promise.resolve(),J=Promise.resolve(),Q=async(t,n,e,{by:o="time"}={})=>{let f=(await z.readdir(t)).filter(m=>n.test(m));if(f.length<=e)return;let y=o==="name"?f.sort():(await Promise.all(f.map(async m=>({name:m,time:(await z.stat(P.join(t,m))).mtimeMs})))).sort((m,j)=>m.time-j.time).map(({name:m})=>m);await Promise.all(y.slice(0,y.length-e).map(m=>z.rm(P.join(t,m),{force:!0})))},st=(t,n)=>{H&&(F=F.then(async()=>{let e=P.join(H,`${t}.html`),o=new Date;try{await z.utimes(e,o,o);return}catch{}await z.mkdir(H,{recursive:!0}),await Ft(e,n),await Q(H,/^[a-f0-9]{16}\.html$/,nn)}).catch(()=>{}))},q=(t,n)=>{i&&(F=F.then(async()=>{let e=P.join(i,"history",t),o=_(n);if(await z.mkdir(e,{recursive:!0}),(await z.readdir(e)).filter(m=>rn.test(m)).sort().at(-1)?.endsWith(`-${o}.html`))return;let y=new Date().toISOString().replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Ft(P.join(e,`${y}-${o}.html`),n),await Q(e,rn,br,{by:"name"})}).catch(()=>{}))},s=new Map,g=t=>i&&P.join(i,"receipts",t),r=(t,n,e,o)=>{for(s.set(`${t} ${n}`,{digest:e,answer:o});s.size>an*4;)s.delete(s.keys().next().value);let f=g(t);f&&(F=F.then(async()=>{await z.mkdir(f,{recursive:!0}),await Ft(P.join(f,`${n}.json`),JSON.stringify({digest:e,answer:o})),await Q(f,{test:y=>y.endsWith(".json")&&Qt.test(y.slice(0,-5))},an)}).catch(()=>{}))},a=async(t,n)=>{let e=s.get(`${t} ${n}`);if(e)return e;let o=g(t);if(!o)return null;await F;try{let f=JSON.parse(await z.readFile(P.join(o,`${n}.json`),"utf8"));return typeof f?.digest=="string"&&f.answer?.ok?f:null}catch{return null}},S=new Map,v=(t,n)=>{let e=new Date().toISOString();if(!i)return void S.set(t,[...S.get(t)??[],{time:e,changes:n}].slice(-20));F=F.then(()=>qe({stateDirectory:i,reportsDirectory:l,slug:t,time:e,changes:n})).catch(()=>{})},D=async t=>{if(!i){let n=S.get(t)??[];return S.delete(t),n}return await F,Xe({stateDirectory:i,reportsDirectory:l,slug:t})},T=(t,n)=>{for(L.delete(t),L.set(t,n);L.size>nn;)L.delete(L.keys().next().value);st(t,n)},x=async t=>{if(L.has(t))return L.get(t);if(!H||!Vt.test(t))return null;await F;let n=await z.readFile(P.join(H,`${t}.html`),"utf8").catch(()=>null);return n===null||_(n)!==t?null:(T(t,n),n)},A=new Map,M=t=>{let n=A.get(t);if(n)return n;let e=ve(t,{finish:k});for(A.set(t,e);A.size>8;)A.delete(A.keys().next().value);return e},ot=P.join(P.resolve(l),".gallery","pages"),B=Ye({...h,stateDirectory:i,shown:t=>M(t).text,folderOf:Z,log:d,isPage:t=>P.resolve(Z(t)).startsWith(ot+P.sep)}),nt=(t,n)=>n.then(e=>{e&&c(t)},e=>d?.(`${t}: the Agent's changes not kept (${e.message})`));async function Dt(t,n=void 0){if(typeof t!="string"||!rt.test(t))return null;let e=W(t),o=n!==void 0?n:await z.readFile(e,"utf8").catch(()=>null);if(o===null)return null;let{text:f,changes:y}=M(o);return{file:e,source:o,text:f,version:_(f),changes:y}}async function it(t){if(typeof t!="string"||!rt.test(t))return{source:null,held:!1,signs:[],wait:0,own:!1};let n=W(t),e=await z.readFile(n,"utf8").catch(()=>null),o=(await z.stat(n).catch(()=>null))?.mtimeMs??0;return{source:e,...b.judge(t,{source:e,mtime:o})}}async function kt(t,n=Date.now()+I){for(;;){let e=await it(t);if(!e.held||Date.now()>=n)return e;await vr(Math.max(0,Math.min(xr,n-Date.now())))}}async function Pt(t,{wait:n=I}={}){let e=await kt(t,Date.now()+n),o=await Dt(t,e.held&&e.taken!==void 0?e.taken:e.source);return o&&{...o,held:e.held===!0}}function sn(t,n,{editor:e=Sr,kitTags:o=()=>[]}={}){let{html:f,map:y}=ge(n);T(y.version,n);let m=ue(l),j=de(m).map(({assets:Y,...X})=>({...X,kit:o(Y)})),E=`<script type="application/json" id="doc-edit-map" data-doc-dev>${JSON.stringify({slug:t,token:p,...y,components:j,hidden:m.settings.hidden}).replace(/</g,"\\u003c")}</script>
8
8
  <script data-doc-dev>document.currentScript.remove(); import(${JSON.stringify(e)});</script>`,U=`<style data-doc-dev>.doc-display { display: none; }</style>
9
- <style data-doc-dev data-ge-palette>${wr}</style>
10
- <style data-doc-dev>${dr}</style>
11
- <script data-doc-dev>${mr()}</script>
9
+ <style data-doc-dev data-ge-palette>${hr}</style>
10
+ <style data-doc-dev>${mr}</style>
11
+ <script data-doc-dev>${pr()}</script>
12
12
  <script data-doc-dev>document.currentScript.remove(); document.documentElement.setAttribute("data-ge-order", "file");</script>
13
- <style data-doc-dev data-ge-margin-style>${hr}</style>
14
- <script data-doc-dev>document.currentScript.remove(); ${yr(t,{notes:tr(P.join(Z(t),or))})}</script>`;return{html:pr(c),snippet:E,head:U}}let sn=t=>T(_(t),t);async function ut(t,n=Xt){if(t.method!=="POST")return{error:[405,{ok:!1,reason:"method"}]};let e=t.headers.host??"",o=t.socket.localPort;if(e!==`127.0.0.1:${o}`&&e!==`localhost:${o}`)return{error:[403,{ok:!1,reason:"host"}]};if(t.headers.origin!==`http://${e}`)return{error:[403,{ok:!1,reason:"origin"}]};if(t.headers["x-gallery-token"]!==p)return{error:[403,{ok:!1,reason:"token"}]};if(!/^application\/json\b/i.test(t.headers["content-type"]??""))return{error:[415,{ok:!1,reason:"type"}]};try{return{body:JSON.parse(await vr(t,n))}}catch(c){return{error:c.message==="too-large"?[413,{ok:!1,reason:"body",message:br}]:[400,{ok:!1,reason:"body"}]}}}async function Jt(t,n){let{slug:e,opening:o,known:c=null,texts:y=[],units:m=[],touch:j=[],pageIds:R=null,request:E=null,agent:U=!1}=t;if(typeof e!="string"||!rt.test(e)||![y,m,j].every(Array.isArray))return[400,{ok:!1,reason:"body"}];if(E!==null&&(typeof E!="string"||!Qt.test(E)))return[400,{ok:!1,reason:"body"}];let Y=E===null?null:_(JSON.stringify([o??null,y,m,j])),X=await te(t);if(X)return X;let G=et=>(E!==null&&r(e,E,Y,et),[200,et]),K=W(e),tt=typeof o=="string"&&Vt.test(o)?await x(o):null,V=et=>Xn("sha256",p).update(`${e}
15
- ${et}`).digest("hex").slice(0,32);for(let et=1;;et++){let{source:at,held:Tt}=await it(e);if(at===null)return[404,{ok:!1,reason:"missing"}];if(Tt)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];nt(e,B.look(e,at));let{text:vt,changes:Zt}=M(at),ae=[],Et=ke({current:vt,opening:tt,texts:y,units:m,touch:j,ids:u?()=>{let Rt=typeof u=="function"?u():Ct();return ae.push(Rt),Rt}:!1,seal:V,pageIds:R}),{title:se,icon:ie,...ce}=Et,mt=Et.text===vt?vt:k(Et.text);mt!==Et.text&&(ce.version=_(mt));let fe={...ce,foreign:typeof c=="string"&&_(vt)!==c};if(mt===vt)return G({ok:!0,...fe,wrote:!1,notes:[]});if(q(e,at),!await $(K,mt,{expect:at},U===!0?"agent":"reader")){if(et===rn)return[409,{ok:!1,reason:"busy",message:ft}];continue}q(e,mt),nt(e,B.wrote(e,mt,Rt=>{let Sn=0;return Ae(Rt,{opening:tt,texts:y,units:m,touch:j,pageIds:R,seal:V,ids:u?()=>ae[Sn++]??(typeof u=="function"?u():Ct()):!1})},{reader:U!==!0})),Zt.length&&(d&&d(Ht(K,Zt).join(`
16
- `)),v(e,Zt));let xn=[...se?await At(P.dirname(K),se):[],...ie!==void 0?await _t(P.dirname(K),ie):[]];return G({ok:!0,...fe,wrote:!0,notes:xn})}}async function cn(t,n){return typeof t!="string"||!rt.test(t)?[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}]:!Array.isArray(n)||n.length===0||n.length>fr?[400,{ok:!1,reason:"body"}]:Lt({slug:t},async(e,o)=>{let{source:c,held:y}=await it(t);if(c===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(y)return Date.now()<o?lt:[409,{ok:!1,reason:"busy",message:ft}];let{text:m}=M(c),j=Xe(t,c,m,n),{commit:R,changed:E}=tn(m,j),U=j.map((V,et)=>V.reason?{ok:!1,reason:V.reason}:{ok:!0,changed:E[et],block:V.unit.blockId??null});if(!R)return[200,{ok:!0,results:U,wrote:!1}];let Y=_(m);T(Y,m);let X=await Jt({slug:t,opening:Y,units:R.units,touch:R.touch},o);if(X===lt)return lt;let[G,K]=X;if(!K.ok)return[G,K];let tt=new Map((K.units??[]).map(V=>[V.key,V]));return[200,{ok:!0,wrote:K.wrote===!0,results:U.map((V,et)=>{if(!V.ok)return V;let at=R.keys.get(j[et].unit.id);if(at===void 0)return V;let Tt=tt.get(at);return Tt?.status!=="applied"?{ok:!1,reason:Tt?.reason==="ambiguous"?"ambiguous":"changed"}:{...V,block:K.ids?.[at]??V.block}})}]})}async function te({slug:t,opening:n,texts:e=[],units:o=[],touch:c=[],request:y=null}){if(typeof t!="string"||!rt.test(t)||typeof y!="string"||!Qt.test(y)||![e,o,c].every(Array.isArray))return null;let m=await a(t,y);return m?m.digest===_(JSON.stringify([n??null,e,o,c]))?[200,{...m.answer,again:!0}]:[409,{ok:!1,reason:"request",message:"\u540C\u4E00\u6B21\u4FDD\u5B58\u7684\u5185\u5BB9\u4E0D\u4E00\u81F4"}]:null}async function fn(t,n){let{slug:e,opening:o,texts:c=[],units:y=[],instances:m=[],pageIds:j=null}=t;if(typeof e!="string"||!rt.test(e)||!Array.isArray(c)||!Array.isArray(y)||!Array.isArray(m))return[400,{ok:!1,reason:"body"}];let{source:R,held:E}=await it(e);if(E)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];let U=await Dt(e,R);if(U===null)return[404,{ok:!1,reason:"missing"}];let{text:Y,version:X}=U,G=typeof o=="string"&&Vt.test(o)?await x(o):null;return[200,{ok:!0,version:X,reverted:xe({current:Y,opening:G,texts:c,pageIds:j}),units:be({current:Y,units:y}),parts:$e({current:Y,instances:m,pageIds:j})}]}let ln=600*1e3,bt=new Map;async function ee(t,n){let e=Z(t),o=null;try{o=JSON.parse(await z.readFile(Mt(e).json,"utf8"))}catch{}let{title:c,icon:y}=Oe(n,o);c&&typeof o?.title=="string"&&o.title!==c.to&&await At(e,{from:o.title,to:c.to,synced:!0}),y&&!y.missing&&await _t(e,y.to)}async function un(t,n){let{slug:e,action:o,stamp:c=null,undo:y=null}=t;if(typeof e!="string"||!rt.test(e)||!["accept","revert","undo"].includes(o))return[400,{ok:!1,reason:"body"}];let m=W(e),{source:j,held:R}=await it(e);if(j===null)return[404,{ok:!1,reason:"missing"}];if(R)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];if(o==="undo"){for(let[K,tt]of bt)Date.now()-tt.at>ln&&bt.delete(K);let G=typeof y=="string"?bt.get(y):null;return!G||G.slug!==e?[404,{ok:!1,reason:"gone",message:"\u64A4\u9500\u5DF2\u7ECF\u8FC7\u671F"}]:j!==G.after?[409,{ok:!1,reason:"moved-on",message:"\u64A4\u56DE\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500"}]:(q(e,j),await $(m,G.before,{expect:j})?(q(e,G.before),bt.delete(y),await ee(e,G.before),await B.restore(e,G.saved),await B.wrote(e,G.before),f(e),[200,{ok:!0,version:_(M(G.before).text)}]):[409,{ok:!1,reason:"busy",message:ft}])}await B.look(e,j);let E=await B.snapshot(e),U=E?.state?.base?`${E.state.since}|${E.state.writes}`:null;if(U===null)return[200,{ok:!0,none:!0}];if(U!==c)return[409,{ok:!1,reason:"changed",message:"Agent \u521A\u521A\u53C8\u6539\u4E86\u6587\u6863\uFF0C\u518D\u770B\u4E00\u773C"}];if(o==="accept")return await B.clear(e),f(e),[200,{ok:!0}];let Y=E.base;if(q(e,j),!await $(m,Y,{expect:j}))return[409,{ok:!1,reason:"busy",message:ft}];q(e,Y),await ee(e,Y);let X=qt(8).toString("hex");return bt.set(X,{slug:e,before:j,after:Y,saved:E,at:Date.now()}),await B.clear(e),await B.wrote(e,Y),f(e),[200,{ok:!0,version:_(M(Y).text),undo:X}]}async function dn(t,n){let e=await ut(t);if(e.error)return C(n,...e.error);let o=e.body??{};try{if(o.action!=="read")return C(n,...await Lt(o,un));if(typeof o.slug!="string"||!rt.test(o.slug))return C(n,400,{ok:!1,reason:"body"});let c=await Pt(o.slug,{wait:0});return c===null?C(n,404,{ok:!1,reason:"missing"}):C(n,200,{ok:!0,...await B.read(o.slug,c.source)})}catch(c){return C(n,500,{ok:!1,reason:"write",message:c.message})}}async function At(t,{from:n,to:e,synced:o}){let c=["\u6807\u9898\u5DF2\u66F4\u65B0",...o?[]:["\u5355\u72EC\u6253\u5F00\u6216\u5BFC\u51FA\u65F6\u7684\u9875\u9762\u540D\u79F0\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"]],y=Mt(t).json,m=await z.readFile(y,"utf8").catch(()=>""),j=null;try{j=JSON.parse(m)}catch{}if(j?.title!==n)return[...c,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"];let R=new RegExp(`("title"\\s*:\\s*)${JSON.stringify(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`),E=R.test(m)?m.replace(R,(U,Y)=>Y+JSON.stringify(e)):`${JSON.stringify({...j,title:e},null,2)}
17
- `;try{await $(y,E)}catch(U){return d?.(`${P.basename(y)}'s title was not written (${U.code??U.message}): ${y}`),[...c,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u6CA1\u80FD\u8DDF\u7740\u6539"]}return c}async function _t(t,n){let e=Mt(t).json,o=null;try{o=JSON.parse(await z.readFile(e,"utf8"))}catch{}if(!o||typeof o!="object")return d?.(`${P.basename(e)} could not be read, so its icon was not written: ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"];if((o.icon??null)===n)return[];let{icon:c,...y}=o,m=n===null?y:{...y,icon:n};try{await $(e,`${JSON.stringify(m,null,2)}
18
- `)}catch(j){return d?.(`${P.basename(e)}'s icon was not written (${j.code??j.message}): ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"]}return[]}async function mn(t,n){let e=typeof n=="string"?n.replace(/\s+/g," ").trim():"";if(!e)return{ok:!1,reason:"title",message:"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"};let o=W(t),c=await z.readFile(o,"utf8").catch(()=>null);if(c===null)return{ok:!1,reason:"missing"};nt(t,B.look(t,c));let y=me(c),m=we(y).find(E=>E.kind==="title");if(!m)return{ok:!1,reason:"no-title",message:"\u8FD9\u4EFD\u6587\u6863\u6CA1\u6709\u6807\u9898"};let j=ar(e),R=ge({current:y,edits:[{id:m.id,parts:[{keep:!0,html:j}]}],ids:u});return R.ok?R.text!==c&&!await $(o,R.text,{expect:c})?{ok:!1,reason:"changed-again"}:(R.text!==c&&nt(t,B.wrote(t,R.text,E=>Ne(E,j))),{ok:!0,title:e,notes:R.title?await At(P.dirname(o),R.title):[]}):{ok:!1,reason:"conflict"}}let $t=t=>(n,e)=>{let o=J.then(()=>t(n));return J=o.catch(()=>{}),o.then(([c,y])=>C(e,c,y),c=>C(e,500,{ok:!1,reason:"write",message:c.message}))},ne=(t,{early:n=null}={})=>async(e,o)=>{let c=await ut(e);if(c.error)return C(o,...c.error);let y=c.body??{};try{let m=n&&await n(y);return m?C(o,...m):C(o,...await Lt(y,t))}catch(m){return C(o,500,{ok:!1,reason:"write",message:m.message})}};async function Lt(t,n){let e=Date.now()+I;for(;;){await kt(t.slug,e);let o=J.then(()=>n(t,e));J=o.catch(()=>{});let c=await o;if(c!==lt)return c}}async function Ut(t,{reader:n=!1}={}){if(typeof t!="string"||!rt.test(t))return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};let e=Z(t),{html:o,json:c}=Mt(e);for(let y=1;;y++){let{source:m,held:j}=n?await it(t):{source:await z.readFile(o,"utf8").catch(()=>null),held:!1};if(m===null)return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};if(j)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};nt(t,B.look(t,m));let R=null;try{R=JSON.parse(await z.readFile(c,"utf8"))}catch{}let{text:E,changes:U,added:Y,given:X,repeated:G,title:K,icon:tt}=ve(m,{finish:k,next:typeof u=="function"?u:void 0,metadata:R});if(E!==m){if(q(t,m),!await $(o,E,{expect:m},n?"reader":"agent")){if(y===rn)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};continue}q(t,E),nt(t,B.wrote(t,E)),n&&U.length&&(d&&d(Ht(o,U).join(`
19
- `)),v(t,U))}return K&&typeof R?.title=="string"&&R.title!==K.to&&await At(e,{from:R.title,to:K.to,synced:K.page}),tt&&!tt.missing&&await _t(e,tt.to),{ok:!0,changes:E===m?[]:U,added:E===m?0:Y,given:E===m?[]:X,repeated:G,written:E!==m,title:K,icon:tt}}}let pn=async(t,{reader:n=!1}={})=>{n&&await kt(t);let e=J.then(()=>Ut(t,{reader:n}));return J=e.catch(()=>{}),e};async function Wt(t){let n=await ut(t);if(n.error)return{refused:n.error};let{slug:e,workspace:o}=n.body??{};return typeof e!="string"||!rt.test(e)||typeof o!="string"?{refused:[400,{ok:!1,reason:"body"}]}:cr(o,l)?{slug:e}:{refused:[409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"}]}}async function wn(t,n){try{let e=J.then(async()=>{let{slug:y,refused:m}=await Wt(t);if(m)return{answer:m};let j=await Ut(y);return{slug:j.ok?y:null,answer:[j.ok?200:j.reason==="missing"?404:409,j]}});J=e.catch(()=>{});let{slug:o,answer:c}=await e;return o&&await Yt(o),C(n,...c)}catch(e){return C(n,500,{ok:!1,reason:"write",message:e.message})}}async function hn(t){let{slug:n,refused:e}=await Wt(t);return e||(await Yt(n),[200,{ok:!0}])}async function re(t){let{source:n}=await kt(t),{ended:e,moved:o}=await B.endDraft(t,n);return o&&f(t),e}async function yn(t){let{slug:n,refused:e}=await Wt(t);return e||[200,{ok:!0,ended:await re(n)}]}let dt=Te({reportsDirectory:l}),xt=Ue({reportsDirectory:l,read:t=>Pt(t,{wait:0}),write:$,dropped:(t,n)=>{let e=n.map(ze);d&&d(Kt(P.join(Z(t),"annotations.json"),{items:e}).join(`
20
- `)),i&&(F=F.then(()=>Ge({stateDirectory:i,reportsDirectory:l,slug:t,time:new Date().toISOString(),items:e})).catch(()=>{}))}}),oe=Promise.resolve(),Bt=t=>{let n=oe.then(t);return oe=n.catch(()=>{}),n},gn=t=>(n,e)=>Bt(()=>t(n)).then(([o,c])=>C(e,o,c),o=>C(e,500,{ok:!1,reason:"write",message:o.message})),kn=300,St=new Map;async function Yt(t){let n=St.get(t);n&&(clearTimeout(n.timer),St.delete(t));let e=Bt(()=>xt.afterWrite(t));n&&e.then(n.resolve,n.reject),await e.catch(o=>d?.(`${t}: annotations not checked: ${o.message}`)),await F}let bn=t=>{let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers["x-gallery-token"]!==p?[403,{ok:!1,reason:"token"}]:null};async function $n(t){if(t.method==="GET"){let e=bn(t);if(e)return e;let o=new URL(t.url??"/","http://localhost").searchParams;return o.get("as")==="copy"?xt.copy(o.get("slug")):xt.list(o.get("slug"))}let n=await ut(t);return n.error??xt.change(n.body)}let Nt=(t,n=Xt)=>async e=>{let o=await ut(e,n);return o.error??t(o.body)};return{token:p,preview:an,opened:sn,check:ut,upload:$t(Nt(dt.upload,gr)),addEmoji:$t(Nt(dt.addEmoji)),unfurl:$t(Nt(dt.unfurl)),annotations:gn($n),checkAnnotations(t){let n=St.get(t);return n||(n={timer:0},n.done=new Promise((e,o)=>Object.assign(n,{resolve:e,reject:o})),St.set(t,n)),clearTimeout(n.timer),n.timer=setTimeout(()=>{St.delete(t),Bt(()=>xt.afterWrite(t)).then(n.resolve,n.reject)},kn),n.done},frameable:$t(Nt(dt.frameable)),listEmojis:dt.listEmojis,readEmoji:dt.readEmoji,respond:$t,keepVersion:q,renameReport:mn,read:Dt,settled:it,writerOf:(t,n)=>typeof n=="string"&&N.get(t)?.hash===_(n)?N.get(t).by:null,whenTaken:kt,readTaken:Pt,takeRewrites:D,handIn:pn,handInReport:Ut,handInRequest:wn,settleRequest:(t,n)=>hn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),settleNotes:Yt,roundRequest:(t,n)=>yn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),beginRound:re,commit:ne(Jt,{early:te}),handleCommit:Jt,setTodos:cn,reverted:ne(fn),changes:dn,noteTaken:(t,n)=>B.look(t,n),forgetChanges:t=>B.forget(t),stored:async()=>{await B.idle(),await F}}}export{Vr as a,qr as b,qe as c,oo as d,vn as e,On as f,jn as g,Uo as h};
13
+ <style data-doc-dev data-ge-margin-style>${yr}</style>
14
+ <script data-doc-dev>document.currentScript.remove(); ${gr(t,{notes:er(P.join(Z(t),ar))})}</script>`;return{html:wr(f),snippet:E,head:U}}let cn=t=>T(_(t),t);function te(t){if(t.method!=="POST")return[405,{ok:!1,reason:"method"}];let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers.origin!==`http://${n}`?[403,{ok:!1,reason:"origin"}]:t.headers["x-gallery-token"]!==p?[403,{ok:!1,reason:"token"}]:null}async function ut(t,n=Xt){let e=te(t);if(e)return{error:e};if(!/^application\/json\b/i.test(t.headers["content-type"]??""))return{error:[415,{ok:!1,reason:"type"}]};try{return{body:JSON.parse(await Or(t,n))}}catch(o){return{error:o.message==="too-large"?[413,{ok:!1,reason:"body",message:$r}]:[400,{ok:!1,reason:"body"}]}}}async function Jt(t,n){let{slug:e,opening:o,known:f=null,texts:y=[],units:m=[],touch:j=[],pageIds:R=null,request:E=null,agent:U=!1}=t;if(typeof e!="string"||!rt.test(e)||![y,m,j].every(Array.isArray))return[400,{ok:!1,reason:"body"}];if(E!==null&&(typeof E!="string"||!Qt.test(E)))return[400,{ok:!1,reason:"body"}];let Y=E===null?null:_(JSON.stringify([o??null,y,m,j])),X=await ee(t);if(X)return X;let G=et=>(E!==null&&r(e,E,Y,et),[200,et]),K=W(e),tt=typeof o=="string"&&Vt.test(o)?await x(o):null,V=et=>tr("sha256",p).update(`${e}
15
+ ${et}`).digest("hex").slice(0,32);for(let et=1;;et++){let{source:at,held:Tt}=await it(e);if(at===null)return[404,{ok:!1,reason:"missing"}];if(Tt)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];nt(e,B.look(e,at));let{text:vt,changes:Zt}=M(at),se=[],Et=be({current:vt,opening:tt,texts:y,units:m,touch:j,ids:u?()=>{let Rt=typeof u=="function"?u():Ct();return se.push(Rt),Rt}:!1,seal:V,pageIds:R}),{title:ie,icon:ce,...fe}=Et,mt=Et.text===vt?vt:k(Et.text);mt!==Et.text&&(fe.version=_(mt));let le={...fe,foreign:typeof f=="string"&&_(vt)!==f};if(mt===vt)return G({ok:!0,...le,wrote:!1,notes:[]});if(q(e,at),!await $(K,mt,{expect:at},U===!0?"agent":"reader")){if(et===on)return[409,{ok:!1,reason:"busy",message:ft}];continue}q(e,mt),nt(e,B.wrote(e,mt,Rt=>{let vn=0;return Ne(Rt,{opening:tt,texts:y,units:m,touch:j,pageIds:R,seal:V,ids:u?()=>se[vn++]??(typeof u=="function"?u():Ct()):!1})},{reader:U!==!0})),Zt.length&&(d&&d(Ht(K,Zt).join(`
16
+ `)),v(e,Zt));let Sn=[...ie?await At(P.dirname(K),ie):[],...ce!==void 0?await _t(P.dirname(K),ce):[]];return G({ok:!0,...le,wrote:!0,notes:Sn})}}async function fn(t,n){return typeof t!="string"||!rt.test(t)?[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}]:!Array.isArray(n)||n.length===0||n.length>lr?[400,{ok:!1,reason:"body"}]:Lt({slug:t},async(e,o)=>{let{source:f,held:y}=await it(t);if(f===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(y)return Date.now()<o?lt:[409,{ok:!1,reason:"busy",message:ft}];let{text:m}=M(f),j=tn(t,f,m,n),{commit:R,changed:E}=en(m,j),U=j.map((V,et)=>V.reason?{ok:!1,reason:V.reason}:{ok:!0,changed:E[et],block:V.unit.blockId??null});if(!R)return[200,{ok:!0,results:U,wrote:!1}];let Y=_(m);T(Y,m);let X=await Jt({slug:t,opening:Y,units:R.units,touch:R.touch},o);if(X===lt)return lt;let[G,K]=X;if(!K.ok)return[G,K];let tt=new Map((K.units??[]).map(V=>[V.key,V]));return[200,{ok:!0,wrote:K.wrote===!0,results:U.map((V,et)=>{if(!V.ok)return V;let at=R.keys.get(j[et].unit.id);if(at===void 0)return V;let Tt=tt.get(at);return Tt?.status!=="applied"?{ok:!1,reason:Tt?.reason==="ambiguous"?"ambiguous":"changed"}:{...V,block:K.ids?.[at]??V.block}})}]})}async function ee({slug:t,opening:n,texts:e=[],units:o=[],touch:f=[],request:y=null}){if(typeof t!="string"||!rt.test(t)||typeof y!="string"||!Qt.test(y)||![e,o,f].every(Array.isArray))return null;let m=await a(t,y);return m?m.digest===_(JSON.stringify([n??null,e,o,f]))?[200,{...m.answer,again:!0}]:[409,{ok:!1,reason:"request",message:"\u540C\u4E00\u6B21\u4FDD\u5B58\u7684\u5185\u5BB9\u4E0D\u4E00\u81F4"}]:null}async function ln(t,n){let{slug:e,opening:o,texts:f=[],units:y=[],instances:m=[],pageIds:j=null}=t;if(typeof e!="string"||!rt.test(e)||!Array.isArray(f)||!Array.isArray(y)||!Array.isArray(m))return[400,{ok:!1,reason:"body"}];let{source:R,held:E}=await it(e);if(E)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];let U=await Dt(e,R);if(U===null)return[404,{ok:!1,reason:"missing"}];let{text:Y,version:X}=U,G=typeof o=="string"&&Vt.test(o)?await x(o):null;return[200,{ok:!0,version:X,reverted:Se({current:Y,opening:G,texts:f,pageIds:j}),units:$e({current:Y,units:y}),parts:xe({current:Y,instances:m,pageIds:j})}]}let un=600*1e3,bt=new Map;async function ne(t,n){let e=Z(t),o=null;try{o=JSON.parse(await z.readFile(Mt(e).json,"utf8"))}catch{}let{title:f,icon:y}=je(n,o);f&&typeof o?.title=="string"&&o.title!==f.to&&await At(e,{from:o.title,to:f.to,synced:!0}),y&&!y.missing&&await _t(e,y.to)}async function dn(t,n){let{slug:e,action:o,stamp:f=null,undo:y=null}=t;if(typeof e!="string"||!rt.test(e)||!["accept","revert","undo"].includes(o))return[400,{ok:!1,reason:"body"}];let m=W(e),{source:j,held:R}=await it(e);if(j===null)return[404,{ok:!1,reason:"missing"}];if(R)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];if(o==="undo"){for(let[K,tt]of bt)Date.now()-tt.at>un&&bt.delete(K);let G=typeof y=="string"?bt.get(y):null;return!G||G.slug!==e?[404,{ok:!1,reason:"gone",message:"\u64A4\u9500\u5DF2\u7ECF\u8FC7\u671F"}]:j!==G.after?[409,{ok:!1,reason:"moved-on",message:"\u64A4\u56DE\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500"}]:(q(e,j),await $(m,G.before,{expect:j})?(q(e,G.before),bt.delete(y),await ne(e,G.before),await B.restore(e,G.saved),await B.wrote(e,G.before),c(e),[200,{ok:!0,version:_(M(G.before).text)}]):[409,{ok:!1,reason:"busy",message:ft}])}await B.look(e,j);let E=await B.snapshot(e),U=E?.state?.base?`${E.state.since}|${E.state.writes}`:null;if(U===null)return[200,{ok:!0,none:!0}];if(U!==f)return[409,{ok:!1,reason:"changed",message:"Agent \u521A\u521A\u53C8\u6539\u4E86\u6587\u6863\uFF0C\u518D\u770B\u4E00\u773C"}];if(o==="accept")return await B.clear(e),c(e),[200,{ok:!0}];let Y=E.base;if(q(e,j),!await $(m,Y,{expect:j}))return[409,{ok:!1,reason:"busy",message:ft}];q(e,Y),await ne(e,Y);let X=qt(8).toString("hex");return bt.set(X,{slug:e,before:j,after:Y,saved:E,at:Date.now()}),await B.clear(e),await B.wrote(e,Y),c(e),[200,{ok:!0,version:_(M(Y).text),undo:X}]}async function mn(t,n){let e=await ut(t);if(e.error)return C(n,...e.error);let o=e.body??{};try{if(o.action!=="read")return C(n,...await Lt(o,dn));if(typeof o.slug!="string"||!rt.test(o.slug))return C(n,400,{ok:!1,reason:"body"});let f=await Pt(o.slug,{wait:0});return f===null?C(n,404,{ok:!1,reason:"missing"}):C(n,200,{ok:!0,...await B.read(o.slug,f.source)})}catch(f){return C(n,500,{ok:!1,reason:"write",message:f.message})}}async function At(t,{from:n,to:e,synced:o}){let f=["\u6807\u9898\u5DF2\u66F4\u65B0",...o?[]:["\u5355\u72EC\u6253\u5F00\u6216\u5BFC\u51FA\u65F6\u7684\u9875\u9762\u540D\u79F0\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"]],y=Mt(t).json,m=await z.readFile(y,"utf8").catch(()=>""),j=null;try{j=JSON.parse(m)}catch{}if(j?.title!==n)return[...f,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"];let R=new RegExp(`("title"\\s*:\\s*)${JSON.stringify(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`),E=R.test(m)?m.replace(R,(U,Y)=>Y+JSON.stringify(e)):`${JSON.stringify({...j,title:e},null,2)}
17
+ `;try{await $(y,E)}catch(U){return d?.(`${P.basename(y)}'s title was not written (${U.code??U.message}): ${y}`),[...f,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u6CA1\u80FD\u8DDF\u7740\u6539"]}return f}async function _t(t,n){let e=Mt(t).json,o=null;try{o=JSON.parse(await z.readFile(e,"utf8"))}catch{}if(!o||typeof o!="object")return d?.(`${P.basename(e)} could not be read, so its icon was not written: ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"];if((o.icon??null)===n)return[];let{icon:f,...y}=o,m=n===null?y:{...y,icon:n};try{await $(e,`${JSON.stringify(m,null,2)}
18
+ `)}catch(j){return d?.(`${P.basename(e)}'s icon was not written (${j.code??j.message}): ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"]}return[]}async function pn(t,n){let e=typeof n=="string"?n.replace(/\s+/g," ").trim():"";if(!e)return{ok:!1,reason:"title",message:"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"};let o=W(t),f=await z.readFile(o,"utf8").catch(()=>null);if(f===null)return{ok:!1,reason:"missing"};nt(t,B.look(t,f));let y=pe(f),m=he(y).find(E=>E.kind==="title");if(!m)return{ok:!1,reason:"no-title",message:"\u8FD9\u4EFD\u6587\u6863\u6CA1\u6709\u6807\u9898"};let j=sr(e),R=ke({current:y,edits:[{id:m.id,parts:[{keep:!0,html:j}]}],ids:u});return R.ok?R.text!==f&&!await $(o,R.text,{expect:f})?{ok:!1,reason:"changed-again"}:(R.text!==f&&nt(t,B.wrote(t,R.text,E=>Te(E,j))),{ok:!0,title:e,notes:R.title?await At(P.dirname(o),R.title):[]}):{ok:!1,reason:"conflict"}}let $t=t=>(n,e)=>{let o=J.then(()=>t(n));return J=o.catch(()=>{}),o.then(([f,y])=>C(e,f,y),f=>C(e,500,{ok:!1,reason:"write",message:f.message}))},re=(t,{early:n=null}={})=>async(e,o)=>{let f=await ut(e);if(f.error)return C(o,...f.error);let y=f.body??{};try{let m=n&&await n(y);return m?C(o,...m):C(o,...await Lt(y,t))}catch(m){return C(o,500,{ok:!1,reason:"write",message:m.message})}};async function Lt(t,n){let e=Date.now()+I;for(;;){await kt(t.slug,e);let o=J.then(()=>n(t,e));J=o.catch(()=>{});let f=await o;if(f!==lt)return f}}async function Ut(t,{reader:n=!1}={}){if(typeof t!="string"||!rt.test(t))return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};let e=Z(t),{html:o,json:f}=Mt(e);for(let y=1;;y++){let{source:m,held:j}=n?await it(t):{source:await z.readFile(o,"utf8").catch(()=>null),held:!1};if(m===null)return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};if(j)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};nt(t,B.look(t,m));let R=null;try{R=JSON.parse(await z.readFile(f,"utf8"))}catch{}let{text:E,changes:U,added:Y,given:X,repeated:G,title:K,icon:tt}=Oe(m,{finish:k,next:typeof u=="function"?u:void 0,metadata:R});if(E!==m){if(q(t,m),!await $(o,E,{expect:m},n?"reader":"agent")){if(y===on)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};continue}q(t,E),nt(t,B.wrote(t,E)),n&&U.length&&(d&&d(Ht(o,U).join(`
19
+ `)),v(t,U))}return K&&typeof R?.title=="string"&&R.title!==K.to&&await At(e,{from:R.title,to:K.to,synced:K.page}),tt&&!tt.missing&&await _t(e,tt.to),{ok:!0,changes:E===m?[]:U,added:E===m?0:Y,given:E===m?[]:X,repeated:G,written:E!==m,title:K,icon:tt}}}let wn=async(t,{reader:n=!1}={})=>{n&&await kt(t);let e=J.then(()=>Ut(t,{reader:n}));return J=e.catch(()=>{}),e};async function Wt(t){let n=await ut(t);if(n.error)return{refused:n.error};let{slug:e,workspace:o}=n.body??{};return typeof e!="string"||!rt.test(e)||typeof o!="string"?{refused:[400,{ok:!1,reason:"body"}]}:fr(o,l)?{slug:e}:{refused:[409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"}]}}async function hn(t,n){try{let e=J.then(async()=>{let{slug:y,refused:m}=await Wt(t);if(m)return{answer:m};let j=await Ut(y);return{slug:j.ok?y:null,answer:[j.ok?200:j.reason==="missing"?404:409,j]}});J=e.catch(()=>{});let{slug:o,answer:f}=await e;return o&&await Yt(o),C(n,...f)}catch(e){return C(n,500,{ok:!1,reason:"write",message:e.message})}}async function yn(t){let{slug:n,refused:e}=await Wt(t);return e||(await Yt(n),[200,{ok:!0}])}async function oe(t){let{source:n}=await kt(t),{ended:e,moved:o}=await B.endDraft(t,n);return o&&c(t),e}async function gn(t){let{slug:n,refused:e}=await Wt(t);return e||[200,{ok:!0,ended:await oe(n)}]}let dt=Ee({reportsDirectory:l}),xt=We({reportsDirectory:l,read:t=>Pt(t,{wait:0}),write:$,dropped:(t,n)=>{let e=n.map(Ge);d&&d(Kt(P.join(Z(t),"annotations.json"),{items:e}).join(`
20
+ `)),i&&(F=F.then(()=>Ke({stateDirectory:i,reportsDirectory:l,slug:t,time:new Date().toISOString(),items:e})).catch(()=>{}))}}),ae=Promise.resolve(),Bt=t=>{let n=ae.then(t);return ae=n.catch(()=>{}),n},kn=t=>(n,e)=>Bt(()=>t(n)).then(([o,f])=>C(e,o,f),o=>C(e,500,{ok:!1,reason:"write",message:o.message})),bn=300,St=new Map;async function Yt(t){let n=St.get(t);n&&(clearTimeout(n.timer),St.delete(t));let e=Bt(()=>xt.afterWrite(t));n&&e.then(n.resolve,n.reject),await e.catch(o=>d?.(`${t}: annotations not checked: ${o.message}`)),await F}let $n=t=>{let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers["x-gallery-token"]!==p?[403,{ok:!1,reason:"token"}]:null};async function xn(t){if(t.method==="GET"){let e=$n(t);if(e)return e;let o=new URL(t.url??"/","http://localhost").searchParams;return o.get("as")==="copy"?xt.copy(o.get("slug")):xt.list(o.get("slug"))}let n=await ut(t);return n.error??xt.change(n.body)}let Nt=(t,n=Xt)=>async e=>{let o=await ut(e,n);return o.error??t(o.body)};return{token:p,preview:sn,opened:cn,check:ut,checkHeaders:te,upload:$t(Nt(dt.upload,kr)),addEmoji:$t(Nt(dt.addEmoji)),unfurl:$t(Nt(dt.unfurl)),annotations:kn(xn),checkAnnotations(t){let n=St.get(t);return n||(n={timer:0},n.done=new Promise((e,o)=>Object.assign(n,{resolve:e,reject:o})),St.set(t,n)),clearTimeout(n.timer),n.timer=setTimeout(()=>{St.delete(t),Bt(()=>xt.afterWrite(t)).then(n.resolve,n.reject)},bn),n.done},frameable:$t(Nt(dt.frameable)),listEmojis:dt.listEmojis,readEmoji:dt.readEmoji,respond:$t,keepVersion:q,renameReport:pn,read:Dt,settled:it,writerOf:(t,n)=>typeof n=="string"&&N.get(t)?.hash===_(n)?N.get(t).by:null,whenTaken:kt,readTaken:Pt,takeRewrites:D,handIn:wn,handInReport:Ut,handInRequest:hn,settleRequest:(t,n)=>yn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),settleNotes:Yt,roundRequest:(t,n)=>gn(t).then(([e,o])=>C(n,e,o),e=>C(n,500,{ok:!1,reason:"write",message:e.message})),beginRound:oe,commit:re(Jt,{early:ee}),handleCommit:Jt,setTodos:fn,reverted:re(ln),changes:mn,noteTaken:(t,n)=>B.look(t,n),forgetChanges:t=>B.forget(t),stored:async()=>{await B.idle(),await F}}}export{qr as a,Xr as b,Xe as c,ao as d,On as e,jn as f,Mn as g,Wo as h};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b}from"./chunk-KTKHRC6H.mjs";import"./chunk-YI43RG4P.mjs";import"./chunk-NAMN3RAF.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-RKPWLGZ3.mjs";import"./chunk-N7AZZLGT.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as nameHint,b as run};
2
+ import{a,b}from"./chunk-ASAXY2DJ.mjs";import"./chunk-HBAUKKQH.mjs";import"./chunk-YPPJVDQI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as nameHint,b as run};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c}from"./chunk-7N2LPG33.mjs";import"./chunk-JJNRIFND.mjs";import"./chunk-ASAXY2DJ.mjs";import"./chunk-HBAUKKQH.mjs";import"./chunk-YPPJVDQI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as DEFAULT_DESCRIPTION,c as run,b as slugRefused};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{c as o}from"./chunk-W7XHE4CT.mjs";var i=class r{static create(e,n,s,c){return new Promise((a,l)=>{let t=new WebSocket(e);t.addEventListener("open",()=>a(new r(t,s))),t.addEventListener("error",l)})}#e;#s;onmessage;onclose;constructor(e,n){this.#e=e,this.#s=n,this.#e.addEventListener("message",s=>{this.onmessage&&this.onmessage.call(null,s.data)}),this.#e.addEventListener("close",()=>{this.onclose&&this.onclose.call(null)}),this.#e.addEventListener("error",()=>{this.#s?.(o.error)})}send(e){this.#e.send(e)}close(){this.#e.close()}};export{i as a};
2
+ import{c as o}from"./chunk-EKGYYOSP.mjs";var i=class r{static create(e,n,s,c){return new Promise((a,l)=>{let t=new WebSocket(e);t.addEventListener("open",()=>a(new r(t,s))),t.addEventListener("error",l)})}#e;#s;onmessage;onclose;constructor(e,n){this.#e=e,this.#s=n,this.#e.addEventListener("message",s=>{this.onmessage&&this.onmessage.call(null,s.data)}),this.#e.addEventListener("close",()=>{this.onclose&&this.onclose.call(null)}),this.#e.addEventListener("error",()=>{this.#s?.(o.error)})}send(e){this.#e.send(e)}close(){this.#e.close()}};export{i as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as p,e as L}from"./chunk-A55HN5OK.mjs";L();import{TODO as b}from"../browser/shared/components/list.mjs";import{sha256 as k}from"../browser/shared/files.mjs";import{attr as u,BLOCK_LEVEL as N,elementsOf as O,hasClass as h}from"../browser/shared/html-tree.mjs";var w=new Set(["script","style","template","noscript","svg","math"]),y=/^h([1-6])$/,C=o=>o.replace(/[\s​]+/g," ").trim();function f(o,a=()=>!1){let n="",t=c=>{for(let s of c.childNodes??[])s.nodeName==="#text"?n+=s.value:s.tagName==="br"?n+=" ":s.tagName&&!w.has(s.tagName)&&!a(s)&&t(s)};return t(o),C(n)}function E(o){let a=f(o,t=>N.has(t.tagName));if(a)return a;let n=O(o).find(t=>N.has(t.tagName)&&t.tagName!=="ul"&&t.tagName!=="ol");return n?f(n,t=>t.tagName==="ul"||t.tagName==="ol"):""}function P(o,{at:a=!1}={}){let n=p(String(o),{sourceCodeLocationInfo:a}),t=[],c=[],s=new Map,l=v=>{for(let e of O(v)){if(w.has(e.tagName))continue;let m=y.exec(e.tagName);if(m&&!h(e,"doc-title")){let i=Number(m[1]);for(;t.length&&t.at(-1).level>=i;)t.pop();let r=f(e);r&&t.push({level:i,words:r});continue}if(e.tagName==="li"&&e.parentNode?.tagName==="ul"&&h(e.parentNode,b)){let i=t.map(({words:x})=>x),r=E(e),d=JSON.stringify([r,i]),g=s.get(d)??0;s.set(d,g+1),c.push({text:r,done:u(e,"data-checked")!==void 0,block:u(e,"data-block-id")??null,path:i,nth:g,...a?{at:e.sourceCodeLocation?.startOffset??-1}:{}})}l(e)}};return l(n),c}var V=o=>k(o).slice(0,16);export{P as a,V as b};
2
+ import{b as p,e as L}from"./chunk-N3DSBH5S.mjs";L();import{TODO as b}from"../browser/shared/components/list.mjs";import{sha256 as k}from"../browser/shared/files.mjs";import{attr as u,BLOCK_LEVEL as N,elementsOf as O,hasClass as h}from"../browser/shared/html-tree.mjs";var w=new Set(["script","style","template","noscript","svg","math"]),y=/^h([1-6])$/,C=o=>o.replace(/[\s​]+/g," ").trim();function f(o,a=()=>!1){let n="",t=c=>{for(let s of c.childNodes??[])s.nodeName==="#text"?n+=s.value:s.tagName==="br"?n+=" ":s.tagName&&!w.has(s.tagName)&&!a(s)&&t(s)};return t(o),C(n)}function E(o){let a=f(o,t=>N.has(t.tagName));if(a)return a;let n=O(o).find(t=>N.has(t.tagName)&&t.tagName!=="ul"&&t.tagName!=="ol");return n?f(n,t=>t.tagName==="ul"||t.tagName==="ol"):""}function P(o,{at:a=!1}={}){let n=p(String(o),{sourceCodeLocationInfo:a}),t=[],c=[],s=new Map,l=v=>{for(let e of O(v)){if(w.has(e.tagName))continue;let m=y.exec(e.tagName);if(m&&!h(e,"doc-title")){let i=Number(m[1]);for(;t.length&&t.at(-1).level>=i;)t.pop();let r=f(e);r&&t.push({level:i,words:r});continue}if(e.tagName==="li"&&e.parentNode?.tagName==="ul"&&h(e.parentNode,b)){let i=t.map(({words:x})=>x),r=E(e),d=JSON.stringify([r,i]),g=s.get(d)??0;s.set(d,g+1),c.push({text:r,done:u(e,"data-checked")!==void 0,block:u(e,"data-block-id")??null,path:i,nth:g,...a?{at:e.sourceCodeLocation?.startOffset??-1}:{}})}l(e)}};return l(n),c}var V=o=>k(o).slice(0,16);export{P as a,V as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as p,d as m}from"./chunk-UKSHDZZ6.mjs";import{p as d}from"./chunk-D4EURAX4.mjs";import c from"node:fs";import u from"node:os";import s from"node:path";import{refusal as o,said as t}from"../browser/shared/i18n/index.mjs";var f=64*1024*1024,l=2e3;function h(i){let r;try{r=m(i)}catch{throw o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}try{let e=r.entries;if(e.length>l||e.reduce((n,{size:a})=>n+a,0)>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});return e.map(n=>({name:n.name,data:Buffer.from(r.read(n))}))}catch(e){throw e.code?e:o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}finally{r.close()}}function g(i){let r=s.resolve(String(i??"").trim().replace(/^"(.*)"$/,"$1")),e;try{e=c.statSync(r)}catch{throw o(t("\u627E\u4E0D\u5230 {0}",r),{code:"missing"})}if(e.isDirectory())return d(r);if(!e.isFile())throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});let n=Buffer.alloc(4),a=c.openSync(r,"r");try{c.readSync(a,n,0,4,0)}finally{c.closeSync(a)}if(!p(n))throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});return h(r)}function B(i){if(!p(i))throw o(t("\u9009\u7684\u6587\u4EF6\u4E0D\u662F zip"),{code:"kind"});if(i.length>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});let r=c.mkdtempSync(s.join(u.tmpdir(),"gallery-pack-")),e=s.join(r,"pack.zip");try{return c.writeFileSync(e,i),h(e)}finally{c.rmSync(r,{recursive:!0,force:!0})}}export{g as a,B as b};
2
+ import{b as p,d as m}from"./chunk-2OHANJ6Q.mjs";import{q as d}from"./chunk-LE44MD3O.mjs";import c from"node:fs";import u from"node:os";import s from"node:path";import{refusal as o,said as t}from"../browser/shared/i18n/index.mjs";var f=64*1024*1024,l=2e3;function h(i){let r;try{r=m(i)}catch{throw o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}try{let e=r.entries;if(e.length>l||e.reduce((n,{size:a})=>n+a,0)>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});return e.map(n=>({name:n.name,data:Buffer.from(r.read(n))}))}catch(e){throw e.code?e:o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}finally{r.close()}}function g(i){let r=s.resolve(String(i??"").trim().replace(/^"(.*)"$/,"$1")),e;try{e=c.statSync(r)}catch{throw o(t("\u627E\u4E0D\u5230 {0}",r),{code:"missing"})}if(e.isDirectory())return d(r);if(!e.isFile())throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});let n=Buffer.alloc(4),a=c.openSync(r,"r");try{c.readSync(a,n,0,4,0)}finally{c.closeSync(a)}if(!p(n))throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});return h(r)}function B(i){if(!p(i))throw o(t("\u9009\u7684\u6587\u4EF6\u4E0D\u662F zip"),{code:"kind"});if(i.length>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});let r=c.mkdtempSync(s.join(u.tmpdir(),"gallery-pack-")),e=s.join(r,"pack.zip");try{return c.writeFileSync(e,i),h(e)}finally{c.rmSync(r,{recursive:!0,force:!0})}}export{g as a,B as b};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a}from"./chunk-Y34NR5JL.mjs";import"./chunk-W7XHE4CT.mjs";import"./chunk-5L7RYZCL.mjs";export{a as BrowserWebSocketTransport};
2
+ import{a}from"./chunk-QJ3TFJLQ.mjs";import"./chunk-EKGYYOSP.mjs";import"./chunk-5L7RYZCL.mjs";export{a as BrowserWebSocketTransport};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as w}from"./chunk-JEUK3ZO7.mjs";import{a as te}from"./chunk-ZUNVAXLH.mjs";import{d as F,e as W}from"./chunk-N7AZZLGT.mjs";import{a as H,b as L,d as G,e as $,f as E,g as R,h as U,i as q,j as Y,o as V,q as X,r as Q,s as Z}from"./chunk-D4EURAX4.mjs";import{a as P,b as d,f as ee}from"./chunk-4OZWXZE5.mjs";import{i as K}from"./chunk-OW5NWPOJ.mjs";import{f as S,j as C,s as _,t as B,v as j}from"./chunk-FWNRPMCJ.mjs";import v from"node:fs";import N from"node:path";import{blocksHidden as $e}from"../browser/editor/components/registry.mjs";import{inLanguage as be,told as ve}from"../browser/shared/i18n/index.mjs";import{PACK_ID as xe}from"../browser/shared/pack-manifest.mjs";import{readKeys as Se,writeKey as se}from"../browser/shared/net-keys.mjs";import{HOST as Ne,netHostsOf as Oe}from"../browser/shared/net-policy.mjs";import{PACKAGE_ID as je,SLOT as Ee}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as Ae,layoutOf as A,PACKAGE_MANIFEST as ie,shallowPackages as le}from"../browser/shared/workspace.mjs";var fe=(e,t,{script:o,flow:n,data:a,page:s})=>`{
2
+ import{a as w}from"./chunk-JEUK3ZO7.mjs";import{a as te}from"./chunk-QXVNUASA.mjs";import{d as F,e as W}from"./chunk-2GKGEVMR.mjs";import{a as H,b as L,d as G,e as $,f as E,g as R,h as U,i as q,j as Y,o as V,r as X,s as Q,t as Z}from"./chunk-LE44MD3O.mjs";import{a as P,b as d,f as ee}from"./chunk-4OZWXZE5.mjs";import{i as K}from"./chunk-SAHS56QM.mjs";import{f as S,j as C,s as _,t as B,v as j}from"./chunk-VG5JEIUQ.mjs";import v from"node:fs";import N from"node:path";import{blocksHidden as $e}from"../browser/editor/components/registry.mjs";import{inLanguage as be,told as ve}from"../browser/shared/i18n/index.mjs";import{PACK_ID as xe}from"../browser/shared/pack-manifest.mjs";import{readKeys as Se,writeKey as se}from"../browser/shared/net-keys.mjs";import{HOST as Ne,netHostsOf as Oe}from"../browser/shared/net-policy.mjs";import{PACKAGE_ID as je,SLOT as Ee}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as Ae,layoutOf as A,PACKAGE_MANIFEST as ie,shallowPackages as le}from"../browser/shared/workspace.mjs";var fe=(e,t,{script:o,flow:n,data:a,page:s})=>`{
3
3
  "id": "${e}",
4
4
  "apiVersion": 1,
5
5
  "version": "0.1.0",
@@ -167,4 +167,4 @@ DocKit.component({
167
167
  });
168
168
  `;function ne(e,{script:t=!1,flow:o=!1,data:n=!1,page:a=!1}={}){let s=e.split("/")[1],l={script:t||n,flow:o,data:n,page:a};return{"component.json":fe(e,s,l),"template.html":oe(e,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",{blocks:o&&["<p></p>"],json:n&&'{"items":[]}'}),"example.html":oe(e,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",{blocks:o&&we,json:n&&'{"items":[{"text":"\u7B2C\u4E00\u6761"},{"text":"\u7B2C\u4E8C\u6761"}]}'}),"writing.md":ue(e,s,l),"style.css":ge(e,l),...l.script?{"kit.js":n?ye(e):ke(e)}:{}}}var x="local";function re(e){let t=e.includes("/")?e:`${x}/${e}`;if(!je.test(t))throw new d(`Not a block's id: ${e} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${x}/<name>).`);let o=t.split("/").find(n=>Ae.has(n));if(o)throw new d(`Not a block's id: ${e} (Windows keeps ${o} for a device).`);return t}function Ie(e,t){let o=re(t),n=t.includes("/")?null:$(t);if(!n)return o;let a=S(e);return a.packages.has(o)||a.problems.has(o)||v.existsSync(M(e,o))?o:n.id}var M=(e,t)=>N.join(A(e).components,...t.split("/")),u=e=>e.pack===H?e.name:e.id,z=()=>G().map(u).join(", "),ce=({name:e,file:t})=>`${w(t)} is one level too shallow, and no catalog reads it: a custom block is components/<scope>/<name>/, so move it to components/${x}/${e}/`;function Ce(e,t){let o=le(e).find(({name:s})=>s===t.split("/")[1]),n=E(t)&&$(t);if(n)return`No block ${t} in ${w(A(e).components)}: it is one of Gallery's own, which gallery block add ${u(n)} puts in.`;let a=t.startsWith(`${x}/`)?$(t.slice(x.length+1)):null;return o?ce(o):`No block ${t} in ${w(A(e).components)}: gallery block list says which there are${a?`; Gallery has a block of that name, ${a.id}`:""}.`}function Ge(e,t,{script:o,flow:n,data:a,page:s,recipe:l}){let r=t.split("/")[0],m=$(t);if(E(t))throw new d(`The scope ${r}/ is kept for Gallery's own blocks: give yours another (${x}/<name>, or a <name> alone)${m?`; gallery block add ${u(m)} puts Gallery's in, and gallery block new <id> --recipe ${u(m)} starts one of yours from it`:""}.`);if(R(e).packs?.[r])throw new d(`The scope ${r}/ is the pack ${r}'s, which gallery block pack install put in (installing it again would not keep a block of yours there): give yours another (${x}/<name>, or a <name> alone).`);let h=l===void 0?null:$(l);if(l!==void 0&&!h)throw new d(`No block of Gallery's own is called ${l}: ${z()||"none"}.`);let f=M(e,t);if(v.existsSync(f)||S(e).problems.has(t)){let c=!v.existsSync(N.join(f,ie));console.error(c?`A folder is there with no component.json: ${w(f)}: move it, or give this block another name.`:`Block already exists: ${w(f)}: gallery block show ${t} says what it is; give a new one another name.`),process.exit(1)}let i=h?V(h,t):ne(t,{script:o,flow:n,data:a,page:s});try{v.mkdirSync(f,{recursive:!0});for(let c of L(Object.keys(i)))v.mkdirSync(N.dirname(N.join(f,c)),{recursive:!0}),v.writeFileSync(N.join(f,c),i[c])}catch(c){if(!c.code)throw c;console.error(`Cannot write ${w(f)} (${c.code}).`),process.exit(1)}if(console.log(`Created ${w(f)}: ${Object.keys(i).join(", ")}`),h){console.log(`Made from Gallery's ${h.id} ${h.version}, every word that named it naming ${t}: change its name, words and description in component.json first (two blocks of one name read alike in "/"), and in the same files what is still ${h.name}'s: preview.svg (the picture the menu shows beside the description, still ${h.name}'s drawing: draw yours or delete it), writing.md (how to write it, still about ${h.name}) and example.html (the instance check runs and show prints, still ${h.name}'s words), then what you came for (references/building-blocks.md has every field and the rules), and run gallery block check ${t}, which passes as it stands now.`);return}let p=o||a;console.log(`Next: say in component.json what it is (its name, description and parts), write template.html, what ${s?"a custom page's \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 puts on it":'"/" puts in a document'}, and example.html, an instance as a writer would fill it, then writing.md and style.css${p?" and kit.js":""} (references/building-blocks.md has every field and the rules${n?", and Slots what its slot body holds":""}${s?"; references/pages-and-data.md a card's size and settings and what it reads":""}${p?"; references/block-script.md its script and how it writes back":""}), and run gallery block check ${t}, which passes as it stands now.`),a&&console.log("It keeps a list of lines (the part items, a script of JSON on one line, as context.editJSON writes it): kit.js reads it with context.readJSON and writes it with context.editJSON, from a field (DocKit.input) and a button, hidden where nothing is written; example() adds a line by the function the field calls, and works on template.html's empty instance. Rename the part, the fields of its JSON and the controls for what the block keeps."),s?console.log(`It is a custom page's card (places ["page"], a card of two sizes): gallery page add <slug> ${t} puts one on a page, then gallery page try <slug> <card id> <gesture> tries a reader's gesture on it${a?' (--type .component-field "words" --then Enter)':""}; for a document too, put "document" in places.`):a&&console.log(`In a document: write the element as example.html does, then gallery block try <slug> --type .component-field "words" --then Enter tries the field (the part and the class are the scaffold's: rename them with the block).`)}function Pe(e,t){let o=$(t);if(!o)throw new d(`No block of Gallery's own is called ${t}: ${z()||"none"} (gallery block list says each).`);let n;try{n=q(e,o)}catch(s){if(s.code!=="changed")throw s;console.error(`${w(s.folder)} was changed after gallery block add put it there (or another hand put it there), so it is not replaced: to keep those changes, make a block of your own from Gallery's with gallery block new <id> --recipe ${u(o)} and move them into it; to take Gallery's ${o.version}, delete the folder and run gallery block add ${u(o)} again.`),process.exit(1)}let a=o.places.includes("document")?`a document can write it now (gallery block show ${o.id} says how)`:"custom pages can place it now";n.did==="same"?console.log(`${o.id} ${o.version} is in already, as Gallery ships it: ${w(n.folder)}`):n.did==="updated"?console.log(`Updated ${o.id} from ${n.from??"an older version"} to ${o.version}: ${w(n.folder)}`):console.log(`Added ${o.id} ${o.version}: ${w(n.folder)}`),n.did!=="same"&&console.log(`It is Gallery's, as it ships: no check or try is needed, and ${a}. Change nothing in its folder, or gallery block add will not update it again: for a block like it of your own, gallery block new <id> --recipe ${u(o)}.`)}var k=({zh:e,en:t})=>e===t?e:`${e} / ${t}`;function Ke(e){if(B(e))return null;let t=_(e);return t?C("en",t):"it has no template.html"}var Je={disabled:"disabled by the user: its instances show as they stand, no script and no style"},I=e=>e?.length?` \u8981\u7528\uFF1A${e.join(", ")}`:"";function ae(e,{id:t,name:o,version:n,description:a,state:s,needs:l},r){console.log(`${t} ${k(o)}`);let h=(e.settings.packsOff??[]).includes(t.split("/")[0])?`available; its pack ${t.split("/")[0]} is switched off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, so no menu or library offers it, and a document can still write it`:r==="document"&&s==="hidden"?"available; not in the document's menus, by the user's switch, and a document can still write it":"available";console.log(` \u7248\u672C\uFF1A${n}\uFF08${h}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(a)}`),I(l)&&console.log(I(l));let f=r==="document"&&Ke(e.packages.get(t));f&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${f}`)}function Te(e){let t=S(e),o=j(t),n=o.filter(({reason:i})=>i),a=o.filter(({reason:i})=>!i),s=a.filter(({state:i})=>i!=="disabled"),l=s.filter(({places:i})=>i.includes("document")),r=s.filter(({places:i})=>i.includes("page")),m=le(e),h=G().map(i=>({block:i,state:U(e,i)})).filter(({block:i,state:p})=>!p.added||p.behind||p.changed&&Y(i.version,p.version)),f=$e(t.settings.hidden);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),a.length+n.length+m.length===0)console.log("No custom blocks yet. A document is written with Gallery's blocks and whole blocks; gallery block add <name> puts one of Gallery's own in (below), and gallery block new <id> starts one when the user wants a block to use again.");else{console.log(l.length?`\u6587\u6863\u91CC\u53EF\u7528 (in documents: ${l.length}; gallery block show <id> says how to write each):`:"\u6587\u6863\u91CC\u53EF\u7528 (in documents): none now.");for(let p of l)ae(t,p,"document");console.log(r.length?`\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages: ${r.length}):`:"\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages): none now.");for(let p of r)p.places.includes("document")?console.log(`${p.id} ${k(p.name)} (above: in documents too)`):ae(t,p,"page");let i=a.filter(({state:p})=>p==="disabled");i.length+n.length+m.length>0&&console.log("Not to use now:");for(let{id:p,name:c,version:y,state:O}of i)console.log(`${p} ${k(c)} ${y} ${Je[O]}`);for(let{id:p,reason:c,version:y}of n)console.log(`${p}${y?` ${y}`:""} does not load: ${c.en}`);for(let p of m)console.log(ce(p))}h.length&&console.log("Gallery's own blocks, to add as they are (no check or try needed):");for(let{block:i,state:p}of h){let c=i.places.map(y=>y==="document"?"documents":"custom pages").join(" and ");console.log(`${i.id} ${k(i.title)} ${i.version} (${c})`),console.log(` \u8BF4\u660E\uFF1A${k(i.description)}`),p.changed?console.log(` the workspace's copy (${p.version??"no version"}) was changed after it was added, so it is not updated: to take Gallery's ${i.version}, delete ${w(M(e,i.id))} and run gallery block add ${u(i)} (to keep the changes, gallery block new <id> --recipe ${u(i)} and move them into it)`):console.log(p.added?` gallery block add ${u(i)} (the workspace has ${p.version??"an older one"}: this updates it)`:` gallery block add ${u(i)}`)}f.length&&console.log(`Built-in blocks the user took out of the document's menus (a document can still write them): ${f.join(", ")}`)}var De=(e,{at:t,edit:o,optional:n,min:a,max:s})=>{let l=[n?"optional":"",a!==void 0?`at least ${a}`:"",s!==void 0?`at most ${s}`:""].filter(Boolean),r=o==="flow"?`${Ee}="${e}"`:t;return` ${e} ${r} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${l.length?` (${l.join(", ")})`:""}`};function de(e,t,o){console.log(`${t} ${k(e.name)}`),console.log(` \u7248\u672C\uFF1A${e.version}\uFF08${o}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(e.description)}`),console.log(` \u7528\u5728\uFF1A${e.places.map(l=>l==="document"?"documents":"custom pages").join(", ")}`),I(e.needs)&&console.log(I(e.needs)),console.log(` ${w(e.folder)}`);let n=Object.entries(e.parts);console.log(n.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[l,r]of n)console.log(De(l,r));let a=K(e,"writing.md")?.trimEnd();console.log(a?`How to write it (writing.md):
169
169
  ${a}`:"How to write it: the block has no writing.md.");let s=K(e,"example.html")?.trimEnd();console.log(s?`The example (example.html):
170
- ${s}`:"The example: the block has no example.html.")}function Me(e,t){let o=S(e),n=o.problems.get(t),a=o.packages.get(t)??(n?.off?n:void 0);if(!a){let r=n?.problem,m=!r&&E(t)?$(t):null;if(m)return Fe(m);console.error(r?`${t} does not load: ${C("en",r)}`:Ce(e,t)),process.exit(1)}let{state:s}=j(o).find(r=>r.id===t),l={normal:"available",hidden:"available; not in the document's menus, by the user's switch",disabled:"disabled by the user"}[s]??s;de(a,t,l),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}async function ze(e,t,o,{remove:n}){let a=Se(e);if(t===void 0){let s=[...new Set(j(S(e)).flatMap(({needs:m})=>Oe(m??[])))],l=Object.keys(a).sort();console.log(l.length?`Keys kept (.gallery/keys.json), by host: ${l.join(", ")}.`:"No key kept (.gallery/keys.json holds none).");let r=s.filter(m=>!l.includes(m)).sort();r.length&&console.log(`Hosts the workspace's blocks reach with no key: ${r.join(", ")} (a key is needed only where a block's address names {key}).`);return}if(!Ne.test(t))throw new d(`Not a host a block's needs can name: ${t} (a lowercase name, no scheme, port or path; *. before it for the names under it).`);if(n){if(o!==void 0)throw new d("gallery block key <host> --remove takes no key.");return t in a?(await se(e,t,null),console.log(`Took away the key for ${t}. A block's address that names {key} on it is refused (code "key") until one is kept again.`)):console.log(`No key kept for ${t}: nothing to take away.`)}if(o===void 0)return console.log(t in a?`A key is kept for ${t} (never printed): an address on it that names {key} is fetched with it.`:`No key kept for ${t}: gallery block key ${t} <key> keeps one.`);if(!o.trim()||/[\r\n]/.test(o))throw new d("A key is one line of characters, not empty.");await se(e,t,o),console.log(`Kept the key for ${t} in ${w(A(e).keys)}, which no page, export or cache holds: Gallery writes it where a block's address on ${t} names {key}, as it fetches for the block. Never write the key into a block's files or a page: they are shown and exported.`)}function Fe(e){let t=JSON.parse(v.readFileSync(N.join(e.folder,ie),"utf8"));de({name:e.title,description:e.description,version:e.version,places:e.places,needs:t.needs,folder:e.folder,parts:t.parts??{}},e.id,"Gallery's own, not in this workspace yet");let o=e.places.includes("document")?", and a document writes it as the example above does, straight in the page or a section, with no data-block-id, which the export gives it":`, and gallery page add <slug> ${u(e)} puts a card of it on a custom page`;console.log(`Not in this workspace yet: gallery block add ${u(e)} puts it in as it ships (no check, no try)${o}.`)}var he=e=>be("en",()=>ve(e))??e.message,J=(e,t)=>t.length?[` ${e}: ${t.join(", ")}`]:[];function We(e,t){let o;try{o=X(e,te(t))}catch(a){if(!a.code)throw a;console.error(`Not installed: ${he(a)}`),process.exit(1)}let n=o.added.length+o.updated.length+o.same.length+o.kept.length;o.from===null?console.log(`Installed the pack ${o.id} ${o.version} (${k(o.name)}), ${n} block${n===1?"":"s"}: ${w(o.folder)}`):o.did==="updated"?console.log(`Updated the pack ${o.id} from ${o.from??"an older version"} to ${o.version}: ${w(o.folder)}`):console.log(`The pack ${o.id} ${o.version} is in already, as installed: ${w(o.folder)}`);for(let a of[...J("added",o.added),...o.did==="updated"?J("updated",o.updated):[],...J("taken out (not in this version)",o.removed)])console.log(a);o.kept.length&&console.log(` kept as they are, changed since they were installed: ${o.kept.join(", ")} (to take this version's, delete the block's folder and install the pack again)`),o.ownKept&&console.log(" its pack.json was changed since it was installed, and is kept as it is"),console.log(`Its blocks are offered in "/" and \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 while its switch in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 is on (gallery block pack list says each pack's); gallery block list says each block.`)}function D(e){let t=Z(e);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),t.length===0)return console.log("No block packs: gallery block pack install <folder|zip> installs one.");let o={official:"Gallery's own",installed:"a pack installed",own:"the workspace's own blocks, no pack.json"};for(let n of t){let a=[n.version?`${n.id} ${n.version}`:n.id,o[n.kind],n.enabled?"on":"off",`${n.blocks} block${n.blocks===1?"":"s"}`,...n.author?[`by ${n.author}`]:[]];console.log(`${k(n.name)} (${a.join(", ")})`),n.description&&console.log(` \u8BF4\u660E\uFF1A${k(n.description)}`),n.problem&&console.log(` its pack.json does not read: ${n.problem.en}`),n.changed.length&&console.log(` changed since it was installed: ${n.changed.join(", ")}${n.newer?` (Gallery's is ${n.newer}, not put over them)`:""}`)}}function _e(e,t){if(!xe.test(t))throw new d(`Not a pack's id: ${t} (lowercase letters, digits and hyphens: gallery block pack list says each).`);let o;try{o=Q(e,t)}catch(n){if(!n.code)throw n;console.error(`Not removed: ${he(n)}`),process.exit(1)}console.log(`Removed the pack ${o.id}${o.version?` ${o.version}`:""} (${o.blocks.length} block${o.blocks.length===1?"":"s"}): what documents and pages hold of its blocks stays, shown as blocks that are not there.`)}var T={install:We,list:D,remove:_e};function Be(e,t,o){if(!t)throw new d("Say what to do with packs: install <folder|zip>, list, remove <pack>.");if(!Object.hasOwn(T,t))throw new d(`No such pack command: ${t} (install, list, remove).`);if(T[t]===D){if(o.length)throw new d("gallery block pack list takes nothing else.");return D(e)}if(o.length!==1)throw new d(t==="install"?"gallery block pack install takes one folder or zip: gallery block pack install <folder|zip>.":"gallery block pack remove takes one pack's id: gallery block pack remove <pack>.");return T[t](e,o[0])}var g={new:(e,t,o)=>Ge(e,t,o),add:Pe,list:Te,show:Me,check:async(e,t,{documents:o})=>(await import("./chunk-VS3ZMVGX.mjs")).checkCommand(e,t,{documents:o}),try:async(e,t)=>(await import("./chunk-CRJEG7MT.mjs")).tryCommand(e,t),key:ze,pack:Be},He=["--press","--drag","--to","--key","--type","--select","--then","--steps"],Le={"--key":"--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).","--type":"--type takes a selector and the words to type: --type <selector> <words> (quoted when they hold a blank).","--select":"--select takes a selector and an option: --select <selector> <value> (the option's value or its words)."};function pe(e){let t=e.indexOf("--"),o=new Set,n={};for(let[a,s]of Object.entries(Le)){let l=(t===-1?e:e.slice(0,t)).findIndex(h=>h===a||h.startsWith(`${a}=`));if(l===-1)continue;let r=l+(e[l].includes("=")?1:2),m=e[r];if(m===void 0||r===t||P(m)||o.has(r))throw new d(s);o.add(r),n[a]=m}return{argv:e.filter((a,s)=>!o.has(s)),seconds:n}}function pt(e){let{argv:t,seconds:o}=pe(e);return{argv:t,key:o["--key"]??null}}async function mt(e,{workspace:t}){try{return await Re(e,t)}catch(o){let n=e.find(a=>!P(a));throw o instanceof d&&n==="try"&&(o.synopsis=F),o instanceof d&&n==="pack"&&(o.synopsis=W),o}}async function Re(e,t){let{argv:o,seconds:n}=pe(e),{positional:a,options:s,values:l}=ee({options:["--script","--flow","--data","--page","--keep","--documents","--replace","--remove"],values:[...He,"--recipe"],argv:o}),r=l.get("--recipe"),m=new Map([...l].filter(([b])=>b!=="--recipe")),[h,f,...i]=a,p=Object.keys(g).join(", ");if(!h)throw new d(`Say what to do: ${p}.`);if(!Object.hasOwn(g,h))throw new d(`No such block command: ${h} (${p}).`);let c=g[h];for(let b of["--script","--flow","--data","--page"])if(s.has(b)&&c!==g.new)throw new d(`${b} goes with new, not ${h}.`);if(s.has("--documents")&&c!==g.check)throw new d(`--documents goes with check, not ${h}.`);if(s.has("--remove")&&c!==g.key)throw new d(`--remove goes with key, not ${h}.`);if(r!==void 0&&c!==g.new)throw new d(`--recipe goes with new, not ${h}.`);let y=["--script","--flow","--data","--page"].filter(b=>s.has(b));if(r!==void 0&&y.length)throw new d(`--recipe makes a block of what Gallery's ${r} holds: ${y[0]} goes with a new block of none.${y[0]==="--page"&&$(r)?.places.includes("page")?` ${r} already is a card for a custom page (its places hold page): leave --page out.`:""}`);if(s.has("--flow")&&s.has("--data"))throw new d("--flow and --data do not go together: --flow is a slot for blocks of the document's own, --data a list of lines a reader keeps in the block's JSON. Make the one you need with new, and add the other by hand.");if(s.has("--flow")&&s.has("--page"))throw new d("--flow and --page do not go together: a custom page renders no document's blocks, so a block for a page has no slot.");let O=[...m.keys(),...Object.keys(n).filter(b=>!m.has(b)),...s.has("--keep")?["--keep"]:[],...s.has("--replace")?["--replace"]:[]];if(c===g.try)return c(t,{named:a.slice(1),values:m,seconds:n,keep:s.has("--keep"),replace:s.has("--replace")});if(O.length)throw new d(`${O[0]} goes with try, not ${h}.`);if(c===g.list){if(f!==void 0)throw new d(`gallery block ${h} takes nothing else.`);return c(t)}if(c===g.pack)return c(t,f,i);if(c===g.key){if(i.length>1)throw new d("gallery block key takes a host and its key: gallery block key <host> <key>.");return c(t,f,i[0],{remove:s.has("--remove")})}if(c===g.add){if(f===void 0||i.length>0)throw new d(`gallery block add takes one name of Gallery's own blocks: ${z()}.`);return c(t,f)}if(f===void 0||i.length>0)throw new d(`gallery block ${h} takes one id.`);let me=c===g.show||c===g.check?Ie(t,f):re(f);return c(t,me,{script:s.has("--script"),flow:s.has("--flow"),data:s.has("--data"),page:s.has("--page"),documents:s.has("--documents"),recipe:r})}export{re as a,Ie as b,M as c,u as d,ce as e,Ce as f,He as g,pe as h,pt as i,mt as j};
170
+ ${s}`:"The example: the block has no example.html.")}function Me(e,t){let o=S(e),n=o.problems.get(t),a=o.packages.get(t)??(n?.off?n:void 0);if(!a){let r=n?.problem,m=!r&&E(t)?$(t):null;if(m)return Fe(m);console.error(r?`${t} does not load: ${C("en",r)}`:Ce(e,t)),process.exit(1)}let{state:s}=j(o).find(r=>r.id===t),l={normal:"available",hidden:"available; not in the document's menus, by the user's switch",disabled:"disabled by the user"}[s]??s;de(a,t,l),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}async function ze(e,t,o,{remove:n}){let a=Se(e);if(t===void 0){let s=[...new Set(j(S(e)).flatMap(({needs:m})=>Oe(m??[])))],l=Object.keys(a).sort();console.log(l.length?`Keys kept (.gallery/keys.json), by host: ${l.join(", ")}.`:"No key kept (.gallery/keys.json holds none).");let r=s.filter(m=>!l.includes(m)).sort();r.length&&console.log(`Hosts the workspace's blocks reach with no key: ${r.join(", ")} (a key is needed only where a block's address names {key}).`);return}if(!Ne.test(t))throw new d(`Not a host a block's needs can name: ${t} (a lowercase name, no scheme, port or path; *. before it for the names under it).`);if(n){if(o!==void 0)throw new d("gallery block key <host> --remove takes no key.");return t in a?(await se(e,t,null),console.log(`Took away the key for ${t}. A block's address that names {key} on it is refused (code "key") until one is kept again.`)):console.log(`No key kept for ${t}: nothing to take away.`)}if(o===void 0)return console.log(t in a?`A key is kept for ${t} (never printed): an address on it that names {key} is fetched with it.`:`No key kept for ${t}: gallery block key ${t} <key> keeps one.`);if(!o.trim()||/[\r\n]/.test(o))throw new d("A key is one line of characters, not empty.");await se(e,t,o),console.log(`Kept the key for ${t} in ${w(A(e).keys)}, which no page, export or cache holds: Gallery writes it where a block's address on ${t} names {key}, as it fetches for the block. Never write the key into a block's files or a page: they are shown and exported.`)}function Fe(e){let t=JSON.parse(v.readFileSync(N.join(e.folder,ie),"utf8"));de({name:e.title,description:e.description,version:e.version,places:e.places,needs:t.needs,folder:e.folder,parts:t.parts??{}},e.id,"Gallery's own, not in this workspace yet");let o=e.places.includes("document")?", and a document writes it as the example above does, straight in the page or a section, with no data-block-id, which the export gives it":`, and gallery page add <slug> ${u(e)} puts a card of it on a custom page`;console.log(`Not in this workspace yet: gallery block add ${u(e)} puts it in as it ships (no check, no try)${o}.`)}var he=e=>be("en",()=>ve(e))??e.message,J=(e,t)=>t.length?[` ${e}: ${t.join(", ")}`]:[];function We(e,t){let o;try{o=X(e,te(t))}catch(a){if(!a.code)throw a;console.error(`Not installed: ${he(a)}`),process.exit(1)}let n=o.added.length+o.updated.length+o.same.length+o.kept.length;o.from===null?console.log(`Installed the pack ${o.id} ${o.version} (${k(o.name)}), ${n} block${n===1?"":"s"}: ${w(o.folder)}`):o.did==="updated"?console.log(`Updated the pack ${o.id} from ${o.from??"an older version"} to ${o.version}: ${w(o.folder)}`):console.log(`The pack ${o.id} ${o.version} is in already, as installed: ${w(o.folder)}`);for(let a of[...J("added",o.added),...o.did==="updated"?J("updated",o.updated):[],...J("taken out (not in this version)",o.removed)])console.log(a);o.kept.length&&console.log(` kept as they are, changed since they were installed: ${o.kept.join(", ")} (to take this version's, delete the block's folder and install the pack again)`),o.ownKept&&console.log(" its pack.json was changed since it was installed, and is kept as it is"),console.log(`Its blocks are offered in "/" and \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 while its switch in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 is on (gallery block pack list says each pack's); gallery block list says each block.`)}function D(e){let t=Z(e);console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let o={default:"the default pack, where a block made with no pack named goes",official:"Gallery's own",installed:"a pack installed",own:"the workspace's own blocks, no pack.json"};for(let n of t){let a=[n.version?`${n.id} ${n.version}`:n.id,o[n.kind],n.enabled?"on":"off",`${n.blocks} block${n.blocks===1?"":"s"}`,...n.author?[`by ${n.author}`]:[]];console.log(`${k(n.name)} (${a.join(", ")})`),n.description&&console.log(` \u8BF4\u660E\uFF1A${k(n.description)}`),n.problem&&console.log(` its pack.json does not read: ${n.problem.en}`),n.changed.length&&console.log(` changed since it was installed: ${n.changed.join(", ")}${n.newer?` (Gallery's is ${n.newer}, not put over them)`:""}`)}t.every(({kind:n})=>n==="default")&&console.log("No other block packs: gallery block pack install <folder|zip> installs one.")}function _e(e,t){if(!xe.test(t))throw new d(`Not a pack's id: ${t} (lowercase letters, digits and hyphens: gallery block pack list says each).`);let o;try{o=Q(e,t)}catch(n){if(!n.code)throw n;console.error(`Not removed: ${he(n)}`),process.exit(1)}console.log(`Removed the pack ${o.id}${o.version?` ${o.version}`:""} (${o.blocks.length} block${o.blocks.length===1?"":"s"}): what documents and pages hold of its blocks stays, shown as blocks that are not there.`)}var T={install:We,list:D,remove:_e};function Be(e,t,o){if(!t)throw new d("Say what to do with packs: install <folder|zip>, list, remove <pack>.");if(!Object.hasOwn(T,t))throw new d(`No such pack command: ${t} (install, list, remove).`);if(T[t]===D){if(o.length)throw new d("gallery block pack list takes nothing else.");return D(e)}if(o.length!==1)throw new d(t==="install"?"gallery block pack install takes one folder or zip: gallery block pack install <folder|zip>.":"gallery block pack remove takes one pack's id: gallery block pack remove <pack>.");return T[t](e,o[0])}var g={new:(e,t,o)=>Ge(e,t,o),add:Pe,list:Te,show:Me,check:async(e,t,{documents:o})=>(await import("./chunk-FXQBADMN.mjs")).checkCommand(e,t,{documents:o}),try:async(e,t)=>(await import("./chunk-JI6T3A4Y.mjs")).tryCommand(e,t),key:ze,pack:Be},He=["--press","--drag","--to","--key","--type","--select","--then","--steps"],Le={"--key":"--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).","--type":"--type takes a selector and the words to type: --type <selector> <words> (quoted when they hold a blank).","--select":"--select takes a selector and an option: --select <selector> <value> (the option's value or its words)."};function pe(e){let t=e.indexOf("--"),o=new Set,n={};for(let[a,s]of Object.entries(Le)){let l=(t===-1?e:e.slice(0,t)).findIndex(h=>h===a||h.startsWith(`${a}=`));if(l===-1)continue;let r=l+(e[l].includes("=")?1:2),m=e[r];if(m===void 0||r===t||P(m)||o.has(r))throw new d(s);o.add(r),n[a]=m}return{argv:e.filter((a,s)=>!o.has(s)),seconds:n}}function pt(e){let{argv:t,seconds:o}=pe(e);return{argv:t,key:o["--key"]??null}}async function mt(e,{workspace:t}){try{return await Re(e,t)}catch(o){let n=e.find(a=>!P(a));throw o instanceof d&&n==="try"&&(o.synopsis=F),o instanceof d&&n==="pack"&&(o.synopsis=W),o}}async function Re(e,t){let{argv:o,seconds:n}=pe(e),{positional:a,options:s,values:l}=ee({options:["--script","--flow","--data","--page","--keep","--documents","--replace","--remove"],values:[...He,"--recipe"],argv:o}),r=l.get("--recipe"),m=new Map([...l].filter(([b])=>b!=="--recipe")),[h,f,...i]=a,p=Object.keys(g).join(", ");if(!h)throw new d(`Say what to do: ${p}.`);if(!Object.hasOwn(g,h))throw new d(`No such block command: ${h} (${p}).`);let c=g[h];for(let b of["--script","--flow","--data","--page"])if(s.has(b)&&c!==g.new)throw new d(`${b} goes with new, not ${h}.`);if(s.has("--documents")&&c!==g.check)throw new d(`--documents goes with check, not ${h}.`);if(s.has("--remove")&&c!==g.key)throw new d(`--remove goes with key, not ${h}.`);if(r!==void 0&&c!==g.new)throw new d(`--recipe goes with new, not ${h}.`);let y=["--script","--flow","--data","--page"].filter(b=>s.has(b));if(r!==void 0&&y.length)throw new d(`--recipe makes a block of what Gallery's ${r} holds: ${y[0]} goes with a new block of none.${y[0]==="--page"&&$(r)?.places.includes("page")?` ${r} already is a card for a custom page (its places hold page): leave --page out.`:""}`);if(s.has("--flow")&&s.has("--data"))throw new d("--flow and --data do not go together: --flow is a slot for blocks of the document's own, --data a list of lines a reader keeps in the block's JSON. Make the one you need with new, and add the other by hand.");if(s.has("--flow")&&s.has("--page"))throw new d("--flow and --page do not go together: a custom page renders no document's blocks, so a block for a page has no slot.");let O=[...m.keys(),...Object.keys(n).filter(b=>!m.has(b)),...s.has("--keep")?["--keep"]:[],...s.has("--replace")?["--replace"]:[]];if(c===g.try)return c(t,{named:a.slice(1),values:m,seconds:n,keep:s.has("--keep"),replace:s.has("--replace")});if(O.length)throw new d(`${O[0]} goes with try, not ${h}.`);if(c===g.list){if(f!==void 0)throw new d(`gallery block ${h} takes nothing else.`);return c(t)}if(c===g.pack)return c(t,f,i);if(c===g.key){if(i.length>1)throw new d("gallery block key takes a host and its key: gallery block key <host> <key>.");return c(t,f,i[0],{remove:s.has("--remove")})}if(c===g.add){if(f===void 0||i.length>0)throw new d(`gallery block add takes one name of Gallery's own blocks: ${z()}.`);return c(t,f)}if(f===void 0||i.length>0)throw new d(`gallery block ${h} takes one id.`);let me=c===g.show||c===g.check?Ie(t,f):re(f);return c(t,me,{script:s.has("--script"),flow:s.has("--flow"),data:s.has("--data"),page:s.has("--page"),documents:s.has("--documents"),recipe:r})}export{re as a,Ie as b,M as c,u as d,ce as e,Ce as f,He as g,pe as h,pt as i,mt as j};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as i,l as C}from"./chunk-SX4LJYT6.mjs";import{a as g,c as w}from"./chunk-HYMEEXKN.mjs";import{g as j,o as A,p as S}from"./chunk-FWNRPMCJ.mjs";import f from"node:path";import{attr as P,hasClass as z,walk as D}from"../browser/shared/html-tree.mjs";import{projectRoot as F,sdkDirectory as O,typeRoots as Y}from"../browser/shared/paths.mjs";var H=new Set(["application/ecmascript","application/javascript","application/x-ecmascript","application/x-javascript","text/ecmascript","text/javascript","text/javascript1.0","text/javascript1.1","text/javascript1.2","text/javascript1.3","text/javascript1.4","text/javascript1.5","text/jscript","text/livescript","text/x-ecmascript","text/x-javascript"]);function y(t,{diffs:s=!1,tree:r=g(t)}={}){let n=[];return D(r,a=>{if(a.tagName!=="script"||P(a,"src")!==void 0)return;let o=(P(a,"type")||"").trim().toLowerCase(),l=s&&o==="application/json"&&a.parentNode?.tagName?a.parentNode:null,e=l&&z(l,"doc-diff")?"__declaredDiff(":void 0;if(!e&&o&&o!=="module"&&!H.has(o))return;let{startTag:c,endTag:p}=a.sourceCodeLocation??{};c&&n.push({start:c.endOffset,end:p?.startOffset??t.length,module:o==="module",...e?{call:e}:{}})},{inTemplates:!1}),n}function L(t,s,r=[]){let n=[],a=0,o="",l=e=>e.replace(/[^\r\n]/g," ");for(let{start:e,end:c,call:p}of s){let u=o+l(t.slice(a+o.length,e));if(p){let h=V(u,p,o.length);if(h===null){r.push(e);continue}u=h}n.push(u,t.slice(e,c)),a=c,o=p?");":""}return n.push(o+l(t.slice(a+o.length)),`
2
+ import{a as i,l as C}from"./chunk-YFJU3O7G.mjs";import{a as g,c as w}from"./chunk-2RKIHJI2.mjs";import{g as j,o as A,p as S}from"./chunk-VG5JEIUQ.mjs";import f from"node:path";import{attr as P,hasClass as z,walk as D}from"../browser/shared/html-tree.mjs";import{projectRoot as F,sdkDirectory as O,typeRoots as Y}from"../browser/shared/paths.mjs";var H=new Set(["application/ecmascript","application/javascript","application/x-ecmascript","application/x-javascript","text/ecmascript","text/javascript","text/javascript1.0","text/javascript1.1","text/javascript1.2","text/javascript1.3","text/javascript1.4","text/javascript1.5","text/jscript","text/livescript","text/x-ecmascript","text/x-javascript"]);function y(t,{diffs:s=!1,tree:r=g(t)}={}){let n=[];return D(r,a=>{if(a.tagName!=="script"||P(a,"src")!==void 0)return;let o=(P(a,"type")||"").trim().toLowerCase(),l=s&&o==="application/json"&&a.parentNode?.tagName?a.parentNode:null,e=l&&z(l,"doc-diff")?"__declaredDiff(":void 0;if(!e&&o&&o!=="module"&&!H.has(o))return;let{startTag:c,endTag:p}=a.sourceCodeLocation??{};c&&n.push({start:c.endOffset,end:p?.startOffset??t.length,module:o==="module",...e?{call:e}:{}})},{inTemplates:!1}),n}function L(t,s,r=[]){let n=[],a=0,o="",l=e=>e.replace(/[^\r\n]/g," ");for(let{start:e,end:c,call:p}of s){let u=o+l(t.slice(a+o.length,e));if(p){let h=V(u,p,o.length);if(h===null){r.push(e);continue}u=h}n.push(u,t.slice(e,c)),a=c,o=p?");":""}return n.push(o+l(t.slice(a+o.length)),`
3
3
  export {};
4
4
  `),n.join("")}function V(t,s,r){let n=t.length;for(;;){let a=Math.max(t.lastIndexOf(`
5
5
  `,n-1)+1,r),o=t[n-1]==="\r"?n-1:n;if(o-a>=s.length)return t.slice(0,o-s.length)+s+t.slice(o);if(a<=r)return null;n=a-1}}function Pt(t,s=g(t)){return L(t,y(t,{tree:s}))}var q=new Set(["href","src","action","formaction"]),X=t=>{try{return decodeURIComponent(t)}catch{return t}};function Z(t,s){let r=y(t,{tree:s}).map(({start:n,end:a})=>({code:t.slice(n,a),start:n,where:"the document's script"}));return D(s,n=>{for(let{name:a,value:o}of n.attrs){let l=n.sourceCodeLocation?.attrs?.[a]?.startLine??n.sourceCodeLocation?.startLine,e=q.has(a)?o.replace(/[\t\n\r]/g,"").replace(/^[\u0000-\u0020]+/,""):"";/^on[a-z]+$/.test(a)?r.push({code:o,line:l,where:`the ${a} attribute of <${n.tagName}>`}):/^javascript:/i.test(e)&&r.push({code:X(e.slice(11)),line:l,where:`the javascript: address of <${n.tagName} ${a}>`})}},{inTemplates:!1}),r}var R=new Set(["fetch","XMLHttpRequest","WebSocket","EventSource","sendBeacon","import"]),E=new Set(["window","globalThis","self"]),Q=t=>i.isIdentifier(t)?t.text==="navigator":i.isPropertyAccessExpression(t)&&t.name.text==="navigator"&&i.isIdentifier(t.expression)&&E.has(t.expression.text);function I(t){let{initializer:s}=i.walkUpBindingElementsAndPatterns(t);return!!s&&i.isIdentifier(s)&&E.has(s.text)}function tt(t){let s=t.parent;return i.isPropertyAccessExpression(s)&&s.name===t?i.isIdentifier(s.expression)&&E.has(s.expression.text):i.isBindingElement(s)&&s.propertyName===t?I(s):!((i.isPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isPropertyDeclaration(s)||i.isGetAccessorDeclaration(s)||i.isSetAccessorDeclaration(s))&&s.name===t)}function et(t,s){return i.isIdentifier(t)&&s.has(t.text)&&tt(t)?{name:t.text,reference:i.isPropertyAccessExpression(t.parent)&&t.parent.name===t?t.parent:t}:i.isElementAccessExpression(t)&&i.isIdentifier(t.expression)&&E.has(t.expression.text)&&i.isStringLiteralLike(t.argumentExpression)&&s.has(t.argumentExpression.text)?{name:t.argumentExpression.text,reference:t}:i.isPropertyAccessExpression(t)&&s.has(t.name.text)&&t.name.text==="sendBeacon"&&Q(t.expression)?{name:"sendBeacon",reference:t}:s.has("import")&&i.isCallExpression(t)&&t.expression.kind===i.SyntaxKind.ImportKeyword?{name:"import",reference:t.expression}:null}function st(t,s){let r=new Map,n=(e,c)=>{let p=e.parent;for(;p&&!c(p);)p=p.parent;return p??t},a=e=>i.isFunctionLike(e)||i.isBlock(e)||i.isCaseBlock(e)||i.isForStatement(e)||i.isForInStatement(e)||i.isForOfStatement(e),o=e=>i.isFunctionExpression(e)||i.isClassExpression(e)?e:i.isFunctionDeclaration(e)||i.isClassDeclaration(e)?n(e,a):i.isCatchClause(e.parent)?e.parent:n(e,i.getCombinedNodeFlags(e)&i.NodeFlags.BlockScoped?a:i.isFunctionLike),l=e=>{(i.isParameter(e)||i.isVariableDeclaration(e)||i.isBindingElement(e)||i.isFunctionDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionExpression(e)||i.isClassExpression(e))&&e.name&&i.isIdentifier(e.name)&&s.has(e.name.text)&&!(i.isBindingElement(e)&&I(e))&&r.set(e.name.text,[...r.get(e.name.text)??[],o(e)]),i.forEachChild(e,l)};return l(t),r}function rt(t,s=[]){for(let r=t;r;r=r.parent)if(s.includes(r))return!0;return!1}function Nt(t,s,{tree:r=g(t)}={}){let n=[];for(let{code:a,start:o,line:l,where:e}of Z(t,r))for(let{name:c,how:p,at:u}of k(a,s))n.push({name:c,how:p,line:l??w(t,o+u),where:e});return n.sort((a,o)=>a.line-o.line)}function k(t,s){if(![...s].some(l=>t.includes(l)))return[];let r=[],n=i.createSourceFile("code.js",t,i.ScriptTarget.Latest,!0,i.ScriptKind.JS),a=st(n,s),o=l=>{let e=et(l,s),c=e?.reference.parent;if(e&&!i.isTypeOfExpression(c)&&!(i.isIdentifier(e.reference)&&rt(l,a.get(e.name)))){let p=(i.isCallExpression(c)||i.isNewExpression(c))&&c.expression===e.reference?i.isNewExpression(c)?"new":"call":"use";r.push({name:e.name,how:p,at:l.getStart(n)})}i.forEachChild(l,o)};return o(n),r}var nt=new Set([2304,2552]),it=new Set([2300,2451,2448,2449,2450]),M=t=>nt.has(t)||it.has(t)||t>=1e3&&t<2e3;function at(t,s,r){if(!t.file||r.has(t)||M(t.code))return!1;let n=t.start??-1;return s.some(a=>!a.call&&a.start<=n&&n<a.end)}var ot=(t,s)=>/\bNumberValue\b/.test(t)||/\bd3\.(?:min|max|extent)\(/.test(s)?"; here d3 reads values of no type as strings: give the data its shape once with JSDoc, /** @type {Array<{ label: string, value: number }>} */ const rows = data;, and d3.min or d3.max may give undefined (?? 0)":"";function B(t){let s={allowJs:!0,checkJs:!0,noEmit:!0,allowUmdGlobalAccess:!0,strict:!0,noImplicitAny:!1,target:i.ScriptTarget.ES2022,module:i.ModuleKind.ESNext,moduleResolution:i.ModuleResolutionKind.Bundler,lib:["lib.es2022.d.ts","lib.dom.d.ts","lib.dom.iterable.d.ts"],types:["d3"],typeRoots:Y,skipLibCheck:!1},r=i.createCompilerHost(s),n=r.readFile.bind(r),a=r.fileExists.bind(r);return r.readFile=o=>t.get(f.resolve(o))??n(o),r.fileExists=o=>t.has(f.resolve(o))||a(o),i.createProgram([f.join(O,"index.d.ts"),...t.keys()],s,r)}var ct=/\bDoc[A-Z]\w*/,lt=(t,s)=>ct.test(s)||(t.relatedInformation??[]).some(({file:r})=>r&&f.resolve(r.fileName).startsWith(O+f.sep)),N={katex:"katex","katex-auto-render":"renderMathInElement"};function Dt(t,{assets:s=[]}={}){let r=f.join(F,"reports","__package__","kit.js"),n=t.replace(/^([ \t]*)(?:<!--|-->)/gm,"$1//"),a=s.filter(c=>Object.hasOwn(N,c)).map(c=>`declare const ${N[c]}: any;
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as je}from"./chunk-JEUK3ZO7.mjs";import{a as Te,b as Ne,c as Xe,d as Ze,g as Oe,h as et}from"./chunk-PUOQ65NC.mjs";import{g as Qe}from"./chunk-V6RIYQZZ.mjs";import{b as Se}from"./chunk-SXHBYZST.mjs";import{p as Ee}from"./chunk-HMYTM3GT.mjs";import{a as le}from"./chunk-HYMEEXKN.mjs";import{a as ve,f as Ye,p as ze}from"./chunk-FWNRPMCJ.mjs";import T from"node:fs/promises";import he from"node:os";import x from"node:path";import{pathToFileURL as Re}from"node:url";import{instancesOf as ot,isInstance as bt}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as $t,FALLBACK as xt,INSTANCE as de,SLOT as vt,SLOT_PART as tt}from"../browser/shared/components/installed.mjs";import{jsonIn as Et}from"../browser/shared/json-layout.mjs";import{QUERY_ROUTE as St}from"../browser/shared/workspace-query.mjs";import{documentDirectory as jt,documentFiles as Tt,layoutOf as it,listDocumentSlugs as Nt,PACKAGE_MANIFEST as Ot}from"../browser/shared/workspace.mjs";var At="in a browser, under the export's policy",ce=(e=null)=>e?`the instances in ${e}, in a browser under the export's policy`:"the workspace's documents",q="component-check",ae=[360,736,1024],Ae=["light","dark"],Lt=[1024,360],nt=1e4,rt=6e4,se=3e4,Dn=12e4,lt=2e3,Rt=3e3,Dt=60,Mn=15e3,Mt=2,Pt=8,Ct=se/2,_t=/^(?:wasm-)?eval$/,It=new Set(["TargetCloseError","ConnectionClosedError"]),Pn=e=>e.evaluateOnNewDocument(Ft,St);function Ft(e){let t=globalThis.fetch;if(typeof t!="function"||globalThis.__galleryQueries)return;let i={pending:new Map,count:0};globalThis.__galleryQueries=i,globalThis.fetch=function(r,n){let a=t.apply(this,arguments);try{let p=new URL(typeof r=="string"?r:r?.url??String(r),location.href);if(p.pathname===e){let u=++i.count,w=/\/__gallery\/components\/([a-z0-9-]+\/[a-z0-9-]+)\/kit\.js/.exec(new Error().stack??"");i.pending.set(u,{kind:p.searchParams.get("kind"),block:w?w[1]:null,at:Date.now()});let l=()=>{i.pending.delete(u)};Promise.resolve(a).then(l,l)}}catch{}return a}}var oe=e=>String(e?.message??e).split(`
2
+ import{a as je}from"./chunk-JEUK3ZO7.mjs";import{a as Te,b as Ne,c as Xe,d as Ze,g as Oe,h as et}from"./chunk-4AMTKWDO.mjs";import{g as Qe}from"./chunk-TOE6DPLH.mjs";import{b as Se}from"./chunk-WTEGUPFG.mjs";import{p as Ee}from"./chunk-XMKHCUI6.mjs";import{a as le}from"./chunk-2RKIHJI2.mjs";import{a as ve,f as Ye,p as ze}from"./chunk-VG5JEIUQ.mjs";import T from"node:fs/promises";import he from"node:os";import x from"node:path";import{pathToFileURL as Re}from"node:url";import{instancesOf as ot,isInstance as bt}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as $t,FALLBACK as xt,INSTANCE as de,SLOT as vt,SLOT_PART as tt}from"../browser/shared/components/installed.mjs";import{jsonIn as Et}from"../browser/shared/json-layout.mjs";import{QUERY_ROUTE as St}from"../browser/shared/workspace-query.mjs";import{documentDirectory as jt,documentFiles as Tt,layoutOf as it,listDocumentSlugs as Nt,PACKAGE_MANIFEST as Ot}from"../browser/shared/workspace.mjs";var At="in a browser, under the export's policy",ce=(e=null)=>e?`the instances in ${e}, in a browser under the export's policy`:"the workspace's documents",q="component-check",ae=[360,736,1024],Ae=["light","dark"],Lt=[1024,360],nt=1e4,rt=6e4,se=3e4,Dn=12e4,lt=2e3,Rt=3e3,Dt=60,Mn=15e3,Mt=2,Pt=8,Ct=se/2,_t=/^(?:wasm-)?eval$/,It=new Set(["TargetCloseError","ConnectionClosedError"]),Pn=e=>e.evaluateOnNewDocument(Ft,St);function Ft(e){let t=globalThis.fetch;if(typeof t!="function"||globalThis.__galleryQueries)return;let i={pending:new Map,count:0};globalThis.__galleryQueries=i,globalThis.fetch=function(r,n){let a=t.apply(this,arguments);try{let p=new URL(typeof r=="string"?r:r?.url??String(r),location.href);if(p.pathname===e){let u=++i.count,w=/\/__gallery\/components\/([a-z0-9-]+\/[a-z0-9-]+)\/kit\.js/.exec(new Error().stack??"");i.pending.set(u,{kind:p.searchParams.get("kind"),block:w?w[1]:null,at:Date.now()});let l=()=>{i.pending.delete(u)};Promise.resolve(a).then(l,l)}}catch{}return a}}var oe=e=>String(e?.message??e).split(`
3
3
  `)[0],ct=(e,t)=>`<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${e}</title></head><body><main class="doc-page" data-doc-id="${e}">${t}
4
4
  </main></body></html>
5
5
  `,Bt=({example:e,template:t})=>`<p>example.html</p>${e}
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g}from"./chunk-XQRUG4G3.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{a as handInReports,e as idLines,f as inStepLines,d as noteNew,b as previewSettled,g as rereadLine,c as roundBegins};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as U,b as Z,c as ot,d as q}from"./chunk-N76HWBA3.mjs";import{e as L}from"./chunk-FJYN7RTH.mjs";import{D as nt,a as _,b as V,l as tt,m as D,o as et}from"./chunk-UBBRTJ2R.mjs";import{b as J,c as P,e as Q}from"./chunk-A55HN5OK.mjs";import{IDENTITY as Ne}from"../browser/editor/components/registry.mjs";function gt(e){let{blocks:a,locks:r,units:n,boxes:c}=L(e),l=wt(e,[...a.map(t=>({at:t.innerStart-1,text:` data-ge-block="${t.id}"`})),...r.map(t=>({at:t.at,text:` data-ge-lock="${t.reason}"`})),...n.map(t=>({at:t.at,text:` data-ge-unit="${t.id}"${t.grid?" data-ge-grid":""}${t.keep?` data-ge-keep="${t.keep.reason}"${t.keep.own?" data-ge-keep-own":""}`:""}`})),...n.filter(t=>t.lead!==null).map(t=>({at:t.lead,text:` data-ge-lead="${t.id}"`})),...c.map(t=>({at:t.at,text:` data-ge-box="${t.id}"${t.pure?" data-ge-pure":""}`}))]),p={version:_(e),blocks:a.map(t=>({id:t.id,tag:t.tag,kind:t.kind,caps:Object.keys(t.caps),inner:e.slice(t.innerStart,t.innerEnd),atoms:t.atoms,unit:t.unit,...t.path?{path:t.path}:{},...t.self!==null?{self:!0}:{}})),units:n.map(t=>({id:t.id,kind:t.kind,parent:t.parent,hash:D(e,t),...t.blockId?{blockId:t.blockId}:{},...t.keep?{keep:t.keep}:{},...t.grid?{grid:!0}:{},...t.parts?{parts:t.parts}:{}})),boxes:c.map(t=>({id:t.id,kind:t.kind,unit:t.unit,...t.key!==null?{key:t.key}:{}}))};return{html:l,map:p}}function wt(e,a,r=!0){let n=[],c=0;for(let l of[...a].sort((p,t)=>p.at-t.at)){if(e[l.at]!==">"){if(r)throw new Error(`Unexpected start tag before offset ${l.at}.`);continue}let p=et(e,l.at);n.push(e.slice(c,p),l.text),c=p}return n.push(e.slice(c)),n.join("")}Q();import{COMPONENTS as kt,instancesOf as xt,partOf as st}from"../browser/shared/components/index.mjs";import{attr as rt}from"../browser/shared/html-tree.mjs";var at=new Set(["main","section","article","aside","nav","header","footer","div","details","dialog","figure","blockquote","table","ul","ol","dl"]),Nt=new Set(["script","style","template","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext","pre","code","kbd","samp","var","svg","math"]),It=kt.filter(e=>e.match&&e.pairs);function Ot(e){let a=e.replace(/^/," "),r=J(a,{sourceCodeLocationInfo:!0}),n=f=>a.slice(0,f).split(`
2
+ import{a as U,b as Z,c as ot,d as q}from"./chunk-XKOHV4H6.mjs";import{e as L}from"./chunk-KFZBYDIS.mjs";import{D as nt,a as _,b as V,l as tt,m as D,o as et}from"./chunk-7XDYK3UC.mjs";import{b as J,c as P,e as Q}from"./chunk-N3DSBH5S.mjs";import{IDENTITY as Ne}from"../browser/editor/components/registry.mjs";function gt(e){let{blocks:a,locks:r,units:n,boxes:c}=L(e),l=wt(e,[...a.map(t=>({at:t.innerStart-1,text:` data-ge-block="${t.id}"`})),...r.map(t=>({at:t.at,text:` data-ge-lock="${t.reason}"`})),...n.map(t=>({at:t.at,text:` data-ge-unit="${t.id}"${t.grid?" data-ge-grid":""}${t.keep?` data-ge-keep="${t.keep.reason}"${t.keep.own?" data-ge-keep-own":""}`:""}`})),...n.filter(t=>t.lead!==null).map(t=>({at:t.lead,text:` data-ge-lead="${t.id}"`})),...c.map(t=>({at:t.at,text:` data-ge-box="${t.id}"${t.pure?" data-ge-pure":""}`}))]),p={version:_(e),blocks:a.map(t=>({id:t.id,tag:t.tag,kind:t.kind,caps:Object.keys(t.caps),inner:e.slice(t.innerStart,t.innerEnd),atoms:t.atoms,unit:t.unit,...t.path?{path:t.path}:{},...t.self!==null?{self:!0}:{}})),units:n.map(t=>({id:t.id,kind:t.kind,parent:t.parent,hash:D(e,t),...t.blockId?{blockId:t.blockId}:{},...t.keep?{keep:t.keep}:{},...t.grid?{grid:!0}:{},...t.parts?{parts:t.parts}:{}})),boxes:c.map(t=>({id:t.id,kind:t.kind,unit:t.unit,...t.key!==null?{key:t.key}:{}}))};return{html:l,map:p}}function wt(e,a,r=!0){let n=[],c=0;for(let l of[...a].sort((p,t)=>p.at-t.at)){if(e[l.at]!==">"){if(r)throw new Error(`Unexpected start tag before offset ${l.at}.`);continue}let p=et(e,l.at);n.push(e.slice(c,p),l.text),c=p}return n.push(e.slice(c)),n.join("")}Q();import{COMPONENTS as kt,instancesOf as xt,partOf as st}from"../browser/shared/components/index.mjs";import{attr as rt}from"../browser/shared/html-tree.mjs";var at=new Set(["main","section","article","aside","nav","header","footer","div","details","dialog","figure","blockquote","table","ul","ol","dl"]),Nt=new Set(["script","style","template","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext","pre","code","kbd","samp","var","svg","math"]),It=kt.filter(e=>e.match&&e.pairs);function Ot(e){let a=e.replace(/^/," "),r=J(a,{sourceCodeLocationInfo:!0}),n=f=>a.slice(0,f).split(`
3
3
  `).length,c=[],l=(f,d,s)=>c.push({key:f,tag:a.slice(d,s).replace(/\s+/g," "),line:n(d),offset:d});V(r,"main")||l("no <main> in the file",0,0);let p=[],t=new Set,k=f=>{for(let d of f.childNodes??[]){let s=d.sourceCodeLocation;if(d.nodeName==="#comment"){s&&p.push([s.startOffset,s.endOffset]);continue}if(d.tagName){if(s?.startTag&&p.push([s.startTag.startOffset,s.startTag.endOffset]),Nt.has(d.tagName)){s&&p.push([s.startOffset,s.endOffset??a.length]);continue}s?.endTag&&t.add(s.endTag.startOffset),at.has(d.tagName)&&s?.startTag&&!s.endTag&&l(`<${d.tagName}> not closed`,s.startTag.startOffset,s.startTag.endOffset),k(d)}}};k(r),p.sort((f,d)=>f[0]-d[0]);let N="",h=0;for(let[f,d]of p)d<=h||(N+=a.slice(h,Math.max(h,f))+" ".repeat(d-Math.max(h,f)),h=d);N+=a.slice(h);for(let f of N.matchAll(/<\/([A-Za-z][A-Za-z0-9]*)[^<>]*>?/g)){let d=f[1].toLowerCase();at.has(d)&&!t.has(f.index)&&l(`</${d}> closes nothing`,f.index,f.index+f[0].length)}for(let f of It)for(let d of xt(r,f))for(let{a:s,attrA:g,b:x,attrB:A}of f.pairs){let o=st(d,f.parts[s].at).map(M=>rt(M,g)),u=st(d,f.parts[x].at).map(M=>rt(M,A)),j=M=>new Set(M).size===M.length,I=j(o)&&j(u)&&o.length===u.length&&o.every(M=>u.includes(M)),b=d.sourceCodeLocation;!I&&b&&l(`${f.id}: ${s} and ${x} do not pair`,b.startOffset,b.startTag?.endOffset??b.startOffset)}return c.sort((f,d)=>f.offset-d.offset).map(({key:f,tag:d,line:s})=>({key:f,tag:d,line:s,text:`${f} (line ${s})`}))}Q();import{treeText as z}from"../browser/shared/annotations.mjs";import{attr as F}from"../browser/shared/html-tree.mjs";var it=2e3*2e3,G=2e3,ct=50,lt=1500;function ft(e,a,r,n){let c="",l=a;for(let p of n)p.end<=l||p.start>=r||(p.start>l&&(c+=e.slice(l,p.start)),l=Math.max(l,p.end));return c+e.slice(l,r)}var dt=e=>e.replace(/\s+/g," ").trim(),bt=e=>/\S/.test(e.replace(/<!--[^]*?-->/g,"").replace(/<[^>]*>/g,"").replace(/\u0000/g,"")),pt=e=>e.companion?[{start:e.start,end:e.end},{start:e.companion.start,end:e.companion.end}]:[{start:e.start,end:e.end}];function H(e){let a=L(e),{units:r,blocks:n}=a,c=r[0]?.node??n[0]?.node??null;for(;c?.parentNode;)c=c.parentNode;let l=c?tt(e,[c]):[],p=[...r].sort((o,u)=>o.start-u.start||u.end-o.end),t=new Map,k=[];for(let o of p){for(;k.length&&k.at(-1).end<=o.start;)k.pop();t.set(o,k.at(-1)??null),k.push(o)}for(let o of r.filter(u=>u.companion)){let{start:u,end:j}=o.companion;for(let I of r){if(I===o||I.start<u||I.end>j)continue;let b=t.get(I);(!b||b.start<u)&&t.set(I,o)}}let N=new Map;for(let o of r){let u=t.get(o);u&&N.set(u,[...N.get(u)??[],o])}let h=n.find(o=>o.kind==="title")??null,f=[...r.map(o=>({unit:o,at:o.elStart})),...h?[{unit:null,at:h.start}]:[]].sort((o,u)=>o.at-u.at),d=new Map(f.map((o,u)=>[o.unit,u])),s=new Map;for(let o of r)o.blockId&&s.set(o.blockId,(s.get(o.blockId)??0)+1);let g=f.map(({unit:o})=>{if(!o){let $=dt(ft(e,h.start,h.end,l));return{unit:null,title:!0,kind:"title",key:`title\0${$}`,own:$,counts:1,parent:null,blockId:null,text:z(h.node).slice(0,G)}}let u=N.get(o)??[],j=[...u.flatMap(pt),...l].sort(($,R)=>$.start-R.start),I=dt(pt(o).map(({start:$,end:R})=>ft(e,$,R,j)).join("\0")),b=u.length>0&&!bt(I),M=t.get(o);return{unit:o,kind:o.kind,key:`${o.kind}\0${I}`,own:I,counts:b?0:1,parent:M?d.get(M):null,blockId:o.blockId,text:z(o.node).slice(0,G)}}),x=null;return{rows:g,scanned:a,ref:o=>o.title?{title:!0}:o.blockId&&s.get(o.blockId)===1?{id:o.blockId}:(x??=(()=>{let u=new Map,j=new Map;for(let{unit:I}of f){if(!I)continue;let b=D(e,I);j.set(I,{hash:b,nth:u.get(b)??0}),u.set(b,(u.get(b)??0)+1)}return j})(),x.get(o.unit))}}function St(e,a){if(e.length*a.length<=it)return Z(e,a);let r=s=>s.reduce((g,x)=>g.set(x,(g.get(x)??0)+1),new Map),[n,c]=[r(e),r(a)],l=new Map;a.forEach((s,g)=>{c.get(s)===1&&n.get(s)===1&&l.set(s,g)});let p=[];e.forEach((s,g)=>{l.has(s)&&p.push([g,l.get(s)])});let t=[],k=[];p.forEach(([,s],g)=>{let x=0,A=t.length;for(;x<A;){let o=x+A>>1;p[t[o]][1]<s?x=o+1:A=o}k[g]=x>0?t[x-1]:-1,t[x]=g});let N=[];for(let s=t.at(-1)??-1;s>=0;s=k[s])N.unshift(p[s]);let h=[],[f,d]=[0,0];for(let[s,g]of[...N,[e.length,a.length]]){if((s-f)*(g-d)<=it)for(let[x,A]of Z(e.slice(f,s),a.slice(d,g)))h.push([f+x,d+A]);s<e.length&&h.push([s,g]),[f,d]=[s+1,g+1]}return h}var ut=(e,a)=>a.nested?z(P(e.slice(a.innerStart,a.innerEnd))):z(a.node),mt=e=>e.match(/[A-Za-z0-9]+|\s+|[^A-Za-z0-9\s]/gu)?.length??0,ht=({scanned:e},a)=>(a.title?e.blocks.filter(r=>r.kind==="title"):e.blocks.filter(r=>r.unit===a.unit.id)).sort((r,n)=>r.innerStart-n.innerStart);function yt(e){let a=[],r=n=>{for(let c of n.childNodes??[])c.tagName==="tr"?a.push((c.childNodes??[]).filter(l=>l.tagName==="td"||l.tagName==="th").map(l=>z(l).replace(/\s+/g," ")).join(" \xB7 ")):c.tagName&&r(c.tagName==="template"?c.content:c)};return r(e),a.length?a.join(`
4
4
  `):z(e)}function Mt(e,a,r){let n=e[a],c=0;for(let N=n.parent;N!==null;N=e[N].parent)r(N)&&(c+=1);let l=n.title?"h1":n.unit.node.tagName,p=n.title?n.text:yt(P(n.own.replace(/\u0000/g," "))).slice(0,G),t={kind:n.kind,tag:l,depth:c,text:p},k=l==="li"?n.unit.node.parentNode:null;if((k?.tagName==="ul"||k?.tagName==="ol")&&(t.marker=k.tagName,k.tagName==="ol")){let N=(k.childNodes??[]).filter(h=>h.tagName==="li");t.number=(Number.parseInt(F(k,"start")??"1",10)||1)+N.indexOf(n.unit.node)}return t}function $t(e,a){if(e===a)return null;let r=H(e),n=H(a),[c,l]=[r.rows.map(i=>i.key),n.rows.map(i=>i.key)],p=St(c,l);if(p.length===c.length&&p.length===l.length)return null;let t=i=>{let w=new Map;for(let S of i)S.blockId&&w.set(S.blockId,(w.get(S.blockId)??0)+1);return S=>!!S.blockId&&w.get(S.blockId)===1},[k,N]=[t(r.rows),t(n.rows)],h=[],[f,d]=[0,0];for(let[i,w]of[...p,[c.length,l.length]]){let S=new Map;for(let m=d;m<w;m++)N(n.rows[m])&&S.set(n.rows[m].blockId,m);let T=[],v=d-1;for(let m=f;m<i;m++){let O=k(r.rows[m])?S.get(r.rows[m].blockId):void 0;O!==void 0&&O>v&&(T.push([m,O]),v=O)}let B=[],[y,E]=[f,d];for(let[m,O]of[...T,[i,w]]){for(;y<m;y++){let C=r.rows[y];for(let W=E;W<O;W++){let Y=n.rows[W];if(Y.kind===C.kind&&(C.title||ot(C.own,Y.own))){B.push([y,W]),E=W+1;break}}}m<i&&B.push([m,O]),[y,E]=[m+1,O+1]}B.sort((m,O)=>m[0]-O[0]),[y,E]=[f,d];for(let[m,O]of[...B,[i,w]]){for(;y<m;y++)h.push({type:"del",i:y});for(;E<O;E++)h.push({type:"ins",j:E});m<i&&h.push({type:"chg",i:m,j:O}),[y,E]=[m+1,O+1]}i<c.length&&h.push({type:"same",i,j:w}),[f,d]=[i+1,w+1]}let s=new Set(h.filter(i=>i.type==="ins").map(i=>i.j)),g=new Set(h.filter(i=>i.type==="del").map(i=>i.i)),x=(i,w)=>{let S=new Set;for(let T of w)if(i[T].counts)for(let v=i[T].parent;v!==null;v=i[v].parent)S.add(v);return T=>i[T].counts||(S.has(T)?0:1)},[A,o]=[x(n.rows,s),x(r.rows,g)],u={added:0,changed:0,removed:0},j=[],I=[],b=[],M,$=null,R=null,K=i=>{if(!$)return;let w=Math.max(0,$.rows.length-ct);b.push({...i!==null?{before:n.ref(n.rows[i])}:R!==null?{after:n.ref(n.rows[R])}:{into:"main"},count:$.count,rows:$.rows.slice(0,ct),...w?{more:w}:{}}),$=null},X=i=>g.has(i)&&r.rows[i].counts>0;for(let i of h){if(i.type==="del"){$??={count:0,rows:[]},$.count+=o(i.i),u.removed+=o(i.i),X(i.i)&&$.rows.push(Mt(r.rows,i.i,X));continue}if(K(i.j),R=i.j,i.type==="ins"){let w=n.rows[i.j];u.added+=A(i.j),(w.parent===null||!s.has(w.parent))&&j.push({ref:n.ref(w)})}else if(i.type==="chg"){let[w,S]=[r.rows[i.i],n.rows[i.j]];u.changed+=1;let T=ht(r,w),v=ht(n,S),B=[],y=T.length!==v.length||T.length===0||T.some((E,m)=>E.tag!==v[m].tag);y||(T.forEach((E,m)=>{let[O,C]=[ut(e,E),ut(a,v[m])];mt(O)>lt||mt(C)>lt?y=!0:O!==C&&B.push({nth:m,base:O})}),B.length===0&&(y=!0)),y&&(B=[]),I.push({ref:n.ref(S),...y?{whole:!0}:{texts:B}}),S.title&&(M={base:w.text})}}return K(null),{counts:u,added:j,changed:I,...M?{title:M}:{},removed:b}}function Tt(e){let{units:a}=L(e),r=c=>{for(let l=c;l;l=l.parentNode)if(l.tagName&&(F(l,"data-doc-placeholder")!==void 0||l.tagName==="header"||(F(l,"class")??"").split(/\s+/).includes("doc-header")))return!1;return!0},n=c=>/^(img|picture|svg|canvas|video|audio|iframe|object|embed)$/.test(c.tagName??"")||(c.childNodes??[]).some(n);return!a.some(c=>r(c.node)&&(z(c.node)!==""||n(c.node)))}function jt(e,a){try{return q({current:e,ids:!0,...a}).text}catch{return e}}function Et(e,a){try{let r=L(e).blocks.find(c=>c.kind==="title");if(!r)return e;let n=U({current:e,edits:[{id:r.id,parts:[{keep:!0,html:a}]}],ids:!1});return n.ok?n.text:e}catch{return e}}var we=(e,a,r,n)=>nt.installed.rewrite(e,a,r,{packages:n});export{gt as a,Ot as b,$t as c,Tt as d,jt as e,Et as f,we as g};