@heycys/gallery 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/THIRD-PARTY-NOTICES.md +51 -1
  2. package/browser/editor/components/callout/index.mjs +40 -15
  3. package/browser/editor/components/columns/page.mjs +41 -28
  4. package/browser/editor/components/details/index.mjs +2 -1
  5. package/browser/editor/components/dialog/index.mjs +2 -1
  6. package/browser/editor/components/dialog/page.mjs +0 -18
  7. package/browser/editor/components/divider/index.mjs +1 -1
  8. package/browser/editor/components/figure/page.mjs +10 -1
  9. package/browser/editor/components/file/page.mjs +2 -2
  10. package/browser/editor/components/flowchart/add.mjs +2 -2
  11. package/browser/editor/components/heading/index.mjs +2 -0
  12. package/browser/editor/components/heading/page.mjs +6 -0
  13. package/browser/editor/components/highlight/index.mjs +4 -20
  14. package/browser/editor/components/icons.mjs +5 -2
  15. package/browser/editor/components/image/page.mjs +2 -2
  16. package/browser/editor/components/installed/index.mjs +71 -25
  17. package/browser/editor/components/installed/page.mjs +122 -21
  18. package/browser/editor/components/kit.mjs +3 -0
  19. package/browser/editor/components/media/page.mjs +44 -14
  20. package/browser/editor/components/pages.mjs +2 -2
  21. package/browser/editor/components/registry.mjs +56 -30
  22. package/browser/editor/components/section/index.mjs +2 -1
  23. package/browser/editor/components/set-apart.mjs +24 -0
  24. package/browser/editor/components/table/index.mjs +5 -3
  25. package/browser/editor/components/table/page.mjs +29 -18
  26. package/browser/editor/page/annotate/anchors.mjs +4 -3
  27. package/browser/editor/page/annotate/index.mjs +61 -34
  28. package/browser/editor/page/autosave.mjs +50 -4
  29. package/browser/editor/page/beside.mjs +5 -5
  30. package/browser/editor/page/block-menu/colors.mjs +3 -1
  31. package/browser/editor/page/block-menu/index.mjs +8 -6
  32. package/browser/editor/page/blocks.mjs +16 -7
  33. package/browser/editor/page/caret.mjs +4 -1
  34. package/browser/editor/page/changes/bar.mjs +102 -0
  35. package/browser/editor/page/changes/ghost.mjs +206 -0
  36. package/browser/editor/page/changes/gone-words.mjs +94 -0
  37. package/browser/editor/page/changes/index.mjs +447 -0
  38. package/browser/editor/page/changes/words.mjs +27 -0
  39. package/browser/editor/page/clipboard/import/colors.mjs +3 -3
  40. package/browser/editor/page/clipboard/index.mjs +32 -13
  41. package/browser/editor/page/clipboard/own/blocks.mjs +14 -5
  42. package/browser/editor/page/clipboard/own/describe.mjs +16 -7
  43. package/browser/editor/page/clipboard/own/export.mjs +6 -6
  44. package/browser/editor/page/clipboard/own/selection.mjs +2 -2
  45. package/browser/editor/page/clipboard/own/writers.mjs +0 -11
  46. package/browser/editor/page/columns/index.mjs +1 -1
  47. package/browser/editor/page/commit.mjs +19 -4
  48. package/browser/editor/page/conflicts.mjs +6 -26
  49. package/browser/editor/page/convert.mjs +8 -7
  50. package/browser/editor/page/core.mjs +55 -17
  51. package/browser/editor/page/drag/index.mjs +40 -24
  52. package/browser/editor/page/drag/preview.mjs +9 -4
  53. package/browser/editor/page/editor.mjs +70 -15
  54. package/browser/editor/page/emoji-picker/emoji-tab.mjs +22 -13
  55. package/browser/editor/page/emoji-picker/grid.mjs +7 -5
  56. package/browser/editor/page/emoji-picker/icon-tab.mjs +4 -4
  57. package/browser/editor/page/emoji-picker/icons.mjs +0 -1
  58. package/browser/editor/page/emoji-picker/index.mjs +11 -9
  59. package/browser/editor/page/emoji-picker/styles.mjs +161 -2
  60. package/browser/editor/page/emoji-picker/support.mjs +6 -4
  61. package/browser/editor/page/emoji-picker/upload.mjs +12 -11
  62. package/browser/editor/page/fills.mjs +5 -3
  63. package/browser/editor/page/fold/index.mjs +348 -0
  64. package/browser/editor/page/fold/rule.mjs +125 -0
  65. package/browser/editor/page/folded.mjs +23 -0
  66. package/browser/editor/page/format-bar/bar.mjs +2 -1
  67. package/browser/editor/page/format-bar/index.mjs +1 -1
  68. package/browser/editor/page/geometry.mjs +8 -6
  69. package/browser/editor/page/handle/index.mjs +17 -6
  70. package/browser/editor/page/hints/index.mjs +1 -1
  71. package/browser/editor/page/insert/index.mjs +30 -17
  72. package/browser/editor/page/long-runs.mjs +75 -0
  73. package/browser/editor/page/look.mjs +15 -3
  74. package/browser/editor/page/margin.mjs +45 -24
  75. package/browser/editor/page/menu.mjs +69 -25
  76. package/browser/editor/page/merge.mjs +24 -0
  77. package/browser/editor/page/notices.mjs +1 -1
  78. package/browser/editor/page/offered.mjs +1 -1
  79. package/browser/editor/page/outline/folds.mjs +11 -10
  80. package/browser/editor/page/outline/index.mjs +131 -45
  81. package/browser/editor/page/outline/list.mjs +23 -11
  82. package/browser/editor/page/outline/read.mjs +1 -1
  83. package/browser/editor/page/outline/strip.mjs +7 -1
  84. package/browser/editor/page/panel.mjs +5 -4
  85. package/browser/editor/page/resize/index.mjs +1 -1
  86. package/browser/editor/page/selection/delete.mjs +8 -6
  87. package/browser/editor/page/selection/index.mjs +10 -3
  88. package/browser/editor/page/session.mjs +54 -3
  89. package/browser/editor/page/table/cell-bar.mjs +4 -1
  90. package/browser/editor/page/table/cells.mjs +1 -1
  91. package/browser/editor/page/table/icons.mjs +1 -1
  92. package/browser/editor/page/table/index.mjs +13 -8
  93. package/browser/editor/page/table/widths.mjs +9 -4
  94. package/browser/editor/page/text-select/index.mjs +18 -3
  95. package/browser/editor/page/tooltip.mjs +1 -1
  96. package/browser/editor/page/type-grid.mjs +4 -3
  97. package/browser/editor/page/typing/code-edges.mjs +63 -17
  98. package/browser/editor/page/typing/index.mjs +12 -6
  99. package/browser/editor/page/typing/leave.mjs +1 -1
  100. package/browser/shared/annotations.mjs +8 -10
  101. package/browser/shared/code-folds.mjs +5 -1
  102. package/browser/shared/colors.mjs +15 -13
  103. package/browser/shared/component-catalog.mjs +24 -10
  104. package/browser/shared/components/callout.mjs +4 -2
  105. package/browser/shared/components/index.mjs +61 -7
  106. package/browser/shared/components/installed.mjs +75 -5
  107. package/browser/shared/components/page.mjs +10 -1
  108. package/browser/shared/components/table.mjs +1 -1
  109. package/browser/shared/components/text.mjs +2 -2
  110. package/browser/shared/document-look.mjs +178 -0
  111. package/browser/shared/emoji/data/LICENSE-lucide.txt +43 -0
  112. package/browser/shared/emoji/data/README.md +4 -2
  113. package/browser/shared/emoji/data/categories.json +1 -1
  114. package/browser/shared/emoji/data/keywords-en.json +1 -1
  115. package/browser/shared/emoji/data/keywords-zh.json +1 -1
  116. package/browser/shared/emoji/data/names.json +1 -1
  117. package/browser/shared/emoji/data/positions.json +1 -1
  118. package/browser/shared/emoji/data/twemoji-index.json +1 -1
  119. package/browser/shared/emoji/data/twemoji-svg.bin +0 -0
  120. package/browser/shared/emoji/data.mjs +10 -12
  121. package/browser/shared/emoji/emoji.mjs +8 -7
  122. package/browser/shared/emoji/icon-value.mjs +4 -3
  123. package/browser/shared/html-tree.mjs +11 -5
  124. package/browser/shared/i18n/en.mjs +67 -8
  125. package/browser/shared/long-runs.mjs +39 -0
  126. package/browser/shared/new-names.mjs +5 -2
  127. package/browser/shared/outline.mjs +194 -0
  128. package/browser/shared/preferences.mjs +10 -4
  129. package/browser/shared/session.mjs +5 -4
  130. package/browser/shared/workspace-look.mjs +91 -0
  131. package/browser/shared/zoom.mjs +5 -5
  132. package/dist/chunk-3HIRPVLU.mjs +2 -0
  133. package/dist/chunk-4FS7Z7WR.mjs +2 -0
  134. package/dist/{chunk-LHTFLRB6.mjs → chunk-5MHMDLZD.mjs} +2 -2
  135. package/dist/{chunk-YXAUQPVK.mjs → chunk-5ZKJ3H4P.mjs} +3 -3
  136. package/dist/{chunk-ZBIM6ARY.mjs → chunk-64K7IPLO.mjs} +55 -16
  137. package/dist/{chunk-QYKCJ7FG.mjs → chunk-6QXGZM36.mjs} +1 -1
  138. package/dist/chunk-6RGJOMJP.mjs +16 -0
  139. package/dist/{chunk-EUX7IC5J.mjs → chunk-7DTINW6U.mjs} +2 -2
  140. package/dist/{chunk-6CYG3Z4V.mjs → chunk-AJ73XJF3.mjs} +1 -1
  141. package/dist/chunk-AUZGSZJH.mjs +13 -0
  142. package/dist/{chunk-7QQBR7PB.mjs → chunk-BFE45AKL.mjs} +1 -1
  143. package/dist/chunk-BGGDRNYQ.mjs +10 -0
  144. package/dist/{chunk-L4DVONOG.mjs → chunk-BXO2ZY5P.mjs} +1 -1
  145. package/dist/chunk-CEH4MRCC.mjs +2 -0
  146. package/dist/chunk-CY2FNNAB.mjs +16 -0
  147. package/dist/{chunk-LC7YNQFG.mjs → chunk-DFUDV4LX.mjs} +1 -1
  148. package/dist/chunk-DKXG4XDG.mjs +2 -0
  149. package/dist/chunk-E7LWZRXY.mjs +4 -0
  150. package/dist/chunk-EZQ34M3F.mjs +124 -0
  151. package/dist/chunk-FDLXYYG4.mjs +4 -0
  152. package/dist/chunk-FUKQNOQS.mjs +9 -0
  153. package/dist/{chunk-DB4WKGYF.mjs → chunk-GB5SOYQJ.mjs} +2 -2
  154. package/dist/{chunk-ACOPDCNB.mjs → chunk-IVDLMMBD.mjs} +1 -1
  155. package/dist/chunk-JPOSLGOC.mjs +6 -0
  156. package/dist/chunk-JVHHHGEA.mjs +3 -0
  157. package/dist/chunk-L3QKH4OK.mjs +26 -0
  158. package/dist/{chunk-B3VTYBYR.mjs → chunk-LCTHTZIL.mjs} +2 -2
  159. package/dist/chunk-LEF6DRCK.mjs +59 -0
  160. package/dist/chunk-LS4F7JUM.mjs +2 -0
  161. package/dist/chunk-NO5NJCHO.mjs +2 -0
  162. package/dist/{chunk-UNUEWH4S.mjs → chunk-NQPVAU63.mjs} +1 -1
  163. package/dist/chunk-O35FIXRB.mjs +2 -0
  164. package/dist/chunk-PL6GHLGD.mjs +15 -0
  165. package/dist/{chunk-G7TOXONE.mjs → chunk-QJIR2BLP.mjs} +1 -1
  166. package/dist/chunk-QUPLVPB2.mjs +7 -0
  167. package/dist/chunk-R7BNENLY.mjs +4 -0
  168. package/dist/chunk-S6O4UHLC.mjs +2 -0
  169. package/dist/{chunk-HMHK3EQ6.mjs → chunk-SGJWQKEI.mjs} +1 -1
  170. package/dist/chunk-SYGN7GLU.mjs +2 -0
  171. package/dist/chunk-TYK6VNAB.mjs +10 -0
  172. package/dist/{chunk-EVJ3BX3M.mjs → chunk-U6KNPJPR.mjs} +1 -1
  173. package/dist/{chunk-YZ5Z6H4W.mjs → chunk-UALRNVSE.mjs} +1 -1
  174. package/dist/chunk-UMHUSOPJ.mjs +2 -0
  175. package/dist/chunk-V3HXVQEM.mjs +2 -0
  176. package/dist/{chunk-UXUK4PMC.mjs → chunk-V5JTW2LH.mjs} +1 -1
  177. package/dist/chunk-V5VXUJKG.mjs +2 -0
  178. package/dist/chunk-VBXMADMP.mjs +2 -0
  179. package/dist/chunk-VNV55RUA.mjs +2 -0
  180. package/dist/chunk-VPD2PS35.mjs +2 -0
  181. package/dist/chunk-W3BGBJQW.mjs +2 -0
  182. package/dist/chunk-W4VKN3GF.mjs +7 -0
  183. package/dist/chunk-W5BXXPDJ.mjs +3 -0
  184. package/dist/{chunk-Z52HTUW7.mjs → chunk-XNROSH2T.mjs} +2 -2
  185. package/dist/chunk-XUNHRCOG.mjs +6 -0
  186. package/dist/{chunk-6U2SLSDN.mjs → chunk-Y6RLRPG3.mjs} +1 -1
  187. package/dist/cli.mjs +1 -1
  188. package/dist/server.mjs +1 -1
  189. package/dist/worker.mjs +1 -1
  190. package/kit/math.js +18 -2
  191. package/kit/report.css +248 -137
  192. package/kit/runtime.js +126 -51
  193. package/kit/tables.js +51 -1
  194. package/kit/ui.js +97 -0
  195. package/package.json +1 -1
  196. package/release.json +8 -8
  197. package/sdk/doc-kit.d.ts +9 -3
  198. package/skill/SKILL.md +22 -10
  199. package/skill/references/building-components.md +46 -6
  200. package/skill/references/example-report.html +1 -1
  201. package/skill/references/writing-html.md +4 -4
  202. package/skill/sdk/doc-kit.d.ts +9 -3
  203. package/web/assets/index-Bh74DfsV.css +1 -0
  204. package/web/assets/index-UW0RyFFt.js +13 -0
  205. package/web/index.html +2 -2
  206. package/browser/editor/components/callout/page.mjs +0 -13
  207. package/dist/chunk-2PBALTR3.mjs +0 -57
  208. package/dist/chunk-3LA3EMDE.mjs +0 -15
  209. package/dist/chunk-5FRMCDPY.mjs +0 -16
  210. package/dist/chunk-5LEK2CBS.mjs +0 -2
  211. package/dist/chunk-5OFN5AHC.mjs +0 -2
  212. package/dist/chunk-5SIYS5HN.mjs +0 -2
  213. package/dist/chunk-5TEK3RAD.mjs +0 -2
  214. package/dist/chunk-7GHT2UCA.mjs +0 -15
  215. package/dist/chunk-ATCJYAR4.mjs +0 -2
  216. package/dist/chunk-C7HWOBIF.mjs +0 -2
  217. package/dist/chunk-E7VYDG2X.mjs +0 -2
  218. package/dist/chunk-FQGQH4KM.mjs +0 -2
  219. package/dist/chunk-GPF4YWWB.mjs +0 -9
  220. package/dist/chunk-GYQV7Y4J.mjs +0 -120
  221. package/dist/chunk-HQQMJCQJ.mjs +0 -10
  222. package/dist/chunk-IERUOGC3.mjs +0 -6
  223. package/dist/chunk-ITNLYXXV.mjs +0 -3
  224. package/dist/chunk-NFIBI4IP.mjs +0 -26
  225. package/dist/chunk-O52JMOCZ.mjs +0 -2
  226. package/dist/chunk-QMQUXTU4.mjs +0 -12
  227. package/dist/chunk-QVWVFC5K.mjs +0 -6
  228. package/dist/chunk-QZY6Q64C.mjs +0 -2
  229. package/dist/chunk-TDQP3DKQ.mjs +0 -10
  230. package/dist/chunk-V4CPWKMZ.mjs +0 -2
  231. package/dist/chunk-VACRB2NE.mjs +0 -3
  232. package/dist/chunk-W63L7367.mjs +0 -7
  233. package/dist/chunk-W7CXPCRV.mjs +0 -6
  234. package/dist/chunk-XINNG4F2.mjs +0 -4
  235. package/dist/chunk-YL2DPWVS.mjs +0 -4
  236. package/web/assets/index-B6Ai3wsa.js +0 -13
  237. package/web/assets/index-SYPC3EZy.css +0 -1
@@ -0,0 +1,59 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as w}from"./chunk-TX6JH7TR.mjs";import{c as O}from"./chunk-64K7IPLO.mjs";import{a as k,b as d,f as N}from"./chunk-NSKUTQ5J.mjs";import{i as S}from"./chunk-BGGDRNYQ.mjs";import{c as $,g as b,o as A,p as C,r as x}from"./chunk-W4VKN3GF.mjs";import y from"node:fs";import v from"node:path";import{blocksHidden as K}from"../browser/editor/components/registry.mjs";import{PACKAGE_ID as B,SLOT as L}from"../browser/shared/components/installed.mjs";import{DEVICE_NAMES as R,layoutOf as T,PACKAGE_MANIFEST as U,shallowPackages as F}from"../browser/shared/workspace.mjs";var M=(t,e,{script:o,flow:s})=>`{
3
+ "id": "${t}",
4
+ "apiVersion": 1,
5
+ "version": "0.1.0",
6
+ "name": { "zh": "${e}", "en": "${e}" },
7
+ "description": { "zh": "\u4E00\u4E2A\u53EF\u4EE5\u53CD\u590D\u4F7F\u7528\u7684\u5757", "en": "A block to use again" },
8
+ "words": "${e}",
9
+ "parts": {
10
+ "title": { "at": ":scope > h3", "edit": "text" },
11
+ ${s?'"body": { "edit": "flow" }':'"text": { "at": ":scope > p", "edit": "text", "optional": true }'}
12
+ },${o?`
13
+ "runtime": { "generated": [".component-drawn"] },`:""}
14
+ "markdown": "parts"
15
+ }
16
+ `,P=(t,e,o,s)=>`<div data-doc-component="${t}">
17
+ <h3>${e}</h3>
18
+ ${s?` <div data-doc-slot="body">
19
+ ${s.map(n=>` ${n}
20
+ `).join("")} </div>`:` <p>${o}</p>`}
21
+ </div>
22
+ `,W=["<p>\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002</p>","<ul>"," <li>\u63D2\u69FD\u91CC\u5199\u6587\u6863\u81EA\u5DF1\u7684\u5757</li>"," <li>\u6BB5\u843D\u3001\u5217\u8868\u3001\u8868\u683C\u90FD\u53EF\u4EE5</li>","</ul>"],_=(t,e)=>`/* Every selector starts at the instance, so that nothing here reaches the rest of the page.${e?` Each step is
23
+ a >, so that none reaches into the slot, whose blocks read as the page's.`:""} */
24
+ [data-doc-component="${t}"] { padding: 12px 16px; border: 1px solid var(--doc-border); border-radius: 8px; }
25
+ [data-doc-component="${t}"] > h3 { margin-top: 0; }
26
+ `,G=(t,e,{script:o,flow:s})=>`# ${e}
27
+
28
+ What this block is for, and when a document uses it rather than a block of Gallery's own.
29
+
30
+ ## How to write it
31
+
32
+ Write the element as example.html does: \`gallery component show ${t}\` prints it. Each part, and what goes in it:
33
+
34
+ - the title, its \`h3\`: required.
35
+ ${s?'- the body, its `<div data-doc-slot="body">`: required, the document\'s own blocks, written as anywhere in the document (paragraphs, lists, tables, formulas).\n':"- the text, its `p`: optional.\n"}
36
+ ## How it looks
37
+
38
+ What a reader sees of it, and what it shows while it is empty.
39
+ ${o?`
40
+ ## Its script
41
+
42
+ kit.js runs with the rights of a document's own script. What it draws, it draws in what the manifest's \`runtime\` names${s?", outside the slot: it reads the slot and never writes in it":""}.
43
+ `:""}`,D=t=>`// Starts each instance from what the file says, and draws in a node the manifest's runtime names:
44
+ // the kit takes that off an instance before it starts one again, as an undo may put one back.
45
+ DocKit.component({
46
+ id: "${t}",
47
+ on: ["source"],
48
+ mount(host, context) {
49
+ const drawn = document.createElement("div");
50
+ drawn.className = "component-drawn";
51
+ host.append(drawn);
52
+ const draw = () => { drawn.textContent = context.part("title")?.textContent ?? ""; };
53
+ draw();
54
+ return { update: draw };
55
+ },
56
+ });
57
+ `;function I(t,{script:e=!1,flow:o=!1}={}){let s=t.split("/")[1],n={script:e,flow:o};return{"component.json":M(t,s,n),"template.html":P(t,"\u6807\u9898","\u5199\u5728\u8FD9\u91CC\u3002",o&&["<p></p>"]),"example.html":P(t,"\u4E00\u4E2A\u4F8B\u5B50","\u8FD9\u91CC\u5199\u8FD9\u4E2A\u5757\u5728\u4E00\u4EFD\u6587\u6863\u91CC\u7684\u6837\u5B50\u3002",o&&W),"writing.md":G(t,s,n),"style.css":_(t,o),...e?{"kit.js":D(t)}:{}}}var j="local";function q(t){let e=t.includes("/")?t:`${j}/${t}`;if(!B.test(e))throw new d(`Not a component's id: ${t} (<scope>/<name>, each in lowercase letters, digits and hyphens; a <name> alone is ${j}/<name>).`);let o=e.split("/").find(s=>R.has(s));if(o)throw new d(`Not a component's id: ${t} (Windows keeps ${o} for a device).`);return e}var V=(t,e)=>v.join(T(t).components,...e.split("/")),H=({name:t,file:e})=>`${w(e)} is one level too shallow, and no catalog reads it: a package is components/<scope>/<name>/, so move it to components/${j}/${t}/`;function Y(t,e){let o=F(t).find(({name:s})=>s===e.split("/")[1]);return o?H(o):`No component ${e} in ${w(T(t).components)}: gallery component list says which there are.`}function X(t,e,{script:o,flow:s}){let n=V(t,e);if(y.existsSync(n)||$(t).problems.has(e)){let i=!y.existsSync(v.join(n,U));console.error(i?`A folder is there with no component.json: ${w(n)}: move it, or give this component another name.`:`Component already exists: ${w(n)}: gallery component show ${e} says what it is; give a new one another name.`),process.exit(1)}let a=I(e,{script:o,flow:s});try{y.mkdirSync(n,{recursive:!0});for(let[i,c]of Object.entries(a).reverse())y.writeFileSync(v.join(n,i),c)}catch(i){if(!i.code)throw i;console.error(`Cannot write ${w(n)} (${i.code}).`),process.exit(1)}console.log(`Created ${w(n)}: ${Object.keys(a).join(", ")}`),console.log(`Next: say in component.json what it is (its name, description and parts), write template.html, what "/" puts in a document, and example.html, an instance as a writer would fill it, then writing.md and style.css${o?" and kit.js":""} (references/building-components.md has every field and the rules${s?", and Slots what its slot body holds":""}), and run gallery component check ${e}, which passes as it stands now.`)}var u=({zh:t,en:e})=>t===e?t:`${t} / ${e}`;function z(t){if(C(t))return null;let e=A(t);return e?b("en",e):"it has no template.html"}var J={disabled:"disabled: its instances show as they stand, no script and no style",hidden:"hidden: the menus do not offer it, and the instances there go on running"};function Q(t){let e=$(t),o=x(e),s=o.filter(({reason:r})=>r),n=o.filter(({reason:r})=>!r),a=n.filter(({state:r})=>r==="normal"),i=F(t),c=K(e.settings.hidden),p=()=>{c.length&&console.log(`Hidden by the user, not to write unless asked for: ${c.join(", ")}`)};if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${w(t)}`),n.length+s.length+i.length===0){console.log("No component packages yet. A document is written with Gallery's blocks and whole blocks; gallery component new <id> starts a package when the user wants a block to use again."),p();return}console.log(a.length?`${a.length} component${a.length===1?"":"s"} to write with (gallery component show <id> says how):`:"No component to write with now.");for(let{id:r,name:l,version:m,description:f}of a){console.log(`${r} ${u(l)}`),console.log(` \u7248\u672C\uFF1A${m}\uFF08available\uFF09`),console.log(` \u8BF4\u660E\uFF1A${u(f)}`);let E=z(e.packages.get(r));E&&console.log(` \u6A21\u677F\uFF1Athe menus cannot insert it, and a document can still write it: ${E}`)}let h=n.filter(({state:r})=>r!=="normal");h.length+s.length+i.length>0&&console.log("Not to write with now:");for(let{id:r,name:l,version:m,state:f}of h)console.log(`${r} ${u(l)} ${m} ${J[f]}`);for(let{id:r,reason:l,version:m}of s)console.log(`${r}${m?` ${m}`:""} does not load: ${l.en}`);for(let r of i)console.log(H(r));p()}var Z=(t,{at:e,edit:o,optional:s,min:n,max:a})=>{let i=[s?"optional":"",n!==void 0?`at least ${n}`:"",a!==void 0?`at most ${a}`:""].filter(Boolean),c=o==="flow"?`${L}="${t}"`:e;return` ${t} ${c} ${o==="flow"?"flow (blocks of the document: write any block in it)":o}${i.length?` (${i.join(", ")})`:""}`};function tt(t,e){let o=$(t),s=o.problems.get(e),n=o.packages.get(e)??(s?.off?s:void 0);if(!n){let h=s?.problem;console.error(h?`${e} does not load: ${b("en",h)}`:Y(t,e)),process.exit(1)}let{state:a}=x(o).find(h=>h.id===e);console.log(`${e} ${u(n.name)}`),console.log(` \u7248\u672C\uFF1A${n.version}\uFF08${a==="normal"?"available":a}\uFF09`),console.log(` \u8BF4\u660E\uFF1A${u(n.description)}`),console.log(` ${w(n.folder)}`);let i=Object.entries(n.parts);console.log(i.length?"Parts (edit text: the user types there; flow: blocks of the document; none, or data: the component's):":"No parts.");for(let[h,r]of i)console.log(Z(h,r));let c=S(n,"writing.md")?.trimEnd();console.log(c?`How to write it (writing.md):
58
+ ${c}`:"How to write it: the package has no writing.md.");let p=S(n,"example.html")?.trimEnd();console.log(p?`The example (example.html):
59
+ ${p}`:"The example: the package has no example.html."),console.log("In a document: write the element as the example does, straight in the page or a section, with no data-block-id, which the export gives it.")}var g={new:(t,e,o)=>X(t,e,o),list:Q,show:tt,check:async(t,e)=>(await import("./chunk-R7BNENLY.mjs")).checkCommand(t,e),try:async(t,e)=>(await import("./chunk-FUKQNOQS.mjs")).tryCommand(t,e)},et=["--press","--drag","--to","--key"];function ot(t){let e=t.indexOf("--"),o=(e===-1?t:t.slice(0,e)).findIndex(a=>a==="--key"||a.startsWith("--key="));if(o===-1)return{argv:t,key:null};let s=o+(t[o].includes("=")?1:2),n=t[s];if(n===void 0||s===e||k(n))throw new d("--key takes a selector and a key: --key <selector> <key> (Enter, Space, ArrowRight, a letter, Shift+Tab).");return{argv:t.filter((a,i)=>i!==s),key:n}}async function gt(t,{workspace:e}){try{return await nt(t,e)}catch(o){throw o instanceof d&&t.find(s=>!k(s))==="try"&&(o.synopsis=O),o}}async function nt(t,e){let{argv:o,key:s}=ot(t),{positional:n,options:a,values:i}=N({options:["--script","--flow","--keep"],values:et,argv:o}),[c,p,...h]=n,r=Object.keys(g).join(", ");if(!c)throw new d(`Say what to do: ${r}.`);if(!Object.hasOwn(g,c))throw new d(`No such component command: ${c} (${r}).`);let l=g[c];for(let f of["--script","--flow"])if(a.has(f)&&l!==g.new)throw new d(`${f} goes with new, not ${c}.`);let m=[...i.keys(),...a.has("--keep")?["--keep"]:[]];if(l===g.try)return l(e,{named:n.slice(1),values:i,key:s,keep:a.has("--keep")});if(m.length)throw new d(`${m[0]} goes with try, not ${c}.`);if(l===g.list){if(p!==void 0)throw new d(`gallery component ${c} takes nothing else.`);return l(e)}if(p===void 0||h.length>0)throw new d(`gallery component ${c} takes one id.`);return l(e,q(p),{script:a.has("--script"),flow:a.has("--flow")})}export{q as a,V as b,H as c,Y as d,ot as e,gt as f};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as f,b as g,c as h,d as $,e as v,f as y,g as r,h as x}from"./chunk-S6O4UHLC.mjs";import{b as c,f as p}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";import{descendantsIn as A}from"../browser/shared/outline.mjs";async function N(L){let{positional:u,options:I,values:T}=p({options:["--top","--first"],values:["--under","--after"],argv:L});if(u.length!==1)throw new c("Name the document to move, one.");let e=x(T,I);if(e.under===void 0&&!e.top&&e.after===void 0&&!e.first)throw new c("Say where it goes: --under <document> or --top, and --after <document> or --first.");let s=await f(),a=async(b,k)=>{let d=await $(b,k,s);return d.refused&&(console.error(d.refused),process.exit(1)),d.slug},t=await a(u[0],"the document to move"),l=e.under!==void 0?await a(e.under,"--under"):e.top?"":void 0,m=e.after!==void 0?await a(e.after,"--after"):null,o=await y(t,{parent:l,after:m,first:e.first});o.ok||(console.error(v(s,t,o.reason,{parent:l,after:m,message:o.message})),process.exit(1));let n=await f(),i=A(n.children,t).length,w=`${g(n,t)}${i?` with the ${i} document${i===1?"":"s"} under it`:""}`;o.moved?console.log(`Moved ${w}: now ${r(n,o)}; it was ${r(s,o.from)}.`):console.log(`${w} is there already: ${r(n,o)}.`),console.log(h(n,t))}export{N as run};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as u,d as T,e as h,f as j,g as D,h as S}from"./chunk-S6O4UHLC.mjs";import{a as p,b as C}from"./chunk-TX6JH7TR.mjs";import{a as E,b as I,c as O,i as b}from"./chunk-5ZKJ3H4P.mjs";import{b as v,f as k,g as L}from"./chunk-NSKUTQ5J.mjs";import{b as N}from"./chunk-UALRNVSE.mjs";import{existsSync as R}from"node:fs";import a from"node:path";import{reportsDirectory as w}from"../browser/shared/paths.mjs";import{keptName as U,layoutOf as M,listTrash as X}from"../browser/shared/workspace.mjs";import{parentIn as _}from"../browser/shared/outline.mjs";var z="\u65B0\u6587\u6863";async function q(o,r=w){return U(o)?`"${o}" is a name the workspace keeps for itself: choose another slug.`:R(a.join(M(r).pages,o))?`"${o}" is the \u5199\u4F5C\u504F\u597D page's slug: choose another slug.`:R(a.join(r,o))?`Document already exists: ${p(a.join(r,o))}`:(await X(r)).some(s=>s.slug===o)?`"${o}" is a document's in the trash: choose another slug.`:null}async function te(o){let{positional:r,options:s,values:A}=k({options:["--no-preview","--no-browser","--first"],values:["--under","--after"],argv:o}),[t,g,y=z]=r;if(r.length<2||r.length>3||!t||!g?.trim()||!y.trim())throw new v("Name the slug and the title (then a description, if you choose one), each quoted when it has spaces.");L(t);let n=S(A,s,{top:!1}),$=await q(t);$&&(console.error($),process.exit(1));let F=n.under!==void 0||n.after!==void 0||n.first,c=null;if(F){let e=await u(),i=async(H,P)=>{let m=await T(H,P,e);return m.refused&&(console.error(`${m.refused} Nothing made.`),process.exit(1)),m.slug},l=n.under!==void 0?await i(n.under,"--under"):void 0,f=n.after!==void 0?await i(n.after,"--after"):null;f!==null&&l!==void 0&&_(e.children,f)!==l&&(console.error(`${h(e,t,"level",{parent:l,after:f})} Nothing made.`),process.exit(1)),c={parent:l,after:f,first:n.first}}try{await N(t,g,y)}catch(e){if(e.code!=="EEXIST")throw e;console.error(await q(t)??`Document already exists: ${p(a.join(w,t))}`),process.exit(1)}if(await import("./chunk-CEH4MRCC.mjs").then(({noteNew:e})=>e(t)),console.log(`Created ${p(a.join(w,t,"doc.html"))} and doc.json`),c){let e=await j(t,c),i=await u();e.ok?console.log(`Placed it ${D(i,e)}.`):(console.log(`Not placed (${h(i,t,e.reason,{...c,message:e.message})}): it is at the top level, last; gallery move ${t} puts it where it goes.`),process.exitCode=1)}for(let e of await C())console.log(e);let d=await b(t,{skipped:O(s),command:`gallery new ${t}`});console.log(E(d,"replace the starter section with the document's skeleton (each section's heading) as soon as you can outline it, then write it a section at a time, as ordinary HTML, so that the user watches it grow (gallery check fails while the starter section remains).")),console.log(`Hand in: gallery export ${t}, then gallery qa ${t}`);let x=await I(d,s);x&&console.log(x);for(let e of d)console.log(e)}export{z as a,q as b,te as c};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as E,b as F,c as H}from"./chunk-G7TOXONE.mjs";import{b as L,c as O,d as b,e as D}from"./chunk-W63L7367.mjs";import{existsSync as K}from"node:fs";var Q=120;function R(n,h){let r=({packages:s,problems:l})=>new Map([...s,...l].map(([e,{stamp:m}])=>[e,m])),[o,p]=[r(n),r(h)];return[...new Set([...o.keys(),...p.keys()])].filter(s=>o.get(s)!==p.get(s)).sort()}function v({root:n,tell:h,delay:r=Q,quiet:o=H,hold:p=E,limit:s=F,now:l=Date.now}){let e=null,m=0,f=null,c=new Map;b(n);let I=i=>{e&&m<=l()+i||(clearTimeout(e),m=l()+i,e=setTimeout(y,i),e.unref?.())};function y({settled:i=!1}={}){e=null;let u=b(n),a=O(n,u.settings),M=l();a.stamp!==f?.stamp&&(f={stamp:a.stamp,at:M});let T=M-f.at;if(T<o&&!i)return I(o-T);let d=new Map(a.packages),g=new Map(a.problems),k=1/0;for(let[t,S]of u.packages){if(!(!a.settings.disabled.includes(t)&&(g.has(t)||!d.has(t)&&K(S.folder)))){c.delete(t);continue}c.has(t)||c.set(t,f.at);let x=Math.min(p-T,s-(M-c.get(t)));if(x<=0){c.delete(t);continue}d.set(t,S),g.delete(t),k=Math.min(k,x)}let{settings:w}=a,C=L({packages:d,problems:g,settings:w});if(C!==u.stamp){let t={packages:d,problems:g,settings:w,stamp:C};D(n,t),h(t,R(u,t))}k!==1/0&&I(k)}return{changed:()=>I(r),taken(){clearTimeout(e),y({settled:!0})},close(){clearTimeout(e),e=null}}}export{Q as a,v as b};
2
+ import{a as E,b as F,c as H}from"./chunk-QJIR2BLP.mjs";import{b as L,c as O,d as b,e as D}from"./chunk-W4VKN3GF.mjs";import{existsSync as K}from"node:fs";var Q=120;function R(n,h){let r=({packages:s,problems:l})=>new Map([...s,...l].map(([e,{stamp:m}])=>[e,m])),[o,p]=[r(n),r(h)];return[...new Set([...o.keys(),...p.keys()])].filter(s=>o.get(s)!==p.get(s)).sort()}function v({root:n,tell:h,delay:r=Q,quiet:o=H,hold:p=E,limit:s=F,now:l=Date.now}){let e=null,m=0,f=null,c=new Map;b(n);let I=i=>{e&&m<=l()+i||(clearTimeout(e),m=l()+i,e=setTimeout(y,i),e.unref?.())};function y({settled:i=!1}={}){e=null;let u=b(n),a=O(n,u.settings),M=l();a.stamp!==f?.stamp&&(f={stamp:a.stamp,at:M});let T=M-f.at;if(T<o&&!i)return I(o-T);let d=new Map(a.packages),g=new Map(a.problems),k=1/0;for(let[t,S]of u.packages){if(!(!a.settings.disabled.includes(t)&&(g.has(t)||!d.has(t)&&K(S.folder)))){c.delete(t);continue}c.has(t)||c.set(t,f.at);let x=Math.min(p-T,s-(M-c.get(t)));if(x<=0){c.delete(t);continue}d.set(t,S),g.delete(t),k=Math.min(k,x)}let{settings:w}=a,C=L({packages:d,problems:g,settings:w});if(C!==u.stamp){let t={packages:d,problems:g,settings:w,stamp:C};D(n,t),h(t,R(u,t))}k!==1/0&&I(k)}return{changed:()=>I(r),taken(){clearTimeout(e),y({settled:!0})},close(){clearTimeout(e),e=null}}}export{Q as a,v as b};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-L3QKH4OK.mjs";import"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{g as changeLines,c as handedInSource,f as headerChanged,e as inStep,a as naturalize,d as pendingBlockIds,h as readOnlyTexts,j as scriptKept,b as shownSource,i as writingNotes};
@@ -0,0 +1,15 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as Fe}from"./chunk-TX6JH7TR.mjs";import{a as _e,b as He,c as Be,d as We,e as qe,f as Ge}from"./chunk-DFUDV4LX.mjs";import{g as Ie}from"./chunk-E7LWZRXY.mjs";import{o as Re}from"./chunk-AUZGSZJH.mjs";import{a as me}from"./chunk-HYMEEXKN.mjs";import{b as Ce}from"./chunk-CY2FNNAB.mjs";import{l as Pe}from"./chunk-W4VKN3GF.mjs";import D from"node:fs/promises";import Ue from"node:os";import S from"node:path";import{pathToFileURL as Ye}from"node:url";import{instancesOf as ze}from"../browser/shared/components/index.mjs";import{FALLBACK as it,INSTANCE as ke,SLOT as rt,SLOT_PART as lt}from"../browser/shared/components/installed.mjs";import{layoutOf as ct,PACKAGE_MANIFEST as dt}from"../browser/shared/workspace.mjs";var ht="in a browser, under the export's policy",te="component-check",ne=[360,736,1024],ge=["light","dark"],pt=[1024,360],Ke=1e4,ut=6e4,ye=3e4,Xe=2e3,ft=3e3,wt=60,mt=2,gt=8,kt=ye/2,$t=/^(?:wasm-)?eval$/,yt=new Set(["TargetCloseError","ConnectionClosedError"]),$e=t=>String(t?.message??t).split(`
3
+ `)[0],bt=(t,a)=>`<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${t}</title></head><body><main class="doc-page" data-doc-id="${t}">${a}
4
+ </main></body></html>
5
+ `,xt=({example:t,template:a})=>`<p>example.html</p>${t}
6
+ <hr><p>template.html</p>${a}`,Qe=(t,a)=>ze(me(t),a).map(({sourceCodeLocation:{startLine:i,startOffset:r,endOffset:n}})=>({line:i,markup:t.slice(r,n)}));async function vt(t,a){let i=S.join(a,"components",...t.id.split("/"));for(let r of[dt,"template.html",...t.files]){let n=Pe(t,r);if(!n)continue;let s=await D.readFile(n);await D.mkdir(S.dirname(S.join(i,r)),{recursive:!0}),await D.writeFile(S.join(i,r),r==="kit.js"?`${s}
7
+ //# sourceURL=kit.js
8
+ `:s)}}async function Tt(t,{example:a,template:i},r){await vt(t,r);let n=S.join(r,te);await D.mkdir(n);let s=`${a}
9
+ `,p=Ce(bt(te,xt({example:a,template:i}))).text;await D.writeFile(S.join(n,"doc.html"),p),await D.writeFile(S.join(n,"doc.json"),JSON.stringify({title:te,description:te,type:"component"}));let u=await(await Re({directory:r}))(te),l=S.join(r,"export.html");await D.writeFile(l,u);let w=s.split(`
10
+ `).length-1,k=Qe(p,t).map(({line:c})=>c>w?{file:"template.html",line:c-w}:{file:"example.html",line:c});return{html:u,file:l,places:k,source:p}}async function jt({match:t,instance:a,slotPart:i,slotName:r,fallback:n,parts:s,at:p,source:h,still:u,step:l,times:w,typed:k,typing:c}){let d=()=>[...document.querySelectorAll(t)].filter(e=>!e.parentElement.closest(a)),T=e=>new Promise(o=>setTimeout(o,e)),g=()=>new Promise(e=>{requestAnimationFrame(e),setTimeout(e,100)}),$=async e=>{await g(),await g();let o=e.outerHTML;for(let m=0,y=Date.now()+u;m<3;){if(Date.now()>y)return null;await T(l);let b=e.outerHTML;m=b===o?m+1:0,o=b}return o},f=e=>{let o=document.createElement("template");return o.innerHTML=e,o.content.firstElementChild},x=e=>`<${e.localName}${e.classList.length?` class="${e.getAttribute("class")}"`:""}>`,P=e=>e.nodeType===1?x(e):`the words "${e.data.trim().slice(0,40)}"`,q=e=>[...e.childNodes].filter(o=>o.nodeType===1||o.nodeType===3&&o.data.trim()),R=(e,o)=>["style","class"].includes(o)&&!e.getAttribute(o)?.trim()?null:e.getAttribute(o),V=(e,o)=>{for(let b of new Set([...e.getAttributeNames(),...o.getAttributeNames()]))if(R(e,b)!==R(o,b))return`${b} on ${x(o)}, ${JSON.stringify(R(e,b))} then ${JSON.stringify(R(o,b))}`;let[m,y]=[q(e),q(o)];for(let b=0;b<Math.max(m.length,y.length);b++){let[j,L]=[m[b],y[b]];if(!j||!L)return`${x(o)} ${j?`without ${P(j)}`:`with ${P(L)} more`}`;if(j.nodeType!==L.nodeType||j.localName!==L.localName||j.nodeType===3&&j.data.trim()!==L.data.trim())return`in ${x(o)}, ${P(j)} then ${P(L)}`;let I=j.nodeType===1?V(j,L):null;if(I)return I}return null},se=e=>{let o=new Map;for(let m of e)o.set(x(m),(o.get(x(m))??0)+1);return o},be=()=>[...document.querySelectorAll("*")].filter(e=>!e.closest(a)),xe=e=>[...e.at(-1).keys()].filter(o=>e.length>2&&e.every((m,y)=>y===0||(m.get(o)??0)>(e[y-1].get(o)??0))),ve=e=>e.parentElement?.closest(`${a}, ${i}`)??null,Te=e=>[...e.querySelectorAll(i)].filter(o=>ve(o)===e),H=e=>{let o=e.cloneNode(!0);return Te(o).forEach(m=>m.replaceChildren()),o},X=e=>Te(e).map(o=>{let m=[];for(let y=o.parentElement;y&&y!==e;y=y.parentElement)m.unshift(x(y));return{name:o.getAttribute(r),place:m.join(" > "),blocks:[...DocKit.dehydrate(o.cloneNode(!0)).children].map(y=>y.localName).join(" "),html:o.outerHTML}}),ie=(e,o,m,{markup:y=!0}={})=>e.flatMap(({name:b,place:j,blocks:L,html:I})=>{let N=o.find(F=>F.name===b),z=N?N.place!==j?`moved the slot ${b} (${N.place?`in ${N.place}`:"straight in the instance"}, where the file has it ${j?`in ${j}`:"straight in the instance"})`:N.blocks!==L?`changed the blocks the slot ${b} holds (${L||"none"}, then ${N.blocks||"none"})`:y&&N.html!==I?`changed what the slot ${b} holds`:null:`took the slot ${b} off the instance`;return z?[{kind:"written-in",part:b,how:`${z}, ${m}`}]:[]}),je=e=>o=>ve(o)===e,re=(e,o=()=>!0)=>Object.entries(s).filter(([,{edit:m}])=>o(m)).flatMap(([m,y])=>[...e.querySelectorAll(y.at)].filter(je(e)).map(b=>({name:m,node:b}))),Q=e=>re(e,o=>o==="text"),J=e=>Object.entries(s).filter(([,{edit:o}])=>o==="data").map(([o,m])=>({name:o,node:[...e.querySelectorAll(m.at)].find(je(e))})).filter(({node:o})=>o),C=[],G=d()[p];if(!G)return[{kind:"gone"}];if(G.hasAttribute(n))return[{kind:"fallback"}];let le=await $(G);if(le===null)return[{kind:"moving"}];let ae=f(h),Ee=X(G);C.push(...ie(X(ae),Ee,"as it mounts",{markup:!1}));let ce=Q(ae);Q(G).forEach(({name:e,node:o},m)=>{ce[m]&&ce[m].node.innerHTML!==o.innerHTML&&C.push({kind:"redrawn",part:e,how:`the file says ${JSON.stringify(ce[m].node.textContent.trim())}, the page ${JSON.stringify(o.textContent.trim())}`})});let de=DocKit.dehydrate(G.cloneNode(!0)),[Se,Ne]=[H(ae),H(de)],he=V(Se,Ne);if(he){let e=re(Ne),o=re(Se).find(({node:m},y)=>e[y]&&V(m,e[y].node))?.name;C.push({kind:"left",what:he,...o?{part:o}:{}})}let tt=J(de);for(let[e,{name:o,node:m}]of J(ae).entries())!he&&tt[e]?.node.innerHTML!==m.innerHTML&&C.push({kind:"data",part:o});let Y=[],pe=new MutationObserver(e=>Y.push(...e));pe.observe(document.documentElement,{subtree:!0,childList:!0,characterData:!0});let Ae=new Set,Oe=e=>{Y.push(...pe.takeRecords());for(let{name:o,node:m}of e)(!m.isConnected||Y.some(({target:y})=>m.contains(y)))&&Ae.add(o);Y.length=0},ue=[le],fe=[se(be())],Le=e=>{ue.push(e),fe.push(se(be())),C.push(...ie(Ee,X(v),"as it mounts again"))},v=de,we=Q(v);Y.length=0,G.replaceWith(v);let B=await $(v);if(Oe(we),B!==null){Le(B);for(let e=0;e<w&&B!==null;e++){let o=v.cloneNode(!0);we=Q(o),Y.length=0,v.replaceWith(o),v=o,B=await $(v),Oe(we),B!==null&&Le(B)}}pe.disconnect(),B===null&&C.push({kind:"moving"});for(let e of Ae)C.push({kind:"redrawn",part:e,how:"a mount changes it"});let Me=ue.map(e=>se(H(f(e)).querySelectorAll("*"))),De=xe(Me);for(let e of De)C.push({kind:"piles",what:e,counts:Me.map(o=>o.get(e)??0)});for(let e of xe(fe))C.push({kind:"piles",what:e,outside:!0,counts:fe.map(o=>o.get(e)??0)});if(!De.length){let e=ue.slice(1).map(o=>V(H(f(le)),H(f(o)))).find(Boolean);e&&C.push({kind:"changed",what:e})}let oe=B===null?[]:Q(v).filter(({node:e})=>e.textContent.trim()),nt=[...new Set([...new Map(oe.map(e=>[e.name,e])).values(),...oe])].slice(0,k),at=Date.now()+c;for(let{node:e}of nt){if(Date.now()>at)break;let o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT).nextNode(),m=o.data;o.data=`${m}\u2026`;let y=oe.map(({node:j})=>j.textContent);await $(v);let b=oe.find(({node:j},L)=>!j.isConnected||j.textContent!==y[L]);if(b){C.push({kind:"redrawn",part:b.name,how:"a change of its words does not stand"});break}o.data=m,await $(v)}return B!==null&&J(v).length>0&&C.push(...await ot()),C;async function ot(){let e=[],o=null,m=!1,y="as it hears that it can write (the editable signal)",b=[],j=I=>{if(I.target!==v)return;let{parts:N,run:z}=I.detail,F=N.map(({part:E})=>E.innerHTML),M=N.map(({part:E})=>E.cloneNode(!0)),Z=z(Object.fromEntries(N.map(({name:E},A)=>[E,M[A]]))),W=N.find(({part:E},A)=>E.innerHTML!==F[A]),U=N.find(({part:E},A)=>M[A].cloneNode(!1).outerHTML!==E.cloneNode(!1).outerHTML);if(W&&N.forEach(({part:E},A)=>{E.innerHTML=F[A]}),!m){let E=W??U??N.find((A,ee)=>M[ee].innerHTML!==F[ee]);E&&!b.some(A=>A.when===y)?b.push({kind:"unasked",part:E.name,when:y}):Z&&!E&&I.preventDefault();return}W?o??=`it writes the part ${W.name} on the page, not the draft context.edit hands it, so the editor refuses the edit`:Z&&U&&(o??=`it changes the part ${U.name}'s own tag or attributes, which are the file's: a change writes what a part holds, so the editor refuses the edit`),!(W||!Z||U)&&(N.forEach(({part:E},A)=>{e.push({part:E,before:F[A]}),E.replaceChildren(...M[A].childNodes)}),I.preventDefault())};document.addEventListener("doc-component-edit",j);try{return[...await L(),...b]}finally{document.removeEventListener("doc-component-edit",j)}async function L(){dispatchEvent(new Event("doc-editable")),await $(v),y="as it mounts";let I=v.cloneNode(!0);v.replaceWith(I),v=I;let N=await $(v);y="as it hears its part changed (the source signal)";let z=X(v),F=DocKit.dehydrate(v.cloneNode(!0)),M=[];m=!0;try{if(!DocKit.example(v))return[{kind:"no-example"}]}catch(_){return[{kind:"example",what:`it throws: ${_?.message??_}`}]}finally{m=!1}let Z=await $(v),W=DocKit.dehydrate(v.cloneNode(!0)),U=Object.fromEntries(J(W).map(({name:_,node:K},st)=>[_,K.innerHTML,J(F)[st]?.node.innerHTML]).filter(([,_,K])=>_!==K));o?M.push({kind:"example",what:o}):e.length===0?M.push({kind:"example",what:"context.edit was not taken: it was not called, or it answered false, and the console says why"}):Object.keys(U).length===0?M.push({kind:"example",what:"it changes nothing a part holds"}):M.push({kind:"wrote",parts:U});for(let _ of[F,W])for(let{node:K}of J(_))K.textContent="";let E=V(H(F),H(W));E&&M.push({kind:"example",what:`it changes what is no data part: ${E}`}),M.push(...ie(z,X(v),"as its example makes its edit"));for(let{part:_,before:K}of e.reverse())_.innerHTML=K;let A=await $(v),ee=N!==null&&A!==null?V(H(f(N)),H(f(A))):null;return Z===null||A===null?M.push({kind:"moving"}):ee&&!E&&M.push({kind:"undo",what:ee}),M}}}var Et=t=>t.map(({name:a,removed:i,added:r,lines:n})=>`${a} (-${i} +${r} of its ${n} line${n===1?"":"s"})`).join(" and "),St="a write changes the lines it means and no others, a row moved with the blank before it, JSON written back by jsonIn and laid out in template.html and example.html as jsonIn writes it (building-components.md, Two examples)";function Nt({kind:t,what:a,part:i,how:r,when:n,counts:s,outside:p,parts:h,back:u,line:l},w,{script:k}){let c=T=>({...w,what:T}),d=T=>({...w,what:T,note:!0});switch(t){case"wrote":return{...w,told:!0,what:`its example wrote ${Et(h)}; the server took it${u?"; put back as an undo does, it shows what it showed":""}`};case"laid":return d(`its example's write lays the part ${i} out anew (${r}): ${St}`);case"drops":return{...d(`${a} listens for dragover and not for dragenter: a drop goes where both are cancelled, and the move that enters it asks dragenter alone, so that a release then (on a card's words, its padding) drops nothing: cancel dragenter as dragover is cancelled (preventDefault)`),file:"kit.js",line:l};case"gone":return c("the page does not hold this instance");case"fallback":return c(k?"its component failed or never started: the instance shows what it holds, read-only":"the instance shows as one of no package");case"moving":return d("what it shows never holds still (an animation?), so its mounts could not be compared");case"redrawn":return c(`the component redraws its text part ${i}: ${r}. A text part is the file's, what the user types in: read it, and draw in what is the component's`);case"left":return c(`dehydrate does not leave it as the file has it, so a copy of the view would hold what the kit made of it: ${a}. ${i?`That stands in its part ${i}, which is the file's: read a part, and draw in what is the component's`:"Name what it draws in the manifest's runtime, or take it off in dehydrate"}`);case"data":return c(`a mount changes its data part ${i}, so that a page would write what the component left there, with nothing edited: read a data part, and change it by context.edit alone`);case"no-example":return d("it has a data part and its component offers no example of an edit, so nothing has tried the way back to the file: give DocKit.component an example(host, context) that makes a small context.edit");case"example":return c(`its example: ${a}`);case"refused":return c("what its example wrote cannot go in the file: a script, a handler, an address of code, data-block-id or data-ge-*, what does not read back as itself, or what is no JSON in a script of data");case"undo":return c(`with what its example wrote put back, as an undo does, it does not show what it showed: ${a}: draw from the part, and on the source signal`);case"unasked":return c(`it writes its data part ${i} with no reader's gesture, ${n}, once the page takes edits: a page would write it each time it opened. Call context.edit on a gesture alone, a press, a drop or a key, and draw what the part holds as it is`);case"written-in":return c(`kit.js ${r}: a slot is the document's, its blocks the reader's: read it with context.part, never write in it or move it, and draw outside it`);case"piles":return c(p?`${a} piles up outside the instance on each put-back (${s.join(", then ")} of them), so an undo adds another: a component draws in its instance, and what it has to put elsewhere it takes away again in destroy`:`${a} piles up on each put-back (${s.join(", then ")} of them): it is declared in neither the manifest's runtime nor dehydrate, so an undo adds another`);default:return c(`a mount does not give the same DOM again: ${a}`)}}var At=t=>[...new Map(t.toReversed().map(a=>[`${a.finding.kind}|${a.finding.part??""}|${["piles","example"].includes(a.finding.kind)?a.finding.what:""}|${a.finding.when??""}|${a.finding.line??""}`,a])).values()].toReversed(),Ot=4e6;function Ze(t,a,i=(r,n)=>r===n){let[r,n]=[t.split(`
11
+ `),a.split(`
12
+ `)],s=0;for(;s<r.length&&s<n.length&&i(r[s],n[s]);)s++;let p=0;for(;p<r.length-s&&p<n.length-s&&i(r[r.length-1-p],n[n.length-1-p]);)p++;let[h,u]=[r.slice(s,r.length-p),n.slice(s,n.length-p)];if(h.length===0&&u.length===0)return[];if(h.length*u.length>Ot)return[{removed:h,added:u}];let l=Array.from({length:h.length+1},()=>new Uint32Array(u.length+1));for(let c=h.length-1;c>=0;c--)for(let d=u.length-1;d>=0;d--)l[c][d]=i(h[c],u[d])?l[c+1][d+1]+1:Math.max(l[c+1][d],l[c][d+1]);let w=[],k=null;for(let c=0,d=0;c<h.length||d<u.length;)c<h.length&&d<u.length&&i(h[c],u[d])?(k=null,c++,d++):(k||w.push(k={removed:[],added:[]}),d<u.length&&(c===h.length||l[c][d+1]>=l[c+1][d])?k.added.push(u[d++]):k.removed.push(h[c++]));return w}function Lt(t,a){let i=n=>n.filter(s=>s.trim()).length,r=Ze(t,a);return{removed:r.reduce((n,s)=>n+i(s.removed),0),added:r.reduce((n,s)=>n+i(s.added),0),lines:i(t.split(`
13
+ `))}}function Ve(t,a){let i=0,r=0;for(let[n,s]of t.entries())if(n>0&&i>0&&i<a&&r++,i+=s.replace(/\s+/g,"").length,i>=a)break;return r}function Mt(t,a){let i=r=>r.filter(n=>!n.trim()).length;for(let{removed:r,added:n}of Ze(t,a,(s,p)=>s.trim()===p.trim())){if(i(n)>i(r))return"a line left blank";let[s,p]=[r.join("").replace(/\s+/g,""),n.join("").replace(/\s+/g,"")],h=0;for(;h<s.length&&h<p.length&&s[h]===p[h];)h++;let u=0;for(;u<s.length-h&&u<p.length-h&&s[s.length-1-u]===p[p.length-1-u];)u++;for(let[l,w,k]of[[h,r,n],[u,r.toReversed(),n.toReversed()]]){let[c,d]=[Ve(w,l)+1,Ve(k,l)+1];if(c!==d)return`${c} line${c===1?"":"s"} became ${d}`}}return null}function Dt(t,{source:a,found:i,at:r,findings:n}){let s=Ie(a,ze(me(a),i)[r],t.parts,new Map([[i.id,i]]));if(!s)return[{kind:"refused"}];let p=Object.keys(t.parts),h=s.map(({start:l,end:w,text:k},c)=>({name:p[c],before:a.slice(l,w),after:k}));return[{kind:"wrote",back:!n.some(({kind:l})=>l==="undo"||l==="moving"),parts:h.map(({name:l,before:w,after:k})=>({name:l,...Lt(w,k)}))},...h.flatMap(({name:l,before:w,after:k})=>{let c=Mt(w,k);return c?[{kind:"laid",part:l,how:c}]:[]})]}var Pt=2e3;function Rt({match:t,instance:a,at:i,most:r}){let n=[...document.querySelectorAll(t)].filter(s=>!s.parentElement.closest(a))[i];return n?[window,document,n,...n.querySelectorAll("*")].slice(0,r):[]}function Ct(t){return t.map((a,i)=>i<2?{parent:i-1,named:""}:{parent:i===2?1:t.indexOf(a.parentElement),named:`<${a.localName}${a.classList.length?` class="${a.getAttribute("class")}"`:""}>`})}function It(){let t=new DragEvent("dragenter",{bubbles:!0,cancelable:!0,composed:!0,dataTransfer:new DataTransfer});return this.dispatchEvent(t),t.defaultPrevented}async function Ft(t,{match:a,at:i}){let r=new Map,n=({scriptId:s,url:p})=>r.set(s,p);t.on("Debugger.scriptParsed",n);try{await t.send("Debugger.enable"),await t.send("Debugger.setSkipAllPauses",{skip:!0});let{result:s}=await t.send("Runtime.evaluate",{expression:`(${Rt})(${JSON.stringify({match:a,instance:ke,at:i,most:Pt})})`,objectGroup:"drops"}),{result:p}=await t.send("Runtime.callFunctionOn",{objectId:s.objectId,functionDeclaration:String(Ct),arguments:[{objectId:s.objectId}],returnByValue:!0}),{result:h}=await t.send("Runtime.getProperties",{objectId:s.objectId,ownProperties:!0}),u=h.filter(({name:c,value:d})=>/^\d+$/.test(c)&&d?.objectId).sort((c,d)=>Number(c.name)-Number(d.name)),l=[];for(let{value:c}of u)l.push((await t.send("DOMDebugger.getEventListeners",{objectId:c.objectId})).listeners);let w=(c,d)=>l[c]?.some(T=>T.type===d),k=[];for(let c=2;c<l.length;c++){let d=l[c].find(g=>g.type==="dragover"&&r.get(g.scriptId)==="kit.js");if(!d)continue;let T=!1;for(let g=c;g>=2&&!T;g=p.value[g].parent)T=w(g,"dragenter");if(!T&&(w(0,"dragenter")||w(1,"dragenter"))){let{result:g}=await t.send("Runtime.callFunctionOn",{objectId:u[c].value.objectId,functionDeclaration:String(It),returnByValue:!0});T=g.value===!0}T||k.push({kind:"drops",what:p.value[c].named,line:d.lineNumber+1})}return k}finally{t.off("Debugger.scriptParsed",n),await t.send("Runtime.releaseObjectGroup",{objectGroup:"drops"}).catch(()=>{}),await t.send("Debugger.disable").catch(()=>{})}}function _t(t,a){let i={errors:new Map,notes:new Set,failed:new Set,dialogs:new Set,windows:0,opened:[],asked:1,pending:[]},r=n=>{let[s]=n.split(`
14
+ `);i.errors.has(s)||i.errors.set(s,Number(/\bkit\.js:(\d+)/.exec(n)?.[1])||null)};return t.on("pageerror",n=>r(n.stack??n.message)),t.on("console",n=>{let s=n.type();!["error","warn","warning"].includes(s)||!Be(n,a,["kit.js"])||i.pending.push(Promise.all(n.args().map(p=>p.evaluate(h=>h instanceof Error?h.stack:String(h)).catch(()=>""))).then(p=>{let h=p.join(" ")||n.text();s==="error"?r(h):i.notes.add(h.split(`
15
+ `)[0])}))}),t.on("requestfailed",n=>{n.frame()===t.mainFrame()&&!n.isNavigationRequest()&&i.failed.add(n.url())}),t.on("request",n=>{n.isNavigationRequest()&&n.frame()===t.mainFrame()&&i.opened.push(n.url())}),i}async function Ht(t,a){let i=await t.createCDPSession();return await i.send("Page.enable"),i.on("Page.javascriptDialogOpening",({type:r})=>{a.add(r),i.send("Page.handleJavaScriptDialog",{accept:!1}).catch(()=>{})}),i}function O(t,a,i=ye){let r=0,n=()=>Object.assign(new Error(a),{stuck:!0,doing:a}),s=new Promise((h,u)=>{r=setTimeout(()=>u(n()),i)}),p=t.catch(h=>{throw yt.has(h.name)?n():Object.assign(h,{doing:a})});return Promise.race([p,s]).finally(()=>clearTimeout(r))}var et=t=>new Promise(a=>{if(!t.connected)return a(!0);t.once("disconnected",()=>a(!0)),setTimeout(()=>a(!1),Xe)});function Bt({match:t,instance:a}){let{clientWidth:i,scrollWidth:r}=document.documentElement;if(r<=i+1)return null;let n=[...document.querySelectorAll(t)].filter(s=>!s.parentElement.closest(a));return{wide:r,at:n.findIndex(s=>[s,...s.querySelectorAll("*")].some(p=>p.getBoundingClientRect().right>i+1))}}var Je=16,Wt="#8f8f8f";async function qt(t,a,i){let r=await Promise.all(a.map(async n=>`data:image/png;base64,${(await D.readFile(n)).toString("base64")}`));await t.setViewport({width:ne.reduce((n,s)=>n+s,0)+Je*(ne.length-1),height:900}),await t.setContent(`<!doctype html><body style="margin: 0; display: flex; align-items: flex-start; gap: ${Je}px; background: ${Wt}">${r.map((n,s)=>`<img src="${n}" width="${ne[s]}" alt="" style="display: block">`).join("")}</body>`,{waitUntil:"load"}),await t.screenshot({path:i,fullPage:!0})}async function Gt(t,{file:a,html:i,source:r,places:n,found:s,out:p,loading:h}){let u=await t.createBrowserContext(),l=await u.newPage(),w=Ye(a).href,k=_t(l,w),c=await Ht(l,k.dialogs);u.on("targetcreated",g=>{g.type()==="page"&&(k.windows+=1,g.page().then($=>$?.close()).then(()=>l.bringToFront()).catch(()=>{}))});let d={heard:k,blocked:[],late:[],taken:[],overviews:[],edited:[],asExport:[],answers:[],wide:[],stuck:null,stopped:null,gone:null},T=async g=>d.late.push(...await O(Ge(l,{timeout:Ke}),g,3*Ke+ye));await We(l),await l.setViewport({width:736,height:900}),await l.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]);try{await O(l.goto(w,{waitUntil:"load",timeout:0}),"the page opened",h),await T("the page opened");for(let f of ge){await O(l.emulateMediaFeatures([{name:"prefers-color-scheme",value:f}]),`the ${f} theme came`);for(let x of ne){if(await O(l.setViewport({width:x,height:900}),`the window went to ${x}px`),await T(`it was drawn at ${x}px`),f===ge[0]){let q=await O(l.evaluate(Bt,{match:s.match,instance:ke}),`it was measured at ${x}px`);q&&d.wide.push({width:x,...q})}let P=S.join(p,`${x}-${f}.png`);await O(l.screenshot({path:P,fullPage:!0}),`it was pictured at ${x}px`),d.taken.push(P)}}await O(l.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came"),await O(l.setViewport({width:736,height:900}),"the window went to 736px");let g=Qe(i,s),$=s.files.includes("kit.js")&&Object.values(s.parts).some(({edit:f})=>f==="data");for(let f=0;f<g.length;f++){let x=await O(l.evaluate(jt,{match:s.match,instance:ke,slotPart:lt,slotName:rt,fallback:it,parts:s.parts,at:f,source:g[f].markup,still:ft,step:wt,times:mt,typed:gt,typing:kt}),"an instance was put back"),P=x.find(({kind:R})=>R==="wrote"),q=[...x.filter(R=>R!==P),...P?Dt(P,{source:r,found:s,at:f,findings:x}):[]];$&&!x.some(({kind:R})=>R==="gone"||R==="fallback")&&q.push(...await O(Ft(c,{match:s.match,at:f}),"the page was asked what an instance listens to")),d.answers.push(...q.map(R=>({finding:R,place:n[f]})))}d.blocked=await O(l.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"),k.asked+=1,await O(l.goto(w,{waitUntil:"load",timeout:0}),"the page opened again",h),await T("the page opened again"),await O(l.evaluate(()=>dispatchEvent(new Event("doc-editable"))),"the page was told it takes edits"),await T("it was drawn as the editing page draws it");for(let f of pt){await O(l.setViewport({width:f,height:900}),`the window went to ${f}px`),await T(`it was drawn at ${f}px as the editing page draws it`);let x=S.join(p,`edit-${f}-light.png`);await O(l.screenshot({path:x,fullPage:!0}),`it was pictured at ${f}px as the editing page draws it`),d.edited.push(x),(await D.readFile(x)).equals(await D.readFile(S.join(p,`${f}-light.png`)))&&d.asExport.push(x)}d.blocked.push(...await O(l.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"));for(let f of ge){let x=S.join(p,`overview-${f}.png`);await O(qt(l,ne.map(P=>S.join(p,`${P}-${f}.png`)),x),`the ${f} pictures were put side by side`),d.overviews.push(x)}}catch(g){if(g.syscall)throw g;await et(t)?d.gone=g.doing??"the page answered":g.stuck?d.stuck=g.doing:d.stopped=$e(g)}return await Promise.race([Promise.all(k.pending),new Promise(g=>setTimeout(g,Xe).unref())]),d}var Ut=(t,a)=>t.startsWith(a)?t.slice(a.length):t;function Kt(t,a,i){let r=new Map;for(let{url:n,directive:s,source:p,line:h}of t){if($t.test(n)){let l=!p&&h>0;r.set(`${n}|${p}|${h}`,{file:l?"kit.js":"the page",...l?{line:h}:{},what:"the export's policy blocks code made from words (eval, new Function, a string given to setTimeout): an export runs none"});continue}let u=/^[a-z][a-z0-9+.-]*$/.test(n)?a.filter(l=>l.startsWith(`${n}:`)):[];for(let l of u.length?u:[n])r.set(`${l}|${s}`,{file:"the page",what:`the export's policy blocks ${Ut(l,i)||"something"} (${s}): ${s==="img-src"?"a picture of an instance is a data: address, or a file its style names":"an export holds all it needs"}`})}return[...r.values()]}function Vt({heard:t,blocked:a,late:i,answers:r,wide:n,stuck:s,stopped:p},{places:h,script:u,folder:l}){let w=At(r).map(({finding:$,place:f})=>Nt($,f,{script:u})),k=[...t.failed],c=k.filter($=>!a.some(f=>f.url&&$.startsWith(f.url))),d=t.opened.length>t.asked?"it loads itself again (location.reload(), a new location.href), so a reader's page would not stay":s?`it stopped answering while waiting until ${s}${u?": a script that never ends, or a component that changes what it hears (a text part, on its source signal)":""}`:p&&`the look at it stopped: ${p}`,T=n.map(({width:$,wide:f})=>`${f}px wide in a ${$}px window`).join(", "),g=h[n.find(({at:$})=>$>=0)?.at]??{file:"the page"};return{problems:[...[...t.errors].map(([$,f])=>({file:f?"kit.js":"the page",line:f,what:`the console says ${$}`})),...Kt(a,k,l),...c.map($=>({file:"the page",what:`it could not load ${$.slice(0,120)}`})),...[...t.dialogs].map($=>({file:"the page",what:`it opens a dialog (${$}), which stops a reader's page until it is answered: show what it says in the instance`})),...t.windows?[{file:"the page",what:"it opens a window, which takes a reader away from the page: show it in the instance, or link to it"}]:[],...d?[{file:"the page",what:d}]:[],...n.length?[{...g,what:`the page is ${T}: a reader scrolls the whole page sideways, and gallery qa fails it: let it fit the window (max-width: 100%), or put what is wider in a frame of its own that scrolls`}]:[],...w.filter(({note:$,told:f})=>!$&&!f)],notes:[...[...t.notes].map($=>({file:"the page",what:`the console says ${$}`})),...w.filter(({note:$})=>$),...i.map($=>({file:"the page",what:`waited for ${$}`}))],told:w.filter(({told:$})=>$)}}async function ln(t,a,{example:i,template:r},{find:n=_e,start:s=qe,loading:p=ut}={}){let h=ht,u=null,l=null;try{u=await D.mkdtemp(S.join(Ue.tmpdir(),"gallery-component-check-"));let w=await Tt(a,{example:i,template:r},u),k=n();if(!k)return{title:h,unverified:"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one)"};try{l=await s({executablePath:k,args:He()})}catch(g){return{title:h,unverified:`the browser ${k} did not start, twice, each time with a fresh profile (${$e(g)}; GALLERY_BROWSER=<its executable> picks another)`}}let c=S.join(ct(t).qa,"components",...a.id.split("/"));await D.rm(c,{recursive:!0,force:!0}),await D.mkdir(c,{recursive:!0});let d=await Gt(l.browser,{...w,found:a,out:c,loading:p}),T=Vt(d,{places:w.places,script:a.files.includes("kit.js"),folder:Ye(`${u}${S.sep}`).href});return d.gone?{title:h,...T,unverified:`the browser went while waiting until ${d.gone}, so it says nothing of the package`}:{title:h,...T,...d.taken.length?{pictures:{folder:c,overviews:d.overviews.map(g=>S.basename(g)),each:d.taken.map(g=>S.basename(g)),edited:d.edited.map(g=>S.basename(g)),asExport:d.asExport.map(g=>S.basename(g))}}:{}}}catch(w){return w.reason==="check"?{title:h,problems:w.failures.map(k=>({file:"the export",what:k}))}:w.syscall?{title:h,unverified:`cannot write ${Fe(w.syscall==="mkdtemp"?Ue.tmpdir():w.path)} (${w.code})`}:l&&await et(l.browser)?{title:h,unverified:"the browser went before the page opened"}:{title:h,problems:[{file:"the page",what:`the look at it stopped: ${$e(w)}`}]}}finally{await l?.close(),u&&await D.rm(u,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{})}}export{ht as a,ut as b,ft as c,wt as d,$e as e,bt as f,Et as g,St as h,Lt as i,Mt as j,Ht as k,O as l,et as m,ln as n};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as O}from"./chunk-ITNLYXXV.mjs";import{a as M}from"./chunk-NFIBI4IP.mjs";var b=3e4,j=12e4,k=1500,S=1e4,W=h=>h.reduce((a,{key:c,tag:r})=>a.set(`${c}
2
+ import{b as O}from"./chunk-E7LWZRXY.mjs";import{a as M}from"./chunk-L3QKH4OK.mjs";var b=3e4,j=12e4,k=1500,S=1e4,W=h=>h.reduce((a,{key:c,tag:r})=>a.set(`${c}
3
3
  ${r}`,(a.get(`${c}
4
4
  ${r}`)??0)+1),new Map);function U({now:h=Date.now,hold:a=b,limit:c=j,quiet:r=k}={}){let i=new Map,l=new Map,w=new Map,$=new Map,p=new Map;return{wrote(t,e){$.set(t,M(e))},judge(t,{source:e,mtime:m}){if(e===null)return i.delete(t),w.delete(t),{held:!1,signs:[],wait:0,own:!1};let d=M(e),n=p.get(t)?.hash===d?p.get(t).signs:null;n||(n=O(e),p.set(t,{hash:d,signs:n}));let f=h(),x=(o,s=!1)=>(i.delete(t),l.set(t,W(n)),w.set(t,e),{held:!1,signs:[],wait:o,own:s});if($.get(t)===d)return x(0,!0);let g=l.get(t)??new Map,I=W(n);if([...I].some(([o,s])=>s>(g.get(o)??0))){let o=Math.min(m,f),s=i.get(t)??o;i.set(t,s);let T=Math.min(a-(f-o),c-(f-s));if(T>0)return{held:!0,signs:n.filter(({key:D,tag:L})=>I.get(`${D}
5
5
  ${L}`)>(g.get(`${D}
@@ -0,0 +1,7 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{k as st}from"./chunk-6QXGZM36.mjs";import{a as ot}from"./chunk-UMHUSOPJ.mjs";import I from"node:fs/promises";import ct from"node:path";import{writeAtomic as lt}from"../browser/shared/files.mjs";import{documentFiles as ht}from"../browser/shared/workspace.mjs";var kt=l=>I.access(l).then(()=>!0,()=>!1);async function Dt(l,{create:p,slugOf:c,folderOf:O,fill:L,place:U,under:b="",said:o="\u5BFC\u5165\u81EA {0}",lang:$=null}){let F=[],S=[];async function h(u,P,B){let E=await c(u,B);await p(E,u.title,o.replace("{0}",()=>u.from),{lang:$});let J=O(E),{html:W,json:T}=ht(J),k=await I.readFile(W,"utf8");await lt(W,st(await L({source:k,nodes:u.nodes,icon:u.icon,own:u.own,raws:u.raws,lang:u.lang}))),u.files.length&&await I.mkdir(ct.join(J,"assets"),{recursive:!0});for(let{from:g,name:Z}of u.files){let A=ct.join(J,"assets",Z);await kt(A)||await I.copyFile(g,A)}if(u.icon){let g=JSON.parse(await I.readFile(T,"utf8"));await lt(T,`${JSON.stringify({...g,icon:u.icon},null,2)}
3
+ `)}await U(E,P),F.push(E);for(let g of u.children??[])await h(g,E,null);return E}for(let[u,P]of l.entries())S.push(await h(P,b,u));return{made:F,top:S}}import{randomBytes as Ot}from"node:crypto";import d from"node:fs/promises";import m from"node:path";import{writeAtomic as G}from"../browser/shared/files.mjs";import{sendJson as Y}from"../browser/shared/http.mjs";import{said as z,saying as jt}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as gt}from"../browser/shared/paths.mjs";import{moveDocument as vt,readOutline as bt,validOutline as ut,withOutlineLock as St,writeOutline as xt,writtenAs as Nt}from"../browser/shared/outline.mjs";import{sameDirectory as Et}from"../browser/shared/preview-server.mjs";import{listReportSlugs as Ft,slugPattern as N}from"../browser/shared/reports.mjs";import{COMPONENTS_FOLDER as D,DOCUMENT_FOLDERS as Pt,PAGE_SLUG as At,documentDirectory as Lt,documentFiles as V,layoutOf as $t,listTrash as Jt,packageFolders as Tt,pageSlug as Mt,slugTaken as Rt,trashIdPattern as ft}from"../browser/shared/workspace.mjs";import{effectiveLook as tt,ownLookFor as Ct,ownLookOf as It,sameLook as Gt,withLookField as wt}from"../browser/shared/document-look.mjs";import{workspaceLook as nt,writeWorkspaceLook as Ut}from"../browser/shared/workspace-look.mjs";import{MENTION as Bt}from"../browser/shared/components/mention.mjs";import{findIn as Wt,reportLines as _t,tidyQuery as Ht}from"../browser/shared/search.mjs";import{countWords as Kt}from"../browser/shared/words.mjs";var Qt=([l,p,c,...O])=>O.length?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",l,p,c,O.length+3):c!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",l,p,c):p!==void 0?z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",l,p):z("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",l),mt=l=>l==="en"?"en":null;async function X(l,p){for(let c=0;;c++)try{return await d.rename(l,p)}catch(O){if(!["EPERM","EBUSY","EACCES"].includes(O.code))throw O;if(c>=5)break;await new Promise(L=>setTimeout(L,60*(c+1)))}await d.cp(l,p,{recursive:!0,errorOnExist:!0,force:!1}),await d.rm(l,{recursive:!0,force:!0,maxRetries:5})}var Yt=l=>m.resolve(l);function On({edits:l,reports:p,reportsDirectory:c=gt,server:O={kind:"dev",version:null,stop:null},components:L=null,changed:U=()=>{}}){let{trash:b}=$t(c),o=(t,n,e)=>[t,{ok:!1,reason:n,...jt(e)}],$=t=>d.readFile(t,"utf8").then(JSON.parse).catch(()=>null),F=t=>Lt(t,c),S=t=>V(F(t)),h=t=>m.join(c,t),u=t=>A(V(h(t)).html),P=t=>Promise.resolve(l.forgetChanges?.(t)).catch(()=>{}),B=async t=>{let n=await d.readdir(h(t),{withFileTypes:!0});if(t!==D)return n.map(({name:r})=>r);let e=new Set(Tt(c).map(({id:r})=>r.split("/")[0]));return n.filter(r=>r.isFile()||Pt.includes(r.name)&&!e.has(r.name)).map(({name:r})=>r)},E=async(t,n,e)=>{await d.mkdir(e,{recursive:!0});let r=[];try{for(let i of t)await X(m.join(n,i),m.join(e,i)),r.push(i)}catch(i){for(let a of r)await X(m.join(e,a),m.join(n,a));throw i}},J=async(t,n)=>{if(t!==D)return X(h(t),n);await E(await B(t),h(t),n),await d.rmdir(h(t)).catch(()=>{})},W=async(t,n)=>t===D&&!await u(t)&&(await Promise.all((await d.readdir(n)).map(e=>A(m.join(h(t),e))))).every(e=>!e),T=async t=>await $(V(t).json)??{},k=async t=>{let{title:n=t,description:e="",type:r,instructions:i,icon:a,look:s}=await T(F(t)),y=i===!0?{}:tt(s,nt(c));return{slug:t,title:n,description:e,...r?{type:r}:{},...typeof a=="string"&&a?{icon:a}:{},...i===!0?{instructions:!0}:{},...Object.keys(y).length?{look:y}:{}}},g=()=>Mt(c),Z=async(t,n)=>{let e=await T(F(t));await G(S(t).json,`${JSON.stringify({...e,[n]:!0},null,2)}
4
+ `)},A=t=>d.access(t).then(()=>!0,()=>!1),M=async(t,{own:n=null}={})=>{let e=new Set((await R()).map(({slug:r})=>r));e.delete(n);for(let r=1;;r++){let i=r===1?t:`${t}-${r}`;if(!Rt(i,c)&&!e.has(i))return i}},et=async(t,n)=>{let e=S(t).html,r=await d.readFile(e,"utf8"),i=ot(r).replace(`data-doc-id="${n}"`,`data-doc-id="${t}"`);i!==r&&await G(e,i)},x=()=>bt(c),_=async t=>{await xt(c,t),U()},H=t=>St(c,t);async function K(t,n="",e=1/0){await H(async()=>{let r=await x();for(let s of Object.values(r.children))s.includes(t)&&s.splice(s.indexOf(t),1);let i=n!==t&&(n===""||Object.values(r.children).some(s=>s.includes(n))),a=r.children[i?n:""]??=[];a.splice(Math.max(0,Math.min(e,a.length)),0,t),await _(r)})}function dt(t){return H(async()=>{let n=await x();for(let[e,r]of Object.entries(n.children)){let i=r.indexOf(t);if(!(i<0))return r.splice(i,1,...n.children[t]??[]),delete n.children[t],await _(n),{parent:e,index:i}}return{parent:"",index:1/0}})}let rt=new Map;async function yt(t,n){let e=S(t).html,r=await d.stat(e).catch(()=>null);if(!r)return null;let i=rt.get(t);if(i?.at===r.mtimeMs&&(i.titles===null||i.titles===n))return i.lines;let a=(await l.read(t))?.text??"",s=_t(p.words(a,t));return rt.set(t,{at:r.mtimeMs,titles:a.includes(Bt)?n:null,lines:s}),s}let it=t=>$(m.join(b,t,"entry.json")),R=()=>Jt(c),at={info:async()=>[200,{ok:!0,version:1,gallery:O.version,token:l.token,commands:[...Object.keys(q)],server:{pid:process.pid,workspace:m.resolve(c),kind:O.kind}}],async outline(){let t=await x(),n=await g(),e=[...Object.values(t.children).flat(),...n?[n]:[]],r=async i=>[i,await k(i)];return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(await Promise.all(e.map(r))),trash:await R()}]},trash:async()=>[200,{ok:!0,entries:await R()}],async stats(t){let n=t.get("slug")??"",e=N.test(n)?S(n).html:"",[r,i]=N.test(n)?await Promise.all([d.stat(e),l.read(n)]).catch(()=>[]):[];return!r||!i?o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):[200,{ok:!0,edited:Math.round(r.mtimeMs),words:Kt(i.text)}]},components:async()=>[200,{ok:!0,...L.read()}],async source(t){let n=t.get("slug")??"";if(!N.test(n))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=m.resolve(S(n).html);return await A(e)?[200,{ok:!0,path:e}]:o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async search(t){let n=Ht(t.get("q")??"");if(!n)return[200,{ok:!0,results:[]}];let{children:e}=await x(),r=[],i=w=>(e[w]??[]).forEach(j=>{r.push(j),i(j)});i("");let a=n.toLowerCase(),s=new Map(await Promise.all(r.map(async w=>[w,await k(w)]))),y=JSON.stringify([...s].map(([w,{title:j}])=>[w,j])),f=(await Promise.all(r.map(async w=>{let j=await yt(w,y);if(!j)return null;let C=String(s.get(w).title).toLowerCase().includes(a),{count:v,hits:Q}=Wt(j,n);return C||v?{slug:w,title:C,count:v,hits:Q}:null}))).filter(Boolean);return f.sort((w,j)=>Number(j.title)-Number(w.title)||j.count-w.count),[200,{ok:!0,results:f.slice(0,50)}]}},q={async outline({outline:t,base:n}){return!ut(t)||n!==void 0&&!ut(n)?o(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):await H(async()=>n!==void 0&&!Nt(n.children,(await x()).children)?!1:(await _(t),!0))?[200,{ok:!0,outline:await x()}]:o(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7")},async move({slug:t,parent:n,after:e=null,first:r=!1,workspace:i}){if(typeof i=="string"&&!Et(i,c))return o(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let a=f=>typeof f=="string"&&N.test(f);if(!a(t)||n!==void 0&&n!==""&&!a(n)||e!==null&&!a(e)||typeof r!="boolean")return o(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let s=await g();if(s!==null&&[t,n,e].includes(s))return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let y=await vt(c,t,{parent:n,after:e,first:r});if(y.written&&U(),!y.ok){let[f,w]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"]}[y.reason];return o(f,y.reason,w)}return[200,{ok:!0,...y,outline:await x()}]},async create({title:t,description:n,parent:e="",language:r}){let i=typeof t=="string"&&t.trim()?t.trim():"\u672A\u547D\u540D\u6587\u6863",a=await M("doc");return await P(a),await p.create(a,i,typeof n=="string"&&n.trim()?n.trim():"\u65B0\u6587\u6863",{lang:mt(r)}),await K(a,typeof e=="string"?e:""),[200,{ok:!0,report:await k(a)}]},async instructions({title:t,description:n,language:e}){let r=await g();if(r)return[200,{ok:!0,report:await k(r)}];let i=await M(At),a=(s,y)=>typeof s=="string"&&s.trim()?s.trim().slice(0,200):y;return await p.create(i,a(t,"\u5199\u4F5C\u504F\u597D"),a(n,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:mt(e),page:!0}),await Z(i,"instructions"),[200,{ok:!0,report:await k(i)}]},async components({id:t,hidden:n,disabled:e}){try{return[200,{ok:!0,...await L.write({id:t,hidden:n,disabled:e})}]}catch(r){return o(409,"components",r)}},async duplicate({slug:t,suffix:n}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await M(`${t}-copy`);await P(e);let r=new Set(["",...await B(t)]);await d.cp(h(t),h(e),{recursive:!0,errorOnExist:!0,filter:w=>r.has(m.relative(h(t),w).split(m.sep)[0])}),await et(e,t);let{title:i}=await k(t),a=await l.renameReport(e,`${i}${typeof n=="string"&&n.length>0&&n.length<=20?n:"\uFF08\u526F\u672C\uFF09"}`),s=await x(),[y,f]=Object.entries(s.children).find(([,w])=>w.includes(t))??["",null];return await K(e,y,f?f.indexOf(t)+1:1/0),[200,{ok:!0,report:await k(e),notes:a.notes??[]}]},async look({slug:t,look:n}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await g())return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(n!==null&&(typeof n!="object"||Array.isArray(n)))return o(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let e=S(t).json,r=null;try{r=JSON.parse(await d.readFile(e,"utf8"))}catch{}if(!r||typeof r!="object"||Array.isArray(r))return o(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let i=wt(r,Ct(n,nt(c)));return JSON.stringify(i)!==JSON.stringify(r)&&await G(e,`${JSON.stringify(i,null,2)}
5
+ `),[200,{ok:!0,report:await k(t)}]},async looks({slug:t}){if(typeof t!="string"||!N.test(t)||!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let n=await g();if(t===n)return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let e=await $(S(t).json);if(!e||typeof e!="object"||Array.isArray(e))return o(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=nt(c),i=tt(e.look,r);try{await Ut(c,i)}catch(f){return o(409,"workspace",f)}let a=0,s=(await Ft(c)).filter(f=>f!==n).map(f=>({json:S(f).json,self:f===t})),y=(await R()).map(({id:f})=>({json:V(m.join(b,f,"report")).json,self:!1}));for(let{json:f,self:w}of[...s,...y])for(let j=0;j<3;j++){let C=await d.readFile(f,"utf8").catch(()=>null),v=null;try{v=JSON.parse(C??"")}catch{}if(!v||typeof v!="object"||Array.isArray(v)||!Object.hasOwn(v,"look")||v.instructions===!0)break;let Q=await G(f,`${JSON.stringify(wt(v,{}),null,2)}
6
+ `,{expect:C}).catch(()=>null);if(Q===null)break;if(Q){!w&&Object.keys(It(v.look)).length>0&&!Gt(tt(v.look,r),i)&&a++;break}}return[200,{ok:!0,look:i,replaced:a,report:await k(t)}]},async rename({slug:t,title:n}){if(typeof t!="string"||!N.test(t))return o(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");let e=await l.renameReport(t,n);return e.ok?[200,{ok:!0,report:await k(t),notes:e.notes}]:o({title:400,missing:404}[e.reason]??409,e.reason,e.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t}){if(typeof t!="string"||!N.test(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await g())return o(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await u(t))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await k(t),e=`${Date.now().toString(36)}-${Ot(3).toString("hex")}`,r=await x(),{parent:i,index:a}=await dt(t);try{await d.mkdir(m.join(b,e),{recursive:!0}),await J(t,m.join(b,e,"report"))}catch(y){throw await H(()=>_(r)),await d.rm(m.join(b,e),{recursive:!0,force:!0}).catch(()=>{}),y}let s={id:e,slug:t,title:n,at:Date.now(),parent:i,index:Number.isFinite(a)?a:-1};return await G(m.join(b,e,"entry.json"),`${JSON.stringify(s,null,2)}
7
+ `),[200,{ok:!0,entry:s}]},async restore({id:t}){let n=typeof t=="string"&&ft.test(t)?await it(t):null;if(!n)return o(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");let e=m.join(b,t,"report"),r=await W(n.slug,e),i=r?n.slug:await M(n.slug,{own:n.slug});return r?await E(await d.readdir(e),e,h(i)):await X(e,h(i)),i!==n.slug&&await et(i,n.slug),await d.rm(m.join(b,t),{recursive:!0,force:!0}),await K(i,n.parent,n.index<0?1/0:n.index),[200,{ok:!0,report:await k(i),entry:{...n,slug:i}}]},async destroy({id:t}){let n=typeof t=="string"&&ft.test(t)?await it(t):null;return n?(await u(n.slug)||await P(n.slug),await d.rm(m.join(b,t),{recursive:!0,force:!0}),[200,{ok:!0}]):o(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async export({slug:t}){if(typeof t!="string"||!N.test(t)||!await A(F(t)))return o(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:n=[],file:e,refused:r}=await p.export(t);return r?o(r.reason==="missing"?404:409,r.reason,r.message):n.length?o(422,"check",Qt(n)):[200,{ok:!0,path:Yt(e)}]}};function pt(t,n,e){if(t.method==="GET"&&Object.hasOwn(at,e)){let r=t.headers.host??"",i=t.socket.localPort;return r!==`127.0.0.1:${i}`&&r!==`localhost:${i}`?Y(n,403,{ok:!1,reason:"host"}):at[e](new URL(t.url??"/","http://localhost").searchParams).then(([a,s])=>Y(n,a,s),a=>Y(n,...o(500,"read",a)))}return t.method==="POST"&&e==="stop"?l.respond(async r=>{let i=await l.check(r);return i.error?i.error:O.kind!=="cli"||typeof O.stop!="function"?o(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(n.once("finish",()=>O.stop()),[200,{ok:!0,pid:process.pid}])})(t,n):t.method==="POST"&&Object.hasOwn(q,e)?l.respond(async r=>{let i=await l.check(r);return i.error?i.error:q[e](i.body&&typeof i.body=="object"?i.body:{})})(t,n):Y(n,404,{ok:!1,reason:"unknown"})}return{handle:pt,outline:x,trashEntries:R,place:K,freeSlug:M}}export{Dt as a,On as b};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as ae,f as le,n as ce}from"./chunk-PL6GHLGD.mjs";import{b as C,d as he}from"./chunk-LEF6DRCK.mjs";import{a as N}from"./chunk-TX6JH7TR.mjs";import"./chunk-DFUDV4LX.mjs";import"./chunk-E7LWZRXY.mjs";import"./chunk-64K7IPLO.mjs";import"./chunk-NSKUTQ5J.mjs";import{a as se,i as ne,r as oe}from"./chunk-AUZGSZJH.mjs";import{d as Z,e as Q,i as A,j as ee,k as te}from"./chunk-BGGDRNYQ.mjs";import{a as g}from"./chunk-6QXGZM36.mjs";import"./chunk-UALRNVSE.mjs";import"./chunk-W3BGBJQW.mjs";import"./chunk-JVHHHGEA.mjs";import{a as V,c as x}from"./chunk-HYMEEXKN.mjs";import"./chunk-TYK6VNAB.mjs";import{b as re,h as F}from"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import{c as ie}from"./chunk-L3QKH4OK.mjs";import{c as W,e as J,g as v,o as X}from"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{isUtf8 as Ne}from"node:buffer";import be from"node:fs";import j from"node:path";import{instancesOf as Y,isInstance as Ce,partOf as we}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as k,refusedInCopy as Ie}from"../browser/shared/components/installed.mjs";import{attr as I,elementsOf as ye,walk as P}from"../browser/shared/html-tree.mjs";import{blankedCss as z}from"../browser/shared/css-references.mjs";import{ATTRIBUTE as _,SLOT as me}from"../browser/shared/components/installed.mjs";var Le=new Set(["media","supports","container","layer","starting-style"]);function M(t,e){let s=0,n="";for(let o=0;o<t.length;o++){let i=t[o];i==="\\"?o++:n?n=i===n?"":n:i==='"'||i==="'"?n=i:i===")"||i==="]"?s--:(s===0&&e(i,o),(i==="("||i==="[")&&s++)}}function Ee(t){let e=z(t),s=z(t,{strings:!0}),n={children:[]},o=[n],i=0,a=0;for(let r=0;r<e.length;r++){let l=e[r];if(l==="\\")r++;else if(l==="("||l==="[")a++;else if(l===")"||l==="]")a=Math.max(0,a-1);else{if(a>0)continue;if(l==="{"){let c={prelude:s.slice(i,r),start:i,children:[]};o.at(-1).children.push(c),o.push(c),i=r+1}else l==="}"?(o.length>1&&o.pop(),i=r+1):l===";"&&(i=r+1)}}return n.children}function B(t){let e=[],s=0;return M(t,(n,o)=>{n===","&&(e.push({text:t.slice(s,o),start:s}),s=o+1)}),e.push({text:t.slice(s),start:s}),e.filter(({text:n})=>n.trim())}function D(t){let e=[],s=t.trim(),n="",o=0,i=0,a=r=>{(i||r)>o&&e.push({combinator:n,compound:s.slice(o,i||r)}),i=0};return M(s,(r,l)=>{/\s/.test(r)?l===o?o=l+1:i||=l:">+~".includes(r)?(a(l),n=r,o=l+1):i&&(a(l),n=" ",o=l)}),a(s.length),e}function U(t){let e=[],s=-1,n=0,o="";for(let a=0;a<t.length;a++){let r=t[a];r==="\\"?a++:o?o=r===o?"":o:r==='"'||r==="'"?o=r:r==="("?n++:r===")"?n--:r==="["&&n===0?s=a:r==="]"&&n===0&&s>=0&&(e.push(t.slice(s,a+1)),s=-1)}let i=!1;return M(t,a=>{i||=a==="&"}),{attributes:e,nesting:i,scope:/(?:^|[^\w-]):scope\b/.test(t)}}var Oe=t=>new RegExp(`^\\[\\s*${_}\\s*=\\s*(["'])${t.replace(/[/-]/g,"\\$&")}\\1\\s*i?\\s*\\]$`,"i"),je=t=>z(t).replace(/\\.|\[[^\]]*\]/g,"").includes("&");function pe(t,e,s,n=!1){let o=D(t),i=({compound:f})=>U(f).attributes.some(h=>e.test(h)),a=({compound:f})=>{let{nesting:h,scope:m}=U(f);return!!s&&(h||m)},r=f=>["+","~"].includes(f?.combinator),l=f=>o.slice(f).some(({combinator:h},m)=>(m+f===0?h||" ":h)===" "),c=o.findLastIndex(f=>i(f)||a(f));if(c<0)return!s||je(t)?{why:"outside"}:{why:s==="instance"&&r(o[0])?"beside":null,subject:"inside",deep:n||l(0)};let p=i(o[c])||s==="instance";return{why:p&&r(o[c+1])?"beside":null,subject:p&&c===o.length-1?"instance":"inside",deep:!i(o[c])&&n||l(c+1)}}var fe=t=>t.some(({subject:e})=>e==="instance")?"instance":"inside",Te=new RegExp(`^\\[\\s*${me}\\s*(?:\\]|=)`,"i"),Ae=t=>B(/\)\s*to\s*\(([^)]*)\)/i.exec(t)?.[1]??"").some(({text:e})=>D(e).length===1&&U(e).attributes.some(s=>Te.test(s))),ue=(t,e)=>ge(t,e).outside;function de(t,e,s){if(s.length===0)return[];let n=`slot${s.length===1?"":"s"} ${s.join(" and ")}`;return ge(t,e).deep.map(({line:o,words:i})=>({line:o,what:`${i} also reaches the blocks in ${n}, the document's: write each step with > or wrap the rules in @scope ([${_}="${e}"]) to ([${me}])`}))}function ge(t,e){let s=Oe(e),n=`[${_}="${e}"]`,o=[],i=[],a=(l,c,p)=>{let f=c.replace(/\s+/g," ").trim();o.push({line:x(t,l),what:p==="beside"?`${f} reaches what stands beside the instance: what it styles has to stand in it`:`${f} reaches outside the instance: start it at ${n}`})},r=(l,c,p=!1,f=!1)=>{for(let h of l){let m=h.prelude.length-h.prelude.trimStart().length,d=h.start+m,$=/^@([\w-]+)\s*/.exec(h.prelude.trim());if($){let u=$[1].toLowerCase();if(Le.has(u))r(h.children,c,p,f);else if(u==="page")o.push({line:x(t,d),what:"@page reaches the paper of the whole document: an instance has no page of its own"});else if(u==="scope"){let y=/^@scope\s*\(([^)]*)\)/i.exec(h.prelude.trim())?.[1]??"",S=B(y).map(({text:L})=>({...pe(L,s,c),steps:D(L).length}));y&&S.every(({why:L,steps:Se})=>!L&&Se===1)?r(h.children,fe(S),!1,f||Ae(h.prelude.trim())):a(d,h.prelude,"outside")}continue}let b=B(h.prelude).map(({text:u,start:y})=>{let S=pe(u,s,c,p),L=h.start+y+u.length-u.trimStart().length;return S.why?a(L,u,S.why):S.deep&&!f&&!p&&i.push({line:x(t,L),words:u.replace(/\s+/g," ").trim()}),S});b.some(({why:u})=>u)||r(h.children,fe(b),b.some(u=>u.deep),f)}};return r(Ee(t),null),{outside:o,deep:i}}var w="template.html",E="example.html",R="component.json",Re=new Set(["localStorage","sessionStorage"]),Pe=/^\S+: (?:line \d+ of )?its (?:kit\.js|style\.css) /,ve=/(?: (?:names a file that )?is not in the document's folder|: it is (?:no file of|not in) the document's .*)$|^external resources are not portable: .*$/,Fe=": an example stands in no document: write a picture as a data: address, or draw it from style.css with a file the manifest's assets name",ze=t=>t.replace(ve,e=>(e.startsWith("external")?e:"")+Fe),O=(t,e)=>A({folder:t},e);function T(t,e){let s=null;try{s=be.readFileSync(j.join(t,e))}catch{return null}return Ne(s)?null:{file:e,what:"it is not UTF-8: save it as UTF-8 (PowerShell's > writes UTF-16; Set-Content -Encoding utf8 does not)"}}function G(t,e){let s=/^line (\d+): | \(line (\d+)\)/.exec(e);return s?{file:t,line:Number(s[1]??s[2]),what:e.replace(s[0],"")}:{file:t,what:e}}function H(t,e){let s=g.parseJsonText(R,t),n=s.statements[0]?.expression,o=null;for(let i of e.split(".")){let a=n?.properties?.find(({name:r})=>r?.text===i);if(!a)break;o=s.getLineAndCharacterOfPosition(a.getStart(s)).line+1,n=a.initializer}return o}function Be(t,{message:e,text:s="",values:n=[]}){let o=/at position (\d+)/.exec(e)?.[1];if(o)return x(t,Number(o));for(let i of[...n.map(String),...s.match(/[a-zA-Z][\w.]*/g)??[]]){let a=H(t,i);if(a)return a}return null}var Ue=t=>F(t).map(e=>/^line (\d+): <([^>]+)>: ([\s\S]*)$/.exec(e)).filter(Boolean).map(([,e,s,n])=>({line:Number(e),tag:s,why:n}));function _e(t,{file:e,tree:s,html:n}){let o=[],i=Ue(n),a=Object.entries(t.parts).filter(([,c])=>c.edit==="text"),r=Object.entries(t.parts).filter(([,c])=>c.edit==="data"),l=(c,p)=>{let f=!1;return P(c,h=>{f||=h===p}),f};for(let c of Y(s,t))for(let[p,f]of a)for(let h of we(c,f.at)){let m=h.sourceCodeLocation?.startLine,d=ye(h).find(u=>ie.has(u.tagName)),$=i.find(u=>u.line===m&&u.tag===h.tagName),b=r.find(([,u])=>we(c,u.at).some(y=>y===h||l(y,h)||l(h,y)))?.[0];b?o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and stands in the part ${b}, edited as data, or around it, which is the component's: the editor leaves it read-only: name elements apart`}):d?o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text and holds a block, its <${d.tagName}> at line ${d.sourceCodeLocation?.startLine}: a text part holds words and marks alone, and the editor would leave this one read-only: write its \`at\` as what holds the words (${f.at} > ${d.tagName}), or give each block a part of its own`}):$&&o.push({file:e,line:m,what:`the part ${p} (${f.at}) is edited as text, and the editor would leave it read-only for what it holds: ${$.why}. A text part holds words and marks alone`})}return o}var xe="(?:(?:[zcs]h|[bpmfdtnlgkhjqxrzcsyw])?(?:[iuv]?(?:a(?:i|o|ng?)?|e(?:i|r|ng?)?|o(?:u|ng)?)|i(?:u|ng?)?|u(?:i|n)?|vn?))",Me=new RegExp(`^${xe}$`,"i"),De=new RegExp(`^${xe}{1,8}$`,"i"),q=new RegExp("\\p{Script=Han}","u"),Ge=6,ke=t=>[...t].filter(e=>q.test(e)).length;function Ke(t){let e=t.replaceAll("'",""),s=[0,...Array(e.length).fill(1/0)];for(let n=1;n<=e.length;n++)for(let o=Math.max(0,n-Ge);o<n;o++)s[o]+1<s[n]&&Me.test(e.slice(o,n))&&(s[n]=s[o]+1);return e&&Number.isFinite(s[e.length])?s[e.length]:null}function He({name:t,words:e}){let s=ke(t.zh),n=e.split(/\s+/).filter(Boolean);return s===0?q.test(e)&&!n.some(o=>De.test(o)):!n.some(o=>Ke(o.toLowerCase())===s)}function Ye({id:t,folder:e,catalog:s,off:n,parts:o}){let i=s.packages.get(t),a=s.problems.get(t)?.problem,r=O(e,R)??"",l=[];a&&l.push({file:R,line:Be(r,a),what:v("en",a)}),i?.template===null&&l.push({file:w,what:`there is none, and it is what "/" puts in a document: with none, no menu offers the block: write one <div ${k}="${t}"> with what a new instance holds`}),l.push(...o);let c=T(e,"writing.md");c&&l.push(c);let p=c||O(e,"writing.md")?.trim()?[]:[{file:"writing.md",what:"there is none, so gallery component show has nothing to say of how to write it"}];return i&&He(i)&&p.push({file:R,line:H(r,"words")??H(r,"name.zh"),what:q.test(i.name.zh)?`no word of words spells its whole name ${i.name.zh} in pinyin as an input method composes it, its ${ke(i.name.zh)} Chinese characters a syllable each in one word (as \u65B9\u6848\u6253\u5206 is fangandafen): "/" finds it while those letters are being composed only by such a word. What is counted is how many syllables a word reads as, not which characters they spell`:'its words are Chinese and none of them is pinyin: "/" goes by the letters an input method is composing, so write the pinyin there (\u770B\u677F kanban)'}),n&&p.push({file:"gallery.json",what:"the user turned it off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, which is theirs to change and says nothing of the package: it is checked as if it were on, and the instances of a document show what they hold, read-only, until it is on"}),{title:"manifest",problems:l,notes:p}}function qe(t){let e=g.createSourceFile("kit.js",t,g.ScriptTarget.Latest,!0,g.ScriptKind.JS),s=[],n=o=>{let i=g.isCallExpression(o)&&g.isPropertyAccessExpression(o.expression)?o.expression:null;if(i?.name.text==="component"&&/\bDocKit$/.test(i.expression.getText(e))){let[a]=o.arguments,r=a&&g.isObjectLiteralExpression(a)?a.properties.find(c=>c.name?.getText(e)==="id"):null,l=r&&g.isPropertyAssignment(r)&&g.isStringLiteralLike(r.initializer)?r.initializer.text:null;s.push({id:l,at:o.getStart(e)})}g.forEachChild(o,n)};return n(e),s}function Ve(t){let e="kit.js";if(!t.files.includes("kit.js"))return{title:e,none:"none: a static block"};let s=T(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let n=A(t,"kit.js")??"",o=se(n);if(o)return{title:e,stops:!0,problems:[{file:e,line:o.line,what:`a browser refuses it: ${o.message}`}]};let i=te(t).map(({line:c,what:p})=>({file:e,line:c,what:p})),a=i.length>0;for(let{name:c,at:p}of Z(n,Re))i.push({file:e,line:x(n,p),what:`uses ${c}: an instance keeps what a reader chose with context.state`});let r=qe(n);for(let{id:c,at:p}of r)c!==null&&c!==t.id&&i.push({file:e,line:x(n,p),what:`it registers ${c}, and this package is ${t.id}`});let l=r.length?[]:[{file:e,what:`no DocKit.component({ id: "${t.id}", mount(host, context) { \u2026 } }) is to be read in it, and a script may make that call in ways reading does not tell: running it says whether it starts one`}];for(let{line:c,code:p,message:f,refused:h}of Q(n,{assets:t.assets}))(h?i:l).push({file:e,line:c,what:`TS${p}: ${f}`});return{title:e,stops:a,problems:i.sort((c,p)=>(c.line??0)-(p.line??0)),notes:l}}function We(t){let e="style.css";if(!t.files.includes("style.css"))return{title:e,none:"none"};let s=T(t.folder,e);if(s)return{title:e,stops:!0,problems:[s]};let n=A(t,"style.css")??"",o=ee(t),i=[...ue(n,t.id),...o].map(({line:l,what:c})=>({file:e,line:l,what:c})),a=Object.entries(t.parts??{}).filter(([,{edit:l}])=>l==="flow").map(([l])=>l),r=de(n,t.id,a).map(({line:l,what:c})=>({file:e,line:l,what:c}));return{title:e,stops:o.length>0,problems:i.sort((l,c)=>l.line-c.line),notes:r}}function Je(t,{tree:e}){let s=null;P(e,r=>{s??=r.tagName==="main"?r:null});let n=ye(s??{}),o=(s?.childNodes??[]).some(r=>r.nodeName==="#text"&&r.value.trim()),[i]=n;if(n.length!==1||o||!Ce(i)||I(i,k)!==t)return[{file:w,line:i?.sourceCodeLocation?.startLine,what:`a template is one element, a <div ${k}="${t}"> or a <section>, and it holds ${n.length===1&&!o?`<${i.tagName}${I(i,k)?` ${k}="${I(i,k)}"`:""}>`:`${n.length} element${n.length===1?"":"s"}${o?" and words":""}`}`}];let a=[];return P({childNodes:[i]},r=>{I(r,"data-block-id")!==void 0&&a.push({file:w,line:r.sourceCodeLocation?.startLine,what:"it writes a data-block-id, which every instance made of it would repeat: leave it out, Gallery gives a block its id"})}),a}function Xe(t,{tree:e}){let s=X(t);if(!s)return[];let[n]=Y(e,t),o=null;return n&&P({childNodes:[n]},i=>{Ie(i.tagName,i.attrs)&&(o??=i)}),[{file:w,line:(o??n)?.sourceCodeLocation?.startLine,what:v("en",s)}]}function Ze(t){return[[w,"component-template"],[E,"component-example"]].flatMap(([e,s])=>{let n=O(t,e);if(n===null||!n.trim()||T(t,e))return[];let o=le(s,n),{text:i}=re(o);return[{file:e,slug:s,written:o,html:i,tree:V(i)}]})}function Qe({id:t,folder:e,found:s,pages:n,parts:o}){let i="template.html and example.html",a=[],r=[];for(let h of[w,E]){let m=T(e,h);m?a.push(m):h===w&&!O(e,h)?.trim()&&s.template!==null?a.push({file:h,what:"it is empty"}):h===E&&!n.some(d=>d.file===h)&&a.push({file:h,what:`there is none or it is empty: write an instance as a writer would fill it, a <div ${k}="${t}">; it is what this check runs`})}let l=n.find(h=>h.file===w);l&&a.push(...Je(t,l));let c=n.find(h=>h.file===E);c&&Y(c.tree,s).length===0&&a.push({file:E,what:`it holds no instance of ${t}: a <div ${k}="${t}">`});let p=n.map(({slug:h,written:m,html:d,file:$})=>({file:$,slug:h,written:m,html:d,directory:j.join(e,h),htmlPath:j.join(e,h,"doc.html"),metadata:{title:h,description:h,type:"component"}})),f=ne(p);for(let h of p){for(let m of f.get(h.slug)??[])Pe.test(m)||a.push(G(h.file,ze(m)));for(let m of oe(h))r.push(G(h.file,m));for(let m of F(h.html)){let d=G(h.file,`${m} (read-only in the preview)`);o.some(({file:$,line:b})=>$===d.file&&b===d.line)||r.push(d)}}return l&&!a.some(({file:h})=>h===w)&&a.push(...Xe(s,l)),{title:i,problems:a,notes:r}}function et(t,e){let s=W(t,void 0,{on:e}),n=C(t,e);if(!s.packages.has(e)&&!s.problems.has(e))return null;J(t,s);let o=s.packages.has(e)&&s.settings.disabled.includes(e),i=s.packages.get(e)??{id:e,folder:n,files:["kit.js","style.css"].filter(c=>be.existsSync(j.join(n,c)))},a=Ze(n),r=s.packages.has(e)?null:"its manifest does not load",l=r?[]:a.flatMap(c=>_e(i,c));return{found:s.packages.get(e)??null,pages:a,sections:[Ye({id:e,folder:n,catalog:s,off:o,parts:l}),Ve(i),We(i),r?{title:"template.html and example.html",skipped:r}:Qe({id:e,folder:n,found:i,pages:a,parts:l})]}}var K=({file:t,line:e})=>e?`${t}:${e}`:t;function $e({title:t,problems:e=[],notes:s=[],told:n=[],none:o,skipped:i,unverified:a,pictures:r},l){let c=a?`UNVERIFIED ${a}`:i?`not run: ${i}`:o??(e.length?`${e.length} problem${e.length===1?"":"s"}`:`ok${s.length?`, ${s.length} note${s.length===1?"":"s"}`:""}`);return[`${l}. ${t}: ${c}`,...e.map(p=>` FAIL ${K(p)}: ${p.what}`),...s.map(p=>` note ${K(p)}: ${p.what}`),...n.map(p=>` way back ${K(p)}: ${p.what}`),...r?[tt(r)]:[]]}function tt({folder:t,overviews:e,each:s,edited:n=[],asExport:o=[]}){let i=e.length?`${N(j.join(t,e[0]))}${e.slice(1).map(l=>` and ${l}`).join("")}, the three widths of each theme side by side; then each at full size: `:`${N(t)}: `,a=o.length===0?"":o.length===n.length?", each the same picture as the export's at its width: the block draws nothing more where a reader can edit":`, ${o.join(" and ")} the same picture as the export's at its width`,r=n.length?`; and ${n.join(" and ")}, as the editing page draws it (context.canEdit() true)${a}`:"";return` Pictures (none looked at for you; example.html above the line, template.html below it, each under its name): ${i}${s.join(", ")}${r}`}function st([t,e,s,n]){return t.problems.length?"the manifest":e.stops?"kit.js":s.stops?"style.css":n.skipped||n.problems.length?"template.html and example.html":null}async function Ot(t,e){let s=et(t,e);s||(console.error(he(t,e)),process.exit(1)),console.log(`${e}: ${N(C(t,e))}`),s.sections.forEach((r,l)=>console.log($e(r,l+1).join(`
3
+ `)));let n=st(s.sections),o=C(t,e),i=n?{title:ae,skipped:`${n} first`}:await ce(t,s.found,{example:O(o,E),template:O(o,w)});console.log($e(i,5).join(`
4
+ `));let a=[...s.sections,i].reduce((r,{problems:l=[]})=>r+l.length,0);a?(console.log(`FAIL ${e}: ${a} problem${a===1?"":"s"}`),process.exitCode=1):i.unverified?(console.log(`UNVERIFIED ${e}: the rest passed, and no browser ran it: export a document that holds it and open that in Chrome or Edge.`),process.exitCode=3):console.log(`OK ${e}`)}export{Ot as checkCommand,Ke as fewestSyllables,et as readSections,$e as sectionLines,He as wantsPinyin};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as l,i as u}from"./chunk-NSKUTQ5J.mjs";import h from"node:fs/promises";import{ancestorsIn as f,moveDocument as m,readOutline as p}from"../browser/shared/outline.mjs";import{reportsDirectory as a}from"../browser/shared/paths.mjs";import{findPreviewServer as w}from"../browser/shared/preview-server.mjs";import{roleOf as $}from"../browser/shared/reports.mjs";import{documentDirectory as d,documentFiles as g,pageSlug as y}from"../browser/shared/workspace.mjs";async function D(){let{children:e}=await p(a),t=Object.values(e).flat(),n=r=>typeof r=="string"?r.replace(/\s+/g," ").trim():"",o=new Map(await Promise.all(t.map(async r=>{let i=await h.readFile(g(d(r,a)).json,"utf8").then(JSON.parse).catch(()=>({}));return[r,{slug:r,title:n(i?.title)||r,description:n(i?.description),icon:typeof i?.icon=="string"?i.icon:null}]})));return{children:e,documents:o}}var s=({documents:e},t)=>`${t} (${e.get(t)?.title??t})`;function _(e,t){let n=f(e.children,t).map(o=>s(e,o));return`\u4F4D\u7F6E\uFF1A${n.length?n.join(" \u203A "):"\u9876\u5C42"}`}async function E(e,t,n){let{slug:o}=await u(e);if(o===await y(a))return{refused:`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`};if(!n.documents.has(o)){let r=d(o,a);return{refused:await $(r)==="instructions"?`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`:`No document "${e}" (${t}): gallery list --tree shows the documents and where they are.`}}return{slug:o}}var v={missing:(e,t)=>`No document "${t}" in the sidebar's tree: gallery list --tree shows them.`,parent:(e,t,{parent:n})=>`No document "${n}" to put ${s(e,t)} under: gallery list --tree shows them.`,after:(e,t,{after:n})=>`No document "${n}" to put ${s(e,t)} after: gallery list --tree shows them.`,level:(e,t,{parent:n,after:o})=>`${s(e,o)} is not under ${n?s(e,n):"the top level"}: --after names a document at the level it goes to.`,itself:(e,t)=>`${s(e,t)} cannot go after itself.`,inside:(e,t,{parent:n,after:o})=>n===void 0&&o?`${s(e,t)} cannot go after ${s(e,o)}, which is under it.`:`${s(e,t)} cannot go under ${n===t?"itself":`${s(e,n)}, which is under it`}.`,instructions:(e,t)=>"The \u5199\u4F5C\u504F\u597D page is listed apart: it moves nowhere and holds no documents."},F=(e,t,n,o={})=>(v[n]??((r,i,{message:c})=>`Not moved: ${c??n}.`))(e,t,o);async function b(e,t){let n=`127.0.0.1:${e.port}`;try{let r=await(await fetch(`http://${n}/__gallery/workspace/move`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${n}`,"X-Gallery-Token":e.token},body:JSON.stringify({...t,workspace:a}),signal:AbortSignal.timeout(3e4)})).json().catch(()=>null);return typeof r?.ok!="boolean"||["elsewhere","token","host","origin","unknown"].includes(r.reason)?null:r}catch{return null}}async function L(e,{parent:t=void 0,after:n=null,first:o=!1}={}){let r=await w({reportsDirectory:a}),i={slug:e,...t!==void 0?{parent:t}:{},after:n,first:o},c=r?await b(r,i):null;return c||m(a,e,{parent:t,after:n,first:o})}function P(e,{parent:t,index:n}){let o=e.children[t]??[],r=t?`under ${s(e,t)}`:"at the top level";return o.length===1?`${r}, the only document there`:n===0?`${r}, first`:`${r}, right after ${s(e,o[n-1])}${n===o.length-1?", last":""}`}function I(e,t,{top:n=!0}={}){let o=e.get("--under"),r=e.get("--after");if(o!==void 0&&t.has("--top"))throw new l("--under and --top are two places: give one.");if(r!==void 0&&t.has("--first"))throw new l("--after and --first are two places: give one.");return{under:o,top:n&&t.has("--top"),after:r,first:t.has("--first")}}export{D as a,s as b,_ as c,E as d,F as e,L as f,P as g,I as h};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-6U2SLSDN.mjs";import"./chunk-ITNLYXXV.mjs";import"./chunk-HQQMJCQJ.mjs";import"./chunk-QYKCJ7FG.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-TDQP3DKQ.mjs";import"./chunk-5FRMCDPY.mjs";import"./chunk-E7VYDG2X.mjs";import"./chunk-NFIBI4IP.mjs";import"./chunk-W63L7367.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-Y6RLRPG3.mjs";import"./chunk-E7LWZRXY.mjs";import"./chunk-BGGDRNYQ.mjs";import"./chunk-6QXGZM36.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-TYK6VNAB.mjs";import"./chunk-CY2FNNAB.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-L3QKH4OK.mjs";import"./chunk-W4VKN3GF.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as m,b as u,c as f,d}from"./chunk-FDLXYYG4.mjs";import{b as p}from"./chunk-4FS7Z7WR.mjs";import{j as n}from"./chunk-NSKUTQ5J.mjs";import{k as i,s as a,v as c}from"./chunk-AUZGSZJH.mjs";import{reportsDirectory as g}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as y}from"../browser/shared/workspace.mjs";var k=()=>`No documents in ${g} yet: gallery new <slug> "<title>" makes one.`;async function A(w){let{slugs:e,options:h}=await n({options:["--allow-failures"],argv:w,noneIsAll:!0});e.length===0&&(console.error(k()),process.exit(1)),await p(e),await f(e),await d(e);let{reports:r,failures:t}=await i(e,{prepare:m()}),s=r.filter(o=>!t.has(o.slug));for(let o of s)console.log(`OK ${o.slug}`);for(let o of e)y($(o,g)).both&&console.log(`note ${o}: both doc.html and report.html: report.html is not read`);a(r),u(r);let l=s.length+t.size;console.log(`Checked ${l} document${l===1?"":"s"}: ${s.length} passed, ${t.size} failed.`),await c(t,{allow:h.has("--allow-failures")})}export{k as a,A as b};
@@ -0,0 +1,10 @@
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 Je,B as Qe,C as Xe,D as me,E as Ot,H as tn,I as en,a as pe,e as Ee,f as Fe,g as Oe,h as De,i as wt,j as he,k as Ne,l as Xt,m as Dt,n as Ve,o as Ge,p as vt,q as $e,r as Ye,s as Le,t as mt,u as G,v as Me,w as We,x as Ze,y as je,z as Q}from"./chunk-L3QKH4OK.mjs";import{d as qt}from"./chunk-W4VKN3GF.mjs";import{b as ue,c as de,e as Ae}from"./chunk-A55HN5OK.mjs";import{BLOCK_TYPES as ve,COPIED_AS_ITSELF as zn,IDENTITY as yn}from"../browser/editor/components/registry.mjs";import{copyKeys as Un}from"../browser/editor/components/figure/index.mjs";import{accepts as ye,attributeValue as En,BLOCK_TYPES as Vt,boxRole as be,CHAPTER as On,holdsStraight as Nn,IDENTITY as Ke,isLead as ln,SIZES as $n,sizeValue as an,TOGGLES as cn}from"../browser/editor/components/registry.mjs";import{iconMarkup as Ln,iconValueOf as Mn,validIcon as jn}from"../browser/editor/components/icon/index.mjs";Ae();import{attributeValue as xn,BLOCK_TYPES as nn,HOSTS as wn,TOGGLES as vn}from"../browser/editor/components/registry.mjs";import{texSource as sn}from"../browser/editor/components/math/index.mjs";var Te=new Set(Object.entries(nn).filter(([,s])=>!s.box&&!s.bare).map(([s])=>s)),te=(s,m,w="")=>{let g=Q[m.type]?.leaf;if(g)return g(s,m,w);let k=[s.className,...m.classes??[]].filter(Boolean).join(" ");return`<${s.tag}${k?` class="${k}"`:""}${he(m.attributes)}${w}>${m.html}</${s.tag}>`},Ce=(s,m)=>s===void 0||!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(s).every(([w,g])=>typeof g=="string"&&xn(m,w,g)),Be=s=>s?.empty===!0,qe=(s,m)=>s===void 0?null:w=>s.includes(m.slice(w.startOffset,w.endOffset));function ke(s,m,{empty:w=!1,file:g}={}){if(typeof m!="string"||!m.trim()&&!(w&&m===""))return!1;if(m==="")return!0;if(s.tex&&!sn(m))return!1;let k=s.inside??s.tag,O=`<${k}>${m}</${k}>`,[I,...a]=de(O,{sourceCodeLocationInfo:!0}).childNodes;return a.length===0&&I?.tagName===k&&me(I,[],s.inside!==void 0,{lists:k==="td"||k==="th",known:qe(g,O)})===null}var In=new Set(Object.values(nn).filter(s=>s.text&&s.className).map(s=>s.kind));function Pe(s,m){if(s.keep?.reason==="script")return null;if(s.kind==="list")return m.some(g=>g.unit===s.id&&g.kind==="list")?"list":null;let w=Q[s.kind];return w?.written?w.written(s)?"written":null:s.text===void 0||s.nested?null:["p","h1","h2","h3","h4","li"].includes(s.tag)||In.has(s.kind)?"text":null}function ge(s,m,w){if(!Array.isArray(m)||!m.every(k=>An(s,k,w)))return"invalid";let g=m.filter(k=>k.keep);return g.length>1?"invalid":m.length>g.length&&!s.caps.split||g.length===0&&!s.caps.remove||m.length===0&&s.nested?"fixed":g.length===1&&g[0].html.trim()===""&&!s.caps.empty?"empty":null}function on(s,m,w){let g=`<table><tbody><tr><${s}>${m}</${s}></tr></tbody></table>`,[k,...O]=de(g,{sourceCodeLocationInfo:!0}).childNodes,I=O.length===0&&k?.tagName==="table"&&k.childNodes.length===1?k.childNodes[0]:null,a=I?.childNodes.length===1?I.childNodes[0]:null,p=a?.childNodes.length===1?a.childNodes[0]:null;return p?.tagName===s&&me(p,[],!1,{lists:!0,known:qe(w,g)})===null}var rn={p:"paragraph",h1:"heading",h2:"heading",h3:"heading",h4:"heading",li:"item"},Sn=(s,m)=>s.classes===void 0||!s.keep&&Array.isArray(s.classes)&&new Set(s.classes).size===s.classes.length&&s.classes.every(w=>(vn[rn[m]]??[]).includes(w));function An(s,m,w){if(!m||typeof m.html!="string"||wn[s.kind]?.tex&&!sn(m.html))return!1;let g=m.keep?s.tag:m.tag;if(!m.keep&&Qe[s.tag]!==g||!Sn(m,g)||m.attributes!==void 0&&(m.keep||!Ce(m.attributes,rn[g])))return!1;let k=g==="td"||g==="th",O=k?`<table><tbody><tr><${g}>${m.html}</${g}></tr></tbody></table>`:`<${g}>${m.html}</${g}>`,[I,...a]=de(O,{sourceCodeLocationInfo:!0}).childNodes;if(a.length>0||!I)return!1;let p=I;if(k){let h=I.tagName==="table"&&I.childNodes.length===1?I.childNodes[0]:null,u=h?.childNodes.length===1?h.childNodes[0]:null;p=u?.childNodes.length===1?u.childNodes[0]:null}return p?.tagName===g&&me(p,[],Xe(s.kind,s.tag,s.caps),{lists:k,known:qe(w,O)})===null}import{attr as fn}from"../browser/shared/html-tree.mjs";import{pageLanguage as Tn}from"../browser/shared/components/page.mjs";import{SHEETS as Cn}from"../browser/editor/components/kit.mjs";import{BLOCK_ID as Bn}from"../browser/shared/ids.mjs";function un({current:s,edits:m,units:w=[],partial:g=!1,ids:k=!1,touch:O=[],proposals:I=null}){let a=Ot(s),p=a.blocks,h=s.includes(`\r
3
+ `)?`\r
4
+ `:`
5
+ `,u=[],L=[],j=[],H=new Map,z=null,X,xt=!1,tt=(t,n)=>u.push({unit:t.id,reason:n}),et=t=>{let r=Dt(t).replace(/[0-9.]/g,l=>String.fromCharCode(l.charCodeAt(0)-65248)).replace(/[\s,,]/g,"").replace(/[−–]/g,"-").match(/-?\d+(?:\.\d+)?/)?.[0];return r===void 0?null:Number(r)},ut=(t,n,r)=>{if(t.kind!=="cell")return;let l=s.slice(t.start,t.innerStart),c=/\sdata-sort-value(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/.exec(l);if(!c)return;let d=(c[1]??c[2]??c[3]??"").trim(),x=/^-?\d+(\.\d+)?(e[-+]?\d+)?$/i.test(d)?Number(d):null,[S,f]=[et(s.slice(t.innerStart,t.innerEnd)),et(n)],y="";x!==null&&f!==null?y=` data-sort-value="${Number((f*(S?x/S:1)).toPrecision(12))}"`:x!==null&&S===null&&(y=c[0]),y!==c[0]&&L.push({start:t.start+c.index,end:t.start+c.index+c[0].length,text:y,of:[{id:r}]})},Gt=t=>{t.keep&&e(t)?tt(t,"referenced"):j.push({start:t.start,end:t.end},...t.companion?[t.companion]:[])},ne=(t,n)=>{let r=t.classAttr,l=r?r.value.split(/\s+/).filter(Boolean):[],c=l;for(let[x,S]of n)c=S?c.includes(x)?c:[...c,x]:c.filter(f=>f!==x);if(c.join(" ")===l.join(" "))return;if(ct(t),!r){let x=/^<[A-Za-z][\w-]*/.exec(s.slice(t.elStart,t.elStart+40));if(!x)return tt(t,"unknown");let S=t.elStart+x[0].length;L.push({start:S,end:S,text:` class="${c.join(" ")}"`});return}if(c.length===0){L.push({...Xt(s,r.start,r.end),text:""});return}let d=/=\s*'/.test(s.slice(r.start,r.end))?"'":'"';L.push({start:r.start,end:r.end,text:`class=${d}${c.join(" ")}${d}`})},It=typeof k=="function"?k:k?tn:null,lt=new Set([...s.matchAll(en)].map(t=>t[1]??t[2])),Pt=()=>{for(;;){let t=It();if(!lt.has(t))return lt.add(t)&&t}},se=[],Kt=[],Yt=t=>t?` ${Ke}="${t}"`:"",ie=t=>typeof t=="string"&&Bn.test(t)&&!lt.has(t),at=(t,n)=>{let r=It?ie(n)?(lt.add(n),n):Pt():null;return r&&t!==void 0&&Kt.push({key:t,id:r}),Yt(r)},st=new Set,zt=t=>{st.add(t.at);let n=I?.get(t.id),r=It?ie(n)?(lt.add(n),n):Pt():null;return r&&se.push({at:t.at,id:r}),Yt(r)},ct=t=>{if(!It||!t||t.blockId||t.at===void 0||st.has(t.at))return;let n=Ne(s,t.at);L.push({start:n,end:n,text:zt(t)})},St=t=>{let{element:n,source:r}=vt(t.restore),l=n.sourceCodeLocation,c=fn(n,Ke);if(c&&!lt.has(c))return lt.add(c),t.key!==void 0&&Kt.push({key:t.key,id:c}),r;let d=r,x=l.startTag.endOffset-1;if(c){let S=l.attrs[Ke],f=Xt(d,S.startOffset,S.endOffset);d=d.slice(0,f.start)+d.slice(f.end),x-=f.end-f.start}return x=Ne(d,x),d.slice(0,x)+at(t.key,t.blockId)+d.slice(x)},kt=t=>{let n=null;for(let r of a.units)r.elStart<=t.start&&t.start<r.end&&(!n||r.elStart>n.elStart)&&(n=r);return n},_=new Set;for(let t of m){let{id:n,parts:r}=t??{},l=Number.isInteger(n)?p[n]:void 0;if(!l){u.push({id:n,reason:"unknown"});continue}if(Array.isArray(r)&&r.length===0&&l.self!==null&&a.units[l.self].keep){u.push({id:n,reason:"referenced"});continue}let c=ge(l,r,s);if(c){u.push({id:n,reason:c});continue}if(r.length===0){let N={...Me(s,l.start,l.end),of:[{id:n}]};L.push(N),H.set(n,N),l.self!==null&&_.add(l.self);continue}let d=G(s,l.start),x=d===null?"":h+d,S=N=>`<${N.tag}${N.classes?` class="${N.classes.join(" ")}"`:""}${he(N.attributes)}${at(N.key,N.blockId)}>${N.html}</${N.tag}>`,f=r.findIndex(N=>N.keep),y=kt(l),v=y&&y.at===l.innerStart-1;if((!v||l.tag==="li")&&ct(y),l.tag==="li"&&f>=0){let N=r.slice(0,f),K=r.slice(f+1),C=y?{start:y.start,end:y.end}:null;L.push({start:l.innerStart,end:l.innerEnd,text:r[f].html,of:[{id:n}]}),N.length>0&&L.push({start:l.start,end:l.start,seq:1/0,text:N.map(S).join(x)+x,edge:C,of:[{id:n}]}),K.length>0&&L.push({start:l.end,end:l.end,text:x+K.map(S).join(x),edge:C,of:[{id:n}]})}else{let N=s.slice(l.start,l.innerStart);if(v&&It&&!y.blockId&&!st.has(y.at)&&(N=`${N.slice(0,-1)}${zt(y)}>`),r.length===1&&f===0&&N===s.slice(l.start,l.innerStart)){L.push({start:l.innerStart,end:l.innerEnd,text:r[0].html,of:[{id:n}]}),ut(l,r[0].html,n),l.kind==="title"&&(z={from:Dt(s.slice(l.innerStart,l.innerEnd)),to:Dt(r[0].html)});continue}let K=r.map(C=>C.keep?N+C.html+s.slice(l.innerEnd,l.end):S(C)).join(x);L.push({start:l.start,end:l.end,text:K,of:[{id:n}]})}l.kind==="title"&&(z={from:Dt(s.slice(l.innerStart,l.innerEnd)),to:Dt(r[0].html)})}let Y=(t,n,r)=>{let l=a.units.filter(f=>f.box===t),c=[];for(let f=1;f<l.length;f++){let y=s.slice(l[f-1].end,l[f].start);y.trim()||c.push({pair:[l[f-1],l[f]],gap:y})}let d=c.find(({pair:f})=>f.includes(n))??c[0];if(d)return d.gap.replace(/\r?\n/g,h);let x=G(s,r.start),S=be(a.boxes[t]?.kind)==="root"?h:"";return x===null?"":S+h+x},Wt=t=>{if(t.kind!=="nest"||G(s,t.innerEnd)!==null)return null;let n=a.units[t.unit];return n?G(s,n.elStart):null},Zt=(t,n)=>{let r=s.slice(t.at+1,t.innerEnd).match(/\n([ \t]*)\S/);return r?r[1]:`${n??""} `},Ut=(t,n)=>n!==null&&be(t.kind)==="root",dt=[],Jt=(t,n,r,l)=>{let c=Number.isInteger(n?.into)?a.boxes[n.into]:null,d=Number.isInteger(n?.after),x=c?null:a.units[d?n.after:n?.before],S=c??(x?a.boxes[x.box]:null),f=K=>K>=t.start&&K<t.end;if(!S||!(ye(S.kind,Qt(t))||l===S.kind)||t.kind==="tab"&&S.id!==t.box||x&&(x===t||!r.has(x.id)||f(x.elStart))||c&&f(S.at))return tt(t,"position");let y=G(s,t.start);if(ct(t),c){if(c.innerEnd===null)return tt(t,"missing");let K=Wt(c);if(K!==null){dt.push({start:t.start,end:t.end,at:c.innerEnd,seq:o++,from:y,to:K+nt,wrap:U=>h+K+nt+U+h+K});return}let C=G(s,c.innerEnd),W=Zt(c,C),T=C!==null&&W.startsWith(C)?W.slice(C.length):" ",q=Ut(c,C);dt.push({start:t.start,end:t.end,at:q?c.innerEnd-C.length:c.innerEnd,seq:o++,from:y,to:W,wrap:U=>C===null?U:q?C+T+U+h:T+U+h+C});return}let v=Y(x.box,x,x),N=d?v.includes(`
6
+ `)?v.slice(v.lastIndexOf(`
7
+ `)+1):null:G(s,x.start);dt.push({start:t.start,end:t.end,at:d?x.end:x.start,seq:o++,from:y,to:N,wrap:K=>d?v+K:K+v})},gt=(t,n)=>t.classes===void 0||Array.isArray(t.classes)&&new Set(t.classes).size===t.classes.length&&t.classes.every(r=>(cn[n.kind]??[]).includes(r)),_t=(t,n)=>!Je(t)&&(Q[t.type]?.check?.(t)??!0)&&gt(t,n)&&Ce(t.attributes,n.kind),Ht=(t,n,r={})=>ke(t,n,{...r,file:s}),Rt=(t,n)=>{if(ot.has(t.id))return;let r=Vt[n?.type],l=Pe(t,a.boxes);if(!(l==="text"||l==="written"&&r?.kind!==t.kind)||!Te.has(n?.type)||!ke(r,n.html,{empty:Be(r),file:s}))return tt(t,"invalid");if(!ht.has(t.id)&&!bt.has(t.id)&&!ye(a.boxes[t.box].kind,r.kind))return tt(t,"position");if(!_t(n,r))return tt(t,"invalid");let c=t.blockId?Yt(t.blockId):zt(t);st.add(t.at);let d=l==="written"&&t.node?Fe(s,t.node,Q[t.kind].attribute):t.carried;L.push({start:t.elStart,end:t.end,text:te(r,n,d+c)})},oe=(t,n)=>{if(ot.has(t.id))return;let r=Q[t.kind]?.rewrite;if(!r)return tt(t,"invalid");let l=r(s,t.node,n,{validCell:(c,d)=>on(c,d,s),get packages(){return qt().packages}});if(!l)return tt(t,"invalid");ct(t),L.push(...[l].flat())},re=(t,n)=>{if(Pe(t,a.boxes)!=="list"||n!=="ul"&&n!=="ol")return tt(t,"invalid");let r=/^<(ul|ol)\b/i.exec(s.slice(t.elStart,t.elStart+3)),l=/<\/(ul|ol)\s*>$/i.exec(s.slice(t.elStart,t.end));if(!r||!l)return tt(t,"unknown");if(r[1].toLowerCase()===n)return;ct(t);let c=t.end-l[0].length+2;L.push({start:t.elStart+1,end:t.elStart+3,text:n},{start:c,end:c+2,text:n})},Nt=new Set([...s.matchAll(/\sid\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi)].map(t=>t[1]??t[2]??t[3])),$t=new Map,Lt=new Set,nt=/\n(\t|[ ]+)</.exec(s)?.[1]??" ",yt=(t,n)=>{let r=d=>ye(n,d)||t?.stood===n;if(t?.restore!==void 0){let d=vt(t.restore),x=d?.kind==="item"?Oe(d.element,n):d?.kind;if(!d||!r(x))return!1;if(t.children===void 0)return!0;if(t.boxKeys!==void 0){let f=Ee(d.element,d.kind);return Array.isArray(t.boxKeys)&&t.boxKeys.length===t.children.length&&t.children.every((y,v)=>{let N=f.find(({key:K})=>K===t.boxKeys[v]);return!!N&&yt(y,N.kind)})}let S=Vt[t.type];return Nn(S)&&S.kind===x&&t.children.every(f=>yt(f,S.box))}if(t?.unit!==void 0){let d=Number.isInteger(t.unit)?a.units[t.unit]:void 0;return!d||Lt.has(d.id)||ot.has(d.id)||ht.has(d.id)||_.has(d.id)||d.kind==="tab"||!r(Qt(d))?!1:(Lt.add(d.id),!0)}let l=Vt[t?.type];if(!l||!r(l.kind))return!1;if(t.type==="divider")return!0;if(t.type==="icon")return jn(t.icon);let c=Q[t.type];return l.bare&&c?.check?c.check(t,{validLeaf:Ht,usedIds:Nt})&&gt(t,l):l.box?!Array.isArray(t.children)||t.children.length===0&&!c?.empty||!gt(t,l)||c?.check&&!c.check(t,{validLeaf:Ht,usedIds:Nt})?!1:t.children.every(d=>yt(d,l.box)):!Te.has(t.type)||!ke(l,t.html,{empty:Be(l),file:s})||!_t(t,l)?!1:t.children===void 0?!0:Array.isArray(t.children)&&c?.children?.(t,yt)===!0},Z=(t,n)=>{if(t.unit!==void 0){let y=$t.get(t.unit);return mt(R(y),y.from,n)}if(t.restore!==void 0&&t.children===void 0)return mt(St(t),"",n);let r=Vt[t.type];if(t.type==="divider")return`<hr${at(t.key,t.blockId)}>`;if(t.type==="icon")return Ln(t.icon,at(t.key,t.blockId));let l=n===null?null:n+nt,c=(y,v,N,K=n,C=l)=>C===null?y+v.join("")+N:y+v.map(W=>h+C+W).join("")+h+K+N,d=y=>t.children.map(v=>Z(v,y));if(t.restore!==void 0&&t.boxKeys!==void 0){let y=St(t),{element:v,kind:N}=vt(y),K=Ee(v,N).flatMap(({element:C,key:W})=>{let T=t.children.filter((rt,Ct)=>t.boxKeys[Ct]===W);if(T.length===0)return[];let{startTag:q,endTag:U}=C.sourceCodeLocation,J=n===null?null:G(y,q.startOffset),ft=J===null?null:J+nt;return[{start:q.endOffset,end:U.startOffset,text:c("",T.map(rt=>Z(rt,ft)),"",J,ft)}]}).sort((C,W)=>W.start-C.start).reduce((C,{start:W,end:T,text:q})=>C.slice(0,W)+q+C.slice(T),y);return mt(K,"",n)}if(t.restore!==void 0){let y=St(t),{element:v}=vt(y),{startTag:N,endTag:K}=v.sourceCodeLocation,C=v.childNodes.findLastIndex(T=>T.tagName),W=v.childNodes.slice(C+1).filter(T=>T.nodeName==="#comment").map(({sourceCodeLocation:{startOffset:T,endOffset:q}})=>mt(y.slice(T,q),G(y,T),l));return c(mt(y.slice(0,N.endOffset),"",n),[...d(l),...W],K?y.slice(K.startOffset):`</${r.tag}>`)}let x={get id(){return at(t.key,t.blockId)},get language(){return Tn(s)},idOf:y=>at(y.key,y.blockId),render:(y,v)=>Z(y,v),indent:n,inner:l,step:nt,block:c,children:d,deep:y=>n===null?null:n+nt.repeat(y)},S=Q[t.type]?.write;if(r.bare&&S)return S(t,x);if(!r.box)return t.children?S(t,x):te(r,t,at(t.key,t.blockId));if(S)return S(t,x);let f=[r.className,...t.classes??[]].filter(Boolean).join(" ");return c(`<${r.tag}${f?` class="${f}"`:""}${at(t.key,t.blockId)}>`,d(l),`</${r.tag}>`)},it=[],le=t=>{let{insert:n,place:r}=t,l=T=>u.push({unit:t.id,reason:T}),c=n?.restore!==void 0?vt(n.restore):null;if(n?.type==="icon"||c?.kind==="icon"){let T=Number.isInteger(r?.into)?a.boxes[r.into]:null,q=T?null:a.units[Number.isInteger(r?.after)?r.after:r?.before],U=T??(q?a.boxes[q.box]:null);if(ln(U?.kind,"icon")){if(!yt(n,U.kind))return l("invalid");if(U.innerEnd===null)return l("missing");let rt=a.units.find(Re=>Re.box===U.id&&Re.kind!=="icon"),Ct=rt?rt.start:U.innerEnd,Bt=G(s,Ct);it.push({at:Ct,seq:o++,text:()=>Z(n,Bt)+(Bt===null?"":h+Bt)});return}if(!yt(n,"header"))return l("invalid");let J=p.find(rt=>rt.kind==="title");if(!J)return l("missing");let ft=G(s,J.start);it.push({at:J.start,seq:o++,text:()=>Z(n,ft)+(ft===null?"":h+ft)}),X=c?Mn(c.source):n.icon;return}if(n?.type==="tab"||c?.kind==="tab")return Mt(t,c,l);let d=Number.isInteger(r?.into)?a.boxes[r.into]:null,x=Number.isInteger(r?.after),S=d?null:a.units[x?r.after:r?.before],f=d??(S?a.boxes[S.box]:null),y=n?.restore!==void 0?vt(n.restore):null,v=y?f&&y.kind==="item"?Oe(y.element,f.kind):y.kind:Vt[n?.type]?.kind;if(!f||!v||!(ye(f.kind,v)||n.stood===f.kind)||S&&!Tt.has(S.id))return l("position");let N=new Set(Lt);if(!yt(n,f.kind))return l("invalid");for(let T of Lt){if(N.has(T))continue;let q=a.units[T];ct(q);let U={start:q.start,end:q.end,at:null,from:G(s,q.start)};$t.set(T,U),dt.push(U)}if(d){if(d.innerEnd===null)return l("missing");let T=Wt(d);if(T!==null){it.push({at:d.innerEnd,seq:o++,text:()=>h+T+nt+Z(n,T+nt)+h+T});return}let q=G(s,d.innerEnd),U=Zt(d,q),J=q!==null&&U.startsWith(q)?U.slice(q.length):nt,ft=a.units.filter(Bt=>Bt.box===d.id),rt=be(d.kind)==="root"&&On.has(v)&&(ft.some(Bt=>Tt.has(Bt.id))||!d.pure&&(ft.length>0||n.restore!==void 0))?h:"",Ct=Ut(d,q);it.push({at:Ct?d.innerEnd-q.length:d.innerEnd,seq:o++,text:()=>q===null?Z(n,null):Ct?rt+q+J+Z(n,U)+h:J+Z(n,U)+h+q});return}let K=x?S.end:S.start;if(be(f.kind)==="root"){let T=Y(S.box,S,S),q=x?T.includes(`
8
+ `)?T.slice(T.lastIndexOf(`
9
+ `)+1):null:G(s,S.start);it.push({at:K,seq:o++,text:()=>x?T+Z(n,q):Z(n,q)+T});return}let C=G(s,S.start),W=C===null?"":h+C;it.push({at:K,seq:o++,text:()=>x?W+Z(n,C):Z(n,C)+W})},Mt=({insert:t,place:n},r,l)=>{let c=Number.isInteger(n?.after),d=a.units[c?n.after:n?.before];if(d?.kind!=="tab"||!Tt.has(d.id))return l("position");if(!yt(t,"tabs"))return l("invalid");let x=d.companion,S=a.units[d.parent??-1];if(!x||!S)return l("missing");let f=r?fn(r.element,Cn.tabKey):t.sheet,y=s.slice(S.start,S.end);if(y.includes(`data-sheet-tab="${f}"`)||y.includes(`data-doc-sheet="${f}"`))return l("invalid");let v=G(s,d.start),N=G(s,x.start),K=(U,J)=>U===null?J:c?h+U+J:J+h+U,C=()=>r?mt(St(t),"",v):Ze({...t,sheet:f},at(t.key,t.blockId)),W=()=>{if(r)return mt(r.panel,"",N);let U=`<div data-doc-sheet="${f}">`;if(t.children.length===0)return N===null?`${U}</div>`:`${U}${h}${N}</div>`;let J=N===null?null:N+nt,ft=t.children.map(rt=>Z(rt,J));return J===null?U+ft.join("")+"</div>":U+ft.map(rt=>h+J+rt).join("")+h+N+"</div>"};it.push({at:c?d.end:d.start,seq:o++,text:()=>K(v,C())});let T=c?/^\s*/.exec(s.slice(x.end))[0]:/\s*$/.exec(s.slice(0,x.start))[0],q=N!==null&&/\n[ \t]*\r?\n/.test(T)?h:"";it.push({at:c?x.end:x.start,seq:o++,text:()=>c?q+K(N,W()):K(N,W())+q})},Ie=(t,n)=>{let r=t.node?.sourceCodeLocation;if(t.at===void 0||!r)return tt(t,"unknown");ct(t),L.push(...je(s,r.startTag,[["style",l=>Ge(l?.value??"",n)||null]]))},D=(t,n)=>{let r=t.node?.sourceCodeLocation;if(t.at===void 0||!r)return tt(t,"unknown");ct(t),L.push(...je(s,r.startTag,n))},jt=new Map,pt=new Map,At=new Map,ot=new Set(w.filter(t=>t?.remove===!0).map(t=>t.id)),ht=new Set(w.filter(t=>t?.move).map(t=>t.id)),bt=new Map,ae=(t,n)=>n?.unit!==void 0?bt.set(n.unit,t.id):Array.isArray(n?.children)&&n.children.forEach(r=>ae(t,r));w.forEach(t=>ae(t,t?.insert));let ce=new Map(w.filter(t=>Number.isInteger(t?.id)&&t.replace).map(t=>[t.id,t.replace])),Qt=t=>Vt[ce.get(t.id)?.type]?.kind??t.kind,Tt=new Set(a.units.map(t=>t.id).filter(t=>!ot.has(t)&&!ht.has(t)&&!bt.has(t)&&!_.has(t))),fe=a.units.filter(t=>ht.has(t.id)||bt.has(t.id)),Se=(t,n)=>r=>n.some(l=>l!==t&&t.start<=l.start&&l.end<=t.end&&l.start<=r&&r<l.end),e=t=>!!t.keep&&!t.keep.at.every(Se(t,fe)),i=(t,n)=>{let r=[L,j,dt,it],l=r.map(c=>c.length);n(),r.forEach((c,d)=>c.slice(l[d]).forEach(x=>x.of??=t))},o=0;for(let t of w){let{id:n,remove:r,toggle:l,on:c,move:d,size:x,value:S,attribute:f,stood:y}=t??{},v=Number.isInteger(n)?a.units[n]:void 0;i([{unit:n}],()=>{if(t?.insert&&typeof n=="string")le(t);else if(v&&t.replace){let N=u.length;Rt(v,t.replace),u.length>N&&ce.delete(v.id)}else v&&t.retag?re(v,t.retag):v&&(t.table||t.source)?oe(v,t.table??t.source):v&&r===!0?e(v)?u.push({unit:n,reason:"referenced"}):v.kind==="tab"&&a.units.every(N=>N.box!==v.box||ot.has(N.id))?u.push({unit:n,reason:"last"}):(v.kind==="icon"&&!ln(a.boxes[v.box]?.kind,"icon")&&(xt=!0),Gt(v)):v&&d&&typeof d=="object"&&!ot.has(n)?_.has(n)||Jt(v,d,Tt,y):v&&typeof c=="boolean"&&(cn[v.kind]??[]).includes(l)?(jt.get(v)??jt.set(v,new Map).get(v)).set(l,c):v&&$n[v.kind]?.[x]&&(S===null||an(v.kind,x,S)!==null)?ot.has(n)||(pt.get(v)??pt.set(v,new Map).get(v)).set(x,S===null?null:an(v.kind,x,S)):v&&typeof f=="string"&&En(v.kind,f,S)?ot.has(n)||(At.get(v)??At.set(v,new Map).get(v)).set(f,S):u.push({unit:n,reason:x===void 0&&f===void 0?"unknown":"invalid"})})}let b=new Set(u.map(t=>t.unit).filter(t=>t!==void 0)),M=t=>(ot.has(t.id)||ht.has(t.id)||bt.has(t.id))&&!b.has(bt.get(t.id)??t.id);for(let t of a.boxes){if(!["list","quote"].includes(t.kind)||!t.pure||t.unit===null)continue;let n=a.units[t.unit];if(!n||ot.has(n.id)||ht.has(n.id)||bt.has(n.id))continue;let r=a.units.filter(c=>c.box===t.id);if(r.length===0||!r.every(M))continue;let l=c=>!!c&&(c.into===t.id||[n,...r].some(d=>c.after===d.id||c.before===d.id));w.some(c=>l(c?.insert?c.place:c?.move))||Gt(n)}for(let[t,n]of jt)i([{unit:t.id}],()=>ne(t,n));for(let[t,n]of pt)i([{unit:t.id}],()=>Ie(t,n));for(let[t,n]of At)i([{unit:t.id}],()=>D(t,n));for(let t of O)ct(a.units[t]);let E=new Set([...H.keys()].map(t=>p[t].wrapper).filter(Boolean));for(let t of E){let n=t.ids.map(r=>H.get(r));n.some(r=>!r)||j.some(r=>r.start<=t.start&&t.end<=r.end)||(n.forEach(r=>r.skip=!0),L.push({...Me(s,t.start,t.end),of:t.ids.map(r=>({id:r}))}))}if(z&&z.from!==z.to){let t=Ve(s,z);z.synced=!!t,t&&L.push(t)}else z=null;let $=new Map;for(let t of j){let n=`${t.start}:${t.end}`;$.has(n)?$.get(n).of=[...$.get(n).of??[],...t.of??[]]:$.set(n,t)}j.splice(0,j.length,...$.values());let A=(t,n)=>{t.of?.length||u.push({reason:n});for(let r of t.of??[])u.push({...r,reason:n})},B=(t,n,r)=>n===r?t.start<n&&n<t.end:t.start<=n&&r<=t.end,F=(t,n,r,l=null)=>{let c=null;for(let d of dt){let x=l!==null&&d.start===l.start&&d.end===l.end;d!==r&&(x||B(d,t,n))&&(!c||d.start>=c.start)&&(c=d)}return c},V=(t,n,r,l=null)=>{let c=F(t,n,r,l);return j.some(d=>d!==r&&B(d,t,n)&&!(c&&B(d,c.start,c.end)))},P=new Set,R=t=>{if(P.has(t))return A(t,"position"),"";P.add(t);try{return Et(t)}finally{P.delete(t)}},Et=t=>{let[n,r]=t?[t.start,t.end]:[0,s.length],l=(f,y,v=null,N=null)=>F(f,y,v,N)===t&&!V(f,y,v,N),c=[];for(let f of[...j,...dt].filter(y=>y!==t&&l(y.start,y.end,y)).sort((y,v)=>y.start-v.start)){let y=c.at(-1);y&&(f.start<=y.end||!s.slice(y.end,f.start).trim())?(y.end=Math.max(y.end,f.end),y.of.push(...f.of??[])):c.push({start:f.start,end:f.end,of:[...f.of??[]]})}let d=[...L.filter(f=>!f.skip&&l(f.start,f.end,null,f.edge??null)).map(f=>({...f,seq:f.seq??-2})),...c.map(f=>({...We(s,f.start,f.end),seq:-1,of:f.of})),...[...dt.filter(f=>f.at!==null),...it].filter(f=>l(f.at,f.at,f)).map(f=>({start:f.at,end:f.at,seq:f.seq,text:f.text?f.text():f.wrap(mt(R(f),f.from,f.to)),of:f.of}))].sort((f,y)=>f.start-y.start||f.end-f.start-(y.end-y.start)||f.seq-y.seq),x=[];for(let f of d)x.length>0&&f.start<x.at(-1).end?A(f,"overlap"):x.push(f);let S=s.slice(n,r);for(let f of x.reverse())S=S.slice(0,f.start-n)+f.text+S.slice(f.end-n);return S},Ft=R(null);if(u.length>0&&!g)return{ok:!1,conflicts:u};let He=X??(xt?null:void 0);return{ok:u.length===0,text:Ft,version:pe(Ft),ids:{assigned:se,created:Kt},...z?{title:z}:{},...He!==void 0?{icon:He}:{},...g?{conflicts:u}:{}}}import{attr as bn}from"../browser/shared/html-tree.mjs";import{outsideKey as _n}from"../browser/shared/ids.mjs";Ae();import{commonPrefix as dn,commonRun as bs,commonSuffix as pn,mergeText as hn}from"../browser/editor/page/merge.mjs";var ee=new Map;function xe(s){let m=ee.get(s);if(m)return m;let w=/data-block-id/i.test(s)?De(s,[ue(s,{sourceCodeLocationInfo:!0})]):[],g="",k=0,O=0,I=[];for(let p of w)g+=s.slice(k,p.start),k=p.end,O+=p.end-p.start,I.push({at:g.length,end:p.end,removed:O});g+=s.slice(k);let a={text:g,at:p=>p-(I.findLast(h=>h.end<=p)?.removed??0),source:p=>p+(I.findLast(h=>h.at<=p)?.removed??0)};for(ee.set(s,a);ee.size>4;)ee.delete(ee.keys().next().value);return a}function ze(s,m,w,g=w.start){let[k,O]=[xe(s),xe(m)],I=k.at(w.start),a=k.text.slice(I,k.at(w.end)),p=H=>O.source(H+k.at(g)-I),h=H=>{let z=[];for(let X=H.indexOf(a);X>=0;X=H.indexOf(a,X+1))z.push(X);return z},u=h(O.text);if(u.length<=1&&h(k.text).length<=1)return u.length===1?p(u[0]):-1;let L=k.text.slice(Math.max(0,I-120),I),j=u.filter(H=>O.text.slice(Math.max(0,H-L.length),H)===L);return j.length===1?p(j[0]):u.length>1?-2:-1}function Ue(s,m,w,g){let[O,I]=[xe(s),xe(m)],[a,p]=[O.at(w.start),O.at(w.end)],h=O.text.slice(Math.max(0,a-400),a),u=O.text.slice(p,p+400),L=g.filter(z=>z.tag===w.tag).map(z=>{let[X,xt]=[I.at(z.start),I.at(z.end)];return{other:z,score:pn(h,I.text.slice(Math.max(0,X-400),X))+dn(u,I.text.slice(xt,xt+400))}}).sort((z,X)=>X.score-z.score),[j,H]=L;return j&&j.score>=40&&j.score-(H?.score??0)>=20?j.other:null}function mn(s,m){let w=p=>p.replace(/<[^>]*>/g," ").replace(/&(?:[a-z]+|#\d+);/gi," ").replace(/\s+/g," ").trim(),g=w(s),k=w(m);if(!g||!k)return!g&&!k;if(g.length<2||k.length<2)return g===k;let O=p=>{let h=new Map;for(let u=0;u<p.length-1;u++)h.set(p.slice(u,u+2),(h.get(p.slice(u,u+2))??0)+1);return h},I=O(k),a=0;for(let[p,h]of O(g))a+=Math.min(h,I.get(p)??0);return 2*a/(g.length-1+k.length-1)>=.5}Ae();import{IDENTITY as qn}from"../browser/editor/components/registry.mjs";import{escapeAttribute as Pn}from"../browser/shared/escape.mjs";import{attr as kn}from"../browser/shared/html-tree.mjs";import{CHART_DATA as _e,CHART_SOURCE as we,nextChartKey as Kn}from"../browser/shared/table-chart.mjs";function gn(s,m){if(m.size===0||!s.includes(we))return{text:s,keys:{}};let w=[],g=(a,p)=>{for(let h of a.childNodes??[]){if(!h.tagName)continue;let u=p||m.has(kn(h,qn));for(let L of[_e,we]){let j=kn(h,L);j!==void 0&&w.push({name:L,key:j,made:u,at:h.sourceCodeLocation?.attrs?.[L]??null})}g(h.tagName==="template"?h.content:h,u)}};g(ue(s,{sourceCodeLocationInfo:!0}),!1);let k=new Set(w.map(({key:a})=>a)),O={};for(let a of new Set(w.filter(p=>p.made&&p.name===we).map(p=>p.key))){let p=w.filter(u=>u.key===a&&!u.made),h=w.some(u=>u.key===a&&u.made&&u.name===_e);h&&p.length>0?(O[a]=Kn(k),k.add(O[a])):!h&&p.some(u=>u.name===we)&&(O[a]=null)}return{text:w.filter(({name:a,key:p,made:h,at:u})=>h&&u&&Object.hasOwn(O,p)&&!(O[p]===null&&a===_e)).map(({name:a,key:p,at:h})=>O[p]===null?{...Xt(s,h.startOffset,h.endOffset),put:""}:{start:h.startOffset,end:h.endOffset,put:`${a}="${Pn(O[p])}"`}).sort((a,p)=>p.start-a.start).reduce((a,{start:p,end:h,put:u})=>a.slice(0,p)+u+a.slice(h),s),keys:O}}function Hn({current:s,opening:m=null,texts:w=[],units:g=[],touch:k=[],ids:O=!0,seal:I=null,pageIds:a=null}){let p=Ot(s),h=typeof m=="string"?Ot(m):null,u=e=>s.slice(e.innerStart,e.innerEnd),L=null,j=e=>(L??=new Map(p.units.map(i=>[i.id,wt(s,i)]))).get(e.id),H=new Map,z=new Set,X=new Map,xt=new Set(Array.isArray(a)?a.filter(e=>typeof e=="string"):[]),tt=(e,i,o=!0,b=[])=>{let M=R=>!!R.blockId&&xt.has(R.blockId)&&!b.includes(R.blockId),E=xt.size>0?p.units.filter(R=>!M(R)):p.units,$=typeof i=="string"?E.filter(R=>j(R)===i):[],A=e>=0?h?.units[e]:void 0,B=A&&$.length>1?h.units.filter(R=>!M(R)&&wt(m,R)===i):[];if($.length===1)return{unit:$[0]};if(B.length===$.length&&B.includes(A))return{unit:$[B.indexOf(A)]};if(!A)return $.length>1?{reason:"ambiguous"}:{gone:!0};let F=ze(m,s,A,A.elStart),V=F>=0?E.find(R=>R.elStart===F):null;if(V)return{unit:V};if(F===-2||$.length>1)return{reason:"ambiguous"};if(!o)return{gone:!0};let P=Ue(m,s,A,E);return P&&mn(m.slice(A.start,A.end),s.slice(P.start,P.end))?{unit:P,changed:!0}:{gone:!0}},et=e=>{if(!e||typeof e.key!="number"&&typeof e.key!="string")return{reason:"invalid"};if(H.has(e.key))return H.get(e.key);let i,o=typeof e.blockId=="string"?p.units.filter(b=>b.blockId===e.blockId):[];if(o.length===1&&typeof e.id!="string")i={unit:o[0]};else if(typeof e.id=="string"){let b=p.units.filter(M=>M.blockId===e.id);i=b.length===1?{unit:b[0]}:b.length>1?{reason:"ambiguous"}:Number.isInteger(e.open)&&typeof e.openHash=="string"?tt(e.open,e.openHash,!1,[e.id]):{gone:!0}}else Number.isInteger(e.open)?i=tt(e.open,e.hash,!0,[e.blockId]):i={reason:"invalid"};return i.unit&&!i.unit.blockId&&typeof e.blockId=="string"&&X.set(i.unit.id,e.blockId),H.set(e.key,i),i.unit&&ut(e,i)&&z.add(e.key),i},ut=(e,i)=>i.changed||e.hash===null||typeof e.hash=="string"&&j(i.unit)!==e.hash,Gt=new Set(p.units.map(e=>e.blockId).filter(Boolean)),ne=[],It=e=>e?.restore!==void 0?bn(vt(e.restore?.source)?.element??{},yn)??e.blockId:e?.blockId,lt=e=>{let i=It(e);if(typeof i=="string"&&Gt.has(i))return!0;let o=ve[e?.type];return!!o?.keyed&&typeof e.id=="string"&&p.boxes.some(b=>b.kind===o.box&&b.key===e.id)},Pt=e=>{let i=It(e);e?.key!==void 0&&typeof i=="string"&&Gt.has(i)&&ne.push({key:e.key,id:i}),Array.isArray(e?.children)&&e.children.forEach(Pt)},se=(e,i)=>{let o=ve[i?.type];return!!o&&s.slice(e.elStart,e.end)===te(o,i,(e.carried??"")+(e.blockId?` ${yn}="${e.blockId}"`:""))},Kt=(e,i,o)=>Array.isArray(e)&&Array.isArray(i)&&e.length===i.length&&e[0]===i[0]&&e.slice(1).every((b,M)=>b[0]===i[M+1]?.[0]&&b[1]===i[M+1][1]&&(!o||b[2]===i[M+1][2])),Yt=e=>{if(!e||typeof e.before!="string")return{reason:"invalid"};let i=o=>({block:o,changed:u(o)!==e.before});if(e.title){let o=p.blocks.filter(b=>b.kind==="title");return o.length===1?i(o[0]):{reason:o.length?"ambiguous":"missing"}}if(e.unit){let o=et(e.unit);if(!o.unit)return{reason:o.gone?"missing":o.reason};let b=p.blocks.filter($=>$.unit===o.unit.id);if(e.self){let $=b.find(A=>A.self===o.unit.id);return $?i($):{reason:"missing"}}let M=b.find($=>Kt($.path,e.path,!1));if(M&&Kt(M.path,e.path,!0))return i(M);let E=b.filter($=>u($)===e.before);return E.length===1?i(E[0]):{reason:Q[o.unit.kind]?.textParts&&!ut(e.unit,o)?"package":"structure"}}if(Number.isInteger(e.open)||e.outside){let o=p.blocks.filter(A=>A.unit===null&&A.kind!=="title"&&u(A)===e.before);if(o.length===1)return i(o[0]);let b=Number.isInteger(e.open)?h?.blocks[e.open]:null;if(!b||o.length>1)return{reason:o.length>1?"ambiguous":"missing"};let M=ze(m,s,b),E=M>=0?p.blocks.find(A=>A.start===M):null;if(E)return i(E);let $=M===-2?null:Ue(m,s,b,p.blocks.filter(A=>A.unit===null));return $?i($):{reason:M===-2?"ambiguous":"missing"}}return{reason:"invalid"}},ie=e=>{if(e?.main)return p.boxes.find(o=>o.kind==="main")??null;if(e&&!e.unit&&typeof e.kind=="string")return p.boxes.find(o=>o.unit===null&&o.kind===e.kind&&(o.key??null)===(e.key??null))??null;let i=e?.unit?et(e.unit):null;return i?.unit?p.boxes.find(o=>o.unit===i.unit.id&&o.kind===e.kind&&(o.key??null)===(e.key??null))??null:null},at=[],st=e=>{e&&typeof e=="object"&&(typeof e.key=="number"||typeof e.key=="string")&&at.push(e)},zt=e=>{e?.unit!==void 0&&st(e.unit),e?.copy!==void 0&&st(e.copy),Array.isArray(e?.children)&&e.children.forEach(zt)},ct=e=>{st(e?.after),st(e?.before),st(e?.into?.unit)};for(let e of w)st(e?.block?.unit);for(let e of g)st(e?.unit),ct(e?.place),ct(e?.move),zt(e?.insert);k.forEach(st);let St=new Map;for(let e of at){let i=et(e);i.unit&&(St.get(i.unit)??St.set(i.unit,[]).get(i.unit)).push({key:e.key,changed:!!i.changed})}for(let e of St.values())if(!(new Set(e.map(i=>i.key)).size<2))for(let i of e)i.changed&&H.set(i.key,{gone:!0});let kt=new Map,_=new Map,Y=(e,i,o,b={})=>e.set(i,{key:i,status:"conflict",reason:o,...b}),Wt=new Map,Zt=(e,i,o,b)=>{let M=$=>{for(let A=$.unit;A!=null;A=i.units[A]?.parent)if(A===o.id)return!0;return!1};if(!b)return{hash:wt(e,o),theirs:i.blocks.filter(M).map($=>e.slice($.innerStart,$.innerEnd)).join(`
10
+ `)};let E=$=>Object.fromEntries(b.filter(A=>typeof $?.[A]=="string").map(A=>[A,$[A]]));return{theirs:E(Q[o.kind]?.dataOf?.(e,o.node,qt().packages)??{}),parts:E(o.parts)}},Ut=(e,i,o=null,b={})=>{Wt.set(e,{unit:i,held:o}),Y(_,e,"changed",{...Zt(s,p,i,o),...b})},dt=[],Jt=new Map;for(let e of w){let{key:i,block:o}=e??{},b=e?.parts,M=Array.isArray(b)?b.filter(A=>!A?.keep):[];M.some(lt)&&(M.forEach(Pt),b=b.filter(A=>A?.keep||!lt(A)));let E=Yt(o);if(!E.block){E.reason==="missing"&&Array.isArray(b)&&!b.some(A=>A?.keep)&&b.every(lt)?kt.set(i,{key:i,status:"applied"}):Y(kt,i,E.reason);continue}let $=Array.isArray(b)&&b.length===1&&b[0]?.keep&&typeof b[0].html=="string"?b[0].html:null;if(E.changed&&$!==null&&$===u(E.block))kt.set(i,{key:i,status:"applied"});else if(E.changed){let A=$===null?null:hn(o.before,$,u(E.block));if(A===null||ge(E.block,[{keep:!0,html:A}],s)){Y(kt,i,"changed",{theirs:u(E.block)});continue}b=[{keep:!0,html:A}],kt.set(i,{key:i,status:"merged",html:A})}else kt.set(i,{key:i,status:"applied"});Jt.set(E.block.id,i),dt.push({id:E.block.id,parts:b})}let gt=[],_t=new Map,Ht=(e,i)=>_t.set(e,[..._t.get(e)??[],i]),Rt={},oe=e=>{if(e?.into){let b=ie(e.into);return b?{into:b.id}:null}let i=!!e?.after,o=et(i?e.after:e?.before);return o?.unit?{[i?"after":"before"]:o.unit.id}:null},re=null,Nt=e=>{if(e?.unit!==void 0){let b=et(e.unit);return b.unit?{unit:b.unit.id,stood:e.stood}:null}if(e?.restore!==void 0){let{source:b,seal:M}=e.restore??{};if(!I||typeof b!="string"||M!==I(b))return null;let E=Array.isArray(e.children)?e.children.map(Nt):void 0;return E?.includes(null)?null:{restore:b,key:e.key,blockId:e.blockId,stood:e.stood,...E?{type:e.type,children:E}:{}}}if(e?.copy!==void 0){let b=et(e.copy),M=e.keys===void 0?null:Un(e.keys);return e.keys!==void 0&&!M?null:b.unit&&zn.has(b.unit.kind)?{restore:Le(s,b.unit,{keys:M,taken:re??=new Set($e(s))}),key:e.key,blockId:e.blockId}:null}if(!e||typeof e!="object")return null;let i=Q[e.type]?.source;if(i){let b=$=>Le($,{start:0,end:$.length},{taken:re??=new Set($e(s))}),M=Array.isArray(e.children)?e.children.map(Nt):void 0;if(M?.includes(null))return null;let E=i(e,{packages:qt().packages,written:b});return E?{restore:E,key:e.key,blockId:e.blockId,...M?{type:e.type,children:M,boxKeys:e.boxKeys}:{}}:null}let o=Array.isArray(e.children)?e.children.map(Nt):void 0;return o?.includes(null)?null:{...e,...o?{children:o}:{}}},$t=new Set,Lt=e=>[...$t].filter(i=>i!==e&&[e,e.companion].some(o=>o&&o.start<=i.start&&i.end<=o.end)),nt=e=>{if(e?.unit!==void 0){let i=et(e.unit);i.unit&&$t.add(i.unit)}else Array.isArray(e?.children)&&e.children.forEach(nt)};for(let e of g)e?.move?nt({unit:e.unit}):e?.insert&&nt(e.insert);let yt=(e,i)=>{let o=p.boxes.filter(E=>E.unit===e.id),b=new Map(i.map(E=>[et(E).unit,E])),M=p.units.filter(E=>o.some($=>$.id===E.box));return o.every(E=>E.pure)&&M.length>0&&M.every(E=>$t.has(E)||b.has(E)&&!ut(b.get(E),{unit:E}))},Z=new Set,it=e=>{if(e?.unit!==void 0){let i=et(e.unit);i.unit&&Z.add(i.unit)}else Array.isArray(e?.children)&&e.children.forEach(it)},le=[],Mt=new Map;for(let e of g){let i=e?.key;if(e?.insert&&lt(e.insert)){Pt({...e.insert,key:e.insert.key??i}),_.set(i,{key:i,status:"applied"});continue}if(e?.insert){let B=Nt({...e.insert,key:e.insert.key??i}),F=oe(e.place);if(!B||!F){Y(_,i,!B&&Q[e.insert.type]?.source?Q[e.insert.type].unwritten(e.insert,{packages:qt().packages}):"position");continue}_.set(i,{key:i,status:"applied"}),Ht(i,i),gt.push({id:i,insert:B,place:F}),it(e.insert);continue}let o=et(e?.unit);if(e?.force===!0&&o.gone&&typeof e.hash=="string"&&typeof e.unit.id!="string"){let B=Number.isInteger(e.unit.open)&&e.unit.open>=0?h?.units[e.unit.open]:void 0;o=!h||h.units.some(V=>V!==B&&wt(m,V)===e.hash)?{reason:"ambiguous"}:tt(-1,e.hash,!1,[e.unit.blockId]),o.unit&&!o.unit.blockId&&typeof e.unit.blockId=="string"&&X.set(o.unit.id,e.unit.blockId),H.set(e.unit.key,o)}if(e?.source&&o.gone&&typeof e.unit.id=="string"&&e.parts&&typeof e.parts=="object"){let B=Object.entries(e.parts).filter(([,V])=>typeof V=="string"),F=B.length>0?p.units.filter(V=>V.parts&&!xt.has(V.blockId)&&B.every(([P,R])=>V.parts[P]===R)):[];F.length===1&&(o={unit:F[0]},F[0].blockId||X.set(F[0].id,e.unit.id),H.set(e.unit.key,o),ut(e.unit,o)&&z.add(e.unit.key))}let b=typeof e?.size=="string"||typeof e?.toggle=="string"||typeof e?.attribute=="string",M=e?.remove===!0&&Array.isArray(e.items)&&e.force!==!0&&!!o.unit&&ut(e.unit,o)&&yt(o.unit,e.items);if(e?.remove===!0&&Array.isArray(e.items)&&e.force!==!0&&!M&&(o.gone||o.unit&&ut(e.unit,o))){let B=e.items.map(P=>({ref:P,found:et(P)})),F=B.find(P=>!P.found.unit&&!P.found.gone),V=B.filter(P=>P.found.unit&&!$t.has(P.found.unit));if(F)Y(_,i,F.found.reason);else if(V.some(P=>ut(P.ref,P.found)))o.unit?Ut(i,o.unit):Y(_,i,"changed");else if(V.some(P=>Mt.has(P.found.unit)))Y(_,i,"ambiguous");else{_.set(i,{key:i,status:"applied"});for(let{ref:P,found:R}of V)Mt.set(R.unit,P.key),Ht(R.unit.id,i),gt.push({id:R.unit.id,remove:!0})}continue}if(!o.unit){o.gone&&(e?.remove===!0||b)?_.set(i,{key:i,status:"applied"}):Y(_,i,o.gone?"missing":o.reason);continue}if(e.replace&&se(o.unit,e.replace)){_.set(i,{key:i,status:"applied"});continue}if(e.source){let B=Q[o.unit.kind]?.definition?.(o.unit.node,qt().packages);if(typeof B!="string"||B!==e.definition){Y(_,i,"definition");continue}}if(e.table&&Q[o.unit.kind]?.definition){Y(_,i,"invalid");continue}let E=e.source;if(e.source&&typeof e.source=="object"&&(e.force===!0||ut(e.unit,o))){let B=e.force===!0||!o.changed,F=Et=>B&&Et.every(Ft=>typeof e.parts?.[Ft]=="string"&&e.parts[Ft]===o.unit.parts?.[Ft]),V=Rn(e.source,e.together),P=V.filter(F).flat(),R=V.filter(Et=>!F(Et)).flat();if(R.length>0){if(Ut(i,o.unit,R,P.length>0?{wrote:P}:{}),P.length===0)continue;E=Object.fromEntries(P.map(Et=>[Et,e.source[Et]]))}}else if((e.remove===!0||e.replace||e.table)&&!M&&(e.force===!0?j(o.unit)!==e.hash:ut(e.unit,o))){Ut(i,o.unit);continue}let $=E!==e.source;if(Mt.has(o.unit)&&Mt.get(o.unit)!==e.unit.key){Y(_,i,"ambiguous");continue}Mt.set(o.unit,e.unit.key);let A=null;if(e.remove===!0){A={remove:!0};let{unit:B}=o,F=B.companion?Ye(s,B):mt(s.slice(B.start,B.end),G(s,B.start),"");Rt[i]={source:F,seal:I?I(F):null,...Lt(B).length>0?{around:!0}:{}}}else if(e.move){let B=oe(e.move);if(!B){Y(_,i,"position");continue}A={move:B,stood:e.stood}}else e.replace?A={replace:e.replace}:typeof e.retag=="string"?A={retag:e.retag}:e.table&&typeof e.table=="object"?A={table:e.table}:E&&typeof E=="object"?A={source:E}:typeof e.toggle=="string"?A={toggle:e.toggle,on:e.on}:typeof e.size=="string"?A={size:e.size,value:e.value}:typeof e.attribute=="string"&&(A={attribute:e.attribute,value:e.value});if(!A){Y(_,i,"unknown");continue}$||_.set(i,{key:i,status:"applied"}),Ht(o.unit.id,i),gt.push({id:o.unit.id,...A}),A.move&&Z.add(o.unit),A.remove&&le.push({key:i,unit:o.unit})}for(let{key:e,unit:i}of le)Lt(i).every(o=>Z.has(o))||(Y(_,e,"position"),delete Rt[e],gt.splice(gt.findIndex(o=>o.id===i.id&&o.remove),1));let Ie=[...new Set(k.map(et).filter(e=>e.unit).map(e=>e.unit.id))],D=un({current:s,edits:dt,units:gt,partial:!0,ids:O,touch:Ie,proposals:X}),jt=gn(D.text,new Set((D.ids?.created??[]).map(({id:e})=>e)));D.text=jt.text;for(let e of D.conflicts??[]){e.id!==void 0&&Jt.has(e.id)&&Y(kt,Jt.get(e.id),e.reason);for(let i of _t.get(e.unit)??[])Y(_,i,e.reason),delete Rt[i]}let pt=Ot(D.text),At=new Map,ot=new Map(D.ids.assigned.map(({at:e,id:i})=>[e,i]));for(let[e,i]of H){let o=i.unit?i.unit.blockId??ot.get(i.unit.at):null;o&&At.set(e,o)}for(let[e,{unit:i,held:o}]of Wt){let b=i.blockId??ot.get(i.at),M=b?pt.units.filter(E=>E.blockId===b):[];M.length===1&&_.get(e)?.reason==="changed"&&Object.assign(_.get(e),Zt(D.text,pt,M[0],o))}let ht=new Map([...ne,...D.ids.created].map(({key:e,id:i})=>[e,i])),bt=new Set([...At.values(),...ht.values()]),ae=new Set(pt.units.map(e=>e.blockId).filter(Boolean)),ce=[...bt].filter(e=>!ae.has(e)),Qt=new Map,Tt=new Map,fe=e=>{let o=(Array.isArray(e?.children)?e.children.map(fe).some(Boolean):!1)||[e?.unit,e?.copy].some(b=>b!==void 0&&z.has(b?.key));return e?.key!==void 0&&Tt.set(e.key,o),o};for(let e of g)e?.insert&&fe({...e.insert,key:e.insert.key??e.key});for(let[e,i]of[...At,...[...ht].filter(([o])=>Tt.get(o)!==!0)]){if(z.has(e))continue;let o=pt.units.filter(b=>b.blockId===i);o.length===1&&Qt.set(e,wt(D.text,o[0]))}let Se=g.filter(e=>ve[e?.insert?.type]?.keyed&&typeof e.insert.id=="string"&&_.get(e.key)?.status==="applied").map(e=>({key:e.insert.id,box:ve[e.insert.type].box}));return{text:D.text,version:pe(D.text),texts:[...kt.values()],units:[..._.values()],ids:Object.fromEntries(At),made:Object.fromEntries(ht),hashes:Object.fromEntries(Qt),removed:Rt,gone:ce,file:Vn(D.text,pt,bt,new Set(ht.values())),outside:Dn(D.text,pt),keyed:Fn(D.text,pt,Se),...Object.keys(jt.keys).length>0?{chartKeys:jt.keys}:{},...D.title?{title:D.title}:{},...D.icon!==void 0?{icon:D.icon}:{}}}function Rn(s,m){let w=[];for(let g of[...Array.isArray(m)?m:[],...Object.keys(s).map(k=>[k])]){let k=Array.isArray(g)?g.filter(I=>typeof I=="string"&&Object.hasOwn(s,I)):[],O=w.filter(I=>k.some(a=>I.includes(a)));if(k.length!==0){for(let I of O)w.splice(w.indexOf(I),1);w.push([...new Set([...O.flat(),...k])])}}return w}function Fn(s,m,w){let g={};for(let{key:k,box:O}of w){let I=m.boxes.find(a=>a.kind===O&&a.key===k);I&&(g[k]={units:m.units.filter(a=>a.box===I.id).map(a=>a.blockId??{hash:wt(s,a)})})}return g}function Dn(s,m){let w={};for(let g of m.blocks){let k=g.unit===null?_n(g.kind==="title",bn(g.node,"id")):null;k&&(w[k]=s.slice(g.innerStart,g.innerEnd))}return w}function Vn(s,m,w,g){let k=new Map;for(let a of m.units)a.blockId&&k.set(a.blockId,(k.get(a.blockId)??0)+1);let O=a=>{for(let p=a.parent;p!=null;p=m.units[p].parent)if(g.has(m.units[p].blockId))return!0;return!1},I={};for(let a of m.units){if(!a.blockId||k.get(a.blockId)!==1||!(w.has(a.blockId)||O(a)))continue;let p=a.parent===null?null:m.units[a.parent];I[a.blockId]={kind:a.kind,hash:wt(s,a),keep:a.keep??null,...a.grid?{grid:!0}:{},...a.parts?{parts:a.parts}:{},parent:p?p.blockId??"":null,boxes:m.boxes.filter(h=>h.unit===a.id).map(h=>({kind:h.kind,key:h.key,units:m.units.filter(u=>u.box===h.id).map(u=>u.blockId??{hash:wt(s,u)})})),blocks:m.blocks.filter(h=>h.unit===a.id).map(h=>({...h.self!==null?{self:!0}:{path:h.path},kind:h.kind,caps:Object.keys(h.caps),inner:s.slice(h.innerStart,h.innerEnd),...h.atoms.length>0?{atoms:h.atoms}:{}})),...Q[a.kind]?.definition&&(g.has(a.blockId)||O(a))?{markup:s.slice(a.elStart,a.end)}:{}}}return I}function Vs({current:s,units:m=[]}){let w=Ot(s),g=[];for(let k of m){if(typeof k?.id!="string"||typeof k.key!="string"&&typeof k.key!="number")continue;let O=w.units.filter(a=>a.blockId===k.id);if(O.length===0){g.push({key:k.key,gone:!0});continue}if(O.length>1||k.from===void 0||k.from===k.parent||k.from===""||k.parent==="")continue;(O[0].parent===null?null:w.units[O[0].parent].blockId??"")===k.from&&g.push({key:k.key,moved:!0})}return g}function Gs({current:s,instances:m=[],pageIds:w=null}){let g=Ot(s),k=new Set(Array.isArray(w)?w.filter(I=>typeof I=="string"):[]),O=[];for(let I of m){if(typeof I?.id!="string"||typeof I.key!="string"&&typeof I.key!="number"||!I.parts||typeof I.parts!="object")continue;let a=j=>Object.entries(I.parts).filter(([H,z])=>typeof j.parts?.[H]=="string"&&j.parts[H]!==z?.after&&Array.isArray(z?.before)&&z.before.includes(j.parts[H])),p=g.units.filter(j=>j.blockId===I.id),h=p.length===0?g.units.filter(j=>j.parts&&!k.has(j.blockId)&&a(j).length>0):[],u=p.length===1?p[0]:h.length===1?h[0]:null,L=u?a(u):[];L.length>0&&O.push({key:I.key,parts:Object.fromEntries(L.map(([j])=>[j,u.parts[j]])),markup:s.slice(u.elStart,u.end)})}return O}function Ys({current:s,opening:m=null,texts:w=[],pageIds:g=null}){let k=w.filter(u=>typeof u?.block?.before=="string"&&typeof u.original=="string").map(u=>({entry:u,was:new Set([u.original,...Array.isArray(u.earlier)?u.earlier.filter(L=>typeof L=="string"):[]].filter(L=>L!==u.block.before))})).filter(({was:u})=>u.size>0),O=u=>Hn({current:s,opening:m,ids:!1,pageIds:g,texts:u.map(({entry:{key:L,block:j}})=>({key:L,block:j,parts:[{keep:!0,html:j.before}]}))}).texts,I=O(k),a=new Set(I.filter(u=>u.reason==="overlap").map(u=>u.key)),p=[...I.filter(u=>!a.has(u.key)),...k.filter(({entry:u})=>a.has(u.key)).flatMap(u=>O([u]))],h=new Map(k.map(({entry:u,was:L})=>[u.key,L]));return p.filter(u=>u.status==="merged"&&h.get(u.key)?.has(u.html)).map(({key:u,html:L})=>({key:u,theirs:L}))}export{un as a,bs as b,mn as c,Hn as d,Vs as e,Gs as f,Ys as g};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b}from"./chunk-7QQBR7PB.mjs";import"./chunk-LHTFLRB6.mjs";import"./chunk-ZBIM6ARY.mjs";import"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";export{a as copiedLines,b as run};
2
+ import{a,b}from"./chunk-BFE45AKL.mjs";import"./chunk-5MHMDLZD.mjs";import"./chunk-64K7IPLO.mjs";import"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";export{a as copiedLines,b as run};
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as u}from"./chunk-E7VYDG2X.mjs";import l from"node:fs/promises";import p from"node:path";import{escapeMarkup as b}from"../browser/shared/escape.mjs";import{sha256 as g}from"../browser/shared/files.mjs";import{reportsDirectory as E,starterDirectory as y}from"../browser/shared/paths.mjs";import{listReportSlugs as T,slugPattern as S}from"../browser/shared/reports.mjs";import{documentDirectory as N,documentFiles as $,layoutOf as O,slugTaken as j}from"../browser/shared/workspace.mjs";async function v(t,c){if(!S.test(t))throw new Error(`A document's folder name must be lowercase kebab-case: ${t}`);let s=N(t,c),{html:r,json:n}=$(s),[m,o]=[p.basename(r),p.basename(n)],e,f;try{[e,f]=await Promise.all([l.readFile(r),l.readFile(n,"utf8")])}catch(a){if(a.code!=="ENOENT")throw a;let h=await l.stat(s).then(()=>!0,()=>!1);throw new Error(h?`${s} needs both ${m} and ${o}.`:`${s} does not exist.`)}let i;try{i=JSON.parse(f)}catch(a){throw new Error(`${o} is not valid JSON: ${a.message}`)}for(let a of["title","description","type"])if(typeof i[a]!="string"||i[a].trim()==="")throw new Error(`${o} is missing a non-empty ${a}.`);if(i.source!==void 0&&typeof i.source!="string")throw new Error(`${o} source must be a string when given.`);return{slug:t,directory:s,htmlPath:r,metadataPath:n,html:e.toString("utf8"),fileSha256:g(e),metadata:i}}async function z(t=[],{directory:c=E,prepare:s=null}={}){let r=t.length>0?[...new Set(t)]:await T(c);if(r.length===0)throw new Error(`No documents in ${p.resolve(c)} yet: gallery new <slug> "<title>" makes one.`);let n=[],m=new Map;for(let o of r)try{let e=await v(o,c);s&&([e.written,e.html]=[u(e.html),s(e)]),n.push(e)}catch(e){m.set(o,[e.message])}return{reports:n,failures:m}}var F=/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/,P=/\n[ \t]*<!-- Starter content:[^\n]*-->\n[ \t]*<section\b[^>]*\sdata-doc-placeholder\b[\s\S]*?<\/section>/;async function M(t,c,s,{directory:r=E,blank:n=!1,lang:m=null,page:o=!1}={}){if(!S.test(t))throw new Error("Slug must be lowercase kebab-case.");if(j(t,r))throw Object.assign(new Error(`"${t}" is taken in ${p.resolve(r)}`),{code:"EEXIST"});let e=o?O(r).pages:p.resolve(r),f=p.join(e,t),{html:i,metadata:a}=await R(t,c,s,{blank:n,lang:m});await l.mkdir(e,{recursive:!0}),await l.mkdir(f,{recursive:!1});let h=$(f);return await Promise.all([l.writeFile(h.html,i),l.writeFile(h.json,`${JSON.stringify(a,null,2)}
2
+ import{a as u}from"./chunk-UMHUSOPJ.mjs";import l from"node:fs/promises";import p from"node:path";import{escapeMarkup as b}from"../browser/shared/escape.mjs";import{sha256 as g}from"../browser/shared/files.mjs";import{reportsDirectory as E,starterDirectory as y}from"../browser/shared/paths.mjs";import{listReportSlugs as T,slugPattern as S}from"../browser/shared/reports.mjs";import{documentDirectory as N,documentFiles as $,layoutOf as O,slugTaken as j}from"../browser/shared/workspace.mjs";async function v(t,c){if(!S.test(t))throw new Error(`A document's folder name must be lowercase kebab-case: ${t}`);let s=N(t,c),{html:r,json:n}=$(s),[m,o]=[p.basename(r),p.basename(n)],e,f;try{[e,f]=await Promise.all([l.readFile(r),l.readFile(n,"utf8")])}catch(a){if(a.code!=="ENOENT")throw a;let h=await l.stat(s).then(()=>!0,()=>!1);throw new Error(h?`${s} needs both ${m} and ${o}.`:`${s} does not exist.`)}let i;try{i=JSON.parse(f)}catch(a){throw new Error(`${o} is not valid JSON: ${a.message}`)}for(let a of["title","description","type"])if(typeof i[a]!="string"||i[a].trim()==="")throw new Error(`${o} is missing a non-empty ${a}.`);if(i.source!==void 0&&typeof i.source!="string")throw new Error(`${o} source must be a string when given.`);return{slug:t,directory:s,htmlPath:r,metadataPath:n,html:e.toString("utf8"),fileSha256:g(e),metadata:i}}async function z(t=[],{directory:c=E,prepare:s=null}={}){let r=t.length>0?[...new Set(t)]:await T(c);if(r.length===0)throw new Error(`No documents in ${p.resolve(c)} yet: gallery new <slug> "<title>" makes one.`);let n=[],m=new Map;for(let o of r)try{let e=await v(o,c);s&&([e.written,e.html]=[u(e.html),s(e)]),n.push(e)}catch(e){m.set(o,[e.message])}return{reports:n,failures:m}}var F=/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/,P=/\n[ \t]*<!-- Starter content:[^\n]*-->\n[ \t]*<section\b[^>]*\sdata-doc-placeholder\b[\s\S]*?<\/section>/;async function M(t,c,s,{directory:r=E,blank:n=!1,lang:m=null,page:o=!1}={}){if(!S.test(t))throw new Error("Slug must be lowercase kebab-case.");if(j(t,r))throw Object.assign(new Error(`"${t}" is taken in ${p.resolve(r)}`),{code:"EEXIST"});let e=o?O(r).pages:p.resolve(r),f=p.join(e,t),{html:i,metadata:a}=await R(t,c,s,{blank:n,lang:m});await l.mkdir(e,{recursive:!0}),await l.mkdir(f,{recursive:!1});let h=$(f);return await Promise.all([l.writeFile(h.html,i),l.writeFile(h.json,`${JSON.stringify(a,null,2)}
3
3
  `)]),{slug:t,directory:f,metadata:a}}async function R(t,c,s,{blank:r=!1,lang:n=null}={}){let m=w=>b(w).replaceAll("'","&#39;"),[o,e]=await Promise.all([l.readFile(p.join(y,"doc.html"),"utf8"),l.readFile(p.join(y,"doc.json"),"utf8")]),f={...JSON.parse(e),title:c,description:s},i=r?o.replace(P,`
4
4
  <p></p>`):o;if(r&&i===o)throw new Error("The starter's placeholder section was not found.");let a=typeof n=="string"&&F.test(n)?i.replace(/(<html\b[^>]*\slang=")[^"]*"/,(w,d)=>`${d}${n}"`):i,h={SLUG:t,TITLE:m(c)};return{html:a.replace(/__REPORT_(SLUG|TITLE)__/g,(w,d)=>h[d]),metadata:f}}export{z as a,M as b,R as c};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as d,e as L}from"./chunk-A55HN5OK.mjs";L();import{instanceSlots as x,isInstance as A}from"../browser/shared/components/index.mjs";import{mayHoldOldNames as I,newAttributeName as S,newAttributeValue as b,newScriptNames as N,newStyleNames as j}from"../browser/shared/old-names.mjs";var T=/^data-(?:report|doc)-(?:kit|vendor)$/;function E(o){if(typeof o!="string"||!I(o))return o;let O=d(o,{sourceCodeLocationInfo:!0}),c=[],l=(t,e,s)=>{o.slice(t,e)!==s&&c.push({start:t,end:e,text:s})};function g(t){let e=t.sourceCodeLocation?.attrs??{};for(let{name:n,value:y}of t.attrs){let r=e[n];if(!r)continue;let i=o.slice(r.startOffset,r.endOffset),f=i.indexOf("="),v=f<0?i:i.slice(0,f),m=f<0?"":i.slice(f),C=/^on/i.test(n)||/^\s*javascript:/i.test(y)?N(m):b(n,m,t.tagName);l(r.startOffset,r.endOffset,S(v)+C)}if(t.attrs.some(({name:n})=>T.test(n))||!["style","script"].includes(t.tagName))return;let s=t.childNodes?.[0]?.sourceCodeLocation;if(!s)return;let w=(t.attrs.find(({name:n})=>n==="type")?.value??"").trim().toLowerCase();if(t.tagName==="script"&&/json/.test(w))return;let p=o.slice(s.startOffset,s.endOffset);l(s.startOffset,s.endOffset,t.tagName==="style"?j(p):N(p))}let u=t=>{for(let e of t.childNodes??[]){if(A(e)){x(e).forEach(u);continue}e.tagName&&g(e),u(e.tagName==="template"&&e.content?e.content:e)}};if(u(O),!c.length)return o;c.sort((t,e)=>e.start-t.start);let a=o;for(let{start:t,end:e,text:s}of c)a=a.slice(0,t)+s+a.slice(e);return a}export{E as a};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as $,b as y,c as k,d as x}from"./chunk-S6O4UHLC.mjs";import{a as F,b as h}from"./chunk-TX6JH7TR.mjs";import{b as j,f as D,h as N}from"./chunk-NSKUTQ5J.mjs";import"./chunk-5L7RYZCL.mjs";import S from"node:fs/promises";import{iconKind as I}from"../browser/shared/emoji/icon-value.mjs";import{descendantsIn as O,parentIn as P}from"../browser/shared/outline.mjs";import{fullAddress as T,namedPlace as A}from"../browser/shared/page-address.mjs";import{reportsDirectory as L}from"../browser/shared/paths.mjs";import{documentLinks as R,listReportSlugs as v,roleOf as C}from"../browser/shared/reports.mjs";import{documentDirectory as E,documentFiles as H,isSlugName as J}from"../browser/shared/workspace.mjs";import{findIn as K,rankReports as U,reportLines as Y}from"../browser/shared/search.mjs";async function q(){let i=(await v(L)).filter(J);return(await Promise.all(i.map(async e=>{let l=E(e,L),{html:c,json:a}=H(l),o=await S.stat(c).catch(()=>null);if(!o?.isFile()||await C(l)==="instructions")return null;let r=await S.readFile(a,"utf8").then(JSON.parse).catch(()=>({})),t=n=>typeof n=="string"?n.replace(/\s+/g," ").trim():"";return{slug:e,title:t(r.title)||e,description:t(r.description),edited:o.mtimeMs,file:c}}))).filter(Boolean)}var M=i=>{let s=new Date(i),e=l=>String(l).padStart(2,"0");return`${s.getFullYear()}-${e(s.getMonth()+1)}-${e(s.getDate())} ${e(s.getHours())}:${e(s.getMinutes())}`},p=i=>`${i} document${i===1?"":"s"}`;async function z(i,s,e){let l=[...new Set(e.toLowerCase().split(/\s+/).filter(Boolean))],c=new Set(s.map(({slug:o})=>o));return(await Promise.all(i.filter(({slug:o})=>!c.has(o)).map(async o=>{let r=Y(await S.readFile(o.file,"utf8").catch(()=>"")),t=l.map(n=>K(r,n,{most:1})).filter(({count:n})=>n>0);return t.length?{...o,words:t.length,count:t.reduce((n,{count:f})=>n+f,0),hit:t[0].hits[0].text}:null}))).filter(Boolean).sort((o,r)=>r.words-o.words||r.count-o.count||r.edited-o.edited)}async function G(i,s){if(i.length>1)throw new j("--tree takes one document at most (its slug, link or address).");let e=await $(),l=new Map(s.map(t=>[t.slug,t])),c=e.children[""]??[],a=null;if(i.length===1){let t=await x(i[0],"--tree",e);if(t.refused){for(let n of await h())console.log(n);console.error(t.refused),process.exit(1)}a=t.slug,c=[a]}for(let t of await h())console.log(t);let o=Object.values(e.children).flat().length;if(o===0)return void console.log('No documents yet: gallery new <slug> "<title>" makes one.');if(a===null)console.log(`${p(o)}, as the sidebar shows them (one under another indented):`);else{let t=O(e.children,a).length;console.log(k(e,a)),console.log(t?`${y(e,a)} and the ${p(t)} under it, as the sidebar shows them:`:`${y(e,a)}, with no document under it:`)}let r=(t,n)=>{let{title:f,description:u,icon:d}=e.documents.get(t),g=l.get(t)?.edited,m=[...u?[`\u8BF4\u660E\uFF1A${u}`]:[],...g?[`\u4E0A\u6B21\u7F16\u8F91\uFF1A${M(g)}`]:[]];console.log(`${" ".repeat(n)}${t} ${I(d)==="emoji"?`${d} `:""}${f}${m.length?` \uFF08${m.join("\uFF1B")}\uFF09`:""}`);for(let w of e.children[t]??[])r(w,n+1)};for(let t of c)r(t,0)}async function lt(i){let{positional:s,options:e}=D({options:["--tree"],argv:i}),l=await q();if(e.has("--tree"))return G(s,l);let c=s.join(" ").trim(),{links:a}=await R(),o=s.length===1?A(s[0],a):null,r=o&&o.slug!==s[0],t=r?l.filter(({slug:d})=>d===o.slug):U(l,c),n=[...t,...c&&!r?await z(l,t,c):[]],f=s.length===1&&n.length===0?await N(s[0]):null,u=n.length?await $():null;for(let d of await h())console.log(d);if(f)console.log(f);else if(l.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.');else if(n.length===0)console.log(`No document's title, description, slug or text holds ${c.split(/\s+/).map(d=>`"${d}"`).join(" or ")}: gallery list lists all ${l.length}.`);else{console.log(c?`${n.length} of ${p(l.length)}, the best match first:`:`${p(l.length)}, the one edited last first:`);for(let{slug:d,title:g,description:m,edited:w,file:B,hit:b}of n)console.log(`${d} ${g}`),m&&console.log(` \u8BF4\u660E\uFF1A${m}`),b&&console.log(` \u6B63\u6587\uFF1A${b}`),P(u.children,d)&&console.log(` ${k(u,d)}`),console.log(` \u5730\u5740\uFF1A${T("",{slug:d},a)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${M(w)}`),console.log(` ${F(B)}`)}}export{lt as run};