@heycys/gallery 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/components/columns/page.mjs +4 -4
  3. package/browser/editor/components/embed/index.mjs +2 -2
  4. package/browser/editor/components/flowchart/add.mjs +7 -6
  5. package/browser/editor/components/flowchart/page.mjs +1 -1
  6. package/browser/editor/components/icons.mjs +8 -0
  7. package/browser/editor/components/image/crop.mjs +6 -9
  8. package/browser/editor/components/installed/index.mjs +11 -4
  9. package/browser/editor/components/installed/page.mjs +27 -16
  10. package/browser/editor/components/installed/served.mjs +6 -5
  11. package/browser/editor/components/instances.mjs +18 -0
  12. package/browser/editor/components/list/page.mjs +3 -6
  13. package/browser/editor/components/registry.mjs +13 -4
  14. package/browser/editor/components/table/index.mjs +59 -2
  15. package/browser/editor/components/table/page.mjs +1 -1
  16. package/browser/editor/page/annotate/card.mjs +3 -6
  17. package/browser/editor/page/autosave.mjs +310 -37
  18. package/browser/editor/page/board/client.mjs +57 -0
  19. package/browser/editor/page/board/hint.mjs +145 -0
  20. package/browser/editor/page/board/history.mjs +119 -0
  21. package/browser/editor/page/board/index.mjs +970 -0
  22. package/browser/editor/page/board/settings.mjs +209 -0
  23. package/browser/editor/page/caret.mjs +1 -1
  24. package/browser/editor/page/changes/bar.mjs +6 -14
  25. package/browser/editor/page/changes/index.mjs +2 -2
  26. package/browser/editor/page/clipboard/import/html.mjs +29 -6
  27. package/browser/editor/page/clipboard/import/inline.mjs +32 -0
  28. package/browser/editor/page/clipboard/import/markdown.mjs +58 -13
  29. package/browser/editor/page/clipboard/import/read.mjs +6 -1
  30. package/browser/editor/page/clipboard/import/to-blocks.mjs +44 -12
  31. package/browser/editor/page/clipboard/import/yuque.mjs +622 -0
  32. package/browser/editor/page/clipboard/index.mjs +124 -13
  33. package/browser/editor/page/clipboard/own/blocks.mjs +11 -11
  34. package/browser/editor/page/clipboard/own/chart-keys.mjs +41 -28
  35. package/browser/editor/page/clipboard/own/selection.mjs +1 -1
  36. package/browser/editor/page/columns/index.mjs +48 -46
  37. package/browser/editor/page/commit.mjs +80 -22
  38. package/browser/editor/page/conflicts.mjs +7 -7
  39. package/browser/editor/page/core.mjs +31 -15
  40. package/browser/editor/page/custom-page.mjs +106 -0
  41. package/browser/editor/page/editor.mjs +51 -14
  42. package/browser/editor/page/emoji-picker/styles.mjs +7 -12
  43. package/browser/editor/page/emoji-picker/upload.mjs +2 -2
  44. package/browser/editor/page/handle/index.mjs +5 -8
  45. package/browser/editor/page/history.mjs +24 -4
  46. package/browser/editor/page/links/index.mjs +5 -3
  47. package/browser/editor/page/links/pages.mjs +27 -9
  48. package/browser/editor/page/look.mjs +54 -3
  49. package/browser/editor/page/margin.mjs +18 -3
  50. package/browser/editor/page/media-menu/index.mjs +6 -7
  51. package/browser/editor/page/menu.mjs +18 -7
  52. package/browser/editor/page/notices.mjs +2 -2
  53. package/browser/editor/page/page-objects.mjs +13 -2
  54. package/browser/editor/page/panel.mjs +4 -9
  55. package/browser/editor/page/present-links.mjs +11 -2
  56. package/browser/editor/page/resize/index.mjs +42 -29
  57. package/browser/editor/page/served.mjs +14 -0
  58. package/browser/editor/page/session.mjs +48 -4
  59. package/browser/editor/page/slash-menu/index.mjs +3 -3
  60. package/browser/editor/page/table/cells.mjs +102 -46
  61. package/browser/editor/page/table/icons.mjs +2 -0
  62. package/browser/editor/page/table/index.mjs +29 -10
  63. package/browser/editor/page/table/pictures.mjs +299 -0
  64. package/browser/editor/page/table/views.mjs +150 -0
  65. package/browser/editor/page/text-select/index.mjs +26 -12
  66. package/browser/editor/page/todo-writes.mjs +75 -0
  67. package/browser/editor/page/typing/index.mjs +53 -3
  68. package/browser/editor/page/ui.mjs +13 -0
  69. package/browser/shared/block-packs.mjs +404 -0
  70. package/browser/shared/board-places.mjs +224 -0
  71. package/browser/shared/card-size.mjs +59 -0
  72. package/browser/shared/colors.mjs +3 -2
  73. package/browser/shared/component-catalog.mjs +323 -46
  74. package/browser/shared/component-source.mjs +37 -0
  75. package/browser/shared/components/index.mjs +12 -3
  76. package/browser/shared/components/installed.mjs +35 -3
  77. package/browser/shared/components/page.mjs +18 -8
  78. package/browser/shared/components/state.mjs +5 -1
  79. package/browser/shared/document-look.mjs +10 -5
  80. package/browser/shared/drafts.mjs +432 -0
  81. package/browser/shared/extension-sidebar.mjs +126 -0
  82. package/browser/shared/extensions.mjs +79 -0
  83. package/browser/shared/file-table.mjs +101 -0
  84. package/browser/shared/i18n/en.mjs +307 -27
  85. package/browser/shared/json-layout.mjs +47 -0
  86. package/browser/shared/net-cache.mjs +133 -0
  87. package/browser/shared/net-keys.mjs +32 -0
  88. package/browser/shared/net-policy.mjs +177 -0
  89. package/browser/shared/outline-shape.mjs +128 -0
  90. package/browser/shared/outline.mjs +331 -67
  91. package/browser/shared/pack-manifest.mjs +77 -0
  92. package/browser/shared/page-address.mjs +6 -3
  93. package/browser/shared/page-cards.mjs +308 -0
  94. package/browser/shared/page-links.mjs +69 -6
  95. package/browser/shared/pages.mjs +388 -0
  96. package/browser/shared/paths.mjs +6 -0
  97. package/browser/shared/preview-server.mjs +3 -7
  98. package/browser/shared/session.mjs +8 -1
  99. package/browser/shared/shipped-blocks.mjs +299 -0
  100. package/browser/shared/table-chart.mjs +33 -1
  101. package/browser/shared/todos.mjs +83 -0
  102. package/browser/shared/user-directory.mjs +24 -0
  103. package/browser/shared/versions.mjs +14 -0
  104. package/browser/shared/web-links.mjs +134 -0
  105. package/browser/shared/workspace-columns.mjs +120 -0
  106. package/browser/shared/workspace-name.mjs +154 -0
  107. package/browser/shared/workspace-query.mjs +125 -0
  108. package/browser/shared/workspace-registry.mjs +272 -0
  109. package/browser/shared/workspace.mjs +171 -20
  110. package/dist/chunk-2NRBY6AJ.mjs +2 -0
  111. package/dist/chunk-32ZUEFZ7.mjs +2 -0
  112. package/dist/chunk-35NQ4PLQ.mjs +2 -0
  113. package/dist/chunk-3KJHLHUO.mjs +2 -0
  114. package/dist/chunk-3NJACR4W.mjs +2 -0
  115. package/dist/chunk-4AV456RQ.mjs +2 -0
  116. package/dist/chunk-4OZWXZE5.mjs +5 -0
  117. package/dist/chunk-5XYHDBJ5.mjs +2 -0
  118. package/dist/chunk-5ZJA7CXT.mjs +2 -0
  119. package/dist/chunk-6A53MZYZ.mjs +2 -0
  120. package/dist/chunk-6EXH3ORZ.mjs +166 -0
  121. package/dist/chunk-6EZ7FNIK.mjs +3 -0
  122. package/dist/{chunk-V5JTW2LH.mjs → chunk-6QBHU4DF.mjs} +1 -1
  123. package/dist/{chunk-Y6RLRPG3.mjs → chunk-6VTU6KEO.mjs} +1 -1
  124. package/dist/chunk-B4P2CM2J.mjs +3 -0
  125. package/dist/{chunk-FDLXYYG4.mjs → chunk-BPL64HGA.mjs} +1 -1
  126. package/dist/chunk-BVEFGE4B.mjs +2 -0
  127. package/dist/{chunk-LS4F7JUM.mjs → chunk-BZ5RAF7L.mjs} +1 -1
  128. package/dist/chunk-CRJEG7MT.mjs +2 -0
  129. package/dist/{chunk-LCTHTZIL.mjs → chunk-D4CKRD3V.mjs} +91 -91
  130. package/dist/chunk-D4EURAX4.mjs +4 -0
  131. package/dist/chunk-DQCE7TJY.mjs +5 -0
  132. package/dist/chunk-DR73Y2UJ.mjs +3 -0
  133. package/dist/{chunk-TMYZB6AV.mjs → chunk-EKNHM3P4.mjs} +1 -1
  134. package/dist/{chunk-GB5SOYQJ.mjs → chunk-ERLAIBOA.mjs} +2 -2
  135. package/dist/chunk-EURLTOTZ.mjs +4 -0
  136. package/dist/chunk-FJYN7RTH.mjs +4 -0
  137. package/dist/chunk-FWNRPMCJ.mjs +12 -0
  138. package/dist/chunk-FWW4CSAZ.mjs +2 -0
  139. package/dist/{chunk-2B5E4CDJ.mjs → chunk-GPIWQ4X4.mjs} +1 -1
  140. package/dist/chunk-GY3FAUVM.mjs +2 -0
  141. package/dist/chunk-HLYV7RIH.mjs +2 -0
  142. package/dist/chunk-HMYTM3GT.mjs +15 -0
  143. package/dist/chunk-IA4PSIMD.mjs +2 -0
  144. package/dist/chunk-JEUK3ZO7.mjs +2 -0
  145. package/dist/chunk-KTKHRC6H.mjs +2 -0
  146. package/dist/chunk-L7UP52JO.mjs +2 -0
  147. package/dist/{chunk-SYGN7GLU.mjs → chunk-MHW7ZKOU.mjs} +1 -1
  148. package/dist/chunk-N76HWBA3.mjs +10 -0
  149. package/dist/chunk-N7AZZLGT.mjs +548 -0
  150. package/dist/chunk-NAMN3RAF.mjs +2 -0
  151. package/dist/{chunk-5ZKJ3H4P.mjs → chunk-NFMCP2HI.mjs} +3 -3
  152. package/dist/chunk-NG375ILQ.mjs +2 -0
  153. package/dist/chunk-NVRNLK25.mjs +6 -0
  154. package/dist/chunk-NWFBE2YA.mjs +2 -0
  155. package/dist/chunk-NWR2LT5B.mjs +2 -0
  156. package/dist/chunk-OJKMINIU.mjs +20 -0
  157. package/dist/{chunk-4FS7Z7WR.mjs → chunk-OUUP3WKT.mjs} +1 -1
  158. package/dist/{chunk-BGGDRNYQ.mjs → chunk-OW5NWPOJ.mjs} +1 -1
  159. package/dist/chunk-PAREWQGB.mjs +4 -0
  160. package/dist/chunk-POQSE4C2.mjs +2 -0
  161. package/dist/chunk-PUOQ65NC.mjs +2 -0
  162. package/dist/{chunk-XNROSH2T.mjs → chunk-PVER7LSC.mjs} +2 -2
  163. package/dist/chunk-PZDLJJTJ.mjs +3 -0
  164. package/dist/chunk-Q47PLKIJ.mjs +15 -0
  165. package/dist/chunk-Q4UEPUWF.mjs +2 -0
  166. package/dist/chunk-QKXMPUXC.mjs +2 -0
  167. package/dist/chunk-QOUEFUCH.mjs +16 -0
  168. package/dist/chunk-RFDZXFJF.mjs +13 -0
  169. package/dist/chunk-RKPWLGZ3.mjs +4 -0
  170. package/dist/chunk-RMECZA2K.mjs +2 -0
  171. package/dist/{chunk-7DTINW6U.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  172. package/dist/chunk-SX4LJYT6.mjs +8 -0
  173. package/dist/chunk-SXHBYZST.mjs +16 -0
  174. package/dist/chunk-TANZRINB.mjs +2 -0
  175. package/dist/chunk-TEZAWDSQ.mjs +2 -0
  176. package/dist/chunk-UBBRTJ2R.mjs +24 -0
  177. package/dist/chunk-UFNYFFKO.mjs +20 -0
  178. package/dist/chunk-UGWYKHBL.mjs +170 -0
  179. package/dist/chunk-UKSHDZZ6.mjs +2 -0
  180. package/dist/chunk-UNOYVIYR.mjs +2 -0
  181. package/dist/{chunk-E7LWZRXY.mjs → chunk-V6RIYQZZ.mjs} +1 -1
  182. package/dist/chunk-VJPFVNNW.mjs +15 -0
  183. package/dist/chunk-VS3ZMVGX.mjs +5 -0
  184. package/dist/chunk-VTKNEYT3.mjs +6 -0
  185. package/dist/chunk-VXACTLO3.mjs +3 -0
  186. package/dist/chunk-YI43RG4P.mjs +2 -0
  187. package/dist/chunk-YQGT4AB2.mjs +6 -0
  188. package/dist/chunk-ZB4H7ZN4.mjs +2 -0
  189. package/dist/{chunk-IVDLMMBD.mjs → chunk-ZHEHPMBK.mjs} +1 -1
  190. package/dist/chunk-ZTHICSSF.mjs +2 -0
  191. package/dist/chunk-ZUNVAXLH.mjs +2 -0
  192. package/dist/chunk-ZWPMCK7P.mjs +2 -0
  193. package/dist/cli.mjs +1 -1
  194. package/dist/server.mjs +1 -1
  195. package/dist/{chunk-U6KNPJPR.mjs → update-fetch.mjs} +1 -1
  196. package/dist/worker.mjs +1 -1
  197. package/kit/board.css +95 -0
  198. package/kit/board.js +250 -0
  199. package/kit/charts.js +5 -71
  200. package/kit/code.js +14 -14
  201. package/kit/report.css +255 -17
  202. package/kit/runtime.js +1600 -125
  203. package/kit/state.js +10 -1
  204. package/kit/tables.js +128 -43
  205. package/kit/ui.js +77 -35
  206. package/package.json +2 -1
  207. package/packs/gallery/card/component.json +14 -0
  208. package/packs/gallery/card/example.html +10 -0
  209. package/packs/gallery/card/preview.svg +1 -0
  210. package/packs/gallery/card/style.css +6 -0
  211. package/packs/gallery/card/template.html +6 -0
  212. package/packs/gallery/card/writing.md +14 -0
  213. package/packs/gallery/chart-card/component.json +15 -0
  214. package/packs/gallery/chart-card/example.html +14 -0
  215. package/packs/gallery/chart-card/kit.js +130 -0
  216. package/packs/gallery/chart-card/preview.svg +1 -0
  217. package/packs/gallery/chart-card/style.css +42 -0
  218. package/packs/gallery/chart-card/template.html +13 -0
  219. package/packs/gallery/chart-card/writing.md +20 -0
  220. package/packs/gallery/chart-view/component.json +20 -0
  221. package/packs/gallery/chart-view/example.html +13 -0
  222. package/packs/gallery/chart-view/kit.js +355 -0
  223. package/packs/gallery/chart-view/preview.svg +1 -0
  224. package/packs/gallery/chart-view/style.css +94 -0
  225. package/packs/gallery/chart-view/template.html +3 -0
  226. package/packs/gallery/chart-view/writing.md +22 -0
  227. package/packs/gallery/countdown/component.json +18 -0
  228. package/packs/gallery/countdown/example.html +3 -0
  229. package/packs/gallery/countdown/kit.js +156 -0
  230. package/packs/gallery/countdown/preview.svg +1 -0
  231. package/packs/gallery/countdown/style.css +130 -0
  232. package/packs/gallery/countdown/template.html +3 -0
  233. package/packs/gallery/countdown/writing.md +22 -0
  234. package/packs/gallery/habit/component.json +14 -0
  235. package/packs/gallery/habit/example.html +3 -0
  236. package/packs/gallery/habit/kit.js +295 -0
  237. package/packs/gallery/habit/preview.svg +1 -0
  238. package/packs/gallery/habit/style.css +246 -0
  239. package/packs/gallery/habit/template.html +3 -0
  240. package/packs/gallery/habit/writing.md +21 -0
  241. package/packs/gallery/heatmap/component.json +18 -0
  242. package/packs/gallery/heatmap/example.html +3 -0
  243. package/packs/gallery/heatmap/kit.js +351 -0
  244. package/packs/gallery/heatmap/preview.svg +1 -0
  245. package/packs/gallery/heatmap/style.css +201 -0
  246. package/packs/gallery/heatmap/template.html +3 -0
  247. package/packs/gallery/heatmap/writing.md +21 -0
  248. package/packs/gallery/kanban/component.json +18 -0
  249. package/packs/gallery/kanban/example.html +12 -0
  250. package/packs/gallery/kanban/kit.js +540 -0
  251. package/packs/gallery/kanban/preview.svg +1 -0
  252. package/packs/gallery/kanban/style.css +212 -0
  253. package/packs/gallery/kanban/template.html +3 -0
  254. package/packs/gallery/kanban/writing.md +20 -0
  255. package/packs/gallery/metric/component.json +22 -0
  256. package/packs/gallery/metric/example.html +15 -0
  257. package/packs/gallery/metric/kit.js +248 -0
  258. package/packs/gallery/metric/preview.svg +1 -0
  259. package/packs/gallery/metric/style.css +92 -0
  260. package/packs/gallery/metric/template.html +3 -0
  261. package/packs/gallery/metric/writing.md +23 -0
  262. package/packs/gallery/note/component.json +14 -0
  263. package/packs/gallery/note/example.html +3 -0
  264. package/packs/gallery/note/kit.js +102 -0
  265. package/packs/gallery/note/preview.svg +1 -0
  266. package/packs/gallery/note/style.css +76 -0
  267. package/packs/gallery/note/template.html +3 -0
  268. package/packs/gallery/note/writing.md +18 -0
  269. package/packs/gallery/pack.json +8 -0
  270. package/packs/gallery/recent/component.json +13 -0
  271. package/packs/gallery/recent/example.html +1 -0
  272. package/packs/gallery/recent/kit.js +238 -0
  273. package/packs/gallery/recent/preview.svg +1 -0
  274. package/packs/gallery/recent/style.css +158 -0
  275. package/packs/gallery/recent/template.html +1 -0
  276. package/packs/gallery/recent/writing.md +15 -0
  277. package/packs/gallery/static/component.json +13 -0
  278. package/packs/gallery/static/example.html +11 -0
  279. package/packs/gallery/static/preview.svg +1 -0
  280. package/packs/gallery/static/style.css +138 -0
  281. package/packs/gallery/static/template.html +1 -0
  282. package/packs/gallery/static/writing.md +18 -0
  283. package/packs/gallery/stats/component.json +13 -0
  284. package/packs/gallery/stats/example.html +1 -0
  285. package/packs/gallery/stats/kit.js +166 -0
  286. package/packs/gallery/stats/preview.svg +1 -0
  287. package/packs/gallery/stats/style.css +151 -0
  288. package/packs/gallery/stats/template.html +1 -0
  289. package/packs/gallery/stats/writing.md +11 -0
  290. package/packs/gallery/today/component.json +12 -0
  291. package/packs/gallery/today/example.html +1 -0
  292. package/packs/gallery/today/kit.js +185 -0
  293. package/packs/gallery/today/preview.svg +1 -0
  294. package/packs/gallery/today/style.css +120 -0
  295. package/packs/gallery/today/template.html +1 -0
  296. package/packs/gallery/today/writing.md +14 -0
  297. package/packs/gallery/todos/component.json +19 -0
  298. package/packs/gallery/todos/example.html +3 -0
  299. package/packs/gallery/todos/kit.js +342 -0
  300. package/packs/gallery/todos/preview.svg +1 -0
  301. package/packs/gallery/todos/style.css +267 -0
  302. package/packs/gallery/todos/template.html +3 -0
  303. package/packs/gallery/todos/writing.md +30 -0
  304. package/packs/gallery/weather/component.json +19 -0
  305. package/packs/gallery/weather/example.html +3 -0
  306. package/packs/gallery/weather/kit.js +312 -0
  307. package/packs/gallery/weather/preview.svg +1 -0
  308. package/packs/gallery/weather/style.css +258 -0
  309. package/packs/gallery/weather/template.html +3 -0
  310. package/packs/gallery/weather/writing.md +26 -0
  311. package/packs/gallery-soft/pack.json +8 -0
  312. package/release.json +12 -10
  313. package/sdk/doc-kit.d.ts +396 -5
  314. package/sdk/doc-state.d.ts +2 -0
  315. package/skill/SKILL.md +56 -23
  316. package/skill/references/block-script.md +140 -0
  317. package/skill/references/building-blocks.md +257 -0
  318. package/skill/references/extensions.md +59 -0
  319. package/skill/references/pages-and-data.md +221 -0
  320. package/skill/references/writing-html.md +6 -4
  321. package/skill/sdk/doc-kit.d.ts +396 -5
  322. package/skill/sdk/doc-state.d.ts +2 -0
  323. package/web/assets/index-BK2e_07w.js +13 -0
  324. package/web/assets/index-CWFI83mF.css +1 -0
  325. package/web/index.html +2 -2
  326. package/dist/chunk-3HIRPVLU.mjs +0 -2
  327. package/dist/chunk-5MHMDLZD.mjs +0 -4
  328. package/dist/chunk-64K7IPLO.mjs +0 -255
  329. package/dist/chunk-6QXGZM36.mjs +0 -8
  330. package/dist/chunk-6RGJOMJP.mjs +0 -16
  331. package/dist/chunk-AJ73XJF3.mjs +0 -2
  332. package/dist/chunk-AUZGSZJH.mjs +0 -13
  333. package/dist/chunk-BFE45AKL.mjs +0 -2
  334. package/dist/chunk-BXO2ZY5P.mjs +0 -2
  335. package/dist/chunk-CEH4MRCC.mjs +0 -2
  336. package/dist/chunk-CY2FNNAB.mjs +0 -16
  337. package/dist/chunk-DFUDV4LX.mjs +0 -2
  338. package/dist/chunk-DKXG4XDG.mjs +0 -2
  339. package/dist/chunk-EZQ34M3F.mjs +0 -124
  340. package/dist/chunk-EZY3WC6Z.mjs +0 -15
  341. package/dist/chunk-FUKQNOQS.mjs +0 -9
  342. package/dist/chunk-JPOSLGOC.mjs +0 -6
  343. package/dist/chunk-L3QKH4OK.mjs +0 -26
  344. package/dist/chunk-LAE5NQ4B.mjs +0 -2
  345. package/dist/chunk-LEF6DRCK.mjs +0 -59
  346. package/dist/chunk-NO5NJCHO.mjs +0 -2
  347. package/dist/chunk-NQPVAU63.mjs +0 -2
  348. package/dist/chunk-NSKUTQ5J.mjs +0 -5
  349. package/dist/chunk-O35FIXRB.mjs +0 -2
  350. package/dist/chunk-P2CAZPDP.mjs +0 -3
  351. package/dist/chunk-PL6GHLGD.mjs +0 -15
  352. package/dist/chunk-QJIR2BLP.mjs +0 -6
  353. package/dist/chunk-QUPLVPB2.mjs +0 -7
  354. package/dist/chunk-R7BNENLY.mjs +0 -4
  355. package/dist/chunk-S6O4UHLC.mjs +0 -2
  356. package/dist/chunk-SGJWQKEI.mjs +0 -2
  357. package/dist/chunk-TX6JH7TR.mjs +0 -2
  358. package/dist/chunk-TYK6VNAB.mjs +0 -10
  359. package/dist/chunk-UALRNVSE.mjs +0 -4
  360. package/dist/chunk-V3HXVQEM.mjs +0 -2
  361. package/dist/chunk-V5VXUJKG.mjs +0 -2
  362. package/dist/chunk-VBXMADMP.mjs +0 -2
  363. package/dist/chunk-VNV55RUA.mjs +0 -2
  364. package/dist/chunk-VPD2PS35.mjs +0 -2
  365. package/dist/chunk-W4VKN3GF.mjs +0 -7
  366. package/dist/chunk-W5BXXPDJ.mjs +0 -3
  367. package/dist/chunk-XUNHRCOG.mjs +0 -6
  368. package/skill/references/building-components.md +0 -367
  369. package/web/assets/index-Bh74DfsV.css +0 -1
  370. package/web/assets/index-UW0RyFFt.js +0 -13
@@ -0,0 +1,170 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as w}from"./chunk-JEUK3ZO7.mjs";import{a as te}from"./chunk-ZUNVAXLH.mjs";import{d as F,e as W}from"./chunk-N7AZZLGT.mjs";import{a as H,b as L,d as G,e as $,f as E,g as R,h as U,i as q,j as Y,o as V,q as X,r as Q,s as Z}from"./chunk-D4EURAX4.mjs";import{a as P,b as d,f as ee}from"./chunk-4OZWXZE5.mjs";import{i as K}from"./chunk-OW5NWPOJ.mjs";import{f as S,j as C,s as _,t as B,v as j}from"./chunk-FWNRPMCJ.mjs";import v from"node:fs";import N from"node:path";import{blocksHidden as $e}from"../browser/editor/components/registry.mjs";import{inLanguage as be,told as ve}from"../browser/shared/i18n/index.mjs";import{PACK_ID as xe}from"../browser/shared/pack-manifest.mjs";import{readKeys as Se,writeKey as se}from"../browser/shared/net-keys.mjs";import{HOST as Ne,netHostsOf as Oe}from"../browser/shared/net-policy.mjs";import{PACKAGE_ID as je,SLOT as Ee}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as Ae,layoutOf as A,PACKAGE_MANIFEST as ie,shallowPackages as le}from"../browser/shared/workspace.mjs";var fe=(e,t,{script:o,flow:n,data:a,page:s})=>`{
3
+ "id": "${e}",
4
+ "apiVersion": 1,
5
+ "version": "0.1.0",
6
+ "name": { "zh": "${t}", "en": "${t}" },
7
+ "description": { "zh": "\u4E00\u4E2A\u53EF\u4EE5\u53CD\u590D\u4F7F\u7528\u7684\u5757", "en": "A block to use again" },
8
+ "words": "${t}",${s?`
9
+ "places": ["page"],
10
+ "card": { "sizes": [[4, 3], [2, 3]], "resize": true },`:""}
11
+ "parts": {
12
+ "title": { "at": ":scope > h3", "edit": "${s?"none":"text"}" }${a?`,
13
+ "items": { "at": ":scope > script", "edit": "data" }`:n?`,
14
+ "body": { "edit": "flow" }`:`,
15
+ "text": { "at": ":scope > p", "edit": "${s?"none":"text"}", "optional": true }`}
16
+ },${o?`
17
+ "runtime": { "generated": [".component-drawn"] },`:""}
18
+ "markdown": "parts"
19
+ }
20
+ `,oe=(e,t,o,{blocks:n,json:a})=>`<div data-doc-component="${e}">
21
+ <h3>${t}</h3>
22
+ ${a?` <script type="application/json">${a}</script>`:n?` <div data-doc-slot="body">
23
+ ${n.map(s=>` ${s}
24
+ `).join("")} </div>`:` <p>${o}</p>`}
25
+ </div>
26
+ `,we=["<p>\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002</p>","<ul>"," <li>\u63D2\u69FD\u91CC\u5199\u6587\u6863\u81EA\u5DF1\u7684\u5757</li>"," <li>\u6BB5\u843D\u3001\u5217\u8868\u3001\u8868\u683C\u90FD\u53EF\u4EE5</li>","</ul>"],ge=(e,{flow:t,data:o})=>`/* Every selector starts at the instance, so that nothing here reaches the rest of the page.${t?` Each step is
27
+ a >, so that none reaches into the slot, whose blocks read as the page's.`:""} */
28
+ [data-doc-component="${e}"] { padding: 12px 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
29
+ [data-doc-component="${e}"] > h3 { margin-top: 0; }
30
+ ${o?`/* The hidden attribute hides a control whatever display the rules below give it (the kit holds [hidden] over a
31
+ style): the field and the buttons are drawn hidden where nothing is written, an export. */
32
+ [data-doc-component="${e}"] .component-list { margin: 0 0 8px; padding: 0; list-style: none; }
33
+ [data-doc-component="${e}"] .component-list > li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
34
+ [data-doc-component="${e}"] .component-field { display: block; box-sizing: border-box; width: 100%; padding: 4px 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: inherit; font: inherit; }
35
+ [data-doc-component="${e}"] .component-remove { padding: 0 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: var(--doc-muted); font: inherit; cursor: pointer; }
36
+ `:""}`,ue=(e,t,{script:o,flow:n,data:a,page:s})=>`# ${t}
37
+
38
+ What this block is for, and when ${s?"a custom page":"a document"} uses it rather than a block of Gallery's own.
39
+
40
+ ## How to write it
41
+
42
+ Write the element as example.html does: \`gallery block show ${e}\` prints it. Each part, and what goes in it:
43
+
44
+ - the title, its \`h3\`: required${s?", written in the file (a page shows it as written)":""}.
45
+ ${a?'- the items, its `<script type="application/json">`: `{"items":[{"text":"\u2026"}]}`, each item a line a reader adds on the block and takes away with its button. Leave the items of a block that is there alone: they are the reader\'s.\n':n?'- the body, its `<div data-doc-slot="body">`: required, the document\'s own blocks, written as anywhere in the document (paragraphs, lists, tables, formulas).\n':"- the text, its `p`: optional.\n"}${s?`
46
+ ## On a page
47
+
48
+ A card of a custom page: \`gallery page add <slug> ${e}\` puts one on it, at the first free spot by its size (4 \xD7 3, or 2 \xD7 3), which the user may change by dragging its edge.
49
+ `:""}
50
+ ## How it looks
51
+
52
+ What a reader sees of it, and what it shows while it is empty.${a?" Where nothing is written (an export) its field and buttons are not shown.":""}
53
+ ${o?`
54
+ ## Its script
55
+
56
+ kit.js runs with the rights of a document's own script. What it draws, it draws in what the manifest's \`runtime\` names${n?", outside the slot: it reads the slot and never writes in it":""}.${a?" It reads the items with `context.readJSON` and writes them back with `context.editJSON`, one write for each add or removal (one undo step); `example()` adds an item, by the function the field calls, and works on an empty instance too.":""}
57
+ `:""}`,ke=e=>`// Starts each instance from what the file says, and draws in a node the manifest's runtime names:
58
+ // the kit takes that off an instance before it starts one again, as an undo may put one back.
59
+ DocKit.component({
60
+ id: "${e}",
61
+ on: ["source"],
62
+ mount(host, context) {
63
+ const drawn = document.createElement("div");
64
+ drawn.className = "component-drawn";
65
+ host.append(drawn);
66
+ const draw = () => { drawn.textContent = context.part("title")?.textContent ?? ""; };
67
+ draw();
68
+ return { update: draw };
69
+ },
70
+ });
71
+ `,ye=e=>`// A list of lines a reader keeps in this block. Its data part, items, is a script of JSON:
72
+ // {"items":[{"text":"\u2026"}]}. The block draws what it holds on every \`source\` (an undo, an Agent's write,
73
+ // the page coming to edit) and writes only on a reader's gesture: a line typed in the field (DocKit.input:
74
+ // Enter or leaving the field, never while an input method composes) and a press of a line's button, each
75
+ // one context.editJSON, one undo step. A control that writes is drawn only while context.canEdit() and
76
+ // hidden otherwise, as an export needs (the hidden attribute: the kit holds it over any display).
77
+
78
+ /**
79
+ * The items \`data\` holds (context.readJSON's, or the draft context.editJSON hands a change); throws
80
+ * saying why when it is no { "items": [] }, and the block draws nothing over it.
81
+ * @param {any} data
82
+ * @returns {{ text: string }[]}
83
+ */
84
+ function itemsOf(data) {
85
+ if (data === null || typeof data !== "object" || !Array.isArray(data.items)) throw new Error('its data is no { "items": [] }');
86
+ return data.items;
87
+ }
88
+
89
+ /**
90
+ * One item more, one write: what the field calls once the reader is done with it, and the example too.
91
+ * Whether it was taken.
92
+ * @param {DocComponentContext} context
93
+ * @param {string} text
94
+ */
95
+ function addItem(context, text) {
96
+ return context.editJSON("items", (data) => {
97
+ itemsOf(data).push({ text });
98
+ });
99
+ }
100
+
101
+ /**
102
+ * The item numbered \`index\` taken away, one write: what a line's button calls. Whether it was taken.
103
+ * @param {DocComponentContext} context
104
+ * @param {number} index
105
+ */
106
+ function removeItem(context, index) {
107
+ return context.editJSON("items", (data) => {
108
+ itemsOf(data).splice(index, 1);
109
+ });
110
+ }
111
+
112
+ DocKit.component({
113
+ id: "${e}",
114
+ on: ["source", "editable"],
115
+ mount(host, context) {
116
+ const drawn = document.createElement("div");
117
+ drawn.className = "component-drawn";
118
+ const list = document.createElement("ul");
119
+ list.className = "component-list";
120
+ const field = document.createElement("input");
121
+ field.className = "component-field";
122
+ field.type = "text";
123
+ field.placeholder = "\u5199\u4E00\u6761\uFF0C\u56DE\u8F66\u6DFB\u52A0";
124
+ drawn.append(list, field);
125
+ host.append(drawn);
126
+ const typed = DocKit.input(field, {
127
+ signal: context.signal,
128
+ commit(value) {
129
+ if (value.trim() && addItem(context, value.trim())) typed.set("");
130
+ },
131
+ });
132
+ context.listen(list, "click", (event) => {
133
+ const button = event.target instanceof Element ? event.target.closest("button") : null;
134
+ if (button && context.canEdit()) removeItem(context, Number(button.value));
135
+ });
136
+ const draw = () => {
137
+ const data = context.readJSON("items");
138
+ if (data === undefined) return; // no JSON: the instance has failed, and Gallery shows what it holds
139
+ let items;
140
+ try {
141
+ items = itemsOf(data);
142
+ } catch (error) {
143
+ return context.fail(error);
144
+ }
145
+ const writes = context.canEdit();
146
+ list.replaceChildren(...items.map((item, index) => {
147
+ const line = document.createElement("li");
148
+ const words = document.createElement("span");
149
+ words.textContent = item.text;
150
+ const remove = document.createElement("button");
151
+ remove.type = "button";
152
+ remove.className = "component-remove";
153
+ remove.value = String(index);
154
+ remove.textContent = "\u5220\u9664";
155
+ remove.hidden = !writes;
156
+ line.append(words, remove);
157
+ return line;
158
+ }));
159
+ field.hidden = !writes;
160
+ };
161
+ draw();
162
+ return { update: draw };
163
+ },
164
+ example(host, context) {
165
+ addItem(context, "\u53C8\u4E00\u6761");
166
+ },
167
+ });
168
+ `;function ne(e,{script:t=!1,flow:o=!1,data:n=!1,page:a=!1}={}){let s=e.split("/")[1],l={script:t||n,flow:o,data:n,page:a};return{"component.json":fe(e,s,l),"template.html":oe(e,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",{blocks:o&&["<p></p>"],json:n&&'{"items":[]}'}),"example.html":oe(e,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",{blocks:o&&we,json:n&&'{"items":[{"text":"\u7B2C\u4E00\u6761"},{"text":"\u7B2C\u4E8C\u6761"}]}'}),"writing.md":ue(e,s,l),"style.css":ge(e,l),...l.script?{"kit.js":n?ye(e):ke(e)}:{}}}var x="local";function re(e){let t=e.includes("/")?e:`${x}/${e}`;if(!je.test(t))throw new d(`Not a block's id: ${e} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${x}/<name>).`);let o=t.split("/").find(n=>Ae.has(n));if(o)throw new d(`Not a block's id: ${e} (Windows keeps ${o} for a device).`);return t}function Ie(e,t){let o=re(t),n=t.includes("/")?null:$(t);if(!n)return o;let a=S(e);return a.packages.has(o)||a.problems.has(o)||v.existsSync(M(e,o))?o:n.id}var M=(e,t)=>N.join(A(e).components,...t.split("/")),u=e=>e.pack===H?e.name:e.id,z=()=>G().map(u).join(", "),ce=({name:e,file:t})=>`${w(t)} is one level too shallow, and no catalog reads it: a custom block is components/<scope>/<name>/, so move it to components/${x}/${e}/`;function Ce(e,t){let o=le(e).find(({name:s})=>s===t.split("/")[1]),n=E(t)&&$(t);if(n)return`No block ${t} in ${w(A(e).components)}: it is one of Gallery's own, which gallery block add ${u(n)} puts in.`;let a=t.startsWith(`${x}/`)?$(t.slice(x.length+1)):null;return o?ce(o):`No block ${t} in ${w(A(e).components)}: gallery block list says which there are${a?`; Gallery has a block of that name, ${a.id}`:""}.`}function Ge(e,t,{script:o,flow:n,data:a,page:s,recipe:l}){let r=t.split("/")[0],m=$(t);if(E(t))throw new d(`The scope ${r}/ is kept for Gallery's own blocks: give yours another (${x}/<name>, or a <name> alone)${m?`; gallery block add ${u(m)} puts Gallery's in, and gallery block new <id> --recipe ${u(m)} starts one of yours from it`:""}.`);if(R(e).packs?.[r])throw new d(`The scope ${r}/ is the pack ${r}'s, which gallery block pack install put in (installing it again would not keep a block of yours there): give yours another (${x}/<name>, or a <name> alone).`);let h=l===void 0?null:$(l);if(l!==void 0&&!h)throw new d(`No block of Gallery's own is called ${l}: ${z()||"none"}.`);let f=M(e,t);if(v.existsSync(f)||S(e).problems.has(t)){let c=!v.existsSync(N.join(f,ie));console.error(c?`A folder is there with no component.json: ${w(f)}: move it, or give this block another name.`:`Block already exists: ${w(f)}: gallery block show ${t} says what it is; give a new one another name.`),process.exit(1)}let i=h?V(h,t):ne(t,{script:o,flow:n,data:a,page:s});try{v.mkdirSync(f,{recursive:!0});for(let c of L(Object.keys(i)))v.mkdirSync(N.dirname(N.join(f,c)),{recursive:!0}),v.writeFileSync(N.join(f,c),i[c])}catch(c){if(!c.code)throw c;console.error(`Cannot write ${w(f)} (${c.code}).`),process.exit(1)}if(console.log(`Created ${w(f)}: ${Object.keys(i).join(", ")}`),h){console.log(`Made from Gallery's ${h.id} ${h.version}, every word that named it naming ${t}: change its name, words and description in component.json first (two blocks of one name read alike in "/"), and in the same files what is still ${h.name}'s: preview.svg (the picture the menu shows beside the description, still ${h.name}'s drawing: draw yours or delete it), writing.md (how to write it, still about ${h.name}) and example.html (the instance check runs and show prints, still ${h.name}'s words), then what you came for (references/building-blocks.md has every field and the rules), and run gallery block check ${t}, which passes as it stands now.`);return}let p=o||a;console.log(`Next: say in component.json what it is (its name, description and parts), write template.html, what ${s?"a custom page's \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 puts on it":'"/" puts in a document'}, and example.html, an instance as a writer would fill it, then writing.md and style.css${p?" and kit.js":""} (references/building-blocks.md has every field and the rules${n?", and Slots what its slot body holds":""}${s?"; references/pages-and-data.md a card's size and settings and what it reads":""}${p?"; references/block-script.md its script and how it writes back":""}), and run gallery block check ${t}, which passes as it stands now.`),a&&console.log("It keeps a list of lines (the part items, a script of JSON on one line, as context.editJSON writes it): kit.js reads it with context.readJSON and writes it with context.editJSON, from a field (DocKit.input) and a button, hidden where nothing is written; example() adds a line by the function the field calls, and works on template.html's empty instance. Rename the part, the fields of its JSON and the controls for what the block keeps."),s?console.log(`It is a custom page's card (places ["page"], a card of two sizes): gallery page add <slug> ${t} puts one on a page, then gallery page try <slug> <card id> <gesture> tries a reader's gesture on it${a?' (--type .component-field "words" --then Enter)':""}; for a document too, put "document" in places.`):a&&console.log(`In a document: write the element as example.html does, then gallery block try <slug> --type .component-field "words" --then Enter tries the field (the part and the class are the scaffold's: rename them with the block).`)}function Pe(e,t){let o=$(t);if(!o)throw new d(`No block of Gallery's own is called ${t}: ${z()||"none"} (gallery block list says each).`);let n;try{n=q(e,o)}catch(s){if(s.code!=="changed")throw s;console.error(`${w(s.folder)} was changed after gallery block add put it there (or another hand put it there), so it is not replaced: to keep those changes, make a block of your own from Gallery's with gallery block new <id> --recipe ${u(o)} and move them into it; to take Gallery's ${o.version}, delete the folder and run gallery block add ${u(o)} again.`),process.exit(1)}let a=o.places.includes("document")?`a document can write it now (gallery block show ${o.id} says how)`:"custom pages can place it now";n.did==="same"?console.log(`${o.id} ${o.version} is in already, as Gallery ships it: ${w(n.folder)}`):n.did==="updated"?console.log(`Updated ${o.id} from ${n.from??"an older version"} to ${o.version}: ${w(n.folder)}`):console.log(`Added ${o.id} ${o.version}: ${w(n.folder)}`),n.did!=="same"&&console.log(`It is Gallery's, as it ships: no check or try is needed, and ${a}. Change nothing in its folder, or gallery block add will not update it again: for a block like it of your own, gallery block new <id> --recipe ${u(o)}.`)}var k=({zh:e,en:t})=>e===t?e:`${e} / ${t}`;function Ke(e){if(B(e))return null;let t=_(e);return t?C("en",t):"it has no template.html"}var Je={disabled:"disabled by the user: its instances show as they stand, no script and no style"},I=e=>e?.length?` \u8981\u7528\uFF1A${e.join(", ")}`:"";function ae(e,{id:t,name:o,version:n,description:a,state:s,needs:l},r){console.log(`${t} ${k(o)}`);let h=(e.settings.packsOff??[]).includes(t.split("/")[0])?`available; its pack ${t.split("/")[0]} is switched off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, so no menu or library offers it, and a document can still write it`:r==="document"&&s==="hidden"?"available; not in the document's menus, by the user's switch, and a document can still write it":"available";console.log(` \u7248\u672C\uFF1A${n}\uFF08${h}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(a)}`),I(l)&&console.log(I(l));let f=r==="document"&&Ke(e.packages.get(t));f&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${f}`)}function Te(e){let t=S(e),o=j(t),n=o.filter(({reason:i})=>i),a=o.filter(({reason:i})=>!i),s=a.filter(({state:i})=>i!=="disabled"),l=s.filter(({places:i})=>i.includes("document")),r=s.filter(({places:i})=>i.includes("page")),m=le(e),h=G().map(i=>({block:i,state:U(e,i)})).filter(({block:i,state:p})=>!p.added||p.behind||p.changed&&Y(i.version,p.version)),f=$e(t.settings.hidden);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),a.length+n.length+m.length===0)console.log("No custom blocks yet. A document is written with Gallery's blocks and whole blocks; gallery block add <name> puts one of Gallery's own in (below), and gallery block new <id> starts one when the user wants a block to use again.");else{console.log(l.length?`\u6587\u6863\u91CC\u53EF\u7528 (in documents: ${l.length}; gallery block show <id> says how to write each):`:"\u6587\u6863\u91CC\u53EF\u7528 (in documents): none now.");for(let p of l)ae(t,p,"document");console.log(r.length?`\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages: ${r.length}):`:"\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages): none now.");for(let p of r)p.places.includes("document")?console.log(`${p.id} ${k(p.name)} (above: in documents too)`):ae(t,p,"page");let i=a.filter(({state:p})=>p==="disabled");i.length+n.length+m.length>0&&console.log("Not to use now:");for(let{id:p,name:c,version:y,state:O}of i)console.log(`${p} ${k(c)} ${y} ${Je[O]}`);for(let{id:p,reason:c,version:y}of n)console.log(`${p}${y?` ${y}`:""} does not load: ${c.en}`);for(let p of m)console.log(ce(p))}h.length&&console.log("Gallery's own blocks, to add as they are (no check or try needed):");for(let{block:i,state:p}of h){let c=i.places.map(y=>y==="document"?"documents":"custom pages").join(" and ");console.log(`${i.id} ${k(i.title)} ${i.version} (${c})`),console.log(` \u8BF4\u660E\uFF1A${k(i.description)}`),p.changed?console.log(` the workspace's copy (${p.version??"no version"}) was changed after it was added, so it is not updated: to take Gallery's ${i.version}, delete ${w(M(e,i.id))} and run gallery block add ${u(i)} (to keep the changes, gallery block new <id> --recipe ${u(i)} and move them into it)`):console.log(p.added?` gallery block add ${u(i)} (the workspace has ${p.version??"an older one"}: this updates it)`:` gallery block add ${u(i)}`)}f.length&&console.log(`Built-in blocks the user took out of the document's menus (a document can still write them): ${f.join(", ")}`)}var De=(e,{at:t,edit:o,optional:n,min:a,max:s})=>{let l=[n?"optional":"",a!==void 0?`at least ${a}`:"",s!==void 0?`at most ${s}`:""].filter(Boolean),r=o==="flow"?`${Ee}="${e}"`:t;return` ${e} ${r} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${l.length?` (${l.join(", ")})`:""}`};function de(e,t,o){console.log(`${t} ${k(e.name)}`),console.log(` \u7248\u672C\uFF1A${e.version}\uFF08${o}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(e.description)}`),console.log(` \u7528\u5728\uFF1A${e.places.map(l=>l==="document"?"documents":"custom pages").join(", ")}`),I(e.needs)&&console.log(I(e.needs)),console.log(` ${w(e.folder)}`);let n=Object.entries(e.parts);console.log(n.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[l,r]of n)console.log(De(l,r));let a=K(e,"writing.md")?.trimEnd();console.log(a?`How to write it (writing.md):
169
+ ${a}`:"How to write it: the block has no writing.md.");let s=K(e,"example.html")?.trimEnd();console.log(s?`The example (example.html):
170
+ ${s}`:"The example: the block has no example.html.")}function Me(e,t){let o=S(e),n=o.problems.get(t),a=o.packages.get(t)??(n?.off?n:void 0);if(!a){let r=n?.problem,m=!r&&E(t)?$(t):null;if(m)return Fe(m);console.error(r?`${t} does not load: ${C("en",r)}`:Ce(e,t)),process.exit(1)}let{state:s}=j(o).find(r=>r.id===t),l={normal:"available",hidden:"available; not in the document's menus, by the user's switch",disabled:"disabled by the user"}[s]??s;de(a,t,l),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}async function ze(e,t,o,{remove:n}){let a=Se(e);if(t===void 0){let s=[...new Set(j(S(e)).flatMap(({needs:m})=>Oe(m??[])))],l=Object.keys(a).sort();console.log(l.length?`Keys kept (.gallery/keys.json), by host: ${l.join(", ")}.`:"No key kept (.gallery/keys.json holds none).");let r=s.filter(m=>!l.includes(m)).sort();r.length&&console.log(`Hosts the workspace's blocks reach with no key: ${r.join(", ")} (a key is needed only where a block's address names {key}).`);return}if(!Ne.test(t))throw new d(`Not a host a block's needs can name: ${t} (a lowercase name, no scheme, port or path; *. before it for the names under it).`);if(n){if(o!==void 0)throw new d("gallery block key <host> --remove takes no key.");return t in a?(await se(e,t,null),console.log(`Took away the key for ${t}. A block's address that names {key} on it is refused (code "key") until one is kept again.`)):console.log(`No key kept for ${t}: nothing to take away.`)}if(o===void 0)return console.log(t in a?`A key is kept for ${t} (never printed): an address on it that names {key} is fetched with it.`:`No key kept for ${t}: gallery block key ${t} <key> keeps one.`);if(!o.trim()||/[\r\n]/.test(o))throw new d("A key is one line of characters, not empty.");await se(e,t,o),console.log(`Kept the key for ${t} in ${w(A(e).keys)}, which no page, export or cache holds: Gallery writes it where a block's address on ${t} names {key}, as it fetches for the block. Never write the key into a block's files or a page: they are shown and exported.`)}function Fe(e){let t=JSON.parse(v.readFileSync(N.join(e.folder,ie),"utf8"));de({name:e.title,description:e.description,version:e.version,places:e.places,needs:t.needs,folder:e.folder,parts:t.parts??{}},e.id,"Gallery's own, not in this workspace yet");let o=e.places.includes("document")?", and a document writes it as the example above does, straight in the page or a section, with no data-block-id, which the export gives it":`, and gallery page add <slug> ${u(e)} puts a card of it on a custom page`;console.log(`Not in this workspace yet: gallery block add ${u(e)} puts it in as it ships (no check, no try)${o}.`)}var he=e=>be("en",()=>ve(e))??e.message,J=(e,t)=>t.length?[` ${e}: ${t.join(", ")}`]:[];function We(e,t){let o;try{o=X(e,te(t))}catch(a){if(!a.code)throw a;console.error(`Not installed: ${he(a)}`),process.exit(1)}let n=o.added.length+o.updated.length+o.same.length+o.kept.length;o.from===null?console.log(`Installed the pack ${o.id} ${o.version} (${k(o.name)}), ${n} block${n===1?"":"s"}: ${w(o.folder)}`):o.did==="updated"?console.log(`Updated the pack ${o.id} from ${o.from??"an older version"} to ${o.version}: ${w(o.folder)}`):console.log(`The pack ${o.id} ${o.version} is in already, as installed: ${w(o.folder)}`);for(let a of[...J("added",o.added),...o.did==="updated"?J("updated",o.updated):[],...J("taken out (not in this version)",o.removed)])console.log(a);o.kept.length&&console.log(` kept as they are, changed since they were installed: ${o.kept.join(", ")} (to take this version's, delete the block's folder and install the pack again)`),o.ownKept&&console.log(" its pack.json was changed since it was installed, and is kept as it is"),console.log(`Its blocks are offered in "/" and \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 while its switch in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 is on (gallery block pack list says each pack's); gallery block list says each block.`)}function D(e){let t=Z(e);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),t.length===0)return console.log("No block packs: gallery block pack install <folder|zip> installs one.");let o={official:"Gallery's own",installed:"a pack installed",own:"the workspace's own blocks, no pack.json"};for(let n of t){let a=[n.version?`${n.id} ${n.version}`:n.id,o[n.kind],n.enabled?"on":"off",`${n.blocks} block${n.blocks===1?"":"s"}`,...n.author?[`by ${n.author}`]:[]];console.log(`${k(n.name)} (${a.join(", ")})`),n.description&&console.log(` \u8BF4\u660E\uFF1A${k(n.description)}`),n.problem&&console.log(` its pack.json does not read: ${n.problem.en}`),n.changed.length&&console.log(` changed since it was installed: ${n.changed.join(", ")}${n.newer?` (Gallery's is ${n.newer}, not put over them)`:""}`)}}function _e(e,t){if(!xe.test(t))throw new d(`Not a pack's id: ${t} (lowercase letters, digits and hyphens: gallery block pack list says each).`);let o;try{o=Q(e,t)}catch(n){if(!n.code)throw n;console.error(`Not removed: ${he(n)}`),process.exit(1)}console.log(`Removed the pack ${o.id}${o.version?` ${o.version}`:""} (${o.blocks.length} block${o.blocks.length===1?"":"s"}): what documents and pages hold of its blocks stays, shown as blocks that are not there.`)}var T={install:We,list:D,remove:_e};function Be(e,t,o){if(!t)throw new d("Say what to do with packs: install <folder|zip>, list, remove <pack>.");if(!Object.hasOwn(T,t))throw new d(`No such pack command: ${t} (install, list, remove).`);if(T[t]===D){if(o.length)throw new d("gallery block pack list takes nothing else.");return D(e)}if(o.length!==1)throw new d(t==="install"?"gallery block pack install takes one folder or zip: gallery block pack install <folder|zip>.":"gallery block pack remove takes one pack's id: gallery block pack remove <pack>.");return T[t](e,o[0])}var g={new:(e,t,o)=>Ge(e,t,o),add:Pe,list:Te,show:Me,check:async(e,t,{documents:o})=>(await import("./chunk-VS3ZMVGX.mjs")).checkCommand(e,t,{documents:o}),try:async(e,t)=>(await import("./chunk-CRJEG7MT.mjs")).tryCommand(e,t),key:ze,pack:Be},He=["--press","--drag","--to","--key","--type","--select","--then","--steps"],Le={"--key":"--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).","--type":"--type takes a selector and the words to type: --type <selector> <words> (quoted when they hold a blank).","--select":"--select takes a selector and an option: --select <selector> <value> (the option's value or its words)."};function pe(e){let t=e.indexOf("--"),o=new Set,n={};for(let[a,s]of Object.entries(Le)){let l=(t===-1?e:e.slice(0,t)).findIndex(h=>h===a||h.startsWith(`${a}=`));if(l===-1)continue;let r=l+(e[l].includes("=")?1:2),m=e[r];if(m===void 0||r===t||P(m)||o.has(r))throw new d(s);o.add(r),n[a]=m}return{argv:e.filter((a,s)=>!o.has(s)),seconds:n}}function pt(e){let{argv:t,seconds:o}=pe(e);return{argv:t,key:o["--key"]??null}}async function mt(e,{workspace:t}){try{return await Re(e,t)}catch(o){let n=e.find(a=>!P(a));throw o instanceof d&&n==="try"&&(o.synopsis=F),o instanceof d&&n==="pack"&&(o.synopsis=W),o}}async function Re(e,t){let{argv:o,seconds:n}=pe(e),{positional:a,options:s,values:l}=ee({options:["--script","--flow","--data","--page","--keep","--documents","--replace","--remove"],values:[...He,"--recipe"],argv:o}),r=l.get("--recipe"),m=new Map([...l].filter(([b])=>b!=="--recipe")),[h,f,...i]=a,p=Object.keys(g).join(", ");if(!h)throw new d(`Say what to do: ${p}.`);if(!Object.hasOwn(g,h))throw new d(`No such block command: ${h} (${p}).`);let c=g[h];for(let b of["--script","--flow","--data","--page"])if(s.has(b)&&c!==g.new)throw new d(`${b} goes with new, not ${h}.`);if(s.has("--documents")&&c!==g.check)throw new d(`--documents goes with check, not ${h}.`);if(s.has("--remove")&&c!==g.key)throw new d(`--remove goes with key, not ${h}.`);if(r!==void 0&&c!==g.new)throw new d(`--recipe goes with new, not ${h}.`);let y=["--script","--flow","--data","--page"].filter(b=>s.has(b));if(r!==void 0&&y.length)throw new d(`--recipe makes a block of what Gallery's ${r} holds: ${y[0]} goes with a new block of none.${y[0]==="--page"&&$(r)?.places.includes("page")?` ${r} already is a card for a custom page (its places hold page): leave --page out.`:""}`);if(s.has("--flow")&&s.has("--data"))throw new d("--flow and --data do not go together: --flow is a slot for blocks of the document's own, --data a list of lines a reader keeps in the block's JSON. Make the one you need with new, and add the other by hand.");if(s.has("--flow")&&s.has("--page"))throw new d("--flow and --page do not go together: a custom page renders no document's blocks, so a block for a page has no slot.");let O=[...m.keys(),...Object.keys(n).filter(b=>!m.has(b)),...s.has("--keep")?["--keep"]:[],...s.has("--replace")?["--replace"]:[]];if(c===g.try)return c(t,{named:a.slice(1),values:m,seconds:n,keep:s.has("--keep"),replace:s.has("--replace")});if(O.length)throw new d(`${O[0]} goes with try, not ${h}.`);if(c===g.list){if(f!==void 0)throw new d(`gallery block ${h} takes nothing else.`);return c(t)}if(c===g.pack)return c(t,f,i);if(c===g.key){if(i.length>1)throw new d("gallery block key takes a host and its key: gallery block key <host> <key>.");return c(t,f,i[0],{remove:s.has("--remove")})}if(c===g.add){if(f===void 0||i.length>0)throw new d(`gallery block add takes one name of Gallery's own blocks: ${z()}.`);return c(t,f)}if(f===void 0||i.length>0)throw new d(`gallery block ${h} takes one id.`);let me=c===g.show||c===g.check?Ie(t,f):re(f);return c(t,me,{script:s.has("--script"),flow:s.has("--flow"),data:s.has("--data"),page:s.has("--page"),documents:s.has("--documents"),recipe:r})}export{re as a,Ie as b,M as c,u as d,ce as e,Ce as f,He as g,pe as h,pt as i,mt as j};
@@ -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 L from"node:fs";import{pipeline as F}from"node:stream/promises";import z from"node:zlib";import{refusal as B,said as k}from"../browser/shared/i18n/index.mjs";var T=67324752,O=33639248,A=101010256,P=101075792,W=117853008,I=4294967295,D=2048;function v(t=new Date){let o=t.getHours()<<11|t.getMinutes()<<5|Math.floor(t.getSeconds()/2),n=Math.max(1980,t.getFullYear())-1980<<9|t.getMonth()+1<<5|t.getDate();return[o,n]}function K(t){let[o,n]=v(),c=[],d=[],r=0;for(let a of t){let u=Buffer.isBuffer(a.data)?a.data:Buffer.from(a.data??"","utf8"),e=Buffer.from(a.name,"utf8"),w=u.length>64?z.deflateRawSync(u):null,h=w&&w.length<u.length?w:u,m=h===u?0:8,g=z.crc32(u);if(u.length>=I||r>=I)throw new Error("\u538B\u7F29\u5305\u592A\u5927\uFF08\u8D85\u8FC7 4GB\uFF09");let l=Buffer.alloc(30);l.writeUInt32LE(T,0),l.writeUInt16LE(20,4),l.writeUInt16LE(D,6),l.writeUInt16LE(m,8),l.writeUInt16LE(o,10),l.writeUInt16LE(n,12),l.writeUInt32LE(g,14),l.writeUInt32LE(h.length,18),l.writeUInt32LE(u.length,22),l.writeUInt16LE(e.length,26),l.writeUInt16LE(0,28);let s=Buffer.alloc(46);s.writeUInt32LE(O,0),s.writeUInt16LE(20,4),s.writeUInt16LE(20,6),s.writeUInt16LE(D,8),s.writeUInt16LE(m,10),s.writeUInt16LE(o,12),s.writeUInt16LE(n,14),s.writeUInt32LE(g,16),s.writeUInt32LE(h.length,20),s.writeUInt32LE(u.length,24),s.writeUInt16LE(e.length,28),s.writeUInt32LE(r,42),c.push(l,e,h),d.push(s,e),r+=l.length+e.length+h.length}if(t.length>=65535)throw new Error("\u538B\u7F29\u5305\u91CC\u7684\u6587\u4EF6\u592A\u591A");let i=Buffer.concat(d),f=Buffer.alloc(22);return f.writeUInt32LE(A,0),f.writeUInt16LE(t.length,8),f.writeUInt16LE(t.length,10),f.writeUInt32LE(i.length,12),f.writeUInt32LE(r,16),Buffer.concat([...c,i,f])}var G=new TextDecoder("utf-8",{fatal:!0}),H=new TextDecoder("gbk");function X(t,o){if(o&D)return t.toString("utf8");try{return G.decode(t)}catch{return H.decode(t)}}var Q=t=>t.length>=4&&t.readUInt32LE(0)===T,U=()=>new Error("ZIP \u6587\u4EF6\u5DF2\u635F\u574F"),E=(t,o)=>Number(t.readBigUInt64LE(o));function C(t,o){let n=Math.min(o,65557),c=t(o-n,n),d=-1;for(let e=c.length-22;e>=0;e-=1)if(c.readUInt32LE(e)===A){d=e;break}if(d<0)throw new Error("\u4E0D\u662F\u6709\u6548\u7684 ZIP \u6587\u4EF6");let r=c.readUInt16LE(d+10),i=c.readUInt32LE(d+12),f=c.readUInt32LE(d+16);if(r===65535||i===I||f===I){let e=t(o-n+d-20,20);if(e.readUInt32LE(0)!==W)throw U();let w=t(E(e,8),56);if(w.readUInt32LE(0)!==P)throw U();r=E(w,32),i=E(w,40),f=E(w,48)}let a=t(f,i),u=[];for(let e=0,w=0;w<r;w+=1){if(a.readUInt32LE(e)!==O)throw U();let h=a.readUInt16LE(e+8),m=a.readUInt16LE(e+10),g=a.readUInt32LE(e+20),l=a.readUInt32LE(e+24),s=a.readUInt16LE(e+28),Z=a.readUInt16LE(e+30),N=a.readUInt16LE(e+32),R=a.readUInt32LE(e+42),b=X(a.subarray(e+46,e+46+s),h),p=a.subarray(e+46+s,e+46+s+Z);for(let x=0;x+4<=p.length;x+=4+p.readUInt16LE(x+2)){if(p.readUInt16LE(x)!==1)continue;let S=x+4;l===I&&(l=E(p,S),S+=8),g===I&&(g=E(p,S),S+=8),R===I&&(R=E(p,S))}if(e+=46+s+Z+N,!b.endsWith("/")){if(h&1)throw B(k("{0} \u5DF2\u52A0\u5BC6",b));if(m!==0&&m!==8)throw B(k("{0}\uFF1A\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F",b));u.push({name:b,method:m,packedSize:g,size:l,local:R})}}return u}function M(t,o){let n=t(o.local,30);if(n.readUInt32LE(0)!==T)throw U();return o.local+30+n.readUInt16LE(26)+n.readUInt16LE(28)}function V(t){let o=(n,c)=>{if(n<0||n+c>t.length)throw U();return t.subarray(n,n+c)};return C(o,t.length).map(n=>{let c=o(M(o,n),n.packedSize),d=n.method===0?Buffer.from(c):z.inflateRawSync(c);if(d.length!==n.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",n.name));return{name:n.name,data:d}})}function _(t){let o=L.openSync(t,"r"),n=L.fstatSync(o).size,c=(r,i)=>{if(r<0||r+i>n)throw U();let f=Buffer.alloc(i);for(let a=0;a<i;){let u=L.readSync(o,f,a,i-a,r+a);if(u===0)throw U();a+=u}return f},d;try{d=C(c,n)}catch(r){throw L.closeSync(o),r}return{entries:d,read(r){let i=c(M(c,r),r.packedSize),f=r.method===0?i:z.inflateRawSync(i);if(f.length!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name));return f},async extract(r,i){let f=M(c,r);if(r.packedSize===0)await L.promises.writeFile(i,"");else{let a=L.createReadStream(null,{fd:o,start:f,end:f+r.packedSize-1,autoClose:!1});await F(...r.method===0?[a]:[a,z.createInflateRaw()],L.createWriteStream(i))}if((await L.promises.stat(i)).size!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name))},close:()=>L.closeSync(o)}}export{K as a,Q as b,V as c,_ as d};
@@ -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 y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-ZWPMCK7P.mjs";import{c as P,d as W}from"./chunk-RKPWLGZ3.mjs";import"./chunk-N7AZZLGT.mjs";import"./chunk-UFNYFFKO.mjs";import"./chunk-D4EURAX4.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as R}from"node:crypto";import{existsSync as X,readdirSync as G,readFileSync as Y,statSync as _}from"node:fs";import c from"node:fs/promises";import q from"node:os";import i from"node:path";import{release as J,reportsDirectory as V,skillDirectory as H}from"../browser/shared/paths.mjs";import{copyOldDocuments as Q,ensureWorkspace as Z,layoutOf as z,oldStateOf as K}from"../browser/shared/workspace.mjs";var S=o=>_(o,{throwIfNoEntry:!1})?.isDirectory()??!1;function ee({agent:o=null,project:e=!1,dir:r=null,cwd:t=process.cwd(),env:s=process.env}={}){if(r)return[{agent:null,target:i.resolve(t,r),skills:null}];let a=o?[o]:Object.keys(y),u=d=>e?i.join(i.resolve(t),y[d].project):i.resolve(y[d].home(s)),p=a.filter(d=>S(u(d)));return(o||p.length?o?a:p:["claude"]).map(d=>{let h=i.join(u(d),"skills");return{agent:d,target:i.join(h,"gallery"),skills:h}})}function te(o){try{return C(Y(i.join(o,"SKILL.md"),"utf8"))}catch{return null}}function T(o){let e=_(o,{throwIfNoEntry:!1});if(!e)return{kind:"absent"};if(!e.isDirectory())return{kind:"other",why:"it is a file"};let r=G(o);if(r.length===0)return{kind:"absent"};if(r.includes(".git"))return{kind:"other",why:"it is a git checkout"};let t=te(o),s=u=>r.includes(u);return(s("package.json")&&s("src")||s("reports"))&&(t==="gallery"||t==="html-report-studio")?{kind:"fat",name:t}:t==="gallery"&&!s("package.json")&&!s("src")&&!s("reports")?{kind:"thin"}:{kind:"other",why:t?`its SKILL.md is the skill "${t}"`:"it holds no Gallery skill"}}function oe(o){return S(o)?G(o,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(".")).map(e=>i.join(o,e.name)).filter(e=>T(e).kind==="fat"):[]}function re(o){let e=i.join(K(o),"servers");return S(e)?G(e).filter(r=>r.endsWith(".json")).flatMap(r=>{try{let{pid:t,port:s}=JSON.parse(Y(i.join(e,r),"utf8"));return!Number.isInteger(t)||t<=0||t===process.pid?[]:(process.kill(t,0),[{pid:t,port:s}])}catch(t){return t.code==="EPERM"?[{pid:Number.NaN,port:null}]:[]}}):[]}async function O(o){let e=0,r=0,t=async s=>{for(let a of await c.readdir(s,{withFileTypes:!0})){let u=i.join(s,a.name);a.isDirectory()?await t(u):(e++,r+=(await c.lstat(u)).size)}};return await t(o).catch(()=>{}),{files:e,bytes:r}}var B=o=>`${(o/1024/1024).toFixed(1)} MB`,se=(o,e)=>`${o} ${e}${o===1?"":"s"}`;async function v(o,e){for(let r=0;;r++)try{return await c.rename(o,e)}catch(t){if(process.platform!=="win32"||r>=10||!["EPERM","EBUSY","EACCES"].includes(t.code))throw t;await new Promise(s=>setTimeout(s,100*(r+1)))}}function ne(o,e=new Date){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,t=i.join(z(o).gallery,`old-skill-${r}`);for(let s=1;;s++){let a=s===1?t:`${t}-${s}`;if(!X(a))return a}}async function ie(o,e){await c.mkdir(i.dirname(e),{recursive:!0});try{return await v(o,e),null}catch(s){if(s.code!=="EXDEV")return`${s.code??s.message}`}let r=await O(o);await c.cp(o,e,{recursive:!0,preserveTimestamps:!0,verbatimSymlinks:!0,errorOnExist:!0,force:!1});let t=await O(e);return t.files!==r.files||t.bytes!==r.bytes?`the copy holds ${t.files} files, ${t.bytes} bytes, of ${r.files}, ${r.bytes}: the old folder was left as it was`:(await c.rm(o,{recursive:!0,force:!0}),null)}async function U(o){let e=[],r=async t=>{for(let s of await c.readdir(t,{withFileTypes:!0})){let a=i.join(t,s.name);s.isDirectory()?await r(a):e.push([i.relative(o,a).split(i.sep).join("/"),await c.readFile(a)])}};return await r(o),e.sort(([t],[s])=>t<s?-1:t>s?1:0)}var le=(o,e)=>o.length===e.length&&o.every(([r,t],s)=>r===e[s][0]&&t.equals(e[s][1]));async function ae(o,e,r){if(r==="thin"&&le(await U(o),await U(e)))return"same";let t=i.dirname(e);await c.mkdir(t,{recursive:!0});let s=R(4).toString("hex"),a=i.join(t,`.gallery-skill-new-${s}`);if(await c.cp(o,a,{recursive:!0}),r==="absent")return X(e)&&await c.rmdir(e),await v(a,e),"new";let u=i.join(t,`.gallery-skill-old-${s}`);await v(e,u);try{await v(a,e)}catch(p){throw await v(u,e).catch(()=>{}),await c.rm(a,{recursive:!0,force:!0}),p}return await c.rm(u,{recursive:!0,force:!0}),"updated"}async function $e(o,{version:e}){let{positional:r,options:t,values:s}=M({options:["--project"],values:["--agent","--dir"],argv:o});if(r[0]!=="install")throw new j(r.length?`No such skill command: ${r[0]} (install).`:"Say what to do: gallery skill install.");if(r.length>1)throw new j(`gallery skill install takes no other argument: ${r[1]}`);let a=s.get("--agent")??null;if(a!==null&&!Object.hasOwn(y,a))throw new j(`--agent is claude or codex, not ${a}.`);let u=s.get("--dir")??null;if(u!==null&&(a!==null||t.has("--project")))throw new j("--dir names the skill's folder itself: not with --agent or --project.");let p=ee({agent:a,project:t.has("--project"),dir:u}),d=[],h=p.map(n=>({...n,...T(n.target)}));for(let{target:n,kind:l,why:f}of h)l==="other"&&d.push(`${n} holds something that is not a Gallery skill (${f}): move it away, or pass --dir <another folder>.`);let N=[...new Set(h.flatMap(({target:n,kind:l,skills:f})=>[...l==="fat"?[n]:[],...f?oe(f):[]]))];for(let n of N)for(let{pid:l,port:f}of re(n))d.push(Number.isNaN(l)?`The older Gallery skill ${n} has a preview server running that this user cannot see: stop it first.`:`The older Gallery skill ${n} has its preview server running (pid ${l}${f?`, port ${f}`:""}): stop it first (close the window that runs it, or end process ${l}), then run gallery skill install again.`);if(d.length){for(let n of d)console.error(n);console.error("Nothing was changed."),process.exit(1)}if(N.length){let n=V;try{let{ours:l,reads:f}=await Z(n);l||(console.error(W(n,f)),process.exit(1))}catch(l){if(!l.code)throw l;console.error(P(n,l.code)),process.exit(1)}console.log(`\u5DE5\u4F5C\u533A\uFF1A${n}`);for(let l of N){console.log(`An older Gallery skill (the whole tools) is in ${l}: its documents go into the workspace, then it moves out of the skills folder.`);let f=i.join(l,"reports");if(S(f)){let m=await Q({from:f,to:n,state:K(l)});for(let w of A(m,f,n))console.log(` ${w}`)}else console.log(" It holds no documents (no reports/ folder).");let g=i.join(l,"exports");if(S(g)){let m=z(n).exports;await c.mkdir(m,{recursive:!0});let w=[],I=[];for(let E of(await c.readdir(g)).filter(x=>x.endsWith(".html")).sort())try{await c.copyFile(i.join(g,E),i.join(m,E),c.constants.COPYFILE_EXCL),w.push(E)}catch(x){if(x.code!=="EEXIST")throw x;I.push(E)}w.length&&console.log(` Exports: copied ${se(w.length,"file")} into ${m}: ${w.join(", ")}`),I.length&&console.log(` Exports not copied (the name is taken in ${m}; they stay in the moved folder's exports/): ${I.join(", ")}`)}let{bytes:k}=await O(l),$=await O(i.join(l,"node_modules")),D=ne(n),L=await ie(l,D);L&&(console.error(`Could not move ${l} to ${D} (${L}). Its documents are copied; move the folder out of the skills folder yourself (it is never needed in it again), then run gallery skill install again.`),process.exit(1)),console.log(` Moved the old skill to ${D} (${B(k)}${$.files?`; its node_modules/, ${B($.bytes)}, may be deleted: nothing reads it any more`:""}).`)}}let F=H,b=null;if(!J){let{buildSkill:n}=await import("./chunk-Q47PLKIJ.mjs");b=await c.mkdtemp(i.join(q.tmpdir(),"gallery-skill-")),F=i.join(b,"gallery"),n(F,{version:e})}try{let n=!1;for(let{agent:l,target:f}of h){let g=T(f).kind,k=await ae(F,f,g),$=l?` for ${y[l].name}`:"";console.log(k==="same"?`The Gallery skill ${e}${$} is installed already, unchanged: ${f}`:`${k==="updated"?"Updated":"Installed"} the Gallery skill ${e}${$}: ${f}`),n||=k!=="same"}n&&console.log("Open a new Agent session to use it.")}finally{b&&await c.rm(b,{recursive:!0,force:!0})}}export{y as AGENTS,T as kindOf,$e as run,ee as targetsOf};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as U,b as Z,c as ot,d as q}from"./chunk-TYK6VNAB.mjs";import{E as L,a as _,b as V,h as tt,i as D,k as et,z as nt}from"./chunk-L3QKH4OK.mjs";import{b as J,c as P,e as Q}from"./chunk-A55HN5OK.mjs";import{IDENTITY as Ne}from"../browser/editor/components/registry.mjs";function gt(e){let{blocks:a,locks:r,units:n,boxes:c}=L(e),l=wt(e,[...a.map(t=>({at:t.innerStart-1,text:` data-ge-block="${t.id}"`})),...r.map(t=>({at:t.at,text:` data-ge-lock="${t.reason}"`})),...n.map(t=>({at:t.at,text:` data-ge-unit="${t.id}"${t.grid?" data-ge-grid":""}${t.keep?` data-ge-keep="${t.keep.reason}"${t.keep.own?" data-ge-keep-own":""}`:""}`})),...n.filter(t=>t.lead!==null).map(t=>({at:t.lead,text:` data-ge-lead="${t.id}"`})),...c.map(t=>({at:t.at,text:` data-ge-box="${t.id}"${t.pure?" data-ge-pure":""}`}))]),p={version:_(e),blocks:a.map(t=>({id:t.id,tag:t.tag,kind:t.kind,caps:Object.keys(t.caps),inner:e.slice(t.innerStart,t.innerEnd),atoms:t.atoms,unit:t.unit,...t.path?{path:t.path}:{},...t.self!==null?{self:!0}:{}})),units:n.map(t=>({id:t.id,kind:t.kind,parent:t.parent,hash:D(e,t),...t.blockId?{blockId:t.blockId}:{},...t.keep?{keep:t.keep}:{},...t.grid?{grid:!0}:{},...t.parts?{parts:t.parts}:{}})),boxes:c.map(t=>({id:t.id,kind:t.kind,unit:t.unit,...t.key!==null?{key:t.key}:{}}))};return{html:l,map:p}}function wt(e,a,r=!0){let n=[],c=0;for(let l of[...a].sort((p,t)=>p.at-t.at)){if(e[l.at]!==">"){if(r)throw new Error(`Unexpected start tag before offset ${l.at}.`);continue}let p=et(e,l.at);n.push(e.slice(c,p),l.text),c=p}return n.push(e.slice(c)),n.join("")}Q();import{COMPONENTS as kt,instancesOf as xt,partOf as st}from"../browser/shared/components/index.mjs";import{attr as rt}from"../browser/shared/html-tree.mjs";var at=new Set(["main","section","article","aside","nav","header","footer","div","details","dialog","figure","blockquote","table","ul","ol","dl"]),Nt=new Set(["script","style","template","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext","pre","code","kbd","samp","var","svg","math"]),It=kt.filter(e=>e.match&&e.pairs);function Ot(e){let a=e.replace(/^/," "),r=J(a,{sourceCodeLocationInfo:!0}),n=f=>a.slice(0,f).split(`
2
+ import{a as U,b as Z,c as ot,d as q}from"./chunk-N76HWBA3.mjs";import{e as L}from"./chunk-FJYN7RTH.mjs";import{D as nt,a as _,b as V,l as tt,m as D,o as et}from"./chunk-UBBRTJ2R.mjs";import{b as J,c as P,e as Q}from"./chunk-A55HN5OK.mjs";import{IDENTITY as Ne}from"../browser/editor/components/registry.mjs";function gt(e){let{blocks:a,locks:r,units:n,boxes:c}=L(e),l=wt(e,[...a.map(t=>({at:t.innerStart-1,text:` data-ge-block="${t.id}"`})),...r.map(t=>({at:t.at,text:` data-ge-lock="${t.reason}"`})),...n.map(t=>({at:t.at,text:` data-ge-unit="${t.id}"${t.grid?" data-ge-grid":""}${t.keep?` data-ge-keep="${t.keep.reason}"${t.keep.own?" data-ge-keep-own":""}`:""}`})),...n.filter(t=>t.lead!==null).map(t=>({at:t.lead,text:` data-ge-lead="${t.id}"`})),...c.map(t=>({at:t.at,text:` data-ge-box="${t.id}"${t.pure?" data-ge-pure":""}`}))]),p={version:_(e),blocks:a.map(t=>({id:t.id,tag:t.tag,kind:t.kind,caps:Object.keys(t.caps),inner:e.slice(t.innerStart,t.innerEnd),atoms:t.atoms,unit:t.unit,...t.path?{path:t.path}:{},...t.self!==null?{self:!0}:{}})),units:n.map(t=>({id:t.id,kind:t.kind,parent:t.parent,hash:D(e,t),...t.blockId?{blockId:t.blockId}:{},...t.keep?{keep:t.keep}:{},...t.grid?{grid:!0}:{},...t.parts?{parts:t.parts}:{}})),boxes:c.map(t=>({id:t.id,kind:t.kind,unit:t.unit,...t.key!==null?{key:t.key}:{}}))};return{html:l,map:p}}function wt(e,a,r=!0){let n=[],c=0;for(let l of[...a].sort((p,t)=>p.at-t.at)){if(e[l.at]!==">"){if(r)throw new Error(`Unexpected start tag before offset ${l.at}.`);continue}let p=et(e,l.at);n.push(e.slice(c,p),l.text),c=p}return n.push(e.slice(c)),n.join("")}Q();import{COMPONENTS as kt,instancesOf as xt,partOf as st}from"../browser/shared/components/index.mjs";import{attr as rt}from"../browser/shared/html-tree.mjs";var at=new Set(["main","section","article","aside","nav","header","footer","div","details","dialog","figure","blockquote","table","ul","ol","dl"]),Nt=new Set(["script","style","template","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext","pre","code","kbd","samp","var","svg","math"]),It=kt.filter(e=>e.match&&e.pairs);function Ot(e){let a=e.replace(/^/," "),r=J(a,{sourceCodeLocationInfo:!0}),n=f=>a.slice(0,f).split(`
3
3
  `).length,c=[],l=(f,d,s)=>c.push({key:f,tag:a.slice(d,s).replace(/\s+/g," "),line:n(d),offset:d});V(r,"main")||l("no <main> in the file",0,0);let p=[],t=new Set,k=f=>{for(let d of f.childNodes??[]){let s=d.sourceCodeLocation;if(d.nodeName==="#comment"){s&&p.push([s.startOffset,s.endOffset]);continue}if(d.tagName){if(s?.startTag&&p.push([s.startTag.startOffset,s.startTag.endOffset]),Nt.has(d.tagName)){s&&p.push([s.startOffset,s.endOffset??a.length]);continue}s?.endTag&&t.add(s.endTag.startOffset),at.has(d.tagName)&&s?.startTag&&!s.endTag&&l(`<${d.tagName}> not closed`,s.startTag.startOffset,s.startTag.endOffset),k(d)}}};k(r),p.sort((f,d)=>f[0]-d[0]);let N="",h=0;for(let[f,d]of p)d<=h||(N+=a.slice(h,Math.max(h,f))+" ".repeat(d-Math.max(h,f)),h=d);N+=a.slice(h);for(let f of N.matchAll(/<\/([A-Za-z][A-Za-z0-9]*)[^<>]*>?/g)){let d=f[1].toLowerCase();at.has(d)&&!t.has(f.index)&&l(`</${d}> closes nothing`,f.index,f.index+f[0].length)}for(let f of It)for(let d of xt(r,f))for(let{a:s,attrA:g,b:x,attrB:A}of f.pairs){let o=st(d,f.parts[s].at).map(M=>rt(M,g)),u=st(d,f.parts[x].at).map(M=>rt(M,A)),j=M=>new Set(M).size===M.length,I=j(o)&&j(u)&&o.length===u.length&&o.every(M=>u.includes(M)),b=d.sourceCodeLocation;!I&&b&&l(`${f.id}: ${s} and ${x} do not pair`,b.startOffset,b.startTag?.endOffset??b.startOffset)}return c.sort((f,d)=>f.offset-d.offset).map(({key:f,tag:d,line:s})=>({key:f,tag:d,line:s,text:`${f} (line ${s})`}))}Q();import{treeText as z}from"../browser/shared/annotations.mjs";import{attr as F}from"../browser/shared/html-tree.mjs";var it=2e3*2e3,G=2e3,ct=50,lt=1500;function ft(e,a,r,n){let c="",l=a;for(let p of n)p.end<=l||p.start>=r||(p.start>l&&(c+=e.slice(l,p.start)),l=Math.max(l,p.end));return c+e.slice(l,r)}var dt=e=>e.replace(/\s+/g," ").trim(),bt=e=>/\S/.test(e.replace(/<!--[^]*?-->/g,"").replace(/<[^>]*>/g,"").replace(/\u0000/g,"")),pt=e=>e.companion?[{start:e.start,end:e.end},{start:e.companion.start,end:e.companion.end}]:[{start:e.start,end:e.end}];function H(e){let a=L(e),{units:r,blocks:n}=a,c=r[0]?.node??n[0]?.node??null;for(;c?.parentNode;)c=c.parentNode;let l=c?tt(e,[c]):[],p=[...r].sort((o,u)=>o.start-u.start||u.end-o.end),t=new Map,k=[];for(let o of p){for(;k.length&&k.at(-1).end<=o.start;)k.pop();t.set(o,k.at(-1)??null),k.push(o)}for(let o of r.filter(u=>u.companion)){let{start:u,end:j}=o.companion;for(let I of r){if(I===o||I.start<u||I.end>j)continue;let b=t.get(I);(!b||b.start<u)&&t.set(I,o)}}let N=new Map;for(let o of r){let u=t.get(o);u&&N.set(u,[...N.get(u)??[],o])}let h=n.find(o=>o.kind==="title")??null,f=[...r.map(o=>({unit:o,at:o.elStart})),...h?[{unit:null,at:h.start}]:[]].sort((o,u)=>o.at-u.at),d=new Map(f.map((o,u)=>[o.unit,u])),s=new Map;for(let o of r)o.blockId&&s.set(o.blockId,(s.get(o.blockId)??0)+1);let g=f.map(({unit:o})=>{if(!o){let $=dt(ft(e,h.start,h.end,l));return{unit:null,title:!0,kind:"title",key:`title\0${$}`,own:$,counts:1,parent:null,blockId:null,text:z(h.node).slice(0,G)}}let u=N.get(o)??[],j=[...u.flatMap(pt),...l].sort(($,R)=>$.start-R.start),I=dt(pt(o).map(({start:$,end:R})=>ft(e,$,R,j)).join("\0")),b=u.length>0&&!bt(I),M=t.get(o);return{unit:o,kind:o.kind,key:`${o.kind}\0${I}`,own:I,counts:b?0:1,parent:M?d.get(M):null,blockId:o.blockId,text:z(o.node).slice(0,G)}}),x=null;return{rows:g,scanned:a,ref:o=>o.title?{title:!0}:o.blockId&&s.get(o.blockId)===1?{id:o.blockId}:(x??=(()=>{let u=new Map,j=new Map;for(let{unit:I}of f){if(!I)continue;let b=D(e,I);j.set(I,{hash:b,nth:u.get(b)??0}),u.set(b,(u.get(b)??0)+1)}return j})(),x.get(o.unit))}}function St(e,a){if(e.length*a.length<=it)return Z(e,a);let r=s=>s.reduce((g,x)=>g.set(x,(g.get(x)??0)+1),new Map),[n,c]=[r(e),r(a)],l=new Map;a.forEach((s,g)=>{c.get(s)===1&&n.get(s)===1&&l.set(s,g)});let p=[];e.forEach((s,g)=>{l.has(s)&&p.push([g,l.get(s)])});let t=[],k=[];p.forEach(([,s],g)=>{let x=0,A=t.length;for(;x<A;){let o=x+A>>1;p[t[o]][1]<s?x=o+1:A=o}k[g]=x>0?t[x-1]:-1,t[x]=g});let N=[];for(let s=t.at(-1)??-1;s>=0;s=k[s])N.unshift(p[s]);let h=[],[f,d]=[0,0];for(let[s,g]of[...N,[e.length,a.length]]){if((s-f)*(g-d)<=it)for(let[x,A]of Z(e.slice(f,s),a.slice(d,g)))h.push([f+x,d+A]);s<e.length&&h.push([s,g]),[f,d]=[s+1,g+1]}return h}var ut=(e,a)=>a.nested?z(P(e.slice(a.innerStart,a.innerEnd))):z(a.node),mt=e=>e.match(/[A-Za-z0-9]+|\s+|[^A-Za-z0-9\s]/gu)?.length??0,ht=({scanned:e},a)=>(a.title?e.blocks.filter(r=>r.kind==="title"):e.blocks.filter(r=>r.unit===a.unit.id)).sort((r,n)=>r.innerStart-n.innerStart);function yt(e){let a=[],r=n=>{for(let c of n.childNodes??[])c.tagName==="tr"?a.push((c.childNodes??[]).filter(l=>l.tagName==="td"||l.tagName==="th").map(l=>z(l).replace(/\s+/g," ")).join(" \xB7 ")):c.tagName&&r(c.tagName==="template"?c.content:c)};return r(e),a.length?a.join(`
4
4
  `):z(e)}function Mt(e,a,r){let n=e[a],c=0;for(let N=n.parent;N!==null;N=e[N].parent)r(N)&&(c+=1);let l=n.title?"h1":n.unit.node.tagName,p=n.title?n.text:yt(P(n.own.replace(/\u0000/g," "))).slice(0,G),t={kind:n.kind,tag:l,depth:c,text:p},k=l==="li"?n.unit.node.parentNode:null;if((k?.tagName==="ul"||k?.tagName==="ol")&&(t.marker=k.tagName,k.tagName==="ol")){let N=(k.childNodes??[]).filter(h=>h.tagName==="li");t.number=(Number.parseInt(F(k,"start")??"1",10)||1)+N.indexOf(n.unit.node)}return t}function $t(e,a){if(e===a)return null;let r=H(e),n=H(a),[c,l]=[r.rows.map(i=>i.key),n.rows.map(i=>i.key)],p=St(c,l);if(p.length===c.length&&p.length===l.length)return null;let t=i=>{let w=new Map;for(let S of i)S.blockId&&w.set(S.blockId,(w.get(S.blockId)??0)+1);return S=>!!S.blockId&&w.get(S.blockId)===1},[k,N]=[t(r.rows),t(n.rows)],h=[],[f,d]=[0,0];for(let[i,w]of[...p,[c.length,l.length]]){let S=new Map;for(let m=d;m<w;m++)N(n.rows[m])&&S.set(n.rows[m].blockId,m);let T=[],v=d-1;for(let m=f;m<i;m++){let O=k(r.rows[m])?S.get(r.rows[m].blockId):void 0;O!==void 0&&O>v&&(T.push([m,O]),v=O)}let B=[],[y,E]=[f,d];for(let[m,O]of[...T,[i,w]]){for(;y<m;y++){let C=r.rows[y];for(let W=E;W<O;W++){let Y=n.rows[W];if(Y.kind===C.kind&&(C.title||ot(C.own,Y.own))){B.push([y,W]),E=W+1;break}}}m<i&&B.push([m,O]),[y,E]=[m+1,O+1]}B.sort((m,O)=>m[0]-O[0]),[y,E]=[f,d];for(let[m,O]of[...B,[i,w]]){for(;y<m;y++)h.push({type:"del",i:y});for(;E<O;E++)h.push({type:"ins",j:E});m<i&&h.push({type:"chg",i:m,j:O}),[y,E]=[m+1,O+1]}i<c.length&&h.push({type:"same",i,j:w}),[f,d]=[i+1,w+1]}let s=new Set(h.filter(i=>i.type==="ins").map(i=>i.j)),g=new Set(h.filter(i=>i.type==="del").map(i=>i.i)),x=(i,w)=>{let S=new Set;for(let T of w)if(i[T].counts)for(let v=i[T].parent;v!==null;v=i[v].parent)S.add(v);return T=>i[T].counts||(S.has(T)?0:1)},[A,o]=[x(n.rows,s),x(r.rows,g)],u={added:0,changed:0,removed:0},j=[],I=[],b=[],M,$=null,R=null,K=i=>{if(!$)return;let w=Math.max(0,$.rows.length-ct);b.push({...i!==null?{before:n.ref(n.rows[i])}:R!==null?{after:n.ref(n.rows[R])}:{into:"main"},count:$.count,rows:$.rows.slice(0,ct),...w?{more:w}:{}}),$=null},X=i=>g.has(i)&&r.rows[i].counts>0;for(let i of h){if(i.type==="del"){$??={count:0,rows:[]},$.count+=o(i.i),u.removed+=o(i.i),X(i.i)&&$.rows.push(Mt(r.rows,i.i,X));continue}if(K(i.j),R=i.j,i.type==="ins"){let w=n.rows[i.j];u.added+=A(i.j),(w.parent===null||!s.has(w.parent))&&j.push({ref:n.ref(w)})}else if(i.type==="chg"){let[w,S]=[r.rows[i.i],n.rows[i.j]];u.changed+=1;let T=ht(r,w),v=ht(n,S),B=[],y=T.length!==v.length||T.length===0||T.some((E,m)=>E.tag!==v[m].tag);y||(T.forEach((E,m)=>{let[O,C]=[ut(e,E),ut(a,v[m])];mt(O)>lt||mt(C)>lt?y=!0:O!==C&&B.push({nth:m,base:O})}),B.length===0&&(y=!0)),y&&(B=[]),I.push({ref:n.ref(S),...y?{whole:!0}:{texts:B}}),S.title&&(M={base:w.text})}}return K(null),{counts:u,added:j,changed:I,...M?{title:M}:{},removed:b}}function Tt(e){let{units:a}=L(e),r=c=>{for(let l=c;l;l=l.parentNode)if(l.tagName&&(F(l,"data-doc-placeholder")!==void 0||l.tagName==="header"||(F(l,"class")??"").split(/\s+/).includes("doc-header")))return!1;return!0},n=c=>/^(img|picture|svg|canvas|video|audio|iframe|object|embed)$/.test(c.tagName??"")||(c.childNodes??[]).some(n);return!a.some(c=>r(c.node)&&(z(c.node)!==""||n(c.node)))}function jt(e,a){try{return q({current:e,ids:!0,...a}).text}catch{return e}}function Et(e,a){try{let r=L(e).blocks.find(c=>c.kind==="title");if(!r)return e;let n=U({current:e,edits:[{id:r.id,parts:[{keep:!0,html:a}]}],ids:!1});return n.ok?n.text:e}catch{return e}}var we=(e,a,r,n)=>nt.installed.rewrite(e,a,r,{packages:n});export{gt as a,Ot as b,$t as c,Tt as d,jt as e,Et as f,we as g};
@@ -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 Kt,b as Ut}from"./chunk-PZDLJJTJ.mjs";import{a as Bt}from"./chunk-UMHUSOPJ.mjs";import{randomBytes as At}from"node:crypto";import y from"node:fs/promises";import m from"node:path";import{writeAtomic as J}from"../browser/shared/files.mjs";import{sendJson as H}from"../browser/shared/http.mjs";import{said as B,saying as Pt}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as _e}from"../browser/shared/paths.mjs";import{moveDocument as Te,outlineAndFile as Ce,placeIn as wt,readOutline as Fe,validOutline as te,withOutlineLock as Je,writeOutline as Ge,writtenAs as Ye}from"../browser/shared/outline.mjs";import{DOCS as mt,isForeign as ee,isTop as pt,topOf as kt}from"../browser/shared/outline-shape.mjs";import{addDraft as ne,addWorkspace as We,draftEntry as Me,draftFacts as re,draftOf as Lt,findDraft as He,foreignMarker as Ve,projectChoices as Be,registeredIds as oe,workspaceNames as Ke,workspaceOf as X}from"../browser/shared/drafts.mjs";import{forgetSnapshot as ht,shownWorkspaces as Ue}from"../browser/shared/workspace-columns.mjs";import{nameStops as ze}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as De,workspaceId as gt,workspaceKey as ie}from"../browser/shared/workspace-registry.mjs";import{spawn as Xt}from"node:child_process";import Se from"node:os";import Et from"node:path";import{NO_DEFAULT_TREE as ve}from"../browser/shared/drafts.mjs";import{said as zt}from"../browser/shared/i18n/index.mjs";import{packageRoot as be}from"../browser/shared/paths.mjs";import{answerOf as Dt,compareVersions as xe,galleryVersion as Ee,readAnnouncement as xt}from"../browser/shared/preview-server.mjs";import{isWorkspace as Ae,readRegistry as Pe,workspaceId as Le,workspaceKey as dt}from"../browser/shared/workspace-registry.mjs";var Qt={rename:["slug","title"],create:["title","description","language"]},Ie=9e4,Ne=f=>!["","0",void 0].includes(f);function Re(f,{platform:b=process.platform,env:l=process.env}={}){return Ne(l.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:b==="win32"?{command:Et.join(l.SystemRoot||l.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${f}"`],verbatim:!0}:b==="darwin"?{command:"open",args:["-R",f]}:!l.DISPLAY&&!l.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[Et.dirname(f)]}}function Zt(f,b){let l=Re(f,b);return l.skip?Promise.resolve({opened:!1,why:l.skip}):new Promise(L=>{let R;try{R=Xt(l.command,l.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!l.verbatim})}catch(P){return L({opened:!1,why:P.code??P.message})}R.once("error",P=>L({opened:!1,why:P.code??P.message})),R.once("spawn",()=>{R.unref(),L({opened:!0})})})}function $e(f){let b=/^http:\/\/127\.0\.0\.1:(\d{1,5})$/.exec(String(f??"")),l=b?Number(b[1]):0;return l>0&&l<65536?l:null}function qt({root:f,changed:b=()=>{},log:l=()=>{},gallery:L=Et.join(be,"bin","gallery.mjs")}){let R=dt(f),P=new Map;function yt(p){let d={...process.env,[ve]:"1",GALLERY_NO_UPDATE_CHECK:"1"};return delete d.GALLERY_WORKSPACE,delete d.GALLERY_SERVER_KIND,d.GALLERY_VITE_CACHE_DIR&&(d.GALLERY_VITE_CACHE_DIR=`${d.GALLERY_VITE_CACHE_DIR}-${Le(p)}`),new Promise(v=>{let E=[],A;try{A=Xt(process.execPath,[L,"--workspace",p,"open","--no-browser"],{cwd:Se.homedir(),env:d,stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch(j){return v({ok:!1,message:j.message})}A.stdout.on("data",j=>E.push(String(j))),A.stderr.on("data",j=>E.push(String(j)));let O=setTimeout(()=>A.kill(),Ie);A.once("error",j=>{clearTimeout(O),v({ok:!1,message:j.message})}),A.once("exit",j=>{clearTimeout(O);let $=E.join("").trim().split(/\r?\n/).filter(Boolean);v(j===0?{ok:!0}:{ok:!1,message:$.slice(-3).join(" ")||`gallery open ended with ${j}`})})})}async function lt(p){let d=await xt({reportsDirectory:p});return!d||await Dt(d,p,5e3)!=="yes"||d.kind!=="dev"&&xe(d.version,Ee)<0?null:{port:d.port,token:d.token,pid:d.pid}}async function G(p,{start:d=!0}={}){if(dt(p)===R)return{refused:"self",message:"\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"};if(!Ae(p))return{refused:"workspace",message:zt("\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A{0} \u4E0D\u5728\u4E86",p)};let v=await lt(p);if(v||!d)return v??{refused:"start",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u5728\u8FD0\u884C"};let E=dt(p);P.has(E)||(l(`starting the server of ${p}`),P.set(E,yt(p).finally(()=>P.delete(E))));let A=await P.get(E);return await lt(p)??{refused:"start",message:A.ok?"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54":zt("\u6CA1\u80FD\u542F\u52A8\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\uFF1A{0}",A.message)}}async function Ot(p,d,v){if(!Object.hasOwn(Qt,d))return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let E=await G(p);if(E.refused)return[409,{ok:!1,reason:E.refused,message:E.message}];let A=Object.fromEntries(Qt[d].filter(j=>v?.[j]!==void 0).map(j=>[j,v[j]])),O=`127.0.0.1:${E.port}`;try{let j=await fetch(`http://${O}/__gallery/workspace/${d}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${O}`,"X-Gallery-Token":E.token},body:JSON.stringify(A),signal:AbortSignal.timeout(3e4)}),$=await j.json().catch(()=>null);return $&&typeof $.ok=="boolean"?[j.status,$]:[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C"}]}catch{return[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}]}}let S=new Map;async function W(p){let d=$e(p);if(d===null)return!1;let v=S.get(d);if(v&&Date.now()-v.at<6e4)return v.answer;let E=(async()=>{for(let{root:A}of Pe().workspaces){let O=await xt({reportsDirectory:A});if(O?.port===d&&await Dt(O,A,3e3)==="yes")return!0}return!1})();return S.set(d,{at:Date.now(),answer:E}),E}let q=new Map,C=new Map,K=new Set,c=!1;async function et(p,d,v){let E=new AbortController,A={controller:E,port:v.port};C.set(p,A);try{let O=await fetch(`http://127.0.0.1:${v.port}/__gallery/events?workspace=own`,{signal:E.signal});if(!O.ok||!O.body)return;K.has(p)&&b(d),K.add(p);let j=new TextDecoder,$="";for await(let jt of O.body){$+=j.decode(jt,{stream:!0});for(let I=$.indexOf(`
3
+
4
+ `);I>=0;I=$.indexOf(`
5
+
6
+ `)){let St=$.slice(0,I);$=$.slice(I+2),/^data: workspace /m.test(St)&&b(d)}}}catch{}finally{C.get(p)===A&&C.delete(p)}}async function U(){for(let[p,d]of C)q.has(p)||d.controller.abort();for(let[p,d]of q){if(c||C.has(p)||dt(d)===R)continue;let v=await xt({reportsDirectory:d});v&&!C.has(p)&&!c&&et(p,d,v)}}let F=Promise.resolve(),x=setInterval(()=>{F=F.then(U).catch(()=>{})},3e3);x.unref();function Y(p){q.clear();for(let[d,v]of p)v&&q.set(d,v);F=F.then(U).catch(()=>{})}function nt(){c=!0,clearInterval(x);for(let{controller:p}of C.values())p.abort();C.clear()}return{serverOf:G,forward:Ot,shellVouched:W,follow:Y,close:nt,get following(){return[...C.keys()]}}}import{LINK_FILE as It,linkStem as Qe,linkValue as at,ownAddress as Nt,readLinkText as Xe}from"../browser/shared/web-links.mjs";import{sameDirectory as Z}from"../browser/shared/preview-server.mjs";import{listReportSlugs as Ze,slugPattern as _}from"../browser/shared/reports.mjs";import{COMPONENTS_FOLDER as qe,DOCUMENT_FOLDERS as tn,PAGE_SLUG as en,SHARED_FOLDERS as Rt,defaultWorkspace as nn,documentDirectory as rn,documentFiles as st,ensureWorkspace as on,idHolder as an,isDocSlug as sn,layoutOf as ae,listTrash as cn,newDocSlug as $t,packageFolders as ln,pageSlug as un,readLink as _t,slugTaken as fn,trashIdPattern as se}from"../browser/shared/workspace.mjs";import{HOME as dn,listPages as wn,pageFiles as ct,readPageMeta as ce,renamePage as mn}from"../browser/shared/pages.mjs";import{listExtensions as pn}from"../browser/shared/extensions.mjs";import{effectiveLook as Tt,ownLookFor as kn,ownLookOf as hn,sameLook as gn,withLookField as le}from"../browser/shared/document-look.mjs";import{workspaceLook as Ct,writeWorkspaceLook as yn}from"../browser/shared/workspace-look.mjs";import{findIn as On,tidyQuery as jn}from"../browser/shared/search.mjs";var Sn=([f,b,l,...L])=>L.length?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",f,b,l,L.length+3):l!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",f,b,l):b!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",f,b):B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",f),ue=f=>f==="en"?"en":null,vn=32*1024*1024;async function V(f,b){for(let l=0;;l++)try{return await y.rename(f,b)}catch(L){if(!["EPERM","EBUSY","EACCES"].includes(L.code))throw L;if(l>=5)break;await new Promise(R=>setTimeout(R,60*(l+1)))}await y.cp(f,b,{recursive:!0,errorOnExist:!0,force:!1}),await y.rm(f,{recursive:!0,force:!0,maxRetries:5})}var bn=f=>m.resolve(f);function ar({edits:f,reports:b,reportsDirectory:l=_e,server:L={kind:"dev",version:null,stop:null},components:R=null,changed:P=()=>{},relayed:yt=P,index:lt=null,web:G=null,elsewhere:Ot=null}){let{trash:S}=ae(l),W=Ot??qt({root:l,changed:t=>{t&&ht(t),yt()}}),q=null,C=()=>q??=ze(),K=lt??Ut({root:l,read:Kt(f),draw:(t,e)=>b.words(t,e)}),c=(t,e,n)=>[t,{ok:!1,reason:e,...Pt(n)}],et=t=>y.readFile(t,"utf8").then(JSON.parse).catch(()=>null),U=t=>rn(t,l),F=t=>st(U(t)),x=t=>m.join(l,t),Y=t=>tt(st(x(t)).html),nt=t=>Promise.resolve(f.forgetChanges?.(t)).catch(()=>{}),p=async t=>{let e=await y.readdir(x(t),{withFileTypes:!0});if(!Rt.includes(t))return e.map(({name:r})=>r);let n=t===qe?new Set(ln(l).map(({id:r})=>r.split("/")[0])):new Set;return e.filter(r=>r.isFile()||tn.includes(r.name)&&!n.has(r.name)).map(({name:r})=>r)},d=async(t,e,n)=>{await y.mkdir(n,{recursive:!0});let r=[];try{for(let o of t)await V(m.join(e,o),m.join(n,o)),r.push(o)}catch(o){for(let i of r)await V(m.join(n,i),m.join(e,i));throw o}},v=async(t,e)=>{if(!Rt.includes(t))return V(x(t),e);await d(await p(t),x(t),e),await y.rmdir(x(t)).catch(()=>{})},E=async(t,e)=>Rt.includes(t)&&!await Y(t)&&(await Promise.all((await y.readdir(e)).map(n=>tt(m.join(x(t),n))))).every(n=>!n),A=async t=>await et(st(t).json)??{},O=async t=>{let{title:e=t,description:n="",type:r,instructions:o,icon:i,look:a}=await A(U(t)),s=o===!0?{}:Tt(a,Ct(l));return{slug:t,title:e,description:n,...r?{type:r}:{},...typeof i=="string"&&i?{icon:i}:{},...o===!0?{instructions:!0}:{},...Object.keys(s).length?{look:s}:{}}},j=async t=>{let e=await _t(x(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},$=async(t,e,n=[])=>{let r=Lt(t),o=r&&n.find(({id:M})=>M===r.ws),i=o?.facts.get(r.slug);if(i){let M=m.join(o.root,r.slug);return{slug:t,title:i.title,description:i.description,kind:"draft",workspace:r.ws,...i.icon?{icon:i.icon}:{},path:i.path,folder:M,root:o.root}}let{ws:a,title:s,description:u,icon:k,path:g,folder:w,root:h,missing:N}=await re(t,e);return{slug:t,title:s,description:u,kind:"draft",workspace:a,...k?{icon:k}:{},...g?{path:g,folder:w,root:h}:{},...N?{missing:N}:{}}},jt=async(t,e,n,r)=>ee(t)?$(t,n,r):e.includes(t)?await j(t)??{slug:t,title:t,description:"",kind:"link",url:""}:O(t),I=gt(l),St=()=>ie(nn())===ie(l),fe=(t,e)=>{let n=t.shown.find(({isDefault:s})=>s)?.id??(St()?I:null),r=new Set([...t.drafts.map(s=>Lt(s)?.ws),...t.groups.map(({workspace:s})=>s),...t.shown.map(({id:s})=>s)].filter(Boolean)),o=new Set(t.groups.filter(({workspace:s,title:u})=>s&&!u).map(({workspace:s})=>s));t.groups.find(({id:s})=>s===mt)?.title||o.add(I),o.delete(n);let i=Ke(new Set([...r,I]),{ids:new Map([...e,[I,[l]]]),stops:C(),among:o});W.follow(new Map([...i].filter(([s])=>s!==I).map(([s,{root:u}])=>[s,u])));let a=Object.fromEntries([...r].map(s=>[s,{...i.get(s)??{missing:X(s,e).refused??"unknown"},...s===n?{default:!0}:{}}]));return a[I]={...i.get(I),there:!0,self:!0,...I===n?{default:!0}:{}},a},z=()=>un(l),de=async(t,e)=>{let n=await A(U(t));await J(F(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
7
+ `)},tt=t=>y.access(t).then(()=>!0,()=>!1),ut=async(t,{own:e=null}={})=>{let n=new Set((await rt()).map(({slug:r})=>r));n.delete(e);for(let r=1;;r++){let o=r===1?t:`${t}-${r}`;if(!fn(o,l)&&!n.has(o))return o}},vt=async t=>{let e=await ut(t.slug,{own:t.slug});return sn(t.slug)?e===t.slug&&!await an(t.slug,l)?e:$t(l):e},Ft=async(t,e)=>{let n=F(t).html,r=await y.readFile(n,"utf8"),o=Bt(r).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);o!==r&&await J(n,o)},T=()=>Fe(l),D=async t=>{await Ge(l,t),P()},Q=t=>Je(l,t);async function ft(t,e="",n=1/0){await Q(async()=>{let r=await T();wt(r,t,e,n),await D(r)})}async function Jt(t,{parent:e="",after:n=null,first:r=!1}={}){await Q(async()=>{let o=await T();for(let a of Object.values(o.children))a.includes(t)&&a.splice(a.indexOf(t),1);let i=typeof n=="string"?Object.keys(o.children).find(a=>o.children[a].includes(n)):void 0;i!==void 0?wt(o,t,i,o.children[i].indexOf(n)+1):wt(o,t,typeof e=="string"?e:"",r===!0?0:1/0),await D(o)})}function we(t,e){let n=new Set(Object.values(t.children).flat()),r={...t.children};for(let{id:o}of e.groups){if(o===mt)continue;let i=a=>{let s=(e.children[a]??[]).filter(u=>!n.has(u));(pt(a)||s.length)&&(r[a]=s),s.forEach(i)};i(kt(o))}return{groups:e.groups,children:r}}function Gt(t){return Q(async()=>{let e=await T();for(let[n,r]of Object.entries(e.children)){let o=r.indexOf(t);if(!(o<0))return r.splice(o,1,...e.children[t]??[]),delete e.children[t],await D(e),{parent:n,index:o}}return{parent:"",index:1/0}})}let me=(t,e)=>K.lines(t,e),Yt=t=>et(m.join(S,t,"entry.json")),rt=()=>cn(l);async function pe(t){if(t===dn)return c(409,"home","\u9996\u9875\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");let e=await ce(t,l);if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${At(3).toString("hex")}`;try{await y.mkdir(m.join(S,n),{recursive:!0}),await V(ct(t,l).folder,m.join(S,n,"page"))}catch(o){throw await y.rm(m.join(S,n),{recursive:!0,force:!0}).catch(()=>{}),o}let r={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await J(m.join(S,n,"entry.json"),`${JSON.stringify(r,null,2)}
8
+ `),[200,{ok:!0,entry:r}]}async function ke(t){let e=m.join(S,t.id,"page"),n=await vt(t);if(await y.mkdir(ae(l).customPages,{recursive:!0}),await V(e,ct(n,l).folder),n!==t.slug){let{html:r}=ct(n,l),o=await y.readFile(r,"utf8").catch(()=>null),i=o?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);o!==null&&i!==o&&await J(r,i)}return await y.rm(m.join(S,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await ce(n,l),entry:{...t,slug:n}}]}async function he(t){let e=await _t(x(t));if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${At(3).toString("hex")}`,r=await T(),{parent:o,index:i}=await Gt(t);try{await y.mkdir(m.join(S,n),{recursive:!0}),await V(x(t),m.join(S,n,"link"))}catch(s){throw await Q(()=>D(r)),await y.rm(m.join(S,n),{recursive:!0,force:!0}).catch(()=>{}),s}let a={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:o,index:Number.isFinite(i)?i:-1};return await J(m.join(S,n,"entry.json"),`${JSON.stringify(a,null,2)}
9
+ `),[200,{ok:!0,entry:a}]}async function ge(t){let e=m.join(S,t.id,"link"),n=await vt(t);return await V(e,x(n)),await y.rm(m.join(S,t.id),{recursive:!0,force:!0}),await ft(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await j(n),entry:{...t,slug:n}}]}function ye(t,{parent:e,after:n,first:r}){let o=a=>pt(a)?Object.hasOwn(t.children,a):Object.values(t.children).some(s=>s.includes(a));if(n!=null){let a=Object.keys(t.children).find(s=>t.children[s].includes(n));return a===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==a?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:a,index:t.children[a].indexOf(n)+1}}let i=e??kt(mt);return pt(i)&&t.groups.some(a=>a.extension&&kt(a.id)===i)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:o(i)?{parent:i,index:r?0:(t.children[i]??[]).length}:{refused:[404,"parent",pt(i)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let ot=new Map;function Oe(t){let e=ot.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=G?G.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return ot.size>=500&&ot.delete(ot.keys().next().value),ot.set(t,{at:Date.now(),answer:n}),n}function Wt(t,e){return G?.icon?(async()=>{let n=await G.icon(e).catch(()=>null);if(!n)return null;let r=m.join(x(t),It),o=await y.readFile(r,"utf8").catch(()=>null),i=o===null?null:Xe(o);if(!i||i.url!==e||i.siteIcon===n)return null;let a=at({...i,siteIcon:n});return a.refused||!a.value.siteIcon||!await J(r,`${JSON.stringify(a.value,null,2)}
10
+ `,{expect:o})?null:(P(),n)})().catch(()=>null):Promise.resolve(null)}let Mt={info:async()=>[200,{ok:!0,version:1,gallery:L.version,token:f.token,commands:[...Object.keys(it)],server:{pid:process.pid,workspace:m.resolve(l),kind:L.kind}}],async outline(){let{outline:t,others:e}=await Ce(l),n=await z(),r=[...Object.values(t.children).flat(),...n?[n]:[]],o=oe(),i=async w=>[w,await jt(w,t.links,o,e)],[a,s,u,k]=await Promise.all([Promise.all(r.map(i)),wn(l),rt(),pn(l)]),g=k.map(({id:w,title:h,icon:N,entries:M,count:bt,error:Vt})=>({id:w,title:h,...N?{icon:N}:{},entries:M,count:bt,...Vt?{error:Pt(Vt)}:{}}));return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(a),pages:s,trash:u,workspaces:fe(t,o),self:I,extensions:g}]},trash:async()=>[200,{ok:!0,entries:await rt()}],async stats(t){let e=t.get("slug")??"",n=_.test(e)?await K.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async query(t){let e;try{e=JSON.parse(t.get("options")??"{}")}catch{return[400,{ok:!1,reason:"options",message:"options is JSON"}]}return K.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,...R.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!_.test(e))return c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=m.resolve(n?ct(e,l).html:F(e).html);return await tt(r)?[200,{ok:!0,path:r}]:c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await Be(l,{stops:C()})}],shell:async t=>[200,{ok:!0,shell:await W.shellVouched(t.get("origin"))}],async search(t){let e=jn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:r,links:o}=await T(),i=[],a=w=>(n[w]??[]).forEach(h=>{!o.includes(h)&&!ee(h)&&i.push(h),a(h)});for(let{id:w}of r)a(kt(w));let s=e.toLowerCase(),u=new Map(await Promise.all(i.map(async w=>[w,await O(w)]))),k=JSON.stringify([...u].map(([w,{title:h}])=>[w,h])),g=(await Promise.all(i.map(async w=>{let h=await me(w,k);if(!h)return null;let N=String(u.get(w).title).toLowerCase().includes(s),{count:M,hits:bt}=On(h,e);return N||M?{slug:w,title:N,count:M,hits:bt}:null}))).filter(Boolean);return g.sort((w,h)=>Number(h.title)-Number(w.title)||h.count-w.count),[200,{ok:!0,results:g.slice(0,50)}]}},it={async outline({outline:t,base:e}){return!te(t)||e!==void 0&&!te(e)?c(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):await Q(async()=>{let r=await T();return e!==void 0&&!Ye(e,r)?!1:(await D(t.groups?t:we(t,r)),!0)})?[200,{ok:!0,outline:await T()}]:c(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:e,after:n=null,first:r=!1,workspace:o}){if(typeof o=="string"&&!Z(o,l))return c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let i=u=>typeof u=="string"&&_.test(u);if(!i(t)||e!==void 0&&e!==""&&!i(e)||n!==null&&!i(n)||typeof r!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let a=await z();if(a!==null&&[t,e,n].includes(a))return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let s=await Te(l,t,{parent:e,after:n,first:r});if(s.written&&P(),!s.ok){let[u,k]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"]}[s.reason];return c(u,s.reason,k)}return[200,{ok:!0,...s,outline:await T()}]},async create({title:t,description:e,parent:n="",after:r=null,first:o=!1,language:i}){let a=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",s=await $t(l);return await nt(s),await b.create(s,a,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:ue(i)}),await Jt(s,{parent:n,after:r,first:o}),[200,{ok:!0,report:await O(s)}]},async instructions({title:t,description:e,language:n}){let r=await z();if(r)return[200,{ok:!0,report:await O(r)}];let o=await ut(en),i=(a,s)=>typeof a=="string"&&a.trim()?a.trim().slice(0,200):s;return await b.create(o,i(t,"\u5199\u4F5C\u504F\u597D"),i(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:ue(n),page:!0}),await de(o,"instructions"),[200,{ok:!0,report:await O(o)}]},async components({id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:i,pack:a,enabled:s}){try{return[200,{ok:!0,...await R.write(a!==void 0?{pack:a,enabled:s}:{id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:i})}]}catch(u){return c(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=await $t(l);await nt(r);let o=new Set(["",...await p(t)]);await y.cp(x(t),x(r),{recursive:!0,errorOnExist:!0,filter:w=>o.has(m.relative(x(t),w).split(m.sep)[0])}),await Ft(r,t);let{title:i}=await O(t),a=i||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),s=await f.renameReport(r,`${a}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),u=await T(),[k,g]=Object.entries(u.children).find(([,w])=>w.includes(t))??["",null];return await ft(r,k,g?g.indexOf(t)+1:1/0),[200,{ok:!0,report:await O(r),notes:s.notes??[]}]},async look({slug:t,look:e}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await z())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return c(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=F(t).json,r=null;try{r=JSON.parse(await y.readFile(n,"utf8"))}catch{}if(!r||typeof r!="object"||Array.isArray(r))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let o=le(r,kn(e,Ct(l)));return JSON.stringify(o)!==JSON.stringify(r)&&await J(n,`${JSON.stringify(o,null,2)}
11
+ `),[200,{ok:!0,report:await O(t)}]},async looks({slug:t}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await z();if(t===e)return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await et(F(t).json);if(!n||typeof n!="object"||Array.isArray(n))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=Ct(l),o=Tt(n.look,r);try{await yn(l,o)}catch(u){return c(409,"workspace",u)}let i=0,a=(await Ze(l)).filter(u=>u!==e).map(u=>({json:F(u).json,self:u===t})),s=(await rt()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:st(m.join(S,u,"report")).json,self:!1}));for(let{json:u,self:k}of[...a,...s])for(let g=0;g<3;g++){let w=await y.readFile(u,"utf8").catch(()=>null),h=null;try{h=JSON.parse(w??"")}catch{}if(!h||typeof h!="object"||Array.isArray(h)||!Object.hasOwn(h,"look")||h.instructions===!0)break;let N=await J(u,`${JSON.stringify(le(h,{}),null,2)}
12
+ `,{expect:w}).catch(()=>null);if(N===null)break;if(N){!k&&Object.keys(hn(h.look)).length>0&&!gn(Tt(h.look,r),o)&&i++;break}}return[200,{ok:!0,look:o,replaced:i,report:await O(t)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!_.test(t))return c(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let o;try{o=await mn(t,e,l)}catch{return c(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return o?[200,{ok:!0,page:o}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let r=await f.renameReport(t,e);return r.ok?[200,{ok:!0,report:await O(t),notes:r.notes}]:c({title:400,missing:404}[r.reason]??409,r.reason,r.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!_.test(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return pe(t);if(e==="link")return he(t);if(t===await z())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await O(t),r=`${Date.now().toString(36)}-${At(3).toString("hex")}`,o=await T(),{parent:i,index:a}=await Gt(t);try{await y.mkdir(m.join(S,r),{recursive:!0}),await v(t,m.join(S,r,"report"))}catch(u){throw await Q(()=>D(o)),await y.rm(m.join(S,r),{recursive:!0,force:!0}).catch(()=>{}),u}let s={id:r,kind:"document",slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(a)?a:-1};return await J(m.join(S,r,"entry.json"),`${JSON.stringify(s,null,2)}
13
+ `),[200,{ok:!0,entry:s}]},async restore({id:t}){let e=typeof t=="string"&&se.test(t)?await Yt(t):null;if(!e)return c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return ke(e);if(e.kind==="link")return ge(e);let n=m.join(S,t,"report"),r=await E(e.slug,n),o=r?e.slug:await vt(e);return r?await d(await y.readdir(n),n,x(o)):await V(n,x(o)),o!==e.slug&&await Ft(o,e.slug),await y.rm(m.join(S,t),{recursive:!0,force:!0}),await ft(o,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await O(o),entry:{...e,kind:"document",slug:o}}]},async destroy({id:t}){let e=typeof t=="string"&&se.test(t)?await Yt(t):null;return e?((e.kind??"document")==="document"&&!await Y(e.slug)&&await nt(e.slug),await y.rm(m.join(S,t),{recursive:!0,force:!0}),[200,{ok:!0}]):c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:r,after:o=null,first:i=!1},{port:a,wait:s=!1}={}){let u=at({url:t,title:e,icon:n});if(u.refused)return c(400,u.refused,u.message);if(Nt(u.value.url,a))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(r!=null&&typeof r!="string"||o!==null&&typeof o!="string"||typeof i!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let k=await Q(async()=>{let w=await T(),h=ye(w,{parent:r,after:o,first:i||r==null&&o===null});if(h.refused)return h;let N=await ut(Qe(u.value.title,u.value.url));return await y.mkdir(x(N),{recursive:!0}),await J(m.join(x(N),It),`${JSON.stringify(u.value,null,2)}
14
+ `),wt(w,N,h.parent,h.index),await D(w),{slug:N,parent:h.parent,index:h.index}});if(k.refused)return c(...k.refused);let g=Wt(k.slug,u.value.url);return s&&await g,[200,{ok:!0,link:await j(k.slug),parent:k.parent,index:k.index,outline:await T()}]},async"link-set"({slug:t,url:e,title:n,icon:r},{port:o,wait:i=!1}={}){let a=typeof t=="string"&&_.test(t)?await _t(x(t)):null;if(!a)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let s=e??a.url,u=at({url:s,title:n??a.title,icon:r===void 0?a.icon??null:r,siteIcon:a.siteIcon??null});if(u.refused)return c(400,u.refused,u.message);let k=u.value.url!==a.url;if(k&&Nt(u.value.url,o))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(k&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(a)&&await J(m.join(x(t),It),`${JSON.stringify(u.value,null,2)}
15
+ `),k){let g=Wt(t,u.value.url);i&&await g}return[200,{ok:!0,link:await j(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let r=await He(t),o=typeof n=="string"?n:null;if(r.kind==="missing")return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(r.kind==="plain")return c(409,"plain","\u8FD9\u4E0D\u662F Gallery \u7684\u5E95\u7A3F\u6216\u5DE5\u4F5C\u533A\uFF0C\u53EF\u4EE5\u7528\u300C\u5BFC\u5165\u300D\u628A\u6587\u4EF6\u590D\u5236\u8FDB\u6765");if(r.kind==="nested")return c(409,"nested","\u8FD9\u4EFD\u5E95\u7A3F\u4E0D\u5728\u5B83\u5DE5\u4F5C\u533A\u7684\u7B2C\u4E00\u5C42\uFF08\u5728\u56DE\u6536\u533A\u91CC\uFF0C\u6216\u662F\u5199\u4F5C\u504F\u597D\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");if(r.kind==="name")return c(409,"name","\u8FD9\u4E2A\u6587\u4EF6\u5939\u7684\u540D\u5B57\u4E0D\u662F Gallery \u6587\u6863\u7684\u5199\u6CD5\uFF08\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");let i=r.kind==="workspace"?r.root:r.kind==="folder"?null:r.root,a=!i||!Ue(l).some(g=>Z(g.root,i));if(!i){let g=r.kind==="folder"?r.folder:r.parent;if(Ve(g))return c(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:g,...Pt(B("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",g))}];if(!(await on(g)).ours)return c(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));i=g}let s=r.kind==="workspace"||r.kind==="folder";if(Z(i,l))return[200,{ok:!0,kind:s?"workspace":"draft",own:!0,existing:!0,...s?{column:mt}:{entry:r.slug}}];let u=await De(i,{force:!0}).catch(()=>"failed"),k=X(gt(i));return k.refused==="ambiguous"?c(409,"ambiguous",B("\u672C\u673A\u767B\u8BB0\u7684 {0} \u4E2A\u5DE5\u4F5C\u533A\u7F16\u53F7\u76F8\u540C\uFF08{1}\uFF09\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A",k.roots.length,gt(i))):!k.root||!Z(k.root,i)?u==="temporary"?c(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):c(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(ht(i),s?[200,{ok:!0,kind:"workspace",...await We(l,i,{changed:P,after:o})}]:[200,{ok:!0,kind:"draft",...await ne(l,i,r.slug,{changed:P,pick:!0,after:o,fresh:a})}])},async"draft-join"({root:t,slug:e}){if(typeof t!="string"||typeof e!="string"||!_.test(e))return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(Z(t,l))return c(409,"own","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let n=X(gt(t));return!n.root||!Z(n.root,t)?c(409,"registry","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):await tt(st(m.join(t,e)).html)?(ht(t),[200,{ok:!0,...await ne(l,t,e,{changed:P})}]):c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async export({slug:t}){if(typeof t!="string"||!_.test(t)||!await tt(U(t)))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:r}=await b.export(t);return r?c(r.reason==="missing"?404:409,r.reason,r.message):e.length?c(422,"check",Sn(e)):[200,{ok:!0,path:bn(n)}]}},Ht={async frameable({url:t},{port:e}){let n=typeof t=="string"?at({url:t,title:"-"}):{refused:"url"};return n.refused?c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Nt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await Oe(n.value.url)}]},async elsewhere({ws:t}){let e=typeof t=="string"?X(t):{refused:"unknown"};if(e.refused)return c(409,e.refused,e.refused==="ambiguous"?"\u672C\u673A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u91CC\u6709\u4E24\u4E2A\u7528\u7684\u662F\u540C\u4E00\u4E2A\u7F16\u53F7\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A":"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let n=await W.serverOf(e.root);return n.refused?c(409,n.refused,n.message):[200,{ok:!0,origin:`http://127.0.0.1:${n.port}`}]},async"draft-command"({ws:t,name:e,...n}){let r=typeof t=="string"?X(t):{refused:"unknown"};return r.refused?c(409,r.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):W.forward(r.root,e,n)},async"draft-create"({ws:t,title:e,description:n,language:r,parent:o="",after:i=null,first:a=!1}){if(t===I)return c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let s=typeof t=="string"?X(t):{refused:"unknown"};if(s.refused)return c(409,s.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[u,k]=await W.forward(s.root,"create",{title:e,description:n,language:r});if(!k?.ok)return[u,k];let g=k.report?.slug;if(typeof g!="string"||!_.test(g))return c(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let w=Me(t,g);return ht(s.root),await Jt(w,{parent:o,after:i,first:a}),[200,{ok:!0,entry:w,report:{...k.report,slug:w,kind:"draft",workspace:t}}]},async reveal({entry:t,ws:e,page:n}){let r=oe(),o=null;return typeof n=="string"?o=_.test(n)?ct(n,l).folder:null:typeof t=="string"&&Lt(t)?o=(await re(t,r)).folder:e===I?o=m.resolve(l):typeof e=="string"&&(o=X(e,r).root??null),!o||!await tt(o)?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:o,...await Zt(o)}]},async title({url:t}){let e=typeof t=="string"?at({url:t,title:"-"}):{refused:"url"};if(e.refused)return c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=G?await G.title(e.value.url).catch(()=>""):"";return[200,{ok:!0,title:typeof n=="string"?n.slice(0,200):""}]}};function je(t,e,n){if(t.method==="GET"&&Object.hasOwn(Mt,n)){let o=t.headers.host??"",i=t.socket.localPort;return o!==`127.0.0.1:${i}`&&o!==`localhost:${i}`?H(e,403,{ok:!1,reason:"host"}):Mt[n](new URL(t.url??"/","http://localhost").searchParams).then(([a,s])=>H(e,a,s),a=>H(e,...c(500,"read",a)))}if(t.method==="POST"&&n==="stop")return f.respond(async o=>{let i=await f.check(o);return i.error?i.error:L.kind!=="cli"||typeof L.stop!="function"?c(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(e.once("finish",()=>L.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return f.respond(async o=>{let i=await f.check(o,vn);if(i.error)return i.error;if(!R?.install)return c(404,"unknown");try{return[200,{ok:!0,...R.install(i.body??{})}]}catch(a){if(!a.code)throw a;return c(409,a.code,a)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let o=await f.check(t);if(o.error)return o.error;let{slug:i,items:a}=o.body??{};return typeof i!="string"||!_.test(i)||!Array.isArray(a)?[400,{ok:!1,reason:"body"}]:!await Y(i)||i===await z()?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):f.setTodos(i,a)})().then(([o,i])=>H(e,o,i),o=>H(e,...c(500,"write",o.message)));let r={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(it,n)?f.respond(async o=>{let i=await f.check(o);if(i.error)return i.error;let a=i.body&&typeof i.body=="object"?i.body:{};return typeof a.workspace=="string"&&!Z(a.workspace,l)?c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):it[n](a,r)})(t,e):t.method==="POST"&&Object.hasOwn(Ht,n)?(async()=>{let o=await f.check(t);return o.error?o.error:Ht[n](o.body&&typeof o.body=="object"?o.body:{},r)})().then(([o,i])=>H(e,o,i),o=>H(e,...c(500,"read",o))):H(e,404,{ok:!1,reason:"unknown"})}return{handle:je,outline:T,trashEntries:rt,place:ft,freeSlug:ut,index:K,run:(t,e,n={})=>Object.hasOwn(it,t)?it[t](e??{},{wait:!0,...n}):Promise.resolve(c(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4")),close:()=>W.close()}}export{ar as a};
@@ -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{a as ue,b as ge,k as we,v as $e,w as be}from"./chunk-QOUEFUCH.mjs";import{M as ye}from"./chunk-VTKNEYT3.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-BPL64HGA.mjs";import{c as P,f as ke}from"./chunk-UGWYKHBL.mjs";import"./chunk-OUUP3WKT.mjs";import{a as R}from"./chunk-JEUK3ZO7.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{b as de,h as _}from"./chunk-SXHBYZST.mjs";import"./chunk-N7AZZLGT.mjs";import{n as ie}from"./chunk-D4EURAX4.mjs";import"./chunk-4OZWXZE5.mjs";import{a as pe,j as fe,s as me}from"./chunk-HMYTM3GT.mjs";import{d as re,e as le,i as I,j as ce,k as he}from"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import{a as w}from"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import{a as U,c as S}from"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import{c as ae}from"./chunk-UBBRTJ2R.mjs";import{a as F,f as te,h as se,j as z,r as ne,s as oe}from"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{isUtf8 as ze}from"node:buffer";import W from"node:fs";import j from"node:path";import{instanceSlots as Ue,instancesOf as X,isInstance as Z,partOf as V}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as $,refusedInCopy as _e}from"../browser/shared/components/installed.mjs";import{attr as b,elementsOf as Q,walk as T}from"../browser/shared/html-tree.mjs";import{blankedCss as B}from"../browser/shared/css-references.mjs";import{ATTRIBUTE as G,SLOT as Le}from"../browser/shared/components/installed.mjs";var Te=new Set(["media","supports","container","layer","starting-style"]);function K(t,e){let s=0,o="";for(let n=0;n<t.length;n++){let i=t[n];i==="\\"?n++:o?o=i===o?"":o:i==='"'||i==="'"?o=i:i===")"||i==="]"?s--:(s===0&&e(i,n),(i==="("||i==="[")&&s++)}}function Ce(t){let e=B(t),s=B(t,{strings:!0}),o={children:[]},n=[o],i=0,r=0;for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\")a++;else if(l==="("||l==="[")r++;else if(l===")"||l==="]")r=Math.max(0,r-1);else{if(r>0)continue;if(l==="{"){let c={prelude:s.slice(i,a),start:i,children:[]};n.at(-1).children.push(c),n.push(c),i=a+1}else l==="}"?(n.length>1&&n.pop(),i=a+1):l===";"&&(i=a+1)}}return o.children}function M(t){let e=[],s=0;return K(t,(o,n)=>{o===","&&(e.push({text:t.slice(s,n),start:s}),s=n+1)}),e.push({text:t.slice(s),start:s}),e.filter(({text:o})=>o.trim())}function q(t){let e=[],s=t.trim(),o="",n=0,i=0,r=a=>{(i||a)>n&&e.push({combinator:o,compound:s.slice(n,i||a)}),i=0};return K(s,(a,l)=>{/\s/.test(a)?l===n?n=l+1:i||=l:">+~".includes(a)?(r(l),o=a,n=l+1):i&&(r(l),o=" ",n=l)}),r(s.length),e}function D(t){let e=[],s=-1,o=0,n="";for(let r=0;r<t.length;r++){let a=t[r];a==="\\"?r++:n?n=a===n?"":n:a==='"'||a==="'"?n=a:a==="("?o++:a===")"?o--:a==="["&&o===0?s=r:a==="]"&&o===0&&s>=0&&(e.push(t.slice(s,r+1)),s=-1)}let i=!1;return K(t,r=>{i||=r==="&"}),{attributes:e,nesting:i,scope:/(?:^|[^\w-]):scope\b/.test(t)}}var Ie=t=>new RegExp(`^\\[\\s*${G}\\s*=\\s*(["'])${t.replace(/[/-]/g,"\\$&")}\\1\\s*i?\\s*\\]$`,"i"),Re=t=>B(t).replace(/\\.|\[[^\]]*\]/g,"").includes("&");function xe(t,e,s,o=!1){let n=q(t),i=({compound:f})=>D(f).attributes.some(h=>e.test(h)),r=({compound:f})=>{let{nesting:h,scope:m}=D(f);return!!s&&(h||m)},a=f=>["+","~"].includes(f?.combinator),l=f=>n.slice(f).some(({combinator:h},m)=>(m+f===0?h||" ":h)===" "),c=n.findLastIndex(f=>i(f)||r(f));if(c<0)return!s||Re(t)?{why:"outside"}:{why:s==="instance"&&a(n[0])?"beside":null,subject:"inside",deep:o||l(0)};let p=i(n[c])||s==="instance";return{why:p&&a(n[c+1])?"beside":null,subject:p&&c===n.length-1?"instance":"inside",deep:!i(n[c])&&o||l(c+1)}}var Se=t=>t.some(({subject:e})=>e==="instance")?"instance":"inside",Pe=new RegExp(`^\\[\\s*${Le}\\s*(?:\\]|=)`,"i"),Fe=t=>M(/\)\s*to\s*\(([^)]*)\)/i.exec(t)?.[1]??"").some(({text:e})=>q(e).length===1&&D(e).attributes.some(s=>Pe.test(s))),Ee=(t,e)=>Ne(t,e).outside;function je(t,e,s){if(s.length===0)return[];let o=`slot${s.length===1?"":"s"} ${s.join(" and ")}`;return Ne(t,e).deep.map(({line:n,words:i})=>({line:n,what:`${i} also reaches the blocks in ${o}, the document's: write each step with > or wrap the rules in @scope ([${G}="${e}"]) to ([${Le}])`}))}function Ne(t,e){let s=Ie(e),o=`[${G}="${e}"]`,n=[],i=[],r=(l,c,p)=>{let f=c.replace(/\s+/g," ").trim();n.push({line:S(t,l),what:p==="beside"?`${f} reaches what stands beside the instance: what it styles has to stand in it`:`${f} reaches outside the instance: start it at ${o}`})},a=(l,c,p=!1,f=!1)=>{for(let h of l){let m=h.prelude.length-h.prelude.trimStart().length,u=h.start+m,y=/^@([\w-]+)\s*/.exec(h.prelude.trim());if(y){let d=y[1].toLowerCase();if(Te.has(d))a(h.children,c,p,f);else if(d==="page")n.push({line:S(t,u),what:"@page reaches the paper of the whole document: an instance has no page of its own"});else if(d==="scope"){let x=/^@scope\s*\(([^)]*)\)/i.exec(h.prelude.trim())?.[1]??"",L=M(x).map(({text:E})=>({...xe(E,s,c),steps:q(E).length}));x&&L.every(({why:E,steps:Ae})=>!E&&Ae===1)?a(h.children,Se(L),!1,f||Fe(h.prelude.trim())):r(u,h.prelude,"outside")}continue}let k=M(h.prelude).map(({text:d,start:x})=>{let L=xe(d,s,c,p),E=h.start+x+d.length-d.trimStart().length;return L.why?r(E,d,L.why):L.deep&&!f&&!p&&i.push({line:S(t,E),words:d.replace(/\s+/g," ").trim()}),L});k.some(({why:d})=>d)||a(h.children,Se(k),k.some(d=>d.deep),f)}};return a(Ce(t),null),{outside:n,deep:i}}var g="template.html",N="example.html",O="component.json",Be=new Set(["localStorage","sessionStorage"]),Me=/^\S+: (?:line \d+ of )?its (?:kit\.js|style\.css) /,De=/(?: (?:names a file that )?is not in the document's folder|: it is (?:no file of|not in) the document's .*)$|^external resources are not portable: .*$/,Ge=": an example stands in no document: write a picture as a data: address, or draw it from style.css with a file the manifest's assets name",Ke=t=>t.replace(De,e=>(e.startsWith("external")?e:"")+Ge),A=(t,e)=>I({folder:t},e);function C(t,e){let s=null;try{s=W.readFileSync(j.join(t,e))}catch{return null}return ze(s)?null:{file:e,what:"it is not UTF-8: save it as UTF-8 (PowerShell's > writes UTF-16; Set-Content -Encoding utf8 does not)"}}function H(t,e){let s=/^line (\d+): | \(line (\d+)\)/.exec(e);return s?{file:t,line:Number(s[1]??s[2]),what:e.replace(s[0],"")}:{file:t,what:e}}function v(t,e){let s=w.parseJsonText(O,t),o=s.statements[0]?.expression,n=null;for(let i of e.split(".")){let r=o?.properties?.find(({name:a})=>a?.text===i);if(!r)break;n=s.getLineAndCharacterOfPosition(r.getStart(s)).line+1,o=r.initializer}return n}function qe(t,{message:e,text:s="",values:o=[]}){let n=/at position (\d+)/.exec(e)?.[1];if(n)return S(t,Number(n));for(let i of[...o.map(String),...s.match(/[a-zA-Z][\w.]*/g)??[]]){let r=v(t,i);if(r)return r}return null}var He=t=>_(t).map(e=>/^line (\d+): <([^>]+)>: ([\s\S]*)$/.exec(e)).filter(Boolean).map(([,e,s,o])=>({line:Number(e),tag:s,why:o}));function Je(t,{file:e,tree:s,html:o}){let n=[],i=He(o),r=Object.entries(t.parts).filter(([,c])=>c.edit==="text"),a=Object.entries(t.parts).filter(([,c])=>c.edit==="data"),l=(c,p)=>{let f=!1;return T(c,h=>{f||=h===p}),f};for(let c of X(s,t))for(let[p,f]of r)for(let h of V(c,f.at)){let m=h.sourceCodeLocation?.startLine,u=Q(h).find(d=>ae.has(d.tagName)),y=i.find(d=>d.line===m&&d.tag===h.tagName),k=a.find(([,d])=>V(c,d.at).some(x=>x===h||l(x,h)||l(h,x)))?.[0];k?n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and stands in the part ${k}, edited as data, or around it, which is the component's: the editor leaves it read-only: name elements apart`}):u?n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text and holds a block, its <${u.tagName}> at line ${u.sourceCodeLocation?.startLine}: a text part holds words and marks alone, and the editor would leave this one read-only: write its \`at\` as what holds the words (${f.at} > ${u.tagName}), or give each block a part of its own`}):y&&n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and the editor would leave it read-only for what it holds: ${y.why}. A text part holds words and marks alone`})}return n}var Oe="(?:(?:[zcs]h|[bpmfdtnlgkhjqxrzcsyw])?(?:[iuv]?(?:a(?:i|o|ng?)?|e(?:i|r|ng?)?|o(?:u|ng)?)|i(?:u|ng?)?|u(?:i|n)?|vn?))",Ye=new RegExp(`^${Oe}$`,"i"),Ve=new RegExp(`^${Oe}{1,8}$`,"i"),ee=new RegExp("\\p{Script=Han}","u"),We=6,ve=t=>[...t].filter(e=>ee.test(e)).length;function Xe(t){let e=t.replaceAll("'",""),s=[0,...Array(e.length).fill(1/0)];for(let o=1;o<=e.length;o++)for(let n=Math.max(0,o-We);n<o;n++)s[n]+1<s[o]&&Ye.test(e.slice(n,o))&&(s[o]=s[n]+1);return e&&Number.isFinite(s[e.length])?s[e.length]:null}function Ze({name:t,words:e}){let s=ve(t.zh),o=e.split(/\s+/).filter(Boolean);return s===0?ee.test(e)&&!o.some(n=>Ve.test(n)):!o.some(n=>Xe(n.toLowerCase())===s)}function Qe({id:t,folder:e,catalog:s,off:o,parts:n}){let i=s.packages.get(t),r=s.problems.get(t)?.problem,a=A(e,O)??"",l=[];r&&l.push({file:O,line:qe(a,r),what:z("en",r)}),i?.template===null&&l.push({file:g,what:`there is none, and it is what "/" puts in a document: with none, no menu offers the block: write one <div ${$}="${t}"> with what a new instance holds`}),l.push(...n);let c=C(e,"writing.md");c&&l.push(c);let p=c||A(e,"writing.md")?.trim()?[]:[{file:"writing.md",what:"there is none, so gallery block show has nothing to say of how to write it"}];i&&Ze(i)&&p.push({file:O,line:v(a,"words")??v(a,"name.zh"),what:ee.test(i.name.zh)?`no word of words spells its whole name ${i.name.zh} in pinyin as an input method composes it, its ${ve(i.name.zh)} Chinese characters a syllable each in one word (as \u65B9\u6848\u6253\u5206 is fangandafen): "/" finds it while those letters are being composed only by such a word. What is counted is how many syllables a word reads as, not which characters they spell`:'its words are Chinese and none of them is pinyin: "/" goes by the letters an input method is composing, so write the pinyin there (\u770B\u677F kanban)'});let f=(()=>{try{return ie(W.readFileSync(j.join(e,"preview.svg")),t)}catch{return null}})();return f&&p.push({file:"preview.svg",what:`it is Gallery's ${f.id} picture, byte for byte (a block made with --recipe keeps its recipe's drawing, which the menu shows beside this block's name): draw this block's own, or delete preview.svg, which the menu does without`}),o&&p.push({file:"gallery.json",what:"the user turned it off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, which is theirs to change and says nothing of the block: it is checked as if it were on, and the instances of a document show what they hold, read-only, until it is on"}),i&&(l.push(...tt(i)),p.push(...et(i,a))),{title:"manifest",problems:l,notes:p}}function et({places:t,parts:e,card:s},o){let n=[];if(t.includes("page"))for(let[i,r]of Object.entries(e))r.edit==="text"&&n.push({file:O,line:v(o,`parts.${i}`),what:`the part ${i} is edited as text, which is read-only on a custom page (no editor runs there): a block whose places hold page keeps what a reader changes there in a data part, with its own field or the card's settings`});else v(o,"card")&&n.push({file:O,line:v(o,"card"),what:`card is for a custom page's board, and its places (${t.join(", ")}) hold no page: nothing reads it`});return n}function tt(t){if(t.settings.length===0||!t.template)return[];let e=ne(t.template,t.id),s=e?V(e.root,t.parts[F].at):[];if(s.length!==1||(b(s[0],"type")??"").trim().toLowerCase()!=="application/json")return[{file:g,what:`its manifest has settings, and the template holds ${s.length===1?`a <${s[0].tagName}> where`:`${s.length} elements of`} its settings part (${t.parts[F].at}): it is to hold one <script type="application/json">, the values a new card starts with ({} for each setting's default)`}];let o=s[0].childNodes.map(n=>n.value??"").join("").trim();try{let n=JSON.parse(o||"{}");if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("it is no object");return[]}catch(n){return[{file:g,line:s[0].sourceCodeLocation?.startLine,what:`its settings part is not a JSON object (${n.message}): write {} or the values of some of its settings, by key`}]}}function st(t){let e=w.createSourceFile("kit.js",t,w.ScriptTarget.Latest,!0,w.ScriptKind.JS),s=[],o=n=>{let i=w.isCallExpression(n)&&w.isPropertyAccessExpression(n.expression)?n.expression:null;if(i?.name.text==="component"&&/\bDocKit$/.test(i.expression.getText(e))){let[r]=n.arguments,a=r&&w.isObjectLiteralExpression(r)?r.properties.find(c=>c.name?.getText(e)==="id"):null,l=a&&w.isPropertyAssignment(a)&&w.isStringLiteralLike(a.initializer)?a.initializer.text:null;s.push({id:l,at:n.getStart(e)})}w.forEachChild(n,o)};return o(e),s}function nt(t){let e="kit.js";if(!t.files.includes("kit.js"))return{title:e,none:"none: a static block"};let s=C(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let o=I(t,"kit.js")??"",n=pe(o);if(n)return{title:e,stops:!0,problems:[{file:e,line:n.line,what:`a browser refuses it: ${n.message}`}]};let i=he(t).map(({line:c,what:p})=>({file:e,line:c,what:p})),r=i.length>0;for(let{name:c,at:p}of re(o,Be))i.push({file:e,line:S(o,p),what:`uses ${c}: an instance keeps what a reader chose with context.state`});let a=st(o);for(let{id:c,at:p}of a)c!==null&&c!==t.id&&i.push({file:e,line:S(o,p),what:`it registers ${c}, and this block is ${t.id}`});let l=a.length?[]:[{file:e,what:`no DocKit.component({ id: "${t.id}", mount(host, context) { \u2026 } }) is to be read in it, and a script may make that call in ways reading does not tell: running it says whether it starts one`}];for(let{line:c,code:p,message:f,refused:h}of le(o,{assets:t.assets}))(h?i:l).push({file:e,line:c,what:`TS${p}: ${f}`});return{title:e,stops:r,problems:i.sort((c,p)=>(c.line??0)-(p.line??0)),notes:l}}function ot(t){let e="style.css";if(!t.files.includes("style.css"))return{title:e,none:"none"};let s=C(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let o=I(t,"style.css")??"",n=ce(t),i=[...Ee(o,t.id),...n].map(({line:l,what:c})=>({file:e,line:l,what:c})),r=Object.entries(t.parts??{}).filter(([,{edit:l}])=>l==="flow").map(([l])=>l),a=je(o,t.id,r).map(({line:l,what:c})=>({file:e,line:l,what:c}));return{title:e,stops:n.length>0,problems:i.sort((l,c)=>l.line-c.line),notes:a}}function it(t,{tree:e}){let s=null;T(e,a=>{s??=a.tagName==="main"?a:null});let o=Q(s??{}),n=(s?.childNodes??[]).some(a=>a.nodeName==="#text"&&a.value.trim()),[i]=o;if(o.length!==1||n||!Z(i)||b(i,$)!==t)return[{file:g,line:i?.sourceCodeLocation?.startLine,what:`a template is one element, a <div ${$}="${t}"> or a <section>, and it holds ${o.length===1&&!n?`<${i.tagName}${b(i,$)?` ${$}="${b(i,$)}"`:""}>`:`${o.length} element${o.length===1?"":"s"}${n?" and words":""}`}`}];let r=[];return T({childNodes:[i]},a=>{b(a,"data-block-id")!==void 0&&r.push({file:g,line:a.sourceCodeLocation?.startLine,what:"it writes a data-block-id, which every instance made of it would repeat: leave it out, Gallery gives a block its id"})}),r}var at=[[t=>b(t,"data-doc-chart")!==void 0,t=>`a chart (<${t.tagName} data-doc-chart="${b(t,"data-doc-chart")}">)`],[t=>t.tagName==="figure",()=>"a card (<figure>)"],[t=>t.tagName==="caption",()=>"a table's <caption>"],[Z,t=>`an instance of ${b(t,$)}`]];function rt(t,e){let s=null;if(T(U(e),i=>{s??=Z(i)&&b(i,$)===t?i:null}),!s)return[];let o=[],n=(i,r)=>{for(let a of Q(i)){let l=at.find(([c])=>c(a));l?o.push({file:g,line:a.sourceCodeLocation?.startLine,what:`its slot ${b(r,"data-doc-slot")} holds ${l[1](a)}, which a new block from "/" would not have: a menu makes what a template's slot holds as a paste of it makes blocks, and a paste makes no chart, card, table caption or instance of a block. Keep the template's slots to blocks the page makes (paragraphs, headings, lists, quotes, code, a plain table, a disclosure), and show the rest in example.html`}):n(a.tagName==="template"?a.content:a,r)}};for(let i of Ue(s))n(i,i);return o}function lt(t,{tree:e}){let s=oe(t);if(!s)return[];let[o]=X(e,t),n=null;return o&&T({childNodes:[o]},i=>{_e(i.tagName,i.attrs)&&(n??=i)}),[{file:g,line:(n??o)?.sourceCodeLocation?.startLine,what:z("en",s)}]}function ct(t){return[[g,"component-template"],[N,"component-example"]].flatMap(([e,s])=>{let o=A(t,e);if(o===null||!o.trim()||C(t,e))return[];let n=we(s,o),{text:i}=de(n);return[{file:e,slug:s,written:n,html:i,tree:U(i)}]})}function ht({id:t,folder:e,found:s,pages:o,parts:n}){let i="template.html and example.html",r=[],a=[];for(let h of[g,N]){let m=C(e,h);m?r.push(m):h===g&&!A(e,h)?.trim()&&s.template!==null?r.push({file:h,what:"it is empty"}):h===N&&!o.some(u=>u.file===h)&&r.push({file:h,what:`there is none or it is empty: write an instance as a writer would fill it, a <div ${$}="${t}">; it is what this check runs`})}let l=o.find(h=>h.file===g);l&&r.push(...it(t,l),...rt(t,l.written));let c=o.find(h=>h.file===N);c&&X(c.tree,s).length===0&&r.push({file:N,what:`it holds no instance of ${t}: a <div ${$}="${t}">`});let p=o.map(({slug:h,written:m,html:u,file:y})=>({file:y,slug:h,written:m,html:u,directory:j.join(e,h),htmlPath:j.join(e,h,"doc.html"),metadata:{title:h,description:h,type:"component"}})),f=fe(p);for(let h of p){for(let m of f.get(h.slug)??[])Me.test(m)||r.push(H(h.file,Ke(m)));for(let m of me(h))a.push(H(h.file,m));for(let m of _(h.html)){let u=H(h.file,`${m} (read-only in the preview)`);n.some(({file:y,line:k})=>y===u.file&&k===u.line)||a.push(u)}}return l&&!r.some(({file:h})=>h===g)&&r.push(...lt(s,l)),{title:i,problems:r,notes:a}}function pt(t,e){let s=te(t,void 0,{on:e}),o=P(t,e);if(!s.packages.has(e)&&!s.problems.has(e))return null;se(t,s);let n=s.packages.has(e)&&s.settings.disabled.includes(e),i=s.packages.get(e)??{id:e,folder:o,files:["kit.js","style.css"].filter(c=>W.existsSync(j.join(o,c)))},r=ct(o),a=s.packages.has(e)?null:"its manifest does not load",l=a?[]:r.flatMap(c=>Je(i,c));return{found:s.packages.get(e)??null,pages:r,sections:[Qe({id:e,folder:o,catalog:s,off:n,parts:l}),nt(i),ot(i),a?{title:"template.html and example.html",skipped:a}:ht({id:e,folder:o,found:i,pages:r,parts:l})]}}var J=({file:t,line:e})=>e?`${t}:${e}`:t;function Y({title:t,problems:e=[],notes:s=[],told:o=[],none:n,skipped:i,unverified:r,pictures:a},l){let c=r?`UNVERIFIED ${r}`:i?`not run: ${i}`:n??(e.length?`${e.length} problem${e.length===1?"":"s"}`:`ok${s.length?`, ${s.length} note${s.length===1?"":"s"}`:""}`);return[`${l}. ${t}: ${c}`,...e.map(p=>` FAIL ${J(p)}: ${p.what}`),...s.map(p=>` note ${J(p)}: ${p.what}`),...o.map(p=>` way back ${J(p)}: ${p.what}`),...a?[ft(a)]:[]]}function ft({folder:t,overviews:e,each:s,edited:o=[],asExport:n=[],documents:i=!1}){let r=e.length?`${R(j.join(t,e[0]))}${e.slice(1).map(c=>` and ${c}`).join("")}, the three widths of each theme side by side; then each at full size: `:`${R(t)}: `,a=n.length===0?"":n.length===o.length?", each the same picture as the export's at its width: the block draws nothing more where a reader can edit":`, ${n.join(" and ")} the same picture as the export's at its width`,l=o.length?`; and ${o.join(" and ")}, as the editing page draws it (context.canEdit() true)${a}`:"";return` Pictures (none looked at for you; ${i?"each instance under a line naming where it stands in the document":"example.html above the line, template.html below it, each under its name"}): ${r}${s.join(", ")}${l}`}function mt([t,e,s,o]){return t.problems.length?"the manifest":e.stops?"kit.js":s.stops?"style.css":o.skipped||o.problems.length?"template.html and example.html":null}async function _t(t,e,{documents:s=!1}={}){let o=pt(t,e);o||(console.error(ke(t,e)),process.exit(1)),console.log(`${e}: ${R(P(t,e))}`),o.sections.forEach((p,f)=>console.log(Y(p,f+1).join(`
3
+ `)));let n=mt(o.sections),i=P(t,e),r=n?{title:ue,skipped:`${n} first`}:await $e(t,o.found,{example:A(i,N),template:A(i,g)});console.log(Y(r,5).join(`
4
+ `));let a=s?n?[{title:ge(),skipped:`${n} first`}]:await be(t,o.found):[];a.forEach((p,f)=>console.log(Y(p,6+f).join(`
5
+ `)));let l=ye([r,...a].filter(({pictures:p})=>p).map(({pictures:{folder:p,overviews:f,each:h,edited:m=[]}})=>({folder:p,files:[...f,...h,...m].map(u=>j.join(p,u))})));l&&console.log(l);let c=[...o.sections,r,...a].reduce((p,{problems:f=[]})=>p+f.length,0);c?(console.log(`FAIL ${e}: ${c} problem${c===1?"":"s"}`),process.exitCode=1):r.unverified||a.some(({unverified:p})=>p)?(console.log(`UNVERIFIED ${e}: the rest passed, and no browser ran ${r.unverified?"it":"the documents' instances"}: export a document that holds it and open that in Chrome or Edge.`),process.exitCode=3):console.log(`OK ${e}${s?" and its instances in the workspace's documents":""}`)}export{_t as checkCommand,Xe as fewestSyllables,pt as readSections,Y as sectionLines,Ze as wantsPinyin};