@heycys/gallery 0.2.0 → 0.2.2

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 (144) 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/annotate/index.mjs +3 -2
  5. package/browser/editor/page/board/index.mjs +2 -1
  6. package/browser/editor/page/board/settings.mjs +2 -1
  7. package/browser/editor/page/clipboard/import/read.mjs +20 -2
  8. package/browser/editor/page/core.mjs +3 -2
  9. package/browser/editor/page/custom-page.mjs +4 -3
  10. package/browser/editor/page/editor.mjs +9 -5
  11. package/browser/editor/page/emoji-picker/support.mjs +3 -2
  12. package/browser/editor/page/links/index.mjs +1 -12
  13. package/browser/editor/page/links/pages.mjs +3 -2
  14. package/browser/editor/page/outline/folds.mjs +3 -0
  15. package/browser/editor/page/post.mjs +2 -1
  16. package/browser/editor/page/present-links.mjs +4 -3
  17. package/browser/editor/page/present-shell.mjs +3 -58
  18. package/browser/editor/page/session.mjs +3 -37
  19. package/browser/editor/page/storage.mjs +5 -5
  20. package/browser/shared/component-catalog.mjs +2 -2
  21. package/browser/shared/document-copy.mjs +43 -0
  22. package/browser/shared/drafts.mjs +32 -50
  23. package/browser/shared/emoji/icon-value.mjs +4 -3
  24. package/browser/shared/extension-manifest.mjs +90 -0
  25. package/browser/shared/extensions.mjs +93 -7
  26. package/browser/shared/http.mjs +1 -1
  27. package/browser/shared/i18n/en.mjs +55 -14
  28. package/browser/shared/media.mjs +2 -1
  29. package/browser/shared/outline-shape.mjs +6 -0
  30. package/browser/shared/outline.mjs +95 -10
  31. package/browser/shared/page-address.mjs +8 -15
  32. package/browser/shared/paths.mjs +2 -1
  33. package/browser/shared/preferences.mjs +3 -1
  34. package/browser/shared/preview-server.mjs +51 -63
  35. package/browser/shared/service-location.mjs +18 -0
  36. package/browser/shared/session.mjs +3 -6
  37. package/browser/shared/workspace-address.mjs +19 -0
  38. package/browser/shared/workspace-columns.mjs +12 -9
  39. package/browser/shared/workspace-registry.mjs +6 -40
  40. package/browser/shared/workspace.mjs +3 -6
  41. package/browser/shared/writing-preferences.mjs +6 -4
  42. package/dist/{chunk-W7665ZEC.mjs → chunk-236JJXWY.mjs} +2 -2
  43. package/dist/{chunk-EAIFITAV.mjs → chunk-2KAVXMKG.mjs} +1 -1
  44. package/dist/chunk-2T4PZQEP.mjs +2 -0
  45. package/dist/{chunk-HXG7EOPJ.mjs → chunk-3SKOU6OZ.mjs} +1 -1
  46. package/dist/{chunk-AR5D57ZD.mjs → chunk-3XZOA7AH.mjs} +2 -2
  47. package/dist/{chunk-UYVCQK3H.mjs → chunk-4B2TB5K2.mjs} +1 -1
  48. package/dist/{chunk-3MBRL2PM.mjs → chunk-4KUO7R2M.mjs} +8 -8
  49. package/dist/chunk-4SNV4HA5.mjs +2 -0
  50. package/dist/chunk-53XDTHTG.mjs +4 -0
  51. package/dist/chunk-5XV3YYLG.mjs +2 -0
  52. package/dist/{chunk-ZDLPUOAG.mjs → chunk-65NTKF4N.mjs} +1 -1
  53. package/dist/chunk-6GV3CBB2.mjs +2 -0
  54. package/dist/{chunk-WQDQWCX5.mjs → chunk-6L6V7YR2.mjs} +1 -1
  55. package/dist/{chunk-ITOH5EGO.mjs → chunk-6NLXUKAY.mjs} +1 -1
  56. package/dist/chunk-6Q7ASAXJ.mjs +3 -0
  57. package/dist/{chunk-7OG26PGF.mjs → chunk-6QWQXHAV.mjs} +1 -1
  58. package/dist/chunk-6XD6U3QA.mjs +5 -0
  59. package/dist/{chunk-YNAWBAYN.mjs → chunk-7EFHNQ5B.mjs} +1 -1
  60. package/dist/{chunk-OFHXGWOX.mjs → chunk-7ISBBDJR.mjs} +1 -1
  61. package/dist/{chunk-QE5RG76S.mjs → chunk-7UZUQQ7Q.mjs} +29 -24
  62. package/dist/chunk-BLNQUR5R.mjs +168 -0
  63. package/dist/chunk-BMX3VUHY.mjs +2 -0
  64. package/dist/chunk-BN7M3IN7.mjs +8 -0
  65. package/dist/{chunk-K5XATEOO.mjs → chunk-BQNTTFPL.mjs} +1 -1
  66. package/dist/chunk-C257H6IA.mjs +2 -0
  67. package/dist/chunk-CHQU37CA.mjs +2 -0
  68. package/dist/{chunk-CMA72MAG.mjs → chunk-E4IHAIJ7.mjs} +1 -1
  69. package/dist/{chunk-VS7JIGJW.mjs → chunk-E7656LR7.mjs} +1 -1
  70. package/dist/{chunk-VFX2KNHP.mjs → chunk-ECZBLQKK.mjs} +1 -1
  71. package/dist/{chunk-MN7BZL4R.mjs → chunk-ERE2BXYV.mjs} +1 -1
  72. package/dist/chunk-FFV733MA.mjs +2 -0
  73. package/dist/{chunk-AHN3NFKJ.mjs → chunk-GJJRBGMY.mjs} +1 -1
  74. package/dist/{chunk-BZ5RAF7L.mjs → chunk-GKOBB6DH.mjs} +1 -1
  75. package/dist/chunk-GMJD7ID3.mjs +2 -0
  76. package/dist/{chunk-OEXWRJME.mjs → chunk-IA2SIEJQ.mjs} +1 -1
  77. package/dist/chunk-JPG2LBQM.mjs +11 -0
  78. package/dist/{chunk-POTA2FV4.mjs → chunk-JXXHAXYH.mjs} +1 -1
  79. package/dist/{chunk-FDMAXMQA.mjs → chunk-K3JKPFL5.mjs} +1 -1
  80. package/dist/{chunk-J5PUIV3Y.mjs → chunk-KLQP46Y3.mjs} +1 -1
  81. package/dist/chunk-LMUZQK5O.mjs +2 -0
  82. package/dist/{chunk-JLTZF4LA.mjs → chunk-M4NRDYI5.mjs} +1 -1
  83. package/dist/{chunk-HPOI4ZX7.mjs → chunk-MKIBJTJZ.mjs} +1 -1
  84. package/dist/{chunk-5K44HLTZ.mjs → chunk-MNWJ4EZY.mjs} +1 -1
  85. package/dist/{chunk-FETSREUN.mjs → chunk-NHP66IWR.mjs} +1 -1
  86. package/dist/{chunk-PGDE24N5.mjs → chunk-OEIJLMPI.mjs} +1 -1
  87. package/dist/{chunk-YROX2O22.mjs → chunk-PDZR3L3C.mjs} +1 -1
  88. package/dist/{chunk-6N3PX4XX.mjs → chunk-PLB7L22J.mjs} +1 -1
  89. package/dist/{chunk-LM4XFQHZ.mjs → chunk-Q4MS6OFC.mjs} +1 -1
  90. package/dist/{chunk-7JDX4E65.mjs → chunk-Q7P3Q5YX.mjs} +1 -1
  91. package/dist/{chunk-ZHEHPMBK.mjs → chunk-QNECWMGR.mjs} +1 -1
  92. package/dist/{chunk-YI43RG4P.mjs → chunk-QP7BOHE4.mjs} +1 -1
  93. package/dist/chunk-QVGOPHOF.mjs +2 -0
  94. package/dist/{chunk-DAZL73VK.mjs → chunk-RRKJMHNX.mjs} +2 -2
  95. package/dist/chunk-S3SX3COT.mjs +20 -0
  96. package/dist/{chunk-HDWTZ763.mjs → chunk-TKWEX4FD.mjs} +2 -2
  97. package/dist/{chunk-YLPSMDIS.mjs → chunk-ULXSPX5H.mjs} +2 -2
  98. package/dist/chunk-USIHBCSW.mjs +15 -0
  99. package/dist/{chunk-TR7TWGHB.mjs → chunk-VPMRP2TL.mjs} +1 -1
  100. package/dist/{chunk-ZQS6H473.mjs → chunk-VRPVVMRB.mjs} +1 -1
  101. package/dist/{chunk-F6HVDZR4.mjs → chunk-VZ2RQ3AM.mjs} +1 -1
  102. package/dist/{chunk-R2ZDLJYT.mjs → chunk-W5NPH5UA.mjs} +1 -1
  103. package/dist/chunk-WFGPMCTZ.mjs +4 -0
  104. package/dist/chunk-XZCFPKGO.mjs +2 -0
  105. package/dist/{chunk-4OKWZY5E.mjs → chunk-YN37ZDLW.mjs} +1 -1
  106. package/dist/chunk-ZFGMJVJC.mjs +2 -0
  107. package/dist/cli.mjs +1 -1
  108. package/dist/server.mjs +1 -1
  109. package/dist/worker.mjs +1 -1
  110. package/kit/report.css +3 -3
  111. package/kit/runtime.js +12 -2
  112. package/kit/state.js +2 -0
  113. package/kit/ui.js +5 -1
  114. package/package.json +1 -1
  115. package/release.json +7 -7
  116. package/skill/SKILL.md +13 -12
  117. package/skill/references/building-blocks.md +1 -1
  118. package/skill/references/extensions.md +48 -8
  119. package/web/assets/index-FLb9jCfl.css +1 -0
  120. package/web/assets/index-czjrXVjf.js +15 -0
  121. package/web/index.html +2 -2
  122. package/dist/chunk-5XA2ZBAE.mjs +0 -8
  123. package/dist/chunk-67N2QJYT.mjs +0 -2
  124. package/dist/chunk-6KBYRA2C.mjs +0 -2
  125. package/dist/chunk-DJISHPUL.mjs +0 -3
  126. package/dist/chunk-EKNHM3P4.mjs +0 -2
  127. package/dist/chunk-EP25HDAJ.mjs +0 -2
  128. package/dist/chunk-GHOYKMQ3.mjs +0 -4
  129. package/dist/chunk-IV64FFI4.mjs +0 -2
  130. package/dist/chunk-J43Z6LSS.mjs +0 -2
  131. package/dist/chunk-JA7G53PC.mjs +0 -2
  132. package/dist/chunk-JZT7I2OJ.mjs +0 -2
  133. package/dist/chunk-L2SUIS5S.mjs +0 -2
  134. package/dist/chunk-L7UP52JO.mjs +0 -2
  135. package/dist/chunk-MTYYHM2G.mjs +0 -15
  136. package/dist/chunk-MXUBKDRO.mjs +0 -15
  137. package/dist/chunk-NAMN3RAF.mjs +0 -2
  138. package/dist/chunk-ORID3AE7.mjs +0 -166
  139. package/dist/chunk-SWUTTZCN.mjs +0 -2
  140. package/dist/chunk-U7NZI6N4.mjs +0 -4
  141. package/dist/chunk-UJQJKNGK.mjs +0 -2
  142. package/dist/chunk-ZWWC4KLF.mjs +0 -20
  143. package/web/assets/index-BM_K-Auu.css +0 -1
  144. package/web/assets/index-DRslOBiv.js +0 -15
@@ -0,0 +1,20 @@
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 De,b as Fe}from"./chunk-IA4PSIMD.mjs";import{b as Ie}from"./chunk-F4ZA6JRZ.mjs";import{a as be,b as Ne,c as ht,d as Te,e as Ee,f as Re}from"./chunk-6NLXUKAY.mjs";import{b as je,c as Me,e as Ae,g as Gt}from"./chunk-VRPVVMRB.mjs";import{a as he}from"./chunk-UMHUSOPJ.mjs";import{a as $e,d as xe,e as Se,f as ve,g as Oe}from"./chunk-W5NPH5UA.mjs";import{e as ye,f as ge,g as ke,h as Kt}from"./chunk-ECZBLQKK.mjs";import{a as J,m as we}from"./chunk-E7656LR7.mjs";import{g as me,u as pe}from"./chunk-TKWEX4FD.mjs";var Mn=3e4,An=12e4,Nn=1500,Je=1e4,Pe=p=>p.reduce((u,{key:d,tag:f})=>u.set(`${d}
3
+ ${f}`,(u.get(`${d}
4
+ ${f}`)??0)+1),new Map);function Le({now:p=Date.now,hold:u=Mn,limit:d=An,quiet:f=Nn}={}){let b=new Map,h=new Map,x=new Map,l=new Map,c=new Map;return{wrote(g,k){l.set(g,J(k))},judge(g,{source:k,mtime:R}){if(k===null)return b.delete(g),x.delete(g),{held:!1,signs:[],wait:0,own:!1};let N=J(k),S=c.get(g)?.hash===N?c.get(g).signs:null;S||(S=Ne(k),c.set(g,{hash:N,signs:S}));let Q=p(),L=(U,D=!1)=>(b.delete(g),h.set(g,Pe(S)),x.set(g,k),{held:!1,signs:[],wait:U,own:D});if(l.get(g)===N)return L(0,!0);let _=h.get(g)??new Map,z=Pe(S);if([...z].some(([U,D])=>D>(_.get(U)??0))){let U=Math.min(R,Q),D=b.get(g)??U;b.set(g,D);let V=Math.min(u-(Q-U),d-(Q-D));if(V>0)return{held:!0,signs:S.filter(({key:s,tag:w})=>z.get(`${s}
5
+ ${w}`)>(_.get(`${s}
6
+ ${w}`)??0)),wait:V,own:!1,taken:x.get(g)}}return L(Math.min(f,Math.max(0,f-(Q-R))))}}}import{documentKey as nr}from"../browser/shared/workspace-address.mjs";import{serviceLocation as rr}from"../browser/shared/service-location.mjs";import{createHmac as or,randomBytes as ee}from"node:crypto";import{existsSync as ar,mkdirSync as sr,readFileSync as ir,writeFileSync as cr}from"node:fs";import H from"node:fs/promises";import P from"node:path";import{FILE as fr}from"../browser/shared/annotations.mjs";import{escapeTyped as lr}from"../browser/shared/escape.mjs";import{writeAtomic as Jt}from"../browser/shared/files.mjs";import{sendJson as Y}from"../browser/shared/http.mjs";import{REQUEST_ID as Xt}from"../browser/shared/ids.mjs";import{UPLOAD_REQUEST_LIMIT as ur}from"../browser/shared/media.mjs";import{reportsDirectory as dr}from"../browser/shared/paths.mjs";import{sameDirectory as mr}from"../browser/shared/preview-server.mjs";import{slugPattern as rt}from"../browser/shared/reports.mjs";import{TODO_MOST as pr}from"../browser/shared/workspace-query.mjs";import{documentDirectory as wr,documentFiles as Nt,isDocumentSource as hr}from"../browser/shared/workspace.mjs";import Qt from"node:fs/promises";import _e from"node:path";import{checkAnnotations as Tn,cleanAnchor as En,cleanItem as Ue,FILE as Rn,itemsText as In,readItems as Dn,treeText as We}from"../browser/shared/annotations.mjs";import{writeAtomic as Fn}from"../browser/shared/files.mjs";import{slugPattern as Pn}from"../browser/shared/reports.mjs";import{documentDirectory as Be,documentFiles as Jn}from"../browser/shared/workspace.mjs";var Ln=600*1e3,_n=600*1e3;function Un(p){let{units:u,boxes:d}=ke(p),f=[...u].sort((l,c)=>l.elStart-c.elStart),b=new Map(f.map((l,c)=>[l.id,c])),h=new Map(f.map(l=>[l.id,We(l.node)])),x={h2:null,h3:null,h4:null};return f.map(l=>{let c=[];for(let N=l;N;N=N.parent===null?null:u[N.parent]){let S=d[N.box];if(S?.kind==="panel"&&S.key!==null){let L=u.find(_=>_.kind==="tab"&&_.parent===S.unit&&_.key===S.key);L&&c.unshift({tab:h.get(L.id)})}let Q=S?.unit===null||S?.unit===void 0?null:u[S.unit];if(Q?.tag==="details"&&S.kind==="details"){let L=Q.node.childNodes.find(_=>_.tagName==="summary");L&&c.push({details:We(L)})}}let g=c.find(N=>N.tab)?.tab,k=c.find(N=>N.details)?.details,R=[g,x.h2,x.h3,x.h4,k].filter(Boolean);return l.tag==="h2"?Object.assign(x,{h2:h.get(l.id),h3:null,h4:null}):l.tag==="h3"?Object.assign(x,{h3:h.get(l.id),h4:null}):l.tag==="h4"&&(x.h4=h.get(l.id)),{id:l.blockId,text:h.get(l.id),parent:l.parent===null?null:b.get(l.parent)??null,where:R,heading:/^h[2-4]$/.test(l.tag)}})}function Ye({reportsDirectory:p,read:u,write:d=Fn,dropped:f=()=>{},now:b=Date.now}){let h=new Map,x=new Map,l=new Map,c=(s,w)=>{let r=l.get(s);if(r?.text===w)return r.units;let a=Un(w);return l.set(s,{text:w,units:a}),a},g=s=>_e.join(Be(s,p),Rn),k=s=>typeof s=="string"&&Pn.test(s);async function R(s){let w=await Qt.readFile(g(s),"utf8").catch(()=>null);return{text:w,items:w===null?[]:Dn(w)}}async function N(s,w,r){let a=In(w);return a===r||(a===null?await Qt.rm(g(s),{force:!0}):await d(g(s),a)),S(a)}let S=s=>s===null?"":J(s),Q=s=>{let w=h.get(s)??new Map;for(let[r,a]of w)b()-a>Ln&&w.delete(r);return[...w.keys()]},L=(s,w)=>w.forEach(r=>h.get(s)?.delete(r)),_=s=>{let w=x.get(s)??x.set(s,new Map).get(s);for(let[r,a]of w)b()-a>_n&&w.delete(r);return w};async function z(s,{keep:w=null,items:r=null,before:a=void 0}={}){let O=r?{items:r,text:a}:await R(s),v=await u(s).catch(()=>null);if(!v)return{items:O.items,units:[],places:new Map,version:S(O.text),missing:!0};let I=c(s,v.text),T=_(s),$=Tn(O.items,I,{keep:new Set([...T.keys(),w])});for(let A of T.keys())$.waiting.has(A)||T.delete(A);if($.dropped.length>0){let A=h.get(s)??h.set(s,new Map).get(s);for(let tt of $.dropped)A.set(tt.id,b())}let M=$.changed||r?await N(s,$.items,O.text):S(O.text);return $.dropped.length>0&&f(s,$.dropped),{items:$.items,units:I,places:$.places,version:M,missing:!1}}let Z=(s,{items:w,version:r})=>({ok:!0,version:r,items:w,dropped:Q(s)});async function U(s){if(!k(s))return[400,{ok:!1,reason:"body"}];let w=await z(s);return w.missing?[404,{ok:!1,reason:"missing"}]:[200,Z(s,w)]}async function D(s){if(!k(s))return[400,{ok:!1,reason:"body"}];let w=await z(s);if(w.missing)return[404,{ok:!1,reason:"missing"}];let r=null,a=Jn(Be(s,p));try{r=JSON.parse(await Qt.readFile(a.json,"utf8"))}catch{}let O=await u(s).catch(()=>null),v=/<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(O?.text??"")?.[1]?.replace(/<[^>]*>/g,"").trim(),I=typeof r?.title=="string"&&r.title.trim()?r.title.trim():v||s,T=w.units.some(M=>M.heading),$=w.items.map(M=>{let A=w.units[w.places.get(M.id)?.at],tt=A?.where?.length?A.where:A?.heading?[A.text]:[];return{where:tt,top:T&&tt.length===0,blocks:M.anchor.blocks.filter(ot=>w.units.some($t=>$t.id===ot)),whole:M.anchor.kind==="blocks",quote:M.anchor.quote,text:M.text}});return[200,{ok:!0,title:I,path:_e.resolve(a.html),items:$}]}async function V(s){let{slug:w}=s??{};if(!k(w))return[400,{ok:!1,reason:"body"}];if(!await u(w).catch(()=>null))return[404,{ok:!1,reason:"missing"}];let r=await R(w);if(s.anchors&&typeof s.anchors=="object"&&!Array.isArray(s.anchors)){let T=r.items.map(M=>{let A=Object.hasOwn(s.anchors,M.id)?En(s.anchors[M.id]):null;return A&&A.kind===M.anchor.kind?{...M,anchor:A}:M}),$=await N(w,T,r.text);return[200,Z(w,{items:T,version:$})]}let a=r.items,O=null,v=null;if(s.put!==void 0){let T=a.find(M=>M.id===s.put?.id),$=Ue({...s.put,created:T?.created??s.put?.created});if(!$)return[400,{ok:!1,reason:"item"}];a=T?a.map(M=>M.id===$.id?$:M):[...a,$],O=$.id,T||_(w).set($.id,b()),L(w,[$.id])}else if(typeof s.remove=="string")a=a.filter(T=>T.id!==s.remove);else if(s.clear===!0)v=a,a=[];else if(Array.isArray(s.restore)){let T=new Map(a.map(A=>[A.id,A])),$=s.restore.map(A=>Ue(A,A?.updated)).filter(A=>A&&!(T.get(A.id)?.updated>A.updated)),M=new Set($.map(A=>A.id));for(let A of M)T.has(A)||_(w).set(A,b());a=[...a.filter(A=>!M.has(A.id)),...$],L(w,[...M])}else return[400,{ok:!1,reason:"body"}];let I=await z(w,{keep:O,items:a,before:r.text});return[200,{...Z(w,I),...v?{removed:v}:{}}]}async function st(s){if(!k(s))return;let{text:w}=await R(s);w!==null&&await z(s)}return{list:U,copy:D,change:V,afterWrite:st}}import yt from"node:fs/promises";import gt from"node:path";import{writeAtomic as Ze}from"../browser/shared/files.mjs";import{slugPattern as Vt}from"../browser/shared/reports.mjs";var Pt=1,Mt={seen:"seen.html",base:"base.html",state:"state.json"},Wn=4,Bn=1800*1e3;function Ce({stateDirectory:p=null,shown:u,folderOf:d,isPage:f=()=>!1,log:b=null,now:h=Date.now,quiet:x=Bn}){let l=new Map,c=r=>gt.join(p,"changes",r),g=Promise.resolve(),k=r=>{let a=g.then(r);return g=a.catch(O=>b?.(`changes: ${O.message}`)),a};async function R(r){if(!p)return l.get(r)?.state??null;try{let a=JSON.parse(await yt.readFile(gt.join(c(r),Mt.state),"utf8"));return a?.v===Pt&&typeof a.seen=="string"?a:null}catch{return null}}async function N(r,a){return p?yt.readFile(gt.join(c(r),Mt[a]),"utf8").catch(()=>null):l.get(r)?.[a]??null}async function S(r,a,O={}){if(!p){let v=l.get(r)??{};l.set(r,{...v,...O,state:a});return}await yt.mkdir(c(r),{recursive:!0});for(let[v,I]of Object.entries(O))I===null?await yt.rm(gt.join(c(r),Mt[v]),{force:!0}):await Ze(gt.join(c(r),Mt[v]),I);await Ze(gt.join(c(r),Mt.state),`${JSON.stringify(a)}
7
+ `)}async function Q(r){l.delete(r),p&&await yt.rm(c(r),{recursive:!0,force:!0,maxRetries:3})}let L=async r=>Math.round((await yt.stat(d(r)).catch(()=>null))?.birthtimeMs??0),_=r=>r?.base?`${r.since}|${r.writes}`:null,z=r=>Number.isFinite(r?.draft)&&h()-r.draft<x?r.draft:null,Z=(r,a,O,v=z(r))=>[{v:Pt,born:r?.born??0,seen:a,...v===null?{}:{draft:v}},{seen:O,base:null}];async function U(r){let a=await R(r);if(!a)return null;let O=await L(r);return a.born&&O&&a.born!==O?(await Q(r),null):a}async function D(r,a){if(typeof a!="string"||!Vt.test(r)||f(r))return!1;let O=J(a),v=await U(r);if(!v)return await S(r,{v:Pt,born:await L(r),seen:O},{seen:a}),!1;if(v.seen===O)return!1;let I=await N(r,"seen"),T=new Date(h()).toISOString();if(I===null)return await S(r,...Z(v,O,a)),!1;let $=u(I),M=u(a);if(!v.base){if(!ht($,M))return await S(r,...Z(v,O,a)),!1;if(z(v)!==null||Te($))return await S(r,...Z(v,O,a,h())),!1;let{draft:ot,...$t}=v;return await S(r,{...$t,seen:O,base:J($),since:T,at:T,writes:1},{seen:a,base:$}),!0}let A=await N(r,"base");if(A===null||!ht(A,M))return await S(r,...Z(v,O,a)),!0;let tt=ht($,M)!==null;return await S(r,{...v,seen:O,...tt?{at:T,writes:v.writes+1}:{}},{seen:a}),tt}async function V(r,a,O,v){if(!Vt.test(r)||f(r))return!1;let I=await U(r),T=J(a);if(!I?.base)return await S(r,...Z(I??{born:await L(r)},T,a,v?null:z(I))),!1;let $=await N(r,"base");if($!==null&&O)try{$=O($)}catch(M){b?.(`changes: ${r}: the baseline did not take the edit (${M.message})`)}return $===null||!ht($,u(a))?(await S(r,...Z(I,T,a)),!0):(await S(r,{...I,seen:T,base:J($)},{seen:a,base:$}),!1)}async function st(r,a){if(!Vt.test(r)||f(r))return{ended:!1,moved:!1};let O=typeof a=="string"?await D(r,a):!1,v=await U(r);if(v?.draft===void 0)return{ended:!1,moved:O};let{draft:I,...T}=v;return await S(r,T),{ended:z(v)!==null,moved:O}}let s=new Map;async function w(r,a){await D(r,a);let O=u(a),v=J(O),I=await U(r);if(!I?.base)return{pending:!1,version:v};let T=`${r} ${I.base} ${v}`,$=s.get(T);if($===void 0){let M=await N(r,"base");for($=M===null?null:ht(M,O),s.set(T,$);s.size>Wn;)s.delete(s.keys().next().value)}return $?{pending:!0,version:v,stamp:_(I),since:I.since,writes:I.writes,...$}:{pending:!1,version:v}}return{look:(r,a)=>k(()=>D(r,a)),wrote:(r,a,O=null,{reader:v=!1}={})=>k(()=>V(r,a,O,v)),endDraft:(r,a=null)=>k(()=>st(r,a)),read:(r,a)=>k(()=>w(r,a)),stamp:r=>k(async()=>_(await U(r))),snapshot:r=>k(async()=>{let a=await U(r);return a?{state:a,seen:await N(r,"seen"),base:await N(r,"base")}:null}),clear:r=>k(async()=>{let a=await U(r);a?.base&&await S(r,{v:Pt,born:a.born,seen:a.seen},{base:null})}),restore:(r,a)=>k(async()=>{a?.state&&await S(r,a.state,{seen:a.seen,base:a.base})}),forget:r=>k(()=>Q(r)),idle:()=>k(async()=>{})}}import{randomBytes as Yn}from"node:crypto";import ct from"node:fs/promises";import kt from"node:path";import{FILE as Zn,readItems as Cn}from"../browser/shared/annotations.mjs";import{writeAtomic as Hn}from"../browser/shared/files.mjs";import{documentDirectory as zn}from"../browser/shared/workspace.mjs";var Kn=20,Ke=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,He=80,Ge=({stateDirectory:p,slug:u})=>kt.join(p,"dropped-annotations",u),Qe=p=>({id:p.id,text:p.text,quote:p.anchor?.quote??"",kind:p.anchor?.kind??"text"});async function Ve({stateDirectory:p,reportsDirectory:u,slug:d,time:f,items:b}){let h=Ge({stateDirectory:p,reportsDirectory:u,slug:d});await ct.mkdir(h,{recursive:!0});let x=f.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Hn(kt.join(h,`${x}-${Yn(4).toString("hex")}.json`),JSON.stringify({time:f,items:b}));let l=(await ct.readdir(h)).filter(c=>Ke.test(c)).sort();await Promise.all(l.slice(0,Math.max(0,l.length-Kn)).map(c=>ct.rm(kt.join(h,c),{force:!0})))}async function no({stateDirectory:p,reportsDirectory:u,slug:d}){let f=Ge({stateDirectory:p,reportsDirectory:u,slug:d}),b=(await ct.readdir(f).catch(()=>[])).filter(l=>Ke.test(l)).sort();if(b.length===0)return[];let h=new Set(Cn(await ct.readFile(kt.join(zn(d,u),Zn),"utf8").catch(()=>"")).map(l=>l.id)),x=[];for(let l of b){let c=kt.join(f,l);try{let g=JSON.parse(await ct.readFile(c,"utf8")),k=Array.isArray(g?.items)?g.items.filter(R=>typeof R?.id=="string"&&!h.has(R.id)):[];typeof g?.time=="string"&&k.length&&x.push({time:g.time,items:k})}catch{}await ct.rm(c,{force:!0}).catch(()=>{})}return x}var Gn=(p,u=new Date)=>{let d=new Date(p),f=h=>String(h).padStart(2,"0"),b=`${f(d.getHours())}:${f(d.getMinutes())}`;return d.toDateString()===u.toDateString()?b:`${d.getFullYear()}-${f(d.getMonth()+1)}-${f(d.getDate())} ${b}`},ze=p=>{let u=String(p??"").replace(/\s+/g," ").trim();return JSON.stringify(u.length>He?`${u.slice(0,He-1)}\u2026`:u)};function qt(p,{time:u=null,items:d},{today:f=new Date}={}){let b=kt.resolve(p),h=`${d.length} \u6279\u6CE8 (annotation${d.length===1?"":"s"})`;return[`annotations ${b}: ${u?`at ${Gn(u,f)}, `:""}Gallery deleted ${h} whose words are gone from the document (rewritten or deleted):`,...d.map(({id:x,text:l,quote:c,kind:g})=>` ${x} ${ze(l)} on ${g==="blocks"?"the blocks ":""}${ze(c)}`)]}function ro(p,u,{today:d=new Date}={}){return u.length?[...u.flatMap(f=>qt(p,f,{today:d}))," they were the reader's: say in your hand-off which your edit carried out and which you left, and never write them back"]:[]}import{randomBytes as Qn}from"node:crypto";import bt from"node:fs/promises";import At from"node:path";import{writeAtomic as Vn}from"../browser/shared/files.mjs";var qn=20,qe=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,Xe=({stateDirectory:p,slug:u})=>At.join(p,"rewrites",u);async function tn({stateDirectory:p,reportsDirectory:u,slug:d,time:f,changes:b}){let h=Xe({stateDirectory:p,reportsDirectory:u,slug:d});await bt.mkdir(h,{recursive:!0});let x=f.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Vn(At.join(h,`${x}-${Qn(4).toString("hex")}.json`),JSON.stringify({time:f,changes:b}));let l=(await bt.readdir(h)).filter(c=>qe.test(c)).sort();await Promise.all(l.slice(0,Math.max(0,l.length-qn)).map(c=>bt.rm(At.join(h,c),{force:!0})))}async function en({stateDirectory:p,reportsDirectory:u,slug:d}){let f=Xe({stateDirectory:p,reportsDirectory:u,slug:d}),b=(await bt.readdir(f).catch(()=>[])).filter(x=>qe.test(x)).sort(),h=[];for(let x of b){let l=At.join(f,x);try{let c=JSON.parse(await bt.readFile(l,"utf8"));typeof c?.time=="string"&&Array.isArray(c.changes)&&h.push(c)}catch{}await bt.rm(l,{force:!0}).catch(()=>{})}return h}var Xn=(p,u=new Date)=>{let d=new Date(p),f=h=>String(h).padStart(2,"0"),b=`${f(d.getHours())}:${f(d.getMinutes())}`;return d.toDateString()===u.toDateString()?b:`${d.getFullYear()}-${f(d.getMonth()+1)}-${f(d.getDate())} ${b}`};function fo(p,u,{today:d=new Date}={}){if(!u.length)return[];let f=At.resolve(p),b=[];for(let{time:h,changes:x}of u){let l=[];for(let{line:c,rule:g,key:k}of[...x].sort((R,N)=>R.line-N.line)){let R=`line ${c} ${g}${k?` ${k}`:""}`;l.includes(R)||l.push(R)}b.push(`preview ${f}: at ${Xn(h,d)}, when the reader edited the page, the preview wrote your natural HTML as the kit's markup: ${l.join(", ")}`),b.push(...x.filter(c=>c.note).map(({line:c,rule:g,note:k})=>` line ${c}, ${g}: ${k}`))}return b.push(" re-read the file before editing it (those lines are the file's as you had left it)"),b}import{todoRef as tr}from"../browser/shared/workspace-query.mjs";var er=(p,u)=>p.length===u.length&&p.every((d,f)=>d===u[f]);function nn(p,u,d,f){let b=Fe(u),h=De(d,{at:!0}),x=null,l=c=>(x??=ye(d).units).find(g=>g.elStart===c)??null;return f.map(c=>{let g=tr(c?.ref);if(!g||g.slug!==p||typeof c.done!="boolean")return{reason:"ref"};let k=g.block?h.find(N=>N.block===g.block)??null:null;if(k&&k.text!==g.text)return{reason:"changed"};if(!k){let N=h.filter(S=>S.text===g.text&&er(S.path,g.path));if(g.version===b)k=N.find(S=>S.nth===g.nth)??null;else{if(N.length>1)return{reason:"ambiguous"};k=N[0]??null}}if(!k)return{reason:"changed"};let R=l(k.at);return R?{unit:R,done:k.done,want:c.done}:{reason:"locked"}})}function rn(p,u){let d=new Map,f=u.map(c=>{if(!c.unit)return!1;let g=d.has(c.unit.id)?d.get(c.unit.id):c.done;return d.set(c.unit.id,c.want),g!==c.want}),b=new Map;for(let c of u)c.unit&&d.get(c.unit.id)!==c.done&&b.set(c.unit.id,c);if(b.size===0)return{commit:null,changed:f};let h=[],x=[],l=new Map;for(let[c,g]of b){let k=`todo${h.length}`,R=g.unit.blockId?{key:k,id:g.unit.blockId}:{key:k,open:c,hash:we(p,g.unit)};h.push({key:k,unit:R,attribute:"data-checked",value:d.get(c)?"":null}),x.push(R),l.set(c,k)}return{commit:{units:h,touch:x,keys:l},changed:f}}import{EMPTY_STYLE as yr,emptyWordsScript as gr,showEmpty as kr}from"../browser/editor/components/placeholder.mjs";import{TOKENS as br}from"../browser/editor/page/look.mjs";import{MARGIN_STYLE as $r,earlyMarginScript as xr}from"../browser/editor/page/margin.mjs";var te=/^[a-f0-9]{16}$/,ne=2*1024*1024,Sr=ur,on=50,an=/^\d{8}T\d{6}Z-[a-f0-9]{16}\.html$/,vr=30,sn=3,cn=200,ft="\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u7A0D\u540E\u518D\u540C\u6B65",Or="\u8FD9\u6B21\u7684\u4FEE\u6539\u592A\u5927\uFF0C\u4E00\u6B21\u5B58\u4E0D\u4E0B",jr=250,lt=Symbol("again"),Mr="/__gallery/edit/src/editor/page/editor.mjs",Ar=p=>new Promise(u=>setTimeout(u,p));function Nr(p,u=ne){return new Promise((d,f)=>{let b=[],h=0;p.on("data",x=>{h+=x.length,h>u?b.length=0:b.push(x)}),p.on("end",()=>h>u?f(new Error("too-large")):d(Buffer.concat(b).toString("utf8"))),p.on("error",f)})}function Tr(p){if(!p)return ee(16).toString("hex");let u=P.join(p,"token");try{let f=ir(u,"utf8").trim();if(/^[a-f0-9]{32}$/.test(f))return f}catch{}let d=ee(16).toString("hex");try{sr(p,{recursive:!0,mode:448}),cr(u,d,{mode:384})}catch{}return d}function zo({base:p="",token:u=null,reportsDirectory:d=dr,stateDirectory:f=null,write:b=Jt,ids:h=!0,finish:x=R=>R,log:l=null,settling:c={},reviewing:g={},onChanges:k=()=>{}}={}){let R=u??Tr(rr().data),N=Le(c),S=c.wait??Je,Q=new Map,L=async(t,n,e,o="reader")=>{let i=await b(t,n,e);if(i!==!1&&hr(P.basename(t))){let y=P.basename(P.dirname(t));N.wrote(y,n),Q.set(y,{hash:J(n),by:o})}return i},_=t=>wr(t,d),z=t=>Nt(_(t)).html,Z=new Map,U=f&&P.join(f,"snapshots"),D=Promise.resolve(),V=Promise.resolve(),st=async(t,n,e,{by:o="time"}={})=>{let i=(await H.readdir(t)).filter(m=>n.test(m));if(i.length<=e)return;let y=o==="name"?i.sort():(await Promise.all(i.map(async m=>({name:m,time:(await H.stat(P.join(t,m))).mtimeMs})))).sort((m,j)=>m.time-j.time).map(({name:m})=>m);await Promise.all(y.slice(0,y.length-e).map(m=>H.rm(P.join(t,m),{force:!0})))},s=(t,n)=>{U&&(D=D.then(async()=>{let e=P.join(U,`${t}.html`),o=new Date;try{await H.utimes(e,o,o);return}catch{}await H.mkdir(U,{recursive:!0}),await Jt(e,n),await st(U,/^[a-f0-9]{16}\.html$/,on)}).catch(()=>{}))},w=(t,n)=>{f&&(D=D.then(async()=>{let e=P.join(f,"history",t),o=J(n);if(await H.mkdir(e,{recursive:!0}),(await H.readdir(e)).filter(m=>an.test(m)).sort().at(-1)?.endsWith(`-${o}.html`))return;let y=new Date().toISOString().replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await Jt(P.join(e,`${y}-${o}.html`),n),await st(e,an,vr,{by:"name"})}).catch(()=>{}))},r=new Map,a=t=>f&&P.join(f,"receipts",t),O=(t,n,e,o)=>{for(r.set(`${t} ${n}`,{digest:e,answer:o});r.size>cn*4;)r.delete(r.keys().next().value);let i=a(t);i&&(D=D.then(async()=>{await H.mkdir(i,{recursive:!0}),await Jt(P.join(i,`${n}.json`),JSON.stringify({digest:e,answer:o})),await st(i,{test:y=>y.endsWith(".json")&&Xt.test(y.slice(0,-5))},cn)}).catch(()=>{}))},v=async(t,n)=>{let e=r.get(`${t} ${n}`);if(e)return e;let o=a(t);if(!o)return null;await D;try{let i=JSON.parse(await H.readFile(P.join(o,`${n}.json`),"utf8"));return typeof i?.digest=="string"&&i.answer?.ok?i:null}catch{return null}},I=new Map,T=(t,n)=>{let e=new Date().toISOString();if(!f)return void I.set(t,[...I.get(t)??[],{time:e,changes:n}].slice(-20));D=D.then(()=>tn({stateDirectory:f,reportsDirectory:d,slug:t,time:e,changes:n})).catch(()=>{})},$=async t=>{if(!f){let n=I.get(t)??[];return I.delete(t),n}return await D,en({stateDirectory:f,reportsDirectory:d,slug:t})},M=(t,n)=>{for(Z.delete(t),Z.set(t,n);Z.size>on;)Z.delete(Z.keys().next().value);s(t,n)},A=async t=>{if(Z.has(t))return Z.get(t);if(!U||!te.test(t))return null;await D;let n=await H.readFile(P.join(U,`${t}.html`),"utf8").catch(()=>null);return n===null||J(n)!==t?null:(M(t,n),n)},tt=new Map,ot=t=>{let n=tt.get(t);if(n)return n;let e=je(t,{finish:x});for(tt.set(t,e);tt.size>8;)tt.delete(tt.keys().next().value);return e},$t=P.join(P.resolve(d),".gallery","pages"),C=Ce({...g,stateDirectory:f,shown:t=>ot(t).text,folderOf:_,log:l,isPage:t=>P.resolve(_(t)).startsWith($t+P.sep)}),ut=(t,n)=>n.then(e=>{e&&k(t)},e=>l?.(`${t}: the Agent's changes not kept (${e.message})`));async function Lt(t,n=void 0){if(typeof t!="string"||!rt.test(t))return null;let e=z(t),o=n!==void 0?n:await H.readFile(e,"utf8").catch(()=>null);if(o===null)return null;let{text:i,changes:y}=ot(o);return{file:e,source:o,text:i,version:J(i),changes:y}}async function it(t){if(typeof t!="string"||!rt.test(t))return{source:null,held:!1,signs:[],wait:0,own:!1};let n=z(t),e=await H.readFile(n,"utf8").catch(()=>null),o=(await H.stat(n).catch(()=>null))?.mtimeMs??0;return{source:e,...N.judge(t,{source:e,mtime:o})}}async function xt(t,n=Date.now()+S){for(;;){let e=await it(t);if(!e.held||Date.now()>=n)return e;await Ar(Math.max(0,Math.min(jr,n-Date.now())))}}async function _t(t,{wait:n=S}={}){let e=await xt(t,Date.now()+n),o=await Lt(t,e.held&&e.taken!==void 0?e.taken:e.source);return o&&{...o,held:e.held===!0}}function fn(t,n,{editor:e=Mr,kitTags:o=()=>[]}={}){let{html:i,map:y}=be(n);M(y.version,n);let m=me(),j=pe(m).map(({assets:B,...X})=>({...X,kit:o(B)})),E=`<script type="application/json" id="doc-edit-map" data-doc-dev>${JSON.stringify({slug:t,token:R,...y,components:j,hidden:m.settings.hidden}).replace(/</g,"\\u003c")}</script>
8
+ <script data-doc-dev>document.currentScript.remove(); import(${JSON.stringify(e)});</script>`,W=`<style data-doc-dev>.doc-display { display: none; }</style>
9
+ <style data-doc-dev data-ge-palette>${br}</style>
10
+ <style data-doc-dev>${yr}</style>
11
+ <script data-doc-dev>${gr()}</script>
12
+ <script data-doc-dev>document.currentScript.remove(); document.documentElement.setAttribute("data-ge-order", "file");</script>
13
+ <style data-doc-dev data-ge-margin-style>${$r}</style>
14
+ <script data-doc-dev>document.currentScript.remove(); ${xr(nr(t,p),{notes:ar(P.join(_(t),fr))})}</script>`;return{html:kr(i),snippet:E,head:W}}let ln=t=>M(J(t),t);function re(t){if(t.method!=="POST")return[405,{ok:!1,reason:"method"}];let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers.origin!==`http://${n}`?[403,{ok:!1,reason:"origin"}]:t.headers["x-gallery-token"]!==R?[403,{ok:!1,reason:"token"}]:null}async function dt(t,n=ne){let e=re(t);if(e)return{error:e};if(!/^application\/json\b/i.test(t.headers["content-type"]??""))return{error:[415,{ok:!1,reason:"type"}]};try{return{body:JSON.parse(await Nr(t,n))}}catch(o){return{error:o.message==="too-large"?[413,{ok:!1,reason:"body",message:Or}]:[400,{ok:!1,reason:"body"}]}}}async function Ut(t,n){let{slug:e,opening:o,known:i=null,texts:y=[],units:m=[],touch:j=[],pageIds:F=null,request:E=null,agent:W=!1}=t;if(typeof e!="string"||!rt.test(e)||![y,m,j].every(Array.isArray))return[400,{ok:!1,reason:"body"}];if(E!==null&&(typeof E!="string"||!Xt.test(E)))return[400,{ok:!1,reason:"body"}];let B=E===null?null:J(JSON.stringify([o??null,y,m,j])),X=await oe(t);if(X)return X;let K=nt=>(E!==null&&O(e,E,B,nt),[200,nt]),G=z(e),et=typeof o=="string"&&te.test(o)?await A(o):null,q=nt=>or("sha256",R).update(`${e}
15
+ ${nt}`).digest("hex").slice(0,32);for(let nt=1;;nt++){let{source:at,held:It}=await it(e);if(at===null)return[404,{ok:!1,reason:"missing"}];if(It)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];ut(e,C.look(e,at));let{text:jt,changes:zt}=ot(at),ce=[],Dt=xe({current:jt,opening:et,texts:y,units:m,touch:j,ids:h?()=>{let Ft=typeof h=="function"?h():Kt();return ce.push(Ft),Ft}:!1,seal:q,pageIds:F}),{title:fe,icon:le,...ue}=Dt,wt=Dt.text===jt?jt:x(Dt.text);wt!==Dt.text&&(ue.version=J(wt));let de={...ue,foreign:typeof i=="string"&&J(jt)!==i};if(wt===jt)return K({ok:!0,...de,wrote:!1,notes:[]});if(w(e,at),!await L(G,wt,{expect:at},W===!0?"agent":"reader")){if(nt===sn)return[409,{ok:!1,reason:"busy",message:ft}];continue}w(e,wt),ut(e,C.wrote(e,wt,Ft=>{let jn=0;return Ee(Ft,{opening:et,texts:y,units:m,touch:j,pageIds:F,seal:q,ids:h?()=>ce[jn++]??(typeof h=="function"?h():Kt()):!1})},{reader:W!==!0})),zt.length&&(l&&l(Gt(G,zt).join(`
16
+ `)),T(e,zt));let On=[...fe?await Tt(P.dirname(G),fe):[],...le!==void 0?await Wt(P.dirname(G),le):[]];return K({ok:!0,...de,wrote:!0,notes:On})}}async function un(t,n){return typeof t!="string"||!rt.test(t)?[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}]:!Array.isArray(n)||n.length===0||n.length>pr?[400,{ok:!1,reason:"body"}]:Bt({slug:t},async(e,o)=>{let{source:i,held:y}=await it(t);if(i===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(y)return Date.now()<o?lt:[409,{ok:!1,reason:"busy",message:ft}];let{text:m}=ot(i),j=nn(t,i,m,n),{commit:F,changed:E}=rn(m,j),W=j.map((q,nt)=>q.reason?{ok:!1,reason:q.reason}:{ok:!0,changed:E[nt],block:q.unit.blockId??null});if(!F)return[200,{ok:!0,results:W,wrote:!1}];let B=J(m);M(B,m);let X=await Ut({slug:t,opening:B,units:F.units,touch:F.touch},o);if(X===lt)return lt;let[K,G]=X;if(!G.ok)return[K,G];let et=new Map((G.units??[]).map(q=>[q.key,q]));return[200,{ok:!0,wrote:G.wrote===!0,results:W.map((q,nt)=>{if(!q.ok)return q;let at=F.keys.get(j[nt].unit.id);if(at===void 0)return q;let It=et.get(at);return It?.status!=="applied"?{ok:!1,reason:It?.reason==="ambiguous"?"ambiguous":"changed"}:{...q,block:G.ids?.[at]??q.block}})}]})}async function oe({slug:t,opening:n,texts:e=[],units:o=[],touch:i=[],request:y=null}){if(typeof t!="string"||!rt.test(t)||typeof y!="string"||!Xt.test(y)||![e,o,i].every(Array.isArray))return null;let m=await v(t,y);return m?m.digest===J(JSON.stringify([n??null,e,o,i]))?[200,{...m.answer,again:!0}]:[409,{ok:!1,reason:"request",message:"\u540C\u4E00\u6B21\u4FDD\u5B58\u7684\u5185\u5BB9\u4E0D\u4E00\u81F4"}]:null}async function dn(t,n){let{slug:e,opening:o,texts:i=[],units:y=[],instances:m=[],pageIds:j=null}=t;if(typeof e!="string"||!rt.test(e)||!Array.isArray(i)||!Array.isArray(y)||!Array.isArray(m))return[400,{ok:!1,reason:"body"}];let{source:F,held:E}=await it(e);if(E)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];let W=await Lt(e,F);if(W===null)return[404,{ok:!1,reason:"missing"}];let{text:B,version:X}=W,K=typeof o=="string"&&te.test(o)?await A(o):null;return[200,{ok:!0,version:X,reverted:Oe({current:B,opening:K,texts:i,pageIds:j}),units:Se({current:B,units:y}),parts:ve({current:B,instances:m,pageIds:j})}]}let mn=600*1e3,St=new Map;async function ae(t,n){let e=_(t),o=null;try{o=JSON.parse(await H.readFile(Nt(e).json,"utf8"))}catch{}let{title:i,icon:y}=Ae(n,o);i&&typeof o?.title=="string"&&o.title!==i.to&&await Tt(e,{from:o.title,to:i.to,synced:!0}),y&&!y.missing&&await Wt(e,y.to)}async function pn(t,n){let{slug:e,action:o,stamp:i=null,undo:y=null}=t;if(typeof e!="string"||!rt.test(e)||!["accept","revert","undo"].includes(o))return[400,{ok:!1,reason:"body"}];let m=z(e),{source:j,held:F}=await it(e);if(j===null)return[404,{ok:!1,reason:"missing"}];if(F)return Date.now()<n?lt:[409,{ok:!1,reason:"busy",message:ft}];if(o==="undo"){for(let[G,et]of St)Date.now()-et.at>mn&&St.delete(G);let K=typeof y=="string"?St.get(y):null;return!K||K.slug!==e?[404,{ok:!1,reason:"gone",message:"\u64A4\u9500\u5DF2\u7ECF\u8FC7\u671F"}]:j!==K.after?[409,{ok:!1,reason:"moved-on",message:"\u64A4\u56DE\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500"}]:(w(e,j),await L(m,K.before,{expect:j})?(w(e,K.before),St.delete(y),await ae(e,K.before),await C.restore(e,K.saved),await C.wrote(e,K.before),k(e),[200,{ok:!0,version:J(ot(K.before).text)}]):[409,{ok:!1,reason:"busy",message:ft}])}await C.look(e,j);let E=await C.snapshot(e),W=E?.state?.base?`${E.state.since}|${E.state.writes}`:null;if(W===null)return[200,{ok:!0,none:!0}];if(W!==i)return[409,{ok:!1,reason:"changed",message:"Agent \u521A\u521A\u53C8\u6539\u4E86\u6587\u6863\uFF0C\u518D\u770B\u4E00\u773C"}];if(o==="accept")return await C.clear(e),k(e),[200,{ok:!0}];let B=E.base;if(w(e,j),!await L(m,B,{expect:j}))return[409,{ok:!1,reason:"busy",message:ft}];w(e,B),await ae(e,B);let X=ee(8).toString("hex");return St.set(X,{slug:e,before:j,after:B,saved:E,at:Date.now()}),await C.clear(e),await C.wrote(e,B),k(e),[200,{ok:!0,version:J(ot(B).text),undo:X}]}async function wn(t,n){let e=await dt(t);if(e.error)return Y(n,...e.error);let o=e.body??{};try{if(o.action!=="read")return Y(n,...await Bt(o,pn));if(typeof o.slug!="string"||!rt.test(o.slug))return Y(n,400,{ok:!1,reason:"body"});let i=await _t(o.slug,{wait:0});return i===null?Y(n,404,{ok:!1,reason:"missing"}):Y(n,200,{ok:!0,...await C.read(o.slug,i.source)})}catch(i){return Y(n,500,{ok:!1,reason:"write",message:i.message})}}async function Tt(t,{from:n,to:e,synced:o}){let i=["\u6807\u9898\u5DF2\u66F4\u65B0",...o?[]:["\u5355\u72EC\u6253\u5F00\u6216\u5BFC\u51FA\u65F6\u7684\u9875\u9762\u540D\u79F0\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"]],y=Nt(t).json,m=await H.readFile(y,"utf8").catch(()=>""),j=null;try{j=JSON.parse(m)}catch{}if(j?.title!==n)return[...i,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u539F\u672C\u5C31\u548C\u6807\u9898\u4E0D\u540C\uFF0C\u6CA1\u6709\u8DDF\u7740\u6539"];let F=new RegExp(`("title"\\s*:\\s*)${JSON.stringify(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`),E=F.test(m)?m.replace(F,(W,B)=>B+JSON.stringify(e)):`${JSON.stringify({...j,title:e},null,2)}
17
+ `;try{await L(y,E)}catch(W){return l?.(`${P.basename(y)}'s title was not written (${W.code??W.message}): ${y}`),[...i,"\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u6587\u6863\u540D\u6CA1\u80FD\u8DDF\u7740\u6539"]}return i}async function Wt(t,n){let e=Nt(t).json,o=null;try{o=JSON.parse(await H.readFile(e,"utf8"))}catch{}if(!o||typeof o!="object")return l?.(`${P.basename(e)} could not be read, so its icon was not written: ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"];if((o.icon??null)===n)return[];let{icon:i,...y}=o,m=n===null?y:{...y,icon:n};try{await L(e,`${JSON.stringify(m,null,2)}
18
+ `)}catch(j){return l?.(`${P.basename(e)}'s icon was not written (${j.code??j.message}): ${e}`),["\u9875\u9762\u56FE\u6807\u5DF2\u66F4\u6362\uFF0C\u4F46\u641C\u7D22\u548C\u4FA7\u680F\u91CC\uFF08\u6CA1\u6253\u5F00\u8FD9\u4EFD\u6587\u6863\u65F6\uFF09\u7684\u56FE\u6807\u6CA1\u80FD\u8DDF\u7740\u6362"]}return[]}async function hn(t,n){let e=typeof n=="string"?n.replace(/\s+/g," ").trim():"";if(!e)return{ok:!1,reason:"title",message:"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"};let o=z(t),i=await H.readFile(o,"utf8").catch(()=>null);if(i===null)return{ok:!1,reason:"missing"};ut(t,C.look(t,i));let y=he(i),m=ge(y).find(E=>E.kind==="title");if(!m)return{ok:!1,reason:"no-title",message:"\u8FD9\u4EFD\u6587\u6863\u6CA1\u6709\u6807\u9898"};let j=lr(e),F=$e({current:y,edits:[{id:m.id,parts:[{keep:!0,html:j}]}],ids:h});return F.ok?F.text!==i&&!await L(o,F.text,{expect:i})?{ok:!1,reason:"changed-again"}:(F.text!==i&&ut(t,C.wrote(t,F.text,E=>Re(E,j))),{ok:!0,title:e,notes:F.title?await Tt(P.dirname(o),F.title):[]}):{ok:!1,reason:"conflict"}}let vt=t=>(n,e)=>{let o=V.then(()=>t(n));return V=o.catch(()=>{}),o.then(([i,y])=>Y(e,i,y),i=>Y(e,500,{ok:!1,reason:"write",message:i.message}))},se=(t,{early:n=null}={})=>async(e,o)=>{let i=await dt(e);if(i.error)return Y(o,...i.error);let y=i.body??{};try{let m=n&&await n(y);return m?Y(o,...m):Y(o,...await Bt(y,t))}catch(m){return Y(o,500,{ok:!1,reason:"write",message:m.message})}};async function Bt(t,n){let e=Date.now()+S;for(;;){await xt(t.slug,e);let o=V.then(()=>n(t,e));V=o.catch(()=>{});let i=await o;if(i!==lt)return i}}async function Yt(t,{reader:n=!1}={}){if(typeof t!="string"||!rt.test(t))return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};let e=_(t),{html:o,json:i}=Nt(e);for(let y=1;;y++){let{source:m,held:j}=n?await it(t):{source:await H.readFile(o,"utf8").catch(()=>null),held:!1};if(m===null)return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};if(j)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};ut(t,C.look(t,m));let F=null;try{F=JSON.parse(await H.readFile(i,"utf8"))}catch{}let{text:E,changes:W,added:B,given:X,repeated:K,title:G,icon:et}=Me(m,{finish:x,next:typeof h=="function"?h:void 0,metadata:F});if(E!==m){if(w(t,m),!await L(o,E,{expect:m},n?"reader":"agent")){if(y===sn)return{ok:!1,reason:"busy",message:"\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u6CA1\u6709\u5199\u5165"};continue}w(t,E),ut(t,C.wrote(t,E)),n&&W.length&&(l&&l(Gt(o,W).join(`
19
+ `)),T(t,W))}return G&&typeof F?.title=="string"&&F.title!==G.to&&await Tt(e,{from:F.title,to:G.to,synced:G.page}),et&&!et.missing&&await Wt(e,et.to),{ok:!0,changes:E===m?[]:W,added:E===m?0:B,given:E===m?[]:X,repeated:K,written:E!==m,title:G,icon:et}}}let yn=async(t,{reader:n=!1}={})=>{n&&await xt(t);let e=V.then(()=>Yt(t,{reader:n}));return V=e.catch(()=>{}),e};async function Zt(t){let n=await dt(t);if(n.error)return{refused:n.error};let{slug:e,workspace:o}=n.body??{};return typeof e!="string"||!rt.test(e)||typeof o!="string"?{refused:[400,{ok:!1,reason:"body"}]}:mr(o,d)?{slug:e}:{refused:[409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"}]}}async function gn(t,n){try{let e=V.then(async()=>{let{slug:y,refused:m}=await Zt(t);if(m)return{answer:m};let j=await Yt(y);return{slug:j.ok?y:null,answer:[j.ok?200:j.reason==="missing"?404:409,j]}});V=e.catch(()=>{});let{slug:o,answer:i}=await e;return o&&await Et(o),Y(n,...i)}catch(e){return Y(n,500,{ok:!1,reason:"write",message:e.message})}}async function kn(t){let{slug:n,refused:e}=await Zt(t);return e||(await Et(n),[200,{ok:!0}])}async function ie(t){let{source:n}=await xt(t),{ended:e,moved:o}=await C.endDraft(t,n);return o&&k(t),e}async function bn(t){let{slug:n,refused:e}=await Zt(t);return e||[200,{ok:!0,ended:await ie(n)}]}let mt=Ie({reportsDirectory:d}),Ot=Ye({reportsDirectory:d,read:t=>_t(t,{wait:0}),write:L,dropped:(t,n)=>{let e=n.map(Qe);l&&l(qt(P.join(_(t),"annotations.json"),{items:e}).join(`
20
+ `)),f&&(D=D.then(()=>Ve({stateDirectory:f,reportsDirectory:d,slug:t,time:new Date().toISOString(),items:e})).catch(()=>{}))}}),Ct=Promise.resolve(),Ht=t=>{let n=Ct.then(t);return Ct=n.catch(()=>{}),n},$n=t=>(n,e)=>Ht(()=>t(n)).then(([o,i])=>Y(e,o,i),o=>Y(e,500,{ok:!1,reason:"write",message:o.message})),xn=300,pt=new Map;async function Et(t){let n=pt.get(t);n&&(clearTimeout(n.timer),pt.delete(t));let e=Ht(()=>Ot.afterWrite(t));n&&e.then(n.resolve,n.reject),await e.catch(o=>l?.(`${t}: annotations not checked: ${o.message}`)),await D}let Sn=t=>{let n=t.headers.host??"",e=t.socket.localPort;return n!==`127.0.0.1:${e}`&&n!==`localhost:${e}`?[403,{ok:!1,reason:"host"}]:t.headers["x-gallery-token"]!==R?[403,{ok:!1,reason:"token"}]:null};async function vn(t){if(t.method==="GET"){let e=Sn(t);if(e)return e;let o=new URL(t.url??"/","http://localhost").searchParams;return o.get("as")==="copy"?Ot.copy(o.get("slug")):Ot.list(o.get("slug"))}let n=await dt(t);return n.error??Ot.change(n.body)}let Rt=(t,n=ne)=>async e=>{let o=await dt(e,n);return o.error??t(o.body)};return{token:R,preview:fn,opened:ln,check:dt,checkHeaders:re,upload:vt(Rt(mt.upload,Sr)),addEmoji:vt(Rt(mt.addEmoji)),unfurl:vt(Rt(mt.unfurl)),annotations:$n(vn),checkAnnotations(t){let n=pt.get(t);return n||(n={timer:0},n.done=new Promise((e,o)=>Object.assign(n,{resolve:e,reject:o})),pt.set(t,n)),clearTimeout(n.timer),n.timer=setTimeout(()=>{pt.delete(t),Ht(()=>Ot.afterWrite(t)).then(n.resolve,n.reject)},xn),n.done},frameable:vt(Rt(mt.frameable)),listEmojis:mt.listEmojis,readEmoji:mt.readEmoji,respond:vt,keepVersion:w,renameReport:hn,read:Lt,settled:it,writerOf:(t,n)=>typeof n=="string"&&Q.get(t)?.hash===J(n)?Q.get(t).by:null,whenTaken:xt,readTaken:_t,takeRewrites:$,handIn:yn,handInReport:Yt,handInRequest:gn,settleRequest:(t,n)=>kn(t).then(([e,o])=>Y(n,e,o),e=>Y(n,500,{ok:!1,reason:"write",message:e.message})),settleNotes:Et,roundRequest:(t,n)=>bn(t).then(([e,o])=>Y(n,e,o),e=>Y(n,500,{ok:!1,reason:"write",message:e.message})),beginRound:ie,commit:se(Ut,{early:oe}),handleCommit:Ut,setTodos:un,reverted:se(dn),changes:wn,noteTaken:(t,n)=>C.look(t,n),forgetChanges:t=>C.forget(t),drain:async()=>{await V,await Promise.all([...pt.keys()].map(Et)),await Ct,await C.idle(),await D},stored:async()=>{await C.idle(),await D}}}export{no as a,ro as b,en as c,fo as d,Mn as e,An as f,Nn as g,Tr as h,zo as i};
@@ -1,6 +1,6 @@
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 H,c as X,e as ve}from"./chunk-A55HN5OK.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Pe}from"node:crypto";import{existsSync as Ce,lstatSync as De,readFileSync as _,readdirSync as Me,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ke,parsePart as Ge,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as ot,OWN_SCOPE as it,PACK_FILE as ne,PACK_ID as he,readPackManifest as rt}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as at,PACKAGE_MANIFEST as I,WORKSPACE_MARK as ct,findWorkspace as lt,layoutOf as G,markerOf as ft,packageFolders as dt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),pt=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],mt=["at","edit","optional","min","max"],ut=["generated","attrs"],ht=["document","page"],wt=["document"],yt=["sizes","w","h","min","max","resize","fit","bare","consent"],y={w:12,h:24},bt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},gt=["key","label","type","options","default","required"],kt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],Ot=/^\d{4}-\d{2}-\d{2}$/,$t="settings",Et=["workspace","tables"],St=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,At=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Nt=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:At(n)}:s])),jt=["parts","text"],we=["kit.js","style.css","preview.svg"],M="template.html",zt=[I,M,...we],V=e=>[...new Set([...zt,...e])].sort(),Tt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,It=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Pe("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=De(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&_(s)}catch{return null}}var ce=new Map,vt=2e3;function _t(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(_(e)));return Date.now()-s>vt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=_t(o))}catch{}s.update(`${t}\0${f}
3
- `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},E=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},v=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ke(n).tag);function Pt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),E(n,mt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ge(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}St.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var Ct=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Dt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),E(e,ut,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(l){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,l.message))}return d.split(",").map(l=>l.trim().startsWith(":scope")?l.trim().replace(":scope",s):`${s} ${l.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)It.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let c=d=>{let a=t(d,"runtime.generated");return Ct(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(c),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var T=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Mt(e){return e===void 0?wt:((!Array.isArray(e)||e.length===0||!e.every(n=>ht.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Ft(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),E(e,yt,"card.");let n=a=>Array.isArray(a)&&a.length===2&&T(a[0],y.w)&&T(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let l=["w","h"].find(p=>e[p]!==void 0);l&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",l))}for(let a of["w","h"])e[a]!==void 0&&!T(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let l=e[a];if(l!==void 0){u(l)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),E(l,["w","h"],`card.${a}.`);for(let p of["w","h"])l[p]!==void 0&&!T(l[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=l}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,c=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([l,p])=>l<t.w||l>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let l={w:f,h:c}[a];l!==null&&!e.sizes&&(l<t[a]||l>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,l,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!bt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),e.consent!==void 0&&v(e.consent,"card.consent"),{sizes:e.sizes?e.sizes.map(([a,l])=>[a,l]):null,any:d,w:f,h:c,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1,...e.consent!==void 0?{consent:{zh:e.consent.zh,en:e.consent.en}}:{}}}var Lt=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&Ot.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Rt(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let c=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",c)),E(o,gt,`${c}.`),(typeof o.key!="string"||!kt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",c)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),v(o.label,`${c}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",c,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",c)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",c,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",c)),o.default!==void 0&&!Lt(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",c,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",c))});let t=n[$t];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Kt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Et.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Gt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Vt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)Tt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Ut(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))at.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});E(t,pt),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),v(t.name,"name"),v(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))Pt(w,$);let o=Dt(t.runtime,e),{kit:f,own:c}=Vt(t.assets,n);t.markdown!==void 0&&!jt.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Mt(t.places);Gt(d,t.parts);let a=Ft(t.card),l=Rt(t.settings,t.parts),p=Kt(t.needs),h=ye(n,M);return h&&ge(h,M),{id:e,match:Ze(e),parts:Nt(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:l,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...c])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(c))}}function Wt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Ut(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var P=()=>lt().root,Bt=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,x=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Jt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,x(s,me)]).filter(([,n])=>n.length>0)),Zt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),C=e=>{let n=Zt(e?.components?.packs);return{hidden:x(e?.components?.hidden,Bt),disabled:x(e?.components?.disabled,A),shown:x(e?.components?.shown,A),unlisted:x(e?.components?.unlisted,A),net:Jt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),qt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ft(e);return s?{value:n}:{problem:t?qt:B}}function ke(e){try{return L(_(G(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var On=(e=P())=>C(ke(e).value),Yt=["EPERM","EACCES","EBUSY","EROFS"];async function $n(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:c,pack:d,enabled:a}){let l=G(e).marker,p=await Le.readFile(l,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:ze,unlisted:Te}=C(h),g=u(h?.components)?h.components:{},Z=$(ze,t),q=$(Te,f),z={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};z.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(c!==void 0){let m={...u(g.net)?g.net:{}};c.length>0?m[n]=[...new Set(c)]:delete m[n],Object.keys(m).length>0?z.net=m:delete z.net}await He(l,`${JSON.stringify({...h??ct,components:z},null,2)}
2
+ import{a as H,c as X,e as ve}from"./chunk-A55HN5OK.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Pe}from"node:crypto";import{existsSync as Ce,lstatSync as De,readFileSync as _,readdirSync as Me,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ke,parsePart as Ge,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as ot,OWN_SCOPE as it,PACK_FILE as ne,PACK_ID as he,readPackManifest as rt}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as at,PACKAGE_MANIFEST as I,WORKSPACE_MARK as ct,defaultWorkspace as lt,layoutOf as G,markerOf as ft,packageFolders as dt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),pt=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],mt=["at","edit","optional","min","max"],ut=["generated","attrs"],ht=["document","page"],wt=["document"],yt=["sizes","w","h","min","max","resize","fit","bare","consent"],y={w:12,h:24},bt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},gt=["key","label","type","options","default","required"],kt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],Ot=/^\d{4}-\d{2}-\d{2}$/,$t="settings",Et=["workspace","tables"],St=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,At=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Nt=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:At(n)}:s])),jt=["parts","text"],we=["kit.js","style.css","preview.svg"],M="template.html",zt=[I,M,...we],V=e=>[...new Set([...zt,...e])].sort(),Tt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,It=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Pe("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=De(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&_(s)}catch{return null}}var ce=new Map,vt=2e3;function _t(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(_(e)));return Date.now()-s>vt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=_t(o))}catch{}s.update(`${t}\0${f}
3
+ `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},E=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},v=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ke(n).tag);function Pt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),E(n,mt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ge(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}St.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var Ct=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Dt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),E(e,ut,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(l){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,l.message))}return d.split(",").map(l=>l.trim().startsWith(":scope")?l.trim().replace(":scope",s):`${s} ${l.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)It.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let c=d=>{let a=t(d,"runtime.generated");return Ct(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(c),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var T=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Mt(e){return e===void 0?wt:((!Array.isArray(e)||e.length===0||!e.every(n=>ht.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Ft(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),E(e,yt,"card.");let n=a=>Array.isArray(a)&&a.length===2&&T(a[0],y.w)&&T(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let l=["w","h"].find(p=>e[p]!==void 0);l&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",l))}for(let a of["w","h"])e[a]!==void 0&&!T(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let l=e[a];if(l!==void 0){u(l)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),E(l,["w","h"],`card.${a}.`);for(let p of["w","h"])l[p]!==void 0&&!T(l[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=l}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,c=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([l,p])=>l<t.w||l>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let l={w:f,h:c}[a];l!==null&&!e.sizes&&(l<t[a]||l>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,l,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!bt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),e.consent!==void 0&&v(e.consent,"card.consent"),{sizes:e.sizes?e.sizes.map(([a,l])=>[a,l]):null,any:d,w:f,h:c,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1,...e.consent!==void 0?{consent:{zh:e.consent.zh,en:e.consent.en}}:{}}}var Lt=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&Ot.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Rt(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let c=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",c)),E(o,gt,`${c}.`),(typeof o.key!="string"||!kt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",c)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),v(o.label,`${c}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",c,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",c)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",c,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",c)),o.default!==void 0&&!Lt(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",c,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",c))});let t=n[$t];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Kt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Et.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Gt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Vt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)Tt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Ut(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))at.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});E(t,pt),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),v(t.name,"name"),v(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))Pt(w,$);let o=Dt(t.runtime,e),{kit:f,own:c}=Vt(t.assets,n);t.markdown!==void 0&&!jt.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Mt(t.places);Gt(d,t.parts);let a=Ft(t.card),l=Rt(t.settings,t.parts),p=Kt(t.needs),h=ye(n,M);return h&&ge(h,M),{id:e,match:Ze(e),parts:Nt(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:l,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...c])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(c))}}function Wt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Ut(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var P=()=>lt(),Bt=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,x=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Jt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,x(s,me)]).filter(([,n])=>n.length>0)),Zt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),C=e=>{let n=Zt(e?.components?.packs);return{hidden:x(e?.components?.hidden,Bt),disabled:x(e?.components?.disabled,A),shown:x(e?.components?.shown,A),unlisted:x(e?.components?.unlisted,A),net:Jt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),qt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ft(e);return s?{value:n}:{problem:t?qt:B}}function ke(e){try{return L(_(G(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var On=(e=P())=>C(ke(e).value),Yt=["EPERM","EACCES","EBUSY","EROFS"];async function $n(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:c,pack:d,enabled:a}){let l=G(e).marker,p=await Le.readFile(l,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:ze,unlisted:Te}=C(h),g=u(h?.components)?h.components:{},Z=$(ze,t),q=$(Te,f),z={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};z.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(c!==void 0){let m={...u(g.net)?g.net:{}};c.length>0?m[n]=[...new Set(c)]:delete m[n],Object.keys(m).length>0?z.net=m:delete z.net}await He(l,`${JSON.stringify({...h??ct,components:z},null,2)}
4
4
  `,{expect:p}).catch(m=>{throw Yt.includes(m.code)&&r(i("gallery.json \u5199\u4E0D\u8FDB\u53BB\uFF1A\u53EF\u80FD\u662F\u53EA\u8BFB\u7684\uFF0C\u6216\u88AB\u522B\u7684\u7A0B\u5E8F\u5360\u7740")),m})||r(i("gallery.json \u521A\u521A\u88AB\u6539\u8FC7\uFF1A\u518D\u8BD5\u4E00\u6B21"))}var Ht=e=>({...e,off:!0,disabled:!0,problem:i("\u5728\u8BBE\u7F6E\u91CC\u505C\u7528\u4E86"),stamp:S(n=>n.update(`${e.stamp} off`))}),D=C(null),Xt=({packages:e,problems:n,settings:s=D,packs:t=new Map})=>S(o=>{for(let{id:f,stamp:c}of[...e.values(),...n.values()].sort(U))o.update(`${f} ${c}
5
5
  `);o.update(`hidden ${[...s.hidden].sort().join(" ")}
6
6
  `),o.update(`shown ${[...s.shown].sort().join(" ")}
@@ -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 _}from"./chunk-W7665ZEC.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-7JDX4E65.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-3MBRL2PM.mjs";import{M as Ae}from"./chunk-HPOI4ZX7.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-EAIFITAV.mjs";import{d as Ce,g as je}from"./chunk-EP25HDAJ.mjs";import"./chunk-AR5D57ZD.mjs";import"./chunk-67N2QJYT.mjs";import{i as ie}from"./chunk-5XA2ZBAE.mjs";import{a as W}from"./chunk-JEUK3ZO7.mjs";import"./chunk-JLTZF4LA.mjs";import{a as re,b as le,e as de,f as K,g as ce}from"./chunk-PUOQ65NC.mjs";import"./chunk-7OG26PGF.mjs";import"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-QE5RG76S.mjs";import{a as H,b as j,c as P,d as D,f as oe}from"./chunk-UYVCQK3H.mjs";import{a as te,e as B,f as ae}from"./chunk-J5PUIV3Y.mjs";import{b as se}from"./chunk-4OZWXZE5.mjs";import"./chunk-MXUBKDRO.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-PAREWQGB.mjs";import{j as ne}from"./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{f as Z,j as ee}from"./chunk-HDWTZ763.mjs";import{b as X,e as _e}from"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";_e();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import O from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as He,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as M,hasClass as q,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],De=["light","dark"],Ze=900,et=3e4,tt=new Set(["iframe","frame","object","embed"]),at=/^\d+$/,ot={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function st(e,{catalog:g,folder:o,slug:h}){let i=[],s=d=>d?.sourceCodeLocation?.startLine??1,n=(d,a)=>i.push({line:typeof d=="number"?d:s(d),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),c=[],f=[];Re(t,d=>{d.tagName&&(d.tagName==="main"&&q(d,"gallery-page")&&c.push(d),q(d,"gallery-board")&&f.push(d),q(d,"gallery-card")&&!q(d.parentNode,"gallery-board")&&n(d,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`))},{inTemplates:!1}),c.length===0&&(f.length>0||j(e).cards.length>0)&&n(1,`no <main class="gallery-page">: a page's boards stand in one (it is how a block knows it is on a page: context.place "page", and how the page follows the theme)`);let y=new Map;for(let d of f){let a=d.parentNode;for(;a&&!(a.tagName==="main"&&q(a,"gallery-page"));)a=a.parentNode;c.length&&!a&&n(d,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=M(d,"data-board-id");r===void 0||r===""?n(d,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):H.test(r)?y.has(r)?n(d,`data-board-id="${r}" again (line ${y.get(r)} has it): each board's id is its own`):y.set(r,s(d)):n(d,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let S=new Map,N=new Map;for(let d of j(e).cards){let{node:a}=d,r=M(a,"data-card-id"),k=r&&H.test(r)?`card ${r}`:"this card";r===void 0||r===""?n(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):H.test(r)?S.has(r)?n(a,`data-card-id="${r}" again (line ${S.get(r)} has it): each card's id is its own, and the page's writes go by it`):S.set(r,s(a)):n(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?n(a,`${k} holds no instance of a custom block (an element with ${He}): a card is one block's instance, gallery/static's for what only shows`):u>1?n(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):d.instance&&d.instance.parentNode!==a&&n(d.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let b={};for(let x of["x","y","w","h"]){let A=M(a,`data-${x}`),[L,E]=ot[x];A===void 0?n(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):at.test(A.trim())?Number(A)<L||Number(A)>E?n(a,`${k}'s data-${x}="${A}": ${x} is ${E===1/0?`${L} or more`:`${L} to ${E}`}${x==="w"?" (a row is 12 cells)":""}`):b[x]=Number(A):n(a,`${k}'s data-${x}="${A}" is no whole number`)}b.x!==void 0&&b.w!==void 0&&b.x+b.w>12?n(a,`${k} reaches past the row's end: data-x ${b.x} and data-w ${b.w} make ${b.x+b.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(b).length===4&&N.set(d.board,[...N.get(d.board)??[],{id:r??null,...b,line:s(a)}]),d.block&&nt(d.block,g,x=>n(d.instance,`${k}'s block ${d.block}: ${x}`))}for(let d of N.values())for(let a=0;a<d.length;a++)for(let r=a+1;r<d.length;r++){let[k,u]=[d[a],d[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&n(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return i.push(...it(e,{folder:o,slug:h})),i.sort((d,a)=>d.line-a.line)}function nt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let i=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):i?o(`it does not load (${ee("en",i.problem)}): gallery block check ${e} says why`):ae(e)&&B(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${B(e).pack===te?B(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function it(e,{folder:g,slug:o}){let h=[],i=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let n=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",c=Me(n)??(n.startsWith(i)?Me(n.slice(i.length-7)):null),f=`"${n.length>60?`${n.slice(0,60)}\u2026`:n}"`,y=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(c!==null){Qe(c)?tt.has(s.node.tagName)&&!Te(c)?h.push({line:s.line,what:`${y}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture, stylesheet or script for saving only: write what it shows in the page itself, frame a site by its https address, or offer the file with a link, <a href="${c}" download>`}):Ue(O.join(g,c))||h.push({line:s.line,what:`${y}: ${c} is not in the page's folder (${W(O.join(g,"assets"))}): put the file there${Te(c)?"":", or link to it"}`}):h.push({line:s.line,what:`${y} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!n||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(n)||h.push({line:s.line,what:`${y} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function rt(e,g){let o=P(e).text,h=[];for(let i of j(o).cards){let s=i.block?g.packages.get(i.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let n=G(D(o,i),_,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=n?.text.trim()?JSON.parse(n.text):{}}catch{continue}let c=je(s,t);c.length&&h.push({id:i.id,block:i.block,line:i.node.sourceCodeLocation?.startLine??1,empty:c})}return h}var lt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:i,zh:s})=>`${h} (${s&&s!==i?`${i}, ${s}`:i})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,dt=(e,g=!1)=>{let o=h=>M(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${M(e.node,"data-x")},${M(e.node,"data-y")}`,Pe=e=>`${M(e.node,"data-w")},${M(e.node,"data-h")}`;function ct(e,g,o){let[h,i]=[P(e).text,P(g).text],[s,n]=[j(h).cards,j(i).cards],t=new Set([...s,...n].map(a=>a.board)).size>1,c=a=>dt(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)n.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:c(a)});for(let a of n)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:c(a)});for(let a of n){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:c(r),now:c(a)}),u&&f.resized.push({id:a.id,block:a.block,was:c(r),now:c(a)});let[b,x]=[D(h,r),D(i,a)];if(b===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,L=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[E,l]=L?[G(b,_,L),G(x,_,L)]:[null,null];if(!E||!l){f.markup.push({id:a.id,block:A?a.block:null});continue}let v=E.parts.flatMap(({name:$,text:m},I)=>m===l.parts[I].text?[]:[{name:$,...Y(m,l.parts[I].text),runs:ke(m,l.parts[I].text)}]);v.length&&f.data.push({id:a.id,block:a.block,parts:v}),E.outside!==l.outside&&f.markup.push({id:a.id,block:a.block})}let y=(a,r)=>{let k="",u=0;for(let b of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,b.start),u=b.end;return k+a.slice(u)},[S,N]=[y(h,s),y(i,n)],d=a=>a.replace(/\s+/g," ");return d(S)!==d(N)&&(f.page=Y(S.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",We="(put there by Gallery)";function ht(e,g){let o=n=>{let t=new Map;for(let c of g)if(c.by===n)for(let[f,y]of Object.entries(c.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(y)?y:[]]));return t},h=o("page"),i=o("gallery"),s=n=>t=>{let c=!!h.get(t.id)?.has(n);return{...t,user:c,...!c&&i.get(t.id)?.has(n)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function pt(e,g){let o=({id:t,block:c})=>`${t}${c?` (${c})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${We}`:"",i=[];for(let t of e.added)i.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)i.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)i.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(c=>c.id===t.id)||i.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)i.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Le(t.parts).map(c=>` ${c}`));for(let t of e.markup)i.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&i.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),i.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.user)),n=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.gallery));return[`Changes since ${g}:`,...i,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...n?[` Each change marked ${We} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function ut(e,g){let{qa:o,state:h}=U(e),i=O.join(o,g,"checked.html"),s=await R.readFile(i,"utf8").catch(()=>null);if(s!==null){let{mtime:y}=await R.stat(i);return{text:s,since:`the last check that found nothing (${qe(y)}, local time, ${W(i)})`,at:y.getTime()}}let n=O.join(h,"pages",g),t=(await R.readdir(n).catch(()=>[])).filter(y=>/^\d{15}-\d{4}\.html$/.test(y)).sort();if(t.length===0)return null;let c=O.join(n,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(c,"utf8"),since:`the page as it was before its last write (${qe(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var qe=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function ft(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let c=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),y=[...t.children].find(S=>S.matches(e));return{id:t.getAttribute("data-card-id"),block:y?.getAttribute(g)??null,out:f.width>0&&(f.left<c.left-1||f.right>c.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!y?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(S=>S.complete&&S.naturalWidth===0).map(o)}}),i=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,n=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:c,at:f})=>({kind:t,block:c,waited:Date.now()-f}));return{cards:h,broken:i,stuck:n,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function wt(e,{address:g,out:o,readers:h=new Set,wait:i=ge,limits:s={}}){let{loading:n=he,ready:t=et,answer:c=pe,closing:f=de,looking:y=ue}=s,S=new Map,N=new Map,d=[],a=!1,r=(l,v,$,m,I=S)=>{if(a)return;let w=I.get(l)??{card:v,what:$,looks:[]};w.looks.push(m),I.set(l,w)},k="a browser context opened",u=(l,v,$=c)=>(k=v,ye(l,v,$)),b=Q.flatMap(l=>De.map(v=>({width:l,theme:v,view:`${l} ${v}`}))),x=null,A=async({width:l,theme:v,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
2
+ import{c as _}from"./chunk-236JJXWY.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-Q7P3Q5YX.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-4KUO7R2M.mjs";import{M as Ae}from"./chunk-MKIBJTJZ.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-2KAVXMKG.mjs";import{d as Ce,g as je}from"./chunk-C257H6IA.mjs";import"./chunk-3XZOA7AH.mjs";import"./chunk-XZCFPKGO.mjs";import{i as ie}from"./chunk-BN7M3IN7.mjs";import{a as W}from"./chunk-JEUK3ZO7.mjs";import"./chunk-M4NRDYI5.mjs";import{a as re,b as le,e as de,f as K,g as ce}from"./chunk-PUOQ65NC.mjs";import"./chunk-6QWQXHAV.mjs";import"./chunk-6Q7ASAXJ.mjs";import"./chunk-S3SX3COT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-6NLXUKAY.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-7UZUQQ7Q.mjs";import{a as H,b as j,c as P,d as D,f as oe}from"./chunk-4B2TB5K2.mjs";import{a as te,e as B,f as ae}from"./chunk-KLQP46Y3.mjs";import{b as se}from"./chunk-4OZWXZE5.mjs";import"./chunk-USIHBCSW.mjs";import"./chunk-3SKOU6OZ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-PLB7L22J.mjs";import"./chunk-PAREWQGB.mjs";import{j as ne}from"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import{f as Z,j as ee}from"./chunk-TKWEX4FD.mjs";import{b as X,e as _e}from"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";_e();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import O from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as He,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as M,hasClass as q,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],De=["light","dark"],Ze=900,et=3e4,tt=new Set(["iframe","frame","object","embed"]),at=/^\d+$/,ot={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function st(e,{catalog:g,folder:o,slug:h}){let i=[],s=d=>d?.sourceCodeLocation?.startLine??1,n=(d,a)=>i.push({line:typeof d=="number"?d:s(d),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),c=[],f=[];Re(t,d=>{d.tagName&&(d.tagName==="main"&&q(d,"gallery-page")&&c.push(d),q(d,"gallery-board")&&f.push(d),q(d,"gallery-card")&&!q(d.parentNode,"gallery-board")&&n(d,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`))},{inTemplates:!1}),c.length===0&&(f.length>0||j(e).cards.length>0)&&n(1,`no <main class="gallery-page">: a page's boards stand in one (it is how a block knows it is on a page: context.place "page", and how the page follows the theme)`);let y=new Map;for(let d of f){let a=d.parentNode;for(;a&&!(a.tagName==="main"&&q(a,"gallery-page"));)a=a.parentNode;c.length&&!a&&n(d,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=M(d,"data-board-id");r===void 0||r===""?n(d,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):H.test(r)?y.has(r)?n(d,`data-board-id="${r}" again (line ${y.get(r)} has it): each board's id is its own`):y.set(r,s(d)):n(d,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let S=new Map,N=new Map;for(let d of j(e).cards){let{node:a}=d,r=M(a,"data-card-id"),k=r&&H.test(r)?`card ${r}`:"this card";r===void 0||r===""?n(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):H.test(r)?S.has(r)?n(a,`data-card-id="${r}" again (line ${S.get(r)} has it): each card's id is its own, and the page's writes go by it`):S.set(r,s(a)):n(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?n(a,`${k} holds no instance of a custom block (an element with ${He}): a card is one block's instance, gallery/static's for what only shows`):u>1?n(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):d.instance&&d.instance.parentNode!==a&&n(d.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let b={};for(let x of["x","y","w","h"]){let A=M(a,`data-${x}`),[L,E]=ot[x];A===void 0?n(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):at.test(A.trim())?Number(A)<L||Number(A)>E?n(a,`${k}'s data-${x}="${A}": ${x} is ${E===1/0?`${L} or more`:`${L} to ${E}`}${x==="w"?" (a row is 12 cells)":""}`):b[x]=Number(A):n(a,`${k}'s data-${x}="${A}" is no whole number`)}b.x!==void 0&&b.w!==void 0&&b.x+b.w>12?n(a,`${k} reaches past the row's end: data-x ${b.x} and data-w ${b.w} make ${b.x+b.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(b).length===4&&N.set(d.board,[...N.get(d.board)??[],{id:r??null,...b,line:s(a)}]),d.block&&nt(d.block,g,x=>n(d.instance,`${k}'s block ${d.block}: ${x}`))}for(let d of N.values())for(let a=0;a<d.length;a++)for(let r=a+1;r<d.length;r++){let[k,u]=[d[a],d[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&n(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return i.push(...it(e,{folder:o,slug:h})),i.sort((d,a)=>d.line-a.line)}function nt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let i=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):i?o(`it does not load (${ee("en",i.problem)}): gallery block check ${e} says why`):ae(e)&&B(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${B(e).pack===te?B(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function it(e,{folder:g,slug:o}){let h=[],i=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let n=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",c=Me(n)??(n.startsWith(i)?Me(n.slice(i.length-7)):null),f=`"${n.length>60?`${n.slice(0,60)}\u2026`:n}"`,y=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(c!==null){Qe(c)?tt.has(s.node.tagName)&&!Te(c)?h.push({line:s.line,what:`${y}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture, stylesheet or script for saving only: write what it shows in the page itself, frame a site by its https address, or offer the file with a link, <a href="${c}" download>`}):Ue(O.join(g,c))||h.push({line:s.line,what:`${y}: ${c} is not in the page's folder (${W(O.join(g,"assets"))}): put the file there${Te(c)?"":", or link to it"}`}):h.push({line:s.line,what:`${y} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!n||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(n)||h.push({line:s.line,what:`${y} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function rt(e,g){let o=P(e).text,h=[];for(let i of j(o).cards){let s=i.block?g.packages.get(i.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let n=G(D(o,i),_,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=n?.text.trim()?JSON.parse(n.text):{}}catch{continue}let c=je(s,t);c.length&&h.push({id:i.id,block:i.block,line:i.node.sourceCodeLocation?.startLine??1,empty:c})}return h}var lt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:i,zh:s})=>`${h} (${s&&s!==i?`${i}, ${s}`:i})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,dt=(e,g=!1)=>{let o=h=>M(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${M(e.node,"data-x")},${M(e.node,"data-y")}`,Pe=e=>`${M(e.node,"data-w")},${M(e.node,"data-h")}`;function ct(e,g,o){let[h,i]=[P(e).text,P(g).text],[s,n]=[j(h).cards,j(i).cards],t=new Set([...s,...n].map(a=>a.board)).size>1,c=a=>dt(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)n.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:c(a)});for(let a of n)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:c(a)});for(let a of n){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:c(r),now:c(a)}),u&&f.resized.push({id:a.id,block:a.block,was:c(r),now:c(a)});let[b,x]=[D(h,r),D(i,a)];if(b===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,L=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[E,l]=L?[G(b,_,L),G(x,_,L)]:[null,null];if(!E||!l){f.markup.push({id:a.id,block:A?a.block:null});continue}let v=E.parts.flatMap(({name:$,text:m},I)=>m===l.parts[I].text?[]:[{name:$,...Y(m,l.parts[I].text),runs:ke(m,l.parts[I].text)}]);v.length&&f.data.push({id:a.id,block:a.block,parts:v}),E.outside!==l.outside&&f.markup.push({id:a.id,block:a.block})}let y=(a,r)=>{let k="",u=0;for(let b of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,b.start),u=b.end;return k+a.slice(u)},[S,N]=[y(h,s),y(i,n)],d=a=>a.replace(/\s+/g," ");return d(S)!==d(N)&&(f.page=Y(S.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",We="(put there by Gallery)";function ht(e,g){let o=n=>{let t=new Map;for(let c of g)if(c.by===n)for(let[f,y]of Object.entries(c.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(y)?y:[]]));return t},h=o("page"),i=o("gallery"),s=n=>t=>{let c=!!h.get(t.id)?.has(n);return{...t,user:c,...!c&&i.get(t.id)?.has(n)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function pt(e,g){let o=({id:t,block:c})=>`${t}${c?` (${c})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${We}`:"",i=[];for(let t of e.added)i.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)i.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)i.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(c=>c.id===t.id)||i.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)i.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Le(t.parts).map(c=>` ${c}`));for(let t of e.markup)i.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&i.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),i.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.user)),n=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.gallery));return[`Changes since ${g}:`,...i,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...n?[` Each change marked ${We} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function ut(e,g){let{qa:o,state:h}=U(e),i=O.join(o,g,"checked.html"),s=await R.readFile(i,"utf8").catch(()=>null);if(s!==null){let{mtime:y}=await R.stat(i);return{text:s,since:`the last check that found nothing (${qe(y)}, local time, ${W(i)})`,at:y.getTime()}}let n=O.join(h,"pages",g),t=(await R.readdir(n).catch(()=>[])).filter(y=>/^\d{15}-\d{4}\.html$/.test(y)).sort();if(t.length===0)return null;let c=O.join(n,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(c,"utf8"),since:`the page as it was before its last write (${qe(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var qe=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function ft(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let c=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),y=[...t.children].find(S=>S.matches(e));return{id:t.getAttribute("data-card-id"),block:y?.getAttribute(g)??null,out:f.width>0&&(f.left<c.left-1||f.right>c.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!y?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(S=>S.complete&&S.naturalWidth===0).map(o)}}),i=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,n=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:c,at:f})=>({kind:t,block:c,waited:Date.now()-f}));return{cards:h,broken:i,stuck:n,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function wt(e,{address:g,out:o,readers:h=new Set,wait:i=ge,limits:s={}}){let{loading:n=he,ready:t=et,answer:c=pe,closing:f=de,looking:y=ue}=s,S=new Map,N=new Map,d=[],a=!1,r=(l,v,$,m,I=S)=>{if(a)return;let w=I.get(l)??{card:v,what:$,looks:[]};w.looks.push(m),I.set(l,w)},k="a browser context opened",u=(l,v,$=c)=>(k=v,ye(l,v,$)),b=Q.flatMap(l=>De.map(v=>({width:l,theme:v,view:`${l} ${v}`}))),x=null,A=async({width:l,theme:v,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
3
3
  `)[0]}`,null,`the console says ${p.text().split(`
4
4
  `)[0]}`,$)}),m.on("response",p=>{let C=new URL(p.url());p.status()>=400&&C.origin===new URL(g).origin&&C.pathname!=="/favicon.ico"&&r(`request ${C.pathname}`,null,`${C.pathname} answered ${p.status()}`,$)}),await u(be(m,{add:p=>r(`dialog ${p}`,null,`it opened a dialog (${p}), which stops a reader's page until it is answered`,$)}),"the tab was set to refuse dialogs"),await u(me(m),"the tab was set to watch the page's reads of the workspace"),await u(m.setViewport({width:l,height:Ze}),`the window went to ${l}px`),await u(m.emulateMediaFeatures([{name:"prefers-color-scheme",value:v}]),`the ${v} theme came`),await u(m.goto(g,{waitUntil:"load",timeout:0}),"the page opened",n),await u(m.waitForSelector("html[data-doc-ready][data-doc-drawn]",{timeout:0}),"the page was drawn (its html got data-doc-drawn)",t),await u(m.evaluate(()=>document.fonts?.ready.then(()=>!0)),"the page's fonts loaded");let I=await u(m.$("main"),"the page's main was found")??await u(m.$("body"),"the page's body was found");await u(I.evaluate(Oe,{still:fe,step:we,wait:i}),"the page held still");let w=await u(m.evaluate(ft,Ye,He),"the page was looked at");for(let{kind:p,block:C,waited:Ge}of w.stuck){let V=w.cards.filter(F=>C?F.block===C:h.has(F.block)),J=F=>`the workspace had not answered ${F} read of "${p}" ${Math.round(Ge/1e3)} s after it asked, so its picture shows it before it drew what it reads, which the picture then does not tell (open the page in Gallery to see it)`;if(V.length)for(let F of V)r(`unanswered ${F.id} ${p}`,F.id,J("its"),$,N);else r(`unanswered ${p}`,null,J("a card's"),$,N)}w.wide&&r("wide",null,`the page is ${w.wide}px wide in a window ${l}px wide: something of its own reaches past the window (a width of its own, a long word), and a reader scrolls it sideways`,$);for(let p of w.broken)r(`broken ${p}`,null,`a picture that does not load: ${p}`,$);for(let p of w.cards){p.fallback&&r(`fallback ${p.id}`,p.id,`its block failed: the card shows what its instance holds, read-only${p.error?` (${p.error.slice(0,200)})`:""}`,$),p.out&&r(`out ${p.id}`,p.id,"it is drawn out of its board",$),p.tall&&r(`tall ${p.id}`,p.id,`what it holds does not fit it: ${p.tall.needs}px high in a card that shows ${p.tall.has}px, the rest scrolling inside the card (give the card more cells, data-h, or a size its block lists; a block whose content grows says card.fit "content")`,$),p.wide&&r(`wide ${p.id}`,p.id,`what it holds is wider than the card: ${p.wide.needs}px in a card ${p.wide.has}px wide`,$);for(let C of p.broken)r(`broken ${p.id} ${C}`,p.id,`a picture that does not load: ${C}`,$)}let T=O.join(o,`${l}-${v}.png`);await u(m.screenshot({path:T,fullPage:!0}),"the page was pictured"),a||d.push(T)}finally{await K(m.close(),f)}},L=l=>({problems:[...S.values()],notes:[...N.values()],pictures:d,unverified:null,stuck:!1,...l}),E=null;try{x=await u(e.createBrowserContext(),"a browser context opened");for(let l of b)E=l,await gt(A(l),y,()=>k);return L({})}catch(l){return await Se(e)?L({unverified:`the browser went while it looked (${z(l)})`}):l.stuck?(r("stopped",null,mt(l,b.indexOf(E??b[0])<b.length-1),(E??b[0]).view),L({stuck:!0})):L({unverified:`the look stopped: ${z(l)}`})}finally{a=!0,await K(x?.close(),f)}}function gt(e,g,o){let h=0,i=new Promise((s,n)=>{h=setTimeout(()=>n(Object.assign(new Error(o()),{stuck:!0,doing:o(),limit:g,whole:!0})),g)});return Promise.race([e,i]).finally(()=>clearTimeout(h))}function mt(e,g){return`${e.whole?`the look was not done in ${xe(e.limit)}, waiting until ${e.doing}`:ve(e)}; the look stopped here and the browser was closed${g?", so the looks after it were not made":""}. A script of the page that never ends does this, and so may a browser that stalled: run the check once more, and if it stops at the same place again, the page holds it up`}function Be(e){let g=[...new Set(e.map(i=>i.split(" ")[0]))],o=[...new Set(e.map(i=>i.split(" ")[1]))],h=i=>i.length<2?i.join(""):`${i.slice(0,-1).join(", ")} and ${i.at(-1)}`;return`at ${h(g)}px${o.length===De.length?"":`, ${h(o)}`}`}async function Ht(e,g){if(g.length!==1)throw new se("gallery page check takes one page's slug.");let[o]=g,h=Xe(o,e);Je(o,e)||(console.error(await Ce(o,e)),process.exit(1));let i=new Date,s=await R.readFile(h.html,"utf8"),n=O.basename(h.html),t=Z(e),{boards:c,cards:f}=j(s);console.log(`${o}: ${W(h.html)}, ${c.length} board${c.length===1?"":"s"} and ${f.length} card${f.length===1?"":"s"}`);let y=[],S=st(s,{catalog:t,folder:h.folder,slug:o});for(let{line:l,what:v}of S)y.push(` FAIL ${n}:${l}: ${v}`);console.log(S.length?`Structure: ${S.length} problem${S.length===1?"":"s"}`:"Structure: nothing wrong (the page's own HTML, scripts and frames its own; every board's and card's id once, one instance a card, the cells on the board and none shared, every block one a page runs, every file of assets/ there)");for(let l of y)console.log(l);for(let l of j(P(s).text).cards)console.log(` ${l.id} ${l.block??"(no instance)"} x ${l.x}, y ${l.y}, ${l.w} \xD7 ${l.h}${c.length>1?` on ${l.board}`:""} ${n}:${l.node.sourceCodeLocation?.startLine}`);let N=rt(s,t);for(let l of N)console.log(` note ${n}:${l.line}: ${lt(l)}`);let d=await ut(e,o),a=d?await oe(U(e).state,o,d.at):[];console.log((d?pt(ht(ct(d.text,s,t),a),d.since):["No earlier version to tell changes against: the next check that finds nothing keeps this one, and says what changed since."]).join(`
5
- `));let r=new Map(j(P(s).text).cards.map(l=>[l.id,l.node.sourceCodeLocation?.startLine??1])),k=(l,v=null,$=0)=>{if(l)return{line:`FAIL ${o}: ${l} problem${l===1?"":"s"}`,code:1};if(v)return{line:`UNVERIFIED ${o}: ${v}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:I,empty:w})=>`${I} (${w.map(({key:T})=>T).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),b=async(l,v,$=0)=>{let{line:m,code:I}=k(l,v,$);if(console.log(m),I===0){let w=O.join(U(e).qa,o,"checked.html");await R.mkdir(O.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,i,i)}process.exitCode=I};if(!u.ok)return b(S.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return b(S.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Ie(e);let A=await Ee(e,{directory:h.folder,files:h,text:s}),L=O.join(U(e).qa,o,"check"),E=null;try{let{pageAloneOf:l}=await import("./chunk-UJQJKNGK.mjs"),v=l(u.port,A.slug);console.log(`Looked at: ${v} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${n}), at ${Q.join(", ")}px, light and dark`);try{E=await ce({executablePath:x,args:le()})}catch(w){return b(S.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(L,{recursive:!0,force:!0}),await R.mkdir(L,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await wt(E.browser,{address:v,out:L,readers:$});m.stuck&&(await E.close(),E=null);for(let{card:w,what:T,looks:p}of m.problems)console.log(` FAIL ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${T} (${Be(p)})`);let I=new Map(j(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:T,looks:p}of m.notes)console.log(` note ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}${I.get(w)?` (${I.get(w)})`:""}: `:""}${T} (${Be(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${W(L)}: ${m.pictures.map(w=>O.basename(w)).join(", ")}`),console.log(Ae([{folder:O.dirname(L),files:m.pictures}]))),b(S.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await E?.close(),await Ne(e,A.slug)}}export{We as GALLERYS_MARK,Q as LOOK_WIDTHS,De as THEMES,ze as USERS_MARK,ut as baselineOf,pt as changesSaid,rt as emptyRequired,lt as emptyRequiredSaid,wt as look,ht as markedTheUsers,ct as pageChanges,Ht as pageCheckCommand,st as structureProblems};
5
+ `));let r=new Map(j(P(s).text).cards.map(l=>[l.id,l.node.sourceCodeLocation?.startLine??1])),k=(l,v=null,$=0)=>{if(l)return{line:`FAIL ${o}: ${l} problem${l===1?"":"s"}`,code:1};if(v)return{line:`UNVERIFIED ${o}: ${v}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:I,empty:w})=>`${I} (${w.map(({key:T})=>T).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),b=async(l,v,$=0)=>{let{line:m,code:I}=k(l,v,$);if(console.log(m),I===0){let w=O.join(U(e).qa,o,"checked.html");await R.mkdir(O.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,i,i)}process.exitCode=I};if(!u.ok)return b(S.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return b(S.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Ie(e);let A=await Ee(e,{directory:h.folder,files:h,text:s}),L=O.join(U(e).qa,o,"check"),E=null;try{let{pageAloneOf:l}=await import("./chunk-2T4PZQEP.mjs"),v=l(u.port,A.slug);console.log(`Looked at: ${v} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${n}), at ${Q.join(", ")}px, light and dark`);try{E=await ce({executablePath:x,args:le()})}catch(w){return b(S.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(L,{recursive:!0,force:!0}),await R.mkdir(L,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await wt(E.browser,{address:v,out:L,readers:$});m.stuck&&(await E.close(),E=null);for(let{card:w,what:T,looks:p}of m.problems)console.log(` FAIL ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${T} (${Be(p)})`);let I=new Map(j(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:T,looks:p}of m.notes)console.log(` note ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}${I.get(w)?` (${I.get(w)})`:""}: `:""}${T} (${Be(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${W(L)}: ${m.pictures.map(w=>O.basename(w)).join(", ")}`),console.log(Ae([{folder:O.dirname(L),files:m.pictures}]))),b(S.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await E?.close(),await Ne(e,A.slug)}}export{We as GALLERYS_MARK,Q as LOOK_WIDTHS,De as THEMES,ze as USERS_MARK,ut as baselineOf,pt as changesSaid,rt as emptyRequired,lt as emptyRequiredSaid,wt as look,ht as markedTheUsers,ct as pageChanges,Ht as pageCheckCommand,st as structureProblems};
@@ -0,0 +1,15 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as we,b as q,c as X,f as be,g as L,h as ke,i as Q,l as ye,m as xe}from"./chunk-3SKOU6OZ.mjs";import{a as gt}from"./chunk-ZTHICSSF.mjs";import{b as le,c as $t,e as K,f as de,i as fe,j as he,m as ue,n as pe,o as me,p as ge,q as $e,r as wt}from"./chunk-PLB7L22J.mjs";import{a as pt}from"./chunk-PAREWQGB.mjs";import{a as te,b as ee,c as oe,d as se,e as ne,f as ie,g as ae,h as re,l as ce}from"./chunk-BFJGHSQN.mjs";import{b as mt,c as Yt,d as qt,e as Xt,g as Qt}from"./chunk-U5XL7D6A.mjs";import{a as w,b as Vt,c as Zt}from"./chunk-HYMEEXKN.mjs";import{g as T,j as Kt,l as Gt,m as Jt}from"./chunk-TKWEX4FD.mjs";import{existsSync as bo,readFileSync as ki,readdirSync as yi}from"node:fs";import S from"node:fs/promises";import N from"node:path";function Se(t){if(!t||!Array.isArray(t.lines))throw new Error("diff: lines must be an array.");t.lines.forEach(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 kt,isInstance as Wo}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as Bo}from"../browser/shared/components/installed.mjs";import{attr as F,elementsOf as Ne,hasClass as Ho,walk as yt}from"../browser/shared/html-tree.mjs";import{CHART_DATA as Ko,CHART_KEY as Go,CHART_SOURCE as z,VIEW_FROM as tt,cellWords as Jo,rowsReading as ve,tableRows as Vo}from"../browser/shared/table-chart.mjs";var Zo=t=>t.tagName==="script"&&(F(t,"type")??"").trim().toLowerCase()==="application/json",Oe=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(Oe).join("");function Yo(t){let e=t;for(;e&&e.tagName!=="figure";)e=e.parentNode;let s=e?Ne(e).find(o=>/^h[2-4]$/.test(o.tagName)):null;return s?Jo(Oe(s)):""}function Ee(t,e,s=w(t)){let o=[];return yt(s,n=>{let i=e(n);if(i===void 0||!n.sourceCodeLocation)return;let a=n.childNodes.find(Zo);o.push({type:i,line:n.sourceCodeLocation.startLine,text:a?a.childNodes.map(c=>c.value??"").join(""):null,source:F(n,Ko),tag:n.tagName,holder:n.parentNode?.tagName,title:Yo(n)})},kt),o}var qo=t=>t.tagName==="ol"&&F(t,"data-doc-chart")==="flow",et=(t,e)=>Ee(t,s=>qo(s)?void 0:F(s,"data-doc-chart"),e),Xo=t=>Ee(t,e=>Ho(e,"doc-diff")?"diff":void 0);function G(t){let e=new Map;return yt(t,s=>{let o=F(s,z);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:Ne(s).find(i=>i.tagName==="table")??null})},{...kt,inTemplates:!1}),e}function xt(t,e){let s=e.get(t)??[];if(s.length===0)return{error:`no table's frame carries ${z}="${t}", so the chart has nothing to draw: put the table back, or delete the card`};if(s.length>1)return{error:`${s.length} tables carry ${z}="${t}" (lines ${s.map(({line:c})=>c).join(", ")}): a key names one table (the chart draws the first); take it off the copies`};let[{line:o,table:n}]=s;if(!n)return{error:`the frame carrying ${z}="${t}" (line ${o}) holds no table`};let i=gt(n),a=Vo(i);return a.error?{error:`its table (line ${o}) ${a.error}`}:{...a,line:o,cells:i}}function St(t){let e=[t,...L(t).filter(({files:n})=>n.includes("kit.js")).map(n=>Q(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 Nt(t){let e=w(t),s=[],{defined:o,misnamed:n}=St(t),i=null;for(let{type:a,line:c,text:l,source:r,tag:d,holder:f}of et(t,e)){let h=`data-doc-chart="${a}" (line ${c})`;if(d==="table"){s.push(f==="figure"?`${h} is on a table inside a <figure>: the chart's card is a figure of its own, so write the table outside it, its <caption> the chart's title`:`${h} is on a table the tools leave as written (inside a whole block, an element with a class of the document's own, a cell): a chart is drawn from a table outside one`);continue}if(n.has(a)){s.push(`${h}: the document's script defines "${a}" with DocCharts.define, which refuses that name: a chart type's name is lowercase letters, digits and hyphens, a letter first ("interval", "ci-plot"); rename it in both places`);continue}if(!o.has(a)){s.push(`${h}: the document's script does not define "${a}": define it once in the document's <script> with DocCharts.define("${a}", ({ host, data, tokens, width, height }) => { \u2026 }) (references/writing-html.md, "Figures and charts")`);continue}if(r!==void 0){if(l!==null){s.push(`${h}: a chart drawn from a table takes its data from the table: take its <script type="application/json"> out`);continue}let u=xt(r,i??=G(e));u.error&&s.push(`${h}: ${u.error}`);continue}if(l===null){s.push(`${h} needs its data in a <script type="application/json"> child`);continue}try{JSON.parse(l)}catch(u){s.push(`${h}: its data is not valid JSON (${u.message})`)}}s.push(...Le(e,i??=G(e)).failures);for(let{line:a,text:c}of Xo(t)){if(c===null)continue;let l=`.doc-diff (line ${a})`;try{Se(JSON.parse(c))}catch(r){s.push(`${l}: ${r instanceof SyntaxError?`its options are not valid JSON (${r.message})`:r.message}`)}}return s}function Te(t,{written:e=t}={}){let s=w(t),o=[],{defined:n}=St(t),i=null,a=null;for(let{type:c,line:l,text:r,source:d,title:f,tag:h}of et(t,s)){if(d===void 0||h==="table"||r!==null||!n.has(c))continue;let u=`data-doc-chart="${c}" (line ${l})`;if(!f){a??=new Set(e===t?[]:et(e).map(k=>k.source).filter(k=>k!==void 0));let b=e!==t&&!a.has(d);o.push(`${u}: this chart card has no title: ${b?"write a <caption> on its table (the one with data-doc-chart), which becomes the card's h3":"write an h3 in the card's figure, before the chart"}`)}let m=xt(d,i??=G(s));if(m.error)continue;let{blank:p,twice:g}=ve(m.cells,m.data);p&&o.push(`${u}: its table's header (line ${m.line}) has a cell with no words, so that column's values are keyed "" in data: write the column's name there`),g.length>0&&o.push(`${u}: its table's header (line ${m.line}) names ${g.map(b=>`"${b}"`).join(", ")} twice, so data keeps the later column's value under it: give each column a name of its own`)}return o.push(...Le(s,i??=G(s)).notes),o}var bt=500;function Le(t,e){let s=[],o=[],n=T().packages;return yt(t,i=>{let a=F(i,tt);if(a===void 0||!i.sourceCodeLocation)return;let c=F(i,Bo),l=`${c??i.tagName} (line ${i.sourceCodeLocation.startLine})`;if(!Wo(i))return void s.push(`<${i.tagName}> (line ${i.sourceCodeLocation.startLine}) carries ${tt}="${a}", which only a view of a table carries: an instance of a custom block (<div data-doc-component="<scope>/<name>">) whose block's needs hold "tables"; take it off`);if(!Go.test(a))return void s.push(`${l}: ${tt}="${a}" is no key: a letter, then letters, digits, "_" or "-", 32 at most, as the table's frame writes it in ${z}`);let r=e.get(a)??[];if(r.length===0)return void s.push(`${l}: no table's frame carries ${z}="${a}", so the view has no table to read: put the table back, or delete the view`);if(r.length>1)return void s.push(`${l}: ${r.length} tables carry ${z}="${a}" (lines ${r.map(({line:g})=>g).join(", ")}): a key names one table (the view reads the first); take it off the copies`);let[{line:d,offset:f,table:h}]=r;if(!h)return void s.push(`${l}: the frame carrying ${z}="${a}" (line ${d}) holds no table`);i.sourceCodeLocation.startOffset<f&&o.push(`${l} stands before the table it reads (${z}="${a}", line ${d}): it works there, but each block's writing.md writes the table first and the view after it, as its example does: move the view below the table, unless the document is meant to open on it`);let u=n.get(c)?.needs;u&&!u.includes("tables")&&o.push(`${l} carries ${tt}="${a}", but its block's needs hold no "tables", so it reads no table: add "tables" to needs in its component.json, or take the key off`);let m=gt(h);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>bt&&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 ${bt} rows that slows typing in it; split it, or keep what a view shows to ${bt} rows`)},kt),{failures:s,notes:o}}function Ae(t){let e=w(t),s=[],o=[],{defined:n}=St(t),i=null,a=(c,l)=>`${c} ${l}${c===1?"":"s"}`;for(let{type:c,line:l,text:r,source:d,tag:f}of et(t,e)){if(d===void 0||f==="table"||r!==null||!n.has(c))continue;let h=xt(d,i??=G(e));if(h.error)continue;let{rows:u,columns:m,foot:p,extra:g}=ve(h.cells,h.data),b=`data-doc-chart="${c}" (line ${l})`,k=[a(u,"row")];for(let{name:x,numbers:v,words:E,empty:H}of m){let R=v+E+H,Y=v===R&&R>0?"numbers":E===R&&R>0?"words":[v&&a(v,"number"),E&&`${E} as words`,H&&`${H} empty (null)`].filter(Boolean).join(", ")||"no rows";k.push(`"${x}": ${Y}`),v>0&&E>0&&o.push(`${b}: its table's column "${x}" (line ${h.line}) reads as numbers in ${a(v,"row")} and as words in ${E}: write each of its cells as one number (an empty cell, "\u2014" or "n/a" for none: null in data), or, for a column of words, data-sort-type="text" on its header cell`)}p>0&&o.push(`${b}: its table's <tfoot> (line ${h.line}) holds ${a(p,"row")} the chart leaves out, and a table with a <tfoot> has no table tools in the preview: keep a total out of a table you chart and say it in the text`),g>0&&o.push(`${b}: ${a(g,"row")} of its table (line ${h.line}) ${g===1?"has":"have"} cells past the header, which the chart does not read: give each column a header cell`),s.push(`${c} (line ${l}) reads its table (line ${h.line}): ${k.join("; ")}`)}return{readings:s,notes:o}}import{BODY as xi,componentOf as Si,matchesNode as ko}from"../browser/shared/components/index.mjs";import{FLOW as Ni}from"../browser/shared/components/list.mjs";import{attr as O,elementsOf as yo,walk as M}from"../browser/shared/html-tree.mjs";import{GLYPH_SETS as vi,ICON_COLORS as xo,glyphOf as Oi,glyphValue as Ei,iconKind as Pt,iconMarkup as Ti,iconValueOf as Li}from"../browser/shared/emoji/icon-value.mjs";import Qo from"node:vm";import{LINE_START as nt,lineStart as ts}from"../browser/shared/code-lines.mjs";import{BODY as De,COMPONENTS as es,FLOWS as os,instanceSlots as ss,instancesOf as ns,isInstance as D,isSlot as _e,matchesNode as P,ownSlots as is,partOf as Tt,vocabulary as as}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as C,INSTANCE as rs,PACKAGE_ID as it,SCHEMA as vt,SLOT as I,schemaAhead as cs}from"../browser/shared/components/installed.mjs";import{packageScript as ls}from"../browser/shared/export-wrap.mjs";import{asDocName as ds,kitNamespace as fs}from"../browser/shared/old-names.mjs";import{shortSheets as hs}from"../browser/shared/components/sheets.mjs";import{attr as y,curlyQuoted as us,hasClass as ps,walk as J}from"../browser/shared/html-tree.mjs";var{authoring:st,runtime:Ce}=as(),ms="input, select, textarea, button, details, table",at=t=>t.sourceCodeLocation?.startLine,$=t=>at(t)?` (line ${at(t)})`:"";function ze(t){let e=(o,n)=>{let i=Array.from({length:n.length+1},(a,c)=>c);for(let a=1;a<=o.length;a++){let c=i[0];i[0]=a;for(let l=1;l<=n.length;l++){let r=i[l];i[l]=Math.min(i[l]+1,i[l-1]+1,c+(o[a-1]===n[l-1]?0:1)),c=r}}return i[n.length]},[s]=[...st.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 gs(t,e,s){let{part:o,property:n,min:i}=t.shares,a=new RegExp(`(?:^|;)\\s*${n}\\s*:\\s*([^;]*)`),c=s.map(f=>a.exec(y(f,"style")??"")?.[1].trim()??null),l=c.filter(f=>f!==null);if(l.length===0)return[];let r=`${t.id}${$(e)}`;return l.length<c.length?[`${r}: ${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)?[`${r}: ${n} is a share of the row, a number from ${Math.round(i*1e3)/1e3} to 1 (${l.join(", ")})`]:[]}var ot={"doc-dialog-header":'a detail card has no header: its content region (<div class="doc-dialog-content">) stands alone in its panel',"doc-dialog-title":"a detail card's title is an ordinary heading (<h3>), first in its content region","doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","data-doc-dialog-close":"a detail card has no close button: Esc and a press outside it close it","doc-section-header":"a section's title is a plain heading (<h2>) with an ordinary paragraph below it for the line that says what the section is: no <div> goes around them","doc-grid":'a card row is now columns: <div class="doc-columns"> holding one <div class="doc-column"> per card',"doc-grid-3":'a card row is now columns: <div class="doc-columns"> holding three <div class="doc-column">',"doc-lede":`write the line under the title as a paragraph of the header (an ordinary <p>), or as small text, <p class="doc-note"): the header's lines read as the body's paragraphs`,"doc-source":`write the line under the title as a plain paragraph of the header (an ordinary <p>), or as small text (<p class="doc-note">): the header's lines read as the body's paragraphs`,"doc-prose":"write the text straight in its flow (the page, a Sheet panel, a section, a panel, a column\u2026): it reads the same there","doc-prose-h1":"write an h1","doc-prose-h2":"write an h2","doc-prose-h3":"write an h3","doc-prose-h4":"write an h4","doc-state-grid":'put the groups side by side in columns (<div class="doc-columns">)',"doc-state-group":"write the group's title as a heading and its controls as blocks of their own in a column","doc-state-status":'write the line as small text, <p class="doc-note">',"doc-code-block":'a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre><code>',"doc-code-card":'a code block is <div class="doc-code"> holding its title and its <pre>; a diff is <div class="doc-diff">',"doc-code-header":'write the title as <div class="doc-code-title">: the kit draws the rest of the header',"data-doc-diff":'a diff is <div class="doc-diff"> holding its title and its options as JSON (sdk/doc-code.d.ts)',"data-doc-diff-stats":"the kit shows a diff's counts in its header: remove it","doc-code--wrap":"a code block wraps its long lines by itself: remove it (doc-code--nowrap scrolls them instead)"},$s={[nt]:'write it on its <div class="doc-code">',"data-start":`write ${nt} on its <div class="doc-code">`,"data-line-numbers":'write it on its <div class="doc-code">',"data-folded-lines":'write it on its <div class="doc-code">',"data-title":'write the title in its <div class="doc-code-title">',"data-wrap":'for long lines that scroll, write class="doc-code doc-code--nowrap" on its <div class="doc-code">'};function ws(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($s))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,nt):void 0;return o!==void 0&&ts(o)===null&&e.push(`${nt}="${o}"${$(t)}: the number of a code block's first line is a whole number from 1`),e}var Ie=os.join(", "),bs=t=>P(t.parentNode,Ie)||t.parentNode?.tagName==="div"&&!y(t.parentNode,"class")&&P(t.parentNode.parentNode,Ie);function ks(t,e){let s=[];J(e,n=>s.push(...us(t,n)));let o=n=>n.replace(/=(\s*)[“”]/,'=$1"').replace(/[“”]$/,'"');return s.map(({written:n,line:i},a)=>a===0?`line ${i}: attribute ${n} uses curly quotes (U+201C/U+201D), which HTML reads as part of the value: write straight quotes, ${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 je={details:"write a plain <details> without the class (its <summary>, then what it holds): the export makes it the kit's"},ys="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",xs='a bookmark written the short way is a paragraph in a flow holding only <a class="doc-bookmark" href="https://\u2026">its title</a> (a title attribute its description, nothing else on it, words alone in it): the export makes the card';function Me(t){let e=[];return J(t,s=>{y(s,C)!==void 0&&e.push(s)},De),e}var Ss=t=>{let e=t.parentNode;for(;e&&!(D(e)||_e(e));)e=e.parentNode;return e??null};function Ns(t,e){let s=[];return J(t,o=>{let n=y(o,I);if(n===void 0)return;if(D(o))return void s.push(`${I}="${n}"${$(o)} on the instance itself: a slot is an element inside it`);if(!_e(o))return void s.push(`${I}${$(o)} on a <${o.tagName}>: a slot is a block-level <div> or <section>`);let i=Ss(o),a=i&&D(i)?e?.get(y(i,C)):null;if(!i||!D(i)||a&&Pe(i,a,o))return void s.push(`${I}="${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(`${I}="${n}"${$(o)}: a slot is no block: it carries no data-block-id`)}),s}var vs=(t,e)=>{for(let s=e.parentNode;s;s=s.parentNode)if(s===t)return!0;return!1},Pe=(t,e,s)=>Object.values(e.parts??{}).filter(({edit:o})=>o==="text"||o==="data").some(({at:o})=>Tt(t,o).some(n=>vs(n,s))),Re=(t,e)=>is(t).filter(s=>!Pe(t,e,s)),Os=t=>t.flatMap(e=>D(e)?it.test(y(e,C))?[]:[`${C}="${y(e,C)}"${$(e)} names no custom block: write <scope>/<name>, the id of a custom block of the workspace's components/ folder`]:[`${C}${$(e)} on a <${e.tagName}>: an instance of a component is a block-level <div> or <section>`]);function Ue(t){let e=Me(t).filter(o=>D(o)&&it.test(y(o,C))),s=e.length>0?T():null;return e.flatMap(o=>{let n=y(o,C),i=s.packages.get(n);if(i&&!cs(y(o,vt),i.schema))return[];if(i)return[`line ${at(o)}: <${o.tagName} ${C}="${n}">: ${vt}="${y(o,vt)}" is past the ${i.schema??1} its package's manifest reads (schema): nothing can write it back, and the block shows read-only until the package reads it`];let a=s.problems.get(n)?.problem,c=a?`package ${n} does not load (${Kt("en",a)})`:`no package ${n} in this workspace (components/${n}/component.json)`;return[`line ${at(o)}: <${o.tagName} ${C}="${n}">: ${c}: the block shows what it holds, read-only, and moves, copies and deletes whole`]})}function Ot(t,e){let s=[];for(let{name:o,value:n}of t.attrs){if(ot[o]&&!st.has(o)){s.push(`${o}${$(t)} is gone: ${ot[o]}`);continue}if(o.startsWith("data-doc-")&&!st.has(o)&&s.push(Ce.has(o)?`${o}${$(t)} is the kit's to set: remove it`:`${o}${$(t)} is no attribute of the kit's${ze(o)}`),o==="class"){for(let i of n.split(/\s+/).filter(e))if(!st.has(i)){if(ot[i]){s.push(`class ${i}${$(t)} is gone: ${ot[i]}`);continue}s.push(Ce.has(i)?`class ${i}${$(t)} is the kit's to set: remove it`:`class ${i}${$(t)} is no class of the kit's${ze(ds(i))}: give a class of the document's own a name of its own (not doc-\u2026)`)}}}return s}var Fe=t=>t.startsWith("doc-");function Es(t){try{return new Qo.Script(ls(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 Et=new Map;function Ts(t){if(!t.files.includes("kit.js"))return null;if(Et.get(t.folder)?.stamp!==t.stamp){let e=Q(t,"kit.js"),s=e===null?null:Es(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})`:""}`;Et.set(t.folder,{stamp:t.stamp,failure:o})}return Et.get(t.folder).failure}function Lt(t,e=w(t),s=null){let o=ks(t,e),n=Me(e);o.push(...Os(n));let i=n.length>0?s??T():null,a=i?[...i.packages.values()]:[];i&&o.push(...L(t,i,e).map(Ts).filter(Boolean));for(let r of[...es,...a].filter(d=>d.match&&(d.parts||d.pairs)))for(let d of ns(e,r)){if(r.empty&&!(d.childNodes??[]).some(u=>u.tagName||u.nodeName==="#text"&&u.value.trim()))continue;let f=r.id==="sheets"?hs(d):null;if(f){o.push(`${r.id}${$(d)} has no tabs and is no short form: ${f.why??"it stands where no block does (in a whole block or a figure)"}; ${ys}`);continue}if(je[r.id]&&Object.values(r.parts??{}).some(u=>Tt(d,u.at).length<(u.optional?0:u.min??1))){o.push(`${r.id}${$(d)} carries the kit's class without the kit's parts: ${je[r.id]}`);continue}let h={};for(let[u,m]of Object.entries(r.parts??{})){if(m.edit==="flow"&&it.test(r.id)){let b=Re(d,r).filter(k=>y(k,I)===u);b.length===0&&!m.optional&&o.push(`${r.id}${$(d)} has no ${u} (${I}="${u}")`);for(let k of b.slice(1))o.push(`${r.id}${$(k)}: slot "${u}" twice`);h[u]=b.slice(0,1);continue}h[u]=Tt(d,m.at);let p=m.optional?0:m.min??1,g=m.max??1/0;h[u].length<p?o.push(`${r.id}${$(d)} has ${h[u].length===0?"no":`${h[u].length} of`} ${u} (${m.at.replace(":scope > ","")})${h[u].length>0?`, at least ${p}`:""}`):h[u].length>g&&o.push(`${r.id}${$(d)} has ${h[u].length} of ${u}, at most ${g}`)}if(r.only){let u=new Set(r.only.flatMap(m=>h[m]));for(let m of(d.childNodes??[]).filter(p=>p.tagName&&!u.has(p)))o.push(`${r.id}${$(d)} holds a <${m.tagName}>${$(m)}: only its ${r.only.join(", ")} (${r.only.map(p=>r.parts[p].at.replace(":scope > ","")).join(", ")}) go in it`)}if(r.shares&&o.push(...gs(r,d,h[r.shares.part])),it.test(r.id)){let u=Object.entries(r.parts??{}).filter(([,m])=>m.edit==="flow").map(([m])=>m);for(let m of Re(d,r).filter(p=>!u.includes(y(p,I))))o.push(`${r.id}${$(m)}: slot "${y(m,I)}" is no part of its manifest edited as flow`)}for(let{a:u,attrA:m,b:p,attrB:g}of r.pairs??[]){let b=h[u].map(x=>y(x,m)),k=h[p].map(x=>y(x,g));for(let x of new Set(b.filter((v,E)=>b.indexOf(v)!==E)))o.push(`${r.id}${$(d)}: ${u} "${x}" twice`);for(let x of b.filter(v=>!k.includes(v)))o.push(`${r.id}${$(d)}: ${u.replace(/s$/,"")} "${x}" has no ${p.replace(/s$/,"")} (${g}="${x}")`);for(let x of k.filter(v=>!b.includes(v)))o.push(`${r.id}${$(d)}: ${p.replace(/s$/,"")} "${x}" has no ${u.replace(/s$/,"")} (${m}="${x}")`)}}o.push(...Ns(e,i?.packages));let c=new Set,l=[];J(e,r=>{if(D(r)){let h=new Set(ss(r));o.push(...Ot(r,Fe)),J(r,u=>o.push(...Ot(u,Fe)),{stop:u=>h.has(u)});return}r.tagName==="pre"&&bs(r)&&o.push(`<pre>${$(r)} straight in the text: a code block is <div class="doc-code"> holding its title (<div class="doc-code-title">) and the <pre>`),o.push(...ws(r)),r.tagName==="a"&&ps(r,"doc-bookmark")&&o.push(`<a class="doc-bookmark">${$(r)} is no bookmark: ${xs}`),o.push(...Ot(r,fs));let d=y(r,"data-doc-bind");d!==void 0&&(d.trim()?P(r,ms)?r.tagName==="button"&&y(r,"value")===void 0?o.push(`data-doc-bind${$(r)} on a button without a value: give it the value a click chooses`):c.add(d.trim()):o.push(`data-doc-bind${$(r)} on a ${r.tagName}: only inputs, selects, textareas, buttons with a value, details and tables hold a key`):o.push(`data-doc-bind${$(r)} names no key`));let f=y(r,"data-doc-show");f!==void 0&&l.push([r,f])},De);for(let[r,d]of l){let f=d.split(":")[0].trim();!f||!d.includes(":")?o.push(`data-doc-show="${d}"${$(r)}: write key:value`):c.has(f)||o.push(`data-doc-show="${d}"${$(r)}: nothing binds "${f}" (data-doc-bind="${f}")`)}return o.push(...js(t,e)),o}var Ls=/(?<![\\$])\$(?=[^\s$])([^$]*?[^\s$\\])\$(?![$\d])/g,As=/(?:(?<![A-Za-z0-9_])[A-Za-z]|[)\]}])_[A-Za-z0-9{]/,Cs=t=>/[\\^]/.test(t)||!t.startsWith("{")&&As.test(t),zs=new Set(["head","code","pre","kbd","samp","script","style","template","textarea","noscript","svg","math","title","iframe","object"]),Is=`.doc-math-inline, .doc-math-block, .doc-code, .doc-diff, [data-doc-math-dollar], [data-doc-chart], ${rs}`;function js(t,e){let s=[],o=n=>{for(let i of n.childNodes??[])if(i.nodeName==="#text"&&i.sourceCodeLocation&&i.value.includes("$")){let{startOffset:a,endOffset:c}=i.sourceCodeLocation;for(let l of t.slice(a,c).matchAll(Ls)){if(!Cs(l[1]))continue;let r=l[1].replace(/\s+/g," "),d=r.length>60?`${r.slice(0,59)}\u2026`:r;s.push(`line ${Zt(t,a+l.index)}: $${d}$ is not drawn as a formula (single dollars are off: they are money): write \\(${d}\\)`)}}else i.tagName&&!zs.has(i.tagName)&&!P(i,Is)&&o(i)};return o(e),s}import V from"node:fs";import W from"node:path";import{COLOR_NAMES as Hs}from"../browser/shared/colors.mjs";import{FOLD_DOTS as Ks}from"../browser/shared/code-folds.mjs";import{kitPublicDirectory as Gs,kitSourceDirectory as Js,release as Vs}from"../browser/shared/paths.mjs";import{FLOW_LABEL as Ua}from"../browser/shared/components/list.mjs";var Rs={"code-title":{zh:"\u4EE3\u7801\u5757",en:"Code"},"plain-text":{zh:"\u7EAF\u6587\u672C",en:"Plain text"},"fold-code":{zh:"\u6298\u53E0\u6216\u5C55\u5F00\u4EE3\u7801\u5757",en:"Collapse or expand the code block"},"copy-code":{zh:"\u590D\u5236\u4EE3\u7801",en:"Copy code"},copied:{zh:"\u5DF2\u590D\u5236",en:"Copied"},wrap:{zh:"\u81EA\u52A8\u6362\u884C",en:"Wrap lines"},"no-wrap":{zh:"\u53D6\u6D88\u81EA\u52A8\u6362\u884C",en:"Stop wrapping lines"},fold:{zh:"\u6298\u53E0",en:"Collapse"},unfold:{zh:"\u5C55\u5F00",en:"Expand"},line:{zh:"\u7B2C {0} \u884C",en:"Line {0}"},lines:{zh:"\u7B2C {0}\u2013{1} \u884C",en:"Lines {0}\u2013{1}"},"diff-counts":{zh:"\u65B0\u589E {0} \u884C\uFF0C\u5220\u9664 {1} \u884C",en:"Lines added: {0}, removed: {1}"}};var We="data-ge-language",Fs={"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,(a,c)=>c<o.length?String(o[c]):a)}var _s=`:root[${We}="en"], :root:not([${We}])[lang|="en" i]`;function Be(){let t=e=>Object.entries(Fs).map(([s,o])=>`${o}: ${JSON.stringify(Ds(Rs,e,s))};`).join(" ");return`:root { ${t("zh")} }
4
+ ${_s} { ${t("en")} }`}import{LOOK as At,LOOK_ATTRIBUTES as Ms,SERIF_FONT as He,SIZE_FACTOR as Ps,SPACING as Us,WIDTH as Ct}from"../browser/shared/document-look.mjs";var Ke=[["--doc-body-font-size","--doc-body-line-height"],["--doc-small-font-size","--doc-small-line-height"],["--doc-note-font-size","--doc-note-line-height"],["--doc-title-font-size","--doc-title-line-height"],["--doc-h1-font-size","--doc-h1-line-height"],["--doc-h2-font-size","--doc-h2-line-height"],["--doc-h3-font-size","--doc-h3-line-height"],["--doc-h4-font-size","--doc-h4-line-height"],["--doc-card-title-font-size","--doc-card-title-line-height"],["--doc-table-font-size","--doc-table-line-height"]],Ws=["--doc-component-gap","--doc-block-gap","--doc-media-gap","--doc-paragraph-gap","--doc-group-gap","--doc-list-gap"],zt="--doc-content-max-width";function Bs(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 rt=t=>`${Math.round(t)}px`;function ct(t,{size:e="default",spacing:s="default",width:o="default"}={}){let n=r=>{let d=/^(-?[0-9.]+)px$/.exec(t.get(r)??"");if(!d)throw new Error(`src/render/kit/styles/tokens.css: ${r} is no length in px (src/render/look-css.mjs reads it)`);return Number(d[1])},i=Ps[e],{leading:a,gaps:c}=Us[s],l={};if(e!=="default"||s!=="default")for(let[r,d]of Ke){let f=n(r)*i;e!=="default"&&(l[r]=rt(f)),l[d]=rt(Math.round(f)+(n(d)-n(r))*i*a)}if(s!=="default"){for(let r of Ws)l[r]=rt(n(r)*c);l["--doc-space"]=String(c)}if(o!=="default"){if(n(zt)!==Ct.default)throw new Error(`src/render/kit/styles/tokens.css: ${zt} is not \u9ED8\u8BA4 \u6B63\u6587\u5BBD\u5EA6's ${Ct.default}px (src/shared/document-look.mjs WIDTH)`);l[zt]=rt(Ct[o])}return l}var U=(t,e)=>`${t} { ${Object.entries(e).map(([s,o])=>`${s}: ${o};`).join(" ")} }`,_=(t,e)=>`[${Ms[t]}="${e}"]`;function Ge(t){let e=Bs(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${_("font","serif")}`,{"--doc-sans-font":s,"--doc-font":He}),U(`:root${_("font","mixed")}`,{"--doc-heading-font":He})],[,...n]=At.size,[,...i]=At.spacing,[,...a]=At.width;for(let c of n)o.push(U(`:root${_("size",c)}`,ct(e,{size:c})));for(let c of i)o.push(U(`:root${_("spacing",c)}`,ct(e,{spacing:c})));for(let c of a)o.push(U(`:root${_("width",c)}`,ct(e,{width:c})));for(let c of n)for(let l of i){let r=ct(e,{size:c,spacing:l});o.push(U(`:root${_("size",c)}${_("spacing",l)}`,Object.fromEntries(Ke.map(([,d])=>[d,r[d]]))))}return o.join(`
5
+ `)}var Je=Object.fromEntries(K.filter(t=>t.file).map(t=>[t.file,t.build])),tr=Object.keys(Je),Z=t=>W.join(Js,t),Zs=(t,e,s)=>({entryPoints:[Z(t)],bundle:!0,write:!1,format:"iife",platform:"browser",target:"es2022",...typeof e=="function"?e():e,...s}),Ys=t=>{let e=Je[t];if(!e)throw new Error(`src/render/kit-build.mjs: no kit file "${t}"`);return e},lt=new Map;function qs(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,a)=>!o.includes(i)||s.indexOf(i)!==a).map(i=>`${i} is listed but missing, or listed twice`)];if(n.length>0)throw new Error(`src/render/kit/${t}: ${n.join("; ")}`);return s.map(i=>W.join(W.dirname(t),i))}var Xs=t=>t.replace(/@(text|highlight)-colors\b/g,(e,s)=>Hs.map(o=>`.doc-${s}-${o}`).join(", ")),Qs=t=>{let e=Xs(t.join(`
6
+ `)).replaceAll("@fold-dots",Ks).replace(/^@kit-words;$/m,()=>Be());return e.replace(/^@kit-look;$/m,()=>Ge(e))};function It(t,{fresh:e=!1}={}){let s=Ys(t);if(Vs)return V.promises.readFile(W.join(Gs,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(qs(s.styles,o).map(n=>V.promises.readFile(Z(n),"utf8")))).then(Qs);if(e||!lt.has(t)){let o=le(Zs(s.bundle,s.options)).then(n=>n.outputFiles[0].text);o.catch(()=>lt.delete(t)),lt.set(t,o)}return lt.get(t)}import{kitNamespace as tn}from"../browser/shared/old-names.mjs";import{attr as jt,hasClass as ft}from"../browser/shared/html-tree.mjs";var Ve=t=>t.tagName==="section"&&ft(t,"doc-section"),en=new Set(["section","header","footer","nav","script","style","template","dialog","link","meta"]),on=t=>!en.has(t.tagName),dt=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(dt).join("");function Ye(t,e=[]){for(let s of t.childNodes??[])s.tagName&&((s.tagName==="main"&&ft(s,"doc-page")||jt(s,"data-doc-sheet")!==void 0)&&e.push(s),Ye(s.tagName==="template"?s.content:s,e));return e}var sn=/^(p|li|h[1-4]|blockquote|ul|ol)$/,qe=["doc-summary","doc-panel","doc-note","doc-callout"],nn=t=>sn.test(t.tagName)||qe.some(e=>ft(t,e)),an=new Set(["none","auto","100%","inherit","initial","unset","revert"]),Ze=t=>[...t.matchAll(/(?:^|[;{\s])(?:max-)?width\s*:\s*([^;}]+)/gi)].some(([,e])=>!an.has(e.replace(/!important/i,"").trim().toLowerCase())),rn=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])=>!tn(n))||t.includes("#");return s&&!o};function cn(t){let e=[],s=(o,n)=>{for(let i of o.childNodes??[]){if(!i.tagName)continue;let a=n||i.tagName==="main"&&ft(i,"doc-page");if(a&&nn(i)&&Ze(jt(i,"style")??"")&&e.push(`<${i.tagName}> with style="${jt(i,"style").trim()}"`),i.tagName==="style"){let c=dt(i).replace(/\/\*[\s\S]*?\*\//g,"");for(let[,l,r]of c.matchAll(/([^{}]+)\{([^{}]*)\}/g))if(Ze(r))for(let d of l.split(","))rn(d)&&e.push(`"${d.trim()}" in the document's style`)}s(i.tagName==="template"?i.content:i,a)}};return s(t,!1),e}function Xe(t,{written:e=t}={}){let s=[],o=w(t),n=cn(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 Ye(o)){let a=i.childNodes.filter(c=>c.tagName);a.forEach((c,l)=>{if(!Ve(c))return;let r=l+1;for(;r<a.length&&on(a[r]);)r++;let d=a.slice(l+1,r);if(d.length===0||!Ve(a[r]??{})||/^h[1-4]$/.test(d[0].tagName))return;let f=c.childNodes.map(g=>g.tagName?g:null).filter(Boolean).map(dt).find(g=>g.trim())?.replace(/\s+/g," ").trim().slice(0,40)??"",[h]=d,u=dt(h).replace(/\s+/g," ").trim(),m=`<${h.tagName}>${u?` "${u.length>30?`${u.slice(0,30)}\u2026`:u}"`:""}`,p=h.sourceCodeLocation?.startLine;s.push(`${d.length} block${d.length===1?"":"s"} of body text right after the section "${f}" stand outside it${p?` (line ${p})`:""}, ${d.length===1?`the ${m}`:`the first a ${m}`}, between two sections, with no heading of their own: fine if meant, otherwise they belong inside that section`)})}return s.push(...Te(t,{written:e})),s}import{attr as Qe,hasClass as ln}from"../browser/shared/html-tree.mjs";var to="Write instead where it came from, in words, or a path relative to materials/ (materials/data.csv)",dn=new Set(["script","style","template","noscript","textarea","pre","code","kbd","samp","var"]),fn=["doc-math-inline","doc-math-block"],hn=/\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]|\$\$[\s\S]*?\$\$/g,un=/(?<!\\)\$(?:\\[\s\S]|[^\\$])+\$/g,pn=/[\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]/u,mn=/[^\s"'<>|()[\]{};,。;:、!?()《》「」『』“”‘’【】]+/gu,so=/^[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,gn=/\.[A-Za-z0-9]{1,8}$/,$n=[/(?<![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],wn=/(?:^|[\\/])(?:AppData|scratchpad)(?=[\\/]|$)/i,bn=/^(?:[A-Za-z]:|[\\/]|%[A-Za-z]+%)[\s\S]*[\\/](?:temp|tmp)(?=[\\/])/i,kn=t=>t.includes("://")&&!/^file:/i.test(t),eo=12;function oo(t,e){let s=e;for(;s<t.length&&!pn.test(t[s])&&!(so.test(t[s])&&gn.test(t.slice(e,s)));)s++;return t.slice(e,s).replace(/[.,;:!?]+$/,"")}function yn(t,e=!1){let s=c=>c.replace(/[^\n]/g," "),o=t.replace(hn,s),n=e?o.replace(un,s):o,i=[],a=(c,l)=>i.some(r=>r.at<=c+l.length&&c<=r.at+r.path.length);for(let c of $n)for(let l of n.matchAll(c)){let r=oo(n,l.index);r.length>=l[0].length+2&&!a(l.index,r)&&i.push({at:l.index,path:r})}for(let c of n.matchAll(mn)){let l=c.index;for(;l<c.index+c[0].length&&so.test(n[l]);)l++;let r=oo(n,l);/[\\/]/.test(r)&&(wn.test(r)||bn.test(r))&&!kn(r)&&!a(l,r)&&i.push({at:l,path:r})}return i.sort((c,l)=>c.at-l.at)}function no(t,e=w(t)){let s=[],o=(a,c)=>{for(let l of a.childNodes??[])if(l.nodeName==="#text"){if(!l.sourceCodeLocation)continue;for(let{at:r,path:d}of yn(l.value,c))s.push({line:l.sourceCodeLocation.startLine+(l.value.slice(0,r).match(/\n/g)?.length??0),path:d})}else l.tagName&&!dn.has(l.tagName)&&Qe(l,"hidden")===void 0&&!fn.some(r=>ln(l,r))&&o(l,c||Qe(l,"data-doc-math-dollar")!==void 0)};o(e,!1);let n=s.slice(0,eo).map(({line:a,path:c})=>`line ${a}: "${c.length>80?`${c.slice(0,77)}\u2026`:c}" is a path of this machine in the text a reader reads: a reader on another machine cannot open it. ${to}`),i=s.slice(eo);return i.length>0&&n.push(`${i.length} more path${i.length===1?"":"s"} of this machine in the text a reader reads, on line${new Set(i.map(({line:a})=>a)).size===1?"":"s"} ${[...new Set(i.map(({line:a})=>a))].join(", ")}. ${to}`),n}import{elementsOf as io}from"../browser/shared/html-tree.mjs";import{netSnapshot as xn}from"../browser/shared/net-cache.mjs";import{hostIn as Sn,netHostsOf as Nn}from"../browser/shared/net-policy.mjs";var vn=(t,e)=>`<script type="application/json" data-doc-snapshot data-at="${e}">${JSON.stringify(t).replace(/</g,"\\u003c")}</script>`,Rt=t=>t.some(({needs:e})=>Array.isArray(e)&&e.includes("workspace"));function ao(t,{slug:e,packages:s,root:o,at:n=new Date,workspace:i=null}){let a=s.flatMap(({needs:f})=>Nn(f)),c=a.length===0?null:xn(o,e,f=>{try{return Sn(new URL(f).hostname,a)!==null}catch{return!1}}),l={...i&&Rt(s)?i:{},...c?{net:c}:{}};if(Object.keys(l).length===0)return t;let r=io(io(w(t)).find(f=>f.tagName==="html")??{}).find(f=>f.tagName==="head"),d=r?.sourceCodeLocation?.endTag?.startOffset??r?.sourceCodeLocation?.startTag?.endOffset;return d===void 0?t:`${t.slice(0,d)} ${vn(l,n.toISOString())}
7
+ ${t.slice(d)}`}import{MENTION as On,MENTION_ICON as En}from"../browser/shared/components/mention.mjs";import{escapeAttribute as Tn}from"../browser/shared/escape.mjs";import{attr as ro,elementsOf as Ln,hasClass as co,walk as An}from"../browser/shared/html-tree.mjs";import{addressOn as Cn,decoded as zn,fromFile as In,hosted as jn,pageAddress as Rn,workbenchHash as Fn}from"../browser/shared/page-address.mjs";function Dn(t,e,s){let o=In(t,e),n=Cn(o,s);return n||jn(t)?n:Rn(o)??(Fn(o)===null?null:{slug:null,block:null})}function _n(t,e,s,o){let n=w(t),i=new Set,a=[];An(n,r=>{let d=ro(r,"data-block-id");d!==void 0&&i.add(d),r.tagName==="a"&&ro(r,"href")!==void 0&&r.sourceCodeLocation?.startTag&&a.push(r)});let c=new Map,l=({startOffset:r,endOffset:d})=>c.set(r,[d,""]);for(let r of a){let{prefix:d,value:f}=r.attrs.find(({name:k})=>k==="href"),h=f.startsWith("#")?zn(f.slice(1)):null,u=h===null?f&&Dn(f,e,o):i.has(h)?{slug:e,block:h}:null;if(!u)continue;let m=s(u,f);if(m===f)continue;let{attrs:p,startTag:g,endTag:b}=r.sourceCodeLocation;if(m===null)l(g),b&&l(b),co(r,On)&&Ln(r).filter(k=>co(k,En)).forEach(k=>l(k.sourceCodeLocation));else{let k=d?`${d}:href`:"href";c.set(p[k].startOffset,[p[k].endOffset,`${k}="${Tn(m)}"`])}}return[...c].sort(([r],[d])=>d-r).reduce((r,[d,[f,h]])=>`${r.slice(0,d)}${h}${r.slice(f)}`,t)}function lo(t,e,s,{blocks:o=!0,links:n}){return _n(t,e,({slug:i,block:a})=>{let c=s(i);if(c===null)return null;if(!a||!o)return i===e&&a?null:c;let l=`#${encodeURIComponent(a)}`;return i===e?l:`${c}${l}`},n)}import ht from"node:fs";import Mn from"node:path";import{extensionOf as Pn,imageFile as Un,mediaTypeOf as Wn}from"../browser/shared/media.mjs";var _t=1024*1024,Bn=_t,ho=2400,Ft=2e3,Hn=.25,Kn=new Set(["png","gif"]),fo=.75;function Gn(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 Jn(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 Vn=_t;function Zn(t){let e;try{e=ht.openSync(t,"r");let{size:s}=ht.fstatSync(e),o=Buffer.alloc(Math.min(s,Vn));return ht.readSync(e,o,0,o.length,0),{length:s,head:o}}catch{return null}finally{e!==void 0&&ht.closeSync(e)}}var j=t=>`${Math.max(.1,t/_t).toFixed(1)} MB`;function Yn({bytes:t,width:e,height:s,extension:o,lossless:n}){let i=Math.max(e,s),a=Math.min(1,Ft/i),c=Math.min(t,e*s*a*a*Hn);if(i>ho){if(!n)return c<=t*fo?` \u2014 a ${Ft}px copy would be about ${j(c)}`:"";let l=t*a*a;return` \u2014 a ${Ft}px copy would be about ${j(l)}${o==="png"&&c<l/2?`, or ${j(c)} as a JPEG (for a photograph)`:""}`}return!n&&c<=t*fo?` \u2014 written again as a JPEG of quality about 82, it would be about ${j(c)}`: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 uo({html:t,directory:e,tree:s=w(t)}){let{embedded:o,unserved:n}=re({html:t,directory:e,tree:s}),i=new Map,a=(l,r,d,f=!1)=>{let h=i.get(l)??i.set(l,{at:[],shows:0,served:d}).get(l);h.at.push(r),f||(h.shows+=1)};for(let{file:l,line:r,icon:d}of o)Un(l)&&a(l,r,!0,d);for(let{file:l,line:r}of n)Wn(l).startsWith("image/")&&a(l,r,!1);let c=[];for(let[l,{at:r,shows:d,served:f}]of[...i].sort(([,h],[,u])=>Math.min(...h.at)-Math.min(...u.at))){let h=Zn(Mn.join(e,l));if(!h)continue;let{length:u,head:m}=h,p=Jn(m),g=p?Math.max(p.width,p.height):0,b=u>Bn||g>ho,k=f&&d>1;if(!b&&!k)continue;let x=[...new Set(r)],v=`line${x.length===1?"":"s"} ${x.length>1?`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`:x[0]}`,E=k?`shown ${Dt(d)}: the export embeds it ${Dt(d)}; show it once and refer back to it in words`:"";if(!b){c.push(`${l} (${v}): ${E} (${j(Math.ceil(u/3)*4*d)} as data: URLs)`);continue}let H=r.length===1||!f?"":`, ${Dt(r.length)}`,R=f?r.length:1,Y=`${j(Math.ceil(u/3)*4*R)} as ${R===1?"a data: URL":"data: URLs"}`,Po=p?`, ${p.width}\xD7${p.height}px`:"",Bt=Pn(l),Ht=p?Yn({bytes:u,...p,extension:Bt,lossless:Kn.has(Bt)||Gn(m)}):"",Uo=f?`the export embeds it as it is${H}, ${Y}${Ht}`:`its name keeps it out of the preview and the export (the failure at its line says why); copied into assets/ under a name they take, the export embeds it as it is, ${Y}${Ht}: copy it in at the size the page needs`;c.push(`${l} (${v}): ${j(u)}${Po}; ${Uo}${E?`; ${E}`:""}`)}return c}import{COMPONENTS as hi}from"../browser/shared/components/index.mjs";import{withLook as ui}from"../browser/shared/document-look.mjs";import{reportsDirectory as pi}from"../browser/shared/paths.mjs";import{documentLook as mi}from"../browser/shared/workspace-look.mjs";import po from"node:fs";import{MENTION as mo,MENTION_ICON as go}from"../browser/shared/components/mention.mjs";import{escapeAttribute as qn,escapeText as Xn}from"../browser/shared/escape.mjs";import{iconUrl as Qn,validIcon as ti}from"../browser/shared/emoji/icon-value.mjs";import{attr as ei,hasClass as oi,walk as si}from"../browser/shared/html-tree.mjs";import{fromFile as ni,isFileLink as ii,pageAddress as ai}from"../browser/shared/page-address.mjs";import{reportsDirectory as ri}from"../browser/shared/paths.mjs";import{documentDirectory as ci,documentFiles as li}from"../browser/shared/workspace.mjs";function di(t,e){let{html:s,json:o}=li(ci(t,e));if(!po.existsSync(s))return null;try{let{title:n,icon:i}=JSON.parse(po.readFileSync(o,"utf8"));return{title:n,icon:i}}catch{return{}}}function fi(t,e,s,o){if(s==="words"||typeof t!="string"||!ti(t))return null;if(s==="preview")return Qn(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 $o(t,{slug:e,mode:s="export",reportsDirectory:o=ri}){if(!t.includes(mo))return t;let n=new Map,i=c=>(n.has(c)||n.set(c,di(c,o)),n.get(c)),a=new Map;return si(w(t),c=>{let l=c.tagName==="a"&&oi(c,mo)?ei(c,"href"):void 0,{startTag:r,endTag:d}=c.sourceCodeLocation??{};if(!l||!ii(l)||!r||!d)return;let f=ai(ni(l,e))?.slug;if(!f)return;let h=i(f);if(!h)a.set(r.endOffset-1,[r.endOffset-1," data-doc-gone"]);else if(h.title){let u=fi(h.icon,f,s,o);a.set(r.endOffset,[d.startOffset,`${u?`<img class="${go}" src="${qn(u)}" alt="">`:`<span class="${go}"></span>`}${Xn(h.title)}`])}}),[...a].sort(([c],[l])=>l-c).reduce((c,[l,[r,d]])=>`${c.slice(0,l)}${d}${c.slice(r)}`,t)}var gi=/<script\b[^>]*\bdata-doc-kit="runtime"[^>]*><\/script>/;function $i(t,e,s){let o=Gt(e).filter(({id:n})=>!s.some(i=>i.id===n)).map(Jt).join(" ");return o?t.replace(gi,n=>`${n}
8
+ <script data-doc-dev>${o}</script>`):t}var wo=/(<title\b[^>]*>)\s*(<\/title>)/i;function wi(t){if(!wo.test(t))return t;let e=/^en\b/i.test(/<html\b[^>]*\slang=["']?([^"'\s>]*)/i.exec(t)?.[1]??"");return t.replace(wo,(s,o,n)=>`${o}${e?"Untitled":"\u672A\u547D\u540D\u6587\u6863"}${n}`)}function Mt(t,{slug:e,mode:s="export",files:o=!0,reportsDirectory:n,kit:i,catalog:a}){let{html:c,removed:l}=bi(t,{reportsDirectory:n,kit:i,catalog:a,describe:s==="preview"}),r={slug:e,mode:s,...n?{reportsDirectory:n}:{}},d=Xt(ui(c,mi(e,n??pi)),r),f=o?ce(te(oe(ne(d,r),r),r),r):d;return{html:wi($o(f,r)),removed:l}}function bi(t,{reportsDirectory:e,kit:s,page:o=!1,describe:n=!1,catalog:i=T()}){let a=L(t,i),{html:c,removed:l,used:r}=fe(t,[...hi,...a]),d=ke(he(c,{used:r,page:o,...s?{href:s}:{}}),a);return{html:n?$i(d,i,a):d,removed:l,packages:a}}import{exportsDirectory as Ai,kitPublicDirectory as Ci,release as zi,reportsDirectory as A,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 Di,hosted as Lo,pageAddress as _i,workbenchHash as Mi}from"../browser/shared/page-address.mjs";import{pageLinks as Pi}from"../browser/shared/page-links.mjs";import{layoutOf as Ao}from"../browser/shared/workspace.mjs";import{documentLinks as Ui,listReportSlugs as Wi}from"../browser/shared/reports.mjs";import{documentDirectory as B,documentFiles as Wt}from"../browser/shared/workspace.mjs";import{sha256 as ut}from"../browser/shared/files.mjs";import{EXPORT_CSP as Bi,GENERATOR as Hi,isolateUmd as Ki,packagesMeta as Gi,sourceMeta as Ji}from"../browser/shared/export-wrap.mjs";var So=/__REPORT_[A-Z_]+__/,No=1e6,vo=t=>t.length>1?`${t.slice(0,-1).join(", ")} and ${t.at(-1)}`:`${t[0]}`;function Vi(t){return t.map(({id:e,lines:s,columns:o})=>{let n=new Set(s).size<s.length,i=s.map((a,c)=>n?`${a}:${o[c]}`:`${a}`);return`data-block-id repeats: "${e}" on lines ${vo(i)}${n?" (line:column)":""}; each id names one block: remove it from the copy, which needs none (the later ${i.length>2?`ones, lines ${vo(i.slice(1))}`:`one, line ${i[1]}`}, unless the copy went before its original)`})}var Zi=({slug:t,htmlPath:e,metadataPath:s})=>{let o=e?{html:e,json:s??e.replace(/\.html$/,".json")}:Wt(B(t,A));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 a=[],{htmlName:c,jsonName:l}=Zi({slug:t,htmlPath:o,metadataPath:n}),r=/<h1\b[^>]*\bclass="[^"]*\bdoc-title\b[^"]*"[^>]*>\s*<\/h1>/i.test(e),d=[[/<meta\s+name=["']viewport["']/i,"missing viewport metadata"],[r?/<title>\s*<\/title>|<title>[^<]+<\/title>/i:/<title>[^<]+<\/title>/i,"missing document title"],[/<main(?:\s|>)/i,"missing semantic main element"],[/aria-label|aria-labelledby|<title>/i,"missing accessible labels"]];for(let[p,g]of d)p.test(e)||a.push(g);let f=Buffer.byteLength(e);f>No&&a.push(`the document's editable source is ${f.toLocaleString("en-US")} bytes, over the ${No.toLocaleString("en-US")}-byte limit: aggregate or sample the embedded data, or split the document`),So.test(e)&&a.push(`${c} still contains a starter placeholder such as __REPORT_TITLE__`);for(let[p,g]of Object.entries(s))typeof g=="string"&&So.test(g)&&a.push(`${l} "${p}" is still a starter placeholder such as __REPORT_TITLE__`);/<[a-z][^>]*\sdata-doc-placeholder\b/i.test(e)&&a.push("starter placeholder content ([data-doc-placeholder]) is still present; replace it with the document's content");let h=new Map;M(i,p=>{let g=O(p,"data-block-id"),b=p.sourceCodeLocation?.attrs?.["data-block-id"]??p.sourceCodeLocation;g!==void 0&&h.set(g,[...h.get(g)??[],{line:b?.startLine,column:b?.startCol}])});let u=[...h].filter(([,p])=>p.length>1);a.push(...Vi(u.map(([p,g])=>({id:p,lines:g.map(({line:b})=>b),columns:g.map(({column:b})=>b)}))));let m=null;if(M(i,p=>{!m&&p.tagName==="main"&&(m=p)},{inTemplates:!1}),m){let p=O(m,"data-doc-id");p===void 0?a.push(`main.doc-page needs data-doc-id="${t}"`):p!==t&&a.push(`main[data-doc-id] is "${p}": it must be the document's slug "${t}"`)}return a}var Co=t=>yo(yo(t).find(e=>e.tagName==="html")??{}).find(e=>e.tagName==="head")?.sourceCodeLocation?.startTag?.endOffset,Ut=new Set(["localStorage","sessionStorage"]);function zo(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 Io({slug:t,html:e,directory:s=B(t,A),tree:o=w(e),uses:n=X(e,q,{tree:o}),catalog:i}){let a=[];Co(o)===void 0&&a.push("the page writes no <head> start tag, which an export puts its Content-Security-Policy right after: write <head> \u2026 </head> before <body>");let c=[];M(o,d=>{if(["script","link","img"].includes(d.tagName))for(let f of["src","href"]){let h=O(d,f)?.trim();h&&/^https?:\/\//i.test(h)&&c.push(h)}}),c.length>0&&a.push(`external resources are not portable: ${c.join(", ")}`);for(let{name:d,how:f,line:h,where:u}of n){if(!q.has(d))continue;let m={call:`calls ${d}(\u2026)`,new:`creates new ${d}(\u2026)`}[f]??`uses ${d}`;a.push(`line ${h}: ${u} ${m}: embed its data (inline JSON, DocState); the export blocks the network`)}let{scripts:l,styles:r}=zo(o);for(let d of l)ge.has(d)||a.push(`unsupported script dependency ${d}`);for(let d of r)$e.has(d)||a.push(`unsupported stylesheet dependency ${d}`);return a.push(...ie({html:e,directory:s,tree:o}),...se({html:e,directory:s,tree:o}),...ee({html:e,directory:s,tree:o}),...ae({html:e,directory:s,tree:o})),a.push(...ye(L(e,i,o))),[...new Set(a)]}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=X(t,Ut,{tree:e})}){let o=we(t,e),n=[...ue(t,e),...pe(t,e)];for(let[i,a]of qi)i.test(o)&&n.push(`${o.match(i)[0].replace(/\s*\($/,"")} is gone: ${a}`);for(let{name:i,line:a,where:c}of s)Ut.has(i)&&n.push(`line ${a}: ${c} uses ${i}: use DocState instead of direct browser storage`);return[...new Set(n)]}var Qi=(t,e)=>e.childNodes.find(s=>s.tagName||s.nodeName==="#text"&&s.value.trim())===t,ta=t=>ko(t,Si("highlight").match)||t.tagName==="li"&&ko(t.parentNode,`ol.${Ni}`),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 ${xo.length} colors, <div class="doc-icon" data-icon="/icons/airplane_blue.svg"></div> (MingCute's names; Tabler's as /icons/tabler/plane_blue.svg; the colors ${xo.join(", ")}); or a picture of the document's folder, <div class="doc-icon"><img src="assets/logo.png" alt=""></div>`,jo=t=>t.nodeName==="#text"?t.value:(t.childNodes??[]).map(jo).join("");function Oo(t,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:Oo(t,e,"data-icon"),meant:Pt(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 ${Oo(t,o,"src")}>`,meant:Pt(i)==="image"?i:null}}if(o)return{held:"an <svg>"};let n=jo(e).replace(/\s+/g," ").trim();return{held:n?`"${n.slice(0,40)}"`:"nothing"}}function sa({set:t,name:e,color:s}){let o=vi.find(a=>a!==t);if(mt(o).includes(e))return`; "${e}" is ${o==="tabler"?"Tabler":"MingCute"}'s: ${Ei(o,e,s)}`;let n=e.split("-").filter(a=>a.length>=3),i=mt(t).filter(a=>a.split("-").some(c=>n.includes(c))).slice(0,6);return i.length>0?`; names of its set near it: ${i.join(", ")}`:""}function na({html:t,tree:e=w(t)}){let{all:s,own:o}=Qt(e),n=[],i=a=>a.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 a of s){let c=i(a),l=a.parentNode;!o.includes(a)&&!(ta(l)&&Qi(a,l))&&n.push(`line ${c}: an icon (.doc-icon) stands only right before the document's title, first in a highlight block (.doc-panel, .doc-summary), or first in a flowchart's step (ol.doc-flow > li, in its number's place)`);let r=Li(Vt(t,a)),{held:d,meant:f}=r?{}:oa(t,a);f?n.push(`line ${c}: an icon (.doc-icon) holds ${d}, an icon a page reads only in double quotes: write ${Ti(f)}`):r?Pt(r)==="glyph"&&!Yt(r)&&n.push(`line ${c}: the icon ${r} is none of the icon sets' (MingCute: /icons/<name>_<color>.svg, Tabler: /icons/tabler/<name>_<color>.svg; src/shared/emoji/data/icons.json lists the names of each)${sa(Oi(r))}`):n.push(`line ${c}: an icon (.doc-icon) holds no icon (it holds ${d}): ${ea}`)}return[...new Set(n)]}function Ro(t){let e=w(t.html),s={...t,tree:e,uses:X(t.html,new Set([...q,...Ut]),{tree:e})};return[...Yi(s),...Lt(t.html,e),...Xi(s),...na(s),...Io(s)]}function ia(t){let e=new Map(t.map(n=>[n.slug,[...Ro(n),...Nt(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:a,note:c}of be(t)){if(a){o.get(n)?.scriptNotes.push(c);continue}let l=n?[s.get(n)]:[...e.keys()];for(let r of l)e.get(r).push(n?i:`${i} (shared SDK declaration)`)}for(let[n,i]of e)i.length===0&&e.delete(n);return e}async function Rc(t=[],{prepare:e=null}={}){let{reports:s,failures:o}=await pt(t,{prepare:e});for(let n of s){let i=[...Ro(n),...Nt(n.html)];i.length&&o.set(n.slug,i)}return o}async function aa(t=[],{prepare:e=null,directory:s=A}={}){let{reports:o,failures:n}=await pt(t,{prepare:e,directory:s});for(let[i,a]of ia(o))n.set(i,a);return{reports:o,failures:n}}async function ra({fresh:t=!1,kit:e=Ci,vendor:s=Ii}={}){if(zi)return;let o=K.map(a=>[a,a.file?It(a.file,{fresh:t}):wt(a)]);await S.mkdir(e,{recursive:!0});let n=N.join(s,"katex","fonts");await S.mkdir(n,{recursive:!0});let i=(await S.readdir($t)).filter(a=>a.endsWith(".woff2"));await Promise.all(i.map(a=>S.copyFile(N.join($t,a),N.join(n,a)))),await Promise.all(o.map(async([a,c])=>S.writeFile(a.file?N.join(e,a.file):N.join(s,...a.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,e){let s=N.join(e,"reports.json"),o=await S.readFile(s,"utf8").then(JSON.parse,()=>[]),n=new Map(Array.isArray(o)?o.map(a=>[a.slug,a]):[]);for(let{entry:a}of t)n.set(a.slug,a);let i=[];for(let[a,c]of[...n].sort(([l],[r])=>l.localeCompare(r))){let l=N.join(e,`${a}.html`);await S.stat(l).then(()=>!0,()=>!1)&&i.push(c)}await S.writeFile(s,`${JSON.stringify(i,null,2)}
9
+ `)}async function da(t=[],{prepare:e=null,directory:s=A}={}){let o=Ao(s).built,{reports:n,failures:i}=await aa(t,{prepare:e,directory:s});await ra(),await S.mkdir(o,{recursive:!0}),await ca(o,new Set(await Wi(s)));let a=[];for(let c of n){let l=`${c.slug}.html`,r=N.join(o,l);if(i.has(c.slug)){await S.rm(r,{force:!0});continue}let{html:d,removed:f}=Mt(c.html,{slug:c.slug,reportsDirectory:s});await S.writeFile(r,d),a.push({report:c,html:d,removed:f,entry:{slug:c.slug,...c.metadata,preview:`/generated/${l}`,sourceSha256:ut(c.html),outputSha256:ut(d)}})}return await la(a,o),{built:a,failures:i}}var fa=t=>t.replace(/<\/script/gi,"<\\/script");async function Fo(){return new Map(await Promise.all(K.map(async t=>{let e=await(t.file?It(t.file):wt(t,{inline:!0}));return de(t).endsWith(".css")||(e=fa(e)),[t.id,t.umd?Ki(e):e]})))}function ha(t,e,s=null,o=[]){let n=Co(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=T(),i=A,a=null){let c=L(e,n);e=ao(ha(t,e,o,c),{slug:t,packages:c,root:i,workspace:a}),e=me(xe(e,n),({id:d,element:f,attribute:h})=>{let u=s.get(d);if(typeof u!="string")throw new Error(`${t}: no inline source for the asset "${d}" (loadInlineSources in src/render/pipeline.mjs)`);return`<${f} ${h}="${d}-inline">${u}</${f}>`});let{scripts:l,styles:r}=zo(w(e));if(l.length+r.length>0)throw new Error(`${t}: export still contains a linked script or stylesheet`);return e}async function Eo(t,e=A,{components:s=!0,catalog:o=T()}={}){let n=B(t,e),i=await S.readFile(Wt(n).html),a=i.toString("utf8"),c=w(a);s||(o={packages:new Map});let l=[...s?Lt(a,c,o):[],...Io({slug:t,html:a,directory:n,tree:c,catalog:o})];if(l.length>0){let r=L(a,o,c).find(({id:d})=>l[0].startsWith(`${d}:`)||l[0].startsWith(`${d} (`))?.id;throw Object.assign(new Error(`${t}: ${l[0]}`),{reason:"check",slug:t,failures:l,...r?{component:r}:{}})}return{html:a,sha256:ut(i)}}async function Fc({directory:t=A,workspace:e=null,catalog:s=T()}={}){let o=await Fo(),n=async(i,{files:a=!0}={})=>{let c=await Eo(i,t,{catalog:s}),l=Mt(c.html,{slug:i,files:a,reportsDirectory:t,catalog:s}).html;return Do(i,l,o,c.sha256,s,t,await _o(e,i,l,s))};return n.check=async i=>{await Eo(i,t,{components:!1})},n}async function _o(t,e,s,o){return typeof t!="function"||!Rt(L(s,o))?null:await t(e).catch(()=>null)??null}async function Dc(t=[],{prepare:e=null,workspace:s=null,directory:o=A}={}){let n=Ao(o).exports,i=T(),{built:a,failures:c}=await da(t,{prepare:e,directory:o}),l=await Fo();await S.mkdir(n,{recursive:!0});let r=new Set(a.map(({report:h})=>h.slug)),{links:d}=await Ui(o),f=[];for(let{report:h,html:u}of a)try{let m=lo(u,h.slug,g=>r.has(g)?`${g}.html`:null,{links:d}),p=Do(h.slug,m,l,h.fileSha256,i,o,await _o(s,h.slug,m,i));await S.writeFile(N.join(n,`${h.slug}.html`),p),f.push({slug:h.slug,bytes:Buffer.byteLength(p),sha256:ut(p)})}catch(m){c.set(h.slug,[m.message])}return{built:a,exported:f,failures:c}}function To(t){let 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(Lo(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=To(e),i=s===B(N.basename(s),A)?A:N.dirname(s),a=new Map([[t,n]]),c=d=>{if(!a.has(d)){let f=Wt(B(d,i));a.set(d,bo(f.html)?To(w(ki(f.html,"utf8"))):null)}return a.get(d)},l=null,r=(d,f)=>f===null?_i(d):Di(f,l??=Pi((bo(i)?yi(i):[]).map(h=>({slug:h}))));return M(e,d=>{let f=d.tagName==="a"?O(d,"href"):void 0;if(!f||f==="#"||f==="#top")return;let h=d.sourceCodeLocation?.startLine;if(f.startsWith("#")){n.has(Ri(f.slice(1)))||o.push(`the link to ${f} (line ${h}) names no block or element of this document`);return}let u=Fi(f,t),m=Mi(u),p=r(u,m);(p?!c(p.slug):m!==null)?Lo(f)||o.push(`the link to ${f} (line ${h}) names a document that is not there: gallery list has the slugs`):p?.block&&!c(p.slug).has(p.block)?o.push(`the link to ${f} (line ${h}) names a block document ${p.slug} does not hold`):u&&!p&&ua(f,u,t)&&o.push(`the link to ${f} (line ${h}) leads to no document: a link to one is ../<slug>/doc.html, gallery list has the slugs`)},xi),o}function Mo({slug:t,html:e,directory:s=B(t,A),written:o=e,scriptNotes:n=[]}){let i=w(e),a=Ae(e);return{fix:[...no(e,i),...uo({html:e,directory:s,tree:i})],notes:[...Xe(e,{written:o}),...Ue(i),...pa({slug:t,tree:i,directory:s}),...a.notes,...n],readings:a.readings}}function _c(t){let{fix:e,notes:s}=Mo(t);return[...e,...s]}function Mc(t){let e=t.map(s=>[s.slug,Mo(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(Ai,`${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 Pc(t,{exportNote:e=!1,allow:s}={}){await ma(t,{exportNote:e}),ga(t,{allow:s})}export{Es as a,_n as b,lo as c,$o as d,Mt as e,bi as f,Vi as g,Io as h,Ro as i,ia as j,Rc as k,aa as l,ra as m,da as n,ha as o,Fc as p,Dc as q,Mo as r,_c as s,Mc as t,ma as u,ga as v,Pc as w};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{$ as ha,A as I,B as J,C as K,D as L,E as M,F as N,G as O,H as P,I as Q,J as R,K as S,L as T,M as U,N as V,O as W,P as X,Q as Y,R as Z,S as _,T as $,U as aa,V as ba,W as ca,X as da,Y as ea,Z as fa,_ as ga,a as i,aa as ia,b as j,ba as ja,c as k,ca as ka,d as l,e as m,f as n,g as o,h as p,i as q,j as r,k as s,l as t,m as u,n as v,o as w,p as x,q as y,r as z,s as A,t as B,u as C,v as D,w as E,x as F,y as G,z as H}from"./chunk-HPOI4ZX7.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-EAIFITAV.mjs";import"./chunk-67N2QJYT.mjs";import"./chunk-PUOQ65NC.mjs";import{a,b,c,f as d,g as e,h as f,k as g,l as h}from"./chunk-DJISHPUL.mjs";import"./chunk-ZWWC4KLF.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-4OZWXZE5.mjs";import"./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";export{_ as ADVICE,t as BLOCK_PICTURES,$ as CODE_SIDEWAYS,X as HAND_OVER,u as INK_MARGIN,i as KINDS,j as LEVELS,k as LOOKS,Y as LOOK_YOURSELF,W as MORE_PICTURES,M as MOSTLY_CHANGED,y as MOVED_PART,x as MOVED_WHOLE,w as NEIGHBOUR_EDGE,p as PICTURED_INFO,ca as SCROLLS,v as SCROLL_FRAMES,s as SCROLL_SLACK,ba as WARNED,l as WIDE,m as WIDTHS,f as adoptIdless,aa as adviceOf,e as baselineOf,L as baselineSaid,b as blocksOf,N as blocksToPicture,da as describeLooks,S as disclosuresSaid,g as exportBaselines,G as exportOf,ga as exportingFirst,Q as findingKey,q as findingLevel,O as inkOf,P as inventory,n as layoutNotesOf,o as levelOf,R as lookAt,J as missedWidths,V as morePictures,H as movedBlocks,z as movedClips,ha as namedBlocks,I as nextBaseline,ea as notPicturedLine,c as pageOf,r as picturedAt,T as picturesSaid,D as placeOf,h as previewBaseline,a as rankOf,d as readBaseline,ka as run,K as seenOf,C as sourceIndex,F as staleExport,Z as startFailure,E as timeOf,ia as unknownBlocks,ja as unknownBlocksSaid,U as unopenedSaid,A as urlName,fa as verdictOf,B as wordsOf};
2
+ import{$ as ha,A as I,B as J,C as K,D as L,E as M,F as N,G as O,H as P,I as Q,J as R,K as S,L as T,M as U,N as V,O as W,P as X,Q as Y,R as Z,S as _,T as $,U as aa,V as ba,W as ca,X as da,Y as ea,Z as fa,_ as ga,a as i,aa as ia,b as j,ba as ja,c as k,ca as ka,d as l,e as m,f as n,g as o,h as p,i as q,j as r,k as s,l as t,m as u,n as v,o as w,p as x,q as y,r as z,s as A,t as B,u as C,v as D,w as E,x as F,y as G,z as H}from"./chunk-MKIBJTJZ.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-2KAVXMKG.mjs";import"./chunk-XZCFPKGO.mjs";import"./chunk-PUOQ65NC.mjs";import{a,b,c,f as d,g as e,h as f,k as g,l as h}from"./chunk-6Q7ASAXJ.mjs";import"./chunk-S3SX3COT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-6NLXUKAY.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-USIHBCSW.mjs";import"./chunk-3SKOU6OZ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-PLB7L22J.mjs";import"./chunk-PAREWQGB.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{_ as ADVICE,t as BLOCK_PICTURES,$ as CODE_SIDEWAYS,X as HAND_OVER,u as INK_MARGIN,i as KINDS,j as LEVELS,k as LOOKS,Y as LOOK_YOURSELF,W as MORE_PICTURES,M as MOSTLY_CHANGED,y as MOVED_PART,x as MOVED_WHOLE,w as NEIGHBOUR_EDGE,p as PICTURED_INFO,ca as SCROLLS,v as SCROLL_FRAMES,s as SCROLL_SLACK,ba as WARNED,l as WIDE,m as WIDTHS,f as adoptIdless,aa as adviceOf,e as baselineOf,L as baselineSaid,b as blocksOf,N as blocksToPicture,da as describeLooks,S as disclosuresSaid,g as exportBaselines,G as exportOf,ga as exportingFirst,Q as findingKey,q as findingLevel,O as inkOf,P as inventory,n as layoutNotesOf,o as levelOf,R as lookAt,J as missedWidths,V as morePictures,H as movedBlocks,z as movedClips,ha as namedBlocks,I as nextBaseline,ea as notPicturedLine,c as pageOf,r as picturedAt,T as picturesSaid,D as placeOf,h as previewBaseline,a as rankOf,d as readBaseline,ka as run,K as seenOf,C as sourceIndex,F as staleExport,Z as startFailure,E as timeOf,ia as unknownBlocks,ja as unknownBlocksSaid,U as unopenedSaid,A as urlName,fa as verdictOf,B as wordsOf};