@heycys/gallery 0.2.1 → 0.2.3

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 (169) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/page/annotate/index.mjs +3 -2
  3. package/browser/editor/page/board/index.mjs +2 -1
  4. package/browser/editor/page/board/settings.mjs +2 -1
  5. package/browser/editor/page/core.mjs +3 -2
  6. package/browser/editor/page/custom-page.mjs +4 -3
  7. package/browser/editor/page/editor.mjs +13 -7
  8. package/browser/editor/page/emoji-picker/support.mjs +3 -2
  9. package/browser/editor/page/links/index.mjs +1 -12
  10. package/browser/editor/page/links/pages.mjs +3 -2
  11. package/browser/editor/page/outline/folds.mjs +3 -0
  12. package/browser/editor/page/post.mjs +2 -1
  13. package/browser/editor/page/present-links.mjs +4 -3
  14. package/browser/editor/page/present-shell.mjs +3 -58
  15. package/browser/editor/page/session.mjs +3 -37
  16. package/browser/editor/page/storage.mjs +5 -5
  17. package/browser/shared/component-catalog.mjs +2 -2
  18. package/browser/shared/drafts.mjs +26 -51
  19. package/browser/shared/emoji/icon-value.mjs +2 -1
  20. package/browser/shared/extension-manifest.mjs +90 -0
  21. package/browser/shared/extensions.mjs +26 -16
  22. package/browser/shared/http.mjs +1 -1
  23. package/browser/shared/i18n/en.mjs +46 -15
  24. package/browser/shared/media.mjs +2 -1
  25. package/browser/shared/outline.mjs +11 -51
  26. package/browser/shared/page-address.mjs +8 -15
  27. package/browser/shared/paths.mjs +2 -1
  28. package/browser/shared/preferences.mjs +3 -1
  29. package/browser/shared/preview-server.mjs +51 -63
  30. package/browser/shared/service-location.mjs +18 -0
  31. package/browser/shared/session.mjs +3 -6
  32. package/browser/shared/workspace-address.mjs +22 -0
  33. package/browser/shared/workspace-columns.mjs +1 -2
  34. package/browser/shared/workspace-registry.mjs +6 -40
  35. package/browser/shared/workspace.mjs +3 -6
  36. package/browser/shared/writing-preferences.mjs +6 -4
  37. package/dist/{chunk-5MEXZ2UF.mjs → chunk-225ALKYI.mjs} +1 -1
  38. package/dist/{chunk-7N2LPG33.mjs → chunk-2HS7ZBPU.mjs} +1 -1
  39. package/dist/chunk-3F57LEN5.mjs +2 -0
  40. package/dist/{chunk-MKTX5PGV.mjs → chunk-43B75J5T.mjs} +1 -1
  41. package/dist/{chunk-VKSRM7EY.mjs → chunk-4B2TB5K2.mjs} +1 -1
  42. package/dist/{chunk-LV24RY2E.mjs → chunk-4K5KC6V2.mjs} +1 -1
  43. package/dist/chunk-5GK7HS62.mjs +2 -0
  44. package/dist/chunk-6GV3CBB2.mjs +2 -0
  45. package/dist/{chunk-TOE6DPLH.mjs → chunk-6NLXUKAY.mjs} +1 -1
  46. package/dist/{chunk-ZCP7BTOZ.mjs → chunk-6QBHU4DF.mjs} +1 -1
  47. package/dist/{chunk-QXVNUASA.mjs → chunk-6QWQXHAV.mjs} +1 -1
  48. package/dist/chunk-6XD6U3QA.mjs +5 -0
  49. package/dist/{chunk-DKR7LFIY.mjs → chunk-6Y3HYOBM.mjs} +1 -1
  50. package/dist/{chunk-36FIRJIF.mjs → chunk-742D2WWJ.mjs} +2 -2
  51. package/dist/{chunk-7M7UPWU6.mjs → chunk-7EFHNQ5B.mjs} +1 -1
  52. package/dist/{chunk-2GKGEVMR.mjs → chunk-7UZUQQ7Q.mjs} +25 -24
  53. package/dist/{chunk-VPVOAJ7X.mjs → chunk-AGDILNWB.mjs} +1 -1
  54. package/dist/{chunk-5IIH335D.mjs → chunk-ALZ6ZENZ.mjs} +1 -1
  55. package/dist/{chunk-G4YP7GVC.mjs → chunk-BFJGHSQN.mjs} +1 -1
  56. package/dist/{chunk-AMDGVDNV.mjs → chunk-BQNTTFPL.mjs} +1 -1
  57. package/dist/chunk-BX5AKINW.mjs +15 -0
  58. package/dist/{chunk-PAFSFVYB.mjs → chunk-BYNPEUDS.mjs} +1 -1
  59. package/dist/{chunk-74RPP2M2.mjs → chunk-C564NU2H.mjs} +1 -1
  60. package/dist/{chunk-DH6GMDNN.mjs → chunk-CRDG6EF2.mjs} +1 -1
  61. package/dist/{chunk-7XDYK3UC.mjs → chunk-E7656LR7.mjs} +1 -1
  62. package/dist/{chunk-KFZBYDIS.mjs → chunk-ECZBLQKK.mjs} +1 -1
  63. package/dist/{chunk-ZEY2RLBT.mjs → chunk-ERLAIBOA.mjs} +2 -2
  64. package/dist/{chunk-YFJU3O7G.mjs → chunk-FJLM7YE7.mjs} +1 -1
  65. package/dist/{chunk-AFGUR7SY.mjs → chunk-FNCCVGKX.mjs} +1 -1
  66. package/dist/{chunk-VNUWREXU.mjs → chunk-FOJ3K5Z3.mjs} +1 -1
  67. package/dist/{chunk-WCWYNFDF.mjs → chunk-FQ72LZHB.mjs} +1 -1
  68. package/dist/chunk-G7N7YFVD.mjs +2 -0
  69. package/dist/chunk-GIRXJBGC.mjs +2 -0
  70. package/dist/{chunk-VA3KAQZD.mjs → chunk-GKOBB6DH.mjs} +1 -1
  71. package/dist/chunk-GMJD7ID3.mjs +2 -0
  72. package/dist/chunk-GQJMVSSN.mjs +2 -0
  73. package/dist/{chunk-QZ35UAB4.mjs → chunk-GRAXKKG4.mjs} +1 -1
  74. package/dist/{chunk-SAHS56QM.mjs → chunk-HX4DLE3J.mjs} +1 -1
  75. package/dist/{chunk-2RKIHJI2.mjs → chunk-HYMEEXKN.mjs} +1 -1
  76. package/dist/{chunk-QK3VISCA.mjs → chunk-IA4PSIMD.mjs} +1 -1
  77. package/dist/chunk-IS7N3N6Q.mjs +168 -0
  78. package/dist/{chunk-CZ5KJSGK.mjs → chunk-JJNHKGTD.mjs} +1 -1
  79. package/dist/chunk-JPG2LBQM.mjs +11 -0
  80. package/dist/chunk-JYK5WJPM.mjs +2 -0
  81. package/dist/{chunk-LE44MD3O.mjs → chunk-KLQP46Y3.mjs} +1 -1
  82. package/dist/chunk-L55NOXBE.mjs +4 -0
  83. package/dist/{chunk-FXQBADMN.mjs → chunk-LCB6MARS.mjs} +1 -1
  84. package/dist/{chunk-SOD23RGL.mjs → chunk-LJLVCU6W.mjs} +8 -8
  85. package/dist/{chunk-NAGMRVW4.mjs → chunk-LKX55H76.mjs} +1 -1
  86. package/dist/chunk-LMUZQK5O.mjs +2 -0
  87. package/dist/{chunk-CG3UHDKH.mjs → chunk-M4NRDYI5.mjs} +1 -1
  88. package/dist/{chunk-HM4E43VM.mjs → chunk-MAFIGVXY.mjs} +1 -1
  89. package/dist/chunk-NLDF35P5.mjs +2 -0
  90. package/dist/{chunk-3OFXMN6N.mjs → chunk-NMF3IPYA.mjs} +1 -1
  91. package/dist/chunk-ONKC4BCC.mjs +2 -0
  92. package/dist/{chunk-CPS4SRPF.mjs → chunk-OU6ZZVBX.mjs} +2 -2
  93. package/dist/{chunk-NWRZXELO.mjs → chunk-PAREWQGB.mjs} +1 -1
  94. package/dist/{chunk-BYSF5UMM.mjs → chunk-PKVK6WFC.mjs} +2 -2
  95. package/dist/{chunk-4AMTKWDO.mjs → chunk-PUOQ65NC.mjs} +1 -1
  96. package/dist/{chunk-L7W624FD.mjs → chunk-QJAVCTY7.mjs} +1 -1
  97. package/dist/{chunk-6MPKCH3P.mjs → chunk-QNECWMGR.mjs} +1 -1
  98. package/dist/{chunk-HBAUKKQH.mjs → chunk-QP7BOHE4.mjs} +1 -1
  99. package/dist/chunk-QVGOPHOF.mjs +2 -0
  100. package/dist/{chunk-NFABH3QW.mjs → chunk-RRKJMHNX.mjs} +2 -2
  101. package/dist/chunk-S3SX3COT.mjs +20 -0
  102. package/dist/chunk-SQ3FQCCN.mjs +8 -0
  103. package/dist/{chunk-ZO7SFB2E.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  104. package/dist/{chunk-3A5I2GJK.mjs → chunk-T4Y2ZSVX.mjs} +1 -1
  105. package/dist/{chunk-VG5JEIUQ.mjs → chunk-TKWEX4FD.mjs} +2 -2
  106. package/dist/{chunk-CCSGFCLZ.mjs → chunk-U3SSPL4K.mjs} +1 -1
  107. package/dist/{chunk-DHB7UZ7F.mjs → chunk-U5XL7D6A.mjs} +1 -1
  108. package/dist/{chunk-JXLSHVJ2.mjs → chunk-UMHUSOPJ.mjs} +1 -1
  109. package/dist/chunk-UTF7GBQU.mjs +4 -0
  110. package/dist/chunk-UTMAY3WK.mjs +2 -0
  111. package/dist/{chunk-S2Y7VI4H.mjs → chunk-V4ZHRALW.mjs} +2 -2
  112. package/dist/{chunk-GWOYMENX.mjs → chunk-V6XZ4VIR.mjs} +1 -1
  113. package/dist/{chunk-WTEGUPFG.mjs → chunk-VRPVVMRB.mjs} +1 -1
  114. package/dist/{chunk-XKOHV4H6.mjs → chunk-W5NPH5UA.mjs} +1 -1
  115. package/dist/{chunk-VGTMLQWZ.mjs → chunk-WD4U6XXT.mjs} +1 -1
  116. package/dist/{chunk-4DNHHJSL.mjs → chunk-XBNFXWAW.mjs} +1 -1
  117. package/dist/chunk-XZV72SQ4.mjs +2 -0
  118. package/dist/{chunk-QJ3TFJLQ.mjs → chunk-Y34NR5JL.mjs} +1 -1
  119. package/dist/{chunk-YBB5LWZK.mjs → chunk-YFJB534W.mjs} +1 -1
  120. package/dist/{chunk-V5JRSGZF.mjs → chunk-YN37ZDLW.mjs} +1 -1
  121. package/dist/chunk-Z6OKLRHC.mjs +2 -0
  122. package/dist/chunk-ZLS2FRS6.mjs +3 -0
  123. package/dist/{chunk-JI6T3A4Y.mjs → chunk-ZMHUDYLV.mjs} +1 -1
  124. package/dist/{chunk-KH24LWAT.mjs → chunk-ZTHICSSF.mjs} +1 -1
  125. package/dist/cli.mjs +1 -1
  126. package/dist/server.mjs +1 -1
  127. package/dist/worker.mjs +1 -1
  128. package/kit/math.js +1 -1
  129. package/kit/runtime.js +13 -2
  130. package/kit/state.js +2 -0
  131. package/kit/ui.js +5 -1
  132. package/package.json +1 -1
  133. package/release.json +7 -7
  134. package/skill/SKILL.md +13 -13
  135. package/skill/references/building-blocks.md +1 -1
  136. package/skill/references/extensions.md +45 -9
  137. package/web/assets/index-D8P8uhDW.js +15 -0
  138. package/web/assets/{index-xP0uw3a0.css → index-FLb9jCfl.css} +1 -1
  139. package/web/index.html +2 -2
  140. package/dist/chunk-46ACXOU5.mjs +0 -2
  141. package/dist/chunk-5DPABPBI.mjs +0 -2
  142. package/dist/chunk-5L26JUYA.mjs +0 -2
  143. package/dist/chunk-AEMVZYZQ.mjs +0 -166
  144. package/dist/chunk-ASAXY2DJ.mjs +0 -2
  145. package/dist/chunk-DAMVDXR3.mjs +0 -2
  146. package/dist/chunk-DLFZJJEE.mjs +0 -2
  147. package/dist/chunk-EKNHM3P4.mjs +0 -2
  148. package/dist/chunk-FCK6NXON.mjs +0 -3
  149. package/dist/chunk-FX42XU6J.mjs +0 -2
  150. package/dist/chunk-HATA2W7X.mjs +0 -2
  151. package/dist/chunk-JJNRIFND.mjs +0 -8
  152. package/dist/chunk-JL6R4FG4.mjs +0 -4
  153. package/dist/chunk-KUILYI7H.mjs +0 -4
  154. package/dist/chunk-NIW7F7LU.mjs +0 -4
  155. package/dist/chunk-OU3S466R.mjs +0 -20
  156. package/dist/chunk-QCEATQC4.mjs +0 -2
  157. package/dist/chunk-TDWJKOLN.mjs +0 -2
  158. package/dist/chunk-UGO5N3EI.mjs +0 -15
  159. package/dist/chunk-XMKHCUI6.mjs +0 -15
  160. package/dist/chunk-XQRUG4G3.mjs +0 -2
  161. package/dist/chunk-YPPJVDQI.mjs +0 -2
  162. package/dist/chunk-ZANMKAWS.mjs +0 -2
  163. package/web/assets/index-BHC5ZOMh.js +0 -15
  164. /package/dist/{chunk-N3DSBH5S.mjs → chunk-A55HN5OK.mjs} +0 -0
  165. /package/dist/{chunk-KNZJT4ET.mjs → chunk-QAIHRH3I.mjs} +0 -0
  166. /package/dist/{chunk-ZW2A6GBW.mjs → chunk-QR6A54KJ.mjs} +0 -0
  167. /package/dist/{chunk-74UW7QSL.mjs → chunk-UH4SIXTR.mjs} +0 -0
  168. /package/dist/{chunk-EKGYYOSP.mjs → chunk-W7XHE4CT.mjs} +0 -0
  169. /package/dist/{chunk-5MMN3N5J.mjs → chunk-YEY3RSFQ.mjs} +0 -0
@@ -1,15 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as 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
- `),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
- ${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
- `)}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(`
6
- `)).replaceAll("@fold-dots",Gs).replace(/^@kit-words;$/m,()=>Ke());return e.replace(/^@kit-look;$/m,()=>Ve(e))};function jt(t,{fresh:e=!1}={}){let s=qs(t);if(Zs)return V.promises.readFile(W.join(Js,t),"utf8");if(s.read)return V.promises.readFile(Z(s.read),"utf8");if(s.styles)return V.promises.readFile(Z(s.styles),"utf8").then(o=>Promise.all(Xs(s.styles,o).map(n=>V.promises.readFile(Z(n),"utf8")))).then(tn);if(e||!dt.has(t)){let o=fe(Ys(s.bundle,s.options)).then(n=>n.outputFiles[0].text);o.catch(()=>dt.delete(t)),dt.set(t,o)}return dt.get(t)}import{kitNamespace as en}from"../browser/shared/old-names.mjs";import{attr as Rt,hasClass as ht}from"../browser/shared/html-tree.mjs";var Ye=t=>t.tagName==="section"&&ht(t,"doc-section"),on=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),sn=t=>!on.has(t.tagName),ft=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(ft).join("");function Xe(t,e=[]){for(let s of t.childNodes??[])s.tagName&&((s.tagName==="main"&&ht(s,"doc-page")||Rt(s,"data-doc-sheet")!==void 0)&&e.push(s),Xe(s.tagName==="template"?s.content:s,e));return e}var nn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,Qe=["doc-summary","doc-panel","doc-note","doc-callout"],an=t=>nn.test(t.tagName)||Qe.some(e=>ht(t,e)),rn=new Set(["none","auto","100%","inherit","initial","unset","revert"]),qe=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,e])=>!rn.has(e.replace(/!important/i,"").trim().toLowerCase())),cn=t=>{let e=t.trim().split(/\s*[\s>+~]\s*/).at(-1)??"",s=/^(p|li|h[1-4]|blockquote|ul|ol)\b/.test(e)||Qe.some(n=>e.includes(`.${n}`)),o=[...t.matchAll(/\.([\w-]+)/g)].some(([,n])=>!en(n))||t.includes("#");return s&&!o};function ln(t){let e=[],s=(o,n)=>{for(let i of o.childNodes??[]){if(!i.tagName)continue;let r=n||i.tagName==="main"&&ht(i,"doc-page");if(r&&an(i)&&qe(Rt(i,"style")??"")&&e.push(`<${i.tagName}> with style="${Rt(i,"style").trim()}"`),i.tagName==="style"){let c=ft(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,a]of c.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(qe(a))for(let d of l.split(","))cn(d)&&e.push(`"${d.trim()}" in the document's style`)}s(i.tagName==="template"?i.content:i,r)}};return s(t,!1),e}function to(t,{written:e=t}={}){let s=[],o=w(t),n=ln(o);n.length>0&&s.push(`body text given a width of its own (${n.slice(0,3).join("; ")}${n.length>3?`; ${n.length-3} more`:""}): its lines break before the reading column's edge, leaving an extra right margin; let body text fill the column`);for(let i of Xe(o)){let r=i.childNodes.filter(c=>c.tagName);r.forEach((c,l)=>{if(!Ye(c))return;let a=l+1;for(;a<r.length&&sn(r[a]);)a++;let d=r.slice(l+1,a);if(d.length===0||!Ye(r[a]??{})||/^h[1-4]$/.test(d[0].tagName))return;let f=c.childNodes.map(g=>g.tagName?g:null).filter(Boolean).map(ft).find(g=>g.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"",[u]=d,h=ft(u).replace(/\s+/g," ").trim(),m=`<${u.tagName}>${h?` "${h.length>30?`${h.slice(0,30)}\u2026`:h}"`:""}`,p=u.sourceCodeLocation?.startLine;s.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${f}" stand outside it${p?` (line ${p})`:""}, ${d.length===1?`the ${m}`:`the first a ${m}`}, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return s.push(...Ae(t,{written:e})),s}import{attr as eo,hasClass as dn}from"../browser/shared/html-tree.mjs";var oo="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",fn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),hn=["doc-math-inline","doc-math-block"],un=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,pn=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,mn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,gn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,io=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,$n=/\.[A-Za-z0-9]{1,8}$/,wn=[/(?<![A-Za-z0-9_\\])[A-Za-z]:[\\/]/g,/(?<![A-Za-z0-9_.~:/\\-])\/(?:Users|home|root|tmp|private|mnt|opt|Volumes|var\/folders)\/(?=\S)/g,/(?<![A-Za-z0-9_.~:/\\-])~\/(?=\S)/g,/(?<![A-Za-z0-9_$\\])\$(?:HOME|\{HOME\})\/(?=\S)/g,/(?<![A-Za-z0-9_:\\])\\\\[A-Za-z0-9][\w.$-]*\\(?=[^\s\\])/g,/%(?:TEMP|TMP|APPDATA|LOCALAPPDATA|USERPROFILE)%/gi],bn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,kn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,yn=t=>t.includes("://")&&!/^file:/i.test(t),so=12;function no(t,e){let s=e;for(;s<t.length&&!mn.test(t[s])&&!(io.test(t[s])&&$n.test(t.slice(e,s)));)s++;return t.slice(e,s).replace(/[.,;:!?]+$/,"")}function xn(t,e=!1){let s=c=>c.replace(/[^\n]/g," "),o=t.replace(un,s),n=e?o.replace(pn,s):o,i=[],r=(c,l)=>i.some(a=>a.at<=c+l.length&&c<=a.at+a.path.length);for(let c of wn)for(let l of n.matchAll(c)){let a=no(n,l.index);a.length>=l[0].length+2&&!r(l.index,a)&&i.push({at:l.index,path:a})}for(let c of n.matchAll(gn)){let l=c.index;for(;l<c.index+c[0].length&&io.test(n[l]);)l++;let a=no(n,l);/[\\/]/.test(a)&&(bn.test(a)||kn.test(a))&&!yn(a)&&!r(l,a)&&i.push({at:l,path:a})}return i.sort((c,l)=>c.at-l.at)}function ao(t,e=w(t)){let s=[],o=(r,c)=>{for(let l of r.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:a,path:d}of xn(l.value,c))s.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,a).match(/\n/g)?.length??0),path:d})}else l.tagName&&!fn.has(l.tagName)&&eo(l,"hidden")===void 0&&!hn.some(a=>dn(l,a))&&o(l,c||eo(l,"data-doc-math-dollar")!==void 0)};o(e,!1);let n=s.slice(0,so).map(({line:r,path:c})=>`line ${r}: "${c.length>80?`${c.slice(0,77)}\u2026`:c}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${oo}`),i=s.slice(so);return i.length>0&&n.push(`${i.length} more path${i.length===1?"":"s"} of this machine in the text a reader reads, on line${new Set(i.map(({line:r})=>r)).size===1?"":"s"} ${[...new Set(i.map(({line:r})=>r))].join(", ")}. ${oo}`),n}import{elementsOf as ro}from"../browser/shared/html-tree.mjs";import{netSnapshot as Sn}from"../browser/shared/net-cache.mjs";import{hostIn as Nn,netHostsOf as vn}from"../browser/shared/net-policy.mjs";var On=(t,e)=>`<script type="application/json" data-doc-snapshot data-at="${e}">${JSON.stringify(t).replace(/</g,"\\u003c")}</script>`,Ft=t=>t.some(({needs:e})=>Array.isArray(e)&&e.includes("workspace"));function co(t,{slug:e,packages:s,root:o,at:n=new Date,workspace:i=null}){let r=s.flatMap(({needs:f})=>vn(f)),c=r.length===0?null:Sn(o,e,f=>{try{return Nn(new URL(f).hostname,r)!==null}catch{return!1}}),l={...i&&Ft(s)?i:{},...c?{net:c}:{}};if(Object.keys(l).length===0)return t;let a=ro(ro(w(t)).find(f=>f.tagName==="html")??{}).find(f=>f.tagName==="head"),d=a?.sourceCodeLocation?.endTag?.startOffset??a?.sourceCodeLocation?.startTag?.endOffset;return d===void 0?t:`${t.slice(0,d)} ${On(l,n.toISOString())}
7
- ${t.slice(d)}`}import{MENTION as En,MENTION_ICON as Tn}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Ln}from"../browser/shared/escape.mjs";import{attr as lo,elementsOf as An,hasClass as fo,walk as Cn}from"../browser/shared/html-tree.mjs";import{addressOn as zn,decoded as In,fromFile as jn,hosted as Rn,pageAddress as Fn,workbenchHash as _n}from"../browser/shared/page-address.mjs";function Dn(t,e,s){let o=jn(t,e),n=zn(o,s);return n||Rn(t)?n:Fn(o)??(_n(o)===null?null:{slug:null,block:null})}function Mn(t,e,s,o){let n=w(t),i=new Set,r=[];Cn(n,a=>{let d=lo(a,"data-block-id");d!==void 0&&i.add(d),a.tagName==="a"&&lo(a,"href")!==void 0&&a.sourceCodeLocation?.startTag&&r.push(a)});let c=new Map,l=({startOffset:a,endOffset:d})=>c.set(a,[d,""]);for(let a of r){let{prefix:d,value:f}=a.attrs.find(({name:k})=>k==="href"),u=f.startsWith("#")?In(f.slice(1)):null,h=u===null?f&&Dn(f,e,o):i.has(u)?{slug:e,block:u}:null;if(!h)continue;let m=s(h,f);if(m===f)continue;let{attrs:p,startTag:g,endTag:b}=a.sourceCodeLocation;if(m===null)l(g),b&&l(b),fo(a,En)&&An(a).filter(k=>fo(k,Tn)).forEach(k=>l(k.sourceCodeLocation));else{let k=d?`${d}:href`:"href";c.set(p[k].startOffset,[p[k].endOffset,`${k}="${Ln(m)}"`])}}return[...c].sort(([a],[d])=>d-a).reduce((a,[d,[f,u]])=>`${a.slice(0,d)}${u}${a.slice(f)}`,t)}function ho(t,e,s,{blocks:o=!0,links:n}){return Mn(t,e,({slug:i,block:r})=>{let c=s(i);if(c===null)return null;if(!r||!o)return i===e&&r?null:c;let l=`#${encodeURIComponent(r)}`;return i===e?l:`${c}${l}`},n)}import ut from"node:fs";import Pn from"node:path";import{extensionOf as Un,imageFile as Wn,mediaTypeOf as Bn}from"../browser/shared/media.mjs";var Mt=1024*1024,Hn=Mt,po=2400,_t=2e3,Kn=.25,Gn=new Set(["png","gif"]),uo=.75;function Jn(t){if(t.length<16||t.toString("latin1",0,4)!=="RIFF"||t.toString("latin1",8,12)!=="WEBP")return!1;for(let e=12;e+8<=t.length;){let s=t.toString("latin1",e,e+4);if(s==="VP8L")return!0;if(s==="VP8 "||s==="ANMF")return!1;let o=t.readUInt32LE(e+4);e+=8+o+o%2}return!1}function Vn(t){let e=(s,o)=>s+o<=t.length;if(e(0,24)&&t.readUInt32BE(0)===2303741511&&t.toString("latin1",12,16)==="IHDR")return{width:t.readUInt32BE(16),height:t.readUInt32BE(20)};if(e(0,10)&&/^GIF8[79]a$/.test(t.toString("latin1",0,6)))return{width:t.readUInt16LE(6),height:t.readUInt16LE(8)};if(e(0,4)&&t[0]===255&&t[1]===216){for(let s=2;e(s,4);){if(t[s]!==255)return null;let o=t[s+1];if(o===255){s+=1;continue}if(o===216||o===1||o>=208&&o<=215){s+=2;continue}if(o>=192&&o<=207&&![196,200,204].includes(o))return e(s,9)?{width:t.readUInt16BE(s+7),height:t.readUInt16BE(s+5)}:null;if(o===217||o===218)return null;s+=2+t.readUInt16BE(s+2)}return null}if(e(0,30)&&t.toString("latin1",0,4)==="RIFF"&&t.toString("latin1",8,12)==="WEBP"){let s=t.toString("latin1",12,16);if(s==="VP8 ")return{width:t.readUInt16LE(26)&16383,height:t.readUInt16LE(28)&16383};if(s==="VP8L"){let o=t.readUInt32LE(21);return{width:(o&16383)+1,height:(o>>>14&16383)+1}}return s==="VP8X"?{width:t.readUIntLE(24,3)+1,height:t.readUIntLE(27,3)+1}:null}if(e(0,12)&&t.toString("latin1",4,8)==="ftyp"&&/avi[fs]/.test(t.toString("latin1",8,Math.min(t.length,t.readUInt32BE(0))))){let s=null;for(let o=t.indexOf("ispe",0,"latin1");o>=0&&e(o,16);o=t.indexOf("ispe",o+4,"latin1")){let n={width:t.readUInt32BE(o+8),height:t.readUInt32BE(o+12)};(!s||n.width*n.height>s.width*s.height)&&(s=n)}return s}return null}var Zn=Mt;function Yn(t){let e;try{e=ut.openSync(t,"r");let{size:s}=ut.fstatSync(e),o=Buffer.alloc(Math.min(s,Zn));return ut.readSync(e,o,0,o.length,0),{length:s,head:o}}catch{return null}finally{e!==void 0&&ut.closeSync(e)}}var j=t=>`${Math.max(.1,t/Mt).toFixed(1)} MB`;function qn({bytes:t,width:e,height:s,extension:o,lossless:n}){let i=Math.max(e,s),r=Math.min(1,_t/i),c=Math.min(t,e*s*r*r*Kn);if(i>po){if(!n)return c<=t*uo?` \u2014 a ${_t}px copy would be about ${j(c)}`:"";let l=t*r*r;return` \u2014 a ${_t}px copy would be about ${j(l)}${o==="png"&&c<l/2?`, or ${j(c)} as a JPEG (for a photograph)`:""}`}return!n&&c<=t*uo?` \u2014 written again as a JPEG of quality about 82, it would be about ${j(c)}`:o==="png"&&c<t/2?` \u2014 as a JPEG (for a photograph) it would be about ${j(c)}`:""}var Dt=t=>t===2?"twice":`${t} times`;function mo({html:t,directory:e,tree:s=w(t)}){let{embedded:o,unserved:n}=le({html:t,directory:e,tree:s}),i=new Map,r=(l,a,d,f=!1)=>{let u=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);u.at.push(a),f||(u.shows+=1)};for(let{file:l,line:a,icon:d}of o)Wn(l)&&r(l,a,!0,d);for(let{file:l,line:a}of n)Bn(l).startsWith("image/")&&r(l,a,!1);let c=[];for(let[l,{at:a,shows:d,served:f}]of[...i].sort(([,u],[,h])=>Math.min(...u.at)-Math.min(...h.at))){let u=Yn(Pn.join(e,l));if(!u)continue;let{length:h,head:m}=u,p=Vn(m),g=p?Math.max(p.width,p.height):0,b=h>Hn||g>po,k=f&&d>1;if(!b&&!k)continue;let x=[...new Set(a)],v=`line${x.length===1?"":"s"} ${x.length>1?`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`:x[0]}`,T=k?`shown ${Dt(d)}: the export embeds it ${Dt(d)}; show it once and refer back to it in words`:"";if(!b){c.push(`${l} (${v}): ${T} (${j(Math.ceil(h/3)*4*d)} as data: URLs)`);continue}let H=a.length===1||!f?"":`, ${Dt(a.length)}`,R=f?a.length:1,q=`${j(Math.ceil(h/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,Uo=p?`, ${p.width}\xD7${p.height}px`:"",Kt=Un(l),Gt=p?qn({bytes:h,...p,extension:Kt,lossless:Gn.has(Kt)||Jn(m)}):"",Wo=f?`the export embeds it as it is${H}, ${q}${Gt}`:`its name keeps it out of the preview and the export (the failure at its line says why); copied into assets/ under a name they take, the export embeds it as it is, ${q}${Gt}: copy it in at the size the page needs`;c.push(`${l} (${v}): ${j(h)}${Uo}; ${Wo}${T?`; ${T}`:""}`)}return c}import{COMPONENTS as ui}from"../browser/shared/components/index.mjs";import{withLook as pi}from"../browser/shared/document-look.mjs";import{reportsDirectory as mi}from"../browser/shared/paths.mjs";import{documentLook as gi}from"../browser/shared/workspace-look.mjs";import go from"node:fs";import{MENTION as $o,MENTION_ICON as wo}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Xn,escapeText as Qn}from"../browser/shared/escape.mjs";import{iconUrl as ti,validIcon as ei}from"../browser/shared/emoji/icon-value.mjs";import{attr as oi,hasClass as si,walk as ni}from"../browser/shared/html-tree.mjs";import{fromFile as ii,isFileLink as ai,pageAddress as ri}from"../browser/shared/page-address.mjs";import{reportsDirectory as ci}from"../browser/shared/paths.mjs";import{documentDirectory as li,documentFiles as di}from"../browser/shared/workspace.mjs";function fi(t,e){let{html:s,json:o}=di(li(t,e));if(!go.existsSync(s))return null;try{let{title:n,icon:i}=JSON.parse(go.readFileSync(o,"utf8"));return{title:n,icon:i}}catch{return{}}}function hi(t,e,s,o){if(s==="words"||typeof t!="string"||!ei(t))return null;if(s==="preview")return ti(t,e,{tab:!0});let n=Qt({value:t,slug:e,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${n.body.toString("base64")}`}function bo(t,{slug:e,mode:s="export",reportsDirectory:o=ci}){if(!t.includes($o))return t;let n=new Map,i=c=>(n.has(c)||n.set(c,fi(c,o)),n.get(c)),r=new Map;return ni(w(t),c=>{let l=c.tagName==="a"&&si(c,$o)?oi(c,"href"):void 0,{startTag:a,endTag:d}=c.sourceCodeLocation??{};if(!l||!ai(l)||!a||!d)return;let f=ri(ii(l,e))?.slug;if(!f)return;let u=i(f);if(!u)r.set(a.endOffset-1,[a.endOffset-1," data-doc-gone"]);else if(u.title){let h=hi(u.icon,f,s,o);r.set(a.endOffset,[d.startOffset,`${h?`<img class="${wo}" src="${Xn(h)}" alt="">`:`<span class="${wo}"></span>`}${Qn(u.title)}`])}}),[...r].sort(([c],[l])=>l-c).reduce((c,[l,[a,d]])=>`${c.slice(0,l)}${d}${c.slice(a)}`,t)}var $i=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function wi(t,e,s){let o=Vt(e).filter(({id:n})=>!s.some(i=>i.id===n)).map(Zt).join(" ");return o?t.replace($i,n=>`${n}
8
- <script data-doc-dev>${o}</script>`):t}var ko=/(<title\b[^>]*>)\s*(<\/title>)/i;function bi(t){if(!ko.test(t))return t;let e=/^en\b/i.test(/<html\b[^>]*\slang=["']?([^"'\s>]*)/i.exec(t)?.[1]??"");return t.replace(ko,(s,o,n)=>`${o}${e?"Untitled":"\u672A\u547D\u540D\u6587\u6863"}${n}`)}function Pt(t,{slug:e,mode:s="export",files:o=!0,reportsDirectory:n,kit:i}){let{html:r,removed:c}=ki(t,{reportsDirectory:n,kit:i,describe:s==="preview"}),l={slug:e,mode:s,...n?{reportsDirectory:n}:{}},a=te(pi(r,gi(e,n??mi)),l),d=o?de(oe(ne(ae(a,l),l),l),l):a;return{html:bi(bo(d,l)),removed:c}}function ki(t,{reportsDirectory:e,kit:s,page:o=!1,describe:n=!1}){let i=E(e),r=L(t,i),{html:c,removed:l,used:a}=ue(t,[...ui,...r]),d=xe(pe(c,{used:a,page:o,...s?{href:s}:{}}),r);return{html:n?wi(d,i,r):d,removed:l,packages:r}}import{exportsDirectory as Wt,generatedDirectory as Y,kitPublicDirectory as Ci,release as zi,reportsDirectory as I,vendorDirectory as Ii}from"../browser/shared/paths.mjs";import{referencedFile as ji}from"../browser/shared/media.mjs";import{decoded as Ri,fromFile as Fi,hashAddress as _i,hosted as Co,pageAddress as Di,workbenchHash as Mi}from"../browser/shared/page-address.mjs";import{pageLinks as Pi}from"../browser/shared/page-links.mjs";import{documentLinks as Ui,listReportSlugs as Wi}from"../browser/shared/reports.mjs";import{documentDirectory as B,documentFiles as Ht}from"../browser/shared/workspace.mjs";import{sha256 as pt}from"../browser/shared/files.mjs";import{EXPORT_CSP as Bi,GENERATOR as Hi,isolateUmd as Ki,packagesMeta as Gi,sourceMeta as Ji}from"../browser/shared/export-wrap.mjs";var vo=/__REPORT_[A-Z_]+__/,Oo=1e6,Eo=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function Vi(t){return t.map(({id:e,lines:s,columns:o})=>{let n=new Set(s).size<s.length,i=s.map((r,c)=>n?`${r}:${o[c]}`:`${r}`);return`data-block-id repeats: "${e}" on lines ${Eo(i)}${n?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${Eo(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var Zi=({slug:t,htmlPath:e,metadataPath:s})=>{let o=e?{html:e,json:s??e.replace(/\.html$/,".json")}:Ht(B(t,I));return{htmlName:N.basename(o.html),jsonName:N.basename(o.json)}};function Yi({slug:t,html:e,metadata:s,htmlPath:o,metadataPath:n,tree:i=w(e)}){let r=[],{htmlName:c,jsonName:l}=Zi({slug:t,htmlPath:o,metadataPath:n}),a=/<h1\b[^>]*\bclass="[^"]*\bdoc-title\b[^"]*"[^>]*>\s*<\/h1>/i.test(e),d=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[a?/<title>\s*<\/title>|<title>[^<]+<\/title>/i:/<title>[^<]+<\/title>/i,"missing document title"],[/<main(?:\s|>)/i,"missing semantic main element"],[/aria-label|aria-labelledby|<title>/i,"missing accessible labels"]];for(let[p,g]of d)p.test(e)||r.push(g);let f=Buffer.byteLength(e);f>Oo&&r.push(`the document's editable source is ${f.toLocaleString("en-US")} bytes, over the ${Oo.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),vo.test(e)&&r.push(`${c} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,g]of Object.entries(s))typeof g=="string"&&vo.test(g)&&r.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(e)&&r.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let u=new Map;M(i,p=>{let g=O(p,"data-block-id"),b=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;g!==void 0&&u.set(g,[...u.get(g)??[],{line:b?.startLine,column:b?.startCol}])});let h=[...u].filter(([,p])=>p.length>1);r.push(...Vi(h.map(([p,g])=>({id:p,lines:g.map(({line:b})=>b),columns:g.map(({column:b})=>b)}))));let m=null;if(M(i,p=>{!m&&p.tagName==="main"&&(m=p)},{inTemplates:!1}),m){let p=O(m,"data-doc-id");p===void 0?r.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&r.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return r}var zo=t=>So(So(t).find(e=>e.tagName==="html")??{}).find(e=>e.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Bt=new Set(["localStorage","sessionStorage"]);function Io(t){let e=[],s=[];return M(t,o=>{o.tagName==="script"&&O(o,"src")!==void 0&&e.push(O(o,"src")),(o.tagName==="link"?(O(o,"rel")??"").toLowerCase().split(/\s+/):[]).includes("stylesheet")&&O(o,"href")!==void 0&&s.push(O(o,"href"))}),{scripts:e,styles:s}}function jo({slug:t,html:e,directory:s=B(t,I),tree:o=w(e),uses:n=Q(e,X,{tree:o}),catalog:i}){let r=[];zo(o)===void 0&&r.push("the page writes no <head> start tag, which an export puts its Content-Security-Policy right after: write <head> \u2026 </head> before <body>");let c=[];M(o,d=>{if(["script","link","img"].includes(d.tagName))for(let f of["src","href"]){let u=O(d,f)?.trim();u&&/^https?:\/\//i.test(u)&&c.push(u)}}),c.length>0&&r.push(`external resources are not portable: ${c.join(", ")}`);for(let{name:d,how:f,line:u,where:h}of n){if(!X.has(d))continue;let m={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[f]??`uses ${d}`;r.push(`line ${u}: ${h} ${m}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:a}=Io(o);for(let d of l)we.has(d)||r.push(`unsupported script dependency ${d}`);for(let d of a)be.has(d)||r.push(`unsupported stylesheet dependency ${d}`);return r.push(...re({html:e,directory:s,tree:o}),...ie({html:e,directory:s,tree:o}),...se({html:e,directory:s,tree:o}),...ce({html:e,directory:s,tree:o})),r.push(...Se(L(e,i,o))),[...new Set(r)]}var qi=[[/\bDocSheets\.mount\s*\(/,"Sheet areas start on their own: remove DocSheets.mount (an area keeps its tab under its data-doc-sheets name)"],[/\bDocCode\.(?:View|DiffView|DiffStats|enhance)\b/,'code blocks are highlighted on their own, and a diff is declared as <div class="doc-diff"> holding { path, lines } as JSON (sdk/doc-code.d.ts)'],[/\bDocTables\.(?:enhance|enhanceAll|makeSortable)\b/,"tables start on their own: remove the call"],[/\bDocDialogs\.(?:enhance|enhanceAll)\b/,"detail cards start on their own: remove the call"]];function Xi({html:t,tree:e=w(t),uses:s=Q(t,Bt,{tree:e})}){let o=ke(t,e),n=[...me(t,e),...ge(t,e)];for(let[i,r]of qi)i.test(o)&&n.push(`${o.match(i)[0].replace(/\s*\($/,"")} is gone: ${r}`);for(let{name:i,line:r,where:c}of s)Bt.has(i)&&n.push(`line ${r}: ${c} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(n)]}var Qi=(t,e)=>e.childNodes.find(s=>s.tagName||s.nodeName==="#text"&&s.value.trim())===t,ta=t=>xo(t,Ni("highlight").match)||t.tagName==="li"&&xo(t.parentNode,`ol.${vi}`),ea=`an icon is one of three kinds: an emoji, <div class="doc-icon">\u{1F3AF}</div>; an icon of Gallery's sets in one of ${No.length} colors, <div class="doc-icon" data-icon="/icons/airplane_blue.svg"></div> (MingCute's names; Tabler's as /icons/tabler/plane_blue.svg; the colors ${No.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,Ro=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Ro).join("");function To(t,e,s){let o=e.sourceCodeLocation?.attrs?.[s],n=o?t.slice(o.startOffset,o.endOffset):`${s}="${O(e,s)??""}"`;return n.length>72?`${n.slice(0,71)}\u2026`:n}function oa(t,e){let s=O(e,"data-icon");if(s!==void 0)return{held:To(t,e,"data-icon"),meant:Ut(s)==="glyph"?s:null};let o=null;if(M(e,i=>{o??=["img","svg"].includes(i.tagName)?i:null}),o?.tagName==="img"){let i=O(o,"src");return{held:`<img ${To(t,o,"src")}>`,meant:Ut(i)==="image"?i:null}}if(o)return{held:"an <svg>"};let n=Ro(e).replace(/\s+/g," ").trim();return{held:n?`"${n.slice(0,40)}"`:"nothing"}}function sa({set:t,name:e,color:s}){let o=Oi.find(r=>r!==t);if(gt(o).includes(e))return`; "${e}" is ${o==="tabler"?"Tabler":"MingCute"}'s: ${Ti(o,e,s)}`;let n=e.split("-").filter(r=>r.length>=3),i=gt(t).filter(r=>r.split("-").some(c=>n.includes(c))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function na({html:t,tree:e=w(t)}){let{all:s,own:o}=ee(e),n=[],i=r=>r.sourceCodeLocation?.startLine;o.length>1&&n.push(`line ${i(o[1])}: ${o.length} page icons (.doc-icon) in the header (the first at line ${i(o[0])}): a document has one, right before its title`);for(let r of s){let c=i(r),l=r.parentNode;!o.includes(r)&&!(ta(l)&&Qi(r,l))&&n.push(`line ${c}: an icon (.doc-icon) stands only right before the document's title, first in a highlight block (.doc-panel, .doc-summary), or first in a flowchart's step (ol.doc-flow > li, in its number's place)`);let a=Ai(Yt(t,r)),{held:d,meant:f}=a?{}:oa(t,r);f?n.push(`line ${c}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Li(f)}`):a?Ut(a)==="glyph"&&!Xt(a)&&n.push(`line ${c}: the icon ${a} is none of the icon sets' (MingCute: /icons/<name>_<color>.svg, Tabler: /icons/tabler/<name>_<color>.svg; src/shared/emoji/data/icons.json lists the names of each)${sa(Ei(a))}`):n.push(`line ${c}: an icon (.doc-icon) holds no icon (it holds ${d}): ${ea}`)}return[...new Set(n)]}function Fo(t){let e=w(t.html),s={...t,tree:e,uses:Q(t.html,new Set([...X,...Bt]),{tree:e})};return[...Yi(s),...At(t.html,e),...Xi(s),...na(s),...jo(s)]}function ia(t){let e=new Map(t.map(n=>[n.slug,[...Fo(n),...vt(n.html)]])),s=new Map(t.map(n=>[N.resolve(n.htmlPath),n.slug])),o=new Map(t.map(n=>[N.resolve(n.htmlPath),n]));for(let n of t)n.scriptNotes=[];if(t.length>0)for(let{htmlPath:n,text:i,typeOnly:r,note:c}of ye(t)){if(r){o.get(n)?.scriptNotes.push(c);continue}let l=n?[s.get(n)]:[...e.keys()];for(let a of l)e.get(a).push(n?i:`${i} (shared SDK declaration)`)}for(let[n,i]of e)i.length===0&&e.delete(n);return e}async function Ic(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let n of s){let i=[...Fo(n),...vt(n.html)];i.length&&o.set(n.slug,i)}return o}async function aa(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await mt(t,{prepare:e});for(let[n,i]of ia(s))o.set(n,i);return{reports:s,failures:o}}async function ra({fresh:t=!1,kit:e=Ci,vendor:s=Ii}={}){if(zi)return;let o=K.map(r=>[r,r.file?jt(r.file,{fresh:t}):bt(r)]);await S.mkdir(e,{recursive:!0});let n=N.join(s,"katex","fonts");await S.mkdir(n,{recursive:!0});let i=(await S.readdir(wt)).filter(r=>r.endsWith(".woff2"));await Promise.all(i.map(r=>S.copyFile(N.join(wt,r),N.join(n,r)))),await Promise.all(o.map(async([r,c])=>S.writeFile(r.file?N.join(e,r.file):N.join(s,...r.vendor.path.split("/").slice(2)),await c)))}async function ca(t,e){let s=await S.readdir(t).catch(()=>[]);await Promise.all(s.filter(o=>o.endsWith(".html")&&!e.has(o.slice(0,-5))).map(o=>S.rm(N.join(t,o),{force:!0})))}async function la(t){let e=N.join(Y,"reports.json"),s=await S.readFile(e,"utf8").then(JSON.parse,()=>[]),o=new Map(Array.isArray(s)?s.map(i=>[i.slug,i]):[]);for(let{entry:i}of t)o.set(i.slug,i);let n=[];for(let[i,r]of[...o].sort(([c],[l])=>c.localeCompare(l))){let c=N.join(Y,`${i}.html`);await S.stat(c).then(()=>!0,()=>!1)&&n.push(r)}await S.writeFile(e,`${JSON.stringify(n,null,2)}
9
- `)}async function da(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await aa(t,{prepare:e});await ra(),await S.mkdir(Y,{recursive:!0}),await ca(Y,new Set(await Wi()));let n=[];for(let i of s){let r=`${i.slug}.html`,c=N.join(Y,r);if(o.has(i.slug)){await S.rm(c,{force:!0});continue}let{html:l,removed:a}=Pt(i.html,{slug:i.slug});await S.writeFile(c,l),n.push({report:i,html:l,removed:a,entry:{slug:i.slug,...i.metadata,preview:`/generated/${r}`,sourceSha256:pt(i.html),outputSha256:pt(l)}})}return await la(n),{built:n,failures:o}}var fa=t=>t.replace(/<\/script/gi,"<\\/script");async function _o(){return new Map(await Promise.all(K.map(async t=>{let e=await(t.file?jt(t.file):bt(t,{inline:!0}));return he(t).endsWith(".css")||(e=fa(e)),[t.id,t.umd?Ki(e):e]})))}function ha(t,e,s=null,o=[]){let n=zo(w(e));if(n===void 0)throw new Error(`${t}: the page writes no <head> start tag, which the export's Content-Security-Policy goes right after`);let i=s?`
10
- ${Ji(s)}${o.length>0?`
11
- ${Gi(o)}`:""}`:"";return`${e.slice(0,n)}
12
- <meta name="generator" content="${Hi}">
13
- <meta http-equiv="Content-Security-Policy" content="${Bi}">${i}${e.slice(n)}`}function Do(t,e,s,o=null,n=E(),i=I,r=null){let c=L(e,n);e=co(ha(t,e,o,c),{slug:t,packages:c,root:i,workspace:r}),e=$e(Ne(e,n),({id:d,element:f,attribute:u})=>{let h=s.get(d);if(typeof h!="string")throw new Error(`${t}: no inline source for the asset "${d}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${f} ${u}="${d}-inline">${h}</${f}>`});let{scripts:l,styles:a}=Io(w(e));if(l.length+a.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return e}async function Lo(t,e=I,{components:s=!0}={}){let o=B(t,e),n=await S.readFile(Ht(o).html),i=n.toString("utf8"),r=w(i),c=s?E(e):{packages:new Map},l=[...s?At(i,r,c):[],...jo({slug:t,html:i,directory:o,tree:r,catalog:c})];if(l.length>0){let a=L(i,c,r).find(({id:d})=>l[0].startsWith(`${d}:`)||l[0].startsWith(`${d} (`))?.id;throw Object.assign(new Error(`${t}: ${l[0]}`),{reason:"check",slug:t,failures:l,...a?{component:a}:{}})}return{html:i,sha256:pt(n)}}async function jc({directory:t=I,workspace:e=null}={}){let s=await _o(),o=async(n,{files:i=!0}={})=>{let r=await Lo(n,t),c=Pt(r.html,{slug:n,files:i,reportsDirectory:t}).html,l=E(t);return Do(n,c,s,r.sha256,l,t,await Mo(e,n,c,l))};return o.check=async n=>{await Lo(n,t,{components:!1})},o}async function Mo(t,e,s,o){return typeof t!="function"||!Ft(L(s,o))?null:await t(e).catch(()=>null)??null}async function Rc(t=[],{prepare:e=null,workspace:s=null}={}){let{built:o,failures:n}=await da(t,{prepare:e}),i=await _o();await S.mkdir(Wt,{recursive:!0});let r=new Set(o.map(({report:a})=>a.slug)),{links:c}=await Ui(),l=[];for(let{report:a,html:d}of o)try{let f=ho(d,a.slug,h=>r.has(h)?`${h}.html`:null,{links:c}),u=Do(a.slug,f,i,a.fileSha256,E(),I,await Mo(s,a.slug,f,E()));await S.writeFile(N.join(Wt,`${a.slug}.html`),u),l.push({slug:a.slug,bytes:Buffer.byteLength(u),sha256:pt(u)})}catch(f){n.set(a.slug,[f.message])}return{built:o,exported:l,failures:n}}function Ao(t){let e=new Set;return M(t,s=>{for(let o of["id","data-block-id"])O(s,o)!==void 0&&e.add(O(s,o))}),e}function ua(t,e,s){if(Co(t)||/^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(t)||ji(t))return!1;let{pathname:o}=new URL(e);return!o.startsWith(`/${s}/`)||o.endsWith(".html")}function pa({slug:t,tree:e,directory:s}){let o=[],n=Ao(e),i=s===B(N.basename(s),I)?I:N.dirname(s),r=new Map([[t,n]]),c=d=>{if(!r.has(d)){let f=Ht(B(d,i));r.set(d,yo(f.html)?Ao(w(yi(f.html,"utf8"))):null)}return r.get(d)},l=null,a=(d,f)=>f===null?Di(d):_i(f,l??=Pi((yo(i)?xi(i):[]).map(u=>({slug:u}))));return M(e,d=>{let f=d.tagName==="a"?O(d,"href"):void 0;if(!f||f==="#"||f==="#top")return;let u=d.sourceCodeLocation?.startLine;if(f.startsWith("#")){n.has(Ri(f.slice(1)))||o.push(`the link to ${f} (line ${u}) names no block or element of this document`);return}let h=Fi(f,t),m=Mi(h),p=a(h,m);(p?!c(p.slug):m!==null)?Co(f)||o.push(`the link to ${f} (line ${u}) names a document that is not there: gallery list has the slugs`):p?.block&&!c(p.slug).has(p.block)?o.push(`the link to ${f} (line ${u}) names a block document ${p.slug} does not hold`):h&&!p&&ua(f,h,t)&&o.push(`the link to ${f} (line ${u}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},Si),o}function Po({slug:t,html:e,directory:s=B(t,I),written:o=e,scriptNotes:n=[]}){let i=w(e),r=ze(e);return{fix:[...ao(e,i),...mo({html:e,directory:s,tree:i})],notes:[...to(e,{written:o}),...Be(i),...pa({slug:t,tree:i,directory:s}),...r.notes,...n],readings:r.readings}}function Fc(t){let{fix:e,notes:s}=Po(t);return[...e,...s]}function _c(t){let e=t.map(s=>[s.slug,Po(s)]);for(let[s,{fix:o}]of e)for(let n of o)console.log(`fix ${s}: ${n}`);for(let[s,{notes:o}]of e)for(let n of o)console.log(`note ${s}: ${n}`);for(let[s,{readings:o}]of e)for(let n of o)console.log(`chart ${s}: ${n}`)}async function ma(t,{exportNote:e=!1}={}){for(let[s,o]of t){console.error(`
14
- FAIL ${s}: ${o.length} problem${o.length===1?"":"s"}`);for(let i of o)console.error(` - ${i}`);let n=N.join(Wt,`${s}.html`);e&&await S.stat(n).then(()=>!0,()=>!1)&&console.error(` ${n} was not updated; it still holds an earlier export.`)}}function ga(t,{above:e=!1,allow:s=process.argv.includes("--allow-failures")}={}){t.size!==0&&(console.error(`
15
- ${t.size} document${t.size===1?"":"s"} failed: ${[...t.keys()].join(", ")}${e?" (the failures are listed first, above)":""}`),s||(process.exitCode=1))}async function Dc(t,{exportNote:e=!1,allow:s}={}){await ma(t,{exportNote:e}),ga(t,{allow:s})}export{Ts as a,Mn as b,ho as c,bo as d,Pt as e,ki as f,Vi as g,jo as h,Fo as i,ia as j,Ic as k,aa as l,ra as m,da as n,ha as o,jc as p,Rc as q,Po as r,Fc as s,_c as t,ma as u,ga as v,Dc as w};
@@ -1,2 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{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 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as 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};
@@ -1,2 +0,0 @@
1
- import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as 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};