@heycys/gallery 0.1.1 → 0.1.2

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 (370) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/components/columns/page.mjs +4 -4
  3. package/browser/editor/components/embed/index.mjs +2 -2
  4. package/browser/editor/components/flowchart/add.mjs +7 -6
  5. package/browser/editor/components/flowchart/page.mjs +1 -1
  6. package/browser/editor/components/icons.mjs +8 -0
  7. package/browser/editor/components/image/crop.mjs +6 -9
  8. package/browser/editor/components/installed/index.mjs +11 -4
  9. package/browser/editor/components/installed/page.mjs +27 -16
  10. package/browser/editor/components/installed/served.mjs +6 -5
  11. package/browser/editor/components/instances.mjs +18 -0
  12. package/browser/editor/components/list/page.mjs +3 -6
  13. package/browser/editor/components/registry.mjs +13 -4
  14. package/browser/editor/components/table/index.mjs +59 -2
  15. package/browser/editor/components/table/page.mjs +1 -1
  16. package/browser/editor/page/annotate/card.mjs +3 -6
  17. package/browser/editor/page/autosave.mjs +310 -37
  18. package/browser/editor/page/board/client.mjs +57 -0
  19. package/browser/editor/page/board/hint.mjs +145 -0
  20. package/browser/editor/page/board/history.mjs +119 -0
  21. package/browser/editor/page/board/index.mjs +970 -0
  22. package/browser/editor/page/board/settings.mjs +209 -0
  23. package/browser/editor/page/caret.mjs +1 -1
  24. package/browser/editor/page/changes/bar.mjs +6 -14
  25. package/browser/editor/page/changes/index.mjs +2 -2
  26. package/browser/editor/page/clipboard/import/html.mjs +29 -6
  27. package/browser/editor/page/clipboard/import/inline.mjs +32 -0
  28. package/browser/editor/page/clipboard/import/markdown.mjs +58 -13
  29. package/browser/editor/page/clipboard/import/read.mjs +6 -1
  30. package/browser/editor/page/clipboard/import/to-blocks.mjs +44 -12
  31. package/browser/editor/page/clipboard/import/yuque.mjs +622 -0
  32. package/browser/editor/page/clipboard/index.mjs +124 -13
  33. package/browser/editor/page/clipboard/own/blocks.mjs +11 -11
  34. package/browser/editor/page/clipboard/own/chart-keys.mjs +41 -28
  35. package/browser/editor/page/clipboard/own/selection.mjs +1 -1
  36. package/browser/editor/page/columns/index.mjs +48 -46
  37. package/browser/editor/page/commit.mjs +80 -22
  38. package/browser/editor/page/conflicts.mjs +7 -7
  39. package/browser/editor/page/core.mjs +31 -15
  40. package/browser/editor/page/custom-page.mjs +106 -0
  41. package/browser/editor/page/editor.mjs +51 -14
  42. package/browser/editor/page/emoji-picker/styles.mjs +7 -12
  43. package/browser/editor/page/emoji-picker/upload.mjs +2 -2
  44. package/browser/editor/page/handle/index.mjs +5 -8
  45. package/browser/editor/page/history.mjs +24 -4
  46. package/browser/editor/page/links/index.mjs +5 -3
  47. package/browser/editor/page/links/pages.mjs +27 -9
  48. package/browser/editor/page/look.mjs +54 -3
  49. package/browser/editor/page/margin.mjs +18 -3
  50. package/browser/editor/page/media-menu/index.mjs +6 -7
  51. package/browser/editor/page/menu.mjs +18 -7
  52. package/browser/editor/page/notices.mjs +2 -2
  53. package/browser/editor/page/page-objects.mjs +13 -2
  54. package/browser/editor/page/panel.mjs +4 -9
  55. package/browser/editor/page/present-links.mjs +11 -2
  56. package/browser/editor/page/resize/index.mjs +42 -29
  57. package/browser/editor/page/served.mjs +14 -0
  58. package/browser/editor/page/session.mjs +48 -4
  59. package/browser/editor/page/slash-menu/index.mjs +3 -3
  60. package/browser/editor/page/table/cells.mjs +102 -46
  61. package/browser/editor/page/table/icons.mjs +2 -0
  62. package/browser/editor/page/table/index.mjs +29 -10
  63. package/browser/editor/page/table/pictures.mjs +299 -0
  64. package/browser/editor/page/table/views.mjs +150 -0
  65. package/browser/editor/page/text-select/index.mjs +26 -12
  66. package/browser/editor/page/todo-writes.mjs +75 -0
  67. package/browser/editor/page/typing/index.mjs +53 -3
  68. package/browser/editor/page/ui.mjs +13 -0
  69. package/browser/shared/block-packs.mjs +404 -0
  70. package/browser/shared/board-places.mjs +224 -0
  71. package/browser/shared/card-size.mjs +59 -0
  72. package/browser/shared/colors.mjs +3 -2
  73. package/browser/shared/component-catalog.mjs +323 -46
  74. package/browser/shared/component-source.mjs +37 -0
  75. package/browser/shared/components/index.mjs +12 -3
  76. package/browser/shared/components/installed.mjs +35 -3
  77. package/browser/shared/components/page.mjs +18 -8
  78. package/browser/shared/components/state.mjs +5 -1
  79. package/browser/shared/document-look.mjs +10 -5
  80. package/browser/shared/drafts.mjs +432 -0
  81. package/browser/shared/extension-sidebar.mjs +126 -0
  82. package/browser/shared/extensions.mjs +79 -0
  83. package/browser/shared/file-table.mjs +101 -0
  84. package/browser/shared/i18n/en.mjs +307 -27
  85. package/browser/shared/json-layout.mjs +47 -0
  86. package/browser/shared/net-cache.mjs +133 -0
  87. package/browser/shared/net-keys.mjs +32 -0
  88. package/browser/shared/net-policy.mjs +177 -0
  89. package/browser/shared/outline-shape.mjs +128 -0
  90. package/browser/shared/outline.mjs +331 -67
  91. package/browser/shared/pack-manifest.mjs +77 -0
  92. package/browser/shared/page-address.mjs +6 -3
  93. package/browser/shared/page-cards.mjs +308 -0
  94. package/browser/shared/page-links.mjs +69 -6
  95. package/browser/shared/pages.mjs +388 -0
  96. package/browser/shared/paths.mjs +6 -0
  97. package/browser/shared/preview-server.mjs +3 -7
  98. package/browser/shared/session.mjs +8 -1
  99. package/browser/shared/shipped-blocks.mjs +299 -0
  100. package/browser/shared/table-chart.mjs +33 -1
  101. package/browser/shared/todos.mjs +83 -0
  102. package/browser/shared/user-directory.mjs +24 -0
  103. package/browser/shared/versions.mjs +14 -0
  104. package/browser/shared/web-links.mjs +134 -0
  105. package/browser/shared/workspace-columns.mjs +120 -0
  106. package/browser/shared/workspace-name.mjs +154 -0
  107. package/browser/shared/workspace-query.mjs +125 -0
  108. package/browser/shared/workspace-registry.mjs +272 -0
  109. package/browser/shared/workspace.mjs +171 -20
  110. package/dist/chunk-2NRBY6AJ.mjs +2 -0
  111. package/dist/chunk-32ZUEFZ7.mjs +2 -0
  112. package/dist/chunk-35NQ4PLQ.mjs +2 -0
  113. package/dist/chunk-3KJHLHUO.mjs +2 -0
  114. package/dist/chunk-3NJACR4W.mjs +2 -0
  115. package/dist/chunk-4AV456RQ.mjs +2 -0
  116. package/dist/chunk-4OZWXZE5.mjs +5 -0
  117. package/dist/chunk-5XYHDBJ5.mjs +2 -0
  118. package/dist/chunk-5ZJA7CXT.mjs +2 -0
  119. package/dist/chunk-6A53MZYZ.mjs +2 -0
  120. package/dist/chunk-6EXH3ORZ.mjs +166 -0
  121. package/dist/chunk-6EZ7FNIK.mjs +3 -0
  122. package/dist/{chunk-V5JTW2LH.mjs → chunk-6QBHU4DF.mjs} +1 -1
  123. package/dist/{chunk-Y6RLRPG3.mjs → chunk-6VTU6KEO.mjs} +1 -1
  124. package/dist/chunk-B4P2CM2J.mjs +3 -0
  125. package/dist/{chunk-FDLXYYG4.mjs → chunk-BPL64HGA.mjs} +1 -1
  126. package/dist/chunk-BVEFGE4B.mjs +2 -0
  127. package/dist/{chunk-LS4F7JUM.mjs → chunk-BZ5RAF7L.mjs} +1 -1
  128. package/dist/chunk-CRJEG7MT.mjs +2 -0
  129. package/dist/{chunk-LCTHTZIL.mjs → chunk-D4CKRD3V.mjs} +91 -91
  130. package/dist/chunk-D4EURAX4.mjs +4 -0
  131. package/dist/chunk-DQCE7TJY.mjs +5 -0
  132. package/dist/chunk-DR73Y2UJ.mjs +3 -0
  133. package/dist/{chunk-TMYZB6AV.mjs → chunk-EKNHM3P4.mjs} +1 -1
  134. package/dist/{chunk-GB5SOYQJ.mjs → chunk-ERLAIBOA.mjs} +2 -2
  135. package/dist/chunk-EURLTOTZ.mjs +4 -0
  136. package/dist/chunk-FJYN7RTH.mjs +4 -0
  137. package/dist/chunk-FWNRPMCJ.mjs +12 -0
  138. package/dist/chunk-FWW4CSAZ.mjs +2 -0
  139. package/dist/{chunk-2B5E4CDJ.mjs → chunk-GPIWQ4X4.mjs} +1 -1
  140. package/dist/chunk-GY3FAUVM.mjs +2 -0
  141. package/dist/chunk-HLYV7RIH.mjs +2 -0
  142. package/dist/chunk-HMYTM3GT.mjs +15 -0
  143. package/dist/chunk-IA4PSIMD.mjs +2 -0
  144. package/dist/chunk-JEUK3ZO7.mjs +2 -0
  145. package/dist/chunk-KTKHRC6H.mjs +2 -0
  146. package/dist/chunk-L7UP52JO.mjs +2 -0
  147. package/dist/{chunk-SYGN7GLU.mjs → chunk-MHW7ZKOU.mjs} +1 -1
  148. package/dist/chunk-N76HWBA3.mjs +10 -0
  149. package/dist/chunk-N7AZZLGT.mjs +548 -0
  150. package/dist/chunk-NAMN3RAF.mjs +2 -0
  151. package/dist/{chunk-5ZKJ3H4P.mjs → chunk-NFMCP2HI.mjs} +3 -3
  152. package/dist/chunk-NG375ILQ.mjs +2 -0
  153. package/dist/chunk-NVRNLK25.mjs +6 -0
  154. package/dist/chunk-NWFBE2YA.mjs +2 -0
  155. package/dist/chunk-NWR2LT5B.mjs +2 -0
  156. package/dist/chunk-OJKMINIU.mjs +20 -0
  157. package/dist/{chunk-4FS7Z7WR.mjs → chunk-OUUP3WKT.mjs} +1 -1
  158. package/dist/{chunk-BGGDRNYQ.mjs → chunk-OW5NWPOJ.mjs} +1 -1
  159. package/dist/chunk-PAREWQGB.mjs +4 -0
  160. package/dist/chunk-POQSE4C2.mjs +2 -0
  161. package/dist/chunk-PUOQ65NC.mjs +2 -0
  162. package/dist/{chunk-XNROSH2T.mjs → chunk-PVER7LSC.mjs} +2 -2
  163. package/dist/chunk-PZDLJJTJ.mjs +3 -0
  164. package/dist/chunk-Q47PLKIJ.mjs +15 -0
  165. package/dist/chunk-Q4UEPUWF.mjs +2 -0
  166. package/dist/chunk-QKXMPUXC.mjs +2 -0
  167. package/dist/chunk-QOUEFUCH.mjs +16 -0
  168. package/dist/chunk-RFDZXFJF.mjs +13 -0
  169. package/dist/chunk-RKPWLGZ3.mjs +4 -0
  170. package/dist/chunk-RMECZA2K.mjs +2 -0
  171. package/dist/{chunk-7DTINW6U.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  172. package/dist/chunk-SX4LJYT6.mjs +8 -0
  173. package/dist/chunk-SXHBYZST.mjs +16 -0
  174. package/dist/chunk-TANZRINB.mjs +2 -0
  175. package/dist/chunk-TEZAWDSQ.mjs +2 -0
  176. package/dist/chunk-UBBRTJ2R.mjs +24 -0
  177. package/dist/chunk-UFNYFFKO.mjs +20 -0
  178. package/dist/chunk-UGWYKHBL.mjs +170 -0
  179. package/dist/chunk-UKSHDZZ6.mjs +2 -0
  180. package/dist/chunk-UNOYVIYR.mjs +2 -0
  181. package/dist/{chunk-E7LWZRXY.mjs → chunk-V6RIYQZZ.mjs} +1 -1
  182. package/dist/chunk-VJPFVNNW.mjs +15 -0
  183. package/dist/chunk-VS3ZMVGX.mjs +5 -0
  184. package/dist/chunk-VTKNEYT3.mjs +6 -0
  185. package/dist/chunk-VXACTLO3.mjs +3 -0
  186. package/dist/chunk-YI43RG4P.mjs +2 -0
  187. package/dist/chunk-YQGT4AB2.mjs +6 -0
  188. package/dist/chunk-ZB4H7ZN4.mjs +2 -0
  189. package/dist/{chunk-IVDLMMBD.mjs → chunk-ZHEHPMBK.mjs} +1 -1
  190. package/dist/chunk-ZTHICSSF.mjs +2 -0
  191. package/dist/chunk-ZUNVAXLH.mjs +2 -0
  192. package/dist/chunk-ZWPMCK7P.mjs +2 -0
  193. package/dist/cli.mjs +1 -1
  194. package/dist/server.mjs +1 -1
  195. package/dist/{chunk-U6KNPJPR.mjs → update-fetch.mjs} +1 -1
  196. package/dist/worker.mjs +1 -1
  197. package/kit/board.css +95 -0
  198. package/kit/board.js +250 -0
  199. package/kit/charts.js +5 -71
  200. package/kit/code.js +14 -14
  201. package/kit/report.css +255 -17
  202. package/kit/runtime.js +1600 -125
  203. package/kit/state.js +10 -1
  204. package/kit/tables.js +128 -43
  205. package/kit/ui.js +77 -35
  206. package/package.json +2 -1
  207. package/packs/gallery/card/component.json +14 -0
  208. package/packs/gallery/card/example.html +10 -0
  209. package/packs/gallery/card/preview.svg +1 -0
  210. package/packs/gallery/card/style.css +6 -0
  211. package/packs/gallery/card/template.html +6 -0
  212. package/packs/gallery/card/writing.md +14 -0
  213. package/packs/gallery/chart-card/component.json +15 -0
  214. package/packs/gallery/chart-card/example.html +14 -0
  215. package/packs/gallery/chart-card/kit.js +130 -0
  216. package/packs/gallery/chart-card/preview.svg +1 -0
  217. package/packs/gallery/chart-card/style.css +42 -0
  218. package/packs/gallery/chart-card/template.html +13 -0
  219. package/packs/gallery/chart-card/writing.md +20 -0
  220. package/packs/gallery/chart-view/component.json +20 -0
  221. package/packs/gallery/chart-view/example.html +13 -0
  222. package/packs/gallery/chart-view/kit.js +355 -0
  223. package/packs/gallery/chart-view/preview.svg +1 -0
  224. package/packs/gallery/chart-view/style.css +94 -0
  225. package/packs/gallery/chart-view/template.html +3 -0
  226. package/packs/gallery/chart-view/writing.md +22 -0
  227. package/packs/gallery/countdown/component.json +18 -0
  228. package/packs/gallery/countdown/example.html +3 -0
  229. package/packs/gallery/countdown/kit.js +156 -0
  230. package/packs/gallery/countdown/preview.svg +1 -0
  231. package/packs/gallery/countdown/style.css +130 -0
  232. package/packs/gallery/countdown/template.html +3 -0
  233. package/packs/gallery/countdown/writing.md +22 -0
  234. package/packs/gallery/habit/component.json +14 -0
  235. package/packs/gallery/habit/example.html +3 -0
  236. package/packs/gallery/habit/kit.js +295 -0
  237. package/packs/gallery/habit/preview.svg +1 -0
  238. package/packs/gallery/habit/style.css +246 -0
  239. package/packs/gallery/habit/template.html +3 -0
  240. package/packs/gallery/habit/writing.md +21 -0
  241. package/packs/gallery/heatmap/component.json +18 -0
  242. package/packs/gallery/heatmap/example.html +3 -0
  243. package/packs/gallery/heatmap/kit.js +351 -0
  244. package/packs/gallery/heatmap/preview.svg +1 -0
  245. package/packs/gallery/heatmap/style.css +201 -0
  246. package/packs/gallery/heatmap/template.html +3 -0
  247. package/packs/gallery/heatmap/writing.md +21 -0
  248. package/packs/gallery/kanban/component.json +18 -0
  249. package/packs/gallery/kanban/example.html +12 -0
  250. package/packs/gallery/kanban/kit.js +540 -0
  251. package/packs/gallery/kanban/preview.svg +1 -0
  252. package/packs/gallery/kanban/style.css +212 -0
  253. package/packs/gallery/kanban/template.html +3 -0
  254. package/packs/gallery/kanban/writing.md +20 -0
  255. package/packs/gallery/metric/component.json +22 -0
  256. package/packs/gallery/metric/example.html +15 -0
  257. package/packs/gallery/metric/kit.js +248 -0
  258. package/packs/gallery/metric/preview.svg +1 -0
  259. package/packs/gallery/metric/style.css +92 -0
  260. package/packs/gallery/metric/template.html +3 -0
  261. package/packs/gallery/metric/writing.md +23 -0
  262. package/packs/gallery/note/component.json +14 -0
  263. package/packs/gallery/note/example.html +3 -0
  264. package/packs/gallery/note/kit.js +102 -0
  265. package/packs/gallery/note/preview.svg +1 -0
  266. package/packs/gallery/note/style.css +76 -0
  267. package/packs/gallery/note/template.html +3 -0
  268. package/packs/gallery/note/writing.md +18 -0
  269. package/packs/gallery/pack.json +8 -0
  270. package/packs/gallery/recent/component.json +13 -0
  271. package/packs/gallery/recent/example.html +1 -0
  272. package/packs/gallery/recent/kit.js +238 -0
  273. package/packs/gallery/recent/preview.svg +1 -0
  274. package/packs/gallery/recent/style.css +158 -0
  275. package/packs/gallery/recent/template.html +1 -0
  276. package/packs/gallery/recent/writing.md +15 -0
  277. package/packs/gallery/static/component.json +13 -0
  278. package/packs/gallery/static/example.html +11 -0
  279. package/packs/gallery/static/preview.svg +1 -0
  280. package/packs/gallery/static/style.css +138 -0
  281. package/packs/gallery/static/template.html +1 -0
  282. package/packs/gallery/static/writing.md +18 -0
  283. package/packs/gallery/stats/component.json +13 -0
  284. package/packs/gallery/stats/example.html +1 -0
  285. package/packs/gallery/stats/kit.js +166 -0
  286. package/packs/gallery/stats/preview.svg +1 -0
  287. package/packs/gallery/stats/style.css +151 -0
  288. package/packs/gallery/stats/template.html +1 -0
  289. package/packs/gallery/stats/writing.md +11 -0
  290. package/packs/gallery/today/component.json +12 -0
  291. package/packs/gallery/today/example.html +1 -0
  292. package/packs/gallery/today/kit.js +185 -0
  293. package/packs/gallery/today/preview.svg +1 -0
  294. package/packs/gallery/today/style.css +120 -0
  295. package/packs/gallery/today/template.html +1 -0
  296. package/packs/gallery/today/writing.md +14 -0
  297. package/packs/gallery/todos/component.json +19 -0
  298. package/packs/gallery/todos/example.html +3 -0
  299. package/packs/gallery/todos/kit.js +342 -0
  300. package/packs/gallery/todos/preview.svg +1 -0
  301. package/packs/gallery/todos/style.css +267 -0
  302. package/packs/gallery/todos/template.html +3 -0
  303. package/packs/gallery/todos/writing.md +30 -0
  304. package/packs/gallery/weather/component.json +19 -0
  305. package/packs/gallery/weather/example.html +3 -0
  306. package/packs/gallery/weather/kit.js +312 -0
  307. package/packs/gallery/weather/preview.svg +1 -0
  308. package/packs/gallery/weather/style.css +258 -0
  309. package/packs/gallery/weather/template.html +3 -0
  310. package/packs/gallery/weather/writing.md +26 -0
  311. package/packs/gallery-soft/pack.json +8 -0
  312. package/release.json +12 -10
  313. package/sdk/doc-kit.d.ts +396 -5
  314. package/sdk/doc-state.d.ts +2 -0
  315. package/skill/SKILL.md +56 -23
  316. package/skill/references/block-script.md +140 -0
  317. package/skill/references/building-blocks.md +257 -0
  318. package/skill/references/extensions.md +59 -0
  319. package/skill/references/pages-and-data.md +221 -0
  320. package/skill/references/writing-html.md +6 -4
  321. package/skill/sdk/doc-kit.d.ts +396 -5
  322. package/skill/sdk/doc-state.d.ts +2 -0
  323. package/web/assets/index-BK2e_07w.js +13 -0
  324. package/web/assets/index-CWFI83mF.css +1 -0
  325. package/web/index.html +2 -2
  326. package/dist/chunk-3HIRPVLU.mjs +0 -2
  327. package/dist/chunk-5MHMDLZD.mjs +0 -4
  328. package/dist/chunk-64K7IPLO.mjs +0 -255
  329. package/dist/chunk-6QXGZM36.mjs +0 -8
  330. package/dist/chunk-6RGJOMJP.mjs +0 -16
  331. package/dist/chunk-AJ73XJF3.mjs +0 -2
  332. package/dist/chunk-AUZGSZJH.mjs +0 -13
  333. package/dist/chunk-BFE45AKL.mjs +0 -2
  334. package/dist/chunk-BXO2ZY5P.mjs +0 -2
  335. package/dist/chunk-CEH4MRCC.mjs +0 -2
  336. package/dist/chunk-CY2FNNAB.mjs +0 -16
  337. package/dist/chunk-DFUDV4LX.mjs +0 -2
  338. package/dist/chunk-DKXG4XDG.mjs +0 -2
  339. package/dist/chunk-EZQ34M3F.mjs +0 -124
  340. package/dist/chunk-EZY3WC6Z.mjs +0 -15
  341. package/dist/chunk-FUKQNOQS.mjs +0 -9
  342. package/dist/chunk-JPOSLGOC.mjs +0 -6
  343. package/dist/chunk-L3QKH4OK.mjs +0 -26
  344. package/dist/chunk-LAE5NQ4B.mjs +0 -2
  345. package/dist/chunk-LEF6DRCK.mjs +0 -59
  346. package/dist/chunk-NO5NJCHO.mjs +0 -2
  347. package/dist/chunk-NQPVAU63.mjs +0 -2
  348. package/dist/chunk-NSKUTQ5J.mjs +0 -5
  349. package/dist/chunk-O35FIXRB.mjs +0 -2
  350. package/dist/chunk-P2CAZPDP.mjs +0 -3
  351. package/dist/chunk-PL6GHLGD.mjs +0 -15
  352. package/dist/chunk-QJIR2BLP.mjs +0 -6
  353. package/dist/chunk-QUPLVPB2.mjs +0 -7
  354. package/dist/chunk-R7BNENLY.mjs +0 -4
  355. package/dist/chunk-S6O4UHLC.mjs +0 -2
  356. package/dist/chunk-SGJWQKEI.mjs +0 -2
  357. package/dist/chunk-TX6JH7TR.mjs +0 -2
  358. package/dist/chunk-TYK6VNAB.mjs +0 -10
  359. package/dist/chunk-UALRNVSE.mjs +0 -4
  360. package/dist/chunk-V3HXVQEM.mjs +0 -2
  361. package/dist/chunk-V5VXUJKG.mjs +0 -2
  362. package/dist/chunk-VBXMADMP.mjs +0 -2
  363. package/dist/chunk-VNV55RUA.mjs +0 -2
  364. package/dist/chunk-VPD2PS35.mjs +0 -2
  365. package/dist/chunk-W4VKN3GF.mjs +0 -7
  366. package/dist/chunk-W5BXXPDJ.mjs +0 -3
  367. package/dist/chunk-XUNHRCOG.mjs +0 -6
  368. package/skill/references/building-components.md +0 -367
  369. package/web/assets/index-Bh74DfsV.css +0 -1
  370. package/web/assets/index-UW0RyFFt.js +0 -13
@@ -0,0 +1,5 @@
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 y from"node:fs";import{fileURLToPath as S}from"node:url";import{namedPlace as h}from"../browser/shared/page-address.mjs";import{pageLinks as w}from"../browser/shared/page-links.mjs";import{reportsDirectory as b}from"../browser/shared/paths.mjs";import{listReportSlugs as g,slugPattern as x}from"../browser/shared/reports.mjs";import{RESERVED as v,isSlugName as N,listTrash as O}from"../browser/shared/workspace.mjs";var m=e=>/^--.|^-[A-Za-z]/.test(e),a=class extends Error{constructor(n){super(n),this.name="UsageError"}};function A(e){let n=y.readFileSync(S(e),"utf8").split(/\r?\n/),t=n.findIndex(s=>!s.startsWith("//"));return n.slice(0,t===-1?n.length:t).map(s=>s.replace(/^\/\/ ?/,"")).join(`
3
+ `)}var E=e=>/^Usage: (gallery \S+|npm run \S+|node \S+)/.exec(e)?.[1]??"this command",P=e=>e.split(`
4
+ `)[0],R=(e,n,t=P(e))=>{let s=E(e);return`${n}
5
+ ${t} (${s}${s.startsWith("npm run")?" --":""} --help says more)`},T=e=>{let n=e.indexOf("--");return(n===-1?e:e.slice(0,n)).some(t=>t==="--help"||t==="-h")};function $({options:e=[],values:n=[],argv:t=process.argv.slice(2)}={}){let s=t.indexOf("--"),[o,r]=s===-1?[t,[]]:[t.slice(0,s),t.slice(s+1)],l=[],u=new Set,p=new Map;for(let c=0;c<o.length;c++){let i=o[c],[f,k]=i.startsWith("--")&&i.includes("=")?[i.slice(0,i.indexOf("=")),i.slice(i.indexOf("=")+1)]:[i,void 0];if(!m(i))l.push(i);else if(n.includes(f)){let d=k??(c+1<o.length&&!m(o[c+1])?o[++c]:void 0);if(!d)throw new a(`${f} takes a value`);p.set(f,d)}else if(e.includes(i))u.add(i);else throw new a(`Unknown option: ${i}`)}return{positional:[...l,...r],options:u,values:p}}function U(e){if(!x.test(e))throw new a(`Not a document's slug: ${e} (lowercase kebab-case).`);if(v.has(e))throw new a(`Not a document's slug: ${e} (a name the workspace keeps for itself).`);return e}async function L(e){let n=await O(b),t=n.filter(({kind:r})=>r==="document"),s=h(e,w(t));if(s)return`${e} is a document in the trash ("${t.find(({slug:r})=>r===s.slug).title}"): it has to be restored in the workbench first.`;let o=n.find(({kind:r,slug:l})=>r==="page"&&l===e);return o?`${e} is a custom page in the trash ("${o.title}"), not a document: once it is restored in the workbench, gallery page open ${e} opens it.`:null}async function W(e){let n=(await g()).filter(N),t=h(e,w(n.map(o=>({slug:o}))));if(t)return t;let s=await L(e);if(s)throw new a(s);if(!x.test(e))throw new a(`Not a document's slug, link or address: ${e} (gallery list shows them).`);return{slug:U(e),block:null}}async function D({options:e=[],values:n=[],argv:t,noneIsAll:s=!1}={}){let{positional:o,options:r,values:l}=$({options:["--all",...e],values:n,argv:t}),u=r.has("--all");if(u&&o.length>0)throw new a("Name documents or pass --all, not both.");if(!u&&o.length===0&&!s)throw new a("Name a document (or pass --all).");let p=await Promise.all(o.map(W));return{slugs:u||o.length===0?await g():[...new Set(p.map(({slug:c})=>c))],options:r,values:l}}async function Z(e,{documents:n=!1,...t}={}){let s=A(e),o=t.argv??process.argv.slice(2);T(o)&&(console.log(s),process.exit(0));try{return n?await D({...t,argv:o}):$({...t,argv:o})}catch(r){if(!(r instanceof a))throw r;console.error(R(s,r.message)),process.exit(2)}}export{m as a,a as b,A as c,R as d,T as e,$ as f,U as g,L as h,W as i,D as j,Z as k};
@@ -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}from"./chunk-MHW7ZKOU.mjs";import"./chunk-BPL64HGA.mjs";import"./chunk-OUUP3WKT.mjs";import"./chunk-OJKMINIU.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import"./chunk-SXHBYZST.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-HMYTM3GT.mjs";import"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as noDocuments,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}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};
@@ -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{g as S,h as Q}from"./chunk-UGWYKHBL.mjs";import{a as A,b as z,d as W,g as J,i as K,j as X}from"./chunk-NFMCP2HI.mjs";import{a as w}from"./chunk-JEUK3ZO7.mjs";import{f as R}from"./chunk-N7AZZLGT.mjs";import{h as U,i as q}from"./chunk-UFNYFFKO.mjs";import{a as Y,e as _,f as F}from"./chunk-D4EURAX4.mjs";import{a as B,b as h,f as H}from"./chunk-4OZWXZE5.mjs";import{f as L}from"./chunk-FWNRPMCJ.mjs";import{editStateDirectory as re,reportsDirectory as ee}from"../browser/shared/paths.mjs";import{FIRST_BOARD as ce,HOME as b,createPage as le,listPages as he,pageExists as te,pageFiles as N,pageSlugRefused as se,pagesSettings as de,readPageMeta as pe}from"../browser/shared/pages.mjs";import{findPreviewServer as oe}from"../browser/shared/preview-server.mjs";var M=(e,t)=>`${J(e)}#@${t}`,ge=(e,t)=>`http://127.0.0.1:${e}/pages/${t}`,fe="The home page (\u9996\u9875, slug home) is not made yet: Gallery makes it, with its own cards, when its server first starts in this workspace. gallery open --no-browser starts it: run that once, then gallery page list again. Do not make it with gallery page new.";async function I(e){return q()||te(b,e)||de(e).homeMade||await se(b,e)?null:fe}async function ne(e,t){return(e===b?await I(t):null)??`No custom page "${e}": ${w(N(e,t).html)} does not exist (gallery page list lists those there are).`}async function ae(e){return(await oe({reportsDirectory:e,answering:!0,timeout:2e3}))?.port??null}async function we(e,[t,o,...i]){if(!t||!o?.trim()||i.length)throw new h("Name the slug and the title, the title quoted when it has spaces.");let n=await se(t,e);n&&(console.error(n),process.exit(1));let s=t===b?await I(e):null;s&&(console.error(s),process.exit(1));let a=await le(t,o,{root:e});console.log(`Created ${w(a.html)} and page.json`),console.log(`It is listed in the workbench's sidebar, under \u65B0\u5EFA and \u641C\u7D22${t===b?", first: the home page (\u9996\u9875)":""}, and shows one empty board (data-board-id="main").`);let r=await ae(e),l=`write the page's cards into page.html, each <section class="gallery-card" data-card-id="\u2026" data-x data-y data-w data-h> around one custom block's instance, no script`,m=`at the end tell them where it is in the sidebar (under \u65B0\u5EFA and \u641C\u7D22, its title${t===b?", first":""})`;r?(console.log(`Next: send the user the address on the last line now, in a message of its own (the page is theirs to watch as its cards arrive); ${l}; ${m}.`),console.log(`${A}${M(r,t)}`)):console.log(`Next: run gallery page open ${t} --no-browser now (it starts the server) and send the user the address on its \u4EA4\u7ED9\u7528\u6237 line, in a message of its own, before you write any card (the page is theirs to watch as its cards arrive); then ${l}; ${m}.`)}async function me(e,t){if(t.length)throw new h("gallery page list takes nothing else.");let o=await he(e);console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let i=await I(e);o.length===0&&!i?console.log('No custom pages yet: gallery page new <slug> "<\u6807\u9898>" makes one.'):o.length>0&&console.log(`Custom pages, in the sidebar's order (${o.length}):`);let n=o.length?await ae(e):null;for(let{slug:s,title:a,icon:r}of o)console.log(`- ${s} ${r?`${r} `:""}${a}${s===b?" (\u9996\u9875: the home page)":""}`),console.log(` \u5730\u5740\uFF1A${n?M(n,s):`/#@${s}`} ${w(N(s,e).html)}`);i&&console.log(i)}async function ue(e,[t,...o],i){if(!t||o.length)throw new h("gallery page open takes one page's slug.");await pe(t,e)||(console.error(await ne(t,e)),process.exit(1)),console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let s=await K({command:`gallery page open ${t}`});s.ok||(console.error(s.message),process.exit(1));let a=[X(s),`${z}${ge(s.port,t)}`,`${A}${M(s.port,t)}`];for(let r of a)console.log(r);console.log(await W(a,i))}async function V(e,t,o){let i=`127.0.0.1:${e.port}`;try{let n=await fetch(`http://${i}/__gallery/pages/${t}/cards`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${i}`,"X-Gallery-Token":e.token},body:JSON.stringify({...o,workspace:ee}),signal:AbortSignal.timeout(3e4)}),s=await n.json().catch(()=>null);return!s||["elsewhere","token","host","origin","unknown","method"].includes(s.reason)?null:[n.status,s]}catch{return null}}var $e=8e3,x={places:e=>`${e} is a block of documents (its manifest's places has no "page"): it does not go on a custom page.`,disabled:e=>`${e} is turned off (\u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 \u505C\u7528): nothing of it loads, on a page or in a document.`,missing:e=>`No custom block ${e} in this workspace: gallery block list lists them.`,template:e=>`${e} has no template.html a new card can be made of (gallery block check ${e} says why).`,board:(e,t)=>`No board "${t}" on this page: its <div class="gallery-board" data-board-id="\u2026">s are the ones there are.`,cells:()=>"--x, --y, --w and --h are whole numbers (x and y from 0, w and h from 1).",busy:()=>"page.html was written again and again meanwhile: run this again.",size:()=>"page.html would grow past 1,000,000 bytes.",values:(e,t,o)=>`${e}'s setting ${o?`"${o}" `:""}does not take that value (a text of 10,000 characters at most, a number, a date, one of a select's options, a switch's true or false).`,settings:e=>`${e} has no settings, or a card of it no settings part: --set goes with a block whose manifest has some.`};function ye(e){let t=e.indexOf("--"),o=[],i=[];for(let n=0;n<e.length;n++){let s=e[n];if(t!==-1&&n>=t)i.push(s);else if(s==="--set"||s.startsWith("--set=")){let a=s==="--set"?e[n+1]:s.slice(6);s==="--set"&&(n+=1);let r=a?.indexOf("=")??-1;if(a===void 0||r<1)throw new h("--set takes a setting's key and its value: --set <key>=<value> (--set city=\u4E0A\u6D77).");o.push([a.slice(0,r),a.slice(r+1)])}else i.push(s)}return{argv:i,given:o}}var Z=new Map([["true",!0],["yes",!0],["on",!0],["1",!0],["false",!1],["no",!1],["off",!1],["0",!1]]);function be(e,t){let o=t.settings??[],i=()=>o.length?`its settings are ${o.map(({key:s,label:a})=>`${s} (${a?.en??a?.zh??s})`).join(", ")}`:"it has no settings",n={};for(let[s,a]of e){let r=o.find(l=>l.key===s);if(!r)throw new h(`${t.id} has no setting "${s}": ${i()}.`);if(Object.hasOwn(n,s))throw new h(`--set ${s} is given twice.`);if(r.type==="number"){if(a.trim()!==""&&!Number.isFinite(Number(a)))throw new h(`The setting ${s} of ${t.id} is a number: --set ${s}=<number>, or --set ${s}= for none.`);n[s]=a.trim()===""?null:Number(a)}else if(r.type==="switch"){if(!Z.has(a.trim().toLowerCase()))throw new h(`The setting ${s} of ${t.id} is a switch: --set ${s}=true or --set ${s}=false.`);n[s]=Z.get(a.trim().toLowerCase())}else if(r.type==="select"){if(!r.options.includes(a))throw new h(`The setting ${s} of ${t.id} is one of ${r.options.join(", ")}: --set ${s}=<one of them>.`);n[s]=a}else if(r.type==="date"){if(a!==""&&!/^\d{4}-\d{2}-\d{2}$/.test(a))throw new h(`The setting ${s} of ${t.id} is a date, written YYYY-MM-DD: --set ${s}=2027-02-06.`);n[s]=a}else n[s]=a}return n}function ke(e,t){let o=t&&typeof t=="object"&&!Array.isArray(t)?t:{};return(e.settings??[]).filter(i=>i.required&&i.type!=="switch").filter(({key:i,default:n})=>{let s=Object.hasOwn(o,i)?o[i]:n;return s==null||typeof s=="string"&&s.trim()===""}).map(({key:i,label:n})=>({key:i,label:n?.en??n?.zh??i,zh:n?.zh??null}))}async function xe(e,[t,o,...i],n,s,a,r=[]){if(!t||!o||i.length)throw new h("gallery page add takes a page's slug and a block's id (gallery block list lists them).");let l={};for(let c of["x","y","w","h"]){let p=s.get(`--${c}`);if(p!==void 0){if(!/^\d+$/.test(p)||(c==="w"||c==="h")&&Number(p)<1)throw new h(x.cells());l[c]=Number(p)}}if(l.x===void 0!=(l.y===void 0))throw new h("--x and --y go together: a place is both.");te(t,e)||(console.error(await ne(t,e)),process.exit(1));let m=o.includes("/")?null:_(o),d=o.includes("/")?o:m?m.id:o,u=L(e),$=u.packages.get(d);if(!$){let c=F(d)?_(d):null;u.settings.disabled.includes(d)?console.error(x.disabled(d)):console.error(c?`${d} is one of Gallery's own blocks, not yet in this workspace: gallery block add ${c.pack===Y?c.name:c.id} puts it in; then run this again.`:u.problems.has(d)?`${d} does not load (gallery block check ${d} says why).`:x.missing(d)),process.exit(1)}$.places.includes("page")||(console.error(x.places(d)),process.exit(1));let g=s.get("--board"),k=r.length?be(r,$):null,j={op:"add",block:d,...g?{board:g}:{},...l,...k?{settings:k}:{},agent:!0},T=await oe({reportsDirectory:e}),v=T?await V(T,t,j):null;for(let c=0;v?.[1]?.reason==="missing"&&c<$e/250;c++)await new Promise(p=>setTimeout(p,250)),v=await V(T,t,j);let[ie,f]=v??await U({root:e,stateDirectory:re,catalog:()=>u}).apply(t,j);if(!f?.ok){let c=f?.reason;console.error(x[c]?.(d,g??ce,f?.message)??`Not added (${ie}: ${c??"no answer"}${f?.message?`: ${f.message}`:""}).`),process.exit(1)}let y=f.cards.find(c=>c.id===f.card),G=(f.pushed??[]).map(c=>f.cards.find(p=>p.id===c)).filter(Boolean);console.log(`Added a card of ${d} to ${w(N(t,e).html)}${v?" (through the workspace's running server: an open page shows it at once)":""}:`),console.log(` data-card-id="${y.id}" on board ${y.board}: x ${y.x}, y ${y.y}, w ${y.w}, h ${y.h}${f.measure?" (its block gives no height: 2 cells, --h sets another)":""}`),G.length&&console.log(` Pushed down under it, as it met them: ${G.map(c=>`${c.id} (y ${c.y})`).join(", ")}; no card moved up.`),k&&console.log(` Settings written with it: ${Object.entries(k).map(([c,p])=>`${c}=${JSON.stringify(p)}`).join(", ")}`),console.log(k?"The rest of its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.":"Its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.");let O=ke($,{...k??{}});if(O.length){let c=O.map(({key:p,label:E,zh:P})=>`${p} (${P&&P!==E?`${E}, ${P}`:E})`).join(", ");console.log(`${d} needs its setting ${c} before the card shows anything, and this card has none: ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents) and tell them in the handoff which you did. Give it with the add (${O.map(({key:p})=>`--set ${p}=<value>`).join(" ")}); for this card, write it in its settings part of ${w(N(t,e).html)} (the <script type="application/json"> of data-card-id="${y.id}": {"${O[0].key}":"\u2026"}), re-reading the page right before, or the user fills it in on the card (the grip at its top right \u203A \u8BBE\u7F6E\u2026).`)}}var C={new:we,list:me,open:ue,add:xe,try:async(e,t,o,i,n)=>(await import("./chunk-FWW4CSAZ.mjs")).pageTryCommand(e,{named:t,values:i,seconds:n,keep:o.has("--keep"),replace:o.has("--replace")}),check:async(e,t)=>(await import("./chunk-DQCE7TJY.mjs")).pageCheckCommand(e,t)},D=["--board","--x","--y","--w","--h"];async function Ie(e){try{return await ve(e)}catch(t){throw t instanceof h&&e.find(o=>!B(o))==="try"&&(t.synopsis=R),t}}async function ve(e){let{argv:t,seconds:o}=Q(e),{argv:i,given:n}=ye(t),{positional:s,options:a,values:r}=H({options:["--no-browser","--keep","--replace"],values:[...D,...S],argv:i}),[l,...m]=s,d=Object.keys(C).join(", ");if(!l)throw new h(`Say what to do: ${d}.`);if(!Object.hasOwn(C,l))throw new h(`No such page command: ${l} (${d}).`);if(a.has("--no-browser")&&l!=="open")throw new h(`--no-browser goes with open, not ${l}.`);let u=[...S.filter(g=>r.has(g)),...Object.keys(o).filter(g=>!r.has(g)),...a.has("--keep")?["--keep"]:[],...a.has("--replace")?["--replace"]:[]];if(u.length&&l!=="try")throw new h(`${u[0]} goes with try, not ${l}.`);let $=D.filter(g=>r.has(g));if($.length&&l!=="add")throw new h(`${$.join(", ")} go with add, not ${l}.`);if(n.length&&l!=="add")throw new h(`--set goes with add, not ${l}.`);return C[l](ee,m,a,new Map([...r].filter(([g])=>l==="try"?S.includes(g):D.includes(g))),o,n)}export{M as a,ge as b,fe as c,ne as d,ye as e,be as f,ke as g,Ie as h};
@@ -0,0 +1,166 @@
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 On}from"./chunk-DR73Y2UJ.mjs";import{b as En}from"./chunk-NWFBE2YA.mjs";import{a as $n,i as Sn,j as bn}from"./chunk-PUOQ65NC.mjs";import{a as vn,b as xn}from"./chunk-ZUNVAXLH.mjs";import{k as ze}from"./chunk-6VTU6KEO.mjs";import{h as pn}from"./chunk-OJKMINIU.mjs";import{a as gn}from"./chunk-B4P2CM2J.mjs";import{a as kn}from"./chunk-VJPFVNNW.mjs";import{a as wn,b as yn}from"./chunk-PZDLJJTJ.mjs";import{a as hn}from"./chunk-UKSHDZZ6.mjs";import{a as ln,b as He,d as dn,e as fn,f as mn,g as un}from"./chunk-35NQ4PLQ.mjs";import{b as lt,e as Ft,g as dt,h as Ut,j as Bt,k as zt}from"./chunk-UFNYFFKO.mjs";import{a as At,d as Dt,e as Lt,f as It,k as Nt,l as Mt,m as Wt,q as Ht,s as ft,t as Gt}from"./chunk-D4EURAX4.mjs";import{b as en,c as tn,d as Ee,e as nn,f as on,g as Be,i as rn,m as an,p as sn,q as cn}from"./chunk-HMYTM3GT.mjs";import{d as Qt,e as Te,f as We,g as mt,h as qt,k as Ue}from"./chunk-SX4LJYT6.mjs";import{b as Kt,c as Jt}from"./chunk-PAREWQGB.mjs";import{i as Vt,j as Xt,k as Zt}from"./chunk-W3BGBJQW.mjs";import{d as Yt}from"./chunk-JVHHHGEA.mjs";import{a as De}from"./chunk-UBBRTJ2R.mjs";import{c as it,g as ae,j as jt,k as _t,p as Pt,q as Tt,v as Rt,w as ct}from"./chunk-FWNRPMCJ.mjs";import at from"node:fs";import es from"node:fs/promises";import ts from"node:http";import{editStateDirectory as ns,kitPublicDirectory as os,release as rs,releaseFile as st,reportsDirectory as _e,vendorDirectory as as,workbenchDirectory as ss}from"../browser/shared/paths.mjs";import{serve as Uo}from"../browser/shared/http.mjs";import{ensureWorkspace as is,layoutOf as cs}from"../browser/shared/workspace.mjs";import ye from"node:fs/promises";import Y from"node:path";import{assetFile as Ho,referencedFile as Cn}from"../browser/shared/media.mjs";import{pageAssetAddress as Go}from"../browser/shared/pages.mjs";function ut(e,n){if(!/assets\//i.test(e))return e;let t=Xt(e,a=>Cn(a)!==null);return Vt(e,Zt(t,a=>{let s=Cn(a.value);return Ho(s)?`${Go(n,s)}${/[?#].*$/.exec(a.value.trim())?.[0]??""}`:null}))}function jn(e,{reportsDirectory:n,kit:t,slug:a=null}={}){let{html:s,packages:f}=on(a?ut(e,a):e,{reportsDirectory:n,kit:t,page:!0});return{html:s,packages:f}}import{Z as Ko}from"../browser/shared/layers.mjs";import{escapeMarkup as pt}from"../browser/shared/escape.mjs";import{layoutNotesScript as Jo}from"../browser/shared/qa-levels.mjs";var Ge=30,Yo=`
3
+ [data-doc-dev].doc-checks { position: fixed; z-index: ${Ko.checks}; left: 12px; bottom: 12px; max-width: min(520px, calc(100vw - 24px));
4
+ font: 13px/1.5 system-ui, sans-serif; color: light-dark(#37352f, #e3e2e0); }
5
+ [data-doc-dev].doc-checks[hidden] { display: none; }
6
+ [data-doc-dev].doc-checks > summary { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; cursor: pointer;
7
+ list-style: none; color: light-dark(#a1352b, #f19c92); background: light-dark(#fce9e7, #3b2321);
8
+ box-shadow: 0 0 0 1px light-dark(rgb(161 53 43 / 18%), rgb(241 156 146 / 22%)); user-select: none; }
9
+ [data-doc-dev].doc-checks > summary::-webkit-details-marker { display: none; }
10
+ [data-doc-dev].doc-checks > div { margin-top: 6px; padding: 8px 12px; max-height: 50vh; overflow: auto; border-radius: 10px;
11
+ background: light-dark(#ffffff, #252525); box-shadow: 0 0 0 1px light-dark(rgb(42 28 0 / 7%), #383836), 0 20px 24px light-dark(rgb(25 25 25 / 5%), rgb(0 0 0 / 20%)); }
12
+ [data-doc-dev].doc-checks ul { margin: 0; padding-left: 18px; }
13
+ [data-doc-dev].doc-checks li { margin: 2px 0; overflow-wrap: anywhere; }
14
+ [data-doc-dev].doc-checks p { margin: 6px 0 0; color: light-dark(#787774, #9b9a97); }
15
+ [data-doc-dev].doc-checks .doc-checks-live:not(:first-child) { margin-top: 8px; }
16
+ @media print { [data-doc-dev].doc-checks { display: none; } }`,Vo=`(() => {
17
+ document.currentScript.remove();
18
+ ${Jo()}
19
+ const panel = document.querySelector("details.doc-checks[data-doc-dev]");
20
+ if (!panel) return;
21
+ const failures = Number(panel.dataset.failures) || 0;
22
+ const live = panel.querySelector(".doc-checks-live ul");
23
+ // The note's words in the UI's language (the root's data-ge-language).
24
+ const english = document.documentElement.getAttribute("data-ge-language") === "en";
25
+ const WORDS = english
26
+ ? { card: "Chart card", table: "Table", named: (kind, name) => kind + " \u201C" + name + "\u201D", first: (name) => "Table (first column \u201C" + name + "\u201D)", colon: ": ",
27
+ failing: (count) => "Checks failed \xB7 " + count, more: (count) => count + " more", all: (slug) => "gallery check " + slug + " runs every check (TypeScript too)." }
28
+ : { card: "\u56FE\u8868\u5361\u7247", table: "\u8868\u683C", named: (kind, name) => kind + "\u300C" + name + "\u300D", first: (name) => "\u8868\u683C\uFF08\u9996\u5217\u300C" + name + "\u300D\uFF09", colon: "\uFF1A",
29
+ failing: (count) => "\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 " + count + " \u9879", more: (count) => "\u8FD8\u6709 " + count + " \u9879", all: (slug) => "gallery check " + slug + " \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002" };
30
+ const more = panel.querySelector("[data-more]");
31
+ if (more) more.textContent = WORDS.more(more.dataset.more);
32
+ const all = panel.querySelector("[data-all]");
33
+ if (all) all.textContent = WORDS.all(all.dataset.all);
34
+ const tidy = (node) => (node?.textContent ?? "").replace(/\\s+/g, " ").trim().slice(0, 40);
35
+ const what = (host) => {
36
+ const card = host.closest("figure");
37
+ const title = card?.querySelector(":scope > h3, :scope > figcaption");
38
+ const table = host.closest(".doc-table-wrap, table");
39
+ const caption = table?.querySelector("caption");
40
+ const header = table?.querySelector("th");
41
+ return title ? WORDS.named(WORDS.card, tidy(title)) : card ? WORDS.card : caption && tidy(caption) ? WORDS.named(WORDS.table, tidy(caption)) : header ? WORDS.first(tidy(header)) : host.localName;
42
+ };
43
+ // A chart that drew nothing says why in its card (the kit's line, in the same language): that line, else the note in words.
44
+ const said = (host, name, note) => (name === "data-missing" && tidy(host.querySelector(".doc-chart-message"))) || noteInWords(note, { english });
45
+ let shown = "";
46
+ let frame = 0;
47
+ const draw = () => {
48
+ frame = 0;
49
+ const notes = [...document.querySelectorAll("[data-doc-layout]")].filter((host) => !host.closest("[data-doc-dev]"))
50
+ .flatMap((host) => layoutNotesOf(host.getAttribute("data-doc-layout"), document.documentElement.clientWidth)
51
+ .filter(({ level }) => level === "fail")
52
+ .map(({ note, name }) => ({ line: what(host) + WORDS.colon + said(host, name, note), note })));
53
+ const key = notes.map(({ line }) => line).join("\\n");
54
+ if (key === shown) return;
55
+ shown = key;
56
+ live.replaceChildren(...notes.map(({ line, note }) => Object.assign(document.createElement("li"), { textContent: line, title: note })));
57
+ live.parentElement.hidden = notes.length === 0;
58
+ const failing = failures + notes.length;
59
+ panel.querySelector("summary").textContent = failing ? WORDS.failing(failing) : "";
60
+ panel.hidden = failing === 0;
61
+ };
62
+ const later = (records) => {
63
+ if (!globalThis.document?.defaultView) return; // the page is gone
64
+ if (!frame && records.some((record) => !record.target.closest?.("[data-doc-dev]"))) frame = requestAnimationFrame(draw);
65
+ };
66
+ new MutationObserver(later).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ["data-doc-layout"] });
67
+ addEventListener("resize", () => { if (!frame) frame = requestAnimationFrame(draw); });
68
+ draw();
69
+ })();`;function _n(e,n,t={},{directory:a}={}){let s=rn({slug:e,html:n,metadata:t,...a?{directory:a}:{}}),f=s.slice(0,Ge).map(h=>`<li>${pt(h)}</li>`).join(""),r=s.length>Ge?`<p data-more="${s.length-Ge}">\u8FD8\u6709 ${s.length-Ge} \u9879</p>`:"",m=s.length?`<ul>${f}</ul>${r}<p data-all="${pt(e)}">gallery check ${pt(e)} \u8DD1\u5168\u90E8\u68C0\u67E5\uFF08\u542B TypeScript\uFF09\u3002</p>`:"";return`<details class="doc-checks" data-doc-dev data-failures="${s.length}"${s.length?"":" hidden"}><summary>${s.length?`\u68C0\u67E5\u672A\u901A\u8FC7 \xB7 ${s.length} \u9879`:""}</summary><div>${m}<div class="doc-checks-live" hidden><ul></ul></div></div><style>${Yo}</style></details>
70
+ <script data-doc-dev>${Vo}</script>`}import{browserDirectory as ha,editStateDirectory as ga,kitSourceDirectory as _o,release as wa,reportsDirectory as F}from"../browser/shared/paths.mjs";import{sendJson as po,serve as Po,serveFound as Fe}from"../browser/shared/http.mjs";import{languageScript as ho}from"../browser/shared/i18n/index.mjs";import{announcePreviewServer as ya,galleryVersion as ka}from"../browser/shared/preview-server.mjs";import{registerQuietly as va}from"../browser/shared/workspace-registry.mjs";import{lookWord as go}from"../browser/shared/document-look.mjs";import{documentLook as wo,ownLookAt as xa}from"../browser/shared/workspace-look.mjs";import{slugPattern as To}from"../browser/shared/reports.mjs";import{ATTRIBUTE as nt,PACKAGE_ID as $a}from"../browser/shared/components/installed.mjs";import{COMPONENTS_FOLDER as yo,DOCUMENT_FOLDERS as ko,EXTENSIONS_FOLDER as Sa,PAGES_FOLDER as ba,WORKSPACE_FILE as ot,documentDirectory as St,documentFiles as Ea,isDocumentFile as Oa,isDocumentSource as vo,isSlugName as Ro,layoutOf as Ca}from"../browser/shared/workspace.mjs";import{HOME as xo,PAGE_FILES as $o,homeCardsNew as ja,homeHintClosed as _a,isPageFile as Pa,pageFiles as So,pageVersion as bo}from"../browser/shared/pages.mjs";import{LINK_FILE as Ta}from"../browser/shared/web-links.mjs";import{SIDEBAR_FILE as Eo}from"../browser/shared/extension-sidebar.mjs";import{extensionColumnIds as Oo}from"../browser/shared/extensions.mjs";import{isExtensionId as Ra}from"../browser/shared/outline-shape.mjs";import{createHash as lr,randomBytes as dr}from"node:crypto";import q from"node:fs";import ht from"node:os";import we from"node:path";import{Transform as fr}from"node:stream";import{pipeline as mr}from"node:stream/promises";import{exportSourceOf as ur}from"../browser/shared/export-wrap.mjs";import{writeAtomic as gt}from"../browser/shared/files.mjs";import{sendJson as J}from"../browser/shared/http.mjs";import{said as wt,saying as pr}from"../browser/shared/i18n/index.mjs";import{IMPORT_LIMIT as An}from"../browser/shared/import-types.mjs";import{mediaUrl as hr}from"../browser/shared/media.mjs";import{fullAddress as gr}from"../browser/shared/page-address.mjs";import{documentLinks as Dn,slugPattern as Ln}from"../browser/shared/reports.mjs";import{documentDirectory as wr,documentFiles as In,newDocSlug as yr,pageSlug as kr}from"../browser/shared/workspace.mjs";import{readWritingPreferences as vr,saysAnything as xr,unshownLines as $r}from"../browser/shared/writing-preferences.mjs";import Pn from"node:fs/promises";import or from"node:path";import{Worker as Xo}from"node:worker_threads";import{refusal as Zo,said as Qo}from"../browser/shared/i18n/index.mjs";var qo=6e4,me=null,er=0,Ke=0,Oe=new Map;function tr(){me=new Xo(new URL("./worker.mjs",import.meta.url)),me.on("message",({id:n,result:t,error:a})=>{let s=Oe.get(n);s&&(Oe.delete(n),a?s.reject(Object.assign(new Error(a.message),a)):s.resolve(t),Oe.size===0&&(me?.unref(),nr()))});let e=n=>{for(let t of Oe.values())t.reject(n);Oe.clear(),me=null};me.on("error",e),me.on("exit",n=>e(Zo(Qo("\u8F6C\u6362\u8FDB\u7A0B\u610F\u5916\u9000\u51FA\uFF08{0}\uFF09",n))))}function nr(){clearTimeout(Ke),Ke=setTimeout(()=>{if(Oe.size===0&&me){let e=me;me=null,e.removeAllListeners("exit"),e.terminate()}},qo),Ke.unref?.()}function xe(e,n){clearTimeout(Ke),me||tr();let t=++er;return new Promise((a,s)=>{Oe.set(t,{resolve:a,reject:s}),me.ref(),me.postMessage({id:t,type:e,payload:n})})}import{pageLanguage as rr}from"../browser/shared/components/page.mjs";function Je(e){return String(e??"").replace(/[\\/:*?"<>|\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim().slice(0,100).trim()||"Untitled"}function Ye(e,n){let t=e.lastIndexOf("."),[a,s]=t>0?[e.slice(0,t),e.slice(t)]:[e,""];for(let f=0;;f+=1){let r=f===0?e:`${a} ${f}${s}`;if(!n.has(r.toLowerCase()))return n.add(r.toLowerCase()),r}}function Ve(e,n){let t=e.split("/").slice(0,-1),a=n.split("/"),s=0;for(;s<t.length&&s<a.length-1&&t[s]===a[s];)s+=1;return[...t.slice(s).map(()=>".."),...a.slice(s)].map(r=>r===".."?r:encodeURIComponent(r).replace(/\(/g,"%28").replace(/\)/g,"%29")).join("/")}import{documentDirectory as ar,documentFiles as sr}from"../browser/shared/workspace.mjs";var Tn={markdown:"md",html:"html",pdf:"pdf"},ir={markdown:"text/markdown; charset=utf-8",html:"text/html; charset=utf-8",pdf:"application/pdf"},cr=e=>typeof e=="number"&&e>.1&&e<2;function Rn(e){let{format:n,content:t="everything",subpages:a=!1,folders:s=!0,paper:f="A4",scale:r=1}=e??{};return Object.hasOwn(Tn,n)&&["everything","no_files"].includes(t)&&typeof a=="boolean"&&typeof s=="boolean"&&["A4","A3","Letter","Legal","Tabloid"].includes(f)&&cr(r)}async function Fn(e,n,t){let{format:a,content:s="everything",subpages:f=!1,folders:r=!0,paper:m="A4",scale:l=1}=n,h=Tn[a],w=s==="everything",i=[],v=new Map,P=x=>v.get(x)??v.set(x,new Set).get(x),u=async(x,b)=>{let z=await t.titleOf(x),G=Ye(`${Je(z)}.${h}`,P(b)),H=b?`${b}/${G}`:G,A=r?H.slice(0,-(h.length+1)):"";if(i.push({slug:x,title:z,file:H,folder:A,files:b?`${b}/assets`:"assets"}),f)for(let se of await t.childrenOf(x))await u(se,A)};await u(e,"");let{links:T}=await t.links(),S=(x,b)=>tn(b,x.slug,z=>{let G=a==="pdf"?null:i.find(H=>H.slug===z)?.file??null;return G&&Ve(x.file,G)},{blocks:a!=="markdown",links:T}),$=[],V=[];for(let x of i)if(a==="markdown"){await t.check(x.slug);let b=ar(x.slug,t.reportsDirectory),z=Ee(await Pn.readFile(sr(b).html,"utf8"),{slug:x.slug,mode:"words",reportsDirectory:t.reportsDirectory}),G=S(x,z),H=w&&!!$n(),{text:A,files:se,charts:oe,charted:B}=await xe("markdown",{source:G,title:x.title,pictures:H}),K=A,de=new Map;if(se.forEach(({src:p,name:g},E)=>{de.has(p)||(de.set(p,`${x.files}/${Ye(Je(g),P(x.files))}`),w&&V.push({from:or.join(b,p),name:de.get(p)}));let O=de.get(p);K=K.replace(`\0F${E}\0`,()=>Ve(x.file,O))}),H&&oe>0&&K.includes("\0C")){let p=await bn(await t.offline(x.slug,{files:!0})).catch(()=>[]);K=K.replace(/^.*\u0000C(\d+)\u0000.*$/gm,(g,E)=>{let O=p[Number(E)];if(!O)return"\0gone\0";let j=`${x.files}/${Ye(rr(G)==="en"?B[Number(E)]?"Chart.png":"Figure.png":B[Number(E)]?"\u56FE\u8868.png":"\u56FE.png",P(x.files))}`;return $.push({name:j,data:O,later:!0}),g.replace(`\0C${E}\0`,()=>Ve(x.file,j))}).replace(/\n*\u0000gone\u0000\n*/g,`
71
+
72
+ `).replace(/^\n+|\n+$/g,"")}$.push({name:x.file,data:K})}else a==="html"?$.push({name:x.file,data:S(x,await t.offline(x.slug,{files:w}))}):$.push({name:x.file,data:await Sn(S(x,await t.offline(x.slug,{files:w})),{paper:m,scale:l})});for(let x of V){let b=await Pn.readFile(x.from).catch(()=>null);b&&$.push({name:x.name,data:b})}let W=[...$.filter(x=>!x.later&&i.some(b=>b.file===x.name)),...$.filter(x=>x.later||!i.some(b=>b.file===x.name))];return W.length===1?{name:W[0].name,type:ir[a],data:Buffer.isBuffer(W[0].data)?W[0].data:Buffer.from(W[0].data,"utf8")}:{name:`${Je(i[0].title)}.zip`,type:"application/zip",data:hn(W)}}var Sr=3600*1e3,yt=new Set,Nn=!1,br=e=>{yt.add(e),!Nn&&(Nn=!0,process.once("exit",()=>{for(let n of yt)try{q.rmSync(n,{recursive:!0,force:!0})}catch{}}))},Er=/^u-[a-f0-9]{16}$/;function Mn({edits:e,workspace:n,reports:t,reportsDirectory:a,offline:s}){let f=null,r=()=>f??=q.promises.mkdtemp(we.join(ht.tmpdir(),"gallery-uploads-")).then(p=>(br(p),p)),m=new Map,l=(p,g,E)=>[p,{ok:!1,reason:g,...pr(E)}],h=p=>q.promises.access(p).then(()=>!0,()=>!1),w=p=>wr(p,a),i=p=>In(w(p)),v=async p=>{try{return JSON.parse(await q.promises.readFile(i(p).json,"utf8")).title||p}catch{return p}};function P(p){if(p.method!=="POST")return[405,{ok:!1,reason:"method"}];let g=p.headers.host??"",E=p.socket.localPort;return g!==`127.0.0.1:${E}`&&g!==`localhost:${E}`?[403,{ok:!1,reason:"host"}]:p.headers.origin!==`http://${g}`?[403,{ok:!1,reason:"origin"}]:p.headers["x-gallery-token"]!==e.token?[403,{ok:!1,reason:"token"}]:/^application\/octet-stream\b/i.test(p.headers["content-type"]??"")?Number(p.headers["content-length"]??0)>An?l(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09"):null:[415,{ok:!1,reason:"type"}]}async function u(){for(let[p,g]of m)Date.now()-g.at<Sr||(m.delete(p),await q.promises.rm(g.file,{force:!0}).catch(()=>{}))}async function T(p,g){let E=P(p);if(E)return p.resume(),J(g,...E);let O=new URL(p.url,"http://localhost").searchParams.get("name")?.replace(/[\u0000-\u001f]/g,"").trim()??"";if(!O||O.length>255)return p.resume(),J(g,...l(400,"name","\u6587\u4EF6\u540D\u4E0D\u5BF9"));await u();let j=`u-${dr(8).toString("hex")}`,C=we.join(await r(),j),L=0,R=new fr({transform(D,Q,X){L+=D.length,X(L>An?Object.assign(new Error("too-large"),{reason:"size"}):null,D)}});try{await mr(p,R,q.createWriteStream(C))}catch(D){return await q.promises.rm(C,{force:!0}).catch(()=>{}),D.reason==="size"?J(g,...l(413,"size","\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A 5GB\uFF09")):J(g,...l(400,"body","\u6587\u4EF6\u6CA1\u6709\u4F20\u5B8C"))}return m.set(j,{file:C,name:O,at:Date.now()}),J(g,200,{ok:!0,id:j})}async function S(p,g){let E=await e.check(p);if(E.error)return J(g,...E.error);let{slug:O,options:j}=E.body??{};if(typeof O!="string"||!Ln.test(O)||!await h(i(O).html))return J(g,...l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));if(!Rn(j))return J(g,...l(400,"options","\u5BFC\u51FA\u9009\u9879\u4E0D\u5BF9"));try{let C=await s(),L=new Map,R=_=>(L.has(_)||L.set(_,e.handIn(_,{reader:!0}).then(M=>{if(!M.ok)throw Object.assign(new Error(M.message??M.reason),{reason:M.reason});if(M.repeated.length)throw Object.assign(new Error("check"),{reason:"check",slug:_,failures:Be(M.repeated)})})),L.get(_)),D=new Map,Q={reportsDirectory:a,titleOf:v,childrenOf:async _=>{let{children:M,links:ie=[]}=await n.outline(),re=ke=>(M[ke]??[]).flatMap(ve=>ie.includes(ve)||ve.startsWith("~")?re(ve):[ve]);return re(_)},links:()=>Dn(a),offline:async(_,M)=>{await R(_);let ie=await C(_,M),re=j.format==="markdown"?null:ur(ie);return re&&D.set(_,re),ie},check:async _=>(await R(_),C.check(_))},{name:X,type:Z,data:ee}=await Fn(O,j,Q);D.size&&await(await ze([...D.keys()])).keep([...D.keys()],D),g.writeHead(200,{"Content-Type":Z,"Content-Length":ee.length,"Content-Disposition":`attachment; filename*=UTF-8''${encodeURIComponent(X)}`,"X-File-Name":encodeURIComponent(X),"Cache-Control":"no-store"}),g.end(ee)}catch(C){if(C.reason==="check"){let L=await v(C.slug),R=C.component?wt("\u300C{0}\u300D\u91CC\u7684\u7EC4\u4EF6 {1} \u6709\u9519\u8BEF\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\u5E76\u4FEE\u597D",L,C.component):C.failures.length>1?wt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}\uFF08\u5171 {2} \u5904\uFF1A\u53EF\u4EE5\u8BA9 AI \u68C0\u67E5\u8FD9\u4EFD\u6587\u6863\uFF0C\u5217\u51FA\u5168\u90E8\u5E76\u4FEE\u597D\uFF09",L,C.failures[0],C.failures.length):wt("\u300C{0}\u300D\u6CA1\u6709\u901A\u8FC7\u5BFC\u51FA\u524D\u7684\u68C0\u67E5\uFF0C\u6CA1\u6709\u751F\u6210\u6587\u4EF6\uFF1A{1}",L,C.failures[0]);return J(g,...l(422,"check",R))}J(g,...l(C.reason==="browser"?422:C.reason==="busy"?409:C.reason==="missing"?404:500,C.reason??"export",C))}}async function $(p,g){let E=await e.check(p);if(E.error)return J(g,...E.error);let{slug:O}=E.body??{},j=(await e.readTaken(O,{wait:0}))?.text??null;if(j===null)return J(g,...l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"));let C=`http://${p.headers.host}`,{named:L}=await Dn(a),R=en(Ee(j,{slug:O,mode:"words",reportsDirectory:a}),O,Z=>Z.slug&&gr(C,Z,L),L),{text:D,files:Q}=await xe("markdown",{source:R,title:await v(O),pictures:!1}),X=D.replace(/\u0000F(\d+)\u0000/g,(Z,ee)=>{let{src:_,kind:M}=Q[Number(ee)];return encodeURI(`${C}${hr(M==="image"?"asset":"file",O,_)}`)});return J(g,200,{ok:!0,text:X})}let V=async p=>{let g=await e.readTaken(p,{wait:0});return{source:g?.text??"",version:g?.version??null}},W=async(p,g=null)=>{let{source:E,version:O}=g??await V(p),j="\u5199\u4F5C\u504F\u597D",{text:C,files:L}=await xe("markdown",{source:E,title:j,pictures:!1}),R=C.split(`
73
+ `).slice(1).join(`
74
+ `).replace(/^[\s>]*(?:```.*|\d+\.|- \[x\])/gm,"").replace(/<\/?aside>/g,"");if(!/[\p{L}\p{N}]|\u0000F\d+\u0000/u.test(R))return{markdown:`# ${j}
75
+ `,empty:!0,version:O};let D=we.relative(a,w(p)).split(we.sep).join("/");return{markdown:`${C.replace(/\u0000F(\d+)\u0000/g,(Q,X)=>encodeURI(`${D}/${L[Number(X)].src}`))}
76
+ `,empty:!1,version:O}},x=p=>i(p).json,b=async p=>{try{let g=JSON.parse(await q.promises.readFile(x(p),"utf8"));return g&&typeof g=="object"?g:null}catch{return null}},z=p=>lr("sha256").update(p).digest("hex").slice(0,16);async function G(p,g,E,O){let j=await b(p);if(!j||E===null)return;let{synced:C,...L}=j,R={file:z(g),page:E,unshown:O},D=j.madeSame;C===void 0&&D?.file===R.file&&D?.page===R.page&&JSON.stringify(D?.unshown)===JSON.stringify(O)||await gt(x(p),`${JSON.stringify({...L,madeSame:R},null,2)}
77
+ `)}async function H(p,g){let E=await q.promises.mkdtemp(we.join(ht.tmpdir(),"gallery-preferences-"));try{let j=(await xe("import",{uploads:[{file:g,name:"preferences.md"}],scratch:E})).pages[0]??{nodes:[],raws:[],files:[],icon:null,lang:null},C=w(p),L=await b(p)??{},R=In(C).html,D=await q.promises.readFile(R,"utf8").catch(()=>""),Q=/<html\b[^>]*\slang="([^"]*)"/i.exec(D)?.[1]??null,{html:X}=await Jt(p,L.title||"\u5199\u4F5C\u504F\u597D",L.description||"",{blank:!0,lang:Q}),Z=typeof L.icon=="string"&&L.icon?L.icon:null,ee=await xe("fill",{source:X,nodes:j.nodes,icon:Z,raws:j.raws,lang:j.lang});j.files.length&&await q.promises.mkdir(we.join(C,"assets"),{recursive:!0});for(let{from:M,name:ie}of j.files){let re=we.join(C,"assets",ie);await h(re)||await q.promises.copyFile(M,re)}let _=await q.promises.readFile(R,"utf8").catch(()=>null);_!==null&&e.keepVersion?.(p,_),await gt(R,Ue(ee))}finally{await q.promises.rm(E,{recursive:!0,force:!0}).catch(()=>{})}}async function A(p,g){let E=await e.check(p);if(E.error)return J(g,...E.error);let O=E.body?.opening===!0,j=await kr(a);if(!j)return J(g,...l(404,"missing","\u8FD8\u6CA1\u6709\u5199\u4F5C\u504F\u597D"));let C=null,L=(R,D)=>[200,{ok:!0,path:we.resolve(C),remade:R,unshown:D}];return e.respond(async()=>{let R;({file:C,text:R}=await vr(a));let D=await V(j),Q=(await b(j))?.madeSame??null,X=Q===null||Q.page===D.version,Z=Q!==null&&X&&Q.file===z(R);if(O&&Z&&Array.isArray(Q.unshown))return L(!1,Q.unshown);let[ee,_,M,ie]=[R,"",D.version,!1];if(O&&!X)await H(j,C),{markdown:_,version:M}=await W(j),ie=!0;else{let ke=await W(j,D),ve=R.trim()===ke.markdown.trim()||ke.empty&&!xr(R);_=ke.markdown,O?!ve&&!Z&&(await H(j,C),{markdown:_,version:M}=await W(j),ie=!0):ve||(await gt(C,ke.markdown),ee=ke.markdown)}let re=$r(ee,_);return await G(j,ee,M,re),L(ie,re)})(p,g)}async function se(p,g){let E=await e.check(p);if(E.error)return J(g,...E.error);let{uploads:O,parent:j="",from:C,language:L}=E.body??{},R={said:typeof C=="string"&&C.includes("{0}")&&C.length<=60?C:"\u5BFC\u5165\u81EA {0}",lang:L==="en"?"en":null};if(!Array.isArray(O)||O.length===0||O.length>1e3||!O.every(_=>typeof _=="string"&&Er.test(_)))return J(g,...l(400,"body"));let D=O.map(_=>m.get(_)).filter(Boolean);if(D.length!==O.length)return J(g,...l(410,"gone","\u4E0A\u4F20\u7684\u6587\u4EF6\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u5BFC\u5165"));for(let _ of O)m.delete(_);let Q=typeof j=="string"&&Ln.test(j)&&await h(we.join(a,j))?j:"",X=await q.promises.mkdtemp(we.join(ht.tmpdir(),"gallery-import-")),Z=()=>Promise.all([q.promises.rm(X,{recursive:!0,force:!0}),...D.map(({file:_})=>q.promises.rm(_,{force:!0}))]).catch(()=>{}),ee;try{ee=await xe("import",{uploads:D.map(({file:_,name:M})=>({file:_,name:M})),scratch:X})}catch(_){return await Z(),J(g,...l(500,"convert",_))}return e.respond(async()=>{try{let{made:_,top:M}=await gn(ee.pages,{create:t.create,slugOf:()=>yr(a),folderOf:w,fill:ie=>xe("fill",ie),place:n.place,under:Q,...R});return[200,{ok:!0,pages:_.length,reports:M,skipped:ee.skipped,missing:oe(ee.pages)}]}finally{await Z()}})(p,g)}let oe=p=>[...new Set(p.flatMap(function g(E){return[...(E.notes??[]).filter(O=>O.kind==="picture-missing").map(O=>O.name),...E.children.flatMap(g)]}))],B={export:S,markdown:$,upload:T,import:se,preferences:A};function K(p,g,E){return Object.hasOwn(B,E)?B[E](p,g).catch(O=>{g.headersSent||J(g,...l(500,"transfer",O))}):J(g,404,{ok:!1,reason:"unknown"})}async function de(){let p=f;f=null,m.clear();let g=await p?.catch(()=>null);g&&(yt.delete(g),await q.promises.rm(g,{recursive:!0,force:!0}).catch(()=>{}))}return{handle:K,close:de}}import{FACT_KINDS as Fa,QUERY_ROUTE as Aa,WORKSPACE_GLOBAL as Da}from"../browser/shared/workspace-query.mjs";function Wn({settled:e,tell:n,delay:t=120,recheck:a=1e3}){let s=new Map,f=(r,m=t)=>{clearTimeout(s.get(r));let l=setTimeout(async()=>{let h=await e(r).catch(()=>({source:null,held:!1,wait:0}));if(s.get(r)===l){if(h.held)return f(r,Math.min(Math.max(h.wait,50),a));if(h.wait>0)return f(r,h.wait);await n(r,h)}},m);s.set(r,l)};return f}import Or from"node:fs/promises";import{packageScript as Cr}from"../browser/shared/export-wrap.mjs";import{serveFound as jr}from"../browser/shared/http.mjs";import{extensionOf as _r,mediaTypeOf as Pr}from"../browser/shared/media.mjs";var Tr="/__gallery/components/",Rr=/^\/__gallery\/components\/([a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*)\/(.+)$/,Fr={js:"text/javascript; charset=utf-8",mjs:"text/javascript; charset=utf-8",css:"text/css; charset=utf-8",wasm:"application/wasm"};async function Un(e,n,t,{root:a}){if(!e.startsWith(Tr))return!1;let[,s,f]=Rr.exec(e)??[],r=s?ae(a).packages.get(s):null,m=r?.files.includes(f)?Pt(r,f):null,l=m?await Or.readFile(m).catch(()=>null):null,h=l&&f==="kit.js"?Buffer.from(Cr(l.toString("utf8").replace(/^\uFEFF/,""))):l,w=h&&n===r.stamp&&n===Tt(r);return jr(t,h,{type:h?Fr[_r(f)]??Pr(f):void 0,headers:{"X-Content-Type-Options":"nosniff","Cache-Control":w?"max-age=31536000, immutable":"no-store"}}),!0}import{BLOCK_ICON as Ar}from"../browser/editor/components/icons.mjs";import{LISTED_BLOCKS as Bn}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as Dr}from"../browser/shared/components/installed.mjs";import{netHostsOf as zn}from"../browser/shared/net-policy.mjs";import{inLanguage as Hn,refusal as Xe,said as Se}from"../browser/shared/i18n/index.mjs";function Gn({root:e,taken:n}){let t=()=>{let r=ae(e);return{packages:Rt(r).map(m=>{let l=It(m.id)?Lt(m.id):null;return{...m,newer:l?Nt(e,l):null,...l?{addAs:l.pack===At?l.name:l.id}:{}}}),packs:ft(e,{settings:r.settings}),packageIcon:Ar,blocks:Bn.map(({id:m,name:l,icon:h,hideable:w})=>({id:m,name:{zh:Hn("zh",l),en:Hn("en",l)},icon:h,hidden:w&&r.settings.hidden.includes(m),hideable:w})),problem:_t(r)}},a=({id:r,hidden:m,shown:l,disabled:h,unlisted:w,net:i})=>{if(![m,l,h,w,i].every(P=>P===void 0||typeof P=="boolean"))return Se("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9");let v=Bn.find(P=>P.id===r);return v?h!==void 0||l!==void 0||w!==void 0||i!==void 0?Se("\u5185\u7F6E\u5757\u53EA\u80FD\u9690\u85CF\uFF0C\u4E0D\u80FD\u505C\u7528"):m&&!v.hideable?Se("\u8FD9\u4E2A\u5757\u4E0D\u80FD\u9690\u85CF"):null:typeof r=="string"&&Dr.test(r)?i&&zn(ae(e).packages.get(r)?.needs).length===0?Se("\u8FD9\u4E2A\u5757\u4E0D\u8054\u7F51"):null:Se("\u6CA1\u6709\u8FD9\u4E2A\u7EC4\u4EF6")};return{read:t,write:async r=>{if(r?.pack!==void 0){let{pack:i,enabled:v}=r;if(typeof v!="boolean")throw Xe(Se("\u5F00\u5173\u7684\u503C\u4E0D\u5BF9"));if(typeof i!="string"||!ft(e,{settings:ae(e).settings}).some(({id:P})=>P===i))throw Xe(Se("\u6CA1\u6709\u8FD9\u4E2A\u5757\u5305"));return await it(e,{pack:i,enabled:v}),n(),t()}let m=a(r);if(m)throw Xe(m);let{net:l,...h}=r,w=l===void 0?void 0:l?zn(ae(e).packages.get(r.id)?.needs):[];return await it(e,{...h,...w?{net:w}:{}}),n(),t()},install:({path:r,zip:m}={})=>{let l=typeof m=="string"?xn(Buffer.from(m,"base64")):typeof r=="string"&&r.trim()?vn(r):null;if(!l)throw Xe(Se("\u7C98\u8D34\u5757\u5305\u7684\u6587\u4EF6\u5939\u6216 zip \u7684\u8DEF\u5F84"),{code:"path"});let h=Ht(e,l);return n(),{...t(),installed:h}}}}import Lr from"node:path";import{exportsDirectory as Ir}from"../browser/shared/paths.mjs";async function Kn(e,n,{workspace:t=null}={}){let a=Lr.join(Ir,`${n}.html`),s=await ze([n]),f=await e.handInReport(n,{reader:!0});if(!f.ok)return{problems:[],refused:{reason:f.reason,message:f.message},file:a};if(f.repeated.length)return{problems:Be(f.repeated),file:a};let{exported:r,failures:m}=await cn([n],{workspace:t});return await s.keep(r.map(l=>l.slug)),{problems:m.get(n)??[],file:a}}import Jn from"node:fs/promises";import Yn from"node:path";import{MEDIA_ROUTES as Vn,assetFile as Nr,imageFile as Mr,mediaTypeOf as Wr}from"../browser/shared/media.mjs";import{serveFound as Xn}from"../browser/shared/http.mjs";import{slugPattern as Zn}from"../browser/shared/reports.mjs";import{pageFiles as Ur}from"../browser/shared/pages.mjs";import{documentDirectory as Br}from"../browser/shared/workspace.mjs";var kt={asset:e=>({"Content-Type":Wr(e),"Cache-Control":"no-cache"}),file:()=>({"Content-Type":"application/octet-stream","Content-Disposition":"attachment","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}),embed:e=>/\.pdf$/i.test(e)?{"Content-Type":"application/pdf","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}:{"Content-Type":"text/html; charset=utf-8","Content-Security-Policy":"sandbox allow-scripts allow-popups allow-forms allow-modals","X-Content-Type-Options":"nosniff","Cache-Control":"no-cache"}},zr=new RegExp(`^/__gallery/edit/(${Object.keys(Vn).join("|")})/([^/]+)/(assets/[^/]+)$`);async function Qn(e,n,{reportsDirectory:t}){let[,a,s,f]=zr.exec(e)??[];if(!a)return!1;let r=Zn.test(s)&&Vn[a](f)?await Jn.readFile(Yn.join(Br(s,t),f)).catch(()=>null):null;return Xn(n,r,{headers:kt[a](f)}),!0}var Hr=/^\/pages\/([^/]+)\/(assets\/[^/]+)$/;async function qn(e,n,{reportsDirectory:t}){let[,a,s]=Hr.exec(e)??[];if(!a)return!1;let f=Zn.test(a)&&Nr(s)?await Jn.readFile(Yn.join(Ur(a,t).folder,s)).catch(()=>null):null;return Xn(n,f,{headers:(Mr(s)?kt.asset:kt.file)(s)}),!0}import Gr from"node:dns";import{sendJson as Re}from"../browser/shared/http.mjs";import{createNetCache as Kr,dataOf as Jr}from"../browser/shared/net-cache.mjs";import{readKeys as Yr}from"../browser/shared/net-keys.mjs";import{addressKind as Qe,addressOf as io,hostIn as eo,keptHere as to,keyIn as no,mapsHere as Vr,netHostsOf as Xr,proxyHere as Zr,withKey as Qr}from"../browser/shared/net-policy.mjs";import{galleryVersion as qr}from"../browser/shared/preview-server.mjs";var Ze=512*1024,ea=6e4,oo=20,ro=5,ao=1e4,ta=16*1024,na=new Set([301,302,303,307,308]),oa=/^(?:application\/(?:[\w.-]+\+)?json|text\/[\w.+-]+)$/i,$e=(e,n={})=>({ok:!1,code:e,...n}),ne=(e,n={},t)=>Object.assign(new Error(e),{refusal:$e(e,n),...t===void 0?{}:{detail:t}});function ra(e,n){let t;try{t=new URL(e,n)}catch{return{code:"url",why:"a redirect to an address that does not parse"}}let a=io(t.href);return a.code?{code:"url",why:`a redirect to ${t.host?`${t.protocol}//${t.host}`:t.protocol}: ${a.why}`}:a}function so(e,n){let t=[...new Set([n,encodeURIComponent(n)])].filter(Boolean),a=s=>typeof s=="string"?t.reduce((f,r)=>f.split(r).join("{key}"),s):s;return Object.fromEntries(Object.entries(e).map(([s,f])=>[s,a(f)]))}var aa=e=>Gr.promises.lookup(e,{all:!0,verbatim:!0}),vt=e=>URL.parse(e)?.host||"?",xt=e=>Qe(e)==="fake-ip"?"an address a fake-ip proxy's DNS gives":"an address of this computer or of a private network";async function sa(e,{resolve:n,proxy:t}){let a=e.hostname,s=Zr(t),f=u=>{let T=Qe(u);return T==="public"||T==="fake-ip"&&s},r=a.replace(/^\[|\]$/g,"");if(Qe(r)!=="none"){if(f(r))return{address:r};throw ne("private",{host:a,address:r,why:`${r} is ${xt(r)}`})}let m;try{m=(await n(a)).map(u=>typeof u=="string"?u:u.address)}catch(u){throw ne("offline",{why:`${a} did not resolve (${u.code??u.message})`})}if(m.length===0)throw ne("offline",{why:`${a} did not resolve`});let l=m.filter(u=>!f(u));if(l.length===0)return{address:m[0]};let h=l.filter(u=>!Vr(u)),w=h.length?h:l,i=w.find(u=>!u.includes(":"))??w[0],v=`${a} resolved to ${i}, ${xt(i)}`,P=to(a)?"and its name is one kept for this computer (localhost)":t?s?e.protocol!=="https:"?"and an http address is never handed to a proxy by its name (no TLS to check the site)":h.length?"and a private network's address is never handed to a proxy by its name (that network's own machines are there)":null:"and the proxy it goes through is not on this computer":"and no proxy of this computer goes between to reach it by its name";if(P===null)return{address:null,resolved:i,said:v};throw ne("private",{host:a,address:i,why:`${v}, ${P}`},s||!t||to(a)?void 0:`${v}, and the proxy it goes through (${vt(t)}) is not on this computer`)}var ia=({resolve:e=aa,proxyFor:n=ln,connect:t,ca:a}={})=>async(s,{headers:f,signal:r})=>{let m=await n(s.href),l=await sa(s,{resolve:e,proxy:m}),{address:h}=l,w={...t?{connect:t}:{},...a?{ca:a}:{}};try{return await He(s,{address:h,proxy:m,headers:f,signal:r,...w})}catch(i){if(!(m&&i.proxyFailed&&(h!==null||i.code==="ECONNREFUSED")))throw h===null&&!r?.aborted?ne("offline",{why:`${l.said}, and no site the proxy of this computer reached by its name proved to be it`},`${l.said}, handed by its name to the proxy (${vt(m)}): ${i.code??i.message}`):i;let v=u=>`and the proxy of this computer that would reach it${u?` (${vt(m)})`:""} is not running`,P=h===null?l.said:`${s.hostname.replace(/^\[|\]$/g,"")===h?h:`${s.hostname} resolved to ${h}`}, ${xt(h)}`;if(h===null||Qe(h)!=="public")throw ne("private",{host:s.hostname,address:h??l.resolved,why:`${P}, ${v(!1)}`},`${P}, ${v(!0)}`);return He(s,{address:h,proxy:null,headers:f,signal:r,...w})}},co=e=>(n,{headers:t,signal:a})=>He(new URL(`http://127.0.0.1:${e}/${n.protocol.slice(0,-1)}/${n.host}${n.pathname}${n.search}`),{address:"127.0.0.1",headers:t,signal:a});async function ca(e){let n=0,t=[];for await(let a of e){if(n+=a.length,n>ta)throw Object.assign(new Error("too-large"),{status:413});t.push(a)}return JSON.parse(Buffer.concat(t).toString("utf8"))}function la(e,n){let t=/;\s*charset="?([^";]+)"?/i.exec(n)?.[1];try{return new TextDecoder(t||"utf-8").decode(e)}catch{return new TextDecoder("utf-8").decode(e)}}function lo({root:e,catalog:n=()=>ae(e),hop:t=null,now:a=Date.now,cache:s=Kr(e),log:f=()=>{}}){let r=t??ia(),m=new Map,l=u=>{let T=a(),S=(m.get(u)??[]).filter($=>T-$<6e4);return S.length>=oo?(m.set(u,S),!1):(m.set(u,[...S,T]),!0)},h={accept:"application/json, text/plain;q=0.9, text/*;q=0.8","user-agent":`Gallery/${qr} (a custom block's card)`};async function w(u,{hosts:T,allowed:S,key:$}){let V=AbortSignal.timeout(ao),W=u;for(let x=0;;x++){let b;try{b=await r($===void 0?W:new URL(Qr(W.href,$)),{headers:h,signal:V})}catch(A){throw A.refusal?A:ne("offline",{why:V.aborted?`no answer within ${ao/1e3} s`:String(A.code??A.message)})}if(na.has(b.status)&&b.headers.get("location")){if(b.body?.cancel().catch(()=>{}),x>=ro)throw ne("status",{status:b.status,why:`more than ${ro} redirects`});let A=ra(b.headers.get("location"),W);if(A.code)throw ne("url",{why:A.why});let se=eo(A.url.hostname,T);if(!se)throw ne("host",{host:A.url.hostname,why:`a redirect to ${A.url.hostname}, which the block's needs do not name`});if(!S.includes(se))throw ne("consent",{hosts:T.filter(oe=>!S.includes(oe))});W=A.url,$=no(W.href)?$:void 0;continue}if(b.status<200||b.status>299)throw b.body?.cancel().catch(()=>{}),ne("status",{status:b.status});let z=b.headers.get("content-type")??"",G=z.split(";")[0].trim();if(G&&!oa.test(G))throw b.body?.cancel().catch(()=>{}),ne("type",{type:G});if(Number(b.headers.get("content-length"))>Ze)throw b.body?.cancel().catch(()=>{}),ne("too-large",{limit:Ze});let H;try{H=b.body?await dn(b,Ze):Buffer.alloc(0)}catch(A){throw ne("offline",{why:String(A.code??A.message)})}if(H===null)throw ne("too-large",{limit:Ze});return{type:G||"text/plain",text:la(H,z)}}}let i=(u,T,S)=>{let $=Jr(u,T);return $===void 0?$e("type",{why:"the answer is no JSON"}):{ok:!0,data:$,at:u.at,cached:S}};async function v(u){let{block:T,url:S,as:$="json",doc:V=null}=u??{},W=typeof T=="string"?n().packages.get(T):null;if(!W)return $e("missing",{why:"no custom block of that id loads in this workspace"});let x=Xr(W.needs);if($!=="json"&&$!=="text")return $e("url",{why:'as is "json" or "text"'});let b=io(S);if(b.code)return $e("url",{why:b.why});let{url:z}=b,G=eo(z.hostname,x);if(!G)return $e("host",{host:z.hostname,why:x.length?`its needs name ${x.join(", ")}`:"its needs name no host of the net"});let H=n().settings.net?.[T]??[];if(!H.includes(G))return $e("consent",{hosts:x.filter(B=>!H.includes(B))});let A;if(no(z.href)){let B=Yr(e);if(A=B[z.hostname]??B[G],A===void 0)return $e("key",{host:z.hostname})}let se=z.href,oe=s.get(se);if(s.used(se,V,$),oe&&a()-Date.parse(oe.at)<ea)return i(oe,$,!0);if(!l(T))return oe?i(oe,$,!0):$e("rate",{why:`more than ${oo} fetches in a minute`});try{let{type:B,text:K}=await w(z,{hosts:x,allowed:H,key:A});return i(s.put(se,{type:B,text:K,at:new Date(a()).toISOString()}),$,!1)}catch(B){if(!B.refusal)throw B;if(oe&&B.refusal.code!=="consent")return i(oe,$,!0);let K=A===void 0?B.refusal:so(B.refusal,A),de=B.detail===void 0?K.why:A===void 0?B.detail:so({why:B.detail},A).why;return(K.code!=="offline"||B.detail!==void 0)&&f(`${T}: ${z.hostname} refused (${K.code}${de?`: ${de}`:""})`),K}}async function P(u,T){if(u.method!=="POST")return Re(T,405,{ok:!1,reason:"method"});if(u.headers.origin!==`http://${u.headers.host}`)return Re(T,403,{ok:!1,reason:"origin"});if(!/^application\/json\b/i.test(u.headers["content-type"]??""))return Re(T,415,{ok:!1,reason:"type"});let S;try{S=await ca(u)}catch($){return Re(T,$.status??400,{ok:!1,reason:"body"})}try{return Re(T,200,await v(S))}catch($){return Re(T,500,{ok:!1,code:"offline",why:$.message})}}return{handle:P,answer:v,cache:s}}function fo({max:e=20}={}){let n=new Map;return{get(t,a,s){let f=`${t} ${a}`,r=n.get(f);return!r||r.text!==s?null:(n.delete(f),n.set(f,r),r.page)},set(t,a,s,f){let r=`${t} ${a}`;for(n.delete(r),n.set(r,{slug:t,text:s,page:f});n.size>e;)n.delete(n.keys().next().value)},clear(){n.clear()},forget(t){for(let[a,s]of n)s.slug===t&&n.delete(a)},get size(){return n.size}}}import{createHash as da}from"node:crypto";import{readFileSync as fa}from"node:fs";import mo from"node:fs/promises";import ma from"node:path";import{release as ua,releaseFile as pa}from"../browser/shared/paths.mjs";async function qe(e){let n=await Promise.all(e.map(a=>mo.stat(a).then(({mtimeMs:s,size:f})=>`${s} ${f}`,()=>"none"))),t=da("sha256");return e.forEach((a,s)=>t.update(`${a}\0${n[s]}
78
+ `)),t.digest("hex").slice(0,16)}function uo(e,n){let t=null,a=async()=>(await Promise.all(e.map(async s=>(await mo.readdir(s,{recursive:!0,withFileTypes:!0}).catch(()=>[])).filter(r=>r.isFile()).map(r=>ma.join(r.parentPath,r.name))))).flat().filter(n).sort();return{files:()=>t??=a(),changed:()=>{t=null}}}var $t=ua?JSON.parse(fa(pa,"utf8")).stamps:null;var rt=To.source.slice(1,-1),La=new RegExp(`^/generated/(${rt})\\.html$`),Ia=new RegExp(`^/(${rt})/(?:doc|report)\\.html$`),Na=new RegExp(`^/pages/(${rt})$`),Ma=new RegExp(`^/__gallery/pages/(${rt})/(cards|library|hint)$`),Et="/__gallery/events",Ce=ha,Fo=/^\/__gallery\/edit\/(v\/[a-f0-9]{16}\/)?src\/((?:shared(?:\/components|\/emoji|\/i18n)?\/|editor\/(?:page|components)(?:\/[a-z]+(?:-[a-z]+)*){0,2}\/(?!files?\.mjs))[a-z]+(?:-[a-z]+)*\.mjs)$/,Wa=/^\/__gallery\/edit\/(?:v\/[a-f0-9]{16}\/)?src\/(shared\/emoji\/data\/[a-z]+(?:-[a-z]+)*\.(json|bin))$/,et=[Y.join(Ce,"editor","page"),Y.join(Ce,"editor","components"),Y.join(Ce,"shared")],Ua=e=>Fo.test(`/__gallery/edit/src/${Y.relative(Ce,e).split(Y.sep).join("/")}`);var Ba=[_o,Y.join(Ce,"shared","components")],Hc=[_o,...et],tt={"Cache-Control":"no-store"},Co={"Cache-Control":"max-age=31536000, immutable"},bt=(e,n,t)=>Po(e,{type:n,headers:tt,body:t});function za(e){let n=e.headers?.host??"",t=e.socket?.localPort;return!!t&&(n===`127.0.0.1:${t}`||n===`localhost:${t}`)}var Ao=`window.addEventListener("doc-net-fetch", (event) => {
79
+ event.preventDefault();
80
+ event.detail.answer(fetch("/__gallery/net", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(event.detail.ask) }).then((response) => response.json()));
81
+ });`,Do=`let lost = false;
82
+ events.onerror = () => { lost = true; };
83
+ events.onopen = () => {
84
+ if (!lost) return;
85
+ lost = false;
86
+ for (const kind of ${JSON.stringify(Fa)}) window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: kind }));
87
+ };`,Ha=(e,n,t)=>`<script>
88
+ (() => {
89
+ document.currentScript.remove();
90
+ ${Ao}
91
+ const solo = new URLSearchParams(location.search).has("solo");
92
+ let catalog = "${t}";
93
+ const holds = (ids) => document.querySelector(ids === undefined ? "[${nt}]" : ids.split(",").map((id) => '[${nt}="' + id + '"]').join());
94
+ const events = new EventSource("${Et}?slug=${e}");
95
+ ${Do}
96
+ events.onmessage = (event) => {
97
+ const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
98
+ if (kind === "notes") return void window.dispatchEvent(new CustomEvent("doc-annotations-changed", { detail: { version: next ?? "" } }));
99
+ if (kind === "changes") return void window.dispatchEvent(new CustomEvent("doc-changes-changed", { detail: { stamp: next ?? "" } }));
100
+ if (kind === "look") return void window.dispatchEvent(new CustomEvent("doc-look-request", { detail: { look: Object.fromEntries(new URLSearchParams(next ?? "")), from: "file" } }));
101
+ if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
102
+ if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
103
+ if (kind !== "report" && kind !== "assets" && kind !== "components") return;
104
+ if (kind === "components") {
105
+ if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
106
+ if (solo || next === catalog) return;
107
+ catalog = next;
108
+ if (!holds(ids)) return void window.dispatchEvent(new CustomEvent("doc-catalog-changed", { detail: { ids: ids === undefined ? null : ids.split(",").filter(Boolean) } }));
109
+ }
110
+ if (window.__galleryEditBusy) {
111
+ window.dispatchEvent(new CustomEvent({ report: "doc-source-changed", assets: "doc-assets-changed", components: "doc-components-changed" }[kind], { detail: { version: next ?? null } }));
112
+ return;
113
+ }
114
+ if (kind === "report" && next === "${n}") return;
115
+ if (window.__galleryEditReload) return window.__galleryEditReload(); // in a workbench: swapped in, no reload seen
116
+ location.reload();
117
+ };
118
+ })();
119
+ </script>`,Ga=(e,n,t)=>`<script>
120
+ (() => {
121
+ document.currentScript.remove();
122
+ ${Ao}
123
+ let catalog = "${t}";
124
+ const holds = (ids) => {
125
+ const named = ids === undefined ? "[${nt}]" : ids.split(",").filter(Boolean).map((id) => '[${nt}="' + id + '"]').join() || ":not(*)";
126
+ return Boolean(document.querySelector(named)) || [...document.querySelectorAll("template[data-ge-held]")].some((held) => held.content.querySelector(named));
127
+ };
128
+ const again = () => (window.__galleryEditReload ? window.__galleryEditReload() : location.reload());
129
+ const events = new EventSource("${Et}?page=${e}");
130
+ ${Do}
131
+ events.onmessage = (event) => {
132
+ const [kind, next, ids, more, consents, unlisted, packs] = event.data.split(" ");
133
+ if (kind === "page") return void (window.__galleryPageChanged ? window.__galleryPageChanged(next) : next !== "${n}" && again());
134
+ if (kind === "assets") return void again();
135
+ if (kind === "settings") return void window.dispatchEvent(new CustomEvent("doc-settings-changed", { detail: { hidden: next ? next.split(",") : [], disabled: ids ? ids.split(",") : [], shown: more ? more.split(",") : [], net: consents ? consents.split(",") : [], unlisted: unlisted ? unlisted.split(",") : [], packsOff: packs ? packs.split(",") : [] } }));
136
+ if (kind === "data") return void window.dispatchEvent(new CustomEvent("doc-workspace-change", { detail: next ?? "" }));
137
+ if (kind !== "components") return;
138
+ if (document.readyState === "loading") return void document.addEventListener("DOMContentLoaded", () => events.onmessage(event), { once: true });
139
+ if (next === catalog) return;
140
+ catalog = next;
141
+ if (holds(ids)) again();
142
+ };
143
+ })();
144
+ </script>`;function Ka(e,n){let t=Y.relative(e,n).split(Y.sep);if(t[0]===".."||Y.isAbsolute(t[0])||t[0]==="")return null;if(t.length===1&&t[0]===ot)return{slug:null,name:ot,packages:!0};let a=l=>process.platform==="win32"?l.toLowerCase():l;if(a(t[0])===Sa&&t.length>=2&&Ra(t[1])&&!ko.includes(t[1])){let l=t.slice(2);return l.some(h=>h.startsWith("."))?null:{extension:t[1],name:l.length===1?l[0]:null}}if(a(t[0])===ba&&t.length>=2&&Ro(t[1])&&!ko.includes(t[1])){let l=t.slice(2);return l.some(h=>h.startsWith("."))?null:{page:t[1],name:l.length===1?l[0]:null}}let s=t[0]===".gallery"&&t[1]==="pages"&&t.length>=3,[f,...r]=s?t.slice(2):t,m=!s&&a(f)===yo;return!(m||To.test(f))||f==="exports"||r.some(l=>l.startsWith("."))?null:{slug:m?yo:f,name:r.length===1?r[0]:null,...m?{packages:m}:{}}}function Ot(e){let n=i=>process.platform==="win32"?Y.resolve(i).toLowerCase():Y.resolve(i),{gallery:t,preferencesPage:a,exports:s,extensions:f}=Ca(e),[r,m,l,h]=[n(t),n(a),n(s),n(f)],w=(i,v)=>i===v||i.startsWith(v+Y.sep);return i=>{let v=n(i);return w(v,h)&&v!==h&&v.slice(h.length+1).split(Y.sep).some((P,u)=>u>0&&(P==="node_modules"||P===".git"))?!0:w(v,r)&&v!==r&&!w(v,m)||w(v,l)}}var jo=`<script data-doc-dev>document.currentScript.remove(); globalThis.${Da} = ${JSON.stringify(Aa)};</script>`,ue=(e,n,t)=>new RegExp(`</${n}>`,"i").test(e)?e.replace(new RegExp(`</${n}>`,"i"),()=>` ${t}
145
+ </${n}>`):`${e}
146
+ ${t}`;function Lo({stateDirectory:e=ga,logger:n=console,kind:t="dev",workbenchPage:a=null,closeServer:s=async()=>{},exit:f=()=>process.exit(0)}={}){let r=new Set,m=(o,c="",d="report")=>{for(let y of r)(!o||y.slug===o)&&y.response.write(`data: ${o?`${d} ${c}`:"assets"}
147
+
148
+ `)},l=(o,c)=>{for(let d of r)d.page===o&&d.response.write(`data: page ${c}
149
+
150
+ `)},h=!1,w=o=>{h||=o,R("workspace",()=>{let c=h;h=!1;for(let d of r)d.workspace&&(c||!d.ownOnly)&&d.response.write(`data: workspace ${Date.now()}
151
+
152
+ `)})},i=()=>w(!0),v=()=>w(!1),P=o=>m(o,String(Date.now()),"changes"),u=pn({stateDirectory:e,finish:Ue,log:o=>n.info?.(`[gallery] ${o}`),onChanges:P}),T=(o,c,d,{lang:y=null,page:k=!1}={})=>Kt(o,c,d,{blank:!0,lang:y,page:k}),S=e?On({file:Y.join(e,"activity.json")}):null,$=yn({root:F,read:wn(u),activity:S,draw:(o,c)=>Ee(o,{slug:c,mode:"words",reportsDirectory:F})}),V=new Set,W=o=>{for(let c of o)V.add(c);V.size!==0&&R("data",()=>{let c=[...V];V.clear();for(let d of r)if(d.slug||d.page)for(let y of c)d.response.write(`data: data ${y}
153
+
154
+ `)})},x=o=>Y.resolve(Y.dirname(St(o,F)))===Y.resolve(F),b=null,z=null,G=()=>z??=(async()=>{for(let o of r)o.response.end();r.clear(),await Promise.race([s().catch(()=>{}),new Promise(o=>setTimeout(o,3e3))]),await S?.close(),await b?.().catch(()=>{}),await A.close(),H.close(),f()})(),H=kn({server:{kind:t,version:ka,stop:G},edits:u,reports:{create:T,export:o=>Kn(u,o,{workspace:c=>$.snapshot(c)}),words:(o,c)=>Ee(o,{slug:c,mode:"words",reportsDirectory:F})},components:Gn({root:F,taken:()=>Z.taken()}),changed:i,relayed:v,index:$,web:{frameable:fn,title:async o=>(await un(o,async()=>null,{icon:!1,cover:!1})).title,icon:o=>mn(o)}}),A=Mn({edits:u,workspace:H,reports:{create:T},reportsDirectory:F,offline:o=>sn({...o,workspace:c=>$.snapshot(c)})}),se=lo({root:F,hop:process.env.GALLERY_TEST_NET?co(Number(process.env.GALLERY_TEST_NET)):null,log:o=>n.info?.(`[gallery] ${o}`)}),oe=Ut({root:F,edits:u,stateDirectory:e,catalogTaken:()=>Z.taken(),log:o=>n.info?.(`[gallery] ${o}`),shown:ut}),B=(o,c,{present:d=!1,editorModule:y,kit:k}={})=>{let N=c,ce="",te="",pe=!0;try{d||({html:N,snippet:ce,head:te}=u.preview(o,c,{editor:y,kitTags:fe=>qt(fe,k)}))}catch(fe){pe=!1,n.warn(`[gallery] text editing unavailable for ${o}: ${fe.message}`)}if({html:N}=nn(N,{slug:o,mode:"preview",kit:k}),N=ue(N,"head",Ha(o,De(c),ae(F).stamp)),N=ue(N,"head",`<script data-doc-dev>${ho()}</script>`),N=ue(N,"head",jo),te&&(N=ue(N,"head",te)),d)return{html:ue(N,"head",`<style data-doc-present>.doc-display { display: none !important; }</style>
155
+ <script type="module" src="/__gallery/edit/src/editor/page/present-links.mjs" data-doc-dev></script>`),whole:pe};let he="";try{he=_n(o,c)}catch(fe){pe=!1,n.warn(`[gallery] checks unavailable for ${o}: ${fe.message}`)}return he&&(N=ue(N,"body",he)),{html:ce?ue(N,"body",ce):N,whole:pe}},K=fo(),de=uo(et,Ua),p=o=>{let c=St(o,F);return[c,Y.join(c,"assets")]},g=()=>$t?.editor??de.files().then(qe),E=o=>$t?.kit?.[o.id]??qe([mt(o)]),O=async(o,c,{present:d})=>{let[y,k,N]=await Promise.all([d?"":g(),Promise.all(Te.map(E)),qe(p(o))]),ce=[d?"present":y,...k,N,ae(F).stamp,`look:${go(wo(o,F))}`].join(" "),te=K.get(o,ce,c);if(te!==null)return d||u.opened(c),te;let pe=new Map(Te.map((ge,Pe)=>[ge,k[Pe]])),he=d?void 0:`/__gallery/edit/v/${y}/src/editor/page/editor.mjs`,{html:fe,whole:le}=B(o,c,{present:d,editorModule:he,kit:ge=>`${We(ge)}?v=${pe.get(ge)}`});return le&&K.set(o,ce,c,fe),fe},j=async o=>{let c=So(o,F),[d,y]=await Promise.all([ye.readFile(c.html,"utf8").catch(()=>null),ye.readFile(c.json,"utf8").catch(()=>"")]);if(d===null)return null;let[k,N]=await Promise.all([g(),Promise.all(Te.map(E))]),ce=new Map(Te.map((U,be)=>[U,N[be]])),te=ae(F),pe=bo(d,y),he=Ft(d,{blockOf:U=>dt(te,U)}),fe=Object.fromEntries([...new Set(lt(d).cards.map(({block:U})=>U).filter(Boolean))].map(U=>[U,dt(te,U)])),{html:le}=jn(he,{reportsDirectory:F,slug:o,kit:U=>`${We(U)}?v=${ce.get(U)}`}),ge=o===xo&&!_a(F),Pe=U=>te.packages.get(U)?.name??Dt().find(be=>be.id===U)?.title??null,Ie=o===xo?ja(F,lt(d).cards.map(({block:U})=>U)).map(U=>({block:U,name:Pe(U)})):[],Ne=JSON.stringify({slug:o,token:u.token,version:pe,blocks:fe,...ge?{hint:ge}:{},...Ie.length?{news:Ie}:{}}).replace(/</g,"\\u003c");return le=ue(le,"head",`<script type="application/json" data-ge-page data-doc-dev>${Ne}</script>`),le=ue(le,"head",Ga(o,pe,te.stamp)),le=ue(le,"head",`<script data-doc-dev>${ho()}</script>`),le=ue(le,"head",jo),ue(le,"head",`<script type="module" src="/__gallery/edit/v/${k}/src/editor/page/custom-page.mjs" data-doc-dev></script>`)};async function C(o,c,d){try{if(!za(o))return po(c,403,{ok:!1,reason:"host"});let y=new URL(o.url||"/","http://localhost"),k=decodeURI(y.pathname);if(k===Et){c.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive"}),c.write(`retry: 3000
156
+
157
+ `);let I={slug:y.searchParams.get("slug"),page:y.searchParams.get("page"),workspace:y.searchParams.has("workspace"),ownOnly:y.searchParams.get("workspace")==="own",response:c};r.add(I);let{stamp:Me,settings:zo}=ae(F);c.write(`data: components ${Me}
158
+
159
+ `),c.write(`data: ${ct(zo)}
160
+
161
+ `),o.on("close",()=>r.delete(I));return}if(k==="/__gallery/net")return se.handle(o,c);if(k==="/__gallery/edit/commit")return u.commit(o,c);if(k==="/__gallery/edit/reverted")return u.reverted(o,c);if(k==="/__gallery/edit/hand-in")return u.handInRequest(o,c);if(k==="/__gallery/edit/settle")return u.settleRequest(o,c);if(k==="/__gallery/edit/round")return u.roundRequest(o,c);if(k==="/__gallery/edit/upload")return u.upload(o,c);if(k==="/__gallery/edit/unfurl")return u.unfurl(o,c);if(k==="/__gallery/edit/emoji-library"){if(o.method==="POST")return u.addEmoji(o,c);let[I,Me]=await u.listEmojis();return po(c,I,Me)}if(k==="/__gallery/edit/icon"){let I=Yt({value:y.searchParams.get("value")??"",slug:y.searchParams.get("slug"),tab:y.searchParams.has("tab")});return Fe(c,I?.body,{type:I?.type,headers:{"Cache-Control":"max-age=31536000, immutable"}})}if(await Qn(k,c,{reportsDirectory:F})||await qn(k,c,{reportsDirectory:F})||await Un(k,y.searchParams.get("v"),c,{root:F}))return;let N=k.match(/^\/__gallery\/edit\/emoji-library\/([^/]+)$/)?.[1];if(N){let I=await u.readEmoji(N);return Fe(c,I?.body,{type:I?.type,headers:{"Cache-Control":"no-cache"}})}if(k==="/__gallery/edit/frameable")return u.frameable(o,c);if(k==="/__gallery/edit/annotations")return u.annotations(o,c);if(k==="/__gallery/edit/changes")return u.changes(o,c);let ce=k.match(/^\/__gallery\/transfer\/([a-z]+)$/)?.[1];if(ce)return A.handle(o,c,ce);let[,te,pe]=k.match(Ma)??[];if(te)return oe.handle(o,c,te,pe);let he=k.match(/^\/__gallery\/workspace\/([a-z]+(?:-[a-z]+)*)$/)?.[1];if(he)return H.handle(o,c,he);let[,fe,le]=k.match(Fo)??[];if(le){let I=await ye.readFile(Y.join(Ce,le),"utf8").catch(()=>null);return Fe(c,I,{type:"text/javascript; charset=utf-8",headers:fe?Co:tt})}let ge=y.searchParams.has("v")&&Te.find(I=>We(I)===k);if(ge){let I=await ye.readFile(mt(ge)).catch(()=>null);return Fe(c,I,{type:k.endsWith(".css")?"text/css; charset=utf-8":"text/javascript; charset=utf-8",headers:Co})}if(k==="/__gallery/edit/mhchem.js"){let I=await ye.readFile(Qt).catch(()=>null);return Fe(c,I,{type:"text/javascript; charset=utf-8",headers:tt})}let[,Pe,Ie]=k.match(Wa)??[];if(Pe){let I=await ye.readFile(Y.join(Ce,Pe)).catch(()=>null);return Fe(c,I,{type:Ie==="json"?"application/json; charset=utf-8":"application/octet-stream",headers:{"Cache-Control":"max-age=86400"}})}if(a&&(k==="/"||k==="/index.html"))return bt(c,"text/html; charset=utf-8",await a(y.pathname,o));let Ne=k.match(Na)?.[1];if(Ne){let I=await j(Ne);return I===null?d():bt(c,"text/html; charset=utf-8",I)}let U=k.match(La)?.[1];if(!U){let I=k.match(Ia)?.[1];return Ro(I)&&await ye.access(Ea(St(I,F)).html).then(()=>!0,()=>!1)?Po(c,{status:302,headers:{Location:`/generated/${I}.html${y.search}`,...tt}}):d()}let be=await u.readTaken(U);if(be===null)return d();y.searchParams.has("present")||u.noteTaken(U,be.source).then(I=>I&&P(U),()=>{}),bt(c,"text/html; charset=utf-8",await O(U,be.text,{present:y.searchParams.has("present")}))}catch(y){d(y)}}let L=new Map,R=(o,c)=>{clearTimeout(L.get(o)),L.set(o,setTimeout(c,120))},D=o=>{xa(o,F).reads&&m(o,go(wo(o,F)),"look")},Q=Wn({settled:u.settled,async tell(o,c){let d=await u.read(o,c.source).catch(y=>(n.error(`[gallery] ${o}: ${y.message}`),{version:De(c.source??"")}));if(m(o,d?.version??De("")),x(o)){let y=u.writerOf(o,c.source)??"agent";$.changed(o,{source:c.source??null,text:d?.text??null,by:y}).then(W,k=>n.error(`[gallery] ${o}: its facts not read: ${k.message}`))}u.noteTaken(o,c.source).then(y=>y&&P(o),y=>n.error(`[gallery] ${o}: the Agent's changes not kept: ${y.message}`)),u.checkAnnotations(o).catch(y=>n.error(`[gallery] ${o}: annotations not checked: ${y.message}`))}}),X=({id:o,problem:c,off:d})=>d||n.warn(`[gallery] custom block ${o} does not load: ${jt("en",c)}`),Z=En({root:F,tell({stamp:o,problems:c,settings:d},y){for(let k of y)c.has(k)&&X(c.get(k));for(let{response:k}of r)k.write(`data: components ${o} ${y.filter(N=>$a.test(N)).join(",")}
162
+
163
+ `),k.write(`data: ${ct(d)}
164
+
165
+ `)}});for(let o of ae(F).problems.values())X(o);$.start().then(o=>o>0&&W(["activity"]));let ee=Ot(F),_=Oo(F).then(o=>o.join("/"),()=>""),M=!1,ie=o=>{M||=o===Eo,R("extensions",async()=>{let c=M;M=!1;let d=await _;_=Oo(F).then(y=>y.join("/"),()=>d),(c||await _!==d)&&i()})},re=(o,c)=>!wa&&c.some(d=>o.startsWith(d+Y.sep));function ke(o,c){if(o==="reset"){K.clear(),de.changed(),Z.changed(),i();return}if(ee(c))return;let d=Ka(F,c);if(d?.page){let{page:y,name:k}=d;k&&Pa(k)&&R(`page:${y}`,async()=>{let N=So(y,F),[ce,te]=await Promise.all([ye.readFile(N.html,"utf8").catch(()=>null),ye.readFile(N.json,"utf8").catch(()=>"")]);ce!==null&&l(y,bo(ce,te))}),(k===$o.json||k===$o.html&&/^(add|unlink)$/.test(o)||k===null&&/^(add|unlink)Dir$/.test(o))&&i();return}if(d?.extension){(d.name===Eo||d.name===null)&&ie(d.name);return}if(d?.packages&&Z.changed(),d?.name===ot&&d.slug===null&&R("look:*",()=>new Set([...r].map(({slug:y})=>y).filter(Boolean)).forEach(D)),d?.name===ot&&d.slug===null&&i(),d?.slug&&!(d.name&&Oa(d.name))&&K.forget(d.slug),d&&(/^(doc|report)\.json$/.test(d.name??"")||/^(add|unlink)Dir$/.test(o)&&d.name===null)&&K.clear(),d?.slug&&!d.packages&&d.name===null&&/^(add|unlink)Dir$/.test(o)&&x(d.slug)&&($.forget(d.slug),W(["todos","recent","stats"])),d?.slug&&!(d.packages&&d.name===null)&&(/^(doc|report)\.json$/.test(d.name??"")||/^(add|unlink)Dir$/.test(o)&&d.name===null||/^(add|unlink)$/.test(o)&&vo(d.name??""))&&i(),d?.slug&&!d.packages&&d.name===Ta&&i(),/^(add|unlink)(Dir)?$/.test(o)&&re(c,et)&&de.changed(),d?.name&&(vo(d.name)||/^(doc|report)\.json$/.test(d.name))){if(Q(d.slug),/^(doc|report)\.json$/.test(d.name)){let{slug:y}=d;R(`look:${y}`,()=>D(y))}}else if(d?.name==="annotations.json"){let{slug:y}=d;R(`notes:${y}`,async()=>{let k=await ye.readFile(c,"utf8").catch(()=>null);m(y,k===null?"":De(k),"notes")})}else re(c,Ba)?R("kit",async()=>{try{await an({fresh:!0}),m()}catch(y){n.error(`[gallery] shared kit rebuild failed: ${y.message}`)}}):re(c,et)&&R("editor",()=>m())}async function ve(o){b=await ya({reportsDirectory:F,port:o,token:u.token,kind:t}),await va(F)}async function Bo(){for(let o of L.values())clearTimeout(o);Z.close(),await S?.close(),await b?.().catch(()=>{}),b=null,await A.close(),H.close()}return{handle:C,changed:ke,listening:ve,close:Bo,stop:G,edits:u,get listeners(){return r.size}}}import Ja from"node:fs/promises";import Ae from"node:path";import{serve as Io}from"../browser/shared/http.mjs";var Ya={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8",".json":"application/json; charset=utf-8",".map":"application/json; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".ico":"image/x-icon",".woff2":"font/woff2",".woff":"font/woff",".ttf":"font/ttf",".txt":"text/plain; charset=utf-8"},Va=e=>Ya[Ae.extname(e).toLowerCase()]??"application/octet-stream";function Xa(e,n){if(/%(?:2f|5c|00)/i.test(n)||/[\\\0]/.test(n))return null;let t;try{t=decodeURIComponent(n)}catch{return null}let a=t.split("/");if(a.some(r=>r===""||r==="."||r===".."||/[\\\0:]/.test(r)))return null;let s=Ae.resolve(e,...a),f=Ae.relative(e,s);return f&&!f.startsWith("..")&&!Ae.isAbsolute(f)?s:null}async function No(e,n,{web:t,kit:a,vendor:s}){if(e.method!=="GET"&&e.method!=="HEAD")return!1;let f=new URL(e.url||"/","http://localhost").pathname,r=null,m=null;if(f==="/"||f==="/index.html"){if(!t)return!1;[r,m]=[Ae.join(t,"index.html"),{"Cache-Control":"no-store"}]}else{let w=[["/assets/",t&&Ae.join(t,"assets"),"max-age=31536000, immutable"],["/kit/",a,"no-cache"],["/vendor/",s,"no-cache"]].find(([i,v])=>v&&f.startsWith(i));if(!w)return!1;r=Xa(w[1],f.slice(w[0].length)),m={"Cache-Control":w[2]}}let l=r?await Ja.readFile(r).catch(()=>null):null;return l?(Io(n,{type:Va(r),headers:{...m,"X-Content-Type-Options":"nosniff"},body:e.method==="HEAD"?void 0:l}),!0):(Io(n,{status:404}),!0)}import je from"node:fs";import Le from"node:path";import{isExtensionId as Za}from"../browser/shared/outline-shape.mjs";import{DOCUMENT_FOLDERS as Mo,isSlugName as Ct,layoutOf as Qa}from"../browser/shared/workspace.mjs";function qa(e){let{components:n,gallery:t,preferencesPage:a,customPages:s,extensions:f}=Qa(e),r=(i,v)=>{try{return je.readdirSync(i,{withFileTypes:!0}).filter(P=>P.isDirectory()&&v(P.name)).map(P=>Le.join(i,P.name))}catch{return[]}},m=[...r(e,i=>Ct(i)),...r(a,i=>Ct(i))],l=i=>[i,...r(i,v=>!v.startsWith(".")).flatMap(l)],h=r(s,i=>Ct(i)&&!Mo.includes(i)),w=r(f,i=>Za(i)&&!Mo.includes(i));return[...new Set([e,...[t,a,s,f].filter(i=>je.existsSync(i)),...h,...w,...m,...m.map(i=>Le.join(i,"assets")).filter(i=>je.existsSync(i)),...je.existsSync(n)?l(n):[]])]}function Wo(e,n,{folders:t=process.platform==="linux"}={}){let a=Ot(e),s=(w,i)=>{a(i)||Le.basename(i).startsWith(".")||je.stat(i,(v,P)=>{if(v)return n(v.code==="ENOENT"?"unlink":"change",i);let u=P.isDirectory();n(w==="rename"?u?"addDir":"add":u?"addDir":"change",i)})},f=()=>{};if(!t)try{let w=je.watch(e,{recursive:!0},(i,v)=>v?s(i,Le.join(e,v.toString())):n("reset",e));return w.on("error",f),{close:()=>w.close()}}catch(w){if(w.code!=="ERR_FEATURE_UNAVAILABLE_ON_PLATFORM")throw w}let r=new Map,m=null,l=()=>{let w=new Set(qa(e));for(let[i,v]of r)w.has(i)||(v.close(),r.delete(i));for(let i of w)if(!r.has(i))try{let v=je.watch(i,(P,u)=>{if(!u)return n("reset",i);P==="rename"&&h(),s(P,Le.join(i,u.toString()))});v.on("error",f),r.set(i,v)}catch{}},h=()=>{m??=setTimeout(()=>{m=null,l()},50)};return l(),{close(){clearTimeout(m);for(let w of r.values())w.close();r.clear()},get folders(){return[...r.keys()]}}}async function pl({port:e,web:n=ss,kind:t=process.env.GALLERY_SERVER_KIND==="dev"?"dev":"cli",stateDirectory:a=ns,exit:s=(l=0)=>process.exit(l),watch:f=!0,signals:r=!0,log:m=console}={}){await is(_e),await Gt(_e,{log:S=>m.log(`[gallery] ${new Date().toISOString()} ${S}`)}),Wt(_e,S=>m.log(`[gallery] ${new Date().toISOString()} ${S}`)),Mt(_e);let l=await Bt(_e,{stateDirectory:a});l.did==="made"?m.log(`[gallery] ${new Date().toISOString()} the default home page made: ${l.file} (${l.cards.length} cards)`):l.did==="failed"&&m.warn(`[gallery] ${new Date().toISOString()} ${zt(l)}`);let h=null,w=null,i=null,v=cs(_e),P=async()=>{w?.close(),i&&at.unwatchFile(st,i),await es.writeFile(v.lastPortFile,`${e}
166
+ `).catch(()=>{}),await new Promise(S=>{h.close(()=>S()),h.closeAllConnections()})},T=Lo({stateDirectory:a,logger:{info:S=>m.log(S),warn:S=>m.warn(S),error:S=>m.error(S)},kind:t,closeServer:P,exit:()=>s(0)});if(h=ts.createServer((S,$)=>{T.handle(S,$,async V=>{if(V){m.error(`[gallery] ${S.method} ${S.url}: ${V.stack??V.message}`),$.headersSent?$.end():Uo($,{status:500});return}try{if(await No(S,$,{web:n,kit:os,vendor:as}))return}catch(W){m.error(`[gallery] ${S.url}: ${W.message}`)}$.headersSent||Uo($,{status:404})})}),h.keepAliveTimeout=5e3,await new Promise((S,$)=>{h.once("error",$),h.listen(e,"127.0.0.1",()=>{h.off("error",$),S()})}),e=h.address().port,await T.listening(e),f&&(w=Wo(_e,T.changed)),rs){let S=at.readFileSync(st,"utf8");i=()=>{let $=null;try{$=at.readFileSync(st,"utf8")}catch{}$!==S&&(m.log("[gallery] The package was replaced (another version installed): this server stops; the next gallery command starts the new one."),T.stop())},at.watchFile(st,{interval:3e3,persistent:!1},i)}if(r)for(let S of["SIGINT","SIGTERM","SIGHUP"])process.once(S,()=>T.stop());return{server:h,port:e,routes:T,async close(){await P(),await T.close()}}}export{pl as a};
@@ -0,0 +1,3 @@
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 L,d as _,e as D,g as N}from"./chunk-35NQ4PLQ.mjs";import{createHash as q,randomUUID as Q}from"node:crypto";import f from"node:fs/promises";import g from"node:path";import{refusal as V,said as T,saying as X}from"../browser/shared/i18n/index.mjs";import{extensionOf as Y,imageExtension as Z,imageFile as M,mediaTypeOf as tt,UPLOAD_LIMITS as y}from"../browser/shared/media.mjs";import{slugPattern as F}from"../browser/shared/reports.mjs";import{documentDirectory as U,documentFiles as et,layoutOf as nt}from"../browser/shared/workspace.mjs";var z=i=>Y(String(i??"").replace(/[?#].*$/,"")),it=i=>{let e=String(i??"").replace(/[?#].*$/,"");e=e.slice(e.lastIndexOf("/")+1);try{e=decodeURIComponent(e)}catch{}return e.replace(/[\u0000-\u001f<>:"/\\|?*]/g,"").trim().slice(0,120)||"file"};function rt(i){let e=i.subarray(0,16);return e[0]===137&&e.toString("latin1",1,4)==="PNG"?"image/png":e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?"image/x-icon":e[0]===255&&e[1]===216?"image/jpeg":e.toString("latin1",0,4)==="GIF8"?"image/gif":e.toString("latin1",0,4)==="RIFF"&&e.toString("latin1",8,12)==="WEBP"?"image/webp":e.toString("latin1",4,12)==="ftypavif"?"image/avif":/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*<svg\b/i.test(i.subarray(0,512).toString("utf8"))?"image/svg+xml":null}var w=(i,e)=>V(e,{reason:i}),S=(i,e)=>{let l=rt(i);if(!l)throw w("type","\u4EC5\u652F\u6301\u56FE\u7247");return Z(l)},at=(i,e)=>z(e),ot=(i,e)=>{let l=z(e);if(!["html","htm","pdf"].includes(l)||l==="pdf"&&i.subarray(0,5).toString("latin1")!=="%PDF-")throw w("type","\u53EA\u80FD\u5D4C\u5165 HTML \u6216 PDF \u6587\u4EF6");return l},j={big:i=>T("\u56FE\u7247\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",i),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u5F20\u56FE\u7247"},B={big:i=>T("\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",i),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u4E2A\u6587\u4EF6"},k={icon:{limit:y.icon,words:j,extension:S},image:{limit:y.image,words:j,extension:S},file:{limit:y.file,words:B,extension:at,named:!0},embed:{limit:y.embed,words:B,extension:ot,named:!0}};function wt(i,e,l,b){let s=k[i].extension(l,b);return`${i}-${e.slice(0,12)}${s?`.${s}`:""}`}function bt({reportsDirectory:i}){let e=nt(i).emojiLibrary,l=async t=>{let n=U(t,i);return await f.stat(et(n).html).catch(()=>null)?n:null},b=g.join(e,"library.json"),s=(t,n,r)=>[t,{ok:!1,reason:n,...X(r)}];async function O(t,n,{stem:r,limit:a,words:c=j,extension:o=S,given:m}){let u=o(n,m);if(n.length>a)throw w("size",c.big(a/1024/1024));let p=`${r}-${q("sha256").update(n).digest("hex").slice(0,12)}${u?`.${u}`:""}`;await f.mkdir(t,{recursive:!0});let h=g.join(t,p);return await f.stat(h).catch(()=>null)||await f.writeFile(h,n),p}let E=(t,n,r,a=y.icon)=>O(t,n,{stem:r,limit:a});async function I(t,n,r=j){let a=await L(t,{unreachable:r.unreachable});if(!a.ok)throw w("download",r.unreachable);let c=await _(a,n);if(!c)throw w("size",r.big(n/1024/1024));return c}async function $(){try{let t=JSON.parse(await f.readFile(b,"utf8"));return Array.isArray(t)?t:[]}catch{return[]}}let v=t=>({id:t.id,name:t.name,url:`/__gallery/edit/emoji-library/${t.file}`,created_time:t.created,alive:!0});async function A(t){let{slug:n,data:r,url:a,library:c}=t??{},o=Object.hasOwn(k,t?.kind)?t.kind:"icon";if(typeof n!="string"||!F.test(n))return s(400,"body");let m=await l(n);if(!m)return s(404,"missing");let{limit:u,words:p,extension:h,named:J}=k[o];try{let d,x;if(typeof r=="string")d=Buffer.from(r,"base64"),x=t.name;else if(typeof a=="string")d=await I(a,u,p),x=a;else if(typeof c=="string"){let P=(await $()).find(K=>K.id===c);if(!P)return s(404,"library","\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u8868\u60C5\u5DF2\u4E0D\u5728\u8868\u60C5\u5E93\u91CC");d=await f.readFile(g.join(e,P.file))}else return s(400,"body");return[200,{ok:!0,path:`assets/${await O(g.join(m,"assets"),d,{stem:o,limit:u,words:p,extension:h,given:x})}`,...J?{name:it(x),size:d.length}:{}}]}catch(d){return s(422,d.reason??"write",d)}}async function R(t){let{slug:n,url:r,parts:a="all"}=t??{};if(typeof n!="string"||!F.test(n)||typeof r!="string"||!["all","icon","title"].includes(a))return s(400,"body");let c=await l(n);if(!c)return s(404,"missing");try{return[200,{ok:!0,...await N(r,async(m,u)=>`assets/${await E(g.join(c,"assets"),m,u,y.image)}`,{icon:a!=="title",cover:a==="all"})}]}catch(o){return s(422,o.reason??"download",o)}}async function W(t){return typeof t?.url!="string"?s(400,"body"):[200,{ok:!0,...await D(t.url)}]}async function C(t){let{slug:n,name:r,url:a}=t??{};if(typeof r!="string"||!/^[\p{Ll}\p{Lo}\d_-]{1,49}$/u.test(r)||typeof a!="string")return s(400,"body");let c=await $();if(c.some(o=>o.name===r))return s(409,"name","\u540D\u79F0\u5DF2\u88AB\u5360\u7528");try{let o;M(a)&&typeof n=="string"&&F.test(n)?o=await f.readFile(g.join(U(n,i),a)):o=await I(a,y.icon);let m=await E(e,o,"emoji"),u={id:Q(),name:r,file:m,created:Date.now()};return await f.writeFile(b,`${JSON.stringify([...c,u],null,2)}
3
+ `),[200,{ok:!0,entry:v(u)}]}catch(o){return s(422,o.reason??"write",o)}}let G=async()=>[200,{ok:!0,list:(await $()).map(v)}];async function H(t){if(!M(`assets/${t}`))return null;let n=await f.readFile(g.join(e,t)).catch(()=>null);return n&&{type:tt(t),body:n}}return{upload:A,unfurl:R,frameable:W,addEmoji:C,listEmojis:G,readEmoji:H}}export{wt as a,bt as b};