@heycys/gallery 0.2.2 → 0.2.4

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 (222) hide show
  1. package/README.md +1 -1
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/assets/preview/runtime.js +156 -0
  4. package/assets/preview/shell.html +107 -0
  5. package/assets/writing-preferences.md +1 -1
  6. package/browser/editor/components/divider/index.mjs +1 -1
  7. package/browser/editor/page/annotate/card.mjs +6 -0
  8. package/browser/editor/page/annotate/index.mjs +22 -2
  9. package/browser/editor/page/columns/index.mjs +1 -1
  10. package/browser/editor/page/conflicts.mjs +1 -1
  11. package/browser/editor/page/drag/index.mjs +1 -1
  12. package/browser/editor/page/editor.mjs +43 -5
  13. package/browser/editor/page/focus.mjs +104 -0
  14. package/browser/editor/page/handle/index.mjs +14 -2
  15. package/browser/editor/page/links/index.mjs +2 -2
  16. package/browser/editor/page/quiet.mjs +3 -3
  17. package/browser/editor/page/resize/index.mjs +1 -1
  18. package/browser/editor/page/session.mjs +4 -1
  19. package/browser/editor/page/ui.mjs +1 -1
  20. package/browser/shared/annotations.mjs +22 -3
  21. package/browser/shared/block-packs.mjs +13 -4
  22. package/browser/shared/document-look.mjs +14 -0
  23. package/browser/shared/drafts.mjs +1 -1
  24. package/browser/shared/extension-manifest.mjs +40 -12
  25. package/browser/shared/favorite-merge.mjs +17 -0
  26. package/browser/shared/favorites.mjs +77 -0
  27. package/browser/shared/i18n/en.mjs +123 -24
  28. package/browser/shared/outline-ops.mjs +109 -0
  29. package/browser/shared/outline.mjs +6 -0
  30. package/browser/shared/pages.mjs +20 -8
  31. package/browser/shared/paths.mjs +5 -2
  32. package/browser/shared/preference-documents.mjs +137 -0
  33. package/browser/shared/presence.mjs +94 -0
  34. package/browser/shared/preview-server.mjs +8 -5
  35. package/browser/shared/qa-levels.mjs +9 -1
  36. package/browser/shared/session.mjs +4 -0
  37. package/browser/shared/shipped-blocks.mjs +22 -4
  38. package/browser/shared/startup.mjs +101 -0
  39. package/browser/shared/workspace-address.mjs +3 -0
  40. package/browser/shared/workspace-columns.mjs +1 -1
  41. package/browser/shared/workspace-look.mjs +21 -8
  42. package/browser/shared/workspace-registry.mjs +6 -3
  43. package/browser/shared/workspace.mjs +37 -10
  44. package/browser/shared/writing-preferences.mjs +2 -42
  45. package/dist/chunk-25LYSMAE.mjs +2 -0
  46. package/dist/chunk-2I6ZVC5O.mjs +2 -0
  47. package/dist/{chunk-M4NRDYI5.mjs → chunk-2MYTOOP6.mjs} +1 -1
  48. package/dist/chunk-2VNENLER.mjs +2 -0
  49. package/dist/chunk-3FERXZF5.mjs +4 -0
  50. package/dist/chunk-3M6SBBGU.mjs +2 -0
  51. package/dist/chunk-3VCAAF34.mjs +2 -0
  52. package/dist/{chunk-JXXHAXYH.mjs → chunk-3ZTRLGSA.mjs} +1 -1
  53. package/dist/chunk-4FRA5AUE.mjs +2 -0
  54. package/dist/chunk-4LR2QEC2.mjs +4 -0
  55. package/dist/chunk-56SVJENP.mjs +966 -0
  56. package/dist/chunk-5CQISL2G.mjs +4 -0
  57. package/dist/{chunk-RRKJMHNX.mjs → chunk-5I5ZDDWC.mjs} +5 -5
  58. package/dist/chunk-5IHDLEB4.mjs +10 -0
  59. package/dist/chunk-5LRDMV7O.mjs +2 -0
  60. package/dist/chunk-5MVUYRKG.mjs +5 -0
  61. package/dist/chunk-5TLLIZT7.mjs +2 -0
  62. package/dist/chunk-6ILJWFYW.mjs +4 -0
  63. package/dist/chunk-6N25CJ6Y.mjs +3 -0
  64. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-7DTINW6U.mjs} +2 -2
  65. package/dist/chunk-7KWAGKIK.mjs +2 -0
  66. package/dist/chunk-7WNUOAFK.mjs +2 -0
  67. package/dist/chunk-7XCRW5RC.mjs +2 -0
  68. package/dist/{chunk-ERE2BXYV.mjs → chunk-7XSDTILF.mjs} +1 -1
  69. package/dist/chunk-ABKYFOVR.mjs +2 -0
  70. package/dist/chunk-AMUF7PUN.mjs +2 -0
  71. package/dist/{chunk-PLB7L22J.mjs → chunk-B2EIMERT.mjs} +2 -2
  72. package/dist/{chunk-QNECWMGR.mjs → chunk-B45IAAU6.mjs} +1 -1
  73. package/dist/chunk-B6RAGF4R.mjs +2 -0
  74. package/dist/chunk-BSJKFE7I.mjs +4 -0
  75. package/dist/chunk-C72EEVLK.mjs +2 -0
  76. package/dist/chunk-CRAUKZ23.mjs +4 -0
  77. package/dist/chunk-F4CT35KL.mjs +2 -0
  78. package/dist/chunk-F63BNJLG.mjs +2 -0
  79. package/dist/chunk-FBKUPS44.mjs +2 -0
  80. package/dist/chunk-FL52ZL5Z.mjs +15 -0
  81. package/dist/chunk-FOZCU4VW.mjs +2 -0
  82. package/dist/chunk-G5HV7BC3.mjs +2 -0
  83. package/dist/{chunk-ERLAIBOA.mjs → chunk-GB5SOYQJ.mjs} +2 -2
  84. package/dist/chunk-GN3SG3IF.mjs +2 -0
  85. package/dist/{chunk-6QWQXHAV.mjs → chunk-HFTBVEZK.mjs} +1 -1
  86. package/dist/chunk-IOW5HLRK.mjs +2 -0
  87. package/dist/chunk-IQ3GJNTI.mjs +6 -0
  88. package/dist/chunk-K6SPFBUJ.mjs +2 -0
  89. package/dist/chunk-K7Y7SPTS.mjs +2 -0
  90. package/dist/chunk-L2IJCEUH.mjs +2 -0
  91. package/dist/{chunk-GPIWQ4X4.mjs → chunk-L3VT6LM4.mjs} +1 -1
  92. package/dist/chunk-L4WLQYFC.mjs +5 -0
  93. package/dist/{chunk-FFV733MA.mjs → chunk-LAMCAGK6.mjs} +1 -1
  94. package/dist/chunk-LHGKPMTI.mjs +2 -0
  95. package/dist/chunk-LJZIYVNA.mjs +3 -0
  96. package/dist/chunk-LSVCTLS2.mjs +2 -0
  97. package/dist/chunk-LZY74XTP.mjs +2 -0
  98. package/dist/chunk-MC4LRSVH.mjs +2 -0
  99. package/dist/chunk-MCEXN4G5.mjs +2 -0
  100. package/dist/chunk-MTLAOCFF.mjs +181 -0
  101. package/dist/chunk-MZ66LN3B.mjs +2 -0
  102. package/dist/chunk-N5QWJRRI.mjs +2 -0
  103. package/dist/chunk-NF4MMOUB.mjs +2 -0
  104. package/dist/chunk-NHJYAJ73.mjs +3 -0
  105. package/dist/chunk-NRSD7SVY.mjs +2 -0
  106. package/dist/chunk-NT23I4XW.mjs +2 -0
  107. package/dist/chunk-NUALABIS.mjs +3 -0
  108. package/dist/chunk-NW6LAU22.mjs +2 -0
  109. package/dist/chunk-NWWHDGKF.mjs +5 -0
  110. package/dist/chunk-OFRCVMSJ.mjs +2 -0
  111. package/dist/chunk-OKVQQ3CX.mjs +4 -0
  112. package/dist/chunk-OM24O4KR.mjs +8 -0
  113. package/dist/{chunk-4B2TB5K2.mjs → chunk-PBMOC7KA.mjs} +2 -2
  114. package/dist/chunk-PVTCP43W.mjs +2 -0
  115. package/dist/chunk-Q62HZAJS.mjs +2 -0
  116. package/dist/chunk-QBJWIR3Q.mjs +2 -0
  117. package/dist/chunk-QDSEZX7Z.mjs +6 -0
  118. package/dist/chunk-QR4V4A2Z.mjs +15 -0
  119. package/dist/{chunk-QVGOPHOF.mjs → chunk-QRLVVZ3R.mjs} +1 -1
  120. package/dist/chunk-QW3QG67J.mjs +2 -0
  121. package/dist/chunk-R2T2EVWY.mjs +8 -0
  122. package/dist/{chunk-GJJRBGMY.mjs → chunk-R5RERE6G.mjs} +1 -1
  123. package/dist/chunk-RFHEWT3Y.mjs +5 -0
  124. package/dist/chunk-RS2Z2JQP.mjs +2 -0
  125. package/dist/chunk-S6YEC4GE.mjs +16 -0
  126. package/dist/chunk-SHZLMGGW.mjs +2 -0
  127. package/dist/chunk-TALJQM2O.mjs +2 -0
  128. package/dist/chunk-TLNJWEFY.mjs +22 -0
  129. package/dist/{chunk-6Q7ASAXJ.mjs → chunk-TQZU7D7C.mjs} +1 -1
  130. package/dist/chunk-UTKNWYBA.mjs +2 -0
  131. package/dist/chunk-V3TM3TEN.mjs +2 -0
  132. package/dist/chunk-V3XROSP5.mjs +7 -0
  133. package/dist/{chunk-6QBHU4DF.mjs → chunk-V5JTW2LH.mjs} +1 -1
  134. package/dist/chunk-VAXLSISW.mjs +4 -0
  135. package/dist/chunk-VBHI3RG6.mjs +2 -0
  136. package/dist/{chunk-6L6V7YR2.mjs → chunk-VKZJRGDR.mjs} +1 -1
  137. package/dist/chunk-VZXZM7NS.mjs +2 -0
  138. package/dist/chunk-WDS6HEPE.mjs +2 -0
  139. package/dist/chunk-WHGANNEY.mjs +13 -0
  140. package/dist/chunk-WMJWC4QY.mjs +56 -0
  141. package/dist/{chunk-VZ2RQ3AM.mjs → chunk-WWONJJQS.mjs} +1 -1
  142. package/dist/chunk-X4WNLFIK.mjs +2 -0
  143. package/dist/chunk-XNNCQROX.mjs +11 -0
  144. package/dist/chunk-XRYECF23.mjs +170 -0
  145. package/dist/{chunk-K3JKPFL5.mjs → chunk-Z4NEXXFK.mjs} +1 -1
  146. package/dist/{chunk-236JJXWY.mjs → chunk-ZFVF2YPV.mjs} +2 -2
  147. package/dist/chunk-ZM2IX3R2.mjs +2 -0
  148. package/dist/chunk-ZNGGDUZI.mjs +2 -0
  149. package/dist/chunk-ZOEJQOKT.mjs +2 -0
  150. package/dist/cli.mjs +1 -1
  151. package/dist/server.mjs +1 -1
  152. package/dist/update-fetch.mjs +1 -1
  153. package/dist/worker.mjs +1 -1
  154. package/kit/runtime.js +1 -0
  155. package/package.json +1 -1
  156. package/release.json +4 -4
  157. package/skill/SKILL.md +54 -148
  158. package/skill/references/building-blocks.md +4 -4
  159. package/skill/references/charts-and-figures.md +73 -0
  160. package/skill/references/extensions.md +47 -4
  161. package/skill/references/pages-and-data.md +22 -3
  162. package/skill/references/preference-files.md +7 -0
  163. package/skill/references/previews.md +17 -0
  164. package/skill/references/writing-html.md +21 -82
  165. package/web/assets/index-B4uUluLM.js +15 -0
  166. package/web/assets/index-C3vHT8sH.css +1 -0
  167. package/web/index.html +2 -2
  168. package/dist/chunk-2KAVXMKG.mjs +0 -4
  169. package/dist/chunk-2T4PZQEP.mjs +0 -2
  170. package/dist/chunk-3SKOU6OZ.mjs +0 -10
  171. package/dist/chunk-3XZOA7AH.mjs +0 -170
  172. package/dist/chunk-4KUO7R2M.mjs +0 -16
  173. package/dist/chunk-4OZWXZE5.mjs +0 -5
  174. package/dist/chunk-4SNV4HA5.mjs +0 -2
  175. package/dist/chunk-53XDTHTG.mjs +0 -4
  176. package/dist/chunk-5XV3YYLG.mjs +0 -2
  177. package/dist/chunk-65NTKF4N.mjs +0 -6
  178. package/dist/chunk-6GV3CBB2.mjs +0 -2
  179. package/dist/chunk-6NLXUKAY.mjs +0 -4
  180. package/dist/chunk-6XD6U3QA.mjs +0 -5
  181. package/dist/chunk-7EFHNQ5B.mjs +0 -3
  182. package/dist/chunk-7ISBBDJR.mjs +0 -2
  183. package/dist/chunk-7M2BQQGZ.mjs +0 -2
  184. package/dist/chunk-7UZUQQ7Q.mjs +0 -554
  185. package/dist/chunk-ALZ6ZENZ.mjs +0 -3
  186. package/dist/chunk-BLNQUR5R.mjs +0 -168
  187. package/dist/chunk-BMX3VUHY.mjs +0 -2
  188. package/dist/chunk-BN7M3IN7.mjs +0 -8
  189. package/dist/chunk-C257H6IA.mjs +0 -2
  190. package/dist/chunk-CHQU37CA.mjs +0 -2
  191. package/dist/chunk-DR73Y2UJ.mjs +0 -3
  192. package/dist/chunk-E4IHAIJ7.mjs +0 -2
  193. package/dist/chunk-EURLTOTZ.mjs +0 -4
  194. package/dist/chunk-F4ZA6JRZ.mjs +0 -3
  195. package/dist/chunk-GKOBB6DH.mjs +0 -2
  196. package/dist/chunk-GMJD7ID3.mjs +0 -2
  197. package/dist/chunk-IA2SIEJQ.mjs +0 -2
  198. package/dist/chunk-JEUK3ZO7.mjs +0 -2
  199. package/dist/chunk-JPG2LBQM.mjs +0 -11
  200. package/dist/chunk-KLQP46Y3.mjs +0 -4
  201. package/dist/chunk-LMUZQK5O.mjs +0 -2
  202. package/dist/chunk-MKIBJTJZ.mjs +0 -6
  203. package/dist/chunk-MNWJ4EZY.mjs +0 -2
  204. package/dist/chunk-NHP66IWR.mjs +0 -5
  205. package/dist/chunk-OEIJLMPI.mjs +0 -2
  206. package/dist/chunk-PDZR3L3C.mjs +0 -2
  207. package/dist/chunk-PUOQ65NC.mjs +0 -2
  208. package/dist/chunk-Q4MS6OFC.mjs +0 -2
  209. package/dist/chunk-Q7P3Q5YX.mjs +0 -13
  210. package/dist/chunk-QP7BOHE4.mjs +0 -2
  211. package/dist/chunk-S3SX3COT.mjs +0 -20
  212. package/dist/chunk-TANZRINB.mjs +0 -2
  213. package/dist/chunk-UGWMMEJ5.mjs +0 -15
  214. package/dist/chunk-ULXSPX5H.mjs +0 -5
  215. package/dist/chunk-USIHBCSW.mjs +0 -15
  216. package/dist/chunk-VPMRP2TL.mjs +0 -2
  217. package/dist/chunk-WFGPMCTZ.mjs +0 -4
  218. package/dist/chunk-XZCFPKGO.mjs +0 -2
  219. package/dist/chunk-ZFGMJVJC.mjs +0 -2
  220. package/web/assets/index-FLb9jCfl.css +0 -1
  221. package/web/assets/index-czjrXVjf.js +0 -15
  222. /package/dist/{chunk-PAREWQGB.mjs → chunk-NOGQX56R.mjs} +0 -0
@@ -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{h as C,i as K}from"./chunk-XRYECF23.mjs";import{a as u}from"./chunk-5TLLIZT7.mjs";import{a as E,b as F,e as U,o as q,r as J,t as W}from"./chunk-OM24O4KR.mjs";import{e as I,h as L}from"./chunk-56SVJENP.mjs";import{i as z,j as B}from"./chunk-PBMOC7KA.mjs";import{a as G,e as P,f as R}from"./chunk-BSJKFE7I.mjs";import{a as Y,b as d,f as H}from"./chunk-L4WLQYFC.mjs";import{f as T}from"./chunk-TKWEX4FD.mjs";import X from"node:path";import{editStateDirectory as le,reportsDirectory as ee}from"../browser/shared/paths.mjs";import{FIRST_BOARD as de,HOME as A,createPage as he,listPages as pe,pageExists as te,pageFiles as v,pageSlugRefused as se,pagesSettings as ge,readPageMeta as fe}from"../browser/shared/pages.mjs";import{findPreviewServer as oe}from"../browser/shared/preview-server.mjs";var x=(e,t)=>`${q(e)}#@${t}`,we=(e,t)=>`http://127.0.0.1:${e}/pages/${t}`,me="The default home page (\u9996\u9875, slug home) is not made yet: Gallery makes it, with its own cards, when its server first starts in this workspace. gallery open --no-browser starts it: run that once, then gallery page list again.";async function ae(e){return B()||te(A,e)||ge(e).homeMade||await se(A,e)?null:me}async function ne(e,t){return(e===A?await ae(t):null)??`No custom page "${e}": ${u(v(e,t).html)} does not exist (gallery page list lists those there are).`}async function M(e){return(await oe({answering:!0,timeout:2e3}))?.port??null}async function ue(e,[t,a,...i]){if(!t||!a?.trim()||i.length)throw new d("Name the slug and the title, the title quoted when it has spaces.");let n=await se(t,e);n&&(console.error(n),process.exit(1));let s=await he(t,a,{root:e});console.log(`Created ${u(s.html)} and page.json`),console.log(`It is listed in the workbench's sidebar, last among the rows under \u65B0\u5EFA and \u641C\u7D22 (the user may drag it elsewhere), and shows one empty board (data-board-id="main"): use it, or write the page as you like.`);let o=await M(e),r=`write page.html: a board of cards (each <section class="gallery-card" data-card-id="\u2026" data-x data-y data-w data-h> around one custom block's instance; gallery page add places one), or any HTML, CSS and script of your own (references/pages-and-data.md)`,c="at the end tell them where it is in the sidebar (under \u65B0\u5EFA and \u641C\u7D22, its title)";o?(console.log(`\u4E0B\u4E00\u6B65\uFF1Asend the user the address on the last line now, in a message of its own (the page is theirs to watch as its cards arrive); ${r}; ${c}.`),console.log(`${E}${x(o,t)}`)):console.log(`\u4E0B\u4E00\u6B65\uFF1Arun gallery page open ${t} --no-browser now (it starts the server) and send the user the address on its \u4EA4\u7ED9\u7528\u6237 line, in a message of its own, before you write any card (the page is theirs to watch as its cards arrive); then ${r}; ${c}.`)}async function $e(e,t,a){if(t.length)throw new d("gallery page list takes nothing else.");let i=await pe(e),n=await ae(e);if(a.has("--json")){let o=await M(e);console.log(JSON.stringify({workspace:X.resolve(e),server:o?{port:o}:null,pages:i.map(({slug:r,title:c,icon:m,defaultCards:h})=>({slug:r,title:c,icon:m,defaultCards:h,address:o?x(o,r):`/#@${r}`,file:X.resolve(v(r,e).html)})),homeNotMade:!!n},null,2));return}console.log(`\u5DE5\u4F5C\u533A\uFF1A${u(e)}`),i.length===0&&!n?console.log('No custom pages yet: gallery page new <slug> "<\u6807\u9898>" makes one.'):i.length>0&&console.log(`Custom pages, in the sidebar's order (${i.length}):`);let s=i.length?await M(e):null;for(let{slug:o,title:r,icon:c}of i)console.log(`- ${o} ${c?`${c} `:""}${r}`),console.log(` \u5730\u5740\uFF1A${s?x(s,o):`/#@${o}`} ${u(v(o,e).html)}`);n&&console.log(n)}async function ye(e,[t,...a],i){if(!t||a.length)throw new d("gallery page open takes one page's slug.");await fe(t,e)||(console.error(await ne(t,e)),process.exit(1)),console.log(`\u5DE5\u4F5C\u533A\uFF1A${u(e)}`);let s=await J({command:`gallery page open ${t}`});s.ok||(console.error(`\u95EE\u9898\uFF1A${s.message}`),process.exit(1));let o=[...W(s),`${F}${we(s.port,t)}`,`${E}${x(s.port,t)}`];for(let r of o)console.log(r);console.log(await U(o,i))}async function Q(e,t,a){let i=`127.0.0.1:${e.port}`;try{let n=await fetch(`http://${i}/__gallery/pages/${t}/cards`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${i}`,"X-Gallery-Token":e.token},body:JSON.stringify({...a,workspace:ee}),signal:AbortSignal.timeout(3e4)}),s=await n.json().catch(()=>null);return!s||["elsewhere","token","host","origin","unknown","method"].includes(s.reason)?null:[n.status,s]}catch{return null}}var be=8e3,ke=new Set(["missing","places","settings","values"]);async function ve(e,t,a,i=null){let n=await oe(),s=n?await Q(n,t,a):null;for(let c=0;a.op==="add"&&ke.has(s?.[1]?.reason)&&c<be/250;c++)await new Promise(m=>setTimeout(m,250)),s=await Q(n,t,a);let[o,r]=s??await z({root:e,stateDirectory:le,catalog:i??(()=>T(e))}).apply(t,a);return{status:o,answer:r,viaServer:!!s}}var k={places:e=>`${e} is a block of documents (its manifest's places has no "page"): it does not go on a custom page. To make it a card too, write "places": ["document", "page"] in its component.json ("card": { "sizes": [[4, 3]] } sizes it; on a page no text part is edited: what a reader changes there goes in a data part), then run this again.`,disabled:e=>`${e} is turned off (\u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 \u505C\u7528): nothing of it loads, on a page or in a document.`,missing:e=>`No custom block ${e} in this workspace: gallery block list lists them.`,template:e=>`${e} has no template.html a new card can be made of (gallery block check ${e} says why).`,board:(e,t)=>`No board "${t}" on this page: its <div class="gallery-board" data-board-id="\u2026">s are the ones there are.`,cells:()=>"--x, --y, --w and --h are whole numbers (x and y from 0, w and h from 1).",busy:()=>"page.html was written again and again meanwhile: run this again.",size:()=>"page.html would grow past 1,000,000 bytes.",values:(e,t,a)=>`${e}'s setting ${a?`"${a}" `:""}does not take that value (a text of 10,000 characters at most, a number, a date, one of a select's options, a switch's true or false).`,settings:e=>`${e} has no settings, or a card of it no settings part: --set goes with a block whose manifest has some.`};function Se(e){let t=e.indexOf("--"),a=[],i=[];for(let n=0;n<e.length;n++){let s=e[n];if(t!==-1&&n>=t)i.push(s);else if(s==="--set"||s.startsWith("--set=")){let o=s==="--set"?e[n+1]:s.slice(6);s==="--set"&&(n+=1);let r=o?.indexOf("=")??-1;if(o===void 0||r<1)throw new d("--set takes a setting's key and its value: --set <key>=<value> (--set city=\u4E0A\u6D77).");a.push([o.slice(0,r),o.slice(r+1)])}else i.push(s)}return{argv:i,given:a}}var V=new Map([["true",!0],["yes",!0],["on",!0],["1",!0],["false",!1],["no",!1],["off",!1],["0",!1]]);function Oe(e,t){let a=t.settings??[],i=()=>a.length?`its settings are ${a.map(({key:s,label:o})=>`${s} (${o?.en??o?.zh??s})`).join(", ")}`:"it has no settings",n={};for(let[s,o]of e){let r=a.find(c=>c.key===s);if(!r)throw new d(`${t.id} has no setting "${s}": ${i()}.`);if(Object.hasOwn(n,s))throw new d(`--set ${s} is given twice.`);if(r.type==="number"){if(o.trim()!==""&&!Number.isFinite(Number(o)))throw new d(`The setting ${s} of ${t.id} is a number: --set ${s}=<number>, or --set ${s}= for none.`);n[s]=o.trim()===""?null:Number(o)}else if(r.type==="switch"){if(!V.has(o.trim().toLowerCase()))throw new d(`The setting ${s} of ${t.id} is a switch: --set ${s}=true or --set ${s}=false.`);n[s]=V.get(o.trim().toLowerCase())}else if(r.type==="select"){if(!r.options.includes(o))throw new d(`The setting ${s} of ${t.id} is one of ${r.options.join(", ")}: --set ${s}=<one of them>.`);n[s]=o}else if(r.type==="date"){if(o!==""&&!/^\d{4}-\d{2}-\d{2}$/.test(o))throw new d(`The setting ${s} of ${t.id} is a date, written YYYY-MM-DD: --set ${s}=2027-02-06.`);n[s]=o}else n[s]=o}return n}function xe(e,t){let a=t&&typeof t=="object"&&!Array.isArray(t)?t:{};return(e.settings??[]).filter(i=>i.required&&i.type!=="switch").filter(({key:i,default:n})=>{let s=Object.hasOwn(a,i)?a[i]:n;return s==null||typeof s=="string"&&s.trim()===""}).map(({key:i,label:n})=>({key:i,label:n?.en??n?.zh??i,zh:n?.zh??null}))}async function Ne(e,[t,a,...i],n,s,o,r=[]){if(!t||!a||i.length)throw new d("gallery page add takes a page's slug and a block's id (gallery block list lists them).");let c={};for(let l of["x","y","w","h"]){let g=s.get(`--${l}`);if(g!==void 0){if(!/^\d+$/.test(g)||(l==="w"||l==="h")&&Number(g)<1)throw new d(k.cells());c[l]=Number(g)}}if(c.x===void 0!=(c.y===void 0))throw new d("--x and --y go together: a place is both.");te(t,e)||(console.error(await ne(t,e)),process.exit(1));let m=a.includes("/")?null:P(a),h=a.includes("/")?a:m?m.id:a,$=T(e),y=$.packages.get(h);if(!y){let l=R(h)?P(h):null;$.settings.disabled.includes(h)?console.error(k.disabled(h)):console.error(l?`${h} is one of Gallery's own blocks, not yet in this workspace: gallery block add ${l.pack===G?l.name:l.id} puts it in; then run this again.`:$.problems.has(h)?`${h} does not load (gallery block check ${h} says why).`:k.missing(h)),process.exit(1)}y.places.includes("page")||(console.error(k.places(h)),process.exit(1));let p=s.get("--board"),w=r.length?Oe(r,y):null,ie={op:"add",block:h,...p?{board:p}:{},...c,...w?{settings:w}:{},agent:!0},{status:re,answer:f,viaServer:ce}=await ve(e,t,ie,()=>$);if(!f?.ok){let l=f?.reason;console.error(k[l]?.(h,p??de,f?.message)??`Not added (${re}: ${l??"no answer"}${f?.message?`: ${f.message}`:""}).`),process.exit(1)}let b=f.cards.find(l=>l.id===f.card),D=(f.pushed??[]).map(l=>f.cards.find(g=>g.id===l)).filter(Boolean);console.log(`Added a card of ${h} to ${u(v(t,e).html)}${ce?" (through the workspace's running server: an open page shows it at once)":""}:`),console.log(` data-card-id="${b.id}" on board ${b.board}: x ${b.x}, y ${b.y}, w ${b.w}, h ${b.h}${f.measure?" (its block gives no height: 2 cells, --h sets another)":""}`),D.length&&console.log(` Pushed down under it, as it met them: ${D.map(l=>`${l.id} (y ${l.y})`).join(", ")}; no card moved up.`),w&&console.log(` Settings written with it: ${Object.entries(w).map(([l,g])=>`${l}=${JSON.stringify(g)}`).join(", ")}`),console.log(w?"The rest of its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.":"Its data is as the block's template writes it, in the card's instance: write it there if it is to hold something else, leaving every other card as it is.");let S=xe(y,{...w??{}});if(S.length){let l=S.map(({key:g,label:N,zh:j})=>`${g} (${j&&j!==N?`${N}, ${j}`:N})`).join(", ");console.log(`${h} needs its setting ${l} before the card shows anything, and this card has none: ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents) and tell them in the handoff which you did. Give it with the add (${S.map(({key:g})=>`--set ${g}=<value>`).join(" ")}); for this card, write it in its settings part of ${u(v(t,e).html)} (the <script type="application/json"> of data-card-id="${b.id}": {"${S[0].key}":"\u2026"}), re-reading the page right before, or the user fills it in on the card (the grip at its top right \u203A \u8BBE\u7F6E\u2026).`)}}var O=e=>async(t,a,i,n,s,o)=>(await import("./chunk-PVTCP43W.mjs"))[e](t,a,i,n,o),_={new:ue,list:$e,open:ye,add:Ne,set:O("setPage"),move:O("movePage"),card:O("cardCommand"),"reset-cards":O("resetCards"),try:async(e,t,a,i,n)=>(await import("./chunk-L2IJCEUH.mjs")).pageTryCommand(e,{named:t,values:i,seconds:n,keep:a.has("--keep"),replace:a.has("--replace")}),check:async(e,t)=>(await import("./chunk-RFHEWT3Y.mjs")).pageCheckCommand(e,t)},Z=["--board","--x","--y","--w","--h"],je={"--json":["list"],"--title":["set"],"--icon":["set"],"--after":["move"],"--first":["move"],"--move":["card"],"--size":["card"],"--remove":["card"]};async function Ye(e){try{return await Te(e)}catch(t){let a=e.find(i=>!Y(i));throw t instanceof d&&a==="try"&&(t.synopsis=L),t instanceof d&&["set","move","card","reset-cards"].includes(a)&&(t.synopsis=I("page",a)),t}}async function Te(e){let{argv:t,seconds:a}=K(e),{argv:i,given:n}=Se(t),{positional:s,options:o,values:r}=H({options:["--no-browser","--keep","--replace","--json","--first","--remove"],values:[...Z,...C,"--title","--icon","--after","--move","--size"],argv:i}),[c,...m]=s,h=Object.keys(_).join(", ");if(!c)throw new d(`Say what to do: ${h}.`);if(!Object.hasOwn(_,c))throw new d(`No such page command: ${c} (${h}).`);if(o.has("--no-browser")&&c!=="open")throw new d(`--no-browser goes with open, not ${c}.`);let $=[...C.filter(p=>r.has(p)),...Object.keys(a).filter(p=>!r.has(p)),...o.has("--keep")?["--keep"]:[],...o.has("--replace")?["--replace"]:[]];if($.length&&c!=="try")throw new d(`${$[0]} goes with try, not ${c}.`);let y=Z.filter(p=>r.has(p));if(y.length&&c!=="add")throw new d(`${y.join(", ")} go with add, not ${c}.`);if(n.length&&c!=="add"&&c!=="card")throw new d(`--set goes with add and card, not ${c}.`);for(let[p,w]of Object.entries(je))if((o.has(p)||r.has(p))&&!w.includes(c))throw new d(`${p} goes with ${w.join(" and ")}, not ${c}.`);return _[c](ee,m,o,r,a,n)}export{x as a,we as b,me as c,ne as d,ve as e,Se as f,Oe as g,xe as h,Ye as i};
@@ -0,0 +1,5 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as ue,b as we,k as ge,v as $e,w as be}from"./chunk-S6YEC4GE.mjs";import{N as ye}from"./chunk-V3XROSP5.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-OKVQQ3CX.mjs";import"./chunk-X4WNLFIK.mjs";import{c as R,f as ke}from"./chunk-XRYECF23.mjs";import{a as P}from"./chunk-5TLLIZT7.mjs";import"./chunk-LHGKPMTI.mjs";import"./chunk-HFTBVEZK.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import"./chunk-IA4PSIMD.mjs";import{a as fe,j as me,s as de}from"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-TQZU7D7C.mjs";import{d as le,e as ce,i as I,j as he,k as pe}from"./chunk-5IHDLEB4.mjs";import{a as $}from"./chunk-B2EIMERT.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import{b as re,h as z}from"./chunk-VRPVVMRB.mjs";import{a as D,c as S}from"./chunk-HYMEEXKN.mjs";import"./chunk-56SVJENP.mjs";import{n as ie}from"./chunk-BSJKFE7I.mjs";import"./chunk-L4WLQYFC.mjs";import"./chunk-NOGQX56R.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import{c as ae}from"./chunk-E7656LR7.mjs";import{a as F,f as te,h as se,j as U,r as ne,s as oe}from"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{isUtf8 as Ue}from"node:buffer";import X from"node:fs";import E from"node:path";import{instanceSlots as ze,instancesOf as Y,isInstance as Z,partOf as W}from"../browser/shared/components/index.mjs";import{fewestSyllables as Oe}from"../browser/shared/pinyin.mjs";import{ATTRIBUTE as b,refusedInCopy as De}from"../browser/shared/components/installed.mjs";import{attr as y,elementsOf as Q,walk as A}from"../browser/shared/html-tree.mjs";import{blankedCss as M}from"../browser/shared/css-references.mjs";import{ATTRIBUTE as G,SLOT as Le}from"../browser/shared/components/installed.mjs";var Ae=new Set(["media","supports","container","layer","starting-style"]);function K(e,t){let s=0,i="";for(let n=0;n<e.length;n++){let o=e[n];o==="\\"?n++:i?i=o===i?"":i:o==='"'||o==="'"?i=o:o===")"||o==="]"?s--:(s===0&&t(o,n),(o==="("||o==="[")&&s++)}}function Ce(e){let t=M(e),s=M(e,{strings:!0}),i={children:[]},n=[i],o=0,r=0;for(let a=0;a<t.length;a++){let l=t[a];if(l==="\\")a++;else if(l==="("||l==="[")r++;else if(l===")"||l==="]")r=Math.max(0,r-1);else{if(r>0)continue;if(l==="{"){let h={prelude:s.slice(o,a),start:o,children:[]};n.at(-1).children.push(h),n.push(h),o=a+1}else l==="}"?(n.length>1&&n.pop(),o=a+1):l===";"&&(o=a+1)}}return i.children}function _(e){let t=[],s=0;return K(e,(i,n)=>{i===","&&(t.push({text:e.slice(s,n),start:s}),s=n+1)}),t.push({text:e.slice(s),start:s}),t.filter(({text:i})=>i.trim())}function H(e){let t=[],s=e.trim(),i="",n=0,o=0,r=a=>{(o||a)>n&&t.push({combinator:i,compound:s.slice(n,o||a)}),o=0};return K(s,(a,l)=>{/\s/.test(a)?l===n?n=l+1:o||=l:">+~".includes(a)?(r(l),i=a,n=l+1):o&&(r(l),i=" ",n=l)}),r(s.length),t}function B(e){let t=[],s=-1,i=0,n="";for(let r=0;r<e.length;r++){let a=e[r];a==="\\"?r++:n?n=a===n?"":n:a==='"'||a==="'"?n=a:a==="("?i++:a===")"?i--:a==="["&&i===0?s=r:a==="]"&&i===0&&s>=0&&(t.push(e.slice(s,r+1)),s=-1)}let o=!1;return K(e,r=>{o||=r==="&"}),{attributes:t,nesting:o,scope:/(?:^|[^\w-]):scope\b/.test(e)}}var Ie=e=>new RegExp(`^\\[\\s*${G}\\s*=\\s*(["'])${e.replace(/[/-]/g,"\\$&")}\\1\\s*i?\\s*\\]$`,"i"),Pe=e=>M(e).replace(/\\.|\[[^\]]*\]/g,"").includes("&");function xe(e,t,s,i=!1){let n=H(e),o=({compound:p})=>B(p).attributes.some(c=>t.test(c)),r=({compound:p})=>{let{nesting:c,scope:m}=B(p);return!!s&&(c||m)},a=p=>["+","~"].includes(p?.combinator),l=p=>n.slice(p).some(({combinator:c},m)=>(m+p===0?c||" ":c)===" "),h=n.findLastIndex(p=>o(p)||r(p));if(h<0)return!s||Pe(e)?{why:"outside"}:{why:s==="instance"&&a(n[0])?"beside":null,subject:"inside",deep:i||l(0)};let f=o(n[h])||s==="instance";return{why:f&&a(n[h+1])?"beside":null,subject:f&&h===n.length-1?"instance":"inside",deep:!o(n[h])&&i||l(h+1)}}var Se=e=>e.some(({subject:t})=>t==="instance")?"instance":"inside",Re=new RegExp(`^\\[\\s*${Le}\\s*(?:\\]|=)`,"i"),Fe=e=>_(/\)\s*to\s*\(([^)]*)\)/i.exec(e)?.[1]??"").some(({text:t})=>H(t).length===1&&B(t).attributes.some(s=>Re.test(s))),je=(e,t)=>Ne(e,t).outside;function Ee(e,t,s){if(s.length===0)return[];let i=`slot${s.length===1?"":"s"} ${s.join(" and ")}`;return Ne(e,t).deep.map(({line:n,words:o})=>({line:n,what:`${o} also reaches the blocks in ${i}, the document's: write each step with > or wrap the rules in @scope ([${G}="${t}"]) to ([${Le}])`}))}function Ne(e,t){let s=Ie(t),i=`[${G}="${t}"]`,n=[],o=[],r=(l,h,f)=>{let p=h.replace(/\s+/g," ").trim();n.push({line:S(e,l),what:f==="beside"?`${p} reaches what stands beside the instance: what it styles has to stand in it`:`${p} reaches outside the instance: start it at ${i}`})},a=(l,h,f=!1,p=!1)=>{for(let c of l){let m=c.prelude.length-c.prelude.trimStart().length,u=c.start+m,g=/^@([\w-]+)\s*/.exec(c.prelude.trim());if(g){let d=g[1].toLowerCase();if(Ae.has(d))a(c.children,h,f,p);else if(d==="page")n.push({line:S(e,u),what:"@page reaches the paper of the whole document: an instance has no page of its own"});else if(d==="scope"){let x=/^@scope\s*\(([^)]*)\)/i.exec(c.prelude.trim())?.[1]??"",L=_(x).map(({text:j})=>({...xe(j,s,h),steps:H(j).length}));x&&L.every(({why:j,steps:Te})=>!j&&Te===1)?a(c.children,Se(L),!1,p||Fe(c.prelude.trim())):r(u,c.prelude,"outside")}continue}let k=_(c.prelude).map(({text:d,start:x})=>{let L=xe(d,s,h,f),j=c.start+x+d.length-d.trimStart().length;return L.why?r(j,d,L.why):L.deep&&!p&&!f&&o.push({line:S(e,j),words:d.replace(/\s+/g," ").trim()}),L});k.some(({why:d})=>d)||a(c.children,Se(k),k.some(d=>d.deep),p)}};return a(Ce(e),null),{outside:n,deep:o}}var w="template.html",N="example.html",O="component.json",Me=new Set(["localStorage","sessionStorage"]),_e=/^\S+: (?:line \d+ of )?its (?:kit\.js|style\.css) /,Be=/(?: (?:names a file that )?is not in the document's folder|: it is (?:no file of|not in) the document's .*)$|^external resources are not portable: .*$/,Ge=": an example stands in no document: write a picture as a data: address, or draw it from style.css with a file the manifest's assets name",Ke=e=>e.replace(Be,t=>(t.startsWith("external")?t:"")+Ge),T=(e,t)=>I({folder:e},t);function C(e,t){let s=null;try{s=X.readFileSync(E.join(e,t))}catch{return null}return Ue(s)?null:{file:t,what:"it is not UTF-8: save it as UTF-8 (PowerShell's > writes UTF-16; Set-Content -Encoding utf8 does not)"}}function J(e,t){let s=/^line (\d+): | \(line (\d+)\)/.exec(t);return s?{file:e,line:Number(s[1]??s[2]),what:t.replace(s[0],"")}:{file:e,what:t}}function v(e,t){let s=$.parseJsonText(O,e),i=s.statements[0]?.expression,n=null;for(let o of t.split(".")){let r=i?.properties?.find(({name:a})=>a?.text===o);if(!r)break;n=s.getLineAndCharacterOfPosition(r.getStart(s)).line+1,i=r.initializer}return n}function He(e,{message:t,text:s="",values:i=[]}){let n=/at position (\d+)/.exec(t)?.[1];if(n)return S(e,Number(n));for(let o of[...i.map(String),...s.match(/[a-zA-Z][\w.]*/g)??[]]){let r=v(e,o);if(r)return r}return null}var Je=e=>z(e).map(t=>/^line (\d+): <([^>]+)>: ([\s\S]*)$/.exec(t)).filter(Boolean).map(([,t,s,i])=>({line:Number(t),tag:s,why:i}));function qe(e,{file:t,tree:s,html:i}){let n=[],o=Je(i),r=Object.entries(e.parts).filter(([,h])=>h.edit==="text"),a=Object.entries(e.parts).filter(([,h])=>h.edit==="data"),l=(h,f)=>{let p=!1;return A(h,c=>{p||=c===f}),p};for(let h of Y(s,e))for(let[f,p]of r)for(let c of W(h,p.at)){let m=c.sourceCodeLocation?.startLine,u=Q(c).find(d=>ae.has(d.tagName)),g=o.find(d=>d.line===m&&d.tag===c.tagName),k=a.find(([,d])=>W(h,d.at).some(x=>x===c||l(x,c)||l(c,x)))?.[0];k?n.push({file:t,line:m,what:`the part ${f} (${p.at}) is edited as text, and stands in the part ${k}, edited as data, or around it, which is the component's: the editor leaves it read-only: name elements apart`}):u?n.push({file:t,line:m,what:`the part ${f} (${p.at}) is edited as text and holds a block, its <${u.tagName}> at line ${u.sourceCodeLocation?.startLine}: a text part holds words and marks alone, and the editor would leave this one read-only: write its \`at\` as what holds the words (${p.at} > ${u.tagName}), or give each block a part of its own`}):g&&n.push({file:t,line:m,what:`the part ${f} (${p.at}) is edited as text, and the editor would leave it read-only for what it holds: ${g.why}. A text part holds words and marks alone`})}return n}var ee=new RegExp("\\p{Script=Han}","u"),ve=e=>[...e].filter(t=>ee.test(t)).length,Ve={test:e=>{let t=Oe(e);return t!==null&&t<=8}};function We({name:e,words:t}){let s=ve(e.zh),i=t.split(/\s+/).filter(Boolean);return s===0?ee.test(t)&&!i.some(n=>Ve.test(n)):!i.some(n=>Oe(n.toLowerCase())===s)}function Xe({id:e,folder:t,catalog:s,off:i,parts:n}){let o=s.packages.get(e),r=s.problems.get(e)?.problem,a=T(t,O)??"",l=[];r&&l.push({file:O,line:He(a,r),what:U("en",r)}),o?.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 ${b}="${e}"> with what a new instance holds`}),l.push(...n);let h=C(t,"writing.md");h&&l.push(h);let f=h||T(t,"writing.md")?.trim()?[]:[{file:"writing.md",what:"there is none, so gallery block show has nothing to say of how to write it"}];o&&We(o)&&f.push({file:O,line:v(a,"words")??v(a,"name.zh"),what:ee.test(o.name.zh)?`no word of words spells its whole name ${o.name.zh} in pinyin as an input method composes it, its ${ve(o.name.zh)} Chinese characters a syllable each in one word (as \u65B9\u6848\u6253\u5206 is fangandafen): "/" finds it while those letters are being composed only by such a word. What is counted is how many syllables a word reads as, not which characters they spell`:'its words are Chinese and none of them is pinyin: "/" goes by the letters an input method is composing, so write the pinyin there (\u770B\u677F kanban)'});let p=(()=>{try{return ie(X.readFileSync(E.join(t,"preview.svg")),e)}catch{return null}})();return p&&f.push({file:"preview.svg",what:`it is Gallery's ${p.id} picture, byte for byte (a block made with --recipe keeps its recipe's drawing, which the menu shows beside this block's name): draw this block's own, or delete preview.svg, which the menu does without`}),i&&f.push({file:"gallery.json",what:"the user turned it off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868, which is theirs to change and says nothing of the block: it is checked as if it were on, and the instances of a document show what they hold, read-only, until it is on"}),o&&(l.push(...Ze(o)),f.push(...Ye(o,a))),{title:"manifest",problems:l,notes:f}}function Ye({places:e,parts:t,card:s},i){let n=[];if(e.includes("page"))for(let[o,r]of Object.entries(t))r.edit==="text"&&n.push({file:O,line:v(i,`parts.${o}`),what:`the part ${o} is edited as text, which is read-only on a custom page (no editor runs there): a block whose places hold page keeps what a reader changes there in a data part, with its own field or the card's settings`});else v(i,"card")&&n.push({file:O,line:v(i,"card"),what:`card is for a custom page's board, and its places (${e.join(", ")}) hold no page: nothing reads it`});return n}function Ze(e){if(e.settings.length===0||!e.template)return[];let t=ne(e.template,e.id),s=t?W(t.root,e.parts[F].at):[];if(s.length!==1||(y(s[0],"type")??"").trim().toLowerCase()!=="application/json")return[{file:w,what:`its manifest has settings, and the template holds ${s.length===1?`a <${s[0].tagName}> where`:`${s.length} elements of`} its settings part (${e.parts[F].at}): it is to hold one <script type="application/json">, the values a new card starts with ({} for each setting's default)`}];let i=s[0].childNodes.map(n=>n.value??"").join("").trim();try{let n=JSON.parse(i||"{}");if(typeof n!="object"||n===null||Array.isArray(n))throw new Error("it is no object");return[]}catch(n){return[{file:w,line:s[0].sourceCodeLocation?.startLine,what:`its settings part is not a JSON object (${n.message}): write {} or the values of some of its settings, by key`}]}}function Qe(e){let t=$.createSourceFile("kit.js",e,$.ScriptTarget.Latest,!0,$.ScriptKind.JS),s=[],i=n=>{let o=$.isCallExpression(n)&&$.isPropertyAccessExpression(n.expression)?n.expression:null;if(o?.name.text==="component"&&/\bDocKit$/.test(o.expression.getText(t))){let[r]=n.arguments,a=r&&$.isObjectLiteralExpression(r)?r.properties.find(h=>h.name?.getText(t)==="id"):null,l=a&&$.isPropertyAssignment(a)&&$.isStringLiteralLike(a.initializer)?a.initializer.text:null;s.push({id:l,at:n.getStart(t)})}$.forEachChild(n,i)};return i(t),s}function et(e){let t="kit.js";if(!e.files.includes("kit.js"))return{title:t,none:"none: a static block"};let s=C(e.folder,t);if(s)return{title:t,stops:!0,problems:[s]};let i=I(e,"kit.js")??"",n=fe(i);if(n)return{title:t,stops:!0,problems:[{file:t,line:n.line,what:`a browser refuses it: ${n.message}`}]};let o=pe(e).map(({line:h,what:f})=>({file:t,line:h,what:f})),r=o.length>0;for(let{name:h,at:f}of le(i,Me))o.push({file:t,line:S(i,f),what:`uses ${h}: an instance keeps what a reader chose with context.state`});let a=Qe(i);for(let{id:h,at:f}of a)h!==null&&h!==e.id&&o.push({file:t,line:S(i,f),what:`it registers ${h}, and this block is ${e.id}`});let l=a.length?[]:[{file:t,what:`no DocKit.component({ id: "${e.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:h,code:f,message:p,refused:c}of ce(i,{assets:e.assets}))(c?o:l).push({file:t,line:h,what:`TS${f}: ${p}`});return{title:t,stops:r,problems:o.sort((h,f)=>(h.line??0)-(f.line??0)),notes:l}}function tt(e){let t="style.css";if(!e.files.includes("style.css"))return{title:t,none:"none"};let s=C(e.folder,t);if(s)return{title:t,stops:!0,problems:[s]};let i=I(e,"style.css")??"",n=he(e),o=[...je(i,e.id),...n].map(({line:l,what:h})=>({file:t,line:l,what:h})),r=Object.entries(e.parts??{}).filter(([,{edit:l}])=>l==="flow").map(([l])=>l),a=Ee(i,e.id,r).map(({line:l,what:h})=>({file:t,line:l,what:h}));return{title:t,stops:n.length>0,problems:o.sort((l,h)=>l.line-h.line),notes:a}}function st(e,{tree:t}){let s=null;A(t,a=>{s??=a.tagName==="main"?a:null});let i=Q(s??{}),n=(s?.childNodes??[]).some(a=>a.nodeName==="#text"&&a.value.trim()),[o]=i;if(i.length!==1||n||!Z(o)||y(o,b)!==e)return[{file:w,line:o?.sourceCodeLocation?.startLine,what:`a template is one element, a <div ${b}="${e}"> or a <section>, and it holds ${i.length===1&&!n?`<${o.tagName}${y(o,b)?` ${b}="${y(o,b)}"`:""}>`:`${i.length} element${i.length===1?"":"s"}${n?" and words":""}`}`}];let r=[];return A({childNodes:[o]},a=>{y(a,"data-block-id")!==void 0&&r.push({file:w,line:a.sourceCodeLocation?.startLine,what:"it writes a data-block-id, which every instance made of it would repeat: leave it out, Gallery gives a block its id"})}),r}var nt=[[e=>y(e,"data-doc-chart")!==void 0,e=>`a chart (<${e.tagName} data-doc-chart="${y(e,"data-doc-chart")}">)`],[e=>e.tagName==="figure",()=>"a card (<figure>)"],[e=>e.tagName==="caption",()=>"a table's <caption>"],[Z,e=>`an instance of ${y(e,b)}`]];function ot(e,t){let s=null;if(A(D(t),o=>{s??=Z(o)&&y(o,b)===e?o:null}),!s)return[];let i=[],n=(o,r)=>{for(let a of Q(o)){let l=nt.find(([h])=>h(a));l?i.push({file:w,line:a.sourceCodeLocation?.startLine,what:`its slot ${y(r,"data-doc-slot")} holds ${l[1](a)}, which a new block from "/" would not have: a menu makes what a template's slot holds as a paste of it makes blocks, and a paste makes no chart, card, table caption or instance of a block. Keep the template's slots to blocks the page makes (paragraphs, headings, lists, quotes, code, a plain table, a disclosure), and show the rest in example.html`}):n(a.tagName==="template"?a.content:a,r)}};for(let o of ze(s))n(o,o);return i}function it(e,{tree:t}){let s=oe(e);if(!s)return[];let[i]=Y(t,e),n=null;return i&&A({childNodes:[i]},o=>{De(o.tagName,o.attrs)&&(n??=o)}),[{file:w,line:(n??i)?.sourceCodeLocation?.startLine,what:U("en",s)}]}function at(e){return[[w,"component-template"],[N,"component-example"]].flatMap(([t,s])=>{let i=T(e,t);if(i===null||!i.trim()||C(e,t))return[];let n=ge(s,i),{text:o}=re(n);return[{file:t,slug:s,written:n,html:o,tree:D(o)}]})}function rt({id:e,folder:t,found:s,pages:i,parts:n}){let o="template.html and example.html",r=[],a=[];for(let c of[w,N]){let m=C(t,c);m?r.push(m):c===w&&!T(t,c)?.trim()&&s.template!==null?r.push({file:c,what:"it is empty"}):c===N&&!i.some(u=>u.file===c)&&r.push({file:c,what:`there is none or it is empty: write an instance as a writer would fill it, a <div ${b}="${e}">; it is what this check runs`})}let l=i.find(c=>c.file===w);l&&r.push(...st(e,l),...ot(e,l.written));let h=i.find(c=>c.file===N);h&&Y(h.tree,s).length===0&&r.push({file:N,what:`it holds no instance of ${e}: a <div ${b}="${e}">`});let f=i.map(({slug:c,written:m,html:u,file:g})=>({file:g,slug:c,written:m,html:u,directory:E.join(t,c),htmlPath:E.join(t,c,"doc.html"),metadata:{title:c,description:c,type:"component"}})),p=me(f);for(let c of f){for(let m of p.get(c.slug)??[])_e.test(m)||r.push(J(c.file,Ke(m)));for(let m of de(c))a.push(J(c.file,m));for(let m of z(c.html)){let u=J(c.file,`${m} (read-only in the preview)`);n.some(({file:g,line:k})=>g===u.file&&k===u.line)||a.push(u)}}return l&&!r.some(({file:c})=>c===w)&&r.push(...it(s,l)),{title:o,problems:r,notes:a}}function lt(e,t){let s=te(e,void 0,{on:t}),i=R(e,t);if(!s.packages.has(t)&&!s.problems.has(t))return null;se(e,s);let n=s.packages.has(t)&&s.settings.disabled.includes(t),o=s.packages.get(t)??{id:t,folder:i,files:["kit.js","style.css"].filter(h=>X.existsSync(E.join(i,h)))},r=at(i),a=s.packages.has(t)?null:"its manifest does not load",l=a?[]:r.flatMap(h=>qe(o,h));return{found:s.packages.get(t)??null,pages:r,sections:[Xe({id:t,folder:i,catalog:s,off:n,parts:l}),et(o),tt(o),a?{title:"template.html and example.html",skipped:a}:rt({id:t,folder:i,found:o,pages:r,parts:l})]}}var q=({file:e,line:t})=>t?`${e}:${t}`:e;function V({title:e,problems:t=[],notes:s=[],told:i=[],none:n,skipped:o,unverified:r,pictures:a},l){let h=r?`UNVERIFIED ${r}`:o?`not run: ${o}`:n??(t.length?`${t.length} problem${t.length===1?"":"s"}`:`ok${s.length?`, ${s.length} note${s.length===1?"":"s"}`:""}`);return[`${l}. ${e}: ${h}`,...t.map(f=>` FAIL ${q(f)}: ${f.what}`),...s.map(f=>` note ${q(f)}: ${f.what}`),...i.map(f=>` way back ${q(f)}: ${f.what}`),...a?[ct(a)]:[]]}function ct({folder:e,overviews:t,each:s,edited:i=[],asExport:n=[],documents:o=!1}){let r=t.length?`${P(E.join(e,t[0]))}${t.slice(1).map(h=>` and ${h}`).join("")}, the three widths of each theme side by side; then each at full size: `:`${P(e)}: `,a=n.length===0?"":n.length===i.length?", each the same picture as the export's at its width: the block draws nothing more where a reader can edit":`, ${n.join(" and ")} the same picture as the export's at its width`,l=i.length?`; and ${i.join(" and ")}, as the editing page draws it (context.canEdit() true)${a}`:"";return` Pictures (none looked at for you; ${o?"each instance under a line naming where it stands in the document":"example.html above the line, template.html below it, each under its name"}): ${r}${s.join(", ")}${l}`}function ht([e,t,s,i]){return e.problems.length?"the manifest":t.stops?"kit.js":s.stops?"style.css":i.skipped||i.problems.length?"template.html and example.html":null}async function Ut(e,t,{documents:s=!1,elsewhere:i=null}={}){let n=lt(e,t);n||(console.error(ke(e,t)),process.exit(1)),console.log(`${t}: ${P(R(e,t))}`),n.sections.forEach((p,c)=>console.log(V(p,c+1).join(`
3
+ `)));let o=ht(n.sections),r=R(e,t),a=o?{title:ue,skipped:`${o} first`}:await $e(e,n.found,{example:T(r,N),template:T(r,w)});console.log(V(a,5).join(`
4
+ `));let l=s?o?[{title:we(),skipped:`${o} first`}]:await be(e,n.found,{elsewhere:i}):[];l.forEach((p,c)=>console.log(V(p,6+c).join(`
5
+ `)));let h=ye([a,...l].filter(({pictures:p})=>p).map(({pictures:{folder:p,overviews:c,each:m,edited:u=[]}})=>({folder:p,files:[...c,...m,...u].map(g=>E.join(p,g))})));h&&console.log(h);let f=[...n.sections,a,...l].reduce((p,{problems:c=[]})=>p+c.length,0);f?(console.log(`FAIL ${t}: ${f} problem${f===1?"":"s"}`),process.exitCode=1):a.unverified||l.some(({unverified:p})=>p)?(console.log(`UNVERIFIED ${t}: the rest passed, and no browser ran ${a.unverified?"it":"the documents' instances"}: export a document that holds it and open that in Chrome or Edge.`),process.exitCode=3):console.log(`OK ${t}${s?" and its instances in the workspace's documents":""}`)}export{Ut as checkCommand,Oe as fewestSyllables,lt as readSections,V as sectionLines,We 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 g}from"./chunk-F63BNJLG.mjs";import"./chunk-ZNGGDUZI.mjs";import{a,b as i,o as c,q as u}from"./chunk-B6RAGF4R.mjs";import"./chunk-5TLLIZT7.mjs";import"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import"./chunk-VAXLSISW.mjs";import"./chunk-56SVJENP.mjs";import{b as l,f as w}from"./chunk-L4WLQYFC.mjs";import"./chunk-5L7RYZCL.mjs";import{DOCS as $,topOf as p}from"../browser/shared/outline-shape.mjs";import{addColumn as y,newColumnId as v,removeColumn as x,renameColumn as N}from"../browser/shared/outline-ops.mjs";var f=o=>o.replace(/\s+/g," ").trim(),d=o=>o.groups.filter(e=>!e.hidden&&!e.away),h=o=>`Columns now (the sidebar's order): ${d(o).map(i).join(", ")}.`;async function T(o){if(o.length!==1)throw new l('Name the column: gallery column new "<name>".');let e=f(o[0]).slice(0,100);if(!e)throw new l("The name of a column is never empty.");let n=await a(),t=c(n,e);if(t)return void console.log(`The column "${i(t)}" is in the sidebar already (${t.id}): nothing made.`);let s=null,r=await u(m=>(s=v(m),y(m,{id:s,title:e})));r.ok||(console.error(`Not made: ${r.refused??r.message??r.reason}.`),process.exit(1)),console.log(`Made the column "${e}" (${s}), last in the sidebar.`),console.log(h(await a())),console.log(`\u4E0B\u4E00\u6B65\uFF1Agallery new <slug> "<title>" --column "${e}" makes a document in it; gallery move <slug> --column "${e}" moves one.`)}async function k(o){if(o.length!==2)throw new l('Name the column and its new name: gallery column rename "<column>" "<new name>".');let e=f(o[1]).slice(0,100);if(!e)throw new l("The name of a column is never empty.");let n=await a(),t=c(n,o[0]);t||(console.error(`No column "${o[0]}" in the sidebar (${d(n).map(i).join(", ")}): nothing renamed.`),process.exit(1)),t.extension&&(console.error(`The column ${i(t)} is an extension's: its name is the extension's own (gallery extension list), no command renames it.`),process.exit(1));let s=i(t),r=await u(m=>N(m,t.id,e));if(r.ok||(console.error(`Not renamed: ${r.refused??r.message??r.reason}.`),process.exit(1)),!r.changed)return void console.log(`The column "${s}" is called "${e}" already: nothing to change.`);console.log(`Renamed the column "${s}" to "${e}" (${t.id}).`),console.log(h(await a()))}async function C(o){if(o.length!==1)throw new l('Name the column: gallery column remove "<column>".');let e=await a(),n=c(e,o[0]);if(n||(console.error(`No column "${o[0]}" in the sidebar (${d(e).map(i).join(", ")}): nothing removed.`),process.exit(1)),n.id===$&&(console.error(`The column ${i(n)} is the workspace's own: it is never removed.`),process.exit(1)),n.extension&&(console.error(`The column ${i(n)} is an extension's: it goes with the extension's sidebar.json (gallery extension list), no command removes it.`),process.exit(1)),n.workspace)return g(n,e);let t=(e.children[p(n.id)]??[]).length,s=await u(m=>x(m,n.id));s.ok||(console.error(`Not removed: ${s.refused??s.message??s.reason}.`),process.exit(1));let r=await a();console.log(`Removed the column "${i(n)}" (${n.id}); ${t?`the ${t} entr${t===1?"y":"ies"} in it, with those under them, went last to the own column`:"it held nothing"}. No file was deleted.`),console.log(h(r))}async function A(o){let[e,...n]=o,{positional:t}=w({argv:n});if(e==="new")return T(t);if(e==="rename")return k(t);if(e==="remove")return C(t);throw new l(e?`No such action: column ${e} (new, rename, remove).`:"Say what to do: gallery column new, rename or remove.")}export{A as run};
@@ -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{f as D,g as x}from"./chunk-X4WNLFIK.mjs";import{a as h,b as d,c as u,d as w}from"./chunk-TLNJWEFY.mjs";import{p as y}from"./chunk-B2EIMERT.mjs";import{b as l,d as c,e as f,g as m,h as p,i as g,j as a}from"./chunk-VRPVVMRB.mjs";import{a as s}from"./chunk-UMHUSOPJ.mjs";import S from"node:path";import{FILE as j}from"../browser/shared/annotations.mjs";import{editStateDirectory as L,reportsDirectory as i}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as k}from"../browser/shared/workspace.mjs";function O({say:e=!0}={}){return o=>{let{text:t,changes:n}=l(o.html,{finish:y});if(e&&n.length&&console.log(m(o.htmlPath,n,{pending:!0}).join(`
3
+ `)),e){let r=c(o.html);r.length&&console.log(D(o.htmlPath,r,r.length,{pending:!0}).join(`
4
+ `));for(let N of x(o.htmlPath,f(s(o.html),o.metadata),{pending:!0}))console.log(N)}return t}}function b(e){for(let o of e){for(let t of p(o.html))console.log(`note ${o.slug}: ${t} (read-only in the preview)`);for(let t of g(o.html))console.log(`note ${o.slug}: ${t}`);for(let t of a(o.html))console.log(`note ${o.slug}: ${t}`)}}async function q(e){for(let o of e){let t=await u({stateDirectory:L,reportsDirectory:i,slug:o});for(let n of w(k($(o,i)).html,t))console.log(n)}}async function z(e){for(let o of e){let t=await h({stateDirectory:L,reportsDirectory:i,slug:o});for(let n of d(S.join($(o,i),j),t))console.log(n)}}export{O as a,b,q as c,z as d};
@@ -0,0 +1,8 @@
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 P,b as _}from"./chunk-LZY74XTP.mjs";import{spawn as M}from"node:child_process";import R from"node:fs";import h from"node:fs/promises";import H from"node:os";import A from"node:path";import{escapeMarkup as V}from"../browser/shared/escape.mjs";import{packageRoot as z,projectRoot as O,release as I,reportsDirectory as y}from"../browser/shared/paths.mjs";import{workspaceId as K,registerQuietly as U}from"../browser/shared/workspace-registry.mjs";import{serviceLocation as q,workspaceBase as J}from"../browser/shared/service-location.mjs";import{fullAddress as Q}from"../browser/shared/page-address.mjs";import{findPreviewServer as X,galleryVersion as F,portIsFree as Z,previewServerFor as ee,readAnnouncement as te}from"../browser/shared/preview-server.mjs";import{documentLinks as re}from"../browser/shared/reports.mjs";import{defaultWorkspace as ne,documentDirectory as oe,documentFiles as se}from"../browser/shared/workspace.mjs";var g="\u4EA4\u7ED9\u7528\u6237\uFF08\u73B0\u5728\u5C31\u628A\u8FD9\u4E2A\u5730\u5740\u7ED9\u7528\u6237\uFF1B\u7528 Chrome \u6216 Edge \u6253\u5F00\uFF09\uFF1A",ie="Agent \u81EA\u7528\uFF08\u53EA\u6709\u6587\u6863\u9875\uFF0C\u4E0D\u4EA4\u7ED9\u7528\u6237\uFF09\uFF1A",ae=e=>`send the user ${e} now, in a message of its own, before any other step; then `;function We(e,t){let r=e.at(-1)??"";return`\u4E0B\u4E00\u6B65\uFF1A${r.startsWith(g)?ae(r.slice(g.length)):""}${t}`}async function Ye(e,t){let r=e.at(-1)??"";return r.startsWith(g)?t.has("--no-browser")?"Not opened in a browser (--no-browser).":P(await _(r.slice(g.length))):null}var j="GALLERY_NO_PREVIEW",le=e=>!["","0",void 0].includes(e),Ce=e=>e.has("--no-preview")||le(process.env[j]),ce=8080,de=20,pe=(e=process.env)=>{let t=Number(e.GALLERY_PORT);return Number.isInteger(t)&&t>0&&t<65536?t:ce},ue=6e4,fe=5*1024*1024,he=A.join(O,"node_modules","vite","bin","vite.js"),we=A.join(z,"dist","server.mjs"),me=e=>new Promise(t=>setTimeout(t,e)),$e=ne(),b=q(),w=b.serverLog,B=()=>J(y),S=(e,t)=>`http://127.0.0.1:${e}${B()}/generated/${t}.html`,ye=(e,t)=>`${S(e,t)}?agent`,D=e=>`http://127.0.0.1:${e}/`,ve=async(e,t)=>{let r=await re(y).then(o=>o.links,()=>null),n=Q(`http://127.0.0.1:${e}`,t,r);return B()?n.replace("/#",`/#~${K(y)}/`):n};async function ge({first:e=pe(),count:t=de}={}){let r=Number((await h.readFile(b.lastPortFile,"utf8").catch(()=>"")).trim()),n=Array.from({length:Math.max(0,t)},(o,a)=>e+a);return Number.isInteger(r)&&r>0&&r<65536?[r,...n.filter(o=>o!==r)]:n}async function ke(){return await h.mkdir(A.dirname(w),{recursive:!0}),await h.stat(w).then(t=>t.size,()=>0)>fe&&await h.rename(w,`${w}.1`).catch(()=>{}),R.openSync(w,"a")}async function xe(e,t){if(!I){let{writeSharedAssets:p}=await import("./chunk-VKZJRGDR.mjs");await p()}let r=await ke();R.writeSync(r,`
3
+ [${new Date().toISOString()}] ${t}: Gallery ${F} on 127.0.0.1:${e} for ${y}
4
+ `);let[n,o]=I?[[we,"--port",String(e)],H.homedir()]:[[he,"--host","127.0.0.1","--port",String(e),"--strictPort"],O],a=M(process.execPath,n,{cwd:o,env:{...process.env,GALLERY_WORKSPACE:$e,GALLERY_SERVER_KIND:"cli"},detached:!0,stdio:["ignore",r,r],windowsHide:!0});return R.closeSync(r),a.unref(),a}async function be({slug:e=null,command:t=`gallery open${e?` ${e}`:""}`,ports:r=null,starting:n=ue,baseline:o=!1}={}){await U(y);let a=()=>!0;if(e){let s=se(oe(e,y)),c=await h.readFile(s.html,"utf8").catch(()=>null);if(c===null)return{ok:!1,reason:"missing",message:`No document "${e}": ${s.html} does not exist (gallery new ${e} "<\u6807\u9898>" makes one; gallery list lists those there are).`};o&&await import("./chunk-Z4NEXXFK.mjs").then(({previewBaseline:$})=>$(e,c));let u=await h.readFile(s.json,"utf8").then(JSON.parse).catch(()=>({})),i=[/<title>([^<]*)<\/title>/i.exec(c)?.[1]?.trim(),typeof u.title=="string"?u.title.trim():""].filter(Boolean);a=$=>i.length===0||i.some(N=>$.includes(N)||$.includes(V(N)))}let p=Number((await h.readFile(b.lastPortFile,"utf8").catch(()=>"")).trim()),m=r??await ge(),L=m.length?`${Math.min(...m)} to ${Math.max(...m)}`:"none",v=`gallery open${e?` ${e}`:""}`,E=async(s,c=[])=>{let u=!!process.env.GALLERY_SANDBOX,i=await ee({ports:u?[]:m.slice(s),start:$=>xe($,t),...u?{version:"0.0.0"}:{}});return i.busy?.newer?{failed:{ok:!1,reason:"newer",message:`A newer Gallery (${i.busy.version}) serves this Gallery data directory (port ${i.busy.port}, pid ${i.busy.pid}) and gave no answer in 10s; this is Gallery ${F}. Update this one (npm i -g @heycys/gallery@latest), or run ${v} again in a while.`}}:i.busy?{failed:{ok:!1,reason:"busy",message:`The shared Gallery server (port ${i.busy.port}, pid ${i.busy.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run ${v} again in a while, or stop that process first (gallery stop): a second server for this data directory is not started beside it.`}}:i.stuck?{failed:{ok:!1,reason:"stuck",message:`An older Gallery's server serves this Gallery data directory and did not stop: ${i.stuck.message}`}}:i.port===null?{failed:{ok:!1,reason:"ports",message:u?"The sandbox service is stopped. Run gallery sandbox to start a new instance.":`No server for this data directory runs, and no port from ${L} is free to start one on: stop a server on one of them (or name another first port: GALLERY_PORT=<n>), then run ${v}.`}}:{...i,passed:[...c,...i.passed]}},f=await E(0);if(f.failed)return f.failed;let{port:l,started:d,passed:T,replaced:Y}=f,k=f.running??null,G=Date.now()+n,x="",C=async()=>{if(e){let c=await fetch(`${S(l,e)}?present`,{signal:AbortSignal.timeout(5e3)}).catch(()=>null),u=c?.ok?await c.text():"";return x=c?u?`HTTP ${c.status} without the title`:`HTTP ${c.status}`:"no answer",!!(u&&a(u))}let s=await fetch(`http://127.0.0.1:${l}/__gallery/workspace/info`,{signal:AbortSignal.timeout(5e3)}).catch(()=>null);return x=s?`HTTP ${s.status}`:"no answer",!!s?.ok};for(;;await me(300)){if(Date.now()>G)return{ok:!1,reason:"timeout",message:`${e?S(l,e):D(l)} did not answer${e?" with the document's title":""} in ${n/1e3}s (${x})${d?`; the server's output is in ${w}`:""}.`};if(d){let s=await X({answering:!0});if(s&&s.pid!==d.pid){if(d.exitCode===null)try{process.kill(d.pid)}catch{}({port:l}=s),k={pid:s.pid,kind:(await te())?.kind??"cli",version:null},d=null;continue}if(!s&&d.exitCode===null){x="the server started has not announced itself yet";continue}if(!s){if(!await Z(l)){if(f=await E(m.indexOf(l)+1,[...T,`${l} (taken by another program while the server started)`]),f.failed)return f.failed;({port:l,started:d,passed:T}=f),k=f.running??null,G=Date.now()+n;continue}let c=await h.readFile(w,"utf8").catch(()=>"");return{ok:!1,reason:"stopped",message:`The Gallery server on port ${l} stopped (exit ${d.exitCode}). Its last words (${w}):
5
+ ${c.split(`
6
+ `).slice(-15).join(`
7
+ `)}`}}}if(await C())break}return await h.writeFile(b.lastPortFile,`${l}
8
+ `).catch(()=>{}),{ok:!0,port:l,pid:d?.pid??k?.pid??null,kind:k?.kind??"cli",started:!!d,replaced:Y??null,passed:T,movedFrom:Number.isInteger(p)&&p>0&&p!==l?p:null}}var Le=e=>e.length<2?e.join(""):`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`;function W({port:e,pid:t,kind:r,started:n,replaced:o,passed:a=[],movedFrom:p=null}){if(!n&&!o&&p===null)return null;let m=[`pid ${t}`,...r==="dev"?["npm run dev's"]:[],...n?[`started now${a.length?`, after passing over ${Le(a)}`:""}`]:[],...o?[`it replaced Gallery ${o.version??"an older version"}'s server, pid ${o.pid}`]:[]],L=n?`; its log: ${w}`:"",v=p===null?"":` It was on port ${p} before: an address with that port no longer works; use the ones below.`;return`\u63D0\u793A\uFF1AGallery's shared server is on port ${e} (${m.join(", ")}${L}).${v} This command is done; the server runs on in the background (nothing to wait for or keep running).`}var Me=e=>{let t=W(e);return t?[t]:[]};async function Te(e,t,r=null){let n=W(t);return[...n?[n]:[],...e?[`${ie}${ye(t.port,e)}`]:[],`${g}${e?await ve(t.port,{slug:e,block:r}):D(t.port)}`]}async function He(e,{skipped:t,command:r,ports:n=null}){let o=`gallery open ${e} starts it and prints the address to give the user`;if(t)return[`\u63D0\u793A\uFF1AThe server was not started (--no-preview or ${j}): ${o}.`];let a=await be({slug:e,command:r,ports:n});return a.ok?Te(e,a):[`\u95EE\u9898\uFF1AThe server was not started: ${a.message}`,` When that is fixed, ${o}.`]}export{g as a,ie as b,ae as c,We as d,Ye as e,j as f,Ce as g,ce as h,de as i,pe as j,we as k,B as l,S as m,ye as n,D as o,ve as p,ge as q,be as r,W as s,Me as t,Te as u,He as v};
@@ -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{c as Ee,d as X,f as ae,h as ie,i as Ne,l as oe,p as ve}from"./chunk-KLQP46Y3.mjs";import{D as ce}from"./chunk-E7656LR7.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-TKWEX4FD.mjs";import{b as ye,e as mt}from"./chunk-A55HN5OK.mjs";mt();import{createHash as ht}from"node:crypto";import{cellsOf as gt}from"../browser/shared/card-size.mjs";import{escapeAttribute as de}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as le,hasClass as _e,walk as Te}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as He}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,sr=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),De="gallery-board",Fe="gallery-card",Le=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,He)!==void 0,wt=e=>ht("sha256").update(e.replace(/\r\n?/g,`
2
+ import{c as Ee,d as X,f as ae,h as ie,i as Ne,l as oe,p as ve}from"./chunk-BSJKFE7I.mjs";import{D as ce}from"./chunk-E7656LR7.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-TKWEX4FD.mjs";import{b as ye,e as mt}from"./chunk-A55HN5OK.mjs";mt();import{createHash as ht}from"node:crypto";import{cellsOf as gt}from"../browser/shared/card-size.mjs";import{escapeAttribute as de}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as le,hasClass as _e,walk as Te}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as He}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,sr=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),De="gallery-board",Fe="gallery-card",Le=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,He)!==void 0,wt=e=>ht("sha256").update(e.replace(/\r\n?/g,`
3
3
  `)).digest("hex").slice(0,16),kt=e=>ye(e.replace(/^/," "),{sourceCodeLocationInfo:!0});function I(e){let n=[];return Te(kt(e),r=>{if(!_e(r,De))return;let i=le(r).filter(s=>_e(s,Fe)&&s.sourceCodeLocation).map(s=>{let a=le(s).find(Le)??null;a||Te(s,O=>{a??=Le(O)?O:null});let h=s.sourceCodeLocation,g={x:N(s,"data-x"),y:N(s,"data-y"),w:N(s,"data-w"),h:N(s,"data-h")};return{id:N(s,"data-card-id")??null,node:s,board:N(r,"data-board-id")??null,...gt({dataset:g}),instance:a,block:a?N(a,He):null,start:h.startOffset,end:h.endOffset,closed:!!h.endTag}});n.push({id:N(r,"data-board-id")??null,node:r,cards:i})},{inTemplates:!1}),{boards:n,cards:n.flatMap(r=>r.cards)}}function Ot(e){let n=new Set(e.map(({id:s})=>s).filter(s=>typeof s=="string"&&q.test(s))),r=new Set,i=1;return e.map(({id:s})=>{if(typeof s=="string"&&q.test(s)&&!r.has(s))return r.add(s),s;for(;n.has(`c${i}`)||r.has(`c${i}`);)i++;let a=`c${i}`;return r.add(a),a})}function fe(e){let n=new Set(e),r=1;for(;n.has(`c${r}`);)r++;return`c${r}`}function ee(e,n,r){let{startTag:i}=n.sourceCodeLocation,s=i.attrs??{},a=[],h=[];for(let[g,O]of Object.entries(r)){let S=s[g];S?(a.push({start:S.startOffset,end:S.endOffset,text:O===null?"":`${g}="${de(String(O))}"`}),O===null&&e[S.startOffset-1]===" "&&(a.at(-1).start-=1)):O!==null&&h.push(` ${g}="${de(String(O))}"`)}if(h.length){let g=s.class?.endOffset??i.startOffset+1+n.tagName.length;a.push({start:g,end:g,text:h.join("")})}return a}function te(e,n){return[...n].sort((r,i)=>i.start-r.start||i.end-r.end).reduce((r,{start:i,end:s,text:a})=>r.slice(0,i)+a+r.slice(s),e)}function W(e){let{cards:n}=I(e),r=Ot(n),i=n.flatMap((s,a)=>s.id===r[a]?[]:ee(e,s.node,{"data-card-id":r[a]}));return{text:i.length?te(e,i):e,filled:n.flatMap((s,a)=>s.id===r[a]?[]:[r[a]])}}var V=(e,n)=>wt(e.slice(n.start,n.end));function Re(e){let n=W(e).text;return I(n).cards.map(r=>({id:r.id,board:r.board,x:r.x,y:r.y,w:r.w,h:r.h,base:V(n,r),block:r.block}))}var Pe=e=>[e.board,...["x","y","w","h"].map(n=>N(e.node,`data-${n}`))].join(",");function Me(e,n){let r=n.node.sourceCodeLocation.startTag.endOffset;return e.slice(n.start,r).replace(/\s+data-[xywh]="[^"]*"/g,"")+e.slice(r,n.end)}function Je(e,n){let[r,i]=[W(e).text,W(n).text],[s,a]=[I(r).cards,I(i).cards],h={};for(let g of s)a.some(O=>O.id===g.id)||(h[g.id]=["removed"]);for(let g of a){let O=s.find(v=>v.id===g.id);if(!O){h[g.id]=["added"];continue}let S=[...Pe(O)!==Pe(g)?["cells"]:[],...Me(r,O)!==Me(i,g)?["content"]:[]];S.length&&(h[g.id]=S)}return h}function Y(e,n){let{cards:r}=I(e),i=r.flatMap(s=>{let a=n.get(s.id);if(!a)return[];let h={};for(let g of["x","y","w","h"])a[g]!==void 0&&N(s.node,`data-${g}`)!==String(a[g])&&(h[`data-${g}`]=a[g]);return Object.keys(h).length?ee(e,s.node,h):[]});return i.length?te(e,i):e}function xt(e,n,r){let i=e.lastIndexOf(`
4
4
  `,n-1)+1,s=e.indexOf(`
5
5
  `,r),a=s===-1?e.slice(r):e.slice(r,s);return!/^[ \t]*$/.test(e.slice(i,n))||!/^[ \t\r]*$/.test(a)?{from:n,to:r}:{from:i,to:s===-1?e.length:s+1}}function Be(e,n){let r=I(e).cards.find(a=>a.id===n);if(!r)return null;let{from:i,to:s}=xt(e,r.start,r.end);return{text:e.slice(0,i)+e.slice(s),html:e.slice(r.start,r.end)}}var ze=(e,n)=>/^[ \t]*/.exec(e.slice(e.lastIndexOf(`
@@ -19,4 +19,4 @@ import{c as Ee,d as X,f as ae,h as ie,i as Ne,l as oe,p as ve}from"./chunk-KLQP4
19
19
  `:`
20
20
  `,A=We({id:C,...L},m,"",J),G=ue(f,l.id,A),Z=j(c,ge(c,{id:C,...L}).filter(y=>y.id!==C)),P=Y(G.text,Z),B=I(P).cards.find(y=>y.id===C);if(t.settings!==void 0){let y=R.settings(P,{card:C,base:V(P,B),values:t.settings},o);if(y.error)return y;P=y.text,B=I(P).cards.find(K=>K.id===C)}return{text:P,extra:{card:C,html:P.slice(B.start,B.end),measure:k.measured&&t.h===void 0,pushed:[...Z.keys()]}}},remove(f,t){let{card:o,error:d}=E(f,t);if(d)return{error:d};let{text:p,html:l}=Be(f,o.id);return{text:p,extra:{removed:{id:o.id,board:o.board,html:l}}}},edit(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=t.parts!==void 0?t.parts:typeof t.part=="string"?{[t.part]:t.html}:null;if(!u||typeof u!="object"||Array.isArray(u)||Object.keys(u).length===0)return{error:x(400,"part")};let w=Object.fromEntries(Object.entries(u).map(([k,$])=>[k,Ft($,d)])),m=F(f,p,w,o);return m.error?m:{text:m.text,extra:{parts:T(m.parts,d)}}},settings(f,t,{packages:o,slug:d}){let{card:p,error:l}=E(f,t);if(l)return{error:l};let u=o.get(p.block),w=u?.settings??[];if(!u||w.length===0)return{error:x(409,"settings")};let m=t.values;if(!m||typeof m!="object"||Array.isArray(m))return{error:x(400,"values")};for(let[L,J]of Object.entries(m)){let A=w.find(G=>G.key===L);if(!A||!Rt(J,A))return{error:x(400,"values",L)}}let k=_(f,p,o)[Q];if(k===void 0)return{error:x(409,"settings")};let $={};try{$=k.trim()?JSON.parse(k):{}}catch{$={}}(!$||typeof $!="object"||Array.isArray($))&&($={});let c={...$,...m};if(JSON.stringify(c)===JSON.stringify($))return{text:f,extra:{parts:T({[Q]:{was:k,now:k}},d)}};let b=k.trim()?bt(k,c):JSON.stringify(c),C=F(f,p,{[Q]:b},o);return C.error?C:{text:C.text,extra:{parts:T(C.parts,d)}}},async"restore-defaults"(f,t,o){if(!Pt(o.slug,e))return{error:x(409,"defaults")};let d=new Set(I(f).cards.map(w=>w.block)),p=f,l=[],u=[];for(let w of Ct){if(d.has(w))continue;let[m,k]=It[w]??[],$=await R.add(p,{op:"add",block:w,...m?{w:m,h:k}:{}},o),c=o.packages.get(w)?.name??X(a).find(({id:b})=>b===w)?.title??null;if($.error){u.push({block:w,reason:$.error[1].reason,name:c});continue}p=$.text,l.push({card:$.extra.card,block:w,html:$.extra.html,name:c})}return{text:p,extra:{added:l,skipped:u}}}};function ct(f,t,{boards:o,cards:d}){if(typeof t.html!="string"||t.html.length>11e5)return{error:x(400,"html")};let p=t.html.trim(),l=Ge(p);if(!l)return{error:x(400,"html")};let u=Ve(l.node.tagName,l.node.attrs??[]);if(Tt(l.node,A=>{u||=Ve(A.tagName,A.attrs??[])}),u)return{error:x(400,"html")};let w=o.find(A=>A.id===(typeof t.board=="string"?t.board:Qe))??o[0];if(!w)return{error:x(409,"board")};if(t.x!==void 0&&!U(t.x)||t.y!==void 0&&!U(t.y))return{error:x(400,"cells")};let m=d.map(A=>A.id),k=l.id&&!m.includes(l.id)&&q.test(l.id)?l.id:fe(m),$=he({x:t.x??l.x,y:t.y??l.y,w:l.w,h:l.h}),c=w.cards.map(({id:A,x:G,y:Z,w:P,h:B})=>({id:A,x:G,y:Z,w:P,h:B})),b=ue(f,w.id,Ke(p,{id:k,...$})),C=j(c,ge(c,{id:k,...$}).filter(A=>A.id!==k)),L=Y(b.text,C),J=I(L).cards.find(A=>A.id===k);return{text:L,extra:{card:k,html:L.slice(J.start,J.end),pushed:[...C.keys()]}}}async function be(f,t,{by:o}={}){if(!t||typeof t!="object"||!Ht.includes(t.op))return x(400,"op");if(t.workspace!==void 0&&(typeof t.workspace!="string"||!_t(t.workspace,e)))return x(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");if(!we(f,e))return x(404,"missing");let d=jt(f,e);for(let p=0;p<3;p++){let[l,u]=await Promise.all([z.readFile(d.html,"utf8").catch(()=>null),z.readFile(d.json,"utf8").catch(()=>"")]);if(l===null)return x(404,"missing");if(Buffer.byteLength(l)>1e6)return x(413,"size");let w=Xe(l,u),m=W(l).text,k=i(),$={slug:f,get catalog(){return k},get packages(){return k.packages},refresh:()=>{k=i()}},c=await R[t.op](m,t,$);if(c.error)return c.error;let b=c.text;if(Buffer.byteLength(b)>1e6)return x(413,"size");if(b!==l){if(await S(f,l),!await Ye(d.html,b,{expect:l}))continue;await v(f,{op:t.op,by:o==="gallery"?"gallery":t.agent===!0?"agent":"page",cards:Je(l,b)})}return t.op==="restore-defaults"&&await qe(e).catch(()=>{}),[200,{ok:!0,version:Xe(b,u),before:w,cards:Re(b),...c.extra??{}}]}return x(409,"busy")}function Se(f="zh"){oe(e,{directory:a,log:h}).updated.length>0&&s();let t=i(),o=[...t.settings.packsOff??[],...ve(e,t.settings.packs)],d=c=>c.split("/")[0],p=c=>!t.settings.unlisted.includes(c)&&!o.includes(d(c)),l=c=>t.packs?.get(d(c))??u(d(c)),u=c=>{try{return Nt(pe(H.join(a??vt,c,Et),"utf8")).name}catch{return null}},w=[...t.packages.values()].filter(c=>c.places.includes("page")&&p(c.id)).map(c=>({id:c.id,name:c.name,description:c.description,preview:c.files.includes("preview.svg")?je(c,"preview.svg"):null,size:me(c.card),installed:!0,settings:c.settings.length>0,pack:{id:d(c.id),name:l(c.id)}}));for(let c of X(a)){if(!c.places.includes("page")||t.packages.has(c.id)||t.problems.has(c.id)||t.settings.disabled.includes(c.id)||!p(c.id)||ie(e,c).added)continue;let b=null;try{b=`data:image/svg+xml;base64,${pe(H.join(c.folder,"preview.svg")).toString("base64")}`}catch{}let C=null;try{C=JSON.parse(pe(H.join(c.folder,"component.json"),"utf8")).card??null}catch{}w.push({id:c.id,name:c.title,description:c.description,preview:b,size:me(C),installed:!1,settings:!1,pack:{id:c.pack,name:l(c.id)}})}let m=c=>c.name?.[f]??c.name?.zh??c.id,k=Ee(a),$=({pack:c})=>c.id===At?-1:k.includes(c.id)?k.indexOf(c.id):k.length;return w.sort((c,b)=>$(c)-$(b)||(c.pack.id===b.pack.id?0:c.pack.id<b.pack.id?-1:1)||m(c).localeCompare(m(b),"zh-CN")||(c.id<b.id?-1:1))}async function dt(f,t){return we(f,e)?(t?.cards===!0?await qe(e):await Lt(e,f),[200,{ok:!0}]):x(404,"missing")}function lt(f,t,o,d){if((d==="cards"||d==="hint")&&f.method==="POST")return n.respond(async l=>{let u=await n.check(l);return u.error?u.error:d==="hint"?dt(o,u.body):be(o,u.body)})(f,t);if(d==="library"&&f.method==="GET"){let l=f.headers.host??"",u=f.socket.localPort;if(l!==`127.0.0.1:${u}`&&l!==`localhost:${u}`)return re(t,403,{ok:!1,reason:"host"});if(!we(o,e))return re(t,404,{ok:!1,reason:"missing"});let w=new URL(f.url??"/","http://localhost").searchParams.get("language")==="en"?"en":"zh";return re(t,200,{ok:!0,blocks:Se(w)})}let p=["cards","library","hint"].includes(d);return re(t,p?405:404,{ok:!1,reason:p?"method":"unknown"})}return{handle:lt,apply:be,library:Se}}import{readFileSync as ot}from"node:fs";import{writeAtomic as nt}from"../browser/shared/files.mjs";import{HOME as M,HOME_TITLE as Jt,createPage as Bt,hintOf as st,markHomeMade as at,pageExists as Oe,pageFiles as xe,pageSlugRefused as Wt,pagesSettings as Ut,writeHints as se}from"../browser/shared/pages.mjs";import{layoutOf as it,markerOf as Gt}from"../browser/shared/workspace.mjs";import{lineIconValue as Kt}from"../browser/shared/emoji/line-icons.mjs";var Vt="GALLERY_NO_DEFAULT_HOME",$e=Kt("house"),Yt="/icons/home-1_lightgray.svg",Zt=(e=process.env)=>!["","0","false",void 0].includes(e[Vt]);async function Hr(e,{shipped:n=void 0,stateDirectory:r=it(e).state,env:i=process.env}={}){if(Zt(i))return{did:"off"};let s={ours:!1};try{s=Gt(ot(it(e).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread"};if(Ut(e).homeMade)return await Qt(e).catch(()=>{}),{did:"done"};let a="mark";try{if(Oe(M,e))return await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"kept"};a="page";let h=await Wt(M,e);if(h)return{did:"taken",why:h};await Bt(M,Jt,{root:e,icon:$e,defaultCards:!0,hint:!0}),a="cards";let g=rt({root:e,edits:null,stateDirectory:r,catalog:()=>Ce(e),shipped:n}),[,O]=await g.apply(M,{op:"restore-defaults"},{by:"gallery"});return a="mark",await at(e),await se(e,{homeAdopted:!0,homeLineIcon:!0}).catch(()=>{}),{did:"made",file:xe(M,e).html,cards:(O.added??[]).map(({card:S})=>S),skipped:O.skipped??[]}}catch(h){return{did:"failed",stage:a,file:Oe(M,e)?xe(M,e).html:null,why:h?.message??String(h)}}}async function Qt(e){let n=!1,r=()=>{if(!Oe(M,e))return null;let{json:i}=xe(M,e);try{let s=ot(i,"utf8"),a=JSON.parse(s.replace(/^/,""));return a&&typeof a=="object"&&!Array.isArray(a)?{json:i,text:s,value:a}:null}catch{return null}};if(st(e,"homeAdopted")!==!0){let i=r();if(i&&!("defaultCards"in i.value)&&!("hint"in i.value)){let s={...i.value,...i.value.icon?{}:{icon:$e},defaultCards:!0,hint:!0};n=await nt(i.json,`${JSON.stringify(s,null,2)}
21
21
  `,{expect:i.text})}await se(e,{homeAdopted:!0})}if(st(e,"homeLineIcon")!==!0){let i=r();i?.value.icon===Yt&&(n=await nt(i.json,`${JSON.stringify({...i.value,icon:$e},null,2)}
22
- `,{expect:i.text})||n),await se(e,{homeLineIcon:!0})}return n}function Dr({stage:e,file:n,why:r}){return e==="mark"?`The default home page ${n} is there, but gallery.json could not say it was made (${r}); a later start tries again.`:e==="cards"?`The default home page ${n} was made without its cards (${r}): \u6062\u590D\u9ED8\u8BA4\u5361\u7247 in its menu in the sidebar puts them on.`:`The default home page was not made (${r}); a later start tries again.`}export{q as a,I as b,W as c,Me as d,ar as e,Ar as f,Er as g,rt as h,Zt as i,Hr as j,Dr as k};
22
+ `,{expect:i.text})||n),await se(e,{homeLineIcon:!0})}return n}function Dr({stage:e,file:n,why:r}){return e==="mark"?`The default home page ${n} is there, but gallery.json could not say it was made (${r}); a later start tries again.`:e==="cards"?`The default home page ${n} was made without its cards (${r}): \u6062\u590D\u9ED8\u8BA4\u5361\u7247 in its menu in the sidebar puts them on.`:`The default home page was not made (${r}); a later start tries again.`}export{q as a,I as b,W as c,Re as d,Me as e,ar as f,Ar as g,Er as h,rt as i,Zt as j,Hr as k,Dr as l};
@@ -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{d as S,e as O,g as K}from"./chunk-NW6LAU22.mjs";import"./chunk-XRYECF23.mjs";import{j as D}from"./chunk-B6RAGF4R.mjs";import{a as b}from"./chunk-5TLLIZT7.mjs";import"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import"./chunk-HFTBVEZK.mjs";import{c as R}from"./chunk-XNNCQROX.mjs";import"./chunk-LJZIYVNA.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-2OHANJ6Q.mjs";import{c as F}from"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-56SVJENP.mjs";import{d as M}from"./chunk-PBMOC7KA.mjs";import"./chunk-BSJKFE7I.mjs";import{b as w}from"./chunk-L4WLQYFC.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-E7656LR7.mjs";import{a as I,f as A}from"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import Q from"node:fs";import{iconKind as V}from"../browser/shared/emoji/icon-value.mjs";import{headOf as U,pageExists as E,pageFiles as y,readPageMeta as X,setPageMeta as Y}from"../browser/shared/pages.mjs";import{findPreviewServer as Z}from"../browser/shared/preview-server.mjs";import{headPage as W,pageHeadKey as _}from"../browser/shared/sidebar-head.mjs";var ee=e=>e.replace(/\s+/g," ").trim(),N=e=>e==null?"none":JSON.stringify(e),te=e=>e.replace(/^[a-z]:\/(?:[^/]+\/)*?(?=icons\/(?:tabler\/)?[^/]+$)/i,"/");async function B(e,t){let n=await X(t,e);return n||(console.error(await S(t,e)),process.exit(1)),n}async function ue(e,[t,...n],d,s){if(!t||n.length)throw new w("Name one page, then what to set: --title, --icon.");if(!s.has("--title")&&!s.has("--icon"))throw new w('Say what to set: --title "<title>", --icon <emoji|icon|none>.');let r=s.has("--title")?ee(s.get("--title")):void 0;if(r==="")throw new w("--title takes the words of the title: a page's title is never empty.");if(r!==void 0&&r.length>200)throw new w("A page's title is 200 characters at most.");let c;if(s.has("--icon")){let a=te(s.get("--icon").trim()),i=a==="none"?"none":V(a);if(!["none","emoji","glyph"].includes(i)||/["<>&]/.test(a))throw new w(`Not an icon a custom page takes: ${a} (an emoji, none, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg; not a picture).`);if(i==="glyph"&&!F(a))throw new w(`No such icon of the \u56FE\u6807 tab: ${a}.`);c=i==="none"?null:a}let l=await B(e,t),h;try{h=await Y(t,{title:r,icon:c},e)}catch(a){throw a.code==="title"?new w(a.message):a}let f=[...r!==void 0&&h.title!==l.title?[` title: ${N(l.title)} \u2192 ${N(h.title)}`]:[],...c!==void 0&&h.icon!==l.icon?[` icon: ${N(l.icon)} \u2192 ${N(h.icon)}`]:[]];if(!f.length)return void console.log(`Nothing to change: ${t} has ${s.size===1?"that already":"those already"}.`);console.log(`Set the page ${t} (page.json):`);for(let a of f)console.log(a);console.log(`\u91CD\u8BFB\uFF1A${b(y(t,e).json)}`),r!==void 0&&h.title!==l.title&&console.log("\u63D0\u793A\uFF1Apage.html's own <title> is the page's, written by you: it was not changed (the sidebar shows page.json's title). Change it too where the page should say the new name.")}async function oe(e,t,n){let d=await Z(),s=d?await D(d,n,t):null;if(s)return s;let[,r]=await R({edits:{},reports:{},reportsDirectory:e}).run(t,n);return r}async function be(e,[t,...n],d,s){if(!t||n.length)throw new w("gallery page move takes one page's slug.");let r=s.get("--after"),c=d.has("--first");if(r===void 0&&!c)throw new w("Say where it goes: --after <page> or --first.");if(r!==void 0&&c)throw new w("--after and --first are two places: give one.");await B(e,t),r!==void 0&&(r===t&&(console.error(`${t} cannot go after itself.`),process.exit(1)),E(r,e)||(console.error(`No page "${r}" to put ${t} after: gallery page list lists those there are.`),process.exit(1)));let l=await U(e),h=_(t),f=l.filter($=>$!==h),a=c?f.findIndex($=>W($)!==null):f.indexOf(_(r))+1,i=[...f];i.splice(a===-1?i.length:a,0,h);let g=async()=>(await U(e)).map(W).filter(Boolean);if(i.join()===l.join()){console.log(`${t} is there already.`),console.log(`Pages, in the sidebar's order: ${(await g()).join(", ")}`);return}let u=await oe(e,"head",{order:i});u?.ok||(console.error(`Not moved: ${u?.message??u?.reason??"no answer"}.`),process.exit(1)),console.log(`Moved the page ${t} ${c?"to the first place among the pages":`after ${r}`} in the sidebar's head.`),console.log(`Pages, in the sidebar's order: ${(await g()).join(", ")}`)}var x={gone:({id:e})=>`The card ${e} is not on the page any more.`,changed:({id:e})=>`The card ${e} kept changing while it was being written (the open page, or another write): run this again.`,resize:({id:e})=>`The card ${e}'s block cannot be resized (its manifest's card has no resize, or the size is none it takes): --move still moves it.`,cells:()=>"--move and --size take whole numbers: x and y from 0, w from 1 to 12 and h from 1.",block:({id:e})=>`The card ${e}'s block does not load, so its data cannot be written: gallery block check says why.`,settings:({id:e})=>`The card ${e} has no settings part, or its block no settings: --set goes with a block whose manifest has some.`,values:({id:e,key:t})=>`The card ${e}'s setting ${t?`"${t}" `:""}does not take that value (a text of 10,000 characters at most, a number, a date, one of a select's options, a switch's true or false).`,size:()=>"page.html would grow past 1,000,000 bytes.",busy:()=>"page.html was written again and again meanwhile: run this again.",defaults:({slug:e})=>`The page ${e} has no default cards: only a page whose page.json says "defaultCards": true (the default home page) has.`,missing:({slug:e})=>`No custom page "${e}".`},G=(e,t,n)=>{let d=e?.reason??e?.refused;return x[d]?.({...n,key:e?.message})??`Not written (${t}: ${d??"no answer"}${e?.message?`: ${e.message}`:""}).`};function H(e,t,n){let d=M(Q.readFileSync(y(t,e).html,"utf8"));return{card:d.find(s=>s.id===n)??null,cards:d}}async function T(e,t,n,d){let s;for(let r=0;r<3;r++){let{card:c}=H(e,t,n);if(!c)return{status:409,answer:{ok:!1,refused:"gone"}};if(s=await O(e,t,{...d,card:n,base:c.base,agent:!0}),s.answer?.refused!=="changed")break}return s}var j=({x:e,y:t,w:n,h:d})=>`x ${e}, y ${t}, w ${n}, h ${d}`,q=/^(\d+),(\d+)$/,ne=e=>{try{let t=JSON.parse(e??"");return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}catch{return{}}};async function ye(e,[t,n,...d],s,r,c=[]){if(!t||!n||d.length)throw new w("gallery page card takes a page's slug and a card's id (gallery page check lists the cards): gallery page card <slug> <card id> --set|--move|--size|--remove.");let l=s.has("--remove"),h=r.get("--move"),f=r.get("--size");if(!c.length&&h===void 0&&f===void 0&&!l)throw new w("Say what to do with the card: --set <key>=<value>, --move <x>,<y>, --size <w>,<h>, or --remove.");if(l&&(c.length||h!==void 0||f!==void 0))throw new w("--remove goes alone: it takes the card off the page.");let a=h===void 0?null:q.exec(h);if(h!==void 0&&!a)throw new w(x.cells());let i=f===void 0?null:q.exec(f);if(f!==void 0&&(!i||Number(i[1])<1||Number(i[2])<1))throw new w(x.cells());E(t,e)||(console.error(await S(t,e)),process.exit(1));let{card:g,cards:u}=H(e,t,n);g||(console.error(`No card "${n}" on the page ${t}: ${u.length?`its cards are ${u.map(o=>o.id).join(", ")}`:"it has none"} (gallery page check lists them).`),process.exit(1));let $=null;if(c.length){let o=A(e).packages.get(g.block);o||(console.error(x.block({id:n})),process.exit(1)),$=K(c,o)}let k={cards:u,answer:null},v=null,P=!1,z=({answer:o,status:p})=>{console.error(`Not ${l?"removed":"changed"}: ${G(o,p,{id:n,slug:t})}${k.answer?" (the place was written already; the settings were not)":""}`),process.exit(1)};if(l){let o=await T(e,t,n,{op:"remove"});o.answer?.ok||z(o),console.log(`Removed the card ${n} (${g.block??"no block"}, board ${g.board}: ${j(g)}) from ${b(y(t,e).html)}${o.viaServer?" (through the workspace's running server: an open page shows it at once)":""}.`),console.log(`Its data went with it (page.html as it was is kept in .gallery/state/pages/${t}/, the last 20 versions); gallery page add ${t} ${g.block??"<block>"} puts a new card of its block in.`),console.log(`\u91CD\u8BFB\uFF1A${b(y(t,e).html)}`);return}if(a||i){let o=await T(e,t,n,{op:"place",...a?{x:Number(a[1]),y:Number(a[2])}:{},...i?{w:Number(i[1]),h:Number(i[2])}:{}});o.answer?.ok||z(o),k={cards:o.answer.cards,answer:o.answer},P||=o.viaServer}if($){let o=await T(e,t,n,{op:"settings",values:$});o.answer?.ok||z(o),k={cards:o.answer.cards,answer:o.answer},v=ne(o.answer.parts?.[I]?.was),P||=o.viaServer}let m=k.cards.find(o=>o.id===n)??g,C=k.cards.filter(o=>o.id!==n&&u.some(p=>p.id===o.id&&(p.x!==o.x||p.y!==o.y||p.w!==o.w||p.h!==o.h))),L=b(y(t,e).html);if(console.log(`The card ${n} of ${t} (${m.block??"no block"}) on board ${m.board}: ${j(m)}${m.x===g.x&&m.y===g.y&&m.w===g.w&&m.h===g.h?" (the place as it was)":` (was ${j(g)})`}${P?" (through the workspace's running server: an open page shows it at once)":""}.`),i&&(m.w!==Number(i[1])||m.h!==Number(i[2]))&&console.log(` The block's sizes gave ${m.w} \xD7 ${m.h} for the ${i[1]} \xD7 ${i[2]} asked.`),C.length&&console.log(` Pushed down under it, as it met them: ${C.map(o=>`${o.id} (y ${o.y})`).join(", ")}; no card moved up.`),$){let o=Object.entries($).map(([p,J])=>`${p}=${JSON.stringify(J)}${v&&Object.hasOwn(v,p)&&JSON.stringify(v[p])!==JSON.stringify(J)?` (was ${JSON.stringify(v[p])})`:""}`);console.log(` Settings written: ${o.join(", ")}`)}console.log(`\u91CD\u8BFB\uFF1A${L}`)}var ae={disabled:"turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868",missing:"not in the workspace",places:"not a block a page takes",board:"the page has no board"};async function ke(e,[t,...n]){if(!t||n.length)throw new w("gallery page reset-cards takes one page's slug.");E(t,e)||(console.error(await S(t,e)),process.exit(1));let{status:d,answer:s,viaServer:r}=await O(e,t,{op:"restore-defaults",agent:!0});s?.ok||(console.error(`Nothing put back: ${G(s,d,{slug:t})}`),process.exit(1));let c=b(y(t,e).html),l=s.added??[],h=s.skipped??[];if(l.length===0&&h.length===0)return void console.log(`The page ${t} holds a card of every default block already: nothing to put back.`);if(l.length){console.log(`Put back ${l.length} default card${l.length===1?"":"s"} on ${c}${r?" (through the workspace's running server: an open page shows them at once)":""}:`);for(let{card:f,block:a}of l){let i=s.cards.find(g=>g.id===f);console.log(` data-card-id="${f}" of ${a}${i?`, board ${i.board}: ${j(i)}`:""}`)}}else console.log(`No default card was put back on ${c}.`);for(let{block:f,reason:a}of h)console.log(` Not put back: ${f} (${ae[a]??a})`);l.length&&console.log(`\u91CD\u8BFB\uFF1A${c}`)}export{ye as cardCommand,be as movePage,ke as resetCards,ue as setPage};
@@ -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 c,e as w,r as f,u}from"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import{b as t,f as m,i as p}from"./chunk-L4WLQYFC.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as l}from"../browser/shared/paths.mjs";import{joinDefaultTree as L,joinedLine as N}from"../browser/shared/drafts.mjs";var U=5e3;async function O(h){let{positional:i,options:a,values:d}=m({options:["--no-browser","--present"],values:["--settings"],argv:h}),r=d.get("--settings");if(r&&r!=="extensions")throw new t("--settings accepts extensions.");if(r&&i.length)throw new t("Use --settings without a document name.");if(a.has("--present")&&r)throw new t("--present and --settings are two places: give one.");if(a.has("--present")&&i.length===0)throw new t("--present shows a document: name it, gallery open <document> --present.");if(i.length>1)throw new t("Name one document at most.");let{slug:e=null,block:E=null}=i.length?await p(i[0]):{};console.log(`\u5DE5\u4F5C\u533A\uFF1A${l}`);let n=await f({slug:e,baseline:e!==null});if(n.ok||console.error(`\u95EE\u9898\uFF1A${n.message}`),n.reason==="missing"){let{HOME:s,pageExists:v}=await import("../browser/shared/pages.mjs"),{missingPageSaid:x,HOME_NOT_MADE:g}=await import("./chunk-K7Y7SPTS.mjs");v(e,l)?console.error(`"${e}" is a custom page, not a document: gallery page open ${e} opens it and gives its address.`):e===s&&await x(e,l)===g&&console.error(g)}if(e!==null&&n.reason!=="missing"){let{roundBegins:s}=await import("./chunk-UTKNWYBA.mjs");await s(e,n.ok?{}:{wait:U})}if(e!==null&&n.reason!=="missing"){let s=N(await L(l,e));s&&console.log(s)}n.ok||process.exit(1);let o=await u(e,n,E);if(r){let s=new URL(o.at(-1).slice(c.length));s.hash="settings/extensions",o[o.length-1]=c+s.href}a.has("--present")&&(o[o.length-1]=o.at(-1).replace("/#","/?present#"));for(let s of o)console.log(s);console.log(await w(o,a))}export{O 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,b,c}from"./chunk-MZ66LN3B.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-5L7RYZCL.mjs";export{b as installExtension,c as removeExtension,a as throughService};
@@ -0,0 +1,6 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as P,b as F}from"./chunk-LZY74XTP.mjs";import{b as S,f as N}from"./chunk-L4WLQYFC.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as K}from"node:crypto";import{watch as M}from"node:fs";import c from"node:fs/promises";import J from"node:os";import s from"node:path";import{DEVICE_NAMES as V,ensureWorkspace as q,slugTaken as b}from"../browser/shared/workspace.mjs";var Y=t=>typeof t=="string"&&/^[a-z0-9][a-z0-9-]{0,39}$/.test(t)&&!V.has(t),O=(t,e)=>s.relative(t,e)==="",j=t=>c.lstat(t).catch(e=>{if(e.code!=="ENOENT")throw e;return null}),H=t=>s.join(t,"sandbox.json"),B=t=>`http://127.0.0.1:${t}/`,Q=t=>c.rm(t,{recursive:!0,force:!0,maxRetries:5,retryDelay:100});async function p(t){let e=await j(t);if(e&&(!e.isDirectory()||e.isSymbolicLink()||!O(t,await c.realpath(t))))throw new Error(`\u6C99\u76D2\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6\u5939\uFF1A${t}`);return e}async function X(t=!1){let e=s.join(await c.realpath(J.tmpdir()),"gallery-sandboxes");t&&await c.mkdir(e,{mode:448}).catch(r=>{if(r.code!=="EEXIST")throw r});let o=await p(e);if(o&&process.getuid&&(o.uid!==process.getuid()||o.mode&18))throw new Error(`\u6C99\u76D2\u76EE\u5F55\u5FC5\u987B\u5F52\u5F53\u524D\u7528\u6237\u6240\u6709\uFF0C\u4E14\u53EA\u6709\u5F53\u524D\u7528\u6237\u53EF\u5199\uFF1A${e}`);return e}function z(t,e){let o=s.join(t,e);return{name:e,dir:o,home:s.join(o,"home"),data:s.join(o,"data"),cache:s.join(o,"cache")}}async function W(t,e){let o=z(t,e);if(!await p(o.dir))return null;let r=H(o.dir),n=await j(r);if(!n?.isFile()||n.isSymbolicLink()||n.nlink>1||n.size>1024)return null;let i=await c.readFile(r,"utf8").then(JSON.parse).catch(()=>null);return i?.version!==1||i.name!==e||!await p(o.home)||!await p(o.data)||!await p(o.cache)?null:o}var T=t=>({GALLERY_SANDBOX:t.name,GALLERY_WORKSPACE:t.home,GALLERY_DEFAULT_WORKSPACE:t.home,GALLERY_DATA_DIR:t.data,GALLERY_CACHE_DIR:t.cache,GALLERY_VITE_CACHE_DIR:s.join(t.cache,"vite"),GALLERY_NO_AUTOSTART:"1",GALLERY_NO_BROWSER:"1",GALLERY_NO_UPDATE_CHECK:"1",CLAUDE_CONFIG_DIR:s.join(t.dir,"claude"),CODEX_HOME:s.join(t.dir,"codex")});async function U(t){let e=await j(s.join(t.data,"server.json"));if(!e?.isFile()||e.isSymbolicLink()||e.nlink>1)return null;Object.assign(process.env,T(t));let{readAnnouncement:o,answerOf:r}=await import("../browser/shared/preview-server.mjs"),n=await o();if(!n||n.port<1||n.port>65535||n.pid<=0||!O(n.home,t.home))return null;let i=await r(n,2500);if(i==="busy")throw new Error(`\u6C99\u76D2 ${t.name} \u6682\u65F6\u65E0\u6CD5\u54CD\u5E94\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5`);return i==="yes"?n:null}function Z(t){let e=process.platform==="win32",o=r=>"'"+(e?r.replace(/['\u2018-\u201b]/g,"$&$&"):r.replaceAll("'","'\\''"))+"'";for(let[r,n]of Object.entries(T(t)))console.log(e?`$env:${r} = ${o(n)}`:`export ${r}=${o(n)}`);console.log(e?`Set-Location -LiteralPath ${o(t.home)}`:`cd -- ${o(t.home)}`)}async function x(t){let{createReportFromStarter:e}=await import("./chunk-SHZLMGGW.mjs");for(let[o,r,n]of[["sandbox-notes","\u6C99\u76D2\u7B14\u8BB0","\u5728\u8FD9\u91CC\u8BD5\u8BD5\u7F16\u8F91\u3001\u6279\u6CE8\u548C\u62D6\u52A8\u6587\u6863\u3002"],["sandbox-checklist","\u6D4B\u8BD5\u6E05\u5355","\u5728\u8BBE\u7F6E\u91CC\u6253\u5F00\u6216\u5173\u95ED\u6269\u5C55\uFF0C\u7136\u540E\u8FD4\u56DE\u8FD9\u7BC7\u6587\u6863\u3002"]]){let i=o;for(let l=2;b(i,t);l++)i=`${o}-${l}`;let{directory:f}=await e(i,r,n,{directory:t,blank:!0}),h=s.join(f,"doc.html");await c.writeFile(h,(await c.readFile(h,"utf8")).replace("<p></p>",`<p>${n}</p>`))}}function tt(t,e){let o,r=!1,n=Promise.resolve(),i=M(t,{recursive:!0},()=>{clearTimeout(o),o=setTimeout(()=>{n=n.then(async()=>{r||await e()}).catch(f=>console.error(`\u6269\u5C55\u91CD\u65B0\u5B89\u88C5\u5931\u8D25\uFF08${t}\uFF09\uFF1A${f.message}`))},350)});return i.on("error",f=>console.error(`\u65E0\u6CD5\u7EE7\u7EED\u76D1\u542C\u6269\u5C55\uFF08${t}\uFF09\uFF1A${f.message}`)),async()=>{r=!0,clearTimeout(o),i.close(),await n}}async function et(t,e,o,r){let n=(o.get("--extension")??[]).map(a=>s.resolve(a));for(let a of n)if(!await p(a))throw new Error(`\u627E\u4E0D\u5230\u6269\u5C55\u6587\u4EF6\u5939\uFF1A${a}`);let i=o.get("--from");if(i){i=await c.realpath(i);let a=s.relative(i,t.dir);if(!a||!a.startsWith(".."+s.sep)&&a!==".."&&!s.isAbsolute(a))throw new Error("\u6E90\u5DE5\u4F5C\u533A\u4E0D\u80FD\u5305\u542B\u6C99\u76D2\u76EE\u5F55")}try{await c.mkdir(t.dir,{mode:448})}catch(a){throw a.code==="EEXIST"?new Error(`\u6C99\u76D2 ${t.name} \u5DF2\u5B58\u5728\uFF1A\u8BF7\u6362\u4E00\u4E2A\u540D\u79F0`):a}let f=await p(t.dir),h=[],l,w=!1,d=!1,g,A=new Promise(a=>{g=a}),L=()=>{w=!0,l&&l.routes.stop()},$=["SIGINT","SIGTERM","SIGHUP"];for(let a of $)process.on(a,L);try{await Promise.all([t.home,t.data,t.cache].map(m=>c.mkdir(m,{mode:448})));let a={...process.env};if(Object.assign(process.env,T(t)),i){let{copySandboxWorkspace:m}=await import("./chunk-3FERXZF5.mjs"),u=await m(i,t.home);u&&console.log(`\u526F\u672C\u8DF3\u8FC7\u4E86 ${u} \u4E2A\u7B26\u53F7\u94FE\u63A5\u6216\u7279\u6B8A\u6587\u4EF6`)}await q(t.home),e.has("--demo")&&await x(t.home);let{release:k,projectRoot:E,workbenchDirectory:y}=await import("../browser/shared/paths.mjs"),v=y;if(!k&&!w){v=s.join(t.cache,"web");let{buildWorkbench:m}=await import("./chunk-ZM2IX3R2.mjs"),{writeSharedAssets:u}=await import("./chunk-VKZJRGDR.mjs"),_=await Promise.allSettled([m(E,v),u()]);for(let I of _)if(I.status==="rejected")throw I.reason}if(w)return;await c.writeFile(H(t.dir),JSON.stringify({version:1,name:t.name})+`
3
+ `,{flag:"wx",mode:384});let{startProductionServer:R}=await import("./chunk-MC4LRSVH.mjs");if(l=await R({reportsDirectory:t.home,port:0,web:v,kind:"cli",signals:!1,exit:g}),w)return;let{throughService:C}=await import("./chunk-QBJWIR3Q.mjs"),D=new Set;for(let m of n){let{installed:u}=await C("install",{path:m,enable:!0});if(D.has(u.id))throw new Error(`\u91CD\u590D\u7684\u6269\u5C55 ID\uFF1A${u.id}`);D.add(u.id),h.push(tt(m,async()=>{let{installed:_}=await C("install",{path:m,enable:!1});_.did!=="unchanged"&&console.log(`\u6269\u5C55 ${_.id} \u5DF2\u91CD\u65B0\u5B89\u88C5`)})),console.log(`\u6269\u5C55\uFF1A${u.id}\uFF08\u5DF2\u542F\u7528\uFF09`)}d=!0;let G=B(l.port);console.log(`\u6C99\u76D2\uFF1A${t.name}
4
+ \u5730\u5740\uFF1A${G}
5
+ \u5DE5\u4F5C\u533A\uFF1A${t.home}
6
+ Gallery ${r}`),console.log(e.has("--keep")?"Ctrl+C \u505C\u6B62\u670D\u52A1\u5E76\u4FDD\u7559\u6587\u4EF6\u3002":"Ctrl+C \u505C\u6B62\u670D\u52A1\u5E76\u6E05\u7406\u4E34\u65F6\u6587\u4EF6\u3002"),e.has("--open")&&console.log(P(await F(G,{env:a}))),await A}finally{try{if(await Promise.all(h.map(a=>a())),await l?.routes.stop(),d&&e.has("--keep"))console.log(`\u6C99\u76D2\u5DF2\u505C\u6B62\uFF0C\u6587\u4EF6\u4FDD\u7559\u5728 ${t.dir}`);else{if(!O(s.dirname(t.dir),await X()))throw new Error("\u6C99\u76D2\u7684\u4E34\u65F6\u76EE\u5F55\u5DF2\u6539\u53D8\uFF0C\u65E0\u6CD5\u81EA\u52A8\u6E05\u7406");let a=await p(t.dir);a&&a.dev===f.dev&&a.ino===f.ino&&await Q(t.dir)}}finally{for(let a of $)process.off(a,L)}}}async function wt(t,{flag:e,version:o}){if(e!==null)throw new S("\u6C99\u76D2\u4F7F\u7528\u81EA\u5DF1\u7684\u5DE5\u4F5C\u533A\u3002\u8BF7\u7528 --from <workspace> \u590D\u5236\u73B0\u6709\u5DE5\u4F5C\u533A\u3002");let r=t[0]&&!t[0].startsWith("-")?t[0]:"start",n=t[0]===r?t.slice(1):t;if(!["start","list","env","stop"].includes(r))throw new S(`\u672A\u77E5\u7684\u6C99\u76D2\u547D\u4EE4\uFF1A${r}`);let{positional:i,options:f,values:h}=N(r==="start"?{argv:n,options:["--demo","--open","--keep"],values:["--name","--from"],repeated:["--extension"]}:{argv:n}),l=r==="env"||r==="stop";if(i.length!==(l?1:0))throw new S(l?"\u8BF7\u63D0\u4F9B\u4E00\u4E2A\u6C99\u76D2\u540D\u79F0\u3002":"\u8FD9\u91CC\u4E0D\u63A5\u53D7\u4F4D\u7F6E\u53C2\u6570\u3002");let w=h.get("--name")??i[0]??`sb-${K(5).toString("hex")}`;if(!Y(w))throw new S("\u6C99\u76D2\u540D\u79F0\u987B\u4E3A 1\u201340 \u4E2A\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u6216\u8FDE\u5B57\u7B26\uFF0C\u4EE5\u5B57\u6BCD\u6216\u6570\u5B57\u5F00\u5934\u3002");try{let d=await X(r==="start");if(r==="start")return await et(z(d,w),f,h,o);if(r==="list"){let a=await c.readdir(d).catch(E=>{if(E.code!=="ENOENT")throw E;return[]}),k=0;for(let E of a.filter(Y).sort()){let y=await W(d,E).catch(()=>null);if(!y)continue;k++;let v=await U(y).then(R=>R?B(R.port):"\uFF08\u5DF2\u505C\u6B62\uFF09",()=>"\uFF08\u6682\u65F6\u65E0\u6CD5\u54CD\u5E94\uFF09");console.log(`${E} ${v} ${y.home}`)}k||console.log("\u6CA1\u6709\u6C99\u76D2\u3002");return}let g=await W(d,w);if(!g)throw new Error(`\u6CA1\u6709\u53EB ${w} \u7684\u6C99\u76D2`);if(r==="env")return Z(g);let A=await U(g);if(!A)return void console.log(`\u6C99\u76D2 ${w} \u6CA1\u6709\u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u3002`);let{stopServer:L}=await import("../browser/shared/preview-server.mjs"),$=await L(A,{force:!1});if(!$.ok)throw new Error($.message);console.log(`\u6C99\u76D2\u5DF2\u505C\u6B62\uFF1A${w}`)}catch(d){console.error(d.message),process.exitCode=1}}export{wt as run};
@@ -0,0 +1,15 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as $t}from"./chunk-ZTHICSSF.mjs";import{a as we,b as q,c as X,f as be,g as L,h as ke,i as Q,l as ye,m as xe}from"./chunk-5IHDLEB4.mjs";import{b as Vt,d as mt,f as K,g as qt,n as Xt,o as Qt,r as te,s as ee,t as oe,u as se,v as ne,x as gt}from"./chunk-B2EIMERT.mjs";import{a as le,b as de,c as fe,d as he,e as ue,f as pe,g as me,h as ge,l as $e}from"./chunk-BFJGHSQN.mjs";import{b as wt,c as ie,d as ae,e as re,g as ce}from"./chunk-U5XL7D6A.mjs";import{a as w,b as Zt,c as Yt}from"./chunk-HYMEEXKN.mjs";import{a as pt}from"./chunk-NOGQX56R.mjs";import{g as T,j as Kt,l as Gt,m as Jt}from"./chunk-TKWEX4FD.mjs";import{existsSync as bo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function Se(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(o=>{if(!o||!["added","removed","unchanged"].includes(o.type)||typeof o.content!="string"||/[\r\n]/.test(o.content))throw new Error("diff: each line needs a valid type and single-line content.");if(o.lineNumber!=null&&(!Number.isInteger(o.lineNumber)||o.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as kt,isInstance as Wo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Bo}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Ne,hasClass as Ho,walk as yt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Ko,CHART_KEY as Go,CHART_SOURCE as z,VIEW_FROM as tt,cellWords as Jo,rowsReading as ve,tableRows as Vo}from"../browser/shared/table-chart.mjs";var Zo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Oe=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Oe).join("");function Yo(t){let o=t;for(;o&&o.tagName!=="figure";)o=o.parentNode;let s=o?Ne(o).find(e=>/^h[2-4]$/.test(e.tagName)):null;return s?Jo(Oe(s)):""}function Ee(t,o,s=w(t)){let e=[];return yt(s,n=>{let i=o(n);if(i===void 0||!n.sourceCodeLocation)return;let a=n.childNodes.find(Zo);e.push({type:i,line:n.sourceCodeLocation.startLine,text:a?a.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Ko),tag:n.tagName,holder:n.parentNode?.tagName,title:Yo(n)})},kt),e}var qo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",et=(t,o)=>Ee(t,s=>qo(s)?void 0:F(s,"data-doc-chart"),o),Xo=t=>Ee(t,o=>Ho(o,"doc-diff")?"diff":void 0);function G(t){let o=new Map;return yt(t,s=>{let e=F(s,z);if(e===void 0||!s.sourceCodeLocation)return;(o.get(e)??o.set(e,[]).get(e)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Ne(s).find(i=>i.tagName==="table")??null})},{...kt,inTemplates:!1}),o}function xt(t,o){let s=o.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${z}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(s.length>1)return{error:`${s.length} tables carry ${z}="${t}" (lines ${s.map(({line:c})=>c).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:e,table:n}]=s;if(!n)return{error:`the frame carrying ${z}="${t}" (line ${e}) holds no table`};let i=$t(n),a=Vo(i);return a.error?{error:`its table (line ${e}) ${a.error}`}:{...a,line:e,cells:i}}function St(t){let o=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>Q(n,"kit.js")??"")].join(`
3
+ `),s=new Set([...o.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(n=>n[2])),e=new Set([...o.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(n=>n[2]).filter(n=>!s.has(n)));return{defined:s,misnamed:e}}function Qo(t,o){let s=(n,i)=>{let a=Array.from({length:i.length+1},(c,l)=>l);for(let c=1;c<=n.length;c++){let l=[c];for(let r=1;r<=i.length;r++)l[r]=Math.min(a[r]+1,l[r-1]+1,a[r-1]+(n[c-1]===i[r-1]?0:1));a=l}return a[i.length]},e=[...o].map(n=>({name:n,far:n.includes(t)||t.includes(n)?1:s(t,n)})).sort((n,i)=>n.far-i.far);return e[0]&&e[0].far<=Math.max(2,Math.floor(t.length/4))?e[0].name:null}function Nt(t){let o=w(t),s=[],{defined:e,misnamed:n}=St(t),i=null;for(let{type:a,line:c,text:l,source:r,tag:d,holder:f}of et(t,o)){let h=`data-doc-chart="${a}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${h} is on a table inside a <figure>: the chart's card is a figure of its own, so write the table outside it, its <caption> the chart's title`:`${h} is on a table the tools leave as written (inside a whole block, an element with a class of the document's own, a cell): a chart is drawn from a table outside one`);continue}if(n.has(a)){s.push(`${h}: the document's script defines "${a}" with DocCharts.define, which refuses that name: a chart type's name is lowercase letters, digits and hyphens, a letter first ("interval", "ci-plot"); rename it in both places`);continue}if(!e.has(a)){let u=Qo(a,e);s.push(u?`${h}: the document's script does not define "${a}", and defines "${u}": write the same name in both places`:`${h}: the document's script does not define "${a}": define it once in the document's <script> with DocCharts.define("${a}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(r!==void 0){if(l!==null){s.push(`${h}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let u=xt(r,i??=G(o));u.error&&s.push(`${h}: ${u.error}`);continue}if(l===null){s.push(`${h} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(u){s.push(`${h}: its data is not valid JSON (${u.message})`)}}s.push(...Le(o,i??=G(o)).failures);for(let{line:a,text:c}of Xo(t)){if(c===null)continue;let l=`.doc-diff (line ${a})`;try{Se(JSON.parse(c))}catch(r){s.push(`${l}: ${r instanceof SyntaxError?`its options are not valid JSON (${r.message})`:r.message}`)}}return s}function Te(t,{written:o=t}={}){let s=w(t),e=[],{defined:n}=St(t),i=null,a=null;for(let{type:c,line:l,text:r,source:d,title:f,tag:h}of et(t,s)){if(d===void 0||h==="table"||r!==null||!n.has(c))continue;let u=`data-doc-chart="${c}" (line ${l})`;if(!f){a??=new Set(o===t?[]:et(o).map(k=>k.source).filter(k=>k!==void 0));let b=o!==t&&!a.has(d);e.push(`${u}: this chart card has no title: ${b?"write a <caption> on its table (the one with data-doc-chart), which becomes the card's h3":"write an h3 in the card's figure, before the chart"}`)}let m=xt(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=ve(m.cells,m.data);p&&e.push(`${u}: its table's header (line ${m.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),g.length>0&&e.push(`${u}: its table's header (line ${m.line}) names ${g.map(b=>`"${b}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return e.push(...Le(s,i??=G(s)).notes),e}var bt=500;function Le(t,o){let s=[],e=[],n=null;return yt(t,i=>{let a=F(i,tt);if(a===void 0||!i.sourceCodeLocation)return;n??=T().packages;let c=F(i,Bo),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Wo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${tt}="${a}", which only a view of a table carries: an instance of a custom block (<div data-doc-component="<scope>/<name>">) whose block's needs hold "tables"; take it off`);if(!Go.test(a))return void s.push(`${l}: ${tt}="${a}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${z}`);let r=o.get(a)??[];if(r.length===0)return void s.push(`${l}: no table's frame carries ${z}="${a}", so the view has no table to read: put the table back, or delete the view`);if(r.length>1)return void s.push(`${l}: ${r.length} tables carry ${z}="${a}" (lines ${r.map(({line:g})=>g).join(", ")}): a key names one table (the view reads the first); take it off the copies`);let[{line:d,offset:f,table:h}]=r;if(!h)return void s.push(`${l}: the frame carrying ${z}="${a}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&e.push(`${l} stands before the table it reads (${z}="${a}", line ${d}): it works there, but each block's writing.md writes the table first and the view after it, as its example does: move the view below the table, unless the document is meant to open on it`);let u=n.get(c)?.needs;u&&!u.includes("tables")&&e.push(`${l} carries ${tt}="${a}", but its block's needs hold no "tables", so it reads no table: add "tables" to needs in its component.json, or take the key off`);let m=$t(h);m.merged&&e.push(`${l}: its table (line ${d}) has merged cells, which no view reads, so the view shows nothing of it: write each value in its own cell`);let p=m.names?m.rows.length:Math.max(0,m.rows.length-1);p>bt&&e.push(`${l}: its table (line ${d}) has ${p} rows: every view of a table reads it again as it is typed in, and past ${bt} rows that slows typing in it; split it, or keep what a view shows to ${bt} rows`)},kt),{failures:s,notes:e}}function Ae(t){let o=w(t),s=[],e=[],{defined:n}=St(t),i=null,a=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:r,source:d,tag:f}of et(t,o)){if(d===void 0||f==="table"||r!==null||!n.has(c))continue;let h=xt(d,i??=G(o));if(h.error)continue;let{rows:u,columns:m,foot:p,extra:g}=ve(h.cells,h.data),b=`data-doc-chart="${c}" (line ${l})`,k=[a(u,"row")];for(let{name:x,numbers:v,words:E,empty:H}of m){let R=v+E+H,Y=v===R&&R>0?"numbers":E===R&&R>0?"words":[v&&a(v,"number"),E&&`${E} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${Y}`),v>0&&E>0&&e.push(`${b}: its table's column "${x}" (line ${h.line}) reads as numbers in ${a(v,"row")} and as words in ${E}: write each of its cells as one number (an empty cell, "\u2014" or "n/a" for none: null in data), or, for a column of words, data-sort-type="text" on its header cell`)}p>0&&e.push(`${b}: its table's <tfoot> (line ${h.line}) holds ${a(p,"row")} the chart leaves out, and a table with a <tfoot> has no table tools in the preview: keep a total out of a table you chart and say it in the text`),g>0&&e.push(`${b}: ${a(g,"row")} of its table (line ${h.line}) ${g===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),s.push(`${c} (line ${l}) reads its table (line ${h.line}): ${k.join("; ")}`)}return{readings:s,notes:e}}import{BODY as Si,componentOf as Ni,matchesNode as ko}from"../browser/shared/components/index.mjs";import{FLOW as vi}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as yo,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Oi,ICON_COLORS as xo,glyphOf as Ei,glyphValue as Ti,iconKind as Pt,iconMarkup as Li,iconValueOf as Ai}from"../browser/shared/emoji/icon-value.mjs";import ts from"node:vm";import{LINE_START as nt,lineStart as es}from"../browser/shared/code-lines.mjs";import{BODY as De,COMPONENTS as os,FLOWS as ss,instanceSlots as ns,instancesOf as is,isInstance as D,isSlot as _e,matchesNode as P,ownSlots as as,partOf as Tt,vocabulary as rs}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as C,INSTANCE as cs,PACKAGE_ID as it,SCHEMA as vt,SLOT as I,schemaAhead as ls}from"../browser/shared/components/installed.mjs";import{packageScript as ds}from"../browser/shared/export-wrap.mjs";import{asDocName as fs,kitNamespace as hs}from"../browser/shared/old-names.mjs";import{shortSheets as us}from"../browser/shared/components/sheets.mjs";import{attr as y,curlyQuoted as ps,hasClass as ms,walk as J}from"../browser/shared/html-tree.mjs";var{authoring:st,runtime:Ce}=rs(),gs="input, select, textarea, button, details, table",at=t=>t.sourceCodeLocation?.startLine,$=t=>at(t)?` (line ${at(t)})`:"";function ze(t){let o=(e,n)=>{let i=Array.from({length:n.length+1},(a,c)=>c);for(let a=1;a<=e.length;a++){let c=i[0];i[0]=a;for(let l=1;l<=n.length;l++){let r=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(e[a-1]===n[l-1]?0:1)),c=r}}return i[n.length]},[s]=[...st.keys()].filter(e=>e.startsWith(t.slice(0,7))).map(e=>[e,o(t,e)]).sort((e,n)=>e[1]-n[1]);return s&&s[1]<=3?` (${s[0]}?)`:""}function $s(t,o,s){let{part:e,property:n,min:i}=t.shares,a=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>a.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let r=`${t.id}${$(o)}`;return l.length<c.length?[`${r}: ${n} on ${l.length} of its ${c.length} ${e}: write it on every one of them, or on none (equal widths)`]:l.map(Number).some(f=>!Number.isFinite(f)||f<i-1e-9||f>1)?[`${r}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var ot={"doc-dialog-header":'a detail card has no header: its content region (<div class="doc-dialog-content">) stands alone in its panel',"doc-dialog-title":"a detail card's title is an ordinary heading (<h3>), first in its content region","doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","data-doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","doc-section-header":"a section's title is a plain heading (<h2>) with an ordinary paragraph below it for the line that says what the section is: no <div> goes around them","doc-grid":'a card row is now columns: <div class="doc-columns"> holding one <div class="doc-column"> per card',"doc-grid-3":'a card row is now columns: <div class="doc-columns"> holding three <div class="doc-column">',"doc-lede":`write the line under the title as a paragraph of the header (an ordinary <p>), or as small text, <p class="doc-note"): the header's lines read as the body's paragraphs`,"doc-source":`write the line under the title as a plain paragraph of the header (an ordinary <p>), or as small text (<p class="doc-note">): the header's lines read as the body's paragraphs`,"doc-prose":"write the text straight in its flow (the page, a Sheet panel, a section, a panel, a column\u2026): it reads the same there","doc-prose-h1":"write an h1","doc-prose-h2":"write an h2","doc-prose-h3":"write an h3","doc-prose-h4":"write an h4","doc-state-grid":'put the groups side by side in columns (<div class="doc-columns">)',"doc-state-group":"write the group's title as a heading and its controls as blocks of their own in a column","doc-state-status":'write the line as small text, <p class="doc-note">',"doc-code-block":'a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre><code>',"doc-code-card":'a code block is <div class="doc-code"> holding its title and its <pre>; a diff is <div class="doc-diff">',"doc-code-header":'write the title as <div class="doc-code-title">: the kit draws the rest of the header',"data-doc-diff":'a diff is <div class="doc-diff"> holding its title and its options as JSON (sdk/doc-code.d.ts)',"data-doc-diff-stats":"the kit shows a diff's counts in its header: remove it","doc-code--wrap":"a code block wraps its long lines by itself: remove it (doc-code--nowrap scrolls them instead)"},ws={[nt]:'write it on its <div class="doc-code">',"data-start":`write ${nt} on its <div class="doc-code">`,"data-line-numbers":'write it on its <div class="doc-code">',"data-folded-lines":'write it on its <div class="doc-code">',"data-title":'write the title in its <div class="doc-code-title">',"data-wrap":'for long lines that scroll, write class="doc-code doc-code--nowrap" on its <div class="doc-code">'};function bs(t){let o=[],s=t.tagName==="pre"?t.parentNode:t.tagName==="code"&&t.parentNode?.tagName==="pre"?t.parentNode.parentNode:null;if(s?.tagName&&P(s,".doc-code"))for(let[n,i]of Object.entries(ws))y(t,n)!==void 0&&o.push(`${n}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let e=t.tagName==="div"&&P(t,".doc-code")?y(t,nt):void 0;return e!==void 0&&es(e)===null&&o.push(`${nt}="${e}"${$(t)}: the number of a code block's first line is a whole number from 1`),o}var Ie=ss.join(", "),ks=t=>P(t.parentNode,Ie)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Ie);function ys(t,o){let s=[];J(o,n=>s.push(...ps(t,n)));let e=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},a)=>a===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${e(n)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${n} uses curly quotes too: write ${e(n)}`)}var je={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},xs="write a <section> of no attribute straight in it for each tab, starting with its heading (<h2>\u2013<h4>), the tab's name, the rest its blocks, and nothing else: the export makes the kit's tabs",Ss='a bookmark written the short way is a paragraph in a flow holding only <a class="doc-bookmark" href="https://\u2026">its title</a> (a title attribute its description, nothing else on it, words alone in it): the export makes the card';function Me(t){let o=[];return J(t,s=>{y(s,C)!==void 0&&o.push(s)},De),o}var Ns=t=>{let o=t.parentNode;for(;o&&!(D(o)||_e(o));)o=o.parentNode;return o??null};function vs(t,o){let s=[];return J(t,e=>{let n=y(e,I);if(n===void 0)return;if(D(e))return void s.push(`${I}="${n}"${$(e)} on the instance itself: a slot is an element inside it`);if(!_e(e))return void s.push(`${I}${$(e)} on a <${e.tagName}>: a slot is a block-level <div> or <section>`);let i=Ns(e),a=i&&D(i)?o?.get(y(i,C)):null;if(!i||!D(i)||a&&Pe(i,a,e))return void s.push(`${I}="${n}"${$(e)} stands outside any instance's own markup: a slot is a part of a component package's instance, written in its template`);y(e,"data-block-id")!==void 0&&s.push(`${I}="${n}"${$(e)}: a slot is no block: it carries no data-block-id`)}),s}var Os=(t,o)=>{for(let s=o.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},Pe=(t,o,s)=>Object.values(o.parts??{}).filter(({edit:e})=>e==="text"||e==="data").some(({at:e})=>Tt(t,e).some(n=>Os(n,s))),Re=(t,o)=>as(t).filter(s=>!Pe(t,o,s)),Es=t=>t.flatMap(o=>D(o)?it.test(y(o,C))?[]:[`${C}="${y(o,C)}"${$(o)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${C}${$(o)} on a <${o.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Ue(t){let o=Me(t).filter(e=>D(e)&&it.test(y(e,C))),s=o.length>0?T():null;return o.flatMap(e=>{let n=y(e,C),i=s.packages.get(n);if(i&&!ls(y(e,vt),i.schema))return[];if(i)return[`line ${at(e)}: <${e.tagName} ${C}="${n}">: ${vt}="${y(e,vt)}" is past the ${i.schema??1} its package's manifest reads (schema): nothing can write it back, and the block shows read-only until the package reads it`];let a=s.problems.get(n)?.problem,c=a?`package ${n} does not load (${Kt("en",a)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${at(e)}: <${e.tagName} ${C}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Ot(t,o){let s=[];for(let{name:e,value:n}of t.attrs){if(ot[e]&&!st.has(e)){s.push(`${e}${$(t)} is gone: ${ot[e]}`);continue}if(e.startsWith("data-doc-")&&!st.has(e)&&s.push(Ce.has(e)?`${e}${$(t)} is the kit's to set: remove it`:`${e}${$(t)} is no attribute of the kit's${ze(e)}`),e==="class"){for(let i of n.split(/\s+/).filter(o))if(!st.has(i)){if(ot[i]){s.push(`class ${i}${$(t)} is gone: ${ot[i]}`);continue}s.push(Ce.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${ze(fs(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var Fe=t=>t.startsWith("doc-");function Ts(t){try{return new ts.Script(ds(t),{filename:"kit.js"}),null}catch(o){let s=/^kit\.js:(\d+)/.exec(o.stack??"")?.[1];return{message:o.message,line:s?Number(s):null}}}var Et=new Map;function Ls(t){if(!t.files.includes("kit.js"))return null;if(Et.get(t.folder)?.stamp!==t.stamp){let o=Q(t,"kit.js"),s=o===null?null:Ts(o),e=o===null?`${t.id}: its kit.js cannot be read`:s&&`${t.id}: its kit.js does not run: ${s.message}${s.line?` (line ${s.line})`:""}`;Et.set(t.folder,{stamp:t.stamp,failure:e})}return Et.get(t.folder).failure}function Lt(t,o=w(t),s=null){let e=ys(t,o),n=Me(o);e.push(...Es(n));let i=n.length>0?s??T():null,a=i?[...i.packages.values()]:[];i&&e.push(...L(t,i,o).map(Ls).filter(Boolean));for(let r of[...os,...a].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of is(o,r)){if(r.empty&&!(d.childNodes??[]).some(u=>u.tagName||u.nodeName==="#text"&&u.value.trim()))continue;let f=r.id==="sheets"?us(d):null;if(f){e.push(`${r.id}${$(d)} has no tabs and is no short form: ${f.why??"it stands where no block does (in a whole block or a figure)"}; ${xs}`);continue}if(je[r.id]&&Object.values(r.parts??{}).some(u=>Tt(d,u.at).length<(u.optional?0:u.min??1))){e.push(`${r.id}${$(d)} carries the kit's class without the kit's parts: ${je[r.id]}`);continue}let h={};for(let[u,m]of Object.entries(r.parts??{})){if(m.edit==="flow"&&it.test(r.id)){let b=Re(d,r).filter(k=>y(k,I)===u);b.length===0&&!m.optional&&e.push(`${r.id}${$(d)} has no ${u} (${I}="${u}")`);for(let k of b.slice(1))e.push(`${r.id}${$(k)}: slot "${u}" twice`);h[u]=b.slice(0,1);continue}h[u]=Tt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;h[u].length<p?e.push(`${r.id}${$(d)} has ${h[u].length===0?"no":`${h[u].length} of`} ${u} (${m.at.replace(":scope > ","")})${h[u].length>0?`, at least ${p}`:""}`):h[u].length>g&&e.push(`${r.id}${$(d)} has ${h[u].length} of ${u}, at most ${g}`)}if(r.only){let u=new Set(r.only.flatMap(m=>h[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!u.has(p)))e.push(`${r.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${r.only.join(", ")} (${r.only.map(p=>r.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(r.shares&&e.push(...$s(r,d,h[r.shares.part])),it.test(r.id)){let u=Object.entries(r.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of Re(d,r).filter(p=>!u.includes(y(p,I))))e.push(`${r.id}${$(m)}: slot "${y(m,I)}" is no part of its manifest edited as flow`)}for(let{a:u,attrA:m,b:p,attrB:g}of r.pairs??[]){let b=h[u].map(x=>y(x,m)),k=h[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,E)=>b.indexOf(v)!==E)))e.push(`${r.id}${$(d)}: ${u} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))e.push(`${r.id}${$(d)}: ${u.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))e.push(`${r.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${u.replace(/s$/,"")} (${m}="${x}")`)}}e.push(...vs(o,i?.packages));let c=new Set,l=[];J(o,r=>{if(D(r)){let h=new Set(ns(r));e.push(...Ot(r,Fe)),J(r,u=>e.push(...Ot(u,Fe)),{stop:u=>h.has(u)});return}r.tagName==="pre"&&ks(r)&&e.push(`<pre>${$(r)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),e.push(...bs(r)),r.tagName==="a"&&ms(r,"doc-bookmark")&&e.push(`<a class="doc-bookmark">${$(r)} is no bookmark: ${Ss}`),e.push(...Ot(r,hs));let d=y(r,"data-doc-bind");d!==void 0&&(d.trim()?P(r,gs)?r.tagName==="button"&&y(r,"value")===void 0?e.push(`data-doc-bind${$(r)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):e.push(`data-doc-bind${$(r)} on a ${r.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):e.push(`data-doc-bind${$(r)} names no key`));let f=y(r,"data-doc-show");f!==void 0&&l.push([r,f])},De);for(let[r,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?e.push(`data-doc-show="${d}"${$(r)}: write key:value`):c.has(f)||e.push(`data-doc-show="${d}"${$(r)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return e.push(...Rs(t,o)),e}var As=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,Cs=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,zs=t=>/[\\^]/.test(t)||!t.startsWith("{")&&Cs.test(t),Is=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),js=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${cs}`;function Rs(t,o){let s=[],e=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:a,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(a,c).matchAll(As)){if(!zs(l[1]))continue;let r=l[1].replace(/\s+/g," "),d=r.length>60?`${r.slice(0,59)}\u2026`:r;s.push(`line ${Yt(t,a+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!Is.has(i.tagName)&&!P(i,js)&&e(i)};return e(o),s}import V from"node:fs";import W from"node:path";import{COLOR_NAMES as Ks}from"../browser/shared/colors.mjs";import{FOLD_DOTS as Gs}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as Js,kitSourceDirectory as Vs,release as Zs}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Wa}from"../browser/shared/components/list.mjs";var Fs={"code-title":{zh:"\u4EE3\u7801\u5757",en:"Code"},"plain-text":{zh:"\u7EAF\u6587\u672C",en:"Plain text"},"fold-code":{zh:"\u6298\u53E0\u6216\u5C55\u5F00\u4EE3\u7801\u5757",en:"Collapse or expand the code block"},"copy-code":{zh:"\u590D\u5236\u4EE3\u7801",en:"Copy code"},copied:{zh:"\u5DF2\u590D\u5236",en:"Copied"},wrap:{zh:"\u81EA\u52A8\u6362\u884C",en:"Wrap lines"},"no-wrap":{zh:"\u53D6\u6D88\u81EA\u52A8\u6362\u884C",en:"Stop wrapping lines"},fold:{zh:"\u6298\u53E0",en:"Collapse"},unfold:{zh:"\u5C55\u5F00",en:"Expand"},line:{zh:"\u7B2C {0} \u884C",en:"Line {0}"},lines:{zh:"\u7B2C {0}\u2013{1} \u884C",en:"Lines {0}\u2013{1}"},"diff-counts":{zh:"\u65B0\u589E {0} \u884C\uFF0C\u5220\u9664 {1} \u884C",en:"Lines added: {0}, removed: {1}"}};var We="data-ge-language",Ds={"code-title":"--doc-word-code-title"};function _s(t,o,s,...e){let n=t[s];if(!n)throw new Error(`The kit has no word "${s}" here (src/render/kit/words.js).`);let i=n[o]??n.zh;return e.length===0?i:i.replace(/\{(\d+)\}/g,(a,c)=>c<e.length?String(e[c]):a)}var Ms=`:root[${We}="en"], :root:not([${We}])[lang|="en" i]`;function Be(){let t=o=>Object.entries(Ds).map(([s,e])=>`${e}: ${JSON.stringify(_s(Fs,o,s))};`).join(" ");return`:root { ${t("zh")} }
4
+ ${Ms} { ${t("en")} }`}import{LOOK as At,LOOK_ATTRIBUTES as Ps,SERIF_FONT as He,SIZE_FACTOR as Us,SPACING as Ws,WIDTH as Ct}from"../browser/shared/document-look.mjs";var Ke=[["--doc-body-font-size","--doc-body-line-height"],["--doc-small-font-size","--doc-small-line-height"],["--doc-note-font-size","--doc-note-line-height"],["--doc-title-font-size","--doc-title-line-height"],["--doc-h1-font-size","--doc-h1-line-height"],["--doc-h2-font-size","--doc-h2-line-height"],["--doc-h3-font-size","--doc-h3-line-height"],["--doc-h4-font-size","--doc-h4-line-height"],["--doc-card-title-font-size","--doc-card-title-line-height"],["--doc-table-font-size","--doc-table-line-height"]],Bs=["--doc-component-gap","--doc-block-gap","--doc-media-gap","--doc-paragraph-gap","--doc-group-gap","--doc-list-gap"],zt="--doc-content-max-width";function Hs(t){let o=new Map;for(let[,s,e]of String(t).matchAll(/^\s*(--doc-[a-z0-9-]+):\s*([^;]+);/gm))o.has(s)||o.set(s,e.trim());return o}var rt=t=>`${Math.round(t)}px`;function ct(t,{size:o="default",spacing:s="default",width:e="default"}={}){let n=r=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(r)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${r} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Us[o],{leading:a,gaps:c}=Ws[s],l={};if(o!=="default"||s!=="default")for(let[r,d]of Ke){let f=n(r)*i;o!=="default"&&(l[r]=rt(f)),l[d]=rt(Math.round(f)+(n(d)-n(r))*i*a)}if(s!=="default"){for(let r of Bs)l[r]=rt(n(r)*c);l["--doc-space"]=String(c)}if(e!=="default"){if(n(zt)!==Ct.default)throw new Error(`src/render/kit/styles/tokens.css: ${zt} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${Ct.default}px (src/shared/document-look.mjs WIDTH)`);l[zt]=rt(Ct[e])}return l}var U=(t,o)=>`${t} { ${Object.entries(o).map(([s,e])=>`${s}: ${e};`).join(" ")} }`,_=(t,o)=>`[${Ps[t]}="${o}"]`;function Ge(t){let o=Hs(t),s=o.get("--doc-font");if(!s)throw new Error("src/render/kit/styles/tokens.css: no --doc-font (src/render/look-css.mjs keeps it as --doc-sans-font)");let e=[U(`:root${_("font","serif")}`,{"--doc-sans-font":s,"--doc-font":He}),U(`:root${_("font","mixed")}`,{"--doc-heading-font":He})],[,...n]=At.size,[,...i]=At.spacing,[,...a]=At.width;for(let c of n)e.push(U(`:root${_("size",c)}`,ct(o,{size:c})));for(let c of i)e.push(U(`:root${_("spacing",c)}`,ct(o,{spacing:c})));for(let c of a)e.push(U(`:root${_("width",c)}`,ct(o,{width:c})));for(let c of n)for(let l of i){let r=ct(o,{size:c,spacing:l});e.push(U(`:root${_("size",c)}${_("spacing",l)}`,Object.fromEntries(Ke.map(([,d])=>[d,r[d]]))))}return e.join(`
5
+ `)}var Je=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),er=Object.keys(Je),Z=t=>W.join(Vs,t),Ys=(t,o,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof o=="function"?o():o,...s}),qs=t=>{let o=Je[t];if(!o)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return o},lt=new Map;function Xs(t,o){let s=[...o.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),e=V.readdirSync(W.dirname(Z(t))).filter(i=>i.endsWith(".css")&&i!==W.basename(t)),n=[...e.filter(i=>!s.includes(i)).map(i=>`${i} is not listed`),...s.filter((i,a)=>!e.includes(i)||s.indexOf(i)!==a).map(i=>`${i} is listed but missing, or listed twice`)];if(n.length>0)throw new Error(`src/render/kit/${t}: ${n.join("; ")}`);return s.map(i=>W.join(W.dirname(t),i))}var Qs=t=>t.replace(/@(text|highlight)-colors\b/g,(o,s)=>Ks.map(e=>`.doc-${s}-${e}`).join(", ")),tn=t=>{let o=Qs(t.join(`
6
+ `)).replaceAll("@fold-dots",Gs).replace(/^@kit-words;$/m,()=>Be());return o.replace(/^@kit-look;$/m,()=>Ge(o))};function It(t,{fresh:o=!1}={}){let s=qs(t);if(Zs)return V.promises.readFile(W.join(Js,t),"utf8");if(s.read)return V.promises.readFile(Z(s.read),"utf8");if(s.styles)return V.promises.readFile(Z(s.styles),"utf8").then(e=>Promise.all(Xs(s.styles,e).map(n=>V.promises.readFile(Z(n),"utf8")))).then(tn);if(o||!lt.has(t)){let e=Vt(Ys(s.bundle,s.options)).then(n=>n.outputFiles[0].text);e.catch(()=>lt.delete(t)),lt.set(t,e)}return lt.get(t)}import{kitNamespace as en}from"../browser/shared/old-names.mjs";import{attr as jt,hasClass as ft}from"../browser/shared/html-tree.mjs";var Ve=t=>t.tagName==="section"&&ft(t,"doc-section"),on=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),sn=t=>!on.has(t.tagName),dt=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(dt).join("");function Ye(t,o=[]){for(let s of t.childNodes??[])s.tagName&&((s.tagName==="main"&&ft(s,"doc-page")||jt(s,"data-doc-sheet")!==void 0)&&o.push(s),Ye(s.tagName==="template"?s.content:s,o));return o}var nn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,qe=["doc-summary","doc-panel","doc-note","doc-callout"],an=t=>nn.test(t.tagName)||qe.some(o=>ft(t,o)),rn=new Set(["none","auto","100%","inherit","initial","unset","revert"]),Ze=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,o])=>!rn.has(o.replace(/!important/i,"").trim().toLowerCase())),cn=t=>{let o=t.trim().split(/\s*[\s>+~]\s*/).at(-1)??"",s=/^(p|li|h[1-4]|blockquote|ul|ol)\b/.test(o)||qe.some(n=>o.includes(`.${n}`)),e=[...t.matchAll(/\.([\w-]+)/g)].some(([,n])=>!en(n))||t.includes("#");return s&&!e};function ln(t){let o=[],s=(e,n)=>{for(let i of e.childNodes??[]){if(!i.tagName)continue;let a=n||i.tagName==="main"&&ft(i,"doc-page");if(a&&an(i)&&Ze(jt(i,"style")??"")&&o.push(`<${i.tagName}> with style="${jt(i,"style").trim()}"`),i.tagName==="style"){let c=dt(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,r]of c.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(Ze(r))for(let d of l.split(","))cn(d)&&o.push(`"${d.trim()}" in the document's style`)}s(i.tagName==="template"?i.content:i,a)}};return s(t,!1),o}function Xe(t,{written:o=t}={}){let s=[],e=w(t),n=ln(e);n.length>0&&s.push(`body text given a width of its own (${n.slice(0,3).join("; ")}${n.length>3?`; ${n.length-3} more`:""}): its lines break before the reading column's edge, leaving an extra right margin; let body text fill the column`);for(let i of Ye(e)){let a=i.childNodes.filter(c=>c.tagName);a.forEach((c,l)=>{if(!Ve(c))return;let r=l+1;for(;r<a.length&&sn(a[r]);)r++;let d=a.slice(l+1,r);if(d.length===0||!Ve(a[r]??{})||/^h[1-4]$/.test(d[0].tagName))return;let f=c.childNodes.map(g=>g.tagName?g:null).filter(Boolean).map(dt).find(g=>g.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"",[h]=d,u=dt(h).replace(/\s+/g," ").trim(),m=`<${h.tagName}>${u?` "${u.length>30?`${u.slice(0,30)}\u2026`:u}"`:""}`,p=h.sourceCodeLocation?.startLine;s.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${f}" stand outside it${p?` (line ${p})`:""}, ${d.length===1?`the ${m}`:`the first a ${m}`}, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return s.push(...Te(t,{written:o})),s}import{attr as Qe,hasClass as dn}from"../browser/shared/html-tree.mjs";var to="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",fn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),hn=["doc-math-inline","doc-math-block"],un=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,pn=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,mn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,gn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,so=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,$n=/\.[A-Za-z0-9]{1,8}$/,wn=[/(?<![A-Za-z0-9_\\])[A-Za-z]:[\\/]/g,/(?<![A-Za-z0-9_.~:/\\-])\/(?:Users|home|root|tmp|private|mnt|opt|Volumes|var\/folders)\/(?=\S)/g,/(?<![A-Za-z0-9_.~:/\\-])~\/(?=\S)/g,/(?<![A-Za-z0-9_$\\])\$(?:HOME|\{HOME\})\/(?=\S)/g,/(?<![A-Za-z0-9_:\\])\\\\[A-Za-z0-9][\w.$-]*\\(?=[^\s\\])/g,/%(?:TEMP|TMP|APPDATA|LOCALAPPDATA|USERPROFILE)%/gi],bn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,kn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,yn=t=>t.includes("://")&&!/^file:/i.test(t),eo=12;function oo(t,o){let s=o;for(;s<t.length&&!mn.test(t[s])&&!(so.test(t[s])&&$n.test(t.slice(o,s)));)s++;return t.slice(o,s).replace(/[.,;:!?]+$/,"")}function xn(t,o=!1){let s=c=>c.replace(/[^\n]/g," "),e=t.replace(un,s),n=o?e.replace(pn,s):e,i=[],a=(c,l)=>i.some(r=>r.at<=c+l.length&&c<=r.at+r.path.length);for(let c of wn)for(let l of n.matchAll(c)){let r=oo(n,l.index);r.length>=l[0].length+2&&!a(l.index,r)&&i.push({at:l.index,path:r})}for(let c of n.matchAll(gn)){let l=c.index;for(;l<c.index+c[0].length&&so.test(n[l]);)l++;let r=oo(n,l);/[\\/]/.test(r)&&(bn.test(r)||kn.test(r))&&!yn(r)&&!a(l,r)&&i.push({at:l,path:r})}return i.sort((c,l)=>c.at-l.at)}function no(t,o=w(t)){let s=[],e=(a,c)=>{for(let l of a.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:r,path:d}of xn(l.value,c))s.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,r).match(/\n/g)?.length??0),path:d})}else l.tagName&&!fn.has(l.tagName)&&Qe(l,"hidden")===void 0&&!hn.some(r=>dn(l,r))&&e(l,c||Qe(l,"data-doc-math-dollar")!==void 0)};e(o,!1);let n=s.slice(0,eo).map(({line:a,path:c})=>`line ${a}: "${c.length>80?`${c.slice(0,77)}\u2026`:c}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${to}`),i=s.slice(eo);return i.length>0&&n.push(`${i.length} more path${i.length===1?"":"s"} of this machine in the text a reader reads, on line${new Set(i.map(({line:a})=>a)).size===1?"":"s"} ${[...new Set(i.map(({line:a})=>a))].join(", ")}. ${to}`),n}import{elementsOf as io}from"../browser/shared/html-tree.mjs";import{netSnapshot as Sn}from"../browser/shared/net-cache.mjs";import{hostIn as Nn,netHostsOf as vn}from"../browser/shared/net-policy.mjs";var On=(t,o)=>`<script type="application/json" data-doc-snapshot data-at="${o}">${JSON.stringify(t).replace(/</g,"\\u003c")}</script>`,Rt=t=>t.some(({needs:o})=>Array.isArray(o)&&o.includes("workspace"));function ao(t,{slug:o,packages:s,root:e,at:n=new Date,workspace:i=null}){let a=s.flatMap(({needs:f})=>vn(f)),c=a.length===0?null:Sn(e,o,f=>{try{return Nn(new URL(f).hostname,a)!==null}catch{return!1}}),l={...i&&Rt(s)?i:{},...c?{net:c}:{}};if(Object.keys(l).length===0)return t;let r=io(io(w(t)).find(f=>f.tagName==="html")??{}).find(f=>f.tagName==="head"),d=r?.sourceCodeLocation?.endTag?.startOffset??r?.sourceCodeLocation?.startTag?.endOffset;return d===void 0?t:`${t.slice(0,d)} ${On(l,n.toISOString())}
7
+ ${t.slice(d)}`}import{MENTION as En,MENTION_ICON as Tn}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Ln}from"../browser/shared/escape.mjs";import{attr as ro,elementsOf as An,hasClass as co,walk as Cn}from"../browser/shared/html-tree.mjs";import{addressOn as zn,decoded as In,fromFile as jn,hosted as Rn,pageAddress as Fn,workbenchHash as Dn}from"../browser/shared/page-address.mjs";function _n(t,o,s){let e=jn(t,o),n=zn(e,s);return n||Rn(t)?n:Fn(e)??(Dn(e)===null?null:{slug:null,block:null})}function Mn(t,o,s,e){let n=w(t),i=new Set,a=[];Cn(n,r=>{let d=ro(r,"data-block-id");d!==void 0&&i.add(d),r.tagName==="a"&&ro(r,"href")!==void 0&&r.sourceCodeLocation?.startTag&&a.push(r)});let c=new Map,l=({startOffset:r,endOffset:d})=>c.set(r,[d,""]);for(let r of a){let{prefix:d,value:f}=r.attrs.find(({name:k})=>k==="href"),h=f.startsWith("#")?In(f.slice(1)):null,u=h===null?f&&_n(f,o,e):i.has(h)?{slug:o,block:h}:null;if(!u)continue;let m=s(u,f);if(m===f)continue;let{attrs:p,startTag:g,endTag:b}=r.sourceCodeLocation;if(m===null)l(g),b&&l(b),co(r,En)&&An(r).filter(k=>co(k,Tn)).forEach(k=>l(k.sourceCodeLocation));else{let k=d?`${d}:href`:"href";c.set(p[k].startOffset,[p[k].endOffset,`${k}="${Ln(m)}"`])}}return[...c].sort(([r],[d])=>d-r).reduce((r,[d,[f,h]])=>`${r.slice(0,d)}${h}${r.slice(f)}`,t)}function lo(t,o,s,{blocks:e=!0,links:n}){return Mn(t,o,({slug:i,block:a})=>{let c=s(i);if(c===null)return null;if(!a||!e)return i===o&&a?null:c;let l=`#${encodeURIComponent(a)}`;return i===o?l:`${c}${l}`},n)}import ht from"node:fs";import Pn from"node:path";import{extensionOf as Un,imageFile as Wn,mediaTypeOf as Bn}from"../browser/shared/media.mjs";var _t=1024*1024,Hn=_t,ho=2400,Ft=2e3,Kn=.25,Gn=new Set(["png","gif"]),fo=.75;function Jn(t){if(t.length<16||t.toString("latin1",0,4)!=="RIFF"||t.toString("latin1",8,12)!=="WEBP")return!1;for(let o=12;o+8<=t.length;){let s=t.toString("latin1",o,o+4);if(s==="VP8L")return!0;if(s==="VP8 "||s==="ANMF")return!1;let e=t.readUInt32LE(o+4);o+=8+e+e%2}return!1}function Vn(t){let o=(s,e)=>s+e<=t.length;if(o(0,24)&&t.readUInt32BE(0)===2303741511&&t.toString("latin1",12,16)==="IHDR")return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(o(0,10)&&/^GIF8[79]a$/.test(t.toString("latin1",0,6)))return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(o(0,4)&&t[0]===255&&t[1]===216){for(let s=2;o(s,4);){if(t[s]!==255)return null;let e=t[s+1];if(e===255){s+=1;continue}if(e===216||e===1||e>=208&&e<=215){s+=2;continue}if(e>=192&&e<=207&&![196,200,204].includes(e))return o(s,9)?{width:t.readUInt16BE(s+7),height:t.readUInt16BE(s+5)}:null;if(e===217||e===218)return null;s+=2+t.readUInt16BE(s+2)}return null}if(o(0,30)&&t.toString("latin1",0,4)==="RIFF"&&t.toString("latin1",8,12)==="WEBP"){let s=t.toString("latin1",12,16);if(s==="VP8 ")return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383};if(s==="VP8L"){let e=t.readUInt32LE(21);return{width:(e&16383)+1,height:(e>>>14&16383)+1}}return s==="VP8X"?{width:t.readUIntLE(24,3)+1,height:t.readUIntLE(27,3)+1}:null}if(o(0,12)&&t.toString("latin1",4,8)==="ftyp"&&/avi[fs]/.test(t.toString("latin1",8,Math.min(t.length,t.readUInt32BE(0))))){let s=null;for(let e=t.indexOf("ispe",0,"latin1");e>=0&&o(e,16);e=t.indexOf("ispe",e+4,"latin1")){let n={width:t.readUInt32BE(e+8),height:t.readUInt32BE(e+12)};(!s||n.width*n.height>s.width*s.height)&&(s=n)}return s}return null}var Zn=_t;function Yn(t){let o;try{o=ht.openSync(t,"r");let{size:s}=ht.fstatSync(o),e=Buffer.alloc(Math.min(s,Zn));return ht.readSync(o,e,0,e.length,0),{length:s,head:e}}catch{return null}finally{o!==void 0&&ht.closeSync(o)}}var j=t=>`${Math.max(.1,t/_t).toFixed(1)} MB`;function qn({bytes:t,width:o,height:s,extension:e,lossless:n}){let i=Math.max(o,s),a=Math.min(1,Ft/i),c=Math.min(t,o*s*a*a*Kn);if(i>ho){if(!n)return c<=t*fo?` \u2014 a ${Ft}px copy would be about ${j(c)}`:"";let l=t*a*a;return` \u2014 a ${Ft}px copy would be about ${j(l)}${e==="png"&&c<l/2?`, or ${j(c)} as a JPEG (for a photograph)`:""}`}return!n&&c<=t*fo?` \u2014 written again as a JPEG of quality about 82, it would be about ${j(c)}`:e==="png"&&c<t/2?` \u2014 as a JPEG (for a photograph) it would be about ${j(c)}`:""}var Dt=t=>t===2?"twice":`${t} times`;function uo({html:t,directory:o,tree:s=w(t)}){let{embedded:e,unserved:n}=ge({html:t,directory:o,tree:s}),i=new Map,a=(l,r,d,f=!1)=>{let h=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);h.at.push(r),f||(h.shows+=1)};for(let{file:l,line:r,icon:d}of e)Wn(l)&&a(l,r,!0,d);for(let{file:l,line:r}of n)Bn(l).startsWith("image/")&&a(l,r,!1);let c=[];for(let[l,{at:r,shows:d,served:f}]of[...i].sort(([,h],[,u])=>Math.min(...h.at)-Math.min(...u.at))){let h=Yn(Pn.join(o,l));if(!h)continue;let{length:u,head:m}=h,p=Vn(m),g=p?Math.max(p.width,p.height):0,b=u>Hn||g>ho,k=f&&d>1;if(!b&&!k)continue;let x=[...new Set(r)],v=`line${x.length===1?"":"s"} ${x.length>1?`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`:x[0]}`,E=k?`shown ${Dt(d)}: the export embeds it ${Dt(d)}; show it once and refer back to it in words`:"";if(!b){c.push(`${l} (${v}): ${E} (${j(Math.ceil(u/3)*4*d)} as data: URLs)`);continue}let H=r.length===1||!f?"":`, ${Dt(r.length)}`,R=f?r.length:1,Y=`${j(Math.ceil(u/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,Po=p?`, ${p.width}\xD7${p.height}px`:"",Bt=Un(l),Ht=p?qn({bytes:u,...p,extension:Bt,lossless:Gn.has(Bt)||Jn(m)}):"",Uo=f?`the export embeds it as it is${H}, ${Y}${Ht}`:`its name keeps it out of the preview and the export (the failure at its line says why); copied into assets/ under a name they take, the export embeds it as it is, ${Y}${Ht}: copy it in at the size the page needs`;c.push(`${l} (${v}): ${j(u)}${Po}; ${Uo}${E?`; ${E}`:""}`)}return c}import{COMPONENTS as ui}from"../browser/shared/components/index.mjs";import{withLook as pi}from"../browser/shared/document-look.mjs";import{reportsDirectory as mi}from"../browser/shared/paths.mjs";import{documentLook as gi}from"../browser/shared/workspace-look.mjs";import po from"node:fs";import{MENTION as mo,MENTION_ICON as go}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Xn,escapeText as Qn}from"../browser/shared/escape.mjs";import{iconUrl as ti,validIcon as ei}from"../browser/shared/emoji/icon-value.mjs";import{attr as oi,hasClass as si,walk as ni}from"../browser/shared/html-tree.mjs";import{fromFile as ii,isFileLink as ai,pageAddress as ri}from"../browser/shared/page-address.mjs";import{reportsDirectory as ci}from"../browser/shared/paths.mjs";import{documentDirectory as li,documentFiles as di}from"../browser/shared/workspace.mjs";function fi(t,o){let{html:s,json:e}=di(li(t,o));if(!po.existsSync(s))return null;try{let{title:n,icon:i}=JSON.parse(po.readFileSync(e,"utf8"));return{title:n,icon:i}}catch{return{}}}function hi(t,o,s,e){if(s==="words"||typeof t!="string"||!ei(t))return null;if(s==="preview")return ti(t,o,{tab:!0});let n=ae({value:t,slug:o,tab:!0,reportsDirectory:e});return n&&`data:${n.type};base64,${n.body.toString("base64")}`}function $o(t,{slug:o,mode:s="export",reportsDirectory:e=ci}){if(!t.includes(mo))return t;let n=new Map,i=c=>(n.has(c)||n.set(c,fi(c,e)),n.get(c)),a=new Map;return ni(w(t),c=>{let l=c.tagName==="a"&&si(c,mo)?oi(c,"href"):void 0,{startTag:r,endTag:d}=c.sourceCodeLocation??{};if(!l||!ai(l)||!r||!d)return;let f=ri(ii(l,o))?.slug;if(!f)return;let h=i(f);if(!h)a.set(r.endOffset-1,[r.endOffset-1," data-doc-gone"]);else if(h.title){let u=hi(h.icon,f,s,e);a.set(r.endOffset,[d.startOffset,`${u?`<img class="${go}" src="${Xn(u)}" alt="">`:`<span class="${go}"></span>`}${Qn(h.title)}`])}}),[...a].sort(([c],[l])=>l-c).reduce((c,[l,[r,d]])=>`${c.slice(0,l)}${d}${c.slice(r)}`,t)}var $i=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function wi(t,o,s){let e=Gt(o).filter(({id:n})=>!s.some(i=>i.id===n)).map(Jt).join(" ");return e?t.replace($i,n=>`${n}
8
+ <script data-doc-dev>${e}</script>`):t}var wo=/(<title\b[^>]*>)\s*(<\/title>)/i;function bi(t){if(!wo.test(t))return t;let o=/^en\b/i.test(/<html\b[^>]*\slang=["']?([^"'\s>]*)/i.exec(t)?.[1]??"");return t.replace(wo,(s,e,n)=>`${e}${o?"Untitled":"\u672A\u547D\u540D\u6587\u6863"}${n}`)}function Mt(t,{slug:o,mode:s="export",files:e=!0,reportsDirectory:n,kit:i,catalog:a}){let{html:c,removed:l}=ki(t,{reportsDirectory:n,kit:i,catalog:a,describe:s==="preview"}),r={slug:o,mode:s,...n?{reportsDirectory:n}:{}},d=re(pi(c,gi(o,n??mi)),r),f=e?$e(le(fe(ue(d,r),r),r),r):d;return{html:bi($o(f,r)),removed:l}}function ki(t,{reportsDirectory:o,kit:s,page:e=!1,describe:n=!1,catalog:i=null}){let a=L(t,i),{html:c,removed:l,used:r}=Xt(t,[...ui,...a]),d=ke(Qt(c,{used:r,page:e,...s?{href:s}:{}}),a);return{html:n?wi(d,i??T(),a):d,removed:l,packages:a}}import{exportsDirectory as Ci,kitPublicDirectory as zi,release as Ii,reportsDirectory as A,vendorDirectory as ji}from"../browser/shared/paths.mjs";import{referencedFile as Ri}from"../browser/shared/media.mjs";import{decoded as Fi,fromFile as Di,hashAddress as _i,hosted as Lo,pageAddress as Mi,workbenchHash as Pi}from"../browser/shared/page-address.mjs";import{pageLinks as Ui}from"../browser/shared/page-links.mjs";import{layoutOf as Ao}from"../browser/shared/workspace.mjs";import{documentLinks as Wi,listReportSlugs as Bi}from"../browser/shared/reports.mjs";import{documentDirectory as B,documentFiles as Wt}from"../browser/shared/workspace.mjs";import{sha256 as ut}from"../browser/shared/files.mjs";import{EXPORT_CSP as Hi,GENERATOR as Ki,isolateUmd as Gi,packagesMeta as Ji,sourceMeta as Vi}from"../browser/shared/export-wrap.mjs";var So=/__REPORT_[A-Z_]+__/,No=1e6,vo=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function Zi(t){return t.map(({id:o,lines:s,columns:e})=>{let n=new Set(s).size<s.length,i=s.map((a,c)=>n?`${a}:${e[c]}`:`${a}`);return`data-block-id repeats: "${o}" on lines ${vo(i)}${n?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${vo(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var Yi=({slug:t,htmlPath:o,metadataPath:s})=>{let e=o?{html:o,json:s??o.replace(/\.html$/,".json")}:Wt(B(t,A));return{htmlName:N.basename(e.html),jsonName:N.basename(e.json)}};function qi({slug:t,html:o,metadata:s,htmlPath:e,metadataPath:n,tree:i=w(o)}){let a=[],{htmlName:c,jsonName:l}=Yi({slug:t,htmlPath:e,metadataPath:n}),r=/<h1\b[^>]*\bclass="[^"]*\bdoc-title\b[^"]*"[^>]*>\s*<\/h1>/i.test(o),d=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[r?/<title>\s*<\/title>|<title>[^<]+<\/title>/i:/<title>[^<]+<\/title>/i,"missing document title"],[/<main(?:\s|>)/i,"missing semantic main element"],[/aria-label|aria-labelledby|<title>/i,"missing accessible labels"]];for(let[p,g]of d)p.test(o)||a.push(g);let f=Buffer.byteLength(o);f>No&&a.push(`the document's editable source is ${f.toLocaleString("en-US")} bytes, over the ${No.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),So.test(o)&&a.push(`${c} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,g]of Object.entries(s))typeof g=="string"&&So.test(g)&&a.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(o)&&a.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let h=new Map;M(i,p=>{let g=O(p,"data-block-id"),b=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;g!==void 0&&h.set(g,[...h.get(g)??[],{line:b?.startLine,column:b?.startCol}])});let u=[...h].filter(([,p])=>p.length>1);a.push(...Zi(u.map(([p,g])=>({id:p,lines:g.map(({line:b})=>b),columns:g.map(({column:b})=>b)}))));let m=null;if(M(i,p=>{!m&&p.tagName==="main"&&(m=p)},{inTemplates:!1}),m){let p=O(m,"data-doc-id");p===void 0?a.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&a.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return a}var Co=t=>yo(yo(t).find(o=>o.tagName==="html")??{}).find(o=>o.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Ut=new Set(["localStorage","sessionStorage"]);function zo(t){let o=[],s=[];return M(t,e=>{e.tagName==="script"&&O(e,"src")!==void 0&&o.push(O(e,"src")),(e.tagName==="link"?(O(e,"rel")??"").toLowerCase().split(/\s+/):[]).includes("stylesheet")&&O(e,"href")!==void 0&&s.push(O(e,"href"))}),{scripts:o,styles:s}}function Io({slug:t,html:o,directory:s=B(t,A),tree:e=w(o),uses:n=X(o,q,{tree:e}),catalog:i}){let a=[];Co(e)===void 0&&a.push("the page writes no <head> start tag, which an export puts its Content-Security-Policy right after: write <head> \u2026 </head> before <body>");let c=[];M(e,d=>{if(["script","link","img"].includes(d.tagName))for(let f of["src","href"]){let h=O(d,f)?.trim();h&&/^https?:\/\//i.test(h)&&c.push(h)}}),c.length>0&&a.push(`external resources are not portable: ${c.join(", ")}`);for(let{name:d,how:f,line:h,where:u}of n){if(!q.has(d))continue;let m={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[f]??`uses ${d}`;a.push(`line ${h}: ${u} ${m}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:r}=zo(e);for(let d of l)se.has(d)||a.push(`unsupported script dependency ${d}`);for(let d of r)ne.has(d)||a.push(`unsupported stylesheet dependency ${d}`);return a.push(...pe({html:o,directory:s,tree:e}),...he({html:o,directory:s,tree:e}),...de({html:o,directory:s,tree:e}),...me({html:o,directory:s,tree:e})),a.push(...ye(L(o,i,e))),[...new Set(a)]}var Xi=[[/\bDocSheets\.mount\s*\(/,"Sheet areas start on their own: remove DocSheets.mount (an area keeps its tab under its data-doc-sheets name)"],[/\bDocCode\.(?:View|DiffView|DiffStats|enhance)\b/,'code blocks are highlighted on their own, and a diff is declared as <div class="doc-diff"> holding { path, lines } as JSON (sdk/doc-code.d.ts)'],[/\bDocTables\.(?:enhance|enhanceAll|makeSortable)\b/,"tables start on their own: remove the call"],[/\bDocDialogs\.(?:enhance|enhanceAll)\b/,"detail cards start on their own: remove the call"]];function Qi({html:t,tree:o=w(t),uses:s=X(t,Ut,{tree:o})}){let e=we(t,o),n=[...te(t,o),...ee(t,o)];for(let[i,a]of Xi)i.test(e)&&n.push(`${e.match(i)[0].replace(/\s*\($/,"")} is gone: ${a}`);for(let{name:i,line:a,where:c}of s)Ut.has(i)&&n.push(`line ${a}: ${c} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(n)]}var ta=(t,o)=>o.childNodes.find(s=>s.tagName||s.nodeName==="#text"&&s.value.trim())===t,ea=t=>ko(t,Ni("highlight").match)||t.tagName==="li"&&ko(t.parentNode,`ol.${vi}`),oa=`an icon is one of three kinds: an emoji, <div class="doc-icon">\u{1F3AF}</div>; an icon of Gallery's sets in one of ${xo.length} colors, <div class="doc-icon" data-icon="/icons/airplane_blue.svg"></div> (MingCute's names; Tabler's as /icons/tabler/plane_blue.svg; the colors ${xo.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,jo=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(jo).join("");function Oo(t,o,s){let e=o.sourceCodeLocation?.attrs?.[s],n=e?t.slice(e.startOffset,e.endOffset):`${s}="${O(o,s)??""}"`;return n.length>72?`${n.slice(0,71)}\u2026`:n}function sa(t,o){let s=O(o,"data-icon");if(s!==void 0)return{held:Oo(t,o,"data-icon"),meant:Pt(s)==="glyph"?s:null};let e=null;if(M(o,i=>{e??=["img","svg"].includes(i.tagName)?i:null}),e?.tagName==="img"){let i=O(e,"src");return{held:`<img ${Oo(t,e,"src")}>`,meant:Pt(i)==="image"?i:null}}if(e)return{held:"an <svg>"};let n=jo(o).replace(/\s+/g," ").trim();return{held:n?`"${n.slice(0,40)}"`:"nothing"}}function na({set:t,name:o,color:s}){let e=Oi.find(a=>a!==t);if(wt(e).includes(o))return`; "${o}" is ${e==="tabler"?"Tabler":"MingCute"}'s: ${Ti(e,o,s)}`;let n=o.split("-").filter(a=>a.length>=3),i=wt(t).filter(a=>a.split("-").some(c=>n.includes(c))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function ia({html:t,tree:o=w(t)}){let{all:s,own:e}=ce(o),n=[],i=a=>a.sourceCodeLocation?.startLine;e.length>1&&n.push(`line ${i(e[1])}: ${e.length} page icons (.doc-icon) in the header (the first at line ${i(e[0])}): a document has one, right before its title`);for(let a of s){let c=i(a),l=a.parentNode;!e.includes(a)&&!(ea(l)&&ta(a,l))&&n.push(`line ${c}: an icon (.doc-icon) stands only right before the document's title, first in a highlight block (.doc-panel, .doc-summary), or first in a flowchart's step (ol.doc-flow > li, in its number's place)`);let r=Ai(Zt(t,a)),{held:d,meant:f}=r?{}:sa(t,a);f?n.push(`line ${c}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Li(f)}`):r?Pt(r)==="glyph"&&!ie(r)&&n.push(`line ${c}: the icon ${r} is none of the icon sets' (MingCute: /icons/<name>_<color>.svg, Tabler: /icons/tabler/<name>_<color>.svg; src/shared/emoji/data/icons.json lists the names of each)${na(Ei(r))}`):n.push(`line ${c}: an icon (.doc-icon) holds no icon (it holds ${d}): ${oa}`)}return[...new Set(n)]}function Ro(t){let o=w(t.html),s={...t,tree:o,uses:X(t.html,new Set([...q,...Ut]),{tree:o})};return[...qi(s),...Lt(t.html,o),...Qi(s),...ia(s),...Io(s)]}function aa(t){let o=new Map(t.map(n=>[n.slug,[...Ro(n),...Nt(n.html)]])),s=new Map(t.map(n=>[N.resolve(n.htmlPath),n.slug])),e=new Map(t.map(n=>[N.resolve(n.htmlPath),n]));for(let n of t)n.scriptNotes=[];if(t.length>0)for(let{htmlPath:n,text:i,typeOnly:a,note:c}of be(t)){if(a){e.get(n)?.scriptNotes.push(c);continue}let l=n?[s.get(n)]:[...o.keys()];for(let r of l)o.get(r).push(n?i:`${i} (shared SDK declaration)`)}for(let[n,i]of o)i.length===0&&o.delete(n);return o}async function Fc(t=[],{prepare:o=null}={}){let{reports:s,failures:e}=await pt(t,{prepare:o});for(let n of s){let i=[...Ro(n),...Nt(n.html)];i.length&&e.set(n.slug,i)}return e}async function ra(t=[],{prepare:o=null,directory:s=A}={}){let{reports:e,failures:n}=await pt(t,{prepare:o,directory:s});for(let[i,a]of aa(e))n.set(i,a);return{reports:e,failures:n}}async function ca({fresh:t=!1,kit:o=zi,vendor:s=ji}={}){if(Ii)return;let e=K.map(a=>[a,a.file?It(a.file,{fresh:t}):gt(a)]);await S.mkdir(o,{recursive:!0});let n=N.join(s,"katex","fonts");await S.mkdir(n,{recursive:!0});let i=(await S.readdir(mt)).filter(a=>a.endsWith(".woff2"));await Promise.all(i.map(a=>S.copyFile(N.join(mt,a),N.join(n,a)))),await Promise.all(e.map(async([a,c])=>S.writeFile(a.file?N.join(o,a.file):N.join(s,...a.vendor.path.split("/").slice(2)),await c)))}async function la(t,o){let s=await S.readdir(t).catch(()=>[]);await Promise.all(s.filter(e=>e.endsWith(".html")&&!o.has(e.slice(0,-5))).map(e=>S.rm(N.join(t,e),{force:!0})))}async function da(t,o){let s=N.join(o,"reports.json"),e=await S.readFile(s,"utf8").then(JSON.parse,()=>[]),n=new Map(Array.isArray(e)?e.map(a=>[a.slug,a]):[]);for(let{entry:a}of t)n.set(a.slug,a);let i=[];for(let[a,c]of[...n].sort(([l],[r])=>l.localeCompare(r))){let l=N.join(o,`${a}.html`);await S.stat(l).then(()=>!0,()=>!1)&&i.push(c)}await S.writeFile(s,`${JSON.stringify(i,null,2)}
9
+ `)}async function fa(t=[],{prepare:o=null,directory:s=A}={}){let e=Ao(s).built,{reports:n,failures:i}=await ra(t,{prepare:o,directory:s});await ca(),await S.mkdir(e,{recursive:!0}),await la(e,new Set(await Bi(s)));let a=[];for(let c of n){let l=`${c.slug}.html`,r=N.join(e,l);if(i.has(c.slug)){await S.rm(r,{force:!0});continue}let{html:d,removed:f}=Mt(c.html,{slug:c.slug,reportsDirectory:s});await S.writeFile(r,d),a.push({report:c,html:d,removed:f,entry:{slug:c.slug,...c.metadata,preview:`/generated/${l}`,sourceSha256:ut(c.html),outputSha256:ut(d)}})}return await da(a,e),{built:a,failures:i}}var ha=t=>t.replace(/<\/script/gi,"<\\/script");async function Fo(){return new Map(await Promise.all(K.map(async t=>{let o=await(t.file?It(t.file):gt(t,{inline:!0}));return qt(t).endsWith(".css")||(o=ha(o)),[t.id,t.umd?Gi(o):o]})))}function ua(t,o,s=null,e=[]){let n=Co(w(o));if(n===void 0)throw new Error(`${t}: the page writes no <head> start tag, which the export's Content-Security-Policy goes right after`);let i=s?`
10
+ ${Vi(s)}${e.length>0?`
11
+ ${Ji(e)}`:""}`:"";return`${o.slice(0,n)}
12
+ <meta name="generator" content="${Ki}">
13
+ <meta http-equiv="Content-Security-Policy" content="${Hi}">${i}${o.slice(n)}`}function Do(t,o,s,e=null,n=T(),i=A,a=null){let c=L(o,n);o=ao(ua(t,o,e,c),{slug:t,packages:c,root:i,workspace:a}),o=oe(xe(o,n),({id:d,element:f,attribute:h})=>{let u=s.get(d);if(typeof u!="string")throw new Error(`${t}: no inline source for the asset "${d}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${f} ${h}="${d}-inline">${u}</${f}>`});let{scripts:l,styles:r}=zo(w(o));if(l.length+r.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return o}async function Eo(t,o=A,{components:s=!0,catalog:e=T()}={}){let n=B(t,o),i=await S.readFile(Wt(n).html),a=i.toString("utf8"),c=w(a);s||(e={packages:new Map});let l=[...s?Lt(a,c,e):[],...Io({slug:t,html:a,directory:n,tree:c,catalog:e})];if(l.length>0){let r=L(a,e,c).find(({id:d})=>l[0].startsWith(`${d}:`)||l[0].startsWith(`${d} (`))?.id;throw Object.assign(new Error(`${t}: ${l[0]}`),{reason:"check",slug:t,failures:l,...r?{component:r}:{}})}return{html:a,sha256:ut(i)}}async function Dc({directory:t=A,workspace:o=null,catalog:s=T()}={}){let e=await Fo(),n=async(i,{files:a=!0}={})=>{let c=await Eo(i,t,{catalog:s}),l=Mt(c.html,{slug:i,files:a,reportsDirectory:t,catalog:s}).html;return Do(i,l,e,c.sha256,s,t,await _o(o,i,l,s))};return n.check=async i=>{await Eo(i,t,{components:!1})},n}async function _o(t,o,s,e){return typeof t!="function"||!Rt(L(s,e))?null:await t(o).catch(()=>null)??null}async function _c(t=[],{prepare:o=null,workspace:s=null,directory:e=A}={}){let n=Ao(e).exports,i=null,{built:a,failures:c}=await fa(t,{prepare:o,directory:e}),l=await Fo();await S.mkdir(n,{recursive:!0});let r=new Set(a.map(({report:h})=>h.slug)),{links:d}=await Wi(e),f=[];for(let{report:h,html:u}of a)try{let m=lo(u,h.slug,g=>r.has(g)?`${g}.html`:null,{links:d}),p=Do(h.slug,m,l,h.fileSha256,i,e,await _o(s,h.slug,m,i));await S.writeFile(N.join(n,`${h.slug}.html`),p),f.push({slug:h.slug,bytes:Buffer.byteLength(p),sha256:ut(p)})}catch(m){c.set(h.slug,[m.message])}return{built:a,exported:f,failures:c}}function To(t){let o=new Set;return M(t,s=>{for(let e of["id","data-block-id"])O(s,e)!==void 0&&o.add(O(s,e))}),o}function pa(t,o,s){if(Lo(t)||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(t)||Ri(t))return!1;let{pathname:e}=new URL(o);return!e.startsWith(`/${s}/`)||e.endsWith(".html")}function ma({slug:t,tree:o,directory:s}){let e=[],n=To(o),i=s===B(N.basename(s),A)?A:N.dirname(s),a=new Map([[t,n]]),c=d=>{if(!a.has(d)){let f=Wt(B(d,i));a.set(d,bo(f.html)?To(w(yi(f.html,"utf8"))):null)}return a.get(d)},l=null,r=(d,f)=>f===null?Mi(d):_i(f,l??=Ui((bo(i)?xi(i):[]).map(h=>({slug:h}))));return M(o,d=>{let f=d.tagName==="a"?O(d,"href"):void 0;if(!f||f==="#"||f==="#top")return;let h=d.sourceCodeLocation?.startLine;if(f.startsWith("#")){n.has(Fi(f.slice(1)))||e.push(`the link to ${f} (line ${h}) names no block or element of this document`);return}let u=Di(f,t),m=Pi(u),p=r(u,m);(p?!c(p.slug):m!==null)?Lo(f)||e.push(`the link to ${f} (line ${h}) names a document that is not there: gallery list has the slugs`):p?.block&&!c(p.slug).has(p.block)?e.push(`the link to ${f} (line ${h}) names a block document ${p.slug} does not hold`):u&&!p&&pa(f,u,t)&&e.push(`the link to ${f} (line ${h}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},Si),e}function Mo({slug:t,html:o,directory:s=B(t,A),written:e=o,scriptNotes:n=[]}){let i=w(o),a=Ae(o);return{fix:[...no(o,i),...uo({html:o,directory:s,tree:i})],notes:[...Xe(o,{written:e}),...Ue(i),...ma({slug:t,tree:i,directory:s}),...a.notes,...n],readings:a.readings}}function Mc(t){let{fix:o,notes:s}=Mo(t);return[...o,...s]}function Pc(t){let o=t.map(s=>[s.slug,Mo(s)]);for(let[s,{fix:e}]of o)for(let n of e)console.log(`fix ${s}: ${n}`);for(let[s,{notes:e}]of o)for(let n of e)console.log(`note ${s}: ${n}`);for(let[s,{readings:e}]of o)for(let n of e)console.log(`chart ${s}: ${n}`)}async function ga(t,{exportNote:o=!1}={}){for(let[s,e]of t){console.error(`
14
+ FAIL ${s}: ${e.length} problem${e.length===1?"":"s"}`);for(let i of e)console.error(` - ${i}`);let n=N.join(Ci,`${s}.html`);o&&await S.stat(n).then(()=>!0,()=>!1)&&console.error(` ${n} was not updated; it still holds an earlier export.`)}}function $a(t,{above:o=!1,allow:s=process.argv.includes("--allow-failures")}={}){t.size!==0&&(console.error(`
15
+ ${t.size} document${t.size===1?"":"s"} failed: ${[...t.keys()].join(", ")}${o?" (the failures are listed first, above)":""}`),s||(process.exitCode=1))}async function Uc(t,{exportNote:o=!1,allow:s}={}){await ga(t,{exportNote:o}),$a(t,{allow:s})}export{Ts as a,Mn as b,lo as c,$o as d,Mt as e,ki as f,Zi as g,Io as h,Ro as i,aa as j,Fc as k,ra as l,ca as m,fa as n,ua as o,Dc as p,_c as q,Mo as r,Mc as s,Pc as t,ga as u,$a as v,Uc as w};
@@ -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{b as n,f as t}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{answerOf as p,readAnnouncement as a,stopServer as d}from"../browser/shared/preview-server.mjs";async function u(i){let{positional:r}=t({argv:i});if(r.length>0)throw new n(`gallery stop takes no arguments: ${r[0]}`);let e=await a(),s=e?await p(e,1e4):"no";if(s==="no")return void console.log("No Gallery server runs.");s==="busy"&&(console.error(`The Gallery server on port ${e.port} (pid ${e.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${e.pid} yourself.`),process.exit(1)),e.kind==="dev"&&(console.error(`The shared Gallery server is npm run dev's (port ${e.port}, pid ${e.pid}): stop it where it runs.`),process.exit(1));let o=await d(e);o.ok||(console.error(o.message),process.exit(1)),console.log(`Stopped the server on port ${e.port} (pid ${e.pid})${o.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{u as run};
2
+ import{b as n,f as t}from"./chunk-L4WLQYFC.mjs";import"./chunk-5L7RYZCL.mjs";import{answerOf as p,readAnnouncement as a,stopServer as d}from"../browser/shared/preview-server.mjs";async function u(i){let{positional:r}=t({argv:i});if(r.length>0)throw new n(`gallery stop takes no arguments: ${r[0]}`);let e=await a(),s=e?await p(e,1e4):"no";if(s==="no")return void console.log("No Gallery server runs.");s==="busy"&&(console.error(`The Gallery server on port ${e.port} (pid ${e.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${e.pid} yourself.`),process.exit(1)),e.kind==="dev"&&(console.error(`The shared Gallery server is npm run dev's (port ${e.port}, pid ${e.pid}): stop it where it runs.`),process.exit(1));let o=await d(e);o.ok||(console.error(o.message),process.exit(1)),console.log(`Stopped the server on port ${e.port} (pid ${e.pid})${o.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{u 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{b as D}from"./chunk-LSVCTLS2.mjs";import"./chunk-F63BNJLG.mjs";import"./chunk-ZNGGDUZI.mjs";import{a as p,e as d,g as w,h as y,n as k}from"./chunk-B6RAGF4R.mjs";import{a as N}from"./chunk-5TLLIZT7.mjs";import{d as v,e as $,g as x,v as b}from"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import"./chunk-VAXLSISW.mjs";import"./chunk-56SVJENP.mjs";import{b as l,f as h,g}from"./chunk-L4WLQYFC.mjs";import"./chunk-NOGQX56R.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as T}from"../browser/shared/paths.mjs";import{documentDirectory as A,documentFiles as C}from"../browser/shared/workspace.mjs";async function q(L){let{positional:e,options:f,values:m}=h({options:["--no-preview","--no-browser"],values:["--title"],argv:L});if(e.length<1||e.length>2)throw new l("Name the document to copy, then the slug of the copy if you choose one.");let s=m.has("--title")?m.get("--title").replace(/\s+/g," ").trim():void 0;if(s==="")throw new l("--title takes the words of the title: a document's title is never empty.");e[1]!==void 0&&g(e[1]);let r=await p(),c=await y(e[0],"the document to copy",r);c.refused&&(console.error(c.refused),process.exit(1));let{slug:t}=c;if(r.documents.get(t)?.url!==void 0&&(console.error(`${d(r,t)} is a web link, not a document: there is nothing to copy (gallery link add makes another).`),process.exit(1)),t.startsWith("~")&&(console.error(`${t} is a document of another workspace: copy it there (gallery duplicate <slug> --workspace <its path>) or gallery copy it here from there.`),process.exit(1)),e[1]!==void 0){let o=await D(e[1]);o&&(console.error(`${o} Nothing copied.`),process.exit(1))}let i=await k("duplicate",{slug:t,...e[1]!==void 0?{as:e[1]}:{},...s!==void 0?{title:s}:{}});i?.ok||(console.error(`Not copied: ${i?.message??i?.reason??"no answer"}.`),process.exit(1));let n=i.report.slug,S=await p();console.log(`Duplicated ${d(r,t)} as ${n} (${i.report.title}), right after it in the sidebar.`),console.log(w(S,n)),console.log(`The copy's file: ${N(C(A(n,T)).html)} (the original's id, annotations and history stay with the original).`);for(let o of(i.notes??[]).filter(O=>O!=="\u6807\u9898\u5DF2\u66F4\u65B0"))console.log(`\u63D0\u793A\uFF1A${typeof o=="string"?o:o.message??JSON.stringify(o)}`);let a=await b(n,{skipped:x(f),command:`gallery duplicate ${t}`});console.log(v(a,"edit the copy as any document (its file is the path above)."));let u=await $(a,f);u&&console.log(u);for(let o of a)console.log(o)}export{q as run};
@@ -0,0 +1,8 @@
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 g}from"./chunk-LZY74XTP.mjs";import{b as v,d as y,i as b}from"./chunk-LHGKPMTI.mjs";import{b as p,f as u}from"./chunk-L4WLQYFC.mjs";import"./chunk-5L7RYZCL.mjs";import c from"node:fs/promises";import i from"node:path";import{pathToFileURL as k}from"node:url";import{packageRoot as E,previewDirectory as j,release as N}from"../browser/shared/paths.mjs";async function S(){let n=i.join(E,N?"web/assets":"src/workbench/app"),r=await c.readdir(n,{recursive:!0}),s=e=>e.endsWith("tokens.css")?0:e.endsWith("base.css")?1:e.endsWith("components.css")?2:3,o=r.filter(e=>e.endsWith(".css")).sort((e,l)=>s(e)-s(l)||e.localeCompare(l));return(await Promise.all(o.map(e=>c.readFile(i.join(n,e),"utf8")))).join(`
3
+ `)}var d=n=>JSON.stringify(n).replace(/</g,"\\u003c").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"),$=n=>String(n).replace(/[&<>"']/g,r=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[r]);async function C(n,r){if(i.resolve(n)===i.resolve(r))throw new p("Preview output must differ from its source.");let s=await c.readFile(n,"utf8"),o=s.match(/<script\b(?=[^>]*\bid=["']preview-config["'])[^>]*>([\s\S]*?)<\/script>/i)?.[1],e=o?JSON.parse(o):{};e.widths??={normal:0,narrow:560};for(let t of[...s.matchAll(/<link\b[^>]*\brel=["']stylesheet["'][^>]*\bhref=["']([^"']+)["'][^>]*>|<script\b[^>]*\bsrc=["']([^"']+)["'][^>]*><\/script>/gi)]){let a=t[1]??t[2];if(/^[a-z]+:|^\/\//i.test(a))continue;let h=await c.readFile(i.resolve(i.dirname(n),a),"utf8");s=s.replace(t[0],()=>t[1]?`<style>${h.replace(/<\/style/gi,"<\\/style")}</style>`:`<script>${h.replace(/<\/script/gi,"<\\/script")}</script>`)}let l=(e.gallery===!1?"":`<style>${await S()}</style>`)+`<script>${await c.readFile(i.join(j,"runtime.js"),"utf8")}</script>`;s=/<head\b[^>]*>/i.test(s)?s.replace(/<head\b[^>]*>/i,t=>t+l):l+s;let w=(await c.readFile(i.join(j,"shell.html"),"utf8")).replace("{{TITLE}}",()=>$(e.title||i.basename(n))).replace("/*CONFIG*/",()=>d(e)).replace("/*PAGE*/",()=>d(s));return await c.mkdir(i.dirname(r),{recursive:!0}),await c.writeFile(r,w),e}async function P(n,r,s,o){let e=(r.shots??[]).filter(t=>!o||o.includes(t.name));if(o?.some(t=>!e.some(a=>a.name===t)))throw new p("Unknown screenshot name.");for(let t of e)if(!/^[\p{L}\p{N}_-]+$/u.test(t.name))throw new p(`Invalid screenshot name: ${t.name}`);let l=v();if(!l)throw new Error("Chrome or Edge is required for --shots.");await c.mkdir(s,{recursive:!0});let w=await b({executablePath:l,args:y()});try{for(let t of e){let a=await w.browser.newPage(),h=[];a.on("pageerror",m=>h.push(m.message));try{let[m,x]=r.viewport??[1280,800];if(await a.setViewport({width:m,height:x}),await a.goto(k(n).href+"#"+new URLSearchParams(t.state??{})),await a.evaluate(()=>window.pv.ready),t.run&&await a.evaluate(f=>window.pv.run(f),t.run),await a.evaluate(()=>window.pv.run("const a=document.activeElement;if(a&&!a.matches('input,textarea,[contenteditable]'))a.blur();")),await new Promise(f=>setTimeout(f,Math.min(t.wait??400,1e4))),h.length)throw new Error(h.join(`
4
+ `));let F=await a.evaluate(()=>window.pv.frameRect());await a.screenshot({path:i.join(s,t.name+".png"),clip:F})}finally{await a.close()}}}finally{await w.close()}return e.length}async function q(n){let{positional:r,options:s,values:o}=u({argv:n,options:["--open"],values:["--out","--shots","--only"]});if(r[0]==="new"){if(r.length!==2||s.size||o.size)throw new p("Use gallery preview new <name>.");let t=i.resolve(r[1].endsWith(".html")?r[1]:r[1]+".page.html"),a=i.basename(t,".page.html");await c.writeFile(t,`<!doctype html>
5
+ <html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <script type="application/json" id="preview-config">${d({title:a,widths:{normal:0,narrow:560},shots:[{name:"light",state:{theme:"light"}},{name:"dark",state:{theme:"dark"}},{name:"narrow",state:{width:"narrow"}}]})}</script>
7
+ </head><body data-backdrop="gallery"><div class="pref-overlay"><div class="pref-dialog comp-dialog"><header class="pref-head"><span class="pref-title">${$(a)}</span></header><div class="comp-body"></div></div></div></body></html>
8
+ `,{flag:"wx"}),console.log(t);return}if(r.length!==1)throw new p("Name one preview page.");if(o.has("--only")&&!o.has("--shots"))throw new p("--only requires --shots.");let e=i.resolve(r[0]),l=i.resolve(o.get("--out")||e.replace(/(\.page)?\.html?$/i,"")+".preview.html"),w=await C(e,l);console.log(`Preview: ${l}`),o.has("--shots")&&console.log(`Screenshots: ${await P(l,w,i.resolve(o.get("--shots")),o.get("--only")?.split(","))}`),s.has("--open")&&await g(k(l).href)}export{C as buildPreview,S as galleryCss,q as run,P as shootPreview};
@@ -1,3 +1,3 @@
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{k as u}from"./chunk-PLB7L22J.mjs";import n from"node:fs/promises";import d from"node:path";import{writeAtomic as h}from"../browser/shared/files.mjs";import{documentFiles as A}from"../browser/shared/workspace.mjs";var I=s=>n.access(s).then(()=>!0,()=>!1);async function q(s,{create:y,slugOf:F,folderOf:j,fill:p,place:x,under:N="",said:J="\u5BFC\u5165\u81EA {0}",lang:O=null}){let e=[],c=[];async function f(t,r,S){let i=await F(t,S);await y(i,t.title,J.replace("{0}",()=>t.from),{lang:O});let a=j(i),{html:l,json:m}=A(a),k=await n.readFile(l,"utf8");await h(l,u(await p({source:k,nodes:t.nodes,icon:t.icon,own:t.own,raws:t.raws,lang:t.lang}))),t.files.length&&await n.mkdir(d.join(a,"assets"),{recursive:!0});for(let{from:o,name:v}of t.files){let w=d.join(a,"assets",v);await I(w)||await n.copyFile(o,w)}if(t.icon){let o=JSON.parse(await n.readFile(m,"utf8"));await h(m,`${JSON.stringify({...o,icon:t.icon},null,2)}
2
+ import{p as u}from"./chunk-B2EIMERT.mjs";import n from"node:fs/promises";import d from"node:path";import{writeAtomic as h}from"../browser/shared/files.mjs";import{documentFiles as A}from"../browser/shared/workspace.mjs";var I=s=>n.access(s).then(()=>!0,()=>!1);async function q(s,{create:y,slugOf:F,folderOf:j,fill:p,place:x,under:N="",said:J="\u5BFC\u5165\u81EA {0}",lang:O=null}){let e=[],c=[];async function f(t,r,S){let i=await F(t,S);await y(i,t.title,J.replace("{0}",()=>t.from),{lang:O});let a=j(i),{html:l,json:m}=A(a),k=await n.readFile(l,"utf8");await h(l,u(await p({source:k,nodes:t.nodes,icon:t.icon,own:t.own,raws:t.raws,lang:t.lang}))),t.files.length&&await n.mkdir(d.join(a,"assets"),{recursive:!0});for(let{from:o,name:v}of t.files){let w=d.join(a,"assets",v);await I(w)||await n.copyFile(o,w)}if(t.icon){let o=JSON.parse(await n.readFile(m,"utf8"));await h(m,`${JSON.stringify({...o,icon:t.icon},null,2)}
3
3
  `)}await x(i,r),e.push(i);for(let o of t.children??[])await f(o,i,null);return i}for(let[t,r]of s.entries())c.push(await f(r,N,t));return{made:e,top:c}}export{q as a};