@heycys/gallery 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/browser/editor/components/align.mjs +58 -0
  3. package/browser/editor/components/code/index.mjs +1 -1
  4. package/browser/editor/components/embed/page.mjs +1 -1
  5. package/browser/editor/components/file/page.mjs +4 -4
  6. package/browser/editor/components/heading/index.mjs +7 -6
  7. package/browser/editor/components/icon/page.mjs +6 -4
  8. package/browser/editor/components/icons.mjs +5 -2
  9. package/browser/editor/components/image/index.mjs +2 -0
  10. package/browser/editor/components/image/page.mjs +172 -90
  11. package/browser/editor/components/installed/index.mjs +6 -2
  12. package/browser/editor/components/installed/page.mjs +80 -13
  13. package/browser/editor/components/media/icons.mjs +13 -8
  14. package/browser/editor/components/media/page.mjs +5 -3
  15. package/browser/editor/components/media/toolbar.mjs +12 -3
  16. package/browser/editor/components/paragraph/index.mjs +4 -3
  17. package/browser/editor/components/registry.mjs +17 -5
  18. package/browser/editor/components/table/index.mjs +4 -2
  19. package/browser/editor/page/after/index.mjs +288 -0
  20. package/browser/editor/page/align.mjs +91 -0
  21. package/browser/editor/page/beside.mjs +5 -6
  22. package/browser/editor/page/block-menu/index.mjs +6 -3
  23. package/browser/editor/page/blocks.mjs +3 -1
  24. package/browser/editor/page/board/hint.mjs +64 -27
  25. package/browser/editor/page/board/index.mjs +160 -71
  26. package/browser/editor/page/board/motion.mjs +177 -0
  27. package/browser/editor/page/board/settings.mjs +4 -3
  28. package/browser/editor/page/clipboard/import/read.mjs +20 -2
  29. package/browser/editor/page/clipboard/index.mjs +10 -3
  30. package/browser/editor/page/clipboard/own/blocks.mjs +3 -4
  31. package/browser/editor/page/clipboard/own/describe.mjs +6 -2
  32. package/browser/editor/page/commit.mjs +2 -2
  33. package/browser/editor/page/core.mjs +3 -1
  34. package/browser/editor/page/custom-page.mjs +15 -11
  35. package/browser/editor/page/editor.mjs +31 -14
  36. package/browser/editor/page/history.mjs +19 -4
  37. package/browser/editor/page/insert/index.mjs +20 -22
  38. package/browser/editor/page/menu.mjs +15 -7
  39. package/browser/editor/page/page-objects.mjs +3 -7
  40. package/browser/editor/page/present-links.mjs +5 -4
  41. package/browser/editor/page/present-shell.mjs +63 -0
  42. package/browser/editor/page/selection/index.mjs +10 -2
  43. package/browser/editor/page/table/binding.mjs +87 -0
  44. package/browser/editor/page/table/icons.mjs +0 -2
  45. package/browser/editor/page/table/index.mjs +10 -14
  46. package/browser/editor/page/table/views.mjs +5 -52
  47. package/browser/editor/page/table/widths.mjs +82 -10
  48. package/browser/editor/page/typing/index.mjs +44 -12
  49. package/browser/editor/page/typing/leave.mjs +19 -5
  50. package/browser/shared/block-packs.mjs +23 -8
  51. package/browser/shared/component-catalog.mjs +15 -8
  52. package/browser/shared/component-source.mjs +3 -1
  53. package/browser/shared/components/heading.mjs +2 -1
  54. package/browser/shared/components/installed.mjs +1 -1
  55. package/browser/shared/components/page.mjs +2 -0
  56. package/browser/shared/components/paragraph.mjs +8 -1
  57. package/browser/shared/components/table.mjs +1 -0
  58. package/browser/shared/document-copy.mjs +43 -0
  59. package/browser/shared/drafts.mjs +10 -3
  60. package/browser/shared/emoji/icon-value.mjs +2 -2
  61. package/browser/shared/emoji/line-icons.mjs +37 -0
  62. package/browser/shared/extensions.mjs +83 -7
  63. package/browser/shared/http.mjs +9 -0
  64. package/browser/shared/i18n/en.mjs +50 -17
  65. package/browser/shared/outline-shape.mjs +6 -0
  66. package/browser/shared/outline.mjs +165 -12
  67. package/browser/shared/pack-manifest.mjs +12 -1
  68. package/browser/shared/pages.mjs +169 -57
  69. package/browser/shared/pinyin.mjs +92 -0
  70. package/browser/shared/present-step.mjs +17 -0
  71. package/browser/shared/sidebar-head.mjs +70 -0
  72. package/browser/shared/web-links.mjs +5 -0
  73. package/browser/shared/workspace-columns.mjs +11 -7
  74. package/dist/{chunk-N7AZZLGT.mjs → chunk-2GKGEVMR.mjs} +29 -24
  75. package/dist/chunk-2OHANJ6Q.mjs +2 -0
  76. package/dist/{chunk-HYMEEXKN.mjs → chunk-2RKIHJI2.mjs} +1 -1
  77. package/dist/{chunk-742D2WWJ.mjs → chunk-36FIRJIF.mjs} +2 -2
  78. package/dist/{chunk-BPL64HGA.mjs → chunk-3A5I2GJK.mjs} +1 -1
  79. package/dist/{chunk-RFDZXFJF.mjs → chunk-3OFXMN6N.mjs} +1 -1
  80. package/dist/chunk-46ACXOU5.mjs +2 -0
  81. package/dist/{chunk-PUOQ65NC.mjs → chunk-4AMTKWDO.mjs} +1 -1
  82. package/dist/{chunk-VTKNEYT3.mjs → chunk-4DNHHJSL.mjs} +1 -1
  83. package/dist/chunk-5DPABPBI.mjs +2 -0
  84. package/dist/chunk-5IIH335D.mjs +3 -0
  85. package/dist/chunk-5L26JUYA.mjs +2 -0
  86. package/dist/{chunk-3NJACR4W.mjs → chunk-5MEXZ2UF.mjs} +1 -1
  87. package/dist/{chunk-ZHEHPMBK.mjs → chunk-6MPKCH3P.mjs} +1 -1
  88. package/dist/{chunk-C564NU2H.mjs → chunk-74RPP2M2.mjs} +1 -1
  89. package/dist/chunk-7M2BQQGZ.mjs +2 -0
  90. package/dist/{chunk-VXACTLO3.mjs → chunk-7M7UPWU6.mjs} +1 -1
  91. package/dist/{chunk-ZB4H7ZN4.mjs → chunk-7N2LPG33.mjs} +1 -1
  92. package/dist/{chunk-UBBRTJ2R.mjs → chunk-7XDYK3UC.mjs} +1 -1
  93. package/dist/chunk-AEMVZYZQ.mjs +166 -0
  94. package/dist/{chunk-POQSE4C2.mjs → chunk-AFGUR7SY.mjs} +1 -1
  95. package/dist/{chunk-QKXMPUXC.mjs → chunk-AMDGVDNV.mjs} +1 -1
  96. package/dist/{chunk-KTKHRC6H.mjs → chunk-ASAXY2DJ.mjs} +1 -1
  97. package/dist/{chunk-NVRNLK25.mjs → chunk-BYSF5UMM.mjs} +2 -2
  98. package/dist/{chunk-U3SSPL4K.mjs → chunk-CCSGFCLZ.mjs} +1 -1
  99. package/dist/{chunk-NWFBE2YA.mjs → chunk-CG3UHDKH.mjs} +1 -1
  100. package/dist/chunk-CPS4SRPF.mjs +5 -0
  101. package/dist/{chunk-B4P2CM2J.mjs → chunk-CZ5KJSGK.mjs} +1 -1
  102. package/dist/chunk-DAMVDXR3.mjs +2 -0
  103. package/dist/{chunk-NG375ILQ.mjs → chunk-DH6GMDNN.mjs} +1 -1
  104. package/dist/chunk-DHB7UZ7F.mjs +3 -0
  105. package/dist/{chunk-MHW7ZKOU.mjs → chunk-DKR7LFIY.mjs} +1 -1
  106. package/dist/chunk-DLFZJJEE.mjs +2 -0
  107. package/dist/{chunk-6EZ7FNIK.mjs → chunk-F4ZA6JRZ.mjs} +1 -1
  108. package/dist/{chunk-6VTU6KEO.mjs → chunk-FCK6NXON.mjs} +1 -1
  109. package/dist/{chunk-ZWPMCK7P.mjs → chunk-FX42XU6J.mjs} +1 -1
  110. package/dist/chunk-FXQBADMN.mjs +5 -0
  111. package/dist/{chunk-W3BGBJQW.mjs → chunk-G4YP7GVC.mjs} +1 -1
  112. package/dist/{chunk-V6XZ4VIR.mjs → chunk-GWOYMENX.mjs} +1 -1
  113. package/dist/chunk-HATA2W7X.mjs +2 -0
  114. package/dist/{chunk-YI43RG4P.mjs → chunk-HBAUKKQH.mjs} +1 -1
  115. package/dist/{chunk-MAFIGVXY.mjs → chunk-HM4E43VM.mjs} +1 -1
  116. package/dist/{chunk-CRJEG7MT.mjs → chunk-JI6T3A4Y.mjs} +1 -1
  117. package/dist/{chunk-NFMCP2HI.mjs → chunk-JJNRIFND.mjs} +2 -2
  118. package/dist/chunk-JL6R4FG4.mjs +4 -0
  119. package/dist/{chunk-UMHUSOPJ.mjs → chunk-JXLSHVJ2.mjs} +1 -1
  120. package/dist/{chunk-FJYN7RTH.mjs → chunk-KFZBYDIS.mjs} +1 -1
  121. package/dist/{chunk-ZTHICSSF.mjs → chunk-KH24LWAT.mjs} +1 -1
  122. package/dist/{chunk-RKPWLGZ3.mjs → chunk-KUILYI7H.mjs} +1 -1
  123. package/dist/{chunk-RMECZA2K.mjs → chunk-L7W624FD.mjs} +1 -1
  124. package/dist/chunk-LE44MD3O.mjs +4 -0
  125. package/dist/{chunk-4K5KC6V2.mjs → chunk-LV24RY2E.mjs} +1 -1
  126. package/dist/{chunk-43B75J5T.mjs → chunk-MKTX5PGV.mjs} +1 -1
  127. package/dist/{chunk-LKX55H76.mjs → chunk-NAGMRVW4.mjs} +1 -1
  128. package/dist/{chunk-D4CKRD3V.mjs → chunk-NFABH3QW.mjs} +2 -2
  129. package/dist/{chunk-PVER7LSC.mjs → chunk-NIW7F7LU.mjs} +2 -2
  130. package/dist/{chunk-PAREWQGB.mjs → chunk-NWRZXELO.mjs} +1 -1
  131. package/dist/{chunk-OJKMINIU.mjs → chunk-OU3S466R.mjs} +15 -15
  132. package/dist/{chunk-5ZJA7CXT.mjs → chunk-PAFSFVYB.mjs} +1 -1
  133. package/dist/chunk-QCEATQC4.mjs +2 -0
  134. package/dist/{chunk-Y34NR5JL.mjs → chunk-QJ3TFJLQ.mjs} +1 -1
  135. package/dist/{chunk-IA4PSIMD.mjs → chunk-QK3VISCA.mjs} +1 -1
  136. package/dist/{chunk-ZUNVAXLH.mjs → chunk-QXVNUASA.mjs} +1 -1
  137. package/dist/{chunk-GRAXKKG4.mjs → chunk-QZ35UAB4.mjs} +1 -1
  138. package/dist/{chunk-UGWYKHBL.mjs → chunk-S2Y7VI4H.mjs} +2 -2
  139. package/dist/{chunk-OW5NWPOJ.mjs → chunk-SAHS56QM.mjs} +1 -1
  140. package/dist/{chunk-QOUEFUCH.mjs → chunk-SOD23RGL.mjs} +1 -1
  141. package/dist/chunk-TDWJKOLN.mjs +2 -0
  142. package/dist/{chunk-V6RIYQZZ.mjs → chunk-TOE6DPLH.mjs} +1 -1
  143. package/dist/chunk-UGO5N3EI.mjs +15 -0
  144. package/dist/{chunk-Q47PLKIJ.mjs → chunk-UGWMMEJ5.mjs} +1 -1
  145. package/dist/{chunk-NWR2LT5B.mjs → chunk-V5JRSGZF.mjs} +1 -1
  146. package/dist/{chunk-BZ5RAF7L.mjs → chunk-VA3KAQZD.mjs} +1 -1
  147. package/dist/chunk-VG5JEIUQ.mjs +12 -0
  148. package/dist/{chunk-UNOYVIYR.mjs → chunk-VGTMLQWZ.mjs} +1 -1
  149. package/dist/chunk-VKSRM7EY.mjs +22 -0
  150. package/dist/{chunk-YQGT4AB2.mjs → chunk-VNUWREXU.mjs} +1 -1
  151. package/dist/{chunk-AGDILNWB.mjs → chunk-VPVOAJ7X.mjs} +1 -1
  152. package/dist/{chunk-HLYV7RIH.mjs → chunk-WCWYNFDF.mjs} +1 -1
  153. package/dist/chunk-WTEGUPFG.mjs +16 -0
  154. package/dist/{chunk-N76HWBA3.mjs → chunk-XKOHV4H6.mjs} +1 -1
  155. package/dist/{chunk-HMYTM3GT.mjs → chunk-XMKHCUI6.mjs} +1 -1
  156. package/dist/{chunk-OUUP3WKT.mjs → chunk-XQRUG4G3.mjs} +1 -1
  157. package/dist/{chunk-32ZUEFZ7.mjs → chunk-YBB5LWZK.mjs} +1 -1
  158. package/dist/{chunk-SX4LJYT6.mjs → chunk-YFJU3O7G.mjs} +1 -1
  159. package/dist/chunk-YPPJVDQI.mjs +2 -0
  160. package/dist/chunk-ZANMKAWS.mjs +2 -0
  161. package/dist/{chunk-6QBHU4DF.mjs → chunk-ZCP7BTOZ.mjs} +1 -1
  162. package/dist/{chunk-ERLAIBOA.mjs → chunk-ZEY2RLBT.mjs} +2 -2
  163. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-ZO7SFB2E.mjs} +2 -2
  164. package/dist/cli.mjs +1 -1
  165. package/dist/server.mjs +1 -1
  166. package/dist/worker.mjs +1 -1
  167. package/kit/board.css +5 -5
  168. package/kit/code.js +15 -15
  169. package/kit/math.js +1 -1
  170. package/kit/report.css +123 -44
  171. package/kit/runtime.js +45 -7
  172. package/kit/tables.js +2 -0
  173. package/kit/ui.js +2 -0
  174. package/package.json +1 -1
  175. package/packs/gallery/chart-view/kit.js +3 -3
  176. package/packs/gallery/chart-view/writing.md +1 -1
  177. package/packs/gallery/countdown/component.json +1 -1
  178. package/packs/gallery/countdown/kit.js +89 -29
  179. package/packs/gallery/countdown/preview.svg +1 -1
  180. package/packs/gallery/countdown/style.css +88 -100
  181. package/packs/gallery/countdown/writing.md +2 -2
  182. package/packs/gallery/habit/component.json +3 -3
  183. package/packs/gallery/habit/kit.js +114 -75
  184. package/packs/gallery/habit/preview.svg +1 -1
  185. package/packs/gallery/habit/style.css +133 -205
  186. package/packs/gallery/habit/writing.md +2 -2
  187. package/packs/gallery/heatmap/component.json +2 -2
  188. package/packs/gallery/heatmap/kit.js +335 -173
  189. package/packs/gallery/heatmap/preview.svg +1 -1
  190. package/packs/gallery/heatmap/style.css +158 -170
  191. package/packs/gallery/heatmap/writing.md +2 -2
  192. package/packs/gallery/kanban/kit.js +3 -3
  193. package/packs/gallery/kanban/writing.md +1 -1
  194. package/packs/gallery/metric/kit.js +3 -3
  195. package/packs/gallery/metric/writing.md +1 -1
  196. package/packs/gallery/note/component.json +3 -3
  197. package/packs/gallery/note/kit.js +40 -13
  198. package/packs/gallery/note/preview.svg +1 -1
  199. package/packs/gallery/note/style.css +51 -30
  200. package/packs/gallery/note/writing.md +2 -2
  201. package/packs/gallery/recent/component.json +2 -2
  202. package/packs/gallery/recent/kit.js +141 -86
  203. package/packs/gallery/recent/preview.svg +1 -1
  204. package/packs/gallery/recent/style.css +53 -126
  205. package/packs/gallery/recent/writing.md +2 -2
  206. package/packs/gallery/static/component.json +2 -2
  207. package/packs/gallery/static/preview.svg +1 -1
  208. package/packs/gallery/static/style.css +99 -66
  209. package/packs/gallery/static/writing.md +2 -2
  210. package/packs/gallery/stats/component.json +3 -3
  211. package/packs/gallery/stats/kit.js +253 -72
  212. package/packs/gallery/stats/preview.svg +1 -1
  213. package/packs/gallery/stats/style.css +64 -142
  214. package/packs/gallery/stats/writing.md +2 -2
  215. package/packs/gallery/today/component.json +2 -2
  216. package/packs/gallery/today/kit.js +62 -27
  217. package/packs/gallery/today/preview.svg +1 -1
  218. package/packs/gallery/today/style.css +101 -72
  219. package/packs/gallery/today/writing.md +2 -2
  220. package/packs/gallery/todos/component.json +1 -1
  221. package/packs/gallery/todos/kit.js +218 -71
  222. package/packs/gallery/todos/preview.svg +1 -1
  223. package/packs/gallery/todos/style.css +170 -223
  224. package/packs/gallery/todos/writing.md +1 -1
  225. package/packs/gallery/weather/component.json +2 -2
  226. package/packs/gallery/weather/kit.js +165 -90
  227. package/packs/gallery/weather/preview.svg +1 -1
  228. package/packs/gallery/weather/style.css +100 -218
  229. package/packs/gallery/weather/writing.md +1 -1
  230. package/packs/gallery-soft/countdown/component.json +18 -0
  231. package/packs/gallery-soft/countdown/example.html +3 -0
  232. package/packs/gallery-soft/countdown/kit.js +206 -0
  233. package/packs/gallery-soft/countdown/preview.svg +1 -0
  234. package/packs/gallery-soft/countdown/style.css +211 -0
  235. package/packs/gallery-soft/countdown/template.html +3 -0
  236. package/packs/gallery-soft/countdown/writing.md +24 -0
  237. package/packs/gallery-soft/habit/component.json +14 -0
  238. package/packs/gallery-soft/habit/example.html +3 -0
  239. package/packs/gallery-soft/habit/kit.js +366 -0
  240. package/packs/gallery-soft/habit/preview.svg +1 -0
  241. package/packs/gallery-soft/habit/style.css +251 -0
  242. package/packs/gallery-soft/habit/template.html +3 -0
  243. package/packs/gallery-soft/habit/writing.md +23 -0
  244. package/packs/gallery-soft/heatmap/component.json +18 -0
  245. package/packs/gallery-soft/heatmap/example.html +3 -0
  246. package/packs/gallery-soft/heatmap/kit.js +498 -0
  247. package/packs/gallery-soft/heatmap/preview.svg +1 -0
  248. package/packs/gallery-soft/heatmap/style.css +181 -0
  249. package/packs/gallery-soft/heatmap/template.html +3 -0
  250. package/packs/gallery-soft/heatmap/writing.md +23 -0
  251. package/packs/gallery-soft/note/component.json +14 -0
  252. package/packs/gallery-soft/note/example.html +3 -0
  253. package/packs/gallery-soft/note/kit.js +162 -0
  254. package/packs/gallery-soft/note/preview.svg +1 -0
  255. package/packs/gallery-soft/note/style.css +148 -0
  256. package/packs/gallery-soft/note/template.html +3 -0
  257. package/packs/gallery-soft/note/writing.md +20 -0
  258. package/packs/gallery-soft/recent/component.json +13 -0
  259. package/packs/gallery-soft/recent/example.html +1 -0
  260. package/packs/gallery-soft/recent/kit.js +335 -0
  261. package/packs/gallery-soft/recent/preview.svg +1 -0
  262. package/packs/gallery-soft/recent/style.css +160 -0
  263. package/packs/gallery-soft/recent/template.html +1 -0
  264. package/packs/gallery-soft/recent/writing.md +17 -0
  265. package/packs/gallery-soft/static/component.json +13 -0
  266. package/packs/gallery-soft/static/example.html +12 -0
  267. package/packs/gallery-soft/static/preview.svg +1 -0
  268. package/packs/gallery-soft/static/style.css +186 -0
  269. package/packs/gallery-soft/static/template.html +1 -0
  270. package/packs/gallery-soft/static/writing.md +20 -0
  271. package/packs/gallery-soft/stats/component.json +13 -0
  272. package/packs/gallery-soft/stats/example.html +1 -0
  273. package/packs/gallery-soft/stats/kit.js +341 -0
  274. package/packs/gallery-soft/stats/preview.svg +1 -0
  275. package/packs/gallery-soft/stats/style.css +119 -0
  276. package/packs/gallery-soft/stats/template.html +1 -0
  277. package/packs/gallery-soft/stats/writing.md +13 -0
  278. package/packs/gallery-soft/today/component.json +12 -0
  279. package/packs/gallery-soft/today/example.html +1 -0
  280. package/packs/gallery-soft/today/kit.js +222 -0
  281. package/packs/gallery-soft/today/preview.svg +1 -0
  282. package/packs/gallery-soft/today/style.css +178 -0
  283. package/packs/gallery-soft/today/template.html +1 -0
  284. package/packs/gallery-soft/today/writing.md +16 -0
  285. package/packs/gallery-soft/todos/component.json +19 -0
  286. package/packs/gallery-soft/todos/example.html +3 -0
  287. package/packs/gallery-soft/todos/kit.js +527 -0
  288. package/packs/gallery-soft/todos/preview.svg +1 -0
  289. package/packs/gallery-soft/todos/style.css +212 -0
  290. package/packs/gallery-soft/todos/template.html +3 -0
  291. package/packs/gallery-soft/todos/writing.md +32 -0
  292. package/packs/gallery-soft/weather/component.json +19 -0
  293. package/packs/gallery-soft/weather/example.html +3 -0
  294. package/packs/gallery-soft/weather/kit.js +411 -0
  295. package/packs/gallery-soft/weather/preview.svg +1 -0
  296. package/packs/gallery-soft/weather/style.css +185 -0
  297. package/packs/gallery-soft/weather/template.html +3 -0
  298. package/packs/gallery-soft/weather/writing.md +28 -0
  299. package/release.json +10 -10
  300. package/skill/SKILL.md +15 -14
  301. package/skill/references/building-blocks.md +4 -4
  302. package/skill/references/extensions.md +11 -7
  303. package/skill/references/pages-and-data.md +13 -9
  304. package/skill/references/writing-html.md +2 -0
  305. package/web/assets/index-BHC5ZOMh.js +15 -0
  306. package/web/assets/index-xP0uw3a0.css +1 -0
  307. package/web/index.html +2 -2
  308. package/dist/chunk-2NRBY6AJ.mjs +0 -2
  309. package/dist/chunk-35NQ4PLQ.mjs +0 -2
  310. package/dist/chunk-3KJHLHUO.mjs +0 -2
  311. package/dist/chunk-4AV456RQ.mjs +0 -2
  312. package/dist/chunk-5XYHDBJ5.mjs +0 -2
  313. package/dist/chunk-6A53MZYZ.mjs +0 -2
  314. package/dist/chunk-6EXH3ORZ.mjs +0 -166
  315. package/dist/chunk-BVEFGE4B.mjs +0 -2
  316. package/dist/chunk-D4EURAX4.mjs +0 -4
  317. package/dist/chunk-DQCE7TJY.mjs +0 -5
  318. package/dist/chunk-FWNRPMCJ.mjs +0 -12
  319. package/dist/chunk-FWW4CSAZ.mjs +0 -2
  320. package/dist/chunk-GY3FAUVM.mjs +0 -2
  321. package/dist/chunk-JVHHHGEA.mjs +0 -3
  322. package/dist/chunk-L7UP52JO.mjs +0 -2
  323. package/dist/chunk-NAMN3RAF.mjs +0 -2
  324. package/dist/chunk-PZDLJJTJ.mjs +0 -3
  325. package/dist/chunk-SXHBYZST.mjs +0 -16
  326. package/dist/chunk-TEZAWDSQ.mjs +0 -2
  327. package/dist/chunk-UFNYFFKO.mjs +0 -20
  328. package/dist/chunk-UKSHDZZ6.mjs +0 -2
  329. package/dist/chunk-VJPFVNNW.mjs +0 -15
  330. package/dist/chunk-VS3ZMVGX.mjs +0 -5
  331. package/web/assets/index-BK2e_07w.js +0 -13
  332. package/web/assets/index-CWFI83mF.css +0 -1
  333. /package/dist/{chunk-YEY3RSFQ.mjs → chunk-5MMN3N5J.mjs} +0 -0
  334. /package/dist/{chunk-UH4SIXTR.mjs → chunk-74UW7QSL.mjs} +0 -0
  335. /package/dist/{chunk-W7XHE4CT.mjs → chunk-EKGYYOSP.mjs} +0 -0
  336. /package/dist/{chunk-QAIHRH3I.mjs → chunk-KNZJT4ET.mjs} +0 -0
  337. /package/dist/{chunk-A55HN5OK.mjs → chunk-N3DSBH5S.mjs} +0 -0
  338. /package/dist/{chunk-QR6A54KJ.mjs → chunk-ZW2A6GBW.mjs} +0 -0
@@ -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 ae,b as se}from"./chunk-5IIH335D.mjs";import{a as It}from"./chunk-JXLSHVJ2.mjs";import{f as Wt}from"./chunk-VG5JEIUQ.mjs";import{b as ie,e as Ce}from"./chunk-N3DSBH5S.mjs";import{randomBytes as _t}from"node:crypto";import j from"node:fs/promises";import g from"node:path";import{writeAtomic as z}from"../browser/shared/files.mjs";import{sendJson as Q}from"../browser/shared/http.mjs";import{said as rt,saying as Ut}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as an}from"../browser/shared/paths.mjs";import{moveDocument as sn,outlineAndFile as cn,ownsOutline as ln,sharedOutline as me,placeIn as jt,readOutline as pe,validOutline as ke,withOutlineLock as he,writeHead as un,writeOutline as fn,writtenAs as dn}from"../browser/shared/outline.mjs";Ce();import Ot from"node:fs/promises";import Nt from"node:path";import{attr as Fe,walk as Je}from"../browser/shared/html-tree.mjs";import{escapeAttribute as Ge}from"../browser/shared/escape.mjs";import{COMPONENTS_FOLDER as Me,DOCUMENT_FOLDERS as We,SHARED_FOLDERS as Ye,documentFiles as ce,packageFolders as He,readLink as Be}from"../browser/shared/workspace.mjs";async function Yt(w,b){let c=await Ot.readdir(Nt.join(w,b),{withFileTypes:!0});if(!Ye.includes(b))return c.map(({name:A})=>A);let _=b===Me?new Set(He(w).map(({id:A})=>A.split("/")[0])):new Set;return c.filter(A=>A.isFile()||We.includes(A.name)&&!_.has(A.name)).map(({name:A})=>A)}async function Ht(w,b,c,_,{names:A=new Map}={}){let L=Nt.join(w,b),wt=await Ot.access(ce(L).html).then(()=>!0,()=>!1)?null:await Be(L),B=new Set(["",...await Yt(w,b)]);if(await Ot.cp(L,c,{recursive:!0,errorOnExist:!0,force:!1,filter:a=>B.has(Nt.relative(L,a).split(Nt.sep)[0])}),wt)return[];let st=ce(c).html,N=await Ot.readFile(st,"utf8"),G=It(N),ct=new Map,lt=new Set;Je(ie(G.replace(/^\uFEFF/," "),{sourceCodeLocationInfo:!0}),a=>{let M=Fe(a,"data-doc-component");M&&lt.add(M);for(let{name:J,value:W}of a.attrs??[]){let I=a.sourceCodeLocation?.attrs?.[J];if(!I)continue;let F=/^(\.\.\/)([a-z0-9]+(?:-[a-z0-9]+)*)(\/.*)$/.exec(W),Z=J==="data-doc-id"&&W===b?_:["href","src","poster"].includes(J)&&F&&A.has(F[2])?`../${A.get(F[2])}${F[3]}`:W;Z!==W&&ct.set(I.startOffset,{to:I.endOffset,text:`${J}="${Ge(Z)}"`})}});let V=[...ct].sort(([a],[M])=>M-a).reduce((a,[M,J])=>a.slice(0,M)+J.text+a.slice(J.to),G);return await Ot.writeFile(st,V),[...lt]}import{storedHead as wn}from"../browser/shared/sidebar-head.mjs";import{DOCS as Tt,columnWorkspaceId as mn,entryWorkspace as pn,entryPattern as kn,isForeign as ge,isTop as ft,topOf as pt}from"../browser/shared/outline-shape.mjs";import{addDraft as ye,addWorkspace as hn,draftEntry as bt,draftFacts as Oe,draftOf as Kt,findDraft as gn,foreignMarker as yn,projectChoices as On,registeredIds as je,workspaceNames as jn,workspaceOf as X}from"../browser/shared/drafts.mjs";import{forgetSnapshot as nt,shownWorkspaces as bn}from"../browser/shared/workspace-columns.mjs";import{nameStops as Sn}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as vn,workspaceId as Ct,workspaceKey as be}from"../browser/shared/workspace-registry.mjs";import{spawn as fe}from"node:child_process";import Ve from"node:http";import Ue from"node:os";import Vt from"node:path";import{NO_DEFAULT_TREE as Ke}from"../browser/shared/drafts.mjs";import{said as le}from"../browser/shared/i18n/index.mjs";import{packageRoot as ze}from"../browser/shared/paths.mjs";import{answerOf as ue,compareVersions as Xe,galleryVersion as Qe,readAnnouncement as Bt}from"../browser/shared/preview-server.mjs";import{isWorkspace as Ze,readRegistry as De,workspaceId as qe,workspaceKey as $t}from"../browser/shared/workspace-registry.mjs";var Rt={rename:{to:"workspace",fields:["slug","title"]},create:{to:"workspace",fields:["title","description","language"]},trash:{to:"workspace",fields:["slug","kind"]},"link-set":{to:"workspace",fields:["slug","url","title","icon"]},"copy-from":{to:"workspace",fields:["sourceWs","slug","parent","index"]},link:{to:"workspace",fields:["url","title","parent","first"]},restore:{to:"workspace",fields:["id"]},duplicate:{to:"workspace",fields:["slug","suffix","untitled"]},look:{to:"workspace",fields:["slug","look"]},looks:{to:"workspace",fields:["slug"]},markdown:{to:"transfer",fields:["slug"]},import:{to:"transfer",fields:["uploads","parent","from","language"]},annotations:{to:"edit",fields:["slug","restore"]},export:{to:"transfer",fields:["slug","options"],file:"out",timeout:6e5},upload:{to:"transfer",fields:[],query:["name"],file:"in",timeout:36e5}},tn=["content-type","content-length","content-disposition","x-file-name","cache-control"],en=9e4,nn=w=>!["","0",void 0].includes(w);function rn(w,{platform:b=process.platform,env:c=process.env}={}){return nn(c.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:b==="win32"?{command:Vt.join(c.SystemRoot||c.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${w}"`],verbatim:!0}:b==="darwin"?{command:"open",args:["-R",w]}:!c.DISPLAY&&!c.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[Vt.dirname(w)]}}function de(w,b){let c=rn(w,b);return c.skip?Promise.resolve({opened:!1,why:c.skip}):new Promise(_=>{let A;try{A=fe(c.command,c.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!c.verbatim})}catch(L){return _({opened:!1,why:L.code??L.message})}A.once("error",L=>_({opened:!1,why:L.code??L.message})),A.once("spawn",()=>{A.unref(),_({opened:!0})})})}function on(w){let b=/^http:\/\/127\.0\.0\.1:(\d{1,5})$/.exec(String(w??"")),c=b?Number(b[1]):0;return c>0&&c<65536?c:null}function we({root:w,changed:b=()=>{},log:c=()=>{},gallery:_=Vt.join(ze,"bin","gallery.mjs")}){let A=$t(w),L=new Map;function Et(y){let k={...process.env,[Ke]:"1",GALLERY_NO_UPDATE_CHECK:"1"};return delete k.GALLERY_WORKSPACE,delete k.GALLERY_SERVER_KIND,k.GALLERY_VITE_CACHE_DIR&&(k.GALLERY_VITE_CACHE_DIR=`${k.GALLERY_VITE_CACHE_DIR}-${qe(y)}`),new Promise(v=>{let O=[],S;try{S=fe(process.execPath,[_,"--workspace",y,"open","--no-browser"],{cwd:Ue.homedir(),env:k,stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch($){return v({ok:!1,message:$.message})}S.stdout.on("data",$=>O.push(String($))),S.stderr.on("data",$=>O.push(String($)));let P=setTimeout(()=>S.kill(),en);S.once("error",$=>{clearTimeout(P),v({ok:!1,message:$.message})}),S.once("exit",$=>{clearTimeout(P);let m=O.join("").trim().split(/\r?\n/).filter(Boolean);v($===0?{ok:!0}:{ok:!1,message:m.slice(-3).join(" ")||`gallery open ended with ${$}`})})})}async function wt(y){let k=await Bt({reportsDirectory:y});return!k||await ue(k,y,5e3)!=="yes"||k.kind!=="dev"&&Xe(k.version,Qe)<0?null:{port:k.port,token:k.token,pid:k.pid}}async function B(y,{start:k=!0}={}){if($t(y)===A)return{refused:"self",message:"\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"};if(!Ze(y))return{refused:"workspace",message:le("\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A{0} \u4E0D\u5728\u4E86",y)};let v=await wt(y);if(v||!k)return v??{refused:"start",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u5728\u8FD0\u884C"};let O=$t(y);L.has(O)||(c(`starting the server of ${y}`),L.set(O,Et(y).finally(()=>L.delete(O))));let S=await L.get(O);return await wt(y)??{refused:"start",message:S.ok?"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54":le("\u6CA1\u80FD\u542F\u52A8\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\uFF1A{0}",S.message)}}let st=(y,k,v,O)=>{let S=Rt[k],P=Object.fromEntries(S.fields.filter(m=>v?.[m]!==void 0).map(m=>[m,v[m]]));k==="trash"&&P.kind!=="link"&&delete P.kind;let $=new URLSearchParams((S.query??[]).filter(m=>O?.[m]!==void 0).map(m=>[m,String(O[m])]));return{fields:P,host:`127.0.0.1:${y.port}`,path:`/__gallery/${S.to}/${k}${$.size?`?${$}`:""}`}};async function N(y,k,v){if(!Object.hasOwn(Rt,k)||Rt[k].file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let O=await B(y);if(O.refused)return[409,{ok:!1,reason:O.refused,message:O.message}];let{fields:S,host:P,path:$}=st(O,k,v);try{let m=await fetch(`http://${P}${$}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${P}`,"X-Gallery-Token":O.token},body:JSON.stringify(S),signal:AbortSignal.timeout(3e4)}),D=await m.json().catch(()=>null);return D&&typeof D.ok=="boolean"?[m.status,D]:[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"}]}}async function G(y,k,{body:v={},query:O={},request:S=null,response:P}){let $=Rt[k];if(!$?.file)return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let m=await B(y);if(m.refused)return[409,{ok:!1,reason:m.refused,message:m.message}];let{fields:D,host:ot,path:U}=st(m,k,v,O);return new Promise(mt=>{let K={Origin:`http://${ot}`,"X-Gallery-Token":m.token},q=$.file==="out"?Buffer.from(JSON.stringify(D)):null;q?Object.assign(K,{"Content-Type":"application/json","Content-Length":q.length}):Object.assign(K,{"Content-Type":"application/octet-stream",...S.headers["content-length"]?{"Content-Length":S.headers["content-length"]}:{}});let kt=[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}],it=Ve.request({host:"127.0.0.1",port:m.port,path:U,method:"POST",headers:K,timeout:$.timeout},R=>{P.writeHead(R.statusCode??502,Object.fromEntries(tn.filter(Y=>R.headers[Y]!==void 0).map(Y=>[Y,R.headers[Y]]))),R.pipe(P),R.once("end",()=>mt(null)),R.once("error",()=>{P.destroy(),mt(null)})});it.once("timeout",()=>it.destroy()),it.once("error",()=>{P.headersSent?(P.destroy(),mt(null)):mt(kt)}),P.once("close",()=>{P.writableEnded||it.destroy()}),q?it.end(q):S.pipe(it)})}let ct=new Map;async function lt(y){let k=on(y);if(k===null)return!1;let v=ct.get(k);if(v&&Date.now()-v.at<6e4)return v.answer;let O=(async()=>{for(let{root:S}of De().workspaces){let P=await Bt({reportsDirectory:S});if(P?.port===k&&await ue(P,S,3e3)==="yes")return!0}return!1})();return ct.set(k,{at:Date.now(),answer:O}),O}let V=new Map,a=new Map,M=new Set,J=!1;async function W(y,k,v){let O=new AbortController,S={controller:O,port:v.port};a.set(y,S);try{let P=await fetch(`http://127.0.0.1:${v.port}/__gallery/events?workspace=own`,{signal:O.signal});if(!P.ok||!P.body)return;M.has(y)&&b(k),M.add(y);let $=new TextDecoder,m="";for await(let D of P.body){m+=$.decode(D,{stream:!0});for(let ot=m.indexOf(`
3
+
4
+ `);ot>=0;ot=m.indexOf(`
5
+
6
+ `)){let U=m.slice(0,ot);m=m.slice(ot+2),/^data: workspace /m.test(U)&&b(k)}}}catch{}finally{a.get(y)===S&&a.delete(y)}}async function I(){for(let[y,k]of a)V.has(y)||k.controller.abort();for(let[y,k]of V){if(J||a.has(y)||$t(k)===A)continue;let v=await Bt({reportsDirectory:k});v&&!a.has(y)&&!J&&W(y,k,v)}}let F=Promise.resolve(),Z=setInterval(()=>{F=F.then(I).catch(()=>{})},3e3);Z.unref();function Mt(y){V.clear();for(let[k,v]of y)v&&V.set(k,v);F=F.then(I).catch(()=>{})}function At(){J=!0,clearInterval(Z);for(let{controller:y}of a.values())y.abort();a.clear()}return{serverOf:B,forward:N,relay:G,shellVouched:lt,follow:Mt,close:At,get following(){return[...a.keys()]}}}import{LINK_FILE as zt,linkStem as xn,linkValue as St,ownAddress as Xt,readLinkText as En}from"../browser/shared/web-links.mjs";import{sameDirectory as dt}from"../browser/shared/preview-server.mjs";import{listReportSlugs as An,slugPattern as T}from"../browser/shared/reports.mjs";import{PAGE_SLUG as Pn,SHARED_FOLDERS as Se,defaultWorkspace as Ln,documentDirectory as In,documentFiles as vt,ensureWorkspace as Nn,idHolder as $n,isDocSlug as Rn,layoutOf as Ft,listTrash as _n,newDocSlug as Jt,pageSlug as Tn,readLink as Qt,slugTaken as Cn,trashIdPattern as ve}from"../browser/shared/workspace.mjs";import{createPage as Fn,headOf as xe,listPages as Jn,newPageSlug as Gn,pageFiles as xt,readPageMeta as Zt,renamePage as Mn}from"../browser/shared/pages.mjs";import{editExtension as Wn,extensionSource as Yn,listExtensions as Hn}from"../browser/shared/extensions.mjs";import{effectiveLook as Dt,ownLookFor as Bn,ownLookOf as Vn,sameLook as Un,withLookField as Ee}from"../browser/shared/document-look.mjs";import{workspaceLook as qt,writeWorkspaceLook as Kn}from"../browser/shared/workspace-look.mjs";import{findIn as zn,tidyQuery as Xn}from"../browser/shared/search.mjs";var Qn=([w,b,c,..._])=>_.length?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",w,b,c,_.length+3):c!==void 0?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",w,b,c):b!==void 0?rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",w,b):rt("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",w),Gt=w=>w==="en"?"en":null,Zn=32*1024*1024;async function at(w,b){for(let c=0;;c++)try{return await j.rename(w,b)}catch(_){if(!["EPERM","EBUSY","EACCES"].includes(_.code))throw _;if(c>=5)break;await new Promise(A=>setTimeout(A,60*(c+1)))}await j.cp(w,b,{recursive:!0,errorOnExist:!0,force:!1}),await j.rm(w,{recursive:!0,force:!0,maxRetries:5})}var Dn=w=>g.resolve(w);function Ur({edits:w,reports:b,reportsDirectory:c=an,server:_={kind:"dev",version:null,stop:null},components:A=null,changed:L=()=>{},relayed:Et=L,index:wt=null,web:B=null,elsewhere:st=null}){let{trash:N}=Ft(c),G=st??we({root:c,changed:t=>{t&&nt(t),Et()}}),ct=null,lt=()=>ct??=Sn(),V=wt??se({root:c,read:ae(w),draw:(t,e)=>b.words(t,e)}),a=(t,e,n)=>[t,{ok:!1,reason:e,...Ut(n)}],M=t=>j.readFile(t,"utf8").then(JSON.parse).catch(()=>null),J=t=>In(t,c),W=t=>vt(J(t)),I=t=>g.join(c,t),F=t=>K(vt(I(t)).html),Z=t=>Promise.resolve(w.forgetChanges?.(t)).catch(()=>{}),Mt=t=>Yt(c,t),At=async(t,e,n)=>{await j.mkdir(n,{recursive:!0});let o=[];try{for(let r of t)await at(g.join(e,r),g.join(n,r)),o.push(r)}catch(r){for(let i of o)await at(g.join(n,i),g.join(e,i));throw r}},y=async(t,e)=>{if(!Se.includes(t))return at(I(t),e);await At(await Mt(t),I(t),e),await j.rmdir(I(t)).catch(()=>{})},k=async(t,e)=>Se.includes(t)&&!await F(t)&&(await Promise.all((await j.readdir(e)).map(n=>K(g.join(I(t),n))))).every(n=>!n),v=async t=>await M(vt(t).json)??{},O=async t=>{let{title:e=t,description:n="",type:o,instructions:r,icon:i,look:s}=await v(J(t)),l=r===!0?{}:Dt(s,qt(c));return{slug:t,title:e,description:n,...o?{type:o}:{},...typeof i=="string"&&i?{icon:i}:{},...r===!0?{instructions:!0}:{},...Object.keys(l).length?{look:l}:{}}},S=async t=>{let e=await Qt(I(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},P=async(t,e,n=[])=>{let o=Kt(t),r=o&&n.find(({id:et})=>et===o.ws),i=r?.facts.get(o.slug);if(i){let et=g.join(r.root,o.slug);return{slug:t,title:i.title,description:i.description,kind:i.kind==="link"?"link":"draft",workspace:o.ws,...i.icon?{icon:i.icon}:{},...i.kind==="link"?{url:i.url,siteIcon:i.siteIcon}:{},path:i.path,folder:et,root:r.root}}let{ws:s,title:l,description:u,icon:f,path:h,folder:d,root:p,missing:x,kind:H,url:E,siteIcon:C}=await Oe(t,e);return{slug:t,title:l,description:u,kind:H==="link"?"link":"draft",workspace:s,...H==="link"?{url:E,siteIcon:C}:{},...f?{icon:f}:{},...h?{path:h,folder:d,root:p}:{},...x?{missing:x}:{}}},$=async(t,e,n,o)=>ge(t)?P(t,n,o):e.includes(t)?await S(t)??{slug:t,title:t,description:"",kind:"link",url:""}:O(t),m=Ct(c),D=()=>be(Ln())===be(c),ot=(t,e)=>{let n=t.shown.find(({isDefault:l})=>l)?.id??(D()?m:null),o=new Set([...t.drafts.map(l=>Kt(l)?.ws),...t.groups.map(({workspace:l})=>l),...t.shown.map(({id:l})=>l)].filter(Boolean)),r=new Set(t.groups.filter(({workspace:l,title:u})=>l&&!u).map(({workspace:l})=>l));t.groups.find(({id:l})=>l===Tt)?.title||r.add(m),r.delete(n);let i=jn(new Set([...o,m]),{ids:new Map([...e,[m,[c]]]),stops:lt(),among:r});G.follow(new Map([...i].filter(([l])=>l!==m).map(([l,{root:u}])=>[l,u])));let s=Object.fromEntries([...o].map(l=>[l,{...i.get(l)??{missing:X(l,e).refused??"unknown"},...l===n?{default:!0}:{}}]));return s[m]={...i.get(m),there:!0,self:!0,...m===n?{default:!0}:{}},s},U=()=>Tn(c),mt=async(t,e)=>{let n=await v(J(t));await z(W(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
7
+ `)},K=t=>j.access(t).then(()=>!0,()=>!1),q=async(t,{own:e=null}={})=>{let n=new Set((await ht()).map(({slug:o})=>o));n.delete(e);for(let o=1;;o++){let r=o===1?t:`${t}-${o}`;if(!Cn(r,c)&&!n.has(r))return r}},kt=async t=>{let e=await q(t.slug,{own:t.slug});return Rn(t.slug)?e===t.slug&&!await $n(t.slug,c)?e:Jt(c):e},it=async(t,e)=>{let n=W(t).html,o=await j.readFile(n,"utf8"),r=It(o).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);r!==o&&await z(n,r)},R=()=>pe(c),Y=async t=>{await fn(c,t),L()},tt=t=>he(c,t);async function Pt(t,e="",n=1/0){await tt(async()=>{let o=await R();jt(o,t,e,n),await Y(o)})}async function Lt(t,{parent:e="",after:n=null,first:o=!1}={}){await tt(async()=>{let r=await R();for(let s of Object.values(r.children))s.includes(t)&&s.splice(s.indexOf(t),1);let i=typeof n=="string"?Object.keys(r.children).find(s=>r.children[s].includes(n)):void 0;i!==void 0?jt(r,t,i,r.children[i].indexOf(n)+1):jt(r,t,typeof e=="string"?e:"",o===!0?0:1/0),await Y(r)})}function Ae(t,e){let n=new Set(Object.values(t.children).flat()),o={...t.children};for(let{id:r}of e.groups){if(r===Tt)continue;let i=s=>{let l=(e.children[s]??[]).filter(u=>!n.has(u));(ft(s)||l.length)&&(o[s]=l),l.forEach(i)};i(pt(r))}return{groups:e.groups,children:o}}function te(t){return tt(async()=>{let e=await R();for(let[n,o]of Object.entries(e.children)){let r=o.indexOf(t);if(!(r<0))return o.splice(r,1,...e.children[t]??[]),delete e.children[t],await Y(e),{parent:n,index:r}}return{parent:"",index:1/0}})}let Pe=(t,e)=>V.lines(t,e),ee=t=>M(g.join(N,t,"entry.json")),ht=()=>_n(c);async function Le(t){let e=await Zt(t,c);if(!e)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`;try{await j.mkdir(g.join(N,n),{recursive:!0}),await at(xt(t,c).folder,g.join(N,n,"page"))}catch(r){throw await j.rm(g.join(N,n),{recursive:!0,force:!0}).catch(()=>{}),r}let o={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await z(g.join(N,n,"entry.json"),`${JSON.stringify(o,null,2)}
8
+ `),[200,{ok:!0,entry:o}]}async function Ie(t){let e=g.join(N,t.id,"page"),n=await kt(t);if(await j.mkdir(Ft(c).customPages,{recursive:!0}),await at(e,xt(n,c).folder),n!==t.slug){let{html:o}=xt(n,c),r=await j.readFile(o,"utf8").catch(()=>null),i=r?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);r!==null&&i!==r&&await z(o,i)}return await j.rm(g.join(N,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await Zt(n,c),entry:{...t,slug:n}}]}async function Ne(t){let e=await Qt(I(t));if(!e)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,o=await R(),{parent:r,index:i}=await te(t);try{await j.mkdir(g.join(N,n),{recursive:!0}),await at(I(t),g.join(N,n,"link"))}catch(l){throw await tt(()=>Y(o)),await j.rm(g.join(N,n),{recursive:!0,force:!0}).catch(()=>{}),l}let s={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:r,index:Number.isFinite(i)?i:-1};return await z(g.join(N,n,"entry.json"),`${JSON.stringify(s,null,2)}
9
+ `),[200,{ok:!0,entry:s}]}async function $e(t){let e=g.join(N,t.id,"link"),n=await kt(t);return await at(e,I(n)),await j.rm(g.join(N,t.id),{recursive:!0,force:!0}),await Pt(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await S(n),entry:{...t,slug:n}}]}function Re(t,{parent:e,after:n,first:o}){let r=s=>ft(s)?Object.hasOwn(t.children,s):Object.values(t.children).some(l=>l.includes(s));if(n!=null){let s=Object.keys(t.children).find(l=>t.children[l].includes(n));return s===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==s?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:s,index:t.children[s].indexOf(n)+1}}let i=e??pt(Tt);return ft(i)&&t.groups.some(s=>s.extension&&pt(s.id)===i)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:r(i)?{parent:i,index:o?0:(t.children[i]??[]).length}:{refused:[404,"parent",ft(i)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let ut=new Map;function _e(t){let e=ut.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=B?B.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return ut.size>=500&&ut.delete(ut.keys().next().value),ut.set(t,{at:Date.now(),answer:n}),n.then(o=>{["auth","unknown"].includes(o.reason)&&ut.get(t)?.answer===n&&ut.delete(t)}),n}function ne(t,e){return B?.icon?(async()=>{let n=await B.icon(e).catch(()=>null);if(!n)return null;let o=g.join(I(t),zt),r=await j.readFile(o,"utf8").catch(()=>null),i=r===null?null:En(r);if(!i||i.url!==e||i.siteIcon===n)return null;let s=St({...i,siteIcon:n});return s.refused||!s.value.siteIcon||!await z(o,`${JSON.stringify(s.value,null,2)}
10
+ `,{expect:r})?null:(L(),n)})().catch(()=>null):Promise.resolve(null)}let re={info:async()=>[200,{ok:!0,version:1,gallery:_.version,token:w.token,commands:[...Object.keys(gt)],server:{pid:process.pid,workspace:g.resolve(c),kind:_.kind}}],async outline(){let{outline:t,others:e}=await cn(c),n=await U(),o=[...Object.values(t.children).flat(),...n?[n]:[]],r=je(),i=async p=>[p,await $(p,t.links,r,e)],[s,l,u,f]=await Promise.all([Promise.all(o.map(i)),Jn(c),ht(),Hn(c)]),h=f.map(({id:p,file:x,title:H,icon:E,entries:C,count:et,error:yt})=>({id:p,file:x,title:H,...E?{icon:E}:{},entries:C,count:et,...yt?{error:Ut(yt)}:{}})),d=await xe(c,l);return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(s),pages:l,head:d,trash:u,workspaces:ot(t,r),self:m,shared:me(c),extensions:h}]},trash:async()=>[200,{ok:!0,entries:await ht()}],async stats(t){let e=t.get("slug")??"",n=T.test(e)?await V.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:a(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 V.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,...A.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!T.test(e))return a(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let o=g.resolve(n?xt(e,c).html:W(e).html);return await K(o)?[200,{ok:!0,path:o}]:a(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await On(c,{stops:lt()})}],shell:async t=>[200,{ok:!0,shell:await G.shellVouched(t.get("origin"))}],async search(t){let e=Xn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:o,links:r}=await R(),i=[],s=d=>(n[d]??[]).forEach(p=>{!r.includes(p)&&!ge(p)&&i.push(p),s(p)});for(let{id:d}of o)s(pt(d));let l=e.toLowerCase(),u=new Map(await Promise.all(i.map(async d=>[d,await O(d)]))),f=JSON.stringify([...u].map(([d,{title:p}])=>[d,p])),h=(await Promise.all(i.map(async d=>{let p=await Pe(d,f);if(!p)return null;let x=String(u.get(d).title).toLowerCase().includes(l),{count:H,hits:E}=zn(p,e);return x||H?{slug:d,title:x,count:H,hits:E}:null}))).filter(Boolean);return h.sort((d,p)=>Number(p.title)-Number(d.title)||p.count-d.count),[200,{ok:!0,results:h.slice(0,50)}]}},gt={async"extension-edit"({id:t,...e}){let n=await Yn(c,t),o=await he(n?.root??c,()=>Wn(n?.root??c,t,e),{local:!0});return o.ok?(o.written&&L(),[200,{ok:!0}]):a(o.status,o.reason,o.error)},async outline({outline:t,base:e}){return!ke(t)||e!==void 0&&!ke(e)?a(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):me(c)&&!ln(c,t)?a(409,"cross-workspace","\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E"):await tt(async()=>{let o=await R();return e!==void 0&&!dn(e,o)?!1:(await Y(t.groups?t:Ae(t,o)),!0)})?[200,{ok:!0,outline:await R()}]:a(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:e,after:n=null,first:o=!1,workspace:r}){if(typeof r=="string"&&!dt(r,c))return a(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"&&T.test(u);if(!i(t)||e!==void 0&&e!==""&&!i(e)||n!==null&&!i(n)||typeof o!="boolean")return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let s=await U();if(s!==null&&[t,e,n].includes(s))return a(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 l=await sn(c,t,{parent:e,after:n,first:o});if(l.written&&L(),!l.ok){let[u,f]={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"],"cross-workspace":[409,"\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E"]}[l.reason];return a(u,l.reason,f)}return[200,{ok:!0,...l,outline:await R()}]},async create({title:t,description:e,parent:n="",after:o=null,first:r=!1,language:i}){let s=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",l=await Jt(c);return await Z(l),await b.create(l,s,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:Gt(i)}),await Lt(l,{parent:n,after:o,first:r}),[200,{ok:!0,report:await O(l)}]},async instructions({title:t,description:e,language:n}){let o=await U();if(o)return[200,{ok:!0,report:await O(o)}];let r=await q(Pn),i=(s,l)=>typeof s=="string"&&s.trim()?s.trim().slice(0,200):l;return await b.create(r,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:Gt(n),page:!0}),await mt(r,"instructions"),[200,{ok:!0,report:await O(r)}]},async components({id:t,hidden:e,shown:n,disabled:o,unlisted:r,net:i,pack:s,enabled:l}){try{return[200,{ok:!0,...await A.write(s!==void 0?{pack:s,enabled:l}:{id:t,hidden:e,shown:n,disabled:o,unlisted:r,net:i})}]}catch(u){return a(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let o=await Jt(c);await Z(o),await Ht(c,t,I(o),o);let{title:r}=await O(t),i=r||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),s=await w.renameReport(o,`${i}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),l=await R(),[u,f]=Object.entries(l.children).find(([,h])=>h.includes(t))??["",null];return await Pt(o,u,f?f.indexOf(t)+1:1/0),[200,{ok:!0,report:await O(o),notes:s.notes??[]}]},async"copy-from"({sourceWs:t,slug:e,parent:n="",index:o=0}){let r=typeof t=="string"?X(t):{};if(!r.root||t===m||typeof e!="string"||!T.test(e)||typeof n!="string"||!ft(n)&&!kn.test(n)||!Number.isInteger(o)||o<0)return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let i=await pe(r.root);if(!Object.values(i.children).some(d=>d.includes(e)))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let s=[],l=d=>{if(!T.test(d)||s.includes(d))throw new Error("\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21");s.push(d);for(let p of i.children[d]??[])l(p)};l(e);let u=new Map;for(let d of s){let p;do p=await Jt(c);while([...u.values()].includes(p));u.set(d,p)}let f=g.join(Ft(c).gallery,`copy-${_t(8).toString("hex")}`),h=[];try{await j.mkdir(f,{recursive:!0});let d=new Set;for(let x of s)for(let H of await Ht(r.root,x,g.join(f,u.get(x)),u.get(x),{names:u}))d.add(H);let p=[];if(d.size){let x=Wt(r.root),H=Wt(c);for(let E of d){let C=x.packages.get(E),et=H.packages.get(E);if(!C||et&&et.stamp!==C.stamp||H.problems.has(E))throw Object.assign(new Error,rt("\u81EA\u5B9A\u4E49\u5757 {0} \u7F3A\u5931\u6216\u7248\u672C\u51B2\u7A81\uFF0C\u672A\u590D\u5236",E));if(et)continue;let yt=g.join(f,"packages",...E.split("/"));await j.cp(C.folder,yt,{recursive:!0,force:!1,errorOnExist:!0}),p.push({staged:yt,to:g.join(Ft(c).components,...E.split("/"))})}}return await tt(async()=>{let x=await R();if((ft(n)?mn(x.groups.find(E=>pt(E.id)===n),m):pn(n,m))!==m||(ft(n)?!x.groups.some(E=>pt(E.id)===n&&!E.extension):!Object.values(x.children).some(E=>E.includes(n))))throw new Error("\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863");for(let{staged:E,to:C}of p){if(await K(C))throw new Error("\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7");await j.mkdir(g.dirname(C),{recursive:!0}),await j.rename(E,C),h.push(C)}for(let E of s){let C=u.get(E);await j.rename(g.join(f,C),I(C)),h.push(I(C))}nt(c),jt(x,u.get(e),n,o);for(let E of s)i.children[E]?.length&&(x.children[u.get(E)]=i.children[E].map(C=>u.get(C)));await Y(x)}),[200,{ok:!0,slug:u.get(e),count:s.length}]}catch(d){for(let p of h)await j.rm(p,{recursive:!0,force:!0});return nt(c),a(409,"copy",d.text?d:d.message)}finally{await j.rm(f,{recursive:!0,force:!0})}},async look({slug:t,look:e}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await U())return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return a(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=W(t).json,o=null;try{o=JSON.parse(await j.readFile(n,"utf8"))}catch{}if(!o||typeof o!="object"||Array.isArray(o))return a(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=Ee(o,Bn(e,qt(c)));return JSON.stringify(r)!==JSON.stringify(o)&&await z(n,`${JSON.stringify(r,null,2)}
11
+ `),[200,{ok:!0,report:await O(t)}]},async looks({slug:t}){if(typeof t!="string"||!T.test(t)||!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await U();if(t===e)return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await M(W(t).json);if(!n||typeof n!="object"||Array.isArray(n))return a(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let o=qt(c),r=Dt(n.look,o);try{await Kn(c,r)}catch(u){return a(409,"workspace",u)}let i=0,s=(await An(c)).filter(u=>u!==e).map(u=>({json:W(u).json,self:u===t})),l=(await ht()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:vt(g.join(N,u,"report")).json,self:!1}));for(let{json:u,self:f}of[...s,...l])for(let h=0;h<3;h++){let d=await j.readFile(u,"utf8").catch(()=>null),p=null;try{p=JSON.parse(d??"")}catch{}if(!p||typeof p!="object"||Array.isArray(p)||!Object.hasOwn(p,"look")||p.instructions===!0)break;let x=await z(u,`${JSON.stringify(Ee(p,{}),null,2)}
12
+ `,{expect:d}).catch(()=>null);if(x===null)break;if(x){!f&&Object.keys(Vn(p.look)).length>0&&!Un(Dt(p.look,o),r)&&i++;break}}return[200,{ok:!0,look:r,replaced:i,report:await O(t)}]},async head({order:t}){let e=wn(t);return e?(await tt(()=>un(c,e)),L(),[200,{ok:!0,head:await xe(c)}]):a(400,"head","\u4FA7\u680F\u5934\u90E8\u7684\u987A\u5E8F\u4E0D\u5BF9")},async"new-page"({title:t,after:e=null,language:n}){let o=typeof t=="string"?t.replace(/\s+/g," ").trim():"";if(!o||o.length>200)return a(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57");if(e!==null&&(typeof e!="string"||!T.test(e)))return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let r=await Gn(c);return await Fn(r,o,{root:c,blank:!0,after:e,...Gt(n)?{lang:Gt(n)}:{}}),L(),[200,{ok:!0,page:await Zt(r,c)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!T.test(t))return a(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let r;try{r=await Mn(t,e,c)}catch{return a(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return r?[200,{ok:!0,page:r}]:a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let o=await w.renameReport(t,e);return o.ok?[200,{ok:!0,report:await O(t),notes:o.notes}]:a({title:400,missing:404}[o.reason]??409,o.reason,o.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!T.test(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return Le(t);if(e==="link")return Ne(t);if(t===await U())return a(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await F(t))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await O(t),o=`${Date.now().toString(36)}-${_t(3).toString("hex")}`,r=await R(),{parent:i,index:s}=await te(t);try{await j.mkdir(g.join(N,o),{recursive:!0}),await y(t,g.join(N,o,"report"))}catch(u){throw await tt(()=>Y(r)),await j.rm(g.join(N,o),{recursive:!0,force:!0}).catch(()=>{}),u}let l={id:o,kind:"document",slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(s)?s:-1};return await z(g.join(N,o,"entry.json"),`${JSON.stringify(l,null,2)}
13
+ `),[200,{ok:!0,entry:l}]},async restore({id:t}){let e=typeof t=="string"&&ve.test(t)?await ee(t):null;if(!e)return a(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return Ie(e);if(e.kind==="link")return $e(e);let n=g.join(N,t,"report"),o=await k(e.slug,n),r=o?e.slug:await kt(e);return o?await At(await j.readdir(n),n,I(r)):await at(n,I(r)),r!==e.slug&&await it(r,e.slug),await j.rm(g.join(N,t),{recursive:!0,force:!0}),await Pt(r,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await O(r),entry:{...e,kind:"document",slug:r}}]},async destroy({id:t}){let e=typeof t=="string"&&ve.test(t)?await ee(t):null;return e?((e.kind??"document")==="document"&&!await F(e.slug)&&await Z(e.slug),await j.rm(g.join(N,t),{recursive:!0,force:!0}),[200,{ok:!0}]):a(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:o,after:r=null,first:i=!1},{port:s,wait:l=!1}={}){let u=St({url:t,title:e,icon:n});if(u.refused)return a(400,u.refused,u.message);if(Xt(u.value.url,s))return a(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(o!=null&&typeof o!="string"||r!==null&&typeof r!="string"||typeof i!="boolean")return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let f=await tt(async()=>{let d=await R(),p=Re(d,{parent:o,after:r,first:i||o==null&&r===null});if(p.refused)return p;let x=await q(xn(u.value.title,u.value.url));return await j.mkdir(I(x),{recursive:!0}),await z(g.join(I(x),zt),`${JSON.stringify(u.value,null,2)}
14
+ `),jt(d,x,p.parent,p.index),await Y(d),{slug:x,parent:p.parent,index:p.index}});if(f.refused)return a(...f.refused);let h=ne(f.slug,u.value.url);return l&&await h,[200,{ok:!0,link:await S(f.slug),parent:f.parent,index:f.index,outline:await R()}]},async"link-set"({slug:t,url:e,title:n,icon:o},{port:r,wait:i=!1}={}){let s=typeof t=="string"&&T.test(t)?await Qt(I(t)):null;if(!s)return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let l=e??s.url,u=St({url:l,title:n??s.title,icon:o===void 0?s.icon??null:o,siteIcon:s.siteIcon??null});if(u.refused)return a(400,u.refused,u.message);let f=u.value.url!==s.url;if(f&&Xt(u.value.url,r))return a(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(f&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(s)&&await z(g.join(I(t),zt),`${JSON.stringify(u.value,null,2)}
15
+ `),f){let h=ne(t,u.value.url);i&&await h}return[200,{ok:!0,link:await S(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let o=await gn(t),r=typeof n=="string"?n:null;if(o.kind==="missing")return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(o.kind==="plain")return a(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(o.kind==="nested")return a(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(o.kind==="name")return a(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=o.kind==="workspace"?o.root:o.kind==="folder"?null:o.root,s=!i||!bn(c).some(h=>dt(h.root,i));if(!i){let h=o.kind==="folder"?o.folder:o.parent;if(yn(h))return a(409,"marker",rt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",h));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:h,...Ut(rt("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",h))}];if(!(await Nn(h)).ours)return a(409,"marker",rt("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",h));i=h}let l=o.kind==="workspace"||o.kind==="folder";if(dt(i,c))return[200,{ok:!0,kind:l?"workspace":"draft",own:!0,existing:!0,...l?{column:Tt}:{entry:o.slug}}];let u=await vn(i,{force:!0}).catch(()=>"failed"),f=X(Ct(i));return f.refused==="ambiguous"?a(409,"ambiguous",rt("\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",f.roots.length,Ct(i))):!f.root||!dt(f.root,i)?u==="temporary"?a(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):a(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(nt(i),l?[200,{ok:!0,kind:"workspace",...await hn(c,i,{changed:L,after:r})}]:[200,{ok:!0,kind:"draft",...await ye(c,i,o.slug,{changed:L,pick:!0,after:r,fresh:s})}])},async"draft-join"({root:t,slug:e}){if(typeof t!="string"||typeof e!="string"||!T.test(e))return a(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(dt(t,c))return a(409,"own","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let n=X(Ct(t));return!n.root||!dt(n.root,t)?a(409,"registry","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):await K(vt(g.join(t,e)).html)?(nt(t),[200,{ok:!0,...await ye(c,t,e,{changed:L})}]):a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async export({slug:t}){if(typeof t!="string"||!T.test(t)||!await K(J(t)))return a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:o}=await b.export(t);return o?a(o.reason==="missing"?404:409,o.reason,o.message):e.length?a(422,"check",Qn(e)):[200,{ok:!0,path:Dn(n)}]}},oe={async frameable({url:t},{port:e}){let n=typeof t=="string"?St({url:t,title:"-"}):{refused:"url"};return n.refused?a(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Xt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await _e(n.value.url)}]},async elsewhere({ws:t}){let e=typeof t=="string"?X(t):{refused:"unknown"};if(e.refused)return a(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 G.serverOf(e.root);return n.refused?a(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 o=typeof t=="string"?X(t):{refused:"unknown"};if(o.refused)return a(409,o.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let r=await G.forward(o.root,e,n);return r[1]?.ok&&nt(o.root),r},async"draft-duplicate"({ws:t,slug:e,suffix:n,untitled:o}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let r=typeof t=="string"?X(t):{refused:"unknown"};if(r.refused)return a(409,r.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[i,s]=await G.forward(r.root,"duplicate",{slug:e,suffix:n,untitled:o});if(!s?.ok)return[i,s];let l=s.report?.slug;if(typeof l!="string"||!T.test(l))return a(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let u=bt(t,l);return nt(r.root),await Lt(u,{after:bt(t,e)}),[200,{ok:!0,entry:u,report:{...s.report,slug:u,kind:"draft",workspace:t}}]},async"draft-import"({ws:t,uploads:e,parent:n="",from:o,language:r}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let i=typeof t=="string"?X(t):{refused:"unknown"};if(i.refused)return a(409,i.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[s,l]=await G.forward(i.root,"import",{uploads:e,parent:n,from:o,language:r});if(!l?.ok)return[s,l];nt(i.root);let u=(Array.isArray(l.reports)?l.reports:[]).filter(h=>typeof h=="string"&&T.test(h)).map(h=>bt(t,h)),f=typeof n=="string"&&T.test(n)?bt(t,n):null;if(f&&u.length&&Object.values((await R()).children).some(h=>h.includes(f)))for(let h of u)await Lt(h,{parent:f});return[200,{...l,reports:u}]},async"draft-create"({ws:t,title:e,description:n,language:o,parent:r="",after:i=null,first:s=!1}){if(t===m)return a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let l=typeof t=="string"?X(t):{refused:"unknown"};if(l.refused)return a(409,l.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[u,f]=await G.forward(l.root,"create",{title:e,description:n,language:o});if(!f?.ok)return[u,f];let h=f.report?.slug;if(typeof h!="string"||!T.test(h))return a(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let d=bt(t,h);return nt(l.root),await Lt(d,{parent:r,after:i,first:s}),[200,{ok:!0,entry:d,report:{...f.report,slug:d,kind:"draft",workspace:t}}]},async reveal({entry:t,ws:e,page:n}){let o=je(),r=null;return typeof n=="string"?r=T.test(n)?xt(n,c).folder:null:typeof t=="string"&&Kt(t)?r=(await Oe(t,o)).folder:e===m?r=g.resolve(c):typeof e=="string"&&(r=X(e,o).root??null),!r||!await K(r)?a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:r,...await de(r)}]},async title({url:t}){let e=typeof t=="string"?St({url:t,title:"-"}):{refused:"url"};if(e.refused)return a(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=B?await B.title(e.value.url).catch(()=>""):"",o=typeof n=="string"?n:n?.title,r=["auth","unknown"].includes(n?.reason)?n.reason:void 0;return[200,{ok:!0,title:typeof o=="string"?o.slice(0,200):"",...r?{reason:r}:{}}]}};function Te(t,e,n){if(t.method==="GET"&&Object.hasOwn(re,n)){let r=t.headers.host??"",i=t.socket.localPort;return r!==`127.0.0.1:${i}`&&r!==`localhost:${i}`?Q(e,403,{ok:!1,reason:"host"}):re[n](new URL(t.url??"/","http://localhost").searchParams).then(([s,l])=>Q(e,s,l),s=>Q(e,...a(500,"read",s)))}if(t.method==="POST"&&n==="stop")return w.respond(async r=>{let i=await w.check(r);return i.error?i.error:_.kind!=="cli"||typeof _.stop!="function"?a(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",()=>_.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return w.respond(async r=>{let i=await w.check(r,Zn);if(i.error)return i.error;if(!A?.install)return a(404,"unknown");try{return[200,{ok:!0,...A.install(i.body??{})}]}catch(s){if(!s.code)throw s;return a(409,s.code,s)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let r=await w.check(t);if(r.error)return r.error;let{slug:i,items:s}=r.body??{};return typeof i!="string"||!T.test(i)||!Array.isArray(s)?[400,{ok:!1,reason:"body"}]:!await F(i)||i===await U()?a(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):w.setTodos(i,s)})().then(([r,i])=>Q(e,r,i),r=>Q(e,...a(500,"write",r.message)));if(t.method==="POST"&&(n==="draft-export"||n==="draft-upload"))return(async()=>{let r=n==="draft-upload",i=new URL(t.url??"/","http://localhost").searchParams,s={};if(r){let f=w.checkHeaders(t);if(f)return f;if(!/^application\/octet-stream\b/i.test(t.headers["content-type"]??""))return[415,{ok:!1,reason:"type"}]}else{let f=await w.check(t);if(f.error)return f.error;s=f.body&&typeof f.body=="object"?f.body:{}}let l=r?i.get("ws"):s.ws,u=typeof l=="string"?X(l):{refused:"unknown"};return u.refused?a(409,u.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):l===m?a(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"):G.relay(u.root,r?"upload":"export",{body:s,query:{name:i.get("name")??void 0},request:t,response:e})})().then(r=>{r&&(t.resume(),Q(e,...r))},r=>{t.resume(),e.headersSent?e.destroy():Q(e,...a(500,"read",r))});let o={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(gt,n)?w.respond(async r=>{let i=await w.check(r);if(i.error)return i.error;let s=i.body&&typeof i.body=="object"?i.body:{};return typeof s.workspace=="string"&&!dt(s.workspace,c)?a(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):gt[n](s,o)})(t,e):t.method==="POST"&&Object.hasOwn(oe,n)?(async()=>{let r=await w.check(t);return r.error?r.error:oe[n](r.body&&typeof r.body=="object"?r.body:{},o)})().then(([r,i])=>Q(e,r,i),r=>Q(e,...a(500,"read",r))):Q(e,404,{ok:!1,reason:"unknown"})}return{handle:Te,outline:R,trashEntries:ht,place:Pt,freeSlug:q,index:V,run:(t,e,n={})=>Object.hasOwn(gt,t)?gt[t](e??{},{wait:!0,...n}):Promise.resolve(a(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4")),close:()=>G.close()}}export{Ur as a};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as b}from"./chunk-UKSHDZZ6.mjs";import{c as L,d as F}from"./chunk-Q4UEPUWF.mjs";import{c as x,d as j,k as w}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import l from"node:fs";import c from"node:path";import{pathToFileURL as K}from"node:url";import{projectRoot as p}from"../browser/shared/paths.mjs";import{sha256 as A}from"../browser/shared/files.mjs";var g=["SKILL.md","references/writing-html.md","references/building-blocks.md","references/block-script.md","references/pages-and-data.md","references/extensions.md","references/example-report.html","sdk","agents/openai.yaml"],u="## Before anything: the gallery command";function T(n){let[t,s]=n.split(/[.+-]/).map(Number);return{range:`^${n}`,takes:`${n} or a later ${t===0?`0.${s}`:t}.x`}}function N(n,t){let s=n.indexOf(`
2
+ import{a as b}from"./chunk-2OHANJ6Q.mjs";import{c as L,d as F}from"./chunk-Q4UEPUWF.mjs";import{c as x,d as j,k as w}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import l from"node:fs";import c from"node:path";import{pathToFileURL as K}from"node:url";import{projectRoot as p}from"../browser/shared/paths.mjs";import{sha256 as A}from"../browser/shared/files.mjs";var g=["SKILL.md","references/writing-html.md","references/building-blocks.md","references/block-script.md","references/pages-and-data.md","references/extensions.md","references/example-report.html","sdk","agents/openai.yaml"],u="## Before anything: the gallery command";function T(n){let[t,s]=n.split(/[.+-]/).map(Number);return{range:`^${n}`,takes:`${n} or a later ${t===0?`0.${s}`:t}.x`}}function N(n,t){let s=n.indexOf(`
3
3
  ${u}
4
4
  `);if(s<0)throw new Error(`SKILL.md has no section "${u}" (the version range of the command stands there)`);let e=n.indexOf(`
5
5
  ## `,s+u.length+1),i=e<0?n.length:e,{range:r,takes:o}=T(t),a=n.slice(s,i).replace(new RegExp(L.source,"g"),F(t)).replace(/\^\d+\.\d+\.\d+(?:-[\w.]+)?/g,r).replace(/\b\d+\.\d+\.\d+(?:-[\w.]+)? or a later \d+(?:\.\d+)?\.x\b/g,o);return n.slice(0,s)+a+n.slice(i)}function y(n=p){let t=g.filter(r=>!l.existsSync(c.join(n,r)));if(t.length)return t.map(r=>`the skill takes ${r}, which is not there`);let s=E(g,n),e=r=>l.readFileSync(c.join(n,r),"utf8"),i=P(s,e).map(r=>`${r}, which the skill does not hold: link only what it holds`);for(let r of s.filter(o=>o.startsWith("sdk/")&&o.endsWith(".ts")))for(let[,o]of e(r).matchAll(/\bfrom\s+["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)/g))o&&(!o.startsWith("./")||o.includes("/../"))&&i.push(`${r} imports ${o}, outside sdk/: write the types it needs in sdk/`);return i}function R(n,{root:t=p,version:s=JSON.parse(l.readFileSync(c.join(t,"package.json"),"utf8")).version}={}){let e=y(t);if(e.length)throw new Error(`The skill cannot be made:
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j}from"./chunk-SXHBYZST.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-FJYN7RTH.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{g as changeLines,c as handedInSource,f as headerChanged,e as inStep,a as naturalize,d as pendingBlockIds,h as readOnlyTexts,j as scriptKept,b as shownSource,i as writingNotes};
2
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-WTEGUPFG.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{g as changeLines,c as handedInSource,f as headerChanged,e as inStep,a as naturalize,d as pendingBlockIds,h as readOnlyTexts,j as scriptKept,b as shownSource,i as writingNotes};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as f,d as g,e as h,f as $,g as v,i as y,j as r,k as x}from"./chunk-NAMN3RAF.mjs";import{b as c,f as p}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{descendantsIn as A}from"../browser/shared/outline.mjs";async function N(L){let{positional:u,options:I,values:T}=p({options:["--top","--first"],values:["--under","--after"],argv:L});if(u.length!==1)throw new c("Name the document to move, one.");let e=x(T,I);if(e.under===void 0&&!e.top&&e.after===void 0&&!e.first)throw new c("Say where it goes: --under <document> or --top, and --after <document> or --first.");let s=await f(),a=async(b,k)=>{let d=await $(b,k,s);return d.refused&&(console.error(d.refused),process.exit(1)),d.slug},t=await a(u[0],"the document to move"),l=e.under!==void 0?await a(e.under,"--under"):e.top?"":void 0,m=e.after!==void 0?await a(e.after,"--after"):null,o=await y(t,{parent:l,after:m,first:e.first});o.ok||(console.error(v(s,t,o.reason,{parent:l,after:m,message:o.message})),process.exit(1));let n=await f(),i=A(n.children,t).length,w=`${g(n,t)}${i?` with the ${i} document${i===1?"":"s"} under it`:""}`;o.moved?console.log(`Moved ${w}: now ${r(n,o)}; it was ${r(s,o.from)}.`):console.log(`${w} is there already: ${r(n,o)}.`),console.log(h(n,t))}export{N as run};
2
+ import{a as f,d as g,e as h,f as $,g as v,i as y,j as r,k as x}from"./chunk-YPPJVDQI.mjs";import{b as c,f as p}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{descendantsIn as A}from"../browser/shared/outline.mjs";async function N(L){let{positional:u,options:I,values:T}=p({options:["--top","--first"],values:["--under","--after"],argv:L});if(u.length!==1)throw new c("Name the document to move, one.");let e=x(T,I);if(e.under===void 0&&!e.top&&e.after===void 0&&!e.first)throw new c("Say where it goes: --under <document> or --top, and --after <document> or --first.");let s=await f(),a=async(b,k)=>{let d=await $(b,k,s);return d.refused&&(console.error(d.refused),process.exit(1)),d.slug},t=await a(u[0],"the document to move"),l=e.under!==void 0?await a(e.under,"--under"):e.top?"":void 0,m=e.after!==void 0?await a(e.after,"--after"):null,o=await y(t,{parent:l,after:m,first:e.first});o.ok||(console.error(v(s,t,o.reason,{parent:l,after:m,message:o.message})),process.exit(1));let n=await f(),i=A(n.children,t).length,w=`${g(n,t)}${i?` with the ${i} document${i===1?"":"s"} under it`:""}`;o.moved?console.log(`Moved ${w}: now ${r(n,o)}; it was ${r(s,o.from)}.`):console.log(`${w} is there already: ${r(n,o)}.`),console.log(h(n,t))}export{N as run};
@@ -0,0 +1,12 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as H,c as X,e as ve}from"./chunk-N3DSBH5S.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Pe}from"node:crypto";import{existsSync as Ce,lstatSync as De,readFileSync as _,readdirSync as Me,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ke,parsePart as Ge,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as ot,OWN_SCOPE as it,PACK_FILE as ne,PACK_ID as he,readPackManifest as rt}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as at,PACKAGE_MANIFEST as I,WORKSPACE_MARK as ct,findWorkspace as lt,layoutOf as G,markerOf as ft,packageFolders as dt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),pt=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],mt=["at","edit","optional","min","max"],ut=["generated","attrs"],ht=["document","page"],wt=["document"],yt=["sizes","w","h","min","max","resize","fit","bare","consent"],y={w:12,h:24},bt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},gt=["key","label","type","options","default","required"],kt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],Ot=/^\d{4}-\d{2}-\d{2}$/,$t="settings",Et=["workspace","tables"],St=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,At=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Nt=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:At(n)}:s])),jt=["parts","text"],we=["kit.js","style.css","preview.svg"],M="template.html",zt=[I,M,...we],V=e=>[...new Set([...zt,...e])].sort(),Tt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,It=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Pe("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=De(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&_(s)}catch{return null}}var ce=new Map,vt=2e3;function _t(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(_(e)));return Date.now()-s>vt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=_t(o))}catch{}s.update(`${t}\0${f}
3
+ `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},E=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},v=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ke(n).tag);function Pt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),E(n,mt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ge(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}St.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var Ct=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Dt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),E(e,ut,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(l){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,l.message))}return d.split(",").map(l=>l.trim().startsWith(":scope")?l.trim().replace(":scope",s):`${s} ${l.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)It.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let c=d=>{let a=t(d,"runtime.generated");return Ct(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(c),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var T=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Mt(e){return e===void 0?wt:((!Array.isArray(e)||e.length===0||!e.every(n=>ht.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Ft(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),E(e,yt,"card.");let n=a=>Array.isArray(a)&&a.length===2&&T(a[0],y.w)&&T(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let l=["w","h"].find(p=>e[p]!==void 0);l&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",l))}for(let a of["w","h"])e[a]!==void 0&&!T(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let l=e[a];if(l!==void 0){u(l)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),E(l,["w","h"],`card.${a}.`);for(let p of["w","h"])l[p]!==void 0&&!T(l[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=l}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,c=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([l,p])=>l<t.w||l>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let l={w:f,h:c}[a];l!==null&&!e.sizes&&(l<t[a]||l>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,l,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!bt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),e.consent!==void 0&&v(e.consent,"card.consent"),{sizes:e.sizes?e.sizes.map(([a,l])=>[a,l]):null,any:d,w:f,h:c,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1,...e.consent!==void 0?{consent:{zh:e.consent.zh,en:e.consent.en}}:{}}}var Lt=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&Ot.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Rt(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let c=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",c)),E(o,gt,`${c}.`),(typeof o.key!="string"||!kt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",c)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),v(o.label,`${c}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",c,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",c)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",c,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",c)),o.default!==void 0&&!Lt(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",c,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",c))});let t=n[$t];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Kt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Et.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Gt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Vt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)Tt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Ut(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))at.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});E(t,pt),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),v(t.name,"name"),v(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))Pt(w,$);let o=Dt(t.runtime,e),{kit:f,own:c}=Vt(t.assets,n);t.markdown!==void 0&&!jt.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Mt(t.places);Gt(d,t.parts);let a=Ft(t.card),l=Rt(t.settings,t.parts),p=Kt(t.needs),h=ye(n,M);return h&&ge(h,M),{id:e,match:Ze(e),parts:Nt(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:l,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...c])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(c))}}function Wt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Ut(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var P=()=>lt().root,Bt=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,x=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Jt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,x(s,me)]).filter(([,n])=>n.length>0)),Zt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),C=e=>{let n=Zt(e?.components?.packs);return{hidden:x(e?.components?.hidden,Bt),disabled:x(e?.components?.disabled,A),shown:x(e?.components?.shown,A),unlisted:x(e?.components?.unlisted,A),net:Jt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),qt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ft(e);return s?{value:n}:{problem:t?qt:B}}function ke(e){try{return L(_(G(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var On=(e=P())=>C(ke(e).value),Yt=["EPERM","EACCES","EBUSY","EROFS"];async function $n(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:c,pack:d,enabled:a}){let l=G(e).marker,p=await Le.readFile(l,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:ze,unlisted:Te}=C(h),g=u(h?.components)?h.components:{},Z=$(ze,t),q=$(Te,f),z={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};z.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(c!==void 0){let m={...u(g.net)?g.net:{}};c.length>0?m[n]=[...new Set(c)]:delete m[n],Object.keys(m).length>0?z.net=m:delete z.net}await He(l,`${JSON.stringify({...h??ct,components:z},null,2)}
4
+ `,{expect:p}).catch(m=>{throw Yt.includes(m.code)&&r(i("gallery.json \u5199\u4E0D\u8FDB\u53BB\uFF1A\u53EF\u80FD\u662F\u53EA\u8BFB\u7684\uFF0C\u6216\u88AB\u522B\u7684\u7A0B\u5E8F\u5360\u7740")),m})||r(i("gallery.json \u521A\u521A\u88AB\u6539\u8FC7\uFF1A\u518D\u8BD5\u4E00\u6B21"))}var Ht=e=>({...e,off:!0,disabled:!0,problem:i("\u5728\u8BBE\u7F6E\u91CC\u505C\u7528\u4E86"),stamp:S(n=>n.update(`${e.stamp} off`))}),D=C(null),Xt=({packages:e,problems:n,settings:s=D,packs:t=new Map})=>S(o=>{for(let{id:f,stamp:c}of[...e.values(),...n.values()].sort(U))o.update(`${f} ${c}
5
+ `);o.update(`hidden ${[...s.hidden].sort().join(" ")}
6
+ `),o.update(`shown ${[...s.shown].sort().join(" ")}
7
+ `),o.update(`unlisted ${[...s.unlisted??[]].sort().join(" ")}
8
+ `),o.update(`net ${Oe(s).join(" ")}
9
+ `),o.update(`packs off ${(s.packsOff??[]).join(" ")}
10
+ `);for(let[f,c]of[...t].sort(([d],[a])=>d<a?-1:1))o.update(`pack ${f} ${JSON.stringify(c)}
11
+ `);o.update(`settings ${s.problem?.message??""}
12
+ `)}),Oe=({net:e={}})=>Object.entries(e).flatMap(([n,s])=>s.map(t=>`${n}@${t}`)).sort();function Qt(e,n){let{value:s,problem:t}=ke(e);return t?{hidden:n.hidden,disabled:n.disabled,shown:n.shown??[],unlisted:n.unlisted??[],net:n.net??{},packs:n.packs??{},packsOff:n.packsOff??[],problem:t}:C(s)}var R=null,$e=[],En=(e,n=["gallery"])=>{R=e,$e=[...n]};function en(e=P(),n=D,{on:s=null}={}){let t=Qt(e,n),o=new Map,f=new Map,c=dt(e),d=c.map(({id:l})=>l).filter(l=>$e.includes(l.split("/")[0]));if(R&&d.length>0)try{R(e,d)}catch{}for(let{id:l,folder:p}of c){let h=Wt(l,p);(h.problem?f:o).set(h.id,h)}for(let l of o.keys())f.delete(l);for(let l of t.disabled)!o.has(l)||l===s||(f.set(l,Ht(o.get(l))),o.delete(l));let a=tn(e,c.map(({id:l})=>l.split("/")[0]));return{packages:o,problems:f,settings:t,packs:a,stamp:Xt({packages:o,problems:f,settings:t,packs:a})}}function tn(e,n=[]){let{components:s}=G(e),t=[];try{t=Me(s).filter(f=>he.test(f)&&Ce(k.join(s,f,ne)))}catch{}let o=new Map;for(let f of[...new Set([...n,...t])].sort()){let c=null;try{c=f===it?ot.name:rt(_(k.join(s,f,ne),"utf8")).name}catch{}o.set(f,c)}return o}var N=new Map;function Sn(e=P()){let n=k.resolve(e);return N.has(n)||N.set(n,en(n)),N.get(n)}var xn=(e,n)=>{N.set(k.resolve(e),n)},An=(e=P())=>{N.delete(k.resolve(e))},fe=(e,n)=>tt(e,()=>st(n)),J=e=>({zh:fe("zh",e),en:fe("en",e)}),Nn=({settings:e})=>e.problem?J(e.problem):null,Ee=(e,n)=>e.problem?e.disabled?"disabled":"broken":Ye(e.id,n,e.places),Se=({id:e,match:n,parts:s,runtime:t,schema:o,needs:f,card:c})=>({id:e,match:n,parts:s,...t?{runtime:t}:{},...o!==void 0?{schema:o}:{},...f?.length?{needs:f}:{},...c?.consent?{consent:c.consent}:{}}),jn=({packages:e,problems:n})=>[...[...e.values()].map(Se),...[...n.values()].map(({id:s,problem:t})=>({id:s,problem:J(t)}))],nn=e=>`DocKit.describe(${JSON.stringify(e)});`.replace(/</g,"\\u003c"),K=({id:e,stamp:n},s)=>`/__gallery/components/${e}/${s}?v=${n}`;function sn(e){let n=`${Be}="${e.id}"`,s=t=>e.files.includes(t);return{styles:s("style.css")?[`<link rel="stylesheet" href="${K(e,"style.css")}" ${n}>`]:[],scripts:[`<script ${n}>${nn({...Se(e),...s("kit.js")?{script:!0}:{}})}</script>`,...s("kit.js")?[`<script src="${K(e,"kit.js")}" ${n}></script>`]:[]]}}var zn=({folder:e},n)=>j(e,n),Tn=({folder:e,files:n})=>W(e,V(n));function de(e,n){let s=X(e,{sourceCodeLocationInfo:!0}).childNodes.filter(o=>o.tagName||o.nodeName==="#text"&&o.value.trim()),[t]=s;return s.length===1&&t.tagName&&Re(t)&&Xe(t,pe)===n&&t.sourceCodeLocation.endTag?t:null}function on(e,n){let s=de(e,n),t=s&&H(s),o=t&&de(t,n);return o?{markup:t,root:o}:null}function xe({id:e,template:n,parts:s}){if(!n)return{};let t=on(n,e);if(!t)return{problem:i("template.html \u8981\u662F\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u7684\u4E00\u4E2A\u5B9E\u4F8B\uFF0C\u6709\u81EA\u5DF1\u7684\u7ED3\u675F\u6807\u7B7E\uFF0C\u6B64\u5916\u4EC0\u4E48\u90FD\u6CA1\u6709")};let o=[];if(Qe({childNodes:[t.root]},c=>{qe(c.tagName,c.attrs)&&o.push(c.tagName)}),o.length>0)return{problem:i("template.html \u91CC\u7684 <{0}> \u8FDB\u4E0D\u4E86\u65B0\u5EFA\u7684\u5757\uFF1A\u811A\u672C\u3001\u4E8B\u4EF6\u3001\u6837\u5F0F\u548C Gallery \u81EA\u5DF1\u7684\u6807\u8BB0\u90FD\u4E0D\u5199\u5728\u6A21\u677F\u91CC",o[0])};let f=Object.entries(s).find(([,c])=>{let d=Ue(t.root,c.at).length;return d<(c.optional?0:c.min??1)||d>(c.edit==="flow"?1:c.max??1/0)});return f?{problem:i("template.html \u7684 {0} \u548C\u6E05\u5355\u5199\u7684\u6570\u76EE\u4E0D\u7B26",f[0])}:{markup:t.markup}}var In=e=>xe(e).problem??null,Ae=e=>xe(e).markup??null,vn=({packages:e,settings:n=D,packs:s=new Map})=>[...e.values()].sort(U).map(t=>({id:t.id,version:t.version,name:t.name,description:t.description,words:t.words,definition:t.definition,stamp:t.stamp,template:Ae(t),preview:t.files.includes("preview.svg")?K(t,"preview.svg"):null,state:Ee(t,n),places:t.places,needs:t.needs,settings:t.settings,markdown:t.markdown,assets:t.assets,tags:sn(t),pack:{id:t.id.split("/")[0],name:s.get(t.id.split("/")[0])??null}})),_n=({packages:e,problems:n,settings:s=D})=>[...e.values(),...n.values()].sort(U).map(t=>({id:t.id,pack:t.id.split("/")[0],version:t.version??null,name:t.name??null,description:t.description??null,state:Ee(t,s),reason:t.problem&&!t.off?J(t.problem):null,template:!!Ae(t),places:t.places??null,needs:t.needs??null,hidden:s.hidden.includes(t.id),shown:s.shown.includes(t.id),disabled:s.disabled.includes(t.id),unlisted:(s.unlisted??[]).includes(t.id),allowed:(s.net?.[t.id]??[]).filter(o=>et(t.needs).includes(o)),menu:Je(t.places,{...s,disabled:[],unlisted:[],packsOff:[]},t.id)})),Pn=e=>`settings ${e.hidden.join(",")} ${e.disabled.join(",")} ${e.shown.join(",")} ${Oe(e).join(",")} ${(e.unlisted??[]).join(",")} ${(e.packsOff??[]).join(",")}`;export{$t as a,On as b,$n as c,Xt as d,En as e,en as f,Sn as g,xn as h,An as i,fe as j,Nn as k,jn as l,nn as m,K as n,sn as o,zn as p,Tn as q,on as r,In as s,Ae as t,vn as u,_n as v,Pn as w};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a 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};
2
+ import{a as y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-FX42XU6J.mjs";import{c as P,d as W}from"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.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-UGWMMEJ5.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};
@@ -0,0 +1,22 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as Ee,d as X,f as ae,h as ie,i as Ne,l as oe,p as ve}from"./chunk-LE44MD3O.mjs";import{D as ce}from"./chunk-7XDYK3UC.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-VG5JEIUQ.mjs";import{b as ye,e as mt}from"./chunk-N3DSBH5S.mjs";mt();import{createHash as ht}from"node:crypto";import{cellsOf as gt}from"../browser/shared/card-size.mjs";import{escapeAttribute as de}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as le,hasClass as _e,walk as Te}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as He}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,sr=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),De="gallery-board",Fe="gallery-card",Le=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,He)!==void 0,wt=e=>ht("sha256").update(e.replace(/\r\n?/g,`
3
+ `)).digest("hex").slice(0,16),kt=e=>ye(e.replace(/^/," "),{sourceCodeLocationInfo:!0});function I(e){let n=[];return Te(kt(e),r=>{if(!_e(r,De))return;let i=le(r).filter(s=>_e(s,Fe)&&s.sourceCodeLocation).map(s=>{let a=le(s).find(Le)??null;a||Te(s,O=>{a??=Le(O)?O:null});let h=s.sourceCodeLocation,g={x:N(s,"data-x"),y:N(s,"data-y"),w:N(s,"data-w"),h:N(s,"data-h")};return{id:N(s,"data-card-id")??null,node:s,board:N(r,"data-board-id")??null,...gt({dataset:g}),instance:a,block:a?N(a,He):null,start:h.startOffset,end:h.endOffset,closed:!!h.endTag}});n.push({id:N(r,"data-board-id")??null,node:r,cards:i})},{inTemplates:!1}),{boards:n,cards:n.flatMap(r=>r.cards)}}function Ot(e){let n=new Set(e.map(({id:s})=>s).filter(s=>typeof s=="string"&&q.test(s))),r=new Set,i=1;return e.map(({id:s})=>{if(typeof s=="string"&&q.test(s)&&!r.has(s))return r.add(s),s;for(;n.has(`c${i}`)||r.has(`c${i}`);)i++;let a=`c${i}`;return r.add(a),a})}function fe(e){let n=new Set(e),r=1;for(;n.has(`c${r}`);)r++;return`c${r}`}function ee(e,n,r){let{startTag:i}=n.sourceCodeLocation,s=i.attrs??{},a=[],h=[];for(let[g,O]of Object.entries(r)){let S=s[g];S?(a.push({start:S.startOffset,end:S.endOffset,text:O===null?"":`${g}="${de(String(O))}"`}),O===null&&e[S.startOffset-1]===" "&&(a.at(-1).start-=1)):O!==null&&h.push(` ${g}="${de(String(O))}"`)}if(h.length){let g=s.class?.endOffset??i.startOffset+1+n.tagName.length;a.push({start:g,end:g,text:h.join("")})}return a}function te(e,n){return[...n].sort((r,i)=>i.start-r.start||i.end-r.end).reduce((r,{start:i,end:s,text:a})=>r.slice(0,i)+a+r.slice(s),e)}function W(e){let{cards:n}=I(e),r=Ot(n),i=n.flatMap((s,a)=>s.id===r[a]?[]:ee(e,s.node,{"data-card-id":r[a]}));return{text:i.length?te(e,i):e,filled:n.flatMap((s,a)=>s.id===r[a]?[]:[r[a]])}}var V=(e,n)=>wt(e.slice(n.start,n.end));function Re(e){let n=W(e).text;return I(n).cards.map(r=>({id:r.id,board:r.board,x:r.x,y:r.y,w:r.w,h:r.h,base:V(n,r),block:r.block}))}var Pe=e=>[e.board,...["x","y","w","h"].map(n=>N(e.node,`data-${n}`))].join(",");function Me(e,n){let r=n.node.sourceCodeLocation.startTag.endOffset;return e.slice(n.start,r).replace(/\s+data-[xywh]="[^"]*"/g,"")+e.slice(r,n.end)}function Je(e,n){let[r,i]=[W(e).text,W(n).text],[s,a]=[I(r).cards,I(i).cards],h={};for(let g of s)a.some(O=>O.id===g.id)||(h[g.id]=["removed"]);for(let g of a){let O=s.find(v=>v.id===g.id);if(!O){h[g.id]=["added"];continue}let S=[...Pe(O)!==Pe(g)?["cells"]:[],...Me(r,O)!==Me(i,g)?["content"]:[]];S.length&&(h[g.id]=S)}return h}function Y(e,n){let{cards:r}=I(e),i=r.flatMap(s=>{let a=n.get(s.id);if(!a)return[];let h={};for(let g of["x","y","w","h"])a[g]!==void 0&&N(s.node,`data-${g}`)!==String(a[g])&&(h[`data-${g}`]=a[g]);return Object.keys(h).length?ee(e,s.node,h):[]});return i.length?te(e,i):e}function xt(e,n,r){let i=e.lastIndexOf(`
4
+ `,n-1)+1,s=e.indexOf(`
5
+ `,r),a=s===-1?e.slice(r):e.slice(r,s);return!/^[ \t]*$/.test(e.slice(i,n))||!/^[ \t\r]*$/.test(a)?{from:n,to:r}:{from:i,to:s===-1?e.length:s+1}}function Be(e,n){let r=I(e).cards.find(a=>a.id===n);if(!r)return null;let{from:i,to:s}=xt(e,r.start,r.end);return{text:e.slice(0,i)+e.slice(s),html:e.slice(r.start,r.end)}}var ze=(e,n)=>/^[ \t]*/.exec(e.slice(e.lastIndexOf(`
6
+ `,n-1)+1))[0],$t=(e,n)=>e.replace(/\r?\n/g,r=>`${r}${n}`);function We({id:e,x:n,y:r,w:i,h:s},a,h="",g=`
7
+ `){return`${`<section class="${Fe}" data-card-id="${de(e)}" data-x="${n}" data-y="${r}" data-w="${i}" data-h="${s}">`}${g}${h} ${$t(a.trim().replace(/\r?\n/g,g),`${h} `)}${g}${h}</section>`}function ue(e,n,r){let i=I(e).boards.find(j=>j.id===n);if(!i)return null;let{node:s}=i,a=s.sourceCodeLocation,h=e.includes(`\r
8
+ `)?`\r
9
+ `:`
10
+ `,g=i.cards.at(-1),O=g?ze(e,g.start):`${ze(e,a.startOffset)} `,S=r.match(/\n([ \t]*)<\/[a-z]+>\s*$/)?.[1]??"",v=r.trim().replace(/\r?\n/g,`
11
+ `).split(`
12
+ `).map((j,_)=>_===0||S===O?j:j.startsWith(S)?`${O}${j.slice(S.length)}`:j).join(h);if(a.endTag){let j=a.endTag.startOffset,_=e.lastIndexOf(`
13
+ `,j-1)+1,F=/^[ \t]*$/.test(e.slice(_,j)),T=F?_:j,R=`${F?"":h}${O}${v}${h}`;return{text:e.slice(0,T)+R+e.slice(T),start:T+R.indexOf(v)}}let E=a.endOffset,D=`${h}${O}${v}`;return{text:e.slice(0,E)+D+e.slice(E),start:E+D.indexOf(v)}}function ar(e,{blockOf:n=()=>null}={}){let r=W(e).text,i=[];for(let s of I(r).cards){let a=s.block?n(s.block):null,h={"data-ge-base":V(r,s)};a?.fit==="content"&&(h["data-ge-fit"]="content"),a?.bare&&(h["data-ge-bare"]="");let g=s.block===null?null:a?.state??"missing";if(g&&g!=="page"&&(h["data-ge-state"]=g),i.push(...ee(r,s.node,h)),s.instance&&a&&g!=="page"&&g!=="missing"){let{startOffset:O,endOffset:S}=s.instance.sourceCodeLocation;i.push({start:O,end:O,text:"<template data-ge-held>"},{start:S,end:S,text:"</template>"})}}return te(r,i)}function Ue(e){let n=`<!doctype html><html><head></head><body><div class="${De}">`,r=`${n}${e}</div></body></html>`,[i]=I(r).boards;return{text:r,board:i,from:n.length,to:n.length+e.length}}function Ge(e){let{board:n}=Ue(e);if(!n||n.cards.length!==1)return null;let r=le(n.node).length!==1||n.node.childNodes.some(s=>s.nodeName==="#text"&&s.value.trim()),[i]=n.cards;return r||!i.closed||!i.instance||i.instance.parentNode!==i.node?null:i}function Ke(e,{id:n,x:r,y:i,w:s,h:a}){let{text:h,board:g,from:O,to:S}=Ue(e),v={"data-card-id":n,"data-x":r,"data-y":i,"data-w":s,"data-h":a},E=ee(h,g.cards[0].node,v),D=E.reduce((j,{start:_,end:F,text:T})=>j+T.length-(F-_),0);return te(h,E).slice(O,S+D)}import{readFileSync as pe}from"node:fs";import z from"node:fs/promises";import H from"node:path";import{refusedInCopy as Ve}from"../browser/shared/components/installed.mjs";import{writeAtomic as Ye}from"../browser/shared/files.mjs";import{sendJson as re}from"../browser/shared/http.mjs";import{jsonIn as bt}from"../browser/shared/json-layout.mjs";import{defaultSize as me,freeSpot as St,onBoard as he,pushDown as ge,settle as yt,sizeFor as Ze}from"../browser/shared/board-places.mjs";import{FIRST_BOARD as Qe,HOME_CARDS as Ct,HOME_SIZES as It,pageExists as we,pageFiles as jt,pageVersion as Xe,tellHomeCards as qe}from"../browser/shared/pages.mjs";import{OWN_SCOPE as At,PACK_FILE as Et,readPackManifest as Nt}from"../browser/shared/pack-manifest.mjs";import{packsDirectory as vt}from"../browser/shared/paths.mjs";import{sameDirectory as _t}from"../browser/shared/preview-server.mjs";import{walk as Tt}from"../browser/shared/html-tree.mjs";import{closePageHint as Lt,pageDefaults as Pt}from"../browser/shared/pages.mjs";var Mt=20,ke="writes.jsonl",zt=200;async function Ar(e,n,r){return(await z.readFile(H.join(e,"pages",n,ke),"utf8").catch(()=>"")).split(`
14
+ `).flatMap(s=>{try{let a=JSON.parse(s);return a&&typeof a.at=="number"&&a.at>=r&&a.cards&&typeof a.cards=="object"?[a]:[]}catch{return[]}})}var Ht=["place","arrange","add","remove","edit","settings","restore-defaults"],U=e=>Number.isInteger(e)&&e>=0,ne=e=>Number.isInteger(e)&&e>=1,Dt=/^\d{4}-\d{2}-\d{2}$/,x=(e,n,r)=>[e,{ok:!1,reason:n,...r?{message:r}:{}}];function Ft(e,n){return typeof e=="string"?e.replace(new RegExp(`(^|[\\s"'(,=])/pages/${n}/assets/`,"g"),"$1assets/"):e}var et=e=>[409,{ok:!1,refused:e}];function Er(e,n){let r=e.packages.get(n);return r?{state:r.places.includes("page")?"page":"document",card:r.card,settings:r.settings,places:r.places,fit:r.card.fit,bare:r.card.bare,name:r.name,parts:Object.fromEntries(Object.entries(r.parts).filter(([,i])=>i.edit==="data").map(([i,s])=>[i,s.at]))}:e.settings.disabled.includes(n)&&e.problems.has(n)?{state:"disabled",card:null,settings:[],places:[],fit:"fixed",bare:!1,name:null,parts:{}}:null}function Rt(e,{type:n,options:r}){return n==="text"||n==="document"?typeof e=="string"&&e.length<=1e4:n==="number"?typeof e=="number"&&Number.isFinite(e)||e===null:n==="select"?r.includes(e):n==="date"?e===""||typeof e=="string"&&Dt.test(e):n==="switch"?typeof e=="boolean":!1}function tt(e,{x:n,y:r,w:i,h:s}){let a={x:e.x??n,y:e.y??r,w:e.w??i,h:e.h??s};return U(a.x)&&U(a.y)&&ne(a.w)&&ne(a.h)?a:null}function rt({root:e,edits:n,stateDirectory:r,catalog:i=()=>Ie(e),catalogTaken:s=()=>{},shipped:a=void 0,log:h=()=>{},shown:g=O=>O}){let O=0;async function S(f,t){let o=H.join(r,"pages",f);await z.mkdir(o,{recursive:!0}),O=(O+1)%1e4,await z.writeFile(H.join(o,`${String(Date.now()).padStart(15,"0")}-${String(O).padStart(4,"0")}.html`),t);let d=(await z.readdir(o)).filter(p=>/^\d{15}-\d{4}\.html$/.test(p)).sort();for(let p of d.slice(0,Math.max(0,d.length-Mt)))await z.rm(H.join(o,p),{force:!0})}async function v(f,t){let o=H.join(r,"pages",f,ke);try{let d=(await z.readFile(o,"utf8").catch(()=>"")).split(`
15
+ `).filter(Boolean);d.push(JSON.stringify({at:Date.now(),...t})),await Ye(o,`${d.slice(-zt).join(`
16
+ `)}
17
+ `)}catch(d){h(`the write of ${f}'s page.html could not be told in ${ke}: ${d.message}`)}}function E(f,t){if(typeof t.card!="string")return{error:x(400,"card")};let o=I(f).cards.find(d=>d.id===t.card);return o?typeof t.base!="string"||V(f,o)!==t.base?{error:et("changed")}:{card:o}:{error:et("gone")}}let D=(f,t)=>I(f).cards.filter(o=>o.board===t).map(({id:o,x:d,y:p,w:l,h:u})=>({id:o,x:d,y:p,w:l,h:u})),j=(f,t)=>new Map(t.filter(o=>{let d=f.find(p=>p.id===o.id);return!d||d.x!==o.x||d.y!==o.y||d.w!==o.w||d.h!==o.h}).map(o=>[o.id,o])),_=(f,t,o)=>ce.installed.dataOf(f,t.instance,o)??{};function F(f,t,o,d){if(!t.instance||!d.has(t.block))return{error:x(409,"block")};let p=_(f,t,d),l=ce.installed.rewrite(f,t.instance,o,{packages:d});if(!l)return{error:x(400,"part")};let u=[...l].sort((m,k)=>k.start-m.start).reduce((m,{start:k,end:$,text:c})=>m.slice(0,k)+c+m.slice($),f),w=_(u,I(u).cards.find(m=>m.id===t.id),d);return{text:u,parts:Object.fromEntries(Object.keys(o).map(m=>[m,{was:p[m]??"",now:w[m]??""}]))}}function T(f,t){return Object.fromEntries(Object.entries(f).map(([o,{was:d,now:p}])=>[o,{was:g(d,t),now:g(p,t)}]))}let R={place(f,t,{packages:o}){let{card:d,error:p}=E(f,t);if(p)return{error:p};let l=tt(t,d);if(!l)return{error:x(400,"cells")};let u=o.get(d.block);if(l.w!==d.w||l.h!==d.h){let m=u&&!u.card.sizes&&u.card.h===null&&l.w===d.w;if(u&&!u.card.resize&&!m)return{error:x(409,"resize")};u&&!m&&(l={...l,...Ze(u.card,l)})}let w=D(f,d.board);return{text:Y(f,j(w,ge(w,{id:d.id,...l})))}},arrange(f,t){if(!Array.isArray(t.cards)||t.cards.length===0)return{error:x(400,"cards")};let o=[];for(let p of t.cards){let{card:l,error:u}=E(f,p??{});if(u)return{error:u};let w=tt(p,l);if(!w)return{error:x(400,"cells")};o.push({card:l,cells:he(w)})}let d=f;for(let p of new Set(o.map(({card:l})=>l.board))){let l=D(d,p),u=o.filter(({card:m})=>m.board===p),w=l.map(m=>({...m,...u.find(({card:k})=>k.id===m.id)?.cells??{}}));d=Y(d,j(l,yt(w,u.map(({card:m})=>m.id))))}return{text:d}},async add(f,t,o){let{boards:d,cards:p}=I(f);if(t.html!==void 0)return ct(f,t,{boards:d,cards:p});if(typeof t.block!="string")return{error:x(400,"block")};let l=typeof t.board=="string"?d.find(y=>y.id===t.board):d.find(y=>y.id===Qe)??d[0];if(!l)return{error:x(409,"board")};ae(t.block,a)&&oe(e,{ids:[t.block],directory:a,log:h}).updated.length>0&&(s(),o.refresh());let u=o.packages.get(t.block),w=o.catalog.settings.disabled.includes(t.block);if(!u&&!w&&!o.catalog.problems.has(t.block)&&ae(t.block,a)){let y=X(a).find(({id:K})=>K===t.block);y&&y.places.includes("page")&&!ie(e,y).added&&(Ne(e,y),h(`${t.block} added to the workspace for a card of a custom page`),s(),o.refresh(),u=o.packages.get(t.block))}if(!u)return{error:x(409,o.catalog.settings.disabled.includes(t.block)?"disabled":"missing")};if(!u.places.includes("page"))return{error:x(409,"places")};let m=Ae(u);if(!m)return{error:x(409,"template")};if(t.w!==void 0&&!ne(t.w)||t.h!==void 0&&!ne(t.h))return{error:x(400,"cells")};let k=me(u.card),$=t.w!==void 0||t.h!==void 0?Ze(u.card,{w:t.w??k.w,h:t.h??k.h}):k,c=l.cards.map(({id:y,x:K,y:ft,w:ut,h:pt})=>({id:y,x:K,y:ft,w:ut,h:pt})),b=t.x!==void 0||t.y!==void 0?{x:t.x??0,y:t.y??0}:St(c,$);if(!U(b.x)||!U(b.y))return{error:x(400,"cells")};let C=fe(p.map(y=>y.id)),L=he({...b,w:$.w,h:$.h}),J=f.includes(`\r
18
+ `)?`\r
19
+ `:`
20
+ `,A=We({id:C,...L},m,"",J),G=ue(f,l.id,A),Z=j(c,ge(c,{id:C,...L}).filter(y=>y.id!==C)),P=Y(G.text,Z),B=I(P).cards.find(y=>y.id===C);if(t.settings!==void 0){let y=R.settings(P,{card:C,base:V(P,B),values:t.settings},o);if(y.error)return y;P=y.text,B=I(P).cards.find(K=>K.id===C)}return{text:P,extra:{card:C,html:P.slice(B.start,B.end),measure:k.measured&&t.h===void 0,pushed:[...Z.keys()]}}},remove(f,t){let{card:o,error:d}=E(f,t);if(d)return{error:d};let{text:p,html:l}=Be(f,o.id);return{text:p,extra:{removed:{id:o.id,board:o.board,html:l}}}},edit(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=t.parts!==void 0?t.parts:typeof t.part=="string"?{[t.part]:t.html}:null;if(!u||typeof u!="object"||Array.isArray(u)||Object.keys(u).length===0)return{error:x(400,"part")};let w=Object.fromEntries(Object.entries(u).map(([k,$])=>[k,Ft($,d)])),m=F(f,p,w,o);return m.error?m:{text:m.text,extra:{parts:T(m.parts,d)}}},settings(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=o.get(p.block),w=u?.settings??[];if(!u||w.length===0)return{error:x(409,"settings")};let m=t.values;if(!m||typeof m!="object"||Array.isArray(m))return{error:x(400,"values")};for(let[L,J]of Object.entries(m)){let A=w.find(G=>G.key===L);if(!A||!Rt(J,A))return{error:x(400,"values",L)}}let k=_(f,p,o)[Q];if(k===void 0)return{error:x(409,"settings")};let $={};try{$=k.trim()?JSON.parse(k):{}}catch{$={}}(!$||typeof $!="object"||Array.isArray($))&&($={});let c={...$,...m};if(JSON.stringify(c)===JSON.stringify($))return{text:f,extra:{parts:T({[Q]:{was:k,now:k}},d)}};let b=k.trim()?bt(k,c):JSON.stringify(c),C=F(f,p,{[Q]:b},o);return C.error?C:{text:C.text,extra:{parts:T(C.parts,d)}}},async"restore-defaults"(f,t,o){if(!Pt(o.slug,e))return{error:x(409,"defaults")};let d=new Set(I(f).cards.map(w=>w.block)),p=f,l=[],u=[];for(let w of Ct){if(d.has(w))continue;let[m,k]=It[w]??[],$=await R.add(p,{op:"add",block:w,...m?{w:m,h:k}:{}},o),c=o.packages.get(w)?.name??X(a).find(({id:b})=>b===w)?.title??null;if($.error){u.push({block:w,reason:$.error[1].reason,name:c});continue}p=$.text,l.push({card:$.extra.card,block:w,html:$.extra.html,name:c})}return{text:p,extra:{added:l,skipped:u}}}};function ct(f,t,{boards:o,cards:d}){if(typeof t.html!="string"||t.html.length>11e5)return{error:x(400,"html")};let p=t.html.trim(),l=Ge(p);if(!l)return{error:x(400,"html")};let u=Ve(l.node.tagName,l.node.attrs??[]);if(Tt(l.node,A=>{u||=Ve(A.tagName,A.attrs??[])}),u)return{error:x(400,"html")};let w=o.find(A=>A.id===(typeof t.board=="string"?t.board:Qe))??o[0];if(!w)return{error:x(409,"board")};if(t.x!==void 0&&!U(t.x)||t.y!==void 0&&!U(t.y))return{error:x(400,"cells")};let m=d.map(A=>A.id),k=l.id&&!m.includes(l.id)&&q.test(l.id)?l.id:fe(m),$=he({x:t.x??l.x,y:t.y??l.y,w:l.w,h:l.h}),c=w.cards.map(({id:A,x:G,y:Z,w:P,h:B})=>({id:A,x:G,y:Z,w:P,h:B})),b=ue(f,w.id,Ke(p,{id:k,...$})),C=j(c,ge(c,{id:k,...$}).filter(A=>A.id!==k)),L=Y(b.text,C),J=I(L).cards.find(A=>A.id===k);return{text:L,extra:{card:k,html:L.slice(J.start,J.end),pushed:[...C.keys()]}}}async function be(f,t,{by:o}={}){if(!t||typeof t!="object"||!Ht.includes(t.op))return x(400,"op");if(t.workspace!==void 0&&(typeof t.workspace!="string"||!_t(t.workspace,e)))return x(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");if(!we(f,e))return x(404,"missing");let d=jt(f,e);for(let p=0;p<3;p++){let[l,u]=await Promise.all([z.readFile(d.html,"utf8").catch(()=>null),z.readFile(d.json,"utf8").catch(()=>"")]);if(l===null)return x(404,"missing");if(Buffer.byteLength(l)>1e6)return x(413,"size");let w=Xe(l,u),m=W(l).text,k=i(),$={slug:f,get catalog(){return k},get packages(){return k.packages},refresh:()=>{k=i()}},c=await R[t.op](m,t,$);if(c.error)return c.error;let b=c.text;if(Buffer.byteLength(b)>1e6)return x(413,"size");if(b!==l){if(await S(f,l),!await Ye(d.html,b,{expect:l}))continue;await v(f,{op:t.op,by:o==="gallery"?"gallery":t.agent===!0?"agent":"page",cards:Je(l,b)})}return t.op==="restore-defaults"&&await qe(e).catch(()=>{}),[200,{ok:!0,version:Xe(b,u),before:w,cards:Re(b),...c.extra??{}}]}return x(409,"busy")}function Se(f="zh"){oe(e,{directory:a,log:h}).updated.length>0&&s();let t=i(),o=[...t.settings.packsOff??[],...ve(e,t.settings.packs)],d=c=>c.split("/")[0],p=c=>!t.settings.unlisted.includes(c)&&!o.includes(d(c)),l=c=>t.packs?.get(d(c))??u(d(c)),u=c=>{try{return Nt(pe(H.join(a??vt,c,Et),"utf8")).name}catch{return null}},w=[...t.packages.values()].filter(c=>c.places.includes("page")&&p(c.id)).map(c=>({id:c.id,name:c.name,description:c.description,preview:c.files.includes("preview.svg")?je(c,"preview.svg"):null,size:me(c.card),installed:!0,settings:c.settings.length>0,pack:{id:d(c.id),name:l(c.id)}}));for(let c of X(a)){if(!c.places.includes("page")||t.packages.has(c.id)||t.problems.has(c.id)||t.settings.disabled.includes(c.id)||!p(c.id)||ie(e,c).added)continue;let b=null;try{b=`data:image/svg+xml;base64,${pe(H.join(c.folder,"preview.svg")).toString("base64")}`}catch{}let C=null;try{C=JSON.parse(pe(H.join(c.folder,"component.json"),"utf8")).card??null}catch{}w.push({id:c.id,name:c.title,description:c.description,preview:b,size:me(C),installed:!1,settings:!1,pack:{id:c.pack,name:l(c.id)}})}let m=c=>c.name?.[f]??c.name?.zh??c.id,k=Ee(a),$=({pack:c})=>c.id===At?-1:k.includes(c.id)?k.indexOf(c.id):k.length;return w.sort((c,b)=>$(c)-$(b)||(c.pack.id===b.pack.id?0:c.pack.id<b.pack.id?-1:1)||m(c).localeCompare(m(b),"zh-CN")||(c.id<b.id?-1:1))}async function dt(f,t){return we(f,e)?(t?.cards===!0?await qe(e):await Lt(e,f),[200,{ok:!0}]):x(404,"missing")}function lt(f,t,o,d){if((d==="cards"||d==="hint")&&f.method==="POST")return n.respond(async l=>{let u=await n.check(l);return u.error?u.error:d==="hint"?dt(o,u.body):be(o,u.body)})(f,t);if(d==="library"&&f.method==="GET"){let l=f.headers.host??"",u=f.socket.localPort;if(l!==`127.0.0.1:${u}`&&l!==`localhost:${u}`)return re(t,403,{ok:!1,reason:"host"});if(!we(o,e))return re(t,404,{ok:!1,reason:"missing"});let w=new URL(f.url??"/","http://localhost").searchParams.get("language")==="en"?"en":"zh";return re(t,200,{ok:!0,blocks:Se(w)})}let p=["cards","library","hint"].includes(d);return re(t,p?405:404,{ok:!1,reason:p?"method":"unknown"})}return{handle:lt,apply:be,library:Se}}import{readFileSync as ot}from"node:fs";import{writeAtomic as nt}from"../browser/shared/files.mjs";import{HOME as M,HOME_TITLE as Jt,createPage as Bt,hintOf as st,markHomeMade as at,pageExists as Oe,pageFiles as xe,pageSlugRefused as Wt,pagesSettings as Ut,writeHints as se}from"../browser/shared/pages.mjs";import{layoutOf as it,markerOf as Gt}from"../browser/shared/workspace.mjs";import{lineIconValue as Kt}from"../browser/shared/emoji/line-icons.mjs";var Vt="GALLERY_NO_DEFAULT_HOME",$e=Kt("house"),Yt="/icons/home-1_lightgray.svg",Zt=(e=process.env)=>!["","0","false",void 0].includes(e[Vt]);async function Hr(e,{shipped:n=void 0,stateDirectory:r=it(e).state,env:i=process.env}={}){if(Zt(i))return{did:"off"};let s={ours:!1};try{s=Gt(ot(it(e).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread"};if(Ut(e).homeMade)return await Qt(e).catch(()=>{}),{did:"done"};let a="mark";try{if(Oe(M,e))return await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"kept"};a="page";let h=await Wt(M,e);if(h)return{did:"taken",why:h};await Bt(M,Jt,{root:e,icon:$e,defaultCards:!0,hint:!0}),a="cards";let g=rt({root:e,edits:null,stateDirectory:r,catalog:()=>Ce(e),shipped:n}),[,O]=await g.apply(M,{op:"restore-defaults"},{by:"gallery"});return a="mark",await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"made",file:xe(M,e).html,cards:(O.added??[]).map(({card:S})=>S),skipped:O.skipped??[]}}catch(h){return{did:"failed",stage:a,file:Oe(M,e)?xe(M,e).html:null,why:h?.message??String(h)}}}async function Qt(e){let n=!1,r=()=>{if(!Oe(M,e))return null;let{json:i}=xe(M,e);try{let s=ot(i,"utf8"),a=JSON.parse(s.replace(/^/,""));return a&&typeof a=="object"&&!Array.isArray(a)?{json:i,text:s,value:a}:null}catch{return null}};if(st(e,"homeAdopted")!==!0){let i=r();if(i&&!("defaultCards"in i.value)&&!("hint"in i.value)){let s={...i.value,...i.value.icon?{}:{icon:$e},defaultCards:!0,hint:!0};n=await nt(i.json,`${JSON.stringify(s,null,2)}
21
+ `,{expect:i.text})}await se(e,{homeAdopted:!0})}if(st(e,"homeLineIcon")!==!0){let i=r();i?.value.icon===Yt&&(n=await nt(i.json,`${JSON.stringify({...i.value,icon:$e},null,2)}
22
+ `,{expect:i.text})||n),await se(e,{homeLineIcon:!0})}return n}function Dr({stage:e,file:n,why:r}){return e==="mark"?`The default home page ${n} is there, but gallery.json could not say it was made (${r}); a later start tries again.`:e==="cards"?`The default home page ${n} was made without its cards (${r}): \u6062\u590D\u9ED8\u8BA4\u5361\u7247 in its menu in the sidebar puts them on.`:`The default home page was not made (${r}); a later start tries again.`}export{q as a,I as b,W as c,Me as d,ar as e,Ar as f,Er as g,rt as h,Zt as i,Hr as j,Dr as k};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as Q}from"./chunk-ZB4H7ZN4.mjs";import{c as _,d as z,e as B,l as G}from"./chunk-NFMCP2HI.mjs";import"./chunk-KTKHRC6H.mjs";import"./chunk-YI43RG4P.mjs";import{i as q}from"./chunk-NAMN3RAF.mjs";import{a as b,b as J}from"./chunk-JEUK3ZO7.mjs";import{a as Z}from"./chunk-B4P2CM2J.mjs";import{a as ee}from"./chunk-VJPFVNNW.mjs";import"./chunk-PZDLJJTJ.mjs";import"./chunk-IA4PSIMD.mjs";import{c as V,d as Y,e as M}from"./chunk-D4CKRD3V.mjs";import"./chunk-UKSHDZZ6.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import{b as W,h as X}from"./chunk-SXHBYZST.mjs";import"./chunk-RKPWLGZ3.mjs";import"./chunk-N7AZZLGT.mjs";import{b as T,f as C,g as H}from"./chunk-4OZWXZE5.mjs";import"./chunk-ZTHICSSF.mjs";import{k as U}from"./chunk-SX4LJYT6.mjs";import{b as K}from"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import v from"node:fs/promises";import se from"node:os";import x from"node:path";import{IMPORT_EXT as re,kindOf as ie}from"../browser/shared/import-types.mjs";import{reportsDirectory as O}from"../browser/shared/paths.mjs";import{kebab as S}from"../browser/shared/web-links.mjs";import{documentDirectory as oe,documentFiles as E,newDocSlug as ae}from"../browser/shared/workspace.mjs";var ce=Object.values(re).flat().join(" "),j=(d,g)=>`${d} ${g}${d===1?"":"s"}`;function fe(d,g,p){let n=(f,r=g)=>(r.match(f)??[]).length,c=n(/<ol class="doc-flow"/g,p),$=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[c,"flow"],[$,"footnote"]].filter(([f])=>f>0).map(([f,r])=>j(f,r)),h=(d.raws?.length??0)-c-($?1:0);return h>0&&w.push(`${j(h,"HTML block")} kept as written`),w}async function Se(d){let{positional:g,options:p}=C({options:["--no-preview","--no-browser"],argv:d}),[n,c,$]=g;if(g.length<1||g.length>3||!n)throw new T("Name the file; then the slug and the title, if you choose them.");let w=ie(n);if(!w)throw new T(`Not a kind of file gallery import takes: ${n} (${ce}).`);c!==void 0&&H(c);let h=x.resolve(n);await v.stat(h).then(i=>i.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let f=c!==void 0?await Q(c):null;f&&(console.error(f),process.exit(1));let r=x.basename(h),F=await v.mkdtemp(x.join(se.tmpdir(),"gallery-import-")),L,y,R;try{let i,u=[];if(w==="markdown")i=[{...await Y(h,F),from:r,children:[]}];else try{({pages:i,skipped:u}=await V([{file:h,name:r}],F))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}i.length===0&&(console.error(`Nothing in ${r} could be read as a page${u.length?` (not taken: ${u.join(", ")})`:""}.`),process.exit(1)),$?.trim()&&(i[0]={...i[0],title:$.replace(/\s+/g," ").trim()});let I=new Map,te=ee({edits:{},reports:{},reportsDirectory:O});y=(await Z(i,{create:async(e,t,l,{lang:s})=>{let{directory:o}=await K(e,t,l,{blank:!0,lang:s});I.set(e,await v.readFile(E(o).html,"utf8"))},slugOf:(e,t)=>{if(t===0&&c!==void 0)return c;let l=S(e.title)||S(e.from?.replace(/\.[^.]+$/,"")??"")||S(r.replace(/\.[^.]+$/,""));return l?te.freeSlug(l):ae(O)},folderOf:e=>oe(e,O),fill:e=>M(e),place:(e,t)=>q(e,{parent:t})})).made;let P=[],A=(e,t)=>{P.push({page:e,depth:t});for(let l of e.children??[])A(l,t+1)};for(let e of i)A(e,0);let m=await Promise.all(P.map(async({page:e,depth:t},l)=>{let s=y[l],o=oe(s,O),a=E(o).html,k=await v.readFile(a,"utf8"),ne=(await M({source:I.get(s),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),le=X(W(k,{finish:U}).text);return{slug:s,depth:t,page:e,directory:o,htmlFile:a,made:fe(e,ne,k),readOnly:le}}));if(L={slug:y[0]},m.length===1){let[{page:e,directory:t,htmlFile:l,made:s,readOnly:o}]=m;if(console.log(`Created ${b(l)} and ${x.basename(E(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${s.length?s.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let a of e.notes)console.log(` ${a.line?`line ${a.line}: `:""}${a.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let a of o)console.log(` ${a}`)}}else{console.log(`Created ${j(m.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:l,depth:s,page:o,htmlFile:a,made:k}of m)console.log(`${" ".repeat(s+1)}${l} ${o.title} ${b(a)}`),console.log(`${" ".repeat(s+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=m.flatMap(({slug:l,page:s})=>(s.notes??[]).map(o=>` ${l}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
2
+ import{b as Q}from"./chunk-7N2LPG33.mjs";import{c as _,d as z,e as B,l as G}from"./chunk-JJNRIFND.mjs";import"./chunk-ASAXY2DJ.mjs";import"./chunk-HBAUKKQH.mjs";import{i as q}from"./chunk-YPPJVDQI.mjs";import{a as b,b as J}from"./chunk-JEUK3ZO7.mjs";import{a as Z}from"./chunk-CZ5KJSGK.mjs";import{a as ee}from"./chunk-UGO5N3EI.mjs";import"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import{c as V,d as Y,e as M}from"./chunk-NFABH3QW.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import{b as W,h as X}from"./chunk-WTEGUPFG.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import{b as T,f as C,g as H}from"./chunk-4OZWXZE5.mjs";import"./chunk-KH24LWAT.mjs";import{k as U}from"./chunk-YFJU3O7G.mjs";import{b as K}from"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import v from"node:fs/promises";import se from"node:os";import x from"node:path";import{IMPORT_EXT as re,kindOf as ie}from"../browser/shared/import-types.mjs";import{reportsDirectory as O}from"../browser/shared/paths.mjs";import{kebab as S}from"../browser/shared/web-links.mjs";import{documentDirectory as oe,documentFiles as E,newDocSlug as ae}from"../browser/shared/workspace.mjs";var ce=Object.values(re).flat().join(" "),j=(d,g)=>`${d} ${g}${d===1?"":"s"}`;function fe(d,g,p){let n=(f,r=g)=>(r.match(f)??[]).length,c=n(/<ol class="doc-flow"/g,p),$=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[c,"flow"],[$,"footnote"]].filter(([f])=>f>0).map(([f,r])=>j(f,r)),h=(d.raws?.length??0)-c-($?1:0);return h>0&&w.push(`${j(h,"HTML block")} kept as written`),w}async function Se(d){let{positional:g,options:p}=C({options:["--no-preview","--no-browser"],argv:d}),[n,c,$]=g;if(g.length<1||g.length>3||!n)throw new T("Name the file; then the slug and the title, if you choose them.");let w=ie(n);if(!w)throw new T(`Not a kind of file gallery import takes: ${n} (${ce}).`);c!==void 0&&H(c);let h=x.resolve(n);await v.stat(h).then(i=>i.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let f=c!==void 0?await Q(c):null;f&&(console.error(f),process.exit(1));let r=x.basename(h),F=await v.mkdtemp(x.join(se.tmpdir(),"gallery-import-")),L,y,R;try{let i,u=[];if(w==="markdown")i=[{...await Y(h,F),from:r,children:[]}];else try{({pages:i,skipped:u}=await V([{file:h,name:r}],F))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}i.length===0&&(console.error(`Nothing in ${r} could be read as a page${u.length?` (not taken: ${u.join(", ")})`:""}.`),process.exit(1)),$?.trim()&&(i[0]={...i[0],title:$.replace(/\s+/g," ").trim()});let I=new Map,te=ee({edits:{},reports:{},reportsDirectory:O});y=(await Z(i,{create:async(e,t,l,{lang:s})=>{let{directory:o}=await K(e,t,l,{blank:!0,lang:s});I.set(e,await v.readFile(E(o).html,"utf8"))},slugOf:(e,t)=>{if(t===0&&c!==void 0)return c;let l=S(e.title)||S(e.from?.replace(/\.[^.]+$/,"")??"")||S(r.replace(/\.[^.]+$/,""));return l?te.freeSlug(l):ae(O)},folderOf:e=>oe(e,O),fill:e=>M(e),place:(e,t)=>q(e,{parent:t})})).made;let P=[],A=(e,t)=>{P.push({page:e,depth:t});for(let l of e.children??[])A(l,t+1)};for(let e of i)A(e,0);let m=await Promise.all(P.map(async({page:e,depth:t},l)=>{let s=y[l],o=oe(s,O),a=E(o).html,k=await v.readFile(a,"utf8"),ne=(await M({source:I.get(s),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),le=X(W(k,{finish:U}).text);return{slug:s,depth:t,page:e,directory:o,htmlFile:a,made:fe(e,ne,k),readOnly:le}}));if(L={slug:y[0]},m.length===1){let[{page:e,directory:t,htmlFile:l,made:s,readOnly:o}]=m;if(console.log(`Created ${b(l)} and ${x.basename(E(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${s.length?s.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let a of e.notes)console.log(` ${a.line?`line ${a.line}: `:""}${a.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let a of o)console.log(` ${a}`)}}else{console.log(`Created ${j(m.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:l,depth:s,page:o,htmlFile:a,made:k}of m)console.log(`${" ".repeat(s+1)}${l} ${o.title} ${b(a)}`),console.log(`${" ".repeat(s+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=m.flatMap(({slug:l,page:s})=>(s.notes??[]).map(o=>` ${l}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
3
3
  ${e.join(`
4
4
  `)}`);let t=m.flatMap(({slug:l,readOnly:s})=>s.map(o=>` ${l}: ${o}`));t.length&&console.log(`Text the preview leaves read-only (${t.length}), by doc.html's lines as gallery check gives them:
5
5
  ${t.join(`
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a}from"./chunk-MAFIGVXY.mjs";import"./chunk-742D2WWJ.mjs";import"./chunk-5L7RYZCL.mjs";export{a as convertPuppeteerChannelToBrowsersChannel};
2
+ import{a}from"./chunk-HM4E43VM.mjs";import"./chunk-36FIRJIF.mjs";import"./chunk-5L7RYZCL.mjs";export{a as convertPuppeteerChannelToBrowsersChannel};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as R}from"./chunk-MHW7ZKOU.mjs";import{b as I,c as B}from"./chunk-342HXE3Q.mjs";import{a as f,b as F,c as L,d as M}from"./chunk-BPL64HGA.mjs";import{a as S,b as k,g as $}from"./chunk-OUUP3WKT.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import{b as D}from"./chunk-PZDLJJTJ.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import{b as v}from"./chunk-SXHBYZST.mjs";import{j as d}from"./chunk-4OZWXZE5.mjs";import{k as w,q as h,t as g,u as y,v as x}from"./chunk-HMYTM3GT.mjs";import"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import O from"node:fs/promises";import{reportsDirectory as P}from"../browser/shared/paths.mjs";import{documentDirectory as U,documentFiles as q,layoutOf as z}from"../browser/shared/workspace.mjs";function C(s=P){let n=D({root:s,read:async a=>{let o=await O.readFile(q(U(a,s)).html,"utf8").catch(()=>null);return o===null?null:{source:o,text:v(o).text}},activity:N({file:z(s).activity})});return a=>n.snapshot(a)}async function te(s){let{slugs:t,options:n}=await d({options:["--allow-failures"],argv:s});t.length===0&&(console.error(R()),process.exit(1));let a=await b(t),o=await w(t,{prepare:f({say:!1})}),r=await S(t.filter(e=>!o.has(e)));await k(t.filter(e=>o.has(e)||r.failures.has(e))),await L(t),await M(t);let m=t.filter(e=>!o.has(e)&&!r.failures.has(e)),{built:l,exported:p,failures:c}=m.length>0?await h(m,{prepare:f({say:!1}),workspace:C()}):{built:[],exported:[],failures:new Map};for(let[e,i]of[...o,...r.failures])c.set(e,i);await y(c,{exportNote:!0}),await a.keep(p.map(({slug:e})=>e));let A=new Map(l.map(({report:e,removed:i})=>[e.slug,i]));for(let{slug:e,bytes:i,sha256:j}of p){let u=A.get(e),E=u.length>0?`; shared scripts and styles left out (unused): ${u.join(", ")}`:"";console.log(`Exported ${I(e)} (${i.toLocaleString("en-US")} bytes, sha256 ${j})${E}`)}g(l.map(({report:e})=>e)),F(l.map(({report:e})=>e));for(let e of r.lines)console.log(e);r.written.length>0&&console.log($(r.written));for(let{slug:e}of p)console.log(B(e));x(c,{above:!0,allow:n.has("--allow-failures")})}export{te as run};
2
+ import{a as R}from"./chunk-DKR7LFIY.mjs";import{b as I,c as B}from"./chunk-342HXE3Q.mjs";import{a as f,b as F,c as L,d as M}from"./chunk-3A5I2GJK.mjs";import{a as S,b as k,g as $}from"./chunk-XQRUG4G3.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import{b as D}from"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import{b as v}from"./chunk-WTEGUPFG.mjs";import{j as d}from"./chunk-4OZWXZE5.mjs";import{k as w,q as h,t as g,u as y,v as x}from"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import O from"node:fs/promises";import{reportsDirectory as P}from"../browser/shared/paths.mjs";import{documentDirectory as U,documentFiles as q,layoutOf as z}from"../browser/shared/workspace.mjs";function C(s=P){let n=D({root:s,read:async a=>{let o=await O.readFile(q(U(a,s)).html,"utf8").catch(()=>null);return o===null?null:{source:o,text:v(o).text}},activity:N({file:z(s).activity})});return a=>n.snapshot(a)}async function te(s){let{slugs:t,options:n}=await d({options:["--allow-failures"],argv:s});t.length===0&&(console.error(R()),process.exit(1));let a=await b(t),o=await w(t,{prepare:f({say:!1})}),r=await S(t.filter(e=>!o.has(e)));await k(t.filter(e=>o.has(e)||r.failures.has(e))),await L(t),await M(t);let m=t.filter(e=>!o.has(e)&&!r.failures.has(e)),{built:l,exported:p,failures:c}=m.length>0?await h(m,{prepare:f({say:!1}),workspace:C()}):{built:[],exported:[],failures:new Map};for(let[e,i]of[...o,...r.failures])c.set(e,i);await y(c,{exportNote:!0}),await a.keep(p.map(({slug:e})=>e));let A=new Map(l.map(({report:e,removed:i})=>[e.slug,i]));for(let{slug:e,bytes:i,sha256:j}of p){let u=A.get(e),E=u.length>0?`; shared scripts and styles left out (unused): ${u.join(", ")}`:"";console.log(`Exported ${I(e)} (${i.toLocaleString("en-US")} bytes, sha256 ${j})${E}`)}g(l.map(({report:e})=>e)),F(l.map(({report:e})=>e));for(let e of r.lines)console.log(e);r.written.length>0&&console.log($(r.written));for(let{slug:e}of p)console.log(B(e));x(c,{above:!0,allow:n.has("--allow-failures")})}export{te as run};