@heycys/gallery 0.1.1 → 0.2.0

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 (473) 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/columns/page.mjs +4 -4
  5. package/browser/editor/components/embed/index.mjs +2 -2
  6. package/browser/editor/components/embed/page.mjs +1 -1
  7. package/browser/editor/components/file/page.mjs +4 -4
  8. package/browser/editor/components/flowchart/add.mjs +7 -6
  9. package/browser/editor/components/flowchart/page.mjs +1 -1
  10. package/browser/editor/components/heading/index.mjs +7 -6
  11. package/browser/editor/components/icons.mjs +11 -0
  12. package/browser/editor/components/image/crop.mjs +6 -9
  13. package/browser/editor/components/image/index.mjs +2 -0
  14. package/browser/editor/components/image/page.mjs +172 -90
  15. package/browser/editor/components/installed/index.mjs +15 -4
  16. package/browser/editor/components/installed/page.mjs +103 -25
  17. package/browser/editor/components/installed/served.mjs +6 -5
  18. package/browser/editor/components/instances.mjs +18 -0
  19. package/browser/editor/components/list/page.mjs +3 -6
  20. package/browser/editor/components/media/icons.mjs +13 -8
  21. package/browser/editor/components/media/page.mjs +5 -3
  22. package/browser/editor/components/media/toolbar.mjs +12 -3
  23. package/browser/editor/components/paragraph/index.mjs +4 -3
  24. package/browser/editor/components/registry.mjs +30 -9
  25. package/browser/editor/components/table/index.mjs +61 -2
  26. package/browser/editor/components/table/page.mjs +1 -1
  27. package/browser/editor/page/after/index.mjs +288 -0
  28. package/browser/editor/page/align.mjs +91 -0
  29. package/browser/editor/page/annotate/card.mjs +3 -6
  30. package/browser/editor/page/autosave.mjs +310 -37
  31. package/browser/editor/page/beside.mjs +5 -6
  32. package/browser/editor/page/block-menu/index.mjs +6 -3
  33. package/browser/editor/page/blocks.mjs +3 -1
  34. package/browser/editor/page/board/client.mjs +57 -0
  35. package/browser/editor/page/board/hint.mjs +182 -0
  36. package/browser/editor/page/board/history.mjs +119 -0
  37. package/browser/editor/page/board/index.mjs +1059 -0
  38. package/browser/editor/page/board/motion.mjs +177 -0
  39. package/browser/editor/page/board/settings.mjs +210 -0
  40. package/browser/editor/page/caret.mjs +1 -1
  41. package/browser/editor/page/changes/bar.mjs +6 -14
  42. package/browser/editor/page/changes/index.mjs +2 -2
  43. package/browser/editor/page/clipboard/import/html.mjs +29 -6
  44. package/browser/editor/page/clipboard/import/inline.mjs +32 -0
  45. package/browser/editor/page/clipboard/import/markdown.mjs +58 -13
  46. package/browser/editor/page/clipboard/import/read.mjs +6 -1
  47. package/browser/editor/page/clipboard/import/to-blocks.mjs +44 -12
  48. package/browser/editor/page/clipboard/import/yuque.mjs +622 -0
  49. package/browser/editor/page/clipboard/index.mjs +133 -15
  50. package/browser/editor/page/clipboard/own/blocks.mjs +13 -14
  51. package/browser/editor/page/clipboard/own/chart-keys.mjs +41 -28
  52. package/browser/editor/page/clipboard/own/describe.mjs +6 -2
  53. package/browser/editor/page/clipboard/own/selection.mjs +1 -1
  54. package/browser/editor/page/columns/index.mjs +48 -46
  55. package/browser/editor/page/commit.mjs +80 -22
  56. package/browser/editor/page/conflicts.mjs +7 -7
  57. package/browser/editor/page/core.mjs +34 -16
  58. package/browser/editor/page/custom-page.mjs +110 -0
  59. package/browser/editor/page/editor.mjs +71 -17
  60. package/browser/editor/page/emoji-picker/styles.mjs +7 -12
  61. package/browser/editor/page/emoji-picker/upload.mjs +2 -2
  62. package/browser/editor/page/handle/index.mjs +5 -8
  63. package/browser/editor/page/history.mjs +41 -6
  64. package/browser/editor/page/insert/index.mjs +20 -22
  65. package/browser/editor/page/links/index.mjs +5 -3
  66. package/browser/editor/page/links/pages.mjs +27 -9
  67. package/browser/editor/page/look.mjs +54 -3
  68. package/browser/editor/page/margin.mjs +18 -3
  69. package/browser/editor/page/media-menu/index.mjs +6 -7
  70. package/browser/editor/page/menu.mjs +33 -14
  71. package/browser/editor/page/notices.mjs +2 -2
  72. package/browser/editor/page/page-objects.mjs +9 -2
  73. package/browser/editor/page/panel.mjs +4 -9
  74. package/browser/editor/page/present-links.mjs +15 -5
  75. package/browser/editor/page/present-shell.mjs +63 -0
  76. package/browser/editor/page/resize/index.mjs +42 -29
  77. package/browser/editor/page/selection/index.mjs +10 -2
  78. package/browser/editor/page/served.mjs +14 -0
  79. package/browser/editor/page/session.mjs +48 -4
  80. package/browser/editor/page/slash-menu/index.mjs +3 -3
  81. package/browser/editor/page/table/binding.mjs +87 -0
  82. package/browser/editor/page/table/cells.mjs +102 -46
  83. package/browser/editor/page/table/index.mjs +24 -9
  84. package/browser/editor/page/table/pictures.mjs +299 -0
  85. package/browser/editor/page/table/views.mjs +103 -0
  86. package/browser/editor/page/table/widths.mjs +82 -10
  87. package/browser/editor/page/text-select/index.mjs +26 -12
  88. package/browser/editor/page/todo-writes.mjs +75 -0
  89. package/browser/editor/page/typing/index.mjs +97 -15
  90. package/browser/editor/page/typing/leave.mjs +19 -5
  91. package/browser/editor/page/ui.mjs +13 -0
  92. package/browser/shared/block-packs.mjs +419 -0
  93. package/browser/shared/board-places.mjs +224 -0
  94. package/browser/shared/card-size.mjs +59 -0
  95. package/browser/shared/colors.mjs +3 -2
  96. package/browser/shared/component-catalog.mjs +330 -46
  97. package/browser/shared/component-source.mjs +39 -0
  98. package/browser/shared/components/heading.mjs +2 -1
  99. package/browser/shared/components/index.mjs +12 -3
  100. package/browser/shared/components/installed.mjs +35 -3
  101. package/browser/shared/components/page.mjs +20 -8
  102. package/browser/shared/components/paragraph.mjs +8 -1
  103. package/browser/shared/components/state.mjs +5 -1
  104. package/browser/shared/components/table.mjs +1 -0
  105. package/browser/shared/document-look.mjs +10 -5
  106. package/browser/shared/drafts.mjs +432 -0
  107. package/browser/shared/emoji/line-icons.mjs +37 -0
  108. package/browser/shared/extension-sidebar.mjs +126 -0
  109. package/browser/shared/extensions.mjs +79 -0
  110. package/browser/shared/file-table.mjs +101 -0
  111. package/browser/shared/http.mjs +9 -0
  112. package/browser/shared/i18n/en.mjs +330 -27
  113. package/browser/shared/json-layout.mjs +47 -0
  114. package/browser/shared/net-cache.mjs +133 -0
  115. package/browser/shared/net-keys.mjs +32 -0
  116. package/browser/shared/net-policy.mjs +177 -0
  117. package/browser/shared/outline-shape.mjs +128 -0
  118. package/browser/shared/outline.mjs +359 -67
  119. package/browser/shared/pack-manifest.mjs +88 -0
  120. package/browser/shared/page-address.mjs +6 -3
  121. package/browser/shared/page-cards.mjs +308 -0
  122. package/browser/shared/page-links.mjs +69 -6
  123. package/browser/shared/pages.mjs +500 -0
  124. package/browser/shared/paths.mjs +6 -0
  125. package/browser/shared/pinyin.mjs +92 -0
  126. package/browser/shared/present-step.mjs +17 -0
  127. package/browser/shared/preview-server.mjs +3 -7
  128. package/browser/shared/session.mjs +8 -1
  129. package/browser/shared/shipped-blocks.mjs +299 -0
  130. package/browser/shared/sidebar-head.mjs +70 -0
  131. package/browser/shared/table-chart.mjs +33 -1
  132. package/browser/shared/todos.mjs +83 -0
  133. package/browser/shared/user-directory.mjs +24 -0
  134. package/browser/shared/versions.mjs +14 -0
  135. package/browser/shared/web-links.mjs +139 -0
  136. package/browser/shared/workspace-columns.mjs +120 -0
  137. package/browser/shared/workspace-name.mjs +154 -0
  138. package/browser/shared/workspace-query.mjs +125 -0
  139. package/browser/shared/workspace-registry.mjs +272 -0
  140. package/browser/shared/workspace.mjs +171 -20
  141. package/dist/chunk-2OHANJ6Q.mjs +2 -0
  142. package/dist/chunk-3MBRL2PM.mjs +16 -0
  143. package/dist/chunk-4OKWZY5E.mjs +2 -0
  144. package/dist/chunk-4OZWXZE5.mjs +5 -0
  145. package/dist/chunk-5K44HLTZ.mjs +2 -0
  146. package/dist/{chunk-5ZKJ3H4P.mjs → chunk-5XA2ZBAE.mjs} +3 -3
  147. package/dist/{chunk-4FS7Z7WR.mjs → chunk-67N2QJYT.mjs} +1 -1
  148. package/dist/chunk-6KBYRA2C.mjs +2 -0
  149. package/dist/chunk-6N3PX4XX.mjs +8 -0
  150. package/dist/{chunk-V5JTW2LH.mjs → chunk-6QBHU4DF.mjs} +1 -1
  151. package/dist/chunk-7JDX4E65.mjs +13 -0
  152. package/dist/chunk-7M2BQQGZ.mjs +2 -0
  153. package/dist/chunk-7OG26PGF.mjs +2 -0
  154. package/dist/chunk-AHN3NFKJ.mjs +3 -0
  155. package/dist/chunk-ALZ6ZENZ.mjs +3 -0
  156. package/dist/chunk-AR5D57ZD.mjs +170 -0
  157. package/dist/{chunk-W3BGBJQW.mjs → chunk-BFJGHSQN.mjs} +1 -1
  158. package/dist/{chunk-LS4F7JUM.mjs → chunk-BZ5RAF7L.mjs} +1 -1
  159. package/dist/chunk-CMA72MAG.mjs +2 -0
  160. package/dist/{chunk-LCTHTZIL.mjs → chunk-DAZL73VK.mjs} +91 -91
  161. package/dist/{chunk-Y6RLRPG3.mjs → chunk-DJISHPUL.mjs} +1 -1
  162. package/dist/chunk-DR73Y2UJ.mjs +3 -0
  163. package/dist/{chunk-FDLXYYG4.mjs → chunk-EAIFITAV.mjs} +1 -1
  164. package/dist/{chunk-TMYZB6AV.mjs → chunk-EKNHM3P4.mjs} +1 -1
  165. package/dist/chunk-EP25HDAJ.mjs +2 -0
  166. package/dist/{chunk-GB5SOYQJ.mjs → chunk-ERLAIBOA.mjs} +2 -2
  167. package/dist/chunk-EURLTOTZ.mjs +4 -0
  168. package/dist/chunk-F4ZA6JRZ.mjs +3 -0
  169. package/dist/chunk-F6HVDZR4.mjs +2 -0
  170. package/dist/chunk-FDMAXMQA.mjs +2 -0
  171. package/dist/chunk-FETSREUN.mjs +5 -0
  172. package/dist/chunk-GHOYKMQ3.mjs +4 -0
  173. package/dist/{chunk-2B5E4CDJ.mjs → chunk-GPIWQ4X4.mjs} +1 -1
  174. package/dist/chunk-HDWTZ763.mjs +12 -0
  175. package/dist/chunk-HPOI4ZX7.mjs +6 -0
  176. package/dist/{chunk-BGGDRNYQ.mjs → chunk-HXG7EOPJ.mjs} +1 -1
  177. package/dist/chunk-IA4PSIMD.mjs +2 -0
  178. package/dist/{chunk-E7LWZRXY.mjs → chunk-ITOH5EGO.mjs} +1 -1
  179. package/dist/chunk-IV64FFI4.mjs +2 -0
  180. package/dist/chunk-J43Z6LSS.mjs +2 -0
  181. package/dist/chunk-J5PUIV3Y.mjs +4 -0
  182. package/dist/chunk-JA7G53PC.mjs +2 -0
  183. package/dist/chunk-JEUK3ZO7.mjs +2 -0
  184. package/dist/chunk-JLTZF4LA.mjs +2 -0
  185. package/dist/chunk-JZT7I2OJ.mjs +2 -0
  186. package/dist/chunk-K5XATEOO.mjs +2 -0
  187. package/dist/chunk-L2SUIS5S.mjs +2 -0
  188. package/dist/chunk-L7UP52JO.mjs +2 -0
  189. package/dist/chunk-LM4XFQHZ.mjs +2 -0
  190. package/dist/chunk-MN7BZL4R.mjs +2 -0
  191. package/dist/chunk-MTYYHM2G.mjs +15 -0
  192. package/dist/chunk-MXUBKDRO.mjs +15 -0
  193. package/dist/chunk-NAMN3RAF.mjs +2 -0
  194. package/dist/{chunk-SYGN7GLU.mjs → chunk-OEXWRJME.mjs} +1 -1
  195. package/dist/chunk-OFHXGWOX.mjs +2 -0
  196. package/dist/chunk-ORID3AE7.mjs +166 -0
  197. package/dist/chunk-PAREWQGB.mjs +4 -0
  198. package/dist/chunk-PGDE24N5.mjs +2 -0
  199. package/dist/chunk-POTA2FV4.mjs +2 -0
  200. package/dist/chunk-PUOQ65NC.mjs +2 -0
  201. package/dist/chunk-Q4UEPUWF.mjs +2 -0
  202. package/dist/chunk-QE5RG76S.mjs +549 -0
  203. package/dist/chunk-R2ZDLJYT.mjs +10 -0
  204. package/dist/{chunk-7DTINW6U.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  205. package/dist/chunk-SWUTTZCN.mjs +2 -0
  206. package/dist/chunk-TANZRINB.mjs +2 -0
  207. package/dist/chunk-TR7TWGHB.mjs +2 -0
  208. package/dist/chunk-U5XL7D6A.mjs +3 -0
  209. package/dist/{chunk-XNROSH2T.mjs → chunk-U7NZI6N4.mjs} +2 -2
  210. package/dist/chunk-UGWMMEJ5.mjs +15 -0
  211. package/dist/chunk-UJQJKNGK.mjs +2 -0
  212. package/dist/chunk-UYVCQK3H.mjs +22 -0
  213. package/dist/chunk-VFX2KNHP.mjs +4 -0
  214. package/dist/chunk-VS7JIGJW.mjs +24 -0
  215. package/dist/chunk-W7665ZEC.mjs +6 -0
  216. package/dist/chunk-WQDQWCX5.mjs +2 -0
  217. package/dist/chunk-YI43RG4P.mjs +2 -0
  218. package/dist/chunk-YLPSMDIS.mjs +5 -0
  219. package/dist/chunk-YNAWBAYN.mjs +3 -0
  220. package/dist/chunk-YROX2O22.mjs +2 -0
  221. package/dist/chunk-ZDLPUOAG.mjs +6 -0
  222. package/dist/{chunk-IVDLMMBD.mjs → chunk-ZHEHPMBK.mjs} +1 -1
  223. package/dist/chunk-ZQS6H473.mjs +16 -0
  224. package/dist/chunk-ZTHICSSF.mjs +2 -0
  225. package/dist/chunk-ZWWC4KLF.mjs +20 -0
  226. package/dist/cli.mjs +1 -1
  227. package/dist/server.mjs +1 -1
  228. package/dist/{chunk-U6KNPJPR.mjs → update-fetch.mjs} +1 -1
  229. package/dist/worker.mjs +1 -1
  230. package/kit/board.css +95 -0
  231. package/kit/board.js +250 -0
  232. package/kit/charts.js +5 -71
  233. package/kit/code.js +17 -17
  234. package/kit/report.css +335 -18
  235. package/kit/runtime.js +1638 -125
  236. package/kit/state.js +10 -1
  237. package/kit/tables.js +130 -43
  238. package/kit/ui.js +79 -35
  239. package/package.json +2 -1
  240. package/packs/gallery/card/component.json +14 -0
  241. package/packs/gallery/card/example.html +10 -0
  242. package/packs/gallery/card/preview.svg +1 -0
  243. package/packs/gallery/card/style.css +6 -0
  244. package/packs/gallery/card/template.html +6 -0
  245. package/packs/gallery/card/writing.md +14 -0
  246. package/packs/gallery/chart-card/component.json +15 -0
  247. package/packs/gallery/chart-card/example.html +14 -0
  248. package/packs/gallery/chart-card/kit.js +130 -0
  249. package/packs/gallery/chart-card/preview.svg +1 -0
  250. package/packs/gallery/chart-card/style.css +42 -0
  251. package/packs/gallery/chart-card/template.html +13 -0
  252. package/packs/gallery/chart-card/writing.md +20 -0
  253. package/packs/gallery/chart-view/component.json +20 -0
  254. package/packs/gallery/chart-view/example.html +13 -0
  255. package/packs/gallery/chart-view/kit.js +355 -0
  256. package/packs/gallery/chart-view/preview.svg +1 -0
  257. package/packs/gallery/chart-view/style.css +94 -0
  258. package/packs/gallery/chart-view/template.html +3 -0
  259. package/packs/gallery/chart-view/writing.md +22 -0
  260. package/packs/gallery/countdown/component.json +18 -0
  261. package/packs/gallery/countdown/example.html +3 -0
  262. package/packs/gallery/countdown/kit.js +216 -0
  263. package/packs/gallery/countdown/preview.svg +1 -0
  264. package/packs/gallery/countdown/style.css +118 -0
  265. package/packs/gallery/countdown/template.html +3 -0
  266. package/packs/gallery/countdown/writing.md +22 -0
  267. package/packs/gallery/habit/component.json +14 -0
  268. package/packs/gallery/habit/example.html +3 -0
  269. package/packs/gallery/habit/kit.js +334 -0
  270. package/packs/gallery/habit/preview.svg +1 -0
  271. package/packs/gallery/habit/style.css +174 -0
  272. package/packs/gallery/habit/template.html +3 -0
  273. package/packs/gallery/habit/writing.md +21 -0
  274. package/packs/gallery/heatmap/component.json +18 -0
  275. package/packs/gallery/heatmap/example.html +3 -0
  276. package/packs/gallery/heatmap/kit.js +513 -0
  277. package/packs/gallery/heatmap/preview.svg +1 -0
  278. package/packs/gallery/heatmap/style.css +189 -0
  279. package/packs/gallery/heatmap/template.html +3 -0
  280. package/packs/gallery/heatmap/writing.md +21 -0
  281. package/packs/gallery/kanban/component.json +18 -0
  282. package/packs/gallery/kanban/example.html +12 -0
  283. package/packs/gallery/kanban/kit.js +540 -0
  284. package/packs/gallery/kanban/preview.svg +1 -0
  285. package/packs/gallery/kanban/style.css +212 -0
  286. package/packs/gallery/kanban/template.html +3 -0
  287. package/packs/gallery/kanban/writing.md +20 -0
  288. package/packs/gallery/metric/component.json +22 -0
  289. package/packs/gallery/metric/example.html +15 -0
  290. package/packs/gallery/metric/kit.js +248 -0
  291. package/packs/gallery/metric/preview.svg +1 -0
  292. package/packs/gallery/metric/style.css +92 -0
  293. package/packs/gallery/metric/template.html +3 -0
  294. package/packs/gallery/metric/writing.md +23 -0
  295. package/packs/gallery/note/component.json +14 -0
  296. package/packs/gallery/note/example.html +3 -0
  297. package/packs/gallery/note/kit.js +129 -0
  298. package/packs/gallery/note/preview.svg +1 -0
  299. package/packs/gallery/note/style.css +97 -0
  300. package/packs/gallery/note/template.html +3 -0
  301. package/packs/gallery/note/writing.md +18 -0
  302. package/packs/gallery/pack.json +8 -0
  303. package/packs/gallery/recent/component.json +13 -0
  304. package/packs/gallery/recent/example.html +1 -0
  305. package/packs/gallery/recent/kit.js +293 -0
  306. package/packs/gallery/recent/preview.svg +1 -0
  307. package/packs/gallery/recent/style.css +85 -0
  308. package/packs/gallery/recent/template.html +1 -0
  309. package/packs/gallery/recent/writing.md +15 -0
  310. package/packs/gallery/static/component.json +13 -0
  311. package/packs/gallery/static/example.html +11 -0
  312. package/packs/gallery/static/preview.svg +1 -0
  313. package/packs/gallery/static/style.css +171 -0
  314. package/packs/gallery/static/template.html +1 -0
  315. package/packs/gallery/static/writing.md +18 -0
  316. package/packs/gallery/stats/component.json +13 -0
  317. package/packs/gallery/stats/example.html +1 -0
  318. package/packs/gallery/stats/kit.js +347 -0
  319. package/packs/gallery/stats/preview.svg +1 -0
  320. package/packs/gallery/stats/style.css +73 -0
  321. package/packs/gallery/stats/template.html +1 -0
  322. package/packs/gallery/stats/writing.md +11 -0
  323. package/packs/gallery/today/component.json +12 -0
  324. package/packs/gallery/today/example.html +1 -0
  325. package/packs/gallery/today/kit.js +220 -0
  326. package/packs/gallery/today/preview.svg +1 -0
  327. package/packs/gallery/today/style.css +149 -0
  328. package/packs/gallery/today/template.html +1 -0
  329. package/packs/gallery/today/writing.md +14 -0
  330. package/packs/gallery/todos/component.json +19 -0
  331. package/packs/gallery/todos/example.html +3 -0
  332. package/packs/gallery/todos/kit.js +489 -0
  333. package/packs/gallery/todos/preview.svg +1 -0
  334. package/packs/gallery/todos/style.css +214 -0
  335. package/packs/gallery/todos/template.html +3 -0
  336. package/packs/gallery/todos/writing.md +30 -0
  337. package/packs/gallery/weather/component.json +19 -0
  338. package/packs/gallery/weather/example.html +3 -0
  339. package/packs/gallery/weather/kit.js +387 -0
  340. package/packs/gallery/weather/preview.svg +1 -0
  341. package/packs/gallery/weather/style.css +140 -0
  342. package/packs/gallery/weather/template.html +3 -0
  343. package/packs/gallery/weather/writing.md +26 -0
  344. package/packs/gallery-soft/countdown/component.json +18 -0
  345. package/packs/gallery-soft/countdown/example.html +3 -0
  346. package/packs/gallery-soft/countdown/kit.js +206 -0
  347. package/packs/gallery-soft/countdown/preview.svg +1 -0
  348. package/packs/gallery-soft/countdown/style.css +211 -0
  349. package/packs/gallery-soft/countdown/template.html +3 -0
  350. package/packs/gallery-soft/countdown/writing.md +24 -0
  351. package/packs/gallery-soft/habit/component.json +14 -0
  352. package/packs/gallery-soft/habit/example.html +3 -0
  353. package/packs/gallery-soft/habit/kit.js +366 -0
  354. package/packs/gallery-soft/habit/preview.svg +1 -0
  355. package/packs/gallery-soft/habit/style.css +251 -0
  356. package/packs/gallery-soft/habit/template.html +3 -0
  357. package/packs/gallery-soft/habit/writing.md +23 -0
  358. package/packs/gallery-soft/heatmap/component.json +18 -0
  359. package/packs/gallery-soft/heatmap/example.html +3 -0
  360. package/packs/gallery-soft/heatmap/kit.js +498 -0
  361. package/packs/gallery-soft/heatmap/preview.svg +1 -0
  362. package/packs/gallery-soft/heatmap/style.css +181 -0
  363. package/packs/gallery-soft/heatmap/template.html +3 -0
  364. package/packs/gallery-soft/heatmap/writing.md +23 -0
  365. package/packs/gallery-soft/note/component.json +14 -0
  366. package/packs/gallery-soft/note/example.html +3 -0
  367. package/packs/gallery-soft/note/kit.js +162 -0
  368. package/packs/gallery-soft/note/preview.svg +1 -0
  369. package/packs/gallery-soft/note/style.css +148 -0
  370. package/packs/gallery-soft/note/template.html +3 -0
  371. package/packs/gallery-soft/note/writing.md +20 -0
  372. package/packs/gallery-soft/pack.json +8 -0
  373. package/packs/gallery-soft/recent/component.json +13 -0
  374. package/packs/gallery-soft/recent/example.html +1 -0
  375. package/packs/gallery-soft/recent/kit.js +335 -0
  376. package/packs/gallery-soft/recent/preview.svg +1 -0
  377. package/packs/gallery-soft/recent/style.css +160 -0
  378. package/packs/gallery-soft/recent/template.html +1 -0
  379. package/packs/gallery-soft/recent/writing.md +17 -0
  380. package/packs/gallery-soft/static/component.json +13 -0
  381. package/packs/gallery-soft/static/example.html +12 -0
  382. package/packs/gallery-soft/static/preview.svg +1 -0
  383. package/packs/gallery-soft/static/style.css +186 -0
  384. package/packs/gallery-soft/static/template.html +1 -0
  385. package/packs/gallery-soft/static/writing.md +20 -0
  386. package/packs/gallery-soft/stats/component.json +13 -0
  387. package/packs/gallery-soft/stats/example.html +1 -0
  388. package/packs/gallery-soft/stats/kit.js +341 -0
  389. package/packs/gallery-soft/stats/preview.svg +1 -0
  390. package/packs/gallery-soft/stats/style.css +119 -0
  391. package/packs/gallery-soft/stats/template.html +1 -0
  392. package/packs/gallery-soft/stats/writing.md +13 -0
  393. package/packs/gallery-soft/today/component.json +12 -0
  394. package/packs/gallery-soft/today/example.html +1 -0
  395. package/packs/gallery-soft/today/kit.js +222 -0
  396. package/packs/gallery-soft/today/preview.svg +1 -0
  397. package/packs/gallery-soft/today/style.css +178 -0
  398. package/packs/gallery-soft/today/template.html +1 -0
  399. package/packs/gallery-soft/today/writing.md +16 -0
  400. package/packs/gallery-soft/todos/component.json +19 -0
  401. package/packs/gallery-soft/todos/example.html +3 -0
  402. package/packs/gallery-soft/todos/kit.js +527 -0
  403. package/packs/gallery-soft/todos/preview.svg +1 -0
  404. package/packs/gallery-soft/todos/style.css +212 -0
  405. package/packs/gallery-soft/todos/template.html +3 -0
  406. package/packs/gallery-soft/todos/writing.md +32 -0
  407. package/packs/gallery-soft/weather/component.json +19 -0
  408. package/packs/gallery-soft/weather/example.html +3 -0
  409. package/packs/gallery-soft/weather/kit.js +411 -0
  410. package/packs/gallery-soft/weather/preview.svg +1 -0
  411. package/packs/gallery-soft/weather/style.css +185 -0
  412. package/packs/gallery-soft/weather/template.html +3 -0
  413. package/packs/gallery-soft/weather/writing.md +28 -0
  414. package/release.json +12 -10
  415. package/sdk/doc-kit.d.ts +396 -5
  416. package/sdk/doc-state.d.ts +2 -0
  417. package/skill/SKILL.md +56 -23
  418. package/skill/references/block-script.md +140 -0
  419. package/skill/references/building-blocks.md +257 -0
  420. package/skill/references/extensions.md +59 -0
  421. package/skill/references/pages-and-data.md +225 -0
  422. package/skill/references/writing-html.md +8 -4
  423. package/skill/sdk/doc-kit.d.ts +396 -5
  424. package/skill/sdk/doc-state.d.ts +2 -0
  425. package/web/assets/index-BM_K-Auu.css +1 -0
  426. package/web/assets/index-DRslOBiv.js +15 -0
  427. package/web/index.html +2 -2
  428. package/dist/chunk-3HIRPVLU.mjs +0 -2
  429. package/dist/chunk-5MHMDLZD.mjs +0 -4
  430. package/dist/chunk-64K7IPLO.mjs +0 -255
  431. package/dist/chunk-6QXGZM36.mjs +0 -8
  432. package/dist/chunk-6RGJOMJP.mjs +0 -16
  433. package/dist/chunk-AJ73XJF3.mjs +0 -2
  434. package/dist/chunk-AUZGSZJH.mjs +0 -13
  435. package/dist/chunk-BFE45AKL.mjs +0 -2
  436. package/dist/chunk-BXO2ZY5P.mjs +0 -2
  437. package/dist/chunk-CEH4MRCC.mjs +0 -2
  438. package/dist/chunk-CY2FNNAB.mjs +0 -16
  439. package/dist/chunk-DFUDV4LX.mjs +0 -2
  440. package/dist/chunk-DKXG4XDG.mjs +0 -2
  441. package/dist/chunk-EZQ34M3F.mjs +0 -124
  442. package/dist/chunk-EZY3WC6Z.mjs +0 -15
  443. package/dist/chunk-FUKQNOQS.mjs +0 -9
  444. package/dist/chunk-JPOSLGOC.mjs +0 -6
  445. package/dist/chunk-JVHHHGEA.mjs +0 -3
  446. package/dist/chunk-L3QKH4OK.mjs +0 -26
  447. package/dist/chunk-LAE5NQ4B.mjs +0 -2
  448. package/dist/chunk-LEF6DRCK.mjs +0 -59
  449. package/dist/chunk-NO5NJCHO.mjs +0 -2
  450. package/dist/chunk-NQPVAU63.mjs +0 -2
  451. package/dist/chunk-NSKUTQ5J.mjs +0 -5
  452. package/dist/chunk-O35FIXRB.mjs +0 -2
  453. package/dist/chunk-P2CAZPDP.mjs +0 -3
  454. package/dist/chunk-PL6GHLGD.mjs +0 -15
  455. package/dist/chunk-QJIR2BLP.mjs +0 -6
  456. package/dist/chunk-QUPLVPB2.mjs +0 -7
  457. package/dist/chunk-R7BNENLY.mjs +0 -4
  458. package/dist/chunk-S6O4UHLC.mjs +0 -2
  459. package/dist/chunk-SGJWQKEI.mjs +0 -2
  460. package/dist/chunk-TX6JH7TR.mjs +0 -2
  461. package/dist/chunk-TYK6VNAB.mjs +0 -10
  462. package/dist/chunk-UALRNVSE.mjs +0 -4
  463. package/dist/chunk-V3HXVQEM.mjs +0 -2
  464. package/dist/chunk-V5VXUJKG.mjs +0 -2
  465. package/dist/chunk-VBXMADMP.mjs +0 -2
  466. package/dist/chunk-VNV55RUA.mjs +0 -2
  467. package/dist/chunk-VPD2PS35.mjs +0 -2
  468. package/dist/chunk-W4VKN3GF.mjs +0 -7
  469. package/dist/chunk-W5BXXPDJ.mjs +0 -3
  470. package/dist/chunk-XUNHRCOG.mjs +0 -6
  471. package/skill/references/building-components.md +0 -367
  472. package/web/assets/index-Bh74DfsV.css +0 -1
  473. package/web/assets/index-UW0RyFFt.js +0 -13
@@ -0,0 +1,13 @@
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 Oe,f as we,g as ge,h as $e,i as We,j as ne,l as Y,m as Ge,n as Ae,o as Ke,p as Ve,q as ze,r as g,t as Qe,u as Ye}from"./chunk-3MBRL2PM.mjs";import{M as Xe}from"./chunk-HPOI4ZX7.mjs";import{f as Te,i as Je}from"./chunk-5XA2ZBAE.mjs";import{a as K}from"./chunk-JEUK3ZO7.mjs";import{a as me}from"./chunk-JLTZF4LA.mjs";import{a as Ue,b as Ze,f as pe,g as qe}from"./chunk-PUOQ65NC.mjs";import{e as Ne,g as te}from"./chunk-ZWWC4KLF.mjs";import{b as Se}from"./chunk-ZQS6H473.mjs";import{b as T,i as Pe}from"./chunk-4OZWXZE5.mjs";import{a as Be}from"./chunk-HYMEEXKN.mjs";import{f as Ee,j as He}from"./chunk-HDWTZ763.mjs";import{randomBytes as Ct}from"node:crypto";import{existsSync as It}from"node:fs";import N from"node:fs/promises";import A from"node:path";import{isInstance as Re,isSlot as jt,partOf as Mt}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as ke,FALLBACK as Rt,FIELDS as Dt,INSTANCE as ft,PACKAGE_ID as _t,SLOT as Ft}from"../browser/shared/components/installed.mjs";import{attr as ce,walk as Ht}from"../browser/shared/html-tree.mjs";import{documentDirectory as Pt,documentFiles as Bt,layoutOf as se,packageFolders as Jt,slugTaken as Ut}from"../browser/shared/workspace.mjs";var et=10,Ce=6,Zt=3,qt=100,De=1024,_e=900,Wt=4e3,le=3e4,Gt=1500,Ie=3e4,je=500,Kt=5e3,Vt=200,tt=20,nt=160,ye=12,zt=3600*1e3,Qt=["p","pi","pin"],he=e=>new Promise(t=>setTimeout(t,e));async function at(e){let{_keyDefinitions:t}=await import("./chunk-43B75J5T.mjs"),n=Object.hasOwn(t,e)?[e]:e.split("+"),a=new Set(["Control","Shift","Alt","Meta"]);if(n.some(s=>!Object.hasOwn(t,s))||n.slice(0,-1).some(s=>!a.has(s)))throw new T(`Not a key: ${e} (a key as a browser names it, Enter, Space, Escape, Tab, ArrowRight, a letter or a digit, after modifiers joined by "+": Shift+Tab, Control+Enter).`);return n}var ie={press:"<selector>",drag:'<selector>, with "to": <selector>',key:"[<selector>, <key>]",type:"[<selector>, <words>]",select:"[<selector>, <value>]"};async function ut(e,t=null){let n=d=>new T(t?`${t[0].toUpperCase()}${t.slice(1)}: ${d}`:`${d[0].toUpperCase()}${d.slice(1)}`);if(!e||typeof e!="object"||Array.isArray(e))throw n(`a step is an object naming one gesture: ${Object.entries(ie).map(([d,h])=>`"${d}": ${h}`).join(", ")}, and "then": <key> after it.`);let a=Object.keys(e).filter(d=>!Object.hasOwn(ie,d)&&!["to","then","replace"].includes(d));if(a.length)throw n(`no such field: ${a.join(", ")} (a step names one of ${Object.keys(ie).join(", ")}, "to" with a drag, "replace": true with typing and "then" after any).`);let s=Object.keys(ie).filter(d=>e[d]!==void 0),o=d=>t?`"${d}"`:`--${d}`;if(s.length!==1)throw n(s.length?`one gesture at a time: ${s.map(o).join(" or ")}.`:t?`name the gesture: ${Object.keys(ie).map(o).join(", ")}.`:"Say the gesture: --press <selector>, --drag <selector> --to <selector>, --key <selector> <key>, --type <selector> <words> or --select <selector> <value>; or --steps <file>.");let[i]=s;if(e.to!==void 0&&i!=="drag")throw n(`${o("to")} goes with ${o("drag")}: ${t?'"drag": <selector>, "to": <selector>':"--drag <selector> --to <selector>"}.`);if(i==="drag"&&e.to===void 0)throw n(`${o("drag")} takes ${o("to")}: ${t?'"drag": <selector>, "to": <selector>':"--drag <selector> --to <selector>"}, where it is dropped.`);if(e.replace!==void 0&&i!=="type")throw n(`${o("replace")} goes with ${o("type")}: it selects what the field holds before the words go in.`);if(e.replace!==void 0&&e.replace!==!0)throw n(`${o("replace")} is true: ${t?'"replace": true':"--replace"} selects what the field holds before the words go in.`);let l=(d,h)=>{if(typeof d!="string"||!d)throw n(`${h} is words: ${JSON.stringify(d)}.`);return d},c=(d,h)=>{if(!Array.isArray(d)||d.length!==2)throw n(`${o(i)} takes ${t?`[<selector>, ${h}]`:`<selector> ${h}`}.`);return[l(d[0],"a selector"),l(d[1],h)]},r={kind:i};if(i==="press"&&(r.at=l(e.press,"a selector")),i==="drag"&&Object.assign(r,{at:l(e.drag,"a selector"),to:l(e.to,"a selector")}),i==="key"){let[d,h]=c(e.key,"<key>");Object.assign(r,{at:d,key:h,keys:await at(h)})}return i==="type"&&([r.at,r.text]=c(e.type,"<words>"),e.replace&&(r.replace=!0)),i==="select"&&([r.at,r.value]=c(e.select,"<value>")),e.then!==void 0&&(r.then={key:l(e.then,"a key"),keys:await at(l(e.then,"a key"))}),r}async function Yt(e,t={},n=!1){if(n&&e.has("--steps"))throw new T('--steps <file> holds every gesture: --replace goes in a step of it, as { "type": [".name", "\u65B0\u540D\u5B57"], "replace": true }, not beside it.');if(e.has("--steps")){let s=["--press","--drag","--to","--key","--type","--select","--then"].filter(o=>e.has(o));if(s.length)throw new T(`--steps <file> holds every gesture: ${s.join(", ")} goes in it, not beside it.`);return null}let a={};for(let s of["press","drag","to","then"])e.has(`--${s}`)&&(a[s]=e.get(`--${s}`));for(let s of["key","type","select"])e.has(`--${s}`)&&(a[s]=[e.get(`--${s}`),t[`--${s}`]]);return n&&(a.replace=!0),ut(a)}async function Xt(e){let t=A.basename(e),n;try{n=await N.readFile(e,"utf8")}catch(o){throw new T(`No steps file: ${K(e)} (${o.code??ne(o)}).`)}let a;try{a=JSON.parse(n.replace(/^/,""))}catch(o){throw new T(`${t} is no JSON: ${ne(o)}. A steps file is a list of steps, as [{ "press": ".add" }, { "type": [".name", "\u65B0\u540D\u5B57"], "then": "Enter" }].`)}if(!Array.isArray(a)||a.length===0)throw new T(`${t} holds no list of steps: write [{ "press": ".add" }, { "type": [".name", "\u65B0\u540D\u5B57"], "then": "Enter" }].`);if(a.length>tt)throw new T(`${t} holds ${a.length} steps, and a trial makes ${tt} at most: try fewer at a time.`);let s=[];for(let[o,i]of a.entries())s.push(await ut(i,`step ${o+1} of ${t}`));return s}var pt=e=>{let t=e.parentNode;for(;t&&!Re(t);)t=t.parentNode;return t??null},en=(e,t)=>{for(let n=e.parentNode;n&&n!==t;n=n.parentNode)if(jt(n))return ce(n,Ft);return null};function wt(e){let t=[];return Ht(Be(e),n=>{if(!Re(n))return;let a=pt(n);t.push({element:n,id:ce(n,ke),blockId:ce(n,"data-block-id")??null,line:n.sourceCodeLocation?.startLine,in:a?{id:ce(a,ke),line:a.sourceCodeLocation?.startLine,slot:en(n,a)}:null})},{inTemplates:!1}),t}var gt=({line:e,in:t},n)=>`${n}:${e}${t?`, in ${t.slot?`the slot ${t.slot} of `:""}${t.id} at ${n}:${t.line}`:""}`,tn=(e,{id:t,blockId:n})=>n??(e.filter(a=>a.id===t).length===1?t:null);function nn(e,t,{slug:n,name:a}){let s=()=>e.map(c=>` ${tn(e,c)??"(no id yet: gallery export gives it one)"} ${c.id} at ${gt(c,a)}`).join(`
3
+ `);if(t===null){if(e.length===1)return 0;throw new T(`${n} holds ${e.length} instances: name one, gallery block try ${n} <instance id> \u2026
4
+ ${s()}`)}let o=e.findIndex(({blockId:c})=>c===t);if(o>=0)return o;let i=t.includes("/")?t:`local/${t}`,l=_t.test(i)?e.flatMap((c,r)=>c.id===i?[r]:[]):[];if(l.length===1)return l[0];throw new T(l.length?`${n} holds ${l.length} instances of ${i}: name one by its id
5
+ ${s()}`:`${n} holds no instance ${t}:
6
+ ${s()}`)}var an=e=>e.replace(/\s+data-block-id="[^"]*"/g,""),st=e=>an(Se(e).text),sn=(e,t)=>(typeof t=="function"?t(e):wt(e)[t]?.element)??null;function ot(e,t,n){let a=sn(e,t);if(!a||ce(a,ke)!==n.id)return null;let s=[],o=Object.entries(n.parts).map(([r,{at:d}])=>{let h=Mt(a,d).filter(f=>f.sourceCodeLocation?.endTag&&!Re(f)&&pt(f)===a).map(({sourceCodeLocation:{startTag:f,endTag:u}})=>({start:f.endOffset,end:u.startOffset}));return s.push(...h),{name:r,text:h.map(({start:f,end:u})=>e.slice(f,u)).join(`
7
+ `)}}),i=s.sort((r,d)=>r.start-d.start||d.end-r.end).filter((r,d)=>!s.slice(0,d).some(h=>h.start<=r.start&&r.end<=h.end)),l="",c=0;for(let{start:r,end:d}of i)l+=e.slice(c,r),c=d;return{parts:o,outside:l+e.slice(c)}}function on(e,t,n,a){let[s,o]=[ot(e,n,a),ot(t,n,a)];return!s||!o?{parts:[],outside:null,gone:!0}:{parts:s.parts.flatMap(({name:l,text:c},r)=>c===o.parts[r].text?[]:[{name:l,...Ae(c,o.parts[r].text),how:Ve(c,o.parts[r].text),runs:Ke(c,o.parts[r].text)}]),outside:s.outside===o.outside?null:Ae(s.outside,o.outside),gone:!1}}function rn(e){let t=n=>n.length>nt?`${n.slice(0,nt)}\u2026`:n;return e.flatMap(({name:n,runs:a=[]})=>{let s=a.flatMap(({removed:l,added:c})=>[...l.map(r=>`- ${t(r)}`),...c.map(r=>`+ ${t(r)}`)]),o=e.length>1?" ":" ",i=s.slice(0,ye).map(l=>`${o}${l}`);return s.length>ye&&i.push(`${o}\u2026 ${s.length-ye} more line${s.length-ye===1?"":"s"}`),e.length>1?[` ${n}:`,...i]:i})}async function cn(e,t=null){let{components:n,marker:a}=se(e);return await mt([t,a,n].filter(Boolean))+me+te+je}async function ln(e,{directory:t,files:n,text:a}){let{scratch:s}=se(e);await N.mkdir(s,{recursive:!0});let o;do o=`try-${Ct(4).toString("hex")}`;while(Ut(o,e)||It(A.join(s,o)));let i=A.join(s,o);await N.mkdir(i),await N.cp(A.join(t,"assets"),A.join(i,"assets"),{recursive:!0}).catch(c=>{if(c.code!=="ENOENT")throw c}),await N.copyFile(n.json,A.join(i,A.basename(n.json))).catch(c=>{if(c.code!=="ENOENT")throw c});let l=A.join(i,A.basename(n.html));return await N.writeFile(l,a),{slug:o,folder:i,file:l}}async function $t(e,t){let{scratch:n,state:a}=se(e);await N.rm(A.join(n,t),{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{});for(let s of await N.readdir(a).catch(()=>[]))await N.rm(A.join(a,s,t),{recursive:!0,force:!0,maxRetries:3,retryDelay:100}).catch(()=>{})}async function dn(e,t=Date.now()){let{scratch:n}=se(e);for(let a of await N.readdir(n,{withFileTypes:!0}).catch(()=>[])){if(!a.isDirectory()||!/^try-[a-f0-9]{8}$/.test(a.name))continue;let{mtimeMs:s}=await N.stat(A.join(n,a.name)).catch(()=>({mtimeMs:t}));t-s>=zt&&await $t(e,a.name)}}async function mt(e){let t=[...e];for(let a of e)for(let s of await N.readdir(a,{recursive:!0,withFileTypes:!0}).catch(()=>[]))t.push(A.join(s.parentPath,s.name));let n=await Promise.all(t.map(a=>N.stat(a).then(({mtimeMs:s})=>s,()=>0)));return Math.max(...n)}var hn=e=>fetch(`${e}/__gallery/workspace/components`,{signal:AbortSignal.timeout(2e3)}).then(t=>t.ok?t.json():null).then(t=>Array.isArray(t?.packages)?t.packages:null,()=>null);async function fn(e,t,n){let{components:a,marker:s}=se(e),o=Jt(e).find(m=>m.id.toLowerCase()===t)?.folder??A.join(a,...t.split("/")),[i,l]=await Promise.all([mt([s,o]),hn(n)]),{packages:c,problems:r,settings:d}=Ee(e),h=l?.find(m=>m.id===t)??null,f=l?h?.state??"none":null,u=f==="normal"||f==="hidden",w=d.disabled.includes(t),k=r.get(t),y=k&&!w&&u?He("en",k.problem):null,p=l!==null&&c.has(t)&&!u;return{by:i+(y?Ne:me+te),held:y,behind:p,off:w,stamp:(c.get(t)??k)?.stamp??null,state:f,reason:h?.reason?.en??null}}var yt=({state:e,reason:t})=>e==="none"?"no such custom block":t?`it as not loading (${t})`:"it turned off";function un(e,{said:t,unparsed:n=null,off:a,behind:s=!1,state:o,reason:i}){let l="the instance shows what it holds, read-only, so a reader can do nothing with it";return n?`${l}: its kit.js did not parse, so no component of it started, and the console says ${n}`:t.length?`${l}: its component failed as the page started it, and the console says ${t.join("; ")}`:a?`${l}: ${e} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868`:s?`${l}: the server has not taken ${e} as components/ holds it, where it loads: its catalog in use has ${yt({state:o,reason:i})}`:o==="disabled"&&!i?`${l}: ${e} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868`:o==="broken"||o==="disabled"?`${l}: the server has ${e} as not loading (${i}): gallery block check ${e} says why`:o==="none"?`${l}: the server has not taken ${e} as components/ holds it (its catalog in use has no such custom block)`:o?`${l}: the page was served before the server took ${e} as components/ holds it, and did not load itself again with it`:`${l}: its component failed or never started, and the console said nothing of it`}var pn=(e,t,n)=>t.held?`${e} does not load as components/ holds it (${t.held}), and the server keeps it as it was until components/ has not changed for ${Ne/1e3}s, as it keeps a custom block written file by file`:t.behind?`components/ holds ${e} as loading, and the server's catalog in use still has ${yt(t)}: it takes what components/ holds once that has not changed for ${te/1e3}s`:n?`${e} or gallery.json changed a moment ago, and the server takes the change once components/ has not changed for ${te/1e3}s, the page served before loading itself again for it`:`the server took ${e} as components/ holds it, and the page served before is to load itself again with it`,wn=(e,t,n)=>t.held?`the server still keeps ${e} as it was`:t.behind?`the server has still not taken ${e} as components/ holds it`:`the server took ${e} as components/ holds it, and the page did not load itself again with it in ${n/1e3}s`;async function gn({root:e,id:t,origin:n,loadedAt:a,loaded:s,told:o=Kt,say:i=l=>console.log(l)}){let l=Date.now(),c,r=0,d=0,h=!1;for(;;await he(Vt)){let f=await fn(e,t,n),u=Date.now();c!==void 0&&f.stamp!==c&&(r=u),c=f.stamp,f.behind&&!d&&(d=u);let w=Math.max(f.by,...[r,d].filter(Boolean).map(y=>y+me+te)),k=s()?"the page loaded itself again":f.off?`gallery.json turns ${t} off now`:a>=w?`the page was asked for after the server took ${t} as components/ holds it`:u>w+o?wn(t,f,o):null;if(k)return h&&i(`Waited ${((u-l)/1e3).toFixed(1)}s: ${k}`),f;h||w-u<=je&&u-l<=je||(h=!0,i(`Waiting: ${pn(t,f,w>u)}, ${Math.ceil((w+o-u)/1e3)}s more at most`))}}function $n({instance:e,at:t,card:n}){return typeof n=="string"?[...[...document.querySelectorAll(".gallery-board > .gallery-card")].find(s=>s.getAttribute("data-card-id")===n)?.children??[]].find(s=>s.matches(e))??null:[...document.querySelectorAll(e)][t]??null}function mn(e,t){let n=u=>`<${u.localName}${u.classList.length?` class="${u.getAttribute("class")}"`:""}>`,a;try{a=e.querySelector(t)}catch{return{invalid:!0}}if(!a)return{none:!0,held:[...new Set([...e.querySelectorAll("[class]")].filter(u=>u.getClientRects().length>0).flatMap(u=>[...u.classList].map(w=>`.${w}`)))].slice(0,16)};let s=((a instanceof HTMLElement?a.innerText:a.textContent)??"").replace(/\s+/g," ").trim(),o={named:n(a),words:s.length>40?`${s.slice(0,40)}\u2026`:s},i=[...a.getClientRects()].filter(({width:u,height:w})=>u>0&&w>0);if(!i.length)return{...o,hidden:!0};let{left:l,top:c,right:r,bottom:d,width:h,height:f}=i.reduce((u,w)=>u.width*u.height>=w.width*w.height?u:w);return{...o,box:{left:l,top:c,right:r,bottom:d,x:l+h/2,y:c+f/2}}}function yn(e,{selector:t,x:n,y:a}){let s=e.querySelector(t),o=document.elementFromPoint(n,a);return!o||s.contains(o)?null:`<${o.localName}${o.classList.length?` class="${o.getAttribute("class")}"`:""}>`}function kn(e,{at:t,to:n}){let[a,s]=[e.querySelector(t),e.querySelector(n)];return a===s?"same":a.contains(s)?"inside":null}function kt(e){let t=a=>a instanceof Element?`<${a.localName}${a.classList.length?` class="${a.getAttribute("class")}"`:""}>`:"the page",n={edits:[],taken:0,states:[],started:null,dropped:null,effect:null};addEventListener("doc-component-edit",a=>{a.target===e&&(n.edits.push({taken:a.defaultPrevented,parts:(a.detail?.parts??[]).map(({name:s})=>s)}),a.defaultPrevented&&(n.taken+=1))}),new MutationObserver(a=>{for(let{oldValue:s}of a)n.states.push(s);n.states.push(document.documentElement.getAttribute("data-ge-save"))}).observe(document.documentElement,{attributes:!0,attributeFilter:["data-ge-save"],attributeOldValue:!0}),document.addEventListener("dragstart",a=>{n.started=t(a.target)},!0),document.addEventListener("drop",a=>{n.dropped=t(a.target)},!0),document.addEventListener("dragend",a=>{n.effect=a.dataTransfer?.dropEffect??null},!0),globalThis.__galleryTry=n}function bn(){return Object.assign(globalThis.__galleryTry,{edits:[],started:null,dropped:null,effect:null}),{taken:globalThis.__galleryTry.taken}}function bt(e){let t=[...e.querySelectorAll("input, select, textarea")].map(n=>n instanceof HTMLInputElement&&["checkbox","radio"].includes(n.type)?n.checked?"ticked":"not ticked":n.value);return{words:(e.innerText??"").replace(/\s+/g," ").trim(),fields:t}}function vn(e){let n=(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.value:e.textContent??"").replace(/\s+/g," ").trim();return n.length>40?`${n.slice(0,40)}\u2026`:n}function xn(e){let t=document.activeElement,n="";if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)try{n=t.value.slice(t.selectionStart??0,t.selectionEnd??0)}catch{}else{let s=getSelection();s&&!s.isCollapsed&&e.contains(s.anchorNode)&&(n=s.toString())}let a=n.replace(/\s+/g," ").trim();return a.length>40?`${a.slice(0,40)}\u2026`:a}function En(e){let t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)try{return t.selectionStart===null?null:t.selectionEnd===t.value.length}catch{return null}let n=getSelection();if(!n?.rangeCount||!e.contains(n.focusNode))return null;let a=document.createRange();return a.selectNodeContents(e),a.setStart(n.focusNode,n.focusOffset),a.toString().trim()===""}function Sn(e){let t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement){t.select();return}let n=document.createRange();n.selectNodeContents(e),getSelection()?.removeAllRanges(),getSelection()?.addRange(n)}function it(e){let t=document.activeElement;return t&&(t===e||e.contains(t)||t instanceof HTMLElement&&t.isContentEditable&&t.contains(e))?null:`<${t?.localName??"body"}>`}function Tn(e){let t=document.activeElement;if(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement){try{t.setSelectionRange(t.value.length,t.value.length)}catch{}return}let n=document.createRange();n.selectNodeContents(e),n.collapse(!1),getSelection()?.removeAllRanges(),getSelection()?.addRange(n)}function Nn(e,{selector:t,value:n}){let a=e.querySelector(t);if(!(a instanceof HTMLSelectElement))return{notSelect:`<${a.localName}${a.classList.length?` class="${a.getAttribute("class")}"`:""}>`};let s=[...a.options],o=s.find(i=>i.value===n)??s.find(i=>i.textContent.trim()===n);return o?a.disabled||o.disabled?{disabled:!0}:(a.focus(),o.selected=!0,a.dispatchEvent(new Event("input",{bubbles:!0})),a.dispatchEvent(new Event("change",{bubbles:!0})),{chosen:o.textContent.trim()}):{options:s.map(i=>i.value===i.textContent.trim()?i.value:`${i.value} (${i.textContent.trim()})`)}}async function Fe(e,{still:t,step:n,wait:a=0}){let s=globalThis.__galleryQueries??null,o=Date.now()+a,i=()=>s!==null&&s.pending.size>0&&Date.now()<o,l=()=>new Promise(r=>{requestAnimationFrame(r),setTimeout(r,100)});await l(),await l();let c=e.outerHTML;for(let r=0,d=Date.now()+t;r<3;){if(Date.now()>d)return null;await new Promise(f=>setTimeout(f,n));let h=e.outerHTML;i()?(r=0,d=Date.now()+t):r=h===c?r+1:0,c=h}return c}function On(e,t,{left:n,top:a,right:s,bottom:o}){let i=0;for(let[l,c,r,d]of[[e.x,t.x,n,s],[e.y,t.y,a,o]]){if(c===l)continue;let[h,f]=[(r-l)/(c-l),(d-l)/(c-l)];i=Math.max(i,Math.min(h,f))}return i*Math.hypot(t.x-e.x,t.y-e.y)}function An(e,t){let n=Math.hypot(t.x-e.x,t.y-e.y),a=c=>n===0?{x:e.x,y:e.y}:{x:e.x+(t.x-e.x)*c/n,y:e.y+(t.y-e.y)*c/n},s=Math.min(Ce,n),o=On(e,t,t)-Zt,i=o>s?o:n,l=[a(s/2),a(s)];for(let c=1;c<=et;c++)l.push(a(s+(i-s)*c/et));return i!==n&&l.push({x:t.x,y:t.y}),l}var de={press:"press",drag:"drag",key:"key",type:"typing",select:"choice"},ae=(e,{named:t,words:n})=>`${e} (${t}${n?` "${n}"`:""})`,rt=e=>Object.assign(new T(e),{unfound:!0});async function vt(e,t){let n=t.slice(0,-1);for(let a of n)await e.keyboard.down(a);await e.keyboard.press(t.at(-1));for(let a of n.toReversed())await e.keyboard.up(a)}async function Ln(e,t,n){let a=!1;for(let[s]of n.matchAll(/[\x00-\x7f]+|[^\x00-\x7f]+/gu)){if(/^[\x00-\x7f]/.test(s)){await e.keyboard.type(s);continue}a=!0;for(let o of Qt)await t.send("Input.imeSetComposition",{text:o,selectionStart:o.length,selectionEnd:o.length});await t.send("Input.insertText",{text:s})}return a?/[\x00-\x7f]/.test(n)?"its ASCII key by key and the rest through an input method":"through an input method, composed then committed":"key by key"}async function Cn(e,t,n,a){let s=await In(e,t,n,a);return n.then?(await vt(e,n.then.keys),{...s,said:`${s.said}, then ${n.then.key} pressed where the focus was`}):s}async function In(e,t,n,a){let s=async c=>{let r=await g(t.evaluate(mn,c),"the page was asked what the selector finds");if(r.invalid)throw new T(`Not a selector: ${c}.`);if(r.none)throw rt(`Nothing in the instance is ${c}${r.held.length?`: what it shows has ${r.held.join(", ")}`:": it shows nothing with a class"}.`);if(r.hidden)throw rt(`${c} finds ${r.named} in the instance, which is not shown (it has no box on the page), so a reader cannot reach it: name what it shows.`);return r},o=await s(n.at);if(n.kind==="press"){let{x:c,y:r}=o.box,d=await g(t.evaluate(yn,{selector:n.at,x:c,y:r}),"the page was asked what stands at the press");return await e.mouse.move(c,r),await e.mouse.down(),await e.mouse.up(),{said:`a press on ${ae(n.at,o)}, with the pointer at its middle`,over:d}}if(n.kind==="drag"){let c=await s(n.to),r=await g(t.evaluate(kn,{at:n.at,to:n.to}),"the page was asked where the drag ends");if(r)throw new T(`${r==="same"?`--drag and --to find the same element, ${o.named}`:`--to ${n.to} finds ${c.named}, which stands in what --drag ${n.at} finds, ${o.named}`}: a drag ends where it is dropped, on another element of the instance (another column, another row), which --to names.`);if(Math.hypot(c.box.x-o.box.x,c.box.y-o.box.y)<Ce)throw new T(`The middles of what --drag ${n.at} and --to ${n.to} find stand less than ${Ce}px apart, too near for a drag to start: name with --to where it is dropped, further off.`);let d=An(o.box,c.box);await e.mouse.move(o.box.x,o.box.y),await e.mouse.down();for(let{x:h,y:f}of d)await e.mouse.move(h,f);return await he(qt),await e.mouse.up(),{said:`a drag of ${ae(n.at,o)} to ${ae(n.to,c)}, with the pointer in ${d.length} moves, released as it comes onto it`}}if(n.kind==="select"){let c=await g(t.evaluate(Nn,{selector:n.at,value:n.value}),"the page was asked to choose the option");if(c.notSelect)throw new T(`${n.at} finds ${c.notSelect} in the instance, which is no <select>: --select names a <select> the instance draws, and the option by its value or its words.`);if(c.options)throw new T(`${n.at} has no option ${JSON.stringify(n.value)}: ${c.options.length?`its options are ${c.options.join(", ")}`:"it has no option"}.`);if(c.disabled)throw new T(`${n.at} or its option ${JSON.stringify(n.value)} is disabled, so a reader cannot choose it.`);return{said:`${JSON.stringify(c.chosen)} chosen in ${ae(n.at,o)}, as a reader picks an option`}}let i=await t.$(n.at);if(n.kind==="type"){let c=!1,r=await g(e.evaluate(vn,i),"the page was asked what the field holds");await g(e.evaluate(it,i),"the page was asked where the focus is")&&(await e.mouse.click(o.box.x,o.box.y),await g(e.evaluate(Tn,i),"the caret went to the end"),c=!0),n.replace&&await g(e.evaluate(Sn,i),"all the field holds was selected");let d=await g(e.evaluate(it,i),"the page was asked where the focus is"),h=await g(e.evaluate(xn,i),"the page was asked what is selected"),f=c||!r||n.replace||h?!0:await g(e.evaluate(En,i),"the page was asked where the caret is"),u=await Ln(e,a,n.text),w=c?", pressed first":", where the focus was",k='(--replace, or "replace": true in a step, puts them in its place)',y=n.replace?`${w}, ${r?`all it held (${JSON.stringify(r)}) selected first (--replace), so that the words took its place`:"nothing in it to replace"}`:h?`${w}, ${h===r?"all it held":"part of it"} (${JSON.stringify(h)}) selected already (a step before), so that the words took its place`:c?`, pressed first and the caret at its end${r?`: it held ${JSON.stringify(r)}, and the words went after it ${k}`:""}`:r?f===!1?`, where the focus was, the caret inside what it held (${JSON.stringify(r)}), where a step before left it (a press puts it where the pointer lands, an arrow key moves it), so that the words went in there, not after it ${k}`:f?`, where the focus was, the caret at its end: it held ${JSON.stringify(r)}, and the words went after it ${k}`:`, where the focus was: it held ${JSON.stringify(r)}, and the words went in at the caret, where a step before left it ${k}`:", where the focus was";return{said:`${JSON.stringify(n.text)} typed in ${ae(n.at,o)}${y}, ${u}`,unfocused:d,typed:!0}}await g(i.focus(),"the focus went to the element");let l=await g(e.evaluate(c=>document.activeElement===c||c.contains(document.activeElement)?null:`<${document.activeElement?.localName??"body"}>`,i),"the page was asked where the focus is");return await vt(e,n.keys),{said:`${n.key} pressed with the focus given to ${ae(n.at,o)}, as Tab gives it`,unfocused:l}}var xt=e=>fetch(`${e}/__gallery/workspace/info`,{signal:AbortSignal.timeout(2e3)}).then(t=>t.ok,()=>!1);async function jn(e,t,n){let a=Date.now();for(let s=0,o=0;;await he(100)){let{seen:i,now:l}=await g(e.evaluate(r=>({seen:globalThis.__galleryTry.states.slice(r),now:document.documentElement.getAttribute("data-ge-save")}),t),"the page was asked where saving stands"),c=l!=="saved"||i.some(r=>r!=="saved");if(c&&l==="saved")return"saved";if(l==="stopped"||l==="reloading")return l;if(s=l==="held"?s+1:0,s>=3)return"held";if(o=l==="offline"?o+1:0,o>0&&o%10===0&&!await xt(n))return"offline";if(!c&&Date.now()-a>Gt)return"unchanged";if(Date.now()-a>Ie)return l}}var Mn=e=>({held:"a card waits for a reader: someone else changed the part meanwhile, and the page held its write for the reader there, which closing the page dropped",offline:"the page could not reach the server (offline)",stopped:"the page stopped saving (stopped): the server refused its write",reloading:"the page loaded itself again (doc.html or a custom block it holds changed meanwhile)",waiting:`it waited ${Ie/1e3}s to be saved and never was`,syncing:`its save took more than ${Ie/1e3}s`})[e];function Rn(e,{parts:t,outside:n,gone:a},{gesture:s,name:o,held:i=!1,scratch:l=!1,aside:c="data-block-id aside"}){if(l)return{unverified:`${e}${!a&&t.length?`, the copy holding what the ${s} wrote, ${Y(t)}`:""}: the trial was made on a scratch copy, gone now, and ${o} holds nothing of it`};let r=n?`; outside the instance's parts -${n.removed} +${n.added} lines someone else wrote meanwhile, which stay`:"";return a?{unverified:`${e}, and ${o} holds the instance no more where it stood: someone else wrote the file meanwhile`}:t.length===0?{unverified:`${e}: ${o} is as it was${n?" in the instance's parts":""} (${c})${r}`}:i?{unverified:`${e}: what ${o} holds of ${Y(t)} is someone else's, which stays${r}`}:{unverified:`${e}: ${o} holds what the ${s} wrote, ${Y(t)}, kept (--keep)${r}`}}function Dn(e,t,{over:n,unfocused:a,refusals:s,name:o}){let i=[];return n&&i.push(`the press landed on ${n}, which stands over it there`),a&&i.push(e==="type"?`the element takes no typing (a field or an editable element), so the words went to ${a}`:`the element takes no focus (a button, a field or a tabindex), so the key went to ${a}`),t.started&&!t.dropped?i.push(`an HTML5 drag started (dragstart on ${t.started}) and nothing took its drop where it was released (dragend's dropEffect ${t.effect??"none"}): a list a card is dropped on cancels dragenter as well as dragover (preventDefault), or a release as the pointer comes onto it drops nothing`):t.dropped&&t.edits.length===0&&i.push(`it was dropped on ${t.dropped}, and no context.edit came of it`),t.edits.some(({taken:l})=>l)?i.push("context.edit was taken, and its change left what the parts hold as it was"):t.edits.length?i.push(`context.edit was called and the page refused it${s.length?`: the console says ${s.join("; ")}`:""}`):t.started||i.push(e==="type"?"no context.edit came of it: the component answers no typing there, or writes what was typed only on a key or as the field loses the focus (then Enter, --then Enter), or asked while context.canEdit() was false":`no context.edit came of it: the component answers no ${de[e]} there, or asked while context.canEdit() was false`),`the ${de[e]} wrote nothing to ${o}: ${i.join("; ")}`}async function Et(e,t){await We(e);let n={own:new Map,others:new Map,dialogs:new Map,pending:[],page:0,from:0},a=new RegExp(`/__gallery/components/${t}/kit\\.js[^:\\s)]*:(\\d+)`),s=(i,l,{at:c="",unparsed:r=!1}={})=>{if(l<n.from)return;let d=i.split(`
8
+ `)[0],h=a.exec(i)??a.exec(c);i.includes(t)||h?n.own.set(d,{line:Number(h?.[1])||null,page:l,unparsed:r&&a.test(c)}):n.others.set(d,{page:l})};e.on("request",i=>{i.isNavigationRequest()&&i.frame()===e.mainFrame()&&(n.page+=1)}),e.on("console",i=>{if(!["error","warn","warning"].includes(i.type())||/^Failed to load resource/.test(i.text()))return;let{page:l}=n;n.pending.push(Promise.all(i.args().map(c=>c.evaluate(r=>r instanceof Error?r.stack:String(r)).catch(()=>""))).then(c=>s(c.join(" ")||i.text(),l)))});let o=await ze(e,{add:i=>n.dialogs.set(i,{page:n.page})});return o.on("Runtime.exceptionThrown",({exceptionDetails:{exception:i,text:l,url:c,lineNumber:r,stackTrace:d}})=>{s(i?.description??String(i?.value??l),n.page,{at:c?`${c}:${r+1}`:"",unparsed:!d&&i?.className==="SyntaxError"})}),await o.send("Runtime.enable"),n}function _n(e){e.from=e.page;for(let t of[e.own,e.others,e.dialogs])for(let[n,{page:a}]of t)a<e.from&&t.delete(n)}var re=e=>Promise.race([Promise.all(e.pending),he(2e3)]);async function Fn(e){let t=n=>e.waitForSelector(n,{timeout:le}).catch(a=>{if(a.name==="TimeoutError")throw a;return e.waitForSelector(n,{timeout:le})});try{return await t("[data-doc-ready]"),await t("html[data-ge-editing][data-ge-save]"),await e.waitForFunction(()=>globalThis.__galleryTryEditable===!0&&document.documentElement.getAttribute("data-ge-save")==="saved",{timeout:le}),!0}catch(n){if(n.name!=="TimeoutError")throw n;return!1}}async function St(e,{where:t,id:n}){let a=await g(e.evaluateHandle($n,{instance:ft,...t}),"the page was asked for the instance"),s=await g(a.evaluate((o,{fallback:i,id:l})=>!(o instanceof Element)||o.getAttribute("data-doc-component")!==l?null:(DocKit.reveal?.(o),{fallback:o.hasAttribute(i),height:o.getBoundingClientRect().height}),{fallback:Rt,id:n}),"the page was asked for the instance");return s?(await e.setViewport({width:De,height:Math.min(Wt,Math.max(_e,Math.ceil(s.height)+240))}),await g(a.evaluate(o=>o.scrollIntoView({block:"center",behavior:"instant"})),"the instance was brought into view"),await g(a.evaluate(Fe,{still:we,step:ge,wait:$e}),"the instance held still"),{host:a,fallback:s.fallback}):null}function Hn({at:e,found:t}){return{where:{at:e},ready:Fn,saves:n=>({mark:()=>g(n.evaluate(()=>globalThis.__galleryTry.states.length),"the page was asked where saving stands"),until:(a,s)=>jn(n,a,s)}),changes:(n,a)=>on(st(n),st(a),e,t),plain:(n,a,s)=>a===n&&Se(n).changes.length>0&&s.parts.length>0,stayed:Mn,outside:"others",aside:"data-block-id aside",inside:Tt}}async function Pn(e){return g(e.evaluate(({instance:t,fields:n})=>{let a=document.activeElement;return a instanceof HTMLElement&&a.closest(t)&&a.matches(n)?(a.blur(),!0):!1},{instance:ft,fields:Dt}),"the focus left the instance's field")}async function Bn(e){await e.keyboard.down("Control"),await e.keyboard.press("z"),await e.keyboard.up("Control")}var Jn=e=>`${e}${[11,12,13].includes(e%100)?"th":["th","st","nd","rd"][e%10]??"th"}`,Un=3,Le=(e,t)=>e.length===1?`the ${de[e[0].kind]}`:`step ${t+1}`,V=e=>e.length===1?`the ${de[e[0].kind]}`:"the steps";function Zn(e,t){if(e.words!==t.words){let a=0;for(;a<e.words.length&&e.words[a]===t.words[a];)a++;let s=o=>JSON.stringify(`${a>20?"\u2026":""}${o.slice(Math.max(0,a-20),a+30)}${o.length>a+30?"\u2026":""}`);return`its words read ${s(e.words)} there and ${s(t.words)} here`}let n=e.fields.findIndex((a,s)=>a!==t.fields[s]);if(n>=0||e.fields.length!==t.fields.length){let a=n>=0?n:Math.min(e.fields.length,t.fields.length);return`its field ${a+1} (of ${e.fields.length}) holds ${JSON.stringify(e.fields[a]??null)} there and ${JSON.stringify(t.fields[a]??null)} here`}return null}var ct=["ticked","not ticked"],qn=["true","false","checked","done"],Wn={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "},Me=e=>new Set(e.normalize("NFKC").toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),lt=e=>e.replace(/<[^>]*>/g," ").replace(/"(?:[^"\\]|\\.)*"\s*:/g," ").replace(/&(?:#(\d+)|#x([\da-f]+)|([a-z]+));/gi,(t,n,a,s)=>{let o=n?Number(n):a?Number.parseInt(a,16):null;return o!==null?o<=1114111?String.fromCodePoint(o):t:Wn[s.toLowerCase()]??t}),dt=e=>qn.map(t=>(e.join(`
9
+ `).toLowerCase().match(new RegExp(`\\b${t}\\b`,"g"))??[]).length).join();function Gn(e){let t=new Set,n=!1;for(let{parts:a}of e)for(let{runs:s=[]}of a)for(let{removed:o,added:i}of s){let[l,c]=[Me(o.map(lt).join(`
10
+ `)),Me(i.map(lt).join(`
11
+ `))];for(let r of c)l.has(r)||t.add(r);for(let r of l)c.has(r)||t.add(r);dt(o)!==dt(i)&&(n=!0)}return{words:t,ticks:n}}function Kn(e,t,n){let a=({words:h,fields:f})=>Me([h,...f.filter(u=>!ct.includes(u))].join(" ")),[s,o]=[a(e),a(t)],i=[...[...s].filter(h=>!o.has(h)),...[...o].filter(h=>!s.has(h))],l=h=>/[^\x00-\x7f]/.test(h),c=h=>[...n.words].some(f=>f===h||[h,f].every(u=>[...u].length>=2)&&[f,h].some(u=>l(u))&&(h.includes(f)||f.includes(h))),r=i.filter(c),d=h=>JSON.stringify(h.fields.filter(f=>ct.includes(f)));return n.ticks&&d(e)!==d(t)&&r.push("a box ticked"),r}async function Vn(e,{root:t,address:n,fresh:a,steps:s,keep:o,file:i,name:l,line:c,found:r,out:d,host:h}){let f=await g(e.createBrowserContext(),"a browser context opened"),u=await g(f.newPage(),"a tab opened"),w=await g(Et(u,r.id),"the tab was set to listen"),k=h.saves(u),y=[w],p={problems:[],notes:[],steps:[]},m=($,O=`${l}:${c}`)=>p.problems.push({where:O,what:$}),L=!o,D=L?`the copy of ${l}`:l,_=new URL(n).origin,C=0,F=0;u.on("request",$=>{!$.isNavigationRequest()||$.frame()!==u.mainFrame()||(C+=1,F=Date.now())});let M=null,H=null,S=async()=>h.changes(H,await N.readFile(i,"utf8").catch(()=>"")),b=($,O,v=!1)=>({...p,unverified:Rn($,O,{gesture:s.length===1?de[s[0].kind]:"steps",name:l,held:v,scratch:L,aside:h.aside}).unverified}),j=h.stayed,Z=await g(u.createCDPSession(),"the tab opened a session");await g(u.evaluateOnNewDocument(()=>addEventListener("doc-editable",()=>{globalThis.__galleryTryEditable=!0})),"the tab was set to tell when the page takes edits"),await g(u.setViewport({width:De,height:_e}),"the window was sized"),await g(u.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came");try{await g(u.goto(n,{waitUntil:"load",timeout:0}),"the page opened",Oe);let $=null,O=null;for(let x=1;!$;x++){let E=C;try{if(!await h.ready(u))return{...p,unverified:`the page did not come to edit in ${le/1e3}s, so nothing was tried`};if($=await St(u,{where:h.where,id:r.id}),!$)return{...p,unverified:`the page does not hold the instance where ${l} has it (${l} changed meanwhile?), so nothing was tried`};if(await he(Math.max(0,await cn(t,L?null:i)-Date.now())),$.fallback&&(O=await gn({root:t,id:r.id,origin:_,loadedAt:F,loaded:()=>C!==E})),C!==E)throw new Error("the page loaded itself again");if($.fallback)break;if(H=await N.readFile(i,"utf8"),await g($.host.evaluate(kt),"the page was asked to listen"),C!==E)throw new Error("the page loaded itself again")}catch(I){if(C===E||x===Un)throw I;$=null,_n(w)}}let{host:v}=$;if($.fallback){await re(w);let x=[...w.own].map(([E,{line:I,unparsed:z}])=>({words:`${E}${I?` (kit.js:${I})`:""}`,unparsed:z}));return w.own.clear(),m(un(r.id,{said:x.map(({words:E})=>E),unparsed:x.find(({unparsed:E})=>E)?.words??null,...O})),await ht(v,p,d,h.framed)}M=C;let P=H,X=null;for(let[x,E]of s.entries()){let I=Le(s,x),{taken:z}=await g(u.evaluate(bn),"the page was asked to listen"),fe=await k.mark(),W=await Cn(u,v,E,Z),Q=await k.until(fe,_),G=await N.readFile(i,"utf8").catch(()=>""),J=h.changes(P,G);if(p.steps.push({said:W.said,parts:J.parts,outside:J.outside,plain:h.plain(H,P,J),taken:z}),C>M)return b(`after ${I}, ${j("reloading")}`,await S());if(j(Q))return b(`after ${I}, ${j(Q)}`,await S(),Q==="held");if(J.gone)return b(`after ${I}`,await S());X={step:E,gestured:W,heard:await g(u.evaluate(()=>globalThis.__galleryTry),"the page was asked what it heard")};for(let{name:ve,how:R}of J.parts)R&&p.notes.push({where:`${l}:${c}`,what:`${I}'s write lays the part ${ve} out anew (${R}): ${Ge}`});J.parts.length&&(p.steps.at(-1).before=P),P=G}await ht(v,p,d,h.framed);let B=await g(v.evaluate(Fe,{still:we,step:ge,wait:$e}).then(()=>v.evaluate(bt)),"the instance held still"),q=p.steps.filter(({parts:x})=>x.length),be=p.steps.map(x=>x.outside).filter(Boolean);if(h.outside==="problem"?p.steps.forEach((x,E)=>{x.outside&&m(`${Le(s,E)} changed ${l} outside ${h.outsideSaid(x.outside)}`)}):be.length&&(p.others={removed:be.reduce((x,{removed:E})=>x+E,0),added:be.reduce((x,{added:E})=>x+E,0)}),q.length===0){await re(w);let x=[...w.own.keys()].filter(I=>I.includes("context.edit"));for(let I of x)w.own.delete(I);let E=Dn(X.step.kind,X.heard,{...X.gestured,refusals:x,name:D});return m(s.length===1?E:`none of the ${s.length} steps wrote anything to ${D}; of the last, step ${s.length}, ${E}`),p}if(!o){let x=await k.mark();if(await Pn(u)){let W=await k.until(x,_);if(C>M)return b(`as the focus left the instance's field, ${j("reloading")}`,await S());if(j(W))return b(`as the focus left the instance's field, ${j(W)}`,await S(),W==="held")}let E=await g(u.evaluate(()=>globalThis.__galleryTry.taken),"the page was asked what it took"),I=s.length===1,z=0,fe=0;e:for(let[W,Q]of[...q.entries()].toReversed()){let G=Le(s,p.steps.indexOf(Q)),J=Math.max(1,(q[W+1]?.taken??E)-Q.taken),ve=R=>I?R===1?"one Ctrl+Z":`${R} Ctrl+Z`:`${R===1?"the Ctrl+Z":`${R} Ctrl+Z`} for ${G}`;for(let R=1;;R++){let oe=R===1?`the Ctrl+Z for ${G}`:`the ${Jn(R)} Ctrl+Z for ${G}`,At=await k.mark();await Bn(u);let ue=await k.until(At,_),Lt=await N.readFile(i,"utf8").catch(()=>""),xe=h.changes(Q.before,Lt);if(C>M)return b(`after ${oe}, ${j("reloading")}`,await S());if(j(ue))return b(`after ${oe}, ${j(ue)}`,await S(),ue==="held");if(xe.gone)return b(`after ${oe}`,await S());if(ue==="unchanged"){m(`${R===1&&I?"one Ctrl+Z":oe} wrote nothing, so ${D} keeps what ${G} wrote: a reader's undo does not take it back (the component keeps Ctrl+Z from the page where the focus is, or wrote by no context.edit)`);break e}if(xe.parts.length===0){fe+=R;break}if(R>=J){m(`after ${ve(R)}${J>1?", one for each write the page took of it,":""} ${D} is not as it was${I?"":` before ${G}`}, ${Y(xe.parts)} still differing: a reader's undo does not give it back (the component writes again as it hears the part change)`);break e}}z+=1}z===q.length&&Object.assign(p,{undone:z,presses:fe})}if(p.problems.length)return p;await pe(u.close());let Ot=x=>p.notes.push({where:`${l}:${c}`,what:x}),ee=await Qn(f,{...await a(P),host:h,found:r,after:B,written:Gn(q),out:d,hearings:y,problem:m,note:Ot,called:V(s)});return p.readBack=ee.back,p.aside=ee.aside??!1,ee.picture&&(p.fresh=ee.picture),ee.unverified?p.unverified=`${ee.unverified}, so it was not read back`:p.others&&(p.unverified=`someone else wrote ${l} meanwhile, outside the instance's parts (the user's page, an Agent), which stays: try it again once the file holds still`),p}catch($){if($ instanceof T){if(p.steps.length&&($.made=p),!$.unfound||(await re(w),w.own.size===0&&w.dialogs.size===0))throw $;return m(`${$.message[0].toLowerCase()}${$.message.slice(1).replace(/\.$/,"")}; its component did not draw it, and the console says why`),p}let O=M===null?null:await S();if(O&&C>M)return b(`after a gesture, ${j("reloading")}`,O);if(await Ye(e)){let v=`the browser went while waiting until ${$.doing??"the page answered"}`;return O?b(v,O):{...p,unverified:`${v}, so nothing was tried`}}return $.stuck?m(`the page stopped answering while waiting until ${$.doing}: a script that never ends, or a component that changes what it hears`,"the page"):m(`the trial stopped: ${ne($)}`,"the page"),p}finally{let $=new Set;for(let O of y){await re(O);for(let[v,{line:P}]of O.own)!$.has(v)&&$.add(v)&&p.problems.push({where:P?`kit.js:${P}`:"the page",what:`the console says ${v}`});for(let v of O.others.keys())!$.has(v)&&$.add(v)&&p.notes.push({where:"the page",what:`the console says ${v}`});for(let v of O.dialogs.keys())!$.has(v)&&$.add(v)&&p.problems.push({where:"the page",what:`it opened a dialog (${v}), which stops a reader's page until it is answered: show what it says in the instance`})}await pe(f.close())}}function zn(e,t,n,a){console.log(`FAIL ${e}: ${Qe(t)}, so nothing was tried and the browser was closed${a?"":`; the copy of ${n} was taken away`}. A script that never ends does this, and so may a browser that stalled: run the command once more`),process.exitCode=1}async function Qn(e,{address:t,file:n,host:a,found:s,after:o,written:i,out:l,hearings:c,problem:r,note:d,called:h}){let f=await g(e.newPage(),"a tab opened");c.push(await g(Et(f,s.id),"the fresh tab was set to listen"));let u=a.saves(f),w=c.at(-1),k=new URL(t).origin;await g(f.evaluateOnNewDocument(()=>addEventListener("doc-editable",()=>{globalThis.__galleryTryEditable=!0})),"the fresh tab was set to tell when the page takes edits"),await g(f.setViewport({width:De,height:_e}),"the window was sized"),await g(f.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came");let y=`a fresh page of what ${h} wrote`,p={back:!1};try{let m=await N.readFile(n,"utf8");if(await g(f.goto(t,{waitUntil:"load",timeout:0}),"the fresh page opened",Oe),!await a.ready(f))return{back:!1,unverified:`${y} did not come to edit in ${le/1e3}s`};let L=await St(f,{where:a.where,id:s.id});if(!L)return r(`${y} does not hold the instance where the file has it: what the steps wrote is no instance of ${s.id} as the page reads it`),p;if(L.fallback){await re(w);let b=[...w.own].map(([j,{line:Z}])=>`${j}${Z?` (kit.js:${Z})`:""}`);return w.own.clear(),r(`${y} shows the instance in its fallback, what it holds read-only: its component failed as the page started it, ${b.length?`and the console says ${b.join("; ")}`:"and the console said nothing of it"}: what ${h} wrote is what its mount cannot read`),p}await g(L.host.evaluate(kt),"the fresh page was asked to listen");let D=await u.until(await u.mark(),k);if(D==="offline")return{back:!1,unverified:`${y}: ${a.stayed(D)}`};if(D!=="unchanged"&&D!=="saved")return r(`${y}: ${a.stayed(D)??D}`),p;let _=a.changes(m,await N.readFile(n,"utf8").catch(()=>""));if(_.gone)return{back:!1,unverified:`${y}: its file holds the instance no more where it stood (someone else wrote it meanwhile)`};if(D==="saved"||_.parts.length)return r(`${y} writes ${_.parts.length?Y(_.parts):"it again"} with no gesture as it opens, so that a page would write each time it opened: draw what the parts hold as they are, and write on a gesture alone`),p;let C=await g(L.host.evaluate(Fe,{still:we,step:ge,wait:$e}).then(()=>L.host.evaluate(bt)),"the fresh page's instance held still"),F=Zn(o,C);if(!F)return{back:!0};let M=A.join(l,"fresh.png");await g(L.host.screenshot({path:M}),"the fresh page's instance was pictured").catch(()=>{});let H=`${y} shows the instance otherwise than the page did after ${h.replace(/^the steps$/,"the last step")}: ${F}`,S=Kn(o,C,i);return S.length?(r(`${H} (the fresh page's picture: ${K(M)}), and what differs is of what ${h} wrote (${S.slice(0,3).map(b=>b==="a box ticked"?b:JSON.stringify(b)).join(", ")}). What it draws of what it wrote is to come from its parts alone, read as it wrote them: a value kept in memory, or written in a form its mount does not read, is gone on the next page`),{...p,picture:M}):(d(`${H}; none of it is of what ${h} wrote, and a fresh page keeps no filter or tab chosen, no editor left open, no words typed and not committed (--then Enter commits them), and need not. Its picture: ${K(M)}. What a reader keeps belongs in a part`),{back:!0,aside:!0,picture:M})}catch(m){return await xt(k)?(m.stuck?r(`${y} stopped answering while waiting until ${m.doing}: a script that never ends, or a component that changes what it hears`,"the page"):r(`${y} could not be read back: ${ne(m)}`,"the page"),p):{back:!1,unverified:`the server stopped answering as ${y} opened`}}finally{await pe(f.close())}}async function ht(e,t,n,a=null){let s=A.join(n,"after.png");try{let o=a?await g(e.evaluateHandle(a),"the instance's frame was found"):e;await g(o.screenshot({path:s}),"the instance was pictured"),t.picture=s}catch(o){if(o.stuck)throw o}return t}var U={gesture:"Gesture: ",step:"Step ",wrote:"Wrote: ",undone:"Undone: ",kept:"Kept (--keep): ",readBack:"Read back: ",picture:"Picture of the instance after "},Tt="nothing outside the instance changed (data-block-id aside)",Yn="open it: no one has looked at it for you";function Xn({slug:e,name:t,steps:n,keep:a,host:s=null},o){let i=n.length>1,l=a?t:`the copy of ${t}`,c=s?.aside??"data-block-id aside",r=Nt({name:t,several:i,keep:a,host:s},o.steps),d=o.steps.filter(({parts:p})=>p.length),h=a&&d.some(({plain:p})=>p)?", its plain HTML the kit's markup":"",f=o.presses??o.undone;if(a&&d.length)r.push(`${U.kept}${t} holds what ${V(n)} wrote`);else if(o.undone){let p=i?f===o.undone?`${f} Ctrl+Z, one for each step that wrote, the last first, each giving ${l} back as it was before its step`:`${f} Ctrl+Z for the ${o.undone} step${o.undone===1?"":"s"} that wrote, one for each write the page took, the last first, each step's giving ${l} back as it was before it`:f===1?`one Ctrl+Z, and ${l} is as it was`:`${f} Ctrl+Z, one for each write the page took of ${V(n)}, and ${l} is as it was`;r.push(`${U.undone}${p} (${c}${h})`)}o.readBack&&r.push(`${U.readBack}${a?`${t} opened again in a fresh page`:`a fresh page of what ${V(n)} wrote (a copy of it)`}: the instance mounts, writes nothing as it opens, and shows what the page showed after ${i?"the last step":V(n)}${o.aside?` of what ${i?"they":"it"} wrote; what else the page showed there, which nothing wrote, it does not (the note)`:""}`);for(let{where:p,what:m}of o.problems)r.push(` FAIL ${p}: ${m}`);for(let{where:p,what:m}of o.notes)r.push(` note ${p}: ${m}`);o.picture&&r.push(`${U.picture}${i?"the last step":V(n)}: ${K(o.picture)} (${Yn})`);let u=[o.picture,o.fresh].filter(Boolean);u.length&&r.push(Xe([{folder:A.dirname(u[0]),files:u}]));let w=o.problems.length;if(w)return{lines:[...r,`FAIL ${e}: ${w} problem${w===1?"":"s"}`],code:1};if(o.unverified)return{lines:[...r,`UNVERIFIED ${e}: ${o.unverified}`],code:3};let k=[...new Set(d.flatMap(({parts:p})=>p.map(({name:m})=>m)))].join(" and "),y=a?", kept (--keep)":`, ${f===1?"one Ctrl+Z":`${f} Ctrl+Z`} took ${i?"them":"it"} back`;return{lines:[...r,`OK ${e}: ${V(n)} wrote ${k}${y}, and a fresh page read ${i?"them":"it"} back${a?"":`; ${t} not written (a scratch copy)`}`],code:0}}function Nt({several:e,keep:t,host:n=null},a){let s=[];for(let[o,i]of a.entries()){if(s.push(e?`${U.step}${o+1}: ${i.said}`:`${U.gesture}${i.said}`),i.parts.length===0){e&&s.push(`${U.wrote}nothing`);continue}let l=t&&i.plain?"; and the page wrote the document's plain HTML as the kit's markup, as its first save of an edit does (gallery check and gallery export say what, by line, once), which stays":"",c=i.outside?n?.outside==="problem"?`; and outside ${n.outsideSaid(i.outside)}`:`; outside the instance's parts -${i.outside.removed} +${i.outside.added} lines someone else wrote meanwhile (the user's page, an Agent), which stay`:`; ${n?.inside??Tt}`;s.push(`${U.wrote}${Y(i.parts)}${c}${l}`,...rn(i.parts))}return s}function ea({name:e,steps:t,keep:n,host:a=null},s){let o=s.steps.length,i=o===1?"step 1":`steps 1 to ${o}`,l=s.steps.some(({parts:d})=>d.length),c=Nt({name:e,several:t.length>1,keep:n,host:a},s.steps),r=`step ${o+1} was not made, for the mistake below`;return n?c.push(l?`${U.kept}${e} holds what ${i} wrote, which stays; ${r}`:`Not made: ${r}; ${i} wrote nothing to ${e}`):c.push(`Not made: ${r}; ${i} ${l?"wrote to":"made"} a scratch copy, gone now, and ${e} holds nothing of ${o===1?"it":"them"}`),c}async function ka(e,{named:t,values:n,seconds:a={},keep:s,replace:o=!1}){let i=await Yt(n,a,o),l=i?[i]:null;if(t.length===0)throw new T("Name the document: gallery block try <slug> [<instance id>] and the gesture.");if(t.length>2)throw new T("gallery block try takes a document and an instance's id at most.");let c=n.has("--steps")?A.resolve(n.get("--steps")):null,r=l??await Xt(c),{slug:d,block:h}=await Pe(t[0]),f=Pt(d,e),u=Bt(f),w=u.html,k=await N.readFile(w,"utf8").catch(()=>null);k===null&&(console.error(`No document "${d}": ${K(w)} does not exist (gallery list lists those there are).`),process.exit(1));let y=wt(k);y.length===0&&(console.error(`${d} holds no instance of a custom block (an element with ${ke}): gallery block list says which there are, and gallery block show <id> how to write one.`),process.exit(1));let p=A.basename(w),m=nn(y,t[1]??h,{slug:d,name:p}),{id:L,line:D}=y[m],_=Ee(e),C=_.packages.get(L);if(!C){let S=_.problems.get(L);console.error(S?.off?`${L} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its instances show what they hold, read-only, so a reader can do nothing with them.`:S?`${L} does not load, so its instances show what they hold, read-only: gallery block check ${L} says why.`:`No component ${L} in this workspace, so its instance shows what it holds, read-only: gallery block list says which there are.`),process.exit(1)}console.log(`${L} in ${d}, ${gt(y[m],p)}: ${K(w)}`),c&&console.log(`Steps: ${r.length} from ${K(c)}, made one after another in one page`);let F=await Je({slug:d,command:`gallery block try ${d}`});if(!F.ok){console.log(`UNVERIFIED ${d}: ${F.message}`),process.exitCode=3;return}await dn(e);let M=[],H=async S=>{let b=await ln(e,{directory:f,files:u,text:S});return M.push(b.slug),b};try{let S=s?{slug:d,file:w}:await H(k),b=Te(F.port,S.slug);console.log(s?`Page: ${b} (the document's page alone, editable: the Agent's own; --keep: what ${V(r)} write stays in ${p}; the server runs on after this command)`:`Page: ${b} (a scratch copy of ${d}, its page alone, editable, made for this trial and gone at its end: ${p} is not written, and no page of the user's shows the trial; the server runs on after this command)`);let j=Ue();if(!j){console.log(`UNVERIFIED ${d}: no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so nothing was tried`),process.exitCode=3;return}let Z;try{Z=await qe({executablePath:j,args:Ze()})}catch(O){console.log(`UNVERIFIED ${d}: the browser ${j} did not start, twice, each time with a fresh profile (${ne(O)}; GALLERY_BROWSER=<its executable> picks another), so nothing was tried`),process.exitCode=3;return}let $=A.join(se(e).qa,d,"try");try{await N.rm($,{recursive:!0,force:!0}),await N.mkdir($,{recursive:!0});let O=async B=>{if(s)return{address:b,file:S.file};let q=await H(B);return{address:Te(F.port,q.slug),file:q.file}},v;try{v=await Vn(Z.browser,{root:e,address:b,fresh:O,steps:r,keep:s,file:S.file,name:p,line:D,found:C,out:$,host:Hn({at:m,found:C})})}catch(B){if(B instanceof T&&B.made&&console.log(ea({name:p,steps:r,keep:s},B.made).join(`
12
+ `)),B.stuck)return zn(d,B,p,s);throw B}let{lines:P,code:X}=Xn({slug:d,name:p,steps:r,keep:s},v);console.log(P.join(`
13
+ `)),process.exitCode=X}finally{await Z.close()}}finally{for(let S of M)await $t(e,S)}}export{le as a,Gt as b,Ie as c,at as d,ie as e,ut as f,Yt as g,Xt as h,wt as i,gt as j,nn as k,an as l,st as m,ot as n,on as o,rn as p,cn as q,ln as r,$t as s,dn as t,fn as u,un as v,gn as w,Fe as x,An as y,Rn as z,Dn as A,Et as B,_n as C,Hn as D,V as E,Zn as F,Me as G,Gn as H,Kn as I,Vn as J,zn as K,U as L,Tt as M,Yn as N,Xn as O,ea as P,ka as Q};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{refusal as ct,said as at}from"../browser/shared/i18n/index.mjs";import{SITE_ICON_BYTES as it,SITE_ICON_TYPES as lt,loginTitle as ut}from"../browser/shared/web-links.mjs";import $ from"node:http";import z from"node:https";import Y from"node:net";import S from"node:tls";import P from"node:zlib";import{Readable as B}from"node:stream";import{execFile as j}from"node:child_process";import{promisify as M}from"node:util";var A=M(j),X=/^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[?::1\]?$|0\.0\.0\.0)/i;function K(t,e){let n=t.toLowerCase();for(let r of e){let o=r.trim().toLowerCase();if(!o)continue;if(o==="*")return!0;if(o==="<local>"){if(!n.includes("."))return!0;continue}if(o.includes("*")){if(new RegExp(`^${o.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`).test(n))return!0;continue}let s=o.replace(/^\./,"").replace(/:\d+$/,"");if(n===s||n.endsWith(`.${s}`))return!0}return!1}var N=t=>/^[a-z]+:\/\//i.test(t)?t:`http://${t}`;function V(t=process.env){let e=t.HTTPS_PROXY||t.https_proxy||t.HTTP_PROXY||t.http_proxy||t.ALL_PROXY||t.all_proxy;return e?{url:N(e),bypass:(t.NO_PROXY||t.no_proxy||"").split(",")}:null}async function J(){let{stdout:t}=await A("reg",["query","HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"],{windowsHide:!0,timeout:3e3}),e=o=>new RegExp(`^\\s*${o}\\s+REG_\\w+\\s+(.*)$`,"mi").exec(t)?.[1]?.trim();if(Number.parseInt(e("ProxyEnable")||"0",16)!==1)return null;let n=e("ProxyServer");if(!n)return null;let r=n;if(n.includes("=")){let o=Object.fromEntries(n.split(";").map(s=>s.split("=").map(c=>c.trim())));if(r=o.https||o.http,!r)return null}return{url:N(r),bypass:(e("ProxyOverride")||"").split(";")}}async function Q(){let{stdout:t}=await A("scutil",["--proxy"],{timeout:3e3}),e=r=>new RegExp(`\\b${r}\\s*:\\s*(\\S+)`).exec(t)?.[1];if(e("HTTPSEnable")!=="1"||!e("HTTPSProxy"))return null;let n=[...t.matchAll(/^\s*\d+\s*:\s*(\S+)\s*$/gm)].map(r=>r[1]);return{url:`http://${e("HTTPSProxy")}:${e("HTTPSPort")||80}`,bypass:n}}var C=null,I=0;async function Z(){let t=V();if(t)return t;if(C!==null&&Date.now()-I<3e4)return C||null;let e=null;try{process.platform==="win32"?e=await J():process.platform==="darwin"&&(e=await Q())}catch{e=null}return C=e||!1,I=Date.now(),e}async function tt(t){let e;try{e=new URL(t).hostname}catch{return null}if(X.test(e))return null;let n=await Z();return n&&!K(e,n.bypass)&&/^http:/i.test(n.url)?n.url:null}var R=t=>t.username?{"proxy-authorization":`Basic ${Buffer.from(`${decodeURIComponent(t.username)}:${decodeURIComponent(t.password)}`).toString("base64")}`}:{};function _(t,e,n,r){return new Promise((o,s)=>{let c=$.request({host:t.hostname,port:t.port||80,method:"CONNECT",path:`${e}:${n}`,headers:{host:`${e}:${n}`,...R(t)},signal:r});c.once("connect",(a,l)=>{a.statusCode===200?o(l):(l.destroy(),s(Object.assign(new Error(`the proxy answered ${a.statusCode}`),{proxyAnswered:a.statusCode})))}),c.once("error",s),c.end()})}function et(t,{method:e,headers:n,signal:r},o){let s=new URL(t),c=new URL(o),a={"accept-encoding":"gzip, deflate, br",...n};return new Promise((l,i)=>{let u=f=>{f.once("response",l),f.once("error",i),f.end()};if(s.protocol==="http:"){u($.request({host:c.hostname,port:c.port||80,method:e,path:s.href,headers:{...a,host:s.host,...R(c)},signal:r}));return}_(c,s.hostname,s.port||443,r).then(f=>{u(z.request(s,{method:e,headers:{...a,host:s.host},defaultPort:443,signal:r,createConnection:()=>S.connect({socket:f,servername:s.hostname,ALPNProtocols:["http/1.1"]})}))},i)})}function T(t,e){let n=new Headers;for(let[l,i]of Object.entries(t.headers))n.set(l,Array.isArray(i)?i.join(", "):String(i));let r=(t.headers["content-encoding"]||"").toLowerCase(),o={gzip:P.createGunzip,"x-gzip":P.createGunzip,deflate:P.createInflate,br:P.createBrotliDecompress}[r],s=o?t.pipe(o()):t;o&&(t.on("error",l=>s.destroy(l)),n.delete("content-encoding"),n.delete("content-length"));let c=[101,204,205,304].includes(t.statusCode);c&&t.resume();let a=new Response(c?null:B.toWeb(s),{status:t.statusCode,statusText:t.statusMessage,headers:n});return Object.defineProperty(a,"url",{value:e}),a}async function nt(t,{method:e="GET",headers:n={},signal:r}={},o){for(let s=0;;s++){let c=await et(t,{method:e,headers:n,signal:r},o),a=c.headers.location;if([301,302,303,307,308].includes(c.statusCode)&&a&&s<10){c.resume(),t=new URL(a,t).href,c.statusCode===303&&(e="GET");continue}return T(c,t)}}var v=t=>t.includes(":")?`[${t}]`:t,ot=t=>/^[\d.]+$/.test(t)||t.includes(":");function Pt(t,{address:e,proxy:n=null,headers:r={},signal:o,connect:s=(a,l)=>Y.connect({host:a,port:l}),ca:c=null}){let a=Number(t.port)||(t.protocol==="https:"?443:80),l=e===null;if(l&&!(n&&t.protocol==="https:"))return Promise.reject(new Error("fetchPinned: only an https address is handed to a proxy by its name"));let i=ot(t.hostname)?void 0:t.hostname,u={"accept-encoding":"gzip, deflate, br",...r,host:t.host},f=`${t.pathname}${t.search}`,L=l||c?[...S.rootCertificates,...c?[c]:[]]:null,b=d=>S.connect({socket:d,servername:i,ALPNProtocols:["http/1.1"],...L?{ca:L}:{},...l?{rejectUnauthorized:!0}:{}}),F=d=>new Promise((x,m)=>{if(o?.aborted)return d.destroy(),m(o.reason);let h=b(d),g=()=>h.destroy(o.reason);o?.addEventListener("abort",g,{once:!0}),h.on("error",p=>{o?.removeEventListener("abort",g),m(p)}),h.once("close",()=>m(new Error("the connection closed before TLS was done"))),h.once("secureConnect",()=>{if(o?.removeEventListener("abort",g),l&&!h.authorized){let p=Object.assign(new Error(`the certificate failed (${h.authorizationError})`),{code:String(h.authorizationError)});return h.destroy(),m(p)}x(h)})});return new Promise((d,x)=>{let m=p=>{let w=(t.protocol==="https:"?z:$).request({method:"GET",signal:o,...p});w.once("response",D=>d(T(D,t.href))),w.once("error",x),w.end()};if(!n){m({host:e,port:a,path:f,headers:u,createConnection:()=>t.protocol==="https:"?b(s(e,a)):s(e,a)});return}let h=new URL(n),g=p=>x(p?.proxyAnswered||o?.aborted?p:Object.assign(p??new Error("the proxy was not reached"),{proxyFailed:!0}));if(t.protocol==="http:"){let p=$.request({host:h.hostname,port:h.port||80,method:"GET",path:`http://${v(e)}:${a}${f}`,headers:{...u,...R(h)},agent:!1,signal:o});p.once("response",w=>d(T(w,t.href))),p.once("error",g),p.end();return}_(h,l?t.hostname:v(e),a,o).then(p=>F(p).then(w=>m({host:l?t.hostname:e,port:a,path:f,headers:u,createConnection:()=>w}),x),g)})}async function rt(t,e={}){let n=await tt(t);if(n)try{return await nt(t,e,n)}catch(r){if(e.signal?.aborted)throw r}return fetch(t,e)}var st="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36";async function y(t,{timeout:e=1e4,accept:n="*/*",headers:r={},unreachable:o="\u6253\u4E0D\u5F00\u8FD9\u4E2A\u7F51\u9875",protocols:s=["http:","https:"]}={}){let c;try{c=new URL(t)}catch{throw Object.assign(new Error("\u4E0D\u662F\u7F51\u5740"),{reason:"url"})}if(!s.includes(c.protocol))throw Object.assign(new Error("\u53EA\u652F\u6301 http(s) \u7F51\u5740"),{reason:"url"});return rt(c,{redirect:"follow",signal:AbortSignal.timeout(e),headers:{"user-agent":st,accept:n,...r}}).catch(()=>{throw Object.assign(new Error(o),{reason:"download"})})}async function E(t,e){let n=t.body.getReader(),r=[],o=0;for(;;){let{done:s,value:c}=await n.read();if(s)break;if(r.push(Buffer.from(c)),o+=c.length,o>=e){n.cancel().catch(()=>{});break}}return Buffer.concat(r)}async function O(t,e){let n=await E(t,e+1);return n.length<=e?n:null}var ft={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "},H=t=>t.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi,(e,n)=>{if(n[0]==="#"){let r=n[1]==="x"||n[1]==="X"?parseInt(n.slice(2),16):Number(n.slice(1));return Number.isFinite(r)&&r>0&&r<=1114111?String.fromCodePoint(r):e}return ft[n.toLowerCase()]??e}),U=t=>H(String(t??"")).replace(/\s+/g," ").trim();function pt(t){let e={};for(let n of t.matchAll(/([\w:-]+)\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+))/g))e[n[1].toLowerCase()]=n[3]??n[4]??n[5]??"";return e}function k(t,e){let n=/charset=([\w-]+)/i.exec(e??"")?.[1];n||(n=/<meta[^>]+charset=["']?([\w-]+)/i.exec(t.subarray(0,4096).toString("latin1"))?.[1]);try{return new TextDecoder(n||"utf-8").decode(t)}catch{return new TextDecoder("utf-8").decode(t)}}function q(t,e){let n=t.search(/<\/head>/i),r=n>0?t.slice(0,n):t.slice(0,3e5),o={},s=[];for(let[i]of r.matchAll(/<(meta|link)\b[^>]*>/gi)){let u=pt(i);if(/^<meta/i.test(i)){let f=(u.property||u.name||u.itemprop||"").toLowerCase();f&&u.content!==void 0&&!(f in o)&&(o[f]=u.content)}else u.rel&&u.href&&/(^|\s)(icon|shortcut icon|apple-touch-icon)(\s|$)/i.test(u.rel)&&s.push({rel:u.rel.toLowerCase(),href:u.href})}let c=i=>{try{return i?new URL(H(i),e).href:null}catch{return null}},a=/<title[^>]*>([\s\S]*?)<\/title>/i.exec(r)?.[1],l=s.find(i=>/(^|\s)icon(\s|$)/.test(i.rel))??s.find(i=>i.rel.includes("icon"));return{title:U(o["og:title"]||o["twitter:title"]||a||"").slice(0,300),description:U(o["og:description"]||o["twitter:description"]||o.description||"").slice(0,600),icon:c(l?.href)||c("/favicon.ico"),cover:c(o["og:image"]||o["og:image:url"]||o["og:image:secure_url"]||o["twitter:image"]||o["twitter:image:src"])}}async function ht(t){if(!t)return null;try{let e=await y(t,{timeout:8e3,accept:"image/*,*/*;q=0.5",protocols:["http:","https:","data:"]}),n=(e.headers.get("content-type")??"").split(";")[0].trim();if(!e.ok||!/^image\//.test(n))return null;let r=await O(e,5*1024*1024);return r?.length?r:null}catch{return null}}async function Rt(t){try{let e=await y(t,{timeout:8e3,accept:"text/html,*/*;q=0.8"});if(e.body?.cancel().catch(()=>{}),[401,403].includes(e.status)||W(e.url))return{frameable:!0,reason:"auth"};if(!e.ok)return{frameable:!0,reason:"unknown"};let n=(e.headers.get("x-frame-options")??"").toLowerCase(),r=(e.headers.get("content-security-policy")??"").split(",").map(o=>/(?:^|;)\s*frame-ancestors\s+([^;]*)/i.exec(o)?.[1]?.trim().toLowerCase()).filter(o=>o!==void 0);return r.length?r.some(o=>o==="'none'"||o==="'self'")?{frameable:!1,reason:"frame-ancestors"}:{frameable:!0,...r.every(o=>o==="*")?{}:{reason:"unknown"}}:n.split(",").some(o=>/^(deny|sameorigin)$/.test(o.trim()))?{frameable:!1,reason:"x-frame-options"}:{frameable:!0}}catch(e){return e.reason==="url"?{frameable:!1,reason:"url"}:{frameable:!0,reason:"unknown"}}}function W(t){try{let e=new URL(t);return/^(?:login|signin|passport|sso)\./i.test(e.hostname)||/\/(?:login|signin|sign-in|oauth2\/challenge)(?:[/.]|$)/i.test(e.pathname)}catch{return!1}}async function Ot(t){try{let e=await y(t,{accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8",headers:{"accept-language":"zh-CN,zh;q=0.9,en;q=0.8"}});if([401,403].includes(e.status)||W(e.url))return e.body?.cancel().catch(()=>{}),{title:"",reason:"auth"};let n=e.headers.get("content-type")??"";if(!e.ok||!/html|xml/i.test(n))return e.body?.cancel().catch(()=>{}),{title:"",reason:"unknown"};let r=q(k(await E(e,1.5*1024*1024),n),e.url||t).title;return ut(r)?{title:"",reason:"auth"}:{title:r.slice(0,200)}}catch{return{title:"",reason:"unknown"}}}function dt(t){let e=t.subarray(0,16);return e[0]===137&&e.toString("latin1",1,4)==="PNG"?"image/png":e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?"image/x-icon":e.toString("latin1",0,3)==="GIF"?"image/gif":e[0]===255&&e[1]===216&&e[2]===255?"image/jpeg":e.toString("latin1",0,4)==="RIFF"&&e.toString("latin1",8,12)==="WEBP"?"image/webp":/^\s*(<\?xml[^>]*>\s*)?<svg[\s>]/i.test(t.subarray(0,512).toString("utf8"))?"image/svg+xml":null}async function G(t,e){if(!t||e<=0)return null;try{let n=await y(t,{timeout:e,accept:"image/*,*/*;q=0.5",protocols:["http:","https:","data:"]});if(!n.ok)return n.body?.cancel().catch(()=>{}),null;let r=(n.headers.get("content-type")??"").split(";")[0].trim().toLowerCase(),o=await O(n,it);if(!o?.length)return null;let s=lt.includes(r)?r:dt(o);return s?`data:${s};base64,${o.toString("base64")}`:null}catch{return null}}async function kt(t,{timeout:e=4e3,env:n=process.env}={}){if(n.GALLERY_SITE_ICON==="off")return null;if(n.GALLERY_SITE_ICON==="local"){let i="";try{i=new URL(t).hostname.replace(/^\[|\]$/g,"")}catch{}if(!/^(127\.\d+\.\d+\.\d+|localhost|::1)$/i.test(i))return null}let r=Date.now()+e,o=()=>r-Date.now(),s=t,c=null;try{let i=await y(t,{timeout:o(),accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8"});s=i.url||t;let u=i.headers.get("content-type")??"";i.ok&&/html|xml/i.test(u)?c=q(k(await E(i,512*1024),u),s).icon:i.body?.cancel().catch(()=>{})}catch{return null}let a=null;try{a=new URL("/favicon.ico",s).href}catch{}return await G(c,o())??(c!==a?G(a,o()):null)}async function qt(t,e,{icon:n=!0,cover:r=!0}={}){let o=await y(t,{accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8",headers:{"accept-language":"zh-CN,zh;q=0.9,en;q=0.8"}}),s=o.url||new URL(t).href,c=o.headers.get("content-type")??"";if(!o.ok)throw ct(at("\u7F51\u9875\u8FD4\u56DE {0}",o.status),{reason:"download"});if(!/html|xml/i.test(c))return o.body?.cancel().catch(()=>{}),{url:s,title:"",description:"",icon:null,cover:null};let a=q(k(await E(o,1.5*1024*1024),c),s),l=async(f,L)=>{let b=await ht(f);try{return b?await e(b,L):null}catch{return null}},[i,u]=await Promise.all([n?l(a.icon,"bookmark-icon"):null,r?l(a.cover,"bookmark-cover"):null]);return{url:s,title:a.title,description:a.description,icon:i,cover:u}}export{tt as a,Pt as b,y as c,O as d,Rt as e,Ot as f,kt as g,qt as h};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as p,d as m}from"./chunk-2OHANJ6Q.mjs";import{q as d}from"./chunk-J5PUIV3Y.mjs";import c from"node:fs";import u from"node:os";import s from"node:path";import{refusal as o,said as t}from"../browser/shared/i18n/index.mjs";var f=64*1024*1024,l=2e3;function h(i){let r;try{r=m(i)}catch{throw o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}try{let e=r.entries;if(e.length>l||e.reduce((n,{size:a})=>n+a,0)>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});return e.map(n=>({name:n.name,data:Buffer.from(r.read(n))}))}catch(e){throw e.code?e:o(t("{0} \u8BFB\u4E0D\u51FA\u6765\uFF1A\u4E0D\u662F\u5B8C\u597D\u7684 zip",s.basename(i)),{code:"kind"})}finally{r.close()}}function g(i){let r=s.resolve(String(i??"").trim().replace(/^"(.*)"$/,"$1")),e;try{e=c.statSync(r)}catch{throw o(t("\u627E\u4E0D\u5230 {0}",r),{code:"missing"})}if(e.isDirectory())return d(r);if(!e.isFile())throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});let n=Buffer.alloc(4),a=c.openSync(r,"r");try{c.readSync(a,n,0,4,0)}finally{c.closeSync(a)}if(!p(n))throw o(t("{0} \u4E0D\u662F\u6587\u4EF6\u5939\uFF0C\u4E5F\u4E0D\u662F zip",r),{code:"kind"});return h(r)}function B(i){if(!p(i))throw o(t("\u9009\u7684\u6587\u4EF6\u4E0D\u662F zip"),{code:"kind"});if(i.length>f)throw o(t("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",l,f/1024/1024),{code:"size"});let r=c.mkdtempSync(s.join(u.tmpdir(),"gallery-pack-")),e=s.join(r,"pack.zip");try{return c.writeFileSync(e,i),h(e)}finally{c.rmSync(r,{recursive:!0,force:!0})}}export{g as a,B as b};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{k as u}from"./chunk-6N3PX4XX.mjs";import n from"node:fs/promises";import d from"node:path";import{writeAtomic as h}from"../browser/shared/files.mjs";import{documentFiles as A}from"../browser/shared/workspace.mjs";var I=s=>n.access(s).then(()=>!0,()=>!1);async function q(s,{create:y,slugOf:F,folderOf:j,fill:p,place:x,under:N="",said:J="\u5BFC\u5165\u81EA {0}",lang:O=null}){let e=[],c=[];async function f(t,r,S){let i=await F(t,S);await y(i,t.title,J.replace("{0}",()=>t.from),{lang:O});let a=j(i),{html:l,json:m}=A(a),k=await n.readFile(l,"utf8");await h(l,u(await p({source:k,nodes:t.nodes,icon:t.icon,own:t.own,raws:t.raws,lang:t.lang}))),t.files.length&&await n.mkdir(d.join(a,"assets"),{recursive:!0});for(let{from:o,name:v}of t.files){let w=d.join(a,"assets",v);await I(w)||await n.copyFile(o,w)}if(t.icon){let o=JSON.parse(await n.readFile(m,"utf8"));await h(m,`${JSON.stringify({...o,icon:t.icon},null,2)}
3
+ `)}await x(i,r),e.push(i);for(let o of t.children??[])await f(o,i,null);return i}for(let[t,r]of s.entries())c.push(await f(r,N,t));return{made:e,top:c}}export{q as a};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as q,b as B}from"./chunk-IA4PSIMD.mjs";import{b as C}from"./chunk-ZTHICSSF.mjs";import x from"node:fs/promises";import W from"node:path";import{MENTION as L}from"../browser/shared/components/mention.mjs";import{writeAtomic as R}from"../browser/shared/files.mjs";import{reportLines as U}from"../browser/shared/search.mjs";import{countWords as Q}from"../browser/shared/words.mjs";import{FACT_KINDS as V,QUERY_KINDS as Y,SNAPSHOT_LIMITS as y,queryOptions as G}from"../browser/shared/workspace-query.mjs";import{documentDirectory as M,documentFiles as T,layoutOf as X,listDocumentSlugs as _,listTrash as Z}from"../browser/shared/workspace.mjs";var ut=f=>c=>f.readTaken(c,{wait:0}),z=({todos:f})=>{let c=new Map,g=d=>JSON.stringify([d.text,d.path]);for(let d of f)c.set(g(d),(c.get(g(d))??0)+1);return f.some(d=>!d.block&&c.get(g(d))>1)},tt=(f,c)=>({hash:B(f),words:Q(c),todos:q(c)});function et(f){let c=new Date(f);return c.setHours(0,0,0,0),c.setDate(c.getDate()-(c.getDay()+6)%7),c.getTime()}function mt({root:f,read:c,draw:g=u=>u,activity:d=null,now:I=()=>new Date}){let u=new Map,m=new Map,b=t=>x.stat(t).then(({mtimeMs:e})=>e,()=>null);async function J(t,e=null){let o=T(M(t,f)),[a,n]=await Promise.all([b(o.html),b(o.json)]);if(a===null)return null;let s=e??await c(t);if(!s)return null;let r={};try{r=JSON.parse(await x.readFile(o.json,"utf8"))??{}}catch{}let{title:i,icon:h}=r,w={slug:t,title:typeof i=="string"&&i.trim()?i:t,icon:typeof h=="string"&&h?h:null,edited:Math.round(a),...tt(s.source,s.text)};return u.set(t,{html:a,json:n,facts:w,held:s.held===!0}),m.has(t)||m.set(t,w),w}async function O(t){let e=u.get(t);if(e&&!e.held){let o=T(M(t,f)),[a,n]=await Promise.all([b(o.html),b(o.json)]);if(a===e.html&&n===e.json)return e.facts}return J(t)}async function S(){let t=await _(f);for(let e of u.keys())t.includes(e)||u.delete(e);for(let e of m.keys())t.includes(e)||m.delete(e);return(await Promise.all(t.map(e=>O(e).catch(()=>null)))).filter(Boolean)}let P={async todos({done:t,slugs:e,limit:o}){let a=(await S()).filter(s=>!e||e.includes(s.slug)).sort((s,r)=>r.edited-s.edited||s.slug.localeCompare(r.slug)),n=[];for(let{slug:s,title:r,icon:i,todos:h,hash:w}of a)for(let l of h)if(!(t!==void 0&&l.done!==t)){if(n.length>=o)return n;n.push({ref:{slug:s,block:l.block,text:l.text,path:l.path,nth:l.nth,version:w},text:l.text,done:l.done,slug:s,title:r,icon:i,path:l.path})}return n},async recent({limit:t}){return(await S()).sort((e,o)=>o.edited-e.edited||e.slug.localeCompare(o.slug)).slice(0,t).map(({slug:e,title:o,icon:a,edited:n})=>({slug:e,title:o,icon:a,edited:new Date(n).toISOString()}))},async stats(){let t=await S(),e=et(I()),o=t.flatMap(a=>a.todos);return{documents:t.length,todos:{done:o.filter(a=>a.done).length,total:o.length},words:t.reduce((a,n)=>a+n.words,0),editedThisWeek:t.filter(a=>a.edited>=e).length}},async activity({days:t}){return d?(await d.load(),await $,d.days(t)):[]},async table({slug:t,key:e,where:o,limit:a},{words:n=!1}={}){let s=await O(t).catch(()=>null),r=u.get(t);if(!s||!r)return k(404,"missing",`no document "${t}"`);if(r.tables??=new Map,!r.tables.has(e)){let l=await c(t);if(!l)return k(404,"missing",`no document "${t}"`);r.tables.set(e,C(l.text,e,t))}let i=r.tables.get(e);if(i.error==="missing")return k(404,"missing",`"${t}" holds no table whose frame carries data-doc-chart-source="${e}"`);if(i.error)return k(422,"missing",`the table "${e}" of "${t}" has merged cells, which no view reads: write each value in its own cell`);let h=Object.keys(o).filter(l=>!i.columns.includes(l));if(h.length>0)return k(400,"options",`table: the table "${e}" of "${t}" has no column ${h.map(l=>JSON.stringify(l)).join(", ")} (its columns: ${i.columns.map(l=>JSON.stringify(l)).join(", ")})`);let w=i.rows.filter(l=>Object.entries(o).every(([D,v])=>l.words[D]===v.replace(/\s+/g," ").trim()));return{columns:[...i.columns],rows:w.slice(0,a).map(({values:l,links:D,words:v})=>({values:{...l},links:D.map(K=>({...K})),...n?{words:{...v}}:{}})),total:w.length}}},k=(t,e,o)=>{throw Object.assign(new Error(o),{refusal:[t,{ok:!1,reason:e,message:o}]})},p=new Map,j=t=>W.join(X(f).gallery,"cache","workspace",`${t}.json`),A=async t=>{if(!p.has(t)){let e=[];try{let o=JSON.parse(await x.readFile(j(t),"utf8"));Array.isArray(o?.tables)&&(e=o.tables.filter(a=>typeof a=="string").slice(-y.tables))}catch{}p.has(t)||p.set(t,e)}return p.get(t)},N=Promise.resolve(),H=async(t,e)=>{let o=await A(t);if(o.at(-1)===e)return;let a=[...o.filter(n=>n!==e),e].slice(-y.tables);p.set(t,a),N=N.then(async()=>{await x.mkdir(W.dirname(j(t)),{recursive:!0}),await R(j(t),`${JSON.stringify({tables:p.get(t)})}
3
+ `)}).catch(()=>{})},F=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,$=Promise.resolve(),E={facts:O,all:S,async lines(t,e){let o=u.get(t);if(!await O(t))return null;let n=u.get(t);if(n!==o||!n.lines||n.lines.titles!==null&&n.lines.titles!==e){let s=await c(t);if(!s)return null;n.lines={titles:s.text.includes(L)?e:null,value:U(g(s.text,t))}}return n.lines.value},async query(t,e,{doc:o=null}={}){if(!Y.includes(t))return[400,{ok:!1,reason:"kind",message:`no kind "${t}": todos, recent, stats, activity or table`}];let{problem:a,options:n}=G(t,e);if(a)return[400,{ok:!1,reason:"options",message:`${t}: ${a}`}];let s;try{s=await P[t](n)}catch(r){if(r.refusal)return r.refusal;throw r}return t==="table"&&typeof o=="string"&&F.test(o)&&await H(o,`${n.slug}#${n.key}`),[200,{ok:!0,kind:t,data:s,at:new Date(I()).toISOString()}]},async snapshot(t){let e=async(n,s)=>{let[r,i]=await E.query(n,s);return r===200?i.data:null},o={todos:await e("todos",{limit:y.todos}),recent:await e("recent",{limit:y.recent}),stats:await e("stats"),activity:await e("activity",{days:y.activity})},a={};for(let n of F.test(t)?await A(t):[]){let[s,r]=n.split("#"),i=await P.table({slug:s,key:r,where:{},limit:y.rows},{words:!0}).catch(()=>null);i&&(a[n]=i)}return Object.keys(a).length>0&&(o.tables=a),Object.fromEntries(Object.entries(o).filter(([,n])=>n!==null))},stored:()=>N,async changed(t,{source:e=null,text:o=null,by:a="agent"}={}){let n=m.get(t)??u.get(t)?.facts??null;u.delete(t);let s=e===null?null:await J(t,{source:e,text:o??e}).catch(()=>null);s?m.set(t,s):m.delete(t);let r=new Set;if(!!n!=!!s)for(let i of["todos","recent","stats","table"])r.add(i);return n&&s&&n.hash!==s.hash&&r.add("table"),n&&s&&n.hash!==s.hash&&(z(n)||z(s))&&r.add("todos"),n&&s&&((n.title!==s.title||JSON.stringify(n.todos)!==JSON.stringify(s.todos))&&r.add("todos"),(n.title!==s.title||n.icon!==s.icon||n.edited!==s.edited)&&r.add("recent"),(n.words!==s.words||n.todos.length!==s.todos.length||n.todos.filter(i=>i.done).length!==s.todos.filter(i=>i.done).length||n.edited!==s.edited)&&r.add("stats")),!n&&s&&r.add("recent"),d&&s&&(await d.load(),await $,d.record(t,{hash:s.hash,words:s.words,mtime:s.edited,by:a})&&r.add("activity")),V.filter(i=>r.has(i))},start(){return d?($=(async()=>{await d.load();let t=await _(f),e=(await Promise.all(t.map(async a=>({slug:a,mtime:await b(T(M(a,f)).html)})))).filter(({mtime:a})=>a!==null),o=(await Z(f).catch(()=>[])).map(a=>a.slug);return d.catchUp(e.map(({slug:a,mtime:n})=>({slug:a,mtime:Math.round(n)})),O,{kept:o})})().catch(()=>0),$):Promise.resolve(0)},forget(t){u.delete(t),m.delete(t)}};return E}export{ut as a,mt as b};
@@ -0,0 +1,170 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as w}from"./chunk-JEUK3ZO7.mjs";import{a as te}from"./chunk-7OG26PGF.mjs";import{d as F,e as W}from"./chunk-QE5RG76S.mjs";import{a as H,b as L,d as G,e as $,f as E,g as R,h as U,i as q,j as Y,o as V,r as X,s as Q,t as Z}from"./chunk-J5PUIV3Y.mjs";import{a as P,b as d,f as ee}from"./chunk-4OZWXZE5.mjs";import{i as K}from"./chunk-HXG7EOPJ.mjs";import{f as S,j as C,s as _,t as B,v as j}from"./chunk-HDWTZ763.mjs";import v from"node:fs";import N from"node:path";import{blocksHidden as $e}from"../browser/editor/components/registry.mjs";import{inLanguage as be,told as ve}from"../browser/shared/i18n/index.mjs";import{PACK_ID as xe}from"../browser/shared/pack-manifest.mjs";import{readKeys as Se,writeKey as se}from"../browser/shared/net-keys.mjs";import{HOST as Ne,netHostsOf as Oe}from"../browser/shared/net-policy.mjs";import{PACKAGE_ID as je,SLOT as Ee}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as Ae,layoutOf as A,PACKAGE_MANIFEST as ie,shallowPackages as le}from"../browser/shared/workspace.mjs";var fe=(e,t,{script:o,flow:n,data:a,page:s})=>`{
3
+ "id": "${e}",
4
+ "apiVersion": 1,
5
+ "version": "0.1.0",
6
+ "name": { "zh": "${t}", "en": "${t}" },
7
+ "description": { "zh": "\u4E00\u4E2A\u53EF\u4EE5\u53CD\u590D\u4F7F\u7528\u7684\u5757", "en": "A block to use again" },
8
+ "words": "${t}",${s?`
9
+ "places": ["page"],
10
+ "card": { "sizes": [[4, 3], [2, 3]], "resize": true },`:""}
11
+ "parts": {
12
+ "title": { "at": ":scope > h3", "edit": "${s?"none":"text"}" }${a?`,
13
+ "items": { "at": ":scope > script", "edit": "data" }`:n?`,
14
+ "body": { "edit": "flow" }`:`,
15
+ "text": { "at": ":scope > p", "edit": "${s?"none":"text"}", "optional": true }`}
16
+ },${o?`
17
+ "runtime": { "generated": [".component-drawn"] },`:""}
18
+ "markdown": "parts"
19
+ }
20
+ `,oe=(e,t,o,{blocks:n,json:a})=>`<div data-doc-component="${e}">
21
+ <h3>${t}</h3>
22
+ ${a?` <script type="application/json">${a}</script>`:n?` <div data-doc-slot="body">
23
+ ${n.map(s=>` ${s}
24
+ `).join("")} </div>`:` <p>${o}</p>`}
25
+ </div>
26
+ `,we=["<p>\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002</p>","<ul>"," <li>\u63D2\u69FD\u91CC\u5199\u6587\u6863\u81EA\u5DF1\u7684\u5757</li>"," <li>\u6BB5\u843D\u3001\u5217\u8868\u3001\u8868\u683C\u90FD\u53EF\u4EE5</li>","</ul>"],ge=(e,{flow:t,data:o})=>`/* Every selector starts at the instance, so that nothing here reaches the rest of the page.${t?` Each step is
27
+ a >, so that none reaches into the slot, whose blocks read as the page's.`:""} */
28
+ [data-doc-component="${e}"] { padding: 12px 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
29
+ [data-doc-component="${e}"] > h3 { margin-top: 0; }
30
+ ${o?`/* The hidden attribute hides a control whatever display the rules below give it (the kit holds [hidden] over a
31
+ style): the field and the buttons are drawn hidden where nothing is written, an export. */
32
+ [data-doc-component="${e}"] .component-list { margin: 0 0 8px; padding: 0; list-style: none; }
33
+ [data-doc-component="${e}"] .component-list > li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 0; }
34
+ [data-doc-component="${e}"] .component-field { display: block; box-sizing: border-box; width: 100%; padding: 4px 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: inherit; font: inherit; }
35
+ [data-doc-component="${e}"] .component-remove { padding: 0 8px; border: 1px solid var(--doc-border); border-radius: 6px; background: transparent; color: var(--doc-muted); font: inherit; cursor: pointer; }
36
+ `:""}`,ue=(e,t,{script:o,flow:n,data:a,page:s})=>`# ${t}
37
+
38
+ What this block is for, and when ${s?"a custom page":"a document"} uses it rather than a block of Gallery's own.
39
+
40
+ ## How to write it
41
+
42
+ Write the element as example.html does: \`gallery block show ${e}\` prints it. Each part, and what goes in it:
43
+
44
+ - the title, its \`h3\`: required${s?", written in the file (a page shows it as written)":""}.
45
+ ${a?'- the items, its `<script type="application/json">`: `{"items":[{"text":"\u2026"}]}`, each item a line a reader adds on the block and takes away with its button. Leave the items of a block that is there alone: they are the reader\'s.\n':n?'- the body, its `<div data-doc-slot="body">`: required, the document\'s own blocks, written as anywhere in the document (paragraphs, lists, tables, formulas).\n':"- the text, its `p`: optional.\n"}${s?`
46
+ ## On a page
47
+
48
+ A card of a custom page: \`gallery page add <slug> ${e}\` puts one on it, at the first free spot by its size (4 \xD7 3, or 2 \xD7 3), which the user may change by dragging its edge.
49
+ `:""}
50
+ ## How it looks
51
+
52
+ What a reader sees of it, and what it shows while it is empty.${a?" Where nothing is written (an export) its field and buttons are not shown.":""}
53
+ ${o?`
54
+ ## Its script
55
+
56
+ kit.js runs with the rights of a document's own script. What it draws, it draws in what the manifest's \`runtime\` names${n?", outside the slot: it reads the slot and never writes in it":""}.${a?" It reads the items with `context.readJSON` and writes them back with `context.editJSON`, one write for each add or removal (one undo step); `example()` adds an item, by the function the field calls, and works on an empty instance too.":""}
57
+ `:""}`,ke=e=>`// Starts each instance from what the file says, and draws in a node the manifest's runtime names:
58
+ // the kit takes that off an instance before it starts one again, as an undo may put one back.
59
+ DocKit.component({
60
+ id: "${e}",
61
+ on: ["source"],
62
+ mount(host, context) {
63
+ const drawn = document.createElement("div");
64
+ drawn.className = "component-drawn";
65
+ host.append(drawn);
66
+ const draw = () => { drawn.textContent = context.part("title")?.textContent ?? ""; };
67
+ draw();
68
+ return { update: draw };
69
+ },
70
+ });
71
+ `,ye=e=>`// A list of lines a reader keeps in this block. Its data part, items, is a script of JSON:
72
+ // {"items":[{"text":"\u2026"}]}. The block draws what it holds on every \`source\` (an undo, an Agent's write,
73
+ // the page coming to edit) and writes only on a reader's gesture: a line typed in the field (DocKit.input:
74
+ // Enter or leaving the field, never while an input method composes) and a press of a line's button, each
75
+ // one context.editJSON, one undo step. A control that writes is drawn only while context.canEdit() and
76
+ // hidden otherwise, as an export needs (the hidden attribute: the kit holds it over any display).
77
+
78
+ /**
79
+ * The items \`data\` holds (context.readJSON's, or the draft context.editJSON hands a change); throws
80
+ * saying why when it is no { "items": [] }, and the block draws nothing over it.
81
+ * @param {any} data
82
+ * @returns {{ text: string }[]}
83
+ */
84
+ function itemsOf(data) {
85
+ if (data === null || typeof data !== "object" || !Array.isArray(data.items)) throw new Error('its data is no { "items": [] }');
86
+ return data.items;
87
+ }
88
+
89
+ /**
90
+ * One item more, one write: what the field calls once the reader is done with it, and the example too.
91
+ * Whether it was taken.
92
+ * @param {DocComponentContext} context
93
+ * @param {string} text
94
+ */
95
+ function addItem(context, text) {
96
+ return context.editJSON("items", (data) => {
97
+ itemsOf(data).push({ text });
98
+ });
99
+ }
100
+
101
+ /**
102
+ * The item numbered \`index\` taken away, one write: what a line's button calls. Whether it was taken.
103
+ * @param {DocComponentContext} context
104
+ * @param {number} index
105
+ */
106
+ function removeItem(context, index) {
107
+ return context.editJSON("items", (data) => {
108
+ itemsOf(data).splice(index, 1);
109
+ });
110
+ }
111
+
112
+ DocKit.component({
113
+ id: "${e}",
114
+ on: ["source", "editable"],
115
+ mount(host, context) {
116
+ const drawn = document.createElement("div");
117
+ drawn.className = "component-drawn";
118
+ const list = document.createElement("ul");
119
+ list.className = "component-list";
120
+ const field = document.createElement("input");
121
+ field.className = "component-field";
122
+ field.type = "text";
123
+ field.placeholder = "\u5199\u4E00\u6761\uFF0C\u56DE\u8F66\u6DFB\u52A0";
124
+ drawn.append(list, field);
125
+ host.append(drawn);
126
+ const typed = DocKit.input(field, {
127
+ signal: context.signal,
128
+ commit(value) {
129
+ if (value.trim() && addItem(context, value.trim())) typed.set("");
130
+ },
131
+ });
132
+ context.listen(list, "click", (event) => {
133
+ const button = event.target instanceof Element ? event.target.closest("button") : null;
134
+ if (button && context.canEdit()) removeItem(context, Number(button.value));
135
+ });
136
+ const draw = () => {
137
+ const data = context.readJSON("items");
138
+ if (data === undefined) return; // no JSON: the instance has failed, and Gallery shows what it holds
139
+ let items;
140
+ try {
141
+ items = itemsOf(data);
142
+ } catch (error) {
143
+ return context.fail(error);
144
+ }
145
+ const writes = context.canEdit();
146
+ list.replaceChildren(...items.map((item, index) => {
147
+ const line = document.createElement("li");
148
+ const words = document.createElement("span");
149
+ words.textContent = item.text;
150
+ const remove = document.createElement("button");
151
+ remove.type = "button";
152
+ remove.className = "component-remove";
153
+ remove.value = String(index);
154
+ remove.textContent = "\u5220\u9664";
155
+ remove.hidden = !writes;
156
+ line.append(words, remove);
157
+ return line;
158
+ }));
159
+ field.hidden = !writes;
160
+ };
161
+ draw();
162
+ return { update: draw };
163
+ },
164
+ example(host, context) {
165
+ addItem(context, "\u53C8\u4E00\u6761");
166
+ },
167
+ });
168
+ `;function ne(e,{script:t=!1,flow:o=!1,data:n=!1,page:a=!1}={}){let s=e.split("/")[1],l={script:t||n,flow:o,data:n,page:a};return{"component.json":fe(e,s,l),"template.html":oe(e,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",{blocks:o&&["<p></p>"],json:n&&'{"items":[]}'}),"example.html":oe(e,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",{blocks:o&&we,json:n&&'{"items":[{"text":"\u7B2C\u4E00\u6761"},{"text":"\u7B2C\u4E8C\u6761"}]}'}),"writing.md":ue(e,s,l),"style.css":ge(e,l),...l.script?{"kit.js":n?ye(e):ke(e)}:{}}}var x="local";function re(e){let t=e.includes("/")?e:`${x}/${e}`;if(!je.test(t))throw new d(`Not a block's id: ${e} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${x}/<name>).`);let o=t.split("/").find(n=>Ae.has(n));if(o)throw new d(`Not a block's id: ${e} (Windows keeps ${o} for a device).`);return t}function Ie(e,t){let o=re(t),n=t.includes("/")?null:$(t);if(!n)return o;let a=S(e);return a.packages.has(o)||a.problems.has(o)||v.existsSync(M(e,o))?o:n.id}var M=(e,t)=>N.join(A(e).components,...t.split("/")),u=e=>e.pack===H?e.name:e.id,z=()=>G().map(u).join(", "),ce=({name:e,file:t})=>`${w(t)} is one level too shallow, and no catalog reads it: a custom block is components/<scope>/<name>/, so move it to components/${x}/${e}/`;function Ce(e,t){let o=le(e).find(({name:s})=>s===t.split("/")[1]),n=E(t)&&$(t);if(n)return`No block ${t} in ${w(A(e).components)}: it is one of Gallery's own, which gallery block add ${u(n)} puts in.`;let a=t.startsWith(`${x}/`)?$(t.slice(x.length+1)):null;return o?ce(o):`No block ${t} in ${w(A(e).components)}: gallery block list says which there are${a?`; Gallery has a block of that name, ${a.id}`:""}.`}function Ge(e,t,{script:o,flow:n,data:a,page:s,recipe:l}){let r=t.split("/")[0],m=$(t);if(E(t))throw new d(`The scope ${r}/ is kept for Gallery's own blocks: give yours another (${x}/<name>, or a <name> alone)${m?`; gallery block add ${u(m)} puts Gallery's in, and gallery block new <id> --recipe ${u(m)} starts one of yours from it`:""}.`);if(R(e).packs?.[r])throw new d(`The scope ${r}/ is the pack ${r}'s, which gallery block pack install put in (installing it again would not keep a block of yours there): give yours another (${x}/<name>, or a <name> alone).`);let h=l===void 0?null:$(l);if(l!==void 0&&!h)throw new d(`No block of Gallery's own is called ${l}: ${z()||"none"}.`);let f=M(e,t);if(v.existsSync(f)||S(e).problems.has(t)){let c=!v.existsSync(N.join(f,ie));console.error(c?`A folder is there with no component.json: ${w(f)}: move it, or give this block another name.`:`Block already exists: ${w(f)}: gallery block show ${t} says what it is; give a new one another name.`),process.exit(1)}let i=h?V(h,t):ne(t,{script:o,flow:n,data:a,page:s});try{v.mkdirSync(f,{recursive:!0});for(let c of L(Object.keys(i)))v.mkdirSync(N.dirname(N.join(f,c)),{recursive:!0}),v.writeFileSync(N.join(f,c),i[c])}catch(c){if(!c.code)throw c;console.error(`Cannot write ${w(f)} (${c.code}).`),process.exit(1)}if(console.log(`Created ${w(f)}: ${Object.keys(i).join(", ")}`),h){console.log(`Made from Gallery's ${h.id} ${h.version}, every word that named it naming ${t}: change its name, words and description in component.json first (two blocks of one name read alike in "/"), and in the same files what is still ${h.name}'s: preview.svg (the picture the menu shows beside the description, still ${h.name}'s drawing: draw yours or delete it), writing.md (how to write it, still about ${h.name}) and example.html (the instance check runs and show prints, still ${h.name}'s words), then what you came for (references/building-blocks.md has every field and the rules), and run gallery block check ${t}, which passes as it stands now.`);return}let p=o||a;console.log(`Next: say in component.json what it is (its name, description and parts), write template.html, what ${s?"a custom page's \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 puts on it":'"/" puts in a document'}, and example.html, an instance as a writer would fill it, then writing.md and style.css${p?" and kit.js":""} (references/building-blocks.md has every field and the rules${n?", and Slots what its slot body holds":""}${s?"; references/pages-and-data.md a card's size and settings and what it reads":""}${p?"; references/block-script.md its script and how it writes back":""}), and run gallery block check ${t}, which passes as it stands now.`),a&&console.log("It keeps a list of lines (the part items, a script of JSON on one line, as context.editJSON writes it): kit.js reads it with context.readJSON and writes it with context.editJSON, from a field (DocKit.input) and a button, hidden where nothing is written; example() adds a line by the function the field calls, and works on template.html's empty instance. Rename the part, the fields of its JSON and the controls for what the block keeps."),s?console.log(`It is a custom page's card (places ["page"], a card of two sizes): gallery page add <slug> ${t} puts one on a page, then gallery page try <slug> <card id> <gesture> tries a reader's gesture on it${a?' (--type .component-field "words" --then Enter)':""}; for a document too, put "document" in places.`):a&&console.log(`In a document: write the element as example.html does, then gallery block try <slug> --type .component-field "words" --then Enter tries the field (the part and the class are the scaffold's: rename them with the block).`)}function Pe(e,t){let o=$(t);if(!o)throw new d(`No block of Gallery's own is called ${t}: ${z()||"none"} (gallery block list says each).`);let n;try{n=q(e,o)}catch(s){if(s.code!=="changed")throw s;console.error(`${w(s.folder)} was changed after gallery block add put it there (or another hand put it there), so it is not replaced: to keep those changes, make a block of your own from Gallery's with gallery block new <id> --recipe ${u(o)} and move them into it; to take Gallery's ${o.version}, delete the folder and run gallery block add ${u(o)} again.`),process.exit(1)}let a=o.places.includes("document")?`a document can write it now (gallery block show ${o.id} says how)`:"custom pages can place it now";n.did==="same"?console.log(`${o.id} ${o.version} is in already, as Gallery ships it: ${w(n.folder)}`):n.did==="updated"?console.log(`Updated ${o.id} from ${n.from??"an older version"} to ${o.version}: ${w(n.folder)}`):console.log(`Added ${o.id} ${o.version}: ${w(n.folder)}`),n.did!=="same"&&console.log(`It is Gallery's, as it ships: no check or try is needed, and ${a}. Change nothing in its folder, or gallery block add will not update it again: for a block like it of your own, gallery block new <id> --recipe ${u(o)}.`)}var k=({zh:e,en:t})=>e===t?e:`${e} / ${t}`;function Ke(e){if(B(e))return null;let t=_(e);return t?C("en",t):"it has no template.html"}var Je={disabled:"disabled by the user: its instances show as they stand, no script and no style"},I=e=>e?.length?` \u8981\u7528\uFF1A${e.join(", ")}`:"";function ae(e,{id:t,name:o,version:n,description:a,state:s,needs:l},r){console.log(`${t} ${k(o)}`);let h=(e.settings.packsOff??[]).includes(t.split("/")[0])?`available; its pack ${t.split("/")[0]} is switched off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, so no menu or library offers it, and a document can still write it`:r==="document"&&s==="hidden"?"available; not in the document's menus, by the user's switch, and a document can still write it":"available";console.log(` \u7248\u672C\uFF1A${n}\uFF08${h}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(a)}`),I(l)&&console.log(I(l));let f=r==="document"&&Ke(e.packages.get(t));f&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${f}`)}function Te(e){let t=S(e),o=j(t),n=o.filter(({reason:i})=>i),a=o.filter(({reason:i})=>!i),s=a.filter(({state:i})=>i!=="disabled"),l=s.filter(({places:i})=>i.includes("document")),r=s.filter(({places:i})=>i.includes("page")),m=le(e),h=G().map(i=>({block:i,state:U(e,i)})).filter(({block:i,state:p})=>!p.added||p.behind||p.changed&&Y(i.version,p.version)),f=$e(t.settings.hidden);if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`),a.length+n.length+m.length===0)console.log("No custom blocks yet. A document is written with Gallery's blocks and whole blocks; gallery block add <name> puts one of Gallery's own in (below), and gallery block new <id> starts one when the user wants a block to use again.");else{console.log(l.length?`\u6587\u6863\u91CC\u53EF\u7528 (in documents: ${l.length}; gallery block show <id> says how to write each):`:"\u6587\u6863\u91CC\u53EF\u7528 (in documents): none now.");for(let p of l)ae(t,p,"document");console.log(r.length?`\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages: ${r.length}):`:"\u81EA\u5B9A\u4E49\u9875\u53EF\u7528 (on custom pages): none now.");for(let p of r)p.places.includes("document")?console.log(`${p.id} ${k(p.name)} (above: in documents too)`):ae(t,p,"page");let i=a.filter(({state:p})=>p==="disabled");i.length+n.length+m.length>0&&console.log("Not to use now:");for(let{id:p,name:c,version:y,state:O}of i)console.log(`${p} ${k(c)} ${y} ${Je[O]}`);for(let{id:p,reason:c,version:y}of n)console.log(`${p}${y?` ${y}`:""} does not load: ${c.en}`);for(let p of m)console.log(ce(p))}h.length&&console.log("Gallery's own blocks, to add as they are (no check or try needed):");for(let{block:i,state:p}of h){let c=i.places.map(y=>y==="document"?"documents":"custom pages").join(" and ");console.log(`${i.id} ${k(i.title)} ${i.version} (${c})`),console.log(` \u8BF4\u660E\uFF1A${k(i.description)}`),p.changed?console.log(` the workspace's copy (${p.version??"no version"}) was changed after it was added, so it is not updated: to take Gallery's ${i.version}, delete ${w(M(e,i.id))} and run gallery block add ${u(i)} (to keep the changes, gallery block new <id> --recipe ${u(i)} and move them into it)`):console.log(p.added?` gallery block add ${u(i)} (the workspace has ${p.version??"an older one"}: this updates it)`:` gallery block add ${u(i)}`)}f.length&&console.log(`Built-in blocks the user took out of the document's menus (a document can still write them): ${f.join(", ")}`)}var De=(e,{at:t,edit:o,optional:n,min:a,max:s})=>{let l=[n?"optional":"",a!==void 0?`at least ${a}`:"",s!==void 0?`at most ${s}`:""].filter(Boolean),r=o==="flow"?`${Ee}="${e}"`:t;return` ${e} ${r} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${l.length?` (${l.join(", ")})`:""}`};function de(e,t,o){console.log(`${t} ${k(e.name)}`),console.log(` \u7248\u672C\uFF1A${e.version}\uFF08${o}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${k(e.description)}`),console.log(` \u7528\u5728\uFF1A${e.places.map(l=>l==="document"?"documents":"custom pages").join(", ")}`),I(e.needs)&&console.log(I(e.needs)),console.log(` ${w(e.folder)}`);let n=Object.entries(e.parts);console.log(n.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[l,r]of n)console.log(De(l,r));let a=K(e,"writing.md")?.trimEnd();console.log(a?`How to write it (writing.md):
169
+ ${a}`:"How to write it: the block has no writing.md.");let s=K(e,"example.html")?.trimEnd();console.log(s?`The example (example.html):
170
+ ${s}`:"The example: the block has no example.html.")}function Me(e,t){let o=S(e),n=o.problems.get(t),a=o.packages.get(t)??(n?.off?n:void 0);if(!a){let r=n?.problem,m=!r&&E(t)?$(t):null;if(m)return Fe(m);console.error(r?`${t} does not load: ${C("en",r)}`:Ce(e,t)),process.exit(1)}let{state:s}=j(o).find(r=>r.id===t),l={normal:"available",hidden:"available; not in the document's menus, by the user's switch",disabled:"disabled by the user"}[s]??s;de(a,t,l),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}async function ze(e,t,o,{remove:n}){let a=Se(e);if(t===void 0){let s=[...new Set(j(S(e)).flatMap(({needs:m})=>Oe(m??[])))],l=Object.keys(a).sort();console.log(l.length?`Keys kept (.gallery/keys.json), by host: ${l.join(", ")}.`:"No key kept (.gallery/keys.json holds none).");let r=s.filter(m=>!l.includes(m)).sort();r.length&&console.log(`Hosts the workspace's blocks reach with no key: ${r.join(", ")} (a key is needed only where a block's address names {key}).`);return}if(!Ne.test(t))throw new d(`Not a host a block's needs can name: ${t} (a lowercase name, no scheme, port or path; *. before it for the names under it).`);if(n){if(o!==void 0)throw new d("gallery block key <host> --remove takes no key.");return t in a?(await se(e,t,null),console.log(`Took away the key for ${t}. A block's address that names {key} on it is refused (code "key") until one is kept again.`)):console.log(`No key kept for ${t}: nothing to take away.`)}if(o===void 0)return console.log(t in a?`A key is kept for ${t} (never printed): an address on it that names {key} is fetched with it.`:`No key kept for ${t}: gallery block key ${t} <key> keeps one.`);if(!o.trim()||/[\r\n]/.test(o))throw new d("A key is one line of characters, not empty.");await se(e,t,o),console.log(`Kept the key for ${t} in ${w(A(e).keys)}, which no page, export or cache holds: Gallery writes it where a block's address on ${t} names {key}, as it fetches for the block. Never write the key into a block's files or a page: they are shown and exported.`)}function Fe(e){let t=JSON.parse(v.readFileSync(N.join(e.folder,ie),"utf8"));de({name:e.title,description:e.description,version:e.version,places:e.places,needs:t.needs,folder:e.folder,parts:t.parts??{}},e.id,"Gallery's own, not in this workspace yet");let o=e.places.includes("document")?", and a document writes it as the example above does, straight in the page or a section, with no data-block-id, which the export gives it":`, and gallery page add <slug> ${u(e)} puts a card of it on a custom page`;console.log(`Not in this workspace yet: gallery block add ${u(e)} puts it in as it ships (no check, no try)${o}.`)}var he=e=>be("en",()=>ve(e))??e.message,J=(e,t)=>t.length?[` ${e}: ${t.join(", ")}`]:[];function We(e,t){let o;try{o=X(e,te(t))}catch(a){if(!a.code)throw a;console.error(`Not installed: ${he(a)}`),process.exit(1)}let n=o.added.length+o.updated.length+o.same.length+o.kept.length;o.from===null?console.log(`Installed the pack ${o.id} ${o.version} (${k(o.name)}), ${n} block${n===1?"":"s"}: ${w(o.folder)}`):o.did==="updated"?console.log(`Updated the pack ${o.id} from ${o.from??"an older version"} to ${o.version}: ${w(o.folder)}`):console.log(`The pack ${o.id} ${o.version} is in already, as installed: ${w(o.folder)}`);for(let a of[...J("added",o.added),...o.did==="updated"?J("updated",o.updated):[],...J("taken out (not in this version)",o.removed)])console.log(a);o.kept.length&&console.log(` kept as they are, changed since they were installed: ${o.kept.join(", ")} (to take this version's, delete the block's folder and install the pack again)`),o.ownKept&&console.log(" its pack.json was changed since it was installed, and is kept as it is"),console.log(`Its blocks are offered in "/" and \u6DFB\u52A0\u81EA\u5B9A\u4E49\u5757 while its switch in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 is on (gallery block pack list says each pack's); gallery block list says each block.`)}function D(e){let t=Z(e);console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(e)}`);let o={default:"the default pack, where a block made with no pack named goes",official:"Gallery's own",installed:"a pack installed",own:"the workspace's own blocks, no pack.json"};for(let n of t){let a=[n.version?`${n.id} ${n.version}`:n.id,o[n.kind],n.enabled?"on":"off",`${n.blocks} block${n.blocks===1?"":"s"}`,...n.author?[`by ${n.author}`]:[]];console.log(`${k(n.name)} (${a.join(", ")})`),n.description&&console.log(` \u8BF4\u660E\uFF1A${k(n.description)}`),n.problem&&console.log(` its pack.json does not read: ${n.problem.en}`),n.changed.length&&console.log(` changed since it was installed: ${n.changed.join(", ")}${n.newer?` (Gallery's is ${n.newer}, not put over them)`:""}`)}t.every(({kind:n})=>n==="default")&&console.log("No other block packs: gallery block pack install <folder|zip> installs one.")}function _e(e,t){if(!xe.test(t))throw new d(`Not a pack's id: ${t} (lowercase letters, digits and hyphens: gallery block pack list says each).`);let o;try{o=Q(e,t)}catch(n){if(!n.code)throw n;console.error(`Not removed: ${he(n)}`),process.exit(1)}console.log(`Removed the pack ${o.id}${o.version?` ${o.version}`:""} (${o.blocks.length} block${o.blocks.length===1?"":"s"}): what documents and pages hold of its blocks stays, shown as blocks that are not there.`)}var T={install:We,list:D,remove:_e};function Be(e,t,o){if(!t)throw new d("Say what to do with packs: install <folder|zip>, list, remove <pack>.");if(!Object.hasOwn(T,t))throw new d(`No such pack command: ${t} (install, list, remove).`);if(T[t]===D){if(o.length)throw new d("gallery block pack list takes nothing else.");return D(e)}if(o.length!==1)throw new d(t==="install"?"gallery block pack install takes one folder or zip: gallery block pack install <folder|zip>.":"gallery block pack remove takes one pack's id: gallery block pack remove <pack>.");return T[t](e,o[0])}var g={new:(e,t,o)=>Ge(e,t,o),add:Pe,list:Te,show:Me,check:async(e,t,{documents:o})=>(await import("./chunk-FETSREUN.mjs")).checkCommand(e,t,{documents:o}),try:async(e,t)=>(await import("./chunk-OFHXGWOX.mjs")).tryCommand(e,t),key:ze,pack:Be},He=["--press","--drag","--to","--key","--type","--select","--then","--steps"],Le={"--key":"--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).","--type":"--type takes a selector and the words to type: --type <selector> <words> (quoted when they hold a blank).","--select":"--select takes a selector and an option: --select <selector> <value> (the option's value or its words)."};function pe(e){let t=e.indexOf("--"),o=new Set,n={};for(let[a,s]of Object.entries(Le)){let l=(t===-1?e:e.slice(0,t)).findIndex(h=>h===a||h.startsWith(`${a}=`));if(l===-1)continue;let r=l+(e[l].includes("=")?1:2),m=e[r];if(m===void 0||r===t||P(m)||o.has(r))throw new d(s);o.add(r),n[a]=m}return{argv:e.filter((a,s)=>!o.has(s)),seconds:n}}function pt(e){let{argv:t,seconds:o}=pe(e);return{argv:t,key:o["--key"]??null}}async function mt(e,{workspace:t}){try{return await Re(e,t)}catch(o){let n=e.find(a=>!P(a));throw o instanceof d&&n==="try"&&(o.synopsis=F),o instanceof d&&n==="pack"&&(o.synopsis=W),o}}async function Re(e,t){let{argv:o,seconds:n}=pe(e),{positional:a,options:s,values:l}=ee({options:["--script","--flow","--data","--page","--keep","--documents","--replace","--remove"],values:[...He,"--recipe"],argv:o}),r=l.get("--recipe"),m=new Map([...l].filter(([b])=>b!=="--recipe")),[h,f,...i]=a,p=Object.keys(g).join(", ");if(!h)throw new d(`Say what to do: ${p}.`);if(!Object.hasOwn(g,h))throw new d(`No such block command: ${h} (${p}).`);let c=g[h];for(let b of["--script","--flow","--data","--page"])if(s.has(b)&&c!==g.new)throw new d(`${b} goes with new, not ${h}.`);if(s.has("--documents")&&c!==g.check)throw new d(`--documents goes with check, not ${h}.`);if(s.has("--remove")&&c!==g.key)throw new d(`--remove goes with key, not ${h}.`);if(r!==void 0&&c!==g.new)throw new d(`--recipe goes with new, not ${h}.`);let y=["--script","--flow","--data","--page"].filter(b=>s.has(b));if(r!==void 0&&y.length)throw new d(`--recipe makes a block of what Gallery's ${r} holds: ${y[0]} goes with a new block of none.${y[0]==="--page"&&$(r)?.places.includes("page")?` ${r} already is a card for a custom page (its places hold page): leave --page out.`:""}`);if(s.has("--flow")&&s.has("--data"))throw new d("--flow and --data do not go together: --flow is a slot for blocks of the document's own, --data a list of lines a reader keeps in the block's JSON. Make the one you need with new, and add the other by hand.");if(s.has("--flow")&&s.has("--page"))throw new d("--flow and --page do not go together: a custom page renders no document's blocks, so a block for a page has no slot.");let O=[...m.keys(),...Object.keys(n).filter(b=>!m.has(b)),...s.has("--keep")?["--keep"]:[],...s.has("--replace")?["--replace"]:[]];if(c===g.try)return c(t,{named:a.slice(1),values:m,seconds:n,keep:s.has("--keep"),replace:s.has("--replace")});if(O.length)throw new d(`${O[0]} goes with try, not ${h}.`);if(c===g.list){if(f!==void 0)throw new d(`gallery block ${h} takes nothing else.`);return c(t)}if(c===g.pack)return c(t,f,i);if(c===g.key){if(i.length>1)throw new d("gallery block key takes a host and its key: gallery block key <host> <key>.");return c(t,f,i[0],{remove:s.has("--remove")})}if(c===g.add){if(f===void 0||i.length>0)throw new d(`gallery block add takes one name of Gallery's own blocks: ${z()}.`);return c(t,f)}if(f===void 0||i.length>0)throw new d(`gallery block ${h} takes one id.`);let me=c===g.show||c===g.check?Ie(t,f):re(f);return c(t,me,{script:s.has("--script"),flow:s.has("--flow"),data:s.has("--data"),page:s.has("--page"),documents:s.has("--documents"),recipe:r})}export{re as a,Ie as b,M as c,u as d,ce as e,Ce as f,He as g,pe as h,pt as i,mt as j};
@@ -1,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{f as A}from"./chunk-JVHHHGEA.mjs";import{a as w,c as U}from"./chunk-HYMEEXKN.mjs";import he from"node:fs";import $e from"node:path";import{reportsDirectory as we}from"../browser/shared/paths.mjs";import{assetFile as be,assetProblem as ge,embedFile as ke}from"../browser/shared/media.mjs";import{attr as H,hasClass as xe,walk as ye}from"../browser/shared/html-tree.mjs";import _ from"node:fs";import ie from"node:path";import{attr as ae,hasClass as ce,walk as fe}from"../browser/shared/html-tree.mjs";import{MEDIA_ROUTES as le,mediaTypeOf as de,mediaUrl as ue}from"../browser/shared/media.mjs";import{documentDirectory as pe}from"../browser/shared/workspace.mjs";function k(e,n,o){let s=null;return fe(e,t=>{!s&&t.tagName===n&&ce(t,o)&&(s=t)}),s}function N(e,n){let o=ie.join(e,n);return _.statSync(o,{throwIfNoEntry:!1})?.isFile()?`data:${de(n)};base64,${_.readFileSync(o).toString("base64")}`:null}function me(e,{attribute:n,route:o,slug:s,mode:t,reportsDirectory:r}){if(!le[o](e))return null;if(t==="preview")return`${n}="${ue(o,s,e)}" data-ge-${n}="${e}"`;let a=N(pe(s,r),e);return a&&`${n}="${a}"`}function x(e,n,{attribute:o,route:s,slug:t,mode:r,reportsDirectory:a}){let i=n.map(f=>({place:f.sourceCodeLocation?.attrs?.[o],value:ae(f,o)})).filter(({place:f})=>f).sort((f,d)=>f.place.startOffset-d.place.startOffset),c=[],l=0;for(let{place:f,value:d}of i){let u=me(d,{attribute:o,route:s,slug:t,mode:r,reportsDirectory:a});u===null||f.startOffset<l||(c.push(e.slice(l,f.startOffset),u),l=f.endOffset)}return c.push(e.slice(l)),c.join("")}function D(e){let n=[];return ye(e,o=>{let s=o.tagName==="figure"&&xe(o,"doc-embed")?k(o,"iframe","doc-embed-frame"):null;s&&n.push(s)}),n}function bt(e,{slug:n,mode:o="export",reportsDirectory:s=we}){return e.includes("doc-embed")?x(e,D(w(e)),{attribute:"src",route:"embed",slug:n,mode:o,reportsDirectory:s}):e}var I=(e,n=w(e))=>D(n).map(o=>o.sourceCodeLocation.startOffset);function gt({html:e,directory:n,tree:o=w(e)}){let s=[];for(let t of D(o)){let r=`line ${t.sourceCodeLocation.startLine}`,a=H(t,"src")??"",i=H(t,"sandbox"),c=/^https:\/\/[^\s"]+$/.test(a),l=!c&&!/^[a-z][a-z0-9+.-]*:/i.test(a)&&!be(a)?ge(a):null;l?s.push(`${r}: an embed's frame (${a.slice(0,80)}): ${l} (an HTML or PDF file; or a web page, https://\u2026)`):!c&&!ke(a)?s.push(`${r}: an embed's frame (${a.slice(0,80)}) shows a web page (https://\u2026, never http) or an HTML or PDF file of the document's folder (assets/<file>)`):!c&&!he.existsSync($e.join(n,a))?s.push(`${r}: the embed's file ${a} is not in the document's folder`):(c||/\.html?$/i.test(a))&&i===void 0?s.push(`${r}: an embed's frame (${a.slice(0,80)}) is sandboxed: sandbox="allow-scripts allow-popups \u2026"`):!c&&/\.html?$/i.test(a)&&/\ballow-same-origin\b/.test(i)?s.push(`${r}: an embedded HTML file (${a}) keeps its own origin: its sandbox has no allow-same-origin`):!c&&/\.pdf$/i.test(a)&&i!==void 0&&s.push(`${r}: an embedded PDF (${a}) is sandboxed, and a sandboxed frame shows no PDF: take its sandbox attribute off`)}return[...new Set(s)]}import Oe from"node:fs";import Se from"node:path";import{reportsDirectory as ve}from"../browser/shared/paths.mjs";import{assetFile as Fe,assetProblem as Le}from"../browser/shared/media.mjs";import{attr as z,hasClass as Ee,walk as Ce}from"../browser/shared/html-tree.mjs";function F(e,n=w(e)){let o=[];return Ce(n,s=>{s.tagName==="figure"&&Ee(s,"doc-file")&&o.push({node:s,link:k(s,"a","doc-file-link")})}),o}function Et(e,{slug:n,mode:o="export",reportsDirectory:s=ve}){if(!e.includes("doc-file"))return e;let t=F(e).flatMap(({link:r})=>r?[r]:[]);return x(e,t,{attribute:"href",route:"file",slug:n,mode:o,reportsDirectory:s})}function Ct({html:e,directory:n,tree:o=w(e)}){let s=[];for(let{link:t}of F(e,o)){if(!t)continue;let r=`line ${t.sourceCodeLocation?.startLine}`,a=z(t,"href")??"";Fe(a)?Oe.existsSync(Se.join(n,a))||s.push(`${r}: the file block's file ${a} is not in the document's folder`):s.push(`${r}: a file block's file (${a.slice(0,80)}): ${Le(a)} (<a class="doc-file-link" href="assets/<file>" download="<name>">)`),z(t,"download")||s.push(`${r}: a file block's link (${a.slice(0,80)}) says the name to save it as: download="<name>"`)}return[...new Set(s)]}import Ne from"node:fs";import De from"node:path";import{reportsDirectory as Re}from"../browser/shared/paths.mjs";import{assetProblem as W,imageFile as K}from"../browser/shared/media.mjs";import{attr as R,hasClass as Me,walk as M}from"../browser/shared/html-tree.mjs";var je={"doc-image":"image","doc-bookmark":"bookmark"},Te={image:"an image's picture",bookmark:"a bookmark's icon or cover"},Pe=/doc-(?:image|bookmark|link-mention-icon)/;function G(e){let n=[];return M(e,o=>{let s=o.tagName==="figure"&&(R(o,"class")??"").split(/\s+/).map(t=>je[t]).find(Boolean);s&&n.push({node:o,kind:s})}),n}function L(e,n=w(e)){let o=new Map,s=(t,r,a)=>{let i=t.sourceCodeLocation;i&&!o.has(i.startOffset)&&o.set(i.startOffset,{at:i.startOffset,line:i.startLine,node:t,what:r,kind:a,mention:a==="mention"})};for(let{node:t,kind:r}of G(n))M(t,a=>a.tagName==="img"&&s(a,Te[r],r));return M(n,t=>t.tagName==="img"&&Me(t,"doc-link-mention-icon")&&s(t,"a link's icon","mention")),[...o.values()].sort((t,r)=>t.at-r.at)}function Ut(e,{slug:n,mode:o="export",reportsDirectory:s=Re}){return Pe.test(e)?x(e,L(e).map(({node:t})=>t),{attribute:"src",route:"asset",slug:n,mode:o,reportsDirectory:s}):e}function At({html:e,directory:n,tree:o=w(e)}){let s=[];for(let{line:t,node:r,what:a,mention:i}of L(e,o)){let c=R(r,"src");i&&!K(c)?s.push(`line ${t}: a link's icon (${(c??"").slice(0,80)}): ${W(c,{picture:!0})}; or write an empty <span class="doc-link-mention-icon"></span>`):c===void 0?s.push(`line ${t}: ${a} has no src: <img src="assets/<file>" alt="\u2026">`):K(c)?Ne.existsSync(De.join(n,c))||s.push(`line ${t}: ${a} ${c} is not in the document's folder`):s.push(`line ${t}: ${a} (${c.slice(0,80)}): ${W(c,{picture:!0})}`)}for(let{node:t,kind:r}of G(o)){let a=r==="bookmark"?k(t,"a","doc-bookmark-card"):null,i=a&&R(a,"href");a&&!/^https?:\/\/[^\s"]+$/.test(i??"")&&s.push(`line ${a.sourceCodeLocation?.startLine}: a bookmark's link (${(i??"").slice(0,80)}) is a web address: <a class="doc-bookmark-card" href="https://\u2026">`)}return[...new Set(s)]}import ee from"node:fs";import te from"node:path";import{escapeAttribute as S}from"../browser/shared/escape.mjs";import{attr as y,hasClass as Be,walk as Ue}from"../browser/shared/html-tree.mjs";import{cssReferences as q}from"../browser/shared/css-references.mjs";import{assetFile as Ae,assetProblem as _e,imageFile as He,mediaUrl as Ie,referencedFile as v}from"../browser/shared/media.mjs";import{reportsDirectory as ze}from"../browser/shared/paths.mjs";import{documentDirectory as We}from"../browser/shared/workspace.mjs";var Y=/^\s*(?:\.\/)?assets\//i,J=1e6;function Ke(e){let n=[],o=0;for(;o<e.length;){for(;o<e.length&&/[\s,]/.test(e[o]);)o++;if(o>=e.length)break;let s=o;for(;s<e.length&&!/\s/.test(e[s]);)s++;let t=e.slice(o,s),r="";if(t.endsWith(","))t=t.replace(/,+$/,""),o=s;else{let i=s;for(let c=0;i<e.length&&(e[i]!==","||c>0);i++)e[i]==="("?c++:e[i]===")"&&c--;r=e.slice(s,i).trim(),o=i+1}let a=r.split(/\s+/).find(i=>/^\d*\.?\d+[wx]$/i.test(i));n.push({url:t,descriptor:r,size:a?parseFloat(a):1,wide:/w$/i.test(a??"")})}return n}function Ge(e){let n=e.filter(o=>o.wide);return(n.length>0?n:e).reduce((o,s)=>!o||s.size>o.size?s:o,null)}var qe=new Set(["body","table","thead","tbody","tfoot","tr","td","th"]);function T(e,n,o=s=>Y.test(s)){let s=[],t=r=>{o(r.value,r.node)&&s.push({...r,value:r.value.trim(),written:r.css?.written})};return Ue(n,r=>{let a=r.sourceCodeLocation;if(a){for(let{name:i,value:c,prefix:l}of r.attrs){let f=l?`${l}:${i}`:i,d=a.attrs?.[f],u={node:r,how:i,key:f,place:d,line:d?.startLine??a.startLine};if(i==="src"||i==="href"||i==="poster"||i==="data"&&r.tagName==="object"||i==="background"&&qe.has(r.tagName))t({...u,value:c});else if(i==="srcset"){let p=Ke(c),g=Ge(p.filter(b=>Y.test(b.url)));p.forEach((b,m)=>t({...u,value:b.url,candidates:p,index:m,largest:b===g}))}else if(i==="style")for(let p of q(c))t({...u,value:p.value,css:p})}if(r.tagName==="style")for(let i of r.childNodes){if(i.nodeName!=="#text"||!i.sourceCodeLocation)continue;let{startOffset:c,endOffset:l}=i.sourceCodeLocation;for(let f of q(e.slice(c,l)))t({node:r,how:"css",value:f.value,line:U(e,c+f.index),css:{...f,offset:c}})}}}),s}function se(e,n){let o=new Map;for(let{at:s,kind:t}of L(e,n))o.set(s,{attribute:"src",owner:"block",icon:t!=="image"});for(let{link:s}of F(e,n))s&&o.set(s.sourceCodeLocation.startOffset,{attribute:"href",owner:"block"});for(let s of I(e,n))o.set(s,{attribute:"src",owner:"block"});for(let s of A(e))o.set(s,{attribute:"src",owner:"icon"});return o}var oe=(e,n)=>{let o=e.get(n.node.sourceCodeLocation.startOffset);return o?.attribute===n.how?o:null},Ye=new Set(["img","input","video","audio","source","track"]),Q="an export holds no stylesheet of the folder (the addresses in one are read from its own place): put its rules in the page's <style>",V=e=>(y(e,"rel")??"").toLowerCase().split(/\s+/),j=/\.html?$/i,Je={html:'src="assets/<file>.html" sandbox="allow-scripts"',pdf:'src="assets/<file>.pdf"'},P=e=>`<figure class="doc-embed doc-embed--file"><iframe class="doc-embed-frame" ${Je[e]}></iframe><figcaption></figcaption></figure>`,X=`its frame with no sandbox (a sandboxed one shows no PDF): ${P("pdf")}`,Z='show a picture with <img src="assets/<file>">, a file to save with a link, <a href="assets/<file>" download="<name>">';function B({node:e,how:n,css:o,value:s}){let t=e.tagName;if(n==="style"||n==="css")return o.kind==="import"?{not:Q}:{use:"shown"};if(n==="srcset"&&(t==="img"||t==="source")||n==="poster"&&t==="video"||n==="src"&&Ye.has(t)||n==="background")return{use:"shown"};if(n==="src"&&t==="iframe"){let r=v(s)??"";return j.test(r)?{use:"frame"}:/\.pdf$/i.test(r)?{not:`a PDF shows in an embed block alone (the kit hands its file to the browser's PDF viewer, in the preview and in an export): make it one, ${X}`}:{not:`a frame shows a page of the folder (an HTML file), not this file, which the preview would hand out for saving: ${Z}`}}if(n==="href"&&(t==="a"||t==="area"))return{use:"link"};if(n==="href"&&(t==="image"||t==="link"&&V(e).some(r=>r.endsWith("icon"))))return{use:"shown"};if(t==="object"||t==="embed"){let r=v(s)??"";return{not:`an export's policy loads no plugin content (<object>, <embed>): ${/\.pdf$/i.test(r)?`show a PDF in an embed block, ${X}`:j.test(r)?`show a page in an embed block, ${P("html")}`:Z}`}}return t==="script"?{not:"an export runs the page's own scripts alone: put the code in the page's <script>"}:t==="link"&&V(e).includes("stylesheet")?{not:Q}:{not:"an export holds a file of the folder as a picture, a font, a video or audio, a link or a frame, not there"}}var E=e=>e.startsWith("assets/")&&Ae(e),Qe=e=>_e(e)??`the folder is assets/, in lowercase: write it so (assets/${e.slice(7)})`,ne=(e,n,o)=>n==="link"&&j.test(o)&&y(e.node,"download")===void 0,Ve=(e,n)=>e==="frame"?"embed":e==="shown"&&He(n)?"asset":"file",Xe=(e,n)=>!!ee.statSync(te.join(e,n),{throwIfNoEntry:!1})?.isFile(),O=({node:e,how:n,value:o,written:s})=>({srcset:`<${e.tagName} srcset="\u2026 ${o} \u2026">`,style:`${s} in the style of <${e.tagName}>`,css:`${s} in <style>`})[n]??`<${e.tagName} ${n}="${o}">`,Ze=e=>{for(let n=e.parentNode;n;n=n.parentNode)if(n.tagName&&Be(n,"doc-icon"))return!0;return!1},et=e=>e.length>1?`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`:`${e[0]}`;function tt(e,n){let o=new Map;for(let{file:a,line:i,owned:c}of e){let l=o.get(a)??o.set(a,{lines:[],owned:!1}).get(a);c?l.owned=!0:l.lines.push(i)}let s=0,t=[];for(let[a,{lines:i,owned:c}]of o){let l=c?i.length:i.length-1;if(l<1)continue;let f=l*Math.ceil(ee.statSync(te.join(n,a)).size/3)*4;s+=f;let d=i.length===1?"once":i.length===2?"twice":`${i.length} times`;t.push({bytes:f,said:`${a} ${d}${c?" besides a media block's or the icon's":""} (line${new Set(i).size>1?"s":""} ${et([...new Set(i)])})`})}if(s<=J)return[];let r=t.sort((a,i)=>i.bytes-a.bytes).map(({said:a})=>a).join(", ");return[`files embedded more than once make an export ${s.toLocaleString("en-US")} bytes bigger, over the ${J.toLocaleString("en-US")} bytes the copies outside the media blocks may add: ${r}; show each fewer times (a picture, a link or a frame holds a copy of its own each time it is written), or, for a CSS background (url() in a <style> or a style attribute), name it once in the page's <style> (--picture: url(assets/<file>)) and write var(--picture) where it shows`]}function re({html:e,directory:n,tree:o}){let s=se(e,o),t=[],r=[],a=[];for(let i of T(e,o)){let{line:c}=i,l=oe(s,i),f=v(i.value),d=f!==null&&Xe(n,f);if(d&&!E(f)&&a.push({file:f,line:c}),l?.owner==="block"){d&&E(f)&&r.push({file:f,line:c,owned:!0,icon:!!l.icon});continue}if(d||t.push(l?`line ${c}: the icon's image ${i.value} is not in the document's folder`:`line ${c}: ${O(i)} names a file that is not in the document's folder`),l){d&&r.push({file:f,line:c,owned:!0,icon:!0});continue}let{use:u,not:p}=B(i);p&&t.push(`line ${c}: ${O(i)}: ${p}`),!(!u||!d)&&(E(f)?ne(i,u,f)?t.push(`line ${c}: ${O(i)} opens an HTML file, which an export cannot (a browser opens no page from a data: address): show it in an embed block, ${P("html")}, or give the link download="<name>" to hand it out as a file`):i.node.tagName==="img"&&i.how==="src"&&Ze(i.node)?t.push(`line ${c}: ${O(i)} is in an icon (.doc-icon) written as an icon is not read (its picker, the browser tab's icon): write it <div class="doc-icon"><img src="assets/<file>" alt=""></div>, in double quotes and with no other class`):(i.how!=="srcset"||i.largest)&&r.push({file:f,line:c}):t.push(`line ${c}: ${O(i)}: ${Qe(f)}`))}return{failures:t,embedded:r,unserved:a}}function ts({html:e,directory:n,tree:o=w(e)}){let{failures:s,embedded:t}=re({html:e,directory:n,tree:o});return[...new Set([...s,...tt(t,n)])]}function ss({html:e,directory:n,tree:o=w(e)}){let{embedded:s,unserved:t}=re({html:e,directory:n,tree:o});return{embedded:s.map(({file:r,line:a,icon:i=!1})=>({file:r,line:a,icon:i})),unserved:t}}function st(e,{slug:n,mode:o,directory:s}){let{use:t}=B(e),r=v(e.value);if(!t||!r||!E(r)||ne(e,t,r))return null;let a=/#.*$/.exec(e.value)?.[0]??"";if(o==="preview")return`${Ie(Ve(t,r),n,r)}${a}`;let i=N(s,r);return i&&`${i}${a}`}function ot(e,n,{mode:o,shown:s}){let[t]=n,{node:r,how:a,key:i}=t,c=(m,h="")=>({start:e.startOffset,end:e.endOffset,text:`${i}="${S(m)}"${h}`}),l=o==="preview"?` data-ge-${a}="${S(y(r,a)??"")}"`:"",d=(o==="preview"?[`data-ge-${a}`,`data-rs-${a}`].map(m=>r.sourceCodeLocation.attrs?.[m]).filter(Boolean):[]).map(m=>({start:m.startOffset,end:m.endOffset,text:""}));if(a==="srcset"){if(o==="export"){let h=n.find(C=>C.largest),$=h&&s(h);return $?[c(`${$} ${h.candidates[h.index].descriptor}`.trim())]:[]}let m=new Map(n.map(h=>[h.index,s(h)]));return[...m.values()].some(Boolean)?[c(t.candidates.map((h,$)=>[m.get($)??h.url,h.descriptor].filter(Boolean).join(" ")).join(", "),l),...d]:[]}if(a==="style"){let m=y(r,"style"),h=n.map($=>({...$.css,address:s($)})).filter($=>$.address).sort(($,C)=>C.start-$.start);for(let $ of h)m=`${m.slice(0,$.start)}${$.address}${m.slice($.end)}`;return h.length>0?[c(m)]:[]}let u=s(t);if(!u)return[];if(o==="preview"||B(t).use!=="link")return[c(u,l),...d];let p=v(t.value).slice(7),g=y(r,"download");if(g===void 0)return[c(u,` download="${S(p)}"`)];let b=r.sourceCodeLocation.attrs?.download;return[c(u),...g===""&&b?[{start:b.startOffset,end:b.endOffset,text:`download="${S(p)}"`}]:[]]}function nt(e,n){let o=[],s=0;for(let{start:t,end:r,text:a}of[...n].sort((i,c)=>i.start-c.start))t<s||(o.push(e.slice(s,t),a),s=r);return o.push(e.slice(s)),o.join("")}var os=(e,n,o=w(e))=>T(e,o,n);function ns(e,n){let o=[],s=new Map;for(let t of e){let r=n(t);typeof r=="string"&&(t.how==="css"?o.push({start:t.css.offset+t.css.start,end:t.css.offset+t.css.end,text:r}):t.place&&s.set(t.place,[...s.get(t.place)??[],{...t,address:r}]))}for(let[t,r]of s){let[{node:a,how:i,key:c,candidates:l}]=r,f=r[0].address;if(i==="srcset"){let d=new Map(r.map(u=>[u.index,u.address]));f=l.map((u,p)=>[d.get(p)??u.url,u.descriptor].filter(Boolean).join(" ")).join(", ")}else if(i==="style"){f=y(a,"style");for(let{css:d,address:u}of[...r].sort((p,g)=>g.css.start-p.css.start))f=`${f.slice(0,d.start)}${u}${f.slice(d.end)}`}o.push({start:t.startOffset,end:t.endOffset,text:`${c}="${S(f)}"`})}return o}function rs(e,{slug:n,mode:o="export",reportsDirectory:s=ze}){if(!/assets\//i.test(e.replace(/\sdata-ge-(?:src|href|icon)="[^"]*"/g,"")))return e;let t=w(e),r=se(e,t),a=We(n,s),i=f=>st(f,{slug:n,mode:o,directory:a}),c=[],l=new Map;for(let f of T(e,t))if(!oe(r,f))if(f.how==="css"){let d=i(f),u=f.css.offset;d&&c.push({start:u+f.css.start,end:u+f.css.end,text:d})}else f.place&&l.set(f.place,[...l.get(f.place)??[],f]);for(let[f,d]of l)c.push(...ot(f,d,{mode:o,shown:i}));return nt(e,c)}export{bt as a,gt as b,Et as c,Ct as d,Ut as e,At as f,ts as g,ss as h,nt as i,os as j,ns as k,rs as l};
2
+ import{f as A}from"./chunk-U5XL7D6A.mjs";import{a as w,c as U}from"./chunk-HYMEEXKN.mjs";import he from"node:fs";import $e from"node:path";import{reportsDirectory as we}from"../browser/shared/paths.mjs";import{assetFile as be,assetProblem as ge,embedFile as ke}from"../browser/shared/media.mjs";import{attr as H,hasClass as xe,walk as ye}from"../browser/shared/html-tree.mjs";import _ from"node:fs";import ie from"node:path";import{attr as ae,hasClass as ce,walk as fe}from"../browser/shared/html-tree.mjs";import{MEDIA_ROUTES as le,mediaTypeOf as de,mediaUrl as ue}from"../browser/shared/media.mjs";import{documentDirectory as pe}from"../browser/shared/workspace.mjs";function k(e,n,o){let s=null;return fe(e,t=>{!s&&t.tagName===n&&ce(t,o)&&(s=t)}),s}function N(e,n){let o=ie.join(e,n);return _.statSync(o,{throwIfNoEntry:!1})?.isFile()?`data:${de(n)};base64,${_.readFileSync(o).toString("base64")}`:null}function me(e,{attribute:n,route:o,slug:s,mode:t,reportsDirectory:r}){if(!le[o](e))return null;if(t==="preview")return`${n}="${ue(o,s,e)}" data-ge-${n}="${e}"`;let a=N(pe(s,r),e);return a&&`${n}="${a}"`}function x(e,n,{attribute:o,route:s,slug:t,mode:r,reportsDirectory:a}){let i=n.map(f=>({place:f.sourceCodeLocation?.attrs?.[o],value:ae(f,o)})).filter(({place:f})=>f).sort((f,d)=>f.place.startOffset-d.place.startOffset),c=[],l=0;for(let{place:f,value:d}of i){let u=me(d,{attribute:o,route:s,slug:t,mode:r,reportsDirectory:a});u===null||f.startOffset<l||(c.push(e.slice(l,f.startOffset),u),l=f.endOffset)}return c.push(e.slice(l)),c.join("")}function D(e){let n=[];return ye(e,o=>{let s=o.tagName==="figure"&&xe(o,"doc-embed")?k(o,"iframe","doc-embed-frame"):null;s&&n.push(s)}),n}function bt(e,{slug:n,mode:o="export",reportsDirectory:s=we}){return e.includes("doc-embed")?x(e,D(w(e)),{attribute:"src",route:"embed",slug:n,mode:o,reportsDirectory:s}):e}var I=(e,n=w(e))=>D(n).map(o=>o.sourceCodeLocation.startOffset);function gt({html:e,directory:n,tree:o=w(e)}){let s=[];for(let t of D(o)){let r=`line ${t.sourceCodeLocation.startLine}`,a=H(t,"src")??"",i=H(t,"sandbox"),c=/^https:\/\/[^\s"]+$/.test(a),l=!c&&!/^[a-z][a-z0-9+.-]*:/i.test(a)&&!be(a)?ge(a):null;l?s.push(`${r}: an embed's frame (${a.slice(0,80)}): ${l} (an HTML or PDF file; or a web page, https://\u2026)`):!c&&!ke(a)?s.push(`${r}: an embed's frame (${a.slice(0,80)}) shows a web page (https://\u2026, never http) or an HTML or PDF file of the document's folder (assets/<file>)`):!c&&!he.existsSync($e.join(n,a))?s.push(`${r}: the embed's file ${a} is not in the document's folder`):(c||/\.html?$/i.test(a))&&i===void 0?s.push(`${r}: an embed's frame (${a.slice(0,80)}) is sandboxed: sandbox="allow-scripts allow-popups \u2026"`):!c&&/\.html?$/i.test(a)&&/\ballow-same-origin\b/.test(i)?s.push(`${r}: an embedded HTML file (${a}) keeps its own origin: its sandbox has no allow-same-origin`):!c&&/\.pdf$/i.test(a)&&i!==void 0&&s.push(`${r}: an embedded PDF (${a}) is sandboxed, and a sandboxed frame shows no PDF: take its sandbox attribute off`)}return[...new Set(s)]}import Oe from"node:fs";import Se from"node:path";import{reportsDirectory as ve}from"../browser/shared/paths.mjs";import{assetFile as Fe,assetProblem as Le}from"../browser/shared/media.mjs";import{attr as z,hasClass as Ee,walk as Ce}from"../browser/shared/html-tree.mjs";function F(e,n=w(e)){let o=[];return Ce(n,s=>{s.tagName==="figure"&&Ee(s,"doc-file")&&o.push({node:s,link:k(s,"a","doc-file-link")})}),o}function Et(e,{slug:n,mode:o="export",reportsDirectory:s=ve}){if(!e.includes("doc-file"))return e;let t=F(e).flatMap(({link:r})=>r?[r]:[]);return x(e,t,{attribute:"href",route:"file",slug:n,mode:o,reportsDirectory:s})}function Ct({html:e,directory:n,tree:o=w(e)}){let s=[];for(let{link:t}of F(e,o)){if(!t)continue;let r=`line ${t.sourceCodeLocation?.startLine}`,a=z(t,"href")??"";Fe(a)?Oe.existsSync(Se.join(n,a))||s.push(`${r}: the file block's file ${a} is not in the document's folder`):s.push(`${r}: a file block's file (${a.slice(0,80)}): ${Le(a)} (<a class="doc-file-link" href="assets/<file>" download="<name>">)`),z(t,"download")||s.push(`${r}: a file block's link (${a.slice(0,80)}) says the name to save it as: download="<name>"`)}return[...new Set(s)]}import Ne from"node:fs";import De from"node:path";import{reportsDirectory as Re}from"../browser/shared/paths.mjs";import{assetProblem as W,imageFile as K}from"../browser/shared/media.mjs";import{attr as R,hasClass as Me,walk as M}from"../browser/shared/html-tree.mjs";var je={"doc-image":"image","doc-bookmark":"bookmark"},Te={image:"an image's picture",bookmark:"a bookmark's icon or cover"},Pe=/doc-(?:image|bookmark|link-mention-icon)/;function G(e){let n=[];return M(e,o=>{let s=o.tagName==="figure"&&(R(o,"class")??"").split(/\s+/).map(t=>je[t]).find(Boolean);s&&n.push({node:o,kind:s})}),n}function L(e,n=w(e)){let o=new Map,s=(t,r,a)=>{let i=t.sourceCodeLocation;i&&!o.has(i.startOffset)&&o.set(i.startOffset,{at:i.startOffset,line:i.startLine,node:t,what:r,kind:a,mention:a==="mention"})};for(let{node:t,kind:r}of G(n))M(t,a=>a.tagName==="img"&&s(a,Te[r],r));return M(n,t=>t.tagName==="img"&&Me(t,"doc-link-mention-icon")&&s(t,"a link's icon","mention")),[...o.values()].sort((t,r)=>t.at-r.at)}function Ut(e,{slug:n,mode:o="export",reportsDirectory:s=Re}){return Pe.test(e)?x(e,L(e).map(({node:t})=>t),{attribute:"src",route:"asset",slug:n,mode:o,reportsDirectory:s}):e}function At({html:e,directory:n,tree:o=w(e)}){let s=[];for(let{line:t,node:r,what:a,mention:i}of L(e,o)){let c=R(r,"src");i&&!K(c)?s.push(`line ${t}: a link's icon (${(c??"").slice(0,80)}): ${W(c,{picture:!0})}; or write an empty <span class="doc-link-mention-icon"></span>`):c===void 0?s.push(`line ${t}: ${a} has no src: <img src="assets/<file>" alt="\u2026">`):K(c)?Ne.existsSync(De.join(n,c))||s.push(`line ${t}: ${a} ${c} is not in the document's folder`):s.push(`line ${t}: ${a} (${c.slice(0,80)}): ${W(c,{picture:!0})}`)}for(let{node:t,kind:r}of G(o)){let a=r==="bookmark"?k(t,"a","doc-bookmark-card"):null,i=a&&R(a,"href");a&&!/^https?:\/\/[^\s"]+$/.test(i??"")&&s.push(`line ${a.sourceCodeLocation?.startLine}: a bookmark's link (${(i??"").slice(0,80)}) is a web address: <a class="doc-bookmark-card" href="https://\u2026">`)}return[...new Set(s)]}import ee from"node:fs";import te from"node:path";import{escapeAttribute as S}from"../browser/shared/escape.mjs";import{attr as y,hasClass as Be,walk as Ue}from"../browser/shared/html-tree.mjs";import{cssReferences as q}from"../browser/shared/css-references.mjs";import{assetFile as Ae,assetProblem as _e,imageFile as He,mediaUrl as Ie,referencedFile as v}from"../browser/shared/media.mjs";import{reportsDirectory as ze}from"../browser/shared/paths.mjs";import{documentDirectory as We}from"../browser/shared/workspace.mjs";var Y=/^\s*(?:\.\/)?assets\//i,J=1e6;function Ke(e){let n=[],o=0;for(;o<e.length;){for(;o<e.length&&/[\s,]/.test(e[o]);)o++;if(o>=e.length)break;let s=o;for(;s<e.length&&!/\s/.test(e[s]);)s++;let t=e.slice(o,s),r="";if(t.endsWith(","))t=t.replace(/,+$/,""),o=s;else{let i=s;for(let c=0;i<e.length&&(e[i]!==","||c>0);i++)e[i]==="("?c++:e[i]===")"&&c--;r=e.slice(s,i).trim(),o=i+1}let a=r.split(/\s+/).find(i=>/^\d*\.?\d+[wx]$/i.test(i));n.push({url:t,descriptor:r,size:a?parseFloat(a):1,wide:/w$/i.test(a??"")})}return n}function Ge(e){let n=e.filter(o=>o.wide);return(n.length>0?n:e).reduce((o,s)=>!o||s.size>o.size?s:o,null)}var qe=new Set(["body","table","thead","tbody","tfoot","tr","td","th"]);function T(e,n,o=s=>Y.test(s)){let s=[],t=r=>{o(r.value,r.node)&&s.push({...r,value:r.value.trim(),written:r.css?.written})};return Ue(n,r=>{let a=r.sourceCodeLocation;if(a){for(let{name:i,value:c,prefix:l}of r.attrs){let f=l?`${l}:${i}`:i,d=a.attrs?.[f],u={node:r,how:i,key:f,place:d,line:d?.startLine??a.startLine};if(i==="src"||i==="href"||i==="poster"||i==="data"&&r.tagName==="object"||i==="background"&&qe.has(r.tagName))t({...u,value:c});else if(i==="srcset"){let p=Ke(c),g=Ge(p.filter(b=>Y.test(b.url)));p.forEach((b,m)=>t({...u,value:b.url,candidates:p,index:m,largest:b===g}))}else if(i==="style")for(let p of q(c))t({...u,value:p.value,css:p})}if(r.tagName==="style")for(let i of r.childNodes){if(i.nodeName!=="#text"||!i.sourceCodeLocation)continue;let{startOffset:c,endOffset:l}=i.sourceCodeLocation;for(let f of q(e.slice(c,l)))t({node:r,how:"css",value:f.value,line:U(e,c+f.index),css:{...f,offset:c}})}}}),s}function se(e,n){let o=new Map;for(let{at:s,kind:t}of L(e,n))o.set(s,{attribute:"src",owner:"block",icon:t!=="image"});for(let{link:s}of F(e,n))s&&o.set(s.sourceCodeLocation.startOffset,{attribute:"href",owner:"block"});for(let s of I(e,n))o.set(s,{attribute:"src",owner:"block"});for(let s of A(e))o.set(s,{attribute:"src",owner:"icon"});return o}var oe=(e,n)=>{let o=e.get(n.node.sourceCodeLocation.startOffset);return o?.attribute===n.how?o:null},Ye=new Set(["img","input","video","audio","source","track"]),Q="an export holds no stylesheet of the folder (the addresses in one are read from its own place): put its rules in the page's <style>",V=e=>(y(e,"rel")??"").toLowerCase().split(/\s+/),j=/\.html?$/i,Je={html:'src="assets/<file>.html" sandbox="allow-scripts"',pdf:'src="assets/<file>.pdf"'},P=e=>`<figure class="doc-embed doc-embed--file"><iframe class="doc-embed-frame" ${Je[e]}></iframe><figcaption></figcaption></figure>`,X=`its frame with no sandbox (a sandboxed one shows no PDF): ${P("pdf")}`,Z='show a picture with <img src="assets/<file>">, a file to save with a link, <a href="assets/<file>" download="<name>">';function B({node:e,how:n,css:o,value:s}){let t=e.tagName;if(n==="style"||n==="css")return o.kind==="import"?{not:Q}:{use:"shown"};if(n==="srcset"&&(t==="img"||t==="source")||n==="poster"&&t==="video"||n==="src"&&Ye.has(t)||n==="background")return{use:"shown"};if(n==="src"&&t==="iframe"){let r=v(s)??"";return j.test(r)?{use:"frame"}:/\.pdf$/i.test(r)?{not:`a PDF shows in an embed block alone (the kit hands its file to the browser's PDF viewer, in the preview and in an export): make it one, ${X}`}:{not:`a frame shows a page of the folder (an HTML file), not this file, which the preview would hand out for saving: ${Z}`}}if(n==="href"&&(t==="a"||t==="area"))return{use:"link"};if(n==="href"&&(t==="image"||t==="link"&&V(e).some(r=>r.endsWith("icon"))))return{use:"shown"};if(t==="object"||t==="embed"){let r=v(s)??"";return{not:`an export's policy loads no plugin content (<object>, <embed>): ${/\.pdf$/i.test(r)?`show a PDF in an embed block, ${X}`:j.test(r)?`show a page in an embed block, ${P("html")}`:Z}`}}return t==="script"?{not:"an export runs the page's own scripts alone: put the code in the page's <script>"}:t==="link"&&V(e).includes("stylesheet")?{not:Q}:{not:"an export holds a file of the folder as a picture, a font, a video or audio, a link or a frame, not there"}}var E=e=>e.startsWith("assets/")&&Ae(e),Qe=e=>_e(e)??`the folder is assets/, in lowercase: write it so (assets/${e.slice(7)})`,ne=(e,n,o)=>n==="link"&&j.test(o)&&y(e.node,"download")===void 0,Ve=(e,n)=>e==="frame"?"embed":e==="shown"&&He(n)?"asset":"file",Xe=(e,n)=>!!ee.statSync(te.join(e,n),{throwIfNoEntry:!1})?.isFile(),O=({node:e,how:n,value:o,written:s})=>({srcset:`<${e.tagName} srcset="\u2026 ${o} \u2026">`,style:`${s} in the style of <${e.tagName}>`,css:`${s} in <style>`})[n]??`<${e.tagName} ${n}="${o}">`,Ze=e=>{for(let n=e.parentNode;n;n=n.parentNode)if(n.tagName&&Be(n,"doc-icon"))return!0;return!1},et=e=>e.length>1?`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`:`${e[0]}`;function tt(e,n){let o=new Map;for(let{file:a,line:i,owned:c}of e){let l=o.get(a)??o.set(a,{lines:[],owned:!1}).get(a);c?l.owned=!0:l.lines.push(i)}let s=0,t=[];for(let[a,{lines:i,owned:c}]of o){let l=c?i.length:i.length-1;if(l<1)continue;let f=l*Math.ceil(ee.statSync(te.join(n,a)).size/3)*4;s+=f;let d=i.length===1?"once":i.length===2?"twice":`${i.length} times`;t.push({bytes:f,said:`${a} ${d}${c?" besides a media block's or the icon's":""} (line${new Set(i).size>1?"s":""} ${et([...new Set(i)])})`})}if(s<=J)return[];let r=t.sort((a,i)=>i.bytes-a.bytes).map(({said:a})=>a).join(", ");return[`files embedded more than once make an export ${s.toLocaleString("en-US")} bytes bigger, over the ${J.toLocaleString("en-US")} bytes the copies outside the media blocks may add: ${r}; show each fewer times (a picture, a link or a frame holds a copy of its own each time it is written), or, for a CSS background (url() in a <style> or a style attribute), name it once in the page's <style> (--picture: url(assets/<file>)) and write var(--picture) where it shows`]}function re({html:e,directory:n,tree:o}){let s=se(e,o),t=[],r=[],a=[];for(let i of T(e,o)){let{line:c}=i,l=oe(s,i),f=v(i.value),d=f!==null&&Xe(n,f);if(d&&!E(f)&&a.push({file:f,line:c}),l?.owner==="block"){d&&E(f)&&r.push({file:f,line:c,owned:!0,icon:!!l.icon});continue}if(d||t.push(l?`line ${c}: the icon's image ${i.value} is not in the document's folder`:`line ${c}: ${O(i)} names a file that is not in the document's folder`),l){d&&r.push({file:f,line:c,owned:!0,icon:!0});continue}let{use:u,not:p}=B(i);p&&t.push(`line ${c}: ${O(i)}: ${p}`),!(!u||!d)&&(E(f)?ne(i,u,f)?t.push(`line ${c}: ${O(i)} opens an HTML file, which an export cannot (a browser opens no page from a data: address): show it in an embed block, ${P("html")}, or give the link download="<name>" to hand it out as a file`):i.node.tagName==="img"&&i.how==="src"&&Ze(i.node)?t.push(`line ${c}: ${O(i)} is in an icon (.doc-icon) written as an icon is not read (its picker, the browser tab's icon): write it <div class="doc-icon"><img src="assets/<file>" alt=""></div>, in double quotes and with no other class`):(i.how!=="srcset"||i.largest)&&r.push({file:f,line:c}):t.push(`line ${c}: ${O(i)}: ${Qe(f)}`))}return{failures:t,embedded:r,unserved:a}}function ts({html:e,directory:n,tree:o=w(e)}){let{failures:s,embedded:t}=re({html:e,directory:n,tree:o});return[...new Set([...s,...tt(t,n)])]}function ss({html:e,directory:n,tree:o=w(e)}){let{embedded:s,unserved:t}=re({html:e,directory:n,tree:o});return{embedded:s.map(({file:r,line:a,icon:i=!1})=>({file:r,line:a,icon:i})),unserved:t}}function st(e,{slug:n,mode:o,directory:s}){let{use:t}=B(e),r=v(e.value);if(!t||!r||!E(r)||ne(e,t,r))return null;let a=/#.*$/.exec(e.value)?.[0]??"";if(o==="preview")return`${Ie(Ve(t,r),n,r)}${a}`;let i=N(s,r);return i&&`${i}${a}`}function ot(e,n,{mode:o,shown:s}){let[t]=n,{node:r,how:a,key:i}=t,c=(m,h="")=>({start:e.startOffset,end:e.endOffset,text:`${i}="${S(m)}"${h}`}),l=o==="preview"?` data-ge-${a}="${S(y(r,a)??"")}"`:"",d=(o==="preview"?[`data-ge-${a}`,`data-rs-${a}`].map(m=>r.sourceCodeLocation.attrs?.[m]).filter(Boolean):[]).map(m=>({start:m.startOffset,end:m.endOffset,text:""}));if(a==="srcset"){if(o==="export"){let h=n.find(C=>C.largest),$=h&&s(h);return $?[c(`${$} ${h.candidates[h.index].descriptor}`.trim())]:[]}let m=new Map(n.map(h=>[h.index,s(h)]));return[...m.values()].some(Boolean)?[c(t.candidates.map((h,$)=>[m.get($)??h.url,h.descriptor].filter(Boolean).join(" ")).join(", "),l),...d]:[]}if(a==="style"){let m=y(r,"style"),h=n.map($=>({...$.css,address:s($)})).filter($=>$.address).sort(($,C)=>C.start-$.start);for(let $ of h)m=`${m.slice(0,$.start)}${$.address}${m.slice($.end)}`;return h.length>0?[c(m)]:[]}let u=s(t);if(!u)return[];if(o==="preview"||B(t).use!=="link")return[c(u,l),...d];let p=v(t.value).slice(7),g=y(r,"download");if(g===void 0)return[c(u,` download="${S(p)}"`)];let b=r.sourceCodeLocation.attrs?.download;return[c(u),...g===""&&b?[{start:b.startOffset,end:b.endOffset,text:`download="${S(p)}"`}]:[]]}function nt(e,n){let o=[],s=0;for(let{start:t,end:r,text:a}of[...n].sort((i,c)=>i.start-c.start))t<s||(o.push(e.slice(s,t),a),s=r);return o.push(e.slice(s)),o.join("")}var os=(e,n,o=w(e))=>T(e,o,n);function ns(e,n){let o=[],s=new Map;for(let t of e){let r=n(t);typeof r=="string"&&(t.how==="css"?o.push({start:t.css.offset+t.css.start,end:t.css.offset+t.css.end,text:r}):t.place&&s.set(t.place,[...s.get(t.place)??[],{...t,address:r}]))}for(let[t,r]of s){let[{node:a,how:i,key:c,candidates:l}]=r,f=r[0].address;if(i==="srcset"){let d=new Map(r.map(u=>[u.index,u.address]));f=l.map((u,p)=>[d.get(p)??u.url,u.descriptor].filter(Boolean).join(" ")).join(", ")}else if(i==="style"){f=y(a,"style");for(let{css:d,address:u}of[...r].sort((p,g)=>g.css.start-p.css.start))f=`${f.slice(0,d.start)}${u}${f.slice(d.end)}`}o.push({start:t.startOffset,end:t.endOffset,text:`${c}="${S(f)}"`})}return o}function rs(e,{slug:n,mode:o="export",reportsDirectory:s=ze}){if(!/assets\//i.test(e.replace(/\sdata-ge-(?:src|href|icon)="[^"]*"/g,"")))return e;let t=w(e),r=se(e,t),a=We(n,s),i=f=>st(f,{slug:n,mode:o,directory:a}),c=[],l=new Map;for(let f of T(e,t))if(!oe(r,f))if(f.how==="css"){let d=i(f),u=f.css.offset;d&&c.push({start:u+f.css.start,end:u+f.css.end,text:d})}else f.place&&l.set(f.place,[...l.get(f.place)??[],f]);for(let[f,d]of l)c.push(...ot(f,d,{mode:o,shown:i}));return nt(e,c)}export{bt as a,gt as b,Et as c,Ct as d,Ut as e,At as f,ts as g,ss as h,nt as i,os as j,ns as k,rs as l};
@@ -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,b as g,c as h,d as $,e as v,f as y,g as r,h as x}from"./chunk-S6O4UHLC.mjs";import{b as c,f as p}from"./chunk-NSKUTQ5J.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-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};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as R}from"./chunk-OEXWRJME.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-EAIFITAV.mjs";import{a as S,b as k,g as $}from"./chunk-67N2QJYT.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import{b as D}from"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import{b as v}from"./chunk-ZQS6H473.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-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.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};