@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,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g}from"./chunk-67N2QJYT.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./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";export{a as handInReports,e as idLines,f as inStepLines,d as noteNew,b as previewSettled,g as rereadLine,c as roundBegins};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y}from"./chunk-EURLTOTZ.mjs";import"./chunk-Q4UEPUWF.mjs";import"./chunk-5L7RYZCL.mjs";export{d as CACHE_FILE,e as FRESH,c as NEWER_LINE,a as PACKAGE,f as RETRY,b as SKILL_LINE,g as TIMEOUT,j as cacheDirectory,h as checkOff,r as claimCheck,o as latestUrl,w as newerLine,l as npmSettings,k as parseNpmrc,p as readCache,s as refreshCache,n as refreshEnv,m as registryOf,u as skillFolders,v as skillLine,x as skillLines,q as stale,t as startRefresh,y as versionNotes,i as viaNpx};
@@ -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{$ as ha,A as I,B as J,C as K,D as L,E as M,F as N,G as O,H as P,I as Q,J as R,K as S,L as T,M as U,N as V,O as W,P as X,Q as Y,R as Z,S as _,T as $,U as aa,V as ba,W as ca,X as da,Y as ea,Z as fa,_ as ga,a as i,aa as ia,b as j,ba as ja,c as k,ca as ka,d as l,e as m,f as n,g as o,h as p,i as q,j as r,k as s,l as t,m as u,n as v,o as w,p as x,q as y,r as z,s as A,t as B,u as C,v as D,w as E,x as F,y as G,z as H}from"./chunk-HPOI4ZX7.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-EAIFITAV.mjs";import"./chunk-67N2QJYT.mjs";import"./chunk-PUOQ65NC.mjs";import{a,b,c,f as d,g as e,h as f,k as g,l as h}from"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-4OZWXZE5.mjs";import"./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";export{_ as ADVICE,t as BLOCK_PICTURES,$ as CODE_SIDEWAYS,X as HAND_OVER,u as INK_MARGIN,i as KINDS,j as LEVELS,k as LOOKS,Y as LOOK_YOURSELF,W as MORE_PICTURES,M as MOSTLY_CHANGED,y as MOVED_PART,x as MOVED_WHOLE,w as NEIGHBOUR_EDGE,p as PICTURED_INFO,ca as SCROLLS,v as SCROLL_FRAMES,s as SCROLL_SLACK,ba as WARNED,l as WIDE,m as WIDTHS,f as adoptIdless,aa as adviceOf,e as baselineOf,L as baselineSaid,b as blocksOf,N as blocksToPicture,da as describeLooks,S as disclosuresSaid,g as exportBaselines,G as exportOf,ga as exportingFirst,Q as findingKey,q as findingLevel,O as inkOf,P as inventory,n as layoutNotesOf,o as levelOf,R as lookAt,J as missedWidths,V as morePictures,H as movedBlocks,z as movedClips,ha as namedBlocks,I as nextBaseline,ea as notPicturedLine,c as pageOf,r as picturedAt,T as picturesSaid,D as placeOf,h as previewBaseline,a as rankOf,d as readBaseline,ka as run,K as seenOf,C as sourceIndex,F as staleExport,Z as startFailure,E as timeOf,ia as unknownBlocks,ja as unknownBlocksSaid,U as unopenedSaid,A as urlName,fa as verdictOf,B as wordsOf};
@@ -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 v,b as j}from"./chunk-HYMEEXKN.mjs";import l from"node:fs";import p from"node:path";import V from"node:zlib";import{escapeAttribute as $,escapeMarkup as _}from"../browser/shared/escape.mjs";import{componentOf as b,instancesOf as L,partOf as O}from"../browser/shared/components/index.mjs";import{ICON_COLOR_VALUES as I,TAB_ICON as N,glyphOf as B,iconKind as u,iconUrl as T,iconValueOf as S,tabIconValue as R}from"../browser/shared/emoji/icon-value.mjs";import{lineIconSvg as z}from"../browser/shared/emoji/line-icons.mjs";import{mediaTypeOf as A,mediaUrl as J}from"../browser/shared/media.mjs";import{emojiDataDirectory as P,reportsDirectory as E}from"../browser/shared/paths.mjs";import{slugPattern as G}from"../browser/shared/reports.mjs";import{documentDirectory as D}from"../browser/shared/workspace.mjs";var g=P,k=String.fromCodePoint(65039),C=null,x=null;function H(){return C??={positions:JSON.parse(l.readFileSync(p.join(g,"positions.json"),"utf8")),index:JSON.parse(l.readFileSync(p.join(g,"twemoji-index.json"),"utf8")),svg:V.gunzipSync(l.readFileSync(p.join(g,"twemoji-svg.bin")))},C}function F(e){let{positions:t,index:r,svg:o}=H(),n=[e,e.replaceAll(k,""),`${e}${k}`].find(c=>t[c]),i=n&&r[t[n][0]];return i?o.subarray(i[0],i[0]+i[1]):null}function U(e){let t=F(e);return t?`data:image/svg+xml;base64,${t.toString("base64")}`:null}function ue(e){return d(""),[...x.keys()].filter(t=>t.startsWith(`${e}/`)).map(t=>t.slice(e.length+1))}function d(e,t="currentColor"){x??=new Map(JSON.parse(l.readFileSync(p.join(g,"icons.json"),"utf8")).icons.flatMap(([,n,i,c,a])=>[[`mingcute/${n}`,c],[`tabler/${i}`,a]].filter(([,s])=>s)));let r=B(e),o=r&&x.get(`${r.set}/${r.name}`);return o?o.split("#COLOR").join(t).replace("<svg ",'<svg aria-hidden="true" '):null}function K(e){let[t,r]=I[B(e)?.color]??I.gray,o=d(e);return o&&o.replace(/<svg\b[^>]*>/,n=>`${n.replace(/ aria-hidden="true"/,"").replace(/^<svg /,'<svg xmlns="http://www.w3.org/2000/svg" ').replace(/ xmlns="http:\/\/www\.w3\.org\/2000\/svg"(?=.* xmlns=)/,"")}<style>svg{color:${t}}@media (prefers-color-scheme:dark){svg{color:${r}}}</style>`)}var W=e=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><text x="18" y="18" text-anchor="middle" dominant-baseline="central" font-size="30" font-family="'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif">${_(e)}</text></svg>`;function q({value:e,slug:t=null,tab:r=!1,reportsDirectory:o=E}){let n=z(e,{color:"#000",tab:r});if(n)return{type:"image/svg+xml",body:Buffer.from(n)};let i=u(e);if(i==="emoji")return{type:"image/svg+xml",body:F(e)??Buffer.from(W(e))};if(i==="glyph"){let a=r?K(e):d(e,"#000");return a&&{type:"image/svg+xml",body:Buffer.from(a)}}if(i!=="image"||!t||!G.test(t))return null;let c=p.join(D(t,o),e);return l.existsSync(c)?{type:A(e),body:l.readFileSync(c)}:null}var M=/(<div\b[^>]*\bclass="doc-icon"[^>]*>)([\s\S]*?)(<\/div>)/g;function de(e,{slug:t,mode:r="export",reportsDirectory:o=E}){return te(X(e,{mode:r}).replace(M,(n,i,c,a)=>{let s=S(n),y=u(s);if(!y)return n;let f=null;if(y==="emoji"){let m=U(s);f=m&&`<img alt="${$(s)}" src="${m}">`}else if(y==="glyph")f=d(s);else if(r==="preview")f=`<img src="${J("asset",t,s)}" alt="">`;else{let m=p.join(D(t,o),s),w=l.existsSync(m)?l.readFileSync(m):null;f=w&&`<img src="data:${A(s)};base64,${w.toString("base64")}" alt="">`}let h=r==="preview"?i.replace(/>$/,` data-ge-icon="${$(s)}">`):i;return f?`${h}${f}${a}`:`${h}${c}${a}`}),ee(Z(e),{slug:t,mode:r,reportsDirectory:o}))}var ye=e=>[...e.matchAll(M)].flatMap(t=>{let r=u(S(t[0]))==="image"?/<img\b[^>]*\bsrc="/.exec(t[2]):null;return r?[t.index+t[1].length+r.index]:[]}),Q=/<button\b[^>]*\bdata-tab-icon="([^"]*)"[^>]*>/g;function X(e,{mode:t="export"}={}){return e.replace(Q,(r,o)=>{if(u(o)!=="emoji"||r.includes(N))return r;let n=t==="preview"?T(o):U(o);if(!n)return r;let i=`${N}: ${R(n)}`;return/\sstyle="/.test(r)?r.replace(/\sstyle="([^"]*)"/,(c,a)=>` style="${a.replace(/;?\s*$/,"; ")}${i}"`):r.replace(/>$/,` style="${i}">`)})}function Y(e){let t=O(e,b("page").header)[0];return{all:L(e,b("icon")),own:t?O(t,b("icon").match):[]}}function Z(e){let[t]=Y(v(e)).own;return t?S(j(e,t)):null}function ee(e,{slug:t,mode:r,reportsDirectory:o}){if(!e)return null;if(r==="preview")return T(e,t,{tab:!0});let n=q({value:e,slug:t,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${Buffer.from(n.body).toString("base64")}`}var te=(e,t)=>t&&/<\/head>/i.test(e)&&!e.includes("data-doc-tab-icon")?e.replace(/<\/head>/i,()=>` <link rel="icon" href="${$(t)}" data-doc-tab-icon>
3
+ </head>`):e;export{U as a,ue as b,d as c,q as d,de as e,ye as f,Y as g,Z as h};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{e as n,f as g}from"./chunk-5ZKJ3H4P.mjs";import{b as m,f as d}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";import{spawn as P}from"node:child_process";import h from"node:fs/promises";import R from"node:path";import{projectRoot as v,release as k,reportsDirectory as t}from"../browser/shared/paths.mjs";import{answerOf as S,findPreviewServer as x,portIsFree as E,readAnnouncement as G}from"../browser/shared/preview-server.mjs";import{layoutOf as $}from"../browser/shared/workspace.mjs";var b=a=>new Promise(s=>setTimeout(s,a));async function O(a){let{positional:s,values:l}=d({values:["--port"],argv:a});if(s.length>0)throw new m(`gallery serve takes no arguments: ${s[0]}`);let o=l.has("--port")?Number(l.get("--port")):null;if(o!==null&&!(Number.isInteger(o)&&o>0&&o<65536))throw new m(`--port takes a port number: ${l.get("--port")}`);let i=await G({reportsDirectory:t}),f=i?await S(i,t,1e4):"no";f!=="no"&&(console.error(`This workspace's Gallery server runs already: ${n(i.port)} (pid ${i.pid}${f==="busy"?", not answering now":""}). gallery stop stops it; one server serves a workspace.`),process.exit(1));let r=null;if(o!==null)await E(o)||(console.error(`Port ${o} is taken: name another (--port), or leave it out for the first free one.`),process.exit(1)),r=o;else{for(let e of await g())if(await E(e)){r=e;break}r===null&&(console.error("No port from 4317 is free: name one (--port <n>)."),process.exit(1))}if(k){process.env.GALLERY_SERVER_KIND="cli";let{startProductionServer:e}=await import("./chunk-VPD2PS35.mjs");await e({port:r,kind:"cli"}),await h.writeFile($(t).lastPortFile,`${r}
3
- `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`);return}let{writeSharedAssets:y}=await import("./chunk-VNV55RUA.mjs");await y();let c=P(process.execPath,[R.join(v,"node_modules","vite","bin","vite.js"),"--host","127.0.0.1","--port",String(r),"--strictPort"],{cwd:v,env:{...process.env,GALLERY_WORKSPACE:t,GALLERY_SERVER_KIND:"cli"},stdio:"inherit"});for(let e of["SIGINT","SIGTERM"])process.on(e,()=>c.kill(e));let w=new Promise(e=>c.once("exit",(u,p)=>e(u??(p?1:0))));for(;;){let e=await Promise.race([w.then(p=>({code:p})),b(300).then(()=>null)]);if(e&&process.exit(e.code),(await x({reportsDirectory:t,answering:!0,timeout:2e3}))?.pid===c.pid)break}await h.writeFile($(t).lastPortFile,`${r}
2
+ import{g as n,h as g}from"./chunk-5XA2ZBAE.mjs";import{b as m,f as d}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{spawn as P}from"node:child_process";import h from"node:fs/promises";import R from"node:path";import{projectRoot as v,release as k,reportsDirectory as t}from"../browser/shared/paths.mjs";import{answerOf as S,findPreviewServer as x,portIsFree as E,readAnnouncement as G}from"../browser/shared/preview-server.mjs";import{layoutOf as $}from"../browser/shared/workspace.mjs";var b=a=>new Promise(s=>setTimeout(s,a));async function O(a){let{positional:s,values:l}=d({values:["--port"],argv:a});if(s.length>0)throw new m(`gallery serve takes no arguments: ${s[0]}`);let o=l.has("--port")?Number(l.get("--port")):null;if(o!==null&&!(Number.isInteger(o)&&o>0&&o<65536))throw new m(`--port takes a port number: ${l.get("--port")}`);let i=await G({reportsDirectory:t}),f=i?await S(i,t,1e4):"no";f!=="no"&&(console.error(`This workspace's Gallery server runs already: ${n(i.port)} (pid ${i.pid}${f==="busy"?", not answering now":""}). gallery stop stops it; one server serves a workspace.`),process.exit(1));let r=null;if(o!==null)await E(o)||(console.error(`Port ${o} is taken: name another (--port), or leave it out for the first free one.`),process.exit(1)),r=o;else{for(let e of await g())if(await E(e)){r=e;break}r===null&&(console.error("No port from 4317 is free: name one (--port <n>)."),process.exit(1))}if(k){process.env.GALLERY_SERVER_KIND="cli";let{startProductionServer:e}=await import("./chunk-L2SUIS5S.mjs");await e({port:r,kind:"cli"}),await h.writeFile($(t).lastPortFile,`${r}
3
+ `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`);return}let{writeSharedAssets:y}=await import("./chunk-WQDQWCX5.mjs");await y();let c=P(process.execPath,[R.join(v,"node_modules","vite","bin","vite.js"),"--host","127.0.0.1","--port",String(r),"--strictPort"],{cwd:v,env:{...process.env,GALLERY_WORKSPACE:t,GALLERY_SERVER_KIND:"cli"},stdio:"inherit"});for(let e of["SIGINT","SIGTERM"])process.on(e,()=>c.kill(e));let w=new Promise(e=>c.once("exit",(u,p)=>e(u??(p?1:0))));for(;;){let e=await Promise.race([w.then(p=>({code:p})),b(300).then(()=>null)]);if(e&&process.exit(e.code),(await x({reportsDirectory:t,answering:!0,timeout:2e3}))?.pid===c.pid)break}await h.writeFile($(t).lastPortFile,`${r}
4
4
  `).catch(()=>{}),console.log(`Gallery serves ${t} at ${n(r)} (Chrome or Edge). Ctrl+C stops it.`),process.exit(await w)}export{O as run};
@@ -0,0 +1,15 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as b}from"./chunk-2OHANJ6Q.mjs";import{c as L,d as F}from"./chunk-Q4UEPUWF.mjs";import{c as x,d as j,k as w}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import l from"node:fs";import c from"node:path";import{pathToFileURL as K}from"node:url";import{projectRoot as p}from"../browser/shared/paths.mjs";import{sha256 as A}from"../browser/shared/files.mjs";var g=["SKILL.md","references/writing-html.md","references/building-blocks.md","references/block-script.md","references/pages-and-data.md","references/extensions.md","references/example-report.html","sdk","agents/openai.yaml"],u="## Before anything: the gallery command";function T(n){let[t,s]=n.split(/[.+-]/).map(Number);return{range:`^${n}`,takes:`${n} or a later ${t===0?`0.${s}`:t}.x`}}function N(n,t){let s=n.indexOf(`
3
+ ${u}
4
+ `);if(s<0)throw new Error(`SKILL.md has no section "${u}" (the version range of the command stands there)`);let e=n.indexOf(`
5
+ ## `,s+u.length+1),i=e<0?n.length:e,{range:r,takes:o}=T(t),a=n.slice(s,i).replace(new RegExp(L.source,"g"),F(t)).replace(/\^\d+\.\d+\.\d+(?:-[\w.]+)?/g,r).replace(/\b\d+\.\d+\.\d+(?:-[\w.]+)? or a later \d+(?:\.\d+)?\.x\b/g,o);return n.slice(0,s)+a+n.slice(i)}function y(n=p){let t=g.filter(r=>!l.existsSync(c.join(n,r)));if(t.length)return t.map(r=>`the skill takes ${r}, which is not there`);let s=E(g,n),e=r=>l.readFileSync(c.join(n,r),"utf8"),i=P(s,e).map(r=>`${r}, which the skill does not hold: link only what it holds`);for(let r of s.filter(o=>o.startsWith("sdk/")&&o.endsWith(".ts")))for(let[,o]of e(r).matchAll(/\bfrom\s+["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)/g))o&&(!o.startsWith("./")||o.includes("/../"))&&i.push(`${r} imports ${o}, outside sdk/: write the types it needs in sdk/`);return i}function R(n,{root:t=p,version:s=JSON.parse(l.readFileSync(c.join(t,"package.json"),"utf8")).version}={}){let e=y(t);if(e.length)throw new Error(`The skill cannot be made:
6
+ ${e.map(i=>` ${i}`).join(`
7
+ `)}`);l.rmSync(n,{recursive:!0,force:!0});for(let i of E(g,t)){let r=c.join(n,i);l.mkdirSync(c.dirname(r),{recursive:!0}),i==="SKILL.md"?l.writeFileSync(r,N(l.readFileSync(c.join(t,i),"utf8"),s)):l.copyFileSync(c.join(t,i),r)}return k(n)}function k(n,t=""){let s=[];for(let e of l.readdirSync(n,{withFileTypes:!0}).sort((i,r)=>i.name.localeCompare(r.name))){let i=t?`${t}/${e.name}`:e.name;e.isDirectory()?s.push(...k(c.join(n,e.name),i)):e.isFile()&&s.push(i)}return s}function E(n,t=p){return n.flatMap(s=>{let e=c.join(t,s);return l.existsSync(e)?l.statSync(e).isDirectory()?k(e,s):[s]:[]})}function v(n){let t=null;return n.split(`
8
+ `).map(s=>{let e=/^\s*(`{3,}|~{3,})(.*)$/.exec(s);return t?(e&&e[1][0]===t[0]&&e[1].length>=t.length&&!e[2].trim()&&(t=null),""):e&&!(e[1][0]==="`"&&e[2].includes("`"))?(t=e[1],""):s}).join(`
9
+ `)}function z(n){let t=v(n).replace(/(`+)(?!`)(?:(?!\n[ \t]*\n)[\s\S])*?[^`]\1(?!`)/g,e=>" ".repeat(e.length));return[...[...t.matchAll(/\]\(\s*(?:<([^<>\n]*)>|((?:[^\s()<>]|\([^\s()<>]*\))+))(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^()\n]*\)))?\s*\)/g)].map(e=>[e.index,e[1]??e[2]]),...[...t.matchAll(/^ {0,3}\[(?!\^)[^\]\n]+\]:[ \t]*(?:<([^<>\n]*)>|(\S+))/gm)].map(e=>[e.index,e[1]??e[2]]),...[...t.matchAll(/<(?:a|img)\s[^>]*?\b(?:href|src)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi)].map(e=>[e.index,e[1]??e[2]])].sort(([e],[i])=>e-i).map(([,e])=>e)}function C(n,t){if(/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(t))return null;let[,s,e=""]=/^([^?#]*)(?:\?[^#]*)?(?:#(.*))?$/s.exec(t),i=o=>{try{return decodeURIComponent(o)}catch{return o}};return{file:s?c.posix.normalize(c.posix.join(c.posix.dirname(n),i(s))).replace(/\/$/,""):n,anchor:i(e)}}function P(n,t){let s=new Set(n),e=new Set(n.flatMap(r=>r.split("/").slice(0,-1).map((o,a,f)=>f.slice(0,a+1).join("/")))),i=[];for(let r of n.filter(o=>/\.md$/i.test(o)))for(let o of z(t(r))){let a=C(r,o);!a||a.file===r||!s.has(a.file)&&!e.has(a.file)&&i.push(`${r} links ${o}`)}return i}function M(n,{root:t=p,version:s=JSON.parse(l.readFileSync(c.join(t,"package.json"),"utf8")).version}={}){let e=y(t);if(e.length)throw new Error(`The skill cannot be made:
10
+ ${e.map(m=>` ${m}`).join(`
11
+ `)}`);let i=c.join(n,"skill","gallery"),r=`gallery-skill-${s}.zip`,o=c.join(n,r);l.rmSync(c.join(n,"skill"),{recursive:!0,force:!0}),l.existsSync(c.join(n,"gallery","PACKAGE-MANIFEST.json"))&&l.rmSync(c.join(n,"gallery"),{recursive:!0,force:!0});for(let m of l.existsSync(n)?l.readdirSync(n):[])/^gallery-skill-.+\.zip(?:\.sha256)?$|^PACKAGE-MANIFEST\.json$/.test(m)&&l.rmSync(c.join(n,m),{force:!0});let a=R(i,{root:t,version:s}),f=a.map(m=>({name:`gallery/${m}`,data:l.readFileSync(c.join(i,m))})),h=b(f);l.writeFileSync(o,h);let S=A(h);l.writeFileSync(`${o}.sha256`,`${S} ${r}
12
+ `);let{range:$}=T(s),I={name:"gallery",version:s,archive:r,holds:"The Agent's documents (SKILL.md, references/writing-html.md, references/building-blocks.md, references/block-script.md, references/pages-and-data.md, references/extensions.md, the example references/example-report.html), the SDK's types (sdk/) and Codex's display metadata (agents/openai.yaml). The tools are the npm package @heycys/gallery, which SKILL.md has the Agent check for and install (with the user's consent); gallery skill install writes this same skill.",skillEntrypoint:"SKILL.md",requires:`@heycys/gallery@${$}`,files:f.map(({name:m,data:d})=>({path:m.slice(8),bytes:d.byteLength,sha256:A(d)}))};l.writeFileSync(c.join(n,"PACKAGE-MANIFEST.json"),`${JSON.stringify(I,null,2)}
13
+ `);let O=f.reduce((m,{data:d})=>m+d.byteLength,0);return{archive:o,skill:i,files:a,bytes:O,zipBytes:h.byteLength,sha256:S,range:$}}if(import.meta.url===K(process.argv[1]).href){let{positional:n}=await w(import.meta.url);n.length>0&&(console.error(j(x(import.meta.url),`Unknown argument: ${n[0]} (skill:package takes none: there is one skill).`)),process.exit(2));let t=y();t.length>0&&(console.error(`Not packaged:
14
+ ${t.map(e=>` ${e}`).join(`
15
+ `)}`),process.exit(1));let s=M(c.join(p,"release"));console.log(`Packaged ${s.archive} (${s.files.length} files, ${s.bytes.toLocaleString("en-US")} bytes; the ZIP ${s.zipBytes.toLocaleString("en-US")} bytes), for @heycys/gallery ${s.range}`),console.log(`The skill's folder: ${s.skill}`),console.log(`SHA-256 ${s.sha256}`)}export{u as BOOTSTRAP,g as SKILL_FILES,R as buildSkill,P as deadLinks,E as filesOf,C as linkTarget,z as linksOf,k as listFiles,M as packageSkill,y as skillProblems,T as skillRange,N as withRange,v as withoutSamples};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g,h}from"./chunk-EP25HDAJ.mjs";import"./chunk-AR5D57ZD.mjs";import"./chunk-5XA2ZBAE.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-7OG26PGF.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-UYVCQK3H.mjs";import"./chunk-J5PUIV3Y.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{c as HOME_NOT_MADE,g as emptyRequiredOf,d as missingPageSaid,a as pageAddressOf,b as pageAloneOf,h as run,e as setsOf,f as settingsGiven};
@@ -0,0 +1,22 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as Ee,d as X,f as ae,h as ie,i as Ne,l as oe,p as ve}from"./chunk-J5PUIV3Y.mjs";import{D as ce}from"./chunk-VS7JIGJW.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-HDWTZ763.mjs";import{b as ye,e as mt}from"./chunk-A55HN5OK.mjs";mt();import{createHash as ht}from"node:crypto";import{cellsOf as gt}from"../browser/shared/card-size.mjs";import{escapeAttribute as de}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as le,hasClass as _e,walk as Te}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as He}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,sr=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),De="gallery-board",Fe="gallery-card",Le=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,He)!==void 0,wt=e=>ht("sha256").update(e.replace(/\r\n?/g,`
3
+ `)).digest("hex").slice(0,16),kt=e=>ye(e.replace(/^/," "),{sourceCodeLocationInfo:!0});function I(e){let n=[];return Te(kt(e),r=>{if(!_e(r,De))return;let i=le(r).filter(s=>_e(s,Fe)&&s.sourceCodeLocation).map(s=>{let a=le(s).find(Le)??null;a||Te(s,O=>{a??=Le(O)?O:null});let h=s.sourceCodeLocation,g={x:N(s,"data-x"),y:N(s,"data-y"),w:N(s,"data-w"),h:N(s,"data-h")};return{id:N(s,"data-card-id")??null,node:s,board:N(r,"data-board-id")??null,...gt({dataset:g}),instance:a,block:a?N(a,He):null,start:h.startOffset,end:h.endOffset,closed:!!h.endTag}});n.push({id:N(r,"data-board-id")??null,node:r,cards:i})},{inTemplates:!1}),{boards:n,cards:n.flatMap(r=>r.cards)}}function Ot(e){let n=new Set(e.map(({id:s})=>s).filter(s=>typeof s=="string"&&q.test(s))),r=new Set,i=1;return e.map(({id:s})=>{if(typeof s=="string"&&q.test(s)&&!r.has(s))return r.add(s),s;for(;n.has(`c${i}`)||r.has(`c${i}`);)i++;let a=`c${i}`;return r.add(a),a})}function fe(e){let n=new Set(e),r=1;for(;n.has(`c${r}`);)r++;return`c${r}`}function ee(e,n,r){let{startTag:i}=n.sourceCodeLocation,s=i.attrs??{},a=[],h=[];for(let[g,O]of Object.entries(r)){let S=s[g];S?(a.push({start:S.startOffset,end:S.endOffset,text:O===null?"":`${g}="${de(String(O))}"`}),O===null&&e[S.startOffset-1]===" "&&(a.at(-1).start-=1)):O!==null&&h.push(` ${g}="${de(String(O))}"`)}if(h.length){let g=s.class?.endOffset??i.startOffset+1+n.tagName.length;a.push({start:g,end:g,text:h.join("")})}return a}function te(e,n){return[...n].sort((r,i)=>i.start-r.start||i.end-r.end).reduce((r,{start:i,end:s,text:a})=>r.slice(0,i)+a+r.slice(s),e)}function W(e){let{cards:n}=I(e),r=Ot(n),i=n.flatMap((s,a)=>s.id===r[a]?[]:ee(e,s.node,{"data-card-id":r[a]}));return{text:i.length?te(e,i):e,filled:n.flatMap((s,a)=>s.id===r[a]?[]:[r[a]])}}var V=(e,n)=>wt(e.slice(n.start,n.end));function Re(e){let n=W(e).text;return I(n).cards.map(r=>({id:r.id,board:r.board,x:r.x,y:r.y,w:r.w,h:r.h,base:V(n,r),block:r.block}))}var Pe=e=>[e.board,...["x","y","w","h"].map(n=>N(e.node,`data-${n}`))].join(",");function Me(e,n){let r=n.node.sourceCodeLocation.startTag.endOffset;return e.slice(n.start,r).replace(/\s+data-[xywh]="[^"]*"/g,"")+e.slice(r,n.end)}function Je(e,n){let[r,i]=[W(e).text,W(n).text],[s,a]=[I(r).cards,I(i).cards],h={};for(let g of s)a.some(O=>O.id===g.id)||(h[g.id]=["removed"]);for(let g of a){let O=s.find(v=>v.id===g.id);if(!O){h[g.id]=["added"];continue}let S=[...Pe(O)!==Pe(g)?["cells"]:[],...Me(r,O)!==Me(i,g)?["content"]:[]];S.length&&(h[g.id]=S)}return h}function Y(e,n){let{cards:r}=I(e),i=r.flatMap(s=>{let a=n.get(s.id);if(!a)return[];let h={};for(let g of["x","y","w","h"])a[g]!==void 0&&N(s.node,`data-${g}`)!==String(a[g])&&(h[`data-${g}`]=a[g]);return Object.keys(h).length?ee(e,s.node,h):[]});return i.length?te(e,i):e}function xt(e,n,r){let i=e.lastIndexOf(`
4
+ `,n-1)+1,s=e.indexOf(`
5
+ `,r),a=s===-1?e.slice(r):e.slice(r,s);return!/^[ \t]*$/.test(e.slice(i,n))||!/^[ \t\r]*$/.test(a)?{from:n,to:r}:{from:i,to:s===-1?e.length:s+1}}function Be(e,n){let r=I(e).cards.find(a=>a.id===n);if(!r)return null;let{from:i,to:s}=xt(e,r.start,r.end);return{text:e.slice(0,i)+e.slice(s),html:e.slice(r.start,r.end)}}var ze=(e,n)=>/^[ \t]*/.exec(e.slice(e.lastIndexOf(`
6
+ `,n-1)+1))[0],$t=(e,n)=>e.replace(/\r?\n/g,r=>`${r}${n}`);function We({id:e,x:n,y:r,w:i,h:s},a,h="",g=`
7
+ `){return`${`<section class="${Fe}" data-card-id="${de(e)}" data-x="${n}" data-y="${r}" data-w="${i}" data-h="${s}">`}${g}${h} ${$t(a.trim().replace(/\r?\n/g,g),`${h} `)}${g}${h}</section>`}function ue(e,n,r){let i=I(e).boards.find(j=>j.id===n);if(!i)return null;let{node:s}=i,a=s.sourceCodeLocation,h=e.includes(`\r
8
+ `)?`\r
9
+ `:`
10
+ `,g=i.cards.at(-1),O=g?ze(e,g.start):`${ze(e,a.startOffset)} `,S=r.match(/\n([ \t]*)<\/[a-z]+>\s*$/)?.[1]??"",v=r.trim().replace(/\r?\n/g,`
11
+ `).split(`
12
+ `).map((j,_)=>_===0||S===O?j:j.startsWith(S)?`${O}${j.slice(S.length)}`:j).join(h);if(a.endTag){let j=a.endTag.startOffset,_=e.lastIndexOf(`
13
+ `,j-1)+1,F=/^[ \t]*$/.test(e.slice(_,j)),T=F?_:j,R=`${F?"":h}${O}${v}${h}`;return{text:e.slice(0,T)+R+e.slice(T),start:T+R.indexOf(v)}}let E=a.endOffset,D=`${h}${O}${v}`;return{text:e.slice(0,E)+D+e.slice(E),start:E+D.indexOf(v)}}function ar(e,{blockOf:n=()=>null}={}){let r=W(e).text,i=[];for(let s of I(r).cards){let a=s.block?n(s.block):null,h={"data-ge-base":V(r,s)};a?.fit==="content"&&(h["data-ge-fit"]="content"),a?.bare&&(h["data-ge-bare"]="");let g=s.block===null?null:a?.state??"missing";if(g&&g!=="page"&&(h["data-ge-state"]=g),i.push(...ee(r,s.node,h)),s.instance&&a&&g!=="page"&&g!=="missing"){let{startOffset:O,endOffset:S}=s.instance.sourceCodeLocation;i.push({start:O,end:O,text:"<template data-ge-held>"},{start:S,end:S,text:"</template>"})}}return te(r,i)}function Ue(e){let n=`<!doctype html><html><head></head><body><div class="${De}">`,r=`${n}${e}</div></body></html>`,[i]=I(r).boards;return{text:r,board:i,from:n.length,to:n.length+e.length}}function Ge(e){let{board:n}=Ue(e);if(!n||n.cards.length!==1)return null;let r=le(n.node).length!==1||n.node.childNodes.some(s=>s.nodeName==="#text"&&s.value.trim()),[i]=n.cards;return r||!i.closed||!i.instance||i.instance.parentNode!==i.node?null:i}function Ke(e,{id:n,x:r,y:i,w:s,h:a}){let{text:h,board:g,from:O,to:S}=Ue(e),v={"data-card-id":n,"data-x":r,"data-y":i,"data-w":s,"data-h":a},E=ee(h,g.cards[0].node,v),D=E.reduce((j,{start:_,end:F,text:T})=>j+T.length-(F-_),0);return te(h,E).slice(O,S+D)}import{readFileSync as pe}from"node:fs";import z from"node:fs/promises";import H from"node:path";import{refusedInCopy as Ve}from"../browser/shared/components/installed.mjs";import{writeAtomic as Ye}from"../browser/shared/files.mjs";import{sendJson as re}from"../browser/shared/http.mjs";import{jsonIn as bt}from"../browser/shared/json-layout.mjs";import{defaultSize as me,freeSpot as St,onBoard as he,pushDown as ge,settle as yt,sizeFor as Ze}from"../browser/shared/board-places.mjs";import{FIRST_BOARD as Qe,HOME_CARDS as Ct,HOME_SIZES as It,pageExists as we,pageFiles as jt,pageVersion as Xe,tellHomeCards as qe}from"../browser/shared/pages.mjs";import{OWN_SCOPE as At,PACK_FILE as Et,readPackManifest as Nt}from"../browser/shared/pack-manifest.mjs";import{packsDirectory as vt}from"../browser/shared/paths.mjs";import{sameDirectory as _t}from"../browser/shared/preview-server.mjs";import{walk as Tt}from"../browser/shared/html-tree.mjs";import{closePageHint as Lt,pageDefaults as Pt}from"../browser/shared/pages.mjs";var Mt=20,ke="writes.jsonl",zt=200;async function Ar(e,n,r){return(await z.readFile(H.join(e,"pages",n,ke),"utf8").catch(()=>"")).split(`
14
+ `).flatMap(s=>{try{let a=JSON.parse(s);return a&&typeof a.at=="number"&&a.at>=r&&a.cards&&typeof a.cards=="object"?[a]:[]}catch{return[]}})}var Ht=["place","arrange","add","remove","edit","settings","restore-defaults"],U=e=>Number.isInteger(e)&&e>=0,ne=e=>Number.isInteger(e)&&e>=1,Dt=/^\d{4}-\d{2}-\d{2}$/,x=(e,n,r)=>[e,{ok:!1,reason:n,...r?{message:r}:{}}];function Ft(e,n){return typeof e=="string"?e.replace(new RegExp(`(^|[\\s"'(,=])/pages/${n}/assets/`,"g"),"$1assets/"):e}var et=e=>[409,{ok:!1,refused:e}];function Er(e,n){let r=e.packages.get(n);return r?{state:r.places.includes("page")?"page":"document",card:r.card,settings:r.settings,places:r.places,fit:r.card.fit,bare:r.card.bare,name:r.name,parts:Object.fromEntries(Object.entries(r.parts).filter(([,i])=>i.edit==="data").map(([i,s])=>[i,s.at]))}:e.settings.disabled.includes(n)&&e.problems.has(n)?{state:"disabled",card:null,settings:[],places:[],fit:"fixed",bare:!1,name:null,parts:{}}:null}function Rt(e,{type:n,options:r}){return n==="text"||n==="document"?typeof e=="string"&&e.length<=1e4:n==="number"?typeof e=="number"&&Number.isFinite(e)||e===null:n==="select"?r.includes(e):n==="date"?e===""||typeof e=="string"&&Dt.test(e):n==="switch"?typeof e=="boolean":!1}function tt(e,{x:n,y:r,w:i,h:s}){let a={x:e.x??n,y:e.y??r,w:e.w??i,h:e.h??s};return U(a.x)&&U(a.y)&&ne(a.w)&&ne(a.h)?a:null}function rt({root:e,edits:n,stateDirectory:r,catalog:i=()=>Ie(e),catalogTaken:s=()=>{},shipped:a=void 0,log:h=()=>{},shown:g=O=>O}){let O=0;async function S(f,t){let o=H.join(r,"pages",f);await z.mkdir(o,{recursive:!0}),O=(O+1)%1e4,await z.writeFile(H.join(o,`${String(Date.now()).padStart(15,"0")}-${String(O).padStart(4,"0")}.html`),t);let d=(await z.readdir(o)).filter(p=>/^\d{15}-\d{4}\.html$/.test(p)).sort();for(let p of d.slice(0,Math.max(0,d.length-Mt)))await z.rm(H.join(o,p),{force:!0})}async function v(f,t){let o=H.join(r,"pages",f,ke);try{let d=(await z.readFile(o,"utf8").catch(()=>"")).split(`
15
+ `).filter(Boolean);d.push(JSON.stringify({at:Date.now(),...t})),await Ye(o,`${d.slice(-zt).join(`
16
+ `)}
17
+ `)}catch(d){h(`the write of ${f}'s page.html could not be told in ${ke}: ${d.message}`)}}function E(f,t){if(typeof t.card!="string")return{error:x(400,"card")};let o=I(f).cards.find(d=>d.id===t.card);return o?typeof t.base!="string"||V(f,o)!==t.base?{error:et("changed")}:{card:o}:{error:et("gone")}}let D=(f,t)=>I(f).cards.filter(o=>o.board===t).map(({id:o,x:d,y:p,w:l,h:u})=>({id:o,x:d,y:p,w:l,h:u})),j=(f,t)=>new Map(t.filter(o=>{let d=f.find(p=>p.id===o.id);return!d||d.x!==o.x||d.y!==o.y||d.w!==o.w||d.h!==o.h}).map(o=>[o.id,o])),_=(f,t,o)=>ce.installed.dataOf(f,t.instance,o)??{};function F(f,t,o,d){if(!t.instance||!d.has(t.block))return{error:x(409,"block")};let p=_(f,t,d),l=ce.installed.rewrite(f,t.instance,o,{packages:d});if(!l)return{error:x(400,"part")};let u=[...l].sort((m,k)=>k.start-m.start).reduce((m,{start:k,end:$,text:c})=>m.slice(0,k)+c+m.slice($),f),w=_(u,I(u).cards.find(m=>m.id===t.id),d);return{text:u,parts:Object.fromEntries(Object.keys(o).map(m=>[m,{was:p[m]??"",now:w[m]??""}]))}}function T(f,t){return Object.fromEntries(Object.entries(f).map(([o,{was:d,now:p}])=>[o,{was:g(d,t),now:g(p,t)}]))}let R={place(f,t,{packages:o}){let{card:d,error:p}=E(f,t);if(p)return{error:p};let l=tt(t,d);if(!l)return{error:x(400,"cells")};let u=o.get(d.block);if(l.w!==d.w||l.h!==d.h){let m=u&&!u.card.sizes&&u.card.h===null&&l.w===d.w;if(u&&!u.card.resize&&!m)return{error:x(409,"resize")};u&&!m&&(l={...l,...Ze(u.card,l)})}let w=D(f,d.board);return{text:Y(f,j(w,ge(w,{id:d.id,...l})))}},arrange(f,t){if(!Array.isArray(t.cards)||t.cards.length===0)return{error:x(400,"cards")};let o=[];for(let p of t.cards){let{card:l,error:u}=E(f,p??{});if(u)return{error:u};let w=tt(p,l);if(!w)return{error:x(400,"cells")};o.push({card:l,cells:he(w)})}let d=f;for(let p of new Set(o.map(({card:l})=>l.board))){let l=D(d,p),u=o.filter(({card:m})=>m.board===p),w=l.map(m=>({...m,...u.find(({card:k})=>k.id===m.id)?.cells??{}}));d=Y(d,j(l,yt(w,u.map(({card:m})=>m.id))))}return{text:d}},async add(f,t,o){let{boards:d,cards:p}=I(f);if(t.html!==void 0)return ct(f,t,{boards:d,cards:p});if(typeof t.block!="string")return{error:x(400,"block")};let l=typeof t.board=="string"?d.find(y=>y.id===t.board):d.find(y=>y.id===Qe)??d[0];if(!l)return{error:x(409,"board")};ae(t.block,a)&&oe(e,{ids:[t.block],directory:a,log:h}).updated.length>0&&(s(),o.refresh());let u=o.packages.get(t.block),w=o.catalog.settings.disabled.includes(t.block);if(!u&&!w&&!o.catalog.problems.has(t.block)&&ae(t.block,a)){let y=X(a).find(({id:K})=>K===t.block);y&&y.places.includes("page")&&!ie(e,y).added&&(Ne(e,y),h(`${t.block} added to the workspace for a card of a custom page`),s(),o.refresh(),u=o.packages.get(t.block))}if(!u)return{error:x(409,o.catalog.settings.disabled.includes(t.block)?"disabled":"missing")};if(!u.places.includes("page"))return{error:x(409,"places")};let m=Ae(u);if(!m)return{error:x(409,"template")};if(t.w!==void 0&&!ne(t.w)||t.h!==void 0&&!ne(t.h))return{error:x(400,"cells")};let k=me(u.card),$=t.w!==void 0||t.h!==void 0?Ze(u.card,{w:t.w??k.w,h:t.h??k.h}):k,c=l.cards.map(({id:y,x:K,y:ft,w:ut,h:pt})=>({id:y,x:K,y:ft,w:ut,h:pt})),b=t.x!==void 0||t.y!==void 0?{x:t.x??0,y:t.y??0}:St(c,$);if(!U(b.x)||!U(b.y))return{error:x(400,"cells")};let C=fe(p.map(y=>y.id)),L=he({...b,w:$.w,h:$.h}),J=f.includes(`\r
18
+ `)?`\r
19
+ `:`
20
+ `,A=We({id:C,...L},m,"",J),G=ue(f,l.id,A),Z=j(c,ge(c,{id:C,...L}).filter(y=>y.id!==C)),P=Y(G.text,Z),B=I(P).cards.find(y=>y.id===C);if(t.settings!==void 0){let y=R.settings(P,{card:C,base:V(P,B),values:t.settings},o);if(y.error)return y;P=y.text,B=I(P).cards.find(K=>K.id===C)}return{text:P,extra:{card:C,html:P.slice(B.start,B.end),measure:k.measured&&t.h===void 0,pushed:[...Z.keys()]}}},remove(f,t){let{card:o,error:d}=E(f,t);if(d)return{error:d};let{text:p,html:l}=Be(f,o.id);return{text:p,extra:{removed:{id:o.id,board:o.board,html:l}}}},edit(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=t.parts!==void 0?t.parts:typeof t.part=="string"?{[t.part]:t.html}:null;if(!u||typeof u!="object"||Array.isArray(u)||Object.keys(u).length===0)return{error:x(400,"part")};let w=Object.fromEntries(Object.entries(u).map(([k,$])=>[k,Ft($,d)])),m=F(f,p,w,o);return m.error?m:{text:m.text,extra:{parts:T(m.parts,d)}}},settings(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=o.get(p.block),w=u?.settings??[];if(!u||w.length===0)return{error:x(409,"settings")};let m=t.values;if(!m||typeof m!="object"||Array.isArray(m))return{error:x(400,"values")};for(let[L,J]of Object.entries(m)){let A=w.find(G=>G.key===L);if(!A||!Rt(J,A))return{error:x(400,"values",L)}}let k=_(f,p,o)[Q];if(k===void 0)return{error:x(409,"settings")};let $={};try{$=k.trim()?JSON.parse(k):{}}catch{$={}}(!$||typeof $!="object"||Array.isArray($))&&($={});let c={...$,...m};if(JSON.stringify(c)===JSON.stringify($))return{text:f,extra:{parts:T({[Q]:{was:k,now:k}},d)}};let b=k.trim()?bt(k,c):JSON.stringify(c),C=F(f,p,{[Q]:b},o);return C.error?C:{text:C.text,extra:{parts:T(C.parts,d)}}},async"restore-defaults"(f,t,o){if(!Pt(o.slug,e))return{error:x(409,"defaults")};let d=new Set(I(f).cards.map(w=>w.block)),p=f,l=[],u=[];for(let w of Ct){if(d.has(w))continue;let[m,k]=It[w]??[],$=await R.add(p,{op:"add",block:w,...m?{w:m,h:k}:{}},o),c=o.packages.get(w)?.name??X(a).find(({id:b})=>b===w)?.title??null;if($.error){u.push({block:w,reason:$.error[1].reason,name:c});continue}p=$.text,l.push({card:$.extra.card,block:w,html:$.extra.html,name:c})}return{text:p,extra:{added:l,skipped:u}}}};function ct(f,t,{boards:o,cards:d}){if(typeof t.html!="string"||t.html.length>11e5)return{error:x(400,"html")};let p=t.html.trim(),l=Ge(p);if(!l)return{error:x(400,"html")};let u=Ve(l.node.tagName,l.node.attrs??[]);if(Tt(l.node,A=>{u||=Ve(A.tagName,A.attrs??[])}),u)return{error:x(400,"html")};let w=o.find(A=>A.id===(typeof t.board=="string"?t.board:Qe))??o[0];if(!w)return{error:x(409,"board")};if(t.x!==void 0&&!U(t.x)||t.y!==void 0&&!U(t.y))return{error:x(400,"cells")};let m=d.map(A=>A.id),k=l.id&&!m.includes(l.id)&&q.test(l.id)?l.id:fe(m),$=he({x:t.x??l.x,y:t.y??l.y,w:l.w,h:l.h}),c=w.cards.map(({id:A,x:G,y:Z,w:P,h:B})=>({id:A,x:G,y:Z,w:P,h:B})),b=ue(f,w.id,Ke(p,{id:k,...$})),C=j(c,ge(c,{id:k,...$}).filter(A=>A.id!==k)),L=Y(b.text,C),J=I(L).cards.find(A=>A.id===k);return{text:L,extra:{card:k,html:L.slice(J.start,J.end),pushed:[...C.keys()]}}}async function be(f,t,{by:o}={}){if(!t||typeof t!="object"||!Ht.includes(t.op))return x(400,"op");if(t.workspace!==void 0&&(typeof t.workspace!="string"||!_t(t.workspace,e)))return x(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");if(!we(f,e))return x(404,"missing");let d=jt(f,e);for(let p=0;p<3;p++){let[l,u]=await Promise.all([z.readFile(d.html,"utf8").catch(()=>null),z.readFile(d.json,"utf8").catch(()=>"")]);if(l===null)return x(404,"missing");if(Buffer.byteLength(l)>1e6)return x(413,"size");let w=Xe(l,u),m=W(l).text,k=i(),$={slug:f,get catalog(){return k},get packages(){return k.packages},refresh:()=>{k=i()}},c=await R[t.op](m,t,$);if(c.error)return c.error;let b=c.text;if(Buffer.byteLength(b)>1e6)return x(413,"size");if(b!==l){if(await S(f,l),!await Ye(d.html,b,{expect:l}))continue;await v(f,{op:t.op,by:o==="gallery"?"gallery":t.agent===!0?"agent":"page",cards:Je(l,b)})}return t.op==="restore-defaults"&&await qe(e).catch(()=>{}),[200,{ok:!0,version:Xe(b,u),before:w,cards:Re(b),...c.extra??{}}]}return x(409,"busy")}function Se(f="zh"){oe(e,{directory:a,log:h}).updated.length>0&&s();let t=i(),o=[...t.settings.packsOff??[],...ve(e,t.settings.packs)],d=c=>c.split("/")[0],p=c=>!t.settings.unlisted.includes(c)&&!o.includes(d(c)),l=c=>t.packs?.get(d(c))??u(d(c)),u=c=>{try{return Nt(pe(H.join(a??vt,c,Et),"utf8")).name}catch{return null}},w=[...t.packages.values()].filter(c=>c.places.includes("page")&&p(c.id)).map(c=>({id:c.id,name:c.name,description:c.description,preview:c.files.includes("preview.svg")?je(c,"preview.svg"):null,size:me(c.card),installed:!0,settings:c.settings.length>0,pack:{id:d(c.id),name:l(c.id)}}));for(let c of X(a)){if(!c.places.includes("page")||t.packages.has(c.id)||t.problems.has(c.id)||t.settings.disabled.includes(c.id)||!p(c.id)||ie(e,c).added)continue;let b=null;try{b=`data:image/svg+xml;base64,${pe(H.join(c.folder,"preview.svg")).toString("base64")}`}catch{}let C=null;try{C=JSON.parse(pe(H.join(c.folder,"component.json"),"utf8")).card??null}catch{}w.push({id:c.id,name:c.title,description:c.description,preview:b,size:me(C),installed:!1,settings:!1,pack:{id:c.pack,name:l(c.id)}})}let m=c=>c.name?.[f]??c.name?.zh??c.id,k=Ee(a),$=({pack:c})=>c.id===At?-1:k.includes(c.id)?k.indexOf(c.id):k.length;return w.sort((c,b)=>$(c)-$(b)||(c.pack.id===b.pack.id?0:c.pack.id<b.pack.id?-1:1)||m(c).localeCompare(m(b),"zh-CN")||(c.id<b.id?-1:1))}async function dt(f,t){return we(f,e)?(t?.cards===!0?await qe(e):await Lt(e,f),[200,{ok:!0}]):x(404,"missing")}function lt(f,t,o,d){if((d==="cards"||d==="hint")&&f.method==="POST")return n.respond(async l=>{let u=await n.check(l);return u.error?u.error:d==="hint"?dt(o,u.body):be(o,u.body)})(f,t);if(d==="library"&&f.method==="GET"){let l=f.headers.host??"",u=f.socket.localPort;if(l!==`127.0.0.1:${u}`&&l!==`localhost:${u}`)return re(t,403,{ok:!1,reason:"host"});if(!we(o,e))return re(t,404,{ok:!1,reason:"missing"});let w=new URL(f.url??"/","http://localhost").searchParams.get("language")==="en"?"en":"zh";return re(t,200,{ok:!0,blocks:Se(w)})}let p=["cards","library","hint"].includes(d);return re(t,p?405:404,{ok:!1,reason:p?"method":"unknown"})}return{handle:lt,apply:be,library:Se}}import{readFileSync as ot}from"node:fs";import{writeAtomic as nt}from"../browser/shared/files.mjs";import{HOME as M,HOME_TITLE as Jt,createPage as Bt,hintOf as st,markHomeMade as at,pageExists as Oe,pageFiles as xe,pageSlugRefused as Wt,pagesSettings as Ut,writeHints as se}from"../browser/shared/pages.mjs";import{layoutOf as it,markerOf as Gt}from"../browser/shared/workspace.mjs";import{lineIconValue as Kt}from"../browser/shared/emoji/line-icons.mjs";var Vt="GALLERY_NO_DEFAULT_HOME",$e=Kt("house"),Yt="/icons/home-1_lightgray.svg",Zt=(e=process.env)=>!["","0","false",void 0].includes(e[Vt]);async function Hr(e,{shipped:n=void 0,stateDirectory:r=it(e).state,env:i=process.env}={}){if(Zt(i))return{did:"off"};let s={ours:!1};try{s=Gt(ot(it(e).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread"};if(Ut(e).homeMade)return await Qt(e).catch(()=>{}),{did:"done"};let a="mark";try{if(Oe(M,e))return await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"kept"};a="page";let h=await Wt(M,e);if(h)return{did:"taken",why:h};await Bt(M,Jt,{root:e,icon:$e,defaultCards:!0,hint:!0}),a="cards";let g=rt({root:e,edits:null,stateDirectory:r,catalog:()=>Ce(e),shipped:n}),[,O]=await g.apply(M,{op:"restore-defaults"},{by:"gallery"});return a="mark",await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"made",file:xe(M,e).html,cards:(O.added??[]).map(({card:S})=>S),skipped:O.skipped??[]}}catch(h){return{did:"failed",stage:a,file:Oe(M,e)?xe(M,e).html:null,why:h?.message??String(h)}}}async function Qt(e){let n=!1,r=()=>{if(!Oe(M,e))return null;let{json:i}=xe(M,e);try{let s=ot(i,"utf8"),a=JSON.parse(s.replace(/^/,""));return a&&typeof a=="object"&&!Array.isArray(a)?{json:i,text:s,value:a}:null}catch{return null}};if(st(e,"homeAdopted")!==!0){let i=r();if(i&&!("defaultCards"in i.value)&&!("hint"in i.value)){let s={...i.value,...i.value.icon?{}:{icon:$e},defaultCards:!0,hint:!0};n=await nt(i.json,`${JSON.stringify(s,null,2)}
21
+ `,{expect:i.text})}await se(e,{homeAdopted:!0})}if(st(e,"homeLineIcon")!==!0){let i=r();i?.value.icon===Yt&&(n=await nt(i.json,`${JSON.stringify({...i.value,icon:$e},null,2)}
22
+ `,{expect:i.text})||n),await se(e,{homeLineIcon:!0})}return n}function Dr({stage:e,file:n,why:r}){return e==="mark"?`The default home page ${n} is there, but gallery.json could not say it was made (${r}); a later start tries again.`:e==="cards"?`The default home page ${n} was made without its cards (${r}): \u6062\u590D\u9ED8\u8BA4\u5361\u7247 in its menu in the sidebar puts them on.`:`The default home page was not made (${r}); a later start tries again.`}export{q as a,I as b,W as c,Me as d,ar as e,Ar as f,Er as g,rt as h,Zt as i,Hr as j,Dr as k};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{D as $,a as H,c as y,d as v,e as q,f as K,g as Y,i as V,k as X,o as z}from"./chunk-VS7JIGJW.mjs";import{g as P}from"./chunk-HDWTZ763.mjs";import{b as S,e as U}from"./chunk-A55HN5OK.mjs";U();import{HOSTS as A,IDENTITY as dt}from"../browser/editor/components/registry.mjs";import{CODE as ut,MATH as tt,MEDIA as mt,PAGE as pt,TABLE as gt}from"../browser/editor/components/kit.mjs";import{TAB as ht}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as Nt,isInstance as w,matchesNode as x,partOf as bt}from"../browser/shared/components/index.mjs";import{texSource as It}from"../browser/editor/components/math/index.mjs";import{MENTION as M,MENTION_ICON as J,MENTION_PAGE as Q}from"../browser/shared/components/mention.mjs";import{imageFile as et}from"../browser/shared/media.mjs";import{isFileLink as kt}from"../browser/shared/page-address.mjs";import{isInkClass as xt}from"../browser/editor/page/marks.mjs";import{ownInline as Tt}from"../browser/editor/page/own.mjs";import{attr as h,hasClass as Ot}from"../browser/shared/html-tree.mjs";var Lt=new Set(["h1","h2","h3","h4","p","li"]),Ct=new Set(["h3","h4","p","figcaption"]),Et=Object.entries(A).flatMap(([t,e])=>(e.parts??[]).map(([r,a])=>{let c=Nt(r);if(c?.parts?.[a]?.edit!=="text")throw new Error(`Host ${t}: ${r} has no part ${a} edited as text`);return{kind:t,match:c.match,at:c.parts[a].at}})),St=t=>Et.filter(({match:e})=>x(t,e)).flatMap(({kind:e,at:r})=>bt(t,r).map(a=>({kind:e,part:a}))),vt=t=>t.sort((e,r)=>e.part.sourceCodeLocation.startOffset-r.part.sourceCodeLocation.startOffset),$t=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),wt=new Set(["ul","ol","blockquote"]),_=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),le={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function At(t,e,r){let a=A[t];if(!a)throw new Error(`Unknown block kind ${t}`);return a.caps({bound:r,blockLevel:y.has(e)})}var st=t=>t.tagName==="span"&&x(t,tt.inline),Bt=t=>t.tagName==="a"&&Ot(t,M),Pt=/^https?:\/\/[^\s"<>]+$/i,C=t=>t.attrs.map(e=>e.name).sort().join(),yt=t=>h(t,"class")===M&&t.childNodes.length===0&&(C(t)==="class"||C(t)===`class,${Q}`&&h(t,Q)==="");function _t(t){if(yt(t))return null;if(C(t)!=="class,href"||h(t,"class")!==M||!(Pt.test(h(t,"href"))||kt(h(t,"href"))))return"mention";let[e,...r]=t.childNodes;return(e?.tagName==="img"?C(e)==="alt,class,src"&&h(e,"class")===J&&h(e,"alt")===""&&et(h(e,"src")):e?.tagName==="span"&&C(e)==="class"&&h(e,"class")===J&&e.childNodes.length===0)&&r.length>0&&r.every(c=>c.nodeName==="#text")&&r.some(c=>c.value.trim())?null:"mention"}var Mt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(xt),jt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===ht,ot=t=>$t.has(t.tagName)||Mt(t)||jt(t),B=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":B(e)),at=t=>Tt(t.tagName,t.attrs,B(t)),Z=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==dt),Wt=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),Dt=(t,e,r={})=>t==="text"?y.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!r.plain;function j(t,e,r=!1,{cell:a=!1,pictures:c=a,known:l=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(r===!0)return`tag:${n.tagName}`;if(n.attrs.some(m=>/^on/i.test(m.name)))return"markup";if(r==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(a&&(n.tagName==="ul"||n.tagName==="ol")){let m=Ut(n,e,l);if(m)return m;continue}if(c&&n.tagName==="img"){if(Ft(n))return"picture";continue}if(st(n)){if(n.childNodes.some(m=>m.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(Bt(n)){let m=_t(n);if(m)return m;e.push(n.sourceCodeLocation);continue}if(at(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!ot(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&Wt(h(n,"href")??""))return"link";let N=j(n,e,!1,{known:l,pictures:c});if(N)return N}return null}var Gt=["src","alt","width"],Rt=/^[1-9]\d{0,3}$/;function Ft(t){let r=t.attrs.map(l=>l.name).find(l=>!Gt.includes(l));if(r)return`the attribute ${r}`;let a=h(t,"src");if(!et(a))return`its src (${a===void 0?"none":a.slice(0,80)}): no picture of the document's assets/ folder`;let c=h(t,"width");return c===void 0||Rt.test(c)?null:`its width (${c}): a whole number of pixels`}function Ut(t,e,r){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let a of t.childNodes){if(a.nodeName==="#text"&&!a.value.trim())continue;if(a.tagName!=="li")return`tag:${a.tagName??"text"}`;if(a.attrs.length>0||!a.sourceCodeLocation?.endTag)return"markup";let c=j(a,e,!1,{known:r,pictures:!0});if(c)return c}return null}function T(t){let e=[],r=[],a=new Map,c=null,l=(o,s,i=null)=>{let u=o.sourceCodeLocation;if(!A[s]||!u?.startTag||h(o,"contenteditable")!==void 0)return!1;let k=[],f=Dt(s,o.tagName),p=i?{childNodes:o.childNodes.slice(0,o.childNodes.indexOf(i))}:o,G=u.endTag?j(p,k,f,{cell:s==="cell"}):"markup";if(G)return r.push({at:u.startTag.endOffset-1,reason:G}),!1;let L=u.startTag.endOffset,ft=i?L+t.slice(L,i.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:u.endTag.startOffset,R={id:e.length,tag:o.tagName,kind:s,bound:!1,caps:{},start:u.startOffset,end:u.endOffset,innerStart:L,innerEnd:ft,atoms:k.map(F=>[F.startOffset-L,F.endOffset-L]),wrapper:null,nested:!!i,node:o};return e.push(R),a.set(o,R),!0},n=o=>(o.childNodes??[]).filter(s=>s.tagName),N=o=>{let s=o.sourceCodeLocation;return s?.startTag&&s.endTag?t.slice(s.startTag.endOffset,s.endTag.startOffset):null},m=o=>o.tagName!=="a"&&!Z(o)&&B(o)&&n(o).every(s=>at(s)?!B(s):ot(s)||st(s)),I=o=>{for(let s of n(o))s.tagName==="td"||s.tagName==="th"?l(s,"cell"):["thead","tbody","tfoot","tr"].includes(s.tagName)&&I(s)},d=o=>{for(let s of n(o))s.tagName==="table"?I(s):!_.has(s.tagName)&&!w(s)&&d(s)},b=o=>{let s=n(o);s.length===1&&s[0].tagName==="code"&&o.childNodes.every(i=>i.tagName||!i.value?.trim())?l(s[0],"code"):s.length===0?l(o,"code"):o.sourceCodeLocation?.startTag&&r.push({at:o.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},g=(o,s=!0)=>{for(let i of n(o)){let u=i.tagName,k=w(i);for(let{kind:f,part:p}of vt(k?$[V(i)].textParts(i,c??=P().packages):St(i)))l(p,f);if(k){for(let{element:f}of Y(i))g(f,s);continue}if(u==="div"&&x(i,ut.match)){for(let f of n(i))f.tagName==="pre"&&h(f,"contenteditable")===void 0&&b(f);continue}if(!(_.has(u)||h(i,"contenteditable")!==void 0))if(u==="table")I(i);else if(u==="figure"){let f=x(i,mt);for(let p of n(i))if(!(f&&p.tagName==="figcaption"))if(Ct.has(p.tagName))l(p,"field");else if(p.tagName==="table")I(p);else{if(_.has(p.tagName))continue;w(p)?g({childNodes:[p]},s):f||v(p)||Z(p)?d(p):g({childNodes:[p]},s)}}else if(u==="details")for(let f of n(i))w(f)?g({childNodes:[f]},s):f.tagName!=="summary"&&g(f,s);else if(u==="h1"&&(o.tagName==="header"||x(i,pt.title)))l(i,"title");else if(u==="li"&&K(i))g({childNodes:n(i)},s);else if(Lt.has(u)){let f=u==="li"?q(i):[];f?.length>0?(l(i,"flow",f[0]),g({childNodes:f},s)):l(i,"flow")||g(i,!1)}else if(u==="div"&&x(i,tt.block)&&n(i).length===0&&It(N(i)))l(i,"tex");else if(u==="div"&&x(i,gt.lead))for(let f of n(i))f.tagName==="span"&&l(f,"field");else s&&!v(i)&&m(i)?l(i,"text"):(g(i,s&&!v(i)),wt.has(u)&&it(i))}},it=o=>{let s=o.sourceCodeLocation,i=n(o).map(f=>a.get(f));if(!(i.length>0&&i.every(Boolean)&&o.childNodes.every(f=>f.tagName||f.nodeName==="#text"&&!f.value.trim()))||!s?.endTag)return;let k={start:s.startOffset,end:s.endOffset,ids:i.map(f=>f.id)};i.forEach(f=>f.wrapper=k)},W=o=>{for(let s of n(o))(s.tagName==="main"?g:W)(s)},D=S(t,{sourceCodeLocationInfo:!0});W(D);let{units:E,boxes:ct,referenced:lt}=X(D,t);for(let o of E)o.grid=!!$[o.kind]?.plain?.(o.node);for(let o of E){let s=$[o.kind]?.dataOf?.(t,o.node,c??=P().packages);s&&(o.parts=Object.fromEntries(Object.entries(s).map(([i,u])=>[i,H(u)])))}for(let o of e){let s=null;for(let i of E)i.start<=o.start&&o.start<i.end&&(!s||i.start>s.start)&&(s=i);o.unit=s?.id??null,o.self=s&&s.at===o.innerStart-1?s.id:null,o.self!==null&&(s.text=o.id),o.path=s&&o.self===null?Ht(s,o.node):null,A.text&&o.kind==="flow"&&o.self===null&&(s?.kind==="block"||s?.kind==="figure")&&(o.kind="text"),o.bound=lt(o.node)!==null,o.caps=Object.fromEntries(At(o.kind,o.tag,o.bound).map(i=>[i,!0]))}return{blocks:e,locks:r,units:E,boxes:ct}}function Ht(t,e){let r=[],a=e;for(;a&&!t.nodes.includes(a);a=a.parentNode){let c=(a.parentNode?.childNodes??[]).filter(l=>l.tagName===a.tagName);r.unshift([a.tagName,c.indexOf(a),c.length])}return a?[a===t.node?"unit":a===t.nodes[0]&&t.lead!==null?"lead":"panel",...r]:null}var fe=t=>T(t).blocks;function de(t){let{units:e,boxes:r}=T(t);return{units:e,boxes:r}}U();import{randomBlockId as qt}from"../browser/shared/ids.mjs";import{IDENTITY as O}from"../browser/editor/components/registry.mjs";var Kt=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function be(t,e=qt){let{units:r}=T(t),a=new Set([...t.matchAll(Kt)].map(d=>d[1]??d[2])),c=()=>{for(;;){let d=e();if(!a.has(d))return a.add(d)&&d}},l=new Set,n=[],N=[],m=[];for(let d of r)if(d.blockId)l.has(d.blockId)&&d.blockIdAttr?(N.push(d.blockId),n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${c()}"`})):l.add(d.blockId);else{let b=c();if(d.blockIdAttr)n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${b}"`});else{let g=z(t,d.at);n.push({start:g,end:g,text:` ${O}="${b}"`})}m.push({id:b,tag:rt(d.tag,d.attrs),at:d.elStart})}let I=t;for(let d of n.sort((b,g)=>g.start-b.start))I=I.slice(0,d.start)+d.text+I.slice(d.end);return m.sort((d,b)=>d.at-b.at),{text:I,added:m.length,renamed:N,given:m.map(({id:d,tag:b})=>({id:d,tag:b}))}}function Ie(t){let e=nt(t);return T(t).units.filter(r=>!r.blockId).sort((r,a)=>r.elStart-a.elStart).map(r=>({line:e(r.elStart),tag:rt(r.tag,r.attrs)}))}function ke(t,e){let r=new Map(e.map(c=>[c.id,c])),a=nt(t);return T(t).units.filter(c=>r.has(c.blockId)).sort((c,l)=>c.elStart-l.elStart).map(c=>({...r.get(c.blockId),line:a(c.elStart)}))}function nt(t){let e=[0];for(let r=t.indexOf(`
3
+ `);r!==-1;r=t.indexOf(`
4
+ `,r+1))e.push(r+1);return r=>{let[a,c]=[0,e.length-1];for(;a<c;){let l=a+c+1>>1;e[l]<=r?a=l:c=l-1}return a+1}}function rt(t,e=[]){let r=e.filter(({name:l})=>l!==O&&l!=="style"),a=l=>{let n=l.replace(/\s+/g," "),N=n.length>32?`${n.slice(0,31)}\u2026`:n;return N===""?"":/[\s"'=<>`]/.test(N)?`="${N.replaceAll('"',"&quot;")}"`:`=${N}`},c=r.slice(0,3).map(({name:l,value:n})=>`${l}${a(n)}`);return`<${[t,...c,...r.length>3?["\u2026"]:[]].join(" ")}>`}function xe(t){let e=new Map,r=a=>{let c=a.attrs?.find(n=>n.name===O)?.value,l=a.sourceCodeLocation?.attrs?.[O]??a.sourceCodeLocation;c!==void 0&&e.set(c,[...e.get(c)??[],l]);for(let n of a.content?.childNodes??a.childNodes??[])r(n)};return r(S(t,{sourceCodeLocationInfo:!0})),[...e].filter(([,a])=>a.length>1).map(([a,c])=>({id:a,lines:c.map(l=>l?.startLine),columns:c.map(l=>l?.startCol)}))}export{le as a,Dt as b,j as c,Ft as d,T as e,fe as f,de as g,qt as h,Kt as i,be as j,Ie as k,ke as l,xe as m};
@@ -0,0 +1,24 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{g as St,r as nt,t as Ct}from"./chunk-HDWTZ763.mjs";import{a as Lt,b as st,c as z,e as vt}from"./chunk-A55HN5OK.mjs";import{createHash as Ee}from"node:crypto";import{BLOCK_LEVEL as ot}from"../browser/shared/html-tree.mjs";var wt=t=>Ee("sha256").update(t).digest("hex").slice(0,16),M=t=>t.nodeName==="#text"&&!t.value.trim();function at(t,e){for(let s of t.childNodes??[]){if(s.tagName===e)return s;let o=s.tagName&&at(s,e);if(o)return o}return null}import{ATTRIBUTES as an,BOX_CLASSES as on,COMPONENT_ATTRIBUTES as rn,COMPONENT_CLASSES as cn,GROUPING as ln,IDENTITY as R,TOGGLES as fn,UNIT_KINDS as dn}from"../browser/editor/components/registry.mjs";import{attr as I,hasClass as kt}from"../browser/shared/html-tree.mjs";import{idsNamed as un}from"../browser/shared/copy-ids.mjs";import{DIALOG as pn,PAGE as mn,SECTION as gn,SHEETS as K,TABLE as Le}from"../browser/editor/components/kit.mjs";import{matchesNode as q,partOf as bt}from"../browser/shared/components/index.mjs";import{escapeMarkup as V}from"../browser/shared/escape.mjs";import{imageFile as Ae}from"../browser/shared/media.mjs";import{emptyFigure as Ie}from"../browser/editor/components/media/write.mjs";var _e=t=>typeof t=="string"&&t.length<=2e3&&/^https?:\/\/[^\s"<>]+$/.test(t),Et=(t,e)=>typeof t=="string"&&t.length<=e&&!/[\u0000-\u001f]/.test(t),At=t=>t.href===""&&!t.title&&!t.description&&!t.icon&&!t.cover&&t.caption==="",It=t=>t==null||Ae(t),_t={bookmark:{check:(t,{validLeaf:e})=>At(t)||_e(t.href)&&Et(t.title,300)&&Et(t.description??"",600)&&It(t.icon)&&It(t.cover)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(At(t))return Ie("bookmark",e);let s=t.title.trim()||new URL(t.href).hostname,o=[`<span class="doc-bookmark-title">${V(s)}</span>`,t.description?`<span class="doc-bookmark-description">${V(t.description)}</span>`:"",`<span class="doc-bookmark-url">${t.icon?`<img class="doc-bookmark-icon" src="${t.icon}" alt="">`:""}<span class="doc-bookmark-href">${V(t.href)}</span></span>`].join(""),n=t.cover?`<span class="doc-bookmark-cover"><img src="${t.cover}" alt=""></span>`:"",a=`<a class="doc-bookmark-card" href="${V(t.href)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text">${o}</span>${n}</a>`;return e.block(`<figure class="doc-bookmark"${e.id}>`,[a,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{BLOCK_TYPES as Be,sizeValue as Me}from"../browser/editor/components/registry.mjs";import{LINE_START as Mt,lineStart as je}from"../browser/shared/code-lines.mjs";import{hasClass as Bt}from"../browser/shared/html-tree.mjs";import{CODE_HEIGHT as rt,FOLDED_LINES as jt,validFolded as Re,validLanguage as De}from"../browser/editor/components/code/index.mjs";var ze=(t,e,s,o,n="",a="",r="",i="")=>`<div class="${t.className}"${s?` data-language="${s}"`:""}${i?` ${Mt}="${i}"`:""}${r?` ${jt}="${r}"`:""}${o?` style="${rt}: ${o}"`:""}${n}><div class="doc-code-title">${a}</div><pre><code>${e}</code></pre></div>`,Ue=(t,e)=>t==="data-language"||t===jt||t===Mt||t==="style"&&new RegExp(`^\\s*${rt}\\s*:[^;]*;?\\s*$`).test(e??""),We=t=>typeof t=="string"&&t.length<=200&&!/[<>\n]|&(?!(amp|lt|gt|quot|#39);)/.test(t),Fe=t=>(t.language===void 0||De(t.language))&&(t.folded===void 0||Re(t.folded))&&(t.height===void 0||Me("code",rt,t.height)===t.height)&&(t.title===void 0||We(t.title))&&(t.lineStart===void 0||typeof t.lineStart=="string"&&String(je(t.lineStart))===t.lineStart);function Ke(t){let{node:e}=t;if(t.tag!=="div"||t.nested||!Bt(e,Be.code.className))return!1;let s=(n,a)=>{let r=n.childNodes??[],i=r.filter(f=>f.tagName);return i.length===a.length&&i.every((f,l)=>f.tagName===a[l])&&r.every(f=>f.tagName||!(f.value??"").trim())?i:null},o=s(e,["div","pre"]);return!!o&&Bt(o[0],"doc-code-title")&&!!s(o[1],["code"])}var Rt={code:{fields:["language","folded","height","title","lineStart"],check:Fe,leaf:(t,e,s)=>ze(t,e.html,e.language,e.height,s,e.title,e.folded,e.lineStart),written:Ke,attribute:Ue}};import{sizeValue as He}from"../browser/editor/components/registry.mjs";import{MIN_COLUMNS as Pe,RATIO as Dt}from"../browser/editor/components/columns/index.mjs";var zt={columns:{check:t=>t.children.length>=Pe&&t.children.every(e=>e.type==="column")},column:{check:t=>t.ratio===void 0||He("column",Dt,t.ratio)===t.ratio,write(t,e){let s=t.ratio===void 0?"":` style="${Dt}: ${t.ratio}"`;return e.block(`<div class="doc-column"${s}${e.id}>`,e.children(e.inner),"</div>")}}};var Ut={details:{empty:!0,check:(t,{validLeaf:e})=>t.title===""||e({tag:"span"},t.title),write(t,e){let s=e.inner===null?null:e.inner+e.step,o=e.block('<div class="doc-details-content">',e.children(s),"</div>",e.inner,s),n=t.classes?.length?` ${t.classes.join(" ")}`:"";return e.block(`<details class="doc-details${n}"${e.id}>`,[`<summary><span class="doc-details-summary-label">${t.title}</span></summary>`,t.children.length>0?o:'<div class="doc-details-content"></div>'],"</details>")}}};var Wt={dialog:{empty:!0,check(t,{usedIds:e}){return typeof t.id!="string"||!/^[A-Za-z][\w-]{0,63}$/.test(t.id)||e.has(t.id)?!1:(e.add(t.id),!0)},write(t,e){let s=t.children.length>0?e.block('<div class="doc-dialog-content">',e.children(e.deep(3)),"</div>",e.deep(2),e.deep(3)):'<div class="doc-dialog-content"></div>',o=e.block('<div class="doc-dialog-panel">',[s],"</div>",e.deep(1),e.deep(2));return e.block(`<dialog class="doc-dialog" id="${t.id}">`,[o],"</dialog>")}}};import{escapeAttribute as Ge}from"../browser/shared/escape.mjs";import{embedFile as Ft}from"../browser/shared/media.mjs";import{emptyFigure as qe}from"../browser/editor/components/media/write.mjs";import{FILE_SANDBOX as Ve,WEB_SANDBOX as Xe}from"../browser/editor/components/embed/index.mjs";var Ye=t=>typeof t=="string"&&t.length<=2e3&&/^https:\/\/[^\s"<>]+$/.test(t),Kt=t=>t.src===""&&t.height===void 0&&t.caption==="",Ht={embed:{check:(t,{validLeaf:e})=>Kt(t)||(Ye(t.src)||Ft(t.src))&&(t.height===void 0||/^\d{2,4}px$/.test(t.height))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Kt(t))return qe("embed",e);let s=Ft(t.src),o=s?/\.pdf$/i.test(t.src)?"":` sandbox="${Ve}"`:` sandbox="${Xe}" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen`,n=`<iframe class="doc-embed-frame" src="${Ge(t.src)}"${o} loading="lazy"></iframe>`,a=t.height?` style="--doc-embed-height: ${t.height}"`:"";return e.block(`<figure class="doc-embed${s?" doc-embed--file":""}"${a}${e.id}>`,[n,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{escapeMarkup as Pt}from"../browser/shared/escape.mjs";import{assetFile as Ze}from"../browser/shared/media.mjs";import{emptyFigure as Je}from"../browser/editor/components/media/write.mjs";var Gt=t=>t.href===""&&t.name===""&&t.size===void 0&&t.caption==="",Qe=t=>typeof t=="string"&&t.trim()!==""&&t.length<=120&&!/[\u0000-\u001f<>:"/\\|?*]/.test(t),qt={file:{check:(t,{validLeaf:e})=>Gt(t)||Ze(t.href)&&Qe(t.name)&&(t.size===void 0||/^\d+(\.\d)? (B|KiB|MiB|GiB)$/.test(t.size))&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Gt(t))return Je("file",e);let s=t.size?`<span class="doc-file-size">${t.size}</span>`:"",o=`<a class="doc-file-link" href="${t.href}" download="${Pt(t.name)}"><span class="doc-file-name">${Pt(t.name)}</span>${s}</a>`;return e.block(`<figure class="doc-file"${e.id}>`,[o,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{FLOW as ts,FLOW_DIRECTION as Vt,FLOW_RATIO as Xt}from"../browser/editor/components/flowchart/index.mjs";import{START as es,validDirection as Yt,validStart as ss}from"../browser/editor/components/list/index.mjs";import{sizeValue as ns,TOGGLES as as}from"../browser/editor/components/registry.mjs";var Zt={flowchart:{check:t=>(t.start===void 0||ss(t.start))&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write:(t,e)=>e.block(`<ol class="${ts}"${t.start?` ${es}="${t.start}"`:""}${t.direction?` ${Vt}="${t.direction}"`:""}${e.id}>`,e.children(e.inner),"</ol>")},step:{check:t=>(t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(e=>(as.step??[]).includes(e)))&&(t.ratio===void 0||ns("step",Xt,t.ratio)===t.ratio)&&(t.direction===void 0||Yt(t.direction))&&t.children.length>0,write(t,e){let s=t.classes?.length?` class="${t.classes.join(" ")}"`:"",o=t.direction?` ${Vt}="${t.direction}"`:"",n=t.ratio===void 0?"":` style="${Xt}: ${t.ratio}"`;return e.block(`<li${s}${o}${n}${e.id}>`,e.children(e.inner),"</li>")}}};import{SPAN as os,SPAN_SIZE as Jt,imageFile as Qt}from"../browser/shared/media.mjs";import{emptyFigure as rs}from"../browser/editor/components/media/write.mjs";var is=/^\d{1,3}(\.\d{1,3})?( \d{1,3}(\.\d{1,3})?){3}$/,te=t=>t.src===""&&t.caption===""&&t.span===void 0&&t.original===void 0&&t.classes===void 0,cs=t=>typeof t=="number"&&Number.isFinite(t)&&t>=Jt.min&&t<=Jt.max,ee={image:{check:(t,{validLeaf:e})=>te(t)||Qt(t.src)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption))&&(t.span===void 0||cs(t.span))&&(t.original===void 0||Qt(t.original)&&typeof t.crop=="string"&&is.test(t.crop)),write(t,e){if(te(t))return rs("image",e);let s=["doc-image",...t.classes??[]].join(" "),o=t.span===void 0?"":` style="${os}: ${Math.round(t.span*1e3)/1e3}"`,n=t.original===void 0?"":` data-original="${t.original}" data-crop="${t.crop}"`;return e.block(`<figure class="${s}"${o}${e.id}>`,[`<img src="${t.src}" alt=""${n}>`,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};vt();import{heldByNode as ls,instanceSlots as fs,isInstance as lt,isSlot as ds,ownSlots as us,partOf as ft}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as G,DATA_MOST as ps,NO_TEXT as ms,PACKAGE_ID as se,SCHEMA as ne,SLOT as ae,fitsDataScript as gs,isDataScript as hs,noDataPart as $s,refusedInCopy as Ns,refusedInData as Os,schemaAhead as oe}from"../browser/shared/components/installed.mjs";import{attr as B,walk as re}from"../browser/shared/html-tree.mjs";import{CHART_KEY as bs,VIEW_FROM as it}from"../browser/shared/table-chart.mjs";var P=(t,e)=>{for(let s=t.parentNode;s;s=s.parentNode)if(s===e)return!0;return!1},xs=t=>{let e=t.parentNode;for(;e&&!lt(e);)e=e.parentNode;return e??null},dt=(t,e)=>xs(t)===e&&ls(t)===e&&!ds(t);function ct(t,e){let o=Object.entries(e.get(B(t,G))?.parts??{}).filter(([,{edit:n}])=>n==="data").map(([n,{at:a}])=>[n,ft(t,a).find(r=>r.sourceCodeLocation&&!lt(r)&&dt(r,t))]).filter(([,n])=>n);return o.filter(([,n],a)=>!o.some(([,r],i)=>P(n,r)||r===n&&i<a))}var ys=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),ks="http://www.w3.org/1999/xhtml",Ts=t=>(t.content??t).childNodes;function ie(t,e,s,o){let n=s;for(let a of Ts(t)){let r=a.sourceCodeLocation;if(r?.startOffset!==n)return!1;if(a.tagName){let{startTag:i,endTag:f}=r,l=ys.has(a.tagName)||a.namespaceURI!==ks&&e.startsWith("/>",r.endOffset-2);if(f?!ie(a,e,i.endOffset,f.startOffset):!l)return!1}n=r.endOffset}return n===o}function Ls(t,e,s){if(e.tagName==="script")return hs(e.tagName,e.attrs)&&gs(s);if($s(e.tagName))return!1;let{startTag:o,endTag:n}=e.sourceCodeLocation,a=t.slice(o.startOffset,o.endOffset),r=`${a}${s}${t.slice(n.startOffset,n.endOffset)}`,[i,...f]=z(e.parentNode,r,{sourceCodeLocationInfo:!0}).childNodes;if(f.length>0||i?.tagName!==e.tagName||i.sourceCodeLocation?.endOffset!==r.length||!i.sourceCodeLocation.endTag||!ie(i,r,a.length,a.length+s.length))return!1;let l=!1;return re(i,m=>{l||=Os(m.tagName,m.attrs)}),!l}var vs=(t,e)=>Object.values(e.get(B(t,G))?.parts??{}).filter(({edit:s})=>s==="text"||s==="data").flatMap(({at:s})=>ft(t,s).filter(o=>dt(o,t))),ce={installed:{slots(t,e){let s=vs(t,e);return fs(t).filter(o=>!s.some(n=>P(o,n)))},boxes(t,e){return this.slots(t,e).map(s=>({element:s,kind:"slot",key:B(s,ae)}))},textParts(t,e){let s=e.get(B(t,G));if(oe(B(t,ne),s?.schema))return[];let o=Object.values(s?.parts??{}).filter(({edit:r})=>r==="text"),n=ct(t,e).map(([,r])=>r),a=[...new Set(o.flatMap(({at:r})=>ft(t,r)))].filter(r=>r.sourceCodeLocation&&!lt(r)&&!ms.has(r.tagName)&&dt(r,t)).filter(r=>!n.some(i=>i===r||P(r,i)||P(i,r)));return a.filter(r=>!a.some(i=>P(r,i))).map(r=>({kind:"installed",part:r}))},source({package:t,html:e,children:s,boxKeys:o,from:n},{packages:a,written:r}){if(typeof t!="string"||!se.test(t))return null;let i=s!==void 0;if(i&&!(Array.isArray(s)&&Array.isArray(o)&&o.length===s.length)||n!=null&&(typeof n!="string"||!bs.test(n)))return null;let f=e===void 0?a.has(t)?Ct(a.get(t)):null:e,l=typeof f=="string"?nt(f,t):null;if(l&&(typeof n=="string"||n===null&&B(l.root,it)!==void 0)&&(l.root.attrs=[...l.root.attrs.filter(({name:L})=>L!==it),...n===null?[]:[{name:it,value:n}]],l=nt(Lt(l.root),t)),!l)return null;let m=us(l.root),u=L=>!L.childNodes.every(N=>N.nodeName==="#text"&&!N.value.trim());if((e!==void 0||!i)&&m.some(u)||i&&!o.every(L=>m.some(N=>B(N,ae)===L)))return null;if(e!==void 0){let L=!1;if(re({childNodes:[l.root]},N=>{L||=Ns(N.tagName,N.attrs)}),L)return null}let v=m.map(L=>L.sourceCodeLocation).sort((L,N)=>N.startOffset-L.startOffset).reduce((L,{startTag:N,endTag:b})=>L.slice(0,N.endOffset)+L.slice(b.startOffset),l.markup);return r(i?v:l.markup)},unwritten:({package:t,html:e},{packages:s})=>e===void 0&&se.test(t)&&!s.has(t)?"no-package":"invalid",definition:(t,e)=>e.get(B(t,G))?.definition,dataOf(t,e,s){let o=ct(e,s).filter(([,n])=>n.sourceCodeLocation.endTag);return o.length>0?Object.fromEntries(o.map(([n,a])=>[n,t.slice(a.sourceCodeLocation.startTag.endOffset,a.sourceCodeLocation.endTag.startOffset)])):null},rewrite(t,e,s,{packages:o}){let n=new Map(ct(e,o)),a=Object.keys(s),r=a.map(f=>s[f]);if(oe(B(e,ne),o.get(B(e,G))?.schema)||a.length===0||!r.every(f=>typeof f=="string")||!a.every(f=>n.has(f))||r.reduce((f,l)=>f+Buffer.byteLength(l),0)>ps||!a.every(f=>n.get(f).sourceCodeLocation.endTag&&Ls(t,n.get(f),s[f])))return null;let i=t.includes(`\r
3
+ `)?`\r
4
+ `:`
5
+ `;return a.map(f=>{let{startTag:l,endTag:m}=n.get(f).sourceCodeLocation;return{start:l.endOffset,end:m.startOffset,text:s[f].replace(/\r?\n/g,i)}})}}};vt();import{IDENTITY as Ss}from"../browser/editor/components/registry.mjs";import{SHEETS as X,TABLE as le}from"../browser/editor/components/kit.mjs";import{escapeAttribute as Y,escapeText as ut}from"../browser/shared/escape.mjs";import{isInstance as Cs,matchesNode as pt}from"../browser/shared/components/index.mjs";import{attr as j}from"../browser/shared/html-tree.mjs";import{CHART_SOURCE as fe,TABLE_READERS as ws}from"../browser/shared/table-chart.mjs";import{freshPrefix as Es,referencedIds as As,rewrite as Is}from"../browser/shared/copy-ids.mjs";var de=(t={})=>Object.entries(t).map(([e,s])=>s===""?` ${e}`:` ${e}="${Y(String(s))}"`).join(""),ue=(t,e)=>t[e-1]==="/"?e-1:e;function Z(t,e,s){let o=e;for(;o>0&&/\s/.test(t[o-1]);)o--;return{start:o,end:s}}function Sa(t){let e=s=>s.nodeName==="#text"?s.value:(s.childNodes??[]).map(e).join("");return e(z(t)).replace(/\s+/g," ").trim()}function Ca(t,{from:e,to:s}){let n=pe(st(t,{sourceCodeLocationInfo:!0}))?.sourceCodeLocation;if(!n?.endTag)return null;let a=t.slice(n.startTag.endOffset,n.endTag.startOffset);if(!e)return a.trim()===""?{start:n.startTag.endOffset,end:n.endTag.startOffset,text:ut(s)}:null;let r=ut(e),i=a.indexOf(r);if(i<0||a.indexOf(r,i+1)>=0)return null;let f=n.startTag.endOffset+i;return{start:f,end:f+r.length,text:ut(s)}}function pe(t){for(let e of t.childNodes??[]){if(e.tagName==="title")return e;if(e.tagName==="body")continue;let s=e.tagName&&pe(e);if(s)return s}return null}function _s(t){let e=[],s=0,o=null,n=0;for(let a=0;a<t.length;a++){let r=t[a];if(r==="&"){let i=/^&(#\d+|#x[\da-f]+|[a-z]\w*);/i.exec(t.slice(a));i&&(a+=i[0].length-1)}else o?r===o?o=null:r==="\\"&&a++:r==='"'||r==="'"?o=r:r==="("?s++:r===")"?s=Math.max(0,s-1):r===";"&&s===0&&(e.push(t.slice(n,a)),n=a+1)}return e.push(t.slice(n)),e.map(a=>a.trim()).filter(Boolean)}function ht(t,e){let s=_s(t);for(let[o,n]of e){let a=s.findIndex(r=>r.slice(0,r.indexOf(":")).trim()===o);n===null?a>=0&&s.splice(a,1):a>=0?s[a]=`${o}: ${n}`:s.push(`${o}: ${n}`)}return s.join("; ")}var Bs=new Set(["pre","textarea","script","style"]);function wa(t){if(typeof t!="string"||!t.trim())return null;let s=z(t,{sourceCodeLocationInfo:!0}).childNodes.filter(f=>f.nodeName!=="#comment"&&!(f.nodeName==="#text"&&!f.value.trim())),[o,n]=s;if(s.length===2&&o.tagName==="button"&&pt(o,X.tab)&&n.tagName&&n.sourceCodeLocation?.endTag&&j(o,X.tabKey)&&j(n,X.panelKey)===j(o,X.tabKey)){let f=o.sourceCodeLocation.endOffset;return{element:o,source:t.slice(0,f),panel:t.slice(f).replace(/^\s+/,""),kind:"tab"}}let a=s.at(-1),r=s.length===2?s[0]:null;if(!a?.tagName||!a.sourceCodeLocation?.startTag||s.length>2||r&&!(r.tagName&&pt(r,le.lead)&&pt(a,le.frame)))return null;let i=W(a);return{element:a,source:t,kind:i}}function Ms(t){let e=[],s=o=>{for(let n of o.childNodes??[]){if(!n.tagName)continue;let a=j(n,"id");a&&e.push(a),s(n.tagName==="template"?n.content:n)}};return s(st(t)),e}var Ea=(t,e)=>`${mt(t.slice(e.start,e.end),U(t,e.start),"")}
6
+ ${mt(t.slice(e.companion.start,e.companion.end),U(t,e.companion.start),"")}`;function Aa(t,e,{keys:s=null,taken:o=null}={}){let n=t.slice(e.start,e.end),a=[],r=z(n,{sourceCodeLocationInfo:!0}),i=[],f=N=>{for(let b of N.childNodes??[])b.tagName&&(i.push(b),f(b.tagName==="template"?b.content:b))};f(r);let l=As(i.flatMap(N=>N.attrs)),m=new Set(i.map(N=>j(N,"id")).filter(N=>N&&l.has(N))),u=new Map;if(m.size>0){let N=o??new Set(Ms(t)),b=Es(N);for(let S of m)u.set(S,`${b}${S}`),N.add(`${b}${S}`)}let v=N=>{for(let b of N.childNodes??[])if(b.tagName){for(let S of[Ss,"id"]){let p=b.sourceCodeLocation?.attrs?.[S];p&&(S==="id"&&u.has(j(b,"id"))?a.push({start:p.startOffset,end:p.endOffset,text:`id="${Y(u.get(j(b,"id")))}"`}):a.push(Z(n,p.startOffset,p.endOffset)))}for(let{name:S,prefix:p,value:$}of u.size>0?b.attrs:[]){let w=p?`${p}:${S}`:S,d=Is(w,$,u),g=b.sourceCodeLocation?.attrs?.[w];d!==null&&g&&a.push({start:g.startOffset,end:g.endOffset,text:`${w}="${Y(d)}"`})}for(let S of[...ws,fe]){let p=b.sourceCodeLocation?.attrs?.[S],$=j(b,S);!p||!s||!Object.hasOwn(s,$)||(s[$]!==null?a.push({start:p.startOffset,end:p.endOffset,text:`${S}="${Y(s[$])}"`}):S===fe&&a.push(Z(n,p.startOffset,p.endOffset)))}v(b.tagName==="template"?b.content:b)}};v(r);let L=a.sort((N,b)=>b.start-N.start).reduce((N,{start:b,end:S,text:p=""})=>N.slice(0,b)+p+N.slice(S),n);return mt(L,U(t,e.start),"")}function mt(t,e,s){if(e===null||s===null||e===s||!t.includes(`
7
+ `))return t;let o=[],n=i=>{for(let f of i.childNodes??[]){if(!f.tagName)continue;let l=f.sourceCodeLocation;(Bs.has(f.tagName)||Cs(f))&&l?.startTag&&l.endTag?o.push([l.startTag.endOffset,l.endTag.startOffset]):n(f.tagName==="template"?f.content:f)}};n(z(t,{sourceCodeLocationInfo:!0}));let a="",r=0;for(let i of t.split(/(?<=\n)/)){let f=o.some(([m,u])=>r>m&&r<=u),l=i===`
8
+ `||i===`\r
9
+ `;a+=r>0&&!f&&!l&&i.startsWith(e)?s+i.slice(e.length):i,r+=i.length}return a}function U(t,e){let s=t.slice(t.lastIndexOf(`
10
+ `,e-1)+1,e);return/^[ \t]*$/.test(s)?s:null}function js(t,e,s){let o=t.lastIndexOf(`
11
+ `,e-1)+1,n=t.indexOf(`
12
+ `,s),a=n<0?t.length:n+1;return/^[ \t]*$/.test(t.slice(o,e))&&/^[ \t]*\r?\n?$/.test(t.slice(s,a))?{start:o,end:a,text:""}:{start:e,end:s,text:""}}function Ia(t,e,s){let o=/^\s*(?=<\/li\s*>)/i.exec(t.slice(s,s+400));if(o)return{start:e-/\s*$/.exec(t.slice(Math.max(0,e-400),e))[0].length,end:s+o[0].length,text:""};let n=js(t,e,s);if(n.start===e&&n.end===s)return n;let a=/^[ \t]*\r?\n$/,r=t.indexOf(`
13
+ `,n.end),i=r>=0&&a.test(t.slice(n.end,r+1)),f=t.lastIndexOf(`
14
+ `,n.start-2)+1,l=n.start>0&&a.test(t.slice(f,n.start)),m=t.slice(0,e).trimEnd(),u=m.endsWith(">")?m.slice(m.lastIndexOf("<")):"",v=/^<[a-z]/i.test(u)&&!/\/\s*>$/.test(u)&&!gt.has(u.match(/^<([a-z0-9-]+)/i)?.[1].toLowerCase()),L=/^\s*<\//.test(t.slice(s,s+200));return i&&(l||v)?{...n,end:r+1}:l&&L?{...n,start:f}:n}import{CONTINUE as Rs,START as Ds,validStart as zs}from"../browser/editor/components/list/index.mjs";var me={item:{children:(t,e)=>t.children.length>0&&t.children.every(s=>e(s,"nest")),write:(t,e)=>e.block(`<li${t.classes?.length?` class="${t.classes.join(" ")}"`:""}${de(t.attributes)}${e.id}>${t.html}`,e.children(e.inner),"</li>")},numbers:{check:t=>(t.start===void 0||zs(t.start))&&(t.continue===void 0||t.continue===!0),write:(t,e)=>e.block(`<ol${t.start?` ${Ds}="${t.start}"`:""}${t.continue?` ${Rs}`:""}${e.id}>`,e.children(e.inner),"</ol>")}};import{iconKind as Us}from"../browser/shared/emoji/icon-value.mjs";import{SHEETS_LABEL as Ws}from"../browser/shared/components/sheets.mjs";var ge=/^[a-z0-9][a-z0-9_-]{0,63}$/i,Fs=(t,e="")=>`<button class="doc-sheet-tab" type="button" data-sheet-tab="${t.sheet}"${t.icon?` data-tab-icon="${t.icon}"`:""}${e}>${t.title}</button>`,he={sheets:{check:t=>typeof t.name=="string"&&ge.test(t.name)&&t.children.length>=1&&t.children.every(e=>e.type==="tab")&&new Set(t.children.map(e=>e.sheet)).size===t.children.length,write(t,e){let s=e.inner===null?null:e.inner+e.step,o=Ws[e.language],n=e.block(`<div class="doc-sheet-tabs" aria-label="${o}">`,t.children.map(r=>Fs(r,e.idOf(r))),"</div>",e.inner,s),a=t.children.map(r=>r.children.length===0?`<div data-doc-sheet="${r.sheet}"></div>`:e.block(`<div data-doc-sheet="${r.sheet}">`,r.children.map(i=>e.render(i,s)),"</div>",e.inner,s));return e.block(`<section class="doc-sheet-shell" data-doc-sheets="${t.name}" aria-label="${o}"${e.id}>`,[n,...a],"</section>")}},tab:{empty:!0,check:t=>typeof t.title=="string"&&t.title.trim()!==""&&t.title.length<=200&&!/[<>\r\n]/.test(t.title)&&typeof t.sheet=="string"&&ge.test(t.sheet)&&(t.icon===void 0||Us(t.icon)==="emoji")}};import{COLUMN_WIDTH as Zs,NUMBERS as Js,tableTiling as Qs,validTable as tn}from"../browser/editor/components/table/index.mjs";import{CHART_SOURCE as en}from"../browser/shared/table-chart.mjs";import{widthHolder as sn}from"../browser/shared/table-slots.mjs";import{CELL_LOOKS as Ps,COLUMN_WIDTH as Oe,validLook as Gs,validWidth as qs}from"../browser/editor/components/table/index.mjs";import{tileSpans as be}from"../browser/shared/table-slots.mjs";import{attr as Nt}from"../browser/shared/html-tree.mjs";function Ks(t,e){let s=t.slice(e.startOffset,e.endOffset),o=/^[^=\s]+\s*=\s*(["'])([\s\S]*)\1$/.exec(s);return o?{value:o[2],quote:o[1]}:{value:s.replace(/^[^=\s]+\s*=?\s*/,""),quote:'"'}}function Hs(t,e,s){let o=ue(t,e.endOffset-1);for(;o-1>e.startOffset&&/\s/.test(t[o-1]);)o--;let n=[];for(let[a,r]of s){let i=e.attrs?.[a],f=i?Ks(t,i):null,l=typeof r=="function"?r(f):r,m=f&&typeof r=="function"?f.quote:'"',u=l===null?"":l===""&&typeof r!="function"?a:`${a}=${m}${l}${m}`;i&&l===null?n.push({...Z(t,i.startOffset,i.endOffset),text:u}):i?n.push({start:i.startOffset,end:i.endOffset,text:u}):l!==null&&n.push({start:o,end:o,text:` ${u}`})}return n}function $e(t,e,s,o){let n=e.sourceCodeLocation.startTag,a=t.slice(n.startOffset,n.endOffset),r=Hs(t,n,s).map((i,f)=>({...i,index:f}));for(let{start:i,end:f,text:l}of r.sort((m,u)=>u.start-m.start||u.index-m.index))a=a.slice(0,i-n.startOffset)+l+a.slice(f-n.startOffset);return o?a.replace(/^<\w+/,`<${o}`):a}function Ot(t){let e=t?.tagName==="table"?t:t?.childNodes?.find(u=>u.tagName==="table"),s=u=>!!(u?.sourceCodeLocation?.startTag&&u.sourceCodeLocation.endTag),o=u=>u.childNodes.filter(v=>v.tagName),n=u=>u.childNodes.every(v=>v.tagName||M(v));if(!s(e)||!n(e))return null;let a=o(e);if(a.some(u=>!["thead","tbody","colgroup","caption"].includes(u.tagName)))return null;let r=a.filter(u=>u.tagName==="thead"),i=a.filter(u=>u.tagName==="tbody");if(r.length>1||i.length!==1||r.length===1&&a.indexOf(r[0])>a.indexOf(i[0]))return null;let f=u=>u.tagName==="tr"&&s(u)&&n(u)&&o(u).every(v=>(v.tagName==="td"||v.tagName==="th")&&s(v)&&F(v,"rowspan")!==null&&F(v,"colspan")!==null),l=[...r,...i];if(!l.every(u=>s(u)&&n(u)&&o(u).every(f)))return null;let m=l.flatMap(u=>o(u).map(v=>({node:v,head:u.tagName==="thead",cells:o(v)})));return be(m.map(u=>({head:u.head,cells:u.cells.map(v=>[F(v,"rowspan"),F(v,"colspan")])})))?{table:e,head:r[0]??null,body:i[0],rows:m}:null}var xe=1e3;function F(t,e){let s=Nt(t,e);return s===void 0?1:/^\s*\d{1,4}\s*$/.test(s)&&Number(s)>=1&&Number(s)<=xe?Number(s):null}var Ne=t=>t===void 0||Number.isInteger(t)&&t>=1&&t<=xe,$t=(t,e)=>t.slice(e.sourceCodeLocation.startTag.startOffset,e.sourceCodeLocation.startTag.endOffset),Vs=(t,e)=>t.slice(e.sourceCodeLocation.startTag.endOffset,e.sourceCodeLocation.endTag.startOffset),ye=(t,e)=>[...(t??"").split(/\s+/).filter(s=>s&&!Ps.includes(s)),...e.split(" ").filter(Boolean)].join(" "),Xs=(t,e)=>`${e>1?` colspan="${e}"`:""}${t>1?` rowspan="${t}"`:""}`,Ys=(t,e,s,o,n,a,r)=>$e(t,e,[...n!==void 0?[["class",i=>ye(i?.value,n)||null]]:[],...a!==void 0?[["style",i=>ht(i?.value??"",[[Oe,a]])||null]]:[],["scope",o],...r!==void 0?[["colspan",r[1]>1?String(r[1]):null],["rowspan",r[0]>1?String(r[0]):null]]:[]],s);function ke(t,e,s,{validCell:o}){let n=Ot(e);if(!n||!Array.isArray(s?.rows)||s.rows.length===0||s.rows.length>2e3)return null;let{table:a,rows:r}=n,i=new Set;if(!s.rows.every((c,h)=>c&&typeof c.head=="boolean"&&(h===0||!c.head||s.rows[h-1].head)&&(c.from===null||Number.isInteger(c.from)&&r[c.from])&&Array.isArray(c.cells)&&c.cells.length<=5e3&&c.cells.every(k=>{if(!k||!["td","th"].includes(k.tag)||![void 0,null,"row","col"].includes(k.scope)||k.look!==void 0&&!Gs(k.look)||k.width!==void 0&&!qs(k.width)||!Ne(k.rowspan)||!Ne(k.colspan)||k.rowspan===void 0!=(k.colspan===void 0)||k.scope&&k.tag!=="th")return!1;if(k.from!==null){let[O,C]=Array.isArray(k.from)?k.from:[];if(!r[O]?.cells[C]||i.has(`${O}:${C}`))return!1;i.add(`${O}:${C}`)}else if(typeof k.html!="string")return!1;return k.html===void 0||typeof k.html=="string"&&k.html.length<=1e5&&(k.html===""||o(k.tag,k.html))}))||!s.rows.some(c=>!c.head))return null;let l=c=>c.rowspan!==void 0?[c.rowspan,c.colspan]:c.from===null?[1,1]:[F(r[c.from[0]].cells[c.from[1]],"rowspan"),F(r[c.from[0]].cells[c.from[1]],"colspan")],m=be(s.rows.map(c=>({head:c.head,cells:c.cells.map(l)})));if(!m||s.rows.length*m.columns>5e3)return null;let u=c=>r.find(h=>h.node.parentNode===c)?.node??r[0]?.node??null,v=c=>{let h=u(c);return h?U(t,h.sourceCodeLocation.startOffset):null},L=U(t,n.body.sourceCodeLocation.startOffset),N=U(t,a.sourceCodeLocation.startOffset),b=t.includes(`\r
15
+ `)?`\r
16
+ `:`
17
+ `,S=c=>{if(c.from===null){let tt=c.look?` class="${ye("",c.look)}"`:"",T=c.width?` style="${ht("",[[Oe,c.width]])}"`:"";return`<${c.tag}${tt}${T}${c.scope?` scope="${c.scope}"`:""}${Xs(c.rowspan??1,c.colspan??1)}>${c.html}</${c.tag}>`}let[h,k]=c.from,O=r[h].cells[k],C=c.tag==="th"?c.scope??null:null;return`${O.tagName===c.tag&&(Nt(O,"scope")??null)===C&&c.look===void 0&&c.width===void 0&&c.rowspan===void 0?$t(t,O):Ys(t,O,c.tag,C,c.look,c.width,c.rowspan===void 0?void 0:[c.rowspan,c.colspan])}${c.html??Vs(t,O)}</${c.tag}>`},p=c=>{let h=c.from===null?null:r[c.from];return h&&h.cells.length===c.cells.length&&c.cells.every((O,C)=>O.from?.[0]===c.from&&O.from[1]===C&&O.html===void 0&&O.look===void 0&&O.width===void 0&&O.rowspan===void 0&&O.tag===h.cells[C].tagName&&(O.tag!=="th"||(O.scope??null)===(Nt(h.cells[C],"scope")??null)))?t.slice(h.node.sourceCodeLocation.startOffset,h.node.sourceCodeLocation.endOffset):`${h?$t(t,h.node):"<tr>"}${c.cells.map(S).join("")}</tr>`},$=(c,h,k)=>{let O=k?$t(t,k):`<${c}>`,C=v(k??(r.some(A=>A.head)?n.head:n.body));return C===null||L===null?`${O}${h.map(p).join("")}</${c}>`:`${O}${h.map(A=>`${b}${C}${p(A)}`).join("")}${b}${L}</${c}>`},w=s.rows.filter(c=>c.head),d=s.rows.filter(c=>!c.head),y=[...a.childNodes.filter(c=>c.tagName==="caption"||c.tagName==="colgroup").map(c=>t.slice(c.sourceCodeLocation.startOffset,c.sourceCodeLocation.endOffset)),...w.length?[$("thead",w,n.head)]:[],$("tbody",d,n.body)],x=L===null||N===null?y.join(""):`${y.map(c=>`${b}${L}${c}`).join("")}${b}${N}`;return{start:a.sourceCodeLocation.startTag.endOffset,end:a.sourceCodeLocation.endTag.startOffset,text:x}}var Te={table:{rewrite:ke,plain:t=>Ot(t)!==null,check:(t,{validLeaf:e})=>tn(t,s=>typeof s=="string"&&e({tag:"td"},s,{empty:!0})),write(t,e){let s=Qs(t),o=(N,b)=>t.spans?.[N]?.[b]??[1,1],n=new Map((t.widths??[]).map((N,b)=>[sn(s,b),N]).filter(([N,b])=>N&&b)),a=(N,b)=>{let[S,p]=o(N,b),$=n.get(`${N}:${b}`);return`${t.looks?.[N]?.[b]?` class="${t.looks[N][b]}"`:""}${$?` style="${Zs}: ${$}"`:""}${p>1?` colspan="${p}"`:""}${S>1?` rowspan="${S}"`:""}`},r=(N,b,S)=>`<tr>${N.map((p,$)=>b?`<th${a(S,$)}>${p}</th>`:t.column&&s.places.get(`${S}:${$}`).c===0?`<th${a(S,$)} scope="row">${p}</th>`:`<td${a(S,$)}>${p}</td>`).join("")}</tr>`,i=e.inner===null?null:e.inner+e.step,f=i===null?null:i+e.step,[l,...m]=t.rows,u=[];t.header&&u.push(e.block("<thead>",[r(l,!0,0)],"</thead>",i,f));let v=t.header?m:t.rows,L=t.header?1:0;return v.length>0&&u.push(e.block("<tbody>",v.map((N,b)=>r(N,!1,b+L)),"</tbody>",i,f)),e.block(`<div class="doc-table-wrap"${t.numbers===!1?` ${Js}="off"`:""}${t.chart?` ${en}="${t.chart}"`:""}${e.id}>`,[e.block('<table class="doc-table">',u,"</table>",e.inner,i)],"</div>")}}};var J={..._t,...Rt,...zt,...Ut,...Wt,...Ht,...qt,...Zt,...ee,...ce,...me,...he,...Te},nn=Object.entries(J).flatMap(([t,e])=>(e.fields??[]).map(s=>[s,t])),mo=t=>nn.some(([e,s])=>t[e]!==void 0&&t.type!==s);import{FLOW as Q,HELD_TAGS as yt}from"../browser/editor/components/list/index.mjs";var hn=new Set(["section","div","blockquote","ul","ol","aside","article"]),Ce=new Set(["script","style","template","noscript","link","meta","header","dialog","form","fieldset","label","input","select","textarea","button","summary","main","caption","dd","dt","tbody","thead","tfoot","tr","td","th","figcaption"]),we=new Set(["img","picture","svg","canvas","video","audio","iframe","object"]),gt=new Set(["hr","img"]),$n=new Set(["label","input","select","textarea","button"]),Nn=t=>cn.some(e=>kt(t,e))||rn.some(e=>I(t,e)!==void 0);function On(t){let e=t.childNodes??[],s=e.findIndex(n=>yt.has(n.tagName));if(s<0)return[];let o=e.slice(s);return o.every(n=>yt.has(n.tagName)||M(n))?o.filter(n=>n.tagName):null}function bn(t){return t.tagName==="li"&&t.parentNode?.tagName==="ol"&&kt(t.parentNode,Q)&&t.childNodes.some(e=>e.tagName)&&t.childNodes.every(e=>e.tagName?yt.has(e.tagName):e.nodeName!=="#text"||!e.value.trim())}function ve(t){let e=t.tagName,s=t.sourceCodeLocation;return Ce.has(e)||!(ot.has(e)||we.has(e))||I(t,"contenteditable")!==void 0?!1:!!(s?.startTag&&(s.endTag||gt.has(e)))}var xn=(t,e=W(t))=>(J[e]?.boxes?.(t,St().packages)??[]).filter(({element:s})=>Tt(s)||s.sourceCodeLocation?.endTag&&s.childNodes.every(M));function Tt(t){if(!t.childNodes.every(s=>s.nodeName!=="#text"||!s.value.trim()))return!1;let e=t.childNodes.filter(s=>s.tagName);return e.length>0&&!e.some(s=>$n.has(s.tagName)||!(ot.has(s.tagName)||we.has(s.tagName)||Ce.has(s.tagName)))}function xt(t,e=null){let s=t.tagName;if(!hn.has(s)||Nn(t)||I(t,"contenteditable")!==void 0)return null;let o=(I(t,"class")??"").split(/\s+/).filter(Boolean),n=t.childNodes.filter(l=>l.tagName),a=()=>n.every(l=>l.tagName==="li")&&t.childNodes.every(l=>l.tagName||!l.value?.trim());if(s==="ol"&&o.includes(Q))return o.every(l=>l===Q)&&a()?"flowchart":null;if(s==="ul"||s==="ol")return o.every(l=>(fn.list??[]).includes(l))&&a()?"list":null;let r=t.childNodes.every(l=>l.nodeName!=="#text"||!l.value.trim()),i=q(t,gn.match);if(s==="section"&&(o.length===0||i))return r&&(n.length>0||i)?"section":null;let f=on.find(([l])=>o.includes(l))?.[1];return f&&r&&n.length===0?f:Tt(t)?f||(o.length>0?null:s==="blockquote"?"quote":ln.has(e)?"plain":null):null}var yn=(t,e,s=()=>!1)=>Object.entries(e.sourceCodeLocation.attrs??{}).filter(([o])=>o!=="class"&&o!==R&&!s(o,I(e,o))).sort((o,n)=>o[1].startOffset-n[1].startOffset).map(([,o])=>` ${t.slice(o.startOffset,o.endOffset)}`).join("");function W(t,e=t.parentNode){let s=(n,a,r)=>(!a||[a].flat().includes(n?.tagName))&&(!r||kt(n,r));return dn.find(({tag:n,class:a,attr:r,parent:i})=>s(t,n,a)&&(!r||I(t,r)!==void 0)&&(!i||e?.tagName&&s(e,i.tag,i.class)))?.kind??"block"}var kn={flowchart:{tagName:"ol",attrs:[{name:"class",value:Q}]}},Lo=(t,e)=>W(t,kn[e]??null);function vo(t,e){let s=[],o=[],n=d=>d.parentNode.childNodes,a=d=>n(d)[n(d).indexOf(d)-1]??null,r=d=>/^[ \t]*$/.test(e.slice(e.lastIndexOf(`
18
+ `,d-1)+1,d)),i=d=>{let g=a(d);for(;g&&M(g);)g=a(g);return g?.tagName?g:null},f=d=>{if(!q(d,Le.frame))return null;let g=i(d);return g&&q(g,Le.lead)&&g.sourceCodeLocation?.endTag?g:null},l=(d,g)=>{let y=d.sourceCodeLocation.startOffset;for(let x=a(d);x;)if(M(x)&&(x.value.match(/\n/g)?.length??0)<=1)x=a(x);else if(x.nodeName==="#comment"&&x.sourceCodeLocation&&r(x.sourceCodeLocation.startOffset))g.add(x),y=x.sourceCodeLocation.startOffset,x=a(x);else break;return y},m=(d,g,y,x)=>{let c=d.sourceCodeLocation,h=f(d),k=c.attrs?.class,O={id:s.length,tag:d.tagName,kind:W(d),box:g.id,parent:y?.id??null,start:l(h??d,x),end:c.endOffset,elStart:c.startOffset,at:c.startTag.endOffset-1,lead:h?h.sourceCodeLocation.startTag.endOffset-1:null,classAttr:k?{start:k.startOffset,end:k.endOffset,value:I(d,"class")}:null,attrs:d.attrs.map(({name:C,value:A})=>({name:C,value:A})),blockId:I(d,R)??null,carried:yn(e,d,C=>!!an[W(d)]?.[C]),blockIdAttr:c.attrs?.[R]?{start:c.attrs[R].startOffset,end:c.attrs[R].endOffset}:null,companion:null,keep:null,node:d,nodes:h?[h,d]:[d]};return s.push(O),h&&x.add(h),O},u=(d,g,y,x=null)=>{let c=d.sourceCodeLocation,h={id:o.length,kind:g,unit:y?.id??null,key:x,at:c.startTag.endOffset-1,innerEnd:c.endTag?.startOffset??null,pure:!0};return o.push(h),h},v=(d,g,y)=>{let x=u(d,"tabs",g),c=new Set;for(let h of d.childNodes){if(!h.tagName){h.nodeName==="#text"&&h.value.trim()&&(x.pure=!1);continue}let k=I(h,K.tabKey),O=k&&y.find(H=>I(H,K.panelKey)===k);if(h.tagName!=="button"||!q(h,K.tab)||!O?.sourceCodeLocation?.endTag||!h.sourceCodeLocation?.endTag){x.pure=!1;continue}let C=m(h,x,g,c);C.kind="tab",C.key=k;let A=O.sourceCodeLocation;C.companion={tag:O.tagName,start:l(O,new Set),end:A.endOffset,elStart:A.startOffset},C.nodes.push(O)}for(let h of d.childNodes)h.nodeName==="#comment"&&!c.has(h)&&(x.pure=!1)},L=(d,g,y,x=null)=>{let c=u(d,g,y,x),h=new Set,k=d.childNodes.filter(O=>O.tagName);k.forEach((O,C)=>{if(k[C+1]&&f(k[C+1])===O)return;if(g==="header"&&O.tagName==="h1"||!ve(O)){c.pure=!1,O.tagName==="dialog"&&b(O,y),g==="main"&&q(O,mn.header)&&O.sourceCodeLocation?.endTag&&L(O,"header",null);return}N(O,m(O,c,y,h),g)});for(let O of d.childNodes)(O.nodeName==="#text"?O.value.trim():!O.tagName&&!h.has(O))&&(c.pure=!1)},N=(d,g,y)=>{if(g.kind==="sheets"){let x=bt(d,K.panels),[c]=bt(d,K.row);c&&v(c,g,x);for(let h of x)(Tt(h)||h.sourceCodeLocation?.endTag&&h.childNodes.every(M))&&L(h,"panel",g,I(h,K.panelKey))}else if(d.tagName==="details")for(let x of d.childNodes)x.tagName&&xt(x)==="details"&&L(x,"details",g);else if(d.tagName==="li"&&bn(d))L(d,"node",g);else if(d.tagName==="li")S.push([d,g]);else{let x=xt(d,y);x&&L(d,x,g);for(let c of J[g.kind]?.boxes?xn(d,g.kind):[])L(c.element,c.kind,g,c.key)}},b=(d,g)=>{let[y]=bt(d,pn.content);y&&xt(y)==="dialog"&&L(y,"dialog",g,I(d,"id")??null)},S=[],p=(d,g)=>{let y=On(d);if(y===null||!d.sourceCodeLocation?.endTag)return;let x=u(d,"nest",g);x.pure=!1,g.nested=y.length>0;let c=new Set;for(let h of y)ve(h)&&N(h,m(h,x,g,c),"nest")},$=at(t,"main");$?.sourceCodeLocation?.startTag&&L($,"main",null);for(let d=0;d<S.length;d++)p(...S[d]);let w=En(t,s);return{units:s,boxes:o,referenced:w}}var Tn=t=>t===void 0||/^\s*(?:module|(?:text|application)\/(?:x-)?(?:javascript|ecmascript)|text\/javascript1\.[0-5]|text\/(?:jscript|livescript))?\s*$/i.test(t);function Ln(t){let e=vn(t),s=new Set,o=[],n=/(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1/g,a=m=>m.split(/\s+/).filter(Boolean).forEach(u=>s.add(u)),r=/(?:\bclassList\s*\.\s*(?:add|remove|toggle|contains|replace)|\.classed|\bgetElementsByClassName|\.(?:has|add|remove|toggle)Class|\bclassName\s*\.\s*(?:includes|indexOf|startsWith|endsWith)|\bclassName\s*\.\s*split\s*\([^)]*\)\s*\.\s*(?:includes|indexOf))\s*\(\s*((?:(["'`])(?:(?!\2)[^\\\n]|\\.)*\2\s*,?\s*)+)/g;for(let[,m]of t.matchAll(r))for(let[,,u]of m.matchAll(n))a(u);if(/(["'`])[^"'`\n]*\.\1\s*\+|\.\$\{/.test(t)||/(?:\bclassList\s*\.\s*(?:add|remove|toggle|contains|replace)|\.classed|\.(?:has|add|remove|toggle)Class)\s*\(\s*[A-Za-z_$][\w$.]*\s*[,)]/.test(t))for(let m of e)/^-?[A-Za-z_][\w-]*$/.test(m)&&s.add(m);let f=/\bclassName\s*(?:[!=]==?|=)\s*(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1|(["'`])((?:(?!\3)[^\\\n]|\\.)*)\3\s*[!=]==?\s*[\w$.]*\bclassName\b/g;for(let m of t.matchAll(f))a(m[2]??m[4]);let l=/\[\s*class\s*([~|^$*]?)=\s*(?:"([^"]*)"|'([^']*)'|([^\]\s]+))\s*(?:[is]\s*)?\]/g;for(let m of e)for(let u of m.matchAll(l)){let v=u[2]??u[3]??u[4];u[1]===""||u[1]==="~"||u[1]==="|"?a(v):o.push(v)}return{names:s,partial:o,selectors:e.join(`
19
+ `)}}function vn(t){let e=[],s=[],o=0,n="",a=0,r=i=>{let f="";for(let l=i;l<t.length;l++){let m=t[l];if(m==="\\"){f+=t.slice(l,l+2),l++;continue}if(m==="`")return e.push(f),l+1;if(m==="$"&&t[l+1]==="{")return e.push(f),s.push(o),l+2;f+=m}return e.push(f),t.length};for(;a<t.length;){let i=t[a],f=t[a+1];if(i==="/"&&f==="/"){let l=t.indexOf(`
20
+ `,a);a=l<0?t.length:l;continue}if(i==="/"&&f==="*"){let l=t.indexOf("*/",a+2);a=l<0?t.length:l+2;continue}if(i==='"'||i==="'"){let l=a+1,m="";for(;l<t.length&&t[l]!==i&&t[l]!==`
21
+ `;)t[l]==="\\"?(m+=t.slice(l,l+2),l+=2):m+=t[l++];e.push(m),a=l+1,n="a";continue}if(i==="`"){a=r(a+1),n="a";continue}if(i==="}"&&s.length&&s.at(-1)===o){s.pop(),a=r(a+1),n="a";continue}if(i==="/"&&(!/[\w$)\]}]/.test(n)||/(?:^|[^\w$.])(?:return|typeof|case|in|of|void|delete|throw|yield|await|else|do)\s*$/.test(t.slice(Math.max(0,a-12),a)))){let l=a+1,m=!1;for(;l<t.length&&t[l]!==`
22
+ `&&(m||t[l]!=="/");)t[l]==="\\"?l++:t[l]==="["?m=!0:t[l]==="]"&&(m=!1),l++;if(t[l]==="/"){for(a=l+1;/[a-z]/i.test(t[a]??"");)a++;n="a";continue}}i==="{"?o++:i==="}"&&o--,/\s/.test(i)||(n=i),a++}return e}var Sn=/\bDocSheets\b|["'`]sheets-|\bactiveSheet\b|data-active-sheet|["'`]sheet["'`]|\bsheet\s*:/,Cn=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function wn(t,e){if(!Sn.test(e))return!1;let s=Cn(t),o=`(["'\`])${s}\\1`;return[`\\bsheet["'\`]?\\s*:\\s*${o}`,`\\.set\\(\\s*(["'\`])${s}\\1`,`\\.set\\(\\s*(["'\`])sheet\\1\\s*,\\s*(["'\`])${s}\\2`,`[!=]==?\\s*${o}`,`${o}\\s*[!=]==?`,`\\bcase\\s+${o}\\s*:`,`active-sheet\\s*=\\s*["']?${s}["'\\]]`].some(n=>new RegExp(n).test(e))}function En(t,e){let s=[],o=new Map,n=p=>{for(let $ of p.childNodes??[]){if(!$.tagName)continue;let w=$.sourceCodeLocation?.startOffset??-1;$.tagName==="script"&&I($,"src")===void 0&&s.push({at:w,code:Tn(I($,"type")),text:$.childNodes.map(d=>d.value??"").join("")});for(let{name:d,value:g}of $.attrs)if(!(d==="aria-labelledby"&&$.tagName==="section"))for(let y of un(d,g))(o.get(y)??o.set(y,[]).get(y)).push(w);n($.tagName==="template"?$.content:$)}};n(t);let a=p=>p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=p=>p.slice(5).replace(/-([a-z])/g,($,w)=>w.toUpperCase()),i=s.filter(p=>p.code),f=i.map(p=>p.text).join(`
23
+ `),l=p=>i.some($=>p($.at))?i.filter($=>!p($.at)).map($=>$.text).join(`
24
+ `):f,m=new Map,u=(p,$)=>(w,d)=>{if(d!==f)return $(w,d);let g=`${p} ${w}`;return m.has(g)||m.set(g,$(w,d)),m.get(g)},v=u("id",(p,$)=>new RegExp(`#${a(p)}(?![\\w-])|(["'\`])${a(p)}\\1`).test($)),L=u("data",(p,$)=>new RegExp(`${a(p)}(?![\\w-])|dataset\\.${r(p)}(?![\\w$])`).test($)),N=new Map,b=u("class",(p,$)=>{N.has($)||N.set($,Ln($));let{names:w,partial:d,selectors:g}=N.get($);return w.has(p)||d.some(y=>y.includes(p))||new RegExp(`\\.${a(p)}(?![\\w-])`).test(g)}),S=p=>p.split(/\s+/).filter($=>$&&!/^(doc-|katex)/.test($));for(let p of e){let $=[[p.start,p.end],...p.companion?[[p.companion.start,p.companion.end]]:[]],w=T=>$.some(([E,_])=>T>=E&&T<_),d=new Map,g=new Map,y=new Map,x=(T,E,_)=>(T.get(E)??T.set(E,[]).get(E)).push(_),c=T=>{if(!T.tagName)return;let E=T.sourceCodeLocation?.startOffset??p.start;for(let{name:_,value:D}of T.attrs)_==="id"&&D?x(d,D,E):_.startsWith("data-")&&_!==R?x(g,_,E):_==="class"&&S(D).forEach(et=>x(y,et,E));(T.tagName==="template"?T.content:T).childNodes?.forEach(c)};p.nodes.forEach(c);let h=l(w),k=(T,E,_)=>[...T].filter(([D])=>E(D)).map(([D,et])=>({name:_(D),at:et})),O=[...p.key&&s.some(T=>!w(T.at)&&wn(p.key,T.text))?[{name:`"${p.key}"`,at:[p.start]}]:[],...k(d,T=>v(T,h),T=>`#${T}`),...k(g,T=>L(T,h),T=>`[${T}]`),...k(y,T=>b(T,h),T=>`.${T}`)],C=k(d,T=>(o.get(T)??[]).some(E=>!w(E)),T=>`#${T}`),A=O.length>0?O:C,H=A.flatMap(T=>T.at),tt=H.some(T=>!e.some(E=>E!==p&&p.start<=E.start&&E.end<=p.end&&E.start<=T&&T<E.end));p.keep=A.length>0?{reason:O.length>0?"script":"ref",names:A.map(T=>T.name),at:H,own:tt}:null}return p=>{let $=p.sourceCodeLocation;if(!$||!p.attrs.some(({name:y})=>y==="id"||y==="class"||y.startsWith("data-")))return null;let w=y=>y>=$.startOffset&&y<$.endOffset,d=l(w),g=null;for(let{name:y,value:x}of p.attrs)if(y==="id"&&x){if(v(x,d))return"script";(o.get(x)??[]).some(c=>!w(c))&&(g="ref")}else{if(y.startsWith("data-")&&y!==R&&L(y,d))return"script";if(y==="class"&&S(x).some(c=>b(c,d)))return"script"}return g}}function An(t,e){let s=[],o=n=>{let a=n.sourceCodeLocation?.attrs?.[R];if(a){let r=a.startOffset>0&&/\s/.test(t[a.startOffset-1])?a.startOffset-1:a.startOffset;s.push({start:r,end:a.endOffset})}for(let r of n.content?.childNodes??n.childNodes??[])o(r)};return e.forEach(o),s.sort((n,a)=>n.start-a.start)}var Se=(t,e,s,o)=>{let n="",a=e;for(let r of o)r.start<a||r.end>s||(n+=t.slice(a,r.start),a=r.end);return n+t.slice(a,s)},So=(t,e)=>{let s=An(t,e.nodes),o=Se(t,e.start,e.end,s);return wt(e.companion?`${o}\0${Se(t,e.companion.start,e.companion.end,s)}`:o)};export{wt as a,at as b,ot as c,Nn as d,On as e,bn as f,xn as g,yn as h,W as i,Lo as j,vo as k,An as l,So as m,de as n,ue as o,Z as p,Sa as q,Ca as r,ht as s,wa as t,Ms as u,Ea as v,Aa as w,mt as x,U as y,js as z,Ia as A,Fs as B,Hs as C,J as D,mo as E};
@@ -0,0 +1,6 @@
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{E as re,J as ae,K as ne,O as ie,P as ce,a as C,b as Q,c as F,g as X,h as Z,n as D,o as ee,r as te,s as se,t as oe}from"./chunk-7JDX4E65.mjs";import{j as K}from"./chunk-3MBRL2PM.mjs";import{d as le}from"./chunk-EP25HDAJ.mjs";import{i as q}from"./chunk-5XA2ZBAE.mjs";import{a as L}from"./chunk-JEUK3ZO7.mjs";import{a as M,b as z,g as J}from"./chunk-PUOQ65NC.mjs";import{b as x,c as T}from"./chunk-UYVCQK3H.mjs";import{b as E}from"./chunk-4OZWXZE5.mjs";import{f as H,j as Y}from"./chunk-HDWTZ763.mjs";import{b as V,e as pe}from"./chunk-A55HN5OK.mjs";pe();import N from"node:fs/promises";import P from"node:path";import{isInstance as ge}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as me}from"../browser/shared/components/installed.mjs";import{attr as we,walk as $e}from"../browser/shared/html-tree.mjs";import{pageExists as ye,pageFiles as be}from"../browser/shared/pages.mjs";import{layoutOf as Ee}from"../browser/shared/workspace.mjs";var xe="card ids aside",ke="nothing else in page.html changed (card ids aside)",Se=e=>new Promise(s=>setTimeout(s,e)),Te=/^\/__gallery\/pages\/[a-z0-9-]+\/cards$/,de=e=>{let s=null;return $e(V(e,{sourceCodeLocationInfo:!0}),n=>{s??=ge(n)?n:null},{inTemplates:!1}),s},fe=(e,s)=>{let n=s.node.sourceCodeLocation.startTag.endOffset;return{frame:e.slice(s.start,n).replace(/\s+data-[xywh]="[^"]*"/g,""),rest:e.slice(n,s.end)}};function Ce(e,s,n,a){let[o,d]=[x(e).cards,x(s).cards],c=[],t=r=>`card ${r.id}${r.block?` (${r.block})`:""}`,l=r=>["x","y","w","h"].map(i=>`${i} ${we(r.node,`data-${i}`)??"-"}`).join(", ");for(let r of o){let i=d.find(g=>g.id===r.id);if(!i){c.push(`${t(r)} taken out`);continue}let m=r.board!==i.board;(m||l(r)!==l(i))&&c.push(`${t(r)}'s place, ${l(r)}${m?` on ${r.board}`:""} then ${l(i)}${m?` on ${i.board}`:""}`);let[h,p]=[fe(e,r),fe(s,i)];if(h.frame===p.frame&&h.rest===p.rest)continue;if(r.id!==n){c.push(t(r));continue}h.frame!==p.frame&&c.push(`${t(r)}'s own frame (an attribute of its <section> but its place)`);let[f,$]=[D(h.rest,de,a),D(p.rest,de,a)];!f||!$?c.push(`${t(r)}'s instance`):f.outside!==$.outside&&c.push(`${t(r)} itself, outside its data parts (a part edited as text or none, or what its instance holds besides its parts)`)}for(let r of d)o.some(i=>i.id===r.id)||c.push(`a ${t(r)} put in`);let w=(r,i)=>{let m="",h=0;for(let p of[...i].sort((f,$)=>f.start-$.start))m+=r.slice(h,p.start),h=p.end;return(m+r.slice(h)).replace(/\s+/g," ")};return(w(e,o)!==w(s,d)||!c.length)&&c.push("the page's own HTML outside its cards (its head, its style, its header)"),c.join("; ")}function Ie(e,s,{card:n,found:a}){let[o,d]=[T(e).text,T(s).text],t=ee(o,d,l=>x(l).cards.find(w=>w.id===n)?.instance??null,a);return t.outside&&(t.outside={...t.outside,what:Ce(o,d,n,a)}),t}async function Oe(e){try{return await e.waitForSelector("[data-doc-ready]",{timeout:C}).catch(s=>{if(s.name==="TimeoutError")throw s;return e.waitForSelector("[data-doc-ready]",{timeout:C})}),await e.waitForFunction(()=>globalThis.__galleryTryEditable===!0&&!!document.querySelector("script[data-ge-page]"),{timeout:C}),!0}catch(s){if(s.name!=="TimeoutError")throw s;return!1}}function ve(e){return e?.startsWith("stopped")?`the page service refused the board's write (${e.slice(7).trim()||"no reason given"}), and the page showed itself again as the file holds it`:{refused:"the page service refused the board's write: the card was changed or taken out meanwhile (someone else's write of page.html), and the page showed itself again as the file holds it",offline:"the page could not reach the server (offline)",reloading:"the page loaded itself again (page.html or a custom block it holds changed meanwhile, or the page service refused a write)",syncing:`its write took more than ${F/1e3}s to be answered`}[e]}function Ae(e){let s=[],n=new Map;return e.on("request",a=>{if(a.method()!=="POST"||!Te.test(new URL(a.url()).pathname))return;let o={done:!1,status:null,answer:null,failed:null};s.push(o),n.set(a,o)}),e.on("response",a=>{let o=n.get(a.request());o&&(o.status=a.status(),o.done=!0,o.status!==200&&a.json().then(d=>{o.answer=d},()=>{}))}),e.on("requestfailed",a=>{let o=n.get(a);o&&(o.failed=a.failure()?.errorText??"failed",o.done=!0)}),{mark:async()=>s.length,async until(a){let o=Date.now();for(let d=0;;await Se(100)){let c=s.slice(a);if(c.length===0){if(Date.now()-o>Q)return"unchanged";continue}if(c.some(l=>!l.done)){if(d=0,Date.now()-o>F)return"syncing";continue}if(++d<4)continue;if(c.some(l=>l.failed))return"offline";let t=c.find(l=>l.status!==200);return t?t.answer?.refused||t.status===409&&!t.answer?"refused":`stopped ${t.answer?.reason??`HTTP ${t.status}`}`:"saved"}}}}function Re({card:e,found:s}){let n={...s,parts:Object.fromEntries(Object.entries(s.parts).filter(([,a])=>a.edit==="data"))};return{where:{card:e},ready:Oe,saves:Ae,changes:(a,o)=>Ie(a,o,{card:e,found:n}),plain:()=>!1,stayed:ve,outside:"problem",outsideSaid:a=>`card ${e}'s data parts: ${a.what}, where a reader's gesture on the card is to change its data parts alone`,aside:xe,inside:ke,framed:a=>a.closest(".gallery-card")??a}}var Le=e=>` ${e.id} ${e.block??"(no instance)"} x ${e.x}, y ${e.y}, w ${e.w}, h ${e.h}${e.board?` on board ${e.board}`:""}`;async function Ke(e,{named:s,values:n,seconds:a={},keep:o,replace:d=!1}){if(s.length===0)throw new E("Name the page and the card: gallery page try <slug> <card id> and the gesture.");if(s.length===1)throw new E(`Name the card of ${s[0]} to try: gallery page try ${s[0]} <card id> and the gesture (its data-card-id; gallery page check ${s[0]} lists the cards).`);if(s.length>2)throw new E("gallery page try takes a page's slug and a card's id.");let c=await X(n,a,d),[t,l]=s,w=n.has("--steps")?P.resolve(n.get("--steps")):null,r=c?[c]:await Z(w),i=be(t,e);ye(t,e)||(console.error(await le(t,e)),process.exit(1));let m=await N.readFile(i.html,"utf8"),{cards:h}=x(T(m).text),p=h.find(u=>u.id===l);if(!p)throw new E(h.length?`${t} has no card ${l}: its cards are
3
+ ${h.map(Le).join(`
4
+ `)}`:`${t} has no card yet: gallery page add ${t} <block> puts one on it.`);let f=P.basename(i.html),$=p.node.sourceCodeLocation?.startLine??null;p.instance||(console.error(`Card ${l} of ${t} (${f}:${$}) holds no instance of a custom block (an element with ${me}): there is nothing on it to try.`),process.exit(1));let g=p.block,_=H(e),k=_.packages.get(g);if(!k){let u=_.problems.get(g);console.error(u?.off?`${g} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so on the page and runs nothing.`:u?`${g} does not load (${Y("en",u.problem)}), so its card runs nothing: gallery block check ${g} says why.`:`No custom block ${g} in this workspace, so its card runs nothing: gallery block list says which there are${g.startsWith("gallery/")?`, and gallery block add ${g.slice(8)} puts one of Gallery's own in`:""}.`),process.exit(1)}k.places.includes("page")||(console.error(`${g} is a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing, so there is nothing to try there (gallery block try tries it in a document).`),process.exit(1)),console.log(`${g} in card ${l} of ${t}, at ${f}:${$}: ${L(i.html)}`),w&&console.log(`Steps: ${r.length} from ${L(w)}, made one after another in one page`);let S=await q({command:`gallery page try ${t}`});if(!S.ok){console.log(`UNVERIFIED ${t}: ${S.message}`),process.exitCode=3;return}let{pageAloneOf:j}=await import("./chunk-UJQJKNGK.mjs");await oe(e);let B=[],G=async u=>{let b=await te(e,{directory:i.folder,files:i,text:u});return B.push(b.slug),b},I=Re({card:l,found:k});try{let u=o?{slug:t,file:i.html}:await G(m),b=j(S.port,u.slug);console.log(o?`Page: ${b} (the custom page alone, editable: the Agent's own; --keep: what ${re(r)} write stays in ${f}, and every page open on it shows it, the user's too; the server runs on after this command)`:`Page: ${b} (a scratch copy of ${t}, its page alone, editable, made for this trial and gone at its end: ${f} is not written, and no page of the user's shows the trial; the server runs on after this command)`);let O=M();if(!O){console.log(`UNVERIFIED ${t}: no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so nothing was tried`),process.exitCode=3;return}let v;try{v=await J({executablePath:O,args:z()})}catch(R){console.log(`UNVERIFIED ${t}: the browser ${O} did not start, twice, each time with a fresh profile (${K(R)}; GALLERY_BROWSER=<its executable> picks another), so nothing was tried`),process.exitCode=3;return}let A=P.join(Ee(e).qa,t,"try");try{await N.rm(A,{recursive:!0,force:!0}),await N.mkdir(A,{recursive:!0});let R=async y=>{if(o)return{address:b,file:u.file};let W=await G(y);return{address:j(S.port,W.slug),file:W.file}},U;try{U=await ae(v.browser,{root:e,address:b,fresh:R,steps:r,keep:o,file:u.file,name:f,line:$,found:k,out:A,host:I})}catch(y){if(y instanceof E&&y.made&&console.log(ce({name:f,steps:r,keep:o,host:I},y.made).join(`
5
+ `)),y.stuck)return ne(t,y,f,o);throw y}let{lines:ue,code:he}=ie({slug:t,name:f,steps:r,keep:o,host:I},U);console.log(ue.join(`
6
+ `)),process.exitCode=he}finally{await v.close()}}finally{for(let u of B)await se(e,u)}}export{xe as a,ke as b,de as c,Ce as d,Ie as e,Ae as f,Re as g,Ke 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{g as a,h as b,i as c,j as d,k as e,l as f,m as g,n as h,o as i,p as j,q as k,r as l,s as m,t as n,u as o,v as p,w as q}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-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{h as buildReports,d as checkReports,f as checkSelectedReports,b as exportFailures,k as exportReports,p as failureSummary,e as handInBlockers,l as notesByKind,m as notesOf,j as offlineReports,o as printFailures,c as quickFailures,a as repeatedIdFailures,q as reportFailures,n as reportNotes,i as withExportPolicy,g as writeSharedAssets};
@@ -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 S,b as K,c as E,d as v,e as x,f as H}from"./chunk-NAMN3RAF.mjs";import{a as D,b as j}from"./chunk-JEUK3ZO7.mjs";import{b as M,f as R,h as T}from"./chunk-4OZWXZE5.mjs";import O from"node:fs/promises";import _ from"node:path";import{iconKind as ee}from"../browser/shared/emoji/icon-value.mjs";import{descendantsIn as J,parentIn as C}from"../browser/shared/outline.mjs";import{topOf as U}from"../browser/shared/outline-shape.mjs";import{fullAddress as z,namedPlace as te}from"../browser/shared/page-address.mjs";import{reportsDirectory as G}from"../browser/shared/paths.mjs";import{documentLinks as Q,listReportSlugs as oe,roleOf as ne}from"../browser/shared/reports.mjs";import{documentDirectory as se,documentFiles as le,isSlugName as ie}from"../browser/shared/workspace.mjs";import{isWorkspace as W,readRegistry as re,workspaceKey as Y}from"../browser/shared/workspace-registry.mjs";import{findIn as ce,rankReports as V,reportLines as ae}from"../browser/shared/search.mjs";async function X(i=G){let n=(await oe(i)).filter(ie);return(await Promise.all(n.map(async a=>{let r=se(a,i),{html:u,json:s}=le(r),g=await O.stat(u).catch(()=>null);if(!g?.isFile()||await ne(r)==="instructions")return null;let l=await O.readFile(s,"utf8").then(JSON.parse).catch(()=>({})),d=t=>typeof t=="string"?t.replace(/\s+/g," ").trim():"";return{slug:a,title:d(l.title)||a,description:d(l.description),edited:g.mtimeMs,file:u}}))).filter(Boolean)}var P=i=>{let n=new Date(i),o=a=>String(a).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`},k=i=>`${i} document${i===1?"":"s"}`;async function de(i,n,o){let a=[...new Set(o.toLowerCase().split(/\s+/).filter(Boolean))],r=new Set(n.map(({slug:s})=>s));return(await Promise.all(i.filter(({slug:s})=>!r.has(s)).map(async s=>{let g=ae(await O.readFile(s.file,"utf8").catch(()=>"")),l=a.map(d=>ce(g,d,{most:1})).filter(({count:d})=>d>0);return l.length?{...s,words:l.length,count:l.reduce((d,{count:t})=>d+t,0),hit:l[0].hits[0].text}:null}))).filter(Boolean).sort((s,g)=>g.words-s.words||g.count-s.count||g.edited-s.edited)}var q=i=>[...i.documents.values()].filter(n=>typeof n.url=="string"),F=i=>`${i} web link${i===1?"":"s"}`;async function ge(i,n){if(i.length>1)throw new M("--tree takes one document at most (its slug, link or address).");let o=await S(),a=new Map(n.map(e=>[e.slug,e])),r=new Map((o.extensions??[]).map(e=>[e.id,e])),u=o.columns.filter(e=>(!e.extension||r.has(e.extension))&&!e.hidden&&!e.away),s=u.length>1?u:null,g=o.children[""]??[],l=null;if(i.length===1){let e=await H(i[0],"--tree",o);if(e.refused){for(let h of await j({reading:!0}))console.log(h);console.error(e.refused),process.exit(1)}l=e.slug,g=[l]}for(let e of await j({reading:!0}))console.log(e);let d=e=>console.log(`${e.title}\u680F\uFF08\u6269\u5C55 ${e.id}\uFF1A${e.error?`\u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.error.message}`:`${e.count} \u4E2A\u6761\u76EE`}\uFF1Bgallery extension check ${e.id} \u6253\u51FA\u5B83\u4EEC\uFF09`),t=()=>{for(let e of r.values())d(e)},p=u.filter(e=>!e.extension).flatMap(e=>J(o.children,U(e.id))),f=p.filter(e=>o.documents.get(e)?.url!==void 0).length,m=p.length-f;if(m+f===0){console.log('No documents yet: gallery new <slug> "<title>" makes one.'),l===null&&t();return}let w=f?`${k(m)} and ${F(f)}`:k(m);if(l===null)console.log(`${w}, as the sidebar shows them (one under another indented)${s?", column by column":""}:`);else{let e=J(o.children,l),h=e.some($=>o.documents.get($)?.url!==void 0)?`${e.length} ${e.length===1?"entry":"entries"}`:k(e.length);console.log(x(o,l)),console.log(e.length?`${v(o,l)} and the ${h} under it, as the sidebar shows them:`:`${v(o,l)}, with no document under it:`)}let c=(e,h)=>{let{title:$,description:y,icon:b,url:B,draft:N}=o.documents.get(e),A=a.get(e)?.edited,L=E(o,e),I=B!==void 0?[`\u7F51\u9875\u94FE\u63A5\uFF1A${B}`]:N?[N.missing?"\u522B\u5904\u7684\u5E95\u7A3F\uFF0C\u627E\u4E0D\u5230\u4E86":L?`\u300C${L}\u300D\u7684\u5E95\u7A3F\uFF1A${N.path}`:`\u522B\u5904\u7684\u5E95\u7A3F\uFF1A${N.path}`]:[...L?[`\u300C${L}\u300D\u7684\u6587\u6863`]:[],...y?[`\u8BF4\u660E\uFF1A${y}`]:[],...A?[`\u4E0A\u6B21\u7F16\u8F91\uFF1A${P(A)}`]:[]];console.log(`${" ".repeat(h)}${e} ${ee(b)==="emoji"?`${b} `:""}${$}${I.length?` \uFF08${I.join("\uFF1B")}\uFF09`:""}`);for(let Z of o.children[e]??[])c(Z,h+1)};if(l!==null||!s){for(let e of g)c(e,0);l===null&&t();return}for(let e of s){if(e.extension){d(r.get(e.extension)),r.delete(e.extension);continue}let h=o.children[U(e.id)]??[];console.log(`${K(e)}\u680F${h.length?"":"\uFF08\u7A7A\uFF09"}`);for(let $ of h)c($,1)}t()}async function fe(i){let n=_.resolve(G),o=(t,p)=>Y(t)===Y(p),a=[n,...re().workspaces.map(({root:t})=>t).filter(t=>!o(t,n))],r=a.filter(W),u=a.filter(t=>!W(t)),s=(await Promise.all(r.map(async t=>(await X(t)).map(p=>({...p,root:t}))))).flat(),g=i.join(" ").trim(),l=V(s,g),d=`${r.length} workspace${r.length===1?"":"s"}`;if(console.log(`Searched ${d} of this machine (gallery workspaces lists them; the current one: ${n}).`),s.length===0)console.log(`No documents in ${r.length===1?"it":"any of them"} yet.`);else if(l.length===0)console.log(`No document's title, description or slug in the ${d} holds ${g.split(/\s+/).map(t=>`"${t}"`).join(" or ")}: gallery list --all lists all ${s.length}.`);else{console.log(g?`${l.length} of ${k(s.length)}, the best match first:`:`${k(s.length)}, the one edited last first:`);let t=new Map,p=f=>(t.has(f)||t.set(f,Promise.all([Q(f),S(f)]).then(([{links:m},w])=>({links:m,tree:w}))),t.get(f));for(let{root:f,slug:m,title:w,description:c,edited:e,file:h}of l){let{links:$,tree:y}=await p(f);console.log(`\u5DE5\u4F5C\u533A\uFF1A${f}`),console.log(`${m} ${w}`),c&&console.log(` \u8BF4\u660E\uFF1A${c}`),C(y.children,m)&&console.log(` ${x(y,m)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:m},$)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P(e)}`),console.log(` ${D(h)}`)}console.log('One in another workspace is worked on there: pass its \u5DE5\u4F5C\u533A as --workspace to every command (gallery open <slug> --workspace "<\u5DE5\u4F5C\u533A>" gives its address).')}u.length&&console.log(`Not searched, no longer there (gallery workspaces --forget <path> forgets one, nothing on disk changed): ${u.join(", ")}`)}async function Me(i){let{positional:n,options:o}=R({options:["--tree","--all"],argv:i});if(o.has("--all")){if(o.has("--tree"))throw new M("--all and --tree go apart: --tree is the current workspace's tree.");return fe(n)}let a=await X();if(o.has("--tree"))return ge(n,a);let r=n.join(" ").trim(),{links:u}=await Q(),s=n.length===1?te(n[0],u):null,g=s&&s.slug!==n[0],l=g?a.filter(({slug:c})=>c===s.slug):V(a,r),d=[...l,...r&&!g?await de(a,l,r):[]],t=await S(),p=r.toLowerCase().split(/\s+/).filter(Boolean),f=g?[]:q(t).filter(({slug:c,title:e,url:h})=>!p.length||p.some($=>`${e} ${h} ${c}`.toLowerCase().includes($))),m=n.length===1&&d.length===0&&f.length===0?await T(n[0]):null;for(let c of await j({reading:!0}))console.log(c);let w=()=>{if(!f.length)return;let c=q(t).length;console.log(r?`${f.length} of ${F(c)} in the sidebar:`:`${F(c)} in the sidebar:`);for(let{slug:e,title:h,url:$}of f)console.log(`${e} ${h}`),console.log(` \u7F51\u9875\u94FE\u63A5\uFF1A${$}`),C(t.children,e)&&console.log(` ${x(t,e)}`)};if(m)console.log(m);else if(a.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.'),w();else if(d.length===0&&f.length===0)console.log(`No document's title, description, slug or text holds ${r.split(/\s+/).map(c=>`"${c}"`).join(" or ")}: gallery list lists all ${a.length}.`);else if(d.length===0)w();else{console.log(r?`${d.length} of ${k(a.length)}, the best match first:`:`${k(a.length)}, the one edited last first:`);for(let{slug:c,title:e,description:h,edited:$,file:y,hit:b}of d)console.log(`${c} ${e}`),h&&console.log(` \u8BF4\u660E\uFF1A${h}`),b&&console.log(` \u6B63\u6587\uFF1A${b}`),C(t.children,c)&&console.log(` ${x(t,c)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:c},u)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P($)}`),console.log(` ${D(y)}`);w()}}export{X as a,P as b,Me as c};
@@ -0,0 +1,5 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as _}from"./chunk-W7665ZEC.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-7JDX4E65.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-3MBRL2PM.mjs";import{M as Ae}from"./chunk-HPOI4ZX7.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-EAIFITAV.mjs";import{d as Ce,g as je}from"./chunk-EP25HDAJ.mjs";import"./chunk-AR5D57ZD.mjs";import"./chunk-67N2QJYT.mjs";import{i as ie}from"./chunk-5XA2ZBAE.mjs";import{a as W}from"./chunk-JEUK3ZO7.mjs";import"./chunk-JLTZF4LA.mjs";import{a as re,b as le,e as de,f as K,g as ce}from"./chunk-PUOQ65NC.mjs";import"./chunk-7OG26PGF.mjs";import"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-QE5RG76S.mjs";import{a as H,b as j,c as P,d as D,f as oe}from"./chunk-UYVCQK3H.mjs";import{a as te,e as B,f as ae}from"./chunk-J5PUIV3Y.mjs";import{b as se}from"./chunk-4OZWXZE5.mjs";import"./chunk-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import{j as ne}from"./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{f as Z,j as ee}from"./chunk-HDWTZ763.mjs";import{b as X,e as _e}from"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";_e();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import O from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as He,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as M,hasClass as q,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],De=["light","dark"],Ze=900,et=3e4,tt=new Set(["iframe","frame","object","embed"]),at=/^\d+$/,ot={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function st(e,{catalog:g,folder:o,slug:h}){let i=[],s=d=>d?.sourceCodeLocation?.startLine??1,n=(d,a)=>i.push({line:typeof d=="number"?d:s(d),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),c=[],f=[];Re(t,d=>{d.tagName&&(d.tagName==="main"&&q(d,"gallery-page")&&c.push(d),q(d,"gallery-board")&&f.push(d),q(d,"gallery-card")&&!q(d.parentNode,"gallery-board")&&n(d,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`))},{inTemplates:!1}),c.length===0&&(f.length>0||j(e).cards.length>0)&&n(1,`no <main class="gallery-page">: a page's boards stand in one (it is how a block knows it is on a page: context.place "page", and how the page follows the theme)`);let y=new Map;for(let d of f){let a=d.parentNode;for(;a&&!(a.tagName==="main"&&q(a,"gallery-page"));)a=a.parentNode;c.length&&!a&&n(d,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=M(d,"data-board-id");r===void 0||r===""?n(d,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):H.test(r)?y.has(r)?n(d,`data-board-id="${r}" again (line ${y.get(r)} has it): each board's id is its own`):y.set(r,s(d)):n(d,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let S=new Map,N=new Map;for(let d of j(e).cards){let{node:a}=d,r=M(a,"data-card-id"),k=r&&H.test(r)?`card ${r}`:"this card";r===void 0||r===""?n(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):H.test(r)?S.has(r)?n(a,`data-card-id="${r}" again (line ${S.get(r)} has it): each card's id is its own, and the page's writes go by it`):S.set(r,s(a)):n(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?n(a,`${k} holds no instance of a custom block (an element with ${He}): a card is one block's instance, gallery/static's for what only shows`):u>1?n(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):d.instance&&d.instance.parentNode!==a&&n(d.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let b={};for(let x of["x","y","w","h"]){let A=M(a,`data-${x}`),[L,E]=ot[x];A===void 0?n(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):at.test(A.trim())?Number(A)<L||Number(A)>E?n(a,`${k}'s data-${x}="${A}": ${x} is ${E===1/0?`${L} or more`:`${L} to ${E}`}${x==="w"?" (a row is 12 cells)":""}`):b[x]=Number(A):n(a,`${k}'s data-${x}="${A}" is no whole number`)}b.x!==void 0&&b.w!==void 0&&b.x+b.w>12?n(a,`${k} reaches past the row's end: data-x ${b.x} and data-w ${b.w} make ${b.x+b.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(b).length===4&&N.set(d.board,[...N.get(d.board)??[],{id:r??null,...b,line:s(a)}]),d.block&&nt(d.block,g,x=>n(d.instance,`${k}'s block ${d.block}: ${x}`))}for(let d of N.values())for(let a=0;a<d.length;a++)for(let r=a+1;r<d.length;r++){let[k,u]=[d[a],d[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&n(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return i.push(...it(e,{folder:o,slug:h})),i.sort((d,a)=>d.line-a.line)}function nt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let i=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):i?o(`it does not load (${ee("en",i.problem)}): gallery block check ${e} says why`):ae(e)&&B(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${B(e).pack===te?B(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function it(e,{folder:g,slug:o}){let h=[],i=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let n=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",c=Me(n)??(n.startsWith(i)?Me(n.slice(i.length-7)):null),f=`"${n.length>60?`${n.slice(0,60)}\u2026`:n}"`,y=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(c!==null){Qe(c)?tt.has(s.node.tagName)&&!Te(c)?h.push({line:s.line,what:`${y}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture, stylesheet or script for saving only: write what it shows in the page itself, frame a site by its https address, or offer the file with a link, <a href="${c}" download>`}):Ue(O.join(g,c))||h.push({line:s.line,what:`${y}: ${c} is not in the page's folder (${W(O.join(g,"assets"))}): put the file there${Te(c)?"":", or link to it"}`}):h.push({line:s.line,what:`${y} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!n||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(n)||h.push({line:s.line,what:`${y} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function rt(e,g){let o=P(e).text,h=[];for(let i of j(o).cards){let s=i.block?g.packages.get(i.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let n=G(D(o,i),_,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=n?.text.trim()?JSON.parse(n.text):{}}catch{continue}let c=je(s,t);c.length&&h.push({id:i.id,block:i.block,line:i.node.sourceCodeLocation?.startLine??1,empty:c})}return h}var lt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:i,zh:s})=>`${h} (${s&&s!==i?`${i}, ${s}`:i})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,dt=(e,g=!1)=>{let o=h=>M(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${M(e.node,"data-x")},${M(e.node,"data-y")}`,Pe=e=>`${M(e.node,"data-w")},${M(e.node,"data-h")}`;function ct(e,g,o){let[h,i]=[P(e).text,P(g).text],[s,n]=[j(h).cards,j(i).cards],t=new Set([...s,...n].map(a=>a.board)).size>1,c=a=>dt(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)n.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:c(a)});for(let a of n)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:c(a)});for(let a of n){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:c(r),now:c(a)}),u&&f.resized.push({id:a.id,block:a.block,was:c(r),now:c(a)});let[b,x]=[D(h,r),D(i,a)];if(b===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,L=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[E,l]=L?[G(b,_,L),G(x,_,L)]:[null,null];if(!E||!l){f.markup.push({id:a.id,block:A?a.block:null});continue}let v=E.parts.flatMap(({name:$,text:m},I)=>m===l.parts[I].text?[]:[{name:$,...Y(m,l.parts[I].text),runs:ke(m,l.parts[I].text)}]);v.length&&f.data.push({id:a.id,block:a.block,parts:v}),E.outside!==l.outside&&f.markup.push({id:a.id,block:a.block})}let y=(a,r)=>{let k="",u=0;for(let b of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,b.start),u=b.end;return k+a.slice(u)},[S,N]=[y(h,s),y(i,n)],d=a=>a.replace(/\s+/g," ");return d(S)!==d(N)&&(f.page=Y(S.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",We="(put there by Gallery)";function ht(e,g){let o=n=>{let t=new Map;for(let c of g)if(c.by===n)for(let[f,y]of Object.entries(c.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(y)?y:[]]));return t},h=o("page"),i=o("gallery"),s=n=>t=>{let c=!!h.get(t.id)?.has(n);return{...t,user:c,...!c&&i.get(t.id)?.has(n)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function pt(e,g){let o=({id:t,block:c})=>`${t}${c?` (${c})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${We}`:"",i=[];for(let t of e.added)i.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)i.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)i.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(c=>c.id===t.id)||i.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)i.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Le(t.parts).map(c=>` ${c}`));for(let t of e.markup)i.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&i.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),i.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.user)),n=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.gallery));return[`Changes since ${g}:`,...i,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...n?[` Each change marked ${We} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function ut(e,g){let{qa:o,state:h}=U(e),i=O.join(o,g,"checked.html"),s=await R.readFile(i,"utf8").catch(()=>null);if(s!==null){let{mtime:y}=await R.stat(i);return{text:s,since:`the last check that found nothing (${qe(y)}, local time, ${W(i)})`,at:y.getTime()}}let n=O.join(h,"pages",g),t=(await R.readdir(n).catch(()=>[])).filter(y=>/^\d{15}-\d{4}\.html$/.test(y)).sort();if(t.length===0)return null;let c=O.join(n,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(c,"utf8"),since:`the page as it was before its last write (${qe(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var qe=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function ft(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let c=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),y=[...t.children].find(S=>S.matches(e));return{id:t.getAttribute("data-card-id"),block:y?.getAttribute(g)??null,out:f.width>0&&(f.left<c.left-1||f.right>c.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!y?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(S=>S.complete&&S.naturalWidth===0).map(o)}}),i=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,n=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:c,at:f})=>({kind:t,block:c,waited:Date.now()-f}));return{cards:h,broken:i,stuck:n,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function wt(e,{address:g,out:o,readers:h=new Set,wait:i=ge,limits:s={}}){let{loading:n=he,ready:t=et,answer:c=pe,closing:f=de,looking:y=ue}=s,S=new Map,N=new Map,d=[],a=!1,r=(l,v,$,m,I=S)=>{if(a)return;let w=I.get(l)??{card:v,what:$,looks:[]};w.looks.push(m),I.set(l,w)},k="a browser context opened",u=(l,v,$=c)=>(k=v,ye(l,v,$)),b=Q.flatMap(l=>De.map(v=>({width:l,theme:v,view:`${l} ${v}`}))),x=null,A=async({width:l,theme:v,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
3
+ `)[0]}`,null,`the console says ${p.text().split(`
4
+ `)[0]}`,$)}),m.on("response",p=>{let C=new URL(p.url());p.status()>=400&&C.origin===new URL(g).origin&&C.pathname!=="/favicon.ico"&&r(`request ${C.pathname}`,null,`${C.pathname} answered ${p.status()}`,$)}),await u(be(m,{add:p=>r(`dialog ${p}`,null,`it opened a dialog (${p}), which stops a reader's page until it is answered`,$)}),"the tab was set to refuse dialogs"),await u(me(m),"the tab was set to watch the page's reads of the workspace"),await u(m.setViewport({width:l,height:Ze}),`the window went to ${l}px`),await u(m.emulateMediaFeatures([{name:"prefers-color-scheme",value:v}]),`the ${v} theme came`),await u(m.goto(g,{waitUntil:"load",timeout:0}),"the page opened",n),await u(m.waitForSelector("html[data-doc-ready][data-doc-drawn]",{timeout:0}),"the page was drawn (its html got data-doc-drawn)",t),await u(m.evaluate(()=>document.fonts?.ready.then(()=>!0)),"the page's fonts loaded");let I=await u(m.$("main"),"the page's main was found")??await u(m.$("body"),"the page's body was found");await u(I.evaluate(Oe,{still:fe,step:we,wait:i}),"the page held still");let w=await u(m.evaluate(ft,Ye,He),"the page was looked at");for(let{kind:p,block:C,waited:Ge}of w.stuck){let V=w.cards.filter(F=>C?F.block===C:h.has(F.block)),J=F=>`the workspace had not answered ${F} read of "${p}" ${Math.round(Ge/1e3)} s after it asked, so its picture shows it before it drew what it reads, which the picture then does not tell (open the page in Gallery to see it)`;if(V.length)for(let F of V)r(`unanswered ${F.id} ${p}`,F.id,J("its"),$,N);else r(`unanswered ${p}`,null,J("a card's"),$,N)}w.wide&&r("wide",null,`the page is ${w.wide}px wide in a window ${l}px wide: something of its own reaches past the window (a width of its own, a long word), and a reader scrolls it sideways`,$);for(let p of w.broken)r(`broken ${p}`,null,`a picture that does not load: ${p}`,$);for(let p of w.cards){p.fallback&&r(`fallback ${p.id}`,p.id,`its block failed: the card shows what its instance holds, read-only${p.error?` (${p.error.slice(0,200)})`:""}`,$),p.out&&r(`out ${p.id}`,p.id,"it is drawn out of its board",$),p.tall&&r(`tall ${p.id}`,p.id,`what it holds does not fit it: ${p.tall.needs}px high in a card that shows ${p.tall.has}px, the rest scrolling inside the card (give the card more cells, data-h, or a size its block lists; a block whose content grows says card.fit "content")`,$),p.wide&&r(`wide ${p.id}`,p.id,`what it holds is wider than the card: ${p.wide.needs}px in a card ${p.wide.has}px wide`,$);for(let C of p.broken)r(`broken ${p.id} ${C}`,p.id,`a picture that does not load: ${C}`,$)}let T=O.join(o,`${l}-${v}.png`);await u(m.screenshot({path:T,fullPage:!0}),"the page was pictured"),a||d.push(T)}finally{await K(m.close(),f)}},L=l=>({problems:[...S.values()],notes:[...N.values()],pictures:d,unverified:null,stuck:!1,...l}),E=null;try{x=await u(e.createBrowserContext(),"a browser context opened");for(let l of b)E=l,await gt(A(l),y,()=>k);return L({})}catch(l){return await Se(e)?L({unverified:`the browser went while it looked (${z(l)})`}):l.stuck?(r("stopped",null,mt(l,b.indexOf(E??b[0])<b.length-1),(E??b[0]).view),L({stuck:!0})):L({unverified:`the look stopped: ${z(l)}`})}finally{a=!0,await K(x?.close(),f)}}function gt(e,g,o){let h=0,i=new Promise((s,n)=>{h=setTimeout(()=>n(Object.assign(new Error(o()),{stuck:!0,doing:o(),limit:g,whole:!0})),g)});return Promise.race([e,i]).finally(()=>clearTimeout(h))}function mt(e,g){return`${e.whole?`the look was not done in ${xe(e.limit)}, waiting until ${e.doing}`:ve(e)}; the look stopped here and the browser was closed${g?", so the looks after it were not made":""}. A script of the page that never ends does this, and so may a browser that stalled: run the check once more, and if it stops at the same place again, the page holds it up`}function Be(e){let g=[...new Set(e.map(i=>i.split(" ")[0]))],o=[...new Set(e.map(i=>i.split(" ")[1]))],h=i=>i.length<2?i.join(""):`${i.slice(0,-1).join(", ")} and ${i.at(-1)}`;return`at ${h(g)}px${o.length===De.length?"":`, ${h(o)}`}`}async function Ht(e,g){if(g.length!==1)throw new se("gallery page check takes one page's slug.");let[o]=g,h=Xe(o,e);Je(o,e)||(console.error(await Ce(o,e)),process.exit(1));let i=new Date,s=await R.readFile(h.html,"utf8"),n=O.basename(h.html),t=Z(e),{boards:c,cards:f}=j(s);console.log(`${o}: ${W(h.html)}, ${c.length} board${c.length===1?"":"s"} and ${f.length} card${f.length===1?"":"s"}`);let y=[],S=st(s,{catalog:t,folder:h.folder,slug:o});for(let{line:l,what:v}of S)y.push(` FAIL ${n}:${l}: ${v}`);console.log(S.length?`Structure: ${S.length} problem${S.length===1?"":"s"}`:"Structure: nothing wrong (the page's own HTML, scripts and frames its own; every board's and card's id once, one instance a card, the cells on the board and none shared, every block one a page runs, every file of assets/ there)");for(let l of y)console.log(l);for(let l of j(P(s).text).cards)console.log(` ${l.id} ${l.block??"(no instance)"} x ${l.x}, y ${l.y}, ${l.w} \xD7 ${l.h}${c.length>1?` on ${l.board}`:""} ${n}:${l.node.sourceCodeLocation?.startLine}`);let N=rt(s,t);for(let l of N)console.log(` note ${n}:${l.line}: ${lt(l)}`);let d=await ut(e,o),a=d?await oe(U(e).state,o,d.at):[];console.log((d?pt(ht(ct(d.text,s,t),a),d.since):["No earlier version to tell changes against: the next check that finds nothing keeps this one, and says what changed since."]).join(`
5
+ `));let r=new Map(j(P(s).text).cards.map(l=>[l.id,l.node.sourceCodeLocation?.startLine??1])),k=(l,v=null,$=0)=>{if(l)return{line:`FAIL ${o}: ${l} problem${l===1?"":"s"}`,code:1};if(v)return{line:`UNVERIFIED ${o}: ${v}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:I,empty:w})=>`${I} (${w.map(({key:T})=>T).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),b=async(l,v,$=0)=>{let{line:m,code:I}=k(l,v,$);if(console.log(m),I===0){let w=O.join(U(e).qa,o,"checked.html");await R.mkdir(O.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,i,i)}process.exitCode=I};if(!u.ok)return b(S.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return b(S.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Ie(e);let A=await Ee(e,{directory:h.folder,files:h,text:s}),L=O.join(U(e).qa,o,"check"),E=null;try{let{pageAloneOf:l}=await import("./chunk-UJQJKNGK.mjs"),v=l(u.port,A.slug);console.log(`Looked at: ${v} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${n}), at ${Q.join(", ")}px, light and dark`);try{E=await ce({executablePath:x,args:le()})}catch(w){return b(S.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(L,{recursive:!0,force:!0}),await R.mkdir(L,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await wt(E.browser,{address:v,out:L,readers:$});m.stuck&&(await E.close(),E=null);for(let{card:w,what:T,looks:p}of m.problems)console.log(` FAIL ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${T} (${Be(p)})`);let I=new Map(j(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:T,looks:p}of m.notes)console.log(` note ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}${I.get(w)?` (${I.get(w)})`:""}: `:""}${T} (${Be(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${W(L)}: ${m.pictures.map(w=>O.basename(w)).join(", ")}`),console.log(Ae([{folder:O.dirname(L),files:m.pictures}]))),b(S.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await E?.close(),await Ne(e,A.slug)}}export{We as GALLERYS_MARK,Q as LOOK_WIDTHS,De as THEMES,ze as USERS_MARK,ut as baselineOf,pt as changesSaid,rt as emptyRequired,lt as emptyRequiredSaid,wt as look,ht as markedTheUsers,ct as pageChanges,Ht as pageCheckCommand,st as structureProblems};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a}from"./chunk-JEUK3ZO7.mjs";import"./chunk-ITOH5EGO.mjs";import{f as D}from"./chunk-ZQS6H473.mjs";import{b as d,f as J,i as k}from"./chunk-4OZWXZE5.mjs";import{c as F}from"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import{a as A}from"./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{existsSync as E}from"node:fs";import R from"node:fs/promises";import m from"node:path";import{iconKind as q}from"../browser/shared/emoji/icon-value.mjs";import{writeAtomic as z}from"../browser/shared/files.mjs";import{reportsDirectory as C}from"../browser/shared/paths.mjs";import{roleOf as M}from"../browser/shared/reports.mjs";import{documentDirectory as P,documentFiles as T,pageSlug as U}from"../browser/shared/workspace.mjs";var K=o=>o.replace(/\s+/g," ").trim(),_=o=>o.replace(/^[a-z]:\/(?:[^/]+\/)*?(?=icons\/(?:tabler\/)?[^/]+$)/i,"/"),h=o=>o===null?"none":JSON.stringify(o);async function ie(o){let{positional:u,values:c}=J({values:["--title","--icon","--description"],argv:o});if(u.length!==1)throw new d("Name one document, then what to set: --title, --icon, --description.");if(!["--title","--icon","--description"].some(e=>c.has(e)))throw new d('Say what to set: --title "<title>", --icon <emoji|none|\u2026>, --description "<text>".');let n=c.has("--title")?K(c.get("--title")):void 0,p=c.has("--description")?K(c.get("--description")):void 0;if(n==="")throw new d("--title takes the words of the title: a document's title is never empty.");if(p==="")throw new d("--description takes words: a document's description is never empty.");let t;if(c.has("--icon")){let e=_(c.get("--icon").trim()),f=e==="none"?"none":q(e);if(!f||/["<>&]/.test(e))throw new d(`Not a page icon: ${e} (an emoji, none, an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg, or a picture of the document's assets/).`);if(f==="glyph"&&!F(e))throw new d(`No such icon of the \u56FE\u6807 tab: ${e}.`);t=f==="none"?null:e}let{slug:w}=await k(u[0]),$=P(w,C);(w===await U(C)||await M($)==="instructions")&&(console.error(`${u[0]} is the \u5199\u4F5C\u504F\u597D page: only the user changes it.`),process.exit(1));let{html:r,json:s}=T($);E(r)||(console.error(`No document "${u[0]}": ${a(r)} does not exist (gallery list lists those there are).`),process.exit(1)),t&&q(t)==="image"&&!E(m.join($,...t.split("/")))&&(console.error(`No picture ${t} in ${a($)}: put it in its assets/ first.`),process.exit(1));let i;try{if(i=JSON.parse(await R.readFile(s,"utf8")),!i||typeof i!="object"||Array.isArray(i))throw new Error("not an object")}catch(e){console.error(`${a(s)} does not read (${e.code??e.message}): mend it first.`),process.exit(1)}let b=null,N=!1;for(let e=1;n!==void 0||t!==void 0;e++){let f=await R.readFile(r,"utf8"),v=A(f),y=D(v,{title:n,icon:t});if(y.missing&&(console.error(`${a(r)} has no title to ${n!==void 0?"set":"put the icon before"}: write it as an h1.doc-title in the page's header (writing-html.md, "The page").`),process.exit(1)),b=y.before,y.text===v)break;if(await z(r,y.text,{expect:f})){N=!0;break}e===3&&(console.error(`${a(r)} kept changing while it was being written (the page saving, or an Agent writing it?): nothing written. Run gallery set again.`),process.exit(1))}let l={...i};n!==void 0&&(l.title=n),p!==void 0&&(l.description=p),t===null?delete l.icon:t!==void 0&&(l.icon=t);let x=JSON.stringify(l)!==JSON.stringify(i);x&&await z(s,`${JSON.stringify(l,null,2)}
3
+ `);let S=m.basename(r),g=[];n!==void 0&&g.push(` title: ${h(b.title)} \u2192 ${h(n)} (${S}'s h1 and <title>, ${m.basename(s)})`),t!==void 0&&g.push(` icon: ${h(b.icon)} \u2192 ${h(t)} (${S}'s header, ${m.basename(s)})`),p!==void 0&&g.push(` description: ${h(typeof i.description=="string"?i.description:null)} \u2192 ${h(p)} (${m.basename(s)})`);let j=[...N?[a(r)]:[],...x?[a(s)]:[]];if(j.length===0){console.log(`Nothing to change: ${w} has ${g.length===1?"that already":"those already"}.`);return}console.log(`Set ${w}:`);for(let e of g)console.log(e);let O=j.length===1;console.log(`Re-read ${j.join(", ")} before editing ${O?"it":"them"}: gallery set wrote ${O?"it":"them"} (${[...N?[`${S}: its header`]:[],...x?[`${m.basename(s)}: ${["title","icon","description"].filter(e=>JSON.stringify(l[e])!==JSON.stringify(i[e])).join(", ")}`]:[]].join("; ")}).`)}export{ie 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{c as O,d as P,e as b,l as C}from"./chunk-5XA2ZBAE.mjs";import{a as q}from"./chunk-JA7G53PC.mjs";import{a as u,f as S,g as w,i as E,j as I,k as H}from"./chunk-NAMN3RAF.mjs";import{a as h,b as R}from"./chunk-JEUK3ZO7.mjs";import{b as D,f as L,g as T}from"./chunk-4OZWXZE5.mjs";import{b as N}from"./chunk-PAREWQGB.mjs";import{existsSync as g}from"node:fs";import i from"node:path";import{reportsDirectory as c}from"../browser/shared/paths.mjs";import{idHolder as z,isDocSlug as B,keptName as G,layoutOf as A,listTrash as J}from"../browser/shared/workspace.mjs";import{parentIn as K}from"../browser/shared/outline.mjs";import{joinDefaultTree as Q,joinedLine as V}from"../browser/shared/drafts.mjs";var W="\u65B0\u6587\u6863";async function F(t,n=c){if(G(t))return`"${t}" is a name the workspace keeps for itself: choose another slug.`;if(g(i.join(A(n).preferencesPage,t)))return`"${t}" is the \u5199\u4F5C\u504F\u597D page's slug: choose another slug.`;if(g(i.join(A(n).customPages,t)))return`"${t}" is a custom page's slug (documents and custom pages share one set of names: gallery page list lists them): choose another slug.`;if(g(i.join(n,t)))return`Document already exists: ${h(i.join(n,t))}`;if((await J(n)).some(r=>r.slug===t))return`"${t}" is the slug of something in the trash: choose another slug.`;if(B(t)){let r=await z(t,n);if(r)return`"${t}" would have the page id (${t.slice(4)}) of "${r}" in this workspace, and two documents may not share an address: choose another slug.`}return null}async function fe(t){let{positional:n,options:r,values:U}=L({options:["--no-preview","--no-browser","--first"],values:["--under","--after"],argv:t}),[e,y,$=W]=n;if(n.length<2||n.length>3||!e||!y?.trim()||!$.trim())throw new D("Name the slug and the title (then a description, if you choose one), each quoted when it has spaces.");T(e);let s=H(U,r,{top:!1}),x=await F(e);x&&(console.error(x),process.exit(1));let M=s.under!==void 0||s.after!==void 0||s.first,l=null;if(M){let o=await u(),a=async(X,_)=>{let p=await S(X,_,o);return p.refused&&(console.error(`${p.refused} Nothing made.`),process.exit(1)),p.slug},f=s.under!==void 0?await a(s.under,"--under"):void 0,d=s.after!==void 0?await a(s.after,"--after"):null;d!==null&&f!==void 0&&K(o.children,d)!==f&&(console.error(`${w(o,e,"level",{parent:f,after:d})} Nothing made.`),process.exit(1)),l={parent:f,after:d,first:s.first}}try{await N(e,y,$)}catch(o){if(o.code!=="EEXIST")throw o;console.error(await F(e)??`Document already exists: ${h(i.join(c,e))}`),process.exit(1)}if(await import("./chunk-SWUTTZCN.mjs").then(({noteNew:o})=>o(e)),console.log(`Created ${h(i.join(c,e,"doc.html"))} and doc.json`),l){let o=await E(e,l),a=await u();o.ok?console.log(`Placed it ${I(a,o)}.`):(console.log(`Not placed (${w(a,e,o.reason,{...l,message:o.message})}): it is at the top level, last; gallery move ${e} puts it where it goes.`),process.exitCode=1)}let v=V(await Q(c,e));v&&console.log(v);for(let o of await R())console.log(o);let j=q(c);j&&console.log(j);let m=await C(e,{skipped:b(r),command:`gallery new ${e}`});console.log(O(m,"replace the starter section with the document's skeleton (each section's heading) as soon as you can outline it, then write it a section at a time, as ordinary HTML, so that the user watches it grow (gallery check fails while the starter section remains).")),console.log(`Hand in: gallery export ${e}, then gallery qa ${e}`);let k=await P(m,r);k&&console.log(k);for(let o of m)console.log(o)}export{W as a,F as b,fe as c};
@@ -0,0 +1,6 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as Q}from"./chunk-YROX2O22.mjs";import{c as _,d as z,e as B,l as G}from"./chunk-5XA2ZBAE.mjs";import"./chunk-JA7G53PC.mjs";import"./chunk-YI43RG4P.mjs";import{i as q}from"./chunk-NAMN3RAF.mjs";import{a as b,b as J}from"./chunk-JEUK3ZO7.mjs";import{a as Z}from"./chunk-AHN3NFKJ.mjs";import{a as ee}from"./chunk-MTYYHM2G.mjs";import"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import{c as V,d as Y,e as M}from"./chunk-DAZL73VK.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import{b as W,h as X}from"./chunk-ZQS6H473.mjs";import"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import{b as T,f as C,g as H}from"./chunk-4OZWXZE5.mjs";import"./chunk-ZTHICSSF.mjs";import{k as U}from"./chunk-6N3PX4XX.mjs";import{b as K}from"./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 v from"node:fs/promises";import se from"node:os";import x from"node:path";import{IMPORT_EXT as re,kindOf as ie}from"../browser/shared/import-types.mjs";import{reportsDirectory as O}from"../browser/shared/paths.mjs";import{kebab as S}from"../browser/shared/web-links.mjs";import{documentDirectory as oe,documentFiles as E,newDocSlug as ae}from"../browser/shared/workspace.mjs";var ce=Object.values(re).flat().join(" "),j=(d,g)=>`${d} ${g}${d===1?"":"s"}`;function fe(d,g,p){let n=(f,r=g)=>(r.match(f)??[]).length,c=n(/<ol class="doc-flow"/g,p),$=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[c,"flow"],[$,"footnote"]].filter(([f])=>f>0).map(([f,r])=>j(f,r)),h=(d.raws?.length??0)-c-($?1:0);return h>0&&w.push(`${j(h,"HTML block")} kept as written`),w}async function Se(d){let{positional:g,options:p}=C({options:["--no-preview","--no-browser"],argv:d}),[n,c,$]=g;if(g.length<1||g.length>3||!n)throw new T("Name the file; then the slug and the title, if you choose them.");let w=ie(n);if(!w)throw new T(`Not a kind of file gallery import takes: ${n} (${ce}).`);c!==void 0&&H(c);let h=x.resolve(n);await v.stat(h).then(i=>i.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let f=c!==void 0?await Q(c):null;f&&(console.error(f),process.exit(1));let r=x.basename(h),F=await v.mkdtemp(x.join(se.tmpdir(),"gallery-import-")),L,y,R;try{let i,u=[];if(w==="markdown")i=[{...await Y(h,F),from:r,children:[]}];else try{({pages:i,skipped:u}=await V([{file:h,name:r}],F))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}i.length===0&&(console.error(`Nothing in ${r} could be read as a page${u.length?` (not taken: ${u.join(", ")})`:""}.`),process.exit(1)),$?.trim()&&(i[0]={...i[0],title:$.replace(/\s+/g," ").trim()});let I=new Map,te=ee({edits:{},reports:{},reportsDirectory:O});y=(await Z(i,{create:async(e,t,l,{lang:s})=>{let{directory:o}=await K(e,t,l,{blank:!0,lang:s});I.set(e,await v.readFile(E(o).html,"utf8"))},slugOf:(e,t)=>{if(t===0&&c!==void 0)return c;let l=S(e.title)||S(e.from?.replace(/\.[^.]+$/,"")??"")||S(r.replace(/\.[^.]+$/,""));return l?te.freeSlug(l):ae(O)},folderOf:e=>oe(e,O),fill:e=>M(e),place:(e,t)=>q(e,{parent:t})})).made;let P=[],A=(e,t)=>{P.push({page:e,depth:t});for(let l of e.children??[])A(l,t+1)};for(let e of i)A(e,0);let m=await Promise.all(P.map(async({page:e,depth:t},l)=>{let s=y[l],o=oe(s,O),a=E(o).html,k=await v.readFile(a,"utf8"),ne=(await M({source:I.get(s),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),le=X(W(k,{finish:U}).text);return{slug:s,depth:t,page:e,directory:o,htmlFile:a,made:fe(e,ne,k),readOnly:le}}));if(L={slug:y[0]},m.length===1){let[{page:e,directory:t,htmlFile:l,made:s,readOnly:o}]=m;if(console.log(`Created ${b(l)} and ${x.basename(E(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${s.length?s.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let a of e.notes)console.log(` ${a.line?`line ${a.line}: `:""}${a.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let a of o)console.log(` ${a}`)}}else{console.log(`Created ${j(m.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:l,depth:s,page:o,htmlFile:a,made:k}of m)console.log(`${" ".repeat(s+1)}${l} ${o.title} ${b(a)}`),console.log(`${" ".repeat(s+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=m.flatMap(({slug:l,page:s})=>(s.notes??[]).map(o=>` ${l}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
3
+ ${e.join(`
4
+ `)}`);let t=m.flatMap(({slug:l,readOnly:s})=>s.map(o=>` ${l}: ${o}`));t.length&&console.log(`Text the preview leaves read-only (${t.length}), by doc.html's lines as gallery check gives them:
5
+ ${t.join(`
6
+ `)}`)}u.length&&console.log(`Not taken from ${r} (${u.length}): ${u.join(", ")}`);for(let e of await J())console.log(e);R=`edit ${b(m[0].htmlFile)}${m.length>1?" (and the others)":""} into the document as \u5199\u4F5C\u504F\u597D asks.`}finally{await v.rm(F,{recursive:!0,force:!0})}let N=await G(L.slug,{skipped:B(p),command:`gallery import ${r}`});console.log(_(N,R)),console.log(`Hand in: gallery export ${y.join(" ")}, then gallery qa ${y.join(" ")}`);let D=await z(N,p);D&&console.log(D);for(let i of N)console.log(i)}export{Se as run};
@@ -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{d as a,e as b,f as c,g as d}from"./chunk-TYK6VNAB.mjs";import"./chunk-L3QKH4OK.mjs";import"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as commitEdits,c as revertedParts,d as revertedTexts,b as revertedUnits};
2
+ import{a,b,c}from"./chunk-YI43RG4P.mjs";import"./chunk-NAMN3RAF.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as documentsOf,c as run,b as when};