@heycys/gallery 0.1.2 → 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 (292) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/browser/editor/components/align.mjs +58 -0
  3. package/browser/editor/components/code/index.mjs +1 -1
  4. package/browser/editor/components/embed/page.mjs +1 -1
  5. package/browser/editor/components/file/page.mjs +4 -4
  6. package/browser/editor/components/heading/index.mjs +7 -6
  7. package/browser/editor/components/icons.mjs +3 -0
  8. package/browser/editor/components/image/index.mjs +2 -0
  9. package/browser/editor/components/image/page.mjs +172 -90
  10. package/browser/editor/components/installed/index.mjs +6 -2
  11. package/browser/editor/components/installed/page.mjs +80 -13
  12. package/browser/editor/components/media/icons.mjs +13 -8
  13. package/browser/editor/components/media/page.mjs +5 -3
  14. package/browser/editor/components/media/toolbar.mjs +12 -3
  15. package/browser/editor/components/paragraph/index.mjs +4 -3
  16. package/browser/editor/components/registry.mjs +17 -5
  17. package/browser/editor/components/table/index.mjs +4 -2
  18. package/browser/editor/page/after/index.mjs +288 -0
  19. package/browser/editor/page/align.mjs +91 -0
  20. package/browser/editor/page/beside.mjs +5 -6
  21. package/browser/editor/page/block-menu/index.mjs +6 -3
  22. package/browser/editor/page/blocks.mjs +3 -1
  23. package/browser/editor/page/board/hint.mjs +64 -27
  24. package/browser/editor/page/board/index.mjs +160 -71
  25. package/browser/editor/page/board/motion.mjs +177 -0
  26. package/browser/editor/page/board/settings.mjs +4 -3
  27. package/browser/editor/page/clipboard/index.mjs +10 -3
  28. package/browser/editor/page/clipboard/own/blocks.mjs +3 -4
  29. package/browser/editor/page/clipboard/own/describe.mjs +6 -2
  30. package/browser/editor/page/commit.mjs +2 -2
  31. package/browser/editor/page/core.mjs +3 -1
  32. package/browser/editor/page/custom-page.mjs +15 -11
  33. package/browser/editor/page/editor.mjs +31 -14
  34. package/browser/editor/page/history.mjs +19 -4
  35. package/browser/editor/page/insert/index.mjs +20 -22
  36. package/browser/editor/page/menu.mjs +15 -7
  37. package/browser/editor/page/page-objects.mjs +3 -7
  38. package/browser/editor/page/present-links.mjs +5 -4
  39. package/browser/editor/page/present-shell.mjs +63 -0
  40. package/browser/editor/page/selection/index.mjs +10 -2
  41. package/browser/editor/page/table/binding.mjs +87 -0
  42. package/browser/editor/page/table/icons.mjs +0 -2
  43. package/browser/editor/page/table/index.mjs +10 -14
  44. package/browser/editor/page/table/views.mjs +5 -52
  45. package/browser/editor/page/table/widths.mjs +82 -10
  46. package/browser/editor/page/typing/index.mjs +44 -12
  47. package/browser/editor/page/typing/leave.mjs +19 -5
  48. package/browser/shared/block-packs.mjs +23 -8
  49. package/browser/shared/component-catalog.mjs +15 -8
  50. package/browser/shared/component-source.mjs +3 -1
  51. package/browser/shared/components/heading.mjs +2 -1
  52. package/browser/shared/components/installed.mjs +1 -1
  53. package/browser/shared/components/page.mjs +2 -0
  54. package/browser/shared/components/paragraph.mjs +8 -1
  55. package/browser/shared/components/table.mjs +1 -0
  56. package/browser/shared/emoji/line-icons.mjs +37 -0
  57. package/browser/shared/http.mjs +9 -0
  58. package/browser/shared/i18n/en.mjs +40 -17
  59. package/browser/shared/outline.mjs +30 -2
  60. package/browser/shared/pack-manifest.mjs +12 -1
  61. package/browser/shared/pages.mjs +169 -57
  62. package/browser/shared/pinyin.mjs +92 -0
  63. package/browser/shared/present-step.mjs +17 -0
  64. package/browser/shared/sidebar-head.mjs +70 -0
  65. package/browser/shared/web-links.mjs +5 -0
  66. package/dist/chunk-2OHANJ6Q.mjs +2 -0
  67. package/dist/{chunk-QOUEFUCH.mjs → chunk-3MBRL2PM.mjs} +1 -1
  68. package/dist/{chunk-NWR2LT5B.mjs → chunk-4OKWZY5E.mjs} +1 -1
  69. package/dist/{chunk-RMECZA2K.mjs → chunk-5K44HLTZ.mjs} +1 -1
  70. package/dist/{chunk-NFMCP2HI.mjs → chunk-5XA2ZBAE.mjs} +2 -2
  71. package/dist/{chunk-OUUP3WKT.mjs → chunk-67N2QJYT.mjs} +1 -1
  72. package/dist/chunk-6KBYRA2C.mjs +2 -0
  73. package/dist/{chunk-SX4LJYT6.mjs → chunk-6N3PX4XX.mjs} +1 -1
  74. package/dist/{chunk-RFDZXFJF.mjs → chunk-7JDX4E65.mjs} +1 -1
  75. package/dist/chunk-7M2BQQGZ.mjs +2 -0
  76. package/dist/{chunk-ZUNVAXLH.mjs → chunk-7OG26PGF.mjs} +1 -1
  77. package/dist/{chunk-B4P2CM2J.mjs → chunk-AHN3NFKJ.mjs} +1 -1
  78. package/dist/chunk-ALZ6ZENZ.mjs +3 -0
  79. package/dist/{chunk-UGWYKHBL.mjs → chunk-AR5D57ZD.mjs} +2 -2
  80. package/dist/{chunk-W3BGBJQW.mjs → chunk-BFJGHSQN.mjs} +1 -1
  81. package/dist/{chunk-HLYV7RIH.mjs → chunk-CMA72MAG.mjs} +1 -1
  82. package/dist/{chunk-D4CKRD3V.mjs → chunk-DAZL73VK.mjs} +2 -2
  83. package/dist/{chunk-6VTU6KEO.mjs → chunk-DJISHPUL.mjs} +1 -1
  84. package/dist/{chunk-BPL64HGA.mjs → chunk-EAIFITAV.mjs} +1 -1
  85. package/dist/chunk-EP25HDAJ.mjs +2 -0
  86. package/dist/{chunk-6EZ7FNIK.mjs → chunk-F4ZA6JRZ.mjs} +1 -1
  87. package/dist/{chunk-3KJHLHUO.mjs → chunk-F6HVDZR4.mjs} +1 -1
  88. package/dist/{chunk-3NJACR4W.mjs → chunk-FDMAXMQA.mjs} +1 -1
  89. package/dist/chunk-FETSREUN.mjs +5 -0
  90. package/dist/{chunk-RKPWLGZ3.mjs → chunk-GHOYKMQ3.mjs} +1 -1
  91. package/dist/chunk-HDWTZ763.mjs +12 -0
  92. package/dist/{chunk-VTKNEYT3.mjs → chunk-HPOI4ZX7.mjs} +1 -1
  93. package/dist/{chunk-OW5NWPOJ.mjs → chunk-HXG7EOPJ.mjs} +1 -1
  94. package/dist/{chunk-V6RIYQZZ.mjs → chunk-ITOH5EGO.mjs} +1 -1
  95. package/dist/{chunk-ZWPMCK7P.mjs → chunk-IV64FFI4.mjs} +1 -1
  96. package/dist/chunk-J43Z6LSS.mjs +2 -0
  97. package/dist/chunk-J5PUIV3Y.mjs +4 -0
  98. package/dist/{chunk-KTKHRC6H.mjs → chunk-JA7G53PC.mjs} +1 -1
  99. package/dist/{chunk-NWFBE2YA.mjs → chunk-JLTZF4LA.mjs} +1 -1
  100. package/dist/{chunk-GY3FAUVM.mjs → chunk-JZT7I2OJ.mjs} +1 -1
  101. package/dist/{chunk-QKXMPUXC.mjs → chunk-K5XATEOO.mjs} +1 -1
  102. package/dist/chunk-L2SUIS5S.mjs +2 -0
  103. package/dist/{chunk-TEZAWDSQ.mjs → chunk-LM4XFQHZ.mjs} +1 -1
  104. package/dist/{chunk-5ZJA7CXT.mjs → chunk-MN7BZL4R.mjs} +1 -1
  105. package/dist/chunk-MTYYHM2G.mjs +15 -0
  106. package/dist/{chunk-HMYTM3GT.mjs → chunk-MXUBKDRO.mjs} +1 -1
  107. package/dist/{chunk-MHW7ZKOU.mjs → chunk-OEXWRJME.mjs} +1 -1
  108. package/dist/{chunk-CRJEG7MT.mjs → chunk-OFHXGWOX.mjs} +1 -1
  109. package/dist/chunk-ORID3AE7.mjs +166 -0
  110. package/dist/{chunk-32ZUEFZ7.mjs → chunk-PGDE24N5.mjs} +1 -1
  111. package/dist/{chunk-UNOYVIYR.mjs → chunk-POTA2FV4.mjs} +1 -1
  112. package/dist/{chunk-N7AZZLGT.mjs → chunk-QE5RG76S.mjs} +18 -17
  113. package/dist/{chunk-N76HWBA3.mjs → chunk-R2ZDLJYT.mjs} +1 -1
  114. package/dist/chunk-SWUTTZCN.mjs +2 -0
  115. package/dist/{chunk-POQSE4C2.mjs → chunk-TR7TWGHB.mjs} +1 -1
  116. package/dist/chunk-U5XL7D6A.mjs +3 -0
  117. package/dist/{chunk-PVER7LSC.mjs → chunk-U7NZI6N4.mjs} +2 -2
  118. package/dist/{chunk-Q47PLKIJ.mjs → chunk-UGWMMEJ5.mjs} +1 -1
  119. package/dist/chunk-UJQJKNGK.mjs +2 -0
  120. package/dist/chunk-UYVCQK3H.mjs +22 -0
  121. package/dist/{chunk-FJYN7RTH.mjs → chunk-VFX2KNHP.mjs} +1 -1
  122. package/dist/{chunk-UBBRTJ2R.mjs → chunk-VS7JIGJW.mjs} +1 -1
  123. package/dist/{chunk-NVRNLK25.mjs → chunk-W7665ZEC.mjs} +2 -2
  124. package/dist/{chunk-NG375ILQ.mjs → chunk-WQDQWCX5.mjs} +1 -1
  125. package/dist/chunk-YLPSMDIS.mjs +5 -0
  126. package/dist/{chunk-VXACTLO3.mjs → chunk-YNAWBAYN.mjs} +1 -1
  127. package/dist/{chunk-ZB4H7ZN4.mjs → chunk-YROX2O22.mjs} +1 -1
  128. package/dist/{chunk-YQGT4AB2.mjs → chunk-ZDLPUOAG.mjs} +1 -1
  129. package/dist/chunk-ZQS6H473.mjs +16 -0
  130. package/dist/{chunk-OJKMINIU.mjs → chunk-ZWWC4KLF.mjs} +15 -15
  131. package/dist/cli.mjs +1 -1
  132. package/dist/server.mjs +1 -1
  133. package/dist/worker.mjs +1 -1
  134. package/kit/board.css +5 -5
  135. package/kit/code.js +15 -15
  136. package/kit/report.css +120 -41
  137. package/kit/runtime.js +45 -7
  138. package/kit/tables.js +2 -0
  139. package/kit/ui.js +2 -0
  140. package/package.json +1 -1
  141. package/packs/gallery/chart-view/kit.js +3 -3
  142. package/packs/gallery/chart-view/writing.md +1 -1
  143. package/packs/gallery/countdown/component.json +1 -1
  144. package/packs/gallery/countdown/kit.js +89 -29
  145. package/packs/gallery/countdown/preview.svg +1 -1
  146. package/packs/gallery/countdown/style.css +88 -100
  147. package/packs/gallery/countdown/writing.md +2 -2
  148. package/packs/gallery/habit/component.json +3 -3
  149. package/packs/gallery/habit/kit.js +114 -75
  150. package/packs/gallery/habit/preview.svg +1 -1
  151. package/packs/gallery/habit/style.css +133 -205
  152. package/packs/gallery/habit/writing.md +2 -2
  153. package/packs/gallery/heatmap/component.json +2 -2
  154. package/packs/gallery/heatmap/kit.js +335 -173
  155. package/packs/gallery/heatmap/preview.svg +1 -1
  156. package/packs/gallery/heatmap/style.css +158 -170
  157. package/packs/gallery/heatmap/writing.md +2 -2
  158. package/packs/gallery/kanban/kit.js +3 -3
  159. package/packs/gallery/kanban/writing.md +1 -1
  160. package/packs/gallery/metric/kit.js +3 -3
  161. package/packs/gallery/metric/writing.md +1 -1
  162. package/packs/gallery/note/component.json +3 -3
  163. package/packs/gallery/note/kit.js +40 -13
  164. package/packs/gallery/note/preview.svg +1 -1
  165. package/packs/gallery/note/style.css +51 -30
  166. package/packs/gallery/note/writing.md +2 -2
  167. package/packs/gallery/recent/component.json +2 -2
  168. package/packs/gallery/recent/kit.js +141 -86
  169. package/packs/gallery/recent/preview.svg +1 -1
  170. package/packs/gallery/recent/style.css +53 -126
  171. package/packs/gallery/recent/writing.md +2 -2
  172. package/packs/gallery/static/component.json +2 -2
  173. package/packs/gallery/static/preview.svg +1 -1
  174. package/packs/gallery/static/style.css +99 -66
  175. package/packs/gallery/static/writing.md +2 -2
  176. package/packs/gallery/stats/component.json +3 -3
  177. package/packs/gallery/stats/kit.js +253 -72
  178. package/packs/gallery/stats/preview.svg +1 -1
  179. package/packs/gallery/stats/style.css +64 -142
  180. package/packs/gallery/stats/writing.md +2 -2
  181. package/packs/gallery/today/component.json +2 -2
  182. package/packs/gallery/today/kit.js +62 -27
  183. package/packs/gallery/today/preview.svg +1 -1
  184. package/packs/gallery/today/style.css +101 -72
  185. package/packs/gallery/today/writing.md +2 -2
  186. package/packs/gallery/todos/component.json +1 -1
  187. package/packs/gallery/todos/kit.js +218 -71
  188. package/packs/gallery/todos/preview.svg +1 -1
  189. package/packs/gallery/todos/style.css +170 -223
  190. package/packs/gallery/todos/writing.md +1 -1
  191. package/packs/gallery/weather/component.json +2 -2
  192. package/packs/gallery/weather/kit.js +165 -90
  193. package/packs/gallery/weather/preview.svg +1 -1
  194. package/packs/gallery/weather/style.css +100 -218
  195. package/packs/gallery/weather/writing.md +1 -1
  196. package/packs/gallery-soft/countdown/component.json +18 -0
  197. package/packs/gallery-soft/countdown/example.html +3 -0
  198. package/packs/gallery-soft/countdown/kit.js +206 -0
  199. package/packs/gallery-soft/countdown/preview.svg +1 -0
  200. package/packs/gallery-soft/countdown/style.css +211 -0
  201. package/packs/gallery-soft/countdown/template.html +3 -0
  202. package/packs/gallery-soft/countdown/writing.md +24 -0
  203. package/packs/gallery-soft/habit/component.json +14 -0
  204. package/packs/gallery-soft/habit/example.html +3 -0
  205. package/packs/gallery-soft/habit/kit.js +366 -0
  206. package/packs/gallery-soft/habit/preview.svg +1 -0
  207. package/packs/gallery-soft/habit/style.css +251 -0
  208. package/packs/gallery-soft/habit/template.html +3 -0
  209. package/packs/gallery-soft/habit/writing.md +23 -0
  210. package/packs/gallery-soft/heatmap/component.json +18 -0
  211. package/packs/gallery-soft/heatmap/example.html +3 -0
  212. package/packs/gallery-soft/heatmap/kit.js +498 -0
  213. package/packs/gallery-soft/heatmap/preview.svg +1 -0
  214. package/packs/gallery-soft/heatmap/style.css +181 -0
  215. package/packs/gallery-soft/heatmap/template.html +3 -0
  216. package/packs/gallery-soft/heatmap/writing.md +23 -0
  217. package/packs/gallery-soft/note/component.json +14 -0
  218. package/packs/gallery-soft/note/example.html +3 -0
  219. package/packs/gallery-soft/note/kit.js +162 -0
  220. package/packs/gallery-soft/note/preview.svg +1 -0
  221. package/packs/gallery-soft/note/style.css +148 -0
  222. package/packs/gallery-soft/note/template.html +3 -0
  223. package/packs/gallery-soft/note/writing.md +20 -0
  224. package/packs/gallery-soft/recent/component.json +13 -0
  225. package/packs/gallery-soft/recent/example.html +1 -0
  226. package/packs/gallery-soft/recent/kit.js +335 -0
  227. package/packs/gallery-soft/recent/preview.svg +1 -0
  228. package/packs/gallery-soft/recent/style.css +160 -0
  229. package/packs/gallery-soft/recent/template.html +1 -0
  230. package/packs/gallery-soft/recent/writing.md +17 -0
  231. package/packs/gallery-soft/static/component.json +13 -0
  232. package/packs/gallery-soft/static/example.html +12 -0
  233. package/packs/gallery-soft/static/preview.svg +1 -0
  234. package/packs/gallery-soft/static/style.css +186 -0
  235. package/packs/gallery-soft/static/template.html +1 -0
  236. package/packs/gallery-soft/static/writing.md +20 -0
  237. package/packs/gallery-soft/stats/component.json +13 -0
  238. package/packs/gallery-soft/stats/example.html +1 -0
  239. package/packs/gallery-soft/stats/kit.js +341 -0
  240. package/packs/gallery-soft/stats/preview.svg +1 -0
  241. package/packs/gallery-soft/stats/style.css +119 -0
  242. package/packs/gallery-soft/stats/template.html +1 -0
  243. package/packs/gallery-soft/stats/writing.md +13 -0
  244. package/packs/gallery-soft/today/component.json +12 -0
  245. package/packs/gallery-soft/today/example.html +1 -0
  246. package/packs/gallery-soft/today/kit.js +222 -0
  247. package/packs/gallery-soft/today/preview.svg +1 -0
  248. package/packs/gallery-soft/today/style.css +178 -0
  249. package/packs/gallery-soft/today/template.html +1 -0
  250. package/packs/gallery-soft/today/writing.md +16 -0
  251. package/packs/gallery-soft/todos/component.json +19 -0
  252. package/packs/gallery-soft/todos/example.html +3 -0
  253. package/packs/gallery-soft/todos/kit.js +527 -0
  254. package/packs/gallery-soft/todos/preview.svg +1 -0
  255. package/packs/gallery-soft/todos/style.css +212 -0
  256. package/packs/gallery-soft/todos/template.html +3 -0
  257. package/packs/gallery-soft/todos/writing.md +32 -0
  258. package/packs/gallery-soft/weather/component.json +19 -0
  259. package/packs/gallery-soft/weather/example.html +3 -0
  260. package/packs/gallery-soft/weather/kit.js +411 -0
  261. package/packs/gallery-soft/weather/preview.svg +1 -0
  262. package/packs/gallery-soft/weather/style.css +185 -0
  263. package/packs/gallery-soft/weather/template.html +3 -0
  264. package/packs/gallery-soft/weather/writing.md +28 -0
  265. package/release.json +9 -9
  266. package/skill/SKILL.md +12 -12
  267. package/skill/references/building-blocks.md +4 -4
  268. package/skill/references/pages-and-data.md +13 -9
  269. package/skill/references/writing-html.md +2 -0
  270. package/web/assets/index-BM_K-Auu.css +1 -0
  271. package/web/assets/index-DRslOBiv.js +15 -0
  272. package/web/index.html +2 -2
  273. package/dist/chunk-2NRBY6AJ.mjs +0 -2
  274. package/dist/chunk-35NQ4PLQ.mjs +0 -2
  275. package/dist/chunk-4AV456RQ.mjs +0 -2
  276. package/dist/chunk-5XYHDBJ5.mjs +0 -2
  277. package/dist/chunk-6A53MZYZ.mjs +0 -2
  278. package/dist/chunk-6EXH3ORZ.mjs +0 -166
  279. package/dist/chunk-BVEFGE4B.mjs +0 -2
  280. package/dist/chunk-D4EURAX4.mjs +0 -4
  281. package/dist/chunk-DQCE7TJY.mjs +0 -5
  282. package/dist/chunk-FWNRPMCJ.mjs +0 -12
  283. package/dist/chunk-FWW4CSAZ.mjs +0 -2
  284. package/dist/chunk-JVHHHGEA.mjs +0 -3
  285. package/dist/chunk-PZDLJJTJ.mjs +0 -3
  286. package/dist/chunk-SXHBYZST.mjs +0 -16
  287. package/dist/chunk-UFNYFFKO.mjs +0 -20
  288. package/dist/chunk-UKSHDZZ6.mjs +0 -2
  289. package/dist/chunk-VJPFVNNW.mjs +0 -15
  290. package/dist/chunk-VS3ZMVGX.mjs +0 -5
  291. package/web/assets/index-BK2e_07w.js +0 -13
  292. package/web/assets/index-CWFI83mF.css +0 -1
@@ -1,12 +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 H,c as X,e as ve}from"./chunk-A55HN5OK.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Me}from"node:crypto";import{existsSync as De,lstatSync as Pe,readFileSync as v,readdirSync as Ce,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ge,parsePart as Ke,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{PACK_FILE as ne,PACK_ID as he,readPackManifest as ot}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as it,PACKAGE_MANIFEST as I,WORKSPACE_MARK as rt,findWorkspace as at,layoutOf as K,markerOf as ct,packageFolders as lt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),ft=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],dt=["at","edit","optional","min","max"],pt=["generated","attrs"],mt=["document","page"],ut=["document"],ht=["sizes","w","h","min","max","resize","fit","bare"],y={w:12,h:24},wt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},yt=["key","label","type","options","default","required"],bt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],gt=/^\d{4}-\d{2}-\d{2}$/,kt="settings",Ot=["workspace","tables"],$t=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,St=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Et=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:St(n)}:s])),At=["parts","text"],we=["kit.js","style.css","preview.svg"],P="template.html",Nt=[I,P,...we],V=e=>[...new Set([...Nt,...e])].sort(),jt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,Tt=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Me("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=Pe(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&v(s)}catch{return null}}var ce=new Map,zt=2e3;function It(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(v(e)));return Date.now()-s>zt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=It(o))}catch{}s.update(`${t}\0${f}
3
- `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},x=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},C=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ge(n).tag);function vt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),x(n,dt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ke(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}$t.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var _t=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Mt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),x(e,pt,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(c){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,c.message))}return d.split(",").map(c=>c.trim().startsWith(":scope")?c.trim().replace(":scope",s):`${s} ${c.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)Tt.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let l=d=>{let a=t(d,"runtime.generated");return _t(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(l),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var z=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Dt(e){return e===void 0?ut:((!Array.isArray(e)||e.length===0||!e.every(n=>mt.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Pt(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),x(e,ht,"card.");let n=a=>Array.isArray(a)&&a.length===2&&z(a[0],y.w)&&z(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let c=["w","h"].find(p=>e[p]!==void 0);c&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",c))}for(let a of["w","h"])e[a]!==void 0&&!z(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let c=e[a];if(c!==void 0){u(c)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),x(c,["w","h"],`card.${a}.`);for(let p of["w","h"])c[p]!==void 0&&!z(c[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=c}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,l=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([c,p])=>c<t.w||c>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let c={w:f,h:l}[a];c!==null&&!e.sizes&&(c<t[a]||c>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,c,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!wt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),{sizes:e.sizes?e.sizes.map(([a,c])=>[a,c]):null,any:d,w:f,h:l,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1}}var Ct=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&gt.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Ft(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let l=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",l)),x(o,yt,`${l}.`),(typeof o.key!="string"||!bt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",l)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),C(o.label,`${l}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",l,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",l)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",l,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",l)),o.default!==void 0&&!Ct(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",l,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",l))});let t=n[kt];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Lt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Ot.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Rt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Gt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)jt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Kt(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))it.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});x(t,ft),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),C(t.name,"name"),C(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))vt(w,$);let o=Mt(t.runtime,e),{kit:f,own:l}=Gt(t.assets,n);t.markdown!==void 0&&!At.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Dt(t.places);Rt(d,t.parts);let a=Pt(t.card),c=Ft(t.settings,t.parts),p=Lt(t.needs),h=ye(n,P);return h&&ge(h,P),{id:e,match:Ze(e),parts:Et(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:c,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...l])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(l))}}function Vt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Kt(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var _=()=>at().root,Ut=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,E=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Wt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,E(s,me)]).filter(([,n])=>n.length>0)),Bt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),M=e=>{let n=Bt(e?.components?.packs);return{hidden:E(e?.components?.hidden,Ut),disabled:E(e?.components?.disabled,A),shown:E(e?.components?.shown,A),unlisted:E(e?.components?.unlisted,A),net:Wt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),Jt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ct(e);return s?{value:n}:{problem:t?Jt:B}}function ke(e){try{return L(v(K(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var gn=(e=_())=>M(ke(e).value),Zt=["EPERM","EACCES","EBUSY","EROFS"];async function kn(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:l,pack:d,enabled:a}){let c=K(e).marker,p=await Le.readFile(c,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:Te,unlisted:ze}=M(h),g=u(h?.components)?h.components:{},Z=$(Te,t),q=$(ze,f),T={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};T.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(l!==void 0){let m={...u(g.net)?g.net:{}};l.length>0?m[n]=[...new Set(l)]:delete m[n],Object.keys(m).length>0?T.net=m:delete T.net}await He(c,`${JSON.stringify({...h??rt,components:T},null,2)}
4
- `,{expect:p}).catch(m=>{throw Zt.includes(m.code)&&r(i("gallery.json \u5199\u4E0D\u8FDB\u53BB\uFF1A\u53EF\u80FD\u662F\u53EA\u8BFB\u7684\uFF0C\u6216\u88AB\u522B\u7684\u7A0B\u5E8F\u5360\u7740")),m})||r(i("gallery.json \u521A\u521A\u88AB\u6539\u8FC7\uFF1A\u518D\u8BD5\u4E00\u6B21"))}var qt=e=>({...e,off:!0,disabled:!0,problem:i("\u5728\u8BBE\u7F6E\u91CC\u505C\u7528\u4E86"),stamp:S(n=>n.update(`${e.stamp} off`))}),D=M(null),Yt=({packages:e,problems:n,settings:s=D,packs:t=new Map})=>S(o=>{for(let{id:f,stamp:l}of[...e.values(),...n.values()].sort(U))o.update(`${f} ${l}
5
- `);o.update(`hidden ${[...s.hidden].sort().join(" ")}
6
- `),o.update(`shown ${[...s.shown].sort().join(" ")}
7
- `),o.update(`unlisted ${[...s.unlisted??[]].sort().join(" ")}
8
- `),o.update(`net ${Oe(s).join(" ")}
9
- `),o.update(`packs off ${(s.packsOff??[]).join(" ")}
10
- `);for(let[f,l]of[...t].sort(([d],[a])=>d<a?-1:1))o.update(`pack ${f} ${JSON.stringify(l)}
11
- `);o.update(`settings ${s.problem?.message??""}
12
- `)}),Oe=({net:e={}})=>Object.entries(e).flatMap(([n,s])=>s.map(t=>`${n}@${t}`)).sort();function Ht(e,n){let{value:s,problem:t}=ke(e);return t?{hidden:n.hidden,disabled:n.disabled,shown:n.shown??[],unlisted:n.unlisted??[],net:n.net??{},packs:n.packs??{},packsOff:n.packsOff??[],problem:t}:M(s)}var R=null,$e=[],On=(e,n=["gallery"])=>{R=e,$e=[...n]};function Xt(e=_(),n=D,{on:s=null}={}){let t=Ht(e,n),o=new Map,f=new Map,l=lt(e),d=l.map(({id:c})=>c).filter(c=>$e.includes(c.split("/")[0]));if(R&&d.length>0)try{R(e,d)}catch{}for(let{id:c,folder:p}of l){let h=Vt(c,p);(h.problem?f:o).set(h.id,h)}for(let c of o.keys())f.delete(c);for(let c of t.disabled)!o.has(c)||c===s||(f.set(c,qt(o.get(c))),o.delete(c));let a=Qt(e,l.map(({id:c})=>c.split("/")[0]));return{packages:o,problems:f,settings:t,packs:a,stamp:Yt({packages:o,problems:f,settings:t,packs:a})}}function Qt(e,n=[]){let{components:s}=K(e),t=[];try{t=Ce(s).filter(f=>he.test(f)&&De(k.join(s,f,ne)))}catch{}let o=new Map;for(let f of[...new Set([...n,...t])].sort()){let l=null;try{l=ot(v(k.join(s,f,ne),"utf8")).name}catch{}o.set(f,l)}return o}var N=new Map;function $n(e=_()){let n=k.resolve(e);return N.has(n)||N.set(n,Xt(n)),N.get(n)}var xn=(e,n)=>{N.set(k.resolve(e),n)},Sn=(e=_())=>{N.delete(k.resolve(e))},fe=(e,n)=>tt(e,()=>st(n)),J=e=>({zh:fe("zh",e),en:fe("en",e)}),En=({settings:e})=>e.problem?J(e.problem):null,xe=(e,n)=>e.problem?e.disabled?"disabled":"broken":Ye(e.id,n,e.places),Se=({id:e,match:n,parts:s,runtime:t,schema:o,needs:f})=>({id:e,match:n,parts:s,...t?{runtime:t}:{},...o!==void 0?{schema:o}:{},...f?.length?{needs:f}:{}}),An=({packages:e,problems:n})=>[...[...e.values()].map(Se),...[...n.values()].map(({id:s,problem:t})=>({id:s,problem:J(t)}))],en=e=>`DocKit.describe(${JSON.stringify(e)});`.replace(/</g,"\\u003c"),G=({id:e,stamp:n},s)=>`/__gallery/components/${e}/${s}?v=${n}`;function tn(e){let n=`${Be}="${e.id}"`,s=t=>e.files.includes(t);return{styles:s("style.css")?[`<link rel="stylesheet" href="${G(e,"style.css")}" ${n}>`]:[],scripts:[`<script ${n}>${en({...Se(e),...s("kit.js")?{script:!0}:{}})}</script>`,...s("kit.js")?[`<script src="${G(e,"kit.js")}" ${n}></script>`]:[]]}}var Nn=({folder:e},n)=>j(e,n),jn=({folder:e,files:n})=>W(e,V(n));function de(e,n){let s=X(e,{sourceCodeLocationInfo:!0}).childNodes.filter(o=>o.tagName||o.nodeName==="#text"&&o.value.trim()),[t]=s;return s.length===1&&t.tagName&&Re(t)&&Xe(t,pe)===n&&t.sourceCodeLocation.endTag?t:null}function nn(e,n){let s=de(e,n),t=s&&H(s),o=t&&de(t,n);return o?{markup:t,root:o}:null}function Ee({id:e,template:n,parts:s}){if(!n)return{};let t=nn(n,e);if(!t)return{problem:i("template.html \u8981\u662F\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u7684\u4E00\u4E2A\u5B9E\u4F8B\uFF0C\u6709\u81EA\u5DF1\u7684\u7ED3\u675F\u6807\u7B7E\uFF0C\u6B64\u5916\u4EC0\u4E48\u90FD\u6CA1\u6709")};let o=[];if(Qe({childNodes:[t.root]},l=>{qe(l.tagName,l.attrs)&&o.push(l.tagName)}),o.length>0)return{problem:i("template.html \u91CC\u7684 <{0}> \u8FDB\u4E0D\u4E86\u65B0\u5EFA\u7684\u5757\uFF1A\u811A\u672C\u3001\u4E8B\u4EF6\u3001\u6837\u5F0F\u548C Gallery \u81EA\u5DF1\u7684\u6807\u8BB0\u90FD\u4E0D\u5199\u5728\u6A21\u677F\u91CC",o[0])};let f=Object.entries(s).find(([,l])=>{let d=Ue(t.root,l.at).length;return d<(l.optional?0:l.min??1)||d>(l.edit==="flow"?1:l.max??1/0)});return f?{problem:i("template.html \u7684 {0} \u548C\u6E05\u5355\u5199\u7684\u6570\u76EE\u4E0D\u7B26",f[0])}:{markup:t.markup}}var Tn=e=>Ee(e).problem??null,Ae=e=>Ee(e).markup??null,zn=({packages:e,settings:n=D,packs:s=new Map})=>[...e.values()].sort(U).map(t=>({id:t.id,version:t.version,name:t.name,description:t.description,words:t.words,definition:t.definition,stamp:t.stamp,template:Ae(t),preview:t.files.includes("preview.svg")?G(t,"preview.svg"):null,state:xe(t,n),places:t.places,needs:t.needs,markdown:t.markdown,assets:t.assets,tags:tn(t),pack:{id:t.id.split("/")[0],name:s.get(t.id.split("/")[0])??null}})),In=({packages:e,problems:n,settings:s=D})=>[...e.values(),...n.values()].sort(U).map(t=>({id:t.id,pack:t.id.split("/")[0],version:t.version??null,name:t.name??null,description:t.description??null,state:xe(t,s),reason:t.problem&&!t.off?J(t.problem):null,template:!!Ae(t),places:t.places??null,needs:t.needs??null,hidden:s.hidden.includes(t.id),shown:s.shown.includes(t.id),disabled:s.disabled.includes(t.id),unlisted:(s.unlisted??[]).includes(t.id),allowed:(s.net?.[t.id]??[]).filter(o=>et(t.needs).includes(o)),menu:Je(t.places,{...s,disabled:[],unlisted:[],packsOff:[]},t.id)})),vn=e=>`settings ${e.hidden.join(",")} ${e.disabled.join(",")} ${e.shown.join(",")} ${Oe(e).join(",")} ${(e.unlisted??[]).join(",")} ${(e.packsOff??[]).join(",")}`;export{kt as a,gn as b,kn as c,Yt as d,On as e,Xt as f,$n as g,xn as h,Sn as i,fe as j,En as k,An as l,en as m,G as n,tn as o,Nn as p,jn as q,nn as r,Tn as s,Ae as t,zn as u,In as v,vn as w};
@@ -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}from"./chunk-NVRNLK25.mjs";import"./chunk-RFDZXFJF.mjs";import"./chunk-QOUEFUCH.mjs";import"./chunk-VTKNEYT3.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-BPL64HGA.mjs";import"./chunk-6A53MZYZ.mjs";import"./chunk-UGWYKHBL.mjs";import"./chunk-OUUP3WKT.mjs";import"./chunk-NFMCP2HI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-NWFBE2YA.mjs";import"./chunk-PUOQ65NC.mjs";import"./chunk-ZUNVAXLH.mjs";import"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-UKSHDZZ6.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import"./chunk-SXHBYZST.mjs";import"./chunk-N7AZZLGT.mjs";import"./chunk-UFNYFFKO.mjs";import"./chunk-D4EURAX4.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-HMYTM3GT.mjs";import"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import"./chunk-UBBRTJ2R.mjs";import"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as PAGE_ASIDE,b as PAGE_INSIDE_ALONE,e as cardChangesOf,c as firstInstance,d as outsideWhat,g as pageHost,f as pageSaves,h as pageTryCommand};
@@ -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{a as v,b as j}from"./chunk-HYMEEXKN.mjs";import c from"node:fs";import f from"node:path";import V from"node:zlib";import{escapeAttribute as $,escapeMarkup as _}from"../browser/shared/escape.mjs";import{componentOf as b,instancesOf as L,partOf as O}from"../browser/shared/components/index.mjs";import{ICON_COLOR_VALUES as I,TAB_ICON as N,glyphOf as T,iconKind as u,iconUrl as A,iconValueOf as h,tabIconValue as R}from"../browser/shared/emoji/icon-value.mjs";import{mediaTypeOf as B,mediaUrl as z}from"../browser/shared/media.mjs";import{emojiDataDirectory as J,reportsDirectory as E}from"../browser/shared/paths.mjs";import{slugPattern as P}from"../browser/shared/reports.mjs";import{documentDirectory as D}from"../browser/shared/workspace.mjs";var g=J,k=String.fromCodePoint(65039),C=null,x=null;function G(){return C??={positions:JSON.parse(c.readFileSync(f.join(g,"positions.json"),"utf8")),index:JSON.parse(c.readFileSync(f.join(g,"twemoji-index.json"),"utf8")),svg:V.gunzipSync(c.readFileSync(f.join(g,"twemoji-svg.bin")))},C}function F(t){let{positions:e,index:n,svg:o}=G(),r=[t,t.replaceAll(k,""),`${t}${k}`].find(a=>e[a]),i=r&&n[e[r][0]];return i?o.subarray(i[0],i[0]+i[1]):null}function U(t){let e=F(t);return e?`data:image/svg+xml;base64,${e.toString("base64")}`:null}function mt(t){return d(""),[...x.keys()].filter(e=>e.startsWith(`${t}/`)).map(e=>e.slice(t.length+1))}function d(t,e="currentColor"){x??=new Map(JSON.parse(c.readFileSync(f.join(g,"icons.json"),"utf8")).icons.flatMap(([,r,i,a,l])=>[[`mingcute/${r}`,a],[`tabler/${i}`,l]].filter(([,s])=>s)));let n=T(t),o=n&&x.get(`${n.set}/${n.name}`);return o?o.split("#COLOR").join(e).replace("<svg ",'<svg aria-hidden="true" '):null}function H(t){let[e,n]=I[T(t)?.color]??I.gray,o=d(t);return o&&o.replace(/<svg\b[^>]*>/,r=>`${r.replace(/ aria-hidden="true"/,"").replace(/^<svg /,'<svg xmlns="http://www.w3.org/2000/svg" ').replace(/ xmlns="http:\/\/www\.w3\.org\/2000\/svg"(?=.* xmlns=)/,"")}<style>svg{color:${e}}@media (prefers-color-scheme:dark){svg{color:${n}}}</style>`)}var K=t=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><text x="18" y="18" text-anchor="middle" dominant-baseline="central" font-size="30" font-family="'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif">${_(t)}</text></svg>`;function W({value:t,slug:e=null,tab:n=!1,reportsDirectory:o=E}){let r=u(t);if(r==="emoji")return{type:"image/svg+xml",body:F(t)??Buffer.from(K(t))};if(r==="glyph"){let a=n?H(t):d(t,"#000");return a&&{type:"image/svg+xml",body:Buffer.from(a)}}if(r!=="image"||!e||!P.test(e))return null;let i=f.join(D(e,o),t);return c.existsSync(i)?{type:B(t),body:c.readFileSync(i)}:null}var M=/(<div\b[^>]*\bclass="doc-icon"[^>]*>)([\s\S]*?)(<\/div>)/g;function gt(t,{slug:e,mode:n="export",reportsDirectory:o=E}){return tt(Q(t,{mode:n}).replace(M,(r,i,a,l)=>{let s=h(r),y=u(s);if(!y)return r;let p=null;if(y==="emoji"){let m=U(s);p=m&&`<img alt="${$(s)}" src="${m}">`}else if(y==="glyph")p=d(s);else if(n==="preview")p=`<img src="${z("asset",e,s)}" alt="">`;else{let m=f.join(D(e,o),s),S=c.existsSync(m)?c.readFileSync(m):null;p=S&&`<img src="data:${B(s)};base64,${S.toString("base64")}" alt="">`}let w=n==="preview"?i.replace(/>$/,` data-ge-icon="${$(s)}">`):i;return p?`${w}${p}${l}`:`${w}${a}${l}`}),Z(Y(t),{slug:e,mode:n,reportsDirectory:o}))}var ut=t=>[...t.matchAll(M)].flatMap(e=>{let n=u(h(e[0]))==="image"?/<img\b[^>]*\bsrc="/.exec(e[2]):null;return n?[e.index+e[1].length+n.index]:[]}),q=/<button\b[^>]*\bdata-tab-icon="([^"]*)"[^>]*>/g;function Q(t,{mode:e="export"}={}){return t.replace(q,(n,o)=>{if(u(o)!=="emoji"||n.includes(N))return n;let r=e==="preview"?A(o):U(o);if(!r)return n;let i=`${N}: ${R(r)}`;return/\sstyle="/.test(n)?n.replace(/\sstyle="([^"]*)"/,(a,l)=>` style="${l.replace(/;?\s*$/,"; ")}${i}"`):n.replace(/>$/,` style="${i}">`)})}function X(t){let e=O(t,b("page").header)[0];return{all:L(t,b("icon")),own:e?O(e,b("icon").match):[]}}function Y(t){let[e]=X(v(t)).own;return e?h(j(t,e)):null}function Z(t,{slug:e,mode:n,reportsDirectory:o}){if(!t)return null;if(n==="preview")return A(t,e,{tab:!0});let r=W({value:t,slug:e,tab:!0,reportsDirectory:o});return r&&`data:${r.type};base64,${Buffer.from(r.body).toString("base64")}`}var tt=(t,e)=>e&&/<\/head>/i.test(t)&&!t.includes("data-doc-tab-icon")?t.replace(/<\/head>/i,()=>` <link rel="icon" href="${$(e)}" data-doc-tab-icon>
3
- </head>`):t;export{U as a,mt as b,d as c,W as d,gt as e,ut as f,X as g,Y as h};
@@ -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{a as q,b as B}from"./chunk-IA4PSIMD.mjs";import{b as C}from"./chunk-ZTHICSSF.mjs";import x from"node:fs/promises";import W from"node:path";import{MENTION as L}from"../browser/shared/components/mention.mjs";import{writeAtomic as R}from"../browser/shared/files.mjs";import{reportLines as U}from"../browser/shared/search.mjs";import{countWords as Q}from"../browser/shared/words.mjs";import{FACT_KINDS as V,QUERY_KINDS as Y,SNAPSHOT_LIMITS as y,queryOptions as G}from"../browser/shared/workspace-query.mjs";import{documentDirectory as M,documentFiles as T,layoutOf as X,listDocumentSlugs as _,listTrash as Z}from"../browser/shared/workspace.mjs";var ut=d=>l=>d.readTaken(l,{wait:0}),z=({todos:d})=>{let l=new Map,g=c=>JSON.stringify([c.text,c.path]);for(let c of d)l.set(g(c),(l.get(g(c))??0)+1);return d.some(c=>!c.block&&l.get(g(c))>1)},tt=(d,l)=>({hash:B(d),words:Q(l),todos:q(l)});function et(d){let l=new Date(d);return l.setHours(0,0,0,0),l.setDate(l.getDate()-(l.getDay()+6)%7),l.getTime()}function mt({root:d,read:l,draw:g=u=>u,activity:c=null,now:I=()=>new Date}){let u=new Map,h=new Map,b=t=>x.stat(t).then(({mtimeMs:e})=>e,()=>null);async function J(t,e=null){let o=T(M(t,d)),[a,n]=await Promise.all([b(o.html),b(o.json)]);if(a===null)return null;let s=e??await l(t);if(!s)return null;let r={};try{r=JSON.parse(await x.readFile(o.json,"utf8"))??{}}catch{}let{title:i,icon:w}=r,f={slug:t,title:typeof i=="string"&&i.trim()?i:t,icon:typeof w=="string"&&w?w:null,edited:Math.round(a),...tt(s.source,s.text)};return u.set(t,{html:a,json:n,facts:f,held:s.held===!0}),h.has(t)||h.set(t,f),f}async function O(t){let e=u.get(t);if(e&&!e.held){let o=T(M(t,d)),[a,n]=await Promise.all([b(o.html),b(o.json)]);if(a===e.html&&n===e.json)return e.facts}return J(t)}async function S(){let t=await _(d);for(let e of u.keys())t.includes(e)||u.delete(e);for(let e of h.keys())t.includes(e)||h.delete(e);return(await Promise.all(t.map(e=>O(e).catch(()=>null)))).filter(Boolean)}let P={async todos({done:t,slugs:e,limit:o}){let a=(await S()).filter(s=>!e||e.includes(s.slug)).sort((s,r)=>r.edited-s.edited||s.slug.localeCompare(r.slug)),n=[];for(let{slug:s,title:r,todos:i,hash:w}of a)for(let f of i)if(!(t!==void 0&&f.done!==t)){if(n.length>=o)return n;n.push({ref:{slug:s,block:f.block,text:f.text,path:f.path,nth:f.nth,version:w},text:f.text,done:f.done,slug:s,title:r,path:f.path})}return n},async recent({limit:t}){return(await S()).sort((e,o)=>o.edited-e.edited||e.slug.localeCompare(o.slug)).slice(0,t).map(({slug:e,title:o,icon:a,edited:n})=>({slug:e,title:o,icon:a,edited:new Date(n).toISOString()}))},async stats(){let t=await S(),e=et(I()),o=t.flatMap(a=>a.todos);return{documents:t.length,todos:{done:o.filter(a=>a.done).length,total:o.length},words:t.reduce((a,n)=>a+n.words,0),editedThisWeek:t.filter(a=>a.edited>=e).length}},async activity({days:t}){return c?(await c.load(),await $,c.days(t)):[]},async table({slug:t,key:e,where:o,limit:a},{words:n=!1}={}){let s=await O(t).catch(()=>null),r=u.get(t);if(!s||!r)return k(404,"missing",`no document "${t}"`);if(r.tables??=new Map,!r.tables.has(e)){let m=await l(t);if(!m)return k(404,"missing",`no document "${t}"`);r.tables.set(e,C(m.text,e,t))}let i=r.tables.get(e);if(i.error==="missing")return k(404,"missing",`"${t}" holds no table whose frame carries data-doc-chart-source="${e}"`);if(i.error)return k(422,"missing",`the table "${e}" of "${t}" has merged cells, which no view reads: write each value in its own cell`);let w=Object.keys(o).filter(m=>!i.columns.includes(m));if(w.length>0)return k(400,"options",`table: the table "${e}" of "${t}" has no column ${w.map(m=>JSON.stringify(m)).join(", ")} (its columns: ${i.columns.map(m=>JSON.stringify(m)).join(", ")})`);let f=i.rows.filter(m=>Object.entries(o).every(([D,v])=>m.words[D]===v.replace(/\s+/g," ").trim()));return{columns:[...i.columns],rows:f.slice(0,a).map(({values:m,links:D,words:v})=>({values:{...m},links:D.map(K=>({...K})),...n?{words:{...v}}:{}})),total:f.length}}},k=(t,e,o)=>{throw Object.assign(new Error(o),{refusal:[t,{ok:!1,reason:e,message:o}]})},p=new Map,j=t=>W.join(X(d).gallery,"cache","workspace",`${t}.json`),A=async t=>{if(!p.has(t)){let e=[];try{let o=JSON.parse(await x.readFile(j(t),"utf8"));Array.isArray(o?.tables)&&(e=o.tables.filter(a=>typeof a=="string").slice(-y.tables))}catch{}p.has(t)||p.set(t,e)}return p.get(t)},N=Promise.resolve(),H=async(t,e)=>{let o=await A(t);if(o.at(-1)===e)return;let a=[...o.filter(n=>n!==e),e].slice(-y.tables);p.set(t,a),N=N.then(async()=>{await x.mkdir(W.dirname(j(t)),{recursive:!0}),await R(j(t),`${JSON.stringify({tables:p.get(t)})}
3
- `)}).catch(()=>{})},F=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,$=Promise.resolve(),E={facts:O,all:S,async lines(t,e){let o=u.get(t);if(!await O(t))return null;let n=u.get(t);if(n!==o||!n.lines||n.lines.titles!==null&&n.lines.titles!==e){let s=await l(t);if(!s)return null;n.lines={titles:s.text.includes(L)?e:null,value:U(g(s.text,t))}}return n.lines.value},async query(t,e,{doc:o=null}={}){if(!Y.includes(t))return[400,{ok:!1,reason:"kind",message:`no kind "${t}": todos, recent, stats, activity or table`}];let{problem:a,options:n}=G(t,e);if(a)return[400,{ok:!1,reason:"options",message:`${t}: ${a}`}];let s;try{s=await P[t](n)}catch(r){if(r.refusal)return r.refusal;throw r}return t==="table"&&typeof o=="string"&&F.test(o)&&await H(o,`${n.slug}#${n.key}`),[200,{ok:!0,kind:t,data:s,at:new Date(I()).toISOString()}]},async snapshot(t){let e=async(n,s)=>{let[r,i]=await E.query(n,s);return r===200?i.data:null},o={todos:await e("todos",{limit:y.todos}),recent:await e("recent",{limit:y.recent}),stats:await e("stats"),activity:await e("activity",{days:y.activity})},a={};for(let n of F.test(t)?await A(t):[]){let[s,r]=n.split("#"),i=await P.table({slug:s,key:r,where:{},limit:y.rows},{words:!0}).catch(()=>null);i&&(a[n]=i)}return Object.keys(a).length>0&&(o.tables=a),Object.fromEntries(Object.entries(o).filter(([,n])=>n!==null))},stored:()=>N,async changed(t,{source:e=null,text:o=null,by:a="agent"}={}){let n=h.get(t)??u.get(t)?.facts??null;u.delete(t);let s=e===null?null:await J(t,{source:e,text:o??e}).catch(()=>null);s?h.set(t,s):h.delete(t);let r=new Set;if(!!n!=!!s)for(let i of["todos","recent","stats","table"])r.add(i);return n&&s&&n.hash!==s.hash&&r.add("table"),n&&s&&n.hash!==s.hash&&(z(n)||z(s))&&r.add("todos"),n&&s&&((n.title!==s.title||JSON.stringify(n.todos)!==JSON.stringify(s.todos))&&r.add("todos"),(n.title!==s.title||n.icon!==s.icon||n.edited!==s.edited)&&r.add("recent"),(n.words!==s.words||n.todos.length!==s.todos.length||n.todos.filter(i=>i.done).length!==s.todos.filter(i=>i.done).length||n.edited!==s.edited)&&r.add("stats")),!n&&s&&r.add("recent"),c&&s&&(await c.load(),await $,c.record(t,{hash:s.hash,words:s.words,mtime:s.edited,by:a})&&r.add("activity")),V.filter(i=>r.has(i))},start(){return c?($=(async()=>{await c.load();let t=await _(d),e=(await Promise.all(t.map(async a=>({slug:a,mtime:await b(T(M(a,d)).html)})))).filter(({mtime:a})=>a!==null),o=(await Z(d).catch(()=>[])).map(a=>a.slug);return c.catchUp(e.map(({slug:a,mtime:n})=>({slug:a,mtime:Math.round(n)})),O,{kept:o})})().catch(()=>0),$):Promise.resolve(0)},forget(t){u.delete(t),h.delete(t)}};return E}export{ut as a,mt as b};
@@ -1,16 +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 Pe}from"./chunk-UMHUSOPJ.mjs";import{d as We,e as Jt,g as Vt,j as Ue,k as ze,l as qe,m as Xt}from"./chunk-FJYN7RTH.mjs";import{B as He,c as lt,d as Ge,q as xt,r as Ke,y as qt,z as ft}from"./chunk-UBBRTJ2R.mjs";import{b as rt,e as co}from"./chunk-A55HN5OK.mjs";co();import ro from"node:path";import{attr as w,curlyQuoted as lo}from"../browser/shared/html-tree.mjs";import{FOLDED_LINES as Je,LINE_START as Ve,NOWRAP as Zt,lineStart as fo,validFolded as uo}from"../browser/shared/code-lines.mjs";import{COLORS as ho}from"../browser/shared/colors.mjs";import{FLOWS as mo,instanceSlots as at,isInstance as it,isSlot as ls,matchesNode as pt}from"../browser/shared/components/index.mjs";import{HEADED as dt}from"../browser/shared/components/dialog.mjs";import{pageLanguage as go}from"../browser/shared/components/page.mjs";import{SHEETS_LABEL as Xe,shortSheets as po}from"../browser/shared/components/sheets.mjs";import{iconMarkup as Ze,iconValueOf as fs}from"../browser/shared/emoji/icon-value.mjs";import{escapeText as ht}from"../browser/shared/escape.mjs";import{COLUMN_GAP as No,READING_WIDTH as Tt,SPAN as Qe,SPAN_SIZE as ut}from"../browser/shared/media.mjs";import{kitNamespace as ds}from"../browser/shared/old-names.mjs";import{CHART_DATA as Oo,CHART_SOURCE as tt,TABLE_READERS as $o,nextChartKey as wo}from"../browser/shared/table-chart.mjs";import{BLOCK_COLORS as ae}from"../browser/editor/components/colors.mjs";import{DETAILS as bo,DIALOG as Yt,PAGE as us,SECTION as ko,SHEETS as Lo}from"../browser/editor/components/kit.mjs";import{DIALOG_TRIGGER as yo}from"../browser/editor/components/dialog/index.mjs";import{CHECKED as ie,FLOW as mt,TODO as te}from"../browser/editor/components/list/index.mjs";import{texSource as vo}from"../browser/editor/components/math/index.mjs";import{BOX_CLASSES as hs,HOLDS_ONE as Co,UNIT_KINDS as So}from"../browser/editor/components/registry.mjs";import{HEADER_LOOK as Ye}from"../browser/editor/components/table/index.mjs";import{backgroundColor as xo,parseColor as To,textColor as Eo}from"../browser/editor/page/clipboard/import/colors.mjs";var ce=new Set(["script","style","template","textarea","noscript","code","svg","math","select","option","button","iframe","video","audio","canvas","object","picture"]),_t=["doc-figure","doc-code","doc-diff","doc-math-inline","doc-math-block","doc-link-mention","doc-sheet-tabs","doc-state-fields","doc-filter-row","doc-image","doc-file","doc-bookmark","doc-embed","doc-icon","doc-title","doc-table-meta"],re=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th","dt","dd","blockquote","figcaption","caption","summary"]),Et=new Set(["main","section","div","article","aside","blockquote","li","details","dialog"]),Io=new Set(ho.map(({name:e})=>e)),C=e=>(w(e,"class")??"").split(/\s+/).filter(Boolean),ts=e=>C(e).every(o=>ae.includes(o)),Ao=ae.filter(e=>e.startsWith("doc-highlight-")),ct=e=>C(e).some(o=>!ds(o)),D=e=>e.nodeName==="#text",jt=/^[\s\u200b-\u200d\u2060\ufeff]*$/,V=e=>D(e)&&jt.test(e.value),L=e=>(e.childNodes??[]).filter(o=>o.tagName),Z=e=>(e.attrs??[]).map(o=>o.name),G=(e,o)=>Z(e).every(f=>o.includes(f)),_o=[ko.match,bo.match,Yt.match,Lo.match,"table.doc-table"].join(", ");function ms(e){let o=C(e);return o.some(f=>_t.includes(f))||Ge(e)||pt(e,_o)||hs.some(([f])=>o.includes(f))||So.some(f=>f.class&&o.includes(f.class)&&(!f.tag||[f.tag].flat().includes(e.tagName)))}var jo=e=>{for(let o=e.parentNode;o?.tagName&&o.tagName!=="main";o=o.parentNode)if(o.tagName==="figure")return!0;return!1},gs=new Set(["thead","tbody","tfoot","tr","colgroup","col"]),le=e=>ct(e)&&e.tagName!=="figure"&&!re.has(e.tagName)&&!gs.has(e.tagName)&&!ms(e),ps=new Set([...lt].filter(e=>!["header","main","dialog","form","fieldset","caption","dd","dt","figcaption","summary","li","td","th",...gs].includes(e))),Bo=/\\\(([\s\S]*?)\\\)/g,wt=e=>vo(e)&&/\S/.test(e);function Mo(e,o=!0){let f=o?e:/^\s*(?:\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$)/.exec(e)?.[0]??"";return/[<>]/.test(f)&&wt(f.replace(/</g,"\\lt ").replace(/>/g,"\\gt "))}var ee=new Set(["br","wbr","img","input"]),Ns=new Set([...lt,"script","style","template","noscript","link","meta"]),Os=new Set(["input","select","textarea","button","label","option"]),Ro=new Set([...lt,"hgroup","search","center","dir","listing","xmp","plaintext"]),se=e=>L(e).some(o=>Ro.has(o.tagName)||se(o)),$s=new Set(["main","section","div","article","aside","blockquote"]),Do=mo.join(", "),ws=e=>$s.has(e.tagName)&&!ct(e)&&(C(e).length===0||pt(e,Do))||ls(e),et=e=>D(e)?!jt.test(e.value):(e.childNodes??[]).some(et),Fo=hs.filter(([,e])=>Co.has(e)).map(([e])=>e),Go=e=>ws(e)&&C(e).some(o=>Fo.includes(o)),bs=e=>e.childNodes.some(o=>D(o)&&!jt.test(o.value))&&L(e).some(o=>lt.has(o.tagName)),Ko=/^[ \t\n\r\f]*/;function Qt(e){let o=[],f=[];for(let u of e)u.tagName&&Ns.has(u.tagName)?(o.push(f),f=[]):f.push(u);o.push(f);let p=u=>!u.tagName&&!et(u),O=u=>(D(u)||u.tagName&&!Os.has(u.tagName))&&et(u);return o.map(u=>{let $=u.findIndex(h=>!p(h));return $<0?[]:u.slice($,u.findLastIndex(h=>!p(h))+1)}).filter(u=>u.some(O))}function Ho(e){let o=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="style"?o.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),o.flatMap(p=>[...p.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").matchAll(/([^{};]*)\{/g)].map(([,O])=>O))}var Po=(e,{tags:o=[],classes:f=[]})=>{let p=[...o.map(u=>`(?<![\\w.#-])${u}`),...f.map(u=>`\\.${u}`)],O=p.length?new RegExp(`(?:${p.join("|")})(?![\\w-])`,"i"):null;return!!O&&e.some(u=>O.test(u))};function Wo(e){let o=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="script"?o.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),o.join(`
3
- `)}var fe=["contains-task-list","task-list-item"],de=["task-list-item"],ks=["task-list-item-checkbox"],ue=(e,o)=>C(e).every(f=>o.includes(f));function Ls(e){let o=e.childNodes.find(f=>!V(f));return o?.tagName==="input"&&G(o,["type","checked","disabled","class"])&&w(o,"type")?.toLowerCase()==="checkbox"&&ue(o,ks)&&o.sourceCodeLocation?.startTag?o:null}var ys=e=>e.tagName==="li"&&ue(e,de)&&w(e,ie)===void 0&&e.sourceCodeLocation?.startTag&&Ls(e),Uo=e=>e.tagName==="ul"&&ue(e,fe)&&L(e).length>0&&e.childNodes.every(o=>o.tagName==="li"||V(o))&&L(e).every(ys),zo={classes:[...new Set([...fe,...de,...ks])]},qo=/checkbox|task-list/i,oe=e=>e.tagName==="ol"&&(w(e,"data-doc-chart")==="flow"||w(e,"data-flow")!==void 0&&w(e,"data-doc-chart")===void 0),Jo=e=>e?.tagName==="ol"&&!ct(e)&&(C(e).includes(mt)||oe(e)),Vo=e=>e.tagName==="li"&&Jo(e.parentNode),At="doc-icon",Xo=e=>e.some(o=>o.tagName==="strong"||o.tagName==="b")&&e.every(o=>o.tagName==="strong"||o.tagName==="b"||D(o)&&jt.test(o.value)||o.nodeName==="#comment"),Zo=/^(?:inherit|unset|currentcolor|none)$/i,Qo=/^(?:inherit|initial|unset|revert|revert-layer|transparent|none)$/i,U=e=>e.replace(/\s+/g," ").trim(),es=/^\s*--doc-(?:table-height|span)\s*:/i;function ne(e){let o=e.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," "),f=[],p="",O=0,u=0;for(let $=0;$<=o.length;$++){let h=o[$];p?h==="\\"?$++:h===p&&(p=""):h==='"'||h==="'"?p=h:h==="("?O++:h===")"?O=Math.max(0,O-1):(h===";"&&O===0||$===o.length)&&(f.push(o.slice(u,$)),u=$+1)}return f.filter($=>$.trim())}function vs(e){let o=new Map;for(let r of ne(e)){let N=r.indexOf(":"),i=U(N<0?r:r.slice(0,N)).toLowerCase();o.set(i==="background-color"?"background":i,N<0?"":U(r.slice(N+1).replace(/!\s*important\s*$/i,"")))}let f=[],p=[],O,u,$=new Set,h=(r,N,i)=>{if((r==="color"?Zo:Qo).test(N))return;let d=To(N);if(!d||d.a===0&&r==="color"){f.push(r);return}if(d.a===0)return;let g=i(N,{nearest:!0})?.replace(/_background$/,"");if(!g||!Io.has(g)){p.push(`${r} ${N} left out: the ${r==="color"?"text's":"page's"} own is the nearest`);return}return i(N)?.replace(/_background$/,"")!==g&&p.push(`${r} ${N} written as the kit's ${g}${r==="color"?"":" highlight"}`),g};for(let[r,N]of o)r==="color"?O=h(r,N,Eo):r==="background"?u=h(r,N,xo):r==="font-weight"&&/^(?:bold|bolder|[6-9]\d\d)$/i.test(N)?$.add("strong"):r==="font-style"&&/^(?:italic|oblique)\b/i.test(N)?$.add("em"):(r==="text-decoration"||r==="text-decoration-line")&&/^(?:(?:underline|line-through|solid)\s*)+$/i.test(N)&&/underline|line-through/i.test(N)?(/underline/i.test(N)&&$.add("u"),/line-through/i.test(N)&&$.add("s")):f.push(r);if(f.length)return{foreign:[...new Set(f)]};let v=[];O&&v.push([`<span class="doc-text-${O}">`,"</span>"]),u&&v.push([`<span class="doc-highlight-${u}">`,"</span>"]);for(let r of["strong","em","u","s"])$.has(r)&&v.push([`<${r}>`,`</${r}>`]);return{open:v.map(([r])=>r).join(""),close:v.map(([,r])=>r).reverse().join(""),notes:p}}var ss=/^(?:language|lang)-([\w#+.-]+)$/,Yo=new Set(["data-language","data-lang","data-block-id"]),tn=[{name:Ve,names:[Ve,"data-start"],value:e=>fo(e)?.toString()??null,says:"the number of its first line is a whole number from 1"},{name:"data-line-numbers",names:["data-line-numbers"],value:e=>/^\s*(?:true|false)\s*$/i.test(e)?e.trim().toLowerCase():null,says:"false hides its line numbers, true shows them"},{name:Je,names:[Je],value:e=>uo(U(e))?U(e):null,says:"its folded lines are their numbers from 1, spaces between"}],os="data-title",ns="data-wrap",en=e=>L(e).length===1&&L(e)[0].tagName==="code"&&e.childNodes.every(o=>o.tagName||V(o))?L(e)[0]:null,sn=new Set(["a","abbr","b","bdi","bdo","cite","code","data","del","dfn","em","font","i","ins","kbd","mark","q","s","samp","small","span","strike","strong","sub","sup","time","tt","u","var","br","wbr"]),on=new Set(["code","kbd","samp","tt","var"]);function Cs(e){for(let o of e.childNodes){if(D(o))continue;if(!o.tagName)return"a comment in its <figcaption>";if(["img","picture","svg"].includes(o.tagName))return"a picture in its <figcaption>";if(!sn.has(o.tagName))return`a <${o.tagName}> in its <figcaption>`;if(!o.sourceCodeLocation?.startTag||!(o.sourceCodeLocation.endTag||ee.has(o.tagName)))return`a <${o.tagName}> not closed in its <figcaption>`;let f=Cs(o);if(f)return f}return""}function as(e){let o=L(e),f=o.filter(v=>v.tagName==="pre"),p=o.filter(v=>v.tagName==="figcaption");if(!f.length)return null;let[O]=f,[u=null]=p,$=e.childNodes.find(v=>!v.tagName&&!V(v)),h=f.length>1||p.length>1||o.length>f.length+p.length?"more than the pre and one <figcaption> in its <figure>":$?D($)?"words in its <figure> outside its caption":"a comment in its <figure>":u?Z(u).length?`its <figcaption> has an attribute of its own (${Z(u).join(", ")})`:u.sourceCodeLocation?.endTag?Cs(u):"its <figcaption> is not closed in the file":"";return h?{pre:O,caption:u,why:h}:{pre:O,caption:u}}function It(e){let o=(e.attrs??[]).filter(({value:p})=>p.trim()),f=e.tagName==="abbr";return o.map(p=>`${p.name} ${JSON.stringify(U(p.value))} dropped: ${f&&p.name==="title"?"write the full name in the text":"write it in the text if the reader needs it"}`)}var z=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;");function nn(e){let o=new Set,f=p=>{for(let O of p.childNodes??[])if(O.tagName){for(let u of[tt,...$o])w(O,u)!==void 0&&o.add(w(O,u));f(O.tagName==="template"?O.content:O)}};return f(e),o}function an(e){let o=new Map,f=p=>{for(let O of p.childNodes??[]){if(!O.tagName)continue;let u=w(O,"id");u!==void 0&&o.set(u,(o.get(u)??0)+1),f(O.tagName==="template"?O.content:O)}};return f(e),o}var cn=/^[A-Za-z][\w-]{0,63}$/;function rn(e){let o=Pe(e),f=rt(o,{sourceCodeLocationInfo:!0}),p=bt(f);if(!p)return{text:o,changes:[]};let O=[],u=[],$=t=>o.slice(0,t).split(`
4
- `).length,h=(t,s,n=[],l={})=>{let a=$(t.sourceCodeLocation.startOffset);n.length||u.push({line:a,rule:s,...l});for(let c of n)u.push({line:a,rule:s,note:c,...l})},v=0,r=(t,s,n,{opens:l=null,closes:a=null,move:c=null,leaves:m=!1}={})=>O.push({start:t,end:s,text:n,order:v++,opens:l,closes:a,move:c,leaves:m}),N=(t,s,n,l)=>{r(t,t,n,{opens:s}),r(s,s,l,{closes:t})},i=t=>t.sourceCodeLocation?.startTag,d=t=>t.sourceCodeLocation?.endTag,g=(t,s,{drop:n=[]}={})=>{let l=C(t).filter(m=>!n.includes(m)),a=[...l,...s.filter(m=>!l.includes(m))],c=t.sourceCodeLocation.attrs?.class;if(a.join(" ")!==C(t).join(" "))if(c&&a.length)r(c.startOffset,c.endOffset,`class="${z(a.join(" "))}"`);else if(c)S(t,"class");else{let m=i(t).startOffset+1+t.tagName.length;r(m,m,` class="${z(a.join(" "))}"`)}},S=(t,s)=>{let n=t.sourceCodeLocation.attrs[s],l=n.startOffset;for(;/[ \t\n\r\f]/.test(o[l-1]??"");)l--;r(l,n.endOffset,"")},T=(t,s,{classes:n=[],drop:l=[]}={})=>{let a=t.sourceCodeLocation,c=Object.entries(a.attrs??{}).filter(([y])=>y!=="class"&&!l.includes(y)).map(([,y])=>` ${o.slice(y.startOffset,y.endOffset)}`).join(""),m=[...n,...C(t).filter(y=>!n.includes(y))];return`<${s}${m.length?` class="${z(m.join(" "))}"`:""}${c}>`},M,q=t=>Po(M??=Ho(f),t),Q,Bs=t=>t.test(Q??=Wo(f)),K=(t,s,n)=>{r(i(t).startOffset,i(t).endOffset,s),d(t)&&r(d(t).startOffset,d(t).endOffset,n)},Mt=t=>K(t,"",""),P=t=>!!(i(t)&&(d(t)||t.tagName==="img")),me,ge=t=>{let s=w(t,"id");if(t.tagName!=="dialog"||!G(t,["id"])||!cn.test(s??"")||!P(t))return!1;let n=L(t);return!(n.length?ps.has(n[0].tagName)&&P(n[0]):t.childNodes.some(a=>!V(a)&&a.nodeName!=="#comment"))||n.some(a=>a.tagName==="form")?!1:(me??=an(f),me.get(s)===1)},Ms=t=>{let s=L(t)[0];return!pt(s,Yt.short)||Z(s).length?null:t.childNodes.slice(0,t.childNodes.indexOf(s)).every(V)?s:null},pe=t=>t.tagName==="dialog"&&(C(t).includes("doc-dialog")||ge(t)),Rt=(t,s=[])=>{for(let n of t.childNodes??[])if(n!==p){if(it(n)){at(n).forEach(l=>Rt(l,s));continue}pe(n)&&P(n)?s.push(n):Rt(n,s)}return s},Dt=d(p)?Rt(f):[],Ne,Rs=t=>(Ne??=new Set((function s(n,l=[]){for(let a of n.childNodes??[])if(a.tagName){if(it(a)){at(a).forEach(c=>s(c,l));continue}pe(a)&&l.push(w(a,"id")),s(a,l)}return l})({childNodes:[p,...Dt]})),/^#./.test(t??"")&&Ne.has(t.slice(1))),Ds=t=>{let[s,...n]=L(t);if(!s||n.length||!C(s).includes("doc-dialog-panel"))return null;let[l,a,...c]=L(s);if(c.length||!l||!a||!C(l).includes(dt.header)||!C(a).includes("doc-dialog-content"))return null;let m=x=>x.childNodes.some(_=>!_.tagName&&!V(_)&&_.nodeName!=="#comment");if(m(s)||m(l)||!P(l)||!i(a))return null;let y=L(l),k=y.filter(x=>C(x).includes(dt.title)),I=y.filter(x=>!k.includes(x)),A=x=>(C(x).includes(dt.close)||w(x,dt.closeAttribute)!==void 0)&&P(x);return k.length!==1||!P(k[0])||I.length>1||!I.every(A)?null:{header:l,title:k[0],close:I[0]??null,content:a}},Nt,Oe=(t,s=[])=>{for(let n of t.childNodes??[])if(n.tagName){for(let{name:l,value:a}of n.attrs)l!=="id"&&l!=="class"&&s.push(a);(n.tagName==="script"||n.tagName==="style")&&s.push(n.childNodes.map(l=>l.value??"").join("")),Oe(n,s)}return s},Fs=(t,s)=>{Nt??=Oe(f).join(`
5
- `);let n=0;for(let l=Nt.indexOf(t);l>=0;l=Nt.indexOf(t,l+t.length))!/[\w-]/.test(Nt[l-1]??"")&&!/[\w-]/.test(Nt[l+t.length]??"")&&n++;return n>(s?1:0)};function Gs(t){let s=Ds(t);if(!s)return;let{header:n,title:l,close:a,content:c}=s,m=w(l,"id"),y=!!m&&w(t,"aria-labelledby")?.trim()===m;y&&S(t,"aria-labelledby"),r(i(n).startOffset,i(n).endOffset,o.slice(i(c).startOffset,i(c).endOffset));let k=i(l).startOffset+1;r(k,k+l.tagName.length,"h3"),g(l,[],{drop:[dt.title]}),m!==void 0&&!(m&&Fs(m,y))&&S(l,"id"),r(d(l).startOffset,d(l).endOffset,"</h3>"),a&&r(a.sourceCodeLocation.startOffset,a.sourceCodeLocation.endOffset,""),r(d(n).startOffset,d(n).endOffset,""),r(i(c).startOffset,i(c).endOffset,"")}let Ft=t=>{for(let s of t.childNodes??[]){if(it(s)){at(s).forEach(Ft);continue}s.tagName&&pt(s,Yt.match)&&Gs(s),Ft(s)}},$e=new Set;function we(t){let s=t.tagName;if(!P(t))return!1;let n=[];if(s==="mark"&&G(t,[]))K(t,'<span class="doc-highlight-yellow">',"</span>");else if((s==="del"||s==="strike")&&G(t,["cite","datetime"]))K(t,"<s>","</s>"),n=It(t);else if(s==="ins"&&G(t,["cite","datetime"]))K(t,"<u>","</u>"),n=It(t);else{if(["kbd","samp","tt","var"].includes(s)&&G(t,[]))return K(t,"<code>","</code>"),$e.add(t),h(t,s),!0;if(s==="a"&&G(t,["href"])&&Rs(w(t,"href")))return g(t,[yo]),h(t,"dialog link"),!1;if(s==="small"&&G(t,[]))K(t,'<span class="doc-text-gray">',"</span>");else if(s==="q"&&G(t,["cite"]))K(t,"\u201C","\u201D"),n=It(t);else if(["abbr","cite","dfn","time","bdi","data"].includes(s)&&G(t,["title","datetime","value"]))Mt(t),n=It(t);else if(s==="span"&&G(t,[])||s==="font"&&G(t,["color"])&&!w(t,"color")?.trim())Mt(t);else if(s==="span"&&G(t,["style"])||s==="font"&&G(t,["color"])){let l=vs(s==="span"?w(t,"style")??"":`color: ${w(t,"color")}`);if(l.foreign)return!1;K(t,l.open,l.close),n=l.notes}else return!1}return $e.add(t),h(t,s,n),!1}function Ks(t){let{startOffset:s,endOffset:n}=t.sourceCodeLocation,l=o.slice(s,n);for(let a of l.matchAll(Bo))N(s+a.index,s+a.index+a[0].length,'<span class="doc-math-inline">',"</span>"),u.push({line:$(s+a.index),rule:"formula"})}let Gt=new Set,be=new Set;function kt(t,s=()=>!1){for(let n of Qt(t)){if(!n.every(k=>k.tagName?i(k)&&(d(k)||ee.has(k.tagName))&&!se(k):k.sourceCodeLocation))continue;let l=n[0].sourceCodeLocation.startOffset,a=n.at(-1).sourceCodeLocation.endOffset,c=o.slice(l,a),m=l+Ko.exec(c)[0].length,y=a-/[ \t\n\r\f]*$/.exec(c)[0].length;if(n.every(D)&&wt(o.slice(m,y)))N(m,y,'<div class="doc-math-block">',"</div>"),u.push({line:$(m),rule:"display formula"}),n.forEach(k=>be.add(k));else if(s(n)){let k=Xo(n);N(m,y,k?"<p>":"<p><strong>",k?"</p>":"</strong></p>"),u.push({line:$(m),rule:"step title",...Le(n[0].parentNode)}),n.forEach(I=>Gt.add(I))}else N(m,y,"<p>","</p>"),u.push({line:$(m),rule:"loose words"}),n.forEach(k=>Gt.add(k))}}let Hs=t=>t[0].parentNode.childNodes.slice(0,t[0].parentNode.childNodes.indexOf(t[0])).every(s=>!s.tagName||C(s).includes(At)),ke=new Set,Le=t=>ke.has(t.parentNode)?{}:(ke.add(t.parentNode),{note:"a step's own words written as its title, the first block of its node: <li><p><strong>\u2026</strong></p> then its content (a paragraph, a list\u2026)</li>"}),Ps=t=>{if(kt(t.childNodes,Hs),t.childNodes.filter(a=>a.tagName&&!C(a).includes(At)).length>0||Qt(t.childNodes).length>0||!i(t)||!d(t))return;let l=t.childNodes.filter(a=>a.tagName).at(-1)?.sourceCodeLocation?.endOffset??i(t).endOffset;r(l,l,"<p></p>"),u.push({line:$(l),rule:"step title",...Le(t)})},Kt,ye=()=>{Kt??=nn(f);let t=wo(Kt);return Kt.add(t),t},Ws=(t,s)=>`<div data-doc-chart="${z(w(t,"data-doc-chart"))}" ${Oo}="${z(s)}"></div>`,Ot=o.includes(`\r
6
- `)?`\r
7
- `:`
8
- `,ve=t=>/^[ \t]*/.exec(o.slice(o.lastIndexOf(`
9
- `,t-1)+1))[0];function Ce(t,s,n,l=null){let a=Se(t),c=a?ft(o,a.sourceCodeLocation.startOffset,a.sourceCodeLocation.endOffset):null,m=!!c&&(c.start!==a.sourceCodeLocation.startOffset||c.end!==a.sourceCodeLocation.endOffset),y=a?{from:i(a).endOffset,to:d(a).startOffset}:null,k=_=>`<figure class="doc-figure">${_?`<h3>${_}</h3>`:""}${Ws(t,n)}</figure>`,I=_=>y?_:_(""),A=m?`${Ot}${ve(i(s).startOffset)}`:"",x=!!(l??d(s));if(x){let _=l?d(t).endOffset:d(s).endOffset;r(_,_,I(F=>`${l??""}${A}${k(F)}`),{closes:i(s).startOffset,move:y}),u.push({line:$(_),rule:"chart",key:n})}else r(i(s).startOffset,i(s).startOffset,I(_=>`${k(_)}${A}`),{opens:i(s).endOffset,move:y}),u.push({line:$(i(s).startOffset),rule:"chart",key:n});return c&&r(c.start,c.end,""),x&&!!l}let[Us]=Ye,Se=t=>{let s=t.childNodes.find(n=>!V(n));return s?.tagName!=="caption"||!P(s)||Z(s).length>0||!et(s)||!s.childNodes.every(n=>D(n)||n.tagName&&!Ns.has(n.tagName)&&!Os.has(n.tagName)&&!se(n))||s.childNodes.every(D)&&wt(o.slice(i(s).endOffset,d(s).startOffset))||q({tags:["caption"]})?null:s},zs=t=>{let s=w(t,"rowspan");return s===void 0||/^\s*\d+\s*$/.test(s)&&Number(s)===1},qs=t=>(w(t,"scope")??"").trim().toLowerCase()==="row";function Js(t){let s=L(t).filter(m=>["thead","tbody","tfoot"].includes(m.tagName)),n=s.flatMap(m=>L(m)).flatMap(m=>L(m)).filter(m=>m.tagName==="th"&&i(m)),l=!q({tags:["th","thead"]});if(l)for(let m of n)qs(m)||g(m,ae.some(y=>C(m).includes(y))?[Us]:Ye);let a=l||!n.length?[]:["its th as written (no header look, no thead): the document's own <style> styles th"],c=m=>m.length>0&&m.every(y=>y.tagName==="tr"&&P(y));for(let m of s){let y=L(m);if(m.tagName!=="tbody"||!c(y))continue;let[k,...I]=y,A=l&&s.length===1&&I.length>0&&L(k).length>0&&L(k).every(F=>F.tagName==="th"&&zs(F)),x=i(m);if(x){if(!A||!d(m))continue;r(x.startOffset,x.endOffset,"<thead>"),r(k.sourceCodeLocation.endOffset,k.sourceCodeLocation.endOffset,`</thead>${o.slice(x.startOffset,x.endOffset)}`),h(k,"header row");continue}A&&(N(k.sourceCodeLocation.startOffset,k.sourceCodeLocation.endOffset,"<thead>","</thead>"),h(k,"header row"));let _=A?I:y;N(_[0].sourceCodeLocation.startOffset,_.at(-1).sourceCodeLocation.endOffset,"<tbody>","</tbody>")}return a}let Ht,Vs=()=>{Ht??=(function s(n,l=new Set){for(let a of n.childNodes??[])a.tagName&&(w(a,"data-doc-sheets")!==void 0&&l.add(w(a,"data-doc-sheets")),s(a.tagName==="template"?a.content:a,l));return l})(f);let t=1;for(;Ht.has(`tabs-${t}`);)t++;return Ht.add(`tabs-${t}`),`tabs-${t}`},xe=new Set,Xs=t=>{let s=[],n=a=>a.childNodes.map(c=>D(c)?c.sourceCodeLocation?o.slice(c.sourceCodeLocation.startOffset,c.sourceCodeLocation.endOffset):c.value:c.tagName?(i(c)&&s.push(U(o.slice(i(c).startOffset,i(c).endOffset))),c.tagName==="br"?" ":n(c)):"").join(""),l=a=>a.childNodes.map(c=>D(c)?c.value:c.tagName==="br"?" ":c.tagName?l(c):"").join("");return{raw:U(n(t)),plain:U(l(t)),left:[...new Set(s)]}},Zs=(t,s,n)=>{let l=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+/,"").slice(0,48).replace(/-+$/,"")||`tab-${s+1}`,a=l;for(let c=2;n.has(a);c++)a=`${l}-${c}`;return n.add(a),a};function Qs(t,s){let n=go(o),l=Xe[n]??Xe.zh,a=w(t,"data-doc-sheets")?.trim()?null:Vs(),c=new Set,m=[],y=s.map(({section:I,heading:A},x)=>{let{raw:_,plain:F,left:Y}=Xs(A),st=Zs(F,x,c);Z(A).length&&m.push(`${Z(A).join(", ")} of the heading "${F}" left out: a tab is its name alone`);for(let ot of Y)m.push(`${ot} in the heading "${F}" left out: a tab's name is plain text`);K(I,`<div data-doc-sheet="${st}">`,"</div>"),xe.add(A);let{startOffset:J,endOffset:X}=A.sourceCodeLocation,W=ft(o,J,X);return r(W.start,W.end,Ot.repeat(o.slice(W.start,W.end).split(`
10
- `).length-1)),He({sheet:st,title:_})}),k=T(t,t.tagName,{classes:["doc-sheet-shell"],drop:a?["data-doc-sheets"]:[]});a&&(k=k.replace(/>$/,` data-doc-sheets="${a}">`)),w(t,"aria-label")===void 0&&(k=k.replace(/>$/,` aria-label="${l}">`)),r(i(t).startOffset,i(t).endOffset,`${k}<div class="doc-sheet-tabs" aria-label="${l}">${y.join("")}</div>`),h(t,"sheets",m)}let Ys=t=>{let s=L(t)[0];return L(t).length===1&&s.tagName==="a"&&C(s).join(" ")==="doc-bookmark"&&G(s,["class","href","title","target","rel"])&&!!w(s,"href")?.trim()&&P(s)&&s.childNodes.every(D)&&t.childNodes.every(n=>n===s||V(n))};function to(t){let s=L(t)[0],n=w(s,"href").trim(),l=U(w(s,"title")??""),a=n;try{a=new URL(n).hostname||n}catch{}let c=[],m=w(s,"target");m!==void 0&&m.trim()!=="_blank"&&c.push(`target ${JSON.stringify(U(m))} left out: a bookmark opens its page in a new tab`);let y=w(s,"rel");y!==void 0&&y.split(/\s+/).some(A=>A&&!["noopener","noreferrer"].includes(A.toLowerCase()))&&c.push(`rel ${JSON.stringify(U(y))} left out: a bookmark's link is rel="noopener noreferrer"`),r(i(t).startOffset,i(t).endOffset,T(t,"figure",{classes:["doc-bookmark"]}));let k=et(s)?"":ht(a);r(i(s).startOffset,i(s).endOffset,`<a class="doc-bookmark-card" href="${z(n)}" target="_blank" rel="noopener noreferrer"><span class="doc-bookmark-text"><span class="doc-bookmark-title">${k}`);let I=l?`<span class="doc-bookmark-description">${ht(l)}</span>`:"";r(d(s).startOffset,d(s).endOffset,`</span>${I}<span class="doc-bookmark-url"><span class="doc-bookmark-href">${ht(n)}</span></span></span></a>`),r(d(t).startOffset,d(t).endOffset,"<figcaption></figcaption></figure>"),h(t,"bookmark",c)}let eo=t=>{let s=t?.parentNode;if(!t?.tagName||!C(t).includes("doc-column")||!s?.tagName||!C(s).includes("doc-columns"))return null;let n=c=>Number(/--doc-column-ratio\s*:\s*(\d*\.?\d+)/i.exec(w(c,"style")??"")?.[1]??1)||1,l=L(s).filter(c=>C(c).includes("doc-column")),a=l.reduce((c,m)=>c+n(m),0);return(Tt-No*(l.length-1))/Tt*(n(t)/a)},Pt=(t,s,n)=>{let l=w(t,"width"),a=/^\s*(\d+(?:\.\d+)?)\s*(px|%)?\s*$/i.exec(l??""),c=(s?w(s,"style")??"":"").trim().replace(/;\s*$/,""),m=t.sourceCodeLocation.attrs?.width;if(!a||!m||/--doc-span\s*:/i.test(c))return null;let y=a[2]==="%",k=y?eo(n):null,I=y?Number(a[1])/100*(k??1):Number(a[1])/Tt,A=Math.round(Math.min(ut.max,Math.max(ut.min,I))*1e3)/1e3,x=m.startOffset;for(;/[ \t\n\r\f]/.test(o[x-1]??"");)x--;r(x,m.endOffset,"");let _=I<ut.min||I>ut.max?`, within ${ut.min} to ${ut.max}`:"",F=y?k===null?"a share of the width it stands in":`a share of the width it stands in, its column ${Math.round(k*1e3)/1e3} of the reading width`:`${Number(a[1])}px of the ${Tt}px reading width`;return{attribute:` style="${z(`${c?`${c}; `:""}${Qe}: ${A}`)}"`,note:`width="${l}" written as ${Qe}: ${A} on its figure (${F}${_}; at most the width it stands in)`}},Wt=(t,s)=>{let n=t?T(t,"figure",{classes:["doc-image"],drop:s?.attribute?["style"]:[]}):'<figure class="doc-image">';return s?.attribute?`${n.slice(0,-1)}${s.attribute}>`:n},so=t=>L(t).filter(s=>s.tagName==="img").length===1&&L(t).every(s=>s.tagName==="img"||s.tagName==="figcaption")&&t.childNodes.every(s=>s.tagName||V(s)),oo=t=>L(t).length===1&&L(t)[0].tagName==="img"&&t.childNodes.every(s=>s.tagName||V(s)),no=t=>t.childNodes.length>0&&t.childNodes.every(D)&&wt(o.slice(i(t).endOffset,d(t).startOffset)),Ut=new Set,Te=()=>q(zo)||Bs(qo),Ee=t=>Uo(t)&&!Te();function Ie(t,s=null,n=null,l=[]){let a=en(t),c=[t,a].filter(Boolean),m=[s,...c].filter(Boolean),y=c.flatMap(C).map(b=>ss.exec(b)?.[1]).find(Boolean)??m.map(b=>w(b,"data-language")??w(b,"data-lang")).find(Boolean),k=b=>m.find(E=>E.sourceCodeLocation.attrs?.[b]),I=(b,E)=>{let B=b?.sourceCodeLocation.attrs[E];return B?` ${o.slice(B.startOffset,B.endOffset)}`:""},A=k("id"),x=[...l],_=new Map(m.map(b=>[b,new Set])),F=b=>b.flatMap(E=>m.filter(B=>w(B,E)!==void 0).map(B=>(_.get(B).add(E),{element:B,name:E,value:w(B,E)}))),Y=(b,E)=>x.push(`${b.name} ${JSON.stringify(U(b.value))} left out (its <${b.element.tagName}>'s): ${E}`),st=tn.flatMap(({name:b,names:E,value:B,says:H})=>{let nt=F(E),R=nt.find(j=>B(j.value)!==null);for(let j of nt)j!==R&&Y(j,B(j.value)===null?H:`the block takes its <${R.element.tagName}>'s ${R.name}`);return R?[` ${b}="${z(B(R.value))}"`]:[]}),J=F([ns]),X=J.find(b=>/^\s*(?:true|false)\s*$/i.test(b.value));for(let b of J)b!==X&&Y(b,X?`the block takes its <${X.element.tagName}>'s ${ns}`:"false keeps its long lines on one line (they scroll), true wraps them");let W=X?X.value.trim().toLowerCase()==="false":c.some(b=>C(b).includes(Zt)),ot=c.flatMap(C).find(b=>Ao.includes(b)),je=F([os]),yt=n?null:je[0],Be=yt?ht(U(yt.value)):"";for(let b of je)b!==yt&&Y(b,n?"its caption is its title":`the block takes its <${yt.element.tagName}>'s ${os}`);let Me=b=>Object.keys(b.sourceCodeLocation.attrs??{}).filter(E=>E!=="class"&&!Yo.has(E)&&!(E==="id"&&b===A)&&!_.get(b).has(E)),Re=b=>{let E=C(b).filter(j=>!ss.test(j)&&j!==Zt&&j!==ot),B=Me(b),nt=(b.attrs.find(j=>j.name==="style")?.value??"").split(";").map(j=>j.trim()).filter(Boolean).every(j=>/^--doc-code-height\s*:/i.test(j)),R=[...E.length?[`class ${JSON.stringify(E.join(" "))}`]:[],...B.filter(j=>!(j==="style"&&nt))];return R.length&&x.push(`${R.join(", ")} kept on its <${b.tagName}>`),`<${b.tagName}${E.length?` class="${z(E.join(" "))}"`:""}${B.map(j=>I(b,j)).join("")}>`},zt=s?Me(s):[],De=`<div class="doc-code${W?` ${Zt}`:""}${ot?` ${ot}`:""}"${I(A,"id")}${I(k("data-block-id"),"data-block-id")}${y?` data-language="${z(y.toLowerCase())}"`:""}${st.join("")}${zt.map(b=>I(s,b)).join("")}>`;zt.length&&x.push(`${zt.join(", ")} kept on the block (its <figure>'s)`);let Fe=Re(t),vt=b=>a?`${b}${Fe}`:`${b}${Fe}<code>`,Ct=a&&P(a)?"</pre>":"</code></pre>",St=b=>`<div class="doc-code-title">${b}</div>`;if(!s)K(t,vt(`${De}${St(Be)}`),`${Ct}</div>`);else if(K(s,De,"</div>"),!n)K(t,vt(St(Be)),Ct);else{let{startOffset:b,endOffset:E}=n.sourceCodeLocation,B={from:i(n).endOffset,to:d(n).startOffset},H=R=>R.replace(/[ \t\n\r\f]+/g," ").trim(),nt=(R,j)=>o.slice(R,j).split(`
11
- `).length-1;if(b<t.sourceCodeLocation.startOffset)r(b,E,R=>`${St(H(R))}${Ot.repeat(nt(b,E))}`,{move:B}),K(t,vt(""),Ct);else{let R=ft(o,b,E),j=nt(R.start,R.end),ao=j?`${Ot.repeat(j)}${ve(i(t).startOffset)}`:"";r(i(t).startOffset,i(t).endOffset,io=>vt(`${St(H(io))}${ao}`),{move:B}),r(R.start,R.end,""),d(t)&&r(d(t).startOffset,d(t).endOffset,Ct)}}if(a&&Z(a).length&&r(i(a).startOffset,i(a).endOffset,Re(a)),n){let b=new Set,E=B=>{for(let H of L(B))(!on.has(H.tagName)||Z(H).length)&&b.add(U(o.slice(i(H).startOffset,i(H).endOffset))),ee.has(H.tagName)?r(i(H).startOffset,i(H).endOffset,H.tagName==="br"?" ":""):(Mt(H),E(H))};E(n);for(let B of b)x.push(`${B} in its caption left out: a code block's title is plain text`)}h(s??t,"code",x)}function Ae(t,s){let n=t.tagName;if(!P(t))return!1;if((n==="p"||n==="div"&&C(t).length===0)&&no(t))return K(t,T(t,"div",{classes:["doc-math-block"]}),"</div>"),h(t,"display formula"),!0;if(n==="figure"&&C(t).length===0&&so(t)){let c=Pt(L(t).find(m=>m.tagName==="img"),t,s);return r(i(t).startOffset,i(t).endOffset,Wt(t,c)),L(t).some(m=>m.tagName==="figcaption")||r(d(t).startOffset,d(t).startOffset,"<figcaption></figcaption>"),h(t,"figure",c?[c.note]:[]),!0}if(n==="img"&&Et.has(s?.tagName)){let c=Pt(t,null,s);return N(i(t).startOffset,i(t).endOffset,Wt(null,c),"<figcaption></figcaption></figure>"),h(t,"picture",c?[c.note]:[]),!0}if(n==="p"&&Et.has(s?.tagName)&&Ys(t))return to(t),!0;if(w(t,"data-doc-sheets")!==void 0){let c=po(t)?.tabs;return c&&Qs(t,c),!1}if(n==="p"&&oo(t)){let c=Pt(L(t)[0],t,s);return K(t,Wt(t,c),"<figcaption></figcaption></figure>"),h(t,"picture",c?[c.note]:[]),!0}let l=n==="figure"&&C(t).length===0?as(t):null;if(l&&!l.why&&P(l.pre))return Ie(l.pre,t,l.caption),!0;if(n==="pre"&&!C(s??{}).includes("doc-code")){let m=s?.tagName==="figure"&&C(s).length===0&&L(s).some(k=>k.tagName==="figcaption")?as(s):null,y=m?.pre===t?m.why:"";return Ie(t,null,null,y?[`its <figure>'s caption stays a caption beside it: ${y}; a <figure> holding the pre and one <figcaption> of words alone makes them its title`]:[]),!0}if(n==="figure")return!Et.has(s?.tagName)||jo(t)?!0:(g(t,["doc-figure"]),h(t,"figure"),ct(t));let a=n==="table"&&C(s??{}).includes("doc-table-wrap");if(n==="table"&&w(t,"data-doc-chart")!==void 0&&!Et.has((a?s.parentNode:s)?.tagName))return!1;if(n==="table"&&w(t,"data-doc-chart")!==void 0&&a&&i(s)){let c=w(s,tt)??ye();if(Ce(t,s,c),w(s,tt)===void 0){let m=i(s).endOffset-1;r(m,m,` ${tt}="${z(c)}"`)}return r(i(t).startOffset,i(t).endOffset,T(t,"table",{drop:["data-doc-chart"]})),!1}if(n==="table"&&(!ct(t)||ms(t))&&!C(s??{}).includes("doc-table-wrap")){let c=t.sourceCodeLocation.attrs?.["data-block-id"],m=w(t,"data-doc-chart")!==void 0,k=(w(t,tt)?.trim()||null)??(m?ye():null),I=w(t,"style"),A=I===void 0?[]:ne(I).filter(W=>es.test(W)),x=A.length?ne(I).filter(W=>!es.test(W)):[],_=W=>` style="${z(W.map(ot=>ot.trim()).join("; "))}"`,F=`<div class="doc-table-wrap"${c?` ${o.slice(c.startOffset,c.endOffset)}`:""}${k?` ${tt}="${z(k)}"`:""}${A.length?_(A):""}>`,Y=T(t,"table",{classes:["doc-table"],drop:["data-block-id",...w(t,tt)!==void 0?[tt]:[],...m?["data-doc-chart"]:[],...A.length?["style"]:[]]}),st=x.length?`${Y.slice(0,-1)}${_(x)}>`:Y,J=m?null:Se(t),X=!1;if(m&&(X=Ce(t,t,k,"</div>")),J){let W=o.slice(i(t).endOffset,J.sourceCodeLocation.startOffset);r(i(t).startOffset,i(J).endOffset,'<p class="doc-note">'),r(d(J).startOffset,d(J).endOffset,`</p>${W}${F}${st}`),h(J,"caption")}else r(i(t).startOffset,i(t).startOffset,F,{opens:d(t).endOffset}),r(i(t).startOffset,i(t).endOffset,st);return X||r(d(t).endOffset,d(t).endOffset,"</div>",{closes:i(t).startOffset}),h(t,"table",Js(t)),!1}if(n==="details"&&ts(t)){let c=L(t)[0]?.tagName==="summary"?L(t)[0]:null;return!c||!P(c)||(r(i(t).startOffset,i(t).endOffset,T(t,"details",{classes:["doc-details"]})),L(c).some(m=>C(m).includes("doc-details-summary-label"))||N(i(c).endOffset,d(c).startOffset,'<span class="doc-details-summary-label">',"</span>"),N(d(c).endOffset,d(t).startOffset,'<div class="doc-details-content">',"</div>"),kt(t.childNodes.slice(t.childNodes.indexOf(c)+1)),h(t,"details")),!1}if(n==="dialog"&&ge(t)){let c=Ms(t);return r(i(t).startOffset,i(t).endOffset,T(t,"dialog",{classes:["doc-dialog"]})),N(i(t).endOffset,d(t).startOffset,'<div class="doc-dialog-panel"><div class="doc-dialog-content">',"</div></div>"),c&&K(c,"<h3>","</h3>"),kt(t.childNodes.slice(c?t.childNodes.indexOf(c)+1:0)),h(t,"dialog"),!1}if(n==="aside"&&ts(t)&&!q({tags:["aside"]}))return g(t,["doc-panel"]),Ut.add(t),h(t,"aside"),!1;if(n==="ul"&&Ee(t)){g(t,[te],{drop:fe});for(let c of L(t))_e(c);return h(t,"task list"),!1}if(oe(t)&&!ct(t))return r(i(t).startOffset,i(t).endOffset,T(t,"ol",{classes:[mt],drop:["data-doc-chart","data-flow"]})),h(t,"flowchart"),!1;if(n==="ul"&&C(t).includes(te)&&!ct(t)){let c=L(t).filter(ys);if(c.length&&!Te()){for(let m of c)_e(m);h(t,"task list")}return!1}return!1}function _e(t){let s=Ls(t);if(g(t,[],{drop:de}),w(s,"checked")!==void 0){let a=i(t).startOffset+1+t.tagName.length;r(a,a,` ${ie}`)}let{startOffset:n,endOffset:l}=s.sourceCodeLocation;r(n,l+(o[l]===" "?1:0),"")}function $t(t,s=null,n=!1){let l=()=>Qt(t.childNodes).length>0;ws(t)&&(bs(t)||(Ut.has(t)||Go(t))&&l())?kt(t.childNodes):Vo(t)&&i(t)&&Ps(t);for(let a of t.childNodes??[]){if(D(a)){a.sourceCodeLocation&&a.value.includes("\\(")&&!be.has(a)&&Ks(a);continue}if(!(!a.tagName||ce.has(a.tagName)||xe.has(a))){if(it(a)){for(let c of at(a))Ut.add(c),$t(c,c);continue}if(!(w(a,"data-doc-chart")!==void 0&&a.tagName!=="table"&&!oe(a)||w(a,"contenteditable")!==void 0)&&!C(a).some(c=>_t.includes(c))){if(a.tagName==="pre"){Ae(a,t);continue}if(!(le(a)&&!Ee(a))){if(Gt.has(a)){we(a)||$t(a,a,!0);continue}Ae(a,t)||n&&we(a)||$t(a,a,n||re.has(a.tagName))}}}}}$t(p,p),$t({childNodes:Dt}),o.includes(dt.header)&&Ft(f);for(let t of Dt){let{startOffset:s,endOffset:n}=t.sourceCodeLocation,l=ft(o,s,n),a=d(p).startOffset,c=l.end>n?qt(o,a):null;r(a,a,m=>c===null?m:`${m}${Ot}${c}`,{move:{from:s,to:n}}),r(l.start,l.end,"",{leaves:!0}),h(t,"card outside main")}if(!O.length)return{text:o,changes:[]};let Lt=O;for(let t of O.filter(s=>s.move)){let{from:s,to:n}=t.move,l=Lt.filter(a=>!a.move&&!a.leaves&&a.start>=s&&a.end<=n);Lt=Lt.filter(a=>!l.includes(a)),t.text=t.text(is(o.slice(s,n),l,s)),t.move=null}return{text:is(o,Lt),changes:u.sort((t,s)=>t.line-s.line)}}function is(e,o,f=0){let p=h=>h.closes!==null?0:h.opens!==null?2:1,O=(h,v)=>p(h)-p(v)||(h.closes!==null?v.closes-h.closes||v.order-h.order:0)||(h.opens!==null?v.opens-h.opens:0)||h.order-v.order,u=[...o].sort((h,v)=>v.start-h.start||v.end-h.end||(h.start===h.end?O(v,h):v.order-h.order)),$=e;for(let{start:h,end:v,text:r}of u)$=$.slice(0,h-f)+r+$.slice(v-f);return $}function Ss(e,{finish:o=f=>f}={}){let{text:f,changes:p}=rn(e);return{text:p.length?o(f):f,changes:p}}function Kn(e,{finish:o,next:f,metadata:p=null}={}){let O=Xt(e);if(O.length)return{text:e,changes:[],added:0,given:[],repeated:O,title:null,icon:null};let u=Ss(e,{finish:o}),{text:$,added:h,given:v}=Ue(u.text,f),r=Ts($,p);return{...r,changes:u.changes,added:h,given:qe(r.text,v),repeated:O}}function Hn(e){return Xt(e).length?[]:ze(Ss(e).text)}var xs=e=>e.units.find(o=>o.kind==="icon"&&e.boxes[o.box]?.kind==="header")??null;function Ts(e,o=null){let f=rt(e,{sourceCodeLocationInfo:!0}),p=bt(f),O=p&&gt(p,r=>pt(r,us.title)),u=O?.sourceCodeLocation?.endTag?xt(e.slice(O.sourceCodeLocation.startTag.endOffset,O.sourceCodeLocation.endTag.startOffset)):"",$=e,h=null;if(u){let r=gt(f,S=>S.tagName==="head"),i=(r&&gt(r,S=>S.tagName==="title"))?.sourceCodeLocation,d=typeof o?.title=="string"?o.title:null,g=!1;if(i?.startTag&&i.endTag){let S=xt(e.slice(i.startTag.endOffset,i.endTag.startOffset));if(!(d&&d!==u&&d.includes(u)?S.split(d).join("\0").includes(u):S.includes(u))){let M=d&&d!==u&&Ke(e,{from:d,to:u})||{start:i.startTag.endOffset,end:i.endTag.startOffset,text:ht(u)};$=e.slice(0,M.start)+M.text+e.slice(M.end),g=!0}}(g||d!==null&&d!==u)&&(h={from:d,to:u,page:g})}let v=null;if(p&&o&&typeof o=="object"){let r=Vt(e),N=xs(r),i=N?fs(e.slice(N.start,N.end)):null,d=o.icon??null;N?i!==null&&i!==d&&(v={from:d,to:i}):v=d===null?null:{from:d,to:d,missing:!0}}return{text:$,title:h,icon:v}}function Pn(e,{title:o,icon:f}={}){let p=N=>{let i=bt(rt(N,{sourceCodeLocationInfo:!0})),d=i&&gt(i,g=>pt(g,us.title));return d?.sourceCodeLocation?.endTag?d.sourceCodeLocation:null},O=N=>xs(Vt(N)),u=p(e);if(!u)return{missing:!0};let $=xt(e.slice(u.startTag.endOffset,u.endTag.startOffset)),h=O(e),v={title:$,icon:h?fs(e.slice(h.start,h.end)):null},r=e;if(f!==void 0&&f!==v.icon){if(h&&f===null){let N=ft(r,h.start,h.end);r=r.slice(0,N.start)+r.slice(N.end)}else if(h){let N=/\sdata-block-id="[^"]*"/.exec(/^<[^>]*>/.exec(r.slice(h.start,h.end))?.[0]??"")?.[0]??"";r=r.slice(0,h.start)+Ze(f,N)+r.slice(h.end)}else{let N=qt(r,u.startTag.startOffset);r=r.slice(0,u.startTag.startOffset)+Ze(f)+(N===null?"":`
12
- ${N}`)+r.slice(u.startTag.startOffset)}u=p(r)}return o!==void 0&&(r=r.slice(0,u.startTag.endOffset)+ht(o)+r.slice(u.endTag.startOffset),r=Ts(r,{title:$||null}).text),{text:r,before:v}}var cs={table:"a table is the kit's framed table","header row":"a header row is a thead, its cells highlighted",caption:"a table's caption is a note line above it (p.doc-note)",figure:"a figure is the kit's card",picture:"a picture is the kit's picture block",details:"a details is the kit's disclosure",dialog:"a dialog is a detail card",aside:"an aside is a highlight panel","task list":"a task list is the kit's to-do list",flowchart:"a marked list is a flowchart",sheets:"headings become tabs",bookmark:"a link card is a bookmark","display formula":"a display formula is the kit's math block","card outside main":"a card outside main moved to main's end"};function Wn(e,o,{dryRun:f=!1,pending:p=!1,reread:O=!f&&!p}={}){let u=new Map;for(let{rule:N,line:i}of o)u.set(N,[...new Set([...u.get(N)??[],i])]);let $=[...u].map(([N,i])=>`${N} (line${i.length>1?"s":""} ${i.join(", ")})`).join(", "),h=ro.resolve(e),v=[...u.keys()].filter(N=>cs[N]).map(N=>cs[N]).join("; "),r=`${v?`; ${v}`:""}; the words and numbers are unchanged`;return[p?`natural ${h}: ${$} not rewritten yet: the export rewrites them in this file as the kit's markup (nothing to fix)${r}`:`natural ${h}: ${$}${f?" would be":""} rewritten in this file as the kit's markup (nothing to fix)${r}`,...o.filter(N=>N.note).map(({line:N,rule:i,note:d})=>` line ${N}, ${i}: ${d}`),...O?[" re-read the file before editing it"]:[]]}var rs="strong, em, b, i, u, s, code, a, sub, sup and br, the kit's colors (doc-text-*, doc-highlight-*) and formulas",he=`write a to-do list as ul.${te} \u203A li, li[${ie}] for a checked item (a GFM task list, every item starting with its box, is made one unless the document's own style or script uses GFM's classes or the boxes)`,Es=e=>C(e).every(ds),Is=e=>L(e).flatMap(o=>[...o.tagName==="span"&&!(G(o,["class"])&&Es(o))?[o]:[],...Is(o)]),As=e=>L(e).some(o=>o.tagName==="img"||As(o)),_s=e=>L(e).flatMap(o=>o.tagName==="img"?[o]:_s(o)),js=e=>L(e).some(o=>o.tagName==="svg"||o.tagName==="canvas"||js(o)),Bt=e=>L(e).some(o=>o.tagName==="input"&&w(o,"type")?.toLowerCase()==="checkbox"||Bt(o)),ln=(e,o)=>{if(e==="tag:img")return"a picture amid the words: give it a paragraph of its own";if(e==="picture"){let f=_s(o).map(We).find(Boolean);return`a picture in a cell written another way${f?` (${f})`:""}: the preview edits <img src="assets/<file>" alt="\u2026" width="N"> (N pixels, or no width), no other attribute`}if(e==="tag:span"){let f=Is(o).filter(p=>G(p,["style","class"])&&w(p,"style")!==void 0&&Es(p)).map(p=>vs(w(p,"style")).foreign).find(Boolean);return f?`a span with a style the kit has no format for (${f.join(", ")}): left as written`:`a <span> with a class or attribute of the document's own (the preview edits ${rs})`}return e==="tag:input"&&Bt(o)?`a checkbox amid the words: ${he}`:e.startsWith("tag:")&&lt.has(e.slice(4))?`a block (<${e.slice(4)}>) amid the words: give the words a paragraph of their own`:e.startsWith("tag:")?`<${e.slice(4)}> amid the words (the preview edits ${rs})`:e==="comment"?"an HTML comment amid the words":e==="markup"?"an element not closed in the file (the parser closed it)":e==="mention"?'a page block written another way: the preview edits only <a class="doc-link-mention" href="../<slug>/doc.html"><span class="doc-link-mention-icon"></span>title</a>, its title plain words, no other attribute':e==="link"?"a javascript: or data: link":e},fn=new Set([...$s,"details"]);function Un(e){let o=rt(e,{sourceCodeLocationInfo:!0}),f=bt(o);if(!f)return[];let p=N=>e.slice(0,N).split(`
13
- `).length,O=new Map,u=[],$=N=>{fn.has(N.tagName)&&N.sourceCodeLocation?.startTag&&bs(N)&&u.push({line:p(N.sourceCodeLocation.startOffset),text:`<${N.tagName}>: words straight in it, outside any paragraph: give them a <p> (the preview cannot reach them, nor move its blocks one by one)`})},h=(N,i=()=>!1)=>{for(let d of L(N)){if(i(d))continue;let g=d.sourceCodeLocation?.startTag;g&&O.set(g.endOffset-1,d),h(d,i)}},v=N=>{for(let i of N.childNodes??[]){if(!i.tagName||ce.has(i.tagName))continue;if(it(i)){h(i,ls),at(i).forEach(v);continue}if(w(i,"data-doc-chart")!==void 0||C(i).some(S=>_t.includes(S))||le(i))continue;let d=i.sourceCodeLocation?.startTag;d&&O.set(d.endOffset-1,i);let g=i.sourceCodeLocation?.endTag;if(re.has(i.tagName)&&d&&i.childNodes.some(S=>D(S)&&/\\\[|\$\$/.test(S.value))&&!(g&&i.childNodes.every(D)&&wt(e.slice(d.endOffset,g.startOffset)))){let S=Mo(e.slice(d.endOffset,g?g.startOffset:i.sourceCodeLocation.endOffset),!!g);u.push({line:p(d.startOffset),text:S?`<${i.tagName}>: the formula holds a bare < or >: write \\lt / \\gt (or &lt; / &gt;)`:`<${i.tagName}>: a display formula (\\[\u2026\\] or $$\u2026$$) amid the words: give it a paragraph of its own`})}i.tagName==="caption"&&d&&(et(i)||L(i).length>0)&&u.push({line:p(d.startOffset),text:'<caption>: the preview cannot edit a table caption; write the line above the table as <p class="doc-note">'}),$(i),v(i)}};$(f),v(f);let r=new Set;for(let{at:N,reason:i}of Jt(e).locks){let d=O.get(N);if(!d)continue;let g=i==="tag:input"&&d.tagName==="li"&&Bt(d)&&d.parentNode?.sourceCodeLocation?.startTag?d.parentNode:null;g&&r.has(g)||(g&&r.add(g),g?u.push({line:p(g.sourceCodeLocation.startOffset),text:`<${g.tagName}>: checkboxes in its items: ${he}`}):u.push({line:p(d.sourceCodeLocation.startOffset),text:`<${d.tagName}>: ${ln(i,d)}`}))}return u.sort((N,i)=>N.line-i.line).map(({line:N,text:i})=>`line ${N}: ${i}`)}function zn(e){let o=rt(e,{sourceCodeLocationInfo:!0}),f=bt(o);if(!f)return[];let p=d=>e.slice(0,d).split(`
14
- `).length,O=[],u=[],$=d=>{for(let g of d.childNodes??[])g.tagName==="style"?u.push((g.childNodes??[]).map(S=>S.value??"").join("")):$(g)};$(o);let h=u.join(`
15
- `).replace(/\/\*[\s\S]*?\*\//g,""),v=d=>new RegExp(`\\.${d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}(?![\\w-])`).test(h),r=d=>{for(let g of L(d).filter(S=>S.tagName==="colgroup"&&w(S,"data-doc-columns")===void 0)){let S=[g,...L(g)].filter(M=>w(M,"width")!==void 0||/(?:^|;)\s*(?:min-|max-)?width\s*:/i.test(w(M,"style")??"")),T=(g.sourceCodeLocation?g:L(g)[0])?.sourceCodeLocation;S.length&&T&&O.push({line:p(T.startOffset),text:`<${g.sourceCodeLocation?"colgroup":"col"}> widths: the kit sizes columns itself; a merged table uses yours`})}},N=d=>{for(let g of d.childNodes??[]){if(!g.tagName||ce.has(g.tagName))continue;if(it(g)){at(g).forEach(N);continue}if(w(g,"data-doc-chart")!==void 0||C(g).some(T=>_t.includes(T)))continue;if(le(g)){let T=g.sourceCodeLocation,M=lo(e,g).some(({name:q})=>q==="class");if(ps.has(g.tagName)&&T?.startTag&&!M&&(et(g)||As(g))&&!js(g)&&!C(g).some(v)){let q=(g.tagName==="ul"||g.tagName==="ol")&&Bt(g)?`; for its checkboxes, ${he}`:"";O.push({line:p(T.startOffset),text:`<${g.tagName} class="${w(g,"class").trim()}"> is a whole block (\u6574\u4F53\u5757): the reader moves it whole and edits its words in place; right for a layout of yours that is no figure (a figure, a diagram or a timeline, goes in <figure class="doc-figure">); drop its class only if its contents were meant as ordinary blocks${q}`})}continue}g.tagName==="table"&&r(g);let S=g.tagName==="ol"&&C(g).includes(mt)?L(g).find(T=>T.tagName!=="li"&&T.sourceCodeLocation):null;if(S&&O.push({line:p(S.sourceCodeLocation.startOffset),text:`<ol class="${mt}"> holds a <${S.tagName}> outside its items: a flowchart's steps are its <li>s (what one holds after its words, a paragraph or a list, is that step's content)`}),g.tagName==="ol"&&C(g).includes(mt))for(let T of L(g).filter(M=>M.tagName==="li")){let M=L(T).find(Q=>!C(Q).includes(At)),q=M?T.childNodes.slice(0,T.childNodes.indexOf(M)):[];M&&M.tagName!=="p"&&M.sourceCodeLocation&&!q.some(Q=>!C(Q).includes(At)&&et(Q))&&O.push({line:p(M.sourceCodeLocation.startOffset),text:`a step of <ol class="${mt}"> begins with a <${M.tagName}>: a step's first block is its title, a paragraph (<p><strong>\u2026</strong></p>), the blocks after it its content`})}N(g)}};return N(f),i(f,(d,g)=>O.push({line:d,text:`a ${dn[g]} in the text: the page shows it as a break or an empty line, not as a character (a tool that decodes \\u2028 or \\u2029 escapes writes one); write the break the text means (<br>, a new paragraph, a new line in code) or take it out`})),O.sort((d,g)=>d.line-g.line).map(({line:d,text:g})=>`line ${d}: ${g}`);function i(d,g){for(let S of d.childNodes??[])if(!(S.tagName==="script"||S.tagName==="style")){if(it(S)){at(S).forEach(T=>i(T,g));continue}if(D(S)&&S.sourceCodeLocation&&/[\u2028\u2029]/.test(S.value)){let{startOffset:T,endOffset:M}=S.sourceCodeLocation,Q=e.slice(T,M).search(/[\u2028\u2029]/);g(p(T+Math.max(Q,0)),S.value.match(/[\u2028\u2029]/)[0])}i(S,g)}}}function qn(e){let o=$=>e.slice(0,$).split(`
16
- `).length,f=$=>D($)?$.value:($.childNodes??[]).map(f).join(""),p=$=>f($).replace(/\s+/g," ").trim(),O=$=>L($).find(h=>/^h[1-6]$/.test(h.tagName)),u=[];for(let $ of Jt(e).units){if($.keep?.reason!=="script"||!$.keep.own)continue;let h=$.node.parentNode;for(;h&&h.tagName!=="section";)h=h.parentNode;let v=$.tag==="section"&&O($.node)?` ${p(O($.node))}`:"",r=h?.tagName&&O(h)?` in ${p(O(h))}`:"";u.push({line:o($.elStart),text:`<${$.tag}>${v}${r} kept by the script: ${$.keep.names.join(", ")} (the reader cannot delete or convert it; rename any of these the script does not select it by)`})}return u.sort(($,h)=>$.line-h.line).map(({line:$,text:h})=>`line ${$}: ${h}`)}var dn={"\u2028":"line separator (U+2028)","\u2029":"paragraph separator (U+2029)"};function bt(e){return gt(e,o=>o.tagName==="main")}function gt(e,o){if(e.tagName&&o(e))return e;for(let f of e.childNodes??[]){let p=gt(f,o);if(p)return p}return null}export{rn as a,Ss as b,Kn as c,Hn as d,Ts as e,Pn as f,Wn as g,Un as h,zn as i,qn as j};
@@ -1,20 +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{c as ye,d as Z,f as se,h as ae,i as Ce,l as ie}from"./chunk-D4EURAX4.mjs";import{D as oe}from"./chunk-UBBRTJ2R.mjs";import{a as X,f as Oe,g as be,n as $e,t as Se}from"./chunk-FWNRPMCJ.mjs";import{b as xe,e as dt}from"./chunk-A55HN5OK.mjs";dt();import{createHash as lt}from"node:crypto";import{cellsOf as ft}from"../browser/shared/card-size.mjs";import{escapeAttribute as ce}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as de,hasClass as je,walk as Ae}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as ve}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,Ut=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),_e="gallery-board",Le="gallery-card",Ee=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,ve)!==void 0,ut=e=>lt("sha256").update(e.replace(/\r\n?/g,`
3
- `)).digest("hex").slice(0,16),pt=e=>xe(e.replace(/^/," "),{sourceCodeLocationInfo:!0});function j(e){let n=[];return Ae(pt(e),r=>{if(!je(r,_e))return;let f=de(r).filter(s=>je(s,Le)&&s.sourceCodeLocation).map(s=>{let a=de(s).find(Ee)??null;a||Ae(s,x=>{a??=Ee(x)?x:null});let h=s.sourceCodeLocation,g={x:N(s,"data-x"),y:N(s,"data-y"),w:N(s,"data-w"),h:N(s,"data-h")};return{id:N(s,"data-card-id")??null,node:s,board:N(r,"data-board-id")??null,...ft({dataset:g}),instance:a,block:a?N(a,ve):null,start:h.startOffset,end:h.endOffset,closed:!!h.endTag}});n.push({id:N(r,"data-board-id")??null,node:r,cards:f})},{inTemplates:!1}),{boards:n,cards:n.flatMap(r=>r.cards)}}function mt(e){let n=new Set(e.map(({id:s})=>s).filter(s=>typeof s=="string"&&q.test(s))),r=new Set,f=1;return e.map(({id:s})=>{if(typeof s=="string"&&q.test(s)&&!r.has(s))return r.add(s),s;for(;n.has(`c${f}`)||r.has(`c${f}`);)f++;let a=`c${f}`;return r.add(a),a})}function le(e){let n=new Set(e),r=1;for(;n.has(`c${r}`);)r++;return`c${r}`}function ee(e,n,r){let{startTag:f}=n.sourceCodeLocation,s=f.attrs??{},a=[],h=[];for(let[g,x]of Object.entries(r)){let S=s[g];S?(a.push({start:S.startOffset,end:S.endOffset,text:x===null?"":`${g}="${ce(String(x))}"`}),x===null&&e[S.startOffset-1]===" "&&(a.at(-1).start-=1)):x!==null&&h.push(` ${g}="${ce(String(x))}"`)}if(h.length){let g=s.class?.endOffset??f.startOffset+1+n.tagName.length;a.push({start:g,end:g,text:h.join("")})}return a}function te(e,n){return[...n].sort((r,f)=>f.start-r.start||f.end-r.end).reduce((r,{start:f,end:s,text:a})=>r.slice(0,f)+a+r.slice(s),e)}function W(e){let{cards:n}=j(e),r=mt(n),f=n.flatMap((s,a)=>s.id===r[a]?[]:ee(e,s.node,{"data-card-id":r[a]}));return{text:f.length?te(e,f):e,filled:n.flatMap((s,a)=>s.id===r[a]?[]:[r[a]])}}var V=(e,n)=>ut(e.slice(n.start,n.end));function ze(e){let n=W(e).text;return j(n).cards.map(r=>({id:r.id,board:r.board,x:r.x,y:r.y,w:r.w,h:r.h,base:V(n,r),block:r.block}))}var Ie=e=>[e.board,...["x","y","w","h"].map(n=>N(e.node,`data-${n}`))].join(",");function Te(e,n){let r=n.node.sourceCodeLocation.startTag.endOffset;return e.slice(n.start,r).replace(/\s+data-[xywh]="[^"]*"/g,"")+e.slice(r,n.end)}function Me(e,n){let[r,f]=[W(e).text,W(n).text],[s,a]=[j(r).cards,j(f).cards],h={};for(let g of s)a.some(x=>x.id===g.id)||(h[g.id]=["removed"]);for(let g of a){let x=s.find(v=>v.id===g.id);if(!x){h[g.id]=["added"];continue}let S=[...Ie(x)!==Ie(g)?["cells"]:[],...Te(r,x)!==Te(f,g)?["content"]:[]];S.length&&(h[g.id]=S)}return h}function Y(e,n){let{cards:r}=j(e),f=r.flatMap(s=>{let a=n.get(s.id);if(!a)return[];let h={};for(let g of["x","y","w","h"])a[g]!==void 0&&N(s.node,`data-${g}`)!==String(a[g])&&(h[`data-${g}`]=a[g]);return Object.keys(h).length?ee(e,s.node,h):[]});return f.length?te(e,f):e}function ht(e,n,r){let f=e.lastIndexOf(`
4
- `,n-1)+1,s=e.indexOf(`
5
- `,r),a=s===-1?e.slice(r):e.slice(r,s);return!/^[ \t]*$/.test(e.slice(f,n))||!/^[ \t\r]*$/.test(a)?{from:n,to:r}:{from:f,to:s===-1?e.length:s+1}}function Pe(e,n){let r=j(e).cards.find(a=>a.id===n);if(!r)return null;let{from:f,to:s}=ht(e,r.start,r.end);return{text:e.slice(0,f)+e.slice(s),html:e.slice(r.start,r.end)}}var Ne=(e,n)=>/^[ \t]*/.exec(e.slice(e.lastIndexOf(`
6
- `,n-1)+1))[0],gt=(e,n)=>e.replace(/\r?\n/g,r=>`${r}${n}`);function Re({id:e,x:n,y:r,w:f,h:s},a,h="",g=`
7
- `){return`${`<section class="${Le}" data-card-id="${ce(e)}" data-x="${n}" data-y="${r}" data-w="${f}" data-h="${s}">`}${g}${h} ${gt(a.trim().replace(/\r?\n/g,g),`${h} `)}${g}${h}</section>`}function fe(e,n,r){let f=j(e).boards.find(A=>A.id===n);if(!f)return null;let{node:s}=f,a=s.sourceCodeLocation,h=e.includes(`\r
8
- `)?`\r
9
- `:`
10
- `,g=f.cards.at(-1),x=g?Ne(e,g.start):`${Ne(e,a.startOffset)} `,S=r.match(/\n([ \t]*)<\/[a-z]+>\s*$/)?.[1]??"",v=r.trim().replace(/\r?\n/g,`
11
- `).split(`
12
- `).map((A,_)=>_===0||S===x?A:A.startsWith(S)?`${x}${A.slice(S.length)}`:A).join(h);if(a.endTag){let A=a.endTag.startOffset,_=e.lastIndexOf(`
13
- `,A-1)+1,R=/^[ \t]*$/.test(e.slice(_,A)),L=R?_:A,H=`${R?"":h}${x}${v}${h}`;return{text:e.slice(0,L)+H+e.slice(L),start:L+H.indexOf(v)}}let I=a.endOffset,P=`${h}${x}${v}`;return{text:e.slice(0,I)+P+e.slice(I),start:I+P.indexOf(v)}}function Gt(e,{blockOf:n=()=>null}={}){let r=W(e).text,f=[];for(let s of j(r).cards){let a=s.block?n(s.block):null,h={"data-ge-base":V(r,s)};a?.fit==="content"&&(h["data-ge-fit"]="content"),a?.bare&&(h["data-ge-bare"]="");let g=s.block===null?null:a?.state??"missing";if(g&&g!=="page"&&(h["data-ge-state"]=g),f.push(...ee(r,s.node,h)),s.instance&&a&&g!=="page"&&g!=="missing"){let{startOffset:x,endOffset:S}=s.instance.sourceCodeLocation;f.push({start:x,end:x,text:"<template data-ge-held>"},{start:S,end:S,text:"</template>"})}}return te(r,f)}function Fe(e){let n=`<!doctype html><html><head></head><body><div class="${_e}">`,r=`${n}${e}</div></body></html>`,[f]=j(r).boards;return{text:r,board:f,from:n.length,to:n.length+e.length}}function De(e){let{board:n}=Fe(e);if(!n||n.cards.length!==1)return null;let r=de(n.node).length!==1||n.node.childNodes.some(s=>s.nodeName==="#text"&&s.value.trim()),[f]=n.cards;return r||!f.closed||!f.instance||f.instance.parentNode!==f.node?null:f}function He(e,{id:n,x:r,y:f,w:s,h:a}){let{text:h,board:g,from:x,to:S}=Fe(e),v={"data-card-id":n,"data-x":r,"data-y":f,"data-w":s,"data-h":a},I=ee(h,g.cards[0].node,v),P=I.reduce((A,{start:_,end:R,text:L})=>A+L.length-(R-_),0);return te(h,I).slice(x,S+P)}import{readFileSync as Be}from"node:fs";import M from"node:fs/promises";import F from"node:path";import{refusedInCopy as Je}from"../browser/shared/components/installed.mjs";import{writeAtomic as We}from"../browser/shared/files.mjs";import{sendJson as re}from"../browser/shared/http.mjs";import{jsonIn as wt}from"../browser/shared/json-layout.mjs";import{defaultSize as ue,freeSpot as kt,onBoard as pe,pushDown as me,settle as xt,sizeFor as Ue}from"../browser/shared/board-places.mjs";import{FIRST_BOARD as Ge,HOME as Ke,HOME_CARDS as Ot,closeHomeHint as bt,pageExists as he,pageFiles as $t,pageVersion as Ve,tellHomeCards as Ye}from"../browser/shared/pages.mjs";import{sameDirectory as St}from"../browser/shared/preview-server.mjs";import{walk as yt}from"../browser/shared/html-tree.mjs";var Ct=20,ge="writes.jsonl",jt=200;async function dr(e,n,r){return(await M.readFile(F.join(e,"pages",n,ge),"utf8").catch(()=>"")).split(`
14
- `).flatMap(s=>{try{let a=JSON.parse(s);return a&&typeof a.at=="number"&&a.at>=r&&a.cards&&typeof a.cards=="object"?[a]:[]}catch{return[]}})}var At=["place","arrange","add","remove","edit","settings","restore-defaults"],U=e=>Number.isInteger(e)&&e>=0,ne=e=>Number.isInteger(e)&&e>=1,Et=/^\d{4}-\d{2}-\d{2}$/,O=(e,n,r)=>[e,{ok:!1,reason:n,...r?{message:r}:{}}];function It(e,n){return typeof e=="string"?e.replace(new RegExp(`(^|[\\s"'(,=])/pages/${n}/assets/`,"g"),"$1assets/"):e}var Qe=e=>[409,{ok:!1,refused:e}];function lr(e,n){let r=e.packages.get(n);return r?{state:r.places.includes("page")?"page":"document",card:r.card,settings:r.settings,places:r.places,fit:r.card.fit,bare:r.card.bare,name:r.name,parts:Object.fromEntries(Object.entries(r.parts).filter(([,f])=>f.edit==="data").map(([f,s])=>[f,s.at]))}:e.settings.disabled.includes(n)&&e.problems.has(n)?{state:"disabled",card:null,settings:[],places:[],fit:"fixed",bare:!1,name:null,parts:{}}:null}function Tt(e,{type:n,options:r}){return n==="text"||n==="document"?typeof e=="string"&&e.length<=1e4:n==="number"?typeof e=="number"&&Number.isFinite(e)||e===null:n==="select"?r.includes(e):n==="date"?e===""||typeof e=="string"&&Et.test(e):n==="switch"?typeof e=="boolean":!1}function Xe(e,{x:n,y:r,w:f,h:s}){let a={x:e.x??n,y:e.y??r,w:e.w??f,h:e.h??s};return U(a.x)&&U(a.y)&&ne(a.w)&&ne(a.h)?a:null}function Ze({root:e,edits:n,stateDirectory:r,catalog:f=()=>be(e),catalogTaken:s=()=>{},shipped:a=void 0,log:h=()=>{},shown:g=x=>x}){let x=0;async function S(d,t){let i=F.join(r,"pages",d);await M.mkdir(i,{recursive:!0}),x=(x+1)%1e4,await M.writeFile(F.join(i,`${String(Date.now()).padStart(15,"0")}-${String(x).padStart(4,"0")}.html`),t);let c=(await M.readdir(i)).filter(m=>/^\d{15}-\d{4}\.html$/.test(m)).sort();for(let m of c.slice(0,Math.max(0,c.length-Ct)))await M.rm(F.join(i,m),{force:!0})}async function v(d,t){let i=F.join(r,"pages",d,ge);try{let c=(await M.readFile(i,"utf8").catch(()=>"")).split(`
15
- `).filter(Boolean);c.push(JSON.stringify({at:Date.now(),...t})),await We(i,`${c.slice(-jt).join(`
16
- `)}
17
- `)}catch(c){h(`the write of ${d}'s page.html could not be told in ${ge}: ${c.message}`)}}function I(d,t){if(typeof t.card!="string")return{error:O(400,"card")};let i=j(d).cards.find(c=>c.id===t.card);return i?typeof t.base!="string"||V(d,i)!==t.base?{error:Qe("changed")}:{card:i}:{error:Qe("gone")}}let P=(d,t)=>j(d).cards.filter(i=>i.board===t).map(({id:i,x:c,y:m,w:l,h:u})=>({id:i,x:c,y:m,w:l,h:u})),A=(d,t)=>new Map(t.filter(i=>{let c=d.find(m=>m.id===i.id);return!c||c.x!==i.x||c.y!==i.y||c.w!==i.w||c.h!==i.h}).map(i=>[i.id,i])),_=(d,t,i)=>oe.installed.dataOf(d,t.instance,i)??{};function R(d,t,i,c){if(!t.instance||!c.has(t.block))return{error:O(409,"block")};let m=_(d,t,c),l=oe.installed.rewrite(d,t.instance,i,{packages:c});if(!l)return{error:O(400,"part")};let u=[...l].sort((p,k)=>k.start-p.start).reduce((p,{start:k,end:b,text:y})=>p.slice(0,k)+y+p.slice(b),d),w=_(u,j(u).cards.find(p=>p.id===t.id),c);return{text:u,parts:Object.fromEntries(Object.keys(i).map(p=>[p,{was:m[p]??"",now:w[p]??""}]))}}function L(d,t){return Object.fromEntries(Object.entries(d).map(([i,{was:c,now:m}])=>[i,{was:g(c,t),now:g(m,t)}]))}let H={place(d,t,{packages:i}){let{card:c,error:m}=I(d,t);if(m)return{error:m};let l=Xe(t,c);if(!l)return{error:O(400,"cells")};let u=i.get(c.block);if(l.w!==c.w||l.h!==c.h){let p=u&&!u.card.sizes&&u.card.h===null&&l.w===c.w;if(u&&!u.card.resize&&!p)return{error:O(409,"resize")};u&&!p&&(l={...l,...Ue(u.card,l)})}let w=P(d,c.board);return{text:Y(d,A(w,me(w,{id:c.id,...l})))}},arrange(d,t){if(!Array.isArray(t.cards)||t.cards.length===0)return{error:O(400,"cards")};let i=[];for(let m of t.cards){let{card:l,error:u}=I(d,m??{});if(u)return{error:u};let w=Xe(m,l);if(!w)return{error:O(400,"cells")};i.push({card:l,cells:pe(w)})}let c=d;for(let m of new Set(i.map(({card:l})=>l.board))){let l=P(c,m),u=i.filter(({card:p})=>p.board===m),w=l.map(p=>({...p,...u.find(({card:k})=>k.id===p.id)?.cells??{}}));c=Y(c,A(l,xt(w,u.map(({card:p})=>p.id))))}return{text:c}},async add(d,t,i){let{boards:c,cards:m}=j(d);if(t.html!==void 0)return nt(d,t,{boards:c,cards:m});if(typeof t.block!="string")return{error:O(400,"block")};let l=typeof t.board=="string"?c.find(C=>C.id===t.board):c.find(C=>C.id===Ge)??c[0];if(!l)return{error:O(409,"board")};se(t.block,a)&&ie(e,{ids:[t.block],directory:a,log:h}).updated.length>0&&(s(),i.refresh());let u=i.packages.get(t.block),w=i.catalog.settings.disabled.includes(t.block);if(!u&&!w&&!i.catalog.problems.has(t.block)&&se(t.block,a)){let C=Z(a).find(({id:K})=>K===t.block);C&&C.places.includes("page")&&!ae(e,C).added&&(Ce(e,C),h(`${t.block} added to the workspace for a card of a custom page`),s(),i.refresh(),u=i.packages.get(t.block))}if(!u)return{error:O(409,i.catalog.settings.disabled.includes(t.block)?"disabled":"missing")};if(!u.places.includes("page"))return{error:O(409,"places")};let p=Se(u);if(!p)return{error:O(409,"template")};if(t.w!==void 0&&!ne(t.w)||t.h!==void 0&&!ne(t.h))return{error:O(400,"cells")};let k=ue(u.card),b=t.w!==void 0||t.h!==void 0?Ue(u.card,{w:t.w??k.w,h:t.h??k.h}):k,y=l.cards.map(({id:C,x:K,y:it,w:ot,h:ct})=>({id:C,x:K,y:it,w:ot,h:ct})),o=t.x!==void 0||t.y!==void 0?{x:t.x??0,y:t.y??0}:kt(y,b);if(!U(o.x)||!U(o.y))return{error:O(400,"cells")};let $=le(m.map(C=>C.id)),T=pe({...o,w:b.w,h:b.h}),B=d.includes(`\r
18
- `)?`\r
19
- `:`
20
- `,E=Re({id:$,...T},p,"",B),G=fe(d,l.id,E),Q=A(y,me(y,{id:$,...T}).filter(C=>C.id!==$)),z=Y(G.text,Q),J=j(z).cards.find(C=>C.id===$);if(t.settings!==void 0){let C=H.settings(z,{card:$,base:V(z,J),values:t.settings},i);if(C.error)return C;z=C.text,J=j(z).cards.find(K=>K.id===$)}return{text:z,extra:{card:$,html:z.slice(J.start,J.end),measure:k.measured&&t.h===void 0,pushed:[...Q.keys()]}}},remove(d,t){let{card:i,error:c}=I(d,t);if(c)return{error:c};let{text:m,html:l}=Pe(d,i.id);return{text:m,extra:{removed:{id:i.id,board:i.board,html:l}}}},edit(d,t,{packages:i,slug:c}){let{card:m,error:l}=I(d,t);if(l)return{error:l};let u=t.parts!==void 0?t.parts:typeof t.part=="string"?{[t.part]:t.html}:null;if(!u||typeof u!="object"||Array.isArray(u)||Object.keys(u).length===0)return{error:O(400,"part")};let w=Object.fromEntries(Object.entries(u).map(([k,b])=>[k,It(b,c)])),p=R(d,m,w,i);return p.error?p:{text:p.text,extra:{parts:L(p.parts,c)}}},settings(d,t,{packages:i,slug:c}){let{card:m,error:l}=I(d,t);if(l)return{error:l};let u=i.get(m.block),w=u?.settings??[];if(!u||w.length===0)return{error:O(409,"settings")};let p=t.values;if(!p||typeof p!="object"||Array.isArray(p))return{error:O(400,"values")};for(let[T,B]of Object.entries(p)){let E=w.find(G=>G.key===T);if(!E||!Tt(B,E))return{error:O(400,"values",T)}}let k=_(d,m,i)[X];if(k===void 0)return{error:O(409,"settings")};let b={};try{b=k.trim()?JSON.parse(k):{}}catch{b={}}(!b||typeof b!="object"||Array.isArray(b))&&(b={});let y={...b,...p};if(JSON.stringify(y)===JSON.stringify(b))return{text:d,extra:{parts:L({[X]:{was:k,now:k}},c)}};let o=k.trim()?wt(k,y):JSON.stringify(y),$=R(d,m,{[X]:o},i);return $.error?$:{text:$.text,extra:{parts:L($.parts,c)}}},async"restore-defaults"(d,t,i){if(i.slug!==Ke)return{error:O(409,"home")};let c=new Set(j(d).cards.map(w=>w.block)),m=d,l=[],u=[];for(let w of Ot){if(c.has(w))continue;let p=await H.add(m,{op:"add",block:w},i),k=i.packages.get(w)?.name??Z(a).find(({id:b})=>b===w)?.title??null;if(p.error){u.push({block:w,reason:p.error[1].reason,name:k});continue}m=p.text,l.push({card:p.extra.card,block:w,html:p.extra.html,name:k})}return{text:m,extra:{added:l,skipped:u}}}};function nt(d,t,{boards:i,cards:c}){if(typeof t.html!="string"||t.html.length>11e5)return{error:O(400,"html")};let m=t.html.trim(),l=De(m);if(!l)return{error:O(400,"html")};let u=Je(l.node.tagName,l.node.attrs??[]);if(yt(l.node,E=>{u||=Je(E.tagName,E.attrs??[])}),u)return{error:O(400,"html")};let w=i.find(E=>E.id===(typeof t.board=="string"?t.board:Ge))??i[0];if(!w)return{error:O(409,"board")};if(t.x!==void 0&&!U(t.x)||t.y!==void 0&&!U(t.y))return{error:O(400,"cells")};let p=c.map(E=>E.id),k=l.id&&!p.includes(l.id)&&q.test(l.id)?l.id:le(p),b=pe({x:t.x??l.x,y:t.y??l.y,w:l.w,h:l.h}),y=w.cards.map(({id:E,x:G,y:Q,w:z,h:J})=>({id:E,x:G,y:Q,w:z,h:J})),o=fe(d,w.id,He(m,{id:k,...b})),$=A(y,me(y,{id:k,...b}).filter(E=>E.id!==k)),T=Y(o.text,$),B=j(T).cards.find(E=>E.id===k);return{text:T,extra:{card:k,html:T.slice(B.start,B.end),pushed:[...$.keys()]}}}async function we(d,t,{by:i}={}){if(!t||typeof t!="object"||!At.includes(t.op))return O(400,"op");if(t.workspace!==void 0&&(typeof t.workspace!="string"||!St(t.workspace,e)))return O(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");if(!he(d,e))return O(404,"missing");let c=$t(d,e);for(let m=0;m<3;m++){let[l,u]=await Promise.all([M.readFile(c.html,"utf8").catch(()=>null),M.readFile(c.json,"utf8").catch(()=>"")]);if(l===null)return O(404,"missing");if(Buffer.byteLength(l)>1e6)return O(413,"size");let w=Ve(l,u),p=W(l).text,k=f(),b={slug:d,get catalog(){return k},get packages(){return k.packages},refresh:()=>{k=f()}},y=await H[t.op](p,t,b);if(y.error)return y.error;let o=y.text;if(Buffer.byteLength(o)>1e6)return O(413,"size");if(o!==l){if(await S(d,l),!await We(c.html,o,{expect:l}))continue;await v(d,{op:t.op,by:i==="gallery"?"gallery":t.agent===!0?"agent":"page",cards:Me(l,o)})}return t.op==="restore-defaults"&&await Ye(e).catch(()=>{}),[200,{ok:!0,version:Ve(o,u),before:w,cards:ze(o),...y.extra??{}}]}return O(409,"busy")}function ke(d="zh"){ie(e,{directory:a,log:h}).updated.length>0&&s();let t=f(),i=t.settings.packsOff??[],c=o=>o.split("/")[0],m=o=>!t.settings.unlisted.includes(o)&&!i.includes(c(o)),l=o=>t.packs?.get(c(o))??null,u=[...t.packages.values()].filter(o=>o.places.includes("page")&&m(o.id)).map(o=>({id:o.id,name:o.name,description:o.description,preview:o.files.includes("preview.svg")?$e(o,"preview.svg"):null,size:ue(o.card),installed:!0,settings:o.settings.length>0,pack:{id:c(o.id),name:l(o.id)}}));for(let o of Z(a)){if(!o.places.includes("page")||t.packages.has(o.id)||t.problems.has(o.id)||t.settings.disabled.includes(o.id)||!m(o.id)||ae(e,o).added)continue;let $=null;try{$=`data:image/svg+xml;base64,${Be(F.join(o.folder,"preview.svg")).toString("base64")}`}catch{}let T=null;try{T=JSON.parse(Be(F.join(o.folder,"component.json"),"utf8")).card??null}catch{}u.push({id:o.id,name:o.title,description:o.description,preview:$,size:ue(T),installed:!1,settings:!1,pack:{id:o.pack,name:l(o.id)}})}let w=o=>o.name?.[d]??o.name?.zh??o.id,p=new Map;for(let o of u)p.set(w(o),(p.get(w(o))??0)+1);for(let o of u)p.get(w(o))>1&&(o.of=o.pack.name?.[d]??o.pack.id);let k=ye(a),b=o=>k.includes(o.pack.id),y=o=>b(o)?k.indexOf(o.pack.id):k.length;return u.sort((o,$)=>b(o)===b($)?w(o).localeCompare(w($),"zh-CN")||y(o)-y($)||(o.id<$.id?-1:1):b(o)?-1:1)}async function st(d,t){return d!==Ke?O(409,"home"):he(d,e)?(t?.cards===!0?await Ye(e):await bt(e),[200,{ok:!0}]):O(404,"missing")}function at(d,t,i,c){if((c==="cards"||c==="hint")&&d.method==="POST")return n.respond(async l=>{let u=await n.check(l);return u.error?u.error:c==="hint"?st(i,u.body):we(i,u.body)})(d,t);if(c==="library"&&d.method==="GET"){let l=d.headers.host??"",u=d.socket.localPort;if(l!==`127.0.0.1:${u}`&&l!==`localhost:${u}`)return re(t,403,{ok:!1,reason:"host"});if(!he(i,e))return re(t,404,{ok:!1,reason:"missing"});let w=new URL(d.url??"/","http://localhost").searchParams.get("language")==="en"?"en":"zh";return re(t,200,{ok:!0,blocks:ke(w)})}let m=["cards","library","hint"].includes(c);return re(t,m?405:404,{ok:!1,reason:m?"method":"unknown"})}return{handle:at,apply:we,library:ke}}import{readFileSync as Nt}from"node:fs";import{HOME as D,HOME_TITLE as vt,createPage as _t,markHomeMade as qe,pageExists as et,pageFiles as tt,pageSlugRefused as Lt,pagesSettings as zt}from"../browser/shared/pages.mjs";import{layoutOf as rt,markerOf as Mt}from"../browser/shared/workspace.mjs";var Pt="GALLERY_NO_DEFAULT_HOME",Rt=(e=process.env)=>!["","0","false",void 0].includes(e[Pt]);async function wr(e,{shipped:n=void 0,stateDirectory:r=rt(e).state,env:f=process.env}={}){if(Rt(f))return{did:"off"};let s={ours:!1};try{s=Mt(Nt(rt(e).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread"};if(zt(e).homeMade)return{did:"done"};let a="mark";try{if(et(D,e))return await qe(e),{did:"kept"};a="page";let h=await Lt(D,e);if(h)return{did:"taken",why:h};await _t(D,vt,{root:e}),a="cards";let g=Ze({root:e,edits:null,stateDirectory:r,catalog:()=>Oe(e),shipped:n}),[,x]=await g.apply(D,{op:"restore-defaults"},{by:"gallery"});return a="mark",await qe(e),{did:"made",file:tt(D,e).html,cards:(x.added??[]).map(({card:S})=>S),skipped:x.skipped??[]}}catch(h){return{did:"failed",stage:a,file:et(D,e)?tt(D,e).html:null,why:h?.message??String(h)}}}function kr({stage:e,file:n,why:r}){return e==="mark"?`The default home page ${n} is there, but gallery.json could not say it was made (${r}); a later start tries again.`:e==="cards"?`The default home page ${n} was made without its cards (${r}): \u6062\u590D\u9ED8\u8BA4\u5361\u7247 in its menu in the sidebar puts them on.`:`The default home page was not made (${r}); a later start tries again.`}export{q as a,j as b,W as c,Te as d,Gt as e,dr as f,lr as g,Ze as h,Rt as i,wr as j,kr 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 L from"node:fs";import{pipeline as F}from"node:stream/promises";import z from"node:zlib";import{refusal as B,said as k}from"../browser/shared/i18n/index.mjs";var T=67324752,O=33639248,A=101010256,P=101075792,W=117853008,I=4294967295,D=2048;function v(t=new Date){let o=t.getHours()<<11|t.getMinutes()<<5|Math.floor(t.getSeconds()/2),n=Math.max(1980,t.getFullYear())-1980<<9|t.getMonth()+1<<5|t.getDate();return[o,n]}function K(t){let[o,n]=v(),c=[],d=[],r=0;for(let a of t){let u=Buffer.isBuffer(a.data)?a.data:Buffer.from(a.data??"","utf8"),e=Buffer.from(a.name,"utf8"),w=u.length>64?z.deflateRawSync(u):null,h=w&&w.length<u.length?w:u,m=h===u?0:8,g=z.crc32(u);if(u.length>=I||r>=I)throw new Error("\u538B\u7F29\u5305\u592A\u5927\uFF08\u8D85\u8FC7 4GB\uFF09");let l=Buffer.alloc(30);l.writeUInt32LE(T,0),l.writeUInt16LE(20,4),l.writeUInt16LE(D,6),l.writeUInt16LE(m,8),l.writeUInt16LE(o,10),l.writeUInt16LE(n,12),l.writeUInt32LE(g,14),l.writeUInt32LE(h.length,18),l.writeUInt32LE(u.length,22),l.writeUInt16LE(e.length,26),l.writeUInt16LE(0,28);let s=Buffer.alloc(46);s.writeUInt32LE(O,0),s.writeUInt16LE(20,4),s.writeUInt16LE(20,6),s.writeUInt16LE(D,8),s.writeUInt16LE(m,10),s.writeUInt16LE(o,12),s.writeUInt16LE(n,14),s.writeUInt32LE(g,16),s.writeUInt32LE(h.length,20),s.writeUInt32LE(u.length,24),s.writeUInt16LE(e.length,28),s.writeUInt32LE(r,42),c.push(l,e,h),d.push(s,e),r+=l.length+e.length+h.length}if(t.length>=65535)throw new Error("\u538B\u7F29\u5305\u91CC\u7684\u6587\u4EF6\u592A\u591A");let i=Buffer.concat(d),f=Buffer.alloc(22);return f.writeUInt32LE(A,0),f.writeUInt16LE(t.length,8),f.writeUInt16LE(t.length,10),f.writeUInt32LE(i.length,12),f.writeUInt32LE(r,16),Buffer.concat([...c,i,f])}var G=new TextDecoder("utf-8",{fatal:!0}),H=new TextDecoder("gbk");function X(t,o){if(o&D)return t.toString("utf8");try{return G.decode(t)}catch{return H.decode(t)}}var Q=t=>t.length>=4&&t.readUInt32LE(0)===T,U=()=>new Error("ZIP \u6587\u4EF6\u5DF2\u635F\u574F"),E=(t,o)=>Number(t.readBigUInt64LE(o));function C(t,o){let n=Math.min(o,65557),c=t(o-n,n),d=-1;for(let e=c.length-22;e>=0;e-=1)if(c.readUInt32LE(e)===A){d=e;break}if(d<0)throw new Error("\u4E0D\u662F\u6709\u6548\u7684 ZIP \u6587\u4EF6");let r=c.readUInt16LE(d+10),i=c.readUInt32LE(d+12),f=c.readUInt32LE(d+16);if(r===65535||i===I||f===I){let e=t(o-n+d-20,20);if(e.readUInt32LE(0)!==W)throw U();let w=t(E(e,8),56);if(w.readUInt32LE(0)!==P)throw U();r=E(w,32),i=E(w,40),f=E(w,48)}let a=t(f,i),u=[];for(let e=0,w=0;w<r;w+=1){if(a.readUInt32LE(e)!==O)throw U();let h=a.readUInt16LE(e+8),m=a.readUInt16LE(e+10),g=a.readUInt32LE(e+20),l=a.readUInt32LE(e+24),s=a.readUInt16LE(e+28),Z=a.readUInt16LE(e+30),N=a.readUInt16LE(e+32),R=a.readUInt32LE(e+42),b=X(a.subarray(e+46,e+46+s),h),p=a.subarray(e+46+s,e+46+s+Z);for(let x=0;x+4<=p.length;x+=4+p.readUInt16LE(x+2)){if(p.readUInt16LE(x)!==1)continue;let S=x+4;l===I&&(l=E(p,S),S+=8),g===I&&(g=E(p,S),S+=8),R===I&&(R=E(p,S))}if(e+=46+s+Z+N,!b.endsWith("/")){if(h&1)throw B(k("{0} \u5DF2\u52A0\u5BC6",b));if(m!==0&&m!==8)throw B(k("{0}\uFF1A\u4E0D\u652F\u6301\u7684\u538B\u7F29\u65B9\u5F0F",b));u.push({name:b,method:m,packedSize:g,size:l,local:R})}}return u}function M(t,o){let n=t(o.local,30);if(n.readUInt32LE(0)!==T)throw U();return o.local+30+n.readUInt16LE(26)+n.readUInt16LE(28)}function V(t){let o=(n,c)=>{if(n<0||n+c>t.length)throw U();return t.subarray(n,n+c)};return C(o,t.length).map(n=>{let c=o(M(o,n),n.packedSize),d=n.method===0?Buffer.from(c):z.inflateRawSync(c);if(d.length!==n.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",n.name));return{name:n.name,data:d}})}function _(t){let o=L.openSync(t,"r"),n=L.fstatSync(o).size,c=(r,i)=>{if(r<0||r+i>n)throw U();let f=Buffer.alloc(i);for(let a=0;a<i;){let u=L.readSync(o,f,a,i-a,r+a);if(u===0)throw U();a+=u}return f},d;try{d=C(c,n)}catch(r){throw L.closeSync(o),r}return{entries:d,read(r){let i=c(M(c,r),r.packedSize),f=r.method===0?i:z.inflateRawSync(i);if(f.length!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name));return f},async extract(r,i){let f=M(c,r);if(r.packedSize===0)await L.promises.writeFile(i,"");else{let a=L.createReadStream(null,{fd:o,start:f,end:f+r.packedSize-1,autoClose:!1});await F(...r.method===0?[a]:[a,z.createInflateRaw()],L.createWriteStream(i))}if((await L.promises.stat(i)).size!==r.size)throw B(k("{0}\uFF1A\u5927\u5C0F\u4E0D\u7B26",r.name))},close:()=>L.closeSync(o)}}export{K as a,Q as b,V as c,_ as d};
@@ -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 Kt,b as Ut}from"./chunk-PZDLJJTJ.mjs";import{a as Bt}from"./chunk-UMHUSOPJ.mjs";import{randomBytes as At}from"node:crypto";import y from"node:fs/promises";import m from"node:path";import{writeAtomic as J}from"../browser/shared/files.mjs";import{sendJson as H}from"../browser/shared/http.mjs";import{said as B,saying as Pt}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as _e}from"../browser/shared/paths.mjs";import{moveDocument as Te,outlineAndFile as Ce,placeIn as wt,readOutline as Fe,validOutline as te,withOutlineLock as Je,writeOutline as Ge,writtenAs as Ye}from"../browser/shared/outline.mjs";import{DOCS as mt,isForeign as ee,isTop as pt,topOf as kt}from"../browser/shared/outline-shape.mjs";import{addDraft as ne,addWorkspace as We,draftEntry as Me,draftFacts as re,draftOf as Lt,findDraft as He,foreignMarker as Ve,projectChoices as Be,registeredIds as oe,workspaceNames as Ke,workspaceOf as X}from"../browser/shared/drafts.mjs";import{forgetSnapshot as ht,shownWorkspaces as Ue}from"../browser/shared/workspace-columns.mjs";import{nameStops as ze}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as De,workspaceId as gt,workspaceKey as ie}from"../browser/shared/workspace-registry.mjs";import{spawn as Xt}from"node:child_process";import Se from"node:os";import Et from"node:path";import{NO_DEFAULT_TREE as ve}from"../browser/shared/drafts.mjs";import{said as zt}from"../browser/shared/i18n/index.mjs";import{packageRoot as be}from"../browser/shared/paths.mjs";import{answerOf as Dt,compareVersions as xe,galleryVersion as Ee,readAnnouncement as xt}from"../browser/shared/preview-server.mjs";import{isWorkspace as Ae,readRegistry as Pe,workspaceId as Le,workspaceKey as dt}from"../browser/shared/workspace-registry.mjs";var Qt={rename:["slug","title"],create:["title","description","language"]},Ie=9e4,Ne=f=>!["","0",void 0].includes(f);function Re(f,{platform:b=process.platform,env:l=process.env}={}){return Ne(l.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:b==="win32"?{command:Et.join(l.SystemRoot||l.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${f}"`],verbatim:!0}:b==="darwin"?{command:"open",args:["-R",f]}:!l.DISPLAY&&!l.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[Et.dirname(f)]}}function Zt(f,b){let l=Re(f,b);return l.skip?Promise.resolve({opened:!1,why:l.skip}):new Promise(L=>{let R;try{R=Xt(l.command,l.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!l.verbatim})}catch(P){return L({opened:!1,why:P.code??P.message})}R.once("error",P=>L({opened:!1,why:P.code??P.message})),R.once("spawn",()=>{R.unref(),L({opened:!0})})})}function $e(f){let b=/^http:\/\/127\.0\.0\.1:(\d{1,5})$/.exec(String(f??"")),l=b?Number(b[1]):0;return l>0&&l<65536?l:null}function qt({root:f,changed:b=()=>{},log:l=()=>{},gallery:L=Et.join(be,"bin","gallery.mjs")}){let R=dt(f),P=new Map;function yt(p){let d={...process.env,[ve]:"1",GALLERY_NO_UPDATE_CHECK:"1"};return delete d.GALLERY_WORKSPACE,delete d.GALLERY_SERVER_KIND,d.GALLERY_VITE_CACHE_DIR&&(d.GALLERY_VITE_CACHE_DIR=`${d.GALLERY_VITE_CACHE_DIR}-${Le(p)}`),new Promise(v=>{let E=[],A;try{A=Xt(process.execPath,[L,"--workspace",p,"open","--no-browser"],{cwd:Se.homedir(),env:d,stdio:["ignore","pipe","pipe"],windowsHide:!0})}catch(j){return v({ok:!1,message:j.message})}A.stdout.on("data",j=>E.push(String(j))),A.stderr.on("data",j=>E.push(String(j)));let O=setTimeout(()=>A.kill(),Ie);A.once("error",j=>{clearTimeout(O),v({ok:!1,message:j.message})}),A.once("exit",j=>{clearTimeout(O);let $=E.join("").trim().split(/\r?\n/).filter(Boolean);v(j===0?{ok:!0}:{ok:!1,message:$.slice(-3).join(" ")||`gallery open ended with ${j}`})})})}async function lt(p){let d=await xt({reportsDirectory:p});return!d||await Dt(d,p,5e3)!=="yes"||d.kind!=="dev"&&xe(d.version,Ee)<0?null:{port:d.port,token:d.token,pid:d.pid}}async function G(p,{start:d=!0}={}){if(dt(p)===R)return{refused:"self",message:"\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A"};if(!Ae(p))return{refused:"workspace",message:zt("\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A{0} \u4E0D\u5728\u4E86",p)};let v=await lt(p);if(v||!d)return v??{refused:"start",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u5728\u8FD0\u884C"};let E=dt(p);P.has(E)||(l(`starting the server of ${p}`),P.set(E,yt(p).finally(()=>P.delete(E))));let A=await P.get(E);return await lt(p)??{refused:"start",message:A.ok?"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54":zt("\u6CA1\u80FD\u542F\u52A8\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\uFF1A{0}",A.message)}}async function Ot(p,d,v){if(!Object.hasOwn(Qt,d))return[404,{ok:!1,reason:"unknown",message:"\u8FD9\u4E2A\u547D\u4EE4\u4E0D\u80FD\u8F6C\u7ED9\u522B\u7684\u5DE5\u4F5C\u533A"}];let E=await G(p);if(E.refused)return[409,{ok:!1,reason:E.refused,message:E.message}];let A=Object.fromEntries(Qt[d].filter(j=>v?.[j]!==void 0).map(j=>[j,v[j]])),O=`127.0.0.1:${E.port}`;try{let j=await fetch(`http://${O}/__gallery/workspace/${d}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${O}`,"X-Gallery-Token":E.token},body:JSON.stringify(A),signal:AbortSignal.timeout(3e4)}),$=await j.json().catch(()=>null);return $&&typeof $.ok=="boolean"?[j.status,$]:[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C"}]}catch{return[502,{ok:!1,reason:"answer",message:"\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u56DE\u7B54"}]}}let S=new Map;async function W(p){let d=$e(p);if(d===null)return!1;let v=S.get(d);if(v&&Date.now()-v.at<6e4)return v.answer;let E=(async()=>{for(let{root:A}of Pe().workspaces){let O=await xt({reportsDirectory:A});if(O?.port===d&&await Dt(O,A,3e3)==="yes")return!0}return!1})();return S.set(d,{at:Date.now(),answer:E}),E}let q=new Map,C=new Map,K=new Set,c=!1;async function et(p,d,v){let E=new AbortController,A={controller:E,port:v.port};C.set(p,A);try{let O=await fetch(`http://127.0.0.1:${v.port}/__gallery/events?workspace=own`,{signal:E.signal});if(!O.ok||!O.body)return;K.has(p)&&b(d),K.add(p);let j=new TextDecoder,$="";for await(let jt of O.body){$+=j.decode(jt,{stream:!0});for(let I=$.indexOf(`
3
-
4
- `);I>=0;I=$.indexOf(`
5
-
6
- `)){let St=$.slice(0,I);$=$.slice(I+2),/^data: workspace /m.test(St)&&b(d)}}}catch{}finally{C.get(p)===A&&C.delete(p)}}async function U(){for(let[p,d]of C)q.has(p)||d.controller.abort();for(let[p,d]of q){if(c||C.has(p)||dt(d)===R)continue;let v=await xt({reportsDirectory:d});v&&!C.has(p)&&!c&&et(p,d,v)}}let F=Promise.resolve(),x=setInterval(()=>{F=F.then(U).catch(()=>{})},3e3);x.unref();function Y(p){q.clear();for(let[d,v]of p)v&&q.set(d,v);F=F.then(U).catch(()=>{})}function nt(){c=!0,clearInterval(x);for(let{controller:p}of C.values())p.abort();C.clear()}return{serverOf:G,forward:Ot,shellVouched:W,follow:Y,close:nt,get following(){return[...C.keys()]}}}import{LINK_FILE as It,linkStem as Qe,linkValue as at,ownAddress as Nt,readLinkText as Xe}from"../browser/shared/web-links.mjs";import{sameDirectory as Z}from"../browser/shared/preview-server.mjs";import{listReportSlugs as Ze,slugPattern as _}from"../browser/shared/reports.mjs";import{COMPONENTS_FOLDER as qe,DOCUMENT_FOLDERS as tn,PAGE_SLUG as en,SHARED_FOLDERS as Rt,defaultWorkspace as nn,documentDirectory as rn,documentFiles as st,ensureWorkspace as on,idHolder as an,isDocSlug as sn,layoutOf as ae,listTrash as cn,newDocSlug as $t,packageFolders as ln,pageSlug as un,readLink as _t,slugTaken as fn,trashIdPattern as se}from"../browser/shared/workspace.mjs";import{HOME as dn,listPages as wn,pageFiles as ct,readPageMeta as ce,renamePage as mn}from"../browser/shared/pages.mjs";import{listExtensions as pn}from"../browser/shared/extensions.mjs";import{effectiveLook as Tt,ownLookFor as kn,ownLookOf as hn,sameLook as gn,withLookField as le}from"../browser/shared/document-look.mjs";import{workspaceLook as Ct,writeWorkspaceLook as yn}from"../browser/shared/workspace-look.mjs";import{findIn as On,tidyQuery as jn}from"../browser/shared/search.mjs";var Sn=([f,b,l,...L])=>L.length?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",f,b,l,L.length+3):l!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",f,b,l):b!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",f,b):B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",f),ue=f=>f==="en"?"en":null,vn=32*1024*1024;async function V(f,b){for(let l=0;;l++)try{return await y.rename(f,b)}catch(L){if(!["EPERM","EBUSY","EACCES"].includes(L.code))throw L;if(l>=5)break;await new Promise(R=>setTimeout(R,60*(l+1)))}await y.cp(f,b,{recursive:!0,errorOnExist:!0,force:!1}),await y.rm(f,{recursive:!0,force:!0,maxRetries:5})}var bn=f=>m.resolve(f);function ar({edits:f,reports:b,reportsDirectory:l=_e,server:L={kind:"dev",version:null,stop:null},components:R=null,changed:P=()=>{},relayed:yt=P,index:lt=null,web:G=null,elsewhere:Ot=null}){let{trash:S}=ae(l),W=Ot??qt({root:l,changed:t=>{t&&ht(t),yt()}}),q=null,C=()=>q??=ze(),K=lt??Ut({root:l,read:Kt(f),draw:(t,e)=>b.words(t,e)}),c=(t,e,n)=>[t,{ok:!1,reason:e,...Pt(n)}],et=t=>y.readFile(t,"utf8").then(JSON.parse).catch(()=>null),U=t=>rn(t,l),F=t=>st(U(t)),x=t=>m.join(l,t),Y=t=>tt(st(x(t)).html),nt=t=>Promise.resolve(f.forgetChanges?.(t)).catch(()=>{}),p=async t=>{let e=await y.readdir(x(t),{withFileTypes:!0});if(!Rt.includes(t))return e.map(({name:r})=>r);let n=t===qe?new Set(ln(l).map(({id:r})=>r.split("/")[0])):new Set;return e.filter(r=>r.isFile()||tn.includes(r.name)&&!n.has(r.name)).map(({name:r})=>r)},d=async(t,e,n)=>{await y.mkdir(n,{recursive:!0});let r=[];try{for(let o of t)await V(m.join(e,o),m.join(n,o)),r.push(o)}catch(o){for(let i of r)await V(m.join(n,i),m.join(e,i));throw o}},v=async(t,e)=>{if(!Rt.includes(t))return V(x(t),e);await d(await p(t),x(t),e),await y.rmdir(x(t)).catch(()=>{})},E=async(t,e)=>Rt.includes(t)&&!await Y(t)&&(await Promise.all((await y.readdir(e)).map(n=>tt(m.join(x(t),n))))).every(n=>!n),A=async t=>await et(st(t).json)??{},O=async t=>{let{title:e=t,description:n="",type:r,instructions:o,icon:i,look:a}=await A(U(t)),s=o===!0?{}:Tt(a,Ct(l));return{slug:t,title:e,description:n,...r?{type:r}:{},...typeof i=="string"&&i?{icon:i}:{},...o===!0?{instructions:!0}:{},...Object.keys(s).length?{look:s}:{}}},j=async t=>{let e=await _t(x(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},$=async(t,e,n=[])=>{let r=Lt(t),o=r&&n.find(({id:M})=>M===r.ws),i=o?.facts.get(r.slug);if(i){let M=m.join(o.root,r.slug);return{slug:t,title:i.title,description:i.description,kind:"draft",workspace:r.ws,...i.icon?{icon:i.icon}:{},path:i.path,folder:M,root:o.root}}let{ws:a,title:s,description:u,icon:k,path:g,folder:w,root:h,missing:N}=await re(t,e);return{slug:t,title:s,description:u,kind:"draft",workspace:a,...k?{icon:k}:{},...g?{path:g,folder:w,root:h}:{},...N?{missing:N}:{}}},jt=async(t,e,n,r)=>ee(t)?$(t,n,r):e.includes(t)?await j(t)??{slug:t,title:t,description:"",kind:"link",url:""}:O(t),I=gt(l),St=()=>ie(nn())===ie(l),fe=(t,e)=>{let n=t.shown.find(({isDefault:s})=>s)?.id??(St()?I:null),r=new Set([...t.drafts.map(s=>Lt(s)?.ws),...t.groups.map(({workspace:s})=>s),...t.shown.map(({id:s})=>s)].filter(Boolean)),o=new Set(t.groups.filter(({workspace:s,title:u})=>s&&!u).map(({workspace:s})=>s));t.groups.find(({id:s})=>s===mt)?.title||o.add(I),o.delete(n);let i=Ke(new Set([...r,I]),{ids:new Map([...e,[I,[l]]]),stops:C(),among:o});W.follow(new Map([...i].filter(([s])=>s!==I).map(([s,{root:u}])=>[s,u])));let a=Object.fromEntries([...r].map(s=>[s,{...i.get(s)??{missing:X(s,e).refused??"unknown"},...s===n?{default:!0}:{}}]));return a[I]={...i.get(I),there:!0,self:!0,...I===n?{default:!0}:{}},a},z=()=>un(l),de=async(t,e)=>{let n=await A(U(t));await J(F(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
7
- `)},tt=t=>y.access(t).then(()=>!0,()=>!1),ut=async(t,{own:e=null}={})=>{let n=new Set((await rt()).map(({slug:r})=>r));n.delete(e);for(let r=1;;r++){let o=r===1?t:`${t}-${r}`;if(!fn(o,l)&&!n.has(o))return o}},vt=async t=>{let e=await ut(t.slug,{own:t.slug});return sn(t.slug)?e===t.slug&&!await an(t.slug,l)?e:$t(l):e},Ft=async(t,e)=>{let n=F(t).html,r=await y.readFile(n,"utf8"),o=Bt(r).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);o!==r&&await J(n,o)},T=()=>Fe(l),D=async t=>{await Ge(l,t),P()},Q=t=>Je(l,t);async function ft(t,e="",n=1/0){await Q(async()=>{let r=await T();wt(r,t,e,n),await D(r)})}async function Jt(t,{parent:e="",after:n=null,first:r=!1}={}){await Q(async()=>{let o=await T();for(let a of Object.values(o.children))a.includes(t)&&a.splice(a.indexOf(t),1);let i=typeof n=="string"?Object.keys(o.children).find(a=>o.children[a].includes(n)):void 0;i!==void 0?wt(o,t,i,o.children[i].indexOf(n)+1):wt(o,t,typeof e=="string"?e:"",r===!0?0:1/0),await D(o)})}function we(t,e){let n=new Set(Object.values(t.children).flat()),r={...t.children};for(let{id:o}of e.groups){if(o===mt)continue;let i=a=>{let s=(e.children[a]??[]).filter(u=>!n.has(u));(pt(a)||s.length)&&(r[a]=s),s.forEach(i)};i(kt(o))}return{groups:e.groups,children:r}}function Gt(t){return Q(async()=>{let e=await T();for(let[n,r]of Object.entries(e.children)){let o=r.indexOf(t);if(!(o<0))return r.splice(o,1,...e.children[t]??[]),delete e.children[t],await D(e),{parent:n,index:o}}return{parent:"",index:1/0}})}let me=(t,e)=>K.lines(t,e),Yt=t=>et(m.join(S,t,"entry.json")),rt=()=>cn(l);async function pe(t){if(t===dn)return c(409,"home","\u9996\u9875\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");let e=await ce(t,l);if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${At(3).toString("hex")}`;try{await y.mkdir(m.join(S,n),{recursive:!0}),await V(ct(t,l).folder,m.join(S,n,"page"))}catch(o){throw await y.rm(m.join(S,n),{recursive:!0,force:!0}).catch(()=>{}),o}let r={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await J(m.join(S,n,"entry.json"),`${JSON.stringify(r,null,2)}
8
- `),[200,{ok:!0,entry:r}]}async function ke(t){let e=m.join(S,t.id,"page"),n=await vt(t);if(await y.mkdir(ae(l).customPages,{recursive:!0}),await V(e,ct(n,l).folder),n!==t.slug){let{html:r}=ct(n,l),o=await y.readFile(r,"utf8").catch(()=>null),i=o?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);o!==null&&i!==o&&await J(r,i)}return await y.rm(m.join(S,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await ce(n,l),entry:{...t,slug:n}}]}async function he(t){let e=await _t(x(t));if(!e)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${At(3).toString("hex")}`,r=await T(),{parent:o,index:i}=await Gt(t);try{await y.mkdir(m.join(S,n),{recursive:!0}),await V(x(t),m.join(S,n,"link"))}catch(s){throw await Q(()=>D(r)),await y.rm(m.join(S,n),{recursive:!0,force:!0}).catch(()=>{}),s}let a={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:o,index:Number.isFinite(i)?i:-1};return await J(m.join(S,n,"entry.json"),`${JSON.stringify(a,null,2)}
9
- `),[200,{ok:!0,entry:a}]}async function ge(t){let e=m.join(S,t.id,"link"),n=await vt(t);return await V(e,x(n)),await y.rm(m.join(S,t.id),{recursive:!0,force:!0}),await ft(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await j(n),entry:{...t,slug:n}}]}function ye(t,{parent:e,after:n,first:r}){let o=a=>pt(a)?Object.hasOwn(t.children,a):Object.values(t.children).some(s=>s.includes(a));if(n!=null){let a=Object.keys(t.children).find(s=>t.children[s].includes(n));return a===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==a?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:a,index:t.children[a].indexOf(n)+1}}let i=e??kt(mt);return pt(i)&&t.groups.some(a=>a.extension&&kt(a.id)===i)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:o(i)?{parent:i,index:r?0:(t.children[i]??[]).length}:{refused:[404,"parent",pt(i)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let ot=new Map;function Oe(t){let e=ot.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=G?G.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return ot.size>=500&&ot.delete(ot.keys().next().value),ot.set(t,{at:Date.now(),answer:n}),n}function Wt(t,e){return G?.icon?(async()=>{let n=await G.icon(e).catch(()=>null);if(!n)return null;let r=m.join(x(t),It),o=await y.readFile(r,"utf8").catch(()=>null),i=o===null?null:Xe(o);if(!i||i.url!==e||i.siteIcon===n)return null;let a=at({...i,siteIcon:n});return a.refused||!a.value.siteIcon||!await J(r,`${JSON.stringify(a.value,null,2)}
10
- `,{expect:o})?null:(P(),n)})().catch(()=>null):Promise.resolve(null)}let Mt={info:async()=>[200,{ok:!0,version:1,gallery:L.version,token:f.token,commands:[...Object.keys(it)],server:{pid:process.pid,workspace:m.resolve(l),kind:L.kind}}],async outline(){let{outline:t,others:e}=await Ce(l),n=await z(),r=[...Object.values(t.children).flat(),...n?[n]:[]],o=oe(),i=async w=>[w,await jt(w,t.links,o,e)],[a,s,u,k]=await Promise.all([Promise.all(r.map(i)),wn(l),rt(),pn(l)]),g=k.map(({id:w,title:h,icon:N,entries:M,count:bt,error:Vt})=>({id:w,title:h,...N?{icon:N}:{},entries:M,count:bt,...Vt?{error:Pt(Vt)}:{}}));return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(a),pages:s,trash:u,workspaces:fe(t,o),self:I,extensions:g}]},trash:async()=>[200,{ok:!0,entries:await rt()}],async stats(t){let e=t.get("slug")??"",n=_.test(e)?await K.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async query(t){let e;try{e=JSON.parse(t.get("options")??"{}")}catch{return[400,{ok:!1,reason:"options",message:"options is JSON"}]}return K.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,...R.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!_.test(e))return c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=m.resolve(n?ct(e,l).html:F(e).html);return await tt(r)?[200,{ok:!0,path:r}]:c(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await Be(l,{stops:C()})}],shell:async t=>[200,{ok:!0,shell:await W.shellVouched(t.get("origin"))}],async search(t){let e=jn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:r,links:o}=await T(),i=[],a=w=>(n[w]??[]).forEach(h=>{!o.includes(h)&&!ee(h)&&i.push(h),a(h)});for(let{id:w}of r)a(kt(w));let s=e.toLowerCase(),u=new Map(await Promise.all(i.map(async w=>[w,await O(w)]))),k=JSON.stringify([...u].map(([w,{title:h}])=>[w,h])),g=(await Promise.all(i.map(async w=>{let h=await me(w,k);if(!h)return null;let N=String(u.get(w).title).toLowerCase().includes(s),{count:M,hits:bt}=On(h,e);return N||M?{slug:w,title:N,count:M,hits:bt}:null}))).filter(Boolean);return g.sort((w,h)=>Number(h.title)-Number(w.title)||h.count-w.count),[200,{ok:!0,results:g.slice(0,50)}]}},it={async outline({outline:t,base:e}){return!te(t)||e!==void 0&&!te(e)?c(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):await Q(async()=>{let r=await T();return e!==void 0&&!Ye(e,r)?!1:(await D(t.groups?t:we(t,r)),!0)})?[200,{ok:!0,outline:await T()}]:c(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:e,after:n=null,first:r=!1,workspace:o}){if(typeof o=="string"&&!Z(o,l))return c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let i=u=>typeof u=="string"&&_.test(u);if(!i(t)||e!==void 0&&e!==""&&!i(e)||n!==null&&!i(n)||typeof r!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let a=await z();if(a!==null&&[t,e,n].includes(a))return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let s=await Te(l,t,{parent:e,after:n,first:r});if(s.written&&P(),!s.ok){let[u,k]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"]}[s.reason];return c(u,s.reason,k)}return[200,{ok:!0,...s,outline:await T()}]},async create({title:t,description:e,parent:n="",after:r=null,first:o=!1,language:i}){let a=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",s=await $t(l);return await nt(s),await b.create(s,a,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:ue(i)}),await Jt(s,{parent:n,after:r,first:o}),[200,{ok:!0,report:await O(s)}]},async instructions({title:t,description:e,language:n}){let r=await z();if(r)return[200,{ok:!0,report:await O(r)}];let o=await ut(en),i=(a,s)=>typeof a=="string"&&a.trim()?a.trim().slice(0,200):s;return await b.create(o,i(t,"\u5199\u4F5C\u504F\u597D"),i(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:ue(n),page:!0}),await de(o,"instructions"),[200,{ok:!0,report:await O(o)}]},async components({id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:i,pack:a,enabled:s}){try{return[200,{ok:!0,...await R.write(a!==void 0?{pack:a,enabled:s}:{id:t,hidden:e,shown:n,disabled:r,unlisted:o,net:i})}]}catch(u){return c(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let r=await $t(l);await nt(r);let o=new Set(["",...await p(t)]);await y.cp(x(t),x(r),{recursive:!0,errorOnExist:!0,filter:w=>o.has(m.relative(x(t),w).split(m.sep)[0])}),await Ft(r,t);let{title:i}=await O(t),a=i||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),s=await f.renameReport(r,`${a}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),u=await T(),[k,g]=Object.entries(u.children).find(([,w])=>w.includes(t))??["",null];return await ft(r,k,g?g.indexOf(t)+1:1/0),[200,{ok:!0,report:await O(r),notes:s.notes??[]}]},async look({slug:t,look:e}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await z())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return c(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=F(t).json,r=null;try{r=JSON.parse(await y.readFile(n,"utf8"))}catch{}if(!r||typeof r!="object"||Array.isArray(r))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let o=le(r,kn(e,Ct(l)));return JSON.stringify(o)!==JSON.stringify(r)&&await J(n,`${JSON.stringify(o,null,2)}
11
- `),[200,{ok:!0,report:await O(t)}]},async looks({slug:t}){if(typeof t!="string"||!_.test(t)||!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await z();if(t===e)return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await et(F(t).json);if(!n||typeof n!="object"||Array.isArray(n))return c(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=Ct(l),o=Tt(n.look,r);try{await yn(l,o)}catch(u){return c(409,"workspace",u)}let i=0,a=(await Ze(l)).filter(u=>u!==e).map(u=>({json:F(u).json,self:u===t})),s=(await rt()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:st(m.join(S,u,"report")).json,self:!1}));for(let{json:u,self:k}of[...a,...s])for(let g=0;g<3;g++){let w=await y.readFile(u,"utf8").catch(()=>null),h=null;try{h=JSON.parse(w??"")}catch{}if(!h||typeof h!="object"||Array.isArray(h)||!Object.hasOwn(h,"look")||h.instructions===!0)break;let N=await J(u,`${JSON.stringify(le(h,{}),null,2)}
12
- `,{expect:w}).catch(()=>null);if(N===null)break;if(N){!k&&Object.keys(hn(h.look)).length>0&&!gn(Tt(h.look,r),o)&&i++;break}}return[200,{ok:!0,look:o,replaced:i,report:await O(t)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!_.test(t))return c(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let o;try{o=await mn(t,e,l)}catch{return c(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return o?[200,{ok:!0,page:o}]:c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let r=await f.renameReport(t,e);return r.ok?[200,{ok:!0,report:await O(t),notes:r.notes}]:c({title:400,missing:404}[r.reason]??409,r.reason,r.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!_.test(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return pe(t);if(e==="link")return he(t);if(t===await z())return c(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await Y(t))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await O(t),r=`${Date.now().toString(36)}-${At(3).toString("hex")}`,o=await T(),{parent:i,index:a}=await Gt(t);try{await y.mkdir(m.join(S,r),{recursive:!0}),await v(t,m.join(S,r,"report"))}catch(u){throw await Q(()=>D(o)),await y.rm(m.join(S,r),{recursive:!0,force:!0}).catch(()=>{}),u}let s={id:r,kind:"document",slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(a)?a:-1};return await J(m.join(S,r,"entry.json"),`${JSON.stringify(s,null,2)}
13
- `),[200,{ok:!0,entry:s}]},async restore({id:t}){let e=typeof t=="string"&&se.test(t)?await Yt(t):null;if(!e)return c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return ke(e);if(e.kind==="link")return ge(e);let n=m.join(S,t,"report"),r=await E(e.slug,n),o=r?e.slug:await vt(e);return r?await d(await y.readdir(n),n,x(o)):await V(n,x(o)),o!==e.slug&&await Ft(o,e.slug),await y.rm(m.join(S,t),{recursive:!0,force:!0}),await ft(o,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await O(o),entry:{...e,kind:"document",slug:o}}]},async destroy({id:t}){let e=typeof t=="string"&&se.test(t)?await Yt(t):null;return e?((e.kind??"document")==="document"&&!await Y(e.slug)&&await nt(e.slug),await y.rm(m.join(S,t),{recursive:!0,force:!0}),[200,{ok:!0}]):c(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:r,after:o=null,first:i=!1},{port:a,wait:s=!1}={}){let u=at({url:t,title:e,icon:n});if(u.refused)return c(400,u.refused,u.message);if(Nt(u.value.url,a))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(r!=null&&typeof r!="string"||o!==null&&typeof o!="string"||typeof i!="boolean")return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let k=await Q(async()=>{let w=await T(),h=ye(w,{parent:r,after:o,first:i||r==null&&o===null});if(h.refused)return h;let N=await ut(Qe(u.value.title,u.value.url));return await y.mkdir(x(N),{recursive:!0}),await J(m.join(x(N),It),`${JSON.stringify(u.value,null,2)}
14
- `),wt(w,N,h.parent,h.index),await D(w),{slug:N,parent:h.parent,index:h.index}});if(k.refused)return c(...k.refused);let g=Wt(k.slug,u.value.url);return s&&await g,[200,{ok:!0,link:await j(k.slug),parent:k.parent,index:k.index,outline:await T()}]},async"link-set"({slug:t,url:e,title:n,icon:r},{port:o,wait:i=!1}={}){let a=typeof t=="string"&&_.test(t)?await _t(x(t)):null;if(!a)return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let s=e??a.url,u=at({url:s,title:n??a.title,icon:r===void 0?a.icon??null:r,siteIcon:a.siteIcon??null});if(u.refused)return c(400,u.refused,u.message);let k=u.value.url!==a.url;if(k&&Nt(u.value.url,o))return c(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(k&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(a)&&await J(m.join(x(t),It),`${JSON.stringify(u.value,null,2)}
15
- `),k){let g=Wt(t,u.value.url);i&&await g}return[200,{ok:!0,link:await j(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let r=await He(t),o=typeof n=="string"?n:null;if(r.kind==="missing")return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(r.kind==="plain")return c(409,"plain","\u8FD9\u4E0D\u662F Gallery \u7684\u5E95\u7A3F\u6216\u5DE5\u4F5C\u533A\uFF0C\u53EF\u4EE5\u7528\u300C\u5BFC\u5165\u300D\u628A\u6587\u4EF6\u590D\u5236\u8FDB\u6765");if(r.kind==="nested")return c(409,"nested","\u8FD9\u4EFD\u5E95\u7A3F\u4E0D\u5728\u5B83\u5DE5\u4F5C\u533A\u7684\u7B2C\u4E00\u5C42\uFF08\u5728\u56DE\u6536\u533A\u91CC\uFF0C\u6216\u662F\u5199\u4F5C\u504F\u597D\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");if(r.kind==="name")return c(409,"name","\u8FD9\u4E2A\u6587\u4EF6\u5939\u7684\u540D\u5B57\u4E0D\u662F Gallery \u6587\u6863\u7684\u5199\u6CD5\uFF08\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");let i=r.kind==="workspace"?r.root:r.kind==="folder"?null:r.root,a=!i||!Ue(l).some(g=>Z(g.root,i));if(!i){let g=r.kind==="folder"?r.folder:r.parent;if(Ve(g))return c(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:g,...Pt(B("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",g))}];if(!(await on(g)).ours)return c(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));i=g}let s=r.kind==="workspace"||r.kind==="folder";if(Z(i,l))return[200,{ok:!0,kind:s?"workspace":"draft",own:!0,existing:!0,...s?{column:mt}:{entry:r.slug}}];let u=await De(i,{force:!0}).catch(()=>"failed"),k=X(gt(i));return k.refused==="ambiguous"?c(409,"ambiguous",B("\u672C\u673A\u767B\u8BB0\u7684 {0} \u4E2A\u5DE5\u4F5C\u533A\u7F16\u53F7\u76F8\u540C\uFF08{1}\uFF09\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A",k.roots.length,gt(i))):!k.root||!Z(k.root,i)?u==="temporary"?c(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):c(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(ht(i),s?[200,{ok:!0,kind:"workspace",...await We(l,i,{changed:P,after:o})}]:[200,{ok:!0,kind:"draft",...await ne(l,i,r.slug,{changed:P,pick:!0,after:o,fresh:a})}])},async"draft-join"({root:t,slug:e}){if(typeof t!="string"||typeof e!="string"||!_.test(e))return c(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");if(Z(t,l))return c(409,"own","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let n=X(gt(t));return!n.root||!Z(n.root,t)?c(409,"registry","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):await tt(st(m.join(t,e)).html)?(ht(t),[200,{ok:!0,...await ne(l,t,e,{changed:P})}]):c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async export({slug:t}){if(typeof t!="string"||!_.test(t)||!await tt(U(t)))return c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:r}=await b.export(t);return r?c(r.reason==="missing"?404:409,r.reason,r.message):e.length?c(422,"check",Sn(e)):[200,{ok:!0,path:bn(n)}]}},Ht={async frameable({url:t},{port:e}){let n=typeof t=="string"?at({url:t,title:"-"}):{refused:"url"};return n.refused?c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Nt(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await Oe(n.value.url)}]},async elsewhere({ws:t}){let e=typeof t=="string"?X(t):{refused:"unknown"};if(e.refused)return c(409,e.refused,e.refused==="ambiguous"?"\u672C\u673A\u767B\u8BB0\u7684\u5DE5\u4F5C\u533A\u91CC\u6709\u4E24\u4E2A\u7528\u7684\u662F\u540C\u4E00\u4E2A\u7F16\u53F7\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A":"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let n=await W.serverOf(e.root);return n.refused?c(409,n.refused,n.message):[200,{ok:!0,origin:`http://127.0.0.1:${n.port}`}]},async"draft-command"({ws:t,name:e,...n}){let r=typeof t=="string"?X(t):{refused:"unknown"};return r.refused?c(409,r.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC"):W.forward(r.root,e,n)},async"draft-create"({ws:t,title:e,description:n,language:r,parent:o="",after:i=null,first:a=!1}){if(t===I)return c(409,"self","\u8FD9\u662F\u5F53\u524D\u7684\u5DE5\u4F5C\u533A");let s=typeof t=="string"?X(t):{refused:"unknown"};if(s.refused)return c(409,s.refused,"\u627E\u4E0D\u5230\u5B83\u6240\u5728\u7684\u5DE5\u4F5C\u533A\uFF1A\u5B83\u4E0D\u5728\u672C\u673A\u7684\u767B\u8BB0\u8868\u91CC");let[u,k]=await W.forward(s.root,"create",{title:e,description:n,language:r});if(!k?.ok)return[u,k];let g=k.report?.slug;if(typeof g!="string"||!_.test(g))return c(502,"answer","\u5B83\u6240\u5728\u5DE5\u4F5C\u533A\u7684\u670D\u52A1\u6CA1\u6709\u7ED9\u51FA\u7ED3\u679C");let w=Me(t,g);return ht(s.root),await Jt(w,{parent:o,after:i,first:a}),[200,{ok:!0,entry:w,report:{...k.report,slug:w,kind:"draft",workspace:t}}]},async reveal({entry:t,ws:e,page:n}){let r=oe(),o=null;return typeof n=="string"?o=_.test(n)?ct(n,l).folder:null:typeof t=="string"&&Lt(t)?o=(await re(t,r)).folder:e===I?o=m.resolve(l):typeof e=="string"&&(o=X(e,r).root??null),!o||!await tt(o)?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:o,...await Zt(o)}]},async title({url:t}){let e=typeof t=="string"?at({url:t,title:"-"}):{refused:"url"};if(e.refused)return c(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=G?await G.title(e.value.url).catch(()=>""):"";return[200,{ok:!0,title:typeof n=="string"?n.slice(0,200):""}]}};function je(t,e,n){if(t.method==="GET"&&Object.hasOwn(Mt,n)){let o=t.headers.host??"",i=t.socket.localPort;return o!==`127.0.0.1:${i}`&&o!==`localhost:${i}`?H(e,403,{ok:!1,reason:"host"}):Mt[n](new URL(t.url??"/","http://localhost").searchParams).then(([a,s])=>H(e,a,s),a=>H(e,...c(500,"read",a)))}if(t.method==="POST"&&n==="stop")return f.respond(async o=>{let i=await f.check(o);return i.error?i.error:L.kind!=="cli"||typeof L.stop!="function"?c(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(e.once("finish",()=>L.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return f.respond(async o=>{let i=await f.check(o,vn);if(i.error)return i.error;if(!R?.install)return c(404,"unknown");try{return[200,{ok:!0,...R.install(i.body??{})}]}catch(a){if(!a.code)throw a;return c(409,a.code,a)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let o=await f.check(t);if(o.error)return o.error;let{slug:i,items:a}=o.body??{};return typeof i!="string"||!_.test(i)||!Array.isArray(a)?[400,{ok:!1,reason:"body"}]:!await Y(i)||i===await z()?c(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):f.setTodos(i,a)})().then(([o,i])=>H(e,o,i),o=>H(e,...c(500,"write",o.message)));let r={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(it,n)?f.respond(async o=>{let i=await f.check(o);if(i.error)return i.error;let a=i.body&&typeof i.body=="object"?i.body:{};return typeof a.workspace=="string"&&!Z(a.workspace,l)?c(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):it[n](a,r)})(t,e):t.method==="POST"&&Object.hasOwn(Ht,n)?(async()=>{let o=await f.check(t);return o.error?o.error:Ht[n](o.body&&typeof o.body=="object"?o.body:{},r)})().then(([o,i])=>H(e,o,i),o=>H(e,...c(500,"read",o))):H(e,404,{ok:!1,reason:"unknown"})}return{handle:je,outline:T,trashEntries:rt,place:ft,freeSlug:ut,index:K,run:(t,e,n={})=>Object.hasOwn(it,t)?it[t](e??{},{wait:!0,...n}):Promise.resolve(c(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4")),close:()=>W.close()}}export{ar as a};
@@ -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{a as ue,b as ge,k as we,v as $e,w as be}from"./chunk-QOUEFUCH.mjs";import{M as ye}from"./chunk-VTKNEYT3.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-BPL64HGA.mjs";import{c as P,f as ke}from"./chunk-UGWYKHBL.mjs";import"./chunk-OUUP3WKT.mjs";import{a as R}from"./chunk-JEUK3ZO7.mjs";import"./chunk-PUOQ65NC.mjs";import"./chunk-ZUNVAXLH.mjs";import"./chunk-6VTU6KEO.mjs";import"./chunk-OJKMINIU.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-UKSHDZZ6.mjs";import"./chunk-6EZ7FNIK.mjs";import"./chunk-35NQ4PLQ.mjs";import"./chunk-V6RIYQZZ.mjs";import{b as de,h as _}from"./chunk-SXHBYZST.mjs";import"./chunk-N7AZZLGT.mjs";import{n as ie}from"./chunk-D4EURAX4.mjs";import"./chunk-4OZWXZE5.mjs";import{a as pe,j as fe,s as me}from"./chunk-HMYTM3GT.mjs";import{d as re,e as le,i as I,j as ce,k as he}from"./chunk-OW5NWPOJ.mjs";import"./chunk-ZTHICSSF.mjs";import{a as w}from"./chunk-SX4LJYT6.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import{a as U,c as S}from"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-N76HWBA3.mjs";import"./chunk-FJYN7RTH.mjs";import{c as ae}from"./chunk-UBBRTJ2R.mjs";import{a as F,f as te,h as se,j as z,r as ne,s as oe}from"./chunk-FWNRPMCJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{isUtf8 as ze}from"node:buffer";import W from"node:fs";import j from"node:path";import{instanceSlots as Ue,instancesOf as X,isInstance as Z,partOf as V}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as $,refusedInCopy as _e}from"../browser/shared/components/installed.mjs";import{attr as b,elementsOf as Q,walk as T}from"../browser/shared/html-tree.mjs";import{blankedCss as B}from"../browser/shared/css-references.mjs";import{ATTRIBUTE as G,SLOT as Le}from"../browser/shared/components/installed.mjs";var Te=new Set(["media","supports","container","layer","starting-style"]);function K(t,e){let s=0,o="";for(let n=0;n<t.length;n++){let i=t[n];i==="\\"?n++:o?o=i===o?"":o:i==='"'||i==="'"?o=i:i===")"||i==="]"?s--:(s===0&&e(i,n),(i==="("||i==="[")&&s++)}}function Ce(t){let e=B(t),s=B(t,{strings:!0}),o={children:[]},n=[o],i=0,r=0;for(let a=0;a<e.length;a++){let l=e[a];if(l==="\\")a++;else if(l==="("||l==="[")r++;else if(l===")"||l==="]")r=Math.max(0,r-1);else{if(r>0)continue;if(l==="{"){let c={prelude:s.slice(i,a),start:i,children:[]};n.at(-1).children.push(c),n.push(c),i=a+1}else l==="}"?(n.length>1&&n.pop(),i=a+1):l===";"&&(i=a+1)}}return o.children}function M(t){let e=[],s=0;return K(t,(o,n)=>{o===","&&(e.push({text:t.slice(s,n),start:s}),s=n+1)}),e.push({text:t.slice(s),start:s}),e.filter(({text:o})=>o.trim())}function q(t){let e=[],s=t.trim(),o="",n=0,i=0,r=a=>{(i||a)>n&&e.push({combinator:o,compound:s.slice(n,i||a)}),i=0};return K(s,(a,l)=>{/\s/.test(a)?l===n?n=l+1:i||=l:">+~".includes(a)?(r(l),o=a,n=l+1):i&&(r(l),o=" ",n=l)}),r(s.length),e}function D(t){let e=[],s=-1,o=0,n="";for(let r=0;r<t.length;r++){let a=t[r];a==="\\"?r++:n?n=a===n?"":n:a==='"'||a==="'"?n=a:a==="("?o++:a===")"?o--:a==="["&&o===0?s=r:a==="]"&&o===0&&s>=0&&(e.push(t.slice(s,r+1)),s=-1)}let i=!1;return K(t,r=>{i||=r==="&"}),{attributes:e,nesting:i,scope:/(?:^|[^\w-]):scope\b/.test(t)}}var Ie=t=>new RegExp(`^\\[\\s*${G}\\s*=\\s*(["'])${t.replace(/[/-]/g,"\\$&")}\\1\\s*i?\\s*\\]$`,"i"),Re=t=>B(t).replace(/\\.|\[[^\]]*\]/g,"").includes("&");function xe(t,e,s,o=!1){let n=q(t),i=({compound:f})=>D(f).attributes.some(h=>e.test(h)),r=({compound:f})=>{let{nesting:h,scope:m}=D(f);return!!s&&(h||m)},a=f=>["+","~"].includes(f?.combinator),l=f=>n.slice(f).some(({combinator:h},m)=>(m+f===0?h||" ":h)===" "),c=n.findLastIndex(f=>i(f)||r(f));if(c<0)return!s||Re(t)?{why:"outside"}:{why:s==="instance"&&a(n[0])?"beside":null,subject:"inside",deep:o||l(0)};let p=i(n[c])||s==="instance";return{why:p&&a(n[c+1])?"beside":null,subject:p&&c===n.length-1?"instance":"inside",deep:!i(n[c])&&o||l(c+1)}}var Se=t=>t.some(({subject:e})=>e==="instance")?"instance":"inside",Pe=new RegExp(`^\\[\\s*${Le}\\s*(?:\\]|=)`,"i"),Fe=t=>M(/\)\s*to\s*\(([^)]*)\)/i.exec(t)?.[1]??"").some(({text:e})=>q(e).length===1&&D(e).attributes.some(s=>Pe.test(s))),Ee=(t,e)=>Ne(t,e).outside;function je(t,e,s){if(s.length===0)return[];let o=`slot${s.length===1?"":"s"} ${s.join(" and ")}`;return Ne(t,e).deep.map(({line:n,words:i})=>({line:n,what:`${i} also reaches the blocks in ${o}, the document's: write each step with > or wrap the rules in @scope ([${G}="${e}"]) to ([${Le}])`}))}function Ne(t,e){let s=Ie(e),o=`[${G}="${e}"]`,n=[],i=[],r=(l,c,p)=>{let f=c.replace(/\s+/g," ").trim();n.push({line:S(t,l),what:p==="beside"?`${f} reaches what stands beside the instance: what it styles has to stand in it`:`${f} reaches outside the instance: start it at ${o}`})},a=(l,c,p=!1,f=!1)=>{for(let h of l){let m=h.prelude.length-h.prelude.trimStart().length,u=h.start+m,y=/^@([\w-]+)\s*/.exec(h.prelude.trim());if(y){let d=y[1].toLowerCase();if(Te.has(d))a(h.children,c,p,f);else if(d==="page")n.push({line:S(t,u),what:"@page reaches the paper of the whole document: an instance has no page of its own"});else if(d==="scope"){let x=/^@scope\s*\(([^)]*)\)/i.exec(h.prelude.trim())?.[1]??"",L=M(x).map(({text:E})=>({...xe(E,s,c),steps:q(E).length}));x&&L.every(({why:E,steps:Ae})=>!E&&Ae===1)?a(h.children,Se(L),!1,f||Fe(h.prelude.trim())):r(u,h.prelude,"outside")}continue}let k=M(h.prelude).map(({text:d,start:x})=>{let L=xe(d,s,c,p),E=h.start+x+d.length-d.trimStart().length;return L.why?r(E,d,L.why):L.deep&&!f&&!p&&i.push({line:S(t,E),words:d.replace(/\s+/g," ").trim()}),L});k.some(({why:d})=>d)||a(h.children,Se(k),k.some(d=>d.deep),f)}};return a(Ce(t),null),{outside:n,deep:i}}var g="template.html",N="example.html",O="component.json",Be=new Set(["localStorage","sessionStorage"]),Me=/^\S+: (?:line \d+ of )?its (?:kit\.js|style\.css) /,De=/(?: (?:names a file that )?is not in the document's folder|: it is (?:no file of|not in) the document's .*)$|^external resources are not portable: .*$/,Ge=": an example stands in no document: write a picture as a data: address, or draw it from style.css with a file the manifest's assets name",Ke=t=>t.replace(De,e=>(e.startsWith("external")?e:"")+Ge),A=(t,e)=>I({folder:t},e);function C(t,e){let s=null;try{s=W.readFileSync(j.join(t,e))}catch{return null}return ze(s)?null:{file:e,what:"it is not UTF-8: save it as UTF-8 (PowerShell's > writes UTF-16; Set-Content -Encoding utf8 does not)"}}function H(t,e){let s=/^line (\d+): | \(line (\d+)\)/.exec(e);return s?{file:t,line:Number(s[1]??s[2]),what:e.replace(s[0],"")}:{file:t,what:e}}function v(t,e){let s=w.parseJsonText(O,t),o=s.statements[0]?.expression,n=null;for(let i of e.split(".")){let r=o?.properties?.find(({name:a})=>a?.text===i);if(!r)break;n=s.getLineAndCharacterOfPosition(r.getStart(s)).line+1,o=r.initializer}return n}function qe(t,{message:e,text:s="",values:o=[]}){let n=/at position (\d+)/.exec(e)?.[1];if(n)return S(t,Number(n));for(let i of[...o.map(String),...s.match(/[a-zA-Z][\w.]*/g)??[]]){let r=v(t,i);if(r)return r}return null}var He=t=>_(t).map(e=>/^line (\d+): <([^>]+)>: ([\s\S]*)$/.exec(e)).filter(Boolean).map(([,e,s,o])=>({line:Number(e),tag:s,why:o}));function Je(t,{file:e,tree:s,html:o}){let n=[],i=He(o),r=Object.entries(t.parts).filter(([,c])=>c.edit==="text"),a=Object.entries(t.parts).filter(([,c])=>c.edit==="data"),l=(c,p)=>{let f=!1;return T(c,h=>{f||=h===p}),f};for(let c of X(s,t))for(let[p,f]of r)for(let h of V(c,f.at)){let m=h.sourceCodeLocation?.startLine,u=Q(h).find(d=>ae.has(d.tagName)),y=i.find(d=>d.line===m&&d.tag===h.tagName),k=a.find(([,d])=>V(c,d.at).some(x=>x===h||l(x,h)||l(h,x)))?.[0];k?n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and stands in the part ${k}, edited as data, or around it, which is the component's: the editor leaves it read-only: name elements apart`}):u?n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text and holds a block, its <${u.tagName}> at line ${u.sourceCodeLocation?.startLine}: a text part holds words and marks alone, and the editor would leave this one read-only: write its \`at\` as what holds the words (${f.at} > ${u.tagName}), or give each block a part of its own`}):y&&n.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and the editor would leave it read-only for what it holds: ${y.why}. A text part holds words and marks alone`})}return n}var Oe="(?:(?:[zcs]h|[bpmfdtnlgkhjqxrzcsyw])?(?:[iuv]?(?:a(?:i|o|ng?)?|e(?:i|r|ng?)?|o(?:u|ng)?)|i(?:u|ng?)?|u(?:i|n)?|vn?))",Ye=new RegExp(`^${Oe}$`,"i"),Ve=new RegExp(`^${Oe}{1,8}$`,"i"),ee=new RegExp("\\p{Script=Han}","u"),We=6,ve=t=>[...t].filter(e=>ee.test(e)).length;function Xe(t){let e=t.replaceAll("'",""),s=[0,...Array(e.length).fill(1/0)];for(let o=1;o<=e.length;o++)for(let n=Math.max(0,o-We);n<o;n++)s[n]+1<s[o]&&Ye.test(e.slice(n,o))&&(s[o]=s[n]+1);return e&&Number.isFinite(s[e.length])?s[e.length]:null}function Ze({name:t,words:e}){let s=ve(t.zh),o=e.split(/\s+/).filter(Boolean);return s===0?ee.test(e)&&!o.some(n=>Ve.test(n)):!o.some(n=>Xe(n.toLowerCase())===s)}function Qe({id:t,folder:e,catalog:s,off:o,parts:n}){let i=s.packages.get(t),r=s.problems.get(t)?.problem,a=A(e,O)??"",l=[];r&&l.push({file:O,line:qe(a,r),what:z("en",r)}),i?.template===null&&l.push({file:g,what:`there is none, and it is what "/" puts in a document: with none, no menu offers the block: write one <div ${$}="${t}"> with what a new instance holds`}),l.push(...n);let c=C(e,"writing.md");c&&l.push(c);let p=c||A(e,"writing.md")?.trim()?[]:[{file:"writing.md",what:"there is none, so gallery block show has nothing to say of how to write it"}];i&&Ze(i)&&p.push({file:O,line:v(a,"words")??v(a,"name.zh"),what:ee.test(i.name.zh)?`no word of words spells its whole name ${i.name.zh} in pinyin as an input method composes it, its ${ve(i.name.zh)} Chinese characters a syllable each in one word (as \u65B9\u6848\u6253\u5206 is fangandafen): "/" finds it while those letters are being composed only by such a word. What is counted is how many syllables a word reads as, not which characters they spell`:'its words are Chinese and none of them is pinyin: "/" goes by the letters an input method is composing, so write the pinyin there (\u770B\u677F kanban)'});let f=(()=>{try{return ie(W.readFileSync(j.join(e,"preview.svg")),t)}catch{return null}})();return f&&p.push({file:"preview.svg",what:`it is Gallery's ${f.id} picture, byte for byte (a block made with --recipe keeps its recipe's drawing, which the menu shows beside this block's name): draw this block's own, or delete preview.svg, which the menu does without`}),o&&p.push({file:"gallery.json",what:"the user turned it off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, which is theirs to change and says nothing of the block: it is checked as if it were on, and the instances of a document show what they hold, read-only, until it is on"}),i&&(l.push(...tt(i)),p.push(...et(i,a))),{title:"manifest",problems:l,notes:p}}function et({places:t,parts:e,card:s},o){let n=[];if(t.includes("page"))for(let[i,r]of Object.entries(e))r.edit==="text"&&n.push({file:O,line:v(o,`parts.${i}`),what:`the part ${i} is edited as text, which is read-only on a custom page (no editor runs there): a block whose places hold page keeps what a reader changes there in a data part, with its own field or the card's settings`});else v(o,"card")&&n.push({file:O,line:v(o,"card"),what:`card is for a custom page's board, and its places (${t.join(", ")}) hold no page: nothing reads it`});return n}function tt(t){if(t.settings.length===0||!t.template)return[];let e=ne(t.template,t.id),s=e?V(e.root,t.parts[F].at):[];if(s.length!==1||(b(s[0],"type")??"").trim().toLowerCase()!=="application/json")return[{file:g,what:`its manifest has settings, and the template holds ${s.length===1?`a <${s[0].tagName}> where`:`${s.length} elements of`} its settings part (${t.parts[F].at}): it is to hold one <script type="application/json">, the values a new card starts with ({} for each setting's default)`}];let o=s[0].childNodes.map(n=>n.value??"").join("").trim();try{let n=JSON.parse(o||"{}");if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("it is no object");return[]}catch(n){return[{file:g,line:s[0].sourceCodeLocation?.startLine,what:`its settings part is not a JSON object (${n.message}): write {} or the values of some of its settings, by key`}]}}function st(t){let e=w.createSourceFile("kit.js",t,w.ScriptTarget.Latest,!0,w.ScriptKind.JS),s=[],o=n=>{let i=w.isCallExpression(n)&&w.isPropertyAccessExpression(n.expression)?n.expression:null;if(i?.name.text==="component"&&/\bDocKit$/.test(i.expression.getText(e))){let[r]=n.arguments,a=r&&w.isObjectLiteralExpression(r)?r.properties.find(c=>c.name?.getText(e)==="id"):null,l=a&&w.isPropertyAssignment(a)&&w.isStringLiteralLike(a.initializer)?a.initializer.text:null;s.push({id:l,at:n.getStart(e)})}w.forEachChild(n,o)};return o(e),s}function nt(t){let e="kit.js";if(!t.files.includes("kit.js"))return{title:e,none:"none: a static block"};let s=C(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let o=I(t,"kit.js")??"",n=pe(o);if(n)return{title:e,stops:!0,problems:[{file:e,line:n.line,what:`a browser refuses it: ${n.message}`}]};let i=he(t).map(({line:c,what:p})=>({file:e,line:c,what:p})),r=i.length>0;for(let{name:c,at:p}of re(o,Be))i.push({file:e,line:S(o,p),what:`uses ${c}: an instance keeps what a reader chose with context.state`});let a=st(o);for(let{id:c,at:p}of a)c!==null&&c!==t.id&&i.push({file:e,line:S(o,p),what:`it registers ${c}, and this block is ${t.id}`});let l=a.length?[]:[{file:e,what:`no DocKit.component({ id: "${t.id}", mount(host, context) { \u2026 } }) is to be read in it, and a script may make that call in ways reading does not tell: running it says whether it starts one`}];for(let{line:c,code:p,message:f,refused:h}of le(o,{assets:t.assets}))(h?i:l).push({file:e,line:c,what:`TS${p}: ${f}`});return{title:e,stops:r,problems:i.sort((c,p)=>(c.line??0)-(p.line??0)),notes:l}}function ot(t){let e="style.css";if(!t.files.includes("style.css"))return{title:e,none:"none"};let s=C(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let o=I(t,"style.css")??"",n=ce(t),i=[...Ee(o,t.id),...n].map(({line:l,what:c})=>({file:e,line:l,what:c})),r=Object.entries(t.parts??{}).filter(([,{edit:l}])=>l==="flow").map(([l])=>l),a=je(o,t.id,r).map(({line:l,what:c})=>({file:e,line:l,what:c}));return{title:e,stops:n.length>0,problems:i.sort((l,c)=>l.line-c.line),notes:a}}function it(t,{tree:e}){let s=null;T(e,a=>{s??=a.tagName==="main"?a:null});let o=Q(s??{}),n=(s?.childNodes??[]).some(a=>a.nodeName==="#text"&&a.value.trim()),[i]=o;if(o.length!==1||n||!Z(i)||b(i,$)!==t)return[{file:g,line:i?.sourceCodeLocation?.startLine,what:`a template is one element, a <div ${$}="${t}"> or a <section>, and it holds ${o.length===1&&!n?`<${i.tagName}${b(i,$)?` ${$}="${b(i,$)}"`:""}>`:`${o.length} element${o.length===1?"":"s"}${n?" and words":""}`}`}];let r=[];return T({childNodes:[i]},a=>{b(a,"data-block-id")!==void 0&&r.push({file:g,line:a.sourceCodeLocation?.startLine,what:"it writes a data-block-id, which every instance made of it would repeat: leave it out, Gallery gives a block its id"})}),r}var at=[[t=>b(t,"data-doc-chart")!==void 0,t=>`a chart (<${t.tagName} data-doc-chart="${b(t,"data-doc-chart")}">)`],[t=>t.tagName==="figure",()=>"a card (<figure>)"],[t=>t.tagName==="caption",()=>"a table's <caption>"],[Z,t=>`an instance of ${b(t,$)}`]];function rt(t,e){let s=null;if(T(U(e),i=>{s??=Z(i)&&b(i,$)===t?i:null}),!s)return[];let o=[],n=(i,r)=>{for(let a of Q(i)){let l=at.find(([c])=>c(a));l?o.push({file:g,line:a.sourceCodeLocation?.startLine,what:`its slot ${b(r,"data-doc-slot")} holds ${l[1](a)}, which a new block from "/" would not have: a menu makes what a template's slot holds as a paste of it makes blocks, and a paste makes no chart, card, table caption or instance of a block. Keep the template's slots to blocks the page makes (paragraphs, headings, lists, quotes, code, a plain table, a disclosure), and show the rest in example.html`}):n(a.tagName==="template"?a.content:a,r)}};for(let i of Ue(s))n(i,i);return o}function lt(t,{tree:e}){let s=oe(t);if(!s)return[];let[o]=X(e,t),n=null;return o&&T({childNodes:[o]},i=>{_e(i.tagName,i.attrs)&&(n??=i)}),[{file:g,line:(n??o)?.sourceCodeLocation?.startLine,what:z("en",s)}]}function ct(t){return[[g,"component-template"],[N,"component-example"]].flatMap(([e,s])=>{let o=A(t,e);if(o===null||!o.trim()||C(t,e))return[];let n=we(s,o),{text:i}=de(n);return[{file:e,slug:s,written:n,html:i,tree:U(i)}]})}function ht({id:t,folder:e,found:s,pages:o,parts:n}){let i="template.html and example.html",r=[],a=[];for(let h of[g,N]){let m=C(e,h);m?r.push(m):h===g&&!A(e,h)?.trim()&&s.template!==null?r.push({file:h,what:"it is empty"}):h===N&&!o.some(u=>u.file===h)&&r.push({file:h,what:`there is none or it is empty: write an instance as a writer would fill it, a <div ${$}="${t}">; it is what this check runs`})}let l=o.find(h=>h.file===g);l&&r.push(...it(t,l),...rt(t,l.written));let c=o.find(h=>h.file===N);c&&X(c.tree,s).length===0&&r.push({file:N,what:`it holds no instance of ${t}: a <div ${$}="${t}">`});let p=o.map(({slug:h,written:m,html:u,file:y})=>({file:y,slug:h,written:m,html:u,directory:j.join(e,h),htmlPath:j.join(e,h,"doc.html"),metadata:{title:h,description:h,type:"component"}})),f=fe(p);for(let h of p){for(let m of f.get(h.slug)??[])Me.test(m)||r.push(H(h.file,Ke(m)));for(let m of me(h))a.push(H(h.file,m));for(let m of _(h.html)){let u=H(h.file,`${m} (read-only in the preview)`);n.some(({file:y,line:k})=>y===u.file&&k===u.line)||a.push(u)}}return l&&!r.some(({file:h})=>h===g)&&r.push(...lt(s,l)),{title:i,problems:r,notes:a}}function pt(t,e){let s=te(t,void 0,{on:e}),o=P(t,e);if(!s.packages.has(e)&&!s.problems.has(e))return null;se(t,s);let n=s.packages.has(e)&&s.settings.disabled.includes(e),i=s.packages.get(e)??{id:e,folder:o,files:["kit.js","style.css"].filter(c=>W.existsSync(j.join(o,c)))},r=ct(o),a=s.packages.has(e)?null:"its manifest does not load",l=a?[]:r.flatMap(c=>Je(i,c));return{found:s.packages.get(e)??null,pages:r,sections:[Qe({id:e,folder:o,catalog:s,off:n,parts:l}),nt(i),ot(i),a?{title:"template.html and example.html",skipped:a}:ht({id:e,folder:o,found:i,pages:r,parts:l})]}}var J=({file:t,line:e})=>e?`${t}:${e}`:t;function Y({title:t,problems:e=[],notes:s=[],told:o=[],none:n,skipped:i,unverified:r,pictures:a},l){let c=r?`UNVERIFIED ${r}`:i?`not run: ${i}`:n??(e.length?`${e.length} problem${e.length===1?"":"s"}`:`ok${s.length?`, ${s.length} note${s.length===1?"":"s"}`:""}`);return[`${l}. ${t}: ${c}`,...e.map(p=>` FAIL ${J(p)}: ${p.what}`),...s.map(p=>` note ${J(p)}: ${p.what}`),...o.map(p=>` way back ${J(p)}: ${p.what}`),...a?[ft(a)]:[]]}function ft({folder:t,overviews:e,each:s,edited:o=[],asExport:n=[],documents:i=!1}){let r=e.length?`${R(j.join(t,e[0]))}${e.slice(1).map(c=>` and ${c}`).join("")}, the three widths of each theme side by side; then each at full size: `:`${R(t)}: `,a=n.length===0?"":n.length===o.length?", each the same picture as the export's at its width: the block draws nothing more where a reader can edit":`, ${n.join(" and ")} the same picture as the export's at its width`,l=o.length?`; and ${o.join(" and ")}, as the editing page draws it (context.canEdit() true)${a}`:"";return` Pictures (none looked at for you; ${i?"each instance under a line naming where it stands in the document":"example.html above the line, template.html below it, each under its name"}): ${r}${s.join(", ")}${l}`}function mt([t,e,s,o]){return t.problems.length?"the manifest":e.stops?"kit.js":s.stops?"style.css":o.skipped||o.problems.length?"template.html and example.html":null}async function _t(t,e,{documents:s=!1}={}){let o=pt(t,e);o||(console.error(ke(t,e)),process.exit(1)),console.log(`${e}: ${R(P(t,e))}`),o.sections.forEach((p,f)=>console.log(Y(p,f+1).join(`
3
- `)));let n=mt(o.sections),i=P(t,e),r=n?{title:ue,skipped:`${n} first`}:await $e(t,o.found,{example:A(i,N),template:A(i,g)});console.log(Y(r,5).join(`
4
- `));let a=s?n?[{title:ge(),skipped:`${n} first`}]:await be(t,o.found):[];a.forEach((p,f)=>console.log(Y(p,6+f).join(`
5
- `)));let l=ye([r,...a].filter(({pictures:p})=>p).map(({pictures:{folder:p,overviews:f,each:h,edited:m=[]}})=>({folder:p,files:[...f,...h,...m].map(u=>j.join(p,u))})));l&&console.log(l);let c=[...o.sections,r,...a].reduce((p,{problems:f=[]})=>p+f.length,0);c?(console.log(`FAIL ${e}: ${c} problem${c===1?"":"s"}`),process.exitCode=1):r.unverified||a.some(({unverified:p})=>p)?(console.log(`UNVERIFIED ${e}: the rest passed, and no browser ran ${r.unverified?"it":"the documents' instances"}: export a document that holds it and open that in Chrome or Edge.`),process.exitCode=3):console.log(`OK ${e}${s?" and its instances in the workspace's documents":""}`)}export{_t as checkCommand,Xe as fewestSyllables,pt as readSections,Y as sectionLines,Ze as wantsPinyin};