@heycys/gallery 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/components/icon/page.mjs +6 -4
  3. package/browser/editor/components/icons.mjs +2 -2
  4. package/browser/editor/page/clipboard/import/read.mjs +20 -2
  5. package/browser/shared/document-copy.mjs +43 -0
  6. package/browser/shared/drafts.mjs +10 -3
  7. package/browser/shared/emoji/icon-value.mjs +2 -2
  8. package/browser/shared/extensions.mjs +83 -7
  9. package/browser/shared/i18n/en.mjs +10 -0
  10. package/browser/shared/outline-shape.mjs +6 -0
  11. package/browser/shared/outline.mjs +135 -10
  12. package/browser/shared/workspace-columns.mjs +11 -7
  13. package/dist/{chunk-QE5RG76S.mjs → chunk-2GKGEVMR.mjs} +11 -7
  14. package/dist/{chunk-HYMEEXKN.mjs → chunk-2RKIHJI2.mjs} +1 -1
  15. package/dist/{chunk-742D2WWJ.mjs → chunk-36FIRJIF.mjs} +2 -2
  16. package/dist/{chunk-EAIFITAV.mjs → chunk-3A5I2GJK.mjs} +1 -1
  17. package/dist/{chunk-7JDX4E65.mjs → chunk-3OFXMN6N.mjs} +1 -1
  18. package/dist/chunk-46ACXOU5.mjs +2 -0
  19. package/dist/{chunk-PUOQ65NC.mjs → chunk-4AMTKWDO.mjs} +1 -1
  20. package/dist/{chunk-HPOI4ZX7.mjs → chunk-4DNHHJSL.mjs} +1 -1
  21. package/dist/chunk-5DPABPBI.mjs +2 -0
  22. package/dist/{chunk-ALZ6ZENZ.mjs → chunk-5IIH335D.mjs} +1 -1
  23. package/dist/{chunk-EP25HDAJ.mjs → chunk-5L26JUYA.mjs} +1 -1
  24. package/dist/{chunk-FDMAXMQA.mjs → chunk-5MEXZ2UF.mjs} +1 -1
  25. package/dist/{chunk-ZHEHPMBK.mjs → chunk-6MPKCH3P.mjs} +1 -1
  26. package/dist/{chunk-C564NU2H.mjs → chunk-74RPP2M2.mjs} +1 -1
  27. package/dist/{chunk-YNAWBAYN.mjs → chunk-7M7UPWU6.mjs} +1 -1
  28. package/dist/{chunk-YROX2O22.mjs → chunk-7N2LPG33.mjs} +1 -1
  29. package/dist/{chunk-VS7JIGJW.mjs → chunk-7XDYK3UC.mjs} +1 -1
  30. package/dist/chunk-AEMVZYZQ.mjs +166 -0
  31. package/dist/{chunk-TR7TWGHB.mjs → chunk-AFGUR7SY.mjs} +1 -1
  32. package/dist/{chunk-K5XATEOO.mjs → chunk-AMDGVDNV.mjs} +1 -1
  33. package/dist/{chunk-JA7G53PC.mjs → chunk-ASAXY2DJ.mjs} +1 -1
  34. package/dist/{chunk-W7665ZEC.mjs → chunk-BYSF5UMM.mjs} +2 -2
  35. package/dist/{chunk-U3SSPL4K.mjs → chunk-CCSGFCLZ.mjs} +1 -1
  36. package/dist/{chunk-JLTZF4LA.mjs → chunk-CG3UHDKH.mjs} +1 -1
  37. package/dist/{chunk-YLPSMDIS.mjs → chunk-CPS4SRPF.mjs} +2 -2
  38. package/dist/{chunk-AHN3NFKJ.mjs → chunk-CZ5KJSGK.mjs} +1 -1
  39. package/dist/chunk-DAMVDXR3.mjs +2 -0
  40. package/dist/{chunk-WQDQWCX5.mjs → chunk-DH6GMDNN.mjs} +1 -1
  41. package/dist/{chunk-U5XL7D6A.mjs → chunk-DHB7UZ7F.mjs} +1 -1
  42. package/dist/{chunk-OEXWRJME.mjs → chunk-DKR7LFIY.mjs} +1 -1
  43. package/dist/chunk-DLFZJJEE.mjs +2 -0
  44. package/dist/{chunk-DJISHPUL.mjs → chunk-FCK6NXON.mjs} +1 -1
  45. package/dist/{chunk-IV64FFI4.mjs → chunk-FX42XU6J.mjs} +1 -1
  46. package/dist/{chunk-FETSREUN.mjs → chunk-FXQBADMN.mjs} +1 -1
  47. package/dist/{chunk-BFJGHSQN.mjs → chunk-G4YP7GVC.mjs} +1 -1
  48. package/dist/{chunk-V6XZ4VIR.mjs → chunk-GWOYMENX.mjs} +1 -1
  49. package/dist/chunk-HATA2W7X.mjs +2 -0
  50. package/dist/{chunk-YI43RG4P.mjs → chunk-HBAUKKQH.mjs} +1 -1
  51. package/dist/{chunk-MAFIGVXY.mjs → chunk-HM4E43VM.mjs} +1 -1
  52. package/dist/{chunk-OFHXGWOX.mjs → chunk-JI6T3A4Y.mjs} +1 -1
  53. package/dist/{chunk-5XA2ZBAE.mjs → chunk-JJNRIFND.mjs} +2 -2
  54. package/dist/chunk-JL6R4FG4.mjs +4 -0
  55. package/dist/{chunk-UMHUSOPJ.mjs → chunk-JXLSHVJ2.mjs} +1 -1
  56. package/dist/{chunk-VFX2KNHP.mjs → chunk-KFZBYDIS.mjs} +1 -1
  57. package/dist/{chunk-ZTHICSSF.mjs → chunk-KH24LWAT.mjs} +1 -1
  58. package/dist/{chunk-GHOYKMQ3.mjs → chunk-KUILYI7H.mjs} +1 -1
  59. package/dist/{chunk-5K44HLTZ.mjs → chunk-L7W624FD.mjs} +1 -1
  60. package/dist/{chunk-J5PUIV3Y.mjs → chunk-LE44MD3O.mjs} +1 -1
  61. package/dist/{chunk-4K5KC6V2.mjs → chunk-LV24RY2E.mjs} +1 -1
  62. package/dist/{chunk-43B75J5T.mjs → chunk-MKTX5PGV.mjs} +1 -1
  63. package/dist/{chunk-LKX55H76.mjs → chunk-NAGMRVW4.mjs} +1 -1
  64. package/dist/{chunk-DAZL73VK.mjs → chunk-NFABH3QW.mjs} +2 -2
  65. package/dist/{chunk-U7NZI6N4.mjs → chunk-NIW7F7LU.mjs} +2 -2
  66. package/dist/{chunk-PAREWQGB.mjs → chunk-NWRZXELO.mjs} +1 -1
  67. package/dist/{chunk-ZWWC4KLF.mjs → chunk-OU3S466R.mjs} +1 -1
  68. package/dist/{chunk-MN7BZL4R.mjs → chunk-PAFSFVYB.mjs} +1 -1
  69. package/dist/chunk-QCEATQC4.mjs +2 -0
  70. package/dist/{chunk-Y34NR5JL.mjs → chunk-QJ3TFJLQ.mjs} +1 -1
  71. package/dist/{chunk-IA4PSIMD.mjs → chunk-QK3VISCA.mjs} +1 -1
  72. package/dist/{chunk-7OG26PGF.mjs → chunk-QXVNUASA.mjs} +1 -1
  73. package/dist/{chunk-GRAXKKG4.mjs → chunk-QZ35UAB4.mjs} +1 -1
  74. package/dist/{chunk-AR5D57ZD.mjs → chunk-S2Y7VI4H.mjs} +2 -2
  75. package/dist/{chunk-HXG7EOPJ.mjs → chunk-SAHS56QM.mjs} +1 -1
  76. package/dist/{chunk-3MBRL2PM.mjs → chunk-SOD23RGL.mjs} +1 -1
  77. package/dist/chunk-TDWJKOLN.mjs +2 -0
  78. package/dist/{chunk-ITOH5EGO.mjs → chunk-TOE6DPLH.mjs} +1 -1
  79. package/dist/chunk-UGO5N3EI.mjs +15 -0
  80. package/dist/{chunk-4OKWZY5E.mjs → chunk-V5JRSGZF.mjs} +1 -1
  81. package/dist/{chunk-BZ5RAF7L.mjs → chunk-VA3KAQZD.mjs} +1 -1
  82. package/dist/{chunk-HDWTZ763.mjs → chunk-VG5JEIUQ.mjs} +1 -1
  83. package/dist/{chunk-POTA2FV4.mjs → chunk-VGTMLQWZ.mjs} +1 -1
  84. package/dist/{chunk-UYVCQK3H.mjs → chunk-VKSRM7EY.mjs} +1 -1
  85. package/dist/{chunk-ZDLPUOAG.mjs → chunk-VNUWREXU.mjs} +1 -1
  86. package/dist/{chunk-AGDILNWB.mjs → chunk-VPVOAJ7X.mjs} +1 -1
  87. package/dist/{chunk-CMA72MAG.mjs → chunk-WCWYNFDF.mjs} +1 -1
  88. package/dist/{chunk-ZQS6H473.mjs → chunk-WTEGUPFG.mjs} +1 -1
  89. package/dist/{chunk-R2ZDLJYT.mjs → chunk-XKOHV4H6.mjs} +1 -1
  90. package/dist/{chunk-MXUBKDRO.mjs → chunk-XMKHCUI6.mjs} +1 -1
  91. package/dist/{chunk-67N2QJYT.mjs → chunk-XQRUG4G3.mjs} +1 -1
  92. package/dist/{chunk-PGDE24N5.mjs → chunk-YBB5LWZK.mjs} +1 -1
  93. package/dist/{chunk-6N3PX4XX.mjs → chunk-YFJU3O7G.mjs} +1 -1
  94. package/dist/chunk-YPPJVDQI.mjs +2 -0
  95. package/dist/chunk-ZANMKAWS.mjs +2 -0
  96. package/dist/{chunk-6QBHU4DF.mjs → chunk-ZCP7BTOZ.mjs} +1 -1
  97. package/dist/{chunk-ERLAIBOA.mjs → chunk-ZEY2RLBT.mjs} +2 -2
  98. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-ZO7SFB2E.mjs} +2 -2
  99. package/dist/cli.mjs +1 -1
  100. package/dist/server.mjs +1 -1
  101. package/dist/worker.mjs +1 -1
  102. package/kit/math.js +1 -1
  103. package/kit/report.css +3 -3
  104. package/package.json +1 -1
  105. package/release.json +5 -5
  106. package/skill/SKILL.md +8 -7
  107. package/skill/references/extensions.md +11 -7
  108. package/web/assets/index-BHC5ZOMh.js +15 -0
  109. package/web/assets/index-xP0uw3a0.css +1 -0
  110. package/web/index.html +2 -2
  111. package/dist/chunk-6KBYRA2C.mjs +0 -2
  112. package/dist/chunk-F6HVDZR4.mjs +0 -2
  113. package/dist/chunk-J43Z6LSS.mjs +0 -2
  114. package/dist/chunk-JZT7I2OJ.mjs +0 -2
  115. package/dist/chunk-L2SUIS5S.mjs +0 -2
  116. package/dist/chunk-L7UP52JO.mjs +0 -2
  117. package/dist/chunk-LM4XFQHZ.mjs +0 -2
  118. package/dist/chunk-MTYYHM2G.mjs +0 -15
  119. package/dist/chunk-NAMN3RAF.mjs +0 -2
  120. package/dist/chunk-ORID3AE7.mjs +0 -166
  121. package/dist/chunk-SWUTTZCN.mjs +0 -2
  122. package/dist/chunk-UJQJKNGK.mjs +0 -2
  123. package/web/assets/index-BM_K-Auu.css +0 -1
  124. package/web/assets/index-DRslOBiv.js +0 -15
  125. /package/dist/{chunk-YEY3RSFQ.mjs → chunk-5MMN3N5J.mjs} +0 -0
  126. /package/dist/{chunk-UH4SIXTR.mjs → chunk-74UW7QSL.mjs} +0 -0
  127. /package/dist/{chunk-W7XHE4CT.mjs → chunk-EKGYYOSP.mjs} +0 -0
  128. /package/dist/{chunk-QAIHRH3I.mjs → chunk-KNZJT4ET.mjs} +0 -0
  129. /package/dist/{chunk-A55HN5OK.mjs → chunk-N3DSBH5S.mjs} +0 -0
  130. /package/dist/{chunk-QR6A54KJ.mjs → chunk-ZW2A6GBW.mjs} +0 -0
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-IV64FFI4.mjs";import{c as P,d as W}from"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-UYVCQK3H.mjs";import"./chunk-J5PUIV3Y.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as R}from"node:crypto";import{existsSync as X,readdirSync as G,readFileSync as Y,statSync as _}from"node:fs";import c from"node:fs/promises";import q from"node:os";import i from"node:path";import{release as J,reportsDirectory as V,skillDirectory as H}from"../browser/shared/paths.mjs";import{copyOldDocuments as Q,ensureWorkspace as Z,layoutOf as z,oldStateOf as K}from"../browser/shared/workspace.mjs";var S=o=>_(o,{throwIfNoEntry:!1})?.isDirectory()??!1;function ee({agent:o=null,project:e=!1,dir:r=null,cwd:t=process.cwd(),env:s=process.env}={}){if(r)return[{agent:null,target:i.resolve(t,r),skills:null}];let a=o?[o]:Object.keys(y),u=d=>e?i.join(i.resolve(t),y[d].project):i.resolve(y[d].home(s)),p=a.filter(d=>S(u(d)));return(o||p.length?o?a:p:["claude"]).map(d=>{let h=i.join(u(d),"skills");return{agent:d,target:i.join(h,"gallery"),skills:h}})}function te(o){try{return C(Y(i.join(o,"SKILL.md"),"utf8"))}catch{return null}}function T(o){let e=_(o,{throwIfNoEntry:!1});if(!e)return{kind:"absent"};if(!e.isDirectory())return{kind:"other",why:"it is a file"};let r=G(o);if(r.length===0)return{kind:"absent"};if(r.includes(".git"))return{kind:"other",why:"it is a git checkout"};let t=te(o),s=u=>r.includes(u);return(s("package.json")&&s("src")||s("reports"))&&(t==="gallery"||t==="html-report-studio")?{kind:"fat",name:t}:t==="gallery"&&!s("package.json")&&!s("src")&&!s("reports")?{kind:"thin"}:{kind:"other",why:t?`its SKILL.md is the skill "${t}"`:"it holds no Gallery skill"}}function oe(o){return S(o)?G(o,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(".")).map(e=>i.join(o,e.name)).filter(e=>T(e).kind==="fat"):[]}function re(o){let e=i.join(K(o),"servers");return S(e)?G(e).filter(r=>r.endsWith(".json")).flatMap(r=>{try{let{pid:t,port:s}=JSON.parse(Y(i.join(e,r),"utf8"));return!Number.isInteger(t)||t<=0||t===process.pid?[]:(process.kill(t,0),[{pid:t,port:s}])}catch(t){return t.code==="EPERM"?[{pid:Number.NaN,port:null}]:[]}}):[]}async function O(o){let e=0,r=0,t=async s=>{for(let a of await c.readdir(s,{withFileTypes:!0})){let u=i.join(s,a.name);a.isDirectory()?await t(u):(e++,r+=(await c.lstat(u)).size)}};return await t(o).catch(()=>{}),{files:e,bytes:r}}var B=o=>`${(o/1024/1024).toFixed(1)} MB`,se=(o,e)=>`${o} ${e}${o===1?"":"s"}`;async function v(o,e){for(let r=0;;r++)try{return await c.rename(o,e)}catch(t){if(process.platform!=="win32"||r>=10||!["EPERM","EBUSY","EACCES"].includes(t.code))throw t;await new Promise(s=>setTimeout(s,100*(r+1)))}}function ne(o,e=new Date){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,t=i.join(z(o).gallery,`old-skill-${r}`);for(let s=1;;s++){let a=s===1?t:`${t}-${s}`;if(!X(a))return a}}async function ie(o,e){await c.mkdir(i.dirname(e),{recursive:!0});try{return await v(o,e),null}catch(s){if(s.code!=="EXDEV")return`${s.code??s.message}`}let r=await O(o);await c.cp(o,e,{recursive:!0,preserveTimestamps:!0,verbatimSymlinks:!0,errorOnExist:!0,force:!1});let t=await O(e);return t.files!==r.files||t.bytes!==r.bytes?`the copy holds ${t.files} files, ${t.bytes} bytes, of ${r.files}, ${r.bytes}: the old folder was left as it was`:(await c.rm(o,{recursive:!0,force:!0}),null)}async function U(o){let e=[],r=async t=>{for(let s of await c.readdir(t,{withFileTypes:!0})){let a=i.join(t,s.name);s.isDirectory()?await r(a):e.push([i.relative(o,a).split(i.sep).join("/"),await c.readFile(a)])}};return await r(o),e.sort(([t],[s])=>t<s?-1:t>s?1:0)}var le=(o,e)=>o.length===e.length&&o.every(([r,t],s)=>r===e[s][0]&&t.equals(e[s][1]));async function ae(o,e,r){if(r==="thin"&&le(await U(o),await U(e)))return"same";let t=i.dirname(e);await c.mkdir(t,{recursive:!0});let s=R(4).toString("hex"),a=i.join(t,`.gallery-skill-new-${s}`);if(await c.cp(o,a,{recursive:!0}),r==="absent")return X(e)&&await c.rmdir(e),await v(a,e),"new";let u=i.join(t,`.gallery-skill-old-${s}`);await v(e,u);try{await v(a,e)}catch(p){throw await v(u,e).catch(()=>{}),await c.rm(a,{recursive:!0,force:!0}),p}return await c.rm(u,{recursive:!0,force:!0}),"updated"}async function $e(o,{version:e}){let{positional:r,options:t,values:s}=M({options:["--project"],values:["--agent","--dir"],argv:o});if(r[0]!=="install")throw new j(r.length?`No such skill command: ${r[0]} (install).`:"Say what to do: gallery skill install.");if(r.length>1)throw new j(`gallery skill install takes no other argument: ${r[1]}`);let a=s.get("--agent")??null;if(a!==null&&!Object.hasOwn(y,a))throw new j(`--agent is claude or codex, not ${a}.`);let u=s.get("--dir")??null;if(u!==null&&(a!==null||t.has("--project")))throw new j("--dir names the skill's folder itself: not with --agent or --project.");let p=ee({agent:a,project:t.has("--project"),dir:u}),d=[],h=p.map(n=>({...n,...T(n.target)}));for(let{target:n,kind:l,why:f}of h)l==="other"&&d.push(`${n} holds something that is not a Gallery skill (${f}): move it away, or pass --dir <another folder>.`);let N=[...new Set(h.flatMap(({target:n,kind:l,skills:f})=>[...l==="fat"?[n]:[],...f?oe(f):[]]))];for(let n of N)for(let{pid:l,port:f}of re(n))d.push(Number.isNaN(l)?`The older Gallery skill ${n} has a preview server running that this user cannot see: stop it first.`:`The older Gallery skill ${n} has its preview server running (pid ${l}${f?`, port ${f}`:""}): stop it first (close the window that runs it, or end process ${l}), then run gallery skill install again.`);if(d.length){for(let n of d)console.error(n);console.error("Nothing was changed."),process.exit(1)}if(N.length){let n=V;try{let{ours:l,reads:f}=await Z(n);l||(console.error(W(n,f)),process.exit(1))}catch(l){if(!l.code)throw l;console.error(P(n,l.code)),process.exit(1)}console.log(`\u5DE5\u4F5C\u533A\uFF1A${n}`);for(let l of N){console.log(`An older Gallery skill (the whole tools) is in ${l}: its documents go into the workspace, then it moves out of the skills folder.`);let f=i.join(l,"reports");if(S(f)){let m=await Q({from:f,to:n,state:K(l)});for(let w of A(m,f,n))console.log(` ${w}`)}else console.log(" It holds no documents (no reports/ folder).");let g=i.join(l,"exports");if(S(g)){let m=z(n).exports;await c.mkdir(m,{recursive:!0});let w=[],I=[];for(let E of(await c.readdir(g)).filter(x=>x.endsWith(".html")).sort())try{await c.copyFile(i.join(g,E),i.join(m,E),c.constants.COPYFILE_EXCL),w.push(E)}catch(x){if(x.code!=="EEXIST")throw x;I.push(E)}w.length&&console.log(` Exports: copied ${se(w.length,"file")} into ${m}: ${w.join(", ")}`),I.length&&console.log(` Exports not copied (the name is taken in ${m}; they stay in the moved folder's exports/): ${I.join(", ")}`)}let{bytes:k}=await O(l),$=await O(i.join(l,"node_modules")),D=ne(n),L=await ie(l,D);L&&(console.error(`Could not move ${l} to ${D} (${L}). Its documents are copied; move the folder out of the skills folder yourself (it is never needed in it again), then run gallery skill install again.`),process.exit(1)),console.log(` Moved the old skill to ${D} (${B(k)}${$.files?`; its node_modules/, ${B($.bytes)}, may be deleted: nothing reads it any more`:""}).`)}}let F=H,b=null;if(!J){let{buildSkill:n}=await import("./chunk-UGWMMEJ5.mjs");b=await c.mkdtemp(i.join(q.tmpdir(),"gallery-skill-")),F=i.join(b,"gallery"),n(F,{version:e})}try{let n=!1;for(let{agent:l,target:f}of h){let g=T(f).kind,k=await ae(F,f,g),$=l?` for ${y[l].name}`:"";console.log(k==="same"?`The Gallery skill ${e}${$} is installed already, unchanged: ${f}`:`${k==="updated"?"Updated":"Installed"} the Gallery skill ${e}${$}: ${f}`),n||=k!=="same"}n&&console.log("Open a new Agent session to use it.")}finally{b&&await c.rm(b,{recursive:!0,force:!0})}}export{y as AGENTS,T as kindOf,$e as run,ee as targetsOf};
2
+ import{a as y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-FX42XU6J.mjs";import{c as P,d as W}from"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-VKSRM7EY.mjs";import"./chunk-LE44MD3O.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as R}from"node:crypto";import{existsSync as X,readdirSync as G,readFileSync as Y,statSync as _}from"node:fs";import c from"node:fs/promises";import q from"node:os";import i from"node:path";import{release as J,reportsDirectory as V,skillDirectory as H}from"../browser/shared/paths.mjs";import{copyOldDocuments as Q,ensureWorkspace as Z,layoutOf as z,oldStateOf as K}from"../browser/shared/workspace.mjs";var S=o=>_(o,{throwIfNoEntry:!1})?.isDirectory()??!1;function ee({agent:o=null,project:e=!1,dir:r=null,cwd:t=process.cwd(),env:s=process.env}={}){if(r)return[{agent:null,target:i.resolve(t,r),skills:null}];let a=o?[o]:Object.keys(y),u=d=>e?i.join(i.resolve(t),y[d].project):i.resolve(y[d].home(s)),p=a.filter(d=>S(u(d)));return(o||p.length?o?a:p:["claude"]).map(d=>{let h=i.join(u(d),"skills");return{agent:d,target:i.join(h,"gallery"),skills:h}})}function te(o){try{return C(Y(i.join(o,"SKILL.md"),"utf8"))}catch{return null}}function T(o){let e=_(o,{throwIfNoEntry:!1});if(!e)return{kind:"absent"};if(!e.isDirectory())return{kind:"other",why:"it is a file"};let r=G(o);if(r.length===0)return{kind:"absent"};if(r.includes(".git"))return{kind:"other",why:"it is a git checkout"};let t=te(o),s=u=>r.includes(u);return(s("package.json")&&s("src")||s("reports"))&&(t==="gallery"||t==="html-report-studio")?{kind:"fat",name:t}:t==="gallery"&&!s("package.json")&&!s("src")&&!s("reports")?{kind:"thin"}:{kind:"other",why:t?`its SKILL.md is the skill "${t}"`:"it holds no Gallery skill"}}function oe(o){return S(o)?G(o,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(".")).map(e=>i.join(o,e.name)).filter(e=>T(e).kind==="fat"):[]}function re(o){let e=i.join(K(o),"servers");return S(e)?G(e).filter(r=>r.endsWith(".json")).flatMap(r=>{try{let{pid:t,port:s}=JSON.parse(Y(i.join(e,r),"utf8"));return!Number.isInteger(t)||t<=0||t===process.pid?[]:(process.kill(t,0),[{pid:t,port:s}])}catch(t){return t.code==="EPERM"?[{pid:Number.NaN,port:null}]:[]}}):[]}async function O(o){let e=0,r=0,t=async s=>{for(let a of await c.readdir(s,{withFileTypes:!0})){let u=i.join(s,a.name);a.isDirectory()?await t(u):(e++,r+=(await c.lstat(u)).size)}};return await t(o).catch(()=>{}),{files:e,bytes:r}}var B=o=>`${(o/1024/1024).toFixed(1)} MB`,se=(o,e)=>`${o} ${e}${o===1?"":"s"}`;async function v(o,e){for(let r=0;;r++)try{return await c.rename(o,e)}catch(t){if(process.platform!=="win32"||r>=10||!["EPERM","EBUSY","EACCES"].includes(t.code))throw t;await new Promise(s=>setTimeout(s,100*(r+1)))}}function ne(o,e=new Date){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,t=i.join(z(o).gallery,`old-skill-${r}`);for(let s=1;;s++){let a=s===1?t:`${t}-${s}`;if(!X(a))return a}}async function ie(o,e){await c.mkdir(i.dirname(e),{recursive:!0});try{return await v(o,e),null}catch(s){if(s.code!=="EXDEV")return`${s.code??s.message}`}let r=await O(o);await c.cp(o,e,{recursive:!0,preserveTimestamps:!0,verbatimSymlinks:!0,errorOnExist:!0,force:!1});let t=await O(e);return t.files!==r.files||t.bytes!==r.bytes?`the copy holds ${t.files} files, ${t.bytes} bytes, of ${r.files}, ${r.bytes}: the old folder was left as it was`:(await c.rm(o,{recursive:!0,force:!0}),null)}async function U(o){let e=[],r=async t=>{for(let s of await c.readdir(t,{withFileTypes:!0})){let a=i.join(t,s.name);s.isDirectory()?await r(a):e.push([i.relative(o,a).split(i.sep).join("/"),await c.readFile(a)])}};return await r(o),e.sort(([t],[s])=>t<s?-1:t>s?1:0)}var le=(o,e)=>o.length===e.length&&o.every(([r,t],s)=>r===e[s][0]&&t.equals(e[s][1]));async function ae(o,e,r){if(r==="thin"&&le(await U(o),await U(e)))return"same";let t=i.dirname(e);await c.mkdir(t,{recursive:!0});let s=R(4).toString("hex"),a=i.join(t,`.gallery-skill-new-${s}`);if(await c.cp(o,a,{recursive:!0}),r==="absent")return X(e)&&await c.rmdir(e),await v(a,e),"new";let u=i.join(t,`.gallery-skill-old-${s}`);await v(e,u);try{await v(a,e)}catch(p){throw await v(u,e).catch(()=>{}),await c.rm(a,{recursive:!0,force:!0}),p}return await c.rm(u,{recursive:!0,force:!0}),"updated"}async function $e(o,{version:e}){let{positional:r,options:t,values:s}=M({options:["--project"],values:["--agent","--dir"],argv:o});if(r[0]!=="install")throw new j(r.length?`No such skill command: ${r[0]} (install).`:"Say what to do: gallery skill install.");if(r.length>1)throw new j(`gallery skill install takes no other argument: ${r[1]}`);let a=s.get("--agent")??null;if(a!==null&&!Object.hasOwn(y,a))throw new j(`--agent is claude or codex, not ${a}.`);let u=s.get("--dir")??null;if(u!==null&&(a!==null||t.has("--project")))throw new j("--dir names the skill's folder itself: not with --agent or --project.");let p=ee({agent:a,project:t.has("--project"),dir:u}),d=[],h=p.map(n=>({...n,...T(n.target)}));for(let{target:n,kind:l,why:f}of h)l==="other"&&d.push(`${n} holds something that is not a Gallery skill (${f}): move it away, or pass --dir <another folder>.`);let N=[...new Set(h.flatMap(({target:n,kind:l,skills:f})=>[...l==="fat"?[n]:[],...f?oe(f):[]]))];for(let n of N)for(let{pid:l,port:f}of re(n))d.push(Number.isNaN(l)?`The older Gallery skill ${n} has a preview server running that this user cannot see: stop it first.`:`The older Gallery skill ${n} has its preview server running (pid ${l}${f?`, port ${f}`:""}): stop it first (close the window that runs it, or end process ${l}), then run gallery skill install again.`);if(d.length){for(let n of d)console.error(n);console.error("Nothing was changed."),process.exit(1)}if(N.length){let n=V;try{let{ours:l,reads:f}=await Z(n);l||(console.error(W(n,f)),process.exit(1))}catch(l){if(!l.code)throw l;console.error(P(n,l.code)),process.exit(1)}console.log(`\u5DE5\u4F5C\u533A\uFF1A${n}`);for(let l of N){console.log(`An older Gallery skill (the whole tools) is in ${l}: its documents go into the workspace, then it moves out of the skills folder.`);let f=i.join(l,"reports");if(S(f)){let m=await Q({from:f,to:n,state:K(l)});for(let w of A(m,f,n))console.log(` ${w}`)}else console.log(" It holds no documents (no reports/ folder).");let g=i.join(l,"exports");if(S(g)){let m=z(n).exports;await c.mkdir(m,{recursive:!0});let w=[],I=[];for(let E of(await c.readdir(g)).filter(x=>x.endsWith(".html")).sort())try{await c.copyFile(i.join(g,E),i.join(m,E),c.constants.COPYFILE_EXCL),w.push(E)}catch(x){if(x.code!=="EEXIST")throw x;I.push(E)}w.length&&console.log(` Exports: copied ${se(w.length,"file")} into ${m}: ${w.join(", ")}`),I.length&&console.log(` Exports not copied (the name is taken in ${m}; they stay in the moved folder's exports/): ${I.join(", ")}`)}let{bytes:k}=await O(l),$=await O(i.join(l,"node_modules")),D=ne(n),L=await ie(l,D);L&&(console.error(`Could not move ${l} to ${D} (${L}). Its documents are copied; move the folder out of the skills folder yourself (it is never needed in it again), then run gallery skill install again.`),process.exit(1)),console.log(` Moved the old skill to ${D} (${B(k)}${$.files?`; its node_modules/, ${B($.bytes)}, may be deleted: nothing reads it any more`:""}).`)}}let F=H,b=null;if(!J){let{buildSkill:n}=await import("./chunk-UGWMMEJ5.mjs");b=await c.mkdtemp(i.join(q.tmpdir(),"gallery-skill-")),F=i.join(b,"gallery"),n(F,{version:e})}try{let n=!1;for(let{agent:l,target:f}of h){let g=T(f).kind,k=await ae(F,f,g),$=l?` for ${y[l].name}`:"";console.log(k==="same"?`The Gallery skill ${e}${$} is installed already, unchanged: ${f}`:`${k==="updated"?"Updated":"Installed"} the Gallery skill ${e}${$}: ${f}`),n||=k!=="same"}n&&console.log("Open a new Agent session to use it.")}finally{b&&await c.rm(b,{recursive:!0,force:!0})}}export{y as AGENTS,T as kindOf,$e as run,ee as targetsOf};
@@ -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-J5PUIV3Y.mjs";import{D as ce}from"./chunk-VS7JIGJW.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-HDWTZ763.mjs";import{b as ye,e as mt}from"./chunk-A55HN5OK.mjs";mt();import{createHash as ht}from"node:crypto";import{cellsOf as gt}from"../browser/shared/card-size.mjs";import{escapeAttribute as de}from"../browser/shared/escape.mjs";import{attr as N,elementsOf as le,hasClass as _e,walk as Te}from"../browser/shared/html-tree.mjs";import{ATTRIBUTE as He}from"../browser/shared/components/installed.mjs";var q=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,sr=Object.freeze(["data-board-id","data-card-id","data-x","data-y","data-w","data-h"]),De="gallery-board",Fe="gallery-card",Le=e=>(e.tagName==="div"||e.tagName==="section")&&N(e,He)!==void 0,wt=e=>ht("sha256").update(e.replace(/\r\n?/g,`
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-LE44MD3O.mjs";import{D as ce}from"./chunk-7XDYK3UC.mjs";import{a as Q,f as Ce,g as Ie,n as je,t as Ae}from"./chunk-VG5JEIUQ.mjs";import{b as ye,e as mt}from"./chunk-N3DSBH5S.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(`
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as Q}from"./chunk-YROX2O22.mjs";import{c as _,d as z,e as B,l as G}from"./chunk-5XA2ZBAE.mjs";import"./chunk-JA7G53PC.mjs";import"./chunk-YI43RG4P.mjs";import{i as q}from"./chunk-NAMN3RAF.mjs";import{a as b,b as J}from"./chunk-JEUK3ZO7.mjs";import{a as Z}from"./chunk-AHN3NFKJ.mjs";import{a as ee}from"./chunk-MTYYHM2G.mjs";import"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import{c as V,d as Y,e as M}from"./chunk-DAZL73VK.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import{b as W,h as X}from"./chunk-ZQS6H473.mjs";import"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import{b as T,f as C,g as H}from"./chunk-4OZWXZE5.mjs";import"./chunk-ZTHICSSF.mjs";import{k as U}from"./chunk-6N3PX4XX.mjs";import{b as K}from"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import v from"node:fs/promises";import se from"node:os";import x from"node:path";import{IMPORT_EXT as re,kindOf as ie}from"../browser/shared/import-types.mjs";import{reportsDirectory as O}from"../browser/shared/paths.mjs";import{kebab as S}from"../browser/shared/web-links.mjs";import{documentDirectory as oe,documentFiles as E,newDocSlug as ae}from"../browser/shared/workspace.mjs";var ce=Object.values(re).flat().join(" "),j=(d,g)=>`${d} ${g}${d===1?"":"s"}`;function fe(d,g,p){let n=(f,r=g)=>(r.match(f)??[]).length,c=n(/<ol class="doc-flow"/g,p),$=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[c,"flow"],[$,"footnote"]].filter(([f])=>f>0).map(([f,r])=>j(f,r)),h=(d.raws?.length??0)-c-($?1:0);return h>0&&w.push(`${j(h,"HTML block")} kept as written`),w}async function Se(d){let{positional:g,options:p}=C({options:["--no-preview","--no-browser"],argv:d}),[n,c,$]=g;if(g.length<1||g.length>3||!n)throw new T("Name the file; then the slug and the title, if you choose them.");let w=ie(n);if(!w)throw new T(`Not a kind of file gallery import takes: ${n} (${ce}).`);c!==void 0&&H(c);let h=x.resolve(n);await v.stat(h).then(i=>i.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let f=c!==void 0?await Q(c):null;f&&(console.error(f),process.exit(1));let r=x.basename(h),F=await v.mkdtemp(x.join(se.tmpdir(),"gallery-import-")),L,y,R;try{let i,u=[];if(w==="markdown")i=[{...await Y(h,F),from:r,children:[]}];else try{({pages:i,skipped:u}=await V([{file:h,name:r}],F))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}i.length===0&&(console.error(`Nothing in ${r} could be read as a page${u.length?` (not taken: ${u.join(", ")})`:""}.`),process.exit(1)),$?.trim()&&(i[0]={...i[0],title:$.replace(/\s+/g," ").trim()});let I=new Map,te=ee({edits:{},reports:{},reportsDirectory:O});y=(await Z(i,{create:async(e,t,l,{lang:s})=>{let{directory:o}=await K(e,t,l,{blank:!0,lang:s});I.set(e,await v.readFile(E(o).html,"utf8"))},slugOf:(e,t)=>{if(t===0&&c!==void 0)return c;let l=S(e.title)||S(e.from?.replace(/\.[^.]+$/,"")??"")||S(r.replace(/\.[^.]+$/,""));return l?te.freeSlug(l):ae(O)},folderOf:e=>oe(e,O),fill:e=>M(e),place:(e,t)=>q(e,{parent:t})})).made;let P=[],A=(e,t)=>{P.push({page:e,depth:t});for(let l of e.children??[])A(l,t+1)};for(let e of i)A(e,0);let m=await Promise.all(P.map(async({page:e,depth:t},l)=>{let s=y[l],o=oe(s,O),a=E(o).html,k=await v.readFile(a,"utf8"),ne=(await M({source:I.get(s),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),le=X(W(k,{finish:U}).text);return{slug:s,depth:t,page:e,directory:o,htmlFile:a,made:fe(e,ne,k),readOnly:le}}));if(L={slug:y[0]},m.length===1){let[{page:e,directory:t,htmlFile:l,made:s,readOnly:o}]=m;if(console.log(`Created ${b(l)} and ${x.basename(E(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${s.length?s.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let a of e.notes)console.log(` ${a.line?`line ${a.line}: `:""}${a.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let a of o)console.log(` ${a}`)}}else{console.log(`Created ${j(m.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:l,depth:s,page:o,htmlFile:a,made:k}of m)console.log(`${" ".repeat(s+1)}${l} ${o.title} ${b(a)}`),console.log(`${" ".repeat(s+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=m.flatMap(({slug:l,page:s})=>(s.notes??[]).map(o=>` ${l}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
2
+ import{b as Q}from"./chunk-7N2LPG33.mjs";import{c as _,d as z,e as B,l as G}from"./chunk-JJNRIFND.mjs";import"./chunk-ASAXY2DJ.mjs";import"./chunk-HBAUKKQH.mjs";import{i as q}from"./chunk-YPPJVDQI.mjs";import{a as b,b as J}from"./chunk-JEUK3ZO7.mjs";import{a as Z}from"./chunk-CZ5KJSGK.mjs";import{a as ee}from"./chunk-UGO5N3EI.mjs";import"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import{c as V,d as Y,e as M}from"./chunk-NFABH3QW.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import{b as W,h as X}from"./chunk-WTEGUPFG.mjs";import"./chunk-KUILYI7H.mjs";import"./chunk-2GKGEVMR.mjs";import{b as T,f as C,g as H}from"./chunk-4OZWXZE5.mjs";import"./chunk-KH24LWAT.mjs";import{k as U}from"./chunk-YFJU3O7G.mjs";import{b as K}from"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import v from"node:fs/promises";import se from"node:os";import x from"node:path";import{IMPORT_EXT as re,kindOf as ie}from"../browser/shared/import-types.mjs";import{reportsDirectory as O}from"../browser/shared/paths.mjs";import{kebab as S}from"../browser/shared/web-links.mjs";import{documentDirectory as oe,documentFiles as E,newDocSlug as ae}from"../browser/shared/workspace.mjs";var ce=Object.values(re).flat().join(" "),j=(d,g)=>`${d} ${g}${d===1?"":"s"}`;function fe(d,g,p){let n=(f,r=g)=>(r.match(f)??[]).length,c=n(/<ol class="doc-flow"/g,p),$=n(/<li id="fn-\d+"/g,p),w=[[n(/<section class="doc-section"/g),"section"],[n(/<h[2-4][\s>]/g),"heading"],[n(/<p[\s>]/g),"paragraph"],[n(/<(?:ul|ol)[\s>]/g),"list"],[n(/<table\b/g),"table"],[n(/class="doc-math-(?:inline|block)"/g,p),"formula"],[n(/<div class="doc-code"/g),"code block"],[n(/<figure class="doc-image"/g),"picture"],[c,"flow"],[$,"footnote"]].filter(([f])=>f>0).map(([f,r])=>j(f,r)),h=(d.raws?.length??0)-c-($?1:0);return h>0&&w.push(`${j(h,"HTML block")} kept as written`),w}async function Se(d){let{positional:g,options:p}=C({options:["--no-preview","--no-browser"],argv:d}),[n,c,$]=g;if(g.length<1||g.length>3||!n)throw new T("Name the file; then the slug and the title, if you choose them.");let w=ie(n);if(!w)throw new T(`Not a kind of file gallery import takes: ${n} (${ce}).`);c!==void 0&&H(c);let h=x.resolve(n);await v.stat(h).then(i=>i.isFile(),()=>!1)||(console.error(`No such file: ${n}`),process.exit(1));let f=c!==void 0?await Q(c):null;f&&(console.error(f),process.exit(1));let r=x.basename(h),F=await v.mkdtemp(x.join(se.tmpdir(),"gallery-import-")),L,y,R;try{let i,u=[];if(w==="markdown")i=[{...await Y(h,F),from:r,children:[]}];else try{({pages:i,skipped:u}=await V([{file:h,name:r}],F))}catch(e){console.error(`${r} could not be read: ${e.message}`),process.exit(1)}i.length===0&&(console.error(`Nothing in ${r} could be read as a page${u.length?` (not taken: ${u.join(", ")})`:""}.`),process.exit(1)),$?.trim()&&(i[0]={...i[0],title:$.replace(/\s+/g," ").trim()});let I=new Map,te=ee({edits:{},reports:{},reportsDirectory:O});y=(await Z(i,{create:async(e,t,l,{lang:s})=>{let{directory:o}=await K(e,t,l,{blank:!0,lang:s});I.set(e,await v.readFile(E(o).html,"utf8"))},slugOf:(e,t)=>{if(t===0&&c!==void 0)return c;let l=S(e.title)||S(e.from?.replace(/\.[^.]+$/,"")??"")||S(r.replace(/\.[^.]+$/,""));return l?te.freeSlug(l):ae(O)},folderOf:e=>oe(e,O),fill:e=>M(e),place:(e,t)=>q(e,{parent:t})})).made;let P=[],A=(e,t)=>{P.push({page:e,depth:t});for(let l of e.children??[])A(l,t+1)};for(let e of i)A(e,0);let m=await Promise.all(P.map(async({page:e,depth:t},l)=>{let s=y[l],o=oe(s,O),a=E(o).html,k=await v.readFile(a,"utf8"),ne=(await M({source:I.get(s),nodes:e.nodes,icon:e.icon,own:e.own})).replace(/<p>\u{E000}\d+\u{E001}<\/p>/gu,""),le=X(W(k,{finish:U}).text);return{slug:s,depth:t,page:e,directory:o,htmlFile:a,made:fe(e,ne,k),readOnly:le}}));if(L={slug:y[0]},m.length===1){let[{page:e,directory:t,htmlFile:l,made:s,readOnly:o}]=m;if(console.log(`Created ${b(l)} and ${x.basename(E(t).json)} from ${r}`),console.log(`Title: ${e.title}`),console.log(`Made: ${s.length?s.join(", "):"nothing but the title"}${e.files.length?` (${j(e.files.length,"file")} in ${b(x.join(t,"assets"))})`:""}`),e.notes?.length){console.log(`Not brought as the file has it (${e.notes.length}):`);for(let a of e.notes)console.log(` ${a.line?`line ${a.line}: `:""}${a.text}`)}if(o.length){console.log(`Text the preview leaves read-only (${o.length}), by doc.html's lines as gallery check gives them:`);for(let a of o)console.log(` ${a}`)}}else{console.log(`Created ${j(m.length,"document")} from ${r} (each nested as in the file):`);for(let{slug:l,depth:s,page:o,htmlFile:a,made:k}of m)console.log(`${" ".repeat(s+1)}${l} ${o.title} ${b(a)}`),console.log(`${" ".repeat(s+2)}Made: ${k.length?k.join(", "):"nothing but the title"}${o.files.length?` (${j(o.files.length,"file")} in its assets/)`:""}`);let e=m.flatMap(({slug:l,page:s})=>(s.notes??[]).map(o=>` ${l}: ${o.line?`line ${o.line}: `:""}${o.text}`));e.length&&console.log(`Not brought as the file has it (${e.length}):
3
3
  ${e.join(`
4
4
  `)}`);let t=m.flatMap(({slug:l,readOnly:s})=>s.map(o=>` ${l}: ${o}`));t.length&&console.log(`Text the preview leaves read-only (${t.length}), by doc.html's lines as gallery check gives them:
5
5
  ${t.join(`
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a}from"./chunk-MAFIGVXY.mjs";import"./chunk-742D2WWJ.mjs";import"./chunk-5L7RYZCL.mjs";export{a as convertPuppeteerChannelToBrowsersChannel};
2
+ import{a}from"./chunk-HM4E43VM.mjs";import"./chunk-36FIRJIF.mjs";import"./chunk-5L7RYZCL.mjs";export{a as convertPuppeteerChannelToBrowsersChannel};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as R}from"./chunk-OEXWRJME.mjs";import{b as I,c as B}from"./chunk-342HXE3Q.mjs";import{a as f,b as F,c as L,d as M}from"./chunk-EAIFITAV.mjs";import{a as S,b as k,g as $}from"./chunk-67N2QJYT.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import{b as D}from"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import{b as v}from"./chunk-ZQS6H473.mjs";import{j as d}from"./chunk-4OZWXZE5.mjs";import{k as w,q as h,t as g,u as y,v as x}from"./chunk-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import O from"node:fs/promises";import{reportsDirectory as P}from"../browser/shared/paths.mjs";import{documentDirectory as U,documentFiles as q,layoutOf as z}from"../browser/shared/workspace.mjs";function C(s=P){let n=D({root:s,read:async a=>{let o=await O.readFile(q(U(a,s)).html,"utf8").catch(()=>null);return o===null?null:{source:o,text:v(o).text}},activity:N({file:z(s).activity})});return a=>n.snapshot(a)}async function te(s){let{slugs:t,options:n}=await d({options:["--allow-failures"],argv:s});t.length===0&&(console.error(R()),process.exit(1));let a=await b(t),o=await w(t,{prepare:f({say:!1})}),r=await S(t.filter(e=>!o.has(e)));await k(t.filter(e=>o.has(e)||r.failures.has(e))),await L(t),await M(t);let m=t.filter(e=>!o.has(e)&&!r.failures.has(e)),{built:l,exported:p,failures:c}=m.length>0?await h(m,{prepare:f({say:!1}),workspace:C()}):{built:[],exported:[],failures:new Map};for(let[e,i]of[...o,...r.failures])c.set(e,i);await y(c,{exportNote:!0}),await a.keep(p.map(({slug:e})=>e));let A=new Map(l.map(({report:e,removed:i})=>[e.slug,i]));for(let{slug:e,bytes:i,sha256:j}of p){let u=A.get(e),E=u.length>0?`; shared scripts and styles left out (unused): ${u.join(", ")}`:"";console.log(`Exported ${I(e)} (${i.toLocaleString("en-US")} bytes, sha256 ${j})${E}`)}g(l.map(({report:e})=>e)),F(l.map(({report:e})=>e));for(let e of r.lines)console.log(e);r.written.length>0&&console.log($(r.written));for(let{slug:e}of p)console.log(B(e));x(c,{above:!0,allow:n.has("--allow-failures")})}export{te as run};
2
+ import{a as R}from"./chunk-DKR7LFIY.mjs";import{b as I,c as B}from"./chunk-342HXE3Q.mjs";import{a as f,b as F,c as L,d as M}from"./chunk-3A5I2GJK.mjs";import{a as S,b as k,g as $}from"./chunk-XQRUG4G3.mjs";import{a as N}from"./chunk-DR73Y2UJ.mjs";import{k as b}from"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import{b as D}from"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import{b as v}from"./chunk-WTEGUPFG.mjs";import{j as d}from"./chunk-4OZWXZE5.mjs";import{k as w,q as h,t as g,u as y,v as x}from"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import O from"node:fs/promises";import{reportsDirectory as P}from"../browser/shared/paths.mjs";import{documentDirectory as U,documentFiles as q,layoutOf as z}from"../browser/shared/workspace.mjs";function C(s=P){let n=D({root:s,read:async a=>{let o=await O.readFile(q(U(a,s)).html,"utf8").catch(()=>null);return o===null?null:{source:o,text:v(o).text}},activity:N({file:z(s).activity})});return a=>n.snapshot(a)}async function te(s){let{slugs:t,options:n}=await d({options:["--allow-failures"],argv:s});t.length===0&&(console.error(R()),process.exit(1));let a=await b(t),o=await w(t,{prepare:f({say:!1})}),r=await S(t.filter(e=>!o.has(e)));await k(t.filter(e=>o.has(e)||r.failures.has(e))),await L(t),await M(t);let m=t.filter(e=>!o.has(e)&&!r.failures.has(e)),{built:l,exported:p,failures:c}=m.length>0?await h(m,{prepare:f({say:!1}),workspace:C()}):{built:[],exported:[],failures:new Map};for(let[e,i]of[...o,...r.failures])c.set(e,i);await y(c,{exportNote:!0}),await a.keep(p.map(({slug:e})=>e));let A=new Map(l.map(({report:e,removed:i})=>[e.slug,i]));for(let{slug:e,bytes:i,sha256:j}of p){let u=A.get(e),E=u.length>0?`; shared scripts and styles left out (unused): ${u.join(", ")}`:"";console.log(`Exported ${I(e)} (${i.toLocaleString("en-US")} bytes, sha256 ${j})${E}`)}g(l.map(({report:e})=>e)),F(l.map(({report:e})=>e));for(let e of r.lines)console.log(e);r.written.length>0&&console.log($(r.written));for(let{slug:e}of p)console.log(B(e));x(c,{above:!0,allow:n.has("--allow-failures")})}export{te as run};
@@ -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{a as We}from"./chunk-UMHUSOPJ.mjs";import{d as Ue,e as Vt,g as Xt,j as ze,k as qe,l as Je,m as Zt}from"./chunk-VFX2KNHP.mjs";import{B as Pe,c as lt,d as Ke,q as St,r as He,y as Jt,z as ft}from"./chunk-VS7JIGJW.mjs";import{b as rt,e as fn}from"./chunk-A55HN5OK.mjs";fn();import dn from"node:path";import{attr as w,curlyQuoted as un}from"../browser/shared/html-tree.mjs";import{FOLDED_LINES as Ve,LINE_START as Xe,NOWRAP as Qt,lineStart as mn,validFolded as hn}from"../browser/shared/code-lines.mjs";import{COLORS as gn}from"../browser/shared/colors.mjs";import{FLOWS as pn,instanceSlots as at,isInstance as it,isSlot as fs,matchesNode as pt}from"../browser/shared/components/index.mjs";import{HEADED as dt}from"../browser/shared/components/dialog.mjs";import{pageLanguage as Nn}from"../browser/shared/components/page.mjs";import{SHEETS_LABEL as Ze,shortSheets as On}from"../browser/shared/components/sheets.mjs";import{iconMarkup as Qe,iconValueOf as ds}from"../browser/shared/emoji/icon-value.mjs";import{escapeText as mt}from"../browser/shared/escape.mjs";import{COLUMN_GAP as $n,READING_WIDTH as Tt,SPAN as Ye,SPAN_SIZE as ut}from"../browser/shared/media.mjs";import{kitNamespace as us}from"../browser/shared/old-names.mjs";import{CHART_DATA as wn,CHART_SOURCE as tt,TABLE_READERS as bn,nextChartKey as kn}from"../browser/shared/table-chart.mjs";import{ALIGNS as Yt}from"../browser/editor/components/align.mjs";import{BLOCK_COLORS as ie}from"../browser/editor/components/colors.mjs";import{DETAILS as Ln,DIALOG as ee,PAGE as ms,SECTION as yn,SHEETS as vn}from"../browser/editor/components/kit.mjs";import{DIALOG_TRIGGER as Cn}from"../browser/editor/components/dialog/index.mjs";import{CHECKED as ce,FLOW as ht,TODO as se}from"../browser/editor/components/list/index.mjs";import{texSource as xn}from"../browser/editor/components/math/index.mjs";import{BOX_CLASSES as hs,HOLDS_ONE as Sn,UNIT_KINDS as Tn}from"../browser/editor/components/registry.mjs";import{HEADER_LOOK as ts}from"../browser/editor/components/table/index.mjs";import{backgroundColor as En,parseColor as An,textColor as In}from"../browser/editor/page/clipboard/import/colors.mjs";var re=new Set(["script","style","template","textarea","noscript","code","svg","math","select","option","button","iframe","video","audio","canvas","object","picture"]),jt=["doc-figure","doc-code","doc-diff","doc-math-inline","doc-math-block","doc-link-mention","doc-sheet-tabs","doc-state-fields","doc-filter-row","doc-image","doc-file","doc-bookmark","doc-embed","doc-icon","doc-title","doc-table-meta"],le=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th","dt","dd","blockquote","figcaption","caption","summary"]),Et=new Set(["main","section","div","article","aside","blockquote","li","details","dialog"]),_n=new Set(gn.map(({name:e})=>e)),C=e=>(w(e,"class")??"").split(/\s+/).filter(Boolean),es=e=>C(e).every(n=>ie.includes(n)),jn=ie.filter(e=>e.startsWith("doc-highlight-")),ct=e=>C(e).some(n=>!us(n)),D=e=>e.nodeName==="#text",Bt=/^[\s\u200b-\u200d\u2060\ufeff]*$/,V=e=>D(e)&&Bt.test(e.value),y=e=>(e.childNodes??[]).filter(n=>n.tagName),Z=e=>(e.attrs??[]).map(n=>n.name),F=(e,n)=>Z(e).every(f=>n.includes(f)),Bn=[yn.match,Ln.match,ee.match,vn.match,"table.doc-table"].join(", ");function gs(e){let n=C(e);return n.some(f=>jt.includes(f))||Ke(e)||pt(e,Bn)||hs.some(([f])=>n.includes(f))||Tn.some(f=>f.class&&n.includes(f.class)&&(!f.tag||[f.tag].flat().includes(e.tagName)))}var Mn=e=>{for(let n=e.parentNode;n?.tagName&&n.tagName!=="main";n=n.parentNode)if(n.tagName==="figure")return!0;return!1},ps=new Set(["thead","tbody","tfoot","tr","colgroup","col"]),fe=e=>ct(e)&&e.tagName!=="figure"&&!le.has(e.tagName)&&!ps.has(e.tagName)&&!gs(e),Ns=new Set([...lt].filter(e=>!["header","main","dialog","form","fieldset","caption","dd","dt","figcaption","summary","li","td","th",...ps].includes(e))),Rn=/\\\(([\s\S]*?)\\\)/g,wt=e=>xn(e)&&/\S/.test(e);function Dn(e,n=!0){let f=n?e:/^\s*(?:\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$)/.exec(e)?.[0]??"";return/[<>]/.test(f)&&wt(f.replace(/</g,"\\lt ").replace(/>/g,"\\gt "))}var ne=new Set(["br","wbr","img","input"]),Os=new Set([...lt,"script","style","template","noscript","link","meta"]),$s=new Set(["input","select","textarea","button","label","option"]),Gn=new Set([...lt,"hgroup","search","center","dir","listing","xmp","plaintext"]),oe=e=>y(e).some(n=>Gn.has(n.tagName)||oe(n)),ws=new Set(["main","section","div","article","aside","blockquote"]),Fn=pn.join(", "),bs=e=>ws.has(e.tagName)&&!ct(e)&&(C(e).length===0||pt(e,Fn))||fs(e),et=e=>D(e)?!Bt.test(e.value):(e.childNodes??[]).some(et),Kn=hs.filter(([,e])=>Sn.has(e)).map(([e])=>e),Hn=e=>bs(e)&&C(e).some(n=>Kn.includes(n)),ks=e=>e.childNodes.some(n=>D(n)&&!Bt.test(n.value))&&y(e).some(n=>lt.has(n.tagName)),Pn=/^[ \t\n\r\f]*/;function te(e){let n=[],f=[];for(let u of e)u.tagName&&Os.has(u.tagName)?(n.push(f),f=[]):f.push(u);n.push(f);let p=u=>!u.tagName&&!et(u),O=u=>(D(u)||u.tagName&&!$s.has(u.tagName))&&et(u);return n.map(u=>{let $=u.findIndex(m=>!p(m));return $<0?[]:u.slice($,u.findLastIndex(m=>!p(m))+1)}).filter(u=>u.some(O))}function Wn(e){let n=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="style"?n.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),n.flatMap(p=>[...p.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").matchAll(/([^{};]*)\{/g)].map(([,O])=>O))}var Un=(e,{tags:n=[],classes:f=[]})=>{let p=[...n.map(u=>`(?<![\\w.#-])${u}`),...f.map(u=>`\\.${u}`)],O=p.length?new RegExp(`(?:${p.join("|")})(?![\\w-])`,"i"):null;return!!O&&e.some(u=>O.test(u))};function zn(e){let n=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="script"?n.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),n.join(`
2
+ import{a as We}from"./chunk-JXLSHVJ2.mjs";import{d as Ue,e as Vt,g as Xt,j as ze,k as qe,l as Je,m as Zt}from"./chunk-KFZBYDIS.mjs";import{B as Pe,c as lt,d as Ke,q as St,r as He,y as Jt,z as ft}from"./chunk-7XDYK3UC.mjs";import{b as rt,e as fn}from"./chunk-N3DSBH5S.mjs";fn();import dn from"node:path";import{attr as w,curlyQuoted as un}from"../browser/shared/html-tree.mjs";import{FOLDED_LINES as Ve,LINE_START as Xe,NOWRAP as Qt,lineStart as mn,validFolded as hn}from"../browser/shared/code-lines.mjs";import{COLORS as gn}from"../browser/shared/colors.mjs";import{FLOWS as pn,instanceSlots as at,isInstance as it,isSlot as fs,matchesNode as pt}from"../browser/shared/components/index.mjs";import{HEADED as dt}from"../browser/shared/components/dialog.mjs";import{pageLanguage as Nn}from"../browser/shared/components/page.mjs";import{SHEETS_LABEL as Ze,shortSheets as On}from"../browser/shared/components/sheets.mjs";import{iconMarkup as Qe,iconValueOf as ds}from"../browser/shared/emoji/icon-value.mjs";import{escapeText as mt}from"../browser/shared/escape.mjs";import{COLUMN_GAP as $n,READING_WIDTH as Tt,SPAN as Ye,SPAN_SIZE as ut}from"../browser/shared/media.mjs";import{kitNamespace as us}from"../browser/shared/old-names.mjs";import{CHART_DATA as wn,CHART_SOURCE as tt,TABLE_READERS as bn,nextChartKey as kn}from"../browser/shared/table-chart.mjs";import{ALIGNS as Yt}from"../browser/editor/components/align.mjs";import{BLOCK_COLORS as ie}from"../browser/editor/components/colors.mjs";import{DETAILS as Ln,DIALOG as ee,PAGE as ms,SECTION as yn,SHEETS as vn}from"../browser/editor/components/kit.mjs";import{DIALOG_TRIGGER as Cn}from"../browser/editor/components/dialog/index.mjs";import{CHECKED as ce,FLOW as ht,TODO as se}from"../browser/editor/components/list/index.mjs";import{texSource as xn}from"../browser/editor/components/math/index.mjs";import{BOX_CLASSES as hs,HOLDS_ONE as Sn,UNIT_KINDS as Tn}from"../browser/editor/components/registry.mjs";import{HEADER_LOOK as ts}from"../browser/editor/components/table/index.mjs";import{backgroundColor as En,parseColor as An,textColor as In}from"../browser/editor/page/clipboard/import/colors.mjs";var re=new Set(["script","style","template","textarea","noscript","code","svg","math","select","option","button","iframe","video","audio","canvas","object","picture"]),jt=["doc-figure","doc-code","doc-diff","doc-math-inline","doc-math-block","doc-link-mention","doc-sheet-tabs","doc-state-fields","doc-filter-row","doc-image","doc-file","doc-bookmark","doc-embed","doc-icon","doc-title","doc-table-meta"],le=new Set(["p","h1","h2","h3","h4","h5","h6","li","td","th","dt","dd","blockquote","figcaption","caption","summary"]),Et=new Set(["main","section","div","article","aside","blockquote","li","details","dialog"]),_n=new Set(gn.map(({name:e})=>e)),C=e=>(w(e,"class")??"").split(/\s+/).filter(Boolean),es=e=>C(e).every(n=>ie.includes(n)),jn=ie.filter(e=>e.startsWith("doc-highlight-")),ct=e=>C(e).some(n=>!us(n)),D=e=>e.nodeName==="#text",Bt=/^[\s\u200b-\u200d\u2060\ufeff]*$/,V=e=>D(e)&&Bt.test(e.value),y=e=>(e.childNodes??[]).filter(n=>n.tagName),Z=e=>(e.attrs??[]).map(n=>n.name),F=(e,n)=>Z(e).every(f=>n.includes(f)),Bn=[yn.match,Ln.match,ee.match,vn.match,"table.doc-table"].join(", ");function gs(e){let n=C(e);return n.some(f=>jt.includes(f))||Ke(e)||pt(e,Bn)||hs.some(([f])=>n.includes(f))||Tn.some(f=>f.class&&n.includes(f.class)&&(!f.tag||[f.tag].flat().includes(e.tagName)))}var Mn=e=>{for(let n=e.parentNode;n?.tagName&&n.tagName!=="main";n=n.parentNode)if(n.tagName==="figure")return!0;return!1},ps=new Set(["thead","tbody","tfoot","tr","colgroup","col"]),fe=e=>ct(e)&&e.tagName!=="figure"&&!le.has(e.tagName)&&!ps.has(e.tagName)&&!gs(e),Ns=new Set([...lt].filter(e=>!["header","main","dialog","form","fieldset","caption","dd","dt","figcaption","summary","li","td","th",...ps].includes(e))),Rn=/\\\(([\s\S]*?)\\\)/g,wt=e=>xn(e)&&/\S/.test(e);function Dn(e,n=!0){let f=n?e:/^\s*(?:\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$)/.exec(e)?.[0]??"";return/[<>]/.test(f)&&wt(f.replace(/</g,"\\lt ").replace(/>/g,"\\gt "))}var ne=new Set(["br","wbr","img","input"]),Os=new Set([...lt,"script","style","template","noscript","link","meta"]),$s=new Set(["input","select","textarea","button","label","option"]),Gn=new Set([...lt,"hgroup","search","center","dir","listing","xmp","plaintext"]),oe=e=>y(e).some(n=>Gn.has(n.tagName)||oe(n)),ws=new Set(["main","section","div","article","aside","blockquote"]),Fn=pn.join(", "),bs=e=>ws.has(e.tagName)&&!ct(e)&&(C(e).length===0||pt(e,Fn))||fs(e),et=e=>D(e)?!Bt.test(e.value):(e.childNodes??[]).some(et),Kn=hs.filter(([,e])=>Sn.has(e)).map(([e])=>e),Hn=e=>bs(e)&&C(e).some(n=>Kn.includes(n)),ks=e=>e.childNodes.some(n=>D(n)&&!Bt.test(n.value))&&y(e).some(n=>lt.has(n.tagName)),Pn=/^[ \t\n\r\f]*/;function te(e){let n=[],f=[];for(let u of e)u.tagName&&Os.has(u.tagName)?(n.push(f),f=[]):f.push(u);n.push(f);let p=u=>!u.tagName&&!et(u),O=u=>(D(u)||u.tagName&&!$s.has(u.tagName))&&et(u);return n.map(u=>{let $=u.findIndex(m=>!p(m));return $<0?[]:u.slice($,u.findLastIndex(m=>!p(m))+1)}).filter(u=>u.some(O))}function Wn(e){let n=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="style"?n.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),n.flatMap(p=>[...p.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," ").matchAll(/([^{};]*)\{/g)].map(([,O])=>O))}var Un=(e,{tags:n=[],classes:f=[]})=>{let p=[...n.map(u=>`(?<![\\w.#-])${u}`),...f.map(u=>`\\.${u}`)],O=p.length?new RegExp(`(?:${p.join("|")})(?![\\w-])`,"i"):null;return!!O&&e.some(u=>O.test(u))};function zn(e){let n=[],f=p=>{for(let O of p.childNodes??[])O.tagName==="script"?n.push(O.childNodes.map(u=>u.value??"").join("")):O.tagName&&O.tagName!=="template"&&f(O)};return f(e),n.join(`
3
3
  `)}var de=["contains-task-list","task-list-item"],ue=["task-list-item"],Ls=["task-list-item-checkbox"],me=(e,n)=>C(e).every(f=>n.includes(f));function ys(e){let n=e.childNodes.find(f=>!V(f));return n?.tagName==="input"&&F(n,["type","checked","disabled","class"])&&w(n,"type")?.toLowerCase()==="checkbox"&&me(n,Ls)&&n.sourceCodeLocation?.startTag?n:null}var vs=e=>e.tagName==="li"&&me(e,ue)&&w(e,ce)===void 0&&e.sourceCodeLocation?.startTag&&ys(e),qn=e=>e.tagName==="ul"&&me(e,de)&&y(e).length>0&&e.childNodes.every(n=>n.tagName==="li"||V(n))&&y(e).every(vs),Jn={classes:[...new Set([...de,...ue,...Ls])]},Vn=/checkbox|task-list/i,ae=e=>e.tagName==="ol"&&(w(e,"data-doc-chart")==="flow"||w(e,"data-flow")!==void 0&&w(e,"data-doc-chart")===void 0),Xn=e=>e?.tagName==="ol"&&!ct(e)&&(C(e).includes(ht)||ae(e)),Zn=e=>e.tagName==="li"&&Xn(e.parentNode),_t="doc-icon",Qn=e=>e.some(n=>n.tagName==="strong"||n.tagName==="b")&&e.every(n=>n.tagName==="strong"||n.tagName==="b"||D(n)&&Bt.test(n.value)||n.nodeName==="#comment"),Yn=/^(?:inherit|unset|currentcolor|none)$/i,to=/^(?:inherit|initial|unset|revert|revert-layer|transparent|none)$/i,P=e=>e.replace(/\s+/g," ").trim(),ss=/^\s*--doc-(?:table-height|span)\s*:/i,eo=/^(?:p|h[1-4])$/,so=/^(center|right)$/i;function It(e){let n=e.replace(/\/\*[\s\S]*?(?:\*\/|$)/g," "),f=[],p="",O=0,u=0;for(let $=0;$<=n.length;$++){let m=n[$];p?m==="\\"?$++:m===p&&(p=""):m==='"'||m==="'"?p=m:m==="("?O++:m===")"?O=Math.max(0,O-1):(m===";"&&O===0||$===n.length)&&(f.push(n.slice(u,$)),u=$+1)}return f.filter($=>$.trim())}function Cs(e){let n=new Map;for(let r of It(e)){let N=r.indexOf(":"),i=P(N<0?r:r.slice(0,N)).toLowerCase();n.set(i==="background-color"?"background":i,N<0?"":P(r.slice(N+1).replace(/!\s*important\s*$/i,"")))}let f=[],p=[],O,u,$=new Set,m=(r,N,i)=>{if((r==="color"?Yn:to).test(N))return;let d=An(N);if(!d||d.a===0&&r==="color"){f.push(r);return}if(d.a===0)return;let g=i(N,{nearest:!0})?.replace(/_background$/,"");if(!g||!_n.has(g)){p.push(`${r} ${N} left out: the ${r==="color"?"text's":"page's"} own is the nearest`);return}return i(N)?.replace(/_background$/,"")!==g&&p.push(`${r} ${N} written as the kit's ${g}${r==="color"?"":" highlight"}`),g};for(let[r,N]of n)r==="color"?O=m(r,N,In):r==="background"?u=m(r,N,En):r==="font-weight"&&/^(?:bold|bolder|[6-9]\d\d)$/i.test(N)?$.add("strong"):r==="font-style"&&/^(?:italic|oblique)\b/i.test(N)?$.add("em"):(r==="text-decoration"||r==="text-decoration-line")&&/^(?:(?:underline|line-through|solid)\s*)+$/i.test(N)&&/underline|line-through/i.test(N)?(/underline/i.test(N)&&$.add("u"),/line-through/i.test(N)&&$.add("s")):f.push(r);if(f.length)return{foreign:[...new Set(f)]};let v=[];O&&v.push([`<span class="doc-text-${O}">`,"</span>"]),u&&v.push([`<span class="doc-highlight-${u}">`,"</span>"]);for(let r of["strong","em","u","s"])$.has(r)&&v.push([`<${r}>`,`</${r}>`]);return{open:v.map(([r])=>r).join(""),close:v.map(([,r])=>r).reverse().join(""),notes:p}}var ns=/^(?:language|lang)-([\w#+.-]+)$/,no=new Set(["data-language","data-lang","data-block-id"]),oo=[{name:Xe,names:[Xe,"data-start"],value:e=>mn(e)?.toString()??null,says:"the number of its first line is a whole number from 1"},{name:"data-line-numbers",names:["data-line-numbers"],value:e=>/^\s*(?:true|false)\s*$/i.test(e)?e.trim().toLowerCase():null,says:"false hides its line numbers, true shows them"},{name:Ve,names:[Ve],value:e=>hn(P(e))?P(e):null,says:"its folded lines are their numbers from 1, spaces between"}],os="data-title",as="data-wrap",ao=e=>y(e).length===1&&y(e)[0].tagName==="code"&&e.childNodes.every(n=>n.tagName||V(n))?y(e)[0]:null,io=new Set(["a","abbr","b","bdi","bdo","cite","code","data","del","dfn","em","font","i","ins","kbd","mark","q","s","samp","small","span","strike","strong","sub","sup","time","tt","u","var","br","wbr"]),co=new Set(["code","kbd","samp","tt","var"]);function xs(e){for(let n of e.childNodes){if(D(n))continue;if(!n.tagName)return"a comment in its <figcaption>";if(["img","picture","svg"].includes(n.tagName))return"a picture in its <figcaption>";if(!io.has(n.tagName))return`a <${n.tagName}> in its <figcaption>`;if(!n.sourceCodeLocation?.startTag||!(n.sourceCodeLocation.endTag||ne.has(n.tagName)))return`a <${n.tagName}> not closed in its <figcaption>`;let f=xs(n);if(f)return f}return""}function is(e){let n=y(e),f=n.filter(v=>v.tagName==="pre"),p=n.filter(v=>v.tagName==="figcaption");if(!f.length)return null;let[O]=f,[u=null]=p,$=e.childNodes.find(v=>!v.tagName&&!V(v)),m=f.length>1||p.length>1||n.length>f.length+p.length?"more than the pre and one <figcaption> in its <figure>":$?D($)?"words in its <figure> outside its caption":"a comment in its <figure>":u?Z(u).length?`its <figcaption> has an attribute of its own (${Z(u).join(", ")})`:u.sourceCodeLocation?.endTag?xs(u):"its <figcaption> is not closed in the file":"";return m?{pre:O,caption:u,why:m}:{pre:O,caption:u}}function At(e){let n=(e.attrs??[]).filter(({value:p})=>p.trim()),f=e.tagName==="abbr";return n.map(p=>`${p.name} ${JSON.stringify(P(p.value))} dropped: ${f&&p.name==="title"?"write the full name in the text":"write it in the text if the reader needs it"}`)}var z=e=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;");function ro(e){let n=new Set,f=p=>{for(let O of p.childNodes??[])if(O.tagName){for(let u of[tt,...bn])w(O,u)!==void 0&&n.add(w(O,u));f(O.tagName==="template"?O.content:O)}};return f(e),n}function lo(e){let n=new Map,f=p=>{for(let O of p.childNodes??[]){if(!O.tagName)continue;let u=w(O,"id");u!==void 0&&n.set(u,(n.get(u)??0)+1),f(O.tagName==="template"?O.content:O)}};return f(e),n}var fo=/^[A-Za-z][\w-]{0,63}$/;function uo(e){let n=We(e),f=rt(n,{sourceCodeLocationInfo:!0}),p=bt(f);if(!p)return{text:n,changes:[]};let O=[],u=[],$=t=>n.slice(0,t).split(`
4
4
  `).length,m=(t,s,o=[],l={})=>{let a=$(t.sourceCodeLocation.startOffset);o.length||u.push({line:a,rule:s,...l});for(let c of o)u.push({line:a,rule:s,note:c,...l})},v=0,r=(t,s,o,{opens:l=null,closes:a=null,move:c=null,leaves:h=!1}={})=>O.push({start:t,end:s,text:o,order:v++,opens:l,closes:a,move:c,leaves:h}),N=(t,s,o,l)=>{r(t,t,o,{opens:s}),r(s,s,l,{closes:t})},i=t=>t.sourceCodeLocation?.startTag,d=t=>t.sourceCodeLocation?.endTag,g=(t,s,{drop:o=[]}={})=>{let l=C(t).filter(h=>!o.includes(h)),a=[...l,...s.filter(h=>!l.includes(h))],c=t.sourceCodeLocation.attrs?.class;if(a.join(" ")!==C(t).join(" "))if(c&&a.length)r(c.startOffset,c.endOffset,`class="${z(a.join(" "))}"`);else if(c)x(t,"class");else{let h=i(t).startOffset+1+t.tagName.length;r(h,h,` class="${z(a.join(" "))}"`)}},x=(t,s)=>{let o=t.sourceCodeLocation.attrs[s],l=o.startOffset;for(;/[ \t\n\r\f]/.test(n[l-1]??"");)l--;r(l,o.endOffset,"")},A=(t,s,{classes:o=[],drop:l=[]}={})=>{let a=t.sourceCodeLocation,c=Object.entries(a.attrs??{}).filter(([L])=>L!=="class"&&!l.includes(L)).map(([,L])=>` ${n.slice(L.startOffset,L.endOffset)}`).join(""),h=[...o,...C(t).filter(L=>!o.includes(L))];return`<${s}${h.length?` class="${z(h.join(" "))}"`:""}${c}>`},M,q=t=>Un(M??=Wn(f),t),Q,Ms=t=>t.test(Q??=zn(f)),K=(t,s,o)=>{r(i(t).startOffset,i(t).endOffset,s),d(t)&&r(d(t).startOffset,d(t).endOffset,o)},Rt=t=>K(t,"",""),W=t=>!!(i(t)&&(d(t)||t.tagName==="img")),ge,pe=t=>{let s=w(t,"id");if(t.tagName!=="dialog"||!F(t,["id"])||!fo.test(s??"")||!W(t))return!1;let o=y(t);return!(o.length?Ns.has(o[0].tagName)&&W(o[0]):t.childNodes.some(a=>!V(a)&&a.nodeName!=="#comment"))||o.some(a=>a.tagName==="form")?!1:(ge??=lo(f),ge.get(s)===1)},Rs=t=>{let s=y(t)[0];return!pt(s,ee.short)||Z(s).length?null:t.childNodes.slice(0,t.childNodes.indexOf(s)).every(V)?s:null},Ne=t=>t.tagName==="dialog"&&(C(t).includes("doc-dialog")||pe(t)),Dt=(t,s=[])=>{for(let o of t.childNodes??[])if(o!==p){if(it(o)){at(o).forEach(l=>Dt(l,s));continue}Ne(o)&&W(o)?s.push(o):Dt(o,s)}return s},Gt=d(p)?Dt(f):[],Oe,Ds=t=>(Oe??=new Set((function s(o,l=[]){for(let a of o.childNodes??[])if(a.tagName){if(it(a)){at(a).forEach(c=>s(c,l));continue}Ne(a)&&l.push(w(a,"id")),s(a,l)}return l})({childNodes:[p,...Gt]})),/^#./.test(t??"")&&Oe.has(t.slice(1))),Gs=t=>{let[s,...o]=y(t);if(!s||o.length||!C(s).includes("doc-dialog-panel"))return null;let[l,a,...c]=y(s);if(c.length||!l||!a||!C(l).includes(dt.header)||!C(a).includes("doc-dialog-content"))return null;let h=T=>T.childNodes.some(_=>!_.tagName&&!V(_)&&_.nodeName!=="#comment");if(h(s)||h(l)||!W(l)||!i(a))return null;let L=y(l),b=L.filter(T=>C(T).includes(dt.title)),S=L.filter(T=>!b.includes(T)),E=T=>(C(T).includes(dt.close)||w(T,dt.closeAttribute)!==void 0)&&W(T);return b.length!==1||!W(b[0])||S.length>1||!S.every(E)?null:{header:l,title:b[0],close:S[0]??null,content:a}},Nt,$e=(t,s=[])=>{for(let o of t.childNodes??[])if(o.tagName){for(let{name:l,value:a}of o.attrs)l!=="id"&&l!=="class"&&s.push(a);(o.tagName==="script"||o.tagName==="style")&&s.push(o.childNodes.map(l=>l.value??"").join("")),$e(o,s)}return s},Fs=(t,s)=>{Nt??=$e(f).join(`
5
5
  `);let o=0;for(let l=Nt.indexOf(t);l>=0;l=Nt.indexOf(t,l+t.length))!/[\w-]/.test(Nt[l-1]??"")&&!/[\w-]/.test(Nt[l+t.length]??"")&&o++;return o>(s?1:0)};function Ks(t){let s=Gs(t);if(!s)return;let{header:o,title:l,close:a,content:c}=s,h=w(l,"id"),L=!!h&&w(t,"aria-labelledby")?.trim()===h;L&&x(t,"aria-labelledby"),r(i(o).startOffset,i(o).endOffset,n.slice(i(c).startOffset,i(c).endOffset));let b=i(l).startOffset+1;r(b,b+l.tagName.length,"h3"),g(l,[],{drop:[dt.title]}),h!==void 0&&!(h&&Fs(h,L))&&x(l,"id"),r(d(l).startOffset,d(l).endOffset,"</h3>"),a&&r(a.sourceCodeLocation.startOffset,a.sourceCodeLocation.endOffset,""),r(d(o).startOffset,d(o).endOffset,""),r(i(c).startOffset,i(c).endOffset,"")}let Ft=t=>{for(let s of t.childNodes??[]){if(it(s)){at(s).forEach(Ft);continue}s.tagName&&pt(s,ee.match)&&Ks(s),Ft(s)}},we=new Set;function be(t){let s=t.tagName;if(!W(t))return!1;let o=[];if(s==="mark"&&F(t,[]))K(t,'<span class="doc-highlight-yellow">',"</span>");else if((s==="del"||s==="strike")&&F(t,["cite","datetime"]))K(t,"<s>","</s>"),o=At(t);else if(s==="ins"&&F(t,["cite","datetime"]))K(t,"<u>","</u>"),o=At(t);else{if(["kbd","samp","tt","var"].includes(s)&&F(t,[]))return K(t,"<code>","</code>"),we.add(t),m(t,s),!0;if(s==="a"&&F(t,["href"])&&Ds(w(t,"href")))return g(t,[Cn]),m(t,"dialog link"),!1;if(s==="small"&&F(t,[]))K(t,'<span class="doc-text-gray">',"</span>");else if(s==="q"&&F(t,["cite"]))K(t,"\u201C","\u201D"),o=At(t);else if(["abbr","cite","dfn","time","bdi","data"].includes(s)&&F(t,["title","datetime","value"]))Rt(t),o=At(t);else if(s==="span"&&F(t,[])||s==="font"&&F(t,["color"])&&!w(t,"color")?.trim())Rt(t);else if(s==="span"&&F(t,["style"])||s==="font"&&F(t,["color"])){let l=Cs(s==="span"?w(t,"style")??"":`color: ${w(t,"color")}`);if(l.foreign)return!1;K(t,l.open,l.close),o=l.notes}else return!1}return we.add(t),m(t,s,o),!1}function Hs(t){let{startOffset:s,endOffset:o}=t.sourceCodeLocation,l=n.slice(s,o);for(let a of l.matchAll(Rn))N(s+a.index,s+a.index+a[0].length,'<span class="doc-math-inline">',"</span>"),u.push({line:$(s+a.index),rule:"formula"})}let Kt=new Set,ke=new Set;function kt(t,s=()=>!1){for(let o of te(t)){if(!o.every(b=>b.tagName?i(b)&&(d(b)||ne.has(b.tagName))&&!oe(b):b.sourceCodeLocation))continue;let l=o[0].sourceCodeLocation.startOffset,a=o.at(-1).sourceCodeLocation.endOffset,c=n.slice(l,a),h=l+Pn.exec(c)[0].length,L=a-/[ \t\n\r\f]*$/.exec(c)[0].length;if(o.every(D)&&wt(n.slice(h,L)))N(h,L,'<div class="doc-math-block">',"</div>"),u.push({line:$(h),rule:"display formula"}),o.forEach(b=>ke.add(b));else if(s(o)){let b=Qn(o);N(h,L,b?"<p>":"<p><strong>",b?"</p>":"</strong></p>"),u.push({line:$(h),rule:"step title",...ye(o[0].parentNode)}),o.forEach(S=>Kt.add(S))}else N(h,L,"<p>","</p>"),u.push({line:$(h),rule:"loose words"}),o.forEach(b=>Kt.add(b))}}let Ps=t=>t[0].parentNode.childNodes.slice(0,t[0].parentNode.childNodes.indexOf(t[0])).every(s=>!s.tagName||C(s).includes(_t)),Le=new Set,ye=t=>Le.has(t.parentNode)?{}:(Le.add(t.parentNode),{note:"a step's own words written as its title, the first block of its node: <li><p><strong>\u2026</strong></p> then its content (a paragraph, a list\u2026)</li>"}),Ws=t=>{if(kt(t.childNodes,Ps),t.childNodes.filter(a=>a.tagName&&!C(a).includes(_t)).length>0||te(t.childNodes).length>0||!i(t)||!d(t))return;let l=t.childNodes.filter(a=>a.tagName).at(-1)?.sourceCodeLocation?.endOffset??i(t).endOffset;r(l,l,"<p></p>"),u.push({line:$(l),rule:"step title",...ye(t)})},Ht,ve=()=>{Ht??=ro(f);let t=kn(Ht);return Ht.add(t),t},Us=(t,s)=>`<div data-doc-chart="${z(w(t,"data-doc-chart"))}" ${wn}="${z(s)}"></div>`,Ot=n.includes(`\r
@@ -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{a as Je,b as Qe,c as ge,e as At,h as Xe,i as tn}from"./chunk-VFX2KNHP.mjs";import{A as Ye,B as We,C as Te,D as Q,E as Ze,a as me,g as Oe,h as He,j as Ne,l as Fe,m as wt,n as ke,o as $e,p as ne,q as Ft,r as De,s as Ve,t as vt,u as Le,v as Ge,w as Me,x as kt,y as G,z as je}from"./chunk-VS7JIGJW.mjs";import{g as Ct}from"./chunk-HDWTZ763.mjs";import{b as pe,c as he,e as Ee}from"./chunk-A55HN5OK.mjs";import{BLOCK_TYPES as Ie,COPIED_AS_ITSELF as Kn,IDENTITY as gn}from"../browser/editor/components/registry.mjs";import{copyKeys as Un}from"../browser/editor/components/figure/index.mjs";import{accepts as xe,attributeValue as An,BLOCK_TYPES as Dt,boxRole as we,CHAPTER as En,holdsStraight as On,IDENTITY as Ke,isLead as rn,SIZES as Nn,sizeValue as ln,TOGGLES as an}from"../browser/editor/components/registry.mjs";import{iconMarkup as $n,iconValueOf as Ln,validIcon as Mn}from"../browser/editor/components/icon/index.mjs";Ee();import{attributeValue as bn,BLOCK_TYPES as en,HOSTS as xn,TOGGLES as wn}from"../browser/editor/components/registry.mjs";import{texSource as nn}from"../browser/editor/components/math/index.mjs";var Ce=new Set(Object.entries(en).filter(([,s])=>!s.box&&!s.bare).map(([s])=>s)),se=(s,m,I="")=>{let k=Q[m.type]?.leaf;if(k)return k(s,m,I);let g=[s.className,...m.classes??[]].filter(Boolean).join(" ");return`<${s.tag}${g?` class="${g}"`:""}${ke(m.attributes)}${I}>${m.html}</${s.tag}>`},Be=(s,m)=>s===void 0||!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(s).every(([I,k])=>typeof k=="string"&&bn(m,I,k)),qe=s=>s?.empty===!0,Pe=(s,m)=>s===void 0?null:I=>s.includes(m.slice(I.startOffset,I.endOffset));function ye(s,m,{empty:I=!1,file:k}={}){if(typeof m!="string"||!m.trim()&&!(I&&m===""))return!1;if(m==="")return!0;if(s.tex&&!nn(m))return!1;let g=s.inside??s.tag,$=`<${g}>${m}</${g}>`,[w,...u]=he($,{sourceCodeLocationInfo:!0}).childNodes;return u.length===0&&w?.tagName===g&&ge(w,[],s.inside!==void 0,{cell:g==="td"||g==="th",known:Pe(k,$)})===null}var vn=new Set(Object.values(en).filter(s=>s.text&&s.className).map(s=>s.kind));function ze(s,m){if(s.keep?.reason==="script")return null;if(s.kind==="list")return m.some(k=>k.unit===s.id&&k.kind==="list")?"list":null;let I=Q[s.kind];return I?.written?I.written(s)?"written":null:s.text===void 0||s.nested?null:["p","h1","h2","h3","h4","li"].includes(s.tag)||vn.has(s.kind)?"text":null}function be(s,m,I){if(!Array.isArray(m)||!m.every(g=>Sn(s,g,I)))return"invalid";let k=m.filter(g=>g.keep);return k.length>1?"invalid":m.length>k.length&&!s.caps.split||k.length===0&&!s.caps.remove||m.length===0&&s.nested?"fixed":k.length===1&&k[0].html.trim()===""&&!s.caps.empty?"empty":null}function sn(s,m,I){let k=`<table><tbody><tr><${s}>${m}</${s}></tr></tbody></table>`,[g,...$]=he(k,{sourceCodeLocationInfo:!0}).childNodes,w=$.length===0&&g?.tagName==="table"&&g.childNodes.length===1?g.childNodes[0]:null,u=w?.childNodes.length===1?w.childNodes[0]:null,h=u?.childNodes.length===1?u.childNodes[0]:null;return h?.tagName===s&&ge(h,[],!1,{cell:!0,known:Pe(I,k)})===null}var on={p:"paragraph",h1:"heading",h2:"heading",h3:"heading",h4:"heading",li:"item"},In=(s,m)=>s.classes===void 0||!s.keep&&Array.isArray(s.classes)&&new Set(s.classes).size===s.classes.length&&s.classes.every(I=>(wn[on[m]]??[]).includes(I));function Sn(s,m,I){if(!m||typeof m.html!="string"||xn[s.kind]?.tex&&!nn(m.html))return!1;let k=m.keep?s.tag:m.tag;if(!m.keep&&Je[s.tag]!==k||!In(m,k)||m.attributes!==void 0&&(m.keep||!Be(m.attributes,on[k])))return!1;let g=k==="td"||k==="th",$=g?`<table><tbody><tr><${k}>${m.html}</${k}></tr></tbody></table>`:`<${k}>${m.html}</${k}>`,[w,...u]=he($,{sourceCodeLocationInfo:!0}).childNodes;if(u.length>0||!w)return!1;let h=w;if(g){let p=w.tagName==="table"&&w.childNodes.length===1?w.childNodes[0]:null,f=p?.childNodes.length===1?p.childNodes[0]:null;h=f?.childNodes.length===1?f.childNodes[0]:null}return h?.tagName===k&&ge(h,[],Qe(s.kind,s.tag,s.caps),{cell:g,known:Pe(I,$)})===null}import{attr as cn}from"../browser/shared/html-tree.mjs";import{pageLanguage as jn}from"../browser/shared/components/page.mjs";import{SHEETS as Tn}from"../browser/editor/components/kit.mjs";import{BLOCK_ID as Cn}from"../browser/shared/ids.mjs";function fn({current:s,edits:m,units:I=[],partial:k=!1,ids:g=!1,touch:$=[],proposals:w=null}){let u=At(s),h=u.blocks,p=s.includes(`\r
2
+ import{a as Je,b as Qe,c as ge,e as At,h as Xe,i as tn}from"./chunk-KFZBYDIS.mjs";import{A as Ye,B as We,C as Te,D as Q,E as Ze,a as me,g as Oe,h as He,j as Ne,l as Fe,m as wt,n as ke,o as $e,p as ne,q as Ft,r as De,s as Ve,t as vt,u as Le,v as Ge,w as Me,x as kt,y as G,z as je}from"./chunk-7XDYK3UC.mjs";import{g as Ct}from"./chunk-VG5JEIUQ.mjs";import{b as pe,c as he,e as Ee}from"./chunk-N3DSBH5S.mjs";import{BLOCK_TYPES as Ie,COPIED_AS_ITSELF as Kn,IDENTITY as gn}from"../browser/editor/components/registry.mjs";import{copyKeys as Un}from"../browser/editor/components/figure/index.mjs";import{accepts as xe,attributeValue as An,BLOCK_TYPES as Dt,boxRole as we,CHAPTER as En,holdsStraight as On,IDENTITY as Ke,isLead as rn,SIZES as Nn,sizeValue as ln,TOGGLES as an}from"../browser/editor/components/registry.mjs";import{iconMarkup as $n,iconValueOf as Ln,validIcon as Mn}from"../browser/editor/components/icon/index.mjs";Ee();import{attributeValue as bn,BLOCK_TYPES as en,HOSTS as xn,TOGGLES as wn}from"../browser/editor/components/registry.mjs";import{texSource as nn}from"../browser/editor/components/math/index.mjs";var Ce=new Set(Object.entries(en).filter(([,s])=>!s.box&&!s.bare).map(([s])=>s)),se=(s,m,I="")=>{let k=Q[m.type]?.leaf;if(k)return k(s,m,I);let g=[s.className,...m.classes??[]].filter(Boolean).join(" ");return`<${s.tag}${g?` class="${g}"`:""}${ke(m.attributes)}${I}>${m.html}</${s.tag}>`},Be=(s,m)=>s===void 0||!!s&&typeof s=="object"&&!Array.isArray(s)&&Object.entries(s).every(([I,k])=>typeof k=="string"&&bn(m,I,k)),qe=s=>s?.empty===!0,Pe=(s,m)=>s===void 0?null:I=>s.includes(m.slice(I.startOffset,I.endOffset));function ye(s,m,{empty:I=!1,file:k}={}){if(typeof m!="string"||!m.trim()&&!(I&&m===""))return!1;if(m==="")return!0;if(s.tex&&!nn(m))return!1;let g=s.inside??s.tag,$=`<${g}>${m}</${g}>`,[w,...u]=he($,{sourceCodeLocationInfo:!0}).childNodes;return u.length===0&&w?.tagName===g&&ge(w,[],s.inside!==void 0,{cell:g==="td"||g==="th",known:Pe(k,$)})===null}var vn=new Set(Object.values(en).filter(s=>s.text&&s.className).map(s=>s.kind));function ze(s,m){if(s.keep?.reason==="script")return null;if(s.kind==="list")return m.some(k=>k.unit===s.id&&k.kind==="list")?"list":null;let I=Q[s.kind];return I?.written?I.written(s)?"written":null:s.text===void 0||s.nested?null:["p","h1","h2","h3","h4","li"].includes(s.tag)||vn.has(s.kind)?"text":null}function be(s,m,I){if(!Array.isArray(m)||!m.every(g=>Sn(s,g,I)))return"invalid";let k=m.filter(g=>g.keep);return k.length>1?"invalid":m.length>k.length&&!s.caps.split||k.length===0&&!s.caps.remove||m.length===0&&s.nested?"fixed":k.length===1&&k[0].html.trim()===""&&!s.caps.empty?"empty":null}function sn(s,m,I){let k=`<table><tbody><tr><${s}>${m}</${s}></tr></tbody></table>`,[g,...$]=he(k,{sourceCodeLocationInfo:!0}).childNodes,w=$.length===0&&g?.tagName==="table"&&g.childNodes.length===1?g.childNodes[0]:null,u=w?.childNodes.length===1?w.childNodes[0]:null,h=u?.childNodes.length===1?u.childNodes[0]:null;return h?.tagName===s&&ge(h,[],!1,{cell:!0,known:Pe(I,k)})===null}var on={p:"paragraph",h1:"heading",h2:"heading",h3:"heading",h4:"heading",li:"item"},In=(s,m)=>s.classes===void 0||!s.keep&&Array.isArray(s.classes)&&new Set(s.classes).size===s.classes.length&&s.classes.every(I=>(wn[on[m]]??[]).includes(I));function Sn(s,m,I){if(!m||typeof m.html!="string"||xn[s.kind]?.tex&&!nn(m.html))return!1;let k=m.keep?s.tag:m.tag;if(!m.keep&&Je[s.tag]!==k||!In(m,k)||m.attributes!==void 0&&(m.keep||!Be(m.attributes,on[k])))return!1;let g=k==="td"||k==="th",$=g?`<table><tbody><tr><${k}>${m.html}</${k}></tr></tbody></table>`:`<${k}>${m.html}</${k}>`,[w,...u]=he($,{sourceCodeLocationInfo:!0}).childNodes;if(u.length>0||!w)return!1;let h=w;if(g){let p=w.tagName==="table"&&w.childNodes.length===1?w.childNodes[0]:null,f=p?.childNodes.length===1?p.childNodes[0]:null;h=f?.childNodes.length===1?f.childNodes[0]:null}return h?.tagName===k&&ge(h,[],Qe(s.kind,s.tag,s.caps),{cell:g,known:Pe(I,$)})===null}import{attr as cn}from"../browser/shared/html-tree.mjs";import{pageLanguage as jn}from"../browser/shared/components/page.mjs";import{SHEETS as Tn}from"../browser/editor/components/kit.mjs";import{BLOCK_ID as Cn}from"../browser/shared/ids.mjs";function fn({current:s,edits:m,units:I=[],partial:k=!1,ids:g=!1,touch:$=[],proposals:w=null}){let u=At(s),h=u.blocks,p=s.includes(`\r
3
3
  `)?`\r
4
4
  `:`
5
5
  `,f=[],O=[],j=[],K=new Map,q=null,X,xt=!1,tt=(t,n)=>f.push({unit:t.id,reason:n}),et=t=>{let o=Ft(t).replace(/[0-9.]/g,l=>String.fromCharCode(l.charCodeAt(0)-65248)).replace(/[\s,,]/g,"").replace(/[−–]/g,"-").match(/-?\d+(?:\.\d+)?/)?.[0];return o===void 0?null:Number(o)},ht=(t,n,o)=>{if(t.kind!=="cell")return;let l=s.slice(t.start,t.innerStart),a=/\sdata-sort-value(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+)))?/.exec(l);if(!a)return;let d=(a[1]??a[2]??a[3]??"").trim(),x=/^-?\d+(\.\d+)?(e[-+]?\d+)?$/i.test(d)?Number(d):null,[S,c]=[et(s.slice(t.innerStart,t.innerEnd)),et(n)],b="";x!==null&&c!==null?b=` data-sort-value="${Number((c*(S?x/S:1)).toPrecision(12))}"`:x!==null&&S===null&&(b=a[0]),b!==a[0]&&O.push({start:t.start+a.index,end:t.start+a.index+a[0].length,text:b,of:[{id:o}]})},Vt=t=>{t.keep&&ee(t)?tt(t,"referenced"):j.push({start:t.start,end:t.end},...t.companion?[t.companion]:[])},oe=(t,n)=>{let o=t.classAttr,l=o?o.value.split(/\s+/).filter(Boolean):[],a=l;for(let[x,S]of n)a=S?a.includes(x)?a:[...a,x]:a.filter(c=>c!==x);if(a.join(" ")===l.join(" "))return;if(ut(t),!o){let x=/^<[A-Za-z][\w-]*/.exec(s.slice(t.elStart,t.elStart+40));if(!x)return tt(t,"unknown");let S=t.elStart+x[0].length;O.push({start:S,end:S,text:` class="${a.join(" ")}"`});return}if(a.length===0){O.push({...ne(s,o.start,o.end),text:""});return}let d=/=\s*'/.test(s.slice(o.start,o.end))?"'":'"';O.push({start:o.start,end:o.end,text:`class=${d}${a.join(" ")}${d}`})},It=typeof g=="function"?g:g?Xe:null,ct=new Set([...s.matchAll(tn)].map(t=>t[1]??t[2])),qt=()=>{for(;;){let t=It();if(!ct.has(t))return ct.add(t)&&t}},re=[],Pt=[],Gt=t=>t?` ${Ke}="${t}"`:"",le=t=>typeof t=="string"&&Cn.test(t)&&!ct.has(t),ft=(t,n)=>{let o=It?le(n)?(ct.add(n),n):qt():null;return o&&t!==void 0&&Pt.push({key:t,id:o}),Gt(o)},ot=new Set,zt=t=>{ot.add(t.at);let n=w?.get(t.id),o=It?le(n)?(ct.add(n),n):qt():null;return o&&re.push({at:t.at,id:o}),Gt(o)},ut=t=>{if(!It||!t||t.blockId||t.at===void 0||ot.has(t.at))return;let n=$e(s,t.at);O.push({start:n,end:n,text:zt(t)})},St=t=>{let{element:n,source:o}=vt(t.restore),l=n.sourceCodeLocation,a=cn(n,Ke);if(a&&!ct.has(a))return ct.add(a),t.key!==void 0&&Pt.push({key:t.key,id:a}),o;let d=o,x=l.startTag.endOffset-1;if(a){let S=l.attrs[Ke],c=ne(d,S.startOffset,S.endOffset);d=d.slice(0,c.start)+d.slice(c.end),x-=c.end-c.start}return x=$e(d,x),d.slice(0,x)+ft(t.key,t.blockId)+d.slice(x)},gt=t=>{let n=null;for(let o of u.units)o.elStart<=t.start&&t.start<o.end&&(!n||o.elStart>n.elStart)&&(n=o);return n},_=new Set;for(let t of m){let{id:n,parts:o}=t??{},l=Number.isInteger(n)?h[n]:void 0;if(!l){f.push({id:n,reason:"unknown"});continue}if(Array.isArray(o)&&o.length===0&&l.self!==null&&u.units[l.self].keep){f.push({id:n,reason:"referenced"});continue}let a=be(l,o,s);if(a){f.push({id:n,reason:a});continue}if(o.length===0){let N={...je(s,l.start,l.end),of:[{id:n}]};O.push(N),K.set(n,N),l.self!==null&&_.add(l.self);continue}let d=G(s,l.start),x=d===null?"":p+d,S=N=>`<${N.tag}${N.classes?` class="${N.classes.join(" ")}"`:""}${ke(N.attributes)}${ft(N.key,N.blockId)}>${N.html}</${N.tag}>`,c=o.findIndex(N=>N.keep),b=gt(l),v=b&&b.at===l.innerStart-1;if((!v||l.tag==="li")&&ut(b),l.tag==="li"&&c>=0){let N=o.slice(0,c),z=o.slice(c+1),C=b?{start:b.start,end:b.end}:null;O.push({start:l.innerStart,end:l.innerEnd,text:o[c].html,of:[{id:n}]}),N.length>0&&O.push({start:l.start,end:l.start,seq:1/0,text:N.map(S).join(x)+x,edge:C,of:[{id:n}]}),z.length>0&&O.push({start:l.end,end:l.end,text:x+z.map(S).join(x),edge:C,of:[{id:n}]})}else{let N=s.slice(l.start,l.innerStart);if(v&&It&&!b.blockId&&!ot.has(b.at)&&(N=`${N.slice(0,-1)}${zt(b)}>`),o.length===1&&c===0&&N===s.slice(l.start,l.innerStart)){O.push({start:l.innerStart,end:l.innerEnd,text:o[0].html,of:[{id:n}]}),ht(l,o[0].html,n),l.kind==="title"&&(q={from:Ft(s.slice(l.innerStart,l.innerEnd)),to:Ft(o[0].html)});continue}let z=o.map(C=>C.keep?N+C.html+s.slice(l.innerEnd,l.end):S(C)).join(x);O.push({start:l.start,end:l.end,text:z,of:[{id:n}]})}l.kind==="title"&&(q={from:Ft(s.slice(l.innerStart,l.innerEnd)),to:Ft(o[0].html)})}let Y=(t,n,o)=>{let l=u.units.filter(c=>c.box===t),a=[];for(let c=1;c<l.length;c++){let b=s.slice(l[c-1].end,l[c].start);b.trim()||a.push({pair:[l[c-1],l[c]],gap:b})}let d=a.find(({pair:c})=>c.includes(n))??a[0];if(d)return d.gap.replace(/\r?\n/g,p);let x=G(s,o.start),S=we(u.boxes[t]?.kind)==="root"?p:"";return x===null?"":S+p+x},Yt=t=>{if(t.kind!=="nest"||G(s,t.innerEnd)!==null)return null;let n=u.units[t.unit];return n?G(s,n.elStart):null},Wt=(t,n)=>{let o=s.slice(t.at+1,t.innerEnd).match(/\n([ \t]*)\S/);return o?o[1]:`${n??""} `},Kt=(t,n)=>n!==null&&we(t.kind)==="root",mt=[],Zt=(t,n,o,l)=>{let a=Number.isInteger(n?.into)?u.boxes[n.into]:null,d=Number.isInteger(n?.after),x=a?null:u.units[d?n.after:n?.before],S=a??(x?u.boxes[x.box]:null),c=z=>z>=t.start&&z<t.end;if(!S||!(xe(S.kind,te(t))||l===S.kind)||t.kind==="tab"&&S.id!==t.box||x&&(x===t||!o.has(x.id)||c(x.elStart))||a&&c(S.at))return tt(t,"position");let b=G(s,t.start);if(ut(t),a){if(a.innerEnd===null)return tt(t,"missing");let z=Yt(a);if(z!==null){mt.push({start:t.start,end:t.end,at:a.innerEnd,seq:lt++,from:b,to:z+nt,wrap:R=>p+z+nt+R+p+z});return}let C=G(s,a.innerEnd),W=Wt(a,C),T=C!==null&&W.startsWith(C)?W.slice(C.length):" ",P=Kt(a,C);mt.push({start:t.start,end:t.end,at:P?a.innerEnd-C.length:a.innerEnd,seq:lt++,from:b,to:W,wrap:R=>C===null?R:P?C+T+R+p:T+R+p+C});return}let v=Y(x.box,x,x),N=d?v.includes(`
@@ -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{a as ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-HXG7EOPJ.mjs";import{a as $t}from"./chunk-ZTHICSSF.mjs";import{b as fe,c as wt,e as K,f as he,i as ue,j as pe,m as me,n as ge,o as $e,p as we,q as be,r as bt}from"./chunk-6N3PX4XX.mjs";import{a as mt}from"./chunk-PAREWQGB.mjs";import{a as oe,b as se,c as ne,d as ie,e as ae,f as re,g as ce,h as le,l as de}from"./chunk-BFJGHSQN.mjs";import{b as gt,c as Xt,d as Qt,e as te,g as ee}from"./chunk-U5XL7D6A.mjs";import{a as w,b as Yt,c as qt}from"./chunk-HYMEEXKN.mjs";import{g as E,j as Jt,l as Vt,m as Zt}from"./chunk-HDWTZ763.mjs";import{existsSync as yo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function ve(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(e=>{if(!e||!["added","removed","unchanged"].includes(e.type)||typeof e.content!="string"||/[\r\n]/.test(e.content))throw new Error("diff: each line needs a valid type and single-line content.");if(e.lineNumber!=null&&(!Number.isInteger(e.lineNumber)||e.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as yt,isInstance as Bo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Ho}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Oe,hasClass as Ko,walk as xt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Go,CHART_KEY as Jo,CHART_SOURCE as C,VIEW_FROM as et,cellWords as Vo,rowsReading as Ee,tableRows as Zo}from"../browser/shared/table-chart.mjs";var Yo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Te=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Te).join("");function qo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Oe(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Vo(Te(s)):""}function Le(t,e,s=w(t)){let o=[];return xt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let r=n.childNodes.find(Yo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:r?r.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Go),tag:n.tagName,holder:n.parentNode?.tagName,title:qo(n)})},yt),o}var Xo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",ot=(t,e)=>Le(t,s=>Xo(s)?void 0:F(s,"data-doc-chart"),e),Qo=t=>Le(t,e=>Ko(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return xt(t,s=>{let o=F(s,C);if(o===void 0||!s.sourceCodeLocation)return;(e.get(o)??e.set(o,[]).get(o)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Oe(s).find(i=>i.tagName==="table")??null})},{...yt,inTemplates:!1}),e}function St(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${C}="${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 ${C}="${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:o,table:n}]=s;if(!n)return{error:`the frame carrying ${C}="${t}" (line ${o}) holds no table`};let i=$t(n),r=Zo(i);return r.error?{error:`its table (line ${o}) ${r.error}`}:{...r,line:o,cells:i}}function Nt(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>tt(n,"kit.js")??"")].join(`
2
+ import{a as ke,b as X,c as Q,f as ye,g as L,h as xe,i as tt,l as Se,m as Ne}from"./chunk-SAHS56QM.mjs";import{a as $t}from"./chunk-KH24LWAT.mjs";import{b as fe,c as wt,e as K,f as he,i as ue,j as pe,m as me,n as ge,o as $e,p as we,q as be,r as bt}from"./chunk-YFJU3O7G.mjs";import{a as mt}from"./chunk-NWRZXELO.mjs";import{a as oe,b as se,c as ne,d as ie,e as ae,f as re,g as ce,h as le,l as de}from"./chunk-G4YP7GVC.mjs";import{b as gt,c as Xt,d as Qt,e as te,g as ee}from"./chunk-DHB7UZ7F.mjs";import{a as w,b as Yt,c as qt}from"./chunk-2RKIHJI2.mjs";import{g as E,j as Jt,l as Vt,m as Zt}from"./chunk-VG5JEIUQ.mjs";import{existsSync as yo,readFileSync as yi,readdirSync as xi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function ve(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(e=>{if(!e||!["added","removed","unchanged"].includes(e.type)||typeof e.content!="string"||/[\r\n]/.test(e.content))throw new Error("diff: each line needs a valid type and single-line content.");if(e.lineNumber!=null&&(!Number.isInteger(e.lineNumber)||e.lineNumber<1))throw new Error("diff: lineNumber must be a positive integer.")})}import{BODY as yt,isInstance as Bo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Ho}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Oe,hasClass as Ko,walk as xt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Go,CHART_KEY as Jo,CHART_SOURCE as C,VIEW_FROM as et,cellWords as Vo,rowsReading as Ee,tableRows as Zo}from"../browser/shared/table-chart.mjs";var Yo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Te=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Te).join("");function qo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Oe(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Vo(Te(s)):""}function Le(t,e,s=w(t)){let o=[];return xt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let r=n.childNodes.find(Yo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:r?r.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Go),tag:n.tagName,holder:n.parentNode?.tagName,title:qo(n)})},yt),o}var Xo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",ot=(t,e)=>Le(t,s=>Xo(s)?void 0:F(s,"data-doc-chart"),e),Qo=t=>Le(t,e=>Ko(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return xt(t,s=>{let o=F(s,C);if(o===void 0||!s.sourceCodeLocation)return;(e.get(o)??e.set(o,[]).get(o)).push({line:s.sourceCodeLocation.startLine,offset:s.sourceCodeLocation.startOffset,table:Oe(s).find(i=>i.tagName==="table")??null})},{...yt,inTemplates:!1}),e}function St(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${C}="${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 ${C}="${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:o,table:n}]=s;if(!n)return{error:`the frame carrying ${C}="${t}" (line ${o}) holds no table`};let i=$t(n),r=Zo(i);return r.error?{error:`its table (line ${o}) ${r.error}`}:{...r,line:o,cells:i}}function Nt(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>tt(n,"kit.js")??"")].join(`
3
3
  `),s=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([a-z][a-z0-9-]*)\1/g)].map(n=>n[2])),o=new Set([...e.matchAll(/DocCharts\.define\(\s*(["'`])([^"'`\n]*)\1/g)].map(n=>n[2]).filter(n=>!s.has(n)));return{defined:s,misnamed:o}}function vt(t){let e=w(t),s=[],{defined:o,misnamed:n}=Nt(t),i=null;for(let{type:r,line:c,text:l,source:a,tag:d,holder:f}of ot(t,e)){let u=`data-doc-chart="${r}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${u} 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`:`${u} 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(r)){s.push(`${u}: the document's script defines "${r}" 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(!o.has(r)){s.push(`${u}: the document's script does not define "${r}": define it once in the document's <script> with DocCharts.define("${r}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(a!==void 0){if(l!==null){s.push(`${u}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let h=St(a,i??=G(e));h.error&&s.push(`${u}: ${h.error}`);continue}if(l===null){s.push(`${u} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(h){s.push(`${u}: its data is not valid JSON (${h.message})`)}}s.push(...Ce(e,i??=G(e)).failures);for(let{line:r,text:c}of Qo(t)){if(c===null)continue;let l=`.doc-diff (line ${r})`;try{ve(JSON.parse(c))}catch(a){s.push(`${l}: ${a instanceof SyntaxError?`its options are not valid JSON (${a.message})`:a.message}`)}}return s}function Ae(t,{written:e=t}={}){let s=w(t),o=[],{defined:n}=Nt(t),i=null,r=null;for(let{type:c,line:l,text:a,source:d,title:f,tag:u}of ot(t,s)){if(d===void 0||u==="table"||a!==null||!n.has(c))continue;let h=`data-doc-chart="${c}" (line ${l})`;if(!f){r??=new Set(e===t?[]:ot(e).map(k=>k.source).filter(k=>k!==void 0));let b=e!==t&&!r.has(d);o.push(`${h}: 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=St(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=Ee(m.cells,m.data);p&&o.push(`${h}: 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&&o.push(`${h}: 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 o.push(...Ce(s,i??=G(s)).notes),o}var kt=500;function Ce(t,e){let s=[],o=[],n=E().packages;return xt(t,i=>{let r=F(i,et);if(r===void 0||!i.sourceCodeLocation)return;let c=F(i,Ho),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Bo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${et}="${r}", 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(!Jo.test(r))return void s.push(`${l}: ${et}="${r}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${C}`);let a=e.get(r)??[];if(a.length===0)return void s.push(`${l}: no table's frame carries ${C}="${r}", so the view has no table to read: put the table back, or delete the view`);if(a.length>1)return void s.push(`${l}: ${a.length} tables carry ${C}="${r}" (lines ${a.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:u}]=a;if(!u)return void s.push(`${l}: the frame carrying ${C}="${r}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&o.push(`${l} stands before the table it reads (${C}="${r}", 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 h=n.get(c)?.needs;h&&!h.includes("tables")&&o.push(`${l} carries ${et}="${r}", 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(u);m.merged&&o.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>kt&&o.push(`${l}: its table (line ${d}) has ${p} rows: every view of a table reads it again as it is typed in, and past ${kt} rows that slows typing in it; split it, or keep what a view shows to ${kt} rows`)},yt),{failures:s,notes:o}}function ze(t){let e=w(t),s=[],o=[],{defined:n}=Nt(t),i=null,r=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:a,source:d,tag:f}of ot(t,e)){if(d===void 0||f==="table"||a!==null||!n.has(c))continue;let u=St(d,i??=G(e));if(u.error)continue;let{rows:h,columns:m,foot:p,extra:g}=Ee(u.cells,u.data),b=`data-doc-chart="${c}" (line ${l})`,k=[r(h,"row")];for(let{name:x,numbers:v,words:T,empty:H}of m){let R=v+T+H,q=v===R&&R>0?"numbers":T===R&&R>0?"words":[v&&r(v,"number"),T&&`${T} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${q}`),v>0&&T>0&&o.push(`${b}: its table's column "${x}" (line ${u.line}) reads as numbers in ${r(v,"row")} and as words in ${T}: 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&&o.push(`${b}: its table's <tfoot> (line ${u.line}) holds ${r(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&&o.push(`${b}: ${r(g,"row")} of its table (line ${u.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 ${u.line}): ${k.join("; ")}`)}return{readings:s,notes:o}}import{BODY as Si,componentOf as Ni,matchesNode as xo}from"../browser/shared/components/index.mjs";import{FLOW as vi}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as So,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as Oi,ICON_COLORS as No,glyphOf as Ei,glyphValue as Ti,iconKind as Ut,iconMarkup as Li,iconValueOf as Ai}from"../browser/shared/emoji/icon-value.mjs";import ts from"node:vm";import{LINE_START as it,lineStart as es}from"../browser/shared/code-lines.mjs";import{BODY as Me,COMPONENTS as os,FLOWS as ss,instanceSlots as ns,instancesOf as is,isInstance as _,isSlot as Pe,matchesNode as P,ownSlots as as,partOf as Lt,vocabulary as rs}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as A,INSTANCE as cs,PACKAGE_ID as at,SCHEMA as Ot,SLOT as z,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:nt,runtime:Ie}=rs(),gs="input, select, textarea, button, details, table",rt=t=>t.sourceCodeLocation?.startLine,$=t=>rt(t)?` (line ${rt(t)})`:"";function je(t){let e=(o,n)=>{let i=Array.from({length:n.length+1},(r,c)=>c);for(let r=1;r<=o.length;r++){let c=i[0];i[0]=r;for(let l=1;l<=n.length;l++){let a=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(o[r-1]===n[l-1]?0:1)),c=a}}return i[n.length]},[s]=[...nt.keys()].filter(o=>o.startsWith(t.slice(0,7))).map(o=>[o,e(t,o)]).sort((o,n)=>o[1]-n[1]);return s&&s[1]<=3?` (${s[0]}?)`:""}function $s(t,e,s){let{part:o,property:n,min:i}=t.shares,r=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>r.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let a=`${t.id}${$(e)}`;return l.length<c.length?[`${a}: ${n} on ${l.length} of its ${c.length} ${o}: 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)?[`${a}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var st={"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={[it]:'write it on its <div class="doc-code">',"data-start":`write ${it} 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 e=[],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&&e.push(`${n}${$(t)} on the <${t.tagName}> of a code block does nothing: ${i}`);let o=t.tagName==="div"&&P(t,".doc-code")?y(t,it):void 0;return o!==void 0&&es(o)===null&&e.push(`${it}="${o}"${$(t)}: the number of a code block's first line is a whole number from 1`),e}var Re=ss.join(", "),ks=t=>P(t.parentNode,Re)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Re);function ys(t,e){let s=[];J(e,n=>s.push(...ps(t,n)));let o=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},r)=>r===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${o(n)}; an editor keeping a file's \u201C\u2026\u201D style may change them`:`line ${i}: attribute ${n} uses curly quotes too: write ${o(n)}`)}var Fe={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 Ue(t){let e=[];return J(t,s=>{y(s,A)!==void 0&&e.push(s)},Me),e}var Ns=t=>{let e=t.parentNode;for(;e&&!(_(e)||Pe(e));)e=e.parentNode;return e??null};function vs(t,e){let s=[];return J(t,o=>{let n=y(o,z);if(n===void 0)return;if(_(o))return void s.push(`${z}="${n}"${$(o)} on the instance itself: a slot is an element inside it`);if(!Pe(o))return void s.push(`${z}${$(o)} on a <${o.tagName}>: a slot is a block-level <div> or <section>`);let i=Ns(o),r=i&&_(i)?e?.get(y(i,A)):null;if(!i||!_(i)||r&&We(i,r,o))return void s.push(`${z}="${n}"${$(o)} stands outside any instance's own markup: a slot is a part of a component package's instance, written in its template`);y(o,"data-block-id")!==void 0&&s.push(`${z}="${n}"${$(o)}: a slot is no block: it carries no data-block-id`)}),s}var Os=(t,e)=>{for(let s=e.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},We=(t,e,s)=>Object.values(e.parts??{}).filter(({edit:o})=>o==="text"||o==="data").some(({at:o})=>Lt(t,o).some(n=>Os(n,s))),_e=(t,e)=>as(t).filter(s=>!We(t,e,s)),Es=t=>t.flatMap(e=>_(e)?at.test(y(e,A))?[]:[`${A}="${y(e,A)}"${$(e)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${A}${$(e)} on a <${e.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Be(t){let e=Ue(t).filter(o=>_(o)&&at.test(y(o,A))),s=e.length>0?E():null;return e.flatMap(o=>{let n=y(o,A),i=s.packages.get(n);if(i&&!ls(y(o,Ot),i.schema))return[];if(i)return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${Ot}="${y(o,Ot)}" 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 r=s.problems.get(n)?.problem,c=r?`package ${n} does not load (${Jt("en",r)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${rt(o)}: <${o.tagName} ${A}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Et(t,e){let s=[];for(let{name:o,value:n}of t.attrs){if(st[o]&&!nt.has(o)){s.push(`${o}${$(t)} is gone: ${st[o]}`);continue}if(o.startsWith("data-doc-")&&!nt.has(o)&&s.push(Ie.has(o)?`${o}${$(t)} is the kit's to set: remove it`:`${o}${$(t)} is no attribute of the kit's${je(o)}`),o==="class"){for(let i of n.split(/\s+/).filter(e))if(!nt.has(i)){if(st[i]){s.push(`class ${i}${$(t)} is gone: ${st[i]}`);continue}s.push(Ie.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${je(fs(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var De=t=>t.startsWith("doc-");function Ts(t){try{return new ts.Script(ds(t),{filename:"kit.js"}),null}catch(e){let s=/^kit\.js:(\d+)/.exec(e.stack??"")?.[1];return{message:e.message,line:s?Number(s):null}}}var Tt=new Map;function Ls(t){if(!t.files.includes("kit.js"))return null;if(Tt.get(t.folder)?.stamp!==t.stamp){let e=tt(t,"kit.js"),s=e===null?null:Ts(e),o=e===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})`:""}`;Tt.set(t.folder,{stamp:t.stamp,failure:o})}return Tt.get(t.folder).failure}function At(t,e=w(t),s=null){let o=ys(t,e),n=Ue(e);o.push(...Es(n));let i=n.length>0?s??E():null,r=i?[...i.packages.values()]:[];i&&o.push(...L(t,i,e).map(Ls).filter(Boolean));for(let a of[...os,...r].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of is(e,a)){if(a.empty&&!(d.childNodes??[]).some(h=>h.tagName||h.nodeName==="#text"&&h.value.trim()))continue;let f=a.id==="sheets"?us(d):null;if(f){o.push(`${a.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(Fe[a.id]&&Object.values(a.parts??{}).some(h=>Lt(d,h.at).length<(h.optional?0:h.min??1))){o.push(`${a.id}${$(d)} carries the kit's class without the kit's parts: ${Fe[a.id]}`);continue}let u={};for(let[h,m]of Object.entries(a.parts??{})){if(m.edit==="flow"&&at.test(a.id)){let b=_e(d,a).filter(k=>y(k,z)===h);b.length===0&&!m.optional&&o.push(`${a.id}${$(d)} has no ${h} (${z}="${h}")`);for(let k of b.slice(1))o.push(`${a.id}${$(k)}: slot "${h}" twice`);u[h]=b.slice(0,1);continue}u[h]=Lt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;u[h].length<p?o.push(`${a.id}${$(d)} has ${u[h].length===0?"no":`${u[h].length} of`} ${h} (${m.at.replace(":scope > ","")})${u[h].length>0?`, at least ${p}`:""}`):u[h].length>g&&o.push(`${a.id}${$(d)} has ${u[h].length} of ${h}, at most ${g}`)}if(a.only){let h=new Set(a.only.flatMap(m=>u[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!h.has(p)))o.push(`${a.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${a.only.join(", ")} (${a.only.map(p=>a.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(a.shares&&o.push(...$s(a,d,u[a.shares.part])),at.test(a.id)){let h=Object.entries(a.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of _e(d,a).filter(p=>!h.includes(y(p,z))))o.push(`${a.id}${$(m)}: slot "${y(m,z)}" is no part of its manifest edited as flow`)}for(let{a:h,attrA:m,b:p,attrB:g}of a.pairs??[]){let b=u[h].map(x=>y(x,m)),k=u[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,T)=>b.indexOf(v)!==T)))o.push(`${a.id}${$(d)}: ${h} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))o.push(`${a.id}${$(d)}: ${h.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))o.push(`${a.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${h.replace(/s$/,"")} (${m}="${x}")`)}}o.push(...vs(e,i?.packages));let c=new Set,l=[];J(e,a=>{if(_(a)){let u=new Set(ns(a));o.push(...Et(a,De)),J(a,h=>o.push(...Et(h,De)),{stop:h=>u.has(h)});return}a.tagName==="pre"&&ks(a)&&o.push(`<pre>${$(a)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),o.push(...bs(a)),a.tagName==="a"&&ms(a,"doc-bookmark")&&o.push(`<a class="doc-bookmark">${$(a)} is no bookmark: ${Ss}`),o.push(...Et(a,hs));let d=y(a,"data-doc-bind");d!==void 0&&(d.trim()?P(a,gs)?a.tagName==="button"&&y(a,"value")===void 0?o.push(`data-doc-bind${$(a)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):o.push(`data-doc-bind${$(a)} on a ${a.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):o.push(`data-doc-bind${$(a)} names no key`));let f=y(a,"data-doc-show");f!==void 0&&l.push([a,f])},Me);for(let[a,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?o.push(`data-doc-show="${d}"${$(a)}: write key:value`):c.has(f)||o.push(`data-doc-show="${d}"${$(a)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return o.push(...Rs(t,e)),o}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,e){let s=[],o=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:r,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(r,c).matchAll(As)){if(!zs(l[1]))continue;let a=l[1].replace(/\s+/g," "),d=a.length>60?`${a.slice(0,59)}\u2026`:a;s.push(`line ${qt(t,r+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)&&o(i)};return o(e),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 Ua}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 He="data-ge-language",_s={"code-title":"--doc-word-code-title"};function Ds(t,e,s,...o){let n=t[s];if(!n)throw new Error(`The kit has no word "${s}" here (src/render/kit/words.js).`);let i=n[e]??n.zh;return o.length===0?i:i.replace(/\{(\d+)\}/g,(r,c)=>c<o.length?String(o[c]):r)}var Ms=`:root[${He}="en"], :root:not([${He}])[lang|="en" i]`;function Ke(){let t=e=>Object.entries(_s).map(([s,o])=>`${o}: ${JSON.stringify(Ds(Fs,e,s))};`).join(" ");return`:root { ${t("zh")} }
4
4
  ${Ms} { ${t("en")} }`}import{LOOK as Ct,LOOK_ATTRIBUTES as Ps,SERIF_FONT as Ge,SIZE_FACTOR as Us,SPACING as Ws,WIDTH as zt}from"../browser/shared/document-look.mjs";var Je=[["--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"],It="--doc-content-max-width";function Hs(t){let e=new Map;for(let[,s,o]of String(t).matchAll(/^\s*(--doc-[a-z0-9-]+):\s*([^;]+);/gm))e.has(s)||e.set(s,o.trim());return e}var ct=t=>`${Math.round(t)}px`;function lt(t,{size:e="default",spacing:s="default",width:o="default"}={}){let n=a=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(a)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${a} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Us[e],{leading:r,gaps:c}=Ws[s],l={};if(e!=="default"||s!=="default")for(let[a,d]of Je){let f=n(a)*i;e!=="default"&&(l[a]=ct(f)),l[d]=ct(Math.round(f)+(n(d)-n(a))*i*r)}if(s!=="default"){for(let a of Bs)l[a]=ct(n(a)*c);l["--doc-space"]=String(c)}if(o!=="default"){if(n(It)!==zt.default)throw new Error(`src/render/kit/styles/tokens.css: ${It} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${zt.default}px (src/shared/document-look.mjs WIDTH)`);l[It]=ct(zt[o])}return l}var U=(t,e)=>`${t} { ${Object.entries(e).map(([s,o])=>`${s}: ${o};`).join(" ")} }`,D=(t,e)=>`[${Ps[t]}="${e}"]`;function Ve(t){let e=Hs(t),s=e.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 o=[U(`:root${D("font","serif")}`,{"--doc-sans-font":s,"--doc-font":Ge}),U(`:root${D("font","mixed")}`,{"--doc-heading-font":Ge})],[,...n]=Ct.size,[,...i]=Ct.spacing,[,...r]=Ct.width;for(let c of n)o.push(U(`:root${D("size",c)}`,lt(e,{size:c})));for(let c of i)o.push(U(`:root${D("spacing",c)}`,lt(e,{spacing:c})));for(let c of r)o.push(U(`:root${D("width",c)}`,lt(e,{width:c})));for(let c of n)for(let l of i){let a=lt(e,{size:c,spacing:l});o.push(U(`:root${D("size",c)}${D("spacing",l)}`,Object.fromEntries(Je.map(([,d])=>[d,a[d]]))))}return o.join(`
5
5
  `)}var Ze=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),tr=Object.keys(Ze),Z=t=>W.join(Vs,t),Ys=(t,e,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof e=="function"?e():e,...s}),qs=t=>{let e=Ze[t];if(!e)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return e},dt=new Map;function Xs(t,e){let s=[...e.matchAll(/^@import\s+"\.\/([a-z0-9-]+\.css)";\s*$/gm)].map(i=>i[1]),o=V.readdirSync(W.dirname(Z(t))).filter(i=>i.endsWith(".css")&&i!==W.basename(t)),n=[...o.filter(i=>!s.includes(i)).map(i=>`${i} is not listed`),...s.filter((i,r)=>!o.includes(i)||s.indexOf(i)!==r).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,(e,s)=>Ks.map(o=>`.doc-${s}-${o}`).join(", ")),tn=t=>{let e=Qs(t.join(`
@@ -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{h as p}from"./chunk-ZWWC4KLF.mjs";import{g as k}from"./chunk-ZQS6H473.mjs";import{g as b}from"./chunk-MXUBKDRO.mjs";import{k as d}from"./chunk-6N3PX4XX.mjs";import v from"node:fs/promises";import h from"node:path";import{editStateDirectory as m,reportsDirectory as f}from"../browser/shared/paths.mjs";import{findPreviewServer as $}from"../browser/shared/preview-server.mjs";import{documentDirectory as S,documentFiles as g,isDocumentSource as j}from"../browser/shared/workspace.mjs";var u=e=>h.resolve(e),D=e=>h.basename(g(h.dirname(e)).json),N={busy:"it kept changing while it was being written (an Agent writing it?); nothing written. Run the export again.",timeout:"the workspace's Gallery server did not answer in 30s; nothing written. Run the export again."};async function w(e,n,o="hand-in",l=3e4){let t=`127.0.0.1:${e.port}`,s;try{s=await fetch(`http://${t}/__gallery/edit/${o}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${t}`,"X-Gallery-Token":e.token},body:JSON.stringify({slug:n,workspace:f}),signal:AbortSignal.timeout(l)})}catch(a){return a.name==="TimeoutError"?{ok:!1,reason:"timeout"}:null}let i=await s.json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin"].includes(i.reason)?null:i}async function P(e){let n=await $({reportsDirectory:f}),o=null,l=[],t=new Map,s=[];for(let i of e){let{html:a,json:c}=g(S(i,f)),r=n?await w(n,i):null;if(r===null&&(o??=p({reportsDirectory:f,stateDirectory:m,finish:d}),r=await o.handIn(i),r.ok&&await o.settleNotes(i)),!r.ok){r.reason!=="missing"&&t.set(i,[`${u(a)} was not handed in: ${N[r.reason]??r.message??r.reason}`]);continue}if(r.repeated?.length){t.set(i,b(r.repeated));continue}s.push(...L(a,r)),r.written&&(r.changes.length&&s.push(...k(a,r.changes,{reread:!1})),r.added&&s.push(...T(a,r.given,r.added)),l.push(u(a))),O(r)&&l.push(u(c))}return{written:l,failures:t,lines:s}}async function _(e){let n=await $({reportsDirectory:f});if(n){for(let o of e)if(await w(n,o,"settle")===null)return}}async function C(e,{wait:n=3e4}={}){try{let o=await $({reportsDirectory:f}),l=o?await w(o,e,"round",n):null;return l!==null?l.ok?l.ended===!0:null:await p({reportsDirectory:f,stateDirectory:m,finish:d}).beginRound(e)}catch{return null}}async function H(e){try{let n=p({reportsDirectory:f,stateDirectory:m,finish:d}),{html:o}=g(S(e,f));await n.noteTaken(e,await v.readFile(o,"utf8"))}catch{}}var O=({title:e=null,icon:n=null})=>!!(e&&typeof e.from=="string"&&e.from!==e.to||n&&!n.missing),x=10;function T(e,n,o=n?.length??0,{pending:l=!1}={}){let t=`${o} block${o===1?"":"s"}`;if(l){let i=[`ids ${u(e)}: ${t} without an id yet: the export gives ${o===1?"it":"each"} one`];return o>x?i:[...i,...n.map(({line:a,tag:c})=>` line ${a} ${c}`)]}let s=[`ids ${u(e)}: ${t} given an id`];return!n||o>x?s:[...s,...n.map(({line:i,tag:a,id:c})=>` line ${i} ${a} \u2192 ${c}`)]}function L(e,{title:n=null,icon:o=null}={},{pending:l=!1}={}){let t=u(h.dirname(e)),s=D(e),i=(c,r,y)=>l?`${c} not ${r} yet (${y}): the export writes ${c.includes(" and ")?"them":"it"}`:`${c} written ${r}: ${y}`,a=[];if(n){let c=[...n.page?["<title>"]:[],...typeof n.from=="string"&&n.from!==n.to?[`${s}'s title`]:[]];c.length&&a.push(`title ${t}: ${i(c.join(" and "),"as its h1 says it",JSON.stringify(n.to))}`)}return o?.missing?a.push(`icon ${t}: ${s} has the icon ${JSON.stringify(o.from)} and the page's header none: write it there (<div class="doc-icon">\u2026</div> before the h1) or take "icon" out of ${s} (the export leaves ${s}'s as it is)`):o&&a.push(`icon ${t}: ${i(`${s}'s icon`,"as its header has it",o.to===null?"none":JSON.stringify(o.to))}`),a}function K(e,{by:n="this export"}={}){let o=e.length===1,l=[...e.filter(t=>j(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the kit's markup, block ids`),...e.filter(t=>/^(doc|report)\.json$/.test(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the title or icon said above`)];return`Re-read ${e.join(", ")} before editing ${o?"it":"them"}: ${n} wrote ${o?"it":"them"} (${l.join("; ")}).`}export{P as a,_ as b,C as c,H as d,T as e,L as f,K as g};
2
+ import{h as p}from"./chunk-OU3S466R.mjs";import{g as k}from"./chunk-WTEGUPFG.mjs";import{g as b}from"./chunk-XMKHCUI6.mjs";import{k as d}from"./chunk-YFJU3O7G.mjs";import v from"node:fs/promises";import h from"node:path";import{editStateDirectory as m,reportsDirectory as f}from"../browser/shared/paths.mjs";import{findPreviewServer as $}from"../browser/shared/preview-server.mjs";import{documentDirectory as S,documentFiles as g,isDocumentSource as j}from"../browser/shared/workspace.mjs";var u=e=>h.resolve(e),D=e=>h.basename(g(h.dirname(e)).json),N={busy:"it kept changing while it was being written (an Agent writing it?); nothing written. Run the export again.",timeout:"the workspace's Gallery server did not answer in 30s; nothing written. Run the export again."};async function w(e,n,o="hand-in",l=3e4){let t=`127.0.0.1:${e.port}`,s;try{s=await fetch(`http://${t}/__gallery/edit/${o}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${t}`,"X-Gallery-Token":e.token},body:JSON.stringify({slug:n,workspace:f}),signal:AbortSignal.timeout(l)})}catch(a){return a.name==="TimeoutError"?{ok:!1,reason:"timeout"}:null}let i=await s.json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin"].includes(i.reason)?null:i}async function P(e){let n=await $({reportsDirectory:f}),o=null,l=[],t=new Map,s=[];for(let i of e){let{html:a,json:c}=g(S(i,f)),r=n?await w(n,i):null;if(r===null&&(o??=p({reportsDirectory:f,stateDirectory:m,finish:d}),r=await o.handIn(i),r.ok&&await o.settleNotes(i)),!r.ok){r.reason!=="missing"&&t.set(i,[`${u(a)} was not handed in: ${N[r.reason]??r.message??r.reason}`]);continue}if(r.repeated?.length){t.set(i,b(r.repeated));continue}s.push(...L(a,r)),r.written&&(r.changes.length&&s.push(...k(a,r.changes,{reread:!1})),r.added&&s.push(...T(a,r.given,r.added)),l.push(u(a))),O(r)&&l.push(u(c))}return{written:l,failures:t,lines:s}}async function _(e){let n=await $({reportsDirectory:f});if(n){for(let o of e)if(await w(n,o,"settle")===null)return}}async function C(e,{wait:n=3e4}={}){try{let o=await $({reportsDirectory:f}),l=o?await w(o,e,"round",n):null;return l!==null?l.ok?l.ended===!0:null:await p({reportsDirectory:f,stateDirectory:m,finish:d}).beginRound(e)}catch{return null}}async function H(e){try{let n=p({reportsDirectory:f,stateDirectory:m,finish:d}),{html:o}=g(S(e,f));await n.noteTaken(e,await v.readFile(o,"utf8"))}catch{}}var O=({title:e=null,icon:n=null})=>!!(e&&typeof e.from=="string"&&e.from!==e.to||n&&!n.missing),x=10;function T(e,n,o=n?.length??0,{pending:l=!1}={}){let t=`${o} block${o===1?"":"s"}`;if(l){let i=[`ids ${u(e)}: ${t} without an id yet: the export gives ${o===1?"it":"each"} one`];return o>x?i:[...i,...n.map(({line:a,tag:c})=>` line ${a} ${c}`)]}let s=[`ids ${u(e)}: ${t} given an id`];return!n||o>x?s:[...s,...n.map(({line:i,tag:a,id:c})=>` line ${i} ${a} \u2192 ${c}`)]}function L(e,{title:n=null,icon:o=null}={},{pending:l=!1}={}){let t=u(h.dirname(e)),s=D(e),i=(c,r,y)=>l?`${c} not ${r} yet (${y}): the export writes ${c.includes(" and ")?"them":"it"}`:`${c} written ${r}: ${y}`,a=[];if(n){let c=[...n.page?["<title>"]:[],...typeof n.from=="string"&&n.from!==n.to?[`${s}'s title`]:[]];c.length&&a.push(`title ${t}: ${i(c.join(" and "),"as its h1 says it",JSON.stringify(n.to))}`)}return o?.missing?a.push(`icon ${t}: ${s} has the icon ${JSON.stringify(o.from)} and the page's header none: write it there (<div class="doc-icon">\u2026</div> before the h1) or take "icon" out of ${s} (the export leaves ${s}'s as it is)`):o&&a.push(`icon ${t}: ${i(`${s}'s icon`,"as its header has it",o.to===null?"none":JSON.stringify(o.to))}`),a}function K(e,{by:n="this export"}={}){let o=e.length===1,l=[...e.filter(t=>j(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the kit's markup, block ids`),...e.filter(t=>/^(doc|report)\.json$/.test(h.basename(t))).map(t=>h.basename(t)).filter((t,s,i)=>i.indexOf(t)===s).map(t=>`${t}: the title or icon said above`)];return`Re-read ${e.join(", ")} before editing ${o?"it":"them"}: ${n} wrote ${o?"it":"them"} (${l.join("; ")}).`}export{P as a,_ as b,C as c,H as d,T as e,L as f,K as g};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j}from"./chunk-AR5D57ZD.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-7OG26PGF.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-J5PUIV3Y.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{g as GESTURES,d as addName,b as blockNamed,i as keyOf,f as missingSaid,c as packageFolder,a as packageNamed,h as pairsOf,j as run,e as shallowSaid};
2
+ import{a,b,c,d,e,f,g,h,i,j}from"./chunk-S2Y7VI4H.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-QXVNUASA.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-2GKGEVMR.mjs";import"./chunk-LE44MD3O.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";export{g as GESTURES,d as addName,b as blockNamed,i as keyOf,f as missingSaid,c as packageFolder,a as packageNamed,h as pairsOf,j as run,e as shallowSaid};
@@ -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{a as g}from"./chunk-HYMEEXKN.mjs";import{createRequire as re}from"node:module";import{typescriptFile as ae}from"../browser/shared/paths.mjs";var ce=re(import.meta.url),B=null;function fe(){return B??=ce(ae??"typescript"),B}var b=new Proxy({},{get:(e,n)=>fe()[n]});import _ from"node:fs/promises";import h from"node:path";import{COMPONENTS as D,instancesOf as ue}from"../browser/shared/components/index.mjs";import{PACKAGE_MARK as q}from"../browser/shared/components/installed.mjs";import{MATH_IGNORED_TAGS as pe}from"../browser/shared/components/math.mjs";import{attr as x,elementsOf as O,walk as y}from"../browser/shared/html-tree.mjs";import I from"node:path";import de from"node:vm";var L=()=>{throw new Error("esbuild is not in the release: Gallery 0.2.0 calls it only in a source checkout")},Le=L,J=L;var Te=new Proxy({},{get:L});import{projectRoot as le}from"../browser/shared/paths.mjs";var T=I.join(le,"src","shared","components","index.mjs");function F(e){let{outputFiles:n}=J({stdin:{contents:`import { FLOWS, FLOW_BLOCKS, runtimeDescriptions } from ${JSON.stringify(e)}; module.exports = { descriptions: runtimeDescriptions(), flows: FLOWS, blockFlows: FLOW_BLOCKS };`,resolveDir:I.dirname(e),loader:"js"},bundle:!0,write:!1,format:"cjs",platform:"node",logLevel:"silent"}),s={module:{exports:null}};return de.runInNewContext(n[0].text,s),JSON.parse(JSON.stringify(s.module.exports))}var W=(e=T)=>F(e).descriptions,G=(e=T)=>F(e).flows,U=(e=T)=>F(e).blockFlows;import{kitPublicDirectory as me,projectRoot as H,release as Y,vendorDirectory as z}from"../browser/shared/paths.mjs";var P=h.join(H,"node_modules"),he=h.join(P,"d3","dist","d3.min.js"),S=Y?h.join(z,"katex"):h.join(P,"katex","dist"),xe=h.join(S,"fonts"),He=h.join(S,"contrib","mhchem.min.js"),u=[{id:"styles",file:"report.css",build:{styles:"styles/index.css"},always:!0},{id:"katex-styles",vendor:{path:"/vendor/katex/katex.min.css",source:h.join(S,"katex.min.css")}},{id:"runtime",file:"runtime.js",build:{bundle:"runtime/index.js",options:()=>({minify:!1,define:{__COMPONENT_RUNTIME__:JSON.stringify(W()),__COMPONENT_FLOWS__:JSON.stringify(G()),__COMPONENT_BLOCK_FLOWS__:JSON.stringify(U())}})},api:"DocKit",always:!0},{id:"code",file:"code.js",build:{bundle:"code.js",options:{minify:!0,legalComments:"inline"}},api:"DocCode",after:["runtime"]},{id:"state",file:"state.js",build:{read:"state.js"},api:"DocState",always:!0},{id:"sheets",file:"sheets.js",build:{read:"sheets.js"},api:"DocSheets",after:["runtime","state"]},{id:"tokens",file:"tokens.js",build:{read:"tokens.js"},api:"DocTokens",always:!0},{id:"ui",file:"ui.js",build:{bundle:"ui.js",options:{minify:!1}},added:!0,after:["runtime","state","tokens"]},{id:"dialogs",file:"dialogs.js",build:{read:"dialogs.js"},api:"DocDialogs",after:["runtime"]},{id:"katex",vendor:{path:"/vendor/katex/katex.min.js",source:h.join(S,"katex.min.js")},umd:!0},{id:"katex-auto-render",vendor:{path:"/vendor/katex/auto-render.min.js",source:h.join(S,"contrib","auto-render.min.js")},umd:!0,after:["katex"]},{id:"math",file:"math.js",build:{bundle:"math-bundle.js",options:{minify:!1,legalComments:"inline",alias:{katex:h.join(H,"src","render","kit","page-katex.js")},nodePaths:[h.join(P,"katex")]}},api:"DocMath",after:["runtime","katex-styles","katex","katex-auto-render"]},{id:"d3",vendor:{path:"/vendor/d3.v7.9.0.min.js",source:he},api:"d3",umd:!0},{id:"charts",file:"charts.js",build:{bundle:"charts/index.js",options:{minify:!1}},api:"DocCharts",after:["runtime","tokens"]},{id:"tables",file:"tables.js",build:{bundle:"tables/index.js",options:{minify:!1}},api:"DocTables",after:["runtime"]},{id:"board-styles",file:"board.css",build:{styles:"board/index.css"},page:!0},{id:"board",file:"board.js",build:{bundle:"board/index.js",options:{minify:!1}},page:!0}],m=e=>e.file?`/kit/${e.file}`:e.vendor.path,ge=e=>e.file?h.join(me,e.file):h.join(z,...e.vendor.path.split("/").slice(2));if(Y)for(let e of u)e.vendor&&(e.vendor.source=ge(e));var k=e=>m(e).endsWith(".css"),E=e=>e.file?"data-doc-kit":"data-doc-vendor",C=e=>u.find(n=>n.id===e),w=(e,n=m(e))=>k(e)?`<link rel="stylesheet" href="${n}" ${E(e)}="${e.id}">`:`<script src="${n}" ${E(e)}="${e.id}"></script>`,we=u.map(e=>({id:e.id,tag:w(e),always:!!e.always,element:k(e)?"style":"script",attribute:E(e)}));function Ye(e,n=m){let s=new Set,i=t=>{s.has(t)||(s.add(t),C(t)?.after?.forEach(i))};return e.forEach(i),u.filter(t=>s.has(t.id)&&!t.always&&!t.added).map(t=>w(t,n(t)))}function ye(e=u,n=D){let s=[],i=e.map(t=>t.id);for(let t of new Set(i.filter((a,o)=>i.indexOf(a)!==o)))s.push(`the asset "${t}" is listed twice`);for(let t of e){!!t.file==!!t.vendor&&s.push(`the asset "${t.id}" is a kit file (file) or a vendor file (vendor), one of them`),t.file&&!["read","bundle","styles"].some(o=>typeof t.build?.[o]=="string")&&s.push(`the kit file "${t.file}" does not say how it is made (build: read, bundle or styles)`),t.vendor&&!(t.vendor.path&&t.vendor.source)&&s.push(`the vendor asset "${t.id}" needs its public path and its source`);for(let o of t.after??[])i.includes(o)?i.indexOf(o)>i.indexOf(t.id)&&s.push(`the asset "${t.id}" loads after "${o}", which the list puts after it`):s.push(`the asset "${t.id}" loads after "${o}", which is no asset`);let a=n.filter(o=>(o.assets??[]).includes(t.id));!t.always&&!t.api&&!t.added&&!t.page&&a.length===0&&s.push(`no report would keep the asset "${t.id}": it is not always kept, defines no global and no component needs it`)}for(let t of n)for(let a of t.assets??[])i.includes(a)||s.push(`the component "${t.id}" needs "${a}", which is no asset`);return s}{let e=ye();if(e.length>0)throw new Error(`src/render/assets.mjs: ${e.join("; ")}`)}var K=/^(?:|module|(?:text|application)\/(?:x-)?(?:javascript|ecmascript)|text\/javascript1\.[0-5]|text\/(?:jscript|livescript))$/,be=/^application\/(?:\S+\+)?json$/,N=e=>(x(e,"type")??"").trim().toLowerCase();function V(e){let n=b.createSourceFile("report.js",e,b.ScriptTarget.Latest,!1,b.ScriptKind.JS),s=[],i=[n];for(;i.length>0;){let t=i.pop();if(t.kind>=b.SyntaxKind.FirstJSDocNode&&t.kind<=b.SyntaxKind.LastJSDocNode)continue;let a=t.getChildren(n);a.length===0&&s.push(e.slice(t.getStart(n),t.end));for(let o=a.length-1;o>=0;o-=1)i.push(a[o])}return s.join(" ")}var Q=e=>new RegExp(`\\b(?:${e.filter(n=>n.api).map(n=>n.api).join("|")})\\b`);function $e(e,n){let s=[],i=t=>{n.test(t)&&s.push(V(t))};return y(e,t=>{t.tagName==="script"&&x(t,"src")===void 0&&K.test(N(t))&&i(t.childNodes.map(a=>a.value??"").join(""));for(let{name:a,value:o}of t.attrs??[]){if(/^on/.test(a)){i(o);continue}let c=o.replace(/[\t\n\r]/g,"").replace(/^[\x00-\x20]+/,"");if(!/^javascript:/i.test(c))continue;let r=c.slice(11);try{r=decodeURIComponent(r)}catch{}i(r)}}),s.join(`
2
+ import{a as g}from"./chunk-2RKIHJI2.mjs";import{createRequire as re}from"node:module";import{typescriptFile as ae}from"../browser/shared/paths.mjs";var ce=re(import.meta.url),B=null;function fe(){return B??=ce(ae??"typescript"),B}var b=new Proxy({},{get:(e,n)=>fe()[n]});import _ from"node:fs/promises";import h from"node:path";import{COMPONENTS as D,instancesOf as ue}from"../browser/shared/components/index.mjs";import{PACKAGE_MARK as q}from"../browser/shared/components/installed.mjs";import{MATH_IGNORED_TAGS as pe}from"../browser/shared/components/math.mjs";import{attr as x,elementsOf as O,walk as y}from"../browser/shared/html-tree.mjs";import I from"node:path";import de from"node:vm";var L=()=>{throw new Error("esbuild is not in the release: Gallery 0.2.1 calls it only in a source checkout")},Le=L,J=L;var Te=new Proxy({},{get:L});import{projectRoot as le}from"../browser/shared/paths.mjs";var T=I.join(le,"src","shared","components","index.mjs");function F(e){let{outputFiles:n}=J({stdin:{contents:`import { FLOWS, FLOW_BLOCKS, runtimeDescriptions } from ${JSON.stringify(e)}; module.exports = { descriptions: runtimeDescriptions(), flows: FLOWS, blockFlows: FLOW_BLOCKS };`,resolveDir:I.dirname(e),loader:"js"},bundle:!0,write:!1,format:"cjs",platform:"node",logLevel:"silent"}),s={module:{exports:null}};return de.runInNewContext(n[0].text,s),JSON.parse(JSON.stringify(s.module.exports))}var W=(e=T)=>F(e).descriptions,G=(e=T)=>F(e).flows,U=(e=T)=>F(e).blockFlows;import{kitPublicDirectory as me,projectRoot as H,release as Y,vendorDirectory as z}from"../browser/shared/paths.mjs";var P=h.join(H,"node_modules"),he=h.join(P,"d3","dist","d3.min.js"),S=Y?h.join(z,"katex"):h.join(P,"katex","dist"),xe=h.join(S,"fonts"),He=h.join(S,"contrib","mhchem.min.js"),u=[{id:"styles",file:"report.css",build:{styles:"styles/index.css"},always:!0},{id:"katex-styles",vendor:{path:"/vendor/katex/katex.min.css",source:h.join(S,"katex.min.css")}},{id:"runtime",file:"runtime.js",build:{bundle:"runtime/index.js",options:()=>({minify:!1,define:{__COMPONENT_RUNTIME__:JSON.stringify(W()),__COMPONENT_FLOWS__:JSON.stringify(G()),__COMPONENT_BLOCK_FLOWS__:JSON.stringify(U())}})},api:"DocKit",always:!0},{id:"code",file:"code.js",build:{bundle:"code.js",options:{minify:!0,legalComments:"inline"}},api:"DocCode",after:["runtime"]},{id:"state",file:"state.js",build:{read:"state.js"},api:"DocState",always:!0},{id:"sheets",file:"sheets.js",build:{read:"sheets.js"},api:"DocSheets",after:["runtime","state"]},{id:"tokens",file:"tokens.js",build:{read:"tokens.js"},api:"DocTokens",always:!0},{id:"ui",file:"ui.js",build:{bundle:"ui.js",options:{minify:!1}},added:!0,after:["runtime","state","tokens"]},{id:"dialogs",file:"dialogs.js",build:{read:"dialogs.js"},api:"DocDialogs",after:["runtime"]},{id:"katex",vendor:{path:"/vendor/katex/katex.min.js",source:h.join(S,"katex.min.js")},umd:!0},{id:"katex-auto-render",vendor:{path:"/vendor/katex/auto-render.min.js",source:h.join(S,"contrib","auto-render.min.js")},umd:!0,after:["katex"]},{id:"math",file:"math.js",build:{bundle:"math-bundle.js",options:{minify:!1,legalComments:"inline",alias:{katex:h.join(H,"src","render","kit","page-katex.js")},nodePaths:[h.join(P,"katex")]}},api:"DocMath",after:["runtime","katex-styles","katex","katex-auto-render"]},{id:"d3",vendor:{path:"/vendor/d3.v7.9.0.min.js",source:he},api:"d3",umd:!0},{id:"charts",file:"charts.js",build:{bundle:"charts/index.js",options:{minify:!1}},api:"DocCharts",after:["runtime","tokens"]},{id:"tables",file:"tables.js",build:{bundle:"tables/index.js",options:{minify:!1}},api:"DocTables",after:["runtime"]},{id:"board-styles",file:"board.css",build:{styles:"board/index.css"},page:!0},{id:"board",file:"board.js",build:{bundle:"board/index.js",options:{minify:!1}},page:!0}],m=e=>e.file?`/kit/${e.file}`:e.vendor.path,ge=e=>e.file?h.join(me,e.file):h.join(z,...e.vendor.path.split("/").slice(2));if(Y)for(let e of u)e.vendor&&(e.vendor.source=ge(e));var k=e=>m(e).endsWith(".css"),E=e=>e.file?"data-doc-kit":"data-doc-vendor",C=e=>u.find(n=>n.id===e),w=(e,n=m(e))=>k(e)?`<link rel="stylesheet" href="${n}" ${E(e)}="${e.id}">`:`<script src="${n}" ${E(e)}="${e.id}"></script>`,we=u.map(e=>({id:e.id,tag:w(e),always:!!e.always,element:k(e)?"style":"script",attribute:E(e)}));function Ye(e,n=m){let s=new Set,i=t=>{s.has(t)||(s.add(t),C(t)?.after?.forEach(i))};return e.forEach(i),u.filter(t=>s.has(t.id)&&!t.always&&!t.added).map(t=>w(t,n(t)))}function ye(e=u,n=D){let s=[],i=e.map(t=>t.id);for(let t of new Set(i.filter((a,o)=>i.indexOf(a)!==o)))s.push(`the asset "${t}" is listed twice`);for(let t of e){!!t.file==!!t.vendor&&s.push(`the asset "${t.id}" is a kit file (file) or a vendor file (vendor), one of them`),t.file&&!["read","bundle","styles"].some(o=>typeof t.build?.[o]=="string")&&s.push(`the kit file "${t.file}" does not say how it is made (build: read, bundle or styles)`),t.vendor&&!(t.vendor.path&&t.vendor.source)&&s.push(`the vendor asset "${t.id}" needs its public path and its source`);for(let o of t.after??[])i.includes(o)?i.indexOf(o)>i.indexOf(t.id)&&s.push(`the asset "${t.id}" loads after "${o}", which the list puts after it`):s.push(`the asset "${t.id}" loads after "${o}", which is no asset`);let a=n.filter(o=>(o.assets??[]).includes(t.id));!t.always&&!t.api&&!t.added&&!t.page&&a.length===0&&s.push(`no report would keep the asset "${t.id}": it is not always kept, defines no global and no component needs it`)}for(let t of n)for(let a of t.assets??[])i.includes(a)||s.push(`the component "${t.id}" needs "${a}", which is no asset`);return s}{let e=ye();if(e.length>0)throw new Error(`src/render/assets.mjs: ${e.join("; ")}`)}var K=/^(?:|module|(?:text|application)\/(?:x-)?(?:javascript|ecmascript)|text\/javascript1\.[0-5]|text\/(?:jscript|livescript))$/,be=/^application\/(?:\S+\+)?json$/,N=e=>(x(e,"type")??"").trim().toLowerCase();function V(e){let n=b.createSourceFile("report.js",e,b.ScriptTarget.Latest,!1,b.ScriptKind.JS),s=[],i=[n];for(;i.length>0;){let t=i.pop();if(t.kind>=b.SyntaxKind.FirstJSDocNode&&t.kind<=b.SyntaxKind.LastJSDocNode)continue;let a=t.getChildren(n);a.length===0&&s.push(e.slice(t.getStart(n),t.end));for(let o=a.length-1;o>=0;o-=1)i.push(a[o])}return s.join(" ")}var Q=e=>new RegExp(`\\b(?:${e.filter(n=>n.api).map(n=>n.api).join("|")})\\b`);function $e(e,n){let s=[],i=t=>{n.test(t)&&s.push(V(t))};return y(e,t=>{t.tagName==="script"&&x(t,"src")===void 0&&K.test(N(t))&&i(t.childNodes.map(a=>a.value??"").join(""));for(let{name:a,value:o}of t.attrs??[]){if(/^on/.test(a)){i(o);continue}let c=o.replace(/[\t\n\r]/g,"").replace(/^[\x00-\x20]+/,"");if(!/^javascript:/i.test(c))continue;let r=c.slice(11);try{r=decodeURIComponent(r)}catch{}i(r)}}),s.join(`
3
3
  `)}function je(e,n){let s=[],i=(o,c)=>{for(let r of o.childNodes??[]){let f=r.sourceCodeLocation;r.nodeName==="#comment"||c&&r.nodeName==="#text"?f&&s.push([f.startOffset,f.endOffset]):r.tagName==="script"?i(r,be.test(N(r))):r.tagName&&i(r.content??r,c||pe.includes(r.tagName))}};i(e,!1);let t="",a=0;for(let[o,c]of s.sort((r,f)=>r[0]-f[0]))o<a||(t+=`${n.slice(a,o)} `,a=c);return t+n.slice(a)}function R(e,n=u,s=D){let i=n.reduce((f,d)=>f.replaceAll(w(d),""),e),t=g(i),a=je(t,i),o=$e(t,Q(n)),c=new Set,r=f=>{c.has(f)||(c.add(f),(n.find(d=>d.id===f)?.after??[]).forEach(r))};for(let f of s){if(!(f.assets??[]).length)continue;((f.uses??[]).some(l=>l.test(a))||f.match&&ue(t,f).length>0)&&f.assets.forEach(r)}for(let f of n)f.api&&new RegExp(`\\b${f.api}\\b`).test(o)&&r(f.id);return c}function ze(e,n=D){let s=R(e,u,n),i=[];for(let t of u){let a=w(t);if(t.always||t.added||s.has(t.id)||!e.includes(a))continue;let o=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp(`[ \\t]*${o}[ \\t]*\\r?\\n?`),""),i.push(t.id)}return{html:e,removed:i,used:s}}function M(e,n){let s=[];return y(n,i=>{let t=Z(i),a=t===void 0?void 0:u.find(c=>m(c)===t.trim()),o=i.sourceCodeLocation;!a||!o||s.push({asset:a,start:o.startOffset,end:o.endOffset,line:o.startLine,exact:e.slice(o.startOffset,o.endOffset)===w(a)})},{inTemplates:!1}),s}var X=e=>e.tagName==="style"||e.tagName==="link"&&(x(e,"rel")??"").toLowerCase().split(/\s+/).includes("stylesheet"),Z=e=>e.tagName==="script"?x(e,"src"):X(e)?x(e,"href"):void 0,j=e=>!!e.sourceCodeLocation,A=e=>e.includes(`\r
4
4
  `)?`\r
5
5
  `:`
@@ -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,i as S}from"./chunk-4OZWXZE5.mjs";import _ from"node:fs/promises";import{listExtensions as I}from"../browser/shared/extensions.mjs";import{ancestorsIn as C,moveDocument as M,outlineAndFile as P}from"../browser/shared/outline.mjs";import{DOCS as k,groupOfTop as A,isForeign as b,isTop as G,topIn as J,topOf as U}from"../browser/shared/outline-shape.mjs";import{draftFacts as q,draftOf as z,registeredIds as B,workspaceNames as K}from"../browser/shared/drafts.mjs";import{reportsDirectory as u}from"../browser/shared/paths.mjs";import{findPreviewServer as R}from"../browser/shared/preview-server.mjs";import{roleOf as W}from"../browser/shared/reports.mjs";import{nameStops as X,workspaceName as H}from"../browser/shared/workspace-name.mjs";import{workspaceKey as w}from"../browser/shared/workspace-registry.mjs";import{defaultWorkspace as Q,documentDirectory as y,documentFiles as V,pageSlug as Y,readLink as Z}from"../browser/shared/workspace.mjs";async function we(e=u,{others:t=w(e)===w(u)}={}){let{outline:{children:n,groups:o,links:s,shown:i},others:c}=await P(e,{others:t}),m=ee(e,o,i),a=new Set(i.map(({id:r})=>r)),p=o.map(r=>({...r,name:m.get(r.id)??null,...t&&r.workspace&&!a.has(r.workspace)?{away:!0}:{}})),$=p.filter(r=>!r.extension),F=await I(e),x=Object.values(n).flat(),N=r=>typeof r=="string"?r.replace(/\s+/g," ").trim():"",j=x.some(b)?B():null,E=new Map(await Promise.all(x.map(async r=>{if(b(r)){let d=z(r),O=c.find(({id:L})=>L===d?.ws)?.facts.get(d.slug),f=O?{...O,missing:null}:await q(r,j);return[r,{slug:r,title:f.title,description:f.description,icon:f.icon,...f.url?{url:f.url}:{},draft:{path:f.path,missing:f.missing,ws:d?.ws??null}}]}if(s.includes(r)){let d=await Z(y(r,e));return[r,{slug:r,title:d?.title??r,description:"",icon:d?.icon??null,url:d?.url??""}]}let h=await _.readFile(V(y(r,e)).json,"utf8").then(JSON.parse).catch(()=>({}));return[r,{slug:r,title:N(h?.title)||r,description:N(h?.description),icon:typeof h?.icon=="string"?h.icon:null}]})));return{children:n,groups:$,columns:p,extensions:F,documents:E}}function ee(e,t,n=[]){let o=w(Q()),s=new Set(t.map(({workspace:a})=>a).filter(Boolean)),i=X(),c=s.size?K(s,{stops:i}):new Map,m=new Map;for(let a of t)if(a.id===k)m.set(a.id,w(e)===o?"\u9ED8\u8BA4\u6587\u6863":H(e,{stops:i}).name);else if(a.workspace){let p=n.find(({id:$})=>$===a.workspace);m.set(a.id,p?.isDefault?"\u9ED8\u8BA4\u6587\u6863":c.get(a.workspace)?.name??a.workspace)}else a.role==="links"&&m.set(a.id,"\u94FE\u63A5");return m}var v=e=>e?.title??e?.name??(e?.id===k?"\u6587\u6863":e?.role==="links"?"\u94FE\u63A5":e?"\u672A\u547D\u540D\u680F":"\u6587\u6863"),T=(e,t)=>e.groups?.find(({id:n})=>n===A(t));function $e(e,t){let n=e.documents.get(t);if(!n||n.url!==void 0)return null;let o=D(e,t),s=n.draft?.ws??null,i=s?e.groups.find(c=>c.workspace===s):e.groups.find(c=>c.id===k);return i&&U(i.id)===o?null:i?i.hidden?i.name??s:v(i):s}var l=({documents:e},t)=>`${t} (${e.get(t)?.title??t})`,D=(e,t)=>J(e.children,t)??"";function ge(e,t){let n=C(e.children,t).map(i=>l(e,i)),o=D(e,t),s=[...o===""?[]:[`${v(T(e,o))}\u680F`],...n];return`\u4F4D\u7F6E\uFF1A${s.length?s.join(" \u203A "):"\u9876\u5C42"}`}async function ye(e,t,n){let{slug:o}=await S(e);if(o===await Y(u))return{refused:`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`};if(!n.documents.has(o)){let s=y(o,u);return{refused:await W(s)==="instructions"?`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`:`No document "${e}" (${t}): gallery list --tree shows the documents and where they are.`}}return{slug:o}}var te={"cross-workspace":()=>"Not moved: copying to another workspace requires confirmation in Gallery; the original stays in its workspace.",missing:(e,t)=>`No document "${t}" in the sidebar's tree: gallery list --tree shows them.`,parent:(e,t,{parent:n})=>`No document "${n}" to put ${l(e,t)} under: gallery list --tree shows them.`,after:(e,t,{after:n})=>`No document "${n}" to put ${l(e,t)} after: gallery list --tree shows them.`,level:(e,t,{parent:n,after:o})=>`${l(e,o)} is not under ${n?l(e,n):"the top level"}: --after names a document at the level it goes to.`,itself:(e,t)=>`${l(e,t)} cannot go after itself.`,inside:(e,t,{parent:n,after:o})=>n===void 0&&o?`${l(e,t)} cannot go after ${l(e,o)}, which is under it.`:`${l(e,t)} cannot go under ${n===t?"itself":`${l(e,n)}, which is under it`}.`,instructions:(e,t)=>"The \u5199\u4F5C\u504F\u597D page is listed apart: it moves nowhere and holds no documents."},ke=(e,t,n,o={})=>(te[n]??((s,i,{message:c})=>`Not moved: ${c??n}.`))(e,t,o);async function ne(e,t,n="move"){let o=`127.0.0.1:${e.port}`;try{let i=await(await fetch(`http://${o}/__gallery/workspace/${n}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${o}`,"X-Gallery-Token":e.token},body:JSON.stringify({...t,workspace:u}),signal:AbortSignal.timeout(3e4)})).json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin","unknown"].includes(i.reason)?null:i}catch{return null}}async function ve(e,{parent:t=void 0,after:n=null,first:o=!1}={}){let s=await R({reportsDirectory:u}),i={slug:e,...t!==void 0?{parent:t}:{},after:n,first:o},c=s?await ne(s,i):null;return c||M(u,e,{parent:t,after:n,first:o})}function xe(e,{parent:t,index:n}){let o=e.children[t]??[],s=t===""?"at the top level":G(t)?`at the top of the ${v(T(e,t))} column`:`under ${l(e,t)}`;return o.length===1?`${s}, the only ${o.some(i=>e.documents.get(i)?.url!==void 0)?"entry":"document"} there`:n===0?`${s}, first`:`${s}, right after ${l(e,o[n-1])}${n===o.length-1?", last":""}`}function Ne(e,t,{top:n=!0}={}){let o=e.get("--under"),s=e.get("--after");if(o!==void 0&&t.has("--top"))throw new g("--under and --top are two places: give one.");if(s!==void 0&&t.has("--first"))throw new g("--after and --first are two places: give one.");return{under:o,top:n&&t.has("--top"),after:s,first:t.has("--first")}}export{we as a,v as b,$e as c,l as d,ge as e,ye as f,ke as g,ne as h,ve as i,xe as j,Ne as k};
@@ -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 h,b as v,d as p,e as j,h as I,j as A}from"./chunk-YPPJVDQI.mjs";import{a as O}from"./chunk-JEUK3ZO7.mjs";import{a as E}from"./chunk-UGO5N3EI.mjs";import"./chunk-5IIH335D.mjs";import"./chunk-QK3VISCA.mjs";import{g as C}from"./chunk-7M2BQQGZ.mjs";import{b as i,f as g,i as y}from"./chunk-4OZWXZE5.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-VG5JEIUQ.mjs";import"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";import D from"node:path";import{pageLinks as F,pageOfLink as J}from"../browser/shared/page-links.mjs";import{reportsDirectory as x}from"../browser/shared/paths.mjs";import{findPreviewServer as K}from"../browser/shared/preview-server.mjs";import{topOf as M}from"../browser/shared/outline-shape.mjs";import{LINK_FILE as U,linkAddress as P,linkIcon as T}from"../browser/shared/web-links.mjs";var $=t=>t.replace(/\s+/g," ").trim(),k=t=>t==null?"none":JSON.stringify(t);async function L(t,e){let n=await K({reportsDirectory:x}),o=n?await I(n,e,t):null;if(o)return o;let[,s]=await E({edits:{},reports:{},reportsDirectory:x,web:{icon:a=>C(a)}}).run(t,e);return s}function _(t,e){let n=[...t.documents.values()].filter(({url:a})=>a!==void 0),o=J(F(n),e.replace(/^.*#/,""));return o?{slug:o,link:t.documents.get(o)}:{refused:t.documents.get(e)?`${p(t,e)} is a document, not a web link: gallery set changes a document.`:`No web link "${e}": gallery list --tree shows the sidebar's entries.`}}var W=(t,e)=>t.groups.find(n=>[v(n),n.id].some(o=>o.toLowerCase()===$(e).toLowerCase()))??null;async function B(t,e,n){if(t.length!==2)throw new i('Name the address and the name: gallery link add <url> "<name>".');let[o,s]=t,a=P(o);if(a.refused)throw new i(`Not an address a web link takes: ${o} (${{url:"no address",scheme:"http or https only",long:"2048 characters at most"}[a.refused]}).`);if(!$(s))throw new i("The name is never empty.");let d=n.get("--column"),u=n.get("--under"),l=n.get("--after"),c=n.get("--icon");if(d!==void 0&&u!==void 0)throw new i("--column and --under are two places: give one.");if(l!==void 0&&e.has("--first"))throw new i("--after and --first are two places: give one.");if(c!==void 0&&!T(c))throw new i(`Not an icon a web link takes: ${c} (an emoji, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg).`);let f=await h(),w;if(d!==void 0){let S=W(f,d);S||(console.error(`No column "${d}" in the sidebar (${f.groups.map(v).join(", ")}): nothing added.`),process.exit(1)),w=M(S.id)}u!==void 0&&(w=(await y(u)).slug);let r=l===void 0?null:(await y(l)).slug,q=e.has("--first")||u===void 0&&r===null,m=await L("link",{url:a.url,title:$(s),...c?{icon:c}:{},...w!==void 0?{parent:w}:{},after:r,first:q});m?.ok||(console.error(`Not added: ${m?.message??m?.reason??"no answer"}.`),process.exit(1));let b=await h(),{slug:N,url:z}=m.link;console.log(`Added the web link ${p(b,N)}: ${z}`),console.log(`Placed it ${A(b,{parent:m.parent,index:m.index})}.`),console.log(j(b,N)),console.log(`It is ${O(D.join(x,N,U))}; the workbench shows the page beside the sidebar (a site that refuses frames: \u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00).`)}async function G(t,e){if(t.length!==1)throw new i("Name one web link, then what to set: --url, --title, --icon.");if(!["--url","--title","--icon"].some(r=>e.has(r)))throw new i('Say what to set: --url <address>, --title "<name>", --icon <emoji|none>.');let n=e.has("--title")?$(e.get("--title")):void 0;if(n==="")throw new i("--title takes the words of the name: a web link's name is never empty.");let o;if(e.has("--url")){let r=P(e.get("--url"));if(r.refused)throw new i(`Not an address a web link takes: ${e.get("--url")}.`);o=r.url}let s;if(e.has("--icon")){let r=e.get("--icon").trim();if(r!=="none"&&!T(r))throw new i(`Not an icon a web link takes: ${r} (an emoji, none, or an icon of the \u56FE\u6807 tab).`);s=r==="none"?null:r}let a=await h(),d=_(a,t[0]);d.refused&&(console.error(d.refused),process.exit(1));let{slug:u,link:l}=d,c=await L("link-set",{slug:u,...o!==void 0?{url:o}:{},...n!==void 0?{title:n}:{},...s!==void 0?{icon:s}:{}});c?.ok||(console.error(`Not set: ${c?.message??c?.reason??"no answer"}.`),process.exit(1));let f=c.link,w=[...n!==void 0&&n!==l.title?[` title: ${k(l.title)} \u2192 ${k(f.title)}`]:[],...o!==void 0&&f.url!==l.url?[` url: ${l.url} \u2192 ${f.url}`]:[],...s!==void 0&&(f.icon??null)!==(l.icon??null)?[` icon: ${k(l.icon)} \u2192 ${k(f.icon??null)}`]:[]];if(!w.length)return void console.log(`Nothing to change: ${u} has ${e.size===1?"that already":"those already"}.`);console.log(`Set the web link ${u}:`);for(let r of w)console.log(r)}async function H(t){if(t.length!==1)throw new i("Name one web link to move to the trash.");let e=await h(),n=_(e,t[0]);n.refused&&(console.error(n.refused),process.exit(1));let o=await L("trash",{slug:n.slug,kind:"link"});o?.ok||(console.error(`Not moved to the trash: ${o?.message??o?.reason??"no answer"}.`),process.exit(1)),console.log(`Moved the web link ${p(e,n.slug)} to the trash: the workbench's \u8BBE\u7F6E \u203A \u56DE\u6536\u533A restores it where it was.`)}async function se(t){let[e,...n]=t;if(e==="add"){let{positional:o,options:s,values:a}=g({options:["--first"],values:["--column","--under","--after","--icon"],argv:n});return B(o,s,a)}if(e==="set"){let{positional:o,values:s}=g({values:["--url","--title","--icon"],argv:n});return G(o,s)}if(e==="remove"){let{positional:o}=g({argv:n});return H(o)}throw new i(e?`No such action: link ${e} (add, set, remove).`:"Say what to do: gallery link add, set or remove.")}export{se as run};