@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
@@ -1,26 +0,0 @@
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 J,n as Ft,p as Ut}from"./chunk-W4VKN3GF.mjs";import{b as z,c as H,e as ot}from"./chunk-A55HN5OK.mjs";import{createHash as Qe}from"node:crypto";import{BLOCK_LEVEL as q}from"../browser/shared/html-tree.mjs";var at=t=>Qe("sha256").update(t).digest("hex").slice(0,16),R=t=>t.nodeName==="#text"&&!t.value.trim();function Nt(t,e){for(let s of t.childNodes??[]){if(s.tagName===e)return s;let o=s.tagName&&Nt(s,e);if(o)return o}return null}import{ATTRIBUTES as Cn,BOX_CLASSES as Sn,COMPONENT_ATTRIBUTES as En,COMPONENT_CLASSES as In,GROUPING as wn,IDENTITY as F,TOGGLES as An,UNIT_KINDS as Bn}from"../browser/editor/components/registry.mjs";import{attr as w,hasClass as Bt}from"../browser/shared/html-tree.mjs";import{idsNamed as _n}from"../browser/shared/copy-ids.mjs";import{DIALOG as Mn,PAGE as jn,SECTION as Rn,SHEETS as X,TABLE as De}from"../browser/editor/components/kit.mjs";import{matchesNode as et,partOf as It}from"../browser/shared/components/index.mjs";import{escapeMarkup as rt}from"../browser/shared/escape.mjs";import{imageFile as ts}from"../browser/shared/media.mjs";import{emptyFigure as es}from"../browser/editor/components/media/write.mjs";var ss=t=>typeof t=="string"&&t.length<=2e3&&/^https?:\/\/[^\s"<>]+$/.test(t),zt=(t,e)=>typeof t=="string"&&t.length<=e&&!/[\u0000-\u001f]/.test(t),Ht=t=>t.href===""&&!t.title&&!t.description&&!t.icon&&!t.cover&&t.caption==="",Gt=t=>t==null||ts(t),Kt={bookmark:{check:(t,{validLeaf:e})=>Ht(t)||ss(t.href)&&zt(t.title,300)&&zt(t.description??"",600)&&Gt(t.icon)&&Gt(t.cover)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption)),write(t,e){if(Ht(t))return es("bookmark",e);let s=t.title.trim()||new URL(t.href).hostname,o=[`<span class="doc-bookmark-title">${rt(s)}</span>`,t.description?`<span class="doc-bookmark-description">${rt(t.description)}</span>`:"",`<span class="doc-bookmark-url">${t.icon?`<img class="doc-bookmark-icon" src="${t.icon}" alt="">`:""}<span class="doc-bookmark-href">${rt(t.href)}</span></span>`].join(""),a=t.cover?`<span class="doc-bookmark-cover"><img src="${t.cover}" alt=""></span>`:"",n=`<a class="doc-bookmark-card" href="${rt(t.href)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text">${o}</span>${a}</a>`;return e.block(`<figure class="doc-bookmark"${e.id}>`,[n,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{BLOCK_TYPES as ns,sizeValue as os}from"../browser/editor/components/registry.mjs";import{LINE_START as Vt,lineStart as as}from"../browser/shared/code-lines.mjs";import{hasClass as qt}from"../browser/shared/html-tree.mjs";import{CODE_HEIGHT as $t,FOLDED_LINES as Xt,validFolded as rs,validLanguage as is}from"../browser/editor/components/code/index.mjs";var cs=(t,e,s,o,a="",n="",r="",l="")=>`<div class="${t.className}"${s?` data-language="${s}"`:""}${l?` ${Vt}="${l}"`:""}${r?` ${Xt}="${r}"`:""}${o?` style="${$t}: ${o}"`:""}${a}><div class="doc-code-title">${n}</div><pre><code>${e}</code></pre></div>`,ls=(t,e)=>t==="data-language"||t===Xt||t===Vt||t==="style"&&new RegExp(`^\\s*${$t}\\s*:[^;]*;?\\s*$`).test(e??""),fs=t=>typeof t=="string"&&t.length<=200&&!/[<>\n]|&(?!(amp|lt|gt|quot|#39);)/.test(t),ds=t=>(t.language===void 0||is(t.language))&&(t.folded===void 0||rs(t.folded))&&(t.height===void 0||os("code",$t,t.height)===t.height)&&(t.title===void 0||fs(t.title))&&(t.lineStart===void 0||typeof t.lineStart=="string"&&String(as(t.lineStart))===t.lineStart);function us(t){let{node:e}=t;if(t.tag!=="div"||t.nested||!qt(e,ns.code.className))return!1;let s=(a,n)=>{let r=a.childNodes??[],l=r.filter(u=>u.tagName);return l.length===n.length&&l.every((u,d)=>u.tagName===n[d])&&r.every(u=>u.tagName||!(u.value??"").trim())?l:null},o=s(e,["div","pre"]);return!!o&&qt(o[0],"doc-code-title")&&!!s(o[1],["code"])}var Yt={code:{fields:["language","folded","height","title","lineStart"],check:ds,leaf:(t,e,s)=>cs(t,e.html,e.language,e.height,s,e.title,e.folded,e.lineStart),written:us,attribute:ls}};import{sizeValue as ms}from"../browser/editor/components/registry.mjs";import{MIN_COLUMNS as ps,RATIO as Zt}from"../browser/editor/components/columns/index.mjs";var Jt={columns:{check:t=>t.children.length>=ps&&t.children.every(e=>e.type==="column")},column:{check:t=>t.ratio===void 0||ms("column",Zt,t.ratio)===t.ratio,write(t,e){let s=t.ratio===void 0?"":` style="${Zt}: ${t.ratio}"`;return e.block(`<div class="doc-column"${s}${e.id}>`,e.children(e.inner),"</div>")}}};var Qt={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),a=t.classes?.length?` ${t.classes.join(" ")}`:"";return e.block(`<details class="doc-details${a}"${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 te={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 gs}from"../browser/shared/escape.mjs";import{embedFile as ee}from"../browser/shared/media.mjs";import{emptyFigure as hs}from"../browser/editor/components/media/write.mjs";import{FILE_SANDBOX as Ns,WEB_SANDBOX as $s}from"../browser/editor/components/embed/index.mjs";var bs=t=>typeof t=="string"&&t.length<=2e3&&/^https:\/\/[^\s"<>]+$/.test(t),se=t=>t.src===""&&t.height===void 0&&t.caption==="",ne={embed:{check:(t,{validLeaf:e})=>se(t)||(bs(t.src)||ee(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(se(t))return hs("embed",e);let s=ee(t.src),o=s?/\.pdf$/i.test(t.src)?"":` sandbox="${Ns}"`:` sandbox="${$s}" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen`,a=`<iframe class="doc-embed-frame" src="${gs(t.src)}"${o} loading="lazy"></iframe>`,n=t.height?` style="--doc-embed-height: ${t.height}"`:"";return e.block(`<figure class="doc-embed${s?" doc-embed--file":""}"${n}${e.id}>`,[a,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};import{escapeMarkup as oe}from"../browser/shared/escape.mjs";import{assetFile as Os}from"../browser/shared/media.mjs";import{emptyFigure as xs}from"../browser/editor/components/media/write.mjs";var ae=t=>t.href===""&&t.name===""&&t.size===void 0&&t.caption==="",ks=t=>typeof t=="string"&&t.trim()!==""&&t.length<=120&&!/[\u0000-\u001f<>:"/\\|?*]/.test(t),re={file:{check:(t,{validLeaf:e})=>ae(t)||Os(t.href)&&ks(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(ae(t))return xs("file",e);let s=t.size?`<span class="doc-file-size">${t.size}</span>`:"",o=`<a class="doc-file-link" href="${t.href}" download="${oe(t.name)}"><span class="doc-file-name">${oe(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 ie,FLOW_RATIO as ce}from"../browser/editor/components/flowchart/index.mjs";import{START as Ls,validDirection as le,validStart as ys}from"../browser/editor/components/list/index.mjs";import{sizeValue as vs,TOGGLES as Cs}from"../browser/editor/components/registry.mjs";var fe={flowchart:{check:t=>(t.start===void 0||ys(t.start))&&(t.direction===void 0||le(t.direction))&&t.children.length>0,write:(t,e)=>e.block(`<ol class="${Ts}"${t.start?` ${Ls}="${t.start}"`:""}${t.direction?` ${ie}="${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=>(Cs.step??[]).includes(e)))&&(t.ratio===void 0||vs("step",ce,t.ratio)===t.ratio)&&(t.direction===void 0||le(t.direction))&&t.children.length>0,write(t,e){let s=t.classes?.length?` class="${t.classes.join(" ")}"`:"",o=t.direction?` ${ie}="${t.direction}"`:"",a=t.ratio===void 0?"":` style="${ce}: ${t.ratio}"`;return e.block(`<li${s}${o}${a}${e.id}>`,e.children(e.inner),"</li>")}}};import{SPAN as Ss,SPAN_SIZE as de,imageFile as ue}from"../browser/shared/media.mjs";import{emptyFigure as Es}from"../browser/editor/components/media/write.mjs";var Is=/^\d{1,3}(\.\d{1,3})?( \d{1,3}(\.\d{1,3})?){3}$/,me=t=>t.src===""&&t.caption===""&&t.span===void 0&&t.original===void 0&&t.classes===void 0,ws=t=>typeof t=="number"&&Number.isFinite(t)&&t>=de.min&&t<=de.max,pe={image:{check:(t,{validLeaf:e})=>me(t)||ue(t.src)&&typeof t.caption=="string"&&(t.caption===""||e({tag:"figcaption"},t.caption))&&(t.span===void 0||ws(t.span))&&(t.original===void 0||ue(t.original)&&typeof t.crop=="string"&&Is.test(t.crop)),write(t,e){if(me(t))return Es("image",e);let s=["doc-image",...t.classes??[]].join(" "),o=t.span===void 0?"":` style="${Ss}: ${Math.round(t.span*1e3)/1e3}"`,a=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=""${a}>`,`<figcaption>${t.caption}</figcaption>`],"</figure>")}}};ot();import{heldByNode as As,instanceSlots as Bs,isInstance as Ot,isSlot as _s,ownSlots as Ms,partOf as xt}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as tt,DATA_MOST as js,NO_TEXT as Rs,PACKAGE_ID as ge,SCHEMA as he,SLOT as Ne,fitsDataScript as Ds,isDataScript as Ws,noDataPart as Ps,refusedInCopy as Fs,refusedInData as Us,schemaAhead as $e}from"../browser/shared/components/installed.mjs";import{attr as M,walk as be}from"../browser/shared/html-tree.mjs";var Q=(t,e)=>{for(let s=t.parentNode;s;s=s.parentNode)if(s===e)return!0;return!1},zs=t=>{let e=t.parentNode;for(;e&&!Ot(e);)e=e.parentNode;return e??null},kt=(t,e)=>zs(t)===e&&As(t)===e&&!_s(t);function bt(t,e){let o=Object.entries(e.get(M(t,tt))?.parts??{}).filter(([,{edit:a}])=>a==="data").map(([a,{at:n}])=>[a,xt(t,n).find(r=>r.sourceCodeLocation&&!Ot(r)&&kt(r,t))]).filter(([,a])=>a);return o.filter(([,a],n)=>!o.some(([,r],l)=>Q(a,r)||r===a&&l<n))}var Hs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","source","track","wbr"]),Gs="http://www.w3.org/1999/xhtml",Ks=t=>(t.content??t).childNodes;function Oe(t,e,s,o){let a=s;for(let n of Ks(t)){let r=n.sourceCodeLocation;if(r?.startOffset!==a)return!1;if(n.tagName){let{startTag:l,endTag:u}=r,d=Hs.has(n.tagName)||n.namespaceURI!==Gs&&e.startsWith("/>",r.endOffset-2);if(u?!Oe(n,e,l.endOffset,u.startOffset):!d)return!1}a=r.endOffset}return a===o}function qs(t,e,s){if(e.tagName==="script")return Ws(e.tagName,e.attrs)&&Ds(s);if(Ps(e.tagName))return!1;let{startTag:o,endTag:a}=e.sourceCodeLocation,n=t.slice(o.startOffset,o.endOffset),r=`${n}${s}${t.slice(a.startOffset,a.endOffset)}`,[l,...u]=H(e.parentNode,r,{sourceCodeLocationInfo:!0}).childNodes;if(u.length>0||l?.tagName!==e.tagName||l.sourceCodeLocation?.endOffset!==r.length||!l.sourceCodeLocation.endTag||!Oe(l,r,n.length,n.length+s.length))return!1;let d=!1;return be(l,m=>{d||=Us(m.tagName,m.attrs)}),!d}var Vs=(t,e)=>Object.values(e.get(M(t,tt))?.parts??{}).filter(({edit:s})=>s==="text"||s==="data").flatMap(({at:s})=>xt(t,s).filter(o=>kt(o,t))),xe={installed:{slots(t,e){let s=Vs(t,e);return Bs(t).filter(o=>!s.some(a=>Q(o,a)))},boxes(t,e){return this.slots(t,e).map(s=>({element:s,kind:"slot",key:M(s,Ne)}))},textParts(t,e){let s=e.get(M(t,tt));if($e(M(t,he),s?.schema))return[];let o=Object.values(s?.parts??{}).filter(({edit:r})=>r==="text"),a=bt(t,e).map(([,r])=>r),n=[...new Set(o.flatMap(({at:r})=>xt(t,r)))].filter(r=>r.sourceCodeLocation&&!Ot(r)&&!Rs.has(r.tagName)&&kt(r,t)).filter(r=>!a.some(l=>l===r||Q(r,l)||Q(l,r)));return n.filter(r=>!n.some(l=>Q(r,l))).map(r=>({kind:"installed",part:r}))},source({package:t,html:e,children:s,boxKeys:o},{packages:a,written:n}){if(typeof t!="string"||!ge.test(t))return null;let r=s!==void 0;if(r&&!(Array.isArray(s)&&Array.isArray(o)&&o.length===s.length))return null;let l=e===void 0?a.has(t)?Ut(a.get(t)):null:e,u=typeof l=="string"?Ft(l,t):null;if(!u)return null;let d=Ms(u.root),m=b=>!b.childNodes.every(S=>S.nodeName==="#text"&&!S.value.trim());if((e!==void 0||!r)&&d.some(m)||r&&!o.every(b=>d.some(S=>M(S,Ne)===b)))return null;if(e!==void 0){let b=!1;if(be({childNodes:[u.root]},S=>{b||=Fs(S.tagName,S.attrs)}),b)return null}let g=d.map(b=>b.sourceCodeLocation).sort((b,S)=>S.startOffset-b.startOffset).reduce((b,{startTag:S,endTag:y})=>b.slice(0,S.endOffset)+b.slice(y.startOffset),u.markup);return n(r?g:u.markup)},unwritten:({package:t,html:e},{packages:s})=>e===void 0&&ge.test(t)&&!s.has(t)?"no-package":"invalid",definition:(t,e)=>e.get(M(t,tt))?.definition,dataOf(t,e,s){let o=bt(e,s).filter(([,a])=>a.sourceCodeLocation.endTag);return o.length>0?Object.fromEntries(o.map(([a,n])=>[a,t.slice(n.sourceCodeLocation.startTag.endOffset,n.sourceCodeLocation.endTag.startOffset)])):null},rewrite(t,e,s,{packages:o}){let a=new Map(bt(e,o)),n=Object.keys(s),r=n.map(u=>s[u]);if($e(M(e,he),o.get(M(e,tt))?.schema)||n.length===0||!r.every(u=>typeof u=="string")||!n.every(u=>a.has(u))||r.reduce((u,d)=>u+Buffer.byteLength(d),0)>js||!n.every(u=>a.get(u).sourceCodeLocation.endTag&&qs(t,a.get(u),s[u])))return null;let l=t.includes(`\r
3
- `)?`\r
4
- `:`
5
- `;return n.map(u=>{let{startTag:d,endTag:m}=a.get(u).sourceCodeLocation;return{start:d.endOffset,end:m.startOffset,text:s[u].replace(/\r?\n/g,l)}})}}};ot();import{IDENTITY as Xs}from"../browser/editor/components/registry.mjs";import{SHEETS as it,TABLE as ke}from"../browser/editor/components/kit.mjs";import{escapeAttribute as ct,escapeText as Te}from"../browser/shared/escape.mjs";import{isInstance as Ys,matchesNode as Tt}from"../browser/shared/components/index.mjs";import{attr as D}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Zs,CHART_SOURCE as Le}from"../browser/shared/table-chart.mjs";import{freshPrefix as Js,referencedIds as Qs,rewrite as tn}from"../browser/shared/copy-ids.mjs";var ye=(t={})=>Object.entries(t).map(([e,s])=>s===""?` ${e}`:` ${e}="${ct(String(s))}"`).join(""),ft=(t,e)=>t[e-1]==="/"?e-1:e;function lt(t,e,s){let o=e;for(;o>0&&/\s/.test(t[o-1]);)o--;return{start:o,end:s}}function ya(t){let e=s=>s.nodeName==="#text"?s.value:(s.childNodes??[]).map(e).join("");return e(H(t)).replace(/\s+/g," ").trim()}function va(t,{from:e,to:s}){let a=ve(z(t,{sourceCodeLocationInfo:!0}))?.sourceCodeLocation;if(!a?.endTag||!e)return null;let n=t.slice(a.startTag.endOffset,a.endTag.startOffset),r=Te(e),l=n.indexOf(r);if(l<0||n.indexOf(r,l+1)>=0)return null;let u=a.startTag.endOffset+l;return{start:u,end:u+r.length,text:Te(s)}}function ve(t){for(let e of t.childNodes??[]){if(e.tagName==="title")return e;if(e.tagName==="body")continue;let s=e.tagName&&ve(e);if(s)return s}return null}function en(t){let e=[],s=0,o=null,a=0;for(let n=0;n<t.length;n++){let r=t[n];if(r==="&"){let l=/^&(#\d+|#x[\da-f]+|[a-z]\w*);/i.exec(t.slice(n));l&&(n+=l[0].length-1)}else o?r===o?o=null:r==="\\"&&n++:r==='"'||r==="'"?o=r:r==="("?s++:r===")"?s=Math.max(0,s-1):r===";"&&s===0&&(e.push(t.slice(a,n)),a=n+1)}return e.push(t.slice(a)),e.map(n=>n.trim()).filter(Boolean)}function vt(t,e){let s=en(t);for(let[o,a]of e){let n=s.findIndex(r=>r.slice(0,r.indexOf(":")).trim()===o);a===null?n>=0&&s.splice(n,1):n>=0?s[n]=`${o}: ${a}`:s.push(`${o}: ${a}`)}return s.join("; ")}var sn=new Set(["pre","textarea","script","style"]);function Ca(t){if(typeof t!="string"||!t.trim())return null;let s=H(t,{sourceCodeLocationInfo:!0}).childNodes.filter(u=>u.nodeName!=="#comment"&&!(u.nodeName==="#text"&&!u.value.trim())),[o,a]=s;if(s.length===2&&o.tagName==="button"&&Tt(o,it.tab)&&a.tagName&&a.sourceCodeLocation?.endTag&&D(o,it.tabKey)&&D(a,it.panelKey)===D(o,it.tabKey)){let u=o.sourceCodeLocation.endOffset;return{element:o,source:t.slice(0,u),panel:t.slice(u).replace(/^\s+/,""),kind:"tab"}}let n=s.at(-1),r=s.length===2?s[0]:null;if(!n?.tagName||!n.sourceCodeLocation?.startTag||s.length>2||r&&!(r.tagName&&Tt(r,ke.lead)&&Tt(n,ke.frame)))return null;let l=W(n);return{element:n,source:t,kind:l}}function nn(t){let e=[],s=o=>{for(let a of o.childNodes??[]){if(!a.tagName)continue;let n=D(a,"id");n&&e.push(n),s(a.tagName==="template"?a.content:a)}};return s(z(t)),e}var Sa=(t,e)=>`${Lt(t.slice(e.start,e.end),G(t,e.start),"")}
6
- ${Lt(t.slice(e.companion.start,e.companion.end),G(t,e.companion.start),"")}`;function Ea(t,e,{keys:s=null,taken:o=null}={}){let a=t.slice(e.start,e.end),n=[],r=H(a,{sourceCodeLocationInfo:!0}),l=[],u=y=>{for(let T of y.childNodes??[])T.tagName&&(l.push(T),u(T.tagName==="template"?T.content:T))};u(r);let d=Qs(l.flatMap(y=>y.attrs)),m=new Set(l.map(y=>D(y,"id")).filter(y=>y&&d.has(y))),g=new Map;if(m.size>0){let y=o??new Set(nn(t)),T=Js(y);for(let C of m)g.set(C,`${T}${C}`),y.add(`${T}${C}`)}let b=y=>{for(let T of y.childNodes??[])if(T.tagName){for(let C of[Xs,"id"]){let h=T.sourceCodeLocation?.attrs?.[C];h&&(C==="id"&&g.has(D(T,"id"))?n.push({start:h.startOffset,end:h.endOffset,text:`id="${ct(g.get(D(T,"id")))}"`}):n.push(lt(a,h.startOffset,h.endOffset)))}for(let{name:C,prefix:h,value:O}of g.size>0?T.attrs:[]){let p=h?`${h}:${C}`:C,i=tn(p,O,g),f=T.sourceCodeLocation?.attrs?.[p];i!==null&&f&&n.push({start:f.startOffset,end:f.endOffset,text:`${p}="${ct(i)}"`})}for(let C of[Zs,Le]){let h=T.sourceCodeLocation?.attrs?.[C],O=D(T,C);!h||!s||!Object.hasOwn(s,O)||(s[O]!==null?n.push({start:h.startOffset,end:h.endOffset,text:`${C}="${ct(s[O])}"`}):C===Le&&n.push(lt(a,h.startOffset,h.endOffset)))}b(T.tagName==="template"?T.content:T)}};b(r);let S=n.sort((y,T)=>T.start-y.start).reduce((y,{start:T,end:C,text:h=""})=>y.slice(0,T)+h+y.slice(C),a);return Lt(S,G(t,e.start),"")}function Lt(t,e,s){if(e===null||s===null||e===s||!t.includes(`
7
- `))return t;let o=[],a=l=>{for(let u of l.childNodes??[]){if(!u.tagName)continue;let d=u.sourceCodeLocation;(sn.has(u.tagName)||Ys(u))&&d?.startTag&&d.endTag?o.push([d.startTag.endOffset,d.endTag.startOffset]):a(u.tagName==="template"?u.content:u)}};a(H(t,{sourceCodeLocationInfo:!0}));let n="",r=0;for(let l of t.split(/(?<=\n)/)){let u=o.some(([m,g])=>r>m&&r<=g),d=l===`
8
- `||l===`\r
9
- `;n+=r>0&&!u&&!d&&l.startsWith(e)?s+l.slice(e.length):l,r+=l.length}return n}function G(t,e){let s=t.slice(t.lastIndexOf(`
10
- `,e-1)+1,e);return/^[ \t]*$/.test(s)?s:null}function on(t,e,s){let o=t.lastIndexOf(`
11
- `,e-1)+1,a=t.indexOf(`
12
- `,s),n=a<0?t.length:a+1;return/^[ \t]*$/.test(t.slice(o,e))&&/^[ \t]*\r?\n?$/.test(t.slice(s,n))?{start:o,end:n,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 a=on(t,e,s);if(a.start===e&&a.end===s)return a;let n=/^[ \t]*\r?\n$/,r=t.indexOf(`
13
- `,a.end),l=r>=0&&n.test(t.slice(a.end,r+1)),u=t.lastIndexOf(`
14
- `,a.start-2)+1,d=a.start>0&&n.test(t.slice(u,a.start)),m=t.slice(0,e).trimEnd(),g=m.endsWith(">")?m.slice(m.lastIndexOf("<")):"",b=/^<[a-z]/i.test(g)&&!/\/\s*>$/.test(g)&&!yt.has(g.match(/^<([a-z0-9-]+)/i)?.[1].toLowerCase()),S=/^\s*<\//.test(t.slice(s,s+200));return l&&(d||b)?{...a,end:r+1}:d&&S?{...a,start:u}:a}import{CONTINUE as an,START as rn,validStart as cn}from"../browser/editor/components/list/index.mjs";var Ce={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(" ")}"`:""}${ye(t.attributes)}${e.id}>${t.html}`,e.children(e.inner),"</li>")},numbers:{check:t=>(t.start===void 0||cn(t.start))&&(t.continue===void 0||t.continue===!0),write:(t,e)=>e.block(`<ol${t.start?` ${rn}="${t.start}"`:""}${t.continue?` ${an}`:""}${e.id}>`,e.children(e.inner),"</ol>")}};import{iconKind as ln}from"../browser/shared/emoji/icon-value.mjs";import{SHEETS_LABEL as fn}from"../browser/shared/components/sheets.mjs";var Se=/^[a-z0-9][a-z0-9_-]{0,63}$/i,dn=(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>`,Ee={sheets:{check:t=>typeof t.name=="string"&&Se.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=fn[e.language],a=e.block(`<div class="doc-sheet-tabs" aria-label="${o}">`,t.children.map(r=>dn(r,e.idOf(r))),"</div>",e.inner,s),n=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(l=>e.render(l,s)),"</div>",e.inner,s));return e.block(`<section class="doc-sheet-shell" data-doc-sheets="${t.name}" aria-label="${o}"${e.id}>`,[a,...n],"</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"&&Se.test(t.sheet)&&(t.icon===void 0||ln(t.icon)==="emoji")}};import{COLUMN_WIDTH as On,NUMBERS as xn,tableTiling as kn,validTable as Tn}from"../browser/editor/components/table/index.mjs";import{CHART_SOURCE as Ln}from"../browser/shared/table-chart.mjs";import{widthHolder as yn}from"../browser/shared/table-slots.mjs";import{CELL_LOOKS as pn,COLUMN_WIDTH as Ae,validLook as gn,validWidth as hn}from"../browser/editor/components/table/index.mjs";import{tileSpans as Be}from"../browser/shared/table-slots.mjs";import{attr as St}from"../browser/shared/html-tree.mjs";function un(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 mn(t,e,s){let o=ft(t,e.endOffset-1);for(;o-1>e.startOffset&&/\s/.test(t[o-1]);)o--;let a=[];for(let[n,r]of s){let l=e.attrs?.[n],u=l?un(t,l):null,d=typeof r=="function"?r(u):r,m=u&&typeof r=="function"?u.quote:'"',g=d===null?"":d===""&&typeof r!="function"?n:`${n}=${m}${d}${m}`;l&&d===null?a.push({...lt(t,l.startOffset,l.endOffset),text:g}):l?a.push({start:l.startOffset,end:l.endOffset,text:g}):d!==null&&a.push({start:o,end:o,text:` ${g}`})}return a}function Ie(t,e,s,o){let a=e.sourceCodeLocation.startTag,n=t.slice(a.startOffset,a.endOffset),r=mn(t,a,s).map((l,u)=>({...l,index:u}));for(let{start:l,end:u,text:d}of r.sort((m,g)=>g.start-m.start||g.index-m.index))n=n.slice(0,l-a.startOffset)+d+n.slice(u-a.startOffset);return o?n.replace(/^<\w+/,`<${o}`):n}function Et(t){let e=t?.tagName==="table"?t:t?.childNodes?.find(g=>g.tagName==="table"),s=g=>!!(g?.sourceCodeLocation?.startTag&&g.sourceCodeLocation.endTag),o=g=>g.childNodes.filter(b=>b.tagName),a=g=>g.childNodes.every(b=>b.tagName||R(b));if(!s(e)||!a(e))return null;let n=o(e);if(n.some(g=>!["thead","tbody","colgroup","caption"].includes(g.tagName)))return null;let r=n.filter(g=>g.tagName==="thead"),l=n.filter(g=>g.tagName==="tbody");if(r.length>1||l.length!==1||r.length===1&&n.indexOf(r[0])>n.indexOf(l[0]))return null;let u=g=>g.tagName==="tr"&&s(g)&&a(g)&&o(g).every(b=>(b.tagName==="td"||b.tagName==="th")&&s(b)&&V(b,"rowspan")!==null&&V(b,"colspan")!==null),d=[...r,...l];if(!d.every(g=>s(g)&&a(g)&&o(g).every(u)))return null;let m=d.flatMap(g=>o(g).map(b=>({node:b,head:g.tagName==="thead",cells:o(b)})));return Be(m.map(g=>({head:g.head,cells:g.cells.map(b=>[V(b,"rowspan"),V(b,"colspan")])})))?{table:e,head:r[0]??null,body:l[0],rows:m}:null}var _e=1e3;function V(t,e){let s=St(t,e);return s===void 0?1:/^\s*\d{1,4}\s*$/.test(s)&&Number(s)>=1&&Number(s)<=_e?Number(s):null}var we=t=>t===void 0||Number.isInteger(t)&&t>=1&&t<=_e,Ct=(t,e)=>t.slice(e.sourceCodeLocation.startTag.startOffset,e.sourceCodeLocation.startTag.endOffset),Nn=(t,e)=>t.slice(e.sourceCodeLocation.startTag.endOffset,e.sourceCodeLocation.endTag.startOffset),Me=(t,e)=>[...(t??"").split(/\s+/).filter(s=>s&&!pn.includes(s)),...e.split(" ").filter(Boolean)].join(" "),$n=(t,e)=>`${e>1?` colspan="${e}"`:""}${t>1?` rowspan="${t}"`:""}`,bn=(t,e,s,o,a,n,r)=>Ie(t,e,[...a!==void 0?[["class",l=>Me(l?.value,a)||null]]:[],...n!==void 0?[["style",l=>vt(l?.value??"",[[Ae,n]])||null]]:[],["scope",o],...r!==void 0?[["colspan",r[1]>1?String(r[1]):null],["rowspan",r[0]>1?String(r[0]):null]]:[]],s);function je(t,e,s,{validCell:o}){let a=Et(e);if(!a||!Array.isArray(s?.rows)||s.rows.length===0||s.rows.length>2e3)return null;let{table:n,rows:r}=a,l=new Set;if(!s.rows.every((c,N)=>c&&typeof c.head=="boolean"&&(N===0||!c.head||s.rows[N-1].head)&&(c.from===null||Number.isInteger(c.from)&&r[c.from])&&Array.isArray(c.cells)&&c.cells.length<=5e3&&c.cells.every(L=>{if(!L||!["td","th"].includes(L.tag)||![void 0,null,"row","col"].includes(L.scope)||L.look!==void 0&&!gn(L.look)||L.width!==void 0&&!hn(L.width)||!we(L.rowspan)||!we(L.colspan)||L.rowspan===void 0!=(L.colspan===void 0)||L.scope&&L.tag!=="th")return!1;if(L.from!==null){let[x,E]=Array.isArray(L.from)?L.from:[];if(!r[x]?.cells[E]||l.has(`${x}:${E}`))return!1;l.add(`${x}:${E}`)}else if(typeof L.html!="string")return!1;return L.html===void 0||typeof L.html=="string"&&L.html.length<=1e5&&(L.html===""||o(L.tag,L.html))}))||!s.rows.some(c=>!c.head))return null;let d=c=>c.rowspan!==void 0?[c.rowspan,c.colspan]:c.from===null?[1,1]:[V(r[c.from[0]].cells[c.from[1]],"rowspan"),V(r[c.from[0]].cells[c.from[1]],"colspan")],m=Be(s.rows.map(c=>({head:c.head,cells:c.cells.map(d)})));if(!m||s.rows.length*m.columns>5e3)return null;let g=r[0]?.node,b=g?G(t,g.sourceCodeLocation.startOffset):null,S=G(t,a.body.sourceCodeLocation.startOffset),y=G(t,n.sourceCodeLocation.startOffset),T=t.includes(`\r
15
- `)?`\r
16
- `:`
17
- `,C=c=>{if(c.from===null){let gt=c.look?` class="${Me("",c.look)}"`:"",v=c.width?` style="${vt("",[[Ae,c.width]])}"`:"";return`<${c.tag}${gt}${v}${c.scope?` scope="${c.scope}"`:""}${$n(c.rowspan??1,c.colspan??1)}>${c.html}</${c.tag}>`}let[N,L]=c.from,x=r[N].cells[L],E=c.tag==="th"?c.scope??null:null;return`${x.tagName===c.tag&&(St(x,"scope")??null)===E&&c.look===void 0&&c.width===void 0&&c.rowspan===void 0?Ct(t,x):bn(t,x,c.tag,E,c.look,c.width,c.rowspan===void 0?void 0:[c.rowspan,c.colspan])}${c.html??Nn(t,x)}</${c.tag}>`},h=c=>{let N=c.from===null?null:r[c.from];return N&&N.cells.length===c.cells.length&&c.cells.every((x,E)=>x.from?.[0]===c.from&&x.from[1]===E&&x.html===void 0&&x.look===void 0&&x.width===void 0&&x.rowspan===void 0&&x.tag===N.cells[E].tagName&&(x.tag!=="th"||(x.scope??null)===(St(N.cells[E],"scope")??null)))?t.slice(N.node.sourceCodeLocation.startOffset,N.node.sourceCodeLocation.endOffset):`${N?Ct(t,N.node):"<tr>"}${c.cells.map(C).join("")}</tr>`},O=(c,N,L)=>{let x=L?Ct(t,L):`<${c}>`;return b===null||S===null?`${x}${N.map(h).join("")}</${c}>`:`${x}${N.map(E=>`${T}${b}${h(E)}`).join("")}${T}${S}</${c}>`},p=s.rows.filter(c=>c.head),i=s.rows.filter(c=>!c.head),$=[...n.childNodes.filter(c=>c.tagName==="caption"||c.tagName==="colgroup").map(c=>t.slice(c.sourceCodeLocation.startOffset,c.sourceCodeLocation.endOffset)),...p.length?[O("thead",p,a.head)]:[],O("tbody",i,a.body)],k=S===null||y===null?$.join(""):`${$.map(c=>`${T}${S}${c}`).join("")}${T}${y}`;return{start:n.sourceCodeLocation.startTag.endOffset,end:n.sourceCodeLocation.endTag.startOffset,text:k}}var Re={table:{rewrite:je,plain:t=>Et(t)!==null,check:(t,{validLeaf:e})=>Tn(t,s=>typeof s=="string"&&e({tag:"td"},s,{empty:!0})),write(t,e){let s=kn(t),o=(y,T)=>t.spans?.[y]?.[T]??[1,1],a=new Map((t.widths??[]).map((y,T)=>[yn(s,T),y]).filter(([y,T])=>y&&T)),n=(y,T)=>{let[C,h]=o(y,T),O=a.get(`${y}:${T}`);return`${t.looks?.[y]?.[T]?` class="${t.looks[y][T]}"`:""}${O?` style="${On}: ${O}"`:""}${h>1?` colspan="${h}"`:""}${C>1?` rowspan="${C}"`:""}`},r=(y,T,C)=>`<tr>${y.map((h,O)=>T?`<th${n(C,O)}>${h}</th>`:t.column&&s.places.get(`${C}:${O}`).c===0?`<th${n(C,O)} scope="row">${h}</th>`:`<td${n(C,O)}>${h}</td>`).join("")}</tr>`,l=e.inner===null?null:e.inner+e.step,u=l===null?null:l+e.step,[d,...m]=t.rows,g=[];t.header&&g.push(e.block("<thead>",[r(d,!0,0)],"</thead>",l,u));let b=t.header?m:t.rows,S=t.header?1:0;return b.length>0&&g.push(e.block("<tbody>",b.map((y,T)=>r(y,!1,T+S)),"</tbody>",l,u)),e.block(`<div class="doc-table-wrap"${t.numbers===!1?` ${xn}="off"`:""}${t.chart?` ${Ln}="${t.chart}"`:""}${e.id}>`,[e.block('<table class="doc-table">',g,"</table>",e.inner,l)],"</div>")}}};var P={...Kt,...Yt,...Jt,...Qt,...te,...ne,...re,...fe,...pe,...xe,...Ce,...Ee,...Re},vn=Object.entries(P).flatMap(([t,e])=>(e.fields??[]).map(s=>[s,t])),dr=t=>vn.some(([e,s])=>t[e]!==void 0&&t.type!==s);import{FLOW as dt,HELD_TAGS as At}from"../browser/editor/components/list/index.mjs";var Dn=new Set(["section","div","blockquote","ul","ol","aside","article"]),Fe=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"]),Ue=new Set(["img","picture","svg","canvas","video","audio","iframe","object"]),yt=new Set(["hr","img"]),Wn=new Set(["label","input","select","textarea","button"]),st=t=>In.some(e=>Bt(t,e))||En.some(e=>w(t,e)!==void 0);function _t(t){let e=t.childNodes??[],s=e.findIndex(a=>At.has(a.tagName));if(s<0)return[];let o=e.slice(s);return o.every(a=>At.has(a.tagName)||R(a))?o.filter(a=>a.tagName):null}function Mt(t){return t.tagName==="li"&&t.parentNode?.tagName==="ol"&&Bt(t.parentNode,dt)&&t.childNodes.some(e=>e.tagName)&&t.childNodes.every(e=>e.tagName?At.has(e.tagName):e.nodeName!=="#text"||!e.value.trim())}function We(t){let e=t.tagName,s=t.sourceCodeLocation;return Fe.has(e)||!(q.has(e)||Ue.has(e))||w(t,"contenteditable")!==void 0?!1:!!(s?.startTag&&(s.endTag||yt.has(e)))}var jt=(t,e=W(t))=>(P[e]?.boxes?.(t,J().packages)??[]).filter(({element:s})=>Rt(s)||s.sourceCodeLocation?.endTag&&s.childNodes.every(R));function Rt(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=>Wn.has(s.tagName)||!(q.has(s.tagName)||Ue.has(s.tagName)||Fe.has(s.tagName)))}function wt(t,e=null){let s=t.tagName;if(!Dn.has(s)||st(t)||w(t,"contenteditable")!==void 0)return null;let o=(w(t,"class")??"").split(/\s+/).filter(Boolean),a=t.childNodes.filter(d=>d.tagName),n=()=>a.every(d=>d.tagName==="li")&&t.childNodes.every(d=>d.tagName||!d.value?.trim());if(s==="ol"&&o.includes(dt))return o.every(d=>d===dt)&&n()?"flowchart":null;if(s==="ul"||s==="ol")return o.every(d=>(An.list??[]).includes(d))&&n()?"list":null;let r=t.childNodes.every(d=>d.nodeName!=="#text"||!d.value.trim()),l=et(t,Rn.match);if(s==="section"&&(o.length===0||l))return r&&(a.length>0||l)?"section":null;let u=Sn.find(([d])=>o.includes(d))?.[1];return u&&r&&a.length===0?u:Rt(t)?u||(o.length>0?null:s==="blockquote"?"quote":wn.has(e)?"plain":null):null}var Pn=(t,e,s=()=>!1)=>Object.entries(e.sourceCodeLocation.attrs??{}).filter(([o])=>o!=="class"&&o!==F&&!s(o,w(e,o))).sort((o,a)=>o[1].startOffset-a[1].startOffset).map(([,o])=>` ${t.slice(o.startOffset,o.endOffset)}`).join("");function W(t,e=t.parentNode){let s=(a,n,r)=>(!n||[n].flat().includes(a?.tagName))&&(!r||Bt(a,r));return Bn.find(({tag:a,class:n,attr:r,parent:l})=>s(t,a,n)&&(!r||w(t,r)!==void 0)&&(!l||e?.tagName&&s(e,l.tag,l.class)))?.kind??"block"}var Fn={flowchart:{tagName:"ol",attrs:[{name:"class",value:dt}]}},kr=(t,e)=>W(t,Fn[e]??null);function ze(t,e){let s=[],o=[],a=i=>i.parentNode.childNodes,n=i=>a(i)[a(i).indexOf(i)-1]??null,r=i=>/^[ \t]*$/.test(e.slice(e.lastIndexOf(`
18
- `,i-1)+1,i)),l=i=>{let f=n(i);for(;f&&R(f);)f=n(f);return f?.tagName?f:null},u=i=>{if(!et(i,De.frame))return null;let f=l(i);return f&&et(f,De.lead)&&f.sourceCodeLocation?.endTag?f:null},d=(i,f)=>{let $=i.sourceCodeLocation.startOffset;for(let k=n(i);k;)if(R(k)&&(k.value.match(/\n/g)?.length??0)<=1)k=n(k);else if(k.nodeName==="#comment"&&k.sourceCodeLocation&&r(k.sourceCodeLocation.startOffset))f.add(k),$=k.sourceCodeLocation.startOffset,k=n(k);else break;return $},m=(i,f,$,k)=>{let c=i.sourceCodeLocation,N=u(i),L=c.attrs?.class,x={id:s.length,tag:i.tagName,kind:W(i),box:f.id,parent:$?.id??null,start:d(N??i,k),end:c.endOffset,elStart:c.startOffset,at:c.startTag.endOffset-1,lead:N?N.sourceCodeLocation.startTag.endOffset-1:null,classAttr:L?{start:L.startOffset,end:L.endOffset,value:w(i,"class")}:null,attrs:i.attrs.map(({name:E,value:A})=>({name:E,value:A})),blockId:w(i,F)??null,carried:Pn(e,i,E=>!!Cn[W(i)]?.[E]),blockIdAttr:c.attrs?.[F]?{start:c.attrs[F].startOffset,end:c.attrs[F].endOffset}:null,companion:null,keep:null,node:i,nodes:N?[N,i]:[i]};return s.push(x),N&&k.add(N),x},g=(i,f,$,k=null)=>{let c=i.sourceCodeLocation,N={id:o.length,kind:f,unit:$?.id??null,key:k,at:c.startTag.endOffset-1,innerEnd:c.endTag?.startOffset??null,pure:!0};return o.push(N),N},b=(i,f,$)=>{let k=g(i,"tabs",f),c=new Set;for(let N of i.childNodes){if(!N.tagName){N.nodeName==="#text"&&N.value.trim()&&(k.pure=!1);continue}let L=w(N,X.tabKey),x=L&&$.find(j=>w(j,X.panelKey)===L);if(N.tagName!=="button"||!et(N,X.tab)||!x?.sourceCodeLocation?.endTag||!N.sourceCodeLocation?.endTag){k.pure=!1;continue}let E=m(N,k,f,c);E.kind="tab",E.key=L;let A=x.sourceCodeLocation;E.companion={tag:x.tagName,start:d(x,new Set),end:A.endOffset,elStart:A.startOffset},E.nodes.push(x)}for(let N of i.childNodes)N.nodeName==="#comment"&&!c.has(N)&&(k.pure=!1)},S=(i,f,$,k=null)=>{let c=g(i,f,$,k),N=new Set,L=i.childNodes.filter(x=>x.tagName);L.forEach((x,E)=>{if(L[E+1]&&u(L[E+1])===x)return;if(f==="header"&&x.tagName==="h1"||!We(x)){c.pure=!1,x.tagName==="dialog"&&T(x,$),f==="main"&&et(x,jn.header)&&x.sourceCodeLocation?.endTag&&S(x,"header",null);return}y(x,m(x,c,$,N),f)});for(let x of i.childNodes)(x.nodeName==="#text"?x.value.trim():!x.tagName&&!N.has(x))&&(c.pure=!1)},y=(i,f,$)=>{if(f.kind==="sheets"){let k=It(i,X.panels),[c]=It(i,X.row);c&&b(c,f,k);for(let N of k)(Rt(N)||N.sourceCodeLocation?.endTag&&N.childNodes.every(R))&&S(N,"panel",f,w(N,X.panelKey))}else if(i.tagName==="details")for(let k of i.childNodes)k.tagName&&wt(k)==="details"&&S(k,"details",f);else if(i.tagName==="li"&&Mt(i))S(i,"node",f);else if(i.tagName==="li")C.push([i,f]);else{let k=wt(i,$);k&&S(i,k,f);for(let c of P[f.kind]?.boxes?jt(i,f.kind):[])S(c.element,c.kind,f,c.key)}},T=(i,f)=>{let[$]=It(i,Mn.content);$&&wt($)==="dialog"&&S($,"dialog",f,w(i,"id")??null)},C=[],h=(i,f)=>{let $=_t(i);if($===null||!i.sourceCodeLocation?.endTag)return;let k=g(i,"nest",f);k.pure=!1,f.nested=$.length>0;let c=new Set;for(let N of $)We(N)&&y(N,m(N,k,f,c),"nest")},O=Nt(t,"main");O?.sourceCodeLocation?.startTag&&S(O,"main",null);for(let i=0;i<C.length;i++)h(...C[i]);let p=Vn(t,s);return{units:s,boxes:o,referenced:p}}var Un=t=>t===void 0||/^\s*(?:module|(?:text|application)\/(?:x-)?(?:javascript|ecmascript)|text\/javascript1\.[0-5]|text\/(?:jscript|livescript))?\s*$/i.test(t);function zn(t){let e=Hn(t),s=new Set,o=[],a=/(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1/g,n=m=>m.split(/\s+/).filter(Boolean).forEach(g=>s.add(g)),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[,,g]of m.matchAll(a))n(g);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 u=/\bclassName\s*(?:[!=]==?|=)\s*(["'`])((?:(?!\1)[^\\\n]|\\.)*)\1|(["'`])((?:(?!\3)[^\\\n]|\\.)*)\3\s*[!=]==?\s*[\w$.]*\bclassName\b/g;for(let m of t.matchAll(u))n(m[2]??m[4]);let d=/\[\s*class\s*([~|^$*]?)=\s*(?:"([^"]*)"|'([^']*)'|([^\]\s]+))\s*(?:[is]\s*)?\]/g;for(let m of e)for(let g of m.matchAll(d)){let b=g[2]??g[3]??g[4];g[1]===""||g[1]==="~"||g[1]==="|"?n(b):o.push(b)}return{names:s,partial:o,selectors:e.join(`
19
- `)}}function Hn(t){let e=[],s=[],o=0,a="",n=0,r=l=>{let u="";for(let d=l;d<t.length;d++){let m=t[d];if(m==="\\"){u+=t.slice(d,d+2),d++;continue}if(m==="`")return e.push(u),d+1;if(m==="$"&&t[d+1]==="{")return e.push(u),s.push(o),d+2;u+=m}return e.push(u),t.length};for(;n<t.length;){let l=t[n],u=t[n+1];if(l==="/"&&u==="/"){let d=t.indexOf(`
20
- `,n);n=d<0?t.length:d;continue}if(l==="/"&&u==="*"){let d=t.indexOf("*/",n+2);n=d<0?t.length:d+2;continue}if(l==='"'||l==="'"){let d=n+1,m="";for(;d<t.length&&t[d]!==l&&t[d]!==`
21
- `;)t[d]==="\\"?(m+=t.slice(d,d+2),d+=2):m+=t[d++];e.push(m),n=d+1,a="a";continue}if(l==="`"){n=r(n+1),a="a";continue}if(l==="}"&&s.length&&s.at(-1)===o){s.pop(),n=r(n+1),a="a";continue}if(l==="/"&&(!/[\w$)\]}]/.test(a)||/(?:^|[^\w$.])(?:return|typeof|case|in|of|void|delete|throw|yield|await|else|do)\s*$/.test(t.slice(Math.max(0,n-12),n)))){let d=n+1,m=!1;for(;d<t.length&&t[d]!==`
22
- `&&(m||t[d]!=="/");)t[d]==="\\"?d++:t[d]==="["?m=!0:t[d]==="]"&&(m=!1),d++;if(t[d]==="/"){for(n=d+1;/[a-z]/i.test(t[n]??"");)n++;a="a";continue}}l==="{"?o++:l==="}"&&o--,/\s/.test(l)||(a=l),n++}return e}var Gn=/\bDocSheets\b|["'`]sheets-|\bactiveSheet\b|data-active-sheet|["'`]sheet["'`]|\bsheet\s*:/,Kn=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function qn(t,e){if(!Gn.test(e))return!1;let s=Kn(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(a=>new RegExp(a).test(e))}function Vn(t,e){let s=[],o=new Map,a=h=>{for(let O of h.childNodes??[]){if(!O.tagName)continue;let p=O.sourceCodeLocation?.startOffset??-1;O.tagName==="script"&&w(O,"src")===void 0&&s.push({at:p,code:Un(w(O,"type")),text:O.childNodes.map(i=>i.value??"").join("")});for(let{name:i,value:f}of O.attrs)if(!(i==="aria-labelledby"&&O.tagName==="section"))for(let $ of _n(i,f))(o.get($)??o.set($,[]).get($)).push(p);a(O.tagName==="template"?O.content:O)}};a(t);let n=h=>h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=h=>h.slice(5).replace(/-([a-z])/g,(O,p)=>p.toUpperCase()),l=s.filter(h=>h.code),u=l.map(h=>h.text).join(`
23
- `),d=h=>l.some(O=>h(O.at))?l.filter(O=>!h(O.at)).map(O=>O.text).join(`
24
- `):u,m=new Map,g=(h,O)=>(p,i)=>{if(i!==u)return O(p,i);let f=`${h} ${p}`;return m.has(f)||m.set(f,O(p,i)),m.get(f)},b=g("id",(h,O)=>new RegExp(`#${n(h)}(?![\\w-])|(["'\`])${n(h)}\\1`).test(O)),S=g("data",(h,O)=>new RegExp(`${n(h)}(?![\\w-])|dataset\\.${r(h)}(?![\\w$])`).test(O)),y=new Map,T=g("class",(h,O)=>{y.has(O)||y.set(O,zn(O));let{names:p,partial:i,selectors:f}=y.get(O);return p.has(h)||i.some($=>$.includes(h))||new RegExp(`\\.${n(h)}(?![\\w-])`).test(f)}),C=h=>h.split(/\s+/).filter(O=>O&&!/^(doc-|katex)/.test(O));for(let h of e){let O=[[h.start,h.end],...h.companion?[[h.companion.start,h.companion.end]]:[]],p=v=>O.some(([I,_])=>v>=I&&v<_),i=new Map,f=new Map,$=new Map,k=(v,I,_)=>(v.get(I)??v.set(I,[]).get(I)).push(_),c=v=>{if(!v.tagName)return;let I=v.sourceCodeLocation?.startOffset??h.start;for(let{name:_,value:U}of v.attrs)_==="id"&&U?k(i,U,I):_.startsWith("data-")&&_!==F?k(f,_,I):_==="class"&&C(U).forEach(ht=>k($,ht,I));(v.tagName==="template"?v.content:v).childNodes?.forEach(c)};h.nodes.forEach(c);let N=d(p),L=(v,I,_)=>[...v].filter(([U])=>I(U)).map(([U,ht])=>({name:_(U),at:ht})),x=[...h.key&&s.some(v=>!p(v.at)&&qn(h.key,v.text))?[{name:`"${h.key}"`,at:[h.start]}]:[],...L(i,v=>b(v,N),v=>`#${v}`),...L(f,v=>S(v,N),v=>`[${v}]`),...L($,v=>T(v,N),v=>`.${v}`)],E=L(i,v=>(o.get(v)??[]).some(I=>!p(I)),v=>`#${v}`),A=x.length>0?x:E,j=A.flatMap(v=>v.at),gt=j.some(v=>!e.some(I=>I!==h&&h.start<=I.start&&I.end<=h.end&&I.start<=v&&v<I.end));h.keep=A.length>0?{reason:x.length>0?"script":"ref",names:A.map(v=>v.name),at:j,own:gt}:null}return h=>{let O=h.sourceCodeLocation;if(!O||!h.attrs.some(({name:$})=>$==="id"||$==="class"||$.startsWith("data-")))return null;let p=$=>$>=O.startOffset&&$<O.endOffset,i=d(p),f=null;for(let{name:$,value:k}of h.attrs)if($==="id"&&k){if(b(k,i))return"script";(o.get(k)??[]).some(c=>!p(c))&&(f="ref")}else{if($.startsWith("data-")&&$!==F&&S($,i))return"script";if($==="class"&&C(k).some(c=>T(c,i)))return"script"}return f}}function Xn(t,e){let s=[],o=a=>{let n=a.sourceCodeLocation?.attrs?.[F];if(n){let r=n.startOffset>0&&/\s/.test(t[n.startOffset-1])?n.startOffset-1:n.startOffset;s.push({start:r,end:n.endOffset})}for(let r of a.content?.childNodes??a.childNodes??[])o(r)};return e.forEach(o),s.sort((a,n)=>a.start-n.start)}var Pe=(t,e,s,o)=>{let a="",n=e;for(let r of o)r.start<n||r.end>s||(a+=t.slice(n,r.start),n=r.end);return a+t.slice(n,s)},Tr=(t,e)=>{let s=Xn(t,e.nodes),o=Pe(t,e.start,e.end,s);return at(e.companion?`${o}\0${Pe(t,e.companion.start,e.companion.end,s)}`:o)};ot();import{HOSTS as mt,IDENTITY as Yn}from"../browser/editor/components/registry.mjs";import{CODE as Zn,MATH as qe,MEDIA as Jn,PAGE as Qn,TABLE as to}from"../browser/editor/components/kit.mjs";import{TAB as eo}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as so,isInstance as ut,matchesNode as K,partOf as no}from"../browser/shared/components/index.mjs";import{texSource as oo}from"../browser/editor/components/math/index.mjs";import{MENTION as Wt,MENTION_ICON as He,MENTION_PAGE as Ge}from"../browser/shared/components/mention.mjs";import{imageFile as ao}from"../browser/shared/media.mjs";import{isFileLink as ro}from"../browser/shared/page-address.mjs";import{isInkClass as io}from"../browser/editor/page/marks.mjs";import{ownInline as co}from"../browser/editor/page/own.mjs";import{attr as B,hasClass as lo}from"../browser/shared/html-tree.mjs";var fo=new Set(["h1","h2","h3","h4","p","li"]),uo=new Set(["h3","h4","p","figcaption"]),mo=Object.entries(mt).flatMap(([t,e])=>(e.parts??[]).map(([s,o])=>{let a=so(s);if(a?.parts?.[o]?.edit!=="text")throw new Error(`Host ${t}: ${s} has no part ${o} edited as text`);return{kind:t,match:a.match,at:a.parts[o].at}})),po=t=>mo.filter(({match:e})=>K(t,e)).flatMap(({kind:e,at:s})=>no(t,s).map(o=>({kind:e,part:o}))),go=t=>t.sort((e,s)=>e.part.sourceCodeLocation.startOffset-s.part.sourceCodeLocation.startOffset),ho=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),No=new Set(["ul","ol","blockquote"]),Dt=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),Fr={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function $o(t,e,s){let o=mt[t];if(!o)throw new Error(`Unknown block kind ${t}`);return o.caps({bound:s,blockLevel:q.has(e)})}var Ve=t=>t.tagName==="span"&&K(t,qe.inline),bo=t=>t.tagName==="a"&&lo(t,Wt),Oo=/^https?:\/\/[^\s"<>]+$/i,nt=t=>t.attrs.map(e=>e.name).sort().join(),xo=t=>B(t,"class")===Wt&&t.childNodes.length===0&&(nt(t)==="class"||nt(t)===`class,${Ge}`&&B(t,Ge)==="");function ko(t){if(xo(t))return null;if(nt(t)!=="class,href"||B(t,"class")!==Wt||!(Oo.test(B(t,"href"))||ro(B(t,"href"))))return"mention";let[e,...s]=t.childNodes;return(e?.tagName==="img"?nt(e)==="alt,class,src"&&B(e,"class")===He&&B(e,"alt")===""&&ao(B(e,"src")):e?.tagName==="span"&&nt(e)==="class"&&B(e,"class")===He&&e.childNodes.length===0)&&s.length>0&&s.every(a=>a.nodeName==="#text")&&s.some(a=>a.value.trim())?null:"mention"}var To=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(io),Lo=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===eo,Xe=t=>ho.has(t.tagName)||To(t)||Lo(t),pt=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":pt(e)),Ye=t=>co(t.tagName,t.attrs,pt(t)),Ke=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==Yn),yo=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),vo=(t,e,s={})=>t==="text"?q.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!s.plain;function Pt(t,e,s=!1,{lists:o=!1,known:a=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(s===!0)return`tag:${n.tagName}`;if(n.attrs.some(l=>/^on/i.test(l.name)))return"markup";if(s==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(a&&!a(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(o&&(n.tagName==="ul"||n.tagName==="ol")){let l=Co(n,e,a);if(l)return l;continue}if(Ve(n)){if(n.childNodes.some(l=>l.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(bo(n)){let l=ko(n);if(l)return l;e.push(n.sourceCodeLocation);continue}if(Ye(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(a&&!a(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!Xe(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&yo(B(n,"href")??""))return"link";let r=Pt(n,e,!1,{known:a});if(r)return r}return null}function Co(t,e,s){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let o of t.childNodes){if(o.nodeName==="#text"&&!o.value.trim())continue;if(o.tagName!=="li")return`tag:${o.tagName??"text"}`;if(o.attrs.length>0||!o.sourceCodeLocation?.endTag)return"markup";let a=Pt(o,e,!1,{known:s});if(a)return a}return null}function Y(t){let e=[],s=[],o=new Map,a=null,n=(p,i,f=null)=>{let $=p.sourceCodeLocation;if(!mt[i]||!$?.startTag||B(p,"contenteditable")!==void 0)return!1;let k=[],c=vo(i,p.tagName),N=f?{childNodes:p.childNodes.slice(0,p.childNodes.indexOf(f))}:p,L=$.endTag?Pt(N,k,c,{lists:i==="cell"}):"markup";if(L)return s.push({at:$.startTag.endOffset-1,reason:L}),!1;let x=$.startTag.endOffset,E=f?x+t.slice(x,f.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:$.endTag.startOffset,A={id:e.length,tag:p.tagName,kind:i,bound:!1,caps:{},start:$.startOffset,end:$.endOffset,innerStart:x,innerEnd:E,atoms:k.map(j=>[j.startOffset-x,j.endOffset-x]),wrapper:null,nested:!!f,node:p};return e.push(A),o.set(p,A),!0},r=p=>(p.childNodes??[]).filter(i=>i.tagName),l=p=>{let i=p.sourceCodeLocation;return i?.startTag&&i.endTag?t.slice(i.startTag.endOffset,i.endTag.startOffset):null},u=p=>p.tagName!=="a"&&!Ke(p)&&pt(p)&&r(p).every(i=>Ye(i)?!pt(i):Xe(i)||Ve(i)),d=p=>{for(let i of r(p))i.tagName==="td"||i.tagName==="th"?n(i,"cell"):["thead","tbody","tfoot","tr"].includes(i.tagName)&&d(i)},m=p=>{for(let i of r(p))i.tagName==="table"?d(i):!Dt.has(i.tagName)&&!ut(i)&&m(i)},g=p=>{let i=r(p);i.length===1&&i[0].tagName==="code"&&p.childNodes.every(f=>f.tagName||!f.value?.trim())?n(i[0],"code"):i.length===0?n(p,"code"):p.sourceCodeLocation?.startTag&&s.push({at:p.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},b=(p,i=!0)=>{for(let f of r(p)){let $=f.tagName,k=ut(f);for(let{kind:c,part:N}of go(k?P[W(f)].textParts(f,a??=J().packages):po(f)))n(N,c);if(k){for(let{element:c}of jt(f))b(c,i);continue}if($==="div"&&K(f,Zn.match)){for(let c of r(f))c.tagName==="pre"&&B(c,"contenteditable")===void 0&&g(c);continue}if(!(Dt.has($)||B(f,"contenteditable")!==void 0))if($==="table")d(f);else if($==="figure"){let c=K(f,Jn);for(let N of r(f))if(!(c&&N.tagName==="figcaption"))if(uo.has(N.tagName))n(N,"field");else if(N.tagName==="table")d(N);else{if(Dt.has(N.tagName))continue;ut(N)?b({childNodes:[N]},i):c||st(N)||Ke(N)?m(N):b({childNodes:[N]},i)}}else if($==="details")for(let c of r(f))ut(c)?b({childNodes:[c]},i):c.tagName!=="summary"&&b(c,i);else if($==="h1"&&(p.tagName==="header"||K(f,Qn.title)))n(f,"title");else if($==="li"&&Mt(f))b({childNodes:r(f)},i);else if(fo.has($)){let c=$==="li"?_t(f):[];c?.length>0?(n(f,"flow",c[0]),b({childNodes:c},i)):n(f,"flow")||b(f,!1)}else if($==="div"&&K(f,qe.block)&&r(f).length===0&&oo(l(f)))n(f,"tex");else if($==="div"&&K(f,to.lead))for(let c of r(f))c.tagName==="span"&&n(c,"field");else i&&!st(f)&&u(f)?n(f,"text"):(b(f,i&&!st(f)),No.has($)&&S(f))}},S=p=>{let i=p.sourceCodeLocation,f=r(p).map(c=>o.get(c));if(!(f.length>0&&f.every(Boolean)&&p.childNodes.every(c=>c.tagName||c.nodeName==="#text"&&!c.value.trim()))||!i?.endTag)return;let k={start:i.startOffset,end:i.endOffset,ids:f.map(c=>c.id)};f.forEach(c=>c.wrapper=k)},y=p=>{for(let i of r(p))(i.tagName==="main"?b:y)(i)},T=z(t,{sourceCodeLocationInfo:!0});y(T);let{units:C,boxes:h,referenced:O}=ze(T,t);for(let p of C)p.grid=!!P[p.kind]?.plain?.(p.node);for(let p of C){let i=P[p.kind]?.dataOf?.(t,p.node,a??=J().packages);i&&(p.parts=Object.fromEntries(Object.entries(i).map(([f,$])=>[f,at($)])))}for(let p of e){let i=null;for(let f of C)f.start<=p.start&&p.start<f.end&&(!i||f.start>i.start)&&(i=f);p.unit=i?.id??null,p.self=i&&i.at===p.innerStart-1?i.id:null,p.self!==null&&(i.text=p.id),p.path=i&&p.self===null?So(i,p.node):null,mt.text&&p.kind==="flow"&&p.self===null&&(i?.kind==="block"||i?.kind==="figure")&&(p.kind="text"),p.bound=O(p.node)!==null,p.caps=Object.fromEntries($o(p.kind,p.tag,p.bound).map(f=>[f,!0]))}return{blocks:e,locks:s,units:C,boxes:h}}function So(t,e){let s=[],o=e;for(;o&&!t.nodes.includes(o);o=o.parentNode){let a=(o.parentNode?.childNodes??[]).filter(n=>n.tagName===o.tagName);s.unshift([o.tagName,a.indexOf(o),a.length])}return o?[o===t.node?"unit":o===t.nodes[0]&&t.lead!==null?"lead":"panel",...s]:null}var Ur=t=>Y(t).blocks;function zr(t){let{units:e,boxes:s}=Y(t);return{units:e,boxes:s}}ot();import{randomBlockId as Eo}from"../browser/shared/ids.mjs";import{IDENTITY as Z}from"../browser/editor/components/registry.mjs";var Io=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function Yr(t,e=Eo){let{units:s}=Y(t),o=new Set([...t.matchAll(Io)].map(m=>m[1]??m[2])),a=()=>{for(;;){let m=e();if(!o.has(m))return o.add(m)&&m}},n=new Set,r=[],l=[],u=[];for(let m of s)if(m.blockId)n.has(m.blockId)&&m.blockIdAttr?(l.push(m.blockId),r.push({start:m.blockIdAttr.start,end:m.blockIdAttr.end,text:`${Z}="${a()}"`})):n.add(m.blockId);else{let g=a();if(m.blockIdAttr)r.push({start:m.blockIdAttr.start,end:m.blockIdAttr.end,text:`${Z}="${g}"`});else{let b=ft(t,m.at);r.push({start:b,end:b,text:` ${Z}="${g}"`})}u.push({id:g,tag:Je(m.tag,m.attrs),at:m.elStart})}let d=t;for(let m of r.sort((g,b)=>b.start-g.start))d=d.slice(0,m.start)+m.text+d.slice(m.end);return u.sort((m,g)=>m.at-g.at),{text:d,added:u.length,renamed:l,given:u.map(({id:m,tag:g})=>({id:m,tag:g}))}}function Zr(t){let e=Ze(t);return Y(t).units.filter(s=>!s.blockId).sort((s,o)=>s.elStart-o.elStart).map(s=>({line:e(s.elStart),tag:Je(s.tag,s.attrs)}))}function Jr(t,e){let s=new Map(e.map(a=>[a.id,a])),o=Ze(t);return Y(t).units.filter(a=>s.has(a.blockId)).sort((a,n)=>a.elStart-n.elStart).map(a=>({...s.get(a.blockId),line:o(a.elStart)}))}function Ze(t){let e=[0];for(let s=t.indexOf(`
25
- `);s!==-1;s=t.indexOf(`
26
- `,s+1))e.push(s+1);return s=>{let[o,a]=[0,e.length-1];for(;o<a;){let n=o+a+1>>1;e[n]<=s?o=n:a=n-1}return o+1}}function Je(t,e=[]){let s=e.filter(({name:n})=>n!==Z&&n!=="style"),o=n=>{let r=n.replace(/\s+/g," "),l=r.length>32?`${r.slice(0,31)}\u2026`:r;return l===""?"":/[\s"'=<>`]/.test(l)?`="${l.replaceAll('"',"&quot;")}"`:`=${l}`},a=s.slice(0,3).map(({name:n,value:r})=>`${n}${o(r)}`);return`<${[t,...a,...s.length>3?["\u2026"]:[]].join(" ")}>`}function Qr(t){let e=new Map,s=o=>{let a=o.attrs?.find(r=>r.name===Z)?.value,n=o.sourceCodeLocation?.attrs?.[Z]??o.sourceCodeLocation;a!==void 0&&e.set(a,[...e.get(a)??[],n]);for(let r of o.content?.childNodes??o.childNodes??[])s(r)};return s(z(t,{sourceCodeLocationInfo:!0})),[...e].filter(([,o])=>o.length>1).map(([o,a])=>({id:o,lines:a.map(n=>n?.startLine),columns:a.map(n=>n?.startCol)}))}export{at as a,Nt as b,q as c,st as d,jt as e,Pn as f,kr as g,Xn as h,Tr as i,ye as j,ft as k,lt as l,ya as m,va as n,vt as o,Ca as p,nn as q,Sa as r,Ea as s,Lt as t,G as u,on as v,Ia as w,dn as x,mn as y,P as z,dr as A,Fr as B,vo as C,Pt as D,Y as E,Ur as F,zr as G,Eo as H,Io as I,Yr as J,Zr as K,Jr as L,Qr as M};
@@ -1,2 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import L from"node:fs";import{pipeline as F}from"node:stream/promises";import z from"node:zlib";import{refusal as B,said as k}from"../browser/shared/i18n/index.mjs";var Z=67324752,O=33639248,A=101010256,P=101075792,W=117853008,I=4294967295,D=2048;function v(t=new Date){let o=t.getHours()<<11|t.getMinutes()<<5|Math.floor(t.getSeconds()/2),n=Math.max(1980,t.getFullYear())-1980<<9|t.getMonth()+1<<5|t.getDate();return[o,n]}function K(t){let[o,n]=v(),c=[],d=[],r=0;for(let a of t){let u=Buffer.isBuffer(a.data)?a.data:Buffer.from(a.data??"","utf8"),e=Buffer.from(a.name,"utf8"),w=u.length>64?z.deflateRawSync(u):null,h=w&&w.length<u.length?w:u,m=h===u?0:8,g=z.crc32(u);if(u.length>=I||r>=I)throw new Error("\u538B\u7F29\u5305\u592A\u5927\uFF08\u8D85\u8FC7 4GB\uFF09");let l=Buffer.alloc(30);l.writeUInt32LE(Z,0),l.writeUInt16LE(20,4),l.writeUInt16LE(D,6),l.writeUInt16LE(m,8),l.writeUInt16LE(o,10),l.writeUInt16LE(n,12),l.writeUInt32LE(g,14),l.writeUInt32LE(h.length,18),l.writeUInt32LE(u.length,22),l.writeUInt16LE(e.length,26),l.writeUInt16LE(0,28);let s=Buffer.alloc(46);s.writeUInt32LE(O,0),s.writeUInt16LE(20,4),s.writeUInt16LE(20,6),s.writeUInt16LE(D,8),s.writeUInt16LE(m,10),s.writeUInt16LE(o,12),s.writeUInt16LE(n,14),s.writeUInt32LE(g,16),s.writeUInt32LE(h.length,20),s.writeUInt32LE(u.length,24),s.writeUInt16LE(e.length,28),s.writeUInt32LE(r,42),c.push(l,e,h),d.push(s,e),r+=l.length+e.length+h.length}if(t.length>=65535)throw new Error("\u538B\u7F29\u5305\u91CC\u7684\u6587\u4EF6\u592A\u591A");let i=Buffer.concat(d),f=Buffer.alloc(22);return f.writeUInt32LE(A,0),f.writeUInt16LE(t.length,8),f.writeUInt16LE(t.length,10),f.writeUInt32LE(i.length,12),f.writeUInt32LE(r,16),Buffer.concat([...c,i,f])}var G=new TextDecoder("utf-8",{fatal:!0}),H=new TextDecoder("gbk");function X(t,o){if(o&D)return t.toString("utf8");try{return G.decode(t)}catch{return H.decode(t)}}var U=()=>new Error("ZIP \u6587\u4EF6\u5DF2\u635F\u574F"),E=(t,o)=>Number(t.readBigUInt64LE(o));function C(t,o){let n=Math.min(o,65557),c=t(o-n,n),d=-1;for(let e=c.length-22;e>=0;e-=1)if(c.readUInt32LE(e)===A){d=e;break}if(d<0)throw new Error("\u4E0D\u662F\u6709\u6548\u7684 ZIP \u6587\u4EF6");let r=c.readUInt16LE(d+10),i=c.readUInt32LE(d+12),f=c.readUInt32LE(d+16);if(r===65535||i===I||f===I){let e=t(o-n+d-20,20);if(e.readUInt32LE(0)!==W)throw U();let w=t(E(e,8),56);if(w.readUInt32LE(0)!==P)throw U();r=E(w,32),i=E(w,40),f=E(w,48)}let a=t(f,i),u=[];for(let e=0,w=0;w<r;w+=1){if(a.readUInt32LE(e)!==O)throw U();let h=a.readUInt16LE(e+8),m=a.readUInt16LE(e+10),g=a.readUInt32LE(e+20),l=a.readUInt32LE(e+24),s=a.readUInt16LE(e+28),T=a.readUInt16LE(e+30),N=a.readUInt16LE(e+32),R=a.readUInt32LE(e+42),b=X(a.subarray(e+46,e+46+s),h),p=a.subarray(e+46+s,e+46+s+T);for(let x=0;x+4<=p.length;x+=4+p.readUInt16LE(x+2)){if(p.readUInt16LE(x)!==1)continue;let S=x+4;l===I&&(l=E(p,S),S+=8),g===I&&(g=E(p,S),S+=8),R===I&&(R=E(p,S))}if(e+=46+s+T+N,!b.endsWith("/")){if(h&1)throw B(k("{0} \u5DF2\u52A0\u5BC6",b));if(m!==0&&m!==8)throw B(k("{0}\uFF1A\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F",b));u.push({name:b,method:m,packedSize:g,size:l,local:R})}}return u}function M(t,o){let n=t(o.local,30);if(n.readUInt32LE(0)!==Z)throw U();return o.local+30+n.readUInt16LE(26)+n.readUInt16LE(28)}function Q(t){let o=(n,c)=>{if(n<0||n+c>t.length)throw U();return t.subarray(n,n+c)};return C(o,t.length).map(n=>{let c=o(M(o,n),n.packedSize),d=n.method===0?Buffer.from(c):z.inflateRawSync(c);if(d.length!==n.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",n.name));return{name:n.name,data:d}})}function V(t){let o=L.openSync(t,"r"),n=L.fstatSync(o).size,c=(r,i)=>{if(r<0||r+i>n)throw U();let f=Buffer.alloc(i);for(let a=0;a<i;){let u=L.readSync(o,f,a,i-a,r+a);if(u===0)throw U();a+=u}return f},d;try{d=C(c,n)}catch(r){throw L.closeSync(o),r}return{entries:d,read(r){let i=c(M(c,r),r.packedSize),f=r.method===0?i:z.inflateRawSync(i);if(f.length!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name));return f},async extract(r,i){let f=M(c,r);if(r.packedSize===0)await L.promises.writeFile(i,"");else{let a=L.createReadStream(null,{fd:o,start:f,end:f+r.packedSize-1,autoClose:!1});await F(...r.method===0?[a]:[a,z.createInflateRaw()],L.createWriteStream(i))}if((await L.promises.stat(i)).size!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name))},close:()=>L.closeSync(o)}}export{K as a,Q as b,V as c};
@@ -1,59 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as w}from"./chunk-TX6JH7TR.mjs";import{c as O}from"./chunk-64K7IPLO.mjs";import{a as k,b as d,f as N}from"./chunk-NSKUTQ5J.mjs";import{i as S}from"./chunk-BGGDRNYQ.mjs";import{c as $,g as b,o as A,p as C,r as x}from"./chunk-W4VKN3GF.mjs";import y from"node:fs";import v from"node:path";import{blocksHidden as K}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as B,SLOT as L}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as R,layoutOf as T,PACKAGE_MANIFEST as U,shallowPackages as F}from"../browser/shared/workspace.mjs";var M=(t,e,{script:o,flow:s})=>`{
3
- "id": "${t}",
4
- "apiVersion": 1,
5
- "version": "0.1.0",
6
- "name": { "zh": "${e}", "en": "${e}" },
7
- "description": { "zh": "\u4E00\u4E2A\u53EF\u4EE5\u53CD\u590D\u4F7F\u7528\u7684\u5757", "en": "A block to use again" },
8
- "words": "${e}",
9
- "parts": {
10
- "title": { "at": ":scope > h3", "edit": "text" },
11
- ${s?'"body": { "edit": "flow" }':'"text": { "at": ":scope > p", "edit": "text", "optional": true }'}
12
- },${o?`
13
- "runtime": { "generated": [".component-drawn"] },`:""}
14
- "markdown": "parts"
15
- }
16
- `,P=(t,e,o,s)=>`<div data-doc-component="${t}">
17
- <h3>${e}</h3>
18
- ${s?` <div data-doc-slot="body">
19
- ${s.map(n=>` ${n}
20
- `).join("")} </div>`:` <p>${o}</p>`}
21
- </div>
22
- `,W=["<p>\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002</p>","<ul>"," <li>\u63D2\u69FD\u91CC\u5199\u6587\u6863\u81EA\u5DF1\u7684\u5757</li>"," <li>\u6BB5\u843D\u3001\u5217\u8868\u3001\u8868\u683C\u90FD\u53EF\u4EE5</li>","</ul>"],_=(t,e)=>`/* Every selector starts at the instance, so that nothing here reaches the rest of the page.${e?` Each step is
23
- a >, so that none reaches into the slot, whose blocks read as the page's.`:""} */
24
- [data-doc-component="${t}"] { padding: 12px 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
25
- [data-doc-component="${t}"] > h3 { margin-top: 0; }
26
- `,G=(t,e,{script:o,flow:s})=>`# ${e}
27
-
28
- What this block is for, and when a document uses it rather than a block of Gallery's own.
29
-
30
- ## How to write it
31
-
32
- Write the element as example.html does: \`gallery component show ${t}\` prints it. Each part, and what goes in it:
33
-
34
- - the title, its \`h3\`: required.
35
- ${s?'- the body, its `<div data-doc-slot="body">`: required, the document\'s own blocks, written as anywhere in the document (paragraphs, lists, tables, formulas).\n':"- the text, its `p`: optional.\n"}
36
- ## How it looks
37
-
38
- What a reader sees of it, and what it shows while it is empty.
39
- ${o?`
40
- ## Its script
41
-
42
- kit.js runs with the rights of a document's own script. What it draws, it draws in what the manifest's \`runtime\` names${s?", outside the slot: it reads the slot and never writes in it":""}.
43
- `:""}`,D=t=>`// Starts each instance from what the file says, and draws in a node the manifest's runtime names:
44
- // the kit takes that off an instance before it starts one again, as an undo may put one back.
45
- DocKit.component({
46
- id: "${t}",
47
- on: ["source"],
48
- mount(host, context) {
49
- const drawn = document.createElement("div");
50
- drawn.className = "component-drawn";
51
- host.append(drawn);
52
- const draw = () => { drawn.textContent = context.part("title")?.textContent ?? ""; };
53
- draw();
54
- return { update: draw };
55
- },
56
- });
57
- `;function I(t,{script:e=!1,flow:o=!1}={}){let s=t.split("/")[1],n={script:e,flow:o};return{"component.json":M(t,s,n),"template.html":P(t,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",o&&["<p></p>"]),"example.html":P(t,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",o&&W),"writing.md":G(t,s,n),"style.css":_(t,o),...e?{"kit.js":D(t)}:{}}}var j="local";function q(t){let e=t.includes("/")?t:`${j}/${t}`;if(!B.test(e))throw new d(`Not a component's id: ${t} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${j}/<name>).`);let o=e.split("/").find(s=>R.has(s));if(o)throw new d(`Not a component's id: ${t} (Windows keeps ${o} for a device).`);return e}var V=(t,e)=>v.join(T(t).components,...e.split("/")),H=({name:t,file:e})=>`${w(e)} is one level too shallow, and no catalog reads it: a package is components/<scope>/<name>/, so move it to components/${j}/${t}/`;function Y(t,e){let o=F(t).find(({name:s})=>s===e.split("/")[1]);return o?H(o):`No component ${e} in ${w(T(t).components)}: gallery component list says which there are.`}function X(t,e,{script:o,flow:s}){let n=V(t,e);if(y.existsSync(n)||$(t).problems.has(e)){let i=!y.existsSync(v.join(n,U));console.error(i?`A folder is there with no component.json: ${w(n)}: move it, or give this component another name.`:`Component already exists: ${w(n)}: gallery component show ${e} says what it is; give a new one another name.`),process.exit(1)}let a=I(e,{script:o,flow:s});try{y.mkdirSync(n,{recursive:!0});for(let[i,c]of Object.entries(a).reverse())y.writeFileSync(v.join(n,i),c)}catch(i){if(!i.code)throw i;console.error(`Cannot write ${w(n)} (${i.code}).`),process.exit(1)}console.log(`Created ${w(n)}: ${Object.keys(a).join(", ")}`),console.log(`Next: say in component.json what it is (its name, description and parts), write template.html, what "/" puts in a document, and example.html, an instance as a writer would fill it, then writing.md and style.css${o?" and kit.js":""} (references/building-components.md has every field and the rules${s?", and Slots what its slot body holds":""}), and run gallery component check ${e}, which passes as it stands now.`)}var u=({zh:t,en:e})=>t===e?t:`${t} / ${e}`;function z(t){if(C(t))return null;let e=A(t);return e?b("en",e):"it has no template.html"}var J={disabled:"disabled: its instances show as they stand, no script and no style",hidden:"hidden: the menus do not offer it, and the instances there go on running"};function Q(t){let e=$(t),o=x(e),s=o.filter(({reason:r})=>r),n=o.filter(({reason:r})=>!r),a=n.filter(({state:r})=>r==="normal"),i=F(t),c=K(e.settings.hidden),p=()=>{c.length&&console.log(`Hidden by the user, not to write unless asked for: ${c.join(", ")}`)};if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(t)}`),n.length+s.length+i.length===0){console.log("No component packages yet. A document is written with Gallery's blocks and whole blocks; gallery component new <id> starts a package when the user wants a block to use again."),p();return}console.log(a.length?`${a.length} component${a.length===1?"":"s"} to write with (gallery component show <id> says how):`:"No component to write with now.");for(let{id:r,name:l,version:m,description:f}of a){console.log(`${r} ${u(l)}`),console.log(` \u7248\u672C\uFF1A${m}\uFF08available\uFF09`),console.log(` \u8BF4\u660E\uFF1A${u(f)}`);let E=z(e.packages.get(r));E&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${E}`)}let h=n.filter(({state:r})=>r!=="normal");h.length+s.length+i.length>0&&console.log("Not to write with now:");for(let{id:r,name:l,version:m,state:f}of h)console.log(`${r} ${u(l)} ${m} ${J[f]}`);for(let{id:r,reason:l,version:m}of s)console.log(`${r}${m?` ${m}`:""} does not load: ${l.en}`);for(let r of i)console.log(H(r));p()}var Z=(t,{at:e,edit:o,optional:s,min:n,max:a})=>{let i=[s?"optional":"",n!==void 0?`at least ${n}`:"",a!==void 0?`at most ${a}`:""].filter(Boolean),c=o==="flow"?`${L}="${t}"`:e;return` ${t} ${c} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${i.length?` (${i.join(", ")})`:""}`};function tt(t,e){let o=$(t),s=o.problems.get(e),n=o.packages.get(e)??(s?.off?s:void 0);if(!n){let h=s?.problem;console.error(h?`${e} does not load: ${b("en",h)}`:Y(t,e)),process.exit(1)}let{state:a}=x(o).find(h=>h.id===e);console.log(`${e} ${u(n.name)}`),console.log(` \u7248\u672C\uFF1A${n.version}\uFF08${a==="normal"?"available":a}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${u(n.description)}`),console.log(` ${w(n.folder)}`);let i=Object.entries(n.parts);console.log(i.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[h,r]of i)console.log(Z(h,r));let c=S(n,"writing.md")?.trimEnd();console.log(c?`How to write it (writing.md):
58
- ${c}`:"How to write it: the package has no writing.md.");let p=S(n,"example.html")?.trimEnd();console.log(p?`The example (example.html):
59
- ${p}`:"The example: the package has no example.html."),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}var g={new:(t,e,o)=>X(t,e,o),list:Q,show:tt,check:async(t,e)=>(await import("./chunk-R7BNENLY.mjs")).checkCommand(t,e),try:async(t,e)=>(await import("./chunk-FUKQNOQS.mjs")).tryCommand(t,e)},et=["--press","--drag","--to","--key"];function ot(t){let e=t.indexOf("--"),o=(e===-1?t:t.slice(0,e)).findIndex(a=>a==="--key"||a.startsWith("--key="));if(o===-1)return{argv:t,key:null};let s=o+(t[o].includes("=")?1:2),n=t[s];if(n===void 0||s===e||k(n))throw new d("--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).");return{argv:t.filter((a,i)=>i!==s),key:n}}async function gt(t,{workspace:e}){try{return await nt(t,e)}catch(o){throw o instanceof d&&t.find(s=>!k(s))==="try"&&(o.synopsis=O),o}}async function nt(t,e){let{argv:o,key:s}=ot(t),{positional:n,options:a,values:i}=N({options:["--script","--flow","--keep"],values:et,argv:o}),[c,p,...h]=n,r=Object.keys(g).join(", ");if(!c)throw new d(`Say what to do: ${r}.`);if(!Object.hasOwn(g,c))throw new d(`No such component command: ${c} (${r}).`);let l=g[c];for(let f of["--script","--flow"])if(a.has(f)&&l!==g.new)throw new d(`${f} goes with new, not ${c}.`);let m=[...i.keys(),...a.has("--keep")?["--keep"]:[]];if(l===g.try)return l(e,{named:n.slice(1),values:i,key:s,keep:a.has("--keep")});if(m.length)throw new d(`${m[0]} goes with try, not ${c}.`);if(l===g.list){if(p!==void 0)throw new d(`gallery component ${c} takes nothing else.`);return l(e)}if(p===void 0||h.length>0)throw new d(`gallery component ${c} takes one id.`);return l(e,q(p),{script:a.has("--script"),flow:a.has("--flow")})}export{q as a,V as b,H as c,Y as d,ot as e,gt as f};
@@ -1,2 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as u,d as T,e as h,f as j,g as D,h as S}from"./chunk-S6O4UHLC.mjs";import{a as p,b as C}from"./chunk-TX6JH7TR.mjs";import{a as E,b as I,c as O,i as b}from"./chunk-5ZKJ3H4P.mjs";import{b as v,f as k,g as L}from"./chunk-NSKUTQ5J.mjs";import{b as N}from"./chunk-UALRNVSE.mjs";import{existsSync as R}from"node:fs";import a from"node:path";import{reportsDirectory as w}from"../browser/shared/paths.mjs";import{keptName as U,layoutOf as M,listTrash as X}from"../browser/shared/workspace.mjs";import{parentIn as _}from"../browser/shared/outline.mjs";var z="\u65B0\u6587\u6863";async function q(o,r=w){return U(o)?`"${o}" is a name the workspace keeps for itself: choose another slug.`:R(a.join(M(r).pages,o))?`"${o}" is the \u5199\u4F5C\u504F\u597D page's slug: choose another slug.`:R(a.join(r,o))?`Document already exists: ${p(a.join(r,o))}`:(await X(r)).some(s=>s.slug===o)?`"${o}" is a document's in the trash: choose another slug.`:null}async function te(o){let{positional:r,options:s,values:A}=k({options:["--no-preview","--no-browser","--first"],values:["--under","--after"],argv:o}),[t,g,y=z]=r;if(r.length<2||r.length>3||!t||!g?.trim()||!y.trim())throw new v("Name the slug and the title (then a description, if you choose one), each quoted when it has spaces.");L(t);let n=S(A,s,{top:!1}),$=await q(t);$&&(console.error($),process.exit(1));let F=n.under!==void 0||n.after!==void 0||n.first,c=null;if(F){let e=await u(),i=async(H,P)=>{let m=await T(H,P,e);return m.refused&&(console.error(`${m.refused} Nothing made.`),process.exit(1)),m.slug},l=n.under!==void 0?await i(n.under,"--under"):void 0,f=n.after!==void 0?await i(n.after,"--after"):null;f!==null&&l!==void 0&&_(e.children,f)!==l&&(console.error(`${h(e,t,"level",{parent:l,after:f})} Nothing made.`),process.exit(1)),c={parent:l,after:f,first:n.first}}try{await N(t,g,y)}catch(e){if(e.code!=="EEXIST")throw e;console.error(await q(t)??`Document already exists: ${p(a.join(w,t))}`),process.exit(1)}if(await import("./chunk-CEH4MRCC.mjs").then(({noteNew:e})=>e(t)),console.log(`Created ${p(a.join(w,t,"doc.html"))} and doc.json`),c){let e=await j(t,c),i=await u();e.ok?console.log(`Placed it ${D(i,e)}.`):(console.log(`Not placed (${h(i,t,e.reason,{...c,message:e.message})}): it is at the top level, last; gallery move ${t} puts it where it goes.`),process.exitCode=1)}for(let e of await C())console.log(e);let d=await b(t,{skipped:O(s),command:`gallery new ${t}`});console.log(E(d,"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 ${t}, then gallery qa ${t}`);let x=await I(d,s);x&&console.log(x);for(let e of d)console.log(e)}export{z as a,q as b,te as c};
@@ -1,2 +0,0 @@
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 E,b as F,c as H}from"./chunk-QJIR2BLP.mjs";import{b as L,c as O,d as b,e as D}from"./chunk-W4VKN3GF.mjs";import{existsSync as K}from"node:fs";var Q=120;function R(n,h){let r=({packages:s,problems:l})=>new Map([...s,...l].map(([e,{stamp:m}])=>[e,m])),[o,p]=[r(n),r(h)];return[...new Set([...o.keys(),...p.keys()])].filter(s=>o.get(s)!==p.get(s)).sort()}function v({root:n,tell:h,delay:r=Q,quiet:o=H,hold:p=E,limit:s=F,now:l=Date.now}){let e=null,m=0,f=null,c=new Map;b(n);let I=i=>{e&&m<=l()+i||(clearTimeout(e),m=l()+i,e=setTimeout(y,i),e.unref?.())};function y({settled:i=!1}={}){e=null;let u=b(n),a=O(n,u.settings),M=l();a.stamp!==f?.stamp&&(f={stamp:a.stamp,at:M});let T=M-f.at;if(T<o&&!i)return I(o-T);let d=new Map(a.packages),g=new Map(a.problems),k=1/0;for(let[t,S]of u.packages){if(!(!a.settings.disabled.includes(t)&&(g.has(t)||!d.has(t)&&K(S.folder)))){c.delete(t);continue}c.has(t)||c.set(t,f.at);let x=Math.min(p-T,s-(M-c.get(t)));if(x<=0){c.delete(t);continue}d.set(t,S),g.delete(t),k=Math.min(k,x)}let{settings:w}=a,C=L({packages:d,problems:g,settings:w});if(C!==u.stamp){let t={packages:d,problems:g,settings:w,stamp:C};D(n,t),h(t,R(u,t))}k!==1/0&&I(k)}return{changed:()=>I(r),taken(){clearTimeout(e),y({settled:!0})},close(){clearTimeout(e),e=null}}}export{Q as a,v as b};
@@ -1,5 +0,0 @@
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 $ from"node:fs";import{fileURLToPath as y}from"node:url";import{namedPlace as h}from"../browser/shared/page-address.mjs";import{pageLinks as w}from"../browser/shared/page-links.mjs";import{reportsDirectory as b}from"../browser/shared/paths.mjs";import{listReportSlugs as g,slugPattern as x}from"../browser/shared/reports.mjs";import{RESERVED as v,isSlugName as N,listTrash as O}from"../browser/shared/workspace.mjs";var d=e=>/^--.|^-[A-Za-z]/.test(e),i=class extends Error{constructor(n){super(n),this.name="UsageError"}};function A(e){let n=$.readFileSync(y(e),"utf8").split(/\r?\n/),t=n.findIndex(s=>!s.startsWith("//"));return n.slice(0,t===-1?n.length:t).map(s=>s.replace(/^\/\/ ?/,"")).join(`
3
- `)}var E=e=>/^Usage: (gallery \S+|npm run \S+|node \S+)/.exec(e)?.[1]??"this command",P=e=>e.split(`
4
- `)[0],R=(e,n,t=P(e))=>{let s=E(e);return`${n}
5
- ${t} (${s}${s.startsWith("npm run")?" --":""} --help says more)`},T=e=>{let n=e.indexOf("--");return(n===-1?e:e.slice(0,n)).some(t=>t==="--help"||t==="-h")};function k({options:e=[],values:n=[],argv:t=process.argv.slice(2)}={}){let s=t.indexOf("--"),[o,a]=s===-1?[t,[]]:[t.slice(0,s),t.slice(s+1)],u=[],l=new Set,p=new Map;for(let c=0;c<o.length;c++){let r=o[c],[f,S]=r.startsWith("--")&&r.includes("=")?[r.slice(0,r.indexOf("=")),r.slice(r.indexOf("=")+1)]:[r,void 0];if(!d(r))u.push(r);else if(n.includes(f)){let m=S??(c+1<o.length&&!d(o[c+1])?o[++c]:void 0);if(!m)throw new i(`${f} takes a value`);p.set(f,m)}else if(e.includes(r))l.add(r);else throw new i(`Unknown option: ${r}`)}return{positional:[...u,...a],options:l,values:p}}function U(e){if(!x.test(e))throw new i(`Not a document's slug: ${e} (lowercase kebab-case).`);if(v.has(e))throw new i(`Not a document's slug: ${e} (a name the workspace keeps for itself).`);return e}async function L(e){let n=await O(b),t=h(e,w(n));return t&&`${e} is a document in the trash ("${n.find(({slug:s})=>s===t.slug).title}"): it has to be restored in the workbench first.`}async function W(e){let n=(await g()).filter(N),t=h(e,w(n.map(o=>({slug:o}))));if(t)return t;let s=await L(e);if(s)throw new i(s);if(!x.test(e))throw new i(`Not a document's slug, link or address: ${e} (gallery list shows them).`);return{slug:U(e),block:null}}async function D({options:e=[],values:n=[],argv:t,noneIsAll:s=!1}={}){let{positional:o,options:a,values:u}=k({options:["--all",...e],values:n,argv:t}),l=a.has("--all");if(l&&o.length>0)throw new i("Name documents or pass --all, not both.");if(!l&&o.length===0&&!s)throw new i("Name a document (or pass --all).");let p=await Promise.all(o.map(W));return{slugs:l||o.length===0?await g():[...new Set(p.map(({slug:c})=>c))],options:a,values:u}}async function Z(e,{documents:n=!1,...t}={}){let s=A(e),o=t.argv??process.argv.slice(2);T(o)&&(console.log(s),process.exit(0));try{return n?await D({...t,argv:o}):k({...t,argv:o})}catch(a){if(!(a instanceof i))throw a;console.error(R(s,a.message)),process.exit(2)}}export{d as a,i as b,A as c,R as d,T as e,k as f,U as g,L as h,W as i,D as j,Z as k};
@@ -1,2 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j}from"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-L3QKH4OK.mjs";import"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{g as changeLines,c as handedInSource,f as headerChanged,e as inStep,a as naturalize,d as pendingBlockIds,h as readOnlyTexts,j as scriptKept,b as shownSource,i as writingNotes};
@@ -1,3 +0,0 @@
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 W from"node:http";import ot from"node:https";import it from"node:tls";import R from"node:zlib";import{Readable as st}from"node:stream";import{execFile as at}from"node:child_process";import{promisify as ct}from"node:util";var q=ct(at),lt=/^(localhost|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[?::1\]?$|0\.0\.0\.0)/i;function ut(t,e){let r=t.toLowerCase();for(let o of e){let n=o.trim().toLowerCase();if(!n)continue;if(n==="*")return!0;if(n==="<local>"){if(!r.includes("."))return!0;continue}if(n.includes("*")){if(new RegExp(`^${n.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*")}$`).test(r))return!0;continue}let i=n.replace(/^\./,"").replace(/:\d+$/,"");if(r===i||r.endsWith(`.${i}`))return!0}return!1}var D=t=>/^[a-z]+:\/\//i.test(t)?t:`http://${t}`;function ft(t=process.env){let e=t.HTTPS_PROXY||t.https_proxy||t.HTTP_PROXY||t.http_proxy||t.ALL_PROXY||t.all_proxy;return e?{url:D(e),bypass:(t.NO_PROXY||t.no_proxy||"").split(",")}:null}async function pt(){let{stdout:t}=await q("reg",["query","HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"],{windowsHide:!0,timeout:3e3}),e=n=>new RegExp(`^\\s*${n}\\s+REG_\\w+\\s+(.*)$`,"mi").exec(t)?.[1]?.trim();if(Number.parseInt(e("ProxyEnable")||"0",16)!==1)return null;let r=e("ProxyServer");if(!r)return null;let o=r;if(r.includes("=")){let n=Object.fromEntries(r.split(";").map(i=>i.split("=").map(s=>s.trim())));if(o=n.https||n.http,!o)return null}return{url:D(o),bypass:(e("ProxyOverride")||"").split(";")}}async function mt(){let{stdout:t}=await q("scutil",["--proxy"],{timeout:3e3}),e=o=>new RegExp(`\\b${o}\\s*:\\s*(\\S+)`).exec(t)?.[1];if(e("HTTPSEnable")!=="1"||!e("HTTPSProxy"))return null;let r=[...t.matchAll(/^\s*\d+\s*:\s*(\S+)\s*$/gm)].map(o=>o[1]);return{url:`http://${e("HTTPSProxy")}:${e("HTTPSPort")||80}`,bypass:r}}var I=null,H=0;async function dt(){let t=ft();if(t)return t;if(I!==null&&Date.now()-H<3e4)return I||null;let e=null;try{process.platform==="win32"?e=await pt():process.platform==="darwin"&&(e=await mt())}catch{e=null}return I=e||!1,H=Date.now(),e}async function ht(t){let e;try{e=new URL(t).hostname}catch{return null}if(lt.test(e))return null;let r=await dt();return r&&!ut(e,r.bypass)&&/^http:/i.test(r.url)?r.url:null}var M=t=>t.username?{"proxy-authorization":`Basic ${Buffer.from(`${decodeURIComponent(t.username)}:${decodeURIComponent(t.password)}`).toString("base64")}`}:{};function gt(t,e,r,o){return new Promise((n,i)=>{let s=W.request({host:t.hostname,port:t.port||80,method:"CONNECT",path:`${e}:${r}`,headers:{host:`${e}:${r}`,...M(t)},signal:o});s.once("connect",(l,m)=>{l.statusCode===200?n(m):(m.destroy(),i(new Error(`the proxy answered ${l.statusCode}`)))}),s.once("error",i),s.end()})}function yt(t,{method:e,headers:r,signal:o},n){let i=new URL(t),s=new URL(n),l={"accept-encoding":"gzip, deflate, br",...r};return new Promise((m,u)=>{let d=g=>{g.once("response",m),g.once("error",u),g.end()};if(i.protocol==="http:"){d(W.request({host:s.hostname,port:s.port||80,method:e,path:i.href,headers:{...l,host:i.host,...M(s)},signal:o}));return}gt(s,i.hostname,i.port||443,o).then(g=>{d(ot.request(i,{method:e,headers:{...l,host:i.host},defaultPort:443,signal:o,createConnection:()=>it.connect({socket:g,servername:i.hostname,ALPNProtocols:["http/1.1"]})}))},u)})}function wt(t,e){let r=new Headers;for(let[m,u]of Object.entries(t.headers))r.set(m,Array.isArray(u)?u.join(", "):String(u));let o=(t.headers["content-encoding"]||"").toLowerCase(),n={gzip:R.createGunzip,"x-gzip":R.createGunzip,deflate:R.createInflate,br:R.createBrotliDecompress}[o],i=n?t.pipe(n()):t;n&&(t.on("error",m=>i.destroy(m)),r.delete("content-encoding"),r.delete("content-length"));let s=[101,204,205,304].includes(t.statusCode);s&&t.resume();let l=new Response(s?null:st.toWeb(i),{status:t.statusCode,statusText:t.statusMessage,headers:r});return Object.defineProperty(l,"url",{value:e}),l}async function bt(t,{method:e="GET",headers:r={},signal:o}={},n){for(let i=0;;i++){let s=await yt(t,{method:e,headers:r,signal:o},n),l=s.headers.location;if([301,302,303,307,308].includes(s.statusCode)&&l&&i<10){s.resume(),t=new URL(l,t).href,s.statusCode===303&&(e="GET");continue}return wt(s,t)}}async function xt(t,e={}){let r=await ht(t);if(r)try{return await bt(t,e,r)}catch(o){if(e.signal?.aborted)throw o}return fetch(t,e)}var $t="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0 Safari/537.36";async function L(t,{timeout:e=1e4,accept:r="*/*",headers:o={},unreachable:n="\u6253\u4E0D\u5F00\u8FD9\u4E2A\u7F51\u9875",protocols:i=["http:","https:"]}={}){let s;try{s=new URL(t)}catch{throw Object.assign(new Error("\u4E0D\u662F\u7F51\u5740"),{reason:"url"})}if(!i.includes(s.protocol))throw Object.assign(new Error("\u53EA\u652F\u6301 http(s) \u7F51\u5740"),{reason:"url"});return xt(s,{redirect:"follow",signal:AbortSignal.timeout(e),headers:{"user-agent":$t,accept:r,...o}}).catch(()=>{throw Object.assign(new Error(n),{reason:"download"})})}async function _(t,e){let r=t.body.getReader(),o=[],n=0;for(;;){let{done:i,value:s}=await r.read();if(i)break;if(o.push(Buffer.from(s)),n+=s.length,n>=e){r.cancel().catch(()=>{});break}}return Buffer.concat(o)}async function j(t,e){let r=await _(t,e+1);return r.length<=e?r:null}import{createHash as Tt,randomUUID as Rt}from"node:crypto";import b from"node:fs/promises";import P from"node:path";import{refusal as jt,said as Q,saying as vt}from"../browser/shared/i18n/index.mjs";import{extensionOf as Ft,imageExtension as It,imageFile as Y,mediaTypeOf as _t,UPLOAD_LIMITS as S}from"../browser/shared/media.mjs";import{slugPattern as z}from"../browser/shared/reports.mjs";import{documentDirectory as J,documentFiles as zt,layoutOf as At}from"../browser/shared/workspace.mjs";import{refusal as Pt,said as St}from"../browser/shared/i18n/index.mjs";var Lt={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "},G=t=>t.replace(/&(#x[0-9a-f]+|#\d+|\w+);/gi,(e,r)=>{if(r[0]==="#"){let o=r[1]==="x"||r[1]==="X"?parseInt(r.slice(2),16):Number(r.slice(1));return Number.isFinite(o)&&o>0&&o<=1114111?String.fromCodePoint(o):e}return Lt[r.toLowerCase()]??e}),B=t=>G(String(t??"")).replace(/\s+/g," ").trim();function Ot(t){let e={};for(let r of t.matchAll(/([\w:-]+)\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+))/g))e[r[1].toLowerCase()]=r[3]??r[4]??r[5]??"";return e}function Et(t,e){let r=/charset=([\w-]+)/i.exec(e??"")?.[1];r||(r=/<meta[^>]+charset=["']?([\w-]+)/i.exec(t.subarray(0,4096).toString("latin1"))?.[1]);try{return new TextDecoder(r||"utf-8").decode(t)}catch{return new TextDecoder("utf-8").decode(t)}}function Ct(t,e){let r=t.search(/<\/head>/i),o=r>0?t.slice(0,r):t.slice(0,3e5),n={},i=[];for(let[u]of o.matchAll(/<(meta|link)\b[^>]*>/gi)){let d=Ot(u);if(/^<meta/i.test(u)){let g=(d.property||d.name||d.itemprop||"").toLowerCase();g&&d.content!==void 0&&!(g in n)&&(n[g]=d.content)}else d.rel&&d.href&&/(^|\s)(icon|shortcut icon|apple-touch-icon)(\s|$)/i.test(d.rel)&&i.push({rel:d.rel.toLowerCase(),href:d.href})}let s=u=>{try{return u?new URL(G(u),e).href:null}catch{return null}},l=/<title[^>]*>([\s\S]*?)<\/title>/i.exec(o)?.[1],m=i.find(u=>/(^|\s)icon(\s|$)/.test(u.rel))??i.find(u=>u.rel.includes("icon"));return{title:B(n["og:title"]||n["twitter:title"]||l||"").slice(0,300),description:B(n["og:description"]||n["twitter:description"]||n.description||"").slice(0,600),icon:s(m?.href)||s("/favicon.ico"),cover:s(n["og:image"]||n["og:image:url"]||n["og:image:secure_url"]||n["twitter:image"]||n["twitter:image:src"])}}async function kt(t){if(!t)return null;try{let e=await L(t,{timeout:8e3,accept:"image/*,*/*;q=0.5",protocols:["http:","https:","data:"]}),r=(e.headers.get("content-type")??"").split(";")[0].trim();if(!e.ok||!/^image\//.test(r))return null;let o=await j(e,5*1024*1024);return o?.length?o:null}catch{return null}}async function X(t){try{let e=await L(t,{timeout:8e3,accept:"text/html,*/*;q=0.8"});e.body?.cancel().catch(()=>{});let r=(e.headers.get("x-frame-options")??"").toLowerCase(),o=/frame-ancestors([^;]*)/i.exec(e.headers.get("content-security-policy")??"")?.[1]?.trim().toLowerCase();return/deny|sameorigin/.test(r)?{frameable:!1,reason:"x-frame-options"}:o!==void 0&&!/(^|\s)\*(\s|$)/.test(o)?{frameable:!1,reason:"frame-ancestors"}:{frameable:!0}}catch(e){return e.reason==="url"?{frameable:!1,reason:"url"}:{frameable:!0,reason:"unknown"}}}async function K(t,e,{icon:r=!0,cover:o=!0}={}){let n=await L(t,{accept:"text/html,application/xhtml+xml;q=0.9,*/*;q=0.8",headers:{"accept-language":"zh-CN,zh;q=0.9,en;q=0.8"}}),i=n.url||new URL(t).href,s=n.headers.get("content-type")??"";if(!n.ok)throw Pt(St("\u7F51\u9875\u8FD4\u56DE {0}",n.status),{reason:"download"});if(!/html|xml/i.test(s))return n.body?.cancel().catch(()=>{}),{url:i,title:"",description:"",icon:null,cover:null};let l=Ct(Et(await _(n,1.5*1024*1024),s),i),m=async(g,F)=>{let C=await kt(g);try{return C?await e(C,F):null}catch{return null}},[u,d]=await Promise.all([r?m(l.icon,"bookmark-icon"):null,o?m(l.cover,"bookmark-cover"):null]);return{url:i,title:l.title,description:l.description,icon:u,cover:d}}var Z=t=>Ft(String(t??"").replace(/[?#].*$/,"")),Nt=t=>{let e=String(t??"").replace(/[?#].*$/,"");e=e.slice(e.lastIndexOf("/")+1);try{e=decodeURIComponent(e)}catch{}return e.replace(/[\u0000-\u001f<>:"/\\|?*]/g,"").trim().slice(0,120)||"file"};function Ut(t){let e=t.subarray(0,16);return e[0]===137&&e.toString("latin1",1,4)==="PNG"?"image/png":e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?"image/x-icon":e[0]===255&&e[1]===216?"image/jpeg":e.toString("latin1",0,4)==="GIF8"?"image/gif":e.toString("latin1",0,4)==="RIFF"&&e.toString("latin1",8,12)==="WEBP"?"image/webp":e.toString("latin1",4,12)==="ftypavif"?"image/avif":/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*<svg\b/i.test(t.subarray(0,512).toString("utf8"))?"image/svg+xml":null}var E=(t,e)=>jt(e,{reason:t}),A=(t,e)=>{let r=Ut(t);if(!r)throw E("type","\u4EC5\u652F\u6301\u56FE\u7247");return It(r)},Ht=(t,e)=>Z(e),Wt=(t,e)=>{let r=Z(e);if(!["html","htm","pdf"].includes(r)||r==="pdf"&&t.subarray(0,5).toString("latin1")!=="%PDF-")throw E("type","\u53EA\u80FD\u5D4C\u5165 HTML \u6216 PDF \u6587\u4EF6");return r},v={big:t=>Q("\u56FE\u7247\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",t),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u5F20\u56FE\u7247"},V={big:t=>Q("\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",t),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u4E2A\u6587\u4EF6"},N={icon:{limit:S.icon,words:v,extension:A},image:{limit:S.image,words:v,extension:A},file:{limit:S.file,words:V,extension:Ht,named:!0},embed:{limit:S.embed,words:V,extension:Wt,named:!0}};function le(t,e,r,o){let n=N[t].extension(r,o);return`${t}-${e.slice(0,12)}${n?`.${n}`:""}`}function ue({reportsDirectory:t}){let e=At(t).emojiLibrary,r=async a=>{let c=J(a,t);return await b.stat(zt(c).html).catch(()=>null)?c:null},o=P.join(e,"library.json"),n=(a,c,f)=>[a,{ok:!1,reason:c,...vt(f)}];async function i(a,c,{stem:f,limit:p,words:y=v,extension:h=A,given:x}){let w=h(c,x);if(c.length>p)throw E("size",y.big(p/1024/1024));let O=`${f}-${Tt("sha256").update(c).digest("hex").slice(0,12)}${w?`.${w}`:""}`;await b.mkdir(a,{recursive:!0});let k=P.join(a,O);return await b.stat(k).catch(()=>null)||await b.writeFile(k,c),O}let s=(a,c,f,p=S.icon)=>i(a,c,{stem:f,limit:p});async function l(a,c,f=v){let p=await L(a,{unreachable:f.unreachable});if(!p.ok)throw E("download",f.unreachable);let y=await j(p,c);if(!y)throw E("size",f.big(c/1024/1024));return y}async function m(){try{let a=JSON.parse(await b.readFile(o,"utf8"));return Array.isArray(a)?a:[]}catch{return[]}}let u=a=>({id:a.id,name:a.name,url:`/__gallery/edit/emoji-library/${a.file}`,created_time:a.created,alive:!0});async function d(a){let{slug:c,data:f,url:p,library:y}=a??{},h=Object.hasOwn(N,a?.kind)?a.kind:"icon";if(typeof c!="string"||!z.test(c))return n(400,"body");let x=await r(c);if(!x)return n(404,"missing");let{limit:w,words:O,extension:k,named:rt}=N[h];try{let $,T;if(typeof f=="string")$=Buffer.from(f,"base64"),T=a.name;else if(typeof p=="string")$=await l(p,w,O),T=p;else if(typeof y=="string"){let U=(await m()).find(nt=>nt.id===y);if(!U)return n(404,"library","\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u8868\u60C5\u5DF2\u4E0D\u5728\u8868\u60C5\u5E93\u91CC");$=await b.readFile(P.join(e,U.file))}else return n(400,"body");return[200,{ok:!0,path:`assets/${await i(P.join(x,"assets"),$,{stem:h,limit:w,words:O,extension:k,given:T})}`,...rt?{name:Nt(T),size:$.length}:{}}]}catch($){return n(422,$.reason??"write",$)}}async function g(a){let{slug:c,url:f,parts:p="all"}=a??{};if(typeof c!="string"||!z.test(c)||typeof f!="string"||!["all","icon","title"].includes(p))return n(400,"body");let y=await r(c);if(!y)return n(404,"missing");try{return[200,{ok:!0,...await K(f,async(x,w)=>`assets/${await s(P.join(y,"assets"),x,w,S.image)}`,{icon:p!=="title",cover:p==="all"})}]}catch(h){return n(422,h.reason??"download",h)}}async function F(a){return typeof a?.url!="string"?n(400,"body"):[200,{ok:!0,...await X(a.url)}]}async function C(a){let{slug:c,name:f,url:p}=a??{};if(typeof f!="string"||!/^[\p{Ll}\p{Lo}\d_-]{1,49}$/u.test(f)||typeof p!="string")return n(400,"body");let y=await m();if(y.some(h=>h.name===f))return n(409,"name","\u540D\u79F0\u5DF2\u88AB\u5360\u7528");try{let h;Y(p)&&typeof c=="string"&&z.test(c)?h=await b.readFile(P.join(J(c,t),p)):h=await l(p,S.icon);let x=await s(e,h,"emoji"),w={id:Rt(),name:f,file:x,created:Date.now()};return await b.writeFile(o,`${JSON.stringify([...y,w],null,2)}
3
- `),[200,{ok:!0,entry:u(w)}]}catch(h){return n(422,h.reason??"write",h)}}let tt=async()=>[200,{ok:!0,list:(await m()).map(u)}];async function et(a){if(!Y(`assets/${a}`))return null;let c=await b.readFile(P.join(e,a)).catch(()=>null);return c&&{type:_t(a),body:c}}return{upload:d,unfurl:g,frameable:F,addEmoji:C,listEmojis:tt,readEmoji:et}}export{L as a,j as b,le as c,ue as d};
@@ -1,15 +0,0 @@
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 Fe}from"./chunk-TX6JH7TR.mjs";import{a as _e,b as He,c as Be,d as We,e as qe,f as Ge}from"./chunk-DFUDV4LX.mjs";import{g as Ie}from"./chunk-E7LWZRXY.mjs";import{o as Re}from"./chunk-AUZGSZJH.mjs";import{a as me}from"./chunk-HYMEEXKN.mjs";import{b as Ce}from"./chunk-CY2FNNAB.mjs";import{l as Pe}from"./chunk-W4VKN3GF.mjs";import D from"node:fs/promises";import Ue from"node:os";import S from"node:path";import{pathToFileURL as Ye}from"node:url";import{instancesOf as ze}from"../browser/shared/components/index.mjs";import{FALLBACK as it,INSTANCE as ke,SLOT as rt,SLOT_PART as lt}from"../browser/shared/components/installed.mjs";import{layoutOf as ct,PACKAGE_MANIFEST as dt}from"../browser/shared/workspace.mjs";var ht="in a browser, under the export's policy",te="component-check",ne=[360,736,1024],ge=["light","dark"],pt=[1024,360],Ke=1e4,ut=6e4,ye=3e4,Xe=2e3,ft=3e3,wt=60,mt=2,gt=8,kt=ye/2,$t=/^(?:wasm-)?eval$/,yt=new Set(["TargetCloseError","ConnectionClosedError"]),$e=t=>String(t?.message??t).split(`
3
- `)[0],bt=(t,a)=>`<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${t}</title></head><body><main class="doc-page" data-doc-id="${t}">${a}
4
- </main></body></html>
5
- `,xt=({example:t,template:a})=>`<p>example.html</p>${t}
6
- <hr><p>template.html</p>${a}`,Qe=(t,a)=>ze(me(t),a).map(({sourceCodeLocation:{startLine:i,startOffset:r,endOffset:n}})=>({line:i,markup:t.slice(r,n)}));async function vt(t,a){let i=S.join(a,"components",...t.id.split("/"));for(let r of[dt,"template.html",...t.files]){let n=Pe(t,r);if(!n)continue;let s=await D.readFile(n);await D.mkdir(S.dirname(S.join(i,r)),{recursive:!0}),await D.writeFile(S.join(i,r),r==="kit.js"?`${s}
7
- //# sourceURL=kit.js
8
- `:s)}}async function Tt(t,{example:a,template:i},r){await vt(t,r);let n=S.join(r,te);await D.mkdir(n);let s=`${a}
9
- `,p=Ce(bt(te,xt({example:a,template:i}))).text;await D.writeFile(S.join(n,"doc.html"),p),await D.writeFile(S.join(n,"doc.json"),JSON.stringify({title:te,description:te,type:"component"}));let u=await(await Re({directory:r}))(te),l=S.join(r,"export.html");await D.writeFile(l,u);let w=s.split(`
10
- `).length-1,k=Qe(p,t).map(({line:c})=>c>w?{file:"template.html",line:c-w}:{file:"example.html",line:c});return{html:u,file:l,places:k,source:p}}async function jt({match:t,instance:a,slotPart:i,slotName:r,fallback:n,parts:s,at:p,source:h,still:u,step:l,times:w,typed:k,typing:c}){let d=()=>[...document.querySelectorAll(t)].filter(e=>!e.parentElement.closest(a)),T=e=>new Promise(o=>setTimeout(o,e)),g=()=>new Promise(e=>{requestAnimationFrame(e),setTimeout(e,100)}),$=async e=>{await g(),await g();let o=e.outerHTML;for(let m=0,y=Date.now()+u;m<3;){if(Date.now()>y)return null;await T(l);let b=e.outerHTML;m=b===o?m+1:0,o=b}return o},f=e=>{let o=document.createElement("template");return o.innerHTML=e,o.content.firstElementChild},x=e=>`<${e.localName}${e.classList.length?` class="${e.getAttribute("class")}"`:""}>`,P=e=>e.nodeType===1?x(e):`the words "${e.data.trim().slice(0,40)}"`,q=e=>[...e.childNodes].filter(o=>o.nodeType===1||o.nodeType===3&&o.data.trim()),R=(e,o)=>["style","class"].includes(o)&&!e.getAttribute(o)?.trim()?null:e.getAttribute(o),V=(e,o)=>{for(let b of new Set([...e.getAttributeNames(),...o.getAttributeNames()]))if(R(e,b)!==R(o,b))return`${b} on ${x(o)}, ${JSON.stringify(R(e,b))} then ${JSON.stringify(R(o,b))}`;let[m,y]=[q(e),q(o)];for(let b=0;b<Math.max(m.length,y.length);b++){let[j,L]=[m[b],y[b]];if(!j||!L)return`${x(o)} ${j?`without ${P(j)}`:`with ${P(L)} more`}`;if(j.nodeType!==L.nodeType||j.localName!==L.localName||j.nodeType===3&&j.data.trim()!==L.data.trim())return`in ${x(o)}, ${P(j)} then ${P(L)}`;let I=j.nodeType===1?V(j,L):null;if(I)return I}return null},se=e=>{let o=new Map;for(let m of e)o.set(x(m),(o.get(x(m))??0)+1);return o},be=()=>[...document.querySelectorAll("*")].filter(e=>!e.closest(a)),xe=e=>[...e.at(-1).keys()].filter(o=>e.length>2&&e.every((m,y)=>y===0||(m.get(o)??0)>(e[y-1].get(o)??0))),ve=e=>e.parentElement?.closest(`${a}, ${i}`)??null,Te=e=>[...e.querySelectorAll(i)].filter(o=>ve(o)===e),H=e=>{let o=e.cloneNode(!0);return Te(o).forEach(m=>m.replaceChildren()),o},X=e=>Te(e).map(o=>{let m=[];for(let y=o.parentElement;y&&y!==e;y=y.parentElement)m.unshift(x(y));return{name:o.getAttribute(r),place:m.join(" > "),blocks:[...DocKit.dehydrate(o.cloneNode(!0)).children].map(y=>y.localName).join(" "),html:o.outerHTML}}),ie=(e,o,m,{markup:y=!0}={})=>e.flatMap(({name:b,place:j,blocks:L,html:I})=>{let N=o.find(F=>F.name===b),z=N?N.place!==j?`moved the slot ${b} (${N.place?`in ${N.place}`:"straight in the instance"}, where the file has it ${j?`in ${j}`:"straight in the instance"})`:N.blocks!==L?`changed the blocks the slot ${b} holds (${L||"none"}, then ${N.blocks||"none"})`:y&&N.html!==I?`changed what the slot ${b} holds`:null:`took the slot ${b} off the instance`;return z?[{kind:"written-in",part:b,how:`${z}, ${m}`}]:[]}),je=e=>o=>ve(o)===e,re=(e,o=()=>!0)=>Object.entries(s).filter(([,{edit:m}])=>o(m)).flatMap(([m,y])=>[...e.querySelectorAll(y.at)].filter(je(e)).map(b=>({name:m,node:b}))),Q=e=>re(e,o=>o==="text"),J=e=>Object.entries(s).filter(([,{edit:o}])=>o==="data").map(([o,m])=>({name:o,node:[...e.querySelectorAll(m.at)].find(je(e))})).filter(({node:o})=>o),C=[],G=d()[p];if(!G)return[{kind:"gone"}];if(G.hasAttribute(n))return[{kind:"fallback"}];let le=await $(G);if(le===null)return[{kind:"moving"}];let ae=f(h),Ee=X(G);C.push(...ie(X(ae),Ee,"as it mounts",{markup:!1}));let ce=Q(ae);Q(G).forEach(({name:e,node:o},m)=>{ce[m]&&ce[m].node.innerHTML!==o.innerHTML&&C.push({kind:"redrawn",part:e,how:`the file says ${JSON.stringify(ce[m].node.textContent.trim())}, the page ${JSON.stringify(o.textContent.trim())}`})});let de=DocKit.dehydrate(G.cloneNode(!0)),[Se,Ne]=[H(ae),H(de)],he=V(Se,Ne);if(he){let e=re(Ne),o=re(Se).find(({node:m},y)=>e[y]&&V(m,e[y].node))?.name;C.push({kind:"left",what:he,...o?{part:o}:{}})}let tt=J(de);for(let[e,{name:o,node:m}]of J(ae).entries())!he&&tt[e]?.node.innerHTML!==m.innerHTML&&C.push({kind:"data",part:o});let Y=[],pe=new MutationObserver(e=>Y.push(...e));pe.observe(document.documentElement,{subtree:!0,childList:!0,characterData:!0});let Ae=new Set,Oe=e=>{Y.push(...pe.takeRecords());for(let{name:o,node:m}of e)(!m.isConnected||Y.some(({target:y})=>m.contains(y)))&&Ae.add(o);Y.length=0},ue=[le],fe=[se(be())],Le=e=>{ue.push(e),fe.push(se(be())),C.push(...ie(Ee,X(v),"as it mounts again"))},v=de,we=Q(v);Y.length=0,G.replaceWith(v);let B=await $(v);if(Oe(we),B!==null){Le(B);for(let e=0;e<w&&B!==null;e++){let o=v.cloneNode(!0);we=Q(o),Y.length=0,v.replaceWith(o),v=o,B=await $(v),Oe(we),B!==null&&Le(B)}}pe.disconnect(),B===null&&C.push({kind:"moving"});for(let e of Ae)C.push({kind:"redrawn",part:e,how:"a mount changes it"});let Me=ue.map(e=>se(H(f(e)).querySelectorAll("*"))),De=xe(Me);for(let e of De)C.push({kind:"piles",what:e,counts:Me.map(o=>o.get(e)??0)});for(let e of xe(fe))C.push({kind:"piles",what:e,outside:!0,counts:fe.map(o=>o.get(e)??0)});if(!De.length){let e=ue.slice(1).map(o=>V(H(f(le)),H(f(o)))).find(Boolean);e&&C.push({kind:"changed",what:e})}let oe=B===null?[]:Q(v).filter(({node:e})=>e.textContent.trim()),nt=[...new Set([...new Map(oe.map(e=>[e.name,e])).values(),...oe])].slice(0,k),at=Date.now()+c;for(let{node:e}of nt){if(Date.now()>at)break;let o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT).nextNode(),m=o.data;o.data=`${m}\u2026`;let y=oe.map(({node:j})=>j.textContent);await $(v);let b=oe.find(({node:j},L)=>!j.isConnected||j.textContent!==y[L]);if(b){C.push({kind:"redrawn",part:b.name,how:"a change of its words does not stand"});break}o.data=m,await $(v)}return B!==null&&J(v).length>0&&C.push(...await ot()),C;async function ot(){let e=[],o=null,m=!1,y="as it hears that it can write (the editable signal)",b=[],j=I=>{if(I.target!==v)return;let{parts:N,run:z}=I.detail,F=N.map(({part:E})=>E.innerHTML),M=N.map(({part:E})=>E.cloneNode(!0)),Z=z(Object.fromEntries(N.map(({name:E},A)=>[E,M[A]]))),W=N.find(({part:E},A)=>E.innerHTML!==F[A]),U=N.find(({part:E},A)=>M[A].cloneNode(!1).outerHTML!==E.cloneNode(!1).outerHTML);if(W&&N.forEach(({part:E},A)=>{E.innerHTML=F[A]}),!m){let E=W??U??N.find((A,ee)=>M[ee].innerHTML!==F[ee]);E&&!b.some(A=>A.when===y)?b.push({kind:"unasked",part:E.name,when:y}):Z&&!E&&I.preventDefault();return}W?o??=`it writes the part ${W.name} on the page, not the draft context.edit hands it, so the editor refuses the edit`:Z&&U&&(o??=`it changes the part ${U.name}'s own tag or attributes, which are the file's: a change writes what a part holds, so the editor refuses the edit`),!(W||!Z||U)&&(N.forEach(({part:E},A)=>{e.push({part:E,before:F[A]}),E.replaceChildren(...M[A].childNodes)}),I.preventDefault())};document.addEventListener("doc-component-edit",j);try{return[...await L(),...b]}finally{document.removeEventListener("doc-component-edit",j)}async function L(){dispatchEvent(new Event("doc-editable")),await $(v),y="as it mounts";let I=v.cloneNode(!0);v.replaceWith(I),v=I;let N=await $(v);y="as it hears its part changed (the source signal)";let z=X(v),F=DocKit.dehydrate(v.cloneNode(!0)),M=[];m=!0;try{if(!DocKit.example(v))return[{kind:"no-example"}]}catch(_){return[{kind:"example",what:`it throws: ${_?.message??_}`}]}finally{m=!1}let Z=await $(v),W=DocKit.dehydrate(v.cloneNode(!0)),U=Object.fromEntries(J(W).map(({name:_,node:K},st)=>[_,K.innerHTML,J(F)[st]?.node.innerHTML]).filter(([,_,K])=>_!==K));o?M.push({kind:"example",what:o}):e.length===0?M.push({kind:"example",what:"context.edit was not taken: it was not called, or it answered false, and the console says why"}):Object.keys(U).length===0?M.push({kind:"example",what:"it changes nothing a part holds"}):M.push({kind:"wrote",parts:U});for(let _ of[F,W])for(let{node:K}of J(_))K.textContent="";let E=V(H(F),H(W));E&&M.push({kind:"example",what:`it changes what is no data part: ${E}`}),M.push(...ie(z,X(v),"as its example makes its edit"));for(let{part:_,before:K}of e.reverse())_.innerHTML=K;let A=await $(v),ee=N!==null&&A!==null?V(H(f(N)),H(f(A))):null;return Z===null||A===null?M.push({kind:"moving"}):ee&&!E&&M.push({kind:"undo",what:ee}),M}}}var Et=t=>t.map(({name:a,removed:i,added:r,lines:n})=>`${a} (-${i} +${r} of its ${n} line${n===1?"":"s"})`).join(" and "),St="a write changes the lines it means and no others, a row moved with the blank before it, JSON written back by jsonIn and laid out in template.html and example.html as jsonIn writes it (building-components.md, Two examples)";function Nt({kind:t,what:a,part:i,how:r,when:n,counts:s,outside:p,parts:h,back:u,line:l},w,{script:k}){let c=T=>({...w,what:T}),d=T=>({...w,what:T,note:!0});switch(t){case"wrote":return{...w,told:!0,what:`its example wrote ${Et(h)}; the server took it${u?"; put back as an undo does, it shows what it showed":""}`};case"laid":return d(`its example's write lays the part ${i} out anew (${r}): ${St}`);case"drops":return{...d(`${a} listens for dragover and not for dragenter: a drop goes where both are cancelled, and the move that enters it asks dragenter alone, so that a release then (on a card's words, its padding) drops nothing: cancel dragenter as dragover is cancelled (preventDefault)`),file:"kit.js",line:l};case"gone":return c("the page does not hold this instance");case"fallback":return c(k?"its component failed or never started: the instance shows what it holds, read-only":"the instance shows as one of no package");case"moving":return d("what it shows never holds still (an animation?), so its mounts could not be compared");case"redrawn":return c(`the component redraws its text part ${i}: ${r}. A text part is the file's, what the user types in: read it, and draw in what is the component's`);case"left":return c(`dehydrate does not leave it as the file has it, so a copy of the view would hold what the kit made of it: ${a}. ${i?`That stands in its part ${i}, which is the file's: read a part, and draw in what is the component's`:"Name what it draws in the manifest's runtime, or take it off in dehydrate"}`);case"data":return c(`a mount changes its data part ${i}, so that a page would write what the component left there, with nothing edited: read a data part, and change it by context.edit alone`);case"no-example":return d("it has a data part and its component offers no example of an edit, so nothing has tried the way back to the file: give DocKit.component an example(host, context) that makes a small context.edit");case"example":return c(`its example: ${a}`);case"refused":return c("what its example wrote cannot go in the file: a script, a handler, an address of code, data-block-id or data-ge-*, what does not read back as itself, or what is no JSON in a script of data");case"undo":return c(`with what its example wrote put back, as an undo does, it does not show what it showed: ${a}: draw from the part, and on the source signal`);case"unasked":return c(`it writes its data part ${i} with no reader's gesture, ${n}, once the page takes edits: a page would write it each time it opened. Call context.edit on a gesture alone, a press, a drop or a key, and draw what the part holds as it is`);case"written-in":return c(`kit.js ${r}: a slot is the document's, its blocks the reader's: read it with context.part, never write in it or move it, and draw outside it`);case"piles":return c(p?`${a} piles up outside the instance on each put-back (${s.join(", then ")} of them), so an undo adds another: a component draws in its instance, and what it has to put elsewhere it takes away again in destroy`:`${a} piles up on each put-back (${s.join(", then ")} of them): it is declared in neither the manifest's runtime nor dehydrate, so an undo adds another`);default:return c(`a mount does not give the same DOM again: ${a}`)}}var At=t=>[...new Map(t.toReversed().map(a=>[`${a.finding.kind}|${a.finding.part??""}|${["piles","example"].includes(a.finding.kind)?a.finding.what:""}|${a.finding.when??""}|${a.finding.line??""}`,a])).values()].toReversed(),Ot=4e6;function Ze(t,a,i=(r,n)=>r===n){let[r,n]=[t.split(`
11
- `),a.split(`
12
- `)],s=0;for(;s<r.length&&s<n.length&&i(r[s],n[s]);)s++;let p=0;for(;p<r.length-s&&p<n.length-s&&i(r[r.length-1-p],n[n.length-1-p]);)p++;let[h,u]=[r.slice(s,r.length-p),n.slice(s,n.length-p)];if(h.length===0&&u.length===0)return[];if(h.length*u.length>Ot)return[{removed:h,added:u}];let l=Array.from({length:h.length+1},()=>new Uint32Array(u.length+1));for(let c=h.length-1;c>=0;c--)for(let d=u.length-1;d>=0;d--)l[c][d]=i(h[c],u[d])?l[c+1][d+1]+1:Math.max(l[c+1][d],l[c][d+1]);let w=[],k=null;for(let c=0,d=0;c<h.length||d<u.length;)c<h.length&&d<u.length&&i(h[c],u[d])?(k=null,c++,d++):(k||w.push(k={removed:[],added:[]}),d<u.length&&(c===h.length||l[c][d+1]>=l[c+1][d])?k.added.push(u[d++]):k.removed.push(h[c++]));return w}function Lt(t,a){let i=n=>n.filter(s=>s.trim()).length,r=Ze(t,a);return{removed:r.reduce((n,s)=>n+i(s.removed),0),added:r.reduce((n,s)=>n+i(s.added),0),lines:i(t.split(`
13
- `))}}function Ve(t,a){let i=0,r=0;for(let[n,s]of t.entries())if(n>0&&i>0&&i<a&&r++,i+=s.replace(/\s+/g,"").length,i>=a)break;return r}function Mt(t,a){let i=r=>r.filter(n=>!n.trim()).length;for(let{removed:r,added:n}of Ze(t,a,(s,p)=>s.trim()===p.trim())){if(i(n)>i(r))return"a line left blank";let[s,p]=[r.join("").replace(/\s+/g,""),n.join("").replace(/\s+/g,"")],h=0;for(;h<s.length&&h<p.length&&s[h]===p[h];)h++;let u=0;for(;u<s.length-h&&u<p.length-h&&s[s.length-1-u]===p[p.length-1-u];)u++;for(let[l,w,k]of[[h,r,n],[u,r.toReversed(),n.toReversed()]]){let[c,d]=[Ve(w,l)+1,Ve(k,l)+1];if(c!==d)return`${c} line${c===1?"":"s"} became ${d}`}}return null}function Dt(t,{source:a,found:i,at:r,findings:n}){let s=Ie(a,ze(me(a),i)[r],t.parts,new Map([[i.id,i]]));if(!s)return[{kind:"refused"}];let p=Object.keys(t.parts),h=s.map(({start:l,end:w,text:k},c)=>({name:p[c],before:a.slice(l,w),after:k}));return[{kind:"wrote",back:!n.some(({kind:l})=>l==="undo"||l==="moving"),parts:h.map(({name:l,before:w,after:k})=>({name:l,...Lt(w,k)}))},...h.flatMap(({name:l,before:w,after:k})=>{let c=Mt(w,k);return c?[{kind:"laid",part:l,how:c}]:[]})]}var Pt=2e3;function Rt({match:t,instance:a,at:i,most:r}){let n=[...document.querySelectorAll(t)].filter(s=>!s.parentElement.closest(a))[i];return n?[window,document,n,...n.querySelectorAll("*")].slice(0,r):[]}function Ct(t){return t.map((a,i)=>i<2?{parent:i-1,named:""}:{parent:i===2?1:t.indexOf(a.parentElement),named:`<${a.localName}${a.classList.length?` class="${a.getAttribute("class")}"`:""}>`})}function It(){let t=new DragEvent("dragenter",{bubbles:!0,cancelable:!0,composed:!0,dataTransfer:new DataTransfer});return this.dispatchEvent(t),t.defaultPrevented}async function Ft(t,{match:a,at:i}){let r=new Map,n=({scriptId:s,url:p})=>r.set(s,p);t.on("Debugger.scriptParsed",n);try{await t.send("Debugger.enable"),await t.send("Debugger.setSkipAllPauses",{skip:!0});let{result:s}=await t.send("Runtime.evaluate",{expression:`(${Rt})(${JSON.stringify({match:a,instance:ke,at:i,most:Pt})})`,objectGroup:"drops"}),{result:p}=await t.send("Runtime.callFunctionOn",{objectId:s.objectId,functionDeclaration:String(Ct),arguments:[{objectId:s.objectId}],returnByValue:!0}),{result:h}=await t.send("Runtime.getProperties",{objectId:s.objectId,ownProperties:!0}),u=h.filter(({name:c,value:d})=>/^\d+$/.test(c)&&d?.objectId).sort((c,d)=>Number(c.name)-Number(d.name)),l=[];for(let{value:c}of u)l.push((await t.send("DOMDebugger.getEventListeners",{objectId:c.objectId})).listeners);let w=(c,d)=>l[c]?.some(T=>T.type===d),k=[];for(let c=2;c<l.length;c++){let d=l[c].find(g=>g.type==="dragover"&&r.get(g.scriptId)==="kit.js");if(!d)continue;let T=!1;for(let g=c;g>=2&&!T;g=p.value[g].parent)T=w(g,"dragenter");if(!T&&(w(0,"dragenter")||w(1,"dragenter"))){let{result:g}=await t.send("Runtime.callFunctionOn",{objectId:u[c].value.objectId,functionDeclaration:String(It),returnByValue:!0});T=g.value===!0}T||k.push({kind:"drops",what:p.value[c].named,line:d.lineNumber+1})}return k}finally{t.off("Debugger.scriptParsed",n),await t.send("Runtime.releaseObjectGroup",{objectGroup:"drops"}).catch(()=>{}),await t.send("Debugger.disable").catch(()=>{})}}function _t(t,a){let i={errors:new Map,notes:new Set,failed:new Set,dialogs:new Set,windows:0,opened:[],asked:1,pending:[]},r=n=>{let[s]=n.split(`
14
- `);i.errors.has(s)||i.errors.set(s,Number(/\bkit\.js:(\d+)/.exec(n)?.[1])||null)};return t.on("pageerror",n=>r(n.stack??n.message)),t.on("console",n=>{let s=n.type();!["error","warn","warning"].includes(s)||!Be(n,a,["kit.js"])||i.pending.push(Promise.all(n.args().map(p=>p.evaluate(h=>h instanceof Error?h.stack:String(h)).catch(()=>""))).then(p=>{let h=p.join(" ")||n.text();s==="error"?r(h):i.notes.add(h.split(`
15
- `)[0])}))}),t.on("requestfailed",n=>{n.frame()===t.mainFrame()&&!n.isNavigationRequest()&&i.failed.add(n.url())}),t.on("request",n=>{n.isNavigationRequest()&&n.frame()===t.mainFrame()&&i.opened.push(n.url())}),i}async function Ht(t,a){let i=await t.createCDPSession();return await i.send("Page.enable"),i.on("Page.javascriptDialogOpening",({type:r})=>{a.add(r),i.send("Page.handleJavaScriptDialog",{accept:!1}).catch(()=>{})}),i}function O(t,a,i=ye){let r=0,n=()=>Object.assign(new Error(a),{stuck:!0,doing:a}),s=new Promise((h,u)=>{r=setTimeout(()=>u(n()),i)}),p=t.catch(h=>{throw yt.has(h.name)?n():Object.assign(h,{doing:a})});return Promise.race([p,s]).finally(()=>clearTimeout(r))}var et=t=>new Promise(a=>{if(!t.connected)return a(!0);t.once("disconnected",()=>a(!0)),setTimeout(()=>a(!1),Xe)});function Bt({match:t,instance:a}){let{clientWidth:i,scrollWidth:r}=document.documentElement;if(r<=i+1)return null;let n=[...document.querySelectorAll(t)].filter(s=>!s.parentElement.closest(a));return{wide:r,at:n.findIndex(s=>[s,...s.querySelectorAll("*")].some(p=>p.getBoundingClientRect().right>i+1))}}var Je=16,Wt="#8f8f8f";async function qt(t,a,i){let r=await Promise.all(a.map(async n=>`data:image/png;base64,${(await D.readFile(n)).toString("base64")}`));await t.setViewport({width:ne.reduce((n,s)=>n+s,0)+Je*(ne.length-1),height:900}),await t.setContent(`<!doctype html><body style="margin: 0; display: flex; align-items: flex-start; gap: ${Je}px; background: ${Wt}">${r.map((n,s)=>`<img src="${n}" width="${ne[s]}" alt="" style="display: block">`).join("")}</body>`,{waitUntil:"load"}),await t.screenshot({path:i,fullPage:!0})}async function Gt(t,{file:a,html:i,source:r,places:n,found:s,out:p,loading:h}){let u=await t.createBrowserContext(),l=await u.newPage(),w=Ye(a).href,k=_t(l,w),c=await Ht(l,k.dialogs);u.on("targetcreated",g=>{g.type()==="page"&&(k.windows+=1,g.page().then($=>$?.close()).then(()=>l.bringToFront()).catch(()=>{}))});let d={heard:k,blocked:[],late:[],taken:[],overviews:[],edited:[],asExport:[],answers:[],wide:[],stuck:null,stopped:null,gone:null},T=async g=>d.late.push(...await O(Ge(l,{timeout:Ke}),g,3*Ke+ye));await We(l),await l.setViewport({width:736,height:900}),await l.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]);try{await O(l.goto(w,{waitUntil:"load",timeout:0}),"the page opened",h),await T("the page opened");for(let f of ge){await O(l.emulateMediaFeatures([{name:"prefers-color-scheme",value:f}]),`the ${f} theme came`);for(let x of ne){if(await O(l.setViewport({width:x,height:900}),`the window went to ${x}px`),await T(`it was drawn at ${x}px`),f===ge[0]){let q=await O(l.evaluate(Bt,{match:s.match,instance:ke}),`it was measured at ${x}px`);q&&d.wide.push({width:x,...q})}let P=S.join(p,`${x}-${f}.png`);await O(l.screenshot({path:P,fullPage:!0}),`it was pictured at ${x}px`),d.taken.push(P)}}await O(l.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came"),await O(l.setViewport({width:736,height:900}),"the window went to 736px");let g=Qe(i,s),$=s.files.includes("kit.js")&&Object.values(s.parts).some(({edit:f})=>f==="data");for(let f=0;f<g.length;f++){let x=await O(l.evaluate(jt,{match:s.match,instance:ke,slotPart:lt,slotName:rt,fallback:it,parts:s.parts,at:f,source:g[f].markup,still:ft,step:wt,times:mt,typed:gt,typing:kt}),"an instance was put back"),P=x.find(({kind:R})=>R==="wrote"),q=[...x.filter(R=>R!==P),...P?Dt(P,{source:r,found:s,at:f,findings:x}):[]];$&&!x.some(({kind:R})=>R==="gone"||R==="fallback")&&q.push(...await O(Ft(c,{match:s.match,at:f}),"the page was asked what an instance listens to")),d.answers.push(...q.map(R=>({finding:R,place:n[f]})))}d.blocked=await O(l.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"),k.asked+=1,await O(l.goto(w,{waitUntil:"load",timeout:0}),"the page opened again",h),await T("the page opened again"),await O(l.evaluate(()=>dispatchEvent(new Event("doc-editable"))),"the page was told it takes edits"),await T("it was drawn as the editing page draws it");for(let f of pt){await O(l.setViewport({width:f,height:900}),`the window went to ${f}px`),await T(`it was drawn at ${f}px as the editing page draws it`);let x=S.join(p,`edit-${f}-light.png`);await O(l.screenshot({path:x,fullPage:!0}),`it was pictured at ${f}px as the editing page draws it`),d.edited.push(x),(await D.readFile(x)).equals(await D.readFile(S.join(p,`${f}-light.png`)))&&d.asExport.push(x)}d.blocked.push(...await O(l.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"));for(let f of ge){let x=S.join(p,`overview-${f}.png`);await O(qt(l,ne.map(P=>S.join(p,`${P}-${f}.png`)),x),`the ${f} pictures were put side by side`),d.overviews.push(x)}}catch(g){if(g.syscall)throw g;await et(t)?d.gone=g.doing??"the page answered":g.stuck?d.stuck=g.doing:d.stopped=$e(g)}return await Promise.race([Promise.all(k.pending),new Promise(g=>setTimeout(g,Xe).unref())]),d}var Ut=(t,a)=>t.startsWith(a)?t.slice(a.length):t;function Kt(t,a,i){let r=new Map;for(let{url:n,directive:s,source:p,line:h}of t){if($t.test(n)){let l=!p&&h>0;r.set(`${n}|${p}|${h}`,{file:l?"kit.js":"the page",...l?{line:h}:{},what:"the export's policy blocks code made from words (eval, new Function, a string given to setTimeout): an export runs none"});continue}let u=/^[a-z][a-z0-9+.-]*$/.test(n)?a.filter(l=>l.startsWith(`${n}:`)):[];for(let l of u.length?u:[n])r.set(`${l}|${s}`,{file:"the page",what:`the export's policy blocks ${Ut(l,i)||"something"} (${s}): ${s==="img-src"?"a picture of an instance is a data: address, or a file its style names":"an export holds all it needs"}`})}return[...r.values()]}function Vt({heard:t,blocked:a,late:i,answers:r,wide:n,stuck:s,stopped:p},{places:h,script:u,folder:l}){let w=At(r).map(({finding:$,place:f})=>Nt($,f,{script:u})),k=[...t.failed],c=k.filter($=>!a.some(f=>f.url&&$.startsWith(f.url))),d=t.opened.length>t.asked?"it loads itself again (location.reload(), a new location.href), so a reader's page would not stay":s?`it stopped answering while waiting until ${s}${u?": a script that never ends, or a component that changes what it hears (a text part, on its source signal)":""}`:p&&`the look at it stopped: ${p}`,T=n.map(({width:$,wide:f})=>`${f}px wide in a ${$}px window`).join(", "),g=h[n.find(({at:$})=>$>=0)?.at]??{file:"the page"};return{problems:[...[...t.errors].map(([$,f])=>({file:f?"kit.js":"the page",line:f,what:`the console says ${$}`})),...Kt(a,k,l),...c.map($=>({file:"the page",what:`it could not load ${$.slice(0,120)}`})),...[...t.dialogs].map($=>({file:"the page",what:`it opens a dialog (${$}), which stops a reader's page until it is answered: show what it says in the instance`})),...t.windows?[{file:"the page",what:"it opens a window, which takes a reader away from the page: show it in the instance, or link to it"}]:[],...d?[{file:"the page",what:d}]:[],...n.length?[{...g,what:`the page is ${T}: a reader scrolls the whole page sideways, and gallery qa fails it: let it fit the window (max-width: 100%), or put what is wider in a frame of its own that scrolls`}]:[],...w.filter(({note:$,told:f})=>!$&&!f)],notes:[...[...t.notes].map($=>({file:"the page",what:`the console says ${$}`})),...w.filter(({note:$})=>$),...i.map($=>({file:"the page",what:`waited for ${$}`}))],told:w.filter(({told:$})=>$)}}async function ln(t,a,{example:i,template:r},{find:n=_e,start:s=qe,loading:p=ut}={}){let h=ht,u=null,l=null;try{u=await D.mkdtemp(S.join(Ue.tmpdir(),"gallery-component-check-"));let w=await Tt(a,{example:i,template:r},u),k=n();if(!k)return{title:h,unverified:"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one)"};try{l=await s({executablePath:k,args:He()})}catch(g){return{title:h,unverified:`the browser ${k} did not start, twice, each time with a fresh profile (${$e(g)}; GALLERY_BROWSER=<its executable> picks another)`}}let c=S.join(ct(t).qa,"components",...a.id.split("/"));await D.rm(c,{recursive:!0,force:!0}),await D.mkdir(c,{recursive:!0});let d=await Gt(l.browser,{...w,found:a,out:c,loading:p}),T=Vt(d,{places:w.places,script:a.files.includes("kit.js"),folder:Ye(`${u}${S.sep}`).href});return d.gone?{title:h,...T,unverified:`the browser went while waiting until ${d.gone}, so it says nothing of the package`}:{title:h,...T,...d.taken.length?{pictures:{folder:c,overviews:d.overviews.map(g=>S.basename(g)),each:d.taken.map(g=>S.basename(g)),edited:d.edited.map(g=>S.basename(g)),asExport:d.asExport.map(g=>S.basename(g))}}:{}}}catch(w){return w.reason==="check"?{title:h,problems:w.failures.map(k=>({file:"the export",what:k}))}:w.syscall?{title:h,unverified:`cannot write ${Fe(w.syscall==="mkdtemp"?Ue.tmpdir():w.path)} (${w.code})`}:l&&await et(l.browser)?{title:h,unverified:"the browser went before the page opened"}:{title:h,problems:[{file:"the page",what:`the look at it stopped: ${$e(w)}`}]}}finally{await l?.close(),u&&await D.rm(u,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{})}}export{ht as a,ut as b,ft as c,wt as d,$e as e,bt as f,Et as g,St as h,Lt as i,Mt as j,Ht as k,O as l,et as m,ln as n};
@@ -1,6 +0,0 @@
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 O}from"./chunk-E7LWZRXY.mjs";import{a as M}from"./chunk-L3QKH4OK.mjs";var b=3e4,j=12e4,k=1500,S=1e4,W=h=>h.reduce((a,{key:c,tag:r})=>a.set(`${c}
3
- ${r}`,(a.get(`${c}
4
- ${r}`)??0)+1),new Map);function U({now:h=Date.now,hold:a=b,limit:c=j,quiet:r=k}={}){let i=new Map,l=new Map,w=new Map,$=new Map,p=new Map;return{wrote(t,e){$.set(t,M(e))},judge(t,{source:e,mtime:m}){if(e===null)return i.delete(t),w.delete(t),{held:!1,signs:[],wait:0,own:!1};let d=M(e),n=p.get(t)?.hash===d?p.get(t).signs:null;n||(n=O(e),p.set(t,{hash:d,signs:n}));let f=h(),x=(o,s=!1)=>(i.delete(t),l.set(t,W(n)),w.set(t,e),{held:!1,signs:[],wait:o,own:s});if($.get(t)===d)return x(0,!0);let g=l.get(t)??new Map,I=W(n);if([...I].some(([o,s])=>s>(g.get(o)??0))){let o=Math.min(m,f),s=i.get(t)??o;i.set(t,s);let T=Math.min(a-(f-o),c-(f-s));if(T>0)return{held:!0,signs:n.filter(({key:D,tag:L})=>I.get(`${D}
5
- ${L}`)>(g.get(`${D}
6
- ${L}`)??0)),wait:T,own:!1,taken:w.get(t)}}return x(Math.min(r,Math.max(0,r-(f-m))))}}}export{b as a,j as b,k as c,S as d,U as e};
@@ -1,7 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{k as st}from"./chunk-6QXGZM36.mjs";import{a as ot}from"./chunk-UMHUSOPJ.mjs";import I from"node:fs/promises";import ct from"node:path";import{writeAtomic as lt}from"../browser/shared/files.mjs";import{documentFiles as ht}from"../browser/shared/workspace.mjs";var kt=l=>I.access(l).then(()=>!0,()=>!1);async function Dt(l,{create:p,slugOf:c,folderOf:O,fill:L,place:U,under:b="",said:o="\u5BFC\u5165\u81EA {0}",lang:$=null}){let F=[],S=[];async function h(u,P,B){let E=await c(u,B);await p(E,u.title,o.replace("{0}",()=>u.from),{lang:$});let J=O(E),{html:W,json:T}=ht(J),k=await I.readFile(W,"utf8");await lt(W,st(await L({source:k,nodes:u.nodes,icon:u.icon,own:u.own,raws:u.raws,lang:u.lang}))),u.files.length&&await I.mkdir(ct.join(J,"assets"),{recursive:!0});for(let{from:g,name:Z}of u.files){let A=ct.join(J,"assets",Z);await kt(A)||await I.copyFile(g,A)}if(u.icon){let g=JSON.parse(await I.readFile(T,"utf8"));await lt(T,`${JSON.stringify({...g,icon:u.icon},null,2)}
3
- `)}await U(E,P),F.push(E);for(let g of u.children??[])await h(g,E,null);return E}for(let[u,P]of l.entries())S.push(await h(P,b,u));return{made:F,top:S}}import{randomBytes as Ot}from"node:crypto";import d from"node:fs/promises";import m from"node:path";import{writeAtomic as G}from"../browser/shared/files.mjs";import{sendJson as Y}from"../browser/shared/http.mjs";import{said as z,saying as jt}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as gt}from"../browser/shared/paths.mjs";import{moveDocument as vt,readOutline as bt,validOutline as ut,withOutlineLock as St,writeOutline as xt,writtenAs as Nt}from"../browser/shared/outline.mjs";import{sameDirectory as Et}from"../browser/shared/preview-server.mjs";import{listReportSlugs as Ft,slugPattern as N}from"../browser/shared/reports.mjs";import{COMPONENTS_FOLDER as D,DOCUMENT_FOLDERS as Pt,PAGE_SLUG as At,documentDirectory as Lt,documentFiles as V,layoutOf as $t,listTrash as Jt,packageFolders as Tt,pageSlug as Mt,slugTaken as Rt,trashIdPattern as ft}from"../browser/shared/workspace.mjs";import{effectiveLook as tt,ownLookFor as Ct,ownLookOf as It,sameLook as Gt,withLookField as wt}from"../browser/shared/document-look.mjs";import{workspaceLook as nt,writeWorkspaceLook as Ut}from"../browser/shared/workspace-look.mjs";import{MENTION as Bt}from"../browser/shared/components/mention.mjs";import{findIn as Wt,reportLines as _t,tidyQuery as Ht}from"../browser/shared/search.mjs";import{countWords as Kt}from"../browser/shared/words.mjs";var Qt=([l,p,c,...O])=>O.length?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",l,p,c,O.length+3):c!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",l,p,c):p!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",l,p):z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",l),mt=l=>l==="en"?"en":null;async function X(l,p){for(let c=0;;c++)try{return await d.rename(l,p)}catch(O){if(!["EPERM","EBUSY","EACCES"].includes(O.code))throw O;if(c>=5)break;await new Promise(L=>setTimeout(L,60*(c+1)))}await d.cp(l,p,{recursive:!0,errorOnExist:!0,force:!1}),await d.rm(l,{recursive:!0,force:!0,maxRetries:5})}var Yt=l=>m.resolve(l);function On({edits:l,reports:p,reportsDirectory:c=gt,server:O={kind:"dev",version:null,stop:null},components:L=null,changed:U=()=>{}}){let{trash:b}=$t(c),o=(t,n,e)=>[t,{ok:!1,reason:n,...jt(e)}],$=t=>d.readFile(t,"utf8").then(JSON.parse).catch(()=>null),F=t=>Lt(t,c),S=t=>V(F(t)),h=t=>m.join(c,t),u=t=>A(V(h(t)).html),P=t=>Promise.resolve(l.forgetChanges?.(t)).catch(()=>{}),B=async t=>{let n=await d.readdir(h(t),{withFileTypes:!0});if(t!==D)return n.map(({name:r})=>r);let e=new Set(Tt(c).map(({id:r})=>r.split("/")[0]));return n.filter(r=>r.isFile()||Pt.includes(r.name)&&!e.has(r.name)).map(({name:r})=>r)},E=async(t,n,e)=>{await d.mkdir(e,{recursive:!0});let r=[];try{for(let i of t)await X(m.join(n,i),m.join(e,i)),r.push(i)}catch(i){for(let a of r)await X(m.join(e,a),m.join(n,a));throw i}},J=async(t,n)=>{if(t!==D)return X(h(t),n);await E(await B(t),h(t),n),await d.rmdir(h(t)).catch(()=>{})},W=async(t,n)=>t===D&&!await u(t)&&(await Promise.all((await d.readdir(n)).map(e=>A(m.join(h(t),e))))).every(e=>!e),T=async t=>await $(V(t).json)??{},k=async t=>{let{title:n=t,description:e="",type:r,instructions:i,icon:a,look:s}=await T(F(t)),y=i===!0?{}:tt(s,nt(c));return{slug:t,title:n,description:e,...r?{type:r}:{},...typeof a=="string"&&a?{icon:a}:{},...i===!0?{instructions:!0}:{},...Object.keys(y).length?{look:y}:{}}},g=()=>Mt(c),Z=async(t,n)=>{let e=await T(F(t));await G(S(t).json,`${JSON.stringify({...e,[n]:!0},null,2)}
4
- `)},A=t=>d.access(t).then(()=>!0,()=>!1),M=async(t,{own:n=null}={})=>{let e=new Set((await R()).map(({slug:r})=>r));e.delete(n);for(let r=1;;r++){let i=r===1?t:`${t}-${r}`;if(!Rt(i,c)&&!e.has(i))return i}},et=async(t,n)=>{let e=S(t).html,r=await d.readFile(e,"utf8"),i=ot(r).replace(`data-doc-id="${n}"`,`data-doc-id="${t}"`);i!==r&&await G(e,i)},x=()=>bt(c),_=async t=>{await xt(c,t),U()},H=t=>St(c,t);async function K(t,n="",e=1/0){await H(async()=>{let r=await x();for(let s of Object.values(r.children))s.includes(t)&&s.splice(s.indexOf(t),1);let i=n!==t&&(n===""||Object.values(r.children).some(s=>s.includes(n))),a=r.children[i?n:""]??=[];a.splice(Math.max(0,Math.min(e,a.length)),0,t),await _(r)})}function dt(t){return H(async()=>{let n=await x();for(let[e,r]of Object.entries(n.children)){let i=r.indexOf(t);if(!(i<0))return r.splice(i,1,...n.children[t]??[]),delete n.children[t],await _(n),{parent:e,index:i}}return{parent:"",index:1/0}})}let rt=new Map;async function yt(t,n){let e=S(t).html,r=await d.stat(e).catch(()=>null);if(!r)return null;let i=rt.get(t);if(i?.at===r.mtimeMs&&(i.titles===null||i.titles===n))return i.lines;let a=(await l.read(t))?.text??"",s=_t(p.words(a,t));return rt.set(t,{at:r.mtimeMs,titles:a.includes(Bt)?n:null,lines:s}),s}let it=t=>$(m.join(b,t,"entry.json")),R=()=>Jt(c),at={info:async()=>[200,{ok:!0,version:1,gallery:O.version,token:l.token,commands:[...Object.keys(q)],server:{pid:process.pid,workspace:m.resolve(c),kind:O.kind}}],async outline(){let t=await x(),n=await g(),e=[...Object.values(t.children).flat(),...n?[n]:[]],r=async i=>[i,await k(i)];return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(await Promise.all(e.map(r))),trash:await R()}]},trash:async()=>[200,{ok:!0,entries:await R()}],async stats(t){let n=t.get("slug")??"",e=N.test(n)?S(n).html:"",[r,i]=N.test(n)?await Promise.all([d.stat(e),l.read(n)]).catch(()=>[]):[];return!r||!i?o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):[200,{ok:!0,edited:Math.round(r.mtimeMs),words:Kt(i.text)}]},components:async()=>[200,{ok:!0,...L.read()}],async source(t){let n=t.get("slug")??"";if(!N.test(n))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=m.resolve(S(n).html);return await A(e)?[200,{ok:!0,path:e}]:o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async search(t){let n=Ht(t.get("q")??"");if(!n)return[200,{ok:!0,results:[]}];let{children:e}=await x(),r=[],i=w=>(e[w]??[]).forEach(j=>{r.push(j),i(j)});i("");let a=n.toLowerCase(),s=new Map(await Promise.all(r.map(async w=>[w,await k(w)]))),y=JSON.stringify([...s].map(([w,{title:j}])=>[w,j])),f=(await Promise.all(r.map(async w=>{let j=await yt(w,y);if(!j)return null;let C=String(s.get(w).title).toLowerCase().includes(a),{count:v,hits:Q}=Wt(j,n);return C||v?{slug:w,title:C,count:v,hits:Q}:null}))).filter(Boolean);return f.sort((w,j)=>Number(j.title)-Number(w.title)||j.count-w.count),[200,{ok:!0,results:f.slice(0,50)}]}},q={async outline({outline:t,base:n}){return!ut(t)||n!==void 0&&!ut(n)?o(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):await H(async()=>n!==void 0&&!Nt(n.children,(await x()).children)?!1:(await _(t),!0))?[200,{ok:!0,outline:await x()}]:o(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:n,after:e=null,first:r=!1,workspace:i}){if(typeof i=="string"&&!Et(i,c))return o(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let a=f=>typeof f=="string"&&N.test(f);if(!a(t)||n!==void 0&&n!==""&&!a(n)||e!==null&&!a(e)||typeof r!="boolean")return o(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let s=await g();if(s!==null&&[t,n,e].includes(s))return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let y=await vt(c,t,{parent:n,after:e,first:r});if(y.written&&U(),!y.ok){let[f,w]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"]}[y.reason];return o(f,y.reason,w)}return[200,{ok:!0,...y,outline:await x()}]},async create({title:t,description:n,parent:e="",language:r}){let i=typeof t=="string"&&t.trim()?t.trim():"\u672A\u547D\u540D\u6587\u6863",a=await M("doc");return await P(a),await p.create(a,i,typeof n=="string"&&n.trim()?n.trim():"\u65B0\u6587\u6863",{lang:mt(r)}),await K(a,typeof e=="string"?e:""),[200,{ok:!0,report:await k(a)}]},async instructions({title:t,description:n,language:e}){let r=await g();if(r)return[200,{ok:!0,report:await k(r)}];let i=await M(At),a=(s,y)=>typeof s=="string"&&s.trim()?s.trim().slice(0,200):y;return await p.create(i,a(t,"\u5199\u4F5C\u504F\u597D"),a(n,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:mt(e),page:!0}),await Z(i,"instructions"),[200,{ok:!0,report:await k(i)}]},async components({id:t,hidden:n,disabled:e}){try{return[200,{ok:!0,...await L.write({id:t,hidden:n,disabled:e})}]}catch(r){return o(409,"components",r)}},async duplicate({slug:t,suffix:n}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await M(`${t}-copy`);await P(e);let r=new Set(["",...await B(t)]);await d.cp(h(t),h(e),{recursive:!0,errorOnExist:!0,filter:w=>r.has(m.relative(h(t),w).split(m.sep)[0])}),await et(e,t);let{title:i}=await k(t),a=await l.renameReport(e,`${i}${typeof n=="string"&&n.length>0&&n.length<=20?n:"\uFF08\u526F\u672C\uFF09"}`),s=await x(),[y,f]=Object.entries(s.children).find(([,w])=>w.includes(t))??["",null];return await K(e,y,f?f.indexOf(t)+1:1/0),[200,{ok:!0,report:await k(e),notes:a.notes??[]}]},async look({slug:t,look:n}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await g())return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(n!==null&&(typeof n!="object"||Array.isArray(n)))return o(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let e=S(t).json,r=null;try{r=JSON.parse(await d.readFile(e,"utf8"))}catch{}if(!r||typeof r!="object"||Array.isArray(r))return o(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let i=wt(r,Ct(n,nt(c)));return JSON.stringify(i)!==JSON.stringify(r)&&await G(e,`${JSON.stringify(i,null,2)}
5
- `),[200,{ok:!0,report:await k(t)}]},async looks({slug:t}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let n=await g();if(t===n)return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let e=await $(S(t).json);if(!e||typeof e!="object"||Array.isArray(e))return o(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=nt(c),i=tt(e.look,r);try{await Ut(c,i)}catch(f){return o(409,"workspace",f)}let a=0,s=(await Ft(c)).filter(f=>f!==n).map(f=>({json:S(f).json,self:f===t})),y=(await R()).map(({id:f})=>({json:V(m.join(b,f,"report")).json,self:!1}));for(let{json:f,self:w}of[...s,...y])for(let j=0;j<3;j++){let C=await d.readFile(f,"utf8").catch(()=>null),v=null;try{v=JSON.parse(C??"")}catch{}if(!v||typeof v!="object"||Array.isArray(v)||!Object.hasOwn(v,"look")||v.instructions===!0)break;let Q=await G(f,`${JSON.stringify(wt(v,{}),null,2)}
6
- `,{expect:C}).catch(()=>null);if(Q===null)break;if(Q){!w&&Object.keys(It(v.look)).length>0&&!Gt(tt(v.look,r),i)&&a++;break}}return[200,{ok:!0,look:i,replaced:a,report:await k(t)}]},async rename({slug:t,title:n}){if(typeof t!="string"||!N.test(t))return o(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");let e=await l.renameReport(t,n);return e.ok?[200,{ok:!0,report:await k(t),notes:e.notes}]:o({title:400,missing:404}[e.reason]??409,e.reason,e.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t}){if(typeof t!="string"||!N.test(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await g())return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await k(t),e=`${Date.now().toString(36)}-${Ot(3).toString("hex")}`,r=await x(),{parent:i,index:a}=await dt(t);try{await d.mkdir(m.join(b,e),{recursive:!0}),await J(t,m.join(b,e,"report"))}catch(y){throw await H(()=>_(r)),await d.rm(m.join(b,e),{recursive:!0,force:!0}).catch(()=>{}),y}let s={id:e,slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(a)?a:-1};return await G(m.join(b,e,"entry.json"),`${JSON.stringify(s,null,2)}
7
- `),[200,{ok:!0,entry:s}]},async restore({id:t}){let n=typeof t=="string"&&ft.test(t)?await it(t):null;if(!n)return o(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");let e=m.join(b,t,"report"),r=await W(n.slug,e),i=r?n.slug:await M(n.slug,{own:n.slug});return r?await E(await d.readdir(e),e,h(i)):await X(e,h(i)),i!==n.slug&&await et(i,n.slug),await d.rm(m.join(b,t),{recursive:!0,force:!0}),await K(i,n.parent,n.index<0?1/0:n.index),[200,{ok:!0,report:await k(i),entry:{...n,slug:i}}]},async destroy({id:t}){let n=typeof t=="string"&&ft.test(t)?await it(t):null;return n?(await u(n.slug)||await P(n.slug),await d.rm(m.join(b,t),{recursive:!0,force:!0}),[200,{ok:!0}]):o(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async export({slug:t}){if(typeof t!="string"||!N.test(t)||!await A(F(t)))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:n=[],file:e,refused:r}=await p.export(t);return r?o(r.reason==="missing"?404:409,r.reason,r.message):n.length?o(422,"check",Qt(n)):[200,{ok:!0,path:Yt(e)}]}};function pt(t,n,e){if(t.method==="GET"&&Object.hasOwn(at,e)){let r=t.headers.host??"",i=t.socket.localPort;return r!==`127.0.0.1:${i}`&&r!==`localhost:${i}`?Y(n,403,{ok:!1,reason:"host"}):at[e](new URL(t.url??"/","http://localhost").searchParams).then(([a,s])=>Y(n,a,s),a=>Y(n,...o(500,"read",a)))}return t.method==="POST"&&e==="stop"?l.respond(async r=>{let i=await l.check(r);return i.error?i.error:O.kind!=="cli"||typeof O.stop!="function"?o(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(n.once("finish",()=>O.stop()),[200,{ok:!0,pid:process.pid}])})(t,n):t.method==="POST"&&Object.hasOwn(q,e)?l.respond(async r=>{let i=await l.check(r);return i.error?i.error:q[e](i.body&&typeof i.body=="object"?i.body:{})})(t,n):Y(n,404,{ok:!1,reason:"unknown"})}return{handle:pt,outline:x,trashEntries:R,place:K,freeSlug:M}}export{Dt as a,On as b};
@@ -1,4 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as ae,f as le,n as ce}from"./chunk-PL6GHLGD.mjs";import{b as C,d as he}from"./chunk-LEF6DRCK.mjs";import{a as N}from"./chunk-TX6JH7TR.mjs";import"./chunk-DFUDV4LX.mjs";import"./chunk-E7LWZRXY.mjs";import"./chunk-64K7IPLO.mjs";import"./chunk-NSKUTQ5J.mjs";import{a as se,i as ne,r as oe}from"./chunk-AUZGSZJH.mjs";import{d as Z,e as Q,i as A,j as ee,k as te}from"./chunk-BGGDRNYQ.mjs";import{a as g}from"./chunk-6QXGZM36.mjs";import"./chunk-UALRNVSE.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import{a as V,c as x}from"./chunk-HYMEEXKN.mjs";import"./chunk-TYK6VNAB.mjs";import{b as re,h as F}from"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import{c as ie}from"./chunk-L3QKH4OK.mjs";import{c as W,e as J,g as v,o as X}from"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{isUtf8 as Ne}from"node:buffer";import be from"node:fs";import j from"node:path";import{instancesOf as Y,isInstance as Ce,partOf as we}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as k,refusedInCopy as Ie}from"../browser/shared/components/installed.mjs";import{attr as I,elementsOf as ye,walk as P}from"../browser/shared/html-tree.mjs";import{blankedCss as z}from"../browser/shared/css-references.mjs";import{ATTRIBUTE as _,SLOT as me}from"../browser/shared/components/installed.mjs";var Le=new Set(["media","supports","container","layer","starting-style"]);function M(t,e){let s=0,n="";for(let o=0;o<t.length;o++){let i=t[o];i==="\\"?o++:n?n=i===n?"":n:i==='"'||i==="'"?n=i:i===")"||i==="]"?s--:(s===0&&e(i,o),(i==="("||i==="[")&&s++)}}function Ee(t){let e=z(t),s=z(t,{strings:!0}),n={children:[]},o=[n],i=0,a=0;for(let r=0;r<e.length;r++){let l=e[r];if(l==="\\")r++;else if(l==="("||l==="[")a++;else if(l===")"||l==="]")a=Math.max(0,a-1);else{if(a>0)continue;if(l==="{"){let c={prelude:s.slice(i,r),start:i,children:[]};o.at(-1).children.push(c),o.push(c),i=r+1}else l==="}"?(o.length>1&&o.pop(),i=r+1):l===";"&&(i=r+1)}}return n.children}function B(t){let e=[],s=0;return M(t,(n,o)=>{n===","&&(e.push({text:t.slice(s,o),start:s}),s=o+1)}),e.push({text:t.slice(s),start:s}),e.filter(({text:n})=>n.trim())}function D(t){let e=[],s=t.trim(),n="",o=0,i=0,a=r=>{(i||r)>o&&e.push({combinator:n,compound:s.slice(o,i||r)}),i=0};return M(s,(r,l)=>{/\s/.test(r)?l===o?o=l+1:i||=l:">+~".includes(r)?(a(l),n=r,o=l+1):i&&(a(l),n=" ",o=l)}),a(s.length),e}function U(t){let e=[],s=-1,n=0,o="";for(let a=0;a<t.length;a++){let r=t[a];r==="\\"?a++:o?o=r===o?"":o:r==='"'||r==="'"?o=r:r==="("?n++:r===")"?n--:r==="["&&n===0?s=a:r==="]"&&n===0&&s>=0&&(e.push(t.slice(s,a+1)),s=-1)}let i=!1;return M(t,a=>{i||=a==="&"}),{attributes:e,nesting:i,scope:/(?:^|[^\w-]):scope\b/.test(t)}}var Oe=t=>new RegExp(`^\\[\\s*${_}\\s*=\\s*(["'])${t.replace(/[/-]/g,"\\$&")}\\1\\s*i?\\s*\\]$`,"i"),je=t=>z(t).replace(/\\.|\[[^\]]*\]/g,"").includes("&");function pe(t,e,s,n=!1){let o=D(t),i=({compound:f})=>U(f).attributes.some(h=>e.test(h)),a=({compound:f})=>{let{nesting:h,scope:m}=U(f);return!!s&&(h||m)},r=f=>["+","~"].includes(f?.combinator),l=f=>o.slice(f).some(({combinator:h},m)=>(m+f===0?h||" ":h)===" "),c=o.findLastIndex(f=>i(f)||a(f));if(c<0)return!s||je(t)?{why:"outside"}:{why:s==="instance"&&r(o[0])?"beside":null,subject:"inside",deep:n||l(0)};let p=i(o[c])||s==="instance";return{why:p&&r(o[c+1])?"beside":null,subject:p&&c===o.length-1?"instance":"inside",deep:!i(o[c])&&n||l(c+1)}}var fe=t=>t.some(({subject:e})=>e==="instance")?"instance":"inside",Te=new RegExp(`^\\[\\s*${me}\\s*(?:\\]|=)`,"i"),Ae=t=>B(/\)\s*to\s*\(([^)]*)\)/i.exec(t)?.[1]??"").some(({text:e})=>D(e).length===1&&U(e).attributes.some(s=>Te.test(s))),ue=(t,e)=>ge(t,e).outside;function de(t,e,s){if(s.length===0)return[];let n=`slot${s.length===1?"":"s"} ${s.join(" and ")}`;return ge(t,e).deep.map(({line:o,words:i})=>({line:o,what:`${i} also reaches the blocks in ${n}, the document's: write each step with > or wrap the rules in @scope ([${_}="${e}"]) to ([${me}])`}))}function ge(t,e){let s=Oe(e),n=`[${_}="${e}"]`,o=[],i=[],a=(l,c,p)=>{let f=c.replace(/\s+/g," ").trim();o.push({line:x(t,l),what:p==="beside"?`${f} reaches what stands beside the instance: what it styles has to stand in it`:`${f} reaches outside the instance: start it at ${n}`})},r=(l,c,p=!1,f=!1)=>{for(let h of l){let m=h.prelude.length-h.prelude.trimStart().length,d=h.start+m,$=/^@([\w-]+)\s*/.exec(h.prelude.trim());if($){let u=$[1].toLowerCase();if(Le.has(u))r(h.children,c,p,f);else if(u==="page")o.push({line:x(t,d),what:"@page reaches the paper of the whole document: an instance has no page of its own"});else if(u==="scope"){let y=/^@scope\s*\(([^)]*)\)/i.exec(h.prelude.trim())?.[1]??"",S=B(y).map(({text:L})=>({...pe(L,s,c),steps:D(L).length}));y&&S.every(({why:L,steps:Se})=>!L&&Se===1)?r(h.children,fe(S),!1,f||Ae(h.prelude.trim())):a(d,h.prelude,"outside")}continue}let b=B(h.prelude).map(({text:u,start:y})=>{let S=pe(u,s,c,p),L=h.start+y+u.length-u.trimStart().length;return S.why?a(L,u,S.why):S.deep&&!f&&!p&&i.push({line:x(t,L),words:u.replace(/\s+/g," ").trim()}),S});b.some(({why:u})=>u)||r(h.children,fe(b),b.some(u=>u.deep),f)}};return r(Ee(t),null),{outside:o,deep:i}}var w="template.html",E="example.html",R="component.json",Re=new Set(["localStorage","sessionStorage"]),Pe=/^\S+: (?:line \d+ of )?its (?:kit\.js|style\.css) /,ve=/(?: (?:names a file that )?is not in the document's folder|: it is (?:no file of|not in) the document's .*)$|^external resources are not portable: .*$/,Fe=": an example stands in no document: write a picture as a data: address, or draw it from style.css with a file the manifest's assets name",ze=t=>t.replace(ve,e=>(e.startsWith("external")?e:"")+Fe),O=(t,e)=>A({folder:t},e);function T(t,e){let s=null;try{s=be.readFileSync(j.join(t,e))}catch{return null}return Ne(s)?null:{file:e,what:"it is not UTF-8: save it as UTF-8 (PowerShell's > writes UTF-16; Set-Content -Encoding utf8 does not)"}}function G(t,e){let s=/^line (\d+): | \(line (\d+)\)/.exec(e);return s?{file:t,line:Number(s[1]??s[2]),what:e.replace(s[0],"")}:{file:t,what:e}}function H(t,e){let s=g.parseJsonText(R,t),n=s.statements[0]?.expression,o=null;for(let i of e.split(".")){let a=n?.properties?.find(({name:r})=>r?.text===i);if(!a)break;o=s.getLineAndCharacterOfPosition(a.getStart(s)).line+1,n=a.initializer}return o}function Be(t,{message:e,text:s="",values:n=[]}){let o=/at position (\d+)/.exec(e)?.[1];if(o)return x(t,Number(o));for(let i of[...n.map(String),...s.match(/[a-zA-Z][\w.]*/g)??[]]){let a=H(t,i);if(a)return a}return null}var Ue=t=>F(t).map(e=>/^line (\d+): <([^>]+)>: ([\s\S]*)$/.exec(e)).filter(Boolean).map(([,e,s,n])=>({line:Number(e),tag:s,why:n}));function _e(t,{file:e,tree:s,html:n}){let o=[],i=Ue(n),a=Object.entries(t.parts).filter(([,c])=>c.edit==="text"),r=Object.entries(t.parts).filter(([,c])=>c.edit==="data"),l=(c,p)=>{let f=!1;return P(c,h=>{f||=h===p}),f};for(let c of Y(s,t))for(let[p,f]of a)for(let h of we(c,f.at)){let m=h.sourceCodeLocation?.startLine,d=ye(h).find(u=>ie.has(u.tagName)),$=i.find(u=>u.line===m&&u.tag===h.tagName),b=r.find(([,u])=>we(c,u.at).some(y=>y===h||l(y,h)||l(h,y)))?.[0];b?o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and stands in the part ${b}, edited as data, or around it, which is the component's: the editor leaves it read-only: name elements apart`}):d?o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text and holds a block, its <${d.tagName}> at line ${d.sourceCodeLocation?.startLine}: a text part holds words and marks alone, and the editor would leave this one read-only: write its \`at\` as what holds the words (${f.at} > ${d.tagName}), or give each block a part of its own`}):$&&o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and the editor would leave it read-only for what it holds: ${$.why}. A text part holds words and marks alone`})}return o}var xe="(?:(?:[zcs]h|[bpmfdtnlgkhjqxrzcsyw])?(?:[iuv]?(?:a(?:i|o|ng?)?|e(?:i|r|ng?)?|o(?:u|ng)?)|i(?:u|ng?)?|u(?:i|n)?|vn?))",Me=new RegExp(`^${xe}$`,"i"),De=new RegExp(`^${xe}{1,8}$`,"i"),q=new RegExp("\\p{Script=Han}","u"),Ge=6,ke=t=>[...t].filter(e=>q.test(e)).length;function Ke(t){let e=t.replaceAll("'",""),s=[0,...Array(e.length).fill(1/0)];for(let n=1;n<=e.length;n++)for(let o=Math.max(0,n-Ge);o<n;o++)s[o]+1<s[n]&&Me.test(e.slice(o,n))&&(s[n]=s[o]+1);return e&&Number.isFinite(s[e.length])?s[e.length]:null}function He({name:t,words:e}){let s=ke(t.zh),n=e.split(/\s+/).filter(Boolean);return s===0?q.test(e)&&!n.some(o=>De.test(o)):!n.some(o=>Ke(o.toLowerCase())===s)}function Ye({id:t,folder:e,catalog:s,off:n,parts:o}){let i=s.packages.get(t),a=s.problems.get(t)?.problem,r=O(e,R)??"",l=[];a&&l.push({file:R,line:Be(r,a),what:v("en",a)}),i?.template===null&&l.push({file:w,what:`there is none, and it is what "/" puts in a document: with none, no menu offers the block: write one <div ${k}="${t}"> with what a new instance holds`}),l.push(...o);let c=T(e,"writing.md");c&&l.push(c);let p=c||O(e,"writing.md")?.trim()?[]:[{file:"writing.md",what:"there is none, so gallery component show has nothing to say of how to write it"}];return i&&He(i)&&p.push({file:R,line:H(r,"words")??H(r,"name.zh"),what:q.test(i.name.zh)?`no word of words spells its whole name ${i.name.zh} in pinyin as an input method composes it, its ${ke(i.name.zh)} Chinese characters a syllable each in one word (as \u65B9\u6848\u6253\u5206 is fangandafen): "/" finds it while those letters are being composed only by such a word. What is counted is how many syllables a word reads as, not which characters they spell`:'its words are Chinese and none of them is pinyin: "/" goes by the letters an input method is composing, so write the pinyin there (\u770B\u677F kanban)'}),n&&p.push({file:"gallery.json",what:"the user turned it off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, which is theirs to change and says nothing of the package: it is checked as if it were on, and the instances of a document show what they hold, read-only, until it is on"}),{title:"manifest",problems:l,notes:p}}function qe(t){let e=g.createSourceFile("kit.js",t,g.ScriptTarget.Latest,!0,g.ScriptKind.JS),s=[],n=o=>{let i=g.isCallExpression(o)&&g.isPropertyAccessExpression(o.expression)?o.expression:null;if(i?.name.text==="component"&&/\bDocKit$/.test(i.expression.getText(e))){let[a]=o.arguments,r=a&&g.isObjectLiteralExpression(a)?a.properties.find(c=>c.name?.getText(e)==="id"):null,l=r&&g.isPropertyAssignment(r)&&g.isStringLiteralLike(r.initializer)?r.initializer.text:null;s.push({id:l,at:o.getStart(e)})}g.forEachChild(o,n)};return n(e),s}function Ve(t){let e="kit.js";if(!t.files.includes("kit.js"))return{title:e,none:"none: a static block"};let s=T(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let n=A(t,"kit.js")??"",o=se(n);if(o)return{title:e,stops:!0,problems:[{file:e,line:o.line,what:`a browser refuses it: ${o.message}`}]};let i=te(t).map(({line:c,what:p})=>({file:e,line:c,what:p})),a=i.length>0;for(let{name:c,at:p}of Z(n,Re))i.push({file:e,line:x(n,p),what:`uses ${c}: an instance keeps what a reader chose with context.state`});let r=qe(n);for(let{id:c,at:p}of r)c!==null&&c!==t.id&&i.push({file:e,line:x(n,p),what:`it registers ${c}, and this package is ${t.id}`});let l=r.length?[]:[{file:e,what:`no DocKit.component({ id: "${t.id}", mount(host, context) { \u2026 } }) is to be read in it, and a script may make that call in ways reading does not tell: running it says whether it starts one`}];for(let{line:c,code:p,message:f,refused:h}of Q(n,{assets:t.assets}))(h?i:l).push({file:e,line:c,what:`TS${p}: ${f}`});return{title:e,stops:a,problems:i.sort((c,p)=>(c.line??0)-(p.line??0)),notes:l}}function We(t){let e="style.css";if(!t.files.includes("style.css"))return{title:e,none:"none"};let s=T(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let n=A(t,"style.css")??"",o=ee(t),i=[...ue(n,t.id),...o].map(({line:l,what:c})=>({file:e,line:l,what:c})),a=Object.entries(t.parts??{}).filter(([,{edit:l}])=>l==="flow").map(([l])=>l),r=de(n,t.id,a).map(({line:l,what:c})=>({file:e,line:l,what:c}));return{title:e,stops:o.length>0,problems:i.sort((l,c)=>l.line-c.line),notes:r}}function Je(t,{tree:e}){let s=null;P(e,r=>{s??=r.tagName==="main"?r:null});let n=ye(s??{}),o=(s?.childNodes??[]).some(r=>r.nodeName==="#text"&&r.value.trim()),[i]=n;if(n.length!==1||o||!Ce(i)||I(i,k)!==t)return[{file:w,line:i?.sourceCodeLocation?.startLine,what:`a template is one element, a <div ${k}="${t}"> or a <section>, and it holds ${n.length===1&&!o?`<${i.tagName}${I(i,k)?` ${k}="${I(i,k)}"`:""}>`:`${n.length} element${n.length===1?"":"s"}${o?" and words":""}`}`}];let a=[];return P({childNodes:[i]},r=>{I(r,"data-block-id")!==void 0&&a.push({file:w,line:r.sourceCodeLocation?.startLine,what:"it writes a data-block-id, which every instance made of it would repeat: leave it out, Gallery gives a block its id"})}),a}function Xe(t,{tree:e}){let s=X(t);if(!s)return[];let[n]=Y(e,t),o=null;return n&&P({childNodes:[n]},i=>{Ie(i.tagName,i.attrs)&&(o??=i)}),[{file:w,line:(o??n)?.sourceCodeLocation?.startLine,what:v("en",s)}]}function Ze(t){return[[w,"component-template"],[E,"component-example"]].flatMap(([e,s])=>{let n=O(t,e);if(n===null||!n.trim()||T(t,e))return[];let o=le(s,n),{text:i}=re(o);return[{file:e,slug:s,written:o,html:i,tree:V(i)}]})}function Qe({id:t,folder:e,found:s,pages:n,parts:o}){let i="template.html and example.html",a=[],r=[];for(let h of[w,E]){let m=T(e,h);m?a.push(m):h===w&&!O(e,h)?.trim()&&s.template!==null?a.push({file:h,what:"it is empty"}):h===E&&!n.some(d=>d.file===h)&&a.push({file:h,what:`there is none or it is empty: write an instance as a writer would fill it, a <div ${k}="${t}">; it is what this check runs`})}let l=n.find(h=>h.file===w);l&&a.push(...Je(t,l));let c=n.find(h=>h.file===E);c&&Y(c.tree,s).length===0&&a.push({file:E,what:`it holds no instance of ${t}: a <div ${k}="${t}">`});let p=n.map(({slug:h,written:m,html:d,file:$})=>({file:$,slug:h,written:m,html:d,directory:j.join(e,h),htmlPath:j.join(e,h,"doc.html"),metadata:{title:h,description:h,type:"component"}})),f=ne(p);for(let h of p){for(let m of f.get(h.slug)??[])Pe.test(m)||a.push(G(h.file,ze(m)));for(let m of oe(h))r.push(G(h.file,m));for(let m of F(h.html)){let d=G(h.file,`${m} (read-only in the preview)`);o.some(({file:$,line:b})=>$===d.file&&b===d.line)||r.push(d)}}return l&&!a.some(({file:h})=>h===w)&&a.push(...Xe(s,l)),{title:i,problems:a,notes:r}}function et(t,e){let s=W(t,void 0,{on:e}),n=C(t,e);if(!s.packages.has(e)&&!s.problems.has(e))return null;J(t,s);let o=s.packages.has(e)&&s.settings.disabled.includes(e),i=s.packages.get(e)??{id:e,folder:n,files:["kit.js","style.css"].filter(c=>be.existsSync(j.join(n,c)))},a=Ze(n),r=s.packages.has(e)?null:"its manifest does not load",l=r?[]:a.flatMap(c=>_e(i,c));return{found:s.packages.get(e)??null,pages:a,sections:[Ye({id:e,folder:n,catalog:s,off:o,parts:l}),Ve(i),We(i),r?{title:"template.html and example.html",skipped:r}:Qe({id:e,folder:n,found:i,pages:a,parts:l})]}}var K=({file:t,line:e})=>e?`${t}:${e}`:t;function $e({title:t,problems:e=[],notes:s=[],told:n=[],none:o,skipped:i,unverified:a,pictures:r},l){let c=a?`UNVERIFIED ${a}`:i?`not run: ${i}`:o??(e.length?`${e.length} problem${e.length===1?"":"s"}`:`ok${s.length?`, ${s.length} note${s.length===1?"":"s"}`:""}`);return[`${l}. ${t}: ${c}`,...e.map(p=>` FAIL ${K(p)}: ${p.what}`),...s.map(p=>` note ${K(p)}: ${p.what}`),...n.map(p=>` way back ${K(p)}: ${p.what}`),...r?[tt(r)]:[]]}function tt({folder:t,overviews:e,each:s,edited:n=[],asExport:o=[]}){let i=e.length?`${N(j.join(t,e[0]))}${e.slice(1).map(l=>` and ${l}`).join("")}, the three widths of each theme side by side; then each at full size: `:`${N(t)}: `,a=o.length===0?"":o.length===n.length?", each the same picture as the export's at its width: the block draws nothing more where a reader can edit":`, ${o.join(" and ")} the same picture as the export's at its width`,r=n.length?`; and ${n.join(" and ")}, as the editing page draws it (context.canEdit() true)${a}`:"";return` Pictures (none looked at for you; example.html above the line, template.html below it, each under its name): ${i}${s.join(", ")}${r}`}function st([t,e,s,n]){return t.problems.length?"the manifest":e.stops?"kit.js":s.stops?"style.css":n.skipped||n.problems.length?"template.html and example.html":null}async function Ot(t,e){let s=et(t,e);s||(console.error(he(t,e)),process.exit(1)),console.log(`${e}: ${N(C(t,e))}`),s.sections.forEach((r,l)=>console.log($e(r,l+1).join(`
3
- `)));let n=st(s.sections),o=C(t,e),i=n?{title:ae,skipped:`${n} first`}:await ce(t,s.found,{example:O(o,E),template:O(o,w)});console.log($e(i,5).join(`
4
- `));let a=[...s.sections,i].reduce((r,{problems:l=[]})=>r+l.length,0);a?(console.log(`FAIL ${e}: ${a} problem${a===1?"":"s"}`),process.exitCode=1):i.unverified?(console.log(`UNVERIFIED ${e}: the rest passed, and no browser ran it: export a document that holds it and open that in Chrome or Edge.`),process.exitCode=3):console.log(`OK ${e}`)}export{Ot as checkCommand,Ke as fewestSyllables,et as readSections,$e as sectionLines,He as wantsPinyin};
@@ -1,2 +0,0 @@
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 l,i as u}from"./chunk-NSKUTQ5J.mjs";import h from"node:fs/promises";import{ancestorsIn as f,moveDocument as m,readOutline as p}from"../browser/shared/outline.mjs";import{reportsDirectory as a}from"../browser/shared/paths.mjs";import{findPreviewServer as w}from"../browser/shared/preview-server.mjs";import{roleOf as $}from"../browser/shared/reports.mjs";import{documentDirectory as d,documentFiles as g,pageSlug as y}from"../browser/shared/workspace.mjs";async function D(){let{children:e}=await p(a),t=Object.values(e).flat(),n=r=>typeof r=="string"?r.replace(/\s+/g," ").trim():"",o=new Map(await Promise.all(t.map(async r=>{let i=await h.readFile(g(d(r,a)).json,"utf8").then(JSON.parse).catch(()=>({}));return[r,{slug:r,title:n(i?.title)||r,description:n(i?.description),icon:typeof i?.icon=="string"?i.icon:null}]})));return{children:e,documents:o}}var s=({documents:e},t)=>`${t} (${e.get(t)?.title??t})`;function _(e,t){let n=f(e.children,t).map(o=>s(e,o));return`\u4F4D\u7F6E\uFF1A${n.length?n.join(" \u203A "):"\u9876\u5C42"}`}async function E(e,t,n){let{slug:o}=await u(e);if(o===await y(a))return{refused:`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`};if(!n.documents.has(o)){let r=d(o,a);return{refused:await $(r)==="instructions"?`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`:`No document "${e}" (${t}): gallery list --tree shows the documents and where they are.`}}return{slug:o}}var v={missing:(e,t)=>`No document "${t}" in the sidebar's tree: gallery list --tree shows them.`,parent:(e,t,{parent:n})=>`No document "${n}" to put ${s(e,t)} under: gallery list --tree shows them.`,after:(e,t,{after:n})=>`No document "${n}" to put ${s(e,t)} after: gallery list --tree shows them.`,level:(e,t,{parent:n,after:o})=>`${s(e,o)} is not under ${n?s(e,n):"the top level"}: --after names a document at the level it goes to.`,itself:(e,t)=>`${s(e,t)} cannot go after itself.`,inside:(e,t,{parent:n,after:o})=>n===void 0&&o?`${s(e,t)} cannot go after ${s(e,o)}, which is under it.`:`${s(e,t)} cannot go under ${n===t?"itself":`${s(e,n)}, which is under it`}.`,instructions:(e,t)=>"The \u5199\u4F5C\u504F\u597D page is listed apart: it moves nowhere and holds no documents."},F=(e,t,n,o={})=>(v[n]??((r,i,{message:c})=>`Not moved: ${c??n}.`))(e,t,o);async function b(e,t){let n=`127.0.0.1:${e.port}`;try{let r=await(await fetch(`http://${n}/__gallery/workspace/move`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${n}`,"X-Gallery-Token":e.token},body:JSON.stringify({...t,workspace:a}),signal:AbortSignal.timeout(3e4)})).json().catch(()=>null);return typeof r?.ok!="boolean"||["elsewhere","token","host","origin","unknown"].includes(r.reason)?null:r}catch{return null}}async function L(e,{parent:t=void 0,after:n=null,first:o=!1}={}){let r=await w({reportsDirectory:a}),i={slug:e,...t!==void 0?{parent:t}:{},after:n,first:o},c=r?await b(r,i):null;return c||m(a,e,{parent:t,after:n,first:o})}function P(e,{parent:t,index:n}){let o=e.children[t]??[],r=t?`under ${s(e,t)}`:"at the top level";return o.length===1?`${r}, the only document there`:n===0?`${r}, first`:`${r}, right after ${s(e,o[n-1])}${n===o.length-1?", last":""}`}function I(e,t,{top:n=!0}={}){let o=e.get("--under"),r=e.get("--after");if(o!==void 0&&t.has("--top"))throw new l("--under and --top are two places: give one.");if(r!==void 0&&t.has("--first"))throw new l("--after and --first are two places: give one.");return{under:o,top:n&&t.has("--top"),after:r,first:t.has("--first")}}export{D as a,s as b,_ as c,E as d,F as e,L as f,P as g,I as h};
@@ -1,2 +0,0 @@
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}from"./chunk-Y6RLRPG3.mjs";import"./chunk-E7LWZRXY.mjs";import"./chunk-BGGDRNYQ.mjs";import"./chunk-6QXGZM36.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-TYK6VNAB.mjs";import"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-L3QKH4OK.mjs";import"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
@@ -1,2 +0,0 @@
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 o from"node:path";import{reportsDirectory as t}from"../browser/shared/paths.mjs";import{readWritingPreferences as i,saysAnything as a}from"../browser/shared/writing-preferences.mjs";var e=r=>o.resolve(r);async function f(){let{file:r,text:n,made:s}=await i(t);return[`\u5DE5\u4F5C\u533A\uFF1A${o.resolve(t)}`,a(n)?`\u5199\u4F5C\u504F\u597D\uFF1A\u5148\u8BFB\u5B83\uFF0C\u7167\u5B83\u5199\uFF08${e(r)}${s?"\uFF0C\u8FD9\u6B21\u6309\u9ED8\u8BA4\u7684\u5199\u4F5C\u504F\u597D\u65B0\u5EFA":""}\uFF09`:`\u5199\u4F5C\u504F\u597D\uFF1A\u7A7A\uFF08${e(r)}\uFF09`]}export{e as a,f as b};