@heycys/gallery 0.1.0 → 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 (465) hide show
  1. package/THIRD-PARTY-NOTICES.md +51 -1
  2. package/browser/editor/components/callout/index.mjs +40 -15
  3. package/browser/editor/components/columns/page.mjs +45 -32
  4. package/browser/editor/components/details/index.mjs +2 -1
  5. package/browser/editor/components/dialog/index.mjs +2 -1
  6. package/browser/editor/components/dialog/page.mjs +0 -18
  7. package/browser/editor/components/divider/index.mjs +1 -1
  8. package/browser/editor/components/embed/index.mjs +2 -2
  9. package/browser/editor/components/figure/page.mjs +10 -1
  10. package/browser/editor/components/file/page.mjs +2 -2
  11. package/browser/editor/components/flowchart/add.mjs +7 -6
  12. package/browser/editor/components/flowchart/page.mjs +1 -1
  13. package/browser/editor/components/heading/index.mjs +2 -0
  14. package/browser/editor/components/heading/page.mjs +6 -0
  15. package/browser/editor/components/highlight/index.mjs +4 -20
  16. package/browser/editor/components/icons.mjs +13 -2
  17. package/browser/editor/components/image/crop.mjs +6 -9
  18. package/browser/editor/components/image/page.mjs +2 -2
  19. package/browser/editor/components/installed/index.mjs +82 -29
  20. package/browser/editor/components/installed/page.mjs +146 -34
  21. package/browser/editor/components/installed/served.mjs +6 -5
  22. package/browser/editor/components/instances.mjs +18 -0
  23. package/browser/editor/components/kit.mjs +3 -0
  24. package/browser/editor/components/list/page.mjs +3 -6
  25. package/browser/editor/components/media/page.mjs +44 -14
  26. package/browser/editor/components/pages.mjs +2 -2
  27. package/browser/editor/components/registry.mjs +68 -33
  28. package/browser/editor/components/section/index.mjs +2 -1
  29. package/browser/editor/components/set-apart.mjs +24 -0
  30. package/browser/editor/components/table/index.mjs +64 -5
  31. package/browser/editor/components/table/page.mjs +30 -19
  32. package/browser/editor/page/annotate/anchors.mjs +4 -3
  33. package/browser/editor/page/annotate/card.mjs +3 -6
  34. package/browser/editor/page/annotate/index.mjs +61 -34
  35. package/browser/editor/page/autosave.mjs +357 -38
  36. package/browser/editor/page/beside.mjs +5 -5
  37. package/browser/editor/page/block-menu/colors.mjs +3 -1
  38. package/browser/editor/page/block-menu/index.mjs +8 -6
  39. package/browser/editor/page/blocks.mjs +16 -7
  40. package/browser/editor/page/board/client.mjs +57 -0
  41. package/browser/editor/page/board/hint.mjs +145 -0
  42. package/browser/editor/page/board/history.mjs +119 -0
  43. package/browser/editor/page/board/index.mjs +970 -0
  44. package/browser/editor/page/board/settings.mjs +209 -0
  45. package/browser/editor/page/caret.mjs +5 -2
  46. package/browser/editor/page/changes/bar.mjs +94 -0
  47. package/browser/editor/page/changes/ghost.mjs +206 -0
  48. package/browser/editor/page/changes/gone-words.mjs +94 -0
  49. package/browser/editor/page/changes/index.mjs +447 -0
  50. package/browser/editor/page/changes/words.mjs +27 -0
  51. package/browser/editor/page/clipboard/import/colors.mjs +3 -3
  52. package/browser/editor/page/clipboard/import/html.mjs +29 -6
  53. package/browser/editor/page/clipboard/import/inline.mjs +32 -0
  54. package/browser/editor/page/clipboard/import/markdown.mjs +58 -13
  55. package/browser/editor/page/clipboard/import/read.mjs +6 -1
  56. package/browser/editor/page/clipboard/import/to-blocks.mjs +44 -12
  57. package/browser/editor/page/clipboard/import/yuque.mjs +622 -0
  58. package/browser/editor/page/clipboard/index.mjs +156 -26
  59. package/browser/editor/page/clipboard/own/blocks.mjs +25 -16
  60. package/browser/editor/page/clipboard/own/chart-keys.mjs +41 -28
  61. package/browser/editor/page/clipboard/own/describe.mjs +16 -7
  62. package/browser/editor/page/clipboard/own/export.mjs +6 -6
  63. package/browser/editor/page/clipboard/own/selection.mjs +3 -3
  64. package/browser/editor/page/clipboard/own/writers.mjs +0 -11
  65. package/browser/editor/page/columns/index.mjs +48 -46
  66. package/browser/editor/page/commit.mjs +98 -25
  67. package/browser/editor/page/conflicts.mjs +13 -33
  68. package/browser/editor/page/convert.mjs +8 -7
  69. package/browser/editor/page/core.mjs +81 -27
  70. package/browser/editor/page/custom-page.mjs +106 -0
  71. package/browser/editor/page/drag/index.mjs +40 -24
  72. package/browser/editor/page/drag/preview.mjs +9 -4
  73. package/browser/editor/page/editor.mjs +120 -28
  74. package/browser/editor/page/emoji-picker/emoji-tab.mjs +22 -13
  75. package/browser/editor/page/emoji-picker/grid.mjs +7 -5
  76. package/browser/editor/page/emoji-picker/icon-tab.mjs +4 -4
  77. package/browser/editor/page/emoji-picker/icons.mjs +0 -1
  78. package/browser/editor/page/emoji-picker/index.mjs +11 -9
  79. package/browser/editor/page/emoji-picker/styles.mjs +156 -2
  80. package/browser/editor/page/emoji-picker/support.mjs +6 -4
  81. package/browser/editor/page/emoji-picker/upload.mjs +14 -13
  82. package/browser/editor/page/fills.mjs +5 -3
  83. package/browser/editor/page/fold/index.mjs +348 -0
  84. package/browser/editor/page/fold/rule.mjs +125 -0
  85. package/browser/editor/page/folded.mjs +23 -0
  86. package/browser/editor/page/format-bar/bar.mjs +2 -1
  87. package/browser/editor/page/format-bar/index.mjs +1 -1
  88. package/browser/editor/page/geometry.mjs +8 -6
  89. package/browser/editor/page/handle/index.mjs +22 -14
  90. package/browser/editor/page/hints/index.mjs +1 -1
  91. package/browser/editor/page/history.mjs +24 -4
  92. package/browser/editor/page/insert/index.mjs +30 -17
  93. package/browser/editor/page/links/index.mjs +5 -3
  94. package/browser/editor/page/links/pages.mjs +27 -9
  95. package/browser/editor/page/long-runs.mjs +75 -0
  96. package/browser/editor/page/look.mjs +69 -6
  97. package/browser/editor/page/margin.mjs +63 -27
  98. package/browser/editor/page/media-menu/index.mjs +6 -7
  99. package/browser/editor/page/menu.mjs +86 -31
  100. package/browser/editor/page/merge.mjs +24 -0
  101. package/browser/editor/page/notices.mjs +3 -3
  102. package/browser/editor/page/offered.mjs +1 -1
  103. package/browser/editor/page/outline/folds.mjs +11 -10
  104. package/browser/editor/page/outline/index.mjs +131 -45
  105. package/browser/editor/page/outline/list.mjs +23 -11
  106. package/browser/editor/page/outline/read.mjs +1 -1
  107. package/browser/editor/page/outline/strip.mjs +7 -1
  108. package/browser/editor/page/page-objects.mjs +13 -2
  109. package/browser/editor/page/panel.mjs +9 -13
  110. package/browser/editor/page/present-links.mjs +11 -2
  111. package/browser/editor/page/resize/index.mjs +42 -29
  112. package/browser/editor/page/selection/delete.mjs +8 -6
  113. package/browser/editor/page/selection/index.mjs +10 -3
  114. package/browser/editor/page/served.mjs +14 -0
  115. package/browser/editor/page/session.mjs +101 -6
  116. package/browser/editor/page/slash-menu/index.mjs +3 -3
  117. package/browser/editor/page/table/cell-bar.mjs +4 -1
  118. package/browser/editor/page/table/cells.mjs +103 -47
  119. package/browser/editor/page/table/icons.mjs +3 -1
  120. package/browser/editor/page/table/index.mjs +40 -16
  121. package/browser/editor/page/table/pictures.mjs +299 -0
  122. package/browser/editor/page/table/views.mjs +150 -0
  123. package/browser/editor/page/table/widths.mjs +9 -4
  124. package/browser/editor/page/text-select/index.mjs +43 -14
  125. package/browser/editor/page/todo-writes.mjs +75 -0
  126. package/browser/editor/page/tooltip.mjs +1 -1
  127. package/browser/editor/page/type-grid.mjs +4 -3
  128. package/browser/editor/page/typing/code-edges.mjs +63 -17
  129. package/browser/editor/page/typing/index.mjs +65 -9
  130. package/browser/editor/page/typing/leave.mjs +1 -1
  131. package/browser/editor/page/ui.mjs +13 -0
  132. package/browser/shared/annotations.mjs +8 -10
  133. package/browser/shared/block-packs.mjs +404 -0
  134. package/browser/shared/board-places.mjs +224 -0
  135. package/browser/shared/card-size.mjs +59 -0
  136. package/browser/shared/code-folds.mjs +5 -1
  137. package/browser/shared/colors.mjs +17 -14
  138. package/browser/shared/component-catalog.mjs +345 -54
  139. package/browser/shared/component-source.mjs +37 -0
  140. package/browser/shared/components/callout.mjs +4 -2
  141. package/browser/shared/components/index.mjs +72 -9
  142. package/browser/shared/components/installed.mjs +110 -8
  143. package/browser/shared/components/page.mjs +22 -3
  144. package/browser/shared/components/state.mjs +5 -1
  145. package/browser/shared/components/table.mjs +1 -1
  146. package/browser/shared/components/text.mjs +2 -2
  147. package/browser/shared/document-look.mjs +183 -0
  148. package/browser/shared/drafts.mjs +432 -0
  149. package/browser/shared/emoji/data/LICENSE-lucide.txt +43 -0
  150. package/browser/shared/emoji/data/README.md +4 -2
  151. package/browser/shared/emoji/data/categories.json +1 -1
  152. package/browser/shared/emoji/data/keywords-en.json +1 -1
  153. package/browser/shared/emoji/data/keywords-zh.json +1 -1
  154. package/browser/shared/emoji/data/names.json +1 -1
  155. package/browser/shared/emoji/data/positions.json +1 -1
  156. package/browser/shared/emoji/data/twemoji-index.json +1 -1
  157. package/browser/shared/emoji/data/twemoji-svg.bin +0 -0
  158. package/browser/shared/emoji/data.mjs +10 -12
  159. package/browser/shared/emoji/emoji.mjs +8 -7
  160. package/browser/shared/emoji/icon-value.mjs +4 -3
  161. package/browser/shared/extension-sidebar.mjs +126 -0
  162. package/browser/shared/extensions.mjs +79 -0
  163. package/browser/shared/file-table.mjs +101 -0
  164. package/browser/shared/html-tree.mjs +11 -5
  165. package/browser/shared/i18n/en.mjs +374 -35
  166. package/browser/shared/json-layout.mjs +47 -0
  167. package/browser/shared/long-runs.mjs +39 -0
  168. package/browser/shared/net-cache.mjs +133 -0
  169. package/browser/shared/net-keys.mjs +32 -0
  170. package/browser/shared/net-policy.mjs +177 -0
  171. package/browser/shared/new-names.mjs +5 -2
  172. package/browser/shared/outline-shape.mjs +128 -0
  173. package/browser/shared/outline.mjs +458 -0
  174. package/browser/shared/pack-manifest.mjs +77 -0
  175. package/browser/shared/page-address.mjs +6 -3
  176. package/browser/shared/page-cards.mjs +308 -0
  177. package/browser/shared/page-links.mjs +69 -6
  178. package/browser/shared/pages.mjs +388 -0
  179. package/browser/shared/paths.mjs +6 -0
  180. package/browser/shared/preferences.mjs +10 -4
  181. package/browser/shared/preview-server.mjs +3 -7
  182. package/browser/shared/session.mjs +13 -5
  183. package/browser/shared/shipped-blocks.mjs +299 -0
  184. package/browser/shared/table-chart.mjs +33 -1
  185. package/browser/shared/todos.mjs +83 -0
  186. package/browser/shared/user-directory.mjs +24 -0
  187. package/browser/shared/versions.mjs +14 -0
  188. package/browser/shared/web-links.mjs +134 -0
  189. package/browser/shared/workspace-columns.mjs +120 -0
  190. package/browser/shared/workspace-look.mjs +91 -0
  191. package/browser/shared/workspace-name.mjs +154 -0
  192. package/browser/shared/workspace-query.mjs +125 -0
  193. package/browser/shared/workspace-registry.mjs +272 -0
  194. package/browser/shared/workspace.mjs +171 -20
  195. package/browser/shared/zoom.mjs +5 -5
  196. package/dist/chunk-2NRBY6AJ.mjs +2 -0
  197. package/dist/chunk-32ZUEFZ7.mjs +2 -0
  198. package/dist/chunk-35NQ4PLQ.mjs +2 -0
  199. package/dist/chunk-3KJHLHUO.mjs +2 -0
  200. package/dist/chunk-3NJACR4W.mjs +2 -0
  201. package/dist/chunk-4AV456RQ.mjs +2 -0
  202. package/dist/chunk-4OZWXZE5.mjs +5 -0
  203. package/dist/chunk-5XYHDBJ5.mjs +2 -0
  204. package/dist/chunk-5ZJA7CXT.mjs +2 -0
  205. package/dist/chunk-6A53MZYZ.mjs +2 -0
  206. package/dist/chunk-6EXH3ORZ.mjs +166 -0
  207. package/dist/chunk-6EZ7FNIK.mjs +3 -0
  208. package/dist/{chunk-UXUK4PMC.mjs → chunk-6QBHU4DF.mjs} +1 -1
  209. package/dist/{chunk-6U2SLSDN.mjs → chunk-6VTU6KEO.mjs} +1 -1
  210. package/dist/chunk-B4P2CM2J.mjs +3 -0
  211. package/dist/chunk-BPL64HGA.mjs +4 -0
  212. package/dist/chunk-BVEFGE4B.mjs +2 -0
  213. package/dist/chunk-BZ5RAF7L.mjs +2 -0
  214. package/dist/chunk-CRJEG7MT.mjs +2 -0
  215. package/dist/{chunk-B3VTYBYR.mjs → chunk-D4CKRD3V.mjs} +91 -91
  216. package/dist/chunk-D4EURAX4.mjs +4 -0
  217. package/dist/chunk-DQCE7TJY.mjs +5 -0
  218. package/dist/chunk-DR73Y2UJ.mjs +3 -0
  219. package/dist/{chunk-TMYZB6AV.mjs → chunk-EKNHM3P4.mjs} +1 -1
  220. package/dist/{chunk-DB4WKGYF.mjs → chunk-ERLAIBOA.mjs} +2 -2
  221. package/dist/chunk-EURLTOTZ.mjs +4 -0
  222. package/dist/chunk-FJYN7RTH.mjs +4 -0
  223. package/dist/chunk-FWNRPMCJ.mjs +12 -0
  224. package/dist/chunk-FWW4CSAZ.mjs +2 -0
  225. package/dist/{chunk-2B5E4CDJ.mjs → chunk-GPIWQ4X4.mjs} +1 -1
  226. package/dist/chunk-GY3FAUVM.mjs +2 -0
  227. package/dist/chunk-HLYV7RIH.mjs +2 -0
  228. package/dist/chunk-HMYTM3GT.mjs +15 -0
  229. package/dist/chunk-IA4PSIMD.mjs +2 -0
  230. package/dist/chunk-JEUK3ZO7.mjs +2 -0
  231. package/dist/chunk-JVHHHGEA.mjs +3 -0
  232. package/dist/chunk-KTKHRC6H.mjs +2 -0
  233. package/dist/chunk-L7UP52JO.mjs +2 -0
  234. package/dist/chunk-MHW7ZKOU.mjs +2 -0
  235. package/dist/chunk-N76HWBA3.mjs +10 -0
  236. package/dist/chunk-N7AZZLGT.mjs +548 -0
  237. package/dist/chunk-NAMN3RAF.mjs +2 -0
  238. package/dist/{chunk-YXAUQPVK.mjs → chunk-NFMCP2HI.mjs} +3 -3
  239. package/dist/chunk-NG375ILQ.mjs +2 -0
  240. package/dist/chunk-NVRNLK25.mjs +6 -0
  241. package/dist/chunk-NWFBE2YA.mjs +2 -0
  242. package/dist/chunk-NWR2LT5B.mjs +2 -0
  243. package/dist/chunk-OJKMINIU.mjs +20 -0
  244. package/dist/chunk-OUUP3WKT.mjs +2 -0
  245. package/dist/chunk-OW5NWPOJ.mjs +10 -0
  246. package/dist/chunk-PAREWQGB.mjs +4 -0
  247. package/dist/chunk-POQSE4C2.mjs +2 -0
  248. package/dist/chunk-PUOQ65NC.mjs +2 -0
  249. package/dist/{chunk-Z52HTUW7.mjs → chunk-PVER7LSC.mjs} +2 -2
  250. package/dist/chunk-PZDLJJTJ.mjs +3 -0
  251. package/dist/chunk-Q47PLKIJ.mjs +15 -0
  252. package/dist/chunk-Q4UEPUWF.mjs +2 -0
  253. package/dist/chunk-QKXMPUXC.mjs +2 -0
  254. package/dist/chunk-QOUEFUCH.mjs +16 -0
  255. package/dist/chunk-RFDZXFJF.mjs +13 -0
  256. package/dist/chunk-RKPWLGZ3.mjs +4 -0
  257. package/dist/chunk-RMECZA2K.mjs +2 -0
  258. package/dist/{chunk-EUX7IC5J.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  259. package/dist/chunk-SX4LJYT6.mjs +8 -0
  260. package/dist/chunk-SXHBYZST.mjs +16 -0
  261. package/dist/chunk-TANZRINB.mjs +2 -0
  262. package/dist/chunk-TEZAWDSQ.mjs +2 -0
  263. package/dist/chunk-UBBRTJ2R.mjs +24 -0
  264. package/dist/chunk-UFNYFFKO.mjs +20 -0
  265. package/dist/chunk-UGWYKHBL.mjs +170 -0
  266. package/dist/chunk-UKSHDZZ6.mjs +2 -0
  267. package/dist/chunk-UMHUSOPJ.mjs +2 -0
  268. package/dist/chunk-UNOYVIYR.mjs +2 -0
  269. package/dist/chunk-V6RIYQZZ.mjs +4 -0
  270. package/dist/chunk-VJPFVNNW.mjs +15 -0
  271. package/dist/chunk-VS3ZMVGX.mjs +5 -0
  272. package/dist/chunk-VTKNEYT3.mjs +6 -0
  273. package/dist/chunk-VXACTLO3.mjs +3 -0
  274. package/dist/chunk-W3BGBJQW.mjs +2 -0
  275. package/dist/chunk-YI43RG4P.mjs +2 -0
  276. package/dist/chunk-YQGT4AB2.mjs +6 -0
  277. package/dist/chunk-ZB4H7ZN4.mjs +2 -0
  278. package/dist/{chunk-ACOPDCNB.mjs → chunk-ZHEHPMBK.mjs} +1 -1
  279. package/dist/chunk-ZTHICSSF.mjs +2 -0
  280. package/dist/chunk-ZUNVAXLH.mjs +2 -0
  281. package/dist/chunk-ZWPMCK7P.mjs +2 -0
  282. package/dist/cli.mjs +1 -1
  283. package/dist/server.mjs +1 -1
  284. package/dist/{chunk-EVJ3BX3M.mjs → update-fetch.mjs} +1 -1
  285. package/dist/worker.mjs +1 -1
  286. package/kit/board.css +95 -0
  287. package/kit/board.js +250 -0
  288. package/kit/charts.js +5 -71
  289. package/kit/code.js +14 -14
  290. package/kit/math.js +18 -2
  291. package/kit/report.css +500 -151
  292. package/kit/runtime.js +1720 -170
  293. package/kit/state.js +10 -1
  294. package/kit/tables.js +172 -37
  295. package/kit/ui.js +166 -27
  296. package/package.json +2 -1
  297. package/packs/gallery/card/component.json +14 -0
  298. package/packs/gallery/card/example.html +10 -0
  299. package/packs/gallery/card/preview.svg +1 -0
  300. package/packs/gallery/card/style.css +6 -0
  301. package/packs/gallery/card/template.html +6 -0
  302. package/packs/gallery/card/writing.md +14 -0
  303. package/packs/gallery/chart-card/component.json +15 -0
  304. package/packs/gallery/chart-card/example.html +14 -0
  305. package/packs/gallery/chart-card/kit.js +130 -0
  306. package/packs/gallery/chart-card/preview.svg +1 -0
  307. package/packs/gallery/chart-card/style.css +42 -0
  308. package/packs/gallery/chart-card/template.html +13 -0
  309. package/packs/gallery/chart-card/writing.md +20 -0
  310. package/packs/gallery/chart-view/component.json +20 -0
  311. package/packs/gallery/chart-view/example.html +13 -0
  312. package/packs/gallery/chart-view/kit.js +355 -0
  313. package/packs/gallery/chart-view/preview.svg +1 -0
  314. package/packs/gallery/chart-view/style.css +94 -0
  315. package/packs/gallery/chart-view/template.html +3 -0
  316. package/packs/gallery/chart-view/writing.md +22 -0
  317. package/packs/gallery/countdown/component.json +18 -0
  318. package/packs/gallery/countdown/example.html +3 -0
  319. package/packs/gallery/countdown/kit.js +156 -0
  320. package/packs/gallery/countdown/preview.svg +1 -0
  321. package/packs/gallery/countdown/style.css +130 -0
  322. package/packs/gallery/countdown/template.html +3 -0
  323. package/packs/gallery/countdown/writing.md +22 -0
  324. package/packs/gallery/habit/component.json +14 -0
  325. package/packs/gallery/habit/example.html +3 -0
  326. package/packs/gallery/habit/kit.js +295 -0
  327. package/packs/gallery/habit/preview.svg +1 -0
  328. package/packs/gallery/habit/style.css +246 -0
  329. package/packs/gallery/habit/template.html +3 -0
  330. package/packs/gallery/habit/writing.md +21 -0
  331. package/packs/gallery/heatmap/component.json +18 -0
  332. package/packs/gallery/heatmap/example.html +3 -0
  333. package/packs/gallery/heatmap/kit.js +351 -0
  334. package/packs/gallery/heatmap/preview.svg +1 -0
  335. package/packs/gallery/heatmap/style.css +201 -0
  336. package/packs/gallery/heatmap/template.html +3 -0
  337. package/packs/gallery/heatmap/writing.md +21 -0
  338. package/packs/gallery/kanban/component.json +18 -0
  339. package/packs/gallery/kanban/example.html +12 -0
  340. package/packs/gallery/kanban/kit.js +540 -0
  341. package/packs/gallery/kanban/preview.svg +1 -0
  342. package/packs/gallery/kanban/style.css +212 -0
  343. package/packs/gallery/kanban/template.html +3 -0
  344. package/packs/gallery/kanban/writing.md +20 -0
  345. package/packs/gallery/metric/component.json +22 -0
  346. package/packs/gallery/metric/example.html +15 -0
  347. package/packs/gallery/metric/kit.js +248 -0
  348. package/packs/gallery/metric/preview.svg +1 -0
  349. package/packs/gallery/metric/style.css +92 -0
  350. package/packs/gallery/metric/template.html +3 -0
  351. package/packs/gallery/metric/writing.md +23 -0
  352. package/packs/gallery/note/component.json +14 -0
  353. package/packs/gallery/note/example.html +3 -0
  354. package/packs/gallery/note/kit.js +102 -0
  355. package/packs/gallery/note/preview.svg +1 -0
  356. package/packs/gallery/note/style.css +76 -0
  357. package/packs/gallery/note/template.html +3 -0
  358. package/packs/gallery/note/writing.md +18 -0
  359. package/packs/gallery/pack.json +8 -0
  360. package/packs/gallery/recent/component.json +13 -0
  361. package/packs/gallery/recent/example.html +1 -0
  362. package/packs/gallery/recent/kit.js +238 -0
  363. package/packs/gallery/recent/preview.svg +1 -0
  364. package/packs/gallery/recent/style.css +158 -0
  365. package/packs/gallery/recent/template.html +1 -0
  366. package/packs/gallery/recent/writing.md +15 -0
  367. package/packs/gallery/static/component.json +13 -0
  368. package/packs/gallery/static/example.html +11 -0
  369. package/packs/gallery/static/preview.svg +1 -0
  370. package/packs/gallery/static/style.css +138 -0
  371. package/packs/gallery/static/template.html +1 -0
  372. package/packs/gallery/static/writing.md +18 -0
  373. package/packs/gallery/stats/component.json +13 -0
  374. package/packs/gallery/stats/example.html +1 -0
  375. package/packs/gallery/stats/kit.js +166 -0
  376. package/packs/gallery/stats/preview.svg +1 -0
  377. package/packs/gallery/stats/style.css +151 -0
  378. package/packs/gallery/stats/template.html +1 -0
  379. package/packs/gallery/stats/writing.md +11 -0
  380. package/packs/gallery/today/component.json +12 -0
  381. package/packs/gallery/today/example.html +1 -0
  382. package/packs/gallery/today/kit.js +185 -0
  383. package/packs/gallery/today/preview.svg +1 -0
  384. package/packs/gallery/today/style.css +120 -0
  385. package/packs/gallery/today/template.html +1 -0
  386. package/packs/gallery/today/writing.md +14 -0
  387. package/packs/gallery/todos/component.json +19 -0
  388. package/packs/gallery/todos/example.html +3 -0
  389. package/packs/gallery/todos/kit.js +342 -0
  390. package/packs/gallery/todos/preview.svg +1 -0
  391. package/packs/gallery/todos/style.css +267 -0
  392. package/packs/gallery/todos/template.html +3 -0
  393. package/packs/gallery/todos/writing.md +30 -0
  394. package/packs/gallery/weather/component.json +19 -0
  395. package/packs/gallery/weather/example.html +3 -0
  396. package/packs/gallery/weather/kit.js +312 -0
  397. package/packs/gallery/weather/preview.svg +1 -0
  398. package/packs/gallery/weather/style.css +258 -0
  399. package/packs/gallery/weather/template.html +3 -0
  400. package/packs/gallery/weather/writing.md +26 -0
  401. package/packs/gallery-soft/pack.json +8 -0
  402. package/release.json +13 -11
  403. package/sdk/doc-kit.d.ts +404 -7
  404. package/sdk/doc-state.d.ts +2 -0
  405. package/skill/SKILL.md +71 -26
  406. package/skill/references/block-script.md +140 -0
  407. package/skill/references/building-blocks.md +257 -0
  408. package/skill/references/example-report.html +1 -1
  409. package/skill/references/extensions.md +59 -0
  410. package/skill/references/pages-and-data.md +221 -0
  411. package/skill/references/writing-html.md +9 -7
  412. package/skill/sdk/doc-kit.d.ts +404 -7
  413. package/skill/sdk/doc-state.d.ts +2 -0
  414. package/web/assets/index-BK2e_07w.js +13 -0
  415. package/web/assets/index-CWFI83mF.css +1 -0
  416. package/web/index.html +2 -2
  417. package/browser/editor/components/callout/page.mjs +0 -13
  418. package/dist/chunk-2PBALTR3.mjs +0 -57
  419. package/dist/chunk-3LA3EMDE.mjs +0 -15
  420. package/dist/chunk-5FRMCDPY.mjs +0 -16
  421. package/dist/chunk-5LEK2CBS.mjs +0 -2
  422. package/dist/chunk-5OFN5AHC.mjs +0 -2
  423. package/dist/chunk-5SIYS5HN.mjs +0 -2
  424. package/dist/chunk-5TEK3RAD.mjs +0 -2
  425. package/dist/chunk-6CYG3Z4V.mjs +0 -2
  426. package/dist/chunk-7GHT2UCA.mjs +0 -15
  427. package/dist/chunk-7QQBR7PB.mjs +0 -2
  428. package/dist/chunk-ATCJYAR4.mjs +0 -2
  429. package/dist/chunk-C7HWOBIF.mjs +0 -2
  430. package/dist/chunk-E7VYDG2X.mjs +0 -2
  431. package/dist/chunk-EZY3WC6Z.mjs +0 -15
  432. package/dist/chunk-FQGQH4KM.mjs +0 -2
  433. package/dist/chunk-G7TOXONE.mjs +0 -6
  434. package/dist/chunk-GPF4YWWB.mjs +0 -9
  435. package/dist/chunk-GYQV7Y4J.mjs +0 -120
  436. package/dist/chunk-HMHK3EQ6.mjs +0 -2
  437. package/dist/chunk-HQQMJCQJ.mjs +0 -10
  438. package/dist/chunk-IERUOGC3.mjs +0 -6
  439. package/dist/chunk-ITNLYXXV.mjs +0 -3
  440. package/dist/chunk-L4DVONOG.mjs +0 -2
  441. package/dist/chunk-LAE5NQ4B.mjs +0 -2
  442. package/dist/chunk-LC7YNQFG.mjs +0 -2
  443. package/dist/chunk-LHTFLRB6.mjs +0 -4
  444. package/dist/chunk-NFIBI4IP.mjs +0 -26
  445. package/dist/chunk-NSKUTQ5J.mjs +0 -5
  446. package/dist/chunk-O52JMOCZ.mjs +0 -2
  447. package/dist/chunk-P2CAZPDP.mjs +0 -3
  448. package/dist/chunk-QMQUXTU4.mjs +0 -12
  449. package/dist/chunk-QVWVFC5K.mjs +0 -6
  450. package/dist/chunk-QYKCJ7FG.mjs +0 -8
  451. package/dist/chunk-QZY6Q64C.mjs +0 -2
  452. package/dist/chunk-TDQP3DKQ.mjs +0 -10
  453. package/dist/chunk-TX6JH7TR.mjs +0 -2
  454. package/dist/chunk-UNUEWH4S.mjs +0 -2
  455. package/dist/chunk-V4CPWKMZ.mjs +0 -2
  456. package/dist/chunk-VACRB2NE.mjs +0 -3
  457. package/dist/chunk-W63L7367.mjs +0 -7
  458. package/dist/chunk-W7CXPCRV.mjs +0 -6
  459. package/dist/chunk-XINNG4F2.mjs +0 -4
  460. package/dist/chunk-YL2DPWVS.mjs +0 -4
  461. package/dist/chunk-YZ5Z6H4W.mjs +0 -4
  462. package/dist/chunk-ZBIM6ARY.mjs +0 -216
  463. package/skill/references/building-components.md +0 -327
  464. package/web/assets/index-B6Ai3wsa.js +0 -13
  465. package/web/assets/index-SYPC3EZy.css +0 -1
@@ -0,0 +1,4 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as X,c as re,e as oe,j as Z}from"./chunk-FWNRPMCJ.mjs";import{createHash as we}from"node:crypto";import v from"node:fs";import h from"node:path";import{packsDirectory as T}from"../browser/shared/paths.mjs";import{PACKAGE_MANIFEST as M,layoutOf as U}from"../browser/shared/workspace.mjs";var $e="gallery",ee=/^(?:\.DS_Store|\._.*|Thumbs\.db|ehthumbs\.db|desktop\.ini)$/i,W=n=>ee.test(n);function G(n){return v.readdirSync(n,{recursive:!0,withFileTypes:!0}).filter(e=>e.isFile()&&!ee.test(e.name)).map(e=>h.relative(n,h.join(e.parentPath,e.name)).split(h.sep).join("/")).sort()}var Y=n=>[...n.filter(e=>e!==M),...n.includes(M)?[M]:[]];function P(n){return v.existsSync(n)?K(G(n).map(e=>({name:e,data:v.readFileSync(h.join(n,e))}))):null}function K(n){let e=we("sha256"),t=n.filter(({name:i})=>!ee.test(i.split("/").at(-1))).sort((i,s)=>i.name<s.name?-1:i.name>s.name?1:0);for(let{name:i,data:s}of t)e.update(`${i}\0`).update(s).update(`
3
+ `);return e.digest("hex").slice(0,16)}var Q=n=>{try{return v.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name).sort()}catch{return[]}},E=(n=T)=>Q(n);function D(n=T){return Q(n).flatMap(e=>Q(h.join(n,e)).flatMap(t=>{let i=h.join(n,e,t);try{let s=JSON.parse(v.readFileSync(h.join(i,M),"utf8"));return s.id!==`${e}/${t}`?[]:[{name:t,id:s.id,pack:e,folder:i,version:s.version,title:s.name,description:s.description,places:s.places??["document"]}]}catch{return[]}}))}function qe(n,e=T){let t=n.includes("/")?n:`${$e}/${n}`;return D(e).find(i=>i.id===t)??null}var He=(n,e=T)=>E(e).includes(String(n).split("/")[0]);function N(n){try{let e=JSON.parse(v.readFileSync(U(n).blocks,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function z(n,e){let t=U(n).blocks;v.mkdirSync(h.dirname(t),{recursive:!0}),v.writeFileSync(t,`${JSON.stringify(e,null,2)}
4
+ `)}var pe=(n,e)=>h.join(U(n).components,...e.split("/"));function ne(n,e){let t=pe(n,e.id),i=P(t);if(i===null)return{added:!1,version:null,changed:!1,behind:!1};let s=null;try{s=JSON.parse(v.readFileSync(h.join(t,M),"utf8")).version??null}catch{}let l=N(n)[e.id],c=P(e.folder),o=i!==c&&i!==l?.fingerprint;return{added:!0,version:s,changed:o,behind:!o&&i!==c}}function je(n,e){let t=pe(n,e.id),i=ne(n,e);if(i.changed)throw Object.assign(new Error(`${e.id} was changed after it was added`),{code:"changed",folder:t});let s=P(e.folder),l=N(n);if(i.added&&!i.behind)return l[e.id]?.fingerprint!==s&&z(n,{...l,[e.id]:{version:e.version,fingerprint:s}}),{did:"same",folder:t};let c=G(e.folder);if(i.added)for(let o of G(t))c.includes(o)||v.rmSync(h.join(t,o));for(let o of Y(c))v.mkdirSync(h.dirname(h.join(t,o)),{recursive:!0}),v.copyFileSync(h.join(e.folder,o),h.join(t,o));return z(n,{...l,[e.id]:{version:e.version,fingerprint:s}}),{did:i.added?"updated":"added",from:i.version,folder:t}}var ce=n=>/^\d+\.\d+\.\d+$/.test(String(n??""))?n.split(".").map(Number):null;function R(n,e){let[t,i]=[ce(n),ce(e)];if(!t||!i)return n!==e;let s=t.findIndex((l,c)=>l!==i[c]);return s!==-1&&t[s]>i[s]}function Ve(n,e){let t=ne(n,e);return t.changed&&R(e.version,t.version)?e.version:null}var ae=new Map,ue=()=>{};function xe(n,{updated:e,kept:t,failed:i}){let s=[];e.length&&s.push(`Gallery's own blocks in ${n}, as they were added, updated to this Gallery's: ${e.map(({id:l,from:c,to:o})=>`${l} ${c??"?"} -> ${o}`).join(", ")}`);for(let{id:l,version:c,shipped:o}of t)s.push(`${l} in ${n} was changed after it was added, so it stays at ${c??"its version"}: Gallery's is ${o} (\u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 says how to take it)`);for(let{id:l,to:c,why:o}of i)s.push(`${l} in ${n} could not be updated to Gallery's ${c}: ${o}`);return s}function Fe(n,{ids:e=null,directory:t=T,log:i=null}={}){let s={updated:[],kept:[],failed:[]},l=h.resolve(n);for(let c of D(t)){if(e&&!e.includes(c.id))continue;let o=`${l}\0${h.resolve(c.folder)}`;if(ae.get(o)!==c.version){ae.set(o,c.version);try{let r=ne(n,c);if(r.changed&&R(c.version,r.version)&&s.kept.push({id:c.id,version:r.version,shipped:c.version}),!r.behind)continue;je(n,c).did==="updated"&&s.updated.push({id:c.id,from:r.version,to:c.version})}catch(r){s.failed.push({id:c.id,to:c.version,why:r?.message??String(r)})}}}for(let c of xe(l,s))(i??ue)(c);return s}var le=new Set,fe=n=>process.platform==="win32"?h.resolve(n).toLowerCase():h.resolve(n);function Xe(n,e){le.add(fe(n)),ue=e,oe((t,i)=>{le.has(fe(t))&&Fe(t,{ids:i})},E())}var de=n=>[n,n.replace("/","-")],Oe=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Ze(n,e,t=T){for(let i of D(t)){if(i.id===e)continue;let s;try{s=v.readFileSync(h.join(i.folder,"preview.svg"))}catch{continue}if(s.equals(n)||Buffer.from(be(i,e)["preview.svg"]??"").equals(n))return i}return null}function be(n,e){let[t,i]=[de(n.id),de(e)],s=new RegExp(t.map(Oe).join("|"),"g"),l={};for(let c of G(n.folder)){let o=v.readFileSync(h.join(n.folder,c));if(/\.(?:json|html|md|css|js|svg)$/.test(c)){let r=o.toString("utf8").replace(s,f=>i[t.indexOf(f)]);c===M&&(r=r.replace(/"version":\s*"[^"]*"/,'"version": "0.1.0"')),l[c]=r}else l[c]=o}return Object.fromEntries(Y(Object.keys(l)).map(c=>[c,l[c]]))}import m from"node:fs";import u from"node:path";import{refusal as Ae,said as k}from"../browser/shared/i18n/index.mjs";import{PACK_FILE as O,PACK_ID as he,readPackManifest as se}from"../browser/shared/pack-manifest.mjs";import{packsDirectory as me}from"../browser/shared/paths.mjs";import{DEVICE_NAMES as Pe,PACKAGE_MANIFEST as B,layoutOf as H,markerOf as Ee,packageFolders as Ne}from"../browser/shared/workspace.mjs";var ye=Object.freeze(["gallery-soft"]),_e="GALLERY_NO_PACKS",Ie=(n=process.env)=>!["","0","false",void 0].includes(n[_e]),q=2e3,ie=64*1024*1024,ge=/^[a-z0-9][a-z0-9-]*$/,A=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),$=(n,e)=>{throw Ae(e,{code:n})};function Me(n){let e=[];for(let t of m.readdirSync(n,{recursive:!0,withFileTypes:!0})){if(!t.isFile())continue;e.length>=q&&$("size",k("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",q,ie/1024/1024));let i=u.relative(n,u.join(t.parentPath,t.name)).split(u.sep).join("/");e.push({name:i,data:m.readFileSync(u.join(n,...i.split("/")))})}return e}function Ge(n,{refuse:e=()=>{}}={}){let t=[],i=0;for(let{name:r,data:f}of n){let d=String(r).replace(/\\/g,"/");if(d.endsWith("/"))continue;let y=d.split("/");(d.startsWith("/")||/^[A-Za-z]:/.test(d)||d.includes("\0")||y.some(a=>a===""||a==="."||a===".."))&&$("path",k("{0} \u6307\u5411\u5757\u5305\u5916\u9762\uFF0C\u4E0D\u80FD\u88C5",String(r))),!(y[0]==="__MACOSX"||W(y.at(-1)))&&(i+=f.length,t.push({name:d,data:f}))}(t.length>q||i>ie)&&$("size",k("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",q,ie/1024/1024));let s=t;if(!t.some(({name:r})=>r===O)){let r=new Set(t.map(({name:d})=>d.split("/")[0])),[f]=r;(r.size!==1||!t.some(({name:d})=>d===`${f}/${O}`))&&$("manifest",k("\u6700\u4E0A\u4E00\u5C42\u6CA1\u6709 pack.json\uFF1A\u5757\u5305\u662F\u4E00\u4E2A\u6587\u4EF6\u5939\uFF0C\u6700\u4E0A\u4E00\u5C42\u653E pack.json\uFF0C\u6BCF\u4E2A\u5757\u4E00\u4E2A\u6587\u4EF6\u5939")),s=t.map(({name:d,data:y})=>({name:d.slice(f.length+1),data:y}))}let l=se(s.find(({name:r})=>r===O).data.toString("utf8"));e(l);let c=new Map,o=[];for(let r of s){let[f,...d]=r.name.split("/");if(d.length===0){o.push(r);continue}c.has(f)||c.set(f,[]),c.get(f).push({name:d.join("/"),data:r.data})}for(let[r,f]of c){(!ge.test(r)||Pe.has(r))&&$("block",k("{0} \u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u540D\uFF1A\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",r));let d=f.find(a=>a.name===B);d||$("block",k("{0}/ \u91CC\u6CA1\u6709 component.json",r));let y;try{y=JSON.parse(d.data.toString("utf8").replace(/^/,"")).id}catch{$("block",k("{0}/component.json \u4E0D\u662F JSON",r))}y!==`${l.id}/${r}`&&$("block",k("{0}/component.json \u7684 id \u8981\u5199\u6210 {1}",r,`${l.id}/${r}`))}return{manifest:l,blocks:c,own:o}}function Te(n){try{let e=JSON.parse(n.find(({name:t})=>t===B).data.toString("utf8").replace(/^/,"")).version;return typeof e=="string"?e:null}catch{return null}}function Se(n){try{return m.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isFile()&&!W(e.name)).map(e=>e.name).sort()}catch{return[]}}function ve(n){let e=Se(n);return e.length?K(e.map(t=>({name:t,data:m.readFileSync(u.join(n,t))}))):null}function Ce(n){try{return m.readdirSync(n).some(e=>!W(e))}catch{return!1}}function te(n,e,{replacing:t=!1,last:i=B}={}){let s=e.map(({name:o})=>o);if(t)for(let o of G(n))s.includes(o)||m.rmSync(u.join(n,...o.split("/")),{force:!0});let l=new Map(e.map(o=>[o.name,o.data])),c=i===B?Y(s):[...s.filter(o=>o!==i),...s.includes(i)?[i]:[]];for(let o of c){let r=u.join(n,...o.split("/"));m.mkdirSync(u.dirname(r),{recursive:!0}),m.writeFileSync(r,l.get(o))}}function ze(n,e,{official:t=!1,shippedIds:i=E()}={}){let{manifest:s,blocks:l,own:c}=Ge(e,{refuse:({id:g})=>{!t&&i.includes(g)&&$("official",k("{0} \u662F Gallery \u81EA\u5E26\u7684\u5757\u5305\u7528\u7684 id\uFF1A\u6362\u4E00\u4E2A id \u518D\u88C5",g))}}),{id:o}=s,r=u.join(H(n).components,o),f=N(n),d=A(f.packs)?f.packs:{},y=A(d[o])?d[o]:null;!t&&!y&&Ce(r)&&$("taken",k("\u5DE5\u4F5C\u533A\u91CC\u5DF2\u7ECF\u6709 components/{0}\uFF1A\u8FD9\u4E2A\u540D\u5B57\u88AB\u522B\u7684\u5757\u5305\u6216\u522B\u4EBA\u5199\u7684\u5757\u7528\u7740\uFF0C\u6362\u4E00\u4E2A id\uFF0C\u6216\u5148\u628A\u90A3\u4E2A\u6587\u4EF6\u5939\u632A\u8D70",o));let a={id:o,name:s.name,version:s.version,from:y?.version??null,folder:r,added:[],updated:[],same:[],kept:[],removed:[],skipped:[],ownKept:!1},j=[...l.keys()].sort();for(let g of j){let p=`${o}/${g}`,F=l.get(g),w=u.join(r,g),J=K(F),I=P(w),L=A(f[p])?f[p]:null;if(I===null){if(t&&L){a.skipped.push(p);continue}te(w,F),a.added.push(p)}else if(I===J)a.same.push(p);else if(L&&I===L.fingerprint)te(w,F,{replacing:!0}),a.updated.push(p);else{a.kept.push(p);continue}f[p]={version:Te(F),fingerprint:J}}for(let g of Array.isArray(y?.blocks)?y.blocks:[]){let p=String(g).split("/")[1];if(!p||l.has(p)||!ge.test(p))continue;let F=u.join(r,p),w=P(F);if(w!==null&&w!==f[g]?.fingerprint){a.kept.push(g);continue}w!==null&&(m.rmSync(F,{recursive:!0,force:!0,maxRetries:5,retryDelay:100}),a.removed.push(g)),delete f[g]}let x=ve(r),b=K(c);if(x!==b)if(x===null||x===y?.fingerprint){let g=c.map(({name:p})=>p);for(let p of Se(r))g.includes(p)||m.rmSync(u.join(r,p),{force:!0});m.mkdirSync(r,{recursive:!0}),te(r,c,{last:O})}else a.ownKept=!0;let _=a.added.length+a.updated.length+a.removed.length>0||x!==b&&!a.ownKept;return a.did=y?_?"updated":"same":"installed",f.packs={...d,[o]:{version:s.version,fingerprint:a.ownKept?y.fingerprint:b,blocks:j.map(g=>`${o}/${g}`),...t?{official:!0}:{}}},z(n,f),a}function an(n,e,{shippedIds:t=E()}={}){t.includes(e)&&$("official",k("{0} \u662F Gallery \u81EA\u5E26\u7684\u5757\u5305\uFF0C\u4E0D\u80FD\u5220\u9664\uFF1A\u5728 \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 \u91CC\u628A\u5B83\u5173\u6389",e));let i=u.join(H(n).components,e);(!he.test(e)||!m.existsSync(i))&&$("missing",k("\u5DE5\u4F5C\u533A\u91CC\u6CA1\u6709\u5757\u5305 {0}",e));let s=N(n),l=A(s.packs)&&A(s.packs[e])?s.packs[e]:null;l||$("own",k("components/{0} \u4E0D\u662F\u88C5\u8FDB\u6765\u7684\u5757\u5305\uFF0C\u91CC\u9762\u7684\u5757\u662F\u6709\u4EBA\u5728\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5199\u7684\uFF1A\u8981\u5220\u5C31\u81EA\u5DF1\u5220\u6389\u8FD9\u4E2A\u6587\u4EF6\u5939",e)),m.rmSync(i,{recursive:!0,force:!0,maxRetries:5,retryDelay:100});for(let r of Object.keys(s))r.startsWith(`${e}/`)&&delete s[r];let{[e]:c,...o}=s.packs;return z(n,{...s,packs:o}),{id:e,version:l.version??null,blocks:Array.isArray(l.blocks)?l.blocks:[]}}var Ke=n=>({zh:Z("zh",n),en:Z("en",n)});function ln(n,{settings:e=null,shippedIds:t=E(),directory:i=me}={}){let{components:s}=H(n),l=N(n),c=A(l.packs)?l.packs:{},o=Ne(n),r=new Set(o.map(({id:a})=>a.split("/")[0]));try{for(let a of m.readdirSync(s))he.test(a)&&m.existsSync(u.join(s,a,O))&&r.add(a)}catch{}let f=(e??X(n)).packs??{},d=[...r].map(a=>{let j=u.join(s,a),x=null,b=null;if(m.existsSync(u.join(j,O)))try{x=se(m.readFileSync(u.join(j,O),"utf8")),x.id!==a&&(b=k("pack.json \u7684 id \u662F {0}\uFF0C\u5B83\u7684\u6587\u4EF6\u5939\u5374\u662F components/{1}",x.id,a),x=null)}catch(S){b=S}let _=A(c[a])?c[a]:null,g=o.filter(S=>S.id.startsWith(`${a}/`)),p=_?g.filter(S=>A(l[S.id])&&P(S.folder)!==l[S.id].fingerprint).map(S=>S.id):[];_&&ve(j)!==_.fingerprint&&p.push(`${a}/${O}`);let F=t.includes(a),w=null;if(F)try{w=se(m.readFileSync(u.join(i,a,O),"utf8"))}catch{}let J=S=>{try{return JSON.parse(m.readFileSync(u.join(s,...S.split("/"),B),"utf8")).version??null}catch{return null}},I=F?D(i):[],ke=F&&w&&p.some(S=>S.endsWith(`/${O}`)?R(w.version,x?.version??null):I.some(V=>V.id===S)&&R(I.find(V=>V.id===S).version,J(S)))?w.version:null,C=x??(b?null:w);return{id:a,name:C?.name??{zh:a,en:a},description:C?.description??null,version:x?.version??null,author:C?.author??null,homepage:C?.homepage??null,icon:C?.icon??null,kind:F?"official":_?"installed":"own",problem:b?Ke(b):null,blocks:g.length,enabled:f[a]!==!1,changed:p,newer:ke}}),y=({id:a,kind:j})=>j==="official"?t.indexOf(a):j==="installed"?1e3:2e3;return d.sort((a,j)=>y(a)-y(j)||(a.id<j.id?-1:1))}function De(n,e,t){let i=[],s=u.resolve(n);return t?i.push(`Gallery's pack ${e.id} ${e.version} installed in ${s} (${e.added.length+e.same.length+e.updated.length} blocks)${ye.includes(e.id)?", switched off: \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 turns it on":""}`):(e.added.length&&i.push(`Gallery's pack ${e.id} in ${s} has new blocks: ${e.added.join(", ")}`),e.updated.length&&i.push(`Gallery's pack ${e.id} in ${s}, its blocks as they were installed, updated to this Gallery's: ${e.updated.join(", ")}`),e.removed.length&&i.push(`Gallery's pack ${e.id} in ${s}: ${e.removed.join(", ")} no longer in it, taken out`)),i}async function fn(n,{directory:e=me,env:t=process.env,log:i=()=>{}}={}){if(Ie(t))return{did:"off",packs:[]};let s={ours:!1};try{s=Ee(m.readFileSync(H(n).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread",packs:[]};let l=E(e),c=[];for(let o of l)try{let r=!A(N(n).packs?.[o]);r&&ye.includes(o)&&X(n).packs[o]===void 0&&await re(n,{pack:o,enabled:!1});let f=ze(n,Me(u.join(e,o)),{official:!0,shippedIds:l});c.push({...f,first:r});for(let d of De(n,f,r))i(d)}catch(r){i(`Gallery's pack ${o} could not be installed in ${u.resolve(n)}: ${r?.message??r}`),c.push({id:o,failed:r?.message??String(r)})}return{did:"done",packs:c}}export{$e as a,Y as b,E as c,D as d,qe as e,He as f,N as g,ne as h,je as i,R as j,Ve as k,Fe as l,Xe as m,Ze as n,be as o,Me as p,ze as q,an as r,ln as s,fn as t};
@@ -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{c as G}from"./chunk-NVRNLK25.mjs";import{n as _,p as Ee,r as Le,s as Ne,t as Oe,x as je}from"./chunk-RFDZXFJF.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-QOUEFUCH.mjs";import{M as Ae}from"./chunk-VTKNEYT3.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-BPL64HGA.mjs";import{d as Ce,g as Ie}from"./chunk-6A53MZYZ.mjs";import"./chunk-UGWYKHBL.mjs";import"./chunk-OUUP3WKT.mjs";import{i as ie}from"./chunk-NFMCP2HI.mjs";import{a as D}from"./chunk-JEUK3ZO7.mjs";import"./chunk-NWFBE2YA.mjs";import{a as re,b as le,e as ce,f as K,g as de}from"./chunk-PUOQ65NC.mjs";import"./chunk-ZUNVAXLH.mjs";import"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-UKSHDZZ6.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import"./chunk-SXHBYZST.mjs";import"./chunk-N7AZZLGT.mjs";import{a as q,b as T,c as P,d as B,f as se}from"./chunk-UFNYFFKO.mjs";import{a as te,e as H,f as ae}from"./chunk-D4EURAX4.mjs";import{b as oe}from"./chunk-4OZWXZE5.mjs";import"./chunk-HMYTM3GT.mjs";import"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import{j as ne}from"./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{f as Z,j as ee}from"./chunk-FWNRPMCJ.mjs";import{b as X,e as Ge}from"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";Ge();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import j from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Be,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as C,hasClass as W,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],He=["light","dark"],Ze=900,et=3e4,tt=e=>!/^application\/(?:\S+\+)?json$/i.test((e??"").trim()),at=new Set(["iframe","frame","object","embed"]),st=/^(?:javascript|vbscript):/i,ot=/^\d+$/,nt={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function it(e,{catalog:g,folder:o,slug:h}){let l=[],s=n=>n?.sourceCodeLocation?.startLine??1,i=(n,a)=>l.push({line:typeof n=="number"?n:s(n),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),d=[],f=[];Re(t,n=>{if(n.tagName){n.tagName==="main"&&W(n,"gallery-page")&&d.push(n),W(n,"gallery-board")&&f.push(n),n.tagName==="script"&&tt(C(n,"type"))&&i(n,`a <script>${C(n,"src")?` (src="${C(n,"src")}")`:""}: a custom page runs no script of its own (the server puts in its blocks'); what a card does goes in a custom block (references/building-blocks.md)`);for(let{name:a,value:r}of n.attrs??[])/^on/i.test(a)?i(n,`<${n.tagName} ${a}="\u2026">: a custom page runs no script of its own, an on\u2026 attribute neither; what a card does goes in a custom block`):st.test(String(r).replace(/[\u0000- ]/g,""))&&i(n,`<${n.tagName} ${a}="${r.slice(0,40)}">: an address that runs script; a custom page runs none of its own`);W(n,"gallery-card")&&!W(n.parentNode,"gallery-board")&&i(n,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`)}},{inTemplates:!1}),d.length===0&&i(1,`no <main class="gallery-page">: a custom page's boards and what it shows of its own stand in one (it is how a block knows it is on a page: context.place "page")`);let b=new Map;for(let n of f){let a=n.parentNode;for(;a&&!(a.tagName==="main"&&W(a,"gallery-page"));)a=a.parentNode;d.length&&!a&&i(n,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=C(n,"data-board-id");r===void 0||r===""?i(n,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):q.test(r)?b.has(r)?i(n,`data-board-id="${r}" again (line ${b.get(r)} has it): each board's id is its own`):b.set(r,s(n)):i(n,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let v=new Map,N=new Map;for(let n of T(e).cards){let{node:a}=n,r=C(a,"data-card-id"),k=r&&q.test(r)?`card ${r}`:"this card";r===void 0||r===""?i(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):q.test(r)?v.has(r)?i(a,`data-card-id="${r}" again (line ${v.get(r)} has it): each card's id is its own, and the page's writes go by it`):v.set(r,s(a)):i(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?i(a,`${k} holds no instance of a custom block (an element with ${Be}): a card is one block's instance, gallery/static's for what only shows`):u>1?i(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):n.instance&&n.instance.parentNode!==a&&i(n.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let y={};for(let x of["x","y","w","h"]){let A=C(a,`data-${x}`),[E,L]=nt[x];A===void 0?i(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):ot.test(A.trim())?Number(A)<E||Number(A)>L?i(a,`${k}'s data-${x}="${A}": ${x} is ${L===1/0?`${E} or more`:`${E} to ${L}`}${x==="w"?" (a row is 12 cells)":""}`):y[x]=Number(A):i(a,`${k}'s data-${x}="${A}" is no whole number`)}y.x!==void 0&&y.w!==void 0&&y.x+y.w>12?i(a,`${k} reaches past the row's end: data-x ${y.x} and data-w ${y.w} make ${y.x+y.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(y).length===4&&N.set(n.board,[...N.get(n.board)??[],{id:r??null,...y,line:s(a)}]),n.block&&rt(n.block,g,x=>i(n.instance,`${k}'s block ${n.block}: ${x}`))}for(let n of N.values())for(let a=0;a<n.length;a++)for(let r=a+1;r<n.length;r++){let[k,u]=[n[a],n[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&i(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return l.push(...lt(e,{folder:o,slug:h})),l.sort((n,a)=>n.line-a.line)}function rt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let l=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):l?o(`it does not load (${ee("en",l.problem)}): gallery block check ${e} says why`):ae(e)&&H(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${H(e).pack===te?H(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function lt(e,{folder:g,slug:o}){let h=[],l=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let i=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",d=Me(i)??(i.startsWith(l)?Me(i.slice(l.length-7)):null),f=`"${i.length>60?`${i.slice(0,60)}\u2026`:i}"`,b=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(d!==null){let v=s.node.tagName==="link"&&/(?:^|\s)stylesheet(?:\s|$)/i.test(C(s.node,"rel")??"")||s.css?.kind==="import";Qe(d)?v?h.push({line:s.line,what:`${b}: a stylesheet of the page's assets/ is never applied, as the server hands out a page's own file that is no picture for saving only: put its rules in the page's <style>`}):at.has(s.node.tagName)&&!Te(d)?h.push({line:s.line,what:`${b}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture for saving only: show a picture with <img src="assets/<file>">, offer a file with a link, <a href="${d}" download>`}):Ue(j.join(g,d))||h.push({line:s.line,what:`${b}: ${d} is not in the page's folder (${D(j.join(g,"assets"))}): put the file there${Te(d)?"":", or link to it"}`}):h.push({line:s.line,what:`${b} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!i||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(i)||h.push({line:s.line,what:`${b} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function ct(e,g){let o=P(e).text,h=[];for(let l of T(o).cards){let s=l.block?g.packages.get(l.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let i=_(B(o,l),G,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=i?.text.trim()?JSON.parse(i.text):{}}catch{continue}let d=Ie(s,t);d.length&&h.push({id:l.id,block:l.block,line:l.node.sourceCodeLocation?.startLine??1,empty:d})}return h}var dt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:l,zh:s})=>`${h} (${s&&s!==l?`${l}, ${s}`:l})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,ht=(e,g=!1)=>{let o=h=>C(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${C(e.node,"data-x")},${C(e.node,"data-y")}`,Pe=e=>`${C(e.node,"data-w")},${C(e.node,"data-h")}`;function pt(e,g,o){let[h,l]=[P(e).text,P(g).text],[s,i]=[T(h).cards,T(l).cards],t=new Set([...s,...i].map(a=>a.board)).size>1,d=a=>ht(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)i.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:d(a)});for(let a of i)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:d(a)});for(let a of i){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:d(r),now:d(a)}),u&&f.resized.push({id:a.id,block:a.block,was:d(r),now:d(a)});let[y,x]=[B(h,r),B(l,a)];if(y===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,E=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[L,c]=E?[_(y,G,E),_(x,G,E)]:[null,null];if(!L||!c){f.markup.push({id:a.id,block:A?a.block:null});continue}let S=L.parts.flatMap(({name:$,text:m},O)=>m===c.parts[O].text?[]:[{name:$,...Y(m,c.parts[O].text),runs:ke(m,c.parts[O].text)}]);S.length&&f.data.push({id:a.id,block:a.block,parts:S}),L.outside!==c.outside&&f.markup.push({id:a.id,block:a.block})}let b=(a,r)=>{let k="",u=0;for(let y of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,y.start),u=y.end;return k+a.slice(u)},[v,N]=[b(h,s),b(l,i)],n=a=>a.replace(/\s+/g," ");return n(v)!==n(N)&&(f.page=Y(v.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",De="(put there by Gallery)";function ut(e,g){let o=i=>{let t=new Map;for(let d of g)if(d.by===i)for(let[f,b]of Object.entries(d.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(b)?b:[]]));return t},h=o("page"),l=o("gallery"),s=i=>t=>{let d=!!h.get(t.id)?.has(i);return{...t,user:d,...!d&&l.get(t.id)?.has(i)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function ft(e,g){let o=({id:t,block:d})=>`${t}${d?` (${d})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${De}`:"",l=[];for(let t of e.added)l.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)l.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)l.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(d=>d.id===t.id)||l.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)l.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Ee(t.parts).map(d=>` ${d}`));for(let t of e.markup)l.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&l.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),l.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(d=>d.user)),i=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(d=>d.gallery));return[`Changes since ${g}:`,...l,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...i?[` Each change marked ${De} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function wt(e,g){let{qa:o,state:h}=U(e),l=j.join(o,g,"checked.html"),s=await R.readFile(l,"utf8").catch(()=>null);if(s!==null){let{mtime:b}=await R.stat(l);return{text:s,since:`the last check that found nothing (${We(b)}, local time, ${D(l)})`,at:b.getTime()}}let i=j.join(h,"pages",g),t=(await R.readdir(i).catch(()=>[])).filter(b=>/^\d{15}-\d{4}\.html$/.test(b)).sort();if(t.length===0)return null;let d=j.join(i,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(d,"utf8"),since:`the page as it was before its last write (${We(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var We=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function gt(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let d=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),b=[...t.children].find(v=>v.matches(e));return{id:t.getAttribute("data-card-id"),block:b?.getAttribute(g)??null,out:f.width>0&&(f.left<d.left-1||f.right>d.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!b?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(v=>v.complete&&v.naturalWidth===0).map(o)}}),l=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,i=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:d,at:f})=>({kind:t,block:d,waited:Date.now()-f}));return{cards:h,broken:l,stuck:i,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function mt(e,{address:g,out:o,readers:h=new Set,wait:l=ge,limits:s={}}){let{loading:i=he,ready:t=et,answer:d=pe,closing:f=ce,looking:b=ue}=s,v=new Map,N=new Map,n=[],a=!1,r=(c,S,$,m,O=v)=>{if(a)return;let w=O.get(c)??{card:S,what:$,looks:[]};w.looks.push(m),O.set(c,w)},k="a browser context opened",u=(c,S,$=d)=>(k=S,ye(c,S,$)),y=Q.flatMap(c=>He.map(S=>({width:c,theme:S,view:`${c} ${S}`}))),x=null,A=async({width:c,theme:S,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
3
+ `)[0]}`,null,`the console says ${p.text().split(`
4
+ `)[0]}`,$)}),m.on("response",p=>{let I=new URL(p.url());p.status()>=400&&I.origin===new URL(g).origin&&I.pathname!=="/favicon.ico"&&r(`request ${I.pathname}`,null,`${I.pathname} answered ${p.status()}`,$)}),await u(be(m,{add:p=>r(`dialog ${p}`,null,`it opened a dialog (${p}), which stops a reader's page until it is answered`,$)}),"the tab was set to refuse dialogs"),await u(me(m),"the tab was set to watch the page's reads of the workspace"),await u(m.setViewport({width:c,height:Ze}),`the window went to ${c}px`),await u(m.emulateMediaFeatures([{name:"prefers-color-scheme",value:S}]),`the ${S} theme came`),await u(m.goto(g,{waitUntil:"load",timeout:0}),"the page opened",i),await u(m.waitForSelector("html[data-doc-ready][data-doc-drawn]",{timeout:0}),"the page was drawn (its html got data-doc-drawn)",t),await u(m.evaluate(()=>document.fonts?.ready.then(()=>!0)),"the page's fonts loaded");let O=await u(m.$("main"),"the page's main was found")??await u(m.$("body"),"the page's body was found");await u(O.evaluate(je,{still:fe,step:we,wait:l}),"the page held still");let w=await u(m.evaluate(gt,Ye,Be),"the page was looked at");for(let{kind:p,block:I,waited:_e}of w.stuck){let V=w.cards.filter(F=>I?F.block===I:h.has(F.block)),J=F=>`the workspace had not answered ${F} read of "${p}" ${Math.round(_e/1e3)} s after it asked, so its picture shows it before it drew what it reads, which the picture then does not tell (open the page in Gallery to see it)`;if(V.length)for(let F of V)r(`unanswered ${F.id} ${p}`,F.id,J("its"),$,N);else r(`unanswered ${p}`,null,J("a card's"),$,N)}w.wide&&r("wide",null,`the page is ${w.wide}px wide in a window ${c}px wide: something of its own reaches past the window (a width of its own, a long word), and a reader scrolls it sideways`,$);for(let p of w.broken)r(`broken ${p}`,null,`a picture that does not load: ${p}`,$);for(let p of w.cards){p.fallback&&r(`fallback ${p.id}`,p.id,`its block failed: the card shows what its instance holds, read-only${p.error?` (${p.error.slice(0,200)})`:""}`,$),p.out&&r(`out ${p.id}`,p.id,"it is drawn out of its board",$),p.tall&&r(`tall ${p.id}`,p.id,`what it holds does not fit it: ${p.tall.needs}px high in a card that shows ${p.tall.has}px, the rest scrolling inside the card (give the card more cells, data-h, or a size its block lists; a block whose content grows says card.fit "content")`,$),p.wide&&r(`wide ${p.id}`,p.id,`what it holds is wider than the card: ${p.wide.needs}px in a card ${p.wide.has}px wide`,$);for(let I of p.broken)r(`broken ${p.id} ${I}`,p.id,`a picture that does not load: ${I}`,$)}let M=j.join(o,`${c}-${S}.png`);await u(m.screenshot({path:M,fullPage:!0}),"the page was pictured"),a||n.push(M)}finally{await K(m.close(),f)}},E=c=>({problems:[...v.values()],notes:[...N.values()],pictures:n,unverified:null,stuck:!1,...c}),L=null;try{x=await u(e.createBrowserContext(),"a browser context opened");for(let c of y)L=c,await $t(A(c),b,()=>k);return E({})}catch(c){return await Se(e)?E({unverified:`the browser went while it looked (${z(c)})`}):c.stuck?(r("stopped",null,kt(c,y.indexOf(L??y[0])<y.length-1),(L??y[0]).view),E({stuck:!0})):E({unverified:`the look stopped: ${z(c)}`})}finally{a=!0,await K(x?.close(),f)}}function $t(e,g,o){let h=0,l=new Promise((s,i)=>{h=setTimeout(()=>i(Object.assign(new Error(o()),{stuck:!0,doing:o(),limit:g,whole:!0})),g)});return Promise.race([e,l]).finally(()=>clearTimeout(h))}function kt(e,g){return`${e.whole?`the look was not done in ${xe(e.limit)}, waiting until ${e.doing}`:ve(e)}; the look stopped here and the browser was closed${g?", so the looks after it were not made":""}. A script of the page that never ends does this, and so may a browser that stalled: run the check once more, and if it stops at the same place again, the page holds it up`}function qe(e){let g=[...new Set(e.map(l=>l.split(" ")[0]))],o=[...new Set(e.map(l=>l.split(" ")[1]))],h=l=>l.length<2?l.join(""):`${l.slice(0,-1).join(", ")} and ${l.at(-1)}`;return`at ${h(g)}px${o.length===He.length?"":`, ${h(o)}`}`}async function _t(e,g){if(g.length!==1)throw new oe("gallery page check takes one page's slug.");let[o]=g,h=Xe(o,e);Je(o,e)||(console.error(await Ce(o,e)),process.exit(1));let l=new Date,s=await R.readFile(h.html,"utf8"),i=j.basename(h.html),t=Z(e),{boards:d,cards:f}=T(s);console.log(`${o}: ${D(h.html)}, ${d.length} board${d.length===1?"":"s"} and ${f.length} card${f.length===1?"":"s"}`);let b=[],v=it(s,{catalog:t,folder:h.folder,slug:o});for(let{line:c,what:S}of v)b.push(` FAIL ${i}:${c}: ${S}`);console.log(v.length?`Structure: ${v.length} problem${v.length===1?"":"s"}`:"Structure: as a custom page is written (no script of its own, every board's and card's id once, one instance a card, the cells on the board and none shared, every block one a page runs, every file of assets/ there)");for(let c of b)console.log(c);for(let c of T(P(s).text).cards)console.log(` ${c.id} ${c.block??"(no instance)"} x ${c.x}, y ${c.y}, ${c.w} \xD7 ${c.h}${d.length>1?` on ${c.board}`:""} ${i}:${c.node.sourceCodeLocation?.startLine}`);let N=ct(s,t);for(let c of N)console.log(` note ${i}:${c.line}: ${dt(c)}`);let n=await wt(e,o),a=n?await se(U(e).state,o,n.at):[];console.log((n?ft(ut(pt(n.text,s,t),a),n.since):["No earlier version to tell changes against: the next check that finds nothing keeps this one, and says what changed since."]).join(`
5
+ `));let r=new Map(T(P(s).text).cards.map(c=>[c.id,c.node.sourceCodeLocation?.startLine??1])),k=(c,S=null,$=0)=>{if(c)return{line:`FAIL ${o}: ${c} problem${c===1?"":"s"}`,code:1};if(S)return{line:`UNVERIFIED ${o}: ${S}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:O,empty:w})=>`${O} (${w.map(({key:M})=>M).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),y=async(c,S,$=0)=>{let{line:m,code:O}=k(c,S,$);if(console.log(m),O===0){let w=j.join(U(e).qa,o,"checked.html");await R.mkdir(j.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,l,l)}process.exitCode=O};if(!u.ok)return y(v.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return y(v.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Oe(e);let A=await Le(e,{directory:h.folder,files:h,text:s}),E=j.join(U(e).qa,o,"check"),L=null;try{let{pageAloneOf:c}=await import("./chunk-2NRBY6AJ.mjs"),S=c(u.port,A.slug);console.log(`Looked at: ${S} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${i}), at ${Q.join(", ")}px, light and dark`);try{L=await de({executablePath:x,args:le()})}catch(w){return y(v.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(E,{recursive:!0,force:!0}),await R.mkdir(E,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await mt(L.browser,{address:S,out:E,readers:$});m.stuck&&(await L.close(),L=null);for(let{card:w,what:M,looks:p}of m.problems)console.log(` FAIL ${i}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${M} (${qe(p)})`);let O=new Map(T(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:M,looks:p}of m.notes)console.log(` note ${i}:${w?r.get(w)??1:1}: ${w?`card ${w}${O.get(w)?` (${O.get(w)})`:""}: `:""}${M} (${qe(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${D(E)}: ${m.pictures.map(w=>j.basename(w)).join(", ")}`),console.log(Ae([{folder:j.dirname(E),files:m.pictures}]))),y(v.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await L?.close(),await Ne(e,A.slug)}}export{De as GALLERYS_MARK,Q as LOOK_WIDTHS,He as THEMES,ze as USERS_MARK,wt as baselineOf,ft as changesSaid,ct as emptyRequired,dt as emptyRequiredSaid,mt as look,ut as markedTheUsers,pt as pageChanges,_t as pageCheckCommand,it as structureProblems};
@@ -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 D from"node:fs/promises";import R from"node:path";import{writeAtomic as Y}from"../browser/shared/files.mjs";var I=371,S=1,j=["reader","agent"],T=/^\d{4}-\d{2}-\d{2}$/,$=d=>String(d).padStart(2,"0");function k(d){let s=new Date(d);return`${s.getFullYear()}-${$(s.getMonth()+1)}-${$(s.getDate())}`}function x(d,s){let[h,e,w]=d.split("-").map(Number);return k(new Date(h,e-1,w+s,12))}function F(d){let s;try{s=JSON.parse(d)}catch{return null}let h=r=>r!==null&&typeof r=="object"&&!Array.isArray(r);if(!h(s)||s.version!==S||!T.test(s.since??"")||!h(s.days)||!h(s.seen))return null;let e={};for(let[r,t]of Object.entries(s.days))if(!(!T.test(r)||!h(t)))for(let[g,p]of Object.entries(t))for(let b of j){let l=p?.[b];Array.isArray(l)&&l.length===2&&l.every(Number.isInteger)&&l[0]>0&&(((e[r]??={})[g]??={})[b]=[l[0],l[1]])}let w={};for(let[r,t]of Object.entries(s.seen))h(t)&&Number.isFinite(t.mtime)&&typeof t.hash=="string"&&Number.isInteger(t.words)&&(w[r]={mtime:t.mtime,hash:t.hash,words:t.words});return{version:S,since:s.since,days:e,seen:w}}function V({file:d,now:s=()=>new Date,wait:h=1e3}){let e=null,w=null,r=!1,t=null,g=Promise.resolve(),p=()=>k(s());function b(){return w??=D.readFile(d,"utf8").then(F,()=>null).then(n=>(e=n??{version:S,since:p(),days:{},seen:{},fresh:!0},n||(r=!0),e)),w}function l(){r=!0,!t&&(t=setTimeout(()=>{t=null,A()},h),t.unref?.())}function E(){let n=x(p(),-(I-1));for(let i of Object.keys(e.days))i<n&&delete e.days[i];let{version:a,since:c,days:u,seen:f}=e;return`${JSON.stringify({version:a,since:c<n?n:c,days:u,seen:f})}
3
+ `}function A(){if(!e||!r)return g;r=!1,clearTimeout(t),t=null;let n=E();return g=g.then(async()=>{await D.mkdir(R.dirname(d),{recursive:!0}),await Y(d,n)}).catch(()=>{}),g}function N(n,a,c,u){let f=((e.days[a]??={})[n]??={})[j.includes(c)?c:"agent"]??=[0,0];f[0]+=1,f[1]+=u}return{load:b,get since(){return e?.since??p()},record(n,{hash:a,words:c,mtime:u,by:f}){if(!e)return!1;let i=e.seen[n];return e.seen[n]={mtime:u,hash:a,words:c},i?.hash===a?(i.mtime!==u&&l(),!1):(N(n,p(),f,c-(i?.words??0)),l(),!0)},async catchUp(n,a,{kept:c=[]}={}){await b();let u=e.fresh===!0;delete e.fresh;let f=0;for(let{slug:o,mtime:O}of n){let m=e.seen[o];if(m&&m.mtime===O)continue;let y=await a(o).catch(()=>null);if(!y||(e.seen[o]={mtime:y.edited,hash:y.hash,words:y.words},r=!0,u||m?.hash===y.hash))continue;let v=k(y.edited);N(o,v<e.since?e.since:v,"agent",y.words-(m?.words??0)),f+=1}let i=new Set([...n.map(({slug:o})=>o),...c]);for(let o of Object.keys(e.seen))i.has(o)||(delete e.seen[o],r=!0);return r&&l(),f},days(n=365){let a=p(),c=e?.since??a,u=x(a,-(Math.max(1,Math.min(I,n))-1));u<c&&(u=c);let f=[];for(let i=u;i<=a;i=x(i,1)){let o={date:i,edits:0,words:0,reader:{edits:0,words:0},agent:{edits:0,words:0}};for(let O of Object.values(e?.days[i]??{}))for(let m of j){let[y,v]=O[m]??[0,0];o[m].edits+=y,o[m].words+=v,o.edits+=y,o.words+=v}f.push(o)}return f},flush:A,async close(){clearTimeout(t),t=null,await A()}}}export{V as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as n,f as i}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as r}from"../browser/shared/paths.mjs";import{answerOf as a,readAnnouncement as d,stopServer as l}from"../browser/shared/preview-server.mjs";async function m(p){let{positional:s}=i({argv:p});if(s.length>0)throw new n(`gallery stop takes no arguments: ${s[0]}`);let o=await d({reportsDirectory:r}),t=o?await a(o,r,1e4):"no";if(t==="no")return void console.log(`No Gallery server runs for ${r}.`);t==="busy"&&(console.error(`The Gallery server on port ${o.port} (pid ${o.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${o.pid} yourself.`),process.exit(1)),o.kind==="dev"&&(console.error(`This workspace's server is npm run dev's (port ${o.port}, pid ${o.pid}): stop it where it runs.`),process.exit(1));let e=await l(o);e.ok||(console.error(e.message),process.exit(1)),console.log(`Stopped the server on port ${o.port} (pid ${o.pid})${e.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{m as run};
2
+ import{b as n,f as i}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as r}from"../browser/shared/paths.mjs";import{answerOf as a,readAnnouncement as d,stopServer as l}from"../browser/shared/preview-server.mjs";async function m(p){let{positional:s}=i({argv:p});if(s.length>0)throw new n(`gallery stop takes no arguments: ${s[0]}`);let o=await d({reportsDirectory:r}),t=o?await a(o,r,1e4):"no";if(t==="no")return void console.log(`No Gallery server runs for ${r}.`);t==="busy"&&(console.error(`The Gallery server on port ${o.port} (pid ${o.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${o.pid} yourself.`),process.exit(1)),o.kind==="dev"&&(console.error(`This workspace's server is npm run dev's (port ${o.port}, pid ${o.pid}): stop it where it runs.`),process.exit(1));let e=await l(o);e.ok||(console.error(e.message),process.exit(1)),console.log(`Stopped the server on port ${o.port} (pid ${o.pid})${e.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{m as run};
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as Ce}from"./chunk-MAFIGVXY.mjs";import{a as x,e as De,f as Pe,i as ve,l as Oe,m as _e,n as Be,o as Se,p as Fe,r as Te,u as Ie,v as Re}from"./chunk-742D2WWJ.mjs";import{$ as zr,$a as $t,$b as ks,A as K,Aa as wt,Ab as ls,Ac as li,B as _,Ba as gt,Bb as fs,Bc as fi,Ca as bt,Cb as ps,Cc as pi,Da as Et,Db as ds,Dc as di,E as _r,Ea as xt,Eb as hs,Ec as hi,F as we,Fa as yt,Fb as ms,Fc as mi,G as Br,Ga as Dt,Gb as ws,Gc as wi,H as Sr,Ha as Pt,Hb as gs,Hc as gi,I as Fr,Ia as vt,Ib as bs,Ic as bi,J as Tr,Ja as Ot,Jb as Es,Jc as Ei,K as Ir,Ka as _t,Kb as xs,Kc as xi,L as Rr,Lb as Q,Lc as yi,M as ge,Mb as ys,Mc as Di,N as Cr,Nb as Ds,Nc as Pi,O as Ar,Oa as J,Ob as Ps,Oc as vi,P as Lr,Pb as vs,Pc as Oi,Q as kr,Qa as Bt,Qb as Os,Qc as _i,R as Wr,Ra as St,Rb as _s,Rc as Bi,S as $r,Sa as Ft,Sb as Bs,Sc as ye,T as Ur,Ta as Tt,Tb as Ss,Tc as Si,U as Nr,Ua as It,Ub as Fs,Uc as Fi,V as Mr,Va as Rt,Vb as Ts,Vc as Ti,W as Gr,Wa as Ct,Wb as Is,Wc as Ri,X as Vr,Xa as At,Xb as Rs,Xc as Ae,Y as jr,Ya as Lt,Yb as Cs,Yc as Le,Z as Xr,Za as kt,Zb as As,Zc as Ci,_ as Hr,_a as Wt,_b as Ls,_c as q,a as k,aa as Yr,ab as Ut,ac as Ws,ba as Kr,bb as Nt,bc as $s,c as oe,ca as Jr,cb as Mt,cc as Us,d as ae,da as Qr,db as Gt,dc as Ns,e as W,ea as be,eb as Vt,ec as Ms,fa as Zr,fb as jt,fc as Gs,ga as qr,gb as Xt,gc as Vs,h as ne,ha as et,hb as Ht,hc as js,i as ce,ia as rt,ib as zt,ic as Xs,j as ue,ja as tt,jb as Yt,jc as Hs,k as le,ka as st,kb as Kt,kc as zs,l as fe,la as it,lb as xe,lc as Ys,m as pe,ma as Ee,mb as Jt,mc as Ks,na as ot,nb as Qt,nc as Js,oa as at,ob as Zt,oc as Qs,pa as nt,pb as qt,pc as Zs,qa as ct,qb as es,qc as qs,r as de,ra as ut,rb as rs,rc as ei,s as he,sa as lt,sb as ts,sc as ri,t as yr,ta as ft,tb as ss,tc as ti,u as Y,ua as pt,ub as is,uc as si,v as Dr,vb as os,vc as ii,w as me,wb as as,wc as oi,x as Pr,xa as dt,xb as ns,xc as ai,y as vr,ya as ht,yb as cs,yc as ci,z as Or,za as mt,zb as us,zc as ui}from"./chunk-EUX7IC5J.mjs";import{a as ni}from"./chunk-UH4SIXTR.mjs";import{a as Ii}from"./chunk-Y34NR5JL.mjs";import{b as Z}from"./chunk-U3SSPL4K.mjs";import"./chunk-YEY3RSFQ.mjs";import{b as P,c as g,d as I}from"./chunk-W7XHE4CT.mjs";import"./chunk-5L7RYZCL.mjs";import p from"node:fs";import je from"node:path";import{debuglog as Xe}from"node:util";var He=p.constants.O_RDONLY|p.constants.O_NOFOLLOW,ee=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_TRUNC|p.constants.O_NOFOLLOW,ze=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_EXCL|p.constants.O_NOFOLLOW,Ye=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_EXCL,G=384;async function Ke(a,e){return!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.readFile(a,{encoding:e,flag:He}):await p.promises.readFile(a,{encoding:e})}P.value={path:je,debuglog:P.value.debuglog??Xe,ScreenRecorder:P.value.ScreenRecorder,followSymlinks:!0,readFile:Ke,writeFile:async(a,e)=>{!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.writeFile(a,e,{flag:ee,mode:G}):await p.promises.writeFile(a,e)},openFileForWriting:async a=>!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.open(a,ee,G):await p.promises.open(a,"w+"),createWriteStream:(a,e)=>{let r=e?.encoding,t=e?.overwrite??!0;if(!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0){let s=t?ee:ze,c=p.openSync(a,s,G);return p.createWriteStream("",{fd:c,mode:G,encoding:r})}if(!t){let s=p.openSync(a,Ye);return p.createWriteStream("",{fd:s,encoding:r})}return p.createWriteStream(a,r?{encoding:r}:void 0)},mkdir:async(a,e)=>{await p.promises.mkdir(a,e)}};import{mkdtemp as or}from"node:fs/promises";import ar from"node:os";import te from"node:path";import{accessSync as Je,constants as Qe,existsSync as $,rmSync as Ze}from"node:fs";import{tmpdir as qe}from"node:os";import{join as ke}from"node:path";var V=class{#e;#r=new me;#t;#i=!1;#s=[];onclose;onmessage;constructor(e,r,t){this.#e=e,this.#t=t;let s=this.#r.use(new K(r,t));s.on("data",o=>this.#o(o)),s.on("close",()=>{this.onclose&&this.onclose.call(null)}),s.on("error",o=>{this.#t?.(g.error)?.(o)}),this.#r.use(new K(e)).on("error",o=>{this.#t?.(g.error)?.(o)})}send(e){_(!this.#i,"`PipeTransport` is closed."),this.#e.write(e),this.#e.write("\0")}#o(e){if(_(!this.#i,"`PipeTransport` is closed."),this.#s.push(e),e.indexOf("\0")===-1)return;let r=Buffer.concat(this.#s),t=0,s=r.indexOf("\0");for(;s!==-1;){let c=r.toString(void 0,t,s);setImmediate(()=>{this.onmessage&&this.onmessage.call(null,c)}),t=s+1,s=r.indexOf("\0",t)}t>=r.length?this.#s=[]:this.#s=[r.subarray(t)]}close(){this.#i=!0,this.#r.dispose()}};function er(a){try{return Je(a,Qe.W_OK),!0}catch{return!$(a)}}function rr(a){switch(a){case x.FIREFOX:case x.CHROME:return a.charAt(0).toUpperCase()+a.slice(1);default:return a}}var R=class{#e;#r;puppeteer;constructor(e,r,t){this.puppeteer=e,this.#e=r,this.#r=t}get logger(){return this.#r}get browser(){return this.#e}async launch(e={}){e.logger??=this.#r;let{dumpio:r=!1,enableExtensions:t=!1,extensionsEnabledInIncognito:s=[],env:c=process.env,handleSIGINT:o=!0,handleSIGTERM:n=!0,handleSIGHUP:i=!0,acceptInsecureCerts:u=!1,networkEnabled:d=!0,issuesEnabled:f=!0,defaultViewport:h=ge,downloadBehavior:l,slowMo:b=0,timeout:E=3e4,waitForInitialPage:y=!0,protocolTimeout:D,handleDevToolsAsPage:U,idGenerator:C=xe(),blocklist:A,allowlist:B}=e,{protocol:v}=e;if(this.#e==="firefox"&&v===void 0&&(v="webDriverBiDi"),Ae({allowlist:B,blocklist:A,protocol:v}),this.#e==="firefox"&&v==="cdp")throw new Error("Connecting to Firefox using CDP is no longer supported");let m=await this.computeLaunchArguments({...e,protocol:v});if(!$(m.executablePath))throw m.isTempUserDataDir&&await this.cleanUserDataDir(m.userDataDir,{isTemp:!0}),new Error(`Browser was not found at the configured executablePath (${m.executablePath})`);let T=m.args.includes("--remote-debugging-pipe"),N=async()=>{try{await this.cleanUserDataDir(m.userDataDir,{isTemp:m.isTempUserDataDir})}finally{w?.()}};if(this.#e==="firefox"&&v==="webDriverBiDi"&&T)throw new Error("Pipe connections are not supported with Firefox and WebDriver BiDi");let w,O;try{O=Be({executablePath:m.executablePath,args:m.args,handleSIGHUP:i,handleSIGTERM:n,handleSIGINT:o,dumpio:r,env:c,pipe:T,onExit:N,signal:e.signal,logger:e.logger}),w=m.isTempUserDataDir?tr(m.userDataDir,this.#r):void 0}catch(F){throw w?.(),await this.cleanUserDataDir(m.userDataDir,{isTemp:m.isTempUserDataDir}),F}let S,L,se=!1,M=async()=>{se||(se=!0,await this.closeBrowser(O,L))};try{this.#e==="firefox"?S=await this.createBiDiBrowser(O,M,{timeout:E,protocolTimeout:D,slowMo:b,defaultViewport:h,acceptInsecureCerts:u,networkEnabled:d,idGenerator:C,logger:e.logger}):(T?L=await this.createCdpPipeConnection(O,{timeout:E,protocolTimeout:D,slowMo:b,idGenerator:C,logger:e.logger}):L=await this.createCdpSocketConnection(O,{timeout:E,protocolTimeout:D,slowMo:b,idGenerator:C,logger:e.logger}),v==="webDriverBiDi"?S=await this.createBiDiOverCdpBrowser(O,L,M,{defaultViewport:h,acceptInsecureCerts:u,networkEnabled:d,issuesEnabled:f,logger:e.logger}):S=await ye._create(L,[],u,h,l,O.nodeProcess,M,e.targetFilter,void 0,void 0,d,f,U,A,B,e.logger))}catch(F){M();let ie=O.getRecentLogs().join(`
3
- `);throw ie.includes("Failed to create a ProcessSingleton for your profile directory")||process.platform==="win32"&&$(ke(m.userDataDir,"lockfile"))?er(m.userDataDir)?new Error(`The browser is already running for ${m.userDataDir}. Use a different \`userDataDir\` or stop the running browser first.`):new Error(`The browser cannot write to ${m.userDataDir}. Make the \`userDataDir\` writable or use a different one.`):ie.includes("Missing X server")&&e.headless===!1?new Error("Missing X server to start the headful browser. Either set headless to true or use xvfb-run to run your Puppeteer script."):F instanceof Te?new we(F.message):F}return Array.isArray(t)&&await Promise.all([t.map(F=>S.installExtension(F,{enabledInIncognito:s.includes(F)}))]),y&&await this.waitForPageTarget(S,E),S}async closeBrowser(e,r){if(r)try{await r.closeBrowser(),await e.hasClosed()}catch(t){this.#r?.(g.error)?.(t),await e.close()}else await ae(le(k(e.hasClosed()),ce(5e3).pipe(W(()=>k(e.close())))))}async waitForPageTarget(e,r){try{await e.waitForTarget(t=>t.type()==="page",{timeout:r})}catch(t){throw await e.close(),t}}async createCdpSocketConnection(e,r){let t=await e.waitForLineOutput(Se,r.timeout),s=await Z.create(t,void 0,r.logger,r.wsOptions);return new Q(t,s,r.slowMo,r.protocolTimeout,!1,r.idGenerator,r.logger)}async createCdpPipeConnection(e,r){let{3:t,4:s}=e.nodeProcess.stdio,c=new V(t,s,r.logger);return new Q("",c,r.slowMo,r.protocolTimeout,!1,r.idGenerator,r.logger)}async createBiDiOverCdpBrowser(e,r,t,s){let c=process.env.PUPPETEER_WEBDRIVER_BIDI_ONLY==="true",o=await import("./chunk-UXUK4PMC.mjs"),n=await o.connectBidiOverCdp(r,s.logger);return await o.BidiBrowser.create({connection:n,cdpConnection:c?void 0:r,closeCallback:t,process:e.nodeProcess,defaultViewport:s.defaultViewport,acceptInsecureCerts:s.acceptInsecureCerts,networkEnabled:s.networkEnabled,issuesEnabled:s.issuesEnabled,logger:s.logger})}async createBiDiBrowser(e,r,t){let s=await e.waitForLineOutput(Fe,t.timeout)+"/session",c=await Z.create(s,void 0,t.logger,t.wsOptions),o=await import("./chunk-UXUK4PMC.mjs"),n=new o.BidiConnection(s,c,t.idGenerator,t.slowMo,t.protocolTimeout,t.logger);return await o.BidiBrowser.create({connection:n,closeCallback:r,process:e.nodeProcess,defaultViewport:t.defaultViewport,acceptInsecureCerts:t.acceptInsecureCerts,networkEnabled:t.networkEnabled??!0,issuesEnabled:t.issuesEnabled??!0,logger:t.logger})}async getProfilePath(){let e=await this.puppeteer.configuration();return ke(e.temporaryDirectory??qe(),`puppeteer_dev_${this.browser}_profile-`)}async resolveExecutablePath(e,r=!0){let t=await this.puppeteer.configuration(),s=t.executablePath;if(s){if(r&&!$(s))throw new Error(`Tried to find the browser at the configured path (${s}), but no executable was found.`);return s}function c(u,d){switch(u){case"chrome":return d==="shell"?x.CHROMEHEADLESSSHELL:x.CHROME;case"firefox":return x.FIREFOX}return x.CHROME}let o=c(this.browser,e),n=await this.puppeteer.defaultDownloadPath(),i=await this.puppeteer.browserVersion();if(s=Oe({cacheDir:n,browser:o,buildId:i}),r&&!$(s)){let u=t?.[this.browser]?.version;throw u?new Error(`Tried to find the browser at the configured path (${s}) for version ${u}, but no executable was found.`):new Error(`Could not find ${rr(o)} (ver. ${i}). This can occur if either
2
+ import{$ as zr,$a as $t,$b as ks,A as K,Aa as wt,Ab as ls,Ac as li,B as _,Ba as gt,Bb as fs,Bc as fi,Ca as bt,Cb as ps,Cc as pi,Da as Et,Db as ds,Dc as di,E as _r,Ea as xt,Eb as hs,Ec as hi,F as we,Fa as yt,Fb as ms,Fc as mi,G as Br,Ga as Dt,Gb as ws,Gc as wi,H as Sr,Ha as Pt,Hb as gs,Hc as gi,I as Fr,Ia as vt,Ib as bs,Ic as bi,J as Tr,Ja as Ot,Jb as Es,Jc as Ei,K as Ir,Ka as _t,Kb as xs,Kc as xi,L as Rr,Lb as Q,Lc as yi,M as ge,Mb as ys,Mc as Di,N as Cr,Nb as Ds,Nc as Pi,O as Ar,Oa as J,Ob as Ps,Oc as vi,P as Lr,Pb as vs,Pc as Oi,Q as kr,Qa as Bt,Qb as Os,Qc as _i,R as Wr,Ra as St,Rb as _s,Rc as Bi,S as $r,Sa as Ft,Sb as Bs,Sc as ye,T as Ur,Ta as Tt,Tb as Ss,Tc as Si,U as Nr,Ua as It,Ub as Fs,Uc as Fi,V as Mr,Va as Rt,Vb as Ts,Vc as Ti,W as Gr,Wa as Ct,Wb as Is,Wc as Ri,X as Vr,Xa as At,Xb as Rs,Xc as Ae,Y as jr,Ya as Lt,Yb as Cs,Yc as Le,Z as Xr,Za as kt,Zb as As,Zc as Ci,_ as Hr,_a as Wt,_b as Ls,_c as q,a as k,aa as Yr,ab as Ut,ac as Ws,ba as Kr,bb as Nt,bc as $s,c as oe,ca as Jr,cb as Mt,cc as Us,d as ae,da as Qr,db as Gt,dc as Ns,e as W,ea as be,eb as Vt,ec as Ms,fa as Zr,fb as jt,fc as Gs,ga as qr,gb as Xt,gc as Vs,h as ne,ha as et,hb as Ht,hc as js,i as ce,ia as rt,ib as zt,ic as Xs,j as ue,ja as tt,jb as Yt,jc as Hs,k as le,ka as st,kb as Kt,kc as zs,l as fe,la as it,lb as xe,lc as Ys,m as pe,ma as Ee,mb as Jt,mc as Ks,na as ot,nb as Qt,nc as Js,oa as at,ob as Zt,oc as Qs,pa as nt,pb as qt,pc as Zs,qa as ct,qb as es,qc as qs,r as de,ra as ut,rb as rs,rc as ei,s as he,sa as lt,sb as ts,sc as ri,t as yr,ta as ft,tb as ss,tc as ti,u as Y,ua as pt,ub as is,uc as si,v as Dr,vb as os,vc as ii,w as me,wb as as,wc as oi,x as Pr,xa as dt,xb as ns,xc as ai,y as vr,ya as ht,yb as cs,yc as ci,z as Or,za as mt,zb as us,zc as ui}from"./chunk-SQ6Y2ZMA.mjs";import{a as Ii}from"./chunk-Y34NR5JL.mjs";import{b as Z}from"./chunk-U3SSPL4K.mjs";import"./chunk-YEY3RSFQ.mjs";import{b as P,c as g,d as I}from"./chunk-W7XHE4CT.mjs";import{a as Ce}from"./chunk-MAFIGVXY.mjs";import{a as x,e as De,f as Pe,i as ve,l as Oe,m as _e,n as Be,o as Se,p as Fe,r as Te,u as Ie,v as Re}from"./chunk-742D2WWJ.mjs";import{a as ni}from"./chunk-UH4SIXTR.mjs";import"./chunk-5L7RYZCL.mjs";import p from"node:fs";import je from"node:path";import{debuglog as Xe}from"node:util";var He=p.constants.O_RDONLY|p.constants.O_NOFOLLOW,ee=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_TRUNC|p.constants.O_NOFOLLOW,ze=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_EXCL|p.constants.O_NOFOLLOW,Ye=p.constants.O_WRONLY|p.constants.O_CREAT|p.constants.O_EXCL,G=384;async function Ke(a,e){return!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.readFile(a,{encoding:e,flag:He}):await p.promises.readFile(a,{encoding:e})}P.value={path:je,debuglog:P.value.debuglog??Xe,ScreenRecorder:P.value.ScreenRecorder,followSymlinks:!0,readFile:Ke,writeFile:async(a,e)=>{!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.writeFile(a,e,{flag:ee,mode:G}):await p.promises.writeFile(a,e)},openFileForWriting:async a=>!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0?await p.promises.open(a,ee,G):await p.promises.open(a,"w+"),createWriteStream:(a,e)=>{let r=e?.encoding,t=e?.overwrite??!0;if(!P.value.followSymlinks&&p.constants.O_NOFOLLOW!==void 0){let s=t?ee:ze,c=p.openSync(a,s,G);return p.createWriteStream("",{fd:c,mode:G,encoding:r})}if(!t){let s=p.openSync(a,Ye);return p.createWriteStream("",{fd:s,encoding:r})}return p.createWriteStream(a,r?{encoding:r}:void 0)},mkdir:async(a,e)=>{await p.promises.mkdir(a,e)}};import{mkdtemp as or}from"node:fs/promises";import ar from"node:os";import te from"node:path";import{accessSync as Je,constants as Qe,existsSync as $,rmSync as Ze}from"node:fs";import{tmpdir as qe}from"node:os";import{join as ke}from"node:path";var V=class{#e;#r=new me;#t;#i=!1;#s=[];onclose;onmessage;constructor(e,r,t){this.#e=e,this.#t=t;let s=this.#r.use(new K(r,t));s.on("data",o=>this.#o(o)),s.on("close",()=>{this.onclose&&this.onclose.call(null)}),s.on("error",o=>{this.#t?.(g.error)?.(o)}),this.#r.use(new K(e)).on("error",o=>{this.#t?.(g.error)?.(o)})}send(e){_(!this.#i,"`PipeTransport` is closed."),this.#e.write(e),this.#e.write("\0")}#o(e){if(_(!this.#i,"`PipeTransport` is closed."),this.#s.push(e),e.indexOf("\0")===-1)return;let r=Buffer.concat(this.#s),t=0,s=r.indexOf("\0");for(;s!==-1;){let c=r.toString(void 0,t,s);setImmediate(()=>{this.onmessage&&this.onmessage.call(null,c)}),t=s+1,s=r.indexOf("\0",t)}t>=r.length?this.#s=[]:this.#s=[r.subarray(t)]}close(){this.#i=!0,this.#r.dispose()}};function er(a){try{return Je(a,Qe.W_OK),!0}catch{return!$(a)}}function rr(a){switch(a){case x.FIREFOX:case x.CHROME:return a.charAt(0).toUpperCase()+a.slice(1);default:return a}}var R=class{#e;#r;puppeteer;constructor(e,r,t){this.puppeteer=e,this.#e=r,this.#r=t}get logger(){return this.#r}get browser(){return this.#e}async launch(e={}){e.logger??=this.#r;let{dumpio:r=!1,enableExtensions:t=!1,extensionsEnabledInIncognito:s=[],env:c=process.env,handleSIGINT:o=!0,handleSIGTERM:n=!0,handleSIGHUP:i=!0,acceptInsecureCerts:u=!1,networkEnabled:d=!0,issuesEnabled:f=!0,defaultViewport:h=ge,downloadBehavior:l,slowMo:b=0,timeout:E=3e4,waitForInitialPage:y=!0,protocolTimeout:D,handleDevToolsAsPage:U,idGenerator:C=xe(),blocklist:A,allowlist:B}=e,{protocol:v}=e;if(this.#e==="firefox"&&v===void 0&&(v="webDriverBiDi"),Ae({allowlist:B,blocklist:A,protocol:v}),this.#e==="firefox"&&v==="cdp")throw new Error("Connecting to Firefox using CDP is no longer supported");let m=await this.computeLaunchArguments({...e,protocol:v});if(!$(m.executablePath))throw m.isTempUserDataDir&&await this.cleanUserDataDir(m.userDataDir,{isTemp:!0}),new Error(`Browser was not found at the configured executablePath (${m.executablePath})`);let T=m.args.includes("--remote-debugging-pipe"),N=async()=>{try{await this.cleanUserDataDir(m.userDataDir,{isTemp:m.isTempUserDataDir})}finally{w?.()}};if(this.#e==="firefox"&&v==="webDriverBiDi"&&T)throw new Error("Pipe connections are not supported with Firefox and WebDriver BiDi");let w,O;try{O=Be({executablePath:m.executablePath,args:m.args,handleSIGHUP:i,handleSIGTERM:n,handleSIGINT:o,dumpio:r,env:c,pipe:T,onExit:N,signal:e.signal,logger:e.logger}),w=m.isTempUserDataDir?tr(m.userDataDir,this.#r):void 0}catch(F){throw w?.(),await this.cleanUserDataDir(m.userDataDir,{isTemp:m.isTempUserDataDir}),F}let S,L,se=!1,M=async()=>{se||(se=!0,await this.closeBrowser(O,L))};try{this.#e==="firefox"?S=await this.createBiDiBrowser(O,M,{timeout:E,protocolTimeout:D,slowMo:b,defaultViewport:h,acceptInsecureCerts:u,networkEnabled:d,idGenerator:C,logger:e.logger}):(T?L=await this.createCdpPipeConnection(O,{timeout:E,protocolTimeout:D,slowMo:b,idGenerator:C,logger:e.logger}):L=await this.createCdpSocketConnection(O,{timeout:E,protocolTimeout:D,slowMo:b,idGenerator:C,logger:e.logger}),v==="webDriverBiDi"?S=await this.createBiDiOverCdpBrowser(O,L,M,{defaultViewport:h,acceptInsecureCerts:u,networkEnabled:d,issuesEnabled:f,logger:e.logger}):S=await ye._create(L,[],u,h,l,O.nodeProcess,M,e.targetFilter,void 0,void 0,d,f,U,A,B,e.logger))}catch(F){M();let ie=O.getRecentLogs().join(`
3
+ `);throw ie.includes("Failed to create a ProcessSingleton for your profile directory")||process.platform==="win32"&&$(ke(m.userDataDir,"lockfile"))?er(m.userDataDir)?new Error(`The browser is already running for ${m.userDataDir}. Use a different \`userDataDir\` or stop the running browser first.`):new Error(`The browser cannot write to ${m.userDataDir}. Make the \`userDataDir\` writable or use a different one.`):ie.includes("Missing X server")&&e.headless===!1?new Error("Missing X server to start the headful browser. Either set headless to true or use xvfb-run to run your Puppeteer script."):F instanceof Te?new we(F.message):F}return Array.isArray(t)&&await Promise.all([t.map(F=>S.installExtension(F,{enabledInIncognito:s.includes(F)}))]),y&&await this.waitForPageTarget(S,E),S}async closeBrowser(e,r){if(r)try{await r.closeBrowser(),await e.hasClosed()}catch(t){this.#r?.(g.error)?.(t),await e.close()}else await ae(le(k(e.hasClosed()),ce(5e3).pipe(W(()=>k(e.close())))))}async waitForPageTarget(e,r){try{await e.waitForTarget(t=>t.type()==="page",{timeout:r})}catch(t){throw await e.close(),t}}async createCdpSocketConnection(e,r){let t=await e.waitForLineOutput(Se,r.timeout),s=await Z.create(t,void 0,r.logger,r.wsOptions);return new Q(t,s,r.slowMo,r.protocolTimeout,!1,r.idGenerator,r.logger)}async createCdpPipeConnection(e,r){let{3:t,4:s}=e.nodeProcess.stdio,c=new V(t,s,r.logger);return new Q("",c,r.slowMo,r.protocolTimeout,!1,r.idGenerator,r.logger)}async createBiDiOverCdpBrowser(e,r,t,s){let c=process.env.PUPPETEER_WEBDRIVER_BIDI_ONLY==="true",o=await import("./chunk-6QBHU4DF.mjs"),n=await o.connectBidiOverCdp(r,s.logger);return await o.BidiBrowser.create({connection:n,cdpConnection:c?void 0:r,closeCallback:t,process:e.nodeProcess,defaultViewport:s.defaultViewport,acceptInsecureCerts:s.acceptInsecureCerts,networkEnabled:s.networkEnabled,issuesEnabled:s.issuesEnabled,logger:s.logger})}async createBiDiBrowser(e,r,t){let s=await e.waitForLineOutput(Fe,t.timeout)+"/session",c=await Z.create(s,void 0,t.logger,t.wsOptions),o=await import("./chunk-6QBHU4DF.mjs"),n=new o.BidiConnection(s,c,t.idGenerator,t.slowMo,t.protocolTimeout,t.logger);return await o.BidiBrowser.create({connection:n,closeCallback:r,process:e.nodeProcess,defaultViewport:t.defaultViewport,acceptInsecureCerts:t.acceptInsecureCerts,networkEnabled:t.networkEnabled??!0,issuesEnabled:t.issuesEnabled??!0,logger:t.logger})}async getProfilePath(){let e=await this.puppeteer.configuration();return ke(e.temporaryDirectory??qe(),`puppeteer_dev_${this.browser}_profile-`)}async resolveExecutablePath(e,r=!0){let t=await this.puppeteer.configuration(),s=t.executablePath;if(s){if(r&&!$(s))throw new Error(`Tried to find the browser at the configured path (${s}), but no executable was found.`);return s}function c(u,d){switch(u){case"chrome":return d==="shell"?x.CHROMEHEADLESSSHELL:x.CHROME;case"firefox":return x.FIREFOX}return x.CHROME}let o=c(this.browser,e),n=await this.puppeteer.defaultDownloadPath(),i=await this.puppeteer.browserVersion();if(s=Oe({cacheDir:n,browser:o,buildId:i}),r&&!$(s)){let u=t?.[this.browser]?.version;throw u?new Error(`Tried to find the browser at the configured path (${s}) for version ${u}, but no executable was found.`):new Error(`Could not find ${rr(o)} (ver. ${i}). This can occur if either
4
4
  1. you did not perform an installation before running the script (e.g. \`npx puppeteer browsers install ${o}\`) or
5
5
  2. your cache path is incorrectly configured (which is: ${t.cacheDirectory}).
6
6
  For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.`)}return s}},re=new WeakMap;function tr(a,e,r=process){let t=re.get(r);if(!t){let c=new Set,o=()=>{for(let n of c)try{Ze(n.userDataDir,{recursive:!0,force:!0,maxRetries:3,retryDelay:100})}catch(i){n.logger(g.error)?.(i)}};t={entries:c,onExit:o},re.set(r,t),r.once("exit",o)}let s={userDataDir:a,logger:e};return t.entries.add(s),()=>{!t?.entries.delete(s)||t.entries.size>0||(r.off("exit",t.onExit),re.delete(r))}}import sr from"node:fs";var ir={force:!0,recursive:!0,maxRetries:10,retryDelay:100};async function j(a){await sr.promises.rm(a,ir)}var X=class extends R{constructor(e,r){super(e,"chrome",r)}async launch(e={}){return(await this.puppeteer.configuration()).logLevel==="warn"&&process.platform==="darwin"&&process.arch==="x64"&&ar.cpus()[0]?.model.includes("Apple")&&console.warn(["\x1B[1m\x1B[43m\x1B[30m","Degraded performance warning:\x1B[0m\x1B[33m","Launching Chrome on Mac Silicon (arm64) from an x64 Node installation results in","Rosetta translating the Chrome binary, even if Chrome is already arm64. This would","result in huge performance issues. To resolve this, you must run Puppeteer with","a version of Node built for arm64."].join(`
@@ -0,0 +1,4 @@
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 x,b as w,e as _}from"./chunk-Q4UEPUWF.mjs";import{spawn as P}from"node:child_process";import{existsSync as T,mkdirSync as F,readFileSync as g,renameSync as I,rmSync as A,writeFileSync as C}from"node:fs";import m from"node:fs/promises";import j from"node:os";import p from"node:path";import{fileURLToPath as k}from"node:url";import{userDirectory as b}from"../browser/shared/user-directory.mjs";import{compareVersions as O,RELEASED as S}from"../browser/shared/versions.mjs";var d="@heycys/gallery",D="\u6280\u80FD\uFF1A",G="\u65B0\u7248\u672C\uFF1A",Y="update-check.json",U=1440*60*1e3,H=3600*1e3,v=5e3,X="https://registry.npmjs.org/",K=d.split("/")[0],L="\uFF08\u4E4B\u540E\u65B0\u5F00\u7684 Agent \u4F1A\u8BDD\u624D\u8BFB\u5230\u65B0\u6280\u80FD\uFF09",h=t=>!["","0","false",void 0].includes(t),W=(t=process.env)=>h(t.GALLERY_NO_UPDATE_CHECK)||h(t.CI)||h(t.NO_UPDATE_NOTIFIER),J=(t=k(import.meta.url))=>/[\\/]_npx[\\/]/.test(t),V=(t={})=>b("cache",t);function M(t,e=process.env){let o=i=>i.replace(/(?<!\\)\$\{([^${}?]+)(\?)?\}/g,(c,l,s)=>e[l]??(s?"":c)),n={},r=!1;for(let i of t.replace(/^\uFEFF/,"").split(/\r?\n/)){let c=i.trim();if(!c||/^[;#]/.test(c))continue;if(/^\[.*\]$/.test(c)){r=!0;continue}let l=c.indexOf("=");if(r||l<1)continue;let s=c.slice(l+1).trim();/^(".*"|'.*')$/.test(s)?s=s.slice(1,-1):s=s.split(/(?<!\\)[;#]/)[0].replace(/\\([;#])/g,"$1").trim(),n[o(c.slice(0,l).trim())]=o(s)}return n}function $({env:t=process.env,home:e=t.HOME||j.homedir(),platform:o=process.platform,execPath:n=process.execPath}={}){let r={};for(let[a,f]of Object.entries(t)){if(!/^npm_config_/i.test(a)||!f)continue;let y=a.slice(11);r[y.startsWith("//")?y:y.replace(/(?!^)_/g,"-").toLowerCase()]=f}let i=a=>{try{return M(g(a,"utf8"),t)}catch{return{}}},c=a=>p.resolve(/^~[\\/]/.test(a)?p.join(e,a.slice(2)):a),l=o==="win32"?p.dirname(n):p.dirname(p.dirname(n)),s=[],u=[()=>r,()=>i(c(r.userconfig||p.join(e,".npmrc"))),()=>{let a=s[3]??=u[3](),f=r.prefix||s[1].prefix||a.prefix||t.PREFIX||l;return i(c(r.globalconfig||p.join(c(f),"etc","npmrc")))},()=>i(o==="win32"?p.join(l,"node_modules","npm","npmrc"):p.join(l,"lib","node_modules","npm","npmrc"))];return a=>{for(let f=0;f<u.length;f++)if(s[f]??=u[f](),s[f][a])return s[f][a]}}function q(t=process.env,e=$({env:t})){let o=t.GALLERY_REGISTRY||e(`${K}:registry`)||e("registry")||X;return o.endsWith("/")?o:`${o}/`}function z(t=process.env,e=$({env:t})){let o={...t,NODE_USE_ENV_PROXY:"1"},n=(c,l)=>{for(let s of Object.keys(o))c.test(s)&&delete o[s];Object.assign(o,l)},r=e("https-proxy")||e("proxy");r&&n(/^https?_proxy$/i,{HTTPS_PROXY:r,HTTP_PROXY:r});let i=e("noproxy");return i&&n(/^no_proxy$/i,{NO_PROXY:i}),o}var B=t=>`${t}${d.replace("/","%2f")}/latest`;function R(t){try{let e=JSON.parse(g(t,"utf8"));return e&&typeof e=="object"?e:null}catch{return null}}function Q(t,e,o=Date.now()){if(!t||!Number.isFinite(t.checked)||t.registry!==e)return!0;let n=o-t.checked;return n<0||n>=(t.failed?H:U)}var E=(t,e)=>t?.registry===e&&typeof t.latest=="string"&&S.test(t.latest)?t.latest:null;function Z(t,e,o,n=Date.now()){let r=`${t}.${process.pid}.tmp`;try{return F(p.dirname(t),{recursive:!0}),C(r,`${JSON.stringify({checked:n,registry:e,latest:E(o,e),failed:!0,checking:!0})}
3
+ `),I(r,t),!0}catch{return!1}finally{try{A(r,{force:!0})}catch{}}}async function dt(t,e,{timeout:o=v,now:n=Date.now}={}){let r=null;try{let l=await fetch(B(e),{signal:AbortSignal.timeout(o),headers:{Accept:"application/json"}});if(l.ok){let{version:s}=await l.json();typeof s=="string"&&S.test(s)&&(r=s)}}catch{}let i=r?{checked:n(),registry:e,latest:r}:{checked:n(),registry:e,latest:E(R(t),e),failed:!0};await m.mkdir(p.dirname(t),{recursive:!0});let c=`${t}.${process.pid}.tmp`;try{await m.writeFile(c,`${JSON.stringify(i)}
4
+ `),await m.rename(c,t)}finally{await m.rm(c,{force:!0}).catch(()=>{})}return i}function tt(t,e,{env:o=process.env}={}){try{let n=P(process.execPath,[k(new URL("./update-fetch.mjs",import.meta.url)),t,e],{cwd:j.homedir(),env:o,detached:!0,stdio:"ignore",windowsHide:!0});return n.on("error",()=>{}),n.unref(),!0}catch{return!1}}function et({env:t=process.env,cwd:e=process.cwd()}={}){let o=[...Object.values(x).map(r=>({folder:p.join(p.resolve(r.home(t)),"skills","gallery"),project:!1})),...Object.values(x).map(r=>({folder:p.join(p.resolve(e),r.project,"skills","gallery"),project:!0}))],n=r=>process.platform==="win32"?r.toLowerCase():r;return o.filter(({folder:r},i)=>o.findIndex(c=>n(c.folder)===n(r))===i)}var N=(t,e,o)=>o?`npx -y ${d}@^${e} ${t}`:`gallery ${t}`,rt=(t,e,o,n,r=!1)=>`${D}${t} \u662F${e?` Gallery ${e} `:"\u65E7\u7248 Gallery\uFF08\u6CA1\u5199\u7248\u672C\uFF09"}\u7684\uFF0C\u6BD4\u8FD9\u4E2A gallery ${o} \u65E7\uFF1B\u95EE\u8FC7\u7528\u6237\u540E\u8FD0\u884C ${N(`skill install${n?" --project":""}`,o,r)}${L}`,ot=(t,e,o=!1)=>`${G}npm \u4E0A\u6709 Gallery ${t}\uFF0C\u8FD9\u4E2A gallery \u662F ${e}\uFF1B\u95EE\u8FC7\u7528\u6237\u540E\u8FD0\u884C ${o?N("skill install",t,!0):`npm i -g ${d}@^${t}\uFF0C\u518D\u8FD0\u884C gallery skill install`}${L}`;function nt(t,{env:e=process.env,cwd:o=process.cwd(),npx:n=!1}={}){let r=[];for(let{folder:i,project:c}of et({env:e,cwd:o})){let l;try{l=g(p.join(i,"SKILL.md"),"utf8")}catch{continue}if(!["gallery","html-report-studio"].includes(w(l))||T(p.join(i,".git")))continue;let s=_(l);s&&O(s,t)>=0||r.push(rt(i,s,t,c,n))}return r}function yt(t,{env:e=process.env,cwd:o=process.cwd(),now:n=Date.now(),npx:r=J()}={}){let i=[];try{i.push(...nt(t,{env:e,cwd:o,npx:r}))}catch{}if(W(e))return i;try{let c=$({env:e}),l=q(e,c),s=p.join(V({env:e}),Y),u=R(s);Q(u,l,n)&&Z(s,l,u,n)&&tt(s,l,{env:z(e,c)});let a=E(u,l);a&&O(a,t)>0&&i.push(ot(a,t,r))}catch{}return i}export{d as a,D as b,G as c,Y as d,U as e,H as f,v as g,W as h,J as i,V as j,M as k,$ as l,q as m,z as n,B as o,R as p,Q as q,Z as r,dt as s,tt as t,et as u,rt as v,ot as w,nt as x,yt as y};
@@ -0,0 +1,4 @@
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{D as $,a as H,c as y,d as v,e as q,f as K,g as Y,i as V,k as X,o as z}from"./chunk-UBBRTJ2R.mjs";import{g as P}from"./chunk-FWNRPMCJ.mjs";import{b as S,e as U}from"./chunk-A55HN5OK.mjs";U();import{HOSTS as A,IDENTITY as dt}from"../browser/editor/components/registry.mjs";import{CODE as ut,MATH as tt,MEDIA as mt,PAGE as pt,TABLE as gt}from"../browser/editor/components/kit.mjs";import{TAB as ht}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as Nt,isInstance as w,matchesNode as x,partOf as bt}from"../browser/shared/components/index.mjs";import{texSource as It}from"../browser/editor/components/math/index.mjs";import{MENTION as M,MENTION_ICON as J,MENTION_PAGE as Q}from"../browser/shared/components/mention.mjs";import{imageFile as et}from"../browser/shared/media.mjs";import{isFileLink as kt}from"../browser/shared/page-address.mjs";import{isInkClass as xt}from"../browser/editor/page/marks.mjs";import{ownInline as Tt}from"../browser/editor/page/own.mjs";import{attr as h,hasClass as Ot}from"../browser/shared/html-tree.mjs";var Lt=new Set(["h1","h2","h3","h4","p","li"]),Ct=new Set(["h3","h4","p","figcaption"]),Et=Object.entries(A).flatMap(([t,e])=>(e.parts??[]).map(([r,a])=>{let c=Nt(r);if(c?.parts?.[a]?.edit!=="text")throw new Error(`Host ${t}: ${r} has no part ${a} edited as text`);return{kind:t,match:c.match,at:c.parts[a].at}})),St=t=>Et.filter(({match:e})=>x(t,e)).flatMap(({kind:e,at:r})=>bt(t,r).map(a=>({kind:e,part:a}))),vt=t=>t.sort((e,r)=>e.part.sourceCodeLocation.startOffset-r.part.sourceCodeLocation.startOffset),$t=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),wt=new Set(["ul","ol","blockquote"]),_=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),le={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function At(t,e,r){let a=A[t];if(!a)throw new Error(`Unknown block kind ${t}`);return a.caps({bound:r,blockLevel:y.has(e)})}var st=t=>t.tagName==="span"&&x(t,tt.inline),Bt=t=>t.tagName==="a"&&Ot(t,M),Pt=/^https?:\/\/[^\s"<>]+$/i,C=t=>t.attrs.map(e=>e.name).sort().join(),yt=t=>h(t,"class")===M&&t.childNodes.length===0&&(C(t)==="class"||C(t)===`class,${Q}`&&h(t,Q)==="");function _t(t){if(yt(t))return null;if(C(t)!=="class,href"||h(t,"class")!==M||!(Pt.test(h(t,"href"))||kt(h(t,"href"))))return"mention";let[e,...r]=t.childNodes;return(e?.tagName==="img"?C(e)==="alt,class,src"&&h(e,"class")===J&&h(e,"alt")===""&&et(h(e,"src")):e?.tagName==="span"&&C(e)==="class"&&h(e,"class")===J&&e.childNodes.length===0)&&r.length>0&&r.every(c=>c.nodeName==="#text")&&r.some(c=>c.value.trim())?null:"mention"}var Mt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(xt),jt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===ht,ot=t=>$t.has(t.tagName)||Mt(t)||jt(t),B=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":B(e)),at=t=>Tt(t.tagName,t.attrs,B(t)),Z=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==dt),Wt=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),Dt=(t,e,r={})=>t==="text"?y.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!r.plain;function j(t,e,r=!1,{cell:a=!1,pictures:c=a,known:l=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(r===!0)return`tag:${n.tagName}`;if(n.attrs.some(m=>/^on/i.test(m.name)))return"markup";if(r==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(a&&(n.tagName==="ul"||n.tagName==="ol")){let m=Ut(n,e,l);if(m)return m;continue}if(c&&n.tagName==="img"){if(Ft(n))return"picture";continue}if(st(n)){if(n.childNodes.some(m=>m.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(Bt(n)){let m=_t(n);if(m)return m;e.push(n.sourceCodeLocation);continue}if(at(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!ot(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&Wt(h(n,"href")??""))return"link";let N=j(n,e,!1,{known:l,pictures:c});if(N)return N}return null}var Gt=["src","alt","width"],Rt=/^[1-9]\d{0,3}$/;function Ft(t){let r=t.attrs.map(l=>l.name).find(l=>!Gt.includes(l));if(r)return`the attribute ${r}`;let a=h(t,"src");if(!et(a))return`its src (${a===void 0?"none":a.slice(0,80)}): no picture of the document's assets/ folder`;let c=h(t,"width");return c===void 0||Rt.test(c)?null:`its width (${c}): a whole number of pixels`}function Ut(t,e,r){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let a of t.childNodes){if(a.nodeName==="#text"&&!a.value.trim())continue;if(a.tagName!=="li")return`tag:${a.tagName??"text"}`;if(a.attrs.length>0||!a.sourceCodeLocation?.endTag)return"markup";let c=j(a,e,!1,{known:r,pictures:!0});if(c)return c}return null}function T(t){let e=[],r=[],a=new Map,c=null,l=(o,s,i=null)=>{let u=o.sourceCodeLocation;if(!A[s]||!u?.startTag||h(o,"contenteditable")!==void 0)return!1;let k=[],f=Dt(s,o.tagName),p=i?{childNodes:o.childNodes.slice(0,o.childNodes.indexOf(i))}:o,G=u.endTag?j(p,k,f,{cell:s==="cell"}):"markup";if(G)return r.push({at:u.startTag.endOffset-1,reason:G}),!1;let L=u.startTag.endOffset,ft=i?L+t.slice(L,i.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:u.endTag.startOffset,R={id:e.length,tag:o.tagName,kind:s,bound:!1,caps:{},start:u.startOffset,end:u.endOffset,innerStart:L,innerEnd:ft,atoms:k.map(F=>[F.startOffset-L,F.endOffset-L]),wrapper:null,nested:!!i,node:o};return e.push(R),a.set(o,R),!0},n=o=>(o.childNodes??[]).filter(s=>s.tagName),N=o=>{let s=o.sourceCodeLocation;return s?.startTag&&s.endTag?t.slice(s.startTag.endOffset,s.endTag.startOffset):null},m=o=>o.tagName!=="a"&&!Z(o)&&B(o)&&n(o).every(s=>at(s)?!B(s):ot(s)||st(s)),I=o=>{for(let s of n(o))s.tagName==="td"||s.tagName==="th"?l(s,"cell"):["thead","tbody","tfoot","tr"].includes(s.tagName)&&I(s)},d=o=>{for(let s of n(o))s.tagName==="table"?I(s):!_.has(s.tagName)&&!w(s)&&d(s)},b=o=>{let s=n(o);s.length===1&&s[0].tagName==="code"&&o.childNodes.every(i=>i.tagName||!i.value?.trim())?l(s[0],"code"):s.length===0?l(o,"code"):o.sourceCodeLocation?.startTag&&r.push({at:o.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},g=(o,s=!0)=>{for(let i of n(o)){let u=i.tagName,k=w(i);for(let{kind:f,part:p}of vt(k?$[V(i)].textParts(i,c??=P().packages):St(i)))l(p,f);if(k){for(let{element:f}of Y(i))g(f,s);continue}if(u==="div"&&x(i,ut.match)){for(let f of n(i))f.tagName==="pre"&&h(f,"contenteditable")===void 0&&b(f);continue}if(!(_.has(u)||h(i,"contenteditable")!==void 0))if(u==="table")I(i);else if(u==="figure"){let f=x(i,mt);for(let p of n(i))if(!(f&&p.tagName==="figcaption"))if(Ct.has(p.tagName))l(p,"field");else if(p.tagName==="table")I(p);else{if(_.has(p.tagName))continue;w(p)?g({childNodes:[p]},s):f||v(p)||Z(p)?d(p):g({childNodes:[p]},s)}}else if(u==="details")for(let f of n(i))w(f)?g({childNodes:[f]},s):f.tagName!=="summary"&&g(f,s);else if(u==="h1"&&(o.tagName==="header"||x(i,pt.title)))l(i,"title");else if(u==="li"&&K(i))g({childNodes:n(i)},s);else if(Lt.has(u)){let f=u==="li"?q(i):[];f?.length>0?(l(i,"flow",f[0]),g({childNodes:f},s)):l(i,"flow")||g(i,!1)}else if(u==="div"&&x(i,tt.block)&&n(i).length===0&&It(N(i)))l(i,"tex");else if(u==="div"&&x(i,gt.lead))for(let f of n(i))f.tagName==="span"&&l(f,"field");else s&&!v(i)&&m(i)?l(i,"text"):(g(i,s&&!v(i)),wt.has(u)&&it(i))}},it=o=>{let s=o.sourceCodeLocation,i=n(o).map(f=>a.get(f));if(!(i.length>0&&i.every(Boolean)&&o.childNodes.every(f=>f.tagName||f.nodeName==="#text"&&!f.value.trim()))||!s?.endTag)return;let k={start:s.startOffset,end:s.endOffset,ids:i.map(f=>f.id)};i.forEach(f=>f.wrapper=k)},W=o=>{for(let s of n(o))(s.tagName==="main"?g:W)(s)},D=S(t,{sourceCodeLocationInfo:!0});W(D);let{units:E,boxes:ct,referenced:lt}=X(D,t);for(let o of E)o.grid=!!$[o.kind]?.plain?.(o.node);for(let o of E){let s=$[o.kind]?.dataOf?.(t,o.node,c??=P().packages);s&&(o.parts=Object.fromEntries(Object.entries(s).map(([i,u])=>[i,H(u)])))}for(let o of e){let s=null;for(let i of E)i.start<=o.start&&o.start<i.end&&(!s||i.start>s.start)&&(s=i);o.unit=s?.id??null,o.self=s&&s.at===o.innerStart-1?s.id:null,o.self!==null&&(s.text=o.id),o.path=s&&o.self===null?Ht(s,o.node):null,A.text&&o.kind==="flow"&&o.self===null&&(s?.kind==="block"||s?.kind==="figure")&&(o.kind="text"),o.bound=lt(o.node)!==null,o.caps=Object.fromEntries(At(o.kind,o.tag,o.bound).map(i=>[i,!0]))}return{blocks:e,locks:r,units:E,boxes:ct}}function Ht(t,e){let r=[],a=e;for(;a&&!t.nodes.includes(a);a=a.parentNode){let c=(a.parentNode?.childNodes??[]).filter(l=>l.tagName===a.tagName);r.unshift([a.tagName,c.indexOf(a),c.length])}return a?[a===t.node?"unit":a===t.nodes[0]&&t.lead!==null?"lead":"panel",...r]:null}var fe=t=>T(t).blocks;function de(t){let{units:e,boxes:r}=T(t);return{units:e,boxes:r}}U();import{randomBlockId as qt}from"../browser/shared/ids.mjs";import{IDENTITY as O}from"../browser/editor/components/registry.mjs";var Kt=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function be(t,e=qt){let{units:r}=T(t),a=new Set([...t.matchAll(Kt)].map(d=>d[1]??d[2])),c=()=>{for(;;){let d=e();if(!a.has(d))return a.add(d)&&d}},l=new Set,n=[],N=[],m=[];for(let d of r)if(d.blockId)l.has(d.blockId)&&d.blockIdAttr?(N.push(d.blockId),n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${c()}"`})):l.add(d.blockId);else{let b=c();if(d.blockIdAttr)n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${b}"`});else{let g=z(t,d.at);n.push({start:g,end:g,text:` ${O}="${b}"`})}m.push({id:b,tag:rt(d.tag,d.attrs),at:d.elStart})}let I=t;for(let d of n.sort((b,g)=>g.start-b.start))I=I.slice(0,d.start)+d.text+I.slice(d.end);return m.sort((d,b)=>d.at-b.at),{text:I,added:m.length,renamed:N,given:m.map(({id:d,tag:b})=>({id:d,tag:b}))}}function Ie(t){let e=nt(t);return T(t).units.filter(r=>!r.blockId).sort((r,a)=>r.elStart-a.elStart).map(r=>({line:e(r.elStart),tag:rt(r.tag,r.attrs)}))}function ke(t,e){let r=new Map(e.map(c=>[c.id,c])),a=nt(t);return T(t).units.filter(c=>r.has(c.blockId)).sort((c,l)=>c.elStart-l.elStart).map(c=>({...r.get(c.blockId),line:a(c.elStart)}))}function nt(t){let e=[0];for(let r=t.indexOf(`
3
+ `);r!==-1;r=t.indexOf(`
4
+ `,r+1))e.push(r+1);return r=>{let[a,c]=[0,e.length-1];for(;a<c;){let l=a+c+1>>1;e[l]<=r?a=l:c=l-1}return a+1}}function rt(t,e=[]){let r=e.filter(({name:l})=>l!==O&&l!=="style"),a=l=>{let n=l.replace(/\s+/g," "),N=n.length>32?`${n.slice(0,31)}\u2026`:n;return N===""?"":/[\s"'=<>`]/.test(N)?`="${N.replaceAll('"',"&quot;")}"`:`=${N}`},c=r.slice(0,3).map(({name:l,value:n})=>`${l}${a(n)}`);return`<${[t,...c,...r.length>3?["\u2026"]:[]].join(" ")}>`}function xe(t){let e=new Map,r=a=>{let c=a.attrs?.find(n=>n.name===O)?.value,l=a.sourceCodeLocation?.attrs?.[O]??a.sourceCodeLocation;c!==void 0&&e.set(c,[...e.get(c)??[],l]);for(let n of a.content?.childNodes??a.childNodes??[])r(n)};return r(S(t,{sourceCodeLocationInfo:!0})),[...e].filter(([,a])=>a.length>1).map(([a,c])=>({id:a,lines:c.map(l=>l?.startLine),columns:c.map(l=>l?.startCol)}))}export{le as a,Dt as b,j as c,Ft as d,T as e,fe as f,de as g,qt as h,Kt as i,be as j,Ie as k,ke as l,xe as m};
@@ -0,0 +1,12 @@
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 H,c as X,e as ve}from"./chunk-A55HN5OK.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Me}from"node:crypto";import{existsSync as De,lstatSync as Pe,readFileSync as v,readdirSync as Ce,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ge,parsePart as Ke,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{PACK_FILE as ne,PACK_ID as he,readPackManifest as ot}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as it,PACKAGE_MANIFEST as I,WORKSPACE_MARK as rt,findWorkspace as at,layoutOf as K,markerOf as ct,packageFolders as lt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),ft=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],dt=["at","edit","optional","min","max"],pt=["generated","attrs"],mt=["document","page"],ut=["document"],ht=["sizes","w","h","min","max","resize","fit","bare"],y={w:12,h:24},wt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},yt=["key","label","type","options","default","required"],bt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],gt=/^\d{4}-\d{2}-\d{2}$/,kt="settings",Ot=["workspace","tables"],$t=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,St=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Et=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:St(n)}:s])),At=["parts","text"],we=["kit.js","style.css","preview.svg"],P="template.html",Nt=[I,P,...we],V=e=>[...new Set([...Nt,...e])].sort(),jt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,Tt=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Me("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=Pe(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&v(s)}catch{return null}}var ce=new Map,zt=2e3;function It(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(v(e)));return Date.now()-s>zt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=It(o))}catch{}s.update(`${t}\0${f}
3
+ `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},x=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},C=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ge(n).tag);function vt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),x(n,dt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ke(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}$t.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var _t=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Mt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),x(e,pt,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(c){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,c.message))}return d.split(",").map(c=>c.trim().startsWith(":scope")?c.trim().replace(":scope",s):`${s} ${c.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)Tt.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let l=d=>{let a=t(d,"runtime.generated");return _t(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(l),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var z=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Dt(e){return e===void 0?ut:((!Array.isArray(e)||e.length===0||!e.every(n=>mt.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Pt(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),x(e,ht,"card.");let n=a=>Array.isArray(a)&&a.length===2&&z(a[0],y.w)&&z(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let c=["w","h"].find(p=>e[p]!==void 0);c&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",c))}for(let a of["w","h"])e[a]!==void 0&&!z(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let c=e[a];if(c!==void 0){u(c)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),x(c,["w","h"],`card.${a}.`);for(let p of["w","h"])c[p]!==void 0&&!z(c[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=c}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,l=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([c,p])=>c<t.w||c>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let c={w:f,h:l}[a];c!==null&&!e.sizes&&(c<t[a]||c>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,c,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!wt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),{sizes:e.sizes?e.sizes.map(([a,c])=>[a,c]):null,any:d,w:f,h:l,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1}}var Ct=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&gt.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Ft(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let l=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",l)),x(o,yt,`${l}.`),(typeof o.key!="string"||!bt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",l)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),C(o.label,`${l}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",l,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",l)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",l,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",l)),o.default!==void 0&&!Ct(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",l,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",l))});let t=n[kt];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Lt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Ot.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Rt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Gt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)jt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Kt(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))it.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});x(t,ft),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),C(t.name,"name"),C(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))vt(w,$);let o=Mt(t.runtime,e),{kit:f,own:l}=Gt(t.assets,n);t.markdown!==void 0&&!At.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Dt(t.places);Rt(d,t.parts);let a=Pt(t.card),c=Ft(t.settings,t.parts),p=Lt(t.needs),h=ye(n,P);return h&&ge(h,P),{id:e,match:Ze(e),parts:Et(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:c,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...l])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(l))}}function Vt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Kt(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var _=()=>at().root,Ut=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,E=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Wt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,E(s,me)]).filter(([,n])=>n.length>0)),Bt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),M=e=>{let n=Bt(e?.components?.packs);return{hidden:E(e?.components?.hidden,Ut),disabled:E(e?.components?.disabled,A),shown:E(e?.components?.shown,A),unlisted:E(e?.components?.unlisted,A),net:Wt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),Jt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ct(e);return s?{value:n}:{problem:t?Jt:B}}function ke(e){try{return L(v(K(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var gn=(e=_())=>M(ke(e).value),Zt=["EPERM","EACCES","EBUSY","EROFS"];async function kn(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:l,pack:d,enabled:a}){let c=K(e).marker,p=await Le.readFile(c,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:Te,unlisted:ze}=M(h),g=u(h?.components)?h.components:{},Z=$(Te,t),q=$(ze,f),T={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};T.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(l!==void 0){let m={...u(g.net)?g.net:{}};l.length>0?m[n]=[...new Set(l)]:delete m[n],Object.keys(m).length>0?T.net=m:delete T.net}await He(c,`${JSON.stringify({...h??rt,components:T},null,2)}
4
+ `,{expect:p}).catch(m=>{throw Zt.includes(m.code)&&r(i("gallery.json \u5199\u4E0D\u8FDB\u53BB\uFF1A\u53EF\u80FD\u662F\u53EA\u8BFB\u7684\uFF0C\u6216\u88AB\u522B\u7684\u7A0B\u5E8F\u5360\u7740")),m})||r(i("gallery.json \u521A\u521A\u88AB\u6539\u8FC7\uFF1A\u518D\u8BD5\u4E00\u6B21"))}var qt=e=>({...e,off:!0,disabled:!0,problem:i("\u5728\u8BBE\u7F6E\u91CC\u505C\u7528\u4E86"),stamp:S(n=>n.update(`${e.stamp} off`))}),D=M(null),Yt=({packages:e,problems:n,settings:s=D,packs:t=new Map})=>S(o=>{for(let{id:f,stamp:l}of[...e.values(),...n.values()].sort(U))o.update(`${f} ${l}
5
+ `);o.update(`hidden ${[...s.hidden].sort().join(" ")}
6
+ `),o.update(`shown ${[...s.shown].sort().join(" ")}
7
+ `),o.update(`unlisted ${[...s.unlisted??[]].sort().join(" ")}
8
+ `),o.update(`net ${Oe(s).join(" ")}
9
+ `),o.update(`packs off ${(s.packsOff??[]).join(" ")}
10
+ `);for(let[f,l]of[...t].sort(([d],[a])=>d<a?-1:1))o.update(`pack ${f} ${JSON.stringify(l)}
11
+ `);o.update(`settings ${s.problem?.message??""}
12
+ `)}),Oe=({net:e={}})=>Object.entries(e).flatMap(([n,s])=>s.map(t=>`${n}@${t}`)).sort();function Ht(e,n){let{value:s,problem:t}=ke(e);return t?{hidden:n.hidden,disabled:n.disabled,shown:n.shown??[],unlisted:n.unlisted??[],net:n.net??{},packs:n.packs??{},packsOff:n.packsOff??[],problem:t}:M(s)}var R=null,$e=[],On=(e,n=["gallery"])=>{R=e,$e=[...n]};function Xt(e=_(),n=D,{on:s=null}={}){let t=Ht(e,n),o=new Map,f=new Map,l=lt(e),d=l.map(({id:c})=>c).filter(c=>$e.includes(c.split("/")[0]));if(R&&d.length>0)try{R(e,d)}catch{}for(let{id:c,folder:p}of l){let h=Vt(c,p);(h.problem?f:o).set(h.id,h)}for(let c of o.keys())f.delete(c);for(let c of t.disabled)!o.has(c)||c===s||(f.set(c,qt(o.get(c))),o.delete(c));let a=Qt(e,l.map(({id:c})=>c.split("/")[0]));return{packages:o,problems:f,settings:t,packs:a,stamp:Yt({packages:o,problems:f,settings:t,packs:a})}}function Qt(e,n=[]){let{components:s}=K(e),t=[];try{t=Ce(s).filter(f=>he.test(f)&&De(k.join(s,f,ne)))}catch{}let o=new Map;for(let f of[...new Set([...n,...t])].sort()){let l=null;try{l=ot(v(k.join(s,f,ne),"utf8")).name}catch{}o.set(f,l)}return o}var N=new Map;function $n(e=_()){let n=k.resolve(e);return N.has(n)||N.set(n,Xt(n)),N.get(n)}var xn=(e,n)=>{N.set(k.resolve(e),n)},Sn=(e=_())=>{N.delete(k.resolve(e))},fe=(e,n)=>tt(e,()=>st(n)),J=e=>({zh:fe("zh",e),en:fe("en",e)}),En=({settings:e})=>e.problem?J(e.problem):null,xe=(e,n)=>e.problem?e.disabled?"disabled":"broken":Ye(e.id,n,e.places),Se=({id:e,match:n,parts:s,runtime:t,schema:o,needs:f})=>({id:e,match:n,parts:s,...t?{runtime:t}:{},...o!==void 0?{schema:o}:{},...f?.length?{needs:f}:{}}),An=({packages:e,problems:n})=>[...[...e.values()].map(Se),...[...n.values()].map(({id:s,problem:t})=>({id:s,problem:J(t)}))],en=e=>`DocKit.describe(${JSON.stringify(e)});`.replace(/</g,"\\u003c"),G=({id:e,stamp:n},s)=>`/__gallery/components/${e}/${s}?v=${n}`;function tn(e){let n=`${Be}="${e.id}"`,s=t=>e.files.includes(t);return{styles:s("style.css")?[`<link rel="stylesheet" href="${G(e,"style.css")}" ${n}>`]:[],scripts:[`<script ${n}>${en({...Se(e),...s("kit.js")?{script:!0}:{}})}</script>`,...s("kit.js")?[`<script src="${G(e,"kit.js")}" ${n}></script>`]:[]]}}var Nn=({folder:e},n)=>j(e,n),jn=({folder:e,files:n})=>W(e,V(n));function de(e,n){let s=X(e,{sourceCodeLocationInfo:!0}).childNodes.filter(o=>o.tagName||o.nodeName==="#text"&&o.value.trim()),[t]=s;return s.length===1&&t.tagName&&Re(t)&&Xe(t,pe)===n&&t.sourceCodeLocation.endTag?t:null}function nn(e,n){let s=de(e,n),t=s&&H(s),o=t&&de(t,n);return o?{markup:t,root:o}:null}function Ee({id:e,template:n,parts:s}){if(!n)return{};let t=nn(n,e);if(!t)return{problem:i("template.html \u8981\u662F\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u7684\u4E00\u4E2A\u5B9E\u4F8B\uFF0C\u6709\u81EA\u5DF1\u7684\u7ED3\u675F\u6807\u7B7E\uFF0C\u6B64\u5916\u4EC0\u4E48\u90FD\u6CA1\u6709")};let o=[];if(Qe({childNodes:[t.root]},l=>{qe(l.tagName,l.attrs)&&o.push(l.tagName)}),o.length>0)return{problem:i("template.html \u91CC\u7684 <{0}> \u8FDB\u4E0D\u4E86\u65B0\u5EFA\u7684\u5757\uFF1A\u811A\u672C\u3001\u4E8B\u4EF6\u3001\u6837\u5F0F\u548C Gallery \u81EA\u5DF1\u7684\u6807\u8BB0\u90FD\u4E0D\u5199\u5728\u6A21\u677F\u91CC",o[0])};let f=Object.entries(s).find(([,l])=>{let d=Ue(t.root,l.at).length;return d<(l.optional?0:l.min??1)||d>(l.edit==="flow"?1:l.max??1/0)});return f?{problem:i("template.html \u7684 {0} \u548C\u6E05\u5355\u5199\u7684\u6570\u76EE\u4E0D\u7B26",f[0])}:{markup:t.markup}}var Tn=e=>Ee(e).problem??null,Ae=e=>Ee(e).markup??null,zn=({packages:e,settings:n=D,packs:s=new Map})=>[...e.values()].sort(U).map(t=>({id:t.id,version:t.version,name:t.name,description:t.description,words:t.words,definition:t.definition,stamp:t.stamp,template:Ae(t),preview:t.files.includes("preview.svg")?G(t,"preview.svg"):null,state:xe(t,n),places:t.places,needs:t.needs,markdown:t.markdown,assets:t.assets,tags:tn(t),pack:{id:t.id.split("/")[0],name:s.get(t.id.split("/")[0])??null}})),In=({packages:e,problems:n,settings:s=D})=>[...e.values(),...n.values()].sort(U).map(t=>({id:t.id,pack:t.id.split("/")[0],version:t.version??null,name:t.name??null,description:t.description??null,state:xe(t,s),reason:t.problem&&!t.off?J(t.problem):null,template:!!Ae(t),places:t.places??null,needs:t.needs??null,hidden:s.hidden.includes(t.id),shown:s.shown.includes(t.id),disabled:s.disabled.includes(t.id),unlisted:(s.unlisted??[]).includes(t.id),allowed:(s.net?.[t.id]??[]).filter(o=>et(t.needs).includes(o)),menu:Je(t.places,{...s,disabled:[],unlisted:[],packsOff:[]},t.id)})),vn=e=>`settings ${e.hidden.join(",")} ${e.disabled.join(",")} ${e.shown.join(",")} ${Oe(e).join(",")} ${(e.unlisted??[]).join(",")} ${(e.packsOff??[]).join(",")}`;export{kt as a,gn as b,kn as c,Yt as d,On as e,Xt as f,$n as g,xn as h,Sn as i,fe as j,En as k,An as l,en as m,G as n,tn as o,Nn as p,jn as q,nn as r,Tn as s,Ae as t,zn as u,In as v,vn as w};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g,h}from"./chunk-NVRNLK25.mjs";import"./chunk-RFDZXFJF.mjs";import"./chunk-QOUEFUCH.mjs";import"./chunk-VTKNEYT3.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-BPL64HGA.mjs";import"./chunk-6A53MZYZ.mjs";import"./chunk-UGWYKHBL.mjs";import"./chunk-OUUP3WKT.mjs";import"./chunk-NFMCP2HI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-NWFBE2YA.mjs";import"./chunk-PUOQ65NC.mjs";import"./chunk-ZUNVAXLH.mjs";import"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-UKSHDZZ6.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import"./chunk-SXHBYZST.mjs";import"./chunk-N7AZZLGT.mjs";import"./chunk-UFNYFFKO.mjs";import"./chunk-D4EURAX4.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 PAGE_ASIDE,b as PAGE_INSIDE_ALONE,e as cardChangesOf,c as firstInstance,d as outsideWhat,g as pageHost,f as pageSaves,h as pageTryCommand};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";export{b as UsageError,e as asksHelp,g as checkSlug,f as commandArguments,j as documentArguments,i as documentNamed,h as inTrashSaid,a as isOption,k as scriptArguments,d as usageFailureText,c as usageOf};
2
+ import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{b as UsageError,e as asksHelp,g as checkSlug,f as commandArguments,j as documentArguments,i as documentNamed,h as inTrashSaid,a as isOption,k as scriptArguments,d as usageFailureText,c as usageOf};
@@ -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 as h,b as v,d as p,e as j,h as I,j as A}from"./chunk-NAMN3RAF.mjs";import{a as O}from"./chunk-JEUK3ZO7.mjs";import{a as E}from"./chunk-VJPFVNNW.mjs";import"./chunk-PZDLJJTJ.mjs";import"./chunk-IA4PSIMD.mjs";import{f as C}from"./chunk-35NQ4PLQ.mjs";import{b as i,f as g,i as y}from"./chunk-4OZWXZE5.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import D from"node:path";import{pageLinks as F,pageOfLink as J}from"../browser/shared/page-links.mjs";import{reportsDirectory as x}from"../browser/shared/paths.mjs";import{findPreviewServer as K}from"../browser/shared/preview-server.mjs";import{topOf as M}from"../browser/shared/outline-shape.mjs";import{LINK_FILE as U,linkAddress as P,linkIcon as T}from"../browser/shared/web-links.mjs";var $=t=>t.replace(/\s+/g," ").trim(),k=t=>t==null?"none":JSON.stringify(t);async function L(t,e){let n=await K({reportsDirectory:x}),o=n?await I(n,e,t):null;if(o)return o;let[,s]=await E({edits:{},reports:{},reportsDirectory:x,web:{icon:a=>C(a)}}).run(t,e);return s}function _(t,e){let n=[...t.documents.values()].filter(({url:a})=>a!==void 0),o=J(F(n),e.replace(/^.*#/,""));return o?{slug:o,link:t.documents.get(o)}:{refused:t.documents.get(e)?`${p(t,e)} is a document, not a web link: gallery set changes a document.`:`No web link "${e}": gallery list --tree shows the sidebar's entries.`}}var W=(t,e)=>t.groups.find(n=>[v(n),n.id].some(o=>o.toLowerCase()===$(e).toLowerCase()))??null;async function B(t,e,n){if(t.length!==2)throw new i('Name the address and the name: gallery link add <url> "<name>".');let[o,s]=t,a=P(o);if(a.refused)throw new i(`Not an address a web link takes: ${o} (${{url:"no address",scheme:"http or https only",long:"2048 characters at most"}[a.refused]}).`);if(!$(s))throw new i("The name is never empty.");let d=n.get("--column"),u=n.get("--under"),l=n.get("--after"),c=n.get("--icon");if(d!==void 0&&u!==void 0)throw new i("--column and --under are two places: give one.");if(l!==void 0&&e.has("--first"))throw new i("--after and --first are two places: give one.");if(c!==void 0&&!T(c))throw new i(`Not an icon a web link takes: ${c} (an emoji, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg).`);let f=await h(),w;if(d!==void 0){let S=W(f,d);S||(console.error(`No column "${d}" in the sidebar (${f.groups.map(v).join(", ")}): nothing added.`),process.exit(1)),w=M(S.id)}u!==void 0&&(w=(await y(u)).slug);let r=l===void 0?null:(await y(l)).slug,q=e.has("--first")||u===void 0&&r===null,m=await L("link",{url:a.url,title:$(s),...c?{icon:c}:{},...w!==void 0?{parent:w}:{},after:r,first:q});m?.ok||(console.error(`Not added: ${m?.message??m?.reason??"no answer"}.`),process.exit(1));let b=await h(),{slug:N,url:z}=m.link;console.log(`Added the web link ${p(b,N)}: ${z}`),console.log(`Placed it ${A(b,{parent:m.parent,index:m.index})}.`),console.log(j(b,N)),console.log(`It is ${O(D.join(x,N,U))}; the workbench shows the page beside the sidebar (a site that refuses frames: \u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00).`)}async function G(t,e){if(t.length!==1)throw new i("Name one web link, then what to set: --url, --title, --icon.");if(!["--url","--title","--icon"].some(r=>e.has(r)))throw new i('Say what to set: --url <address>, --title "<name>", --icon <emoji|none>.');let n=e.has("--title")?$(e.get("--title")):void 0;if(n==="")throw new i("--title takes the words of the name: a web link's name is never empty.");let o;if(e.has("--url")){let r=P(e.get("--url"));if(r.refused)throw new i(`Not an address a web link takes: ${e.get("--url")}.`);o=r.url}let s;if(e.has("--icon")){let r=e.get("--icon").trim();if(r!=="none"&&!T(r))throw new i(`Not an icon a web link takes: ${r} (an emoji, none, or an icon of the \u56FE\u6807 tab).`);s=r==="none"?null:r}let a=await h(),d=_(a,t[0]);d.refused&&(console.error(d.refused),process.exit(1));let{slug:u,link:l}=d,c=await L("link-set",{slug:u,...o!==void 0?{url:o}:{},...n!==void 0?{title:n}:{},...s!==void 0?{icon:s}:{}});c?.ok||(console.error(`Not set: ${c?.message??c?.reason??"no answer"}.`),process.exit(1));let f=c.link,w=[...n!==void 0&&n!==l.title?[` title: ${k(l.title)} \u2192 ${k(f.title)}`]:[],...o!==void 0&&f.url!==l.url?[` url: ${l.url} \u2192 ${f.url}`]:[],...s!==void 0&&(f.icon??null)!==(l.icon??null)?[` icon: ${k(l.icon)} \u2192 ${k(f.icon??null)}`]:[]];if(!w.length)return void console.log(`Nothing to change: ${u} has ${e.size===1?"that already":"those already"}.`);console.log(`Set the web link ${u}:`);for(let r of w)console.log(r)}async function H(t){if(t.length!==1)throw new i("Name one web link to move to the trash.");let e=await h(),n=_(e,t[0]);n.refused&&(console.error(n.refused),process.exit(1));let o=await L("trash",{slug:n.slug,kind:"link"});o?.ok||(console.error(`Not moved to the trash: ${o?.message??o?.reason??"no answer"}.`),process.exit(1)),console.log(`Moved the web link ${p(e,n.slug)} to the trash: the workbench's \u8BBE\u7F6E \u203A \u56DE\u6536\u533A restores it where it was.`)}async function se(t){let[e,...n]=t;if(e==="add"){let{positional:o,options:s,values:a}=g({options:["--first"],values:["--column","--under","--after","--icon"],argv:n});return B(o,s,a)}if(e==="set"){let{positional:o,values:s}=g({values:["--url","--title","--icon"],argv:n});return G(o,s)}if(e==="remove"){let{positional:o}=g({argv:n});return H(o)}throw new i(e?`No such action: link ${e} (add, set, remove).`:"Say what to do: gallery link add, set or remove.")}export{se 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 as R}from"./chunk-MHW7ZKOU.mjs";import{b as I,c as B}from"./chunk-342HXE3Q.mjs";import{a as f,b as F,c as L,d as M}from"./chunk-BPL64HGA.mjs";import{a as S,b as k,g as $}from"./chunk-OUUP3WKT.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import{b as D}from"./chunk-PZDLJJTJ.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import{b as v}from"./chunk-SXHBYZST.mjs";import{j as d}from"./chunk-4OZWXZE5.mjs";import{k as w,q as h,t as g,u as y,v as x}from"./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";import O from"node:fs/promises";import{reportsDirectory as P}from"../browser/shared/paths.mjs";import{documentDirectory as U,documentFiles as q,layoutOf as z}from"../browser/shared/workspace.mjs";function C(s=P){let n=D({root:s,read:async a=>{let o=await O.readFile(q(U(a,s)).html,"utf8").catch(()=>null);return o===null?null:{source:o,text:v(o).text}},activity:N({file:z(s).activity})});return a=>n.snapshot(a)}async function te(s){let{slugs:t,options:n}=await d({options:["--allow-failures"],argv:s});t.length===0&&(console.error(R()),process.exit(1));let a=await b(t),o=await w(t,{prepare:f({say:!1})}),r=await S(t.filter(e=>!o.has(e)));await k(t.filter(e=>o.has(e)||r.failures.has(e))),await L(t),await M(t);let m=t.filter(e=>!o.has(e)&&!r.failures.has(e)),{built:l,exported:p,failures:c}=m.length>0?await h(m,{prepare:f({say:!1}),workspace:C()}):{built:[],exported:[],failures:new Map};for(let[e,i]of[...o,...r.failures])c.set(e,i);await y(c,{exportNote:!0}),await a.keep(p.map(({slug:e})=>e));let A=new Map(l.map(({report:e,removed:i})=>[e.slug,i]));for(let{slug:e,bytes:i,sha256:j}of p){let u=A.get(e),E=u.length>0?`; shared scripts and styles left out (unused): ${u.join(", ")}`:"";console.log(`Exported ${I(e)} (${i.toLocaleString("en-US")} bytes, sha256 ${j})${E}`)}g(l.map(({report:e})=>e)),F(l.map(({report:e})=>e));for(let e of r.lines)console.log(e);r.written.length>0&&console.log($(r.written));for(let{slug:e}of p)console.log(B(e));x(c,{above:!0,allow:n.has("--allow-failures")})}export{te as run};
@@ -0,0 +1,15 @@
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 ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-OW5NWPOJ.mjs";import{a as $t}from"./chunk-ZTHICSSF.mjs";import{b as fe,c as wt,e as K,f as he,i as ue,j as pe,m as me,n as ge,o as $e,p as we,q as be,r as bt}from"./chunk-SX4LJYT6.mjs";import{a as mt}from"./chunk-PAREWQGB.mjs";import{a as oe,b as se,c as ne,d as ie,e as ae,f as re,g as ce,h as le,l as de}from"./chunk-W3BGBJQW.mjs";import{b as gt,c as Xt,d as Qt,e as te,g as ee}from"./chunk-JVHHHGEA.mjs";import{a as w,b as Yt,c as qt}from"./chunk-HYMEEXKN.mjs";import{g as E,j as Jt,l as Vt,m as Zt}from"./chunk-FWNRPMCJ.mjs";import{existsSync as yo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function ve(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(e=>{if(!e||!["added","removed","unchanged"].includes(e.type)||typeof e.content!="string"||/[\r\n]/.test(e.content))throw new Error("diff: each line needs a valid type and single-line content.");if(e.lineNumber!=null&&(!Number.isInteger(e.lineNumber)||e.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as yt,isInstance as Bo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Ho}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Oe,hasClass as Ko,walk as xt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Go,CHART_KEY as Jo,CHART_SOURCE as C,VIEW_FROM as et,cellWords as Vo,rowsReading as Ee,tableRows as Zo}from"../browser/shared/table-chart.mjs";var Yo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Te=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Te).join("");function qo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Oe(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Vo(Te(s)):""}function Le(t,e,s=w(t)){let o=[];return xt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let r=n.childNodes.find(Yo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:r?r.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Go),tag:n.tagName,holder:n.parentNode?.tagName,title:qo(n)})},yt),o}var Xo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",ot=(t,e)=>Le(t,s=>Xo(s)?void 0:F(s,"data-doc-chart"),e),Qo=t=>Le(t,e=>Ko(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return xt(t,s=>{let o=F(s,C);if(o===void 0||!s.sourceCodeLocation)return;(e.get(o)??e.set(o,[]).get(o)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Oe(s).find(i=>i.tagName==="table")??null})},{...yt,inTemplates:!1}),e}function St(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${C}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(s.length>1)return{error:`${s.length} tables carry ${C}="${t}" (lines ${s.map(({line:c})=>c).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:o,table:n}]=s;if(!n)return{error:`the frame carrying ${C}="${t}" (line ${o}) holds no table`};let i=$t(n),r=Zo(i);return r.error?{error:`its table (line ${o}) ${r.error}`}:{...r,line:o,cells:i}}function Nt(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>tt(n,"kit.js")??"")].join(`
3
+ `),s=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(n=>n[2])),o=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(n=>n[2]).filter(n=>!s.has(n)));return{defined:s,misnamed:o}}function vt(t){let e=w(t),s=[],{defined:o,misnamed:n}=Nt(t),i=null;for(let{type:r,line:c,text:l,source:a,tag:d,holder:f}of ot(t,e)){let u=`data-doc-chart="${r}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${u} is on a table inside a <figure>: the chart's card is a figure of its own, so write the table outside it, its <caption> the chart's title`:`${u} is on a table the tools leave as written (inside a whole block, an element with a class of the document's own, a cell): a chart is drawn from a table outside one`);continue}if(n.has(r)){s.push(`${u}: the document's script defines "${r}" with DocCharts.define, which refuses that name: a chart type's name is lowercase letters, digits and hyphens, a letter first ("interval", "ci-plot"); rename it in both places`);continue}if(!o.has(r)){s.push(`${u}: the document's script does not define "${r}": define it once in the document's <script> with DocCharts.define("${r}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(a!==void 0){if(l!==null){s.push(`${u}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let h=St(a,i??=G(e));h.error&&s.push(`${u}: ${h.error}`);continue}if(l===null){s.push(`${u} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(h){s.push(`${u}: its data is not valid JSON (${h.message})`)}}s.push(...Ce(e,i??=G(e)).failures);for(let{line:r,text:c}of Qo(t)){if(c===null)continue;let l=`.doc-diff (line ${r})`;try{ve(JSON.parse(c))}catch(a){s.push(`${l}: ${a instanceof SyntaxError?`its options are not valid JSON (${a.message})`:a.message}`)}}return s}function Ae(t,{written:e=t}={}){let s=w(t),o=[],{defined:n}=Nt(t),i=null,r=null;for(let{type:c,line:l,text:a,source:d,title:f,tag:u}of ot(t,s)){if(d===void 0||u==="table"||a!==null||!n.has(c))continue;let h=`data-doc-chart="${c}" (line ${l})`;if(!f){r??=new Set(e===t?[]:ot(e).map(k=>k.source).filter(k=>k!==void 0));let b=e!==t&&!r.has(d);o.push(`${h}: this chart card has no title: ${b?"write a <caption> on its table (the one with data-doc-chart), which becomes the card's h3":"write an h3 in the card's figure, before the chart"}`)}let m=St(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=Ee(m.cells,m.data);p&&o.push(`${h}: its table's header (line ${m.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),g.length>0&&o.push(`${h}: its table's header (line ${m.line}) names ${g.map(b=>`"${b}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return o.push(...Ce(s,i??=G(s)).notes),o}var kt=500;function Ce(t,e){let s=[],o=[],n=E().packages;return xt(t,i=>{let r=F(i,et);if(r===void 0||!i.sourceCodeLocation)return;let c=F(i,Ho),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Bo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${et}="${r}", which only a view of a table carries: an instance of a custom block (<div data-doc-component="<scope>/<name>">) whose block's needs hold "tables"; take it off`);if(!Jo.test(r))return void s.push(`${l}: ${et}="${r}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${C}`);let a=e.get(r)??[];if(a.length===0)return void s.push(`${l}: no table's frame carries ${C}="${r}", so the view has no table to read: put the table back, or delete the view`);if(a.length>1)return void s.push(`${l}: ${a.length} tables carry ${C}="${r}" (lines ${a.map(({line:g})=>g).join(", ")}): a key names one table (the view reads the first); take it off the copies`);let[{line:d,offset:f,table:u}]=a;if(!u)return void s.push(`${l}: the frame carrying ${C}="${r}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&o.push(`${l} stands before the table it reads (${C}="${r}", line ${d}): it works there, but each block's writing.md writes the table first and the view after it, as its example does: move the view below the table, unless the document is meant to open on it`);let h=n.get(c)?.needs;h&&!h.includes("tables")&&o.push(`${l} carries ${et}="${r}", but its block's needs hold no "tables", so it reads no table: add "tables" to needs in its component.json, or take the key off`);let m=$t(u);m.merged&&o.push(`${l}: its table (line ${d}) has merged cells, which no view reads, so the view shows nothing of it: write each value in its own cell`);let p=m.names?m.rows.length:Math.max(0,m.rows.length-1);p>kt&&o.push(`${l}: its table (line ${d}) has ${p} rows: every view of a table reads it again as it is typed in, and past ${kt} rows that slows typing in it; split it, or keep what a view shows to ${kt} rows`)},yt),{failures:s,notes:o}}function ze(t){let e=w(t),s=[],o=[],{defined:n}=Nt(t),i=null,r=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:a,source:d,tag:f}of ot(t,e)){if(d===void 0||f==="table"||a!==null||!n.has(c))continue;let u=St(d,i??=G(e));if(u.error)continue;let{rows:h,columns:m,foot:p,extra:g}=Ee(u.cells,u.data),b=`data-doc-chart="${c}" (line ${l})`,k=[r(h,"row")];for(let{name:x,numbers:v,words:T,empty:H}of m){let R=v+T+H,q=v===R&&R>0?"numbers":T===R&&R>0?"words":[v&&r(v,"number"),T&&`${T} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${q}`),v>0&&T>0&&o.push(`${b}: its table's column "${x}" (line ${u.line}) reads as numbers in ${r(v,"row")} and as words in ${T}: write each of its cells as one number (an empty cell, "\u2014" or "n/a" for none: null in data), or, for a column of words, data-sort-type="text" on its header cell`)}p>0&&o.push(`${b}: its table's <tfoot> (line ${u.line}) holds ${r(p,"row")} the chart leaves out, and a table with a <tfoot> has no table tools in the preview: keep a total out of a table you chart and say it in the text`),g>0&&o.push(`${b}: ${r(g,"row")} of its table (line ${u.line}) ${g===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),s.push(`${c} (line ${l}) reads its table (line ${u.line}): ${k.join("; ")}`)}return{readings:s,notes:o}}import{BODY as Si,componentOf as Ni,matchesNode as xo}from"../browser/shared/components/index.mjs";import{FLOW as vi}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as So,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Oi,ICON_COLORS as No,glyphOf as Ei,glyphValue as Ti,iconKind as Ut,iconMarkup as Li,iconValueOf as Ai}from"../browser/shared/emoji/icon-value.mjs";import ts from"node:vm";import{LINE_START as it,lineStart as es}from"../browser/shared/code-lines.mjs";import{BODY as Me,COMPONENTS as os,FLOWS as ss,instanceSlots as ns,instancesOf as is,isInstance as _,isSlot as Pe,matchesNode as P,ownSlots as as,partOf as Lt,vocabulary as rs}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as A,INSTANCE as cs,PACKAGE_ID as at,SCHEMA as Ot,SLOT as z,schemaAhead as ls}from"../browser/shared/components/installed.mjs";import{packageScript as ds}from"../browser/shared/export-wrap.mjs";import{asDocName as fs,kitNamespace as hs}from"../browser/shared/old-names.mjs";import{shortSheets as us}from"../browser/shared/components/sheets.mjs";import{attr as y,curlyQuoted as ps,hasClass as ms,walk as J}from"../browser/shared/html-tree.mjs";var{authoring:nt,runtime:Ie}=rs(),gs="input, select, textarea, button, details, table",rt=t=>t.sourceCodeLocation?.startLine,$=t=>rt(t)?` (line ${rt(t)})`:"";function je(t){let e=(o,n)=>{let i=Array.from({length:n.length+1},(r,c)=>c);for(let r=1;r<=o.length;r++){let c=i[0];i[0]=r;for(let l=1;l<=n.length;l++){let a=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(o[r-1]===n[l-1]?0:1)),c=a}}return i[n.length]},[s]=[...nt.keys()].filter(o=>o.startsWith(t.slice(0,7))).map(o=>[o,e(t,o)]).sort((o,n)=>o[1]-n[1]);return s&&s[1]<=3?` (${s[0]}?)`:""}function $s(t,e,s){let{part:o,property:n,min:i}=t.shares,r=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>r.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let a=`${t.id}${$(e)}`;return l.length<c.length?[`${a}: ${n} on ${l.length} of its ${c.length} ${o}: write it on every one of them, or on none (equal widths)`]:l.map(Number).some(f=>!Number.isFinite(f)||f<i-1e-9||f>1)?[`${a}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var st={"doc-dialog-header":'a detail card has no header: its content region (<div class="doc-dialog-content">) stands alone in its panel',"doc-dialog-title":"a detail card's title is an ordinary heading (<h3>), first in its content region","doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","data-doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","doc-section-header":"a section's title is a plain heading (<h2>) with an ordinary paragraph below it for the line that says what the section is: no <div> goes around them","doc-grid":'a card row is now columns: <div class="doc-columns"> holding one <div class="doc-column"> per card',"doc-grid-3":'a card row is now columns: <div class="doc-columns"> holding three <div class="doc-column">',"doc-lede":`write the line under the title as a paragraph of the header (an ordinary <p>), or as small text, <p class="doc-note"): the header's lines read as the body's paragraphs`,"doc-source":`write the line under the title as a plain paragraph of the header (an ordinary <p>), or as small text (<p class="doc-note">): the header's lines read as the body's paragraphs`,"doc-prose":"write the text straight in its flow (the page, a Sheet panel, a section, a panel, a column\u2026): it reads the same there","doc-prose-h1":"write an h1","doc-prose-h2":"write an h2","doc-prose-h3":"write an h3","doc-prose-h4":"write an h4","doc-state-grid":'put the groups side by side in columns (<div class="doc-columns">)',"doc-state-group":"write the group's title as a heading and its controls as blocks of their own in a column","doc-state-status":'write the line as small text, <p class="doc-note">',"doc-code-block":'a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre><code>',"doc-code-card":'a code block is <div class="doc-code"> holding its title and its <pre>; a diff is <div class="doc-diff">',"doc-code-header":'write the title as <div class="doc-code-title">: the kit draws the rest of the header',"data-doc-diff":'a diff is <div class="doc-diff"> holding its title and its options as JSON (sdk/doc-code.d.ts)',"data-doc-diff-stats":"the kit shows a diff's counts in its header: remove it","doc-code--wrap":"a code block wraps its long lines by itself: remove it (doc-code--nowrap scrolls them instead)"},ws={[it]:'write it on its <div class="doc-code">',"data-start":`write ${it} on its <div class="doc-code">`,"data-line-numbers":'write it on its <div class="doc-code">',"data-folded-lines":'write it on its <div class="doc-code">',"data-title":'write the title in its <div class="doc-code-title">',"data-wrap":'for long lines that scroll, write class="doc-code doc-code--nowrap" on its <div class="doc-code">'};function bs(t){let e=[],s=t.tagName==="pre"?t.parentNode:t.tagName==="code"&&t.parentNode?.tagName==="pre"?t.parentNode.parentNode:null;if(s?.tagName&&P(s,".doc-code"))for(let[n,i]of Object.entries(ws))y(t,n)!==void 0&&e.push(`${n}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let o=t.tagName==="div"&&P(t,".doc-code")?y(t,it):void 0;return o!==void 0&&es(o)===null&&e.push(`${it}="${o}"${$(t)}: the number of a code block's first line is a whole number from 1`),e}var Re=ss.join(", "),ks=t=>P(t.parentNode,Re)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Re);function ys(t,e){let s=[];J(e,n=>s.push(...ps(t,n)));let o=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},r)=>r===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${o(n)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${n} uses curly quotes too: write ${o(n)}`)}var Fe={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},xs="write a <section> of no attribute straight in it for each tab, starting with its heading (<h2>\u2013<h4>), the tab's name, the rest its blocks, and nothing else: the export makes the kit's tabs",Ss='a bookmark written the short way is a paragraph in a flow holding only <a class="doc-bookmark" href="https://\u2026">its title</a> (a title attribute its description, nothing else on it, words alone in it): the export makes the card';function Ue(t){let e=[];return J(t,s=>{y(s,A)!==void 0&&e.push(s)},Me),e}var Ns=t=>{let e=t.parentNode;for(;e&&!(_(e)||Pe(e));)e=e.parentNode;return e??null};function vs(t,e){let s=[];return J(t,o=>{let n=y(o,z);if(n===void 0)return;if(_(o))return void s.push(`${z}="${n}"${$(o)} on the instance itself: a slot is an element inside it`);if(!Pe(o))return void s.push(`${z}${$(o)} on a <${o.tagName}>: a slot is a block-level <div> or <section>`);let i=Ns(o),r=i&&_(i)?e?.get(y(i,A)):null;if(!i||!_(i)||r&&We(i,r,o))return void s.push(`${z}="${n}"${$(o)} stands outside any instance's own markup: a slot is a part of a component package's instance, written in its template`);y(o,"data-block-id")!==void 0&&s.push(`${z}="${n}"${$(o)}: a slot is no block: it carries no data-block-id`)}),s}var Os=(t,e)=>{for(let s=e.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},We=(t,e,s)=>Object.values(e.parts??{}).filter(({edit:o})=>o==="text"||o==="data").some(({at:o})=>Lt(t,o).some(n=>Os(n,s))),_e=(t,e)=>as(t).filter(s=>!We(t,e,s)),Es=t=>t.flatMap(e=>_(e)?at.test(y(e,A))?[]:[`${A}="${y(e,A)}"${$(e)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${A}${$(e)} on a <${e.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Be(t){let e=Ue(t).filter(o=>_(o)&&at.test(y(o,A))),s=e.length>0?E():null;return e.flatMap(o=>{let n=y(o,A),i=s.packages.get(n);if(i&&!ls(y(o,Ot),i.schema))return[];if(i)return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${Ot}="${y(o,Ot)}" is past the ${i.schema??1} its package's manifest reads (schema): nothing can write it back, and the block shows read-only until the package reads it`];let r=s.problems.get(n)?.problem,c=r?`package ${n} does not load (${Jt("en",r)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Et(t,e){let s=[];for(let{name:o,value:n}of t.attrs){if(st[o]&&!nt.has(o)){s.push(`${o}${$(t)} is gone: ${st[o]}`);continue}if(o.startsWith("data-doc-")&&!nt.has(o)&&s.push(Ie.has(o)?`${o}${$(t)} is the kit's to set: remove it`:`${o}${$(t)} is no attribute of the kit's${je(o)}`),o==="class"){for(let i of n.split(/\s+/).filter(e))if(!nt.has(i)){if(st[i]){s.push(`class ${i}${$(t)} is gone: ${st[i]}`);continue}s.push(Ie.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${je(fs(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var De=t=>t.startsWith("doc-");function Ts(t){try{return new ts.Script(ds(t),{filename:"kit.js"}),null}catch(e){let s=/^kit\.js:(\d+)/.exec(e.stack??"")?.[1];return{message:e.message,line:s?Number(s):null}}}var Tt=new Map;function Ls(t){if(!t.files.includes("kit.js"))return null;if(Tt.get(t.folder)?.stamp!==t.stamp){let e=tt(t,"kit.js"),s=e===null?null:Ts(e),o=e===null?`${t.id}: its kit.js cannot be read`:s&&`${t.id}: its kit.js does not run: ${s.message}${s.line?` (line ${s.line})`:""}`;Tt.set(t.folder,{stamp:t.stamp,failure:o})}return Tt.get(t.folder).failure}function At(t,e=w(t),s=null){let o=ys(t,e),n=Ue(e);o.push(...Es(n));let i=n.length>0?s??E():null,r=i?[...i.packages.values()]:[];i&&o.push(...L(t,i,e).map(Ls).filter(Boolean));for(let a of[...os,...r].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of is(e,a)){if(a.empty&&!(d.childNodes??[]).some(h=>h.tagName||h.nodeName==="#text"&&h.value.trim()))continue;let f=a.id==="sheets"?us(d):null;if(f){o.push(`${a.id}${$(d)} has no tabs and is no short form: ${f.why??"it stands where no block does (in a whole block or a figure)"}; ${xs}`);continue}if(Fe[a.id]&&Object.values(a.parts??{}).some(h=>Lt(d,h.at).length<(h.optional?0:h.min??1))){o.push(`${a.id}${$(d)} carries the kit's class without the kit's parts: ${Fe[a.id]}`);continue}let u={};for(let[h,m]of Object.entries(a.parts??{})){if(m.edit==="flow"&&at.test(a.id)){let b=_e(d,a).filter(k=>y(k,z)===h);b.length===0&&!m.optional&&o.push(`${a.id}${$(d)} has no ${h} (${z}="${h}")`);for(let k of b.slice(1))o.push(`${a.id}${$(k)}: slot "${h}" twice`);u[h]=b.slice(0,1);continue}u[h]=Lt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;u[h].length<p?o.push(`${a.id}${$(d)} has ${u[h].length===0?"no":`${u[h].length} of`} ${h} (${m.at.replace(":scope > ","")})${u[h].length>0?`, at least ${p}`:""}`):u[h].length>g&&o.push(`${a.id}${$(d)} has ${u[h].length} of ${h}, at most ${g}`)}if(a.only){let h=new Set(a.only.flatMap(m=>u[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!h.has(p)))o.push(`${a.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${a.only.join(", ")} (${a.only.map(p=>a.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(a.shares&&o.push(...$s(a,d,u[a.shares.part])),at.test(a.id)){let h=Object.entries(a.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of _e(d,a).filter(p=>!h.includes(y(p,z))))o.push(`${a.id}${$(m)}: slot "${y(m,z)}" is no part of its manifest edited as flow`)}for(let{a:h,attrA:m,b:p,attrB:g}of a.pairs??[]){let b=u[h].map(x=>y(x,m)),k=u[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,T)=>b.indexOf(v)!==T)))o.push(`${a.id}${$(d)}: ${h} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))o.push(`${a.id}${$(d)}: ${h.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))o.push(`${a.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${h.replace(/s$/,"")} (${m}="${x}")`)}}o.push(...vs(e,i?.packages));let c=new Set,l=[];J(e,a=>{if(_(a)){let u=new Set(ns(a));o.push(...Et(a,De)),J(a,h=>o.push(...Et(h,De)),{stop:h=>u.has(h)});return}a.tagName==="pre"&&ks(a)&&o.push(`<pre>${$(a)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),o.push(...bs(a)),a.tagName==="a"&&ms(a,"doc-bookmark")&&o.push(`<a class="doc-bookmark">${$(a)} is no bookmark: ${Ss}`),o.push(...Et(a,hs));let d=y(a,"data-doc-bind");d!==void 0&&(d.trim()?P(a,gs)?a.tagName==="button"&&y(a,"value")===void 0?o.push(`data-doc-bind${$(a)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):o.push(`data-doc-bind${$(a)} on a ${a.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):o.push(`data-doc-bind${$(a)} names no key`));let f=y(a,"data-doc-show");f!==void 0&&l.push([a,f])},Me);for(let[a,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?o.push(`data-doc-show="${d}"${$(a)}: write key:value`):c.has(f)||o.push(`data-doc-show="${d}"${$(a)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return o.push(...Rs(t,e)),o}var As=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,Cs=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,zs=t=>/[\\^]/.test(t)||!t.startsWith("{")&&Cs.test(t),Is=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),js=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${cs}`;function Rs(t,e){let s=[],o=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:r,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(r,c).matchAll(As)){if(!zs(l[1]))continue;let a=l[1].replace(/\s+/g," "),d=a.length>60?`${a.slice(0,59)}\u2026`:a;s.push(`line ${qt(t,r+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!Is.has(i.tagName)&&!P(i,js)&&o(i)};return o(e),s}import V from"node:fs";import W from"node:path";import{COLOR_NAMES as Ks}from"../browser/shared/colors.mjs";import{FOLD_DOTS as Gs}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as Js,kitSourceDirectory as Vs,release as Zs}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Ua}from"../browser/shared/components/list.mjs";var Fs={"code-title":{zh:"\u4EE3\u7801\u5757",en:"Code"},"plain-text":{zh:"\u7EAF\u6587\u672C",en:"Plain text"},"fold-code":{zh:"\u6298\u53E0\u6216\u5C55\u5F00\u4EE3\u7801\u5757",en:"Collapse or expand the code block"},"copy-code":{zh:"\u590D\u5236\u4EE3\u7801",en:"Copy code"},copied:{zh:"\u5DF2\u590D\u5236",en:"Copied"},wrap:{zh:"\u81EA\u52A8\u6362\u884C",en:"Wrap lines"},"no-wrap":{zh:"\u53D6\u6D88\u81EA\u52A8\u6362\u884C",en:"Stop wrapping lines"},fold:{zh:"\u6298\u53E0",en:"Collapse"},unfold:{zh:"\u5C55\u5F00",en:"Expand"},line:{zh:"\u7B2C {0} \u884C",en:"Line {0}"},lines:{zh:"\u7B2C {0}\u2013{1} \u884C",en:"Lines {0}\u2013{1}"},"diff-counts":{zh:"\u65B0\u589E {0} \u884C\uFF0C\u5220\u9664 {1} \u884C",en:"Lines added: {0}, removed: {1}"}};var He="data-ge-language",_s={"code-title":"--doc-word-code-title"};function Ds(t,e,s,...o){let n=t[s];if(!n)throw new Error(`The kit has no word "${s}" here (src/render/kit/words.js).`);let i=n[e]??n.zh;return o.length===0?i:i.replace(/\{(\d+)\}/g,(r,c)=>c<o.length?String(o[c]):r)}var Ms=`:root[${He}="en"], :root:not([${He}])[lang|="en" i]`;function Ke(){let t=e=>Object.entries(_s).map(([s,o])=>`${o}: ${JSON.stringify(Ds(Fs,e,s))};`).join(" ");return`:root { ${t("zh")} }
4
+ ${Ms} { ${t("en")} }`}import{LOOK as Ct,LOOK_ATTRIBUTES as Ps,SERIF_FONT as Ge,SIZE_FACTOR as Us,SPACING as Ws,WIDTH as zt}from"../browser/shared/document-look.mjs";var Je=[["--doc-body-font-size","--doc-body-line-height"],["--doc-small-font-size","--doc-small-line-height"],["--doc-note-font-size","--doc-note-line-height"],["--doc-title-font-size","--doc-title-line-height"],["--doc-h1-font-size","--doc-h1-line-height"],["--doc-h2-font-size","--doc-h2-line-height"],["--doc-h3-font-size","--doc-h3-line-height"],["--doc-h4-font-size","--doc-h4-line-height"],["--doc-card-title-font-size","--doc-card-title-line-height"],["--doc-table-font-size","--doc-table-line-height"]],Bs=["--doc-component-gap","--doc-block-gap","--doc-media-gap","--doc-paragraph-gap","--doc-group-gap","--doc-list-gap"],It="--doc-content-max-width";function Hs(t){let e=new Map;for(let[,s,o]of String(t).matchAll(/^\s*(--doc-[a-z0-9-]+):\s*([^;]+);/gm))e.has(s)||e.set(s,o.trim());return e}var ct=t=>`${Math.round(t)}px`;function lt(t,{size:e="default",spacing:s="default",width:o="default"}={}){let n=a=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(a)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${a} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Us[e],{leading:r,gaps:c}=Ws[s],l={};if(e!=="default"||s!=="default")for(let[a,d]of Je){let f=n(a)*i;e!=="default"&&(l[a]=ct(f)),l[d]=ct(Math.round(f)+(n(d)-n(a))*i*r)}if(s!=="default"){for(let a of Bs)l[a]=ct(n(a)*c);l["--doc-space"]=String(c)}if(o!=="default"){if(n(It)!==zt.default)throw new Error(`src/render/kit/styles/tokens.css: ${It} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${zt.default}px (src/shared/document-look.mjs WIDTH)`);l[It]=ct(zt[o])}return l}var U=(t,e)=>`${t} { ${Object.entries(e).map(([s,o])=>`${s}: ${o};`).join(" ")} }`,D=(t,e)=>`[${Ps[t]}="${e}"]`;function Ve(t){let e=Hs(t),s=e.get("--doc-font");if(!s)throw new Error("src/render/kit/styles/tokens.css: no --doc-font (src/render/look-css.mjs keeps it as --doc-sans-font)");let o=[U(`:root${D("font","serif")}`,{"--doc-sans-font":s,"--doc-font":Ge}),U(`:root${D("font","mixed")}`,{"--doc-heading-font":Ge})],[,...n]=Ct.size,[,...i]=Ct.spacing,[,...r]=Ct.width;for(let c of n)o.push(U(`:root${D("size",c)}`,lt(e,{size:c})));for(let c of i)o.push(U(`:root${D("spacing",c)}`,lt(e,{spacing:c})));for(let c of r)o.push(U(`:root${D("width",c)}`,lt(e,{width:c})));for(let c of n)for(let l of i){let a=lt(e,{size:c,spacing:l});o.push(U(`:root${D("size",c)}${D("spacing",l)}`,Object.fromEntries(Je.map(([,d])=>[d,a[d]]))))}return o.join(`
5
+ `)}var Ze=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),tr=Object.keys(Ze),Z=t=>W.join(Vs,t),Ys=(t,e,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof e=="function"?e():e,...s}),qs=t=>{let e=Ze[t];if(!e)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return e},dt=new Map;function Xs(t,e){let s=[...e.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),o=V.readdirSync(W.dirname(Z(t))).filter(i=>i.endsWith(".css")&&i!==W.basename(t)),n=[...o.filter(i=>!s.includes(i)).map(i=>`${i} is not listed`),...s.filter((i,r)=>!o.includes(i)||s.indexOf(i)!==r).map(i=>`${i} is listed but missing, or listed twice`)];if(n.length>0)throw new Error(`src/render/kit/${t}: ${n.join("; ")}`);return s.map(i=>W.join(W.dirname(t),i))}var Qs=t=>t.replace(/@(text|highlight)-colors\b/g,(e,s)=>Ks.map(o=>`.doc-${s}-${o}`).join(", ")),tn=t=>{let e=Qs(t.join(`
6
+ `)).replaceAll("@fold-dots",Gs).replace(/^@kit-words;$/m,()=>Ke());return e.replace(/^@kit-look;$/m,()=>Ve(e))};function jt(t,{fresh:e=!1}={}){let s=qs(t);if(Zs)return V.promises.readFile(W.join(Js,t),"utf8");if(s.read)return V.promises.readFile(Z(s.read),"utf8");if(s.styles)return V.promises.readFile(Z(s.styles),"utf8").then(o=>Promise.all(Xs(s.styles,o).map(n=>V.promises.readFile(Z(n),"utf8")))).then(tn);if(e||!dt.has(t)){let o=fe(Ys(s.bundle,s.options)).then(n=>n.outputFiles[0].text);o.catch(()=>dt.delete(t)),dt.set(t,o)}return dt.get(t)}import{kitNamespace as en}from"../browser/shared/old-names.mjs";import{attr as Rt,hasClass as ht}from"../browser/shared/html-tree.mjs";var Ye=t=>t.tagName==="section"&&ht(t,"doc-section"),on=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),sn=t=>!on.has(t.tagName),ft=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(ft).join("");function Xe(t,e=[]){for(let s of t.childNodes??[])s.tagName&&((s.tagName==="main"&&ht(s,"doc-page")||Rt(s,"data-doc-sheet")!==void 0)&&e.push(s),Xe(s.tagName==="template"?s.content:s,e));return e}var nn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,Qe=["doc-summary","doc-panel","doc-note","doc-callout"],an=t=>nn.test(t.tagName)||Qe.some(e=>ht(t,e)),rn=new Set(["none","auto","100%","inherit","initial","unset","revert"]),qe=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,e])=>!rn.has(e.replace(/!important/i,"").trim().toLowerCase())),cn=t=>{let e=t.trim().split(/\s*[\s>+~]\s*/).at(-1)??"",s=/^(p|li|h[1-4]|blockquote|ul|ol)\b/.test(e)||Qe.some(n=>e.includes(`.${n}`)),o=[...t.matchAll(/\.([\w-]+)/g)].some(([,n])=>!en(n))||t.includes("#");return s&&!o};function ln(t){let e=[],s=(o,n)=>{for(let i of o.childNodes??[]){if(!i.tagName)continue;let r=n||i.tagName==="main"&&ht(i,"doc-page");if(r&&an(i)&&qe(Rt(i,"style")??"")&&e.push(`<${i.tagName}> with style="${Rt(i,"style").trim()}"`),i.tagName==="style"){let c=ft(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,a]of c.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(qe(a))for(let d of l.split(","))cn(d)&&e.push(`"${d.trim()}" in the document's style`)}s(i.tagName==="template"?i.content:i,r)}};return s(t,!1),e}function to(t,{written:e=t}={}){let s=[],o=w(t),n=ln(o);n.length>0&&s.push(`body text given a width of its own (${n.slice(0,3).join("; ")}${n.length>3?`; ${n.length-3} more`:""}): its lines break before the reading column's edge, leaving an extra right margin; let body text fill the column`);for(let i of Xe(o)){let r=i.childNodes.filter(c=>c.tagName);r.forEach((c,l)=>{if(!Ye(c))return;let a=l+1;for(;a<r.length&&sn(r[a]);)a++;let d=r.slice(l+1,a);if(d.length===0||!Ye(r[a]??{})||/^h[1-4]$/.test(d[0].tagName))return;let f=c.childNodes.map(g=>g.tagName?g:null).filter(Boolean).map(ft).find(g=>g.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"",[u]=d,h=ft(u).replace(/\s+/g," ").trim(),m=`<${u.tagName}>${h?` "${h.length>30?`${h.slice(0,30)}\u2026`:h}"`:""}`,p=u.sourceCodeLocation?.startLine;s.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${f}" stand outside it${p?` (line ${p})`:""}, ${d.length===1?`the ${m}`:`the first a ${m}`}, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return s.push(...Ae(t,{written:e})),s}import{attr as eo,hasClass as dn}from"../browser/shared/html-tree.mjs";var oo="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",fn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),hn=["doc-math-inline","doc-math-block"],un=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,pn=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,mn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,gn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,io=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,$n=/\.[A-Za-z0-9]{1,8}$/,wn=[/(?<![A-Za-z0-9_\\])[A-Za-z]:[\\/]/g,/(?<![A-Za-z0-9_.~:/\\-])\/(?:Users|home|root|tmp|private|mnt|opt|Volumes|var\/folders)\/(?=\S)/g,/(?<![A-Za-z0-9_.~:/\\-])~\/(?=\S)/g,/(?<![A-Za-z0-9_$\\])\$(?:HOME|\{HOME\})\/(?=\S)/g,/(?<![A-Za-z0-9_:\\])\\\\[A-Za-z0-9][\w.$-]*\\(?=[^\s\\])/g,/%(?:TEMP|TMP|APPDATA|LOCALAPPDATA|USERPROFILE)%/gi],bn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,kn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,yn=t=>t.includes("://")&&!/^file:/i.test(t),so=12;function no(t,e){let s=e;for(;s<t.length&&!mn.test(t[s])&&!(io.test(t[s])&&$n.test(t.slice(e,s)));)s++;return t.slice(e,s).replace(/[.,;:!?]+$/,"")}function xn(t,e=!1){let s=c=>c.replace(/[^\n]/g," "),o=t.replace(un,s),n=e?o.replace(pn,s):o,i=[],r=(c,l)=>i.some(a=>a.at<=c+l.length&&c<=a.at+a.path.length);for(let c of wn)for(let l of n.matchAll(c)){let a=no(n,l.index);a.length>=l[0].length+2&&!r(l.index,a)&&i.push({at:l.index,path:a})}for(let c of n.matchAll(gn)){let l=c.index;for(;l<c.index+c[0].length&&io.test(n[l]);)l++;let a=no(n,l);/[\\/]/.test(a)&&(bn.test(a)||kn.test(a))&&!yn(a)&&!r(l,a)&&i.push({at:l,path:a})}return i.sort((c,l)=>c.at-l.at)}function ao(t,e=w(t)){let s=[],o=(r,c)=>{for(let l of r.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:a,path:d}of xn(l.value,c))s.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,a).match(/\n/g)?.length??0),path:d})}else l.tagName&&!fn.has(l.tagName)&&eo(l,"hidden")===void 0&&!hn.some(a=>dn(l,a))&&o(l,c||eo(l,"data-doc-math-dollar")!==void 0)};o(e,!1);let n=s.slice(0,so).map(({line:r,path:c})=>`line ${r}: "${c.length>80?`${c.slice(0,77)}\u2026`:c}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${oo}`),i=s.slice(so);return i.length>0&&n.push(`${i.length} more path${i.length===1?"":"s"} of this machine in the text a reader reads, on line${new Set(i.map(({line:r})=>r)).size===1?"":"s"} ${[...new Set(i.map(({line:r})=>r))].join(", ")}. ${oo}`),n}import{elementsOf as ro}from"../browser/shared/html-tree.mjs";import{netSnapshot as Sn}from"../browser/shared/net-cache.mjs";import{hostIn as Nn,netHostsOf as vn}from"../browser/shared/net-policy.mjs";var On=(t,e)=>`<script type="application/json" data-doc-snapshot data-at="${e}">${JSON.stringify(t).replace(/</g,"\\u003c")}</script>`,Ft=t=>t.some(({needs:e})=>Array.isArray(e)&&e.includes("workspace"));function co(t,{slug:e,packages:s,root:o,at:n=new Date,workspace:i=null}){let r=s.flatMap(({needs:f})=>vn(f)),c=r.length===0?null:Sn(o,e,f=>{try{return Nn(new URL(f).hostname,r)!==null}catch{return!1}}),l={...i&&Ft(s)?i:{},...c?{net:c}:{}};if(Object.keys(l).length===0)return t;let a=ro(ro(w(t)).find(f=>f.tagName==="html")??{}).find(f=>f.tagName==="head"),d=a?.sourceCodeLocation?.endTag?.startOffset??a?.sourceCodeLocation?.startTag?.endOffset;return d===void 0?t:`${t.slice(0,d)} ${On(l,n.toISOString())}
7
+ ${t.slice(d)}`}import{MENTION as En,MENTION_ICON as Tn}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Ln}from"../browser/shared/escape.mjs";import{attr as lo,elementsOf as An,hasClass as fo,walk as Cn}from"../browser/shared/html-tree.mjs";import{addressOn as zn,decoded as In,fromFile as jn,hosted as Rn,pageAddress as Fn,workbenchHash as _n}from"../browser/shared/page-address.mjs";function Dn(t,e,s){let o=jn(t,e),n=zn(o,s);return n||Rn(t)?n:Fn(o)??(_n(o)===null?null:{slug:null,block:null})}function Mn(t,e,s,o){let n=w(t),i=new Set,r=[];Cn(n,a=>{let d=lo(a,"data-block-id");d!==void 0&&i.add(d),a.tagName==="a"&&lo(a,"href")!==void 0&&a.sourceCodeLocation?.startTag&&r.push(a)});let c=new Map,l=({startOffset:a,endOffset:d})=>c.set(a,[d,""]);for(let a of r){let{prefix:d,value:f}=a.attrs.find(({name:k})=>k==="href"),u=f.startsWith("#")?In(f.slice(1)):null,h=u===null?f&&Dn(f,e,o):i.has(u)?{slug:e,block:u}:null;if(!h)continue;let m=s(h,f);if(m===f)continue;let{attrs:p,startTag:g,endTag:b}=a.sourceCodeLocation;if(m===null)l(g),b&&l(b),fo(a,En)&&An(a).filter(k=>fo(k,Tn)).forEach(k=>l(k.sourceCodeLocation));else{let k=d?`${d}:href`:"href";c.set(p[k].startOffset,[p[k].endOffset,`${k}="${Ln(m)}"`])}}return[...c].sort(([a],[d])=>d-a).reduce((a,[d,[f,u]])=>`${a.slice(0,d)}${u}${a.slice(f)}`,t)}function ho(t,e,s,{blocks:o=!0,links:n}){return Mn(t,e,({slug:i,block:r})=>{let c=s(i);if(c===null)return null;if(!r||!o)return i===e&&r?null:c;let l=`#${encodeURIComponent(r)}`;return i===e?l:`${c}${l}`},n)}import ut from"node:fs";import Pn from"node:path";import{extensionOf as Un,imageFile as Wn,mediaTypeOf as Bn}from"../browser/shared/media.mjs";var Mt=1024*1024,Hn=Mt,po=2400,_t=2e3,Kn=.25,Gn=new Set(["png","gif"]),uo=.75;function Jn(t){if(t.length<16||t.toString("latin1",0,4)!=="RIFF"||t.toString("latin1",8,12)!=="WEBP")return!1;for(let e=12;e+8<=t.length;){let s=t.toString("latin1",e,e+4);if(s==="VP8L")return!0;if(s==="VP8 "||s==="ANMF")return!1;let o=t.readUInt32LE(e+4);e+=8+o+o%2}return!1}function Vn(t){let e=(s,o)=>s+o<=t.length;if(e(0,24)&&t.readUInt32BE(0)===2303741511&&t.toString("latin1",12,16)==="IHDR")return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(e(0,10)&&/^GIF8[79]a$/.test(t.toString("latin1",0,6)))return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(e(0,4)&&t[0]===255&&t[1]===216){for(let s=2;e(s,4);){if(t[s]!==255)return null;let o=t[s+1];if(o===255){s+=1;continue}if(o===216||o===1||o>=208&&o<=215){s+=2;continue}if(o>=192&&o<=207&&![196,200,204].includes(o))return e(s,9)?{width:t.readUInt16BE(s+7),height:t.readUInt16BE(s+5)}:null;if(o===217||o===218)return null;s+=2+t.readUInt16BE(s+2)}return null}if(e(0,30)&&t.toString("latin1",0,4)==="RIFF"&&t.toString("latin1",8,12)==="WEBP"){let s=t.toString("latin1",12,16);if(s==="VP8 ")return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383};if(s==="VP8L"){let o=t.readUInt32LE(21);return{width:(o&16383)+1,height:(o>>>14&16383)+1}}return s==="VP8X"?{width:t.readUIntLE(24,3)+1,height:t.readUIntLE(27,3)+1}:null}if(e(0,12)&&t.toString("latin1",4,8)==="ftyp"&&/avi[fs]/.test(t.toString("latin1",8,Math.min(t.length,t.readUInt32BE(0))))){let s=null;for(let o=t.indexOf("ispe",0,"latin1");o>=0&&e(o,16);o=t.indexOf("ispe",o+4,"latin1")){let n={width:t.readUInt32BE(o+8),height:t.readUInt32BE(o+12)};(!s||n.width*n.height>s.width*s.height)&&(s=n)}return s}return null}var Zn=Mt;function Yn(t){let e;try{e=ut.openSync(t,"r");let{size:s}=ut.fstatSync(e),o=Buffer.alloc(Math.min(s,Zn));return ut.readSync(e,o,0,o.length,0),{length:s,head:o}}catch{return null}finally{e!==void 0&&ut.closeSync(e)}}var j=t=>`${Math.max(.1,t/Mt).toFixed(1)} MB`;function qn({bytes:t,width:e,height:s,extension:o,lossless:n}){let i=Math.max(e,s),r=Math.min(1,_t/i),c=Math.min(t,e*s*r*r*Kn);if(i>po){if(!n)return c<=t*uo?` \u2014 a ${_t}px copy would be about ${j(c)}`:"";let l=t*r*r;return` \u2014 a ${_t}px copy would be about ${j(l)}${o==="png"&&c<l/2?`, or ${j(c)} as a JPEG (for a photograph)`:""}`}return!n&&c<=t*uo?` \u2014 written again as a JPEG of quality about 82, it would be about ${j(c)}`:o==="png"&&c<t/2?` \u2014 as a JPEG (for a photograph) it would be about ${j(c)}`:""}var Dt=t=>t===2?"twice":`${t} times`;function mo({html:t,directory:e,tree:s=w(t)}){let{embedded:o,unserved:n}=le({html:t,directory:e,tree:s}),i=new Map,r=(l,a,d,f=!1)=>{let u=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);u.at.push(a),f||(u.shows+=1)};for(let{file:l,line:a,icon:d}of o)Wn(l)&&r(l,a,!0,d);for(let{file:l,line:a}of n)Bn(l).startsWith("image/")&&r(l,a,!1);let c=[];for(let[l,{at:a,shows:d,served:f}]of[...i].sort(([,u],[,h])=>Math.min(...u.at)-Math.min(...h.at))){let u=Yn(Pn.join(e,l));if(!u)continue;let{length:h,head:m}=u,p=Vn(m),g=p?Math.max(p.width,p.height):0,b=h>Hn||g>po,k=f&&d>1;if(!b&&!k)continue;let x=[...new Set(a)],v=`line${x.length===1?"":"s"} ${x.length>1?`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`:x[0]}`,T=k?`shown ${Dt(d)}: the export embeds it ${Dt(d)}; show it once and refer back to it in words`:"";if(!b){c.push(`${l} (${v}): ${T} (${j(Math.ceil(h/3)*4*d)} as data: URLs)`);continue}let H=a.length===1||!f?"":`, ${Dt(a.length)}`,R=f?a.length:1,q=`${j(Math.ceil(h/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,Uo=p?`, ${p.width}\xD7${p.height}px`:"",Kt=Un(l),Gt=p?qn({bytes:h,...p,extension:Kt,lossless:Gn.has(Kt)||Jn(m)}):"",Wo=f?`the export embeds it as it is${H}, ${q}${Gt}`:`its name keeps it out of the preview and the export (the failure at its line says why); copied into assets/ under a name they take, the export embeds it as it is, ${q}${Gt}: copy it in at the size the page needs`;c.push(`${l} (${v}): ${j(h)}${Uo}; ${Wo}${T?`; ${T}`:""}`)}return c}import{COMPONENTS as ui}from"../browser/shared/components/index.mjs";import{withLook as pi}from"../browser/shared/document-look.mjs";import{reportsDirectory as mi}from"../browser/shared/paths.mjs";import{documentLook as gi}from"../browser/shared/workspace-look.mjs";import go from"node:fs";import{MENTION as $o,MENTION_ICON as wo}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Xn,escapeText as Qn}from"../browser/shared/escape.mjs";import{iconUrl as ti,validIcon as ei}from"../browser/shared/emoji/icon-value.mjs";import{attr as oi,hasClass as si,walk as ni}from"../browser/shared/html-tree.mjs";import{fromFile as ii,isFileLink as ai,pageAddress as ri}from"../browser/shared/page-address.mjs";import{reportsDirectory as ci}from"../browser/shared/paths.mjs";import{documentDirectory as li,documentFiles as di}from"../browser/shared/workspace.mjs";function fi(t,e){let{html:s,json:o}=di(li(t,e));if(!go.existsSync(s))return null;try{let{title:n,icon:i}=JSON.parse(go.readFileSync(o,"utf8"));return{title:n,icon:i}}catch{return{}}}function hi(t,e,s,o){if(s==="words"||typeof t!="string"||!ei(t))return null;if(s==="preview")return ti(t,e,{tab:!0});let n=Qt({value:t,slug:e,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${n.body.toString("base64")}`}function bo(t,{slug:e,mode:s="export",reportsDirectory:o=ci}){if(!t.includes($o))return t;let n=new Map,i=c=>(n.has(c)||n.set(c,fi(c,o)),n.get(c)),r=new Map;return ni(w(t),c=>{let l=c.tagName==="a"&&si(c,$o)?oi(c,"href"):void 0,{startTag:a,endTag:d}=c.sourceCodeLocation??{};if(!l||!ai(l)||!a||!d)return;let f=ri(ii(l,e))?.slug;if(!f)return;let u=i(f);if(!u)r.set(a.endOffset-1,[a.endOffset-1," data-doc-gone"]);else if(u.title){let h=hi(u.icon,f,s,o);r.set(a.endOffset,[d.startOffset,`${h?`<img class="${wo}" src="${Xn(h)}" alt="">`:`<span class="${wo}"></span>`}${Qn(u.title)}`])}}),[...r].sort(([c],[l])=>l-c).reduce((c,[l,[a,d]])=>`${c.slice(0,l)}${d}${c.slice(a)}`,t)}var $i=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function wi(t,e,s){let o=Vt(e).filter(({id:n})=>!s.some(i=>i.id===n)).map(Zt).join(" ");return o?t.replace($i,n=>`${n}
8
+ <script data-doc-dev>${o}</script>`):t}var ko=/(<title\b[^>]*>)\s*(<\/title>)/i;function bi(t){if(!ko.test(t))return t;let e=/^en\b/i.test(/<html\b[^>]*\slang=["']?([^"'\s>]*)/i.exec(t)?.[1]??"");return t.replace(ko,(s,o,n)=>`${o}${e?"Untitled":"\u672A\u547D\u540D\u6587\u6863"}${n}`)}function Pt(t,{slug:e,mode:s="export",files:o=!0,reportsDirectory:n,kit:i}){let{html:r,removed:c}=ki(t,{reportsDirectory:n,kit:i,describe:s==="preview"}),l={slug:e,mode:s,...n?{reportsDirectory:n}:{}},a=te(pi(r,gi(e,n??mi)),l),d=o?de(oe(ne(ae(a,l),l),l),l):a;return{html:bi(bo(d,l)),removed:c}}function ki(t,{reportsDirectory:e,kit:s,page:o=!1,describe:n=!1}){let i=E(e),r=L(t,i),{html:c,removed:l,used:a}=ue(t,[...ui,...r]),d=xe(pe(c,{used:a,page:o,...s?{href:s}:{}}),r);return{html:n?wi(d,i,r):d,removed:l,packages:r}}import{exportsDirectory as Wt,generatedDirectory as Y,kitPublicDirectory as Ci,release as zi,reportsDirectory as I,vendorDirectory as Ii}from"../browser/shared/paths.mjs";import{referencedFile as ji}from"../browser/shared/media.mjs";import{decoded as Ri,fromFile as Fi,hashAddress as _i,hosted as Co,pageAddress as Di,workbenchHash as Mi}from"../browser/shared/page-address.mjs";import{pageLinks as Pi}from"../browser/shared/page-links.mjs";import{documentLinks as Ui,listReportSlugs as Wi}from"../browser/shared/reports.mjs";import{documentDirectory as B,documentFiles as Ht}from"../browser/shared/workspace.mjs";import{sha256 as pt}from"../browser/shared/files.mjs";import{EXPORT_CSP as Bi,GENERATOR as Hi,isolateUmd as Ki,packagesMeta as Gi,sourceMeta as Ji}from"../browser/shared/export-wrap.mjs";var vo=/__REPORT_[A-Z_]+__/,Oo=1e6,Eo=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function Vi(t){return t.map(({id:e,lines:s,columns:o})=>{let n=new Set(s).size<s.length,i=s.map((r,c)=>n?`${r}:${o[c]}`:`${r}`);return`data-block-id repeats: "${e}" on lines ${Eo(i)}${n?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${Eo(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var Zi=({slug:t,htmlPath:e,metadataPath:s})=>{let o=e?{html:e,json:s??e.replace(/\.html$/,".json")}:Ht(B(t,I));return{htmlName:N.basename(o.html),jsonName:N.basename(o.json)}};function Yi({slug:t,html:e,metadata:s,htmlPath:o,metadataPath:n,tree:i=w(e)}){let r=[],{htmlName:c,jsonName:l}=Zi({slug:t,htmlPath:o,metadataPath:n}),a=/<h1\b[^>]*\bclass="[^"]*\bdoc-title\b[^"]*"[^>]*>\s*<\/h1>/i.test(e),d=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[a?/<title>\s*<\/title>|<title>[^<]+<\/title>/i:/<title>[^<]+<\/title>/i,"missing document title"],[/<main(?:\s|>)/i,"missing semantic main element"],[/aria-label|aria-labelledby|<title>/i,"missing accessible labels"]];for(let[p,g]of d)p.test(e)||r.push(g);let f=Buffer.byteLength(e);f>Oo&&r.push(`the document's editable source is ${f.toLocaleString("en-US")} bytes, over the ${Oo.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),vo.test(e)&&r.push(`${c} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,g]of Object.entries(s))typeof g=="string"&&vo.test(g)&&r.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(e)&&r.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let u=new Map;M(i,p=>{let g=O(p,"data-block-id"),b=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;g!==void 0&&u.set(g,[...u.get(g)??[],{line:b?.startLine,column:b?.startCol}])});let h=[...u].filter(([,p])=>p.length>1);r.push(...Vi(h.map(([p,g])=>({id:p,lines:g.map(({line:b})=>b),columns:g.map(({column:b})=>b)}))));let m=null;if(M(i,p=>{!m&&p.tagName==="main"&&(m=p)},{inTemplates:!1}),m){let p=O(m,"data-doc-id");p===void 0?r.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&r.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return r}var zo=t=>So(So(t).find(e=>e.tagName==="html")??{}).find(e=>e.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Bt=new Set(["localStorage","sessionStorage"]);function Io(t){let e=[],s=[];return M(t,o=>{o.tagName==="script"&&O(o,"src")!==void 0&&e.push(O(o,"src")),(o.tagName==="link"?(O(o,"rel")??"").toLowerCase().split(/\s+/):[]).includes("stylesheet")&&O(o,"href")!==void 0&&s.push(O(o,"href"))}),{scripts:e,styles:s}}function jo({slug:t,html:e,directory:s=B(t,I),tree:o=w(e),uses:n=Q(e,X,{tree:o}),catalog:i}){let r=[];zo(o)===void 0&&r.push("the page writes no <head> start tag, which an export puts its Content-Security-Policy right after: write <head> \u2026 </head> before <body>");let c=[];M(o,d=>{if(["script","link","img"].includes(d.tagName))for(let f of["src","href"]){let u=O(d,f)?.trim();u&&/^https?:\/\//i.test(u)&&c.push(u)}}),c.length>0&&r.push(`external resources are not portable: ${c.join(", ")}`);for(let{name:d,how:f,line:u,where:h}of n){if(!X.has(d))continue;let m={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[f]??`uses ${d}`;r.push(`line ${u}: ${h} ${m}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:a}=Io(o);for(let d of l)we.has(d)||r.push(`unsupported script dependency ${d}`);for(let d of a)be.has(d)||r.push(`unsupported stylesheet dependency ${d}`);return r.push(...re({html:e,directory:s,tree:o}),...ie({html:e,directory:s,tree:o}),...se({html:e,directory:s,tree:o}),...ce({html:e,directory:s,tree:o})),r.push(...Se(L(e,i,o))),[...new Set(r)]}var qi=[[/\bDocSheets\.mount\s*\(/,"Sheet areas start on their own: remove DocSheets.mount (an area keeps its tab under its data-doc-sheets name)"],[/\bDocCode\.(?:View|DiffView|DiffStats|enhance)\b/,'code blocks are highlighted on their own, and a diff is declared as <div class="doc-diff"> holding { path, lines } as JSON (sdk/doc-code.d.ts)'],[/\bDocTables\.(?:enhance|enhanceAll|makeSortable)\b/,"tables start on their own: remove the call"],[/\bDocDialogs\.(?:enhance|enhanceAll)\b/,"detail cards start on their own: remove the call"]];function Xi({html:t,tree:e=w(t),uses:s=Q(t,Bt,{tree:e})}){let o=ke(t,e),n=[...me(t,e),...ge(t,e)];for(let[i,r]of qi)i.test(o)&&n.push(`${o.match(i)[0].replace(/\s*\($/,"")} is gone: ${r}`);for(let{name:i,line:r,where:c}of s)Bt.has(i)&&n.push(`line ${r}: ${c} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(n)]}var Qi=(t,e)=>e.childNodes.find(s=>s.tagName||s.nodeName==="#text"&&s.value.trim())===t,ta=t=>xo(t,Ni("highlight").match)||t.tagName==="li"&&xo(t.parentNode,`ol.${vi}`),ea=`an icon is one of three kinds: an emoji, <div class="doc-icon">\u{1F3AF}</div>; an icon of Gallery's sets in one of ${No.length} colors, <div class="doc-icon" data-icon="/icons/airplane_blue.svg"></div> (MingCute's names; Tabler's as /icons/tabler/plane_blue.svg; the colors ${No.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,Ro=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Ro).join("");function To(t,e,s){let o=e.sourceCodeLocation?.attrs?.[s],n=o?t.slice(o.startOffset,o.endOffset):`${s}="${O(e,s)??""}"`;return n.length>72?`${n.slice(0,71)}\u2026`:n}function oa(t,e){let s=O(e,"data-icon");if(s!==void 0)return{held:To(t,e,"data-icon"),meant:Ut(s)==="glyph"?s:null};let o=null;if(M(e,i=>{o??=["img","svg"].includes(i.tagName)?i:null}),o?.tagName==="img"){let i=O(o,"src");return{held:`<img ${To(t,o,"src")}>`,meant:Ut(i)==="image"?i:null}}if(o)return{held:"an <svg>"};let n=Ro(e).replace(/\s+/g," ").trim();return{held:n?`"${n.slice(0,40)}"`:"nothing"}}function sa({set:t,name:e,color:s}){let o=Oi.find(r=>r!==t);if(gt(o).includes(e))return`; "${e}" is ${o==="tabler"?"Tabler":"MingCute"}'s: ${Ti(o,e,s)}`;let n=e.split("-").filter(r=>r.length>=3),i=gt(t).filter(r=>r.split("-").some(c=>n.includes(c))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function na({html:t,tree:e=w(t)}){let{all:s,own:o}=ee(e),n=[],i=r=>r.sourceCodeLocation?.startLine;o.length>1&&n.push(`line ${i(o[1])}: ${o.length} page icons (.doc-icon) in the header (the first at line ${i(o[0])}): a document has one, right before its title`);for(let r of s){let c=i(r),l=r.parentNode;!o.includes(r)&&!(ta(l)&&Qi(r,l))&&n.push(`line ${c}: an icon (.doc-icon) stands only right before the document's title, first in a highlight block (.doc-panel, .doc-summary), or first in a flowchart's step (ol.doc-flow > li, in its number's place)`);let a=Ai(Yt(t,r)),{held:d,meant:f}=a?{}:oa(t,r);f?n.push(`line ${c}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Li(f)}`):a?Ut(a)==="glyph"&&!Xt(a)&&n.push(`line ${c}: the icon ${a} is none of the icon sets' (MingCute: /icons/<name>_<color>.svg, Tabler: /icons/tabler/<name>_<color>.svg; src/shared/emoji/data/icons.json lists the names of each)${sa(Ei(a))}`):n.push(`line ${c}: an icon (.doc-icon) holds no icon (it holds ${d}): ${ea}`)}return[...new Set(n)]}function Fo(t){let e=w(t.html),s={...t,tree:e,uses:Q(t.html,new Set([...X,...Bt]),{tree:e})};return[...Yi(s),...At(t.html,e),...Xi(s),...na(s),...jo(s)]}function ia(t){let e=new Map(t.map(n=>[n.slug,[...Fo(n),...vt(n.html)]])),s=new Map(t.map(n=>[N.resolve(n.htmlPath),n.slug])),o=new Map(t.map(n=>[N.resolve(n.htmlPath),n]));for(let n of t)n.scriptNotes=[];if(t.length>0)for(let{htmlPath:n,text:i,typeOnly:r,note:c}of ye(t)){if(r){o.get(n)?.scriptNotes.push(c);continue}let l=n?[s.get(n)]:[...e.keys()];for(let a of l)e.get(a).push(n?i:`${i} (shared SDK declaration)`)}for(let[n,i]of e)i.length===0&&e.delete(n);return e}async function Ic(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let n of s){let i=[...Fo(n),...vt(n.html)];i.length&&o.set(n.slug,i)}return o}async function aa(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let[n,i]of ia(s))o.set(n,i);return{reports:s,failures:o}}async function ra({fresh:t=!1,kit:e=Ci,vendor:s=Ii}={}){if(zi)return;let o=K.map(r=>[r,r.file?jt(r.file,{fresh:t}):bt(r)]);await S.mkdir(e,{recursive:!0});let n=N.join(s,"katex","fonts");await S.mkdir(n,{recursive:!0});let i=(await S.readdir(wt)).filter(r=>r.endsWith(".woff2"));await Promise.all(i.map(r=>S.copyFile(N.join(wt,r),N.join(n,r)))),await Promise.all(o.map(async([r,c])=>S.writeFile(r.file?N.join(e,r.file):N.join(s,...r.vendor.path.split("/").slice(2)),await c)))}async function ca(t,e){let s=await S.readdir(t).catch(()=>[]);await Promise.all(s.filter(o=>o.endsWith(".html")&&!e.has(o.slice(0,-5))).map(o=>S.rm(N.join(t,o),{force:!0})))}async function la(t){let e=N.join(Y,"reports.json"),s=await S.readFile(e,"utf8").then(JSON.parse,()=>[]),o=new Map(Array.isArray(s)?s.map(i=>[i.slug,i]):[]);for(let{entry:i}of t)o.set(i.slug,i);let n=[];for(let[i,r]of[...o].sort(([c],[l])=>c.localeCompare(l))){let c=N.join(Y,`${i}.html`);await S.stat(c).then(()=>!0,()=>!1)&&n.push(r)}await S.writeFile(e,`${JSON.stringify(n,null,2)}
9
+ `)}async function da(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await aa(t,{prepare:e});await ra(),await S.mkdir(Y,{recursive:!0}),await ca(Y,new Set(await Wi()));let n=[];for(let i of s){let r=`${i.slug}.html`,c=N.join(Y,r);if(o.has(i.slug)){await S.rm(c,{force:!0});continue}let{html:l,removed:a}=Pt(i.html,{slug:i.slug});await S.writeFile(c,l),n.push({report:i,html:l,removed:a,entry:{slug:i.slug,...i.metadata,preview:`/generated/${r}`,sourceSha256:pt(i.html),outputSha256:pt(l)}})}return await la(n),{built:n,failures:o}}var fa=t=>t.replace(/<\/script/gi,"<\\/script");async function _o(){return new Map(await Promise.all(K.map(async t=>{let e=await(t.file?jt(t.file):bt(t,{inline:!0}));return he(t).endsWith(".css")||(e=fa(e)),[t.id,t.umd?Ki(e):e]})))}function ha(t,e,s=null,o=[]){let n=zo(w(e));if(n===void 0)throw new Error(`${t}: the page writes no <head> start tag, which the export's Content-Security-Policy goes right after`);let i=s?`
10
+ ${Ji(s)}${o.length>0?`
11
+ ${Gi(o)}`:""}`:"";return`${e.slice(0,n)}
12
+ <meta name="generator" content="${Hi}">
13
+ <meta http-equiv="Content-Security-Policy" content="${Bi}">${i}${e.slice(n)}`}function Do(t,e,s,o=null,n=E(),i=I,r=null){let c=L(e,n);e=co(ha(t,e,o,c),{slug:t,packages:c,root:i,workspace:r}),e=$e(Ne(e,n),({id:d,element:f,attribute:u})=>{let h=s.get(d);if(typeof h!="string")throw new Error(`${t}: no inline source for the asset "${d}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${f} ${u}="${d}-inline">${h}</${f}>`});let{scripts:l,styles:a}=Io(w(e));if(l.length+a.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return e}async function Lo(t,e=I,{components:s=!0}={}){let o=B(t,e),n=await S.readFile(Ht(o).html),i=n.toString("utf8"),r=w(i),c=s?E(e):{packages:new Map},l=[...s?At(i,r,c):[],...jo({slug:t,html:i,directory:o,tree:r,catalog:c})];if(l.length>0){let a=L(i,c,r).find(({id:d})=>l[0].startsWith(`${d}:`)||l[0].startsWith(`${d} (`))?.id;throw Object.assign(new Error(`${t}: ${l[0]}`),{reason:"check",slug:t,failures:l,...a?{component:a}:{}})}return{html:i,sha256:pt(n)}}async function jc({directory:t=I,workspace:e=null}={}){let s=await _o(),o=async(n,{files:i=!0}={})=>{let r=await Lo(n,t),c=Pt(r.html,{slug:n,files:i,reportsDirectory:t}).html,l=E(t);return Do(n,c,s,r.sha256,l,t,await Mo(e,n,c,l))};return o.check=async n=>{await Lo(n,t,{components:!1})},o}async function Mo(t,e,s,o){return typeof t!="function"||!Ft(L(s,o))?null:await t(e).catch(()=>null)??null}async function Rc(t=[],{prepare:e=null,workspace:s=null}={}){let{built:o,failures:n}=await da(t,{prepare:e}),i=await _o();await S.mkdir(Wt,{recursive:!0});let r=new Set(o.map(({report:a})=>a.slug)),{links:c}=await Ui(),l=[];for(let{report:a,html:d}of o)try{let f=ho(d,a.slug,h=>r.has(h)?`${h}.html`:null,{links:c}),u=Do(a.slug,f,i,a.fileSha256,E(),I,await Mo(s,a.slug,f,E()));await S.writeFile(N.join(Wt,`${a.slug}.html`),u),l.push({slug:a.slug,bytes:Buffer.byteLength(u),sha256:pt(u)})}catch(f){n.set(a.slug,[f.message])}return{built:o,exported:l,failures:n}}function Ao(t){let e=new Set;return M(t,s=>{for(let o of["id","data-block-id"])O(s,o)!==void 0&&e.add(O(s,o))}),e}function ua(t,e,s){if(Co(t)||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(t)||ji(t))return!1;let{pathname:o}=new URL(e);return!o.startsWith(`/${s}/`)||o.endsWith(".html")}function pa({slug:t,tree:e,directory:s}){let o=[],n=Ao(e),i=s===B(N.basename(s),I)?I:N.dirname(s),r=new Map([[t,n]]),c=d=>{if(!r.has(d)){let f=Ht(B(d,i));r.set(d,yo(f.html)?Ao(w(yi(f.html,"utf8"))):null)}return r.get(d)},l=null,a=(d,f)=>f===null?Di(d):_i(f,l??=Pi((yo(i)?xi(i):[]).map(u=>({slug:u}))));return M(e,d=>{let f=d.tagName==="a"?O(d,"href"):void 0;if(!f||f==="#"||f==="#top")return;let u=d.sourceCodeLocation?.startLine;if(f.startsWith("#")){n.has(Ri(f.slice(1)))||o.push(`the link to ${f} (line ${u}) names no block or element of this document`);return}let h=Fi(f,t),m=Mi(h),p=a(h,m);(p?!c(p.slug):m!==null)?Co(f)||o.push(`the link to ${f} (line ${u}) names a document that is not there: gallery list has the slugs`):p?.block&&!c(p.slug).has(p.block)?o.push(`the link to ${f} (line ${u}) names a block document ${p.slug} does not hold`):h&&!p&&ua(f,h,t)&&o.push(`the link to ${f} (line ${u}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},Si),o}function Po({slug:t,html:e,directory:s=B(t,I),written:o=e,scriptNotes:n=[]}){let i=w(e),r=ze(e);return{fix:[...ao(e,i),...mo({html:e,directory:s,tree:i})],notes:[...to(e,{written:o}),...Be(i),...pa({slug:t,tree:i,directory:s}),...r.notes,...n],readings:r.readings}}function Fc(t){let{fix:e,notes:s}=Po(t);return[...e,...s]}function _c(t){let e=t.map(s=>[s.slug,Po(s)]);for(let[s,{fix:o}]of e)for(let n of o)console.log(`fix ${s}: ${n}`);for(let[s,{notes:o}]of e)for(let n of o)console.log(`note ${s}: ${n}`);for(let[s,{readings:o}]of e)for(let n of o)console.log(`chart ${s}: ${n}`)}async function ma(t,{exportNote:e=!1}={}){for(let[s,o]of t){console.error(`
14
+ FAIL ${s}: ${o.length} problem${o.length===1?"":"s"}`);for(let i of o)console.error(` - ${i}`);let n=N.join(Wt,`${s}.html`);e&&await S.stat(n).then(()=>!0,()=>!1)&&console.error(` ${n} was not updated; it still holds an earlier export.`)}}function ga(t,{above:e=!1,allow:s=process.argv.includes("--allow-failures")}={}){t.size!==0&&(console.error(`
15
+ ${t.size} document${t.size===1?"":"s"} failed: ${[...t.keys()].join(", ")}${e?" (the failures are listed first, above)":""}`),s||(process.exitCode=1))}async function Dc(t,{exportNote:e=!1,allow:s}={}){await ma(t,{exportNote:e}),ga(t,{allow:s})}export{Ts as a,Mn as b,ho as c,bo as d,Pt as e,ki as f,Vi as g,jo as h,Fo as i,ia as j,Ic as k,aa as l,ra as m,da as n,ha as o,jc as p,Rc as q,Po as r,Fc as s,_c as t,ma as u,ga as v,Dc as w};
@@ -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{b as p,e as L}from"./chunk-A55HN5OK.mjs";L();import{TODO as b}from"../browser/shared/components/list.mjs";import{sha256 as k}from"../browser/shared/files.mjs";import{attr as u,BLOCK_LEVEL as N,elementsOf as O,hasClass as h}from"../browser/shared/html-tree.mjs";var w=new Set(["script","style","template","noscript","svg","math"]),y=/^h([1-6])$/,C=o=>o.replace(/[\s​]+/g," ").trim();function f(o,a=()=>!1){let n="",t=c=>{for(let s of c.childNodes??[])s.nodeName==="#text"?n+=s.value:s.tagName==="br"?n+=" ":s.tagName&&!w.has(s.tagName)&&!a(s)&&t(s)};return t(o),C(n)}function E(o){let a=f(o,t=>N.has(t.tagName));if(a)return a;let n=O(o).find(t=>N.has(t.tagName)&&t.tagName!=="ul"&&t.tagName!=="ol");return n?f(n,t=>t.tagName==="ul"||t.tagName==="ol"):""}function P(o,{at:a=!1}={}){let n=p(String(o),{sourceCodeLocationInfo:a}),t=[],c=[],s=new Map,l=v=>{for(let e of O(v)){if(w.has(e.tagName))continue;let m=y.exec(e.tagName);if(m&&!h(e,"doc-title")){let i=Number(m[1]);for(;t.length&&t.at(-1).level>=i;)t.pop();let r=f(e);r&&t.push({level:i,words:r});continue}if(e.tagName==="li"&&e.parentNode?.tagName==="ul"&&h(e.parentNode,b)){let i=t.map(({words:x})=>x),r=E(e),d=JSON.stringify([r,i]),g=s.get(d)??0;s.set(d,g+1),c.push({text:r,done:u(e,"data-checked")!==void 0,block:u(e,"data-block-id")??null,path:i,nth:g,...a?{at:e.sourceCodeLocation?.startOffset??-1}:{}})}l(e)}};return l(n),c}var V=o=>k(o).slice(0,16);export{P as a,V as b};
@@ -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 n from"node:path";import{reportsDirectory as s}from"../browser/shared/paths.mjs";import{readWritingPreferences as i,saysAnything as l}from"../browser/shared/writing-preferences.mjs";var r=e=>n.resolve(e);async function d({reading:e=!1}={}){let{file:t,text:a,made:o}=await i(s);return[`\u5DE5\u4F5C\u533A\uFF1A${n.resolve(s)}`,l(a)?`\u5199\u4F5C\u504F\u597D\uFF1A\u5148\u8BFB\u5B83\uFF0C\u7167\u5B83\u5199\uFF08${r(t)}${o?"\uFF0C\u8FD9\u6B21\u6309\u9ED8\u8BA4\u7684\u5199\u4F5C\u504F\u597D\u65B0\u5EFA":""}\uFF09`:`\u5199\u4F5C\u504F\u597D\uFF1A\u7A7A\uFF08${r(t)}\uFF09`,...o&&e?[`Made now: ${r(t)} was not in the workspace, and gallery list makes it from Gallery's defaults the first time it finds none, as gallery new and gallery import do; it changes no document. It is the user's to change, never yours, and it is for documents: a custom page has no \u5199\u4F5C\u504F\u597D.`]:[]]}export{r as a,d as b};