@heycys/gallery 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/README.md +1 -1
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/assets/preview/runtime.js +156 -0
  4. package/assets/preview/shell.html +107 -0
  5. package/assets/writing-preferences.md +1 -1
  6. package/browser/editor/components/divider/index.mjs +1 -1
  7. package/browser/editor/page/annotate/card.mjs +6 -0
  8. package/browser/editor/page/annotate/index.mjs +22 -2
  9. package/browser/editor/page/columns/index.mjs +1 -1
  10. package/browser/editor/page/conflicts.mjs +1 -1
  11. package/browser/editor/page/drag/index.mjs +1 -1
  12. package/browser/editor/page/editor.mjs +39 -3
  13. package/browser/editor/page/focus.mjs +104 -0
  14. package/browser/editor/page/handle/index.mjs +14 -2
  15. package/browser/editor/page/links/index.mjs +2 -2
  16. package/browser/editor/page/quiet.mjs +3 -3
  17. package/browser/editor/page/resize/index.mjs +1 -1
  18. package/browser/editor/page/session.mjs +4 -1
  19. package/browser/editor/page/ui.mjs +1 -1
  20. package/browser/shared/annotations.mjs +22 -3
  21. package/browser/shared/block-packs.mjs +13 -4
  22. package/browser/shared/document-look.mjs +14 -0
  23. package/browser/shared/drafts.mjs +1 -1
  24. package/browser/shared/extension-manifest.mjs +40 -12
  25. package/browser/shared/favorite-merge.mjs +17 -0
  26. package/browser/shared/favorites.mjs +77 -0
  27. package/browser/shared/i18n/en.mjs +123 -24
  28. package/browser/shared/outline-ops.mjs +109 -0
  29. package/browser/shared/outline.mjs +6 -0
  30. package/browser/shared/pages.mjs +20 -8
  31. package/browser/shared/paths.mjs +5 -2
  32. package/browser/shared/preference-documents.mjs +137 -0
  33. package/browser/shared/presence.mjs +94 -0
  34. package/browser/shared/preview-server.mjs +8 -5
  35. package/browser/shared/qa-levels.mjs +9 -1
  36. package/browser/shared/session.mjs +4 -0
  37. package/browser/shared/shipped-blocks.mjs +22 -4
  38. package/browser/shared/startup.mjs +101 -0
  39. package/browser/shared/workspace-columns.mjs +1 -1
  40. package/browser/shared/workspace-look.mjs +21 -8
  41. package/browser/shared/workspace-registry.mjs +6 -3
  42. package/browser/shared/workspace.mjs +37 -10
  43. package/browser/shared/writing-preferences.mjs +2 -42
  44. package/dist/chunk-25LYSMAE.mjs +2 -0
  45. package/dist/chunk-2I6ZVC5O.mjs +2 -0
  46. package/dist/{chunk-M4NRDYI5.mjs → chunk-2MYTOOP6.mjs} +1 -1
  47. package/dist/chunk-2VNENLER.mjs +2 -0
  48. package/dist/chunk-3FERXZF5.mjs +4 -0
  49. package/dist/chunk-3M6SBBGU.mjs +2 -0
  50. package/dist/chunk-3VCAAF34.mjs +2 -0
  51. package/dist/{chunk-WD4U6XXT.mjs → chunk-3ZTRLGSA.mjs} +1 -1
  52. package/dist/chunk-4FRA5AUE.mjs +2 -0
  53. package/dist/chunk-4LR2QEC2.mjs +4 -0
  54. package/dist/chunk-56SVJENP.mjs +966 -0
  55. package/dist/chunk-5CQISL2G.mjs +4 -0
  56. package/dist/{chunk-RRKJMHNX.mjs → chunk-5I5ZDDWC.mjs} +5 -5
  57. package/dist/chunk-5IHDLEB4.mjs +10 -0
  58. package/dist/chunk-5LRDMV7O.mjs +2 -0
  59. package/dist/chunk-5MVUYRKG.mjs +5 -0
  60. package/dist/chunk-5TLLIZT7.mjs +2 -0
  61. package/dist/chunk-6ILJWFYW.mjs +4 -0
  62. package/dist/chunk-6N25CJ6Y.mjs +3 -0
  63. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-7DTINW6U.mjs} +2 -2
  64. package/dist/chunk-7KWAGKIK.mjs +2 -0
  65. package/dist/chunk-7WNUOAFK.mjs +2 -0
  66. package/dist/chunk-7XCRW5RC.mjs +2 -0
  67. package/dist/{chunk-BYNPEUDS.mjs → chunk-7XSDTILF.mjs} +1 -1
  68. package/dist/chunk-ABKYFOVR.mjs +2 -0
  69. package/dist/chunk-AMUF7PUN.mjs +2 -0
  70. package/dist/{chunk-FJLM7YE7.mjs → chunk-B2EIMERT.mjs} +2 -2
  71. package/dist/{chunk-QNECWMGR.mjs → chunk-B45IAAU6.mjs} +1 -1
  72. package/dist/chunk-B6RAGF4R.mjs +2 -0
  73. package/dist/chunk-BSJKFE7I.mjs +4 -0
  74. package/dist/chunk-C72EEVLK.mjs +2 -0
  75. package/dist/chunk-CRAUKZ23.mjs +4 -0
  76. package/dist/chunk-F4CT35KL.mjs +2 -0
  77. package/dist/chunk-F63BNJLG.mjs +2 -0
  78. package/dist/chunk-FBKUPS44.mjs +2 -0
  79. package/dist/chunk-FL52ZL5Z.mjs +15 -0
  80. package/dist/chunk-FOZCU4VW.mjs +2 -0
  81. package/dist/chunk-G5HV7BC3.mjs +2 -0
  82. package/dist/{chunk-ERLAIBOA.mjs → chunk-GB5SOYQJ.mjs} +2 -2
  83. package/dist/chunk-GN3SG3IF.mjs +2 -0
  84. package/dist/{chunk-6QWQXHAV.mjs → chunk-HFTBVEZK.mjs} +1 -1
  85. package/dist/chunk-IOW5HLRK.mjs +2 -0
  86. package/dist/chunk-IQ3GJNTI.mjs +6 -0
  87. package/dist/chunk-K6SPFBUJ.mjs +2 -0
  88. package/dist/chunk-K7Y7SPTS.mjs +2 -0
  89. package/dist/chunk-L2IJCEUH.mjs +2 -0
  90. package/dist/{chunk-GPIWQ4X4.mjs → chunk-L3VT6LM4.mjs} +1 -1
  91. package/dist/chunk-L4WLQYFC.mjs +5 -0
  92. package/dist/{chunk-NLDF35P5.mjs → chunk-LAMCAGK6.mjs} +1 -1
  93. package/dist/chunk-LHGKPMTI.mjs +2 -0
  94. package/dist/chunk-LJZIYVNA.mjs +3 -0
  95. package/dist/chunk-LSVCTLS2.mjs +2 -0
  96. package/dist/chunk-LZY74XTP.mjs +2 -0
  97. package/dist/chunk-MC4LRSVH.mjs +2 -0
  98. package/dist/chunk-MCEXN4G5.mjs +2 -0
  99. package/dist/chunk-MTLAOCFF.mjs +181 -0
  100. package/dist/chunk-MZ66LN3B.mjs +2 -0
  101. package/dist/chunk-N5QWJRRI.mjs +2 -0
  102. package/dist/chunk-NF4MMOUB.mjs +2 -0
  103. package/dist/chunk-NHJYAJ73.mjs +3 -0
  104. package/dist/chunk-NRSD7SVY.mjs +2 -0
  105. package/dist/chunk-NT23I4XW.mjs +2 -0
  106. package/dist/chunk-NUALABIS.mjs +3 -0
  107. package/dist/chunk-NW6LAU22.mjs +2 -0
  108. package/dist/chunk-NWWHDGKF.mjs +5 -0
  109. package/dist/chunk-OFRCVMSJ.mjs +2 -0
  110. package/dist/chunk-OKVQQ3CX.mjs +4 -0
  111. package/dist/chunk-OM24O4KR.mjs +8 -0
  112. package/dist/{chunk-4B2TB5K2.mjs → chunk-PBMOC7KA.mjs} +2 -2
  113. package/dist/chunk-PVTCP43W.mjs +2 -0
  114. package/dist/chunk-Q62HZAJS.mjs +2 -0
  115. package/dist/chunk-QBJWIR3Q.mjs +2 -0
  116. package/dist/chunk-QDSEZX7Z.mjs +6 -0
  117. package/dist/chunk-QR4V4A2Z.mjs +15 -0
  118. package/dist/{chunk-QVGOPHOF.mjs → chunk-QRLVVZ3R.mjs} +1 -1
  119. package/dist/chunk-QW3QG67J.mjs +2 -0
  120. package/dist/chunk-R2T2EVWY.mjs +8 -0
  121. package/dist/{chunk-JJNHKGTD.mjs → chunk-R5RERE6G.mjs} +1 -1
  122. package/dist/chunk-RFHEWT3Y.mjs +5 -0
  123. package/dist/chunk-RS2Z2JQP.mjs +2 -0
  124. package/dist/chunk-S6YEC4GE.mjs +16 -0
  125. package/dist/chunk-SHZLMGGW.mjs +2 -0
  126. package/dist/chunk-TALJQM2O.mjs +2 -0
  127. package/dist/chunk-TLNJWEFY.mjs +22 -0
  128. package/dist/{chunk-ZLS2FRS6.mjs → chunk-TQZU7D7C.mjs} +1 -1
  129. package/dist/chunk-UTKNWYBA.mjs +2 -0
  130. package/dist/chunk-V3TM3TEN.mjs +2 -0
  131. package/dist/chunk-V3XROSP5.mjs +7 -0
  132. package/dist/{chunk-6QBHU4DF.mjs → chunk-V5JTW2LH.mjs} +1 -1
  133. package/dist/chunk-VAXLSISW.mjs +4 -0
  134. package/dist/chunk-VBHI3RG6.mjs +2 -0
  135. package/dist/{chunk-CRDG6EF2.mjs → chunk-VKZJRGDR.mjs} +1 -1
  136. package/dist/chunk-VZXZM7NS.mjs +2 -0
  137. package/dist/chunk-WDS6HEPE.mjs +2 -0
  138. package/dist/chunk-WHGANNEY.mjs +13 -0
  139. package/dist/chunk-WMJWC4QY.mjs +56 -0
  140. package/dist/{chunk-UTMAY3WK.mjs → chunk-WWONJJQS.mjs} +1 -1
  141. package/dist/chunk-X4WNLFIK.mjs +2 -0
  142. package/dist/chunk-XNNCQROX.mjs +11 -0
  143. package/dist/chunk-XRYECF23.mjs +170 -0
  144. package/dist/{chunk-225ALKYI.mjs → chunk-Z4NEXXFK.mjs} +1 -1
  145. package/dist/{chunk-PKVK6WFC.mjs → chunk-ZFVF2YPV.mjs} +2 -2
  146. package/dist/chunk-ZM2IX3R2.mjs +2 -0
  147. package/dist/chunk-ZNGGDUZI.mjs +2 -0
  148. package/dist/chunk-ZOEJQOKT.mjs +2 -0
  149. package/dist/cli.mjs +1 -1
  150. package/dist/server.mjs +1 -1
  151. package/dist/update-fetch.mjs +1 -1
  152. package/dist/worker.mjs +1 -1
  153. package/package.json +1 -1
  154. package/release.json +3 -3
  155. package/skill/SKILL.md +54 -148
  156. package/skill/references/building-blocks.md +4 -4
  157. package/skill/references/charts-and-figures.md +73 -0
  158. package/skill/references/extensions.md +47 -4
  159. package/skill/references/pages-and-data.md +22 -3
  160. package/skill/references/preference-files.md +7 -0
  161. package/skill/references/previews.md +17 -0
  162. package/skill/references/writing-html.md +21 -82
  163. package/web/assets/index-B4uUluLM.js +15 -0
  164. package/web/assets/index-C3vHT8sH.css +1 -0
  165. package/web/index.html +2 -2
  166. package/dist/chunk-2HS7ZBPU.mjs +0 -2
  167. package/dist/chunk-3F57LEN5.mjs +0 -2
  168. package/dist/chunk-4OZWXZE5.mjs +0 -5
  169. package/dist/chunk-5GK7HS62.mjs +0 -2
  170. package/dist/chunk-6GV3CBB2.mjs +0 -2
  171. package/dist/chunk-6NLXUKAY.mjs +0 -4
  172. package/dist/chunk-6XD6U3QA.mjs +0 -5
  173. package/dist/chunk-6Y3HYOBM.mjs +0 -2
  174. package/dist/chunk-7EFHNQ5B.mjs +0 -3
  175. package/dist/chunk-7M2BQQGZ.mjs +0 -2
  176. package/dist/chunk-7UZUQQ7Q.mjs +0 -554
  177. package/dist/chunk-ALZ6ZENZ.mjs +0 -3
  178. package/dist/chunk-BX5AKINW.mjs +0 -15
  179. package/dist/chunk-DR73Y2UJ.mjs +0 -3
  180. package/dist/chunk-EURLTOTZ.mjs +0 -4
  181. package/dist/chunk-F4ZA6JRZ.mjs +0 -3
  182. package/dist/chunk-FNCCVGKX.mjs +0 -2
  183. package/dist/chunk-FOJ3K5Z3.mjs +0 -6
  184. package/dist/chunk-FQ72LZHB.mjs +0 -2
  185. package/dist/chunk-G7N7YFVD.mjs +0 -2
  186. package/dist/chunk-GIRXJBGC.mjs +0 -2
  187. package/dist/chunk-GKOBB6DH.mjs +0 -2
  188. package/dist/chunk-GMJD7ID3.mjs +0 -2
  189. package/dist/chunk-GQJMVSSN.mjs +0 -2
  190. package/dist/chunk-HX4DLE3J.mjs +0 -10
  191. package/dist/chunk-IS7N3N6Q.mjs +0 -168
  192. package/dist/chunk-JEUK3ZO7.mjs +0 -2
  193. package/dist/chunk-JPG2LBQM.mjs +0 -11
  194. package/dist/chunk-JYK5WJPM.mjs +0 -2
  195. package/dist/chunk-KLQP46Y3.mjs +0 -4
  196. package/dist/chunk-L55NOXBE.mjs +0 -4
  197. package/dist/chunk-LCB6MARS.mjs +0 -5
  198. package/dist/chunk-LJLVCU6W.mjs +0 -16
  199. package/dist/chunk-LMUZQK5O.mjs +0 -2
  200. package/dist/chunk-NMF3IPYA.mjs +0 -13
  201. package/dist/chunk-ONKC4BCC.mjs +0 -2
  202. package/dist/chunk-OU6ZZVBX.mjs +0 -5
  203. package/dist/chunk-PUOQ65NC.mjs +0 -2
  204. package/dist/chunk-QJAVCTY7.mjs +0 -2
  205. package/dist/chunk-QP7BOHE4.mjs +0 -2
  206. package/dist/chunk-S3SX3COT.mjs +0 -20
  207. package/dist/chunk-SQ3FQCCN.mjs +0 -8
  208. package/dist/chunk-T4Y2ZSVX.mjs +0 -4
  209. package/dist/chunk-TANZRINB.mjs +0 -2
  210. package/dist/chunk-UGWMMEJ5.mjs +0 -15
  211. package/dist/chunk-UTF7GBQU.mjs +0 -4
  212. package/dist/chunk-V4ZHRALW.mjs +0 -170
  213. package/dist/chunk-XBNFXWAW.mjs +0 -6
  214. package/dist/chunk-XZV72SQ4.mjs +0 -2
  215. package/dist/chunk-YFJB534W.mjs +0 -2
  216. package/dist/chunk-Z6OKLRHC.mjs +0 -2
  217. package/dist/chunk-ZMHUDYLV.mjs +0 -2
  218. package/web/assets/index-D8P8uhDW.js +0 -15
  219. package/web/assets/index-FLb9jCfl.css +0 -1
  220. /package/dist/{chunk-PAREWQGB.mjs → chunk-NOGQX56R.mjs} +0 -0
@@ -0,0 +1,5 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as _}from"./chunk-ZFVF2YPV.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-WHGANNEY.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-S6YEC4GE.mjs";import{N as Ae}from"./chunk-V3XROSP5.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-OKVQQ3CX.mjs";import{d as Ce,h as je}from"./chunk-NW6LAU22.mjs";import"./chunk-X4WNLFIK.mjs";import"./chunk-XRYECF23.mjs";import{a as W}from"./chunk-5TLLIZT7.mjs";import{r as ie}from"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import"./chunk-2MYTOOP6.mjs";import{b as re,d as le,g as de,h as K,i as ce}from"./chunk-LHGKPMTI.mjs";import"./chunk-HFTBVEZK.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-TQZU7D7C.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import{j as ne}from"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-56SVJENP.mjs";import{a as H,b as j,c as P,e as D,g as oe}from"./chunk-PBMOC7KA.mjs";import{a as te,e as B,f as ae}from"./chunk-BSJKFE7I.mjs";import{b as se}from"./chunk-L4WLQYFC.mjs";import"./chunk-NOGQX56R.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
+ `)[0]}`,null,`the console says ${p.text().split(`
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-K7Y7SPTS.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,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b}from"./chunk-VZXZM7NS.mjs";import"./chunk-OKVQQ3CX.mjs";import"./chunk-X4WNLFIK.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-L4WLQYFC.mjs";import"./chunk-NOGQX56R.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{a as noDocuments,b as run};
@@ -0,0 +1,16 @@
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 pe}from"./chunk-5TLLIZT7.mjs";import{b as Oe,d as Ae,e as et,f as tt,i as Le,l as nt}from"./chunk-LHGKPMTI.mjs";import{p as Ne}from"./chunk-QR4V4A2Z.mjs";import{i as Ze}from"./chunk-6ILJWFYW.mjs";import{b as Te}from"./chunk-VRPVVMRB.mjs";import{a as he}from"./chunk-HYMEEXKN.mjs";import{a as je,f as de,p as Xe}from"./chunk-TKWEX4FD.mjs";import T from"node:fs/promises";import we from"node:os";import x from"node:path";import{pathToFileURL as Me}from"node:url";import{instancesOf as ct,isInstance as St}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as jt,FALLBACK as Tt,INSTANCE as fe,SLOT as Nt,SLOT_PART as at}from"../browser/shared/components/installed.mjs";import{jsonIn as Ot}from"../browser/shared/json-layout.mjs";import{QUERY_ROUTE as At}from"../browser/shared/workspace-query.mjs";import{workspaceKey as st}from"../browser/shared/workspace-registry.mjs";import{documentDirectory as Lt,documentFiles as Rt,layoutOf as dt,listDocumentSlugs as Dt,PACKAGE_MANIFEST as Mt}from"../browser/shared/workspace.mjs";var Pt="in a browser, under the export's policy",ue=(e=null)=>e?`the instances in ${e}, in a browser under the export's policy`:"the workspace's documents",G="component-check",ae=[360,736,1024],Re=["light","dark"],Ct=[1024,360],ot=1e4,ht=6e4,se=3e4,Fn=12e4,pt=2e3,_t=3e3,It=60,Bn=15e3,Ft=2,Bt=8,Ht=se/2,Wt=/^(?:wasm-)?eval$/,qt=new Set(["TargetCloseError","ConnectionClosedError"]),Hn=e=>e.evaluateOnNewDocument(Gt,At);function Gt(e){let t=globalThis.fetch;if(typeof t!="function"||globalThis.__galleryQueries)return;let o={pending:new Map,count:0};globalThis.__galleryQueries=o,globalThis.fetch=function(r,n){let s=t.apply(this,arguments);try{let p=new URL(typeof r=="string"?r:r?.url??String(r),location.href);if(p.pathname===e){let u=++o.count,f=/\/__gallery\/components\/([a-z0-9-]+\/[a-z0-9-]+)\/kit\.js/.exec(new Error().stack??"");o.pending.set(u,{kind:p.searchParams.get("kind"),block:f?f[1]:null,at:Date.now()});let d=()=>{o.pending.delete(u)};Promise.resolve(s).then(d,d)}}catch{}return s}}var oe=e=>String(e?.message??e).split(`
3
+ `)[0],ut=(e,t)=>`<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${e}</title></head><body><main class="doc-page" data-doc-id="${e}">${t}
4
+ </main></body></html>
5
+ `,Ut=({example:e,template:t})=>`<p>example.html</p>${e}
6
+ <hr><p>template.html</p>${t}`,Jt=e=>{for(let t=e.parentNode;t;t=t.parentNode)if(St(t))return!0;return!1},ft=(e,t)=>ct(e,t).filter(o=>!Jt(o)),Pe=(e,t)=>ft(he(e),t).map(({sourceCodeLocation:{startLine:o,startOffset:r,endOffset:n}})=>({line:o,markup:e.slice(r,n)}));async function wt(e,t){let o=x.join(t,"components",...e.id.split("/"));for(let r of[Mt,"template.html",...e.files]){let n=Xe(e,r);if(!n)continue;let s=await T.readFile(n);await T.mkdir(x.dirname(x.join(o,r)),{recursive:!0}),await T.writeFile(x.join(o,r),r==="kit.js"?`${s}
7
+ //# sourceURL=kit.js
8
+ `:s)}}async function Kt(e,{example:t,template:o},r){await wt(e,r);let n=x.join(r,G);await T.mkdir(n);let s=`${t}
9
+ `,p=Te(ut(G,Ut({example:t,template:o}))).text;await T.writeFile(x.join(n,"doc.html"),p),await T.writeFile(x.join(n,"doc.json"),JSON.stringify({title:G,description:G,type:"component"}));let f=await(await Ne({directory:r,catalog:de(r)}))(G),d=x.join(r,"export.html");await T.writeFile(d,f);let g=s.split(`
10
+ `).length-1,c=Pe(p,e).map(({line:i})=>i>g?{file:"template.html",line:i-g}:{file:"example.html",line:i});return{html:f,file:d,places:c,source:p}}function Vt({match:e,instance:t,slot:o,parts:r,boards:n}){if(!Object.entries(r).some(([d,{edit:g}])=>g==="data"&&!n.includes(d)))return[];let s=[...document.querySelectorAll(e)].filter(d=>!d.parentElement.closest(t)),p=d=>d.parentElement?.closest(`${t}, ${o}`)??null,u=d=>`<${d.localName}${d.classList.length?` class="${d.getAttribute("class")}"`:""}>`,f=d=>{let g=(d.textContent||d.getAttribute("aria-label")||d.getAttribute("placeholder")||d.getAttribute("title")||"").replace(/\s+/g," ").trim().slice(0,24);return`${u(d)}${g?` "${g}"`:""}`};return s.flatMap((d,g)=>{let c=[...d.querySelectorAll("button, input, select, textarea")].filter(i=>p(i)===d).filter(i=>{if(i.disabled||i.readOnly||i.type==="hidden")return!1;let w=i.getBoundingClientRect(),k=getComputedStyle(i);return w.width>0&&w.height>0&&k.visibility!=="hidden"&&k.display!=="none"});return c.length?[{at:g,what:c.slice(0,3).map(f).join(", "),counts:[c.length]}]:[]})}async function Yt({match:e,instance:t,slotPart:o,slotName:r,fallback:n,parts:s,boards:p,at:u,source:f,still:d,step:g,times:c,typed:i,typing:w}){let k=()=>[...document.querySelectorAll(e)].filter(a=>!a.parentElement.closest(t)),m=a=>new Promise(l=>setTimeout(l,a)),v=()=>new Promise(a=>{requestAnimationFrame(a),setTimeout(a,100)}),b=async a=>{await v(),await v();let l=a.outerHTML;for(let y=0,E=Date.now()+d;y<3;){if(Date.now()>E)return null;await m(g);let S=a.outerHTML;y=S===l?y+1:0,l=S}return l},R=a=>{let l=document.createElement("template");return l.innerHTML=a,l.content.firstElementChild},h=a=>`<${a.localName}${a.classList.length?` class="${a.getAttribute("class")}"`:""}>`,$=a=>a.nodeType===1?h(a):`the words "${a.data.trim().slice(0,40)}"`,B=a=>[...a.childNodes].filter(l=>l.nodeType===1||l.nodeType===3&&l.data.trim()),H=(a,l)=>["style","class"].includes(l)&&!a.getAttribute(l)?.trim()?null:a.getAttribute(l),M=(a,l)=>{for(let S of new Set([...a.getAttributeNames(),...l.getAttributeNames()]))if(H(a,S)!==H(l,S))return`${S} on ${h(l)}, ${JSON.stringify(H(a,S))} then ${JSON.stringify(H(l,S))}`;let[y,E]=[B(a),B(l)];for(let S=0;S<Math.max(y.length,E.length);S++){let[N,P]=[y[S],E[S]];if(!N||!P)return`${h(l)} ${N?`without ${$(N)}`:`with ${$(P)} more`}`;if(N.nodeType!==P.nodeType||N.localName!==P.localName||N.nodeType===3&&N.data.trim()!==P.data.trim())return`in ${h(l)}, ${$(N)} then ${$(P)}`;let I=N.nodeType===1?M(N,P):null;if(I)return I}return null},me=a=>{let l=new Map;for(let y of a)l.set(h(y),(l.get(h(y))??0)+1);return l},Ie=()=>[...document.querySelectorAll("*")].filter(a=>!a.closest(t)),Fe=a=>[...a.at(-1).keys()].filter(l=>a.length>2&&a.every((y,E)=>E===0||(y.get(l)??0)>(a[E-1].get(l)??0))),Be=a=>a.parentElement?.closest(`${t}, ${o}`)??null,He=a=>[...a.querySelectorAll(o)].filter(l=>Be(l)===a),W=a=>{let l=a.cloneNode(!0);return He(l).forEach(y=>y.replaceChildren()),l},Z=a=>He(a).map(l=>{let y=[];for(let E=l.parentElement;E&&E!==a;E=E.parentElement)y.unshift(h(E));return{name:l.getAttribute(r),place:y.join(" > "),blocks:[...DocKit.dehydrate(l.cloneNode(!0)).children].map(E=>E.localName).join(" "),html:DocKit.dehydrate(l.cloneNode(!0)).outerHTML}}),ge=(a,l,y,{markup:E=!0}={})=>a.flatMap(({name:S,place:N,blocks:P,html:I})=>{let A=l.find(q=>q.name===S),X=A?A.place!==N?`moved the slot ${S} (${A.place?`in ${A.place}`:"straight in the instance"}, where the file has it ${N?`in ${N}`:"straight in the instance"})`:A.blocks!==P?`changed the blocks the slot ${S} holds (${P||"none"}, then ${A.blocks||"none"})`:E&&A.html!==I?`changed what the slot ${S} holds`:null:`took the slot ${S} off the instance`;return X?[{kind:"written-in",part:S,how:`${X}, ${y}`}]:[]}),We=a=>l=>Be(l)===a,ke=(a,l=()=>!0)=>Object.entries(s).filter(([,{edit:y}])=>l(y)).flatMap(([y,E])=>[...a.querySelectorAll(E.at)].filter(We(a)).map(S=>({name:y,node:S}))),ee=a=>ke(a,l=>l==="text"),K=a=>Object.entries(s).filter(([,{edit:l}])=>l==="data").map(([l,y])=>({name:l,node:[...a.querySelectorAll(y.at)].find(We(a))})).filter(({node:l})=>l),_=[],V=k()[u];if(!V)return[{kind:"gone"}];if(V.hasAttribute(n))return[{kind:"fallback"}];let ye=await b(V);if(ye===null)return[{kind:"moving"}];let ie=R(f),qe=Z(V);_.push(...ge(Z(ie),qe,"as it mounts",{markup:!1}));let be=ee(ie);ee(V).forEach(({name:a,node:l},y)=>{be[y]&&be[y].node.innerHTML!==l.innerHTML&&_.push({kind:"redrawn",part:a,how:`the file says ${JSON.stringify(be[y].node.textContent.trim())}, the page ${JSON.stringify(l.textContent.trim())}`})});let $e=DocKit.dehydrate(V.cloneNode(!0)),[Ge,Ue]=[W(ie),W($e)],xe=M(Ge,Ue);if(xe){let a=ke(Ue),l=ke(Ge).find(({node:y},E)=>a[E]&&M(y,a[E].node))?.name;_.push({kind:"left",what:xe,...l?{part:l}:{}})}let yt=K($e);for(let[a,{name:l,node:y}]of K(ie).entries())!xe&&yt[a]?.node.innerHTML!==y.innerHTML&&_.push({kind:"data",part:l});let Q=[],ve=new MutationObserver(a=>Q.push(...a));ve.observe(document.documentElement,{subtree:!0,childList:!0,characterData:!0});let Je=new Set,Ke=a=>{Q.push(...ve.takeRecords());for(let{name:l,node:y}of a)(!y.isConnected||Q.some(({target:E})=>y.contains(E)))&&Je.add(l);Q.length=0},re=[ye],Ee=[me(Ie())],Ve=a=>{re.push(a),Ee.push(me(Ie())),_.push(...ge(qe,Z(j),"as it mounts again"))},j=$e,Se=ee(j);Q.length=0,V.replaceWith(j);let U=await b(j);if(Ke(Se),U!==null){Ve(U);for(let a=0;a<c&&U!==null;a++){let l=j.cloneNode(!0);Se=ee(l),Q.length=0,j.replaceWith(l),j=l,U=await b(j),Ke(Se),U!==null&&Ve(U)}}ve.disconnect(),U===null&&_.push({kind:"moving"});for(let a of Je)_.push({kind:"redrawn",part:a,how:"a mount changes it"});let Ye=re.map(a=>me(W(R(a)).querySelectorAll("*"))),le=Fe(Ye),ze=W(R(re.at(-1))),bt=a=>{for(let l=a.parentElement;l&&l!==ze;l=l.parentElement)if(le.includes(h(l)))return!0;return!1},Qe=le.filter(a=>![...ze.querySelectorAll("*")].filter(l=>h(l)===a).every(bt));for(let a of Qe)_.push({kind:"piles",what:a,counts:Ye.map(l=>l.get(a)??0),held:le.length-Qe.length});for(let a of Fe(Ee))_.push({kind:"piles",what:a,outside:!0,counts:Ee.map(l=>l.get(a)??0)});if(!le.length){let a=re.slice(1).map(l=>M(W(R(ye)),W(R(l)))).find(Boolean);a&&_.push({kind:"changed",what:a})}let ce=U===null?[]:ee(j).filter(({node:a})=>a.textContent.trim()),$t=[...new Set([...new Map(ce.map(a=>[a.name,a])).values(),...ce])].slice(0,i),xt=Date.now()+w;for(let{node:a}of $t){if(Date.now()>xt)break;let l=document.createTreeWalker(a,NodeFilter.SHOW_TEXT).nextNode(),y=l.data;l.data=`${y}\u2026`;let E=ce.map(({node:N})=>N.textContent);await b(j);let S=ce.find(({node:N},P)=>!N.isConnected||N.textContent!==E[P]);if(S){_.push({kind:"redrawn",part:S.name,how:"a change of its words does not stand"});break}l.data=y,await b(j)}return U!==null&&K(j).length>0&&_.push(...await vt()),_;async function vt(){let a=[],l=null,y=!1,E="as it hears that it can write (the editable signal)",S=[],N=I=>{if(I.target!==j)return;let{parts:A,run:X}=I.detail,q=A.map(({part:O})=>O.innerHTML),C=A.map(({part:O})=>O.cloneNode(!0)),te=X(Object.fromEntries(A.map(({name:O},D)=>[O,C[D]]))),J=A.find(({part:O},D)=>O.innerHTML!==q[D]),Y=A.find(({part:O},D)=>C[D].cloneNode(!1).outerHTML!==O.cloneNode(!1).outerHTML);if(J&&A.forEach(({part:O},D)=>{O.innerHTML=q[D]}),!y){let O=J??Y??A.find((D,ne)=>C[ne].innerHTML!==q[ne]);O&&!S.some(D=>D.when===E)?S.push({kind:"unasked",part:O.name,when:E}):te&&!O&&I.preventDefault();return}J?l??=`it writes the part ${J.name} on the page, not the draft context.edit hands it, so the editor refuses the edit`:te&&Y&&(l??=`it changes the part ${Y.name}'s own tag or attributes, which are the file's: a change writes what a part holds, so the editor refuses the edit`),!(J||!te||Y)&&(A.forEach(({part:O},D)=>{a.push({part:O,before:q[D]}),O.replaceChildren(...C[D].childNodes)}),I.preventDefault())};document.addEventListener("doc-component-edit",N);try{return[...await P(),...S]}finally{document.removeEventListener("doc-component-edit",N)}async function P(){dispatchEvent(new Event("doc-editable")),await b(j),E="as it mounts";let I=j.cloneNode(!0);j.replaceWith(I),j=I;let A=await b(j);E="as it hears its part changed (the source signal)";let X=Z(j),q=DocKit.dehydrate(j.cloneNode(!0)),C=[];y=!0;try{if(!DocKit.example(j))return K(j).every(({name:F})=>p.includes(F))?[]:[{kind:"no-example"}]}catch(F){return[{kind:"example",what:`it throws: ${F?.message??F}`}]}finally{y=!1}let te=await b(j),J=DocKit.dehydrate(j.cloneNode(!0)),Y=Object.fromEntries(K(J).map(({name:F,node:z},Et)=>[F,z.innerHTML,K(q)[Et]?.node.innerHTML]).filter(([,F,z])=>F!==z));l?C.push({kind:"example",what:l}):a.length===0?C.push({kind:"example",what:"context.edit was not taken: it was not called, or it answered false, and the console says why"}):Object.keys(Y).length===0?C.push({kind:"example",what:"it changes nothing a part holds"}):C.push({kind:"wrote",parts:Y});for(let F of[q,J])for(let{node:z}of K(F))z.textContent="";let O=M(W(q),W(J));O&&C.push({kind:"example",what:`it changes what is no data part: ${O}`}),C.push(...ge(X,Z(j),"as its example makes its edit"));for(let{part:F,before:z}of a.reverse())F.innerHTML=z;let D=await b(j),ne=A!==null&&D!==null?M(W(R(A)),W(R(D))):null;return te===null||D===null?C.push({kind:"moving"}):ne&&!O&&C.push({kind:"undo",what:ne}),C}}}var zt=e=>e.map(({name:t,removed:o,added:r,lines:n})=>`${t} (-${o} +${r} of its ${n} line${n===1?"":"s"})`).join(" and "),Qt="a write changes the lines it means and no others: a row moved by context.rows, which takes the blank before it along, JSON written back by context.editJSON and laid out in template.html and example.html as it writes it (block-script.md, Two examples)";function De(e,t){try{return JSON.parse(e),Ot(e,JSON.parse(t))===t}catch{return!1}}var Xt="it changes nothing a part holds";function Zt({kind:e,what:t,part:o,how:r,when:n,counts:s,outside:p,parts:u,back:f,line:d,json:g,held:c=0},i,{script:w}){let k=v=>({...i,what:v}),m=v=>({...i,what:v,note:!0});switch(e){case"wrote":return{...i,told:!0,what:`its example wrote ${zt(u)}; the server took it${f?"; put back as an undo does, it shows what it showed":""}`};case"laid":return m(`its example's write lays the part ${o} out anew (${r}): ${Qt}${g?`; this write is context.editJSON's, and what the file held is laid out otherwise: lay ${o} out as it writes it`:""}`);case"drops":return{...m(`${t} listens for dragover and not for dragenter: a drop goes where both are cancelled, and the move that enters it asks dragenter alone, so that a release then (on a card's words, its padding) drops nothing: cancel dragenter as dragover is cancelled (preventDefault)`),file:"kit.js",line:d};case"controls":return{...m(`where nothing is written (this look is an export: context.canEdit() is false) the instance of ${i.file}${i.line?`:${i.line}`:""} still shows ${t}${s[0]>3?` and ${s[0]-3} more`:""}, enabled, and the block has a data part: a reader presses a control that writes to no effect, and the export says the block can be edited. Draw a control that writes only while context.canEdit(), and hide it by the hidden attribute (the kit holds [hidden] over any display the style gives it) or disable it; ignore this for a control that only changes what a reader looks at, a filter or a tab, which an export keeps. Compare 1024-light.png with edit-1024-light.png: the second is what a reader who can edit sees`),file:"kit.js",line:void 0};case"gone":return k("the page does not hold this instance");case"fallback":return k(w?"its component failed or never started: the instance shows what it holds, read-only":"the instance shows as one of no custom block");case"moving":return m("what it shows never holds still (an animation?), so its mounts could not be compared");case"redrawn":return k(`the component redraws its text part ${o}: ${r}. A text part is the file's, what the user types in: read it, and draw in what is the component's`);case"left":return k(`dehydrate does not leave it as the file has it, so a copy of the view would hold what the kit made of it: ${t}. ${o?`That stands in its part ${o}, which is the file's: read a part, and draw in what is the component's`:"Name what it draws in the manifest's runtime, or take it off in dehydrate"}`);case"data":return k(`a mount changes its data part ${o}, so that a page would write what the component left there, with nothing edited: read a data part, and change it by context.edit alone`);case"no-example":return m("it has a data part and its component offers no example of an edit, so nothing has tried the way back to the file: give DocKit.component an example(host, context) that makes a small context.edit");case"example":return t===Xt?{...i,file:"kit.js",line:void 0,what:`its example(host, context) changes nothing a part holds on the instance of ${i.file}${i.line?`:${i.line}`:""}: the check runs it on every instance of example.html and of template.html, and template.html's is empty, with nothing to change a value of (the first entry of a list it does not hold yet). Make example() make a change that works on an empty instance too (add an entry, set a field), and have it call the function a reader's control calls, so that it tries the code a reader runs`}:k(`its example: ${t}`);case"refused":return k("what its example wrote cannot go in the file: a script, a handler, an address of code, data-block-id or data-ge-*, what does not read back as itself, or what is no JSON in a script of data");case"undo":return k(`with what its example wrote put back, as an undo does, it does not show what it showed: ${t}: draw from the part, and on the source signal`);case"unasked":return k(`it writes its data part ${o} with no reader's gesture, ${n}, once the page takes edits: a page would write it each time it opened. Call context.edit on a gesture alone, a press, a drop or a key, and draw what the part holds as it is`);case"written-in":return k(`kit.js ${r}: a slot is the document's, its blocks the reader's: read it with context.part, never write in it or move it, and draw outside it`);case"piles":return k(p?`${t} piles up outside the instance on each put-back (${s.join(", then ")} of them), so an undo adds another: a component draws in its instance, and what it has to put elsewhere it takes away again in destroy`:`${t} piles up on each put-back (${s.join(", then ")} of them${c?", with what it holds":""}): it is declared in neither the manifest's runtime nor dehydrate, so an undo adds another. ${en(t)}`);default:return k(`a mount does not give the same DOM again: ${t}`)}}var en=e=>{let t=/class="([^"\s]+)/.exec(e)?.[1];return t?`Name it in component.json: "runtime": { "generated": [".${t}"] } (beside what generated already names), or take it off in dehydrate`:`Give it a class and name that in component.json's "runtime": { "generated": [".<class>"] }, or take it off in dehydrate`},tn=e=>[...new Map(e.toReversed().map(t=>[`${t.finding.kind}|${t.finding.part??""}|${["piles","example"].includes(t.finding.kind)?t.finding.what:""}|${t.finding.when??""}|${t.finding.line??""}`,t])).values()].toReversed(),nn=4e6;function Ce(e,t,o=(r,n)=>r===n){let[r,n]=[e.split(`
11
+ `),t.split(`
12
+ `)],s=0;for(;s<r.length&&s<n.length&&o(r[s],n[s]);)s++;let p=0;for(;p<r.length-s&&p<n.length-s&&o(r[r.length-1-p],n[n.length-1-p]);)p++;let[u,f]=[r.slice(s,r.length-p),n.slice(s,n.length-p)];if(u.length===0&&f.length===0)return[];if(u.length*f.length>nn)return[{removed:u,added:f}];let d=Array.from({length:u.length+1},()=>new Uint32Array(f.length+1));for(let i=u.length-1;i>=0;i--)for(let w=f.length-1;w>=0;w--)d[i][w]=o(u[i],f[w])?d[i+1][w+1]+1:Math.max(d[i+1][w],d[i][w+1]);let g=[],c=null;for(let i=0,w=0;i<u.length||w<f.length;)i<u.length&&w<f.length&&o(u[i],f[w])?(c=null,i++,w++):(c||g.push(c={removed:[],added:[]}),w<f.length&&(i===u.length||d[i][w+1]>=d[i+1][w])?c.added.push(f[w++]):c.removed.push(u[i++]));return g}function an(e,t){let o=n=>n.filter(s=>s.trim()).length,r=Ce(e,t);return{removed:r.reduce((n,s)=>n+o(s.removed),0),added:r.reduce((n,s)=>n+o(s.added),0),lines:o(e.split(`
13
+ `))}}function Wn(e,t){let o=r=>r.map(n=>n.trim()).filter(Boolean);return Ce(e,t).map(({removed:r,added:n})=>({removed:o(r),added:o(n)})).filter(({removed:r,added:n})=>r.length+n.length>0)}function it(e,t){let o=0,r=0;for(let[n,s]of e.entries())if(n>0&&o>0&&o<t&&r++,o+=s.replace(/\s+/g,"").length,o>=t)break;return r}function sn(e,t){let o=r=>r.filter(n=>!n.trim()).length;for(let{removed:r,added:n}of Ce(e,t,(s,p)=>s.trim()===p.trim())){if(o(n)>o(r))return"a line left blank";let[s,p]=[r.join("").replace(/\s+/g,""),n.join("").replace(/\s+/g,"")],u=0;for(;u<s.length&&u<p.length&&s[u]===p[u];)u++;let f=0;for(;f<s.length-u&&f<p.length-u&&s[s.length-1-f]===p[p.length-1-f];)f++;for(let[d,g,c]of[[u,r,n],[f,r.toReversed(),n.toReversed()]]){let[i,w]=[it(g,d)+1,it(c,d)+1];if(i!==w)return`${i} line${i===1?"":"s"} became ${w}`}}return null}function on(e,t){let o=sn(e,t);return o&&!(De(e,t)&&De(e,e))?o:null}function rn(e,{source:t,found:o,at:r,findings:n}){let s=Ze(t,ft(he(t),o)[r],e.parts,new Map([[o.id,o]]));if(!s)return[{kind:"refused"}];let p=Object.keys(e.parts),u=s.map(({start:d,end:g,text:c},i)=>({name:p[i],before:t.slice(d,g),after:c}));return[{kind:"wrote",back:!n.some(({kind:d})=>d==="undo"||d==="moving"),parts:u.map(({name:d,before:g,after:c})=>({name:d,...an(g,c)}))},...u.flatMap(({name:d,before:g,after:c})=>{let i=on(g,c);return i?[{kind:"laid",part:d,how:i,json:De(g,c)}]:[]})]}var ln=2e3;function cn({match:e,instance:t,at:o,most:r}){let n=[...document.querySelectorAll(e)].filter(s=>!s.parentElement.closest(t))[o];return n?[window,document,n,...n.querySelectorAll("*")].slice(0,r):[]}function dn(e){return e.map((t,o)=>o<2?{parent:o-1,named:""}:{parent:o===2?1:e.indexOf(t.parentElement),named:`<${t.localName}${t.classList.length?` class="${t.getAttribute("class")}"`:""}>`})}function hn(){let e=new DragEvent("dragenter",{bubbles:!0,cancelable:!0,composed:!0,dataTransfer:new DataTransfer});return this.dispatchEvent(e),e.defaultPrevented}async function pn(e,{match:t,at:o}){let r=new Map,n=({scriptId:s,url:p})=>r.set(s,p);e.on("Debugger.scriptParsed",n);try{await e.send("Debugger.enable"),await e.send("Debugger.setSkipAllPauses",{skip:!0});let{result:s}=await e.send("Runtime.evaluate",{expression:`(${cn})(${JSON.stringify({match:t,instance:fe,at:o,most:ln})})`,objectGroup:"drops"}),{result:p}=await e.send("Runtime.callFunctionOn",{objectId:s.objectId,functionDeclaration:String(dn),arguments:[{objectId:s.objectId}],returnByValue:!0}),{result:u}=await e.send("Runtime.getProperties",{objectId:s.objectId,ownProperties:!0}),f=u.filter(({name:i,value:w})=>/^\d+$/.test(i)&&w?.objectId).sort((i,w)=>Number(i.name)-Number(w.name)),d=[];for(let{value:i}of f)d.push((await e.send("DOMDebugger.getEventListeners",{objectId:i.objectId})).listeners);let g=(i,w)=>d[i]?.some(k=>k.type===w),c=[];for(let i=2;i<d.length;i++){let w=d[i].find(m=>m.type==="dragover"&&r.get(m.scriptId)==="kit.js");if(!w)continue;let k=!1;for(let m=i;m>=2&&!k;m=p.value[m].parent)k=g(m,"dragenter");if(!k&&(g(0,"dragenter")||g(1,"dragenter"))){let{result:m}=await e.send("Runtime.callFunctionOn",{objectId:f[i].value.objectId,functionDeclaration:String(hn),returnByValue:!0});k=m.value===!0}k||c.push({kind:"drops",what:p.value[i].named,line:w.lineNumber+1})}return c}finally{e.off("Debugger.scriptParsed",n),await e.send("Runtime.releaseObjectGroup",{objectGroup:"drops"}).catch(()=>{}),await e.send("Debugger.disable").catch(()=>{})}}function un(e,t){let o={errors:new Map,notes:new Set,failed:new Set,dialogs:new Set,windows:0,opened:[],asked:1,pending:[]},r=n=>{let[s]=n.split(`
14
+ `);o.errors.has(s)||o.errors.set(s,Number(/\bkit\.js:(\d+)/.exec(n)?.[1])||null)};return e.on("pageerror",n=>r(n.stack??n.message)),e.on("console",n=>{let s=n.type();!["error","warn","warning"].includes(s)||!et(n,t,["kit.js"])||o.pending.push(Promise.all(n.args().map(p=>p.evaluate(u=>u instanceof Error?u.stack:String(u)).catch(()=>""))).then(p=>{let u=p.join(" ")||n.text();s==="error"?r(u):o.notes.add(u.split(`
15
+ `)[0])}))}),e.on("requestfailed",n=>{n.frame()===e.mainFrame()&&!n.isNavigationRequest()&&o.failed.add(n.url())}),e.on("request",n=>{n.isNavigationRequest()&&n.frame()===e.mainFrame()&&o.opened.push(n.url())}),o}async function fn(e,t){let o=await e.createCDPSession();return await o.send("Page.enable"),o.on("Page.javascriptDialogOpening",({type:r})=>{t.add(r),o.send("Page.handleJavaScriptDialog",{accept:!1}).catch(()=>{})}),o}function L(e,t,o=se){let r=0,n=()=>Object.assign(new Error(t),{stuck:!0,doing:t,limit:o}),s=new Promise((u,f)=>{r=setTimeout(()=>f(n()),o)}),p=e.catch(u=>{throw qt.has(u.name)?n():Object.assign(u,{doing:t})});return Promise.race([p,s]).finally(()=>clearTimeout(r))}var wn=e=>`${Number((e/1e3).toFixed(1))} s`,mt=e=>`the browser did not answer within ${wn(e.limit)}, waiting until ${e.doing}`,_e=e=>new Promise(t=>{if(!e.connected)return t(!0);e.once("disconnected",()=>t(!0)),setTimeout(()=>t(!1),pt)});function mn({match:e,instance:t}){let{clientWidth:o,scrollWidth:r}=document.documentElement;if(r<=o+1)return null;let n=[...document.querySelectorAll(e)].filter(s=>!s.parentElement.closest(t));return{wide:r,at:n.findIndex(s=>[s,...s.querySelectorAll("*")].some(p=>p.getBoundingClientRect().right>o+1))}}var rt=16,gn="#8f8f8f";async function kn(e,t,o){let r=await Promise.all(t.map(async n=>`data:image/png;base64,${(await T.readFile(n)).toString("base64")}`));await e.setViewport({width:ae.reduce((n,s)=>n+s,0)+rt*(ae.length-1),height:900}),await e.setContent(`<!doctype html><body style="margin: 0; display: flex; align-items: flex-start; gap: ${rt}px; background: ${gn}">${r.map((n,s)=>`<img src="${n}" width="${ae[s]}" alt="" style="display: block">`).join("")}</body>`,{waitUntil:"load"}),await e.screenshot({path:o,fullPage:!0})}async function gt(e,{file:t,html:o,source:r,places:n,found:s,out:p,loading:u,answer:f=se}){let d=(b,R)=>L(b,R,f),g=await d(e.createBrowserContext(),"a browser context opened"),c=await d(g.newPage(),"a tab opened"),i=Me(t).href,w=un(c,i),k=await d(fn(c,w.dialogs),"the tab was set to refuse dialogs");g.on("targetcreated",b=>{b.type()==="page"&&(w.windows+=1,b.page().then(R=>R?.close()).then(()=>c.bringToFront()).catch(()=>{}))});let m={heard:w,blocked:[],late:[],taken:[],overviews:[],edited:[],asExport:[],answers:[],wide:[],stuck:null,stopped:null,gone:null},v=async b=>m.late.push(...await L(nt(c,{timeout:ot}),b,3*ot+se));await d(tt(c),"the tab was set to keep what the policy blocks"),await d(c.setViewport({width:736,height:900}),"the window went to 736px"),await d(c.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came");try{await L(c.goto(i,{waitUntil:"load",timeout:0}),"the page opened",u),await v("the page opened");for(let h of Re){await L(c.emulateMediaFeatures([{name:"prefers-color-scheme",value:h}]),`the ${h} theme came`);for(let $ of ae){if(await L(c.setViewport({width:$,height:900}),`the window went to ${$}px`),await v(`it was drawn at ${$}px`),h===Re[0]){let H=await L(c.evaluate(mn,{match:s.match,instance:fe}),`it was measured at ${$}px`);H&&m.wide.push({width:$,...H})}let B=x.join(p,`${$}-${h}.png`);await L(c.screenshot({path:B,fullPage:!0}),`it was pictured at ${$}px`),m.taken.push(B)}}await L(c.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]),"the light theme came"),await L(c.setViewport({width:736,height:900}),"the window went to 736px");let b=Pe(o,s);for(let{at:h,...$}of await L(c.evaluate(Vt,{match:s.match,instance:fe,slot:at,parts:s.parts,boards:s.settings?.length?[je]:[]}),"the page was asked what each instance still shows"))m.answers.push({finding:{kind:"controls",...$},place:n[h]});let R=s.files.includes("kit.js")&&Object.values(s.parts).some(({edit:h})=>h==="data");for(let h=0;h<b.length;h++){let $=await L(c.evaluate(Yt,{match:s.match,instance:fe,slotPart:at,slotName:Nt,fallback:Tt,parts:s.parts,boards:s.settings?.length?[je]:[],at:h,source:b[h].markup,still:_t,step:It,times:Ft,typed:Bt,typing:Ht}),"an instance was put back"),B=$.find(({kind:M})=>M==="wrote"),H=[...$.filter(M=>M!==B),...B?rn(B,{source:r,found:s,at:h,findings:$}):[]];R&&!$.some(({kind:M})=>M==="gone"||M==="fallback")&&H.push(...await L(pn(k,{match:s.match,at:h}),"the page was asked what an instance listens to")),m.answers.push(...H.map(M=>({finding:M,place:n[h]})))}m.blocked=await L(c.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"),w.asked+=1,await L(c.goto(i,{waitUntil:"load",timeout:0}),"the page opened again",u),await v("the page opened again"),await L(c.evaluate(()=>dispatchEvent(new Event("doc-editable"))),"the page was told it takes edits"),await v("it was drawn as the editing page draws it");for(let h of Ct){await L(c.setViewport({width:h,height:900}),`the window went to ${h}px`),await v(`it was drawn at ${h}px as the editing page draws it`);let $=x.join(p,`edit-${h}-light.png`);await L(c.screenshot({path:$,fullPage:!0}),`it was pictured at ${h}px as the editing page draws it`),m.edited.push($),(await T.readFile($)).equals(await T.readFile(x.join(p,`${h}-light.png`)))&&m.asExport.push($)}m.blocked.push(...await L(c.evaluate(()=>globalThis.__qaViolations),"the page was asked what it blocked"));for(let h of Re){let $=x.join(p,`overview-${h}.png`);await L(kn(c,ae.map(B=>x.join(p,`${B}-${h}.png`)),$),`the ${h} pictures were put side by side`),m.overviews.push($)}}catch(b){if(b.syscall)throw b;await _e(e)?m.gone=b.doing??"the page answered":b.stuck?m.stuck=b.doing:m.stopped=oe(b)}return await Promise.race([Promise.all(w.pending),new Promise(b=>setTimeout(b,pt).unref())]),m}var yn=(e,t)=>e.startsWith(t)?e.slice(t.length):e;function bn(e,t,o){let r=new Map;for(let{url:n,directive:s,source:p,line:u}of e){if(Wt.test(n)){let d=!p&&u>0;r.set(`${n}|${p}|${u}`,{file:d?"kit.js":"the page",...d?{line:u}:{},what:"the export's policy blocks code made from words (eval, new Function, a string given to setTimeout): an export runs none"});continue}let f=/^[a-z][a-z0-9+.-]*$/.test(n)?t.filter(d=>d.startsWith(`${n}:`)):[];for(let d of f.length?f:[n])r.set(`${d}|${s}`,{file:"the page",what:`the export's policy blocks ${yn(d,o)||"something"} (${s}): ${s==="img-src"?"a picture of an instance is a data: address, or a file its style names":"an export holds all it needs"}`})}return[...r.values()]}function kt({heard:e,blocked:t,late:o,answers:r,wide:n,stuck:s,stopped:p},{places:u,script:f,folder:d}){let g=({place:h})=>`${h?.file}:${h?.line}`,c=new Set(r.filter(({finding:h})=>h.kind==="piles"&&!h.outside).map(g)),i=h=>c.has(g(h))&&(h.finding.kind==="left"&&!h.finding.part||h.finding.kind==="example"&&String(h.finding.what).startsWith("it changes what is no data part")),w=tn(r.filter(h=>!i(h))).map(({finding:h,place:$})=>Zt(h,$,{script:f})),k=[...e.failed],m=k.filter(h=>!t.some($=>$.url&&h.startsWith($.url))),v=e.opened.length>e.asked?"it loads itself again (location.reload(), a new location.href), so a reader's page would not stay":s?`it stopped answering while waiting until ${s}${f?": a script that never ends, or a component that changes what it hears (a text part, on its source signal)":""}`:p&&`the look at it stopped: ${p}`,b=n.map(({width:h,wide:$})=>`${$}px wide in a ${h}px window`).join(", "),R=u[n.find(({at:h})=>h>=0)?.at]??{file:"the page"};return{problems:[...[...e.errors].map(([h,$])=>({file:$?"kit.js":"the page",line:$,what:`the console says ${h}`})),...bn(t,k,d),...m.map(h=>({file:"the page",what:`it could not load ${h.slice(0,120)}`})),...[...e.dialogs].map(h=>({file:"the page",what:`it opens a dialog (${h}), which stops a reader's page until it is answered: show what it says in the instance`})),...e.windows?[{file:"the page",what:"it opens a window, which takes a reader away from the page: show it in the instance, or link to it"}]:[],...v?[{file:"the page",what:v}]:[],...n.length?[{...R,what:`the page is ${b}: a reader scrolls the whole page sideways, and gallery qa fails it: let it fit the window (max-width: 100%), or put what is wider in a frame of its own that scrolls`}]:[],...w.filter(({note:h,told:$})=>!h&&!$)],notes:[...[...e.notes].map(h=>({file:"the page",what:`the console says ${h}`})),...w.filter(({note:h})=>h),...o.map(h=>({file:"the page",what:`waited for ${h}`}))],told:w.filter(({told:h})=>h)}}async function qn(e,t,{example:o,template:r},{find:n=Oe,start:s=Le,loading:p=ht,answer:u=se}={}){let f=Pt,d=null,g=null;try{d=await T.mkdtemp(x.join(we.tmpdir(),"gallery-component-check-"));let c=await Kt(t,{example:o,template:r},d),i=n();if(!i)return{title:f,unverified:"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one)"};try{g=await s({executablePath:i,args:Ae()})}catch(v){return{title:f,unverified:`the browser ${i} did not start, twice, each time with a fresh profile (${oe(v)}; GALLERY_BROWSER=<its executable> picks another)`}}let w=x.join(dt(e).qa,"components",...t.id.split("/"));await T.rm(w,{recursive:!0,force:!0}),await T.mkdir(w,{recursive:!0});let k=await gt(g.browser,{...c,found:t,out:w,loading:p,answer:u}),m=kt(k,{places:c.places,script:t.files.includes("kit.js"),folder:Me(`${d}${x.sep}`).href});return k.gone?{title:f,...m,unverified:`the browser went while waiting until ${k.gone}, so it says nothing of the block`}:{title:f,...m,...k.taken.length?{pictures:{folder:w,overviews:k.overviews.map(v=>x.basename(v)),each:k.taken.map(v=>x.basename(v)),edited:k.edited.map(v=>x.basename(v)),asExport:k.asExport.map(v=>x.basename(v))}}:{}}}catch(c){return c.reason==="check"?{title:f,problems:c.failures.map(i=>({file:"the export",what:i}))}:c.syscall?{title:f,unverified:`cannot write ${pe(c.syscall==="mkdtemp"?we.tmpdir():c.path)} (${c.code})`}:g&&await _e(g.browser)?{title:f,unverified:"the browser went before the page opened"}:c.stuck?{title:f,problems:[{file:"the page",what:`${mt(c)}, so the look stopped and the browser was closed`}]}:{title:f,problems:[{file:"the page",what:`the look at it stopped: ${oe(c)}`}]}}finally{await g?.close(),d&&await T.rm(d,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{})}}async function lt(e,t,{full:o=!1}={}){let r=[];for(let n of await Dt(e)){let s=Lt(n,e),p=Rt(s).html,u=await T.readFile(p,"utf8").catch(()=>null);if(u===null)continue;let f=ct(he(u),t),d=c=>{for(let i=c.parentNode;i;i=i.parentNode)if(f.includes(i))return!0;return!1},g=f.filter(c=>!d(c)).map(({sourceCodeLocation:{startLine:c,startOffset:i,endOffset:w}})=>({line:c,markup:u.slice(i,w)}));g.length&&r.push({slug:n,place:o?pe(p):`${n}/${x.basename(p)}`,directory:s,instances:g})}return r}async function $n(e,t,o,r){let n=t.instances.map(({line:c,markup:i})=>`<p>${t.place}:${c}</p>${i}`).join(`
16
+ `);for(let c of new Set([e.id,...[...n.matchAll(new RegExp(`${jt}="([^"]+)"`,"g"))].map(([,i])=>i)])){let i=c===e.id?e:o.get(c);i&&await wt(i,r)}let s=x.join(r,G);await T.mkdir(s),await T.cp(x.join(t.directory,"assets"),x.join(s,"assets"),{recursive:!0}).catch(c=>{if(c.code!=="ENOENT")throw c});let p=Te(ut(G,n)).text;await T.writeFile(x.join(s,"doc.html"),p),await T.writeFile(x.join(s,"doc.json"),JSON.stringify({title:G,description:G,type:"component"}));let f=await(await Ne({directory:r,catalog:de(r)}))(G),d=x.join(r,"export.html");await T.writeFile(d,f);let g=Pe(p,e).map((c,i)=>({file:t.place,line:t.instances[i]?.line??null}));return{html:f,file:d,places:g,source:p}}async function Gn(e,t,{elsewhere:o=null,find:r=Oe,start:n=Le,loading:s=ht}={}){let p=o&&st(o)!==st(e)?o:null,u=[...await lt(e,t),...p?await lt(p,t,{full:!0}):[]];if(u.length===0)return[{title:ue(),none:`none holds an instance of ${t.id}`}];let f=r();if(!f)return[{title:ue(),unverified:"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one)"}];let d;try{d=await n({executablePath:f,args:Ae()})}catch(i){return[{title:ue(),unverified:`the browser ${f} did not start, twice, each time with a fresh profile (${oe(i)}; GALLERY_BROWSER=<its executable> picks another)`}]}let{packages:g}=de(e),c=[];try{for(let i of u){let w=ue(i.place),k=null;try{k=await T.mkdtemp(x.join(we.tmpdir(),"gallery-component-check-"));let m=await $n(t,i,g,k),v=x.join(dt(e).qa,"components",...t.id.split("/"),"documents",i.slug);await T.rm(v,{recursive:!0,force:!0}),await T.mkdir(v,{recursive:!0});let b=await gt(d.browser,{...m,found:t,out:v,loading:s}),R=kt(b,{places:m.places,script:t.files.includes("kit.js"),folder:Me(`${k}${x.sep}`).href});if(b.gone){c.push({title:w,...R,unverified:`the browser went while waiting until ${b.gone}, so it says nothing of these instances`});break}c.push({title:w,...R,...b.taken.length?{pictures:{folder:v,overviews:b.overviews.map(h=>x.basename(h)),each:b.taken.map(h=>x.basename(h)),edited:b.edited.map(h=>x.basename(h)),asExport:b.asExport.map(h=>x.basename(h)),documents:!0}}:{}})}catch(m){if(m.reason==="check")c.push({title:w,problems:m.failures.map(v=>({file:i.place,what:`its instances, exported alone: ${v}`}))});else if(m.syscall)c.push({title:w,unverified:`cannot write ${pe(m.syscall==="mkdtemp"?we.tmpdir():m.path)} (${m.code})`});else if(await _e(d.browser)){c.push({title:w,unverified:"the browser went before the page opened"});break}else if(m.stuck){c.push({title:w,problems:[{file:"the page",what:`${mt(m)}, so the look at them stopped, the browser was closed, and no document after them was looked at`}]});break}else c.push({title:w,problems:[{file:"the page",what:`the look at them stopped: ${oe(m)}`}]})}finally{k&&await T.rm(k,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{})}}}finally{await d.close()}return c}export{Pt as a,ue as b,ht as c,se as d,Fn as e,_t as f,It as g,Bn as h,Hn as i,oe as j,ut as k,zt as l,Qt as m,an as n,Wn as o,on as p,fn as q,L as r,wn as s,mt as t,_e as u,qn as v,Gn as w};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c}from"./chunk-NOGQX56R.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{b as createReportFromStarter,a as loadReports,c as starterPage};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as P}from"./chunk-NF4MMOUB.mjs";import"./chunk-ZNGGDUZI.mjs";import{a as w,b as L,e as p,g as j,j as I,l as A,o as E}from"./chunk-B6RAGF4R.mjs";import{a as O}from"./chunk-5TLLIZT7.mjs";import"./chunk-OM24O4KR.mjs";import"./chunk-LZY74XTP.mjs";import{c as S}from"./chunk-XNNCQROX.mjs";import"./chunk-LJZIYVNA.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-ZTHICSSF.mjs";import{g as x}from"./chunk-F4CT35KL.mjs";import{b as s,f as g,i as N}from"./chunk-L4WLQYFC.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import K from"node:path";import{pageLinks as M,pageOfLink as U}from"../browser/shared/page-links.mjs";import{reportsDirectory as T}from"../browser/shared/paths.mjs";import{findPreviewServer as W}from"../browser/shared/preview-server.mjs";import{topOf as B}from"../browser/shared/outline-shape.mjs";import{LINK_FILE as C,linkAddress as _,linkIcon as q}from"../browser/shared/web-links.mjs";var y=n=>n.replace(/\s+/g," ").trim(),k=n=>n==null?"none":JSON.stringify(n);async function z(n,e){let t=await W(),o=t?await I(t,e,n):null;if(o)return o;let[,i]=await S({edits:{},reports:{},reportsDirectory:T,web:{icon:a=>x(a)}}).run(n,e);return i}function D(n,e){let t=[...n.documents.values()].filter(({url:a})=>a!==void 0),o=U(M(t),e.replace(/^.*#/,""));return o?{slug:o,link:n.documents.get(o)}:{refused:n.documents.get(e)?`${p(n,e)} is a document, not a web link: gallery set changes a document.`:`No web link "${e}": gallery list --tree shows the sidebar's entries.`}}async function G(n,e,t){if(n.length!==2)throw new s('Name the address and the name: gallery link add <url> "<name>".');let[o,i]=n,a=_(o);if(a.refused)throw new s(`Not an address a web link takes: ${o} (${{url:"no address",scheme:"http or https only",long:"2048 characters at most"}[a.refused]}).`);if(!y(i))throw new s("The name is never empty.");let d=t.get("--column"),u=t.get("--under"),l=t.get("--after"),c=t.get("--icon");if(d!==void 0&&u!==void 0)throw new s("--column and --under are two places: give one.");if(l!==void 0&&e.has("--first"))throw new s("--after and --first are two places: give one.");if(c!==void 0&&!q(c))throw new s(`Not an icon a web link takes: ${c} (an emoji, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg).`);let f=await w(),m;if(d!==void 0){let v=E(f,d);v||(console.error(`No column "${d}" in the sidebar (${f.groups.map(L).join(", ")}): nothing added.`),process.exit(1)),m=B(v.id)}u!==void 0&&(m=(await N(u)).slug);let r=l===void 0?null:(await N(l)).slug,F=e.has("--first")||u===void 0&&r===null,h=await z("link",{url:a.url,title:y(i),...c?{icon:c}:{},...m!==void 0?{parent:m}:{},after:r,first:F});h?.ok||(console.error(`Not added: ${h?.message??h?.reason??"no answer"}.`),process.exit(1));let $=await w(),{slug:b,url:J}=h.link;console.log(`Added the web link ${p($,b)}: ${J}`),console.log(`Placed it ${A($,{parent:h.parent,index:h.index})}.`),console.log(j($,b)),console.log(`It is ${O(K.join(T,b,C))}; the workbench shows the page beside the sidebar (a site that refuses frames: \u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00).`)}async function H(n,e){if(n.length!==1)throw new s("Name one web link, then what to set: --url, --title, --icon.");if(!["--url","--title","--icon"].some(r=>e.has(r)))throw new s('Say what to set: --url <address>, --title "<name>", --icon <emoji|none>.');let t=e.has("--title")?y(e.get("--title")):void 0;if(t==="")throw new s("--title takes the words of the name: a web link's name is never empty.");let o;if(e.has("--url")){let r=_(e.get("--url"));if(r.refused)throw new s(`Not an address a web link takes: ${e.get("--url")}.`);o=r.url}let i;if(e.has("--icon")){let r=e.get("--icon").trim();if(r!=="none"&&!q(r))throw new s(`Not an icon a web link takes: ${r} (an emoji, none, or an icon of the \u56FE\u6807 tab).`);i=r==="none"?null:r}let a=await w(),d=D(a,n[0]);d.refused&&(console.error(d.refused),process.exit(1));let{slug:u,link:l}=d,c=await z("link-set",{slug:u,...o!==void 0?{url:o}:{},...t!==void 0?{title:t}:{},...i!==void 0?{icon:i}:{}});c?.ok||(console.error(`Not set: ${c?.message??c?.reason??"no answer"}.`),process.exit(1));let f=c.link,m=[...t!==void 0&&t!==l.title?[` title: ${k(l.title)} \u2192 ${k(f.title)}`]:[],...o!==void 0&&f.url!==l.url?[` url: ${l.url} \u2192 ${f.url}`]:[],...i!==void 0&&(f.icon??null)!==(l.icon??null)?[` icon: ${k(l.icon)} \u2192 ${k(f.icon??null)}`]:[]];if(!m.length)return void console.log(`Nothing to change: ${u} has ${e.size===1?"that already":"those already"}.`);console.log(`Set the web link ${u}:`);for(let r of m)console.log(r)}async function Q(n){if(n.length!==1)throw new s("Name one web link to move to the trash.");let e=await w(),t=D(e,n[0]);t.refused&&(console.error(t.refused),process.exit(1));let o=await P({kind:"link",slug:t.slug});o.refused&&(console.error(`Not moved to the trash: ${o.refused}.`),process.exit(1)),console.log(`Moved the web link ${p(e,t.slug)} to the trash: the workbench's \u8BBE\u7F6E \u203A \u56DE\u6536\u533A restores it where it was.`)}async function ae(n){let[e,...t]=n;if(e==="add"){let{positional:o,options:i,values:a}=g({options:["--first"],values:["--column","--under","--after","--icon"],argv:t});return G(o,i,a)}if(e==="set"){let{positional:o,values:i}=g({values:["--url","--title","--icon"],argv:t});return H(o,i)}if(e==="remove"){let{positional:o}=g({argv:t});return Q(o)}throw new s(e?`No such action: link ${e} (add, set, remove).`:"Say what to do: gallery link add, set or remove.")}export{ae as run};
@@ -0,0 +1,22 @@
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 Zt}from"./chunk-ZOEJQOKT.mjs";import{a as Qt,b as qt}from"./chunk-IA4PSIMD.mjs";import{b as Gt}from"./chunk-6N25CJ6Y.mjs";import{a as Ft,b as Bt,c as $e,d as Kt,e as Ct,f as Yt,g as Vt,h as zt}from"./chunk-6ILJWFYW.mjs";import{b as Ee,c as Wt,e as Ht,g as ot}from"./chunk-VRPVVMRB.mjs";import{a as Rt}from"./chunk-UMHUSOPJ.mjs";import{a as Pt,d as Jt,e as Lt,f as _t,g as Ut}from"./chunk-W5NPH5UA.mjs";import{e as It,f as Dt,h as rt}from"./chunk-ECZBLQKK.mjs";import{a as M,m as Et}from"./chunk-E7656LR7.mjs";import{g as Tt,u as At}from"./chunk-TKWEX4FD.mjs";import{documentKey as gr}from"../browser/shared/workspace-address.mjs";import{serviceLocation as br}from"../browser/shared/service-location.mjs";import{createHmac as $r,randomBytes as Ce}from"node:crypto";import{existsSync as xr,mkdirSync as vr,readFileSync as Sr,writeFileSync as Or}from"node:fs";import B from"node:fs/promises";import I from"node:path";import{FILE as jr}from"../browser/shared/annotations.mjs";import{escapeTyped as Mr}from"../browser/shared/escape.mjs";import{writeAtomic as lt}from"../browser/shared/files.mjs";import{sendJson as J}from"../browser/shared/http.mjs";import{REQUEST_ID as ut}from"../browser/shared/ids.mjs";import{UPLOAD_REQUEST_LIMIT as Nr}from"../browser/shared/media.mjs";import{reportsDirectory as Tr}from"../browser/shared/paths.mjs";import{sameDirectory as dt}from"../browser/shared/preview-server.mjs";import{slugPattern as G}from"../browser/shared/reports.mjs";import{TODO_MOST as Ar}from"../browser/shared/workspace-query.mjs";import{documentDirectory as Er,documentFiles as Pe,isDocumentSource as Rr}from"../browser/shared/workspace.mjs";import xe from"node:fs/promises";import ve from"node:path";import{writeAtomic as Xt}from"../browser/shared/files.mjs";import{slugPattern as at}from"../browser/shared/reports.mjs";var Be=1,Re={seen:"seen.html",base:"base.html",state:"state.json"},Gn=4,Qn=1800*1e3;function en({stateDirectory:i=null,shown:f,folderOf:a,isPage:c=()=>!1,log:p=null,now:m=Date.now,quiet:k=Qn}){let y=new Map,u=s=>ve.join(i,"changes",s),g=Promise.resolve(),b=s=>{let d=g.then(s);return g=d.catch(S=>p?.(`changes: ${S.message}`)),d};async function N(s){if(!i)return y.get(s)?.state??null;try{let d=JSON.parse(await xe.readFile(ve.join(u(s),Re.state),"utf8"));return d?.v===Be&&typeof d.seen=="string"?d:null}catch{return null}}async function E(s,d){return i?xe.readFile(ve.join(u(s),Re[d]),"utf8").catch(()=>null):y.get(s)?.[d]??null}async function x(s,d,S={}){if(!i){let v=y.get(s)??{};y.set(s,{...v,...S,state:d});return}await xe.mkdir(u(s),{recursive:!0});for(let[v,_]of Object.entries(S))_===null?await xe.rm(ve.join(u(s),Re[v]),{force:!0}):await Xt(ve.join(u(s),Re[v]),_);await Xt(ve.join(u(s),Re.state),`${JSON.stringify(d)}
3
+ `)}async function X(s){y.delete(s),i&&await xe.rm(u(s),{recursive:!0,force:!0,maxRetries:3})}let C=async s=>Math.round((await xe.stat(a(s)).catch(()=>null))?.birthtimeMs??0),Q=s=>s?.base?`${s.since}|${s.writes}`:null,Y=s=>Number.isFinite(s?.draft)&&m()-s.draft<k?s.draft:null,V=(s,d,S,v=Y(s))=>[{v:Be,born:s?.born??0,seen:d,...v===null?{}:{draft:v}},{seen:S,base:null}];async function L(s){let d=await N(s);if(!d)return null;let S=await C(s);return d.born&&S&&d.born!==S?(await X(s),null):d}async function j(s,d){if(typeof d!="string"||!at.test(s)||c(s))return!1;let S=M(d),v=await L(s);if(!v)return await x(s,{v:Be,born:await C(s),seen:S},{seen:d}),!1;if(v.seen===S)return!1;let _=await E(s,"seen"),K=new Date(m()).toISOString();if(_===null)return await x(s,...V(v,S,d)),!1;let D=f(_),ne=f(d);if(!v.base){if(!$e(D,ne))return await x(s,...V(v,S,d)),!1;if(Y(v)!==null||Yt(D))return await x(s,...V(v,S,d,m())),!1;let{draft:me,...oe}=v;return await x(s,{...oe,seen:S,base:M(D),since:K,at:K,writes:1},{seen:d,base:D}),!0}let fe=await E(s,"base");if(fe===null||!$e(fe,ne))return await x(s,...V(v,S,d)),!0;let Me=$e(D,ne)!==null;return await x(s,{...v,seen:S,...Me?{at:K,writes:v.writes+1}:{}},{seen:d}),Me}async function Z(s,d,S,v){if(!at.test(s)||c(s))return!1;let _=await L(s),K=M(d);if(!_?.base)return await x(s,...V(_??{born:await C(s)},K,d,v?null:Y(_))),!1;let D=await E(s,"base");if(D!==null&&S)try{D=S(D)}catch(ne){p?.(`changes: ${s}: the baseline did not take the edit (${ne.message})`)}return D===null||!$e(D,f(d))?(await x(s,...V(_,K,d)),!0):(await x(s,{..._,seen:K,base:M(D)},{seen:d,base:D}),!1)}async function je(s,d){if(!at.test(s)||c(s))return{ended:!1,moved:!1};let S=typeof d=="string"?await j(s,d):!1,v=await L(s);if(v?.draft===void 0)return{ended:!1,moved:S};let{draft:_,...K}=v;return await x(s,K),{ended:Y(v)!==null,moved:S}}let te=new Map;async function H(s,d){await j(s,d);let S=f(d),v=M(S),_=await L(s);if(!_?.base)return{pending:!1,version:v,...Y(_)!==null?{draft:!0}:{}};let K=`${s} ${_.base} ${v}`,D=te.get(K);if(D===void 0){let ne=await E(s,"base");for(D=ne===null?null:$e(ne,S),te.set(K,D);te.size>Gn;)te.delete(te.keys().next().value)}return D?{pending:!0,version:v,stamp:Q(_),since:_.since,writes:_.writes,...D}:{pending:!1,version:v}}return{look:(s,d)=>b(()=>j(s,d)),wrote:(s,d,S=null,{reader:v=!1}={})=>b(()=>Z(s,d,S,v)),endDraft:(s,d=null)=>b(()=>je(s,d)),read:(s,d)=>b(()=>H(s,d)),stamp:s=>b(async()=>Q(await L(s))),snapshot:s=>b(async()=>{let d=await L(s);return d?{state:d,seen:await E(s,"seen"),base:await E(s,"base")}:null}),clear:s=>b(async()=>{let d=await L(s);d?.base&&await x(s,{v:Be,born:d.born,seen:d.seen},{base:null})}),restore:(s,d)=>b(async()=>{d?.state&&await x(s,d.state,{seen:d.seen,base:d.base})}),forget:s=>b(()=>X(s)),idle:()=>b(async()=>{})}}import ie from"node:fs/promises";import ae from"node:path";import{writeAtomic as st}from"../browser/shared/files.mjs";var Ie=/^(\d{8}T\d{6}(?:\d{3})?Z)-([a-f0-9]{16})\.html$/,tn=30,qn=50,nn=["reader","agent"],rn=["commit","write","revert","undo","restore","hand-in","rename"],De=(i,f)=>ae.join(i,"history",f);function Xn(i){let[,f,a,c,p,m,k,y="0"]=/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(\d{3})?Z$/.exec(i)??[];return f?Date.UTC(+f,+a-1,+c,+p,+m,+k,+y):0}var er=i=>new Date(i).toISOString().replace(/[-:.]/g,"");async function on(i){return(await ie.readdir(i).catch(()=>[])).filter(a=>Ie.test(a)).map(a=>({name:a,time:Xn(Ie.exec(a)[1])})).sort((a,c)=>a.time-c.time||(a.name<c.name?-1:1))}var Ke=i=>i.replace(/\.html$/,".json");async function tr(i,f){try{let a=JSON.parse(await ie.readFile(ae.join(i,Ke(f)),"utf8"));return!a||typeof a!="object"?null:{by:nn.includes(a.by)?a.by:null,kind:rn.includes(a.kind)?a.kind:null,...typeof a.from=="string"&&Ie.test(`${a.from}.html`)?{from:a.from}:{}}}catch{return null}}function nr(i){let f=new Set(i.slice(-tn).map(({name:p})=>p)),a=i.slice(0,Math.max(0,i.length-tn)),c=new Map;for(let p of a)c.set(Math.floor(p.time/36e5),p.name);for(let p of[...c.values()].slice(-qn))f.add(p);return f}async function an(i,f,a={},{now:c=Date.now()}={}){let p=M(f);await ie.mkdir(i,{recursive:!0});let m=await on(i),k=m.at(-1),u={by:a.by!==void 0?nn.includes(a.by)?a.by:null:m.length?"agent":null,kind:rn.includes(a.kind)?a.kind:"write",...typeof a.from=="string"?{from:a.from}:{}};if(k&&k.name.endsWith(`-${p}.html`))return a.by!==void 0&&await st(ae.join(i,Ke(k.name)),`${JSON.stringify(u)}
4
+ `),k.name.replace(/\.html$/,"");let g=Math.max(c,(k?.time??0)+1),b=`${er(g)}-${p}.html`;await st(ae.join(i,Ke(b)),`${JSON.stringify(u)}
5
+ `),await st(ae.join(i,b),f);let N=[...m,{name:b,time:g}],E=nr(N);await Promise.all(N.filter(({name:x})=>!E.has(x)).flatMap(({name:x})=>[ie.rm(ae.join(i,x),{force:!0}),ie.rm(ae.join(i,Ke(x)),{force:!0})]));for(let x of await ie.readdir(i).catch(()=>[]))x.endsWith(".json")&&Ie.test(x.replace(/\.json$/,".html"))&&!E.has(x.replace(/\.json$/,".html"))&&await ie.rm(ae.join(i,x),{force:!0});return b.replace(/\.html$/,"")}async function it(i,{text:f=!1}={}){let a=[];for(let{name:c,time:p}of await on(i)){let[,,m]=Ie.exec(c),k=await tr(i,c),y={id:c.replace(/\.html$/,""),time:new Date(p).toISOString(),version:m,by:k?.by??null,kind:k?.kind??null,...k?.from?{from:k.from}:{}};if(f){let u=await ie.readFile(ae.join(i,c),"utf8").catch(()=>null);if(u===null||M(u)!==m)continue;y.text=u}a.push(y)}return a}function ct(i,f){let a=typeof f=="string"?f.trim().toLowerCase():"";if(!a)return{refused:"none"};let c=i.filter(({id:m,version:k})=>m.toLowerCase()===a||k===a),p=c.length?c:a.length>=6?i.filter(({id:m,version:k})=>k.startsWith(a)||m.toLowerCase().startsWith(a)):[];return p.length?new Set(p.map(({version:m})=>m)).size>1?{refused:"ambiguous",candidates:p.map(({id:m})=>m)}:{version:p.at(-1)}:{refused:"none"}}import{randomBytes as rr}from"node:crypto";import de from"node:fs/promises";import Se from"node:path";import{FILE as or,readItems as ar}from"../browser/shared/annotations.mjs";import{writeAtomic as sr}from"../browser/shared/files.mjs";import{documentDirectory as ir}from"../browser/shared/workspace.mjs";var cr=20,fn=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,sn=80,ln=({stateDirectory:i,slug:f})=>Se.join(i,"dropped-annotations",f),un=i=>({id:i.id,text:i.text,quote:i.anchor?.quote??"",kind:i.anchor?.kind??"text"});async function dn({stateDirectory:i,reportsDirectory:f,slug:a,time:c,items:p}){let m=ln({stateDirectory:i,reportsDirectory:f,slug:a});await de.mkdir(m,{recursive:!0});let k=c.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await sr(Se.join(m,`${k}-${rr(4).toString("hex")}.json`),JSON.stringify({time:c,items:p}));let y=(await de.readdir(m)).filter(u=>fn.test(u)).sort();await Promise.all(y.slice(0,Math.max(0,y.length-cr)).map(u=>de.rm(Se.join(m,u),{force:!0})))}async function wo({stateDirectory:i,reportsDirectory:f,slug:a}){let c=ln({stateDirectory:i,reportsDirectory:f,slug:a}),p=(await de.readdir(c).catch(()=>[])).filter(y=>fn.test(y)).sort();if(p.length===0)return[];let m=new Set(ar(await de.readFile(Se.join(ir(a,f),or),"utf8").catch(()=>"")).map(y=>y.id)),k=[];for(let y of p){let u=Se.join(c,y);try{let g=JSON.parse(await de.readFile(u,"utf8")),b=Array.isArray(g?.items)?g.items.filter(N=>typeof N?.id=="string"&&!m.has(N.id)):[];typeof g?.time=="string"&&b.length&&k.push({time:g.time,items:b})}catch{}await de.rm(u,{force:!0}).catch(()=>{})}return k}var fr=(i,f=new Date)=>{let a=new Date(i),c=m=>String(m).padStart(2,"0"),p=`${c(a.getHours())}:${c(a.getMinutes())}`;return a.toDateString()===f.toDateString()?p:`${a.getFullYear()}-${c(a.getMonth()+1)}-${c(a.getDate())} ${p}`},cn=i=>{let f=String(i??"").replace(/\s+/g," ").trim();return JSON.stringify(f.length>sn?`${f.slice(0,sn-1)}\u2026`:f)};function ft(i,{time:f=null,items:a},{today:c=new Date}={}){let p=Se.resolve(i),m=`${a.length} \u6279\u6CE8 (annotation${a.length===1?"":"s"})`;return[`annotations ${p}: ${f?`at ${fr(f,c)}, `:""}Gallery deleted ${m} whose words are gone from the document (rewritten or deleted):`,...a.map(({id:k,text:y,quote:u,kind:g})=>` ${k} ${cn(y)} on ${g==="blocks"?"the blocks ":""}${cn(u)}`)]}function po(i,f,{today:a=new Date}={}){return f.length?[...f.flatMap(c=>ft(i,c,{today:a}))," 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 lr}from"node:crypto";import Oe from"node:fs/promises";import Fe from"node:path";import{writeAtomic as ur}from"../browser/shared/files.mjs";var dr=20,mn=/^\d{8}T\d{6}Z-[a-f0-9]{8}\.json$/,wn=({stateDirectory:i,slug:f})=>Fe.join(i,"rewrites",f);async function pn({stateDirectory:i,reportsDirectory:f,slug:a,time:c,changes:p}){let m=wn({stateDirectory:i,reportsDirectory:f,slug:a});await Oe.mkdir(m,{recursive:!0});let k=c.replace(/[-:]/g,"").replace(/\.\d+Z$/,"Z");await ur(Fe.join(m,`${k}-${lr(4).toString("hex")}.json`),JSON.stringify({time:c,changes:p}));let y=(await Oe.readdir(m)).filter(u=>mn.test(u)).sort();await Promise.all(y.slice(0,Math.max(0,y.length-dr)).map(u=>Oe.rm(Fe.join(m,u),{force:!0})))}async function hn({stateDirectory:i,reportsDirectory:f,slug:a}){let c=wn({stateDirectory:i,reportsDirectory:f,slug:a}),p=(await Oe.readdir(c).catch(()=>[])).filter(k=>mn.test(k)).sort(),m=[];for(let k of p){let y=Fe.join(c,k);try{let u=JSON.parse(await Oe.readFile(y,"utf8"));typeof u?.time=="string"&&Array.isArray(u.changes)&&m.push(u)}catch{}await Oe.rm(y,{force:!0}).catch(()=>{})}return m}var mr=(i,f=new Date)=>{let a=new Date(i),c=m=>String(m).padStart(2,"0"),p=`${c(a.getHours())}:${c(a.getMinutes())}`;return a.toDateString()===f.toDateString()?p:`${a.getFullYear()}-${c(a.getMonth()+1)}-${c(a.getDate())} ${p}`};function $o(i,f,{today:a=new Date}={}){if(!f.length)return[];let c=Fe.resolve(i),p=[];for(let{time:m,changes:k}of f){let y=[];for(let{line:u,rule:g,key:b}of[...k].sort((N,E)=>N.line-E.line)){let N=`line ${u} ${g}${b?` ${b}`:""}`;y.includes(N)||y.push(N)}p.push(`preview ${c}: at ${mr(m,a)}, when the reader edited the page, the preview wrote your natural HTML as the kit's markup: ${y.join(", ")}`),p.push(...k.filter(u=>u.note).map(({line:u,rule:g,note:b})=>` line ${u}, ${g}: ${b}`))}return p.push(" re-read the file before editing it (those lines are the file's as you had left it)"),p}var wr=3e4,pr=12e4,hr=1500,kn=1e4,yn=i=>i.reduce((f,{key:a,tag:c})=>f.set(`${a}
6
+ ${c}`,(f.get(`${a}
7
+ ${c}`)??0)+1),new Map);function gn({now:i=Date.now,hold:f=wr,limit:a=pr,quiet:c=hr}={}){let p=new Map,m=new Map,k=new Map,y=new Map,u=new Map;return{wrote(g,b){y.set(g,M(b))},judge(g,{source:b,mtime:N}){if(b===null)return p.delete(g),k.delete(g),{held:!1,signs:[],wait:0,own:!1};let E=M(b),x=u.get(g)?.hash===E?u.get(g).signs:null;x||(x=Bt(b),u.set(g,{hash:E,signs:x}));let X=i(),C=(L,j=!1)=>(p.delete(g),m.set(g,yn(x)),k.set(g,b),{held:!1,signs:[],wait:L,own:j});if(y.get(g)===E)return C(0,!0);let Q=m.get(g)??new Map,Y=yn(x);if([...Y].some(([L,j])=>j>(Q.get(L)??0))){let L=Math.min(N,X),j=p.get(g)??L;p.set(g,j);let Z=Math.min(f-(X-L),a-(X-j));if(Z>0)return{held:!0,signs:x.filter(({key:te,tag:H})=>Y.get(`${te}
8
+ ${H}`)>(Q.get(`${te}
9
+ ${H}`)??0)),wait:Z,own:!1,taken:k.get(g)}}return C(Math.min(c,Math.max(0,c-(X-N))))}}}import{todoRef as yr}from"../browser/shared/workspace-query.mjs";var kr=(i,f)=>i.length===f.length&&i.every((a,c)=>a===f[c]);function bn(i,f,a,c){let p=qt(f),m=Qt(a,{at:!0}),k=null,y=u=>(k??=It(a).units).find(g=>g.elStart===u)??null;return c.map(u=>{let g=yr(u?.ref);if(!g||g.slug!==i||typeof u.done!="boolean")return{reason:"ref"};let b=g.block?m.find(E=>E.block===g.block)??null:null;if(b&&b.text!==g.text)return{reason:"changed"};if(!b){let E=m.filter(x=>x.text===g.text&&kr(x.path,g.path));if(g.version===p)b=E.find(x=>x.nth===g.nth)??null;else{if(E.length>1)return{reason:"ambiguous"};b=E[0]??null}}if(!b)return{reason:"changed"};let N=y(b.at);return N?{unit:N,done:b.done,want:u.done}:{reason:"locked"}})}function $n(i,f){let a=new Map,c=f.map(u=>{if(!u.unit)return!1;let g=a.has(u.unit.id)?a.get(u.unit.id):u.done;return a.set(u.unit.id,u.want),g!==u.want}),p=new Map;for(let u of f)u.unit&&a.get(u.unit.id)!==u.done&&p.set(u.unit.id,u);if(p.size===0)return{commit:null,changed:c};let m=[],k=[],y=new Map;for(let[u,g]of p){let b=`todo${m.length}`,N=g.unit.blockId?{key:b,id:g.unit.blockId}:{key:b,open:u,hash:Et(i,g.unit)};m.push({key:b,unit:N,attribute:"data-checked",value:a.get(u)?"":null}),k.push(N),y.set(u,b)}return{commit:{units:m,touch:k,keys:y},changed:c}}import{EMPTY_STYLE as Ir,emptyWordsScript as Dr,showEmpty as Fr}from"../browser/editor/components/placeholder.mjs";import{HOST_NAMES as Pr,KIND_NAMES as Jr}from"../browser/editor/components/registry.mjs";import{TOKENS as Lr}from"../browser/editor/page/look.mjs";import{MARGIN_STYLE as _r,earlyMarginScript as Ur}from"../browser/editor/page/margin.mjs";var mt=/^[a-f0-9]{16}$/,wt=2*1024*1024,Wr=Nr,xn=50,vn=3,Sn=200,se="\u6587\u4EF6\u4E00\u518D\u88AB\u4FEE\u6539\uFF08\u4F8B\u5982 AI \u6B63\u5728\u5199\u5165\uFF09\uFF0C\u7A0D\u540E\u518D\u540C\u6B65",Hr="\u8FD9\u6B21\u7684\u4FEE\u6539\u592A\u5927\uFF0C\u4E00\u6B21\u5B58\u4E0D\u4E0B",Br=250,ce=Symbol("again"),Kr="/__gallery/edit/src/editor/page/editor.mjs",Cr=i=>new Promise(f=>setTimeout(f,i));function Yr(i,f=wt){return new Promise((a,c)=>{let p=[],m=0;i.on("data",k=>{m+=k.length,m>f?p.length=0:p.push(k)}),i.on("end",()=>m>f?c(new Error("too-large")):a(Buffer.concat(p).toString("utf8"))),i.on("error",c)})}function Vr(i){if(!i)return Ce(16).toString("hex");let f=I.join(i,"token");try{let c=Sr(f,"utf8").trim();if(/^[a-f0-9]{32}$/.test(c))return c}catch{}let a=Ce(16).toString("hex");try{vr(i,{recursive:!0,mode:448}),Or(f,a,{mode:384})}catch{}return a}function fa({base:i="",token:f=null,reportsDirectory:a=Tr,stateDirectory:c=null,write:p=lt,ids:m=!0,finish:k=N=>N,log:y=null,settling:u={},reviewing:g={},onChanges:b=()=>{}}={}){let N=f??Vr(br().data),E=gn(u),x=u.wait??kn,X=new Map,C=async(e,n,t,r="reader")=>{let o=await p(e,n,t);if(o!==!1&&Rr(I.basename(e))){let w=I.basename(I.dirname(e));E.wrote(w,n),X.set(w,{hash:M(n),by:r})}return o},Q=e=>Er(e,a),Y=e=>Pe(Q(e)).html,V=new Map,L=c&&I.join(c,"snapshots"),j=Promise.resolve(),Z=Promise.resolve(),je=async(e,n,t,{by:r="time"}={})=>{let o=(await B.readdir(e)).filter(l=>n.test(l));if(o.length<=t)return;let w=r==="name"?o.sort():(await Promise.all(o.map(async l=>({name:l,time:(await B.stat(I.join(e,l))).mtimeMs})))).sort((l,h)=>l.time-h.time).map(({name:l})=>l);await Promise.all(w.slice(0,w.length-t).map(l=>B.rm(I.join(e,l),{force:!0})))},te=(e,n)=>{L&&(j=j.then(async()=>{let t=I.join(L,`${e}.html`),r=new Date;try{await B.utimes(t,r,r);return}catch{}await B.mkdir(L,{recursive:!0}),await lt(t,n),await je(L,/^[a-f0-9]{16}\.html$/,xn)}).catch(()=>{}))},H=(e,n,t={})=>{if(!c||typeof n!="string"||!G.test(e))return Promise.resolve(null);let r=j.then(()=>an(De(c,e),n,t)).catch(()=>null);return j=r,r},s=(e,n)=>typeof n!="string"||X.get(e)?.hash===M(n)?Promise.resolve(null):H(e,n,{kind:"write"}),d=new Map,S=e=>c&&I.join(c,"receipts",e),v=(e,n,t,r)=>{for(d.set(`${e} ${n}`,{digest:t,answer:r});d.size>Sn*4;)d.delete(d.keys().next().value);let o=S(e);o&&(j=j.then(async()=>{await B.mkdir(o,{recursive:!0}),await lt(I.join(o,`${n}.json`),JSON.stringify({digest:t,answer:r})),await je(o,{test:w=>w.endsWith(".json")&&ut.test(w.slice(0,-5))},Sn)}).catch(()=>{}))},_=async(e,n)=>{let t=d.get(`${e} ${n}`);if(t)return t;let r=S(e);if(!r)return null;await j;try{let o=JSON.parse(await B.readFile(I.join(r,`${n}.json`),"utf8"));return typeof o?.digest=="string"&&o.answer?.ok?o:null}catch{return null}},K=new Map,D=(e,n)=>{let t=new Date().toISOString();if(!c)return void K.set(e,[...K.get(e)??[],{time:t,changes:n}].slice(-20));j=j.then(()=>pn({stateDirectory:c,reportsDirectory:a,slug:e,time:t,changes:n})).catch(()=>{})},ne=async e=>{if(!c){let n=K.get(e)??[];return K.delete(e),n}return await j,hn({stateDirectory:c,reportsDirectory:a,slug:e})},fe=(e,n)=>{for(V.delete(e),V.set(e,n);V.size>xn;)V.delete(V.keys().next().value);te(e,n)},Me=async e=>{if(V.has(e))return V.get(e);if(!L||!mt.test(e))return null;await j;let n=await B.readFile(I.join(L,`${e}.html`),"utf8").catch(()=>null);return n===null||M(n)!==e?null:(fe(e,n),n)},me=new Map,oe=e=>{let n=me.get(e);if(n)return n;let t=Ee(e,{finish:k});for(me.set(e,t);me.size>8;)me.delete(me.keys().next().value);return t},On=I.join(I.resolve(a),".gallery","pages"),A=en({...g,stateDirectory:c,shown:e=>oe(e).text,folderOf:Q,log:y,isPage:e=>I.resolve(Q(e)).startsWith(On+I.sep)}),we=(e,n)=>n.then(t=>{t&&b(e)},t=>y?.(`${e}: the Agent's changes not kept (${t.message})`));async function Ye(e,n=void 0){if(typeof e!="string"||!G.test(e))return null;let t=Y(e),r=n!==void 0?n:await B.readFile(t,"utf8").catch(()=>null);if(r===null)return null;let{text:o,changes:w}=oe(r);return{file:t,source:r,text:o,version:M(o),changes:w}}async function re(e){if(typeof e!="string"||!G.test(e))return{source:null,held:!1,signs:[],wait:0,own:!1};let n=Y(e),t=await B.readFile(n,"utf8").catch(()=>null),r=(await B.stat(n).catch(()=>null))?.mtimeMs??0;return{source:t,...E.judge(e,{source:t,mtime:r})}}async function Ne(e,n=Date.now()+x){for(;;){let t=await re(e);if(!t.held||Date.now()>=n)return t;await Cr(Math.max(0,Math.min(Br,n-Date.now())))}}async function Ve(e,{wait:n=x}={}){let t=await Ne(e,Date.now()+n),r=await Ye(e,t.held&&t.taken!==void 0?t.taken:t.source);return r&&{...r,held:t.held===!0}}function jn(e,n,{editor:t=Kr,kitTags:r=()=>[]}={}){let{html:o,map:w}=Ft(n);fe(w.version,n);let l=Tt(),h=At(l).map(({assets:F,...U})=>({...U,kit:r(F)})),$=`<script type="application/json" id="doc-edit-map" data-doc-dev>${JSON.stringify({slug:e,token:N,...w,components:h,hidden:l.settings.hidden}).replace(/</g,"\\u003c")}</script>
10
+ <script data-doc-dev>document.currentScript.remove(); import(${JSON.stringify(t)});</script>`,R=`<style data-doc-dev>.doc-display { display: none; }</style>
11
+ <style data-doc-dev data-ge-palette>${Lr}</style>
12
+ <style data-doc-dev>${Ir}</style>
13
+ <script data-doc-dev>${Dr()}</script>
14
+ <script data-doc-dev>document.currentScript.remove(); document.documentElement.setAttribute("data-ge-order", "file");</script>
15
+ <style data-doc-dev data-ge-margin-style>${_r}</style>
16
+ <script data-doc-dev>document.currentScript.remove(); ${Ur(gr(e,i),{notes:xr(I.join(Q(e),jr))})}</script>`;return{html:Fr(o),snippet:$,head:R}}let Mn=e=>fe(M(e),e);function pt(e){if(e.method!=="POST")return[405,{ok:!1,reason:"method"}];let n=e.headers.host??"",t=e.socket.localPort;return n!==`127.0.0.1:${t}`&&n!==`localhost:${t}`?[403,{ok:!1,reason:"host"}]:e.headers.origin!==`http://${n}`?[403,{ok:!1,reason:"origin"}]:e.headers["x-gallery-token"]!==N?[403,{ok:!1,reason:"token"}]:null}async function le(e,n=wt){let t=pt(e);if(t)return{error:t};if(!/^application\/json\b/i.test(e.headers["content-type"]??""))return{error:[415,{ok:!1,reason:"type"}]};try{return{body:JSON.parse(await Yr(e,n))}}catch(r){return{error:r.message==="too-large"?[413,{ok:!1,reason:"body",message:Hr}]:[400,{ok:!1,reason:"body"}]}}}async function ze(e,n){let{slug:t,opening:r,known:o=null,texts:w=[],units:l=[],touch:h=[],pageIds:O=null,request:$=null,agent:R=!1}=e;if(typeof t!="string"||!G.test(t)||![w,l,h].every(Array.isArray))return[400,{ok:!1,reason:"body"}];if($!==null&&(typeof $!="string"||!ut.test($)))return[400,{ok:!1,reason:"body"}];let F=$===null?null:M(JSON.stringify([r??null,w,l,h])),U=await ht(e);if(U)return U;let T=q=>($!==null&&v(t,$,F,q),[200,q]),P=Y(t),z=typeof r=="string"&&mt.test(r)?await Me(r):null,W=q=>$r("sha256",N).update(`${t}
17
+ ${q}`).digest("hex").slice(0,32);for(let q=1;;q++){let{source:ee,held:ue}=await re(t);if(ee===null)return[404,{ok:!1,reason:"missing"}];if(ue)return Date.now()<n?ce:[409,{ok:!1,reason:"busy",message:se}];s(t,ee),we(t,A.look(t,ee));let{text:Ae,changes:nt}=oe(ee),St=[],We=Jt({current:Ae,opening:z,texts:w,units:l,touch:h,ids:m?()=>{let He=typeof m=="function"?m():rt();return St.push(He),He}:!1,seal:W,pageIds:O}),{title:Ot,icon:jt,...Mt}=We,be=We.text===Ae?Ae:k(We.text);be!==We.text&&(Mt.version=M(be));let Nt={...Mt,foreign:typeof o=="string"&&M(Ae)!==o};if(be===Ae)return T({ok:!0,...Nt,wrote:!1,notes:[]});if(H(t,ee,{kind:"write"}),!await C(P,be,{expect:ee},R===!0?"agent":"reader")){if(q===vn)return[409,{ok:!1,reason:"busy",message:se}];continue}H(t,be,{by:R===!0?"agent":"reader",kind:"commit"}),we(t,A.wrote(t,be,He=>{let Zn=0;return Vt(He,{opening:z,texts:w,units:l,touch:h,pageIds:O,seal:W,ids:m?()=>St[Zn++]??(typeof m=="function"?m():rt()):!1})},{reader:R!==!0})),nt.length&&(y&&y(ot(P,nt).join(`
18
+ `)),D(t,nt));let zn=[...Ot?await Je(I.dirname(P),Ot):[],...jt!==void 0?await Qe(I.dirname(P),jt):[]];return T({ok:!0,...Nt,wrote:!0,notes:zn})}}async function Nn(e,n){return typeof e!="string"||!G.test(e)?[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}]:!Array.isArray(n)||n.length===0||n.length>Ar?[400,{ok:!1,reason:"body"}]:Le({slug:e},async(t,r)=>{let{source:o,held:w}=await re(e);if(o===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(w)return Date.now()<r?ce:[409,{ok:!1,reason:"busy",message:se}];let{text:l}=oe(o),h=bn(e,o,l,n),{commit:O,changed:$}=$n(l,h),R=h.map((W,q)=>W.reason?{ok:!1,reason:W.reason}:{ok:!0,changed:$[q],block:W.unit.blockId??null});if(!O)return[200,{ok:!0,results:R,wrote:!1}];let F=M(l);fe(F,l);let U=await ze({slug:e,opening:F,units:O.units,touch:O.touch},r);if(U===ce)return ce;let[T,P]=U;if(!P.ok)return[T,P];let z=new Map((P.units??[]).map(W=>[W.key,W]));return[200,{ok:!0,wrote:P.wrote===!0,results:R.map((W,q)=>{if(!W.ok)return W;let ee=O.keys.get(h[q].unit.id);if(ee===void 0)return W;let ue=z.get(ee);return ue?.status!=="applied"?{ok:!1,reason:ue?.reason==="ambiguous"?"ambiguous":"changed"}:{...W,block:P.ids?.[ee]??W.block}})}]})}async function ht({slug:e,opening:n,texts:t=[],units:r=[],touch:o=[],request:w=null}){if(typeof e!="string"||!G.test(e)||typeof w!="string"||!ut.test(w)||![t,r,o].every(Array.isArray))return null;let l=await _(e,w);return l?l.digest===M(JSON.stringify([n??null,t,r,o]))?[200,{...l.answer,again:!0}]:[409,{ok:!1,reason:"request",message:"\u540C\u4E00\u6B21\u4FDD\u5B58\u7684\u5185\u5BB9\u4E0D\u4E00\u81F4"}]:null}async function Tn(e,n){let{slug:t,opening:r,texts:o=[],units:w=[],instances:l=[],pageIds:h=null}=e;if(typeof t!="string"||!G.test(t)||!Array.isArray(o)||!Array.isArray(w)||!Array.isArray(l))return[400,{ok:!1,reason:"body"}];let{source:O,held:$}=await re(t);if($)return Date.now()<n?ce:[409,{ok:!1,reason:"busy",message:se}];let R=await Ye(t,O);if(R===null)return[404,{ok:!1,reason:"missing"}];let{text:F,version:U}=R,T=typeof r=="string"&&mt.test(r)?await Me(r):null;return[200,{ok:!0,version:U,reverted:Ut({current:F,opening:T,texts:o,pageIds:h}),units:Lt({current:F,units:w}),parts:_t({current:F,instances:l,pageIds:h})}]}let An=600*1e3,pe=new Map,En=()=>{for(let[e,n]of pe)Date.now()-n.at>An&&pe.delete(e)};async function yt(e,n,t,r){En();let o=typeof n=="string"?pe.get(n):null;return!o||o.slug!==e?[404,{ok:!1,reason:"gone",message:"\u64A4\u9500\u5DF2\u7ECF\u8FC7\u671F"}]:t!==o.after?[409,{ok:!1,reason:"moved-on",message:o.kind==="restore"?"\u6062\u590D\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500":"\u64A4\u56DE\u4E4B\u540E\u6587\u6863\u53C8\u6539\u8FC7\u4E86\uFF0C\u6CA1\u6CD5\u64A4\u9500"}]:(H(e,t,{kind:"write"}),await C(Y(e),o.before,{expect:t},r)?(H(e,o.before,{by:r,kind:"undo"}),pe.delete(n),await Ze(e,o.before),await A.restore(e,o.saved),await A.wrote(e,o.before),b(e),[200,{ok:!0,version:M(oe(o.before).text)}]):[409,{ok:!1,reason:"busy",message:se}])}async function Ze(e,n){let t=Q(e),r=null;try{r=JSON.parse(await B.readFile(Pe(t).json,"utf8"))}catch{}let{title:o,icon:w}=Ht(n,r);o&&typeof r?.title=="string"&&r.title!==o.to&&await Je(t,{from:r.title,to:o.to,synced:!0}),w&&!w.missing&&await Qe(t,w.to)}async function Rn(e,n){let{slug:t,action:r,stamp:o=null,undo:w=null,agent:l=!1}=e;if(typeof t!="string"||!G.test(t)||!["accept","revert","undo"].includes(r))return[400,{ok:!1,reason:"body"}];let h=l===!0?"agent":"reader",O=Y(t),{source:$,held:R}=await re(t);if($===null)return[404,{ok:!1,reason:"missing"}];if(R)return Date.now()<n?ce:[409,{ok:!1,reason:"busy",message:se}];if(r==="undo")return yt(t,w,$,h);s(t,$),await A.look(t,$);let F=await A.snapshot(t),U=F?.state?.base?`${F.state.since}|${F.state.writes}`:null;if(U===null)return[200,{ok:!0,none:!0}];if(U!==o)return[409,{ok:!1,reason:"changed",message:"Agent \u521A\u521A\u53C8\u6539\u4E86\u6587\u6863\uFF0C\u518D\u770B\u4E00\u773C"}];if(r==="accept")return await A.clear(t),b(t),[200,{ok:!0}];let T=F.base,P=H(t,$,{kind:"write"});if(!await C(O,T,{expect:$},h))return[409,{ok:!1,reason:"busy",message:se}];H(t,T,{by:h,kind:"revert"}),await Ze(t,T);let z=Ce(8).toString("hex");pe.set(z,{slug:t,before:$,after:T,saved:F,at:Date.now(),kind:"revert"}),await A.clear(t),await A.wrote(t,T),b(t);let W=l===!0?Ge(T,$,kt):null;return[200,{ok:!0,version:M(oe(T).text),undo:z,...l===!0?{kept:await P,...W}:{}}]}let In=8,kt=40,he=new Map;function Ge(e,n,t=1/0){let r=`${M(e)} ${M(n)} ${t}`;if(he.has(r))return he.get(r);let o=null;try{o=Kt(Ee(e,{finish:k}).text,Ee(n,{finish:k}).text)}catch(h){y?.(`history: a version not compared (${h.message})`)}let w=h=>({...h,name:h.title?"\u6807\u9898":Jr[h.kind]??Pr[h.kind]??"\u5757"}),l=o?{counts:o.counts,blocks:o.blocks.slice(0,t).map(w),...o.blocks.length>t?{more:o.blocks.length-t}:{}}:{counts:{added:0,changed:0,removed:0},blocks:[]};for(he.set(r,l);he.size>200;)he.delete(he.keys().next().value);return l}async function gt(e){let{source:n}=await re(e);return n!==null&&s(e,n),await j,{source:n,versions:c?await it(De(c,e),{text:!0}):[]}}async function Dn(e){let{source:n,versions:t}=await gt(e);if(n===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];let r=M(n),o=t.map(({text:w,...l},h)=>({...l,current:h===t.length-1&&l.version===r,...h===0?{counts:null,blocks:[]}:Ge(t[h-1].text,w,In)}));return[200,{ok:!0,current:r,versions:o.reverse()}]}async function Fn(e,n){let{source:t,versions:r}=await gt(e);if(t===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];let o=ct(r,n);if(o.refused)return[404,{ok:!1,reason:o.refused==="ambiguous"?"ambiguous":"version",message:"\u627E\u4E0D\u5230\u8FD9\u4E2A\u7248\u672C",...o.candidates?{candidates:o.candidates}:{}}];let{text:w,...l}=o.version,h={rows:[],more:0};try{h=Ct(Ee(w,{finish:k}).text)}catch{}return[200,{ok:!0,...l,current:l.version===M(t),...h}]}async function Pn(e,n){let{slug:t,action:r,version:o,undo:w=null,agent:l=!1}=e,h=l===!0?"agent":"reader",O=Y(t),{source:$,held:R}=await re(t);if($===null)return[404,{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"}];if(R)return Date.now()<n?ce:[409,{ok:!1,reason:"busy",message:se}];if(r==="undo")return yt(t,w,$,h);s(t,$),await j;let F=c?await it(De(c,t),{text:!0}):[],U=ct(F,o);if(U.refused)return[404,{ok:!1,reason:U.refused==="ambiguous"?"ambiguous":"version",message:"\u627E\u4E0D\u5230\u8FD9\u4E2A\u7248\u672C",...U.candidates?{candidates:U.candidates}:{}}];let{text:T,id:P,time:z}=U.version;if(T===$)return[200,{ok:!0,same:!0,restored:P,restoredAt:z}];await A.look(t,$);let W=await A.snapshot(t),q=H(t,$,{kind:"write"});if(!await C(O,T,{expect:$},h))return[409,{ok:!1,reason:"busy",message:se}];let ee=H(t,T,{by:h,kind:"restore",from:P});await Ze(t,T);let ue=Ce(8).toString("hex");return pe.set(ue,{slug:t,before:$,after:T,saved:W,at:Date.now(),kind:"restore"}),h==="reader"?(await A.clear(t),await A.wrote(t,T,null,{reader:!0})):await A.look(t,T),b(t),[200,{ok:!0,version:M(oe(T).text),undo:ue,kept:await q,restored:P,restoredAt:z,made:await ee,...h==="agent"?Ge(T,$,kt):{}}]}async function bt(e){let{slug:n,action:t}=e??{};return typeof n!="string"||!G.test(n)||!["versions","show","restore","undo"].includes(t)?[400,{ok:!1,reason:"body"}]:t==="versions"?Dn(n):t==="show"?Fn(n,e.version):Le(e,Pn)}async function Jn(e,n){let t=await le(e);if(t.error)return J(n,...t.error);let r=t.body??{};if(r.workspace!==void 0&&(typeof r.workspace!="string"||!dt(r.workspace,a)))return J(n,409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"});try{return J(n,...await bt(r))}catch(o){return J(n,500,{ok:!1,reason:"write",message:o.message})}}async function $t(e){if(e?.action!=="read")return Le(e??{},Rn);if(typeof e.slug!="string"||!G.test(e.slug))return[400,{ok:!1,reason:"body"}];let n=await Ve(e.slug,{wait:0});return n===null?[404,{ok:!1,reason:"missing"}]:(s(e.slug,n.source),[200,{ok:!0,...await A.read(e.slug,n.source)}])}async function Ln(e,n){let t=await le(e);if(t.error)return J(n,...t.error);let r=t.body??{};if(r.workspace!==void 0&&(typeof r.workspace!="string"||!dt(r.workspace,a)))return J(n,409,{ok:!1,reason:"elsewhere",message:"\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"});try{return J(n,...await $t(r))}catch(o){return J(n,500,{ok:!1,reason:"write",message:o.message})}}async function Je(e,{from:n,to:t,synced:r}){let o=["\u6807\u9898\u5DF2\u66F4\u65B0",...r?[]:["\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"]],w=Pe(e).json,l=await B.readFile(w,"utf8").catch(()=>""),h=null;try{h=JSON.parse(l)}catch{}if(h?.title!==n)return[...o,"\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 O=new RegExp(`("title"\\s*:\\s*)${JSON.stringify(n).replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}`),$=O.test(l)?l.replace(O,(R,F)=>F+JSON.stringify(t)):`${JSON.stringify({...h,title:t},null,2)}
19
+ `;try{await C(w,$)}catch(R){return y?.(`${I.basename(w)}'s title was not written (${R.code??R.message}): ${w}`),[...o,"\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 o}async function Qe(e,n){let t=Pe(e).json,r=null;try{r=JSON.parse(await B.readFile(t,"utf8"))}catch{}if(!r||typeof r!="object")return y?.(`${I.basename(t)} could not be read, so its icon was not written: ${t}`),["\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((r.icon??null)===n)return[];let{icon:o,...w}=r,l=n===null?w:{...w,icon:n};try{await C(t,`${JSON.stringify(l,null,2)}
20
+ `)}catch(h){return y?.(`${I.basename(t)}'s icon was not written (${h.code??h.message}): ${t}`),["\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 _n(e,n){let t=typeof n=="string"?n.replace(/\s+/g," ").trim():"";if(!t)return{ok:!1,reason:"title",message:"\u6807\u9898\u4E0D\u80FD\u4E3A\u7A7A"};let r=Y(e),o=await B.readFile(r,"utf8").catch(()=>null);if(o===null)return{ok:!1,reason:"missing"};s(e,o),we(e,A.look(e,o));let w=Rt(o),l=Dt(w).find($=>$.kind==="title");if(!l)return{ok:!1,reason:"no-title",message:"\u8FD9\u4EFD\u6587\u6863\u6CA1\u6709\u6807\u9898"};let h=Mr(t),O=Pt({current:w,edits:[{id:l.id,parts:[{keep:!0,html:h}]}],ids:m});return O.ok?O.text!==o&&!await C(r,O.text,{expect:o})?{ok:!1,reason:"changed-again"}:(O.text!==o&&(H(e,O.text,{by:"reader",kind:"rename"}),we(e,A.wrote(e,O.text,$=>zt($,h)))),{ok:!0,title:t,notes:O.title?await Je(I.dirname(r),O.title):[]}):{ok:!1,reason:"conflict"}}let Te=e=>(n,t)=>{let r=Z.then(()=>e(n));return Z=r.catch(()=>{}),r.then(([o,w])=>J(t,o,w),o=>J(t,500,{ok:!1,reason:"write",message:o.message}))},xt=(e,{early:n=null}={})=>async(t,r)=>{let o=await le(t);if(o.error)return J(r,...o.error);let w=o.body??{};try{let l=n&&await n(w);return l?J(r,...l):J(r,...await Le(w,e))}catch(l){return J(r,500,{ok:!1,reason:"write",message:l.message})}};async function Le(e,n){let t=Date.now()+x;for(;;){await Ne(e.slug,t);let r=Z.then(()=>n(e,t));Z=r.catch(()=>{});let o=await r;if(o!==ce)return o}}async function qe(e,{reader:n=!1}={}){if(typeof e!="string"||!G.test(e))return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};let t=Q(e),{html:r,json:o}=Pe(t);for(let w=1;;w++){let{source:l,held:h}=n?await re(e):{source:await B.readFile(r,"utf8").catch(()=>null),held:!1};if(l===null)return{ok:!1,reason:"missing",message:"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"};if(h)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"};s(e,l),we(e,A.look(e,l));let O=null;try{O=JSON.parse(await B.readFile(o,"utf8"))}catch{}let{text:$,changes:R,added:F,given:U,repeated:T,title:P,icon:z}=Wt(l,{finish:k,next:typeof m=="function"?m:void 0,metadata:O});if($!==l){if(H(e,l,{kind:"write"}),!await C(r,$,{expect:l},n?"reader":"agent")){if(w===vn)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}H(e,$,{by:n?"reader":"agent",kind:"hand-in"}),we(e,A.wrote(e,$)),n&&R.length&&(y&&y(ot(r,R).join(`
21
+ `)),D(e,R))}return P&&typeof O?.title=="string"&&O.title!==P.to&&await Je(t,{from:O.title,to:P.to,synced:P.page}),z&&!z.missing&&await Qe(t,z.to),{ok:!0,changes:$===l?[]:R,added:$===l?0:F,given:$===l?[]:U,repeated:T,written:$!==l,title:P,icon:z}}}let Un=async(e,{reader:n=!1}={})=>{n&&await Ne(e);let t=Z.then(()=>qe(e,{reader:n}));return Z=t.catch(()=>{}),t};async function Xe(e){let n=await le(e);if(n.error)return{refused:n.error};let{slug:t,workspace:r}=n.body??{};return typeof t!="string"||!G.test(t)||typeof r!="string"?{refused:[400,{ok:!1,reason:"body"}]}:dt(r,a)?{slug:t}:{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 Wn(e,n){try{let t=Z.then(async()=>{let{slug:w,refused:l}=await Xe(e);if(l)return{answer:l};let h=await qe(w);return{slug:h.ok?w:null,answer:[h.ok?200:h.reason==="missing"?404:409,h]}});Z=t.catch(()=>{});let{slug:r,answer:o}=await t;return r&&await _e(r),J(n,...o)}catch(t){return J(n,500,{ok:!1,reason:"write",message:t.message})}}async function Hn(e){let{slug:n,refused:t}=await Xe(e);return t||(await _e(n),[200,{ok:!0}])}async function vt(e){let{source:n}=await Ne(e);s(e,n);let{ended:t,moved:r}=await A.endDraft(e,n);return r&&b(e),t}async function Bn(e){let{slug:n,refused:t}=await Xe(e);return t||[200,{ok:!0,ended:await vt(n)}]}let ye=Gt({reportsDirectory:a}),ke=Zt({reportsDirectory:a,read:e=>Ve(e,{wait:0}),write:C,dropped:(e,n)=>{let t=n.map(un);y&&y(ft(I.join(Q(e),"annotations.json"),{items:t}).join(`
22
+ `)),c&&(j=j.then(()=>dn({stateDirectory:c,reportsDirectory:a,slug:e,time:new Date().toISOString(),items:t})).catch(()=>{}))}}),et=Promise.resolve(),tt=e=>{let n=et.then(e);return et=n.catch(()=>{}),n},Kn=e=>(n,t)=>tt(()=>e(n)).then(([r,o])=>J(t,r,o),r=>J(t,500,{ok:!1,reason:"write",message:r.message})),Cn=300,ge=new Map;async function _e(e){let n=ge.get(e);n&&(clearTimeout(n.timer),ge.delete(e));let t=tt(()=>ke.afterWrite(e));n&&t.then(n.resolve,n.reject),await t.catch(r=>y?.(`${e}: annotations not checked: ${r.message}`)),await j}let Yn=e=>{let n=e.headers.host??"",t=e.socket.localPort;return n!==`127.0.0.1:${t}`&&n!==`localhost:${t}`?[403,{ok:!1,reason:"host"}]:e.headers["x-gallery-token"]!==N?[403,{ok:!1,reason:"token"}]:null};async function Vn(e){if(e.method==="GET"){let t=Yn(e);if(t)return t;let r=new URL(e.url??"/","http://localhost").searchParams,o=r.get("as");return o==="copy"?ke.copy(r.get("slug")):o==="notes"?ke.notes(r.get("slug")):ke.list(r.get("slug"))}let n=await le(e);return n.error??ke.change(n.body)}let Ue=(e,n=wt)=>async t=>{let r=await le(t,n);return r.error??e(r.body)};return{token:N,preview:jn,opened:Mn,check:le,checkHeaders:pt,upload:Te(Ue(ye.upload,Wr)),addEmoji:Te(Ue(ye.addEmoji)),unfurl:Te(Ue(ye.unfurl)),annotations:Kn(Vn),checkAnnotations(e){let n=ge.get(e);return n||(n={timer:0},n.done=new Promise((t,r)=>Object.assign(n,{resolve:t,reject:r})),ge.set(e,n)),clearTimeout(n.timer),n.timer=setTimeout(()=>{ge.delete(e),tt(()=>ke.afterWrite(e)).then(n.resolve,n.reject)},Cn),n.done},frameable:Te(Ue(ye.frameable)),listEmojis:ye.listEmojis,readEmoji:ye.readEmoji,respond:Te,keepVersion:H,renameReport:_n,read:Ye,settled:re,writerOf:(e,n)=>typeof n=="string"&&X.get(e)?.hash===M(n)?X.get(e).by:null,whenTaken:Ne,readTaken:Ve,takeRewrites:ne,handIn:Un,handInReport:qe,handInRequest:Wn,settleRequest:(e,n)=>Hn(e).then(([t,r])=>J(n,t,r),t=>J(n,500,{ok:!1,reason:"write",message:t.message})),settleNotes:_e,roundRequest:(e,n)=>Bn(e).then(([t,r])=>J(n,t,r),t=>J(n,500,{ok:!1,reason:"write",message:t.message})),beginRound:vt,commit:xt(ze,{early:ht}),handleCommit:ze,setTodos:Nn,reverted:xt(Tn),changes:Ln,changesAction:$t,history:Jn,historyAction:bt,noteTaken:async(e,n)=>{let t=s(e,n),r=await A.look(e,n);return await t,r},async takeAll(e){let n=[];for(let t of e){if(typeof t!="string"||!G.test(t))continue;let{source:r,held:o}=await re(t).catch(()=>({source:null}));typeof r!="string"||o||(s(t,r),await A.look(t,r).catch(()=>!1)&&(n.push(t),b(t)))}return n},forgetChanges:async e=>{if(await A.forget(e),!c||typeof e!="string"||!G.test(e))return;let n=j.then(()=>B.rm(De(c,e),{recursive:!0,force:!0,maxRetries:3})).catch(()=>{});j=n,await n},drain:async()=>{await Z,await Promise.all([...ge.keys()].map(_e)),await et,await A.idle(),await j},stored:async()=>{await A.idle(),await j}}}export{wo as a,po as b,hn as c,$o as d,wr as e,pr as f,hr as g,Vr as h,fa as i};
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{b as D}from"./chunk-VRPVVMRB.mjs";import{g as I}from"./chunk-HX4DLE3J.mjs";import{a as $}from"./chunk-HYMEEXKN.mjs";import{e as E,j as F}from"./chunk-ECZBLQKK.mjs";import d from"node:fs/promises";import x from"node:path";import{isInstance as T}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as _}from"../browser/shared/components/installed.mjs";import{exportSourceOf as z}from"../browser/shared/export-wrap.mjs";import{sha256 as b}from"../browser/shared/files.mjs";import{attr as w,hasClass as k}from"../browser/shared/html-tree.mjs";import{reportsDirectory as j}from"../browser/shared/paths.mjs";import{documentDirectory as G,documentFiles as H,layoutOf as B}from"../browser/shared/workspace.mjs";function K(e,t=null){return e.tagName==="figure"&&k(e,"doc-figure")||e.tagName==="div"&&(k(e,"doc-code")||k(e,"doc-diff"))||t===R||T(e)||k(e,"doc-flow")||k(e,"doc-sheet-shell")||w(e,"data-doc-sheets")!==void 0?0:e.tagName==="figure"||k(e,"doc-columns")?1:k(e,"doc-table-wrap")?2:3}function Q(e){let t=new Map,s=new Map;for(let a of E(e).units)a.blockId&&!s.has(a.blockId)&&s.set(a.blockId,a.kind);let l=new Map,n=new Map,c=new Map,i=a=>!!a.tagName&&w(a,"data-block-id")!==void 0,u=(a,f)=>{if(a.nodeName==="#text")return a.value;if(!a.tagName||a.tagName==="template")return"";let r=w(a,"data-doc-chart-data")?.trim();r&&l.get(f).push(r);let o=w(a,"data-doc-chart-source")?.trim();o&&!n.has(o)&&n.set(o,f);let h=a.attrs.map(({name:g,value:y})=>`${g}="${y}"`).sort().join(" ");return`<${a.tagName} ${h}>${(a.childNodes??[]).map(g=>i(g)?"":u(g,f)).join("")}</${a.tagName}>`},p=(a,f)=>{for(let r of a.childNodes??[]){if(!r.tagName||r.tagName==="template")continue;let o=w(r,"data-block-id"),h=f;if(o!==void 0&&!t.has(o)){let g=[r.tagName,...(w(r,"class")??"").split(/\s+/).filter(Boolean).slice(0,1)].join("."),y=c.get(f)??0;c.set(f,y+1),l.set(o,[]);let M=K(r,s.get(o)),N=r.sourceCodeLocation,U=N?(N.endOffset??N.startTag?.endOffset??N.startOffset)-N.startOffset:0,S=u(r,o).replace(L," ");t.set(o,{hash:b(S).slice(0,16),bare:b(S.replace(`data-block-id="${o}"`,"")).slice(0,16),rank:M,card:M<3,whole:s.get(o)===R,figure:s.get(o)===Y,tag:g,parent:f,at:y,size:U,package:T(r)?w(r,_)??null:null}),h=o}p(r,h)}};p($(e),null);let m=new Map([...t].map(([a,{hash:f,bare:r}])=>[a,{hash:f,bare:r}]));for(let[a,f]of l){let r=f.map(o=>m.get(n.get(o))).filter(Boolean);r.length&&(t.get(a).hash=b([m.get(a).hash,...r.map(({hash:o})=>o)].join("|")).slice(0,16),t.get(a).bare=b([m.get(a).bare,...r.map(({bare:o})=>o)].join("|")).slice(0,16))}return t}function V(e){let t=[],s=l=>{for(let n of l.childNodes??[])if(!(!n.tagName||n.tagName==="template"||w(n,"data-block-id")!==void 0))if(n.tagName==="script"||n.tagName==="style"){let c=n.attrs.map(({name:i,value:u})=>`${i}="${u}"`).sort().join(" ");t.push(`<${n.tagName} ${c}>${(n.childNodes??[]).map(i=>i.value??"").join("")}`.replace(L," "))}else s(n)};return s($(e)),t.length?b(t.join("|")).slice(0,16):""}var X=e=>Object.fromEntries(I(e).map(({id:t,stamp:s})=>[t,s])),R="block",Y="figure",L=/[ \t\n\f\r]+/g,Z=["export","preview"];function tt(e){if(e==null)return null;try{let{blocks:t,places:s,moved:l,unseen:n,from:c,time:i,idless:u,page:p,packages:m}=JSON.parse(e)??{};if(!t||typeof t!="object"||Array.isArray(t))return null;let a=s&&typeof s=="object"&&!Array.isArray(s)?s:{},f=r=>Array.isArray(r)?r.filter(o=>typeof o=="string"):[];return{blocks:Object.fromEntries(Object.entries(t).filter(([,r])=>typeof r=="string")),places:Object.fromEntries(Object.entries(a).filter(([,r])=>Array.isArray(r)&&r.length===2&&(r[0]===null||typeof r[0]=="string")&&Number.isInteger(r[1]))),moved:f(l),unseen:f(n),...Z.includes(c)?{from:c,time:Number.isFinite(i)?i:null}:{},...f(u).length?{idless:f(u)}:{},...typeof p=="string"?{page:p}:{},...m&&typeof m=="object"&&!Array.isArray(m)?{packages:Object.fromEntries(Object.entries(m).filter(([,r])=>typeof r=="string"))}:{}}}catch{return null}}var A="ge-idless-";function et(e,{from:t,time:s}){let l=0,{text:n}=F(D(e).text,()=>`${A}${l++}`),c=X(n),i={blocks:{},places:{},moved:[],unseen:[],from:t,time:s,page:V(n),...Object.keys(c).length?{packages:c}:{}},u=[];for(let[p,{hash:m,bare:a,card:f,parent:r,at:o}]of Q(n)){if(p.startsWith(A)){u.push(a);continue}i.blocks[p]=m,r?.startsWith(A)||(i.places[p]=[r,o]),f&&i.unseen.push(p)}return u.length?{...i,idless:u}:i}function bt(e,t){if(!t?.idless?.length)return t;let s=new Map;for(let c of t.idless)s.set(c,(s.get(c)??0)+1);let l={...t,blocks:{...t.blocks},unseen:[...t.unseen]};for(let[c,{hash:i,bare:u,card:p}]of e)Object.hasOwn(t.blocks,c)||!s.get(u)||(s.set(u,s.get(u)-1),l.blocks[c]=i,p&&l.unseen.push(c));let n=[...s].flatMap(([c,i])=>Array(i).fill(c));return n.length?l.idless=n:delete l.idless,l}var st=/<[^>]*\sdata-doc-placeholder\b/,O=(e,t)=>x.join(B(t).qa,e),P=(e,t)=>x.join(O(e,t),"blocks.json"),W=(e,t)=>x.join(O(e,t),"exported.html");async function q(e,t=j){return tt(await d.readFile(P(e,t),"utf8").catch(()=>null))!==null}async function C(e,t,s,l=j){let n=B(l).state,c=async o=>d.readFile(o).then(h=>({bytes:h,file:o}),()=>null),i=await c(W(e,l)),u=[i];if(t){let o=t.slice(0,16),h=x.join(n,"history",e),g=await d.readdir(h).catch(()=>[]);u.push(...await Promise.all(g.filter(y=>y.endsWith(`-${o}.html`)).map(y=>c(x.join(h,y))))),u.push(await c(x.join(n,"snapshots",`${o}.html`)))}let p=i?(await d.stat(i.file).catch(()=>null))?.mtimeMs??null:null,a=!(i&&t&&s!==null&&p!==null&&p>s&&b(i.bytes)!==t)&&t&&u.find(o=>o&&b(o.bytes)===t),f=a||i;if(!f)return null;let r=a&&s!==null?s:f===i?p??s:(await d.stat(f.file).catch(()=>null))?.mtimeMs??s;return{text:f.bytes.toString("utf8"),time:r??null}}async function v(e,t){let s=B(t).exports,l=x.join(s,`${e}.html`),[n,c]=await Promise.all([d.readFile(l,"utf8").catch(()=>null),d.stat(l).catch(()=>null)]);return n===null||!c?null:{said:z(n),time:c.mtimeMs}}async function J(e,t,s,l){if(st.test(t))return!1;let n=et(t,s);return!Object.keys(n.blocks).length&&!n.idless?!1:(await d.mkdir(O(e,l),{recursive:!0}),await d.writeFile(P(e,l),`${JSON.stringify(n)}
2
+ import{g as D}from"./chunk-5IHDLEB4.mjs";import{b as F}from"./chunk-VRPVVMRB.mjs";import{a as $}from"./chunk-HYMEEXKN.mjs";import{e as I,j as E}from"./chunk-ECZBLQKK.mjs";import d from"node:fs/promises";import x from"node:path";import{isInstance as T}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as _}from"../browser/shared/components/installed.mjs";import{exportSourceOf as z}from"../browser/shared/export-wrap.mjs";import{sha256 as b}from"../browser/shared/files.mjs";import{attr as w,hasClass as k}from"../browser/shared/html-tree.mjs";import{reportsDirectory as j}from"../browser/shared/paths.mjs";import{documentDirectory as G,documentFiles as H,layoutOf as B}from"../browser/shared/workspace.mjs";function K(e,t=null){return e.tagName==="figure"&&k(e,"doc-figure")||e.tagName==="div"&&(k(e,"doc-code")||k(e,"doc-diff"))||t===R||T(e)||k(e,"doc-flow")||k(e,"doc-sheet-shell")||w(e,"data-doc-sheets")!==void 0?0:e.tagName==="figure"||k(e,"doc-columns")?1:k(e,"doc-table-wrap")?2:3}function Q(e){let t=new Map,s=new Map;for(let a of I(e).units)a.blockId&&!s.has(a.blockId)&&s.set(a.blockId,a.kind);let l=new Map,n=new Map,c=new Map,i=a=>!!a.tagName&&w(a,"data-block-id")!==void 0,u=(a,f)=>{if(a.nodeName==="#text")return a.value;if(!a.tagName||a.tagName==="template")return"";let r=w(a,"data-doc-chart-data")?.trim();r&&l.get(f).push(r);let o=w(a,"data-doc-chart-source")?.trim();o&&!n.has(o)&&n.set(o,f);let h=a.attrs.map(({name:g,value:y})=>`${g}="${y}"`).sort().join(" ");return`<${a.tagName} ${h}>${(a.childNodes??[]).map(g=>i(g)?"":u(g,f)).join("")}</${a.tagName}>`},p=(a,f)=>{for(let r of a.childNodes??[]){if(!r.tagName||r.tagName==="template")continue;let o=w(r,"data-block-id"),h=f;if(o!==void 0&&!t.has(o)){let g=[r.tagName,...(w(r,"class")??"").split(/\s+/).filter(Boolean).slice(0,1)].join("."),y=c.get(f)??0;c.set(f,y+1),l.set(o,[]);let M=K(r,s.get(o)),N=r.sourceCodeLocation,U=N?(N.endOffset??N.startTag?.endOffset??N.startOffset)-N.startOffset:0,S=u(r,o).replace(L," ");t.set(o,{hash:b(S).slice(0,16),bare:b(S.replace(`data-block-id="${o}"`,"")).slice(0,16),rank:M,card:M<3,whole:s.get(o)===R,figure:s.get(o)===Y,tag:g,parent:f,at:y,size:U,package:T(r)?w(r,_)??null:null}),h=o}p(r,h)}};p($(e),null);let m=new Map([...t].map(([a,{hash:f,bare:r}])=>[a,{hash:f,bare:r}]));for(let[a,f]of l){let r=f.map(o=>m.get(n.get(o))).filter(Boolean);r.length&&(t.get(a).hash=b([m.get(a).hash,...r.map(({hash:o})=>o)].join("|")).slice(0,16),t.get(a).bare=b([m.get(a).bare,...r.map(({bare:o})=>o)].join("|")).slice(0,16))}return t}function V(e){let t=[],s=l=>{for(let n of l.childNodes??[])if(!(!n.tagName||n.tagName==="template"||w(n,"data-block-id")!==void 0))if(n.tagName==="script"||n.tagName==="style"){let c=n.attrs.map(({name:i,value:u})=>`${i}="${u}"`).sort().join(" ");t.push(`<${n.tagName} ${c}>${(n.childNodes??[]).map(i=>i.value??"").join("")}`.replace(L," "))}else s(n)};return s($(e)),t.length?b(t.join("|")).slice(0,16):""}var X=e=>Object.fromEntries(D(e).map(({id:t,stamp:s})=>[t,s])),R="block",Y="figure",L=/[ \t\n\f\r]+/g,Z=["export","preview"];function tt(e){if(e==null)return null;try{let{blocks:t,places:s,moved:l,unseen:n,from:c,time:i,idless:u,page:p,packages:m}=JSON.parse(e)??{};if(!t||typeof t!="object"||Array.isArray(t))return null;let a=s&&typeof s=="object"&&!Array.isArray(s)?s:{},f=r=>Array.isArray(r)?r.filter(o=>typeof o=="string"):[];return{blocks:Object.fromEntries(Object.entries(t).filter(([,r])=>typeof r=="string")),places:Object.fromEntries(Object.entries(a).filter(([,r])=>Array.isArray(r)&&r.length===2&&(r[0]===null||typeof r[0]=="string")&&Number.isInteger(r[1]))),moved:f(l),unseen:f(n),...Z.includes(c)?{from:c,time:Number.isFinite(i)?i:null}:{},...f(u).length?{idless:f(u)}:{},...typeof p=="string"?{page:p}:{},...m&&typeof m=="object"&&!Array.isArray(m)?{packages:Object.fromEntries(Object.entries(m).filter(([,r])=>typeof r=="string"))}:{}}}catch{return null}}var A="ge-idless-";function et(e,{from:t,time:s}){let l=0,{text:n}=E(F(e).text,()=>`${A}${l++}`),c=X(n),i={blocks:{},places:{},moved:[],unseen:[],from:t,time:s,page:V(n),...Object.keys(c).length?{packages:c}:{}},u=[];for(let[p,{hash:m,bare:a,card:f,parent:r,at:o}]of Q(n)){if(p.startsWith(A)){u.push(a);continue}i.blocks[p]=m,r?.startsWith(A)||(i.places[p]=[r,o]),f&&i.unseen.push(p)}return u.length?{...i,idless:u}:i}function bt(e,t){if(!t?.idless?.length)return t;let s=new Map;for(let c of t.idless)s.set(c,(s.get(c)??0)+1);let l={...t,blocks:{...t.blocks},unseen:[...t.unseen]};for(let[c,{hash:i,bare:u,card:p}]of e)Object.hasOwn(t.blocks,c)||!s.get(u)||(s.set(u,s.get(u)-1),l.blocks[c]=i,p&&l.unseen.push(c));let n=[...s].flatMap(([c,i])=>Array(i).fill(c));return n.length?l.idless=n:delete l.idless,l}var st=/<[^>]*\sdata-doc-placeholder\b/,O=(e,t)=>x.join(B(t).qa,e),P=(e,t)=>x.join(O(e,t),"blocks.json"),W=(e,t)=>x.join(O(e,t),"exported.html");async function q(e,t=j){return tt(await d.readFile(P(e,t),"utf8").catch(()=>null))!==null}async function C(e,t,s,l=j){let n=B(l).state,c=async o=>d.readFile(o).then(h=>({bytes:h,file:o}),()=>null),i=await c(W(e,l)),u=[i];if(t){let o=t.slice(0,16),h=x.join(n,"history",e),g=await d.readdir(h).catch(()=>[]);u.push(...await Promise.all(g.filter(y=>y.endsWith(`-${o}.html`)).map(y=>c(x.join(h,y))))),u.push(await c(x.join(n,"snapshots",`${o}.html`)))}let p=i?(await d.stat(i.file).catch(()=>null))?.mtimeMs??null:null,a=!(i&&t&&s!==null&&p!==null&&p>s&&b(i.bytes)!==t)&&t&&u.find(o=>o&&b(o.bytes)===t),f=a||i;if(!f)return null;let r=a&&s!==null?s:f===i?p??s:(await d.stat(f.file).catch(()=>null))?.mtimeMs??s;return{text:f.bytes.toString("utf8"),time:r??null}}async function v(e,t){let s=B(t).exports,l=x.join(s,`${e}.html`),[n,c]=await Promise.all([d.readFile(l,"utf8").catch(()=>null),d.stat(l).catch(()=>null)]);return n===null||!c?null:{said:z(n),time:c.mtimeMs}}async function J(e,t,s,l){if(st.test(t))return!1;let n=et(t,s);return!Object.keys(n.blocks).length&&!n.idless?!1:(await d.mkdir(O(e,l),{recursive:!0}),await d.writeFile(P(e,l),`${JSON.stringify(n)}
3
3
  `),!0)}async function kt(e,t=j){let s=new Map(await Promise.all(e.map(async n=>[n,await v(n,t).catch(()=>null)])));return{keep:async(n,c=null)=>{for(let i of n)try{if(!await q(i,t)){let m=s.get(i),a=await C(i,m?.said??null,m?.time??null,t);a&&await J(i,a.text,{from:"export",time:a.time},t)}let[u,p]=await Promise.all([d.readFile(H(G(i,t)).html),c?{said:c.get(i)??null}:v(i,t)]);p?.said&&b(u)===p.said&&(await d.mkdir(O(i,t),{recursive:!0}),await d.writeFile(W(i,t),u))}catch{}}}}async function xt(e,t,s=j){try{if(await q(e,s))return!1;let l=await v(e,s),n=await C(e,l?.said??null,l?.time??null,s);return await J(e,n?.text??t,n?{from:"export",time:n.time}:{from:"preview",time:Date.now()},s)}catch{return!1}}export{K as a,Q as b,V as c,X as d,Z as e,tt as f,et as g,bt as h,q as i,C as j,kt as k,xt as l};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a,b,c,d,e,f,g,h}from"./chunk-X4WNLFIK.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-NOGQX56R.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{e as forgetKept,a as handInReports,f as idLines,g as inStepLines,d as noteNew,b as previewSettled,h as rereadLine,c as roundBegins};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as a}from"./chunk-XNNCQROX.mjs";import"./chunk-LJZIYVNA.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{a as createWorkspaceService};
@@ -0,0 +1,7 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as pe,b as At}from"./chunk-342HXE3Q.mjs";import{c as ge,d as me}from"./chunk-OKVQQ3CX.mjs";import{b as re}from"./chunk-X4WNLFIK.mjs";import{b as le,d as ce,e as de,f as he,h as zt,i as fe,l as ue}from"./chunk-LHGKPMTI.mjs";import{b as Ht,c as ne,d as se,f as ae,h as ie}from"./chunk-TQZU7D7C.mjs";import{g as oe}from"./chunk-5IHDLEB4.mjs";import{a as ee}from"./chunk-HYMEEXKN.mjs";import{b as jt,j as te}from"./chunk-L4WLQYFC.mjs";import{a as Vt}from"./chunk-UMHUSOPJ.mjs";import{spawnSync as Ie}from"node:child_process";import xt from"node:fs/promises";import ht from"node:path";import{pathToFileURL as Fe}from"node:url";import{MATH_IGNORED_TAGS as De}from"../browser/shared/components/math.mjs";import{exportPackagesOf as _e,exportSourceOf as Pe,packagesSaid as Ve}from"../browser/shared/export-wrap.mjs";import{sha256 as we}from"../browser/shared/files.mjs";import{attr as $e}from"../browser/shared/html-tree.mjs";import{projectRoot as He,qaDirectory as ze,reportsDirectory as Bt}from"../browser/shared/paths.mjs";import{documentDirectory as Lt,documentFiles as It}from"../browser/shared/workspace.mjs";import{KINDS as tn,LEVELS as Ot,LOOKS as Ut,WIDE as en,WIDTHS as on,layoutNotesOf as Ue,levelOf as qe}from"../browser/shared/qa-levels.mjs";import{tableHidesScript as Ge}from"../browser/shared/table-hides.mjs";var Ye=new Set(["code-scrolls","formula-scrolls"]),Ae=(e,o)=>e.level??qe(e.kind,o),Ke=(e,o)=>["fail","warn"].includes(Ae(e,o))||Ye.has(e.kind)&&qe(e.kind,o)==="info",Xe=4,Je=12,Oe=60,Qe=8,Ze=2,xe=200,to=2e3,ye=600;function eo({block:e,above:o=null,below:s=null}){let r=[e,o,s].filter(Boolean),i=Math.min(...r.map(u=>u.left)),c=Math.max(...r.map(u=>u.right)),$=o?Math.max(Math.min(o.top,e.top),e.top-xe):e.top,h=s?Math.min(Math.max(s.bottom,e.bottom),e.bottom+xe):e.bottom,f=(u,y)=>({x:Math.max(0,i),y:Math.max(0,u),width:c-i,height:y-Math.max(0,u)});return e.bottom-e.top<=to?[{part:"",clip:f($,h)}]:[{part:"top",clip:f($,e.top+ye)},{part:"bottom",clip:f(e.bottom-ye,h)}]}function be(e,o=""){if(e.startsWith("data:"))return`${e.slice(0,30)}\u2026 (${e.length} characters)`;let s=o.slice(0,o.lastIndexOf("/")+1);if(s&&e.startsWith(s)&&e.length>s.length)try{return decodeURIComponent(e.slice(s.length))}catch{return e.slice(s.length)}return e.length>60?`\u2026${e.slice(-59)}`:e}var Ft=e=>String(e??"").replace(/\s+/g," ").trim(),Mt=(e,o=40)=>{let s=Ft(e);return`"${s.length>o?`${s.slice(0,o-1)}\u2026`:s}"`},oo=e=>String(e??"").replace(/\s+/g,"").slice(0,120);function no(e,o="doc.html"){let s=new Map,r=new Map,i=new Map,c=(f,u)=>(u&&f.sourceCodeLocation.attrs?.[u]||f.sourceCodeLocation).startLine,$=new Map,h=f=>{if(f.nodeName==="#text")return f.value;if(!f.tagName&&f.nodeName!=="#document"||f.tagName==="template")return"";let u=(f.childNodes??[]).map(h).join("");if(!f.tagName||!f.sourceCodeLocation)return u;let y=$e(f,"data-block-id");y!==void 0&&!s.has(y)&&s.set(y,c(f,"data-block-id"));let F=$e(f,"id");F!==void 0&&!r.has(F)&&r.set(F,c(f,"id"));let Y=oo(u);if(Y.length>=2){let m=`${f.tagName}|${Y}`;$.has(m)||$.set(m,[]),$.get(m).push(f.sourceCodeLocation)}return u};h(ee(e));for(let[f,u]of $)i.set(f,u.sort((y,F)=>y.startOffset-F.startOffset).map(y=>y.startLine));return{blocks:s,ids:r,texts:i,name:o}}function so(e,o){if(!e)return"the page";let s=o.name??"doc.html",r=u=>{let y=u&&o.texts.get(`${u.tag}|${u.words}`);return y?.[Math.min(u.nth??0,y.length-1)]},i=e.table||e.header?.text,c=e.card?` card ${Mt(e.card.text)}`:i?` table ${Mt(i)}`:"",$=e.blocks?.find(u=>o.blocks.has(u));if($!==void 0)return`${s}:${o.blocks.get($)} [data-block-id="${$}"]${c}`;if(r(e.card))return`${s}:${r(e.card)} card ${Mt(e.card.text)}`;if(r(e.header))return`${s}:${r(e.header)} table ${Mt(i)}`;let h=e.texts?.find(r);if(h)return`${s}:${r(h)} ${h===e.texts[0]&&h.tag===e.tag?"":`${e.element} in `}<${h.tag}> ${Mt(h.text,32)}`;let f=e.ids?.find(u=>o.ids.has(u));return f!==void 0?`${s}:${o.ids.get(f)} #${f}${c}`:r(e.section)?`${s}:${r(e.section)} ${e.element} in the section ${Mt(e.section.text)}`:`${e.element}${c} (not found in ${s})`}function Jt(e){let o=new Date(e),s=c=>String(c).padStart(2,"0"),r=-o.getTimezoneOffset(),i=`${r<0?"-":"+"}${s(Math.floor(Math.abs(r)/60))}:${s(Math.abs(r)%60)}`;return`${o.getFullYear()}-${s(o.getMonth()+1)}-${s(o.getDate())}T${s(o.getHours())}:${s(o.getMinutes())}:${s(o.getSeconds())}${i}`}function ao(e,o,s={said:"",now:""}){return e===o?s.said===s.now?{stale:!1,why:""}:{stale:!0,packaged:!0,why:`it holds ${s.said||"no custom block"}, the workspace has ${s.now||"none of them"}`}:{stale:!0,why:e?`made from a text whose sha256 is ${e.slice(0,12)}\u2026, the file's is ${o.slice(0,12)}\u2026`:"it does not say which text it was made from: made before exports said it, or before the kit's names were doc-* (2026-10-26), whose pages gallery qa no longer reads"}}async function Qt(e,{made:o=!1}={}){let s=It(Lt(e,Bt)).html,r=At(e),[i,c]=await Promise.all([xt.readFile(s).catch(()=>null),xt.stat(r).catch(()=>null)]);if(!i)return{problem:`${e}: no document (${s})`};if(!c)return{problem:`${e}: no export (${r}): run gallery export ${e} first`,missing:!0};let $=await xt.readFile(r),h=$.toString("utf8"),f=Pe(h),u={said:_e(h),now:Ve(oe(i.toString("utf8")))},{stale:y,why:F,packaged:Y=!1}=ao(f,we(i),u);return y&&!o?{problem:`${e}: ${r} is not of ${s} as it is now (${F}): run gallery export ${e} first`,stale:!0,why:F,edited:!!f&&!Y,packaged:Y}:{file:r,sha256:we($),time:c.mtimeMs}}function io(e,o){let s=e.map(($,h)=>({length:1,weight:o[h],previous:-1})),r=($,h)=>$.length>h.length||$.length===h.length&&$.weight>h.weight;e.forEach(($,h)=>{for(let f=0;f<h;f++){if(e[f]>=$)continue;let u={length:s[f].length+1,weight:s[f].weight+o[h],previous:f};r(u,s[h])&&(s[h]=u)}});let i=-1;s.forEach(($,h)=>{(i<0||r($,s[i]))&&(i=h)});let c=[];for(let $=i;$>=0;$=s[$].previous)c.unshift($);return c}function Re(e,o){let s=o?.places??{},r=new Set((o?.moved??[]).filter(c=>e.has(c))),i=new Map;for(let[c,{parent:$,size:h=0}]of e){let f=s[c];if(f){if(f[0]!==$){r.add(c);continue}i.has($)||i.set($,[]),i.get($).push({id:c,at:f[1],size:h})}}for(let c of i.values()){let $=new Set(io(c.map(({at:h})=>h),c.map(({size:h})=>h)).map(h=>c[h].id));for(let{id:h}of c)$.has(h)||r.add(h)}return r}function ro(e,o,s,{named:r=null,verified:i=!0,failed:c=!1,seen:$=null,page:h=void 0,packages:f=void 0}={}){if(!i||c||r&&!o)return null;let u=$??new Set([...s.ids,...[...s.held?.values()??[]].flat()]),y=!o,F=y||s.pageChanged?s.cards??[]:[],Y=[...o?.unseen??[],...F],m={blocks:{},places:{},moved:y?[]:[...Re(e,o)].filter(b=>!u.has(b)),unseen:[...new Set(Y)].filter(b=>e.has(b)&&!u.has(b))};for(let[b,{hash:K,parent:X,at:yt}]of e){let U=y||u.has(b)?K:o.blocks[b];U!==void 0&&(m.blocks[b]=U),m.places[b]=[X,yt]}let B=!y&&(r||s.tiles)?o.page:h;typeof B=="string"&&(m.page=B);let I=!y&&(r||s.tiles)?o.packages:f&&Object.fromEntries(Object.entries(f).map(([b,K])=>[b,(s.restyled?.get(b)??[]).every(X=>u.has(X))?K:o.packages[b]]));return I&&Object.keys(I).length&&(m.packages=I),m}function Zt(e){let o=new Map;for(let s of e){let r=new Set(s.held?.covered??[]);for(let i of s.held?.missed??[])r.has(i)||o.set(i,[...o.get(i)??[],s.label??String(s.width)])}return o}function lo(e,o){let s=Zt(o);return new Set([...e.ids,...[...e.held?.values()??[]].flat().filter(r=>!s.has(r))])}function Se(e){let o=e.time?` of ${Jt(e.time)}`:"";return e.from==="export"?`the export${o} (the document before these changes)`:e.from==="preview"?`gallery open${o} (the document before these changes)`:"the last look"}var co=3;function ho(e,o,s=null,{tiles:r=!1,page:i=void 0,packages:c=void 0,complete:$=!1}={}){let h={rest:[],unknown:[],moved:new Set,around:new Map,held:new Map,groups:[],cards:[],pageChanged:!1,changed:new Set,restyled:new Map,left:null},f=[...e.keys()],u=new Map(f.map((a,R)=>[a,R])),y=o?Re(e,o):new Set,F=a=>typeof o?.packages?.[a]=="string"&&typeof c?.[a]=="string"&&o.packages[a]!==c[a],Y=o?f.filter(a=>F(e.get(a).package)&&o.blocks[a]===e.get(a).hash&&!y.has(a)):[],m=new Map;for(let a of Y)m.set(e.get(a).package,[...m.get(e.get(a).package)??[],a]);let B=new Set(Y),I=o?f.filter(a=>o.blocks[a]!==e.get(a).hash||y.has(a)||B.has(a)):[],b=new Set((o?.unseen??[]).filter(a=>e.has(a)&&!I.includes(a))),K=(a,R)=>{let nt=null;for(let Z=e.get(a).parent;Z!==null&&e.has(Z);Z=e.get(Z).parent)R.has(Z)&&(nt=Z);return nt},X=new Set(I),yt=new Set(I.filter(a=>e.get(a).card||y.has(a))),U=a=>X.has(a)&&!y.has(a)&&K(a,yt)===null,et=new Map;for(let a of f)for(let R=e.get(a).parent;R!==null&&e.has(R);R=e.get(R).parent){let nt=et.get(R)??{all:0,changed:0};nt.all+=1,U(a)&&(nt.changed+=1),et.set(R,nt)}let it=f.filter(a=>!e.get(a).card&&et.has(a)&&et.get(a).changed>=co&&et.get(a).changed*2>=et.get(a).all);if(s){let a=[...new Set(s)].filter(l=>e.has(l)),R=new Set(a),nt=new Map;for(let l of f){let E=R.has(l)?null:K(l,R);E!==null&&nt.set(E,[...nt.get(E)??[],l])}let Z="the blocks named",mt=new Set([...a,...[...nt.values()].flat()]),lt=!!o&&typeof o.page=="string"&&typeof i=="string"&&o.page!==i,Tt=new Set([...I.filter(l=>e.get(l).card||y.has(l)),...it]),Nt=!o||lt?f.filter(l=>e.get(l).card&&!I.includes(l)):[],Pt=new Set([...Tt,...Nt]),t=[...I,...it.filter(l=>!X.has(l))].sort((l,E)=>u.get(l)-u.get(E)).filter(l=>!mt.has(l)&&K(l,Tt)===null),n=t.filter(l=>B.has(l)),d={changed:t.filter(l=>!B.has(l)),...n.length?{restyled:n,packages:[...new Set(n.map(l=>e.get(l).package))]}:{},cards:Nt.filter(l=>!mt.has(l)&&K(l,Pt)===null).sort((l,E)=>e.get(l).rank-e.get(E).rank||u.get(l)-u.get(E)),since:o?Se(o):"",first:!o};return{...h,ids:a,why:Z,groups:[{kind:"named",why:Z,ids:a,rest:[]}],held:nt,pageChanged:lt,changed:new Set(I),restyled:m,left:d,unknown:[...new Set(s)].filter(l=>!e.has(l))}}if(e.size===0)return{...h,ids:[],why:"the document has no block ids (never handed in): the whole page in tiles instead",tiles:!0};if(r)return{...h,ids:[],why:null,tiles:!0};let V=(...a)=>(R,nt)=>a.reduce((Z,mt)=>Z||mt(R)-mt(nt),0),ft=a=>e.get(a).rank,k=a=>u.get(a),O=o?Se(o):"",g=!!o&&typeof o.page=="string"&&typeof i=="string"&&o.page!==i,q=f.filter(a=>e.get(a).card&&!I.includes(a)),T=!o||g||I.length===0?q:q.filter(a=>b.has(a)),H=new Set([...I.filter(a=>e.get(a).card||y.has(a)),...it]),z=new Set([...H,...T]),ct=new Map,rt=(a,R)=>a.filter(nt=>{let Z=K(nt,R);return Z!==null&&ct.set(Z,[...ct.get(Z)??[],nt]),Z===null}),pt=[...rt(I,H),...it.filter(a=>!X.has(a)&&K(a,H)===null)].sort(V(a=>+!y.has(a),ft,k)),ut=pt.filter(a=>B.has(a)),J=pt.filter(a=>!B.has(a)),gt=rt(T,z).sort(V(a=>+!b.has(a),ft,k)),x="the cards (chart cards, code blocks, whole blocks, components, flowcharts and Sheet areas, then columns and the other figures, then tables)",P=gt.some(a=>b.has(a))?", those no look has pictured yet first":"",Q=typeof o?.page=="string"&&typeof i=="string",tt=o?g?`${x.replace("the cards","the cards, not changed themselves")}${P}: the document's own <script> or <style> changed since ${O}, which may draw any of them`:I.length?"the cards no look has pictured yet (not changed themselves)":`${x}${P}: no block changed since ${O}${Q?", nor the document's own <script> or <style>":""}`:`${x}: no earlier look to compare with`,C=[...J.length?[{kind:"changed",why:`the blocks changed since ${O}${y.size?" (a moved block pictured with the edges of the blocks before and after it, the moved ones first)":""}`,all:J}]:[],...ut.length?[{kind:"changed",why:`the instances of a custom block changed since ${O} (${[...new Set(ut.map(a=>e.get(a).package))].join(", ")})`,all:ut}]:[],...gt.length||!pt.length?[{kind:"cards",why:tt,all:gt}]:[]],M=Je,S=Oe;for(let a of C)a.ids=a.all.slice(0,Math.max(0,$&&a.kind!=="cards"?S:M)),a.rest=a.all.slice(a.ids.length),M-=a.ids.length,S-=a.ids.length,delete a.all;let G=C.flatMap(a=>a.ids),N=a=>{let{parent:R,at:nt}=e.get(a),Z=mt=>f.find(lt=>e.get(lt).parent===R&&e.get(lt).at===nt+mt)??null;return[Z(-1),Z(1)]},st=new Map(G.filter(a=>y.has(a)).map(a=>[a,N(a)])),D=new Map(G.filter(a=>ct.has(a)).map(a=>[a,ct.get(a)]));return{...h,ids:G,why:C[0].why,groups:C,rest:C.flatMap(a=>a.rest),moved:new Set(G.filter(a=>y.has(a))),around:st,held:D,cards:T,pageChanged:g,changed:new Set(I),restyled:m}}function fo(e){let o=m=>!!m.closest("[data-doc-dev]"),s=[...document.querySelectorAll("details")].filter(m=>!o(m)),r=s.filter(m=>!m.open).length;s.forEach(m=>{m.open||m.setAttribute("data-qa-closed",""),m.open=!0});let i=[...document.images].filter(m=>!o(m));i.forEach(m=>{m.loading==="lazy"&&(m.loading="eager")});let c=[...document.querySelectorAll("dialog")].filter(m=>!o(m)&&!m.open);c.forEach((m,B)=>{m.dataset.qaCard=String(B)});let $=m=>m.parentElement?.closest("dialog[data-qa-card]")??null,h=[...document.querySelectorAll("[data-doc-sheets] > .doc-sheet-tabs > [data-sheet-tab]")].filter(m=>!o(m));h.forEach((m,B)=>{m.dataset.qaTab=String(B)});let f=m=>m.parentElement.parentElement,u=m=>{let B=[];for(let I=m.closest("[data-doc-sheet]");I;I=I.parentElement.closest("[data-doc-sheet]")){let b=h.find(K=>f(K)===I.parentElement&&K.getAttribute("data-sheet-tab")===I.getAttribute("data-doc-sheet"));b&&B.unshift(Number(b.dataset.qaTab))}return B},y=h.map((m,B)=>{let I=[...u(f(m)),B],b=[...f(m).children].find(X=>X.getAttribute("data-doc-sheet")===m.getAttribute("data-sheet-tab"));b&&(b.dataset.qaPanel=String(B));let K=$(m);return{index:B,chain:I,card:K?Number(K.dataset.qaCard):null,label:(m.textContent??"").replace(/\s+/g," ").trim(),shown:I.every(X=>h[X].getAttribute("aria-selected")==="true"),panel:!!b}}),F=c.map((m,B)=>{let I=`[href="#${CSS.escape(m.id)}"]`,b=[...m.querySelectorAll("h1, h2, h3, h4")].find(X=>X.textContent.trim())??document.querySelector(I),K=[];for(let X=$(m);X;X=$(X))K.unshift(Number(X.dataset.qaCard));return{index:B,chain:u(m),within:K,label:(b?.textContent||m.id||"").replace(/\s+/g," ").trim()}}),Y=Promise.all(i.map(m=>m.decode().catch(()=>{})));return Promise.race([Y.then(()=>!0),new Promise(m=>setTimeout(()=>m(!1),e))]).then(m=>({details:s.length,closed:r,images:i.length,loaded:m,sheets:y,cards:F}))}function ve(e){let o=document.querySelector(`[data-qa-card="${e}"]`);return o?(o.open||(globalThis.DocDialogs?globalThis.DocDialogs.open(o,null):typeof o.showModal=="function"?o.showModal():o.setAttribute("open","")),document.activeElement?.blur?.(),Promise.all(o.getAnimations({subtree:!0}).map(s=>s.finished.catch(()=>{}))).then(()=>o.open&&o.getClientRects().length>0)):Promise.resolve(!1)}function Gt(e){let o=document.querySelector(`[data-qa-card="${e}"]`);o?.open&&(globalThis.DocDialogs?globalThis.DocDialogs.close(o):typeof o.close=="function"?o.close():o.removeAttribute("open"))}async function uo({selector:e,up:o=0,margin:s=0,frames:r=2}){let i=document.querySelector(e);for(let g=0;g<o&&i;g++)i=i.parentElement;if(!i||i.getClientRects().length===0)return null;let c=i.getBoundingClientRect();i.scrollIntoView({block:"nearest",inline:"nearest"});let $=i.getBoundingClientRect();if(c.top!==$.top||c.left!==$.left){let g=()=>new Promise(q=>{requestAnimationFrame(()=>q()),setTimeout(q,100)});for(let q=0;q<r;q++)await g()}let h=g=>g===document.body||g===document.documentElement,f=(g,q,W)=>{let{left:T,top:H,right:z,bottom:ct}=g;for(let rt=q;rt&&!h(rt);rt=rt.parentElement){let pt=getComputedStyle(rt),ut=pt.overflowX!=="visible",J=pt.overflowY!=="visible";if(ut||J){let gt=rt.getBoundingClientRect();ut&&([T,z]=[Math.max(T,gt.left),Math.min(z,gt.right)]),J&&([H,ct]=[Math.max(H,gt.top),Math.min(ct,gt.bottom)])}if(rt===W)break}return z>T&&ct>H?{left:T,top:H,right:z,bottom:ct}:null},u=g=>parseFloat(g)||0,y=(g,q)=>{let W=getComputedStyle(g,q);if(["none","normal"].includes(W.content)||W.display==="none"||!["absolute","fixed"].includes(W.position))return null;let T=W.position==="fixed"?null:getComputedStyle(g).position!=="static"?g:g.offsetParent,H=T?T.getBoundingClientRect():{left:0,top:0,right:innerWidth,bottom:innerHeight},z=T?getComputedStyle(T):null,ct={left:H.left+u(z?.borderLeftWidth),top:H.top+u(z?.borderTopWidth),right:H.right-u(z?.borderRightWidth),bottom:H.bottom-u(z?.borderBottomWidth)},rt=(x,P)=>W.boxSizing==="border-box"?0:u(W[`padding${x}`])+u(W[`padding${P}`])+u(W[`border${x}Width`])+u(W[`border${P}Width`]),pt=u(W.width)+rt("Left","Right"),ut=u(W.height)+rt("Top","Bottom"),J=W.left!=="auto"?ct.left+u(W.left)+u(W.marginLeft):W.right!=="auto"?ct.right-u(W.right)-u(W.marginRight)-pt:null,gt=W.top!=="auto"?ct.top+u(W.top)+u(W.marginTop):W.bottom!=="auto"?ct.bottom-u(W.bottom)-u(W.marginBottom)-ut:null;return J===null||gt===null||!(pt>0)||!(ut>0)?null:f({left:J,top:gt,right:J+pt,bottom:gt+ut},g,i)},F=[i.getBoundingClientRect()],Y=[i];for(let g of i.querySelectorAll("*"))g instanceof SVGElement&&g.ownerSVGElement||g.matches("script, style, template")||g.getClientRects().length===0||getComputedStyle(g).visibility!=="hidden"&&(Y.push(g),F.push(f(g.getBoundingClientRect(),g.parentElement,i)));for(let g of Y)F.push(y(g,"::before"),y(g,"::after"));let m=document.createRange(),B=document.createTreeWalker(i,NodeFilter.SHOW_TEXT);for(let g=B.nextNode();g;g=B.nextNode())if(!(!g.nodeValue.trim()||!g.parentElement||g.parentElement.closest("svg, script, style, template"))){m.selectNodeContents(g);for(let q of m.getClientRects())F.push(f(q,g.parentElement,i))}m.detach();let I=F.filter(Boolean),b={left:Math.min(...I.map(g=>g.left)),top:Math.min(...I.map(g=>g.top)),right:Math.max(...I.map(g=>g.right)),bottom:Math.max(...I.map(g=>g.bottom))},K=f(b,i.parentElement,null)??b,X=!1;for(let g=i;g&&!X;g=g.parentElement)X=getComputedStyle(g).position==="fixed";let yt=visualViewport.pageLeft,U=visualViewport.pageTop,[et,it]=X?[yt+innerWidth,U+innerHeight]:[document.documentElement.scrollWidth,document.documentElement.scrollHeight],V=Math.max(X?yt:0,K.left+yt-s),ft=Math.max(X?U:0,K.top+U-s),k=Math.min(et,K.right+yt+s),O=Math.min(it,K.bottom+U+s);return k>V&&O>ft?{clip:{x:V,y:ft,width:k-V,height:O-ft},fixed:X}:null}function ke(e){for(let s of e){let r=document.querySelector(`[data-qa-tab="${s}"]`);r&&r.getAttribute("aria-selected")!=="true"&&r.click()}let o=document.querySelector(`[data-qa-panel="${e.at(-1)}"]`);return!!(o&&!o.hidden&&o.getClientRects().length>0)}function Yt({scope:e,next:o,ignored:s=[],place:r,slack:i=4,whole:c=[],drawn:$=[]}){let h=e?document.querySelector(e):document.body,f=[];if(!h)return{found:f,next:o};let u=document.documentElement.clientWidth,y=Math.round,F=t=>String(t??"").replace(/\s+/g," ").trim(),Y=(t,n=32)=>{let d=F(t);return`"${d.length>n?`${d.slice(0,n-1)}\u2026`:d}"`},m=t=>!!t.closest?.("[data-doc-dev]"),B=t=>{if(!t.isConnected||t.getClientRects().length===0)return!1;for(let n=t;n&&n.nodeType===1;n=n.parentElement){let d=getComputedStyle(n);if(d.visibility==="hidden"||d.display==="none"||Number(d.opacity)===0||n.matches(".katex-mathml, .sr-only, [role=tooltip], [data-doc-dev]"))return!1}return!0},I=t=>`${t.localName}${[...t.classList].filter(n=>!n.startsWith("is-")).slice(0,2).map(n=>`.${n}`).join("")}`,b=t=>(t.textContent??"").replace(/\s+/g,"").slice(0,120),K=new Map,X=t=>{let n=b(t);if(!K.has(t.localName)){let l=new Map;for(let E of document.getElementsByTagName(t.localName)){if(m(E))continue;let L=b(E);l.has(L)||l.set(L,[]),l.get(L).push(E)}K.set(t.localName,l)}let d=K.get(t.localName).get(n)?.indexOf(t)??0;return{tag:t.localName,words:n,nth:Math.max(0,d),text:F(t.textContent).slice(0,80)}},yt=t=>{let n=t.cloneNode(!0);for(let d of n.querySelectorAll(".doc-tab"))d.before(" \xB7 ");return F(n.textContent).replace(/^· /,"")},U=t=>{let n=t.matches("table")?t:t.querySelector("table"),d=t.closest(".doc-table-wrap")??t,l=d.getAttribute("data-doc-chart-source")?.trim(),L=(l?[...document.querySelectorAll("[data-doc-chart-data]")].find(v=>v.getAttribute("data-doc-chart-data").trim()===l&&!m(v)):null)?.closest("figure")?.querySelector(":scope > h2, :scope > h3, :scope > h4, :scope > figcaption"),p=d.previousElementSibling;return F(n?.caption?.textContent)||F(L?.textContent)||(p?.matches("p.doc-note")?yt(p):"")||F(n?.querySelector("th")?.textContent??n?.rows[0]?.cells[0]?.textContent)},et=t=>{let n=t.nodeType===1?t:t.parentElement,d=[],l=[];for(let w=n;w&&w!==document.documentElement;w=w.parentElement)w.hasAttribute("data-block-id")&&d.push(w.getAttribute("data-block-id")),w.id&&!w.hasAttribute("data-qa-tab")&&!w.hasAttribute("data-qa-panel")&&l.push(w.id);let E=[];for(let w=n,j=0;w&&j<4&&!w.matches("body, main, section, [data-doc-sheet], [data-doc-sheets], .doc-columns, .doc-column");w=w.parentElement,j++){let ot=X(w);ot.words.length>=2&&E.push(ot)}let L=n.closest("figure")?.querySelector(":scope > h3, :scope > figcaption, :scope > .doc-figure-caption"),p=n.closest(".doc-table-wrap, table"),v=p?.querySelector("th"),A=n.closest("section")?.querySelector(":scope > h2, :scope > h3, :scope > h4");return{blocks:d,ids:l,texts:E,tag:n.localName,element:I(n),card:L?X(L):null,header:v?X(v):null,table:p?U(p).slice(0,80):null,section:A?X(A):null}};if(r){let t=document.querySelector(r);return{found:f,next:o,anchor:t?et(t):null}}let it=t=>(t.dataset.qaShot||(t.dataset.qaShot=String(++o)),Number(t.dataset.qaShot)),V=(t,n,d,{picture:l=n,url:E,measured:L,scroll:p,level:v}={})=>f.push({kind:t,what:d,anchor:n?et(n):null,shot:l?it(l):null,seen:!!(l&&B(l)),url:E,measured:L,scroll:p,...v?{level:v}:{}}),ft=t=>t.closest("figure")??t.closest("[data-doc-chart]")??t,k=t=>{let n=t.getBoundingClientRect();return n.width>0&&n.height>0},O=(t,n,{x:d=!0,y:l=!0}={})=>Math.max(d?n.left-t.left:-1/0,d?t.right-n.right:-1/0,l?n.top-t.top:-1/0,l?t.bottom-n.bottom:-1/0),g=t=>({left:Math.min(...t.map(n=>n.x)),right:Math.max(...t.map(n=>n.x)),top:Math.min(...t.map(n=>n.y)),bottom:Math.max(...t.map(n=>n.y))}),q=t=>{let n=t.getBBox(),d=t.getScreenCTM();return g([[n.x,n.y],[n.x+n.width,n.y],[n.x+n.width,n.y+n.height],[n.x,n.y+n.height]].map(([l,E])=>new DOMPoint(l,E).matrixTransform(d)))},W=t=>{let n=[];for(let d=t.parentElement;d&&d!==document.documentElement;d=d.parentElement){let l=getComputedStyle(d);d instanceof SVGSVGElement&&l.overflow!=="visible"&&n.push(["the svg's edge",d.getBoundingClientRect(),{}]);let E=/url\(\s*["']?#([^)"']+)/.exec(`${d.getAttribute?.("clip-path")??""} ${l.clipPath??""}`)?.[1],L=E?document.getElementById(E):null,p=L?.getAttribute("clipPathUnits")!=="objectBoundingBox"?L?.querySelector("rect"):null;if(p&&d.getScreenCTM){let[v,A,w,j]=["x","y","width","height"].map(ot=>p[ot].baseVal.value);n.push(["a clip-path",g([[v,A],[v+w,A+j]].map(([ot,dt])=>new DOMPoint(ot,dt).matrixTransform(d.getScreenCTM()))),{}])}if(!(d instanceof SVGElement)){let v=/hidden|clip/.test(l.overflowX),A=/hidden|clip/.test(l.overflowY);(v||A)&&n.push([I(d),d.getBoundingClientRect(),{x:v,y:A}])}}return n},T=t=>`${t.slice(0,4).join("; ")}${t.length>4?`; ${t.length-4} more`:""}`,H=t=>!t.matches("script, [data-doc-dev]")&&(t.matches("svg, canvas")||t.querySelector("svg, canvas")||B(t)&&k(t));for(let t of h.querySelectorAll("[data-doc-chart]"))m(t)||!B(t)||[...t.children].some(H)||V("chart-empty",t,`the ${t.getAttribute("data-doc-chart")||"chart"} chart drew nothing`,{picture:ft(t)});let z=[...h.querySelectorAll("svg")].filter(t=>{if(t.parentElement.closest("svg")||m(t)||t.closest(".katex, .doc-icon, button")||!B(t))return!1;let n=t.getBoundingClientRect();return t.closest("[data-doc-chart], figure")||n.width>=120&&n.height>=60}),ct={across:.6,down:.25},rt=new Map;for(let t of z){let n=ft(t),d=n.getBoundingClientRect(),l=[],E=[],L=[...t.querySelectorAll("text")].filter(A=>!A.closest("defs, clipPath, mask, pattern, marker, symbol")&&F(A.textContent)&&B(A));for(let A of L){let w=q(A),j=W(A).map(([ot,dt,wt])=>[ot,O(w,dt,wt)]).find(([,ot])=>ot>1.5);j?l.push(`${Y(A.textContent,24)} ${y(j[1])}px past ${j[0]}`):O(w,d)>1.5&&E.push(`${Y(A.textContent,24)} ${y(O(w,d))}px past the card's edge`)}l.length&&V("chart-text-clipped",t,T(l),{picture:n}),E.length&&V("chart-text-outside",t,T(E),{picture:n});let p=A=>{let w=/^(-?)[$¥€£]?(\d[\d,]*(?:\.\d+)?)\s*(?:%|‰|[kKMBG]|万|亿)?$/.exec(A.replace(/[−–]/g,"-"));return w?+`${w[1]}${w[2].replace(/,/g,"")}`:NaN},v=A=>A.every(Number.isFinite)&&A[1]!==A[0]&&A.slice(2).every((w,j)=>Math.abs(w-A[j+1]-(A[1]-A[0]))<=1e-9*Math.max(1,Math.abs(w)));for(let A of t.querySelectorAll("g")){let w=[...A.children].filter(_=>_.matches("g.tick")&&B(_)),j=w.map(_=>_.querySelector("text")).filter(_=>_&&F(_.textContent)&&B(_)),ot=j.map(_=>F(_.textContent));if(ot.length<2||ot.length!==w.length||!v(ot.map(p)))continue;let dt=j.map(_=>{let kt=_.getScreenCTM(),Le=(parseFloat(getComputedStyle(_).fontSize)||0)*(kt?Math.hypot(kt.c,kt.d):1);return{label:_,box:q(_),size:Le,turned:!!kt&&Math.abs(kt.b)>.001*Math.abs(kt.a)}});if(dt.some(_=>_.turned||!(_.size>0)))continue;let wt=dt.map(({box:_})=>[(_.left+_.right)/2,(_.top+_.bottom)/2]),at=Math.max(...wt.map(([_])=>_))-Math.min(...wt.map(([_])=>_))>=Math.max(...wt.map(([,_])=>_))-Math.min(...wt.map(([,_])=>_)),bt=({box:_,size:kt})=>at?[_.left,_.right]:[(_.top+_.bottom-kt)/2,(_.top+_.bottom+kt)/2],vt=[...dt].sort((_,kt)=>bt(_)[0]-bt(kt)[0]),St=null;for(let _=1;_<vt.length;_++){let kt=bt(vt[_])[0]-bt(vt[_-1])[1];(!St||kt<St.gap)&&(St={gap:kt,pair:[vt[_-1],vt[_]]})}let Ct=Math.max(...dt.map(_=>_.size));if(!St||St.gap>=ct[at?"across":"down"]*Ct)continue;for(let{label:_}of dt)rt.set(_,A);let[Rt,qt]=St.pair.map(({label:_})=>Y(_.textContent,16)),We=St.gap<0?`${Rt} and ${qt} overlapping by ${y(-St.gap)}px`:`${Rt} and ${qt} ${y(St.gap)}px apart`;V("ticks",t,`${ot.length} tick labels ${at?"across":"down"} a ${y(at?t.getBoundingClientRect().width:t.getBoundingClientRect().height)}px chart crowd: ${We}, under ${at?"a digit's width and a hair":"a quarter of a line"} at their ${y(Ct)}px (${ot.slice(0,6).join(", ")}${ot.length>6?", \u2026":""})`,{picture:n})}}let pt=t=>{let n=t.getBBox(),d=t instanceof SVGTextElement&&parseFloat(getComputedStyle(t).fontSize)||n.height,l=n.y+Math.max(0,(n.height-d)/2),E=l+Math.min(n.height,d),L=t.getScreenCTM();return[[n.x,l],[n.x+n.width,l],[n.x+n.width,E],[n.x,E]].map(([p,v])=>new DOMPoint(p,v).matrixTransform(L))},ut=(t,n)=>{let d=1/0;for(let l of[t,n])for(let E=0;E<l.length;E++){let L=l[E],p=l[(E+1)%l.length],v=Math.hypot(p.x-L.x,p.y-L.y);if(v===0)continue;let A={x:-(p.y-L.y)/v,y:(p.x-L.x)/v},w=wt=>wt.map(at=>at.x*A.x+at.y*A.y),[j,ot]=[w(t),w(n)],dt=Math.min(Math.max(...j),Math.max(...ot))-Math.max(Math.min(...j),Math.min(...ot));if(dt<=0)return 0;d=Math.min(d,dt)}return d===1/0?0:d},J=t=>[...t.querySelectorAll("text")].filter(n=>!n.closest("defs, clipPath, mask, pattern, marker, symbol")&&F(n.textContent)&&B(n));for(let t of z){let n=J(t).map(l=>({label:l,outline:pt(l)})),d=[];n.forEach(({label:l,outline:E},L)=>{for(let p of n.slice(L+1))rt.has(l)&&rt.get(l)===rt.get(p.label)||ut(E,p.outline)>1.5&&d.push(`${Y(l.textContent,20)} and ${Y(p.label.textContent,20)} overlap`)}),d.length&&V("chart-text-overlap",t,T(d),{picture:ft(t)})}let gt=11;for(let t of z){if(!t.hasAttribute("viewBox"))continue;let n=[];for(let E of J(t)){let L=E.getScreenCTM(),p=parseFloat(getComputedStyle(E).fontSize);if(!L||!(p>0))continue;let v=p*Math.hypot(L.c,L.d);v<gt-.05&&n.push(`${Y(E.textContent,24)} at ${v.toFixed(1)}px (font-size ${+p.toFixed(2)})`)}if(!n.length)continue;let d=t.viewBox.baseVal,l=`${n.length} text${n.length>1?"s":""}`;V("svg-text-small",t,`${l} of a drawing scaled by its viewBox (${+d.width.toFixed(2)}\xD7${+d.height.toFixed(2)} drawn ${y(t.getBoundingClientRect().width)}px wide) render below ${gt}px: ${T(n)}`,{picture:ft(t)})}let x=new Set;for(let t of h.querySelectorAll(".doc-table-wrap")){if(m(t)||!B(t))continue;x.add(t);let n=t.querySelector("table");if(!n)continue;let d=Math.max(t.clientWidth,n.offsetWidth),l=Math.max(t.clientHeight,n.offsetHeight),E=d>t.clientWidth+i,L=l>t.clientHeight+i,p=U(t);(E||L)&&V("table-scrolls",t,[E&&`${d}px wide in a ${t.clientWidth}px frame`,L&&`${l}px tall in a ${t.clientHeight}px frame`].filter(Boolean).join(", "),{scroll:{sideways:E,down:L,name:p}});let v=globalThis.__qaTableHides(t,n);v.said&&V("table-columns",t,`${v.said}: the table is ${d}px wide in a ${t.clientWidth}px frame`),v.shown<v.rows&&!t.style.getPropertyValue("--doc-table-height")&&V("table-rows",t,`the frame shows ${v.shown} of ${v.rows} rows: a reader scrolls inside it for the other ${v.rows-v.shown}; style="--doc-table-height: none" on its div.doc-table-wrap shows every row (or split the table where its content divides)`)}let P=t=>!!t.closest("details[data-qa-closed]"),Q="in a disclosure closed in the file: a reader who opens it scrolls";for(let t of h.querySelectorAll(".doc-code, .doc-diff")){if(m(t)||!B(t))continue;let n=t.querySelector(":scope > pre, :scope > .doc-diff-body");if(n&&B(n)){let l=P(t);if(n.scrollHeight>n.clientHeight+i){let E=[t,n].map(A=>A.style.getPropertyValue("--doc-code-height").trim()).find(Boolean),L=n.getBoundingClientRect().top+n.clientTop+n.clientHeight,p=[...n.querySelectorAll(".doc-code-line")].filter(A=>A.getClientRects().length>0&&A.getBoundingClientRect().top>=L-1).length,v=l?`, ${Q} inside it for the rest`:E?`, the block's own height (--doc-code-height: ${E}, the author's or the reader's): a reader scrolls inside it for the rest`:": a reader scrolls inside it for the rest";V("code-scrolls",t,`the code is ${n.scrollHeight}px tall, its frame ${n.clientHeight}px${p?` (its last ${p} line${p===1?"":"s"} below it)`:""}${v}`,{level:l||E?"info":void 0})}if(n.scrollWidth>n.clientWidth+i){let E=t.classList.contains("doc-code--nowrap"),L=l?`, ${Q} sideways for the rest`:E?", its lines left unwrapped (doc-code--nowrap, the author's or the reader's choice): a reader scrolls sideways for the rest of its long lines":": a reader scrolls sideways for the rest";V("code-scrolls",t,`the code is ${n.scrollWidth}px wide, its frame ${n.clientWidth}px${L}`,{level:l||E?"info":void 0})}}let d=t.querySelector(":scope > .doc-code-title");d&&B(d)&&d.scrollWidth>d.clientWidth+1&&V("code-title-cut",t,`its title ${Y(d.textContent,48)} is cut to fit its header (${d.scrollWidth}px of words in ${d.clientWidth}px)`)}for(let t of h.querySelectorAll(".doc-math-block")){if(m(t)||!B(t)||t.scrollWidth<=t.clientWidth+i)continue;let n=P(t);V("formula-scrolls",t,`the formula is ${t.scrollWidth}px wide, its frame ${t.clientWidth}px${n?`, ${Q} it sideways for the rest`:": a reader scrolls it sideways for the rest"}`,{level:n?"info":void 0})}for(let t of h.querySelectorAll("[data-doc-layout]"))m(t)||!B(t)||V("layout",t,t.getAttribute("data-doc-layout"),{picture:t.closest("figure, .doc-table-wrap")??t,measured:x.has(t)});let tt=document.createTreeWalker(h,NodeFilter.SHOW_TEXT),C=new Map;for(let t=tt.nextNode();t;t=tt.nextNode()){if(!/\\\(|\\\[|\$\$/.test(t.nodeValue))continue;let n=t.parentElement;if(!n||n.closest([...s,".katex","[data-doc-dev]"].join(", "))||!B(n))continue;let d=n.closest("p, li, h1, h2, h3, h4, td, th, figcaption, summary, blockquote, dd, dt")??n;C.has(d)||C.set(d,t.nodeValue)}for(let[t,n]of C){let d=n.search(/\\\(|\\\[|\$\$/);V("raw-formula",t,`${Y(n.slice(d,d+40),40)} is shown as written: the kit's math did not render it`)}for(let t of h.querySelectorAll(".katex-error"))m(t)||!B(t)||V("formula-error",t,`${Y(t.textContent,32)}: ${F(t.getAttribute("title"))||"KaTeX could not read it"}`);let M=t=>`"${globalThis.__qaUrlName?.(t,document.baseURI)??t}"`,S=t=>{try{return new URL(t,document.baseURI).href}catch{return t}},G=t=>[...["src","href","poster","data"].filter(n=>t.hasAttribute(n)&&!(n==="href"&&t.matches("a, area"))).map(n=>t.getAttribute(n)),...(t.getAttribute("srcset")??"").split(",").map(n=>n.trim().split(/\s+/)[0]),...[t.getAttribute("style"),t.localName==="style"?t.textContent:""].flatMap(n=>[...String(n??"").matchAll(/url\(\s*["']?([^"')]+)/g)].map(d=>d[1]))].filter(n=>n&&!n.trim().startsWith("#")).map(S),N=[...document.querySelectorAll("*")].filter(t=>!m(t)).flatMap(t=>G(t).map(n=>({node:t,address:n}))),st=new Set;for(let{url:t,directive:n}of globalThis.__qaViolations??[]){let d=/^[a-z][a-z\d+.-]*$/i.test(t)?`${t.toLowerCase()}:`:null,l=N.find(L=>d?!st.has(L)&&L.address.startsWith(d):L.address===t);l&&d&&st.add(l);let E=l?.node??null;e&&!(E&&h.contains(E))||V("blocked",E,`${n} blocked ${M(l?.address??t)}${E?` (${I(E)})`:""}: the export holds every file it shows`,{url:l?.address??t})}for(let t of h.querySelectorAll("img")){if(m(t)||t.complete&&t.naturalWidth>0)continue;let n=t.currentSrc||t.src?S(t.currentSrc||t.src):"";V("image",t,`${n?M(n):"a picture with no src"} did not load`,{picture:t.closest("figure")??t,url:n})}let D=new Set(c),a=new Set($),R=document.createRange(),nt="button, select, input, textarea, [data-doc-dev]",Z=(t,n)=>t!==n&&(t.matches(nt)||[...t.classList].some(d=>d.startsWith("doc-"))),mt=(t,n,d)=>{let l=[],E=!1;for(let L=t,p=!0;L&&L!==document.body&&L!==document.documentElement;L=L.parentElement,p=!1){let v=getComputedStyle(L);if((!p||d)&&(E&&(v.position!=="static"||v.transform!=="none")&&(E=!1),!E)){if(/auto|scroll/.test(v.overflowY))break;/hidden|clip/.test(v.overflowY)&&!Z(L,n)&&l.push(L)}if(v.position==="fixed")break;v.position==="absolute"&&(E=!0)}return l},lt=t=>t.getBoundingClientRect().bottom-(parseFloat(getComputedStyle(t).borderBottomWidth)||0),Tt=t=>{let n=getComputedStyle(t),d=l=>!/^(transparent|rgba\(.*,\s*0\))$/.test(l);return d(n.backgroundColor)||n.backgroundImage!=="none"||["Top","Right","Bottom","Left"].some(l=>parseFloat(n[`border${l}Width`])>0&&n[`border${l}Style`]!=="none"&&d(n[`border${l}Color`]))},Nt="rect, circle, ellipse, line, polyline, polygon, path, use",Pt=(t,n)=>{let d=new Map,l=(p,v,A,w)=>{if(!d.has(p)&&d.size>=3)return;let j=d.get(p)??{words:[],marks:[],depth:0,height:p.getBoundingClientRect().height};A&&j.words.push(A),w&&j.marks.push(w),j.depth=Math.max(j.depth,v),d.set(p,j)},E=p=>p.getBoundingClientRect().height>1.5,L=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let p=L.nextNode();p;p=L.nextNode()){let v=p.parentElement;if(!p.nodeValue.trim()||!v||v.closest("svg, script, style, template, .katex")||!B(v)||n(v))continue;let A=mt(v,t,!0).filter(E);if(A.length===0)continue;let w=getComputedStyle(v),j=parseFloat(w.lineHeight);for(let ot of p.nodeValue.matchAll(/\S+/g)){let dt=ot.index+ot[0].length;R.setStart(p,ot.index),R.setEnd(p,dt);let wt=[...R.getClientRects()];for(let at of wt){let bt=Number.isFinite(j)?Math.max(0,(at.height-j)/2):0,vt=A.find(Ct=>at.bottom-lt(Ct)>1.5+bt);if(!vt)continue;let St=ot.index;if(wt.length>1){let Ct=lt(vt)+1.5+bt;for(let Rt=dt-1;St<Rt;){let qt=St+Rt>>1;R.setStart(p,qt),R.setEnd(p,qt+1),(R.getClientRects()[0]?.bottom??0)>Ct?Rt=qt:St=qt+1}}l(vt,Math.max(...wt.map(Ct=>Ct.bottom))-lt(vt),p.nodeValue.slice(St,dt),null);break}}}for(let p of t.querySelectorAll("*")){let v=p instanceof SVGElement&&p.matches(Nt)&&!p.closest("defs, clipPath, mask, pattern, marker, symbol"),A=!v&&!(p instanceof SVGElement)&&!p.matches("img, picture, video, canvas, iframe, object, embed, script, style, template")&&p.children.length===0&&!p.textContent.trim()&&Tt(p);if(!v&&!A||!B(p))continue;let w=p.getBoundingClientRect();if(w.width<=0&&w.height<=0)continue;let j=v?p.ownerSVGElement:null,ot=[...j&&getComputedStyle(j).overflowY!=="visible"?[j]:[],...mt(j??p,t,!!j)].filter(E),dt=at=>{let bt=at.getBoundingClientRect();return w.left>=bt.left-1.5&&w.right<=bt.right+1.5&&w.top>=bt.top-1.5},wt=ot.find(at=>w.bottom-lt(at)>1.5&&dt(at));wt&&l(wt,w.bottom-lt(wt),null,v?p.localName:I(p))}return d};for(let t of h.querySelectorAll("[data-block-id]")){let n=t.getAttribute("data-block-id"),d=a.has(n);if(!d&&!D.has(n)||m(t)||!B(t))continue;let l=p=>p.closest(".doc-chart-message")||p.closest("h2, h3, h4, p, figcaption")?.parentElement===t,E=new Map,L=document.createTreeWalker(t,NodeFilter.SHOW_TEXT);for(let p=L.nextNode();p&&E.size<3;p=L.nextNode()){let v=p.parentElement;if(!p.nodeValue.trim()||!v||v.closest("svg, script, style, template, .katex")||!B(v)||d&&l(v))continue;let A=v;for(;A!==t&&["inline","contents"].includes(getComputedStyle(A).display);)A=A.parentElement;let w=!1;for(let at=v;at&&!w;at=at===t?null:at.parentElement){let bt=getComputedStyle(at);w=bt.overflowX!=="visible"||bt.overflowY!=="visible"}if(w)continue;let j=getComputedStyle(A),ot=A.getBoundingClientRect(),dt=ot.left+parseFloat(j.borderLeftWidth)+parseFloat(j.paddingLeft),wt=ot.right-parseFloat(j.borderRightWidth)-parseFloat(j.paddingRight);for(let at of p.nodeValue.matchAll(/\S+/g)){R.setStart(p,at.index),R.setEnd(p,at.index+at[0].length);let bt=[...R.getClientRects()],vt=Math.max(0,...bt.flatMap(Ct=>[Ct.right-wt,dt-Ct.left]));if(vt<=1.5||bt.some(Ct=>Ct.right>u+1))continue;let St=E.get(A)??{words:[],reach:0,width:wt-dt};St.words.push(at[0]),St.reach=Math.max(St.reach,vt),E.set(A,St)}}for(let[p,{words:v,reach:A,width:w}]of E)V("overflow-in-block",p,`the words ${Y(v.join(" "),40)} run ${y(A)}px past the side of ${I(p)} (${y(w)}px wide for its words), over what is beside it`,{picture:t});for(let[p,{words:v,marks:A,depth:w,height:j}]of Pt(t,d?l:()=>!1)){let ot=[v.length&&`the words ${Y(v.join(" "),40)}`,A.length&&`${A.length===1?"a mark":`${A.length} marks`} (${[...new Set(A)].slice(0,3).join(", ")})`].filter(Boolean).join(" and "),dt=v.length===0&&A.length===1;V("cut-in-block",p,`${ot} ${dt?"reaches":"reach"} ${y(w)}px past the bottom of ${I(p)} (${y(j)}px tall, its overflow ${getComputedStyle(p).overflowY}), cut off there`,{picture:t})}}if(R.detach(),document.documentElement.scrollWidth>u+1){let t=w=>{for(let j=w.parentElement;j&&j!==document.body;j=j.parentElement)if(getComputedStyle(j).overflowX!=="visible")return!1;return w.nodeType!==1||getComputedStyle(w).position!=="fixed"},n=[...h.querySelectorAll("*")].filter(w=>!(w instanceof SVGElement&&w.ownerSVGElement)&&!m(w)&&w.getBoundingClientRect().right>u+1&&B(w)&&t(w)),d=n.filter(w=>!n.includes(w.parentElement)).slice(0,3),l=`the page is ${document.documentElement.scrollWidth}px wide in a ${u}px window`,E=new Set(n),L=w=>{for(let j=w.parentElement;j;j=j.parentElement)if(E.has(j))return!0;return!1},p=new Map,v=document.createRange(),A=document.createTreeWalker(h,NodeFilter.SHOW_TEXT);for(let w=A.nextNode();w&&p.size<3;w=A.nextNode()){let j=w.parentElement;if(!j||!w.nodeValue.trim()||j.closest("svg, script, style, template")||m(j)||L(w)||!B(j)||!t(w)||(v.selectNodeContents(w),![...v.getClientRects()].some(at=>at.right>u+1)))continue;let ot=j.closest("[data-block-id]")??j;if(p.has(ot))continue;let dt=[],wt=0;for(let at of w.nodeValue.matchAll(/\S+/g)){v.setStart(w,at.index),v.setEnd(w,at.index+at[0].length);let bt=Math.max(...[...v.getClientRects()].map(vt=>vt.right),0);bt<=u+1||(dt.push(at[0]),wt=Math.max(wt,bt))}dt.length&&p.set(ot,{node:j,words:dt.join(" "),right:wt})}v.detach(),d.length===0&&p.size===0&&!e&&V("overflow",null,l);for(let w of d)V("overflow",w,`${l}: ${I(w)} ${Y(w.textContent,24)} reaches ${y(w.getBoundingClientRect().right)}px`);for(let[w,{node:j,words:ot,right:dt}]of p)V("overflow",j,`${l}: the words ${Y(ot,60)} in ${I(w)} run past its edge to ${y(dt)}px (a text that cannot break)`,{picture:w})}return{found:f,next:o}}function po(){let e=s=>!!s.closest("[data-doc-dev]"),o=s=>[...document.querySelectorAll(s)].filter(r=>!e(r)).length;return{charts:o("[data-doc-chart], [data-doc-component='gallery/chart-view']"),tables:o(".doc-table-wrap"),height:document.documentElement.scrollHeight}}var Et=2e4,Me=1800;function Wt(e,o,s){let r=0,i=new Promise((c,$)=>{r=setTimeout(()=>$(new Error(`${s}: no answer in ${o/1e3}s`)),o)});return Promise.race([e,i]).finally(()=>clearTimeout(r))}var Dt=e=>`${e.kind}|${JSON.stringify(e.anchor)}|${e.what}`;async function Ce(e,o,s,{out:r,tiles:i=!1,blocks:c=[],around:$=new Map,held:h=new Map,whole:f=[],drawn:u=[],known:y=null}){let{width:F,height:Y=900,label:m=String(F)}=typeof s=="number"?{width:s}:s,B=m.replace("\xD7","x"),I,b;try{I=await Wt(e.createBrowserContext(),Et,"a browser context opened"),b=await Wt(I.newPage(),Et,"a tab opened")}catch(x){return await zt(I?.close()),{findings:[{kind:"unverified",what:`the browser did not open a page: ${x.message}`,anchor:null,shot:null,seen:!1,state:""}],counts:null,pictures:[],held:{covered:[],missed:[]}}}b.setDefaultTimeout(Et);let K=[],X=[],yt=new Set,U=new Map,et=new Set,it=new Set,V=new Set,ft="",k=0,O=(x,P,Q={})=>K.push({kind:x,what:P,anchor:null,shot:null,seen:!1,state:ft,...Q}),g=Fe(o).href,q=x=>`"${be(x,g)}"`,W=x=>r.folders?.get(x)??r.blocks,T=x=>x.replace(/[^\w-]/g,"_");b.on("pageerror",x=>O("error",`uncaught ${Ft(x.message).slice(0,200)}`)),b.on("console",x=>{x.type()==="error"&&de(x,g)&&O("error",`console: ${Ft(x.text()).slice(0,200)}`)}),b.on("requestfailed",x=>{x.frame()===b.mainFrame()&&O("request",`${q(x.url())}: ${x.failure()?.errorText??"failed"}`,{url:x.url()})}),b.on("response",x=>{x.status()>=400&&x.request().frame()===b.mainFrame()&&O("request",`${q(x.url())}: HTTP ${x.status()}`,{url:x.url()})}),await he(b),await b.evaluateOnNewDocument(`globalThis.__qaUrlName = ${be}; globalThis.__qaTableHides = ${Ge()};`),await b.setViewport({width:F,height:Y}),await b.emulateMediaFeatures([{name:"prefers-color-scheme",value:"light"}]);let H=async x=>{for(let P of await ue(b,{timeout:Et}))O("unverified",`${x}: waited for ${P}`)},z=async(x,P,Q,tt)=>Wt(b.screenshot({path:Q,clip:x,captureBeyondViewport:!P}),Et,"the picture").then(()=>!0,C=>(O("unverified",`no picture of ${tt} (${C.message})`),!1)),ct=async(x,P,Q,tt=0)=>{let C=await b.evaluate(uo,{selector:x,up:tt,margin:Qe,frames:Ze}).catch(M=>({error:M}));return C?.clip?await z(C.clip,C.fixed,P,Q)?C.clip:null:(O("unverified",`no picture of ${Q} (${C?.error?.message??"the element is gone or shows nothing"})`),null)},rt=(x,P)=>x.left<P.x+P.width&&x.right>P.x&&x.top<P.y+P.height&&x.bottom>P.y,pt=async()=>{let x=c.filter(Q=>!et.has(Q)),P=await b.evaluate((Q,tt,C)=>{let M=new Map(Q.map((D,a)=>[D,a])),S=D=>!!D&&!D.closest("[data-doc-dev], dialog:not([open])")&&D.getClientRects().length>0,G=D=>D===null?null:[...document.querySelectorAll("[data-block-id]")].find(a=>a.getAttribute("data-block-id")===D&&S(a))??null,N=D=>{if(!D)return null;let a=D.getBoundingClientRect();return{left:a.left+scrollX,right:a.right+scrollX,top:a.top+scrollY,bottom:a.bottom+scrollY}},st=[];for(let D of document.querySelectorAll("[data-block-id]")){let a=M.get(D.getAttribute("data-block-id"));if(a===void 0||!S(D))continue;M.delete(D.getAttribute("data-block-id")),D.setAttribute("data-qa-block",String(a));let[R,nt]=tt[a]??[],Z=(C[a]??[]).map(mt=>[mt,[...D.querySelectorAll("[data-block-id]")].find(lt=>lt.getAttribute("data-block-id")===mt&&S(lt))]).filter(([,mt])=>mt);st.push({index:a,boxes:tt[a]?{block:N(D),above:N(G(R)),below:N(G(nt))}:null,held:Z.map(([mt,lt])=>({id:mt,box:N(lt)}))})}return st},x,x.map(Q=>$.get(Q)??null),x.map(Q=>h.get(Q)??[]));for(let{index:Q,boxes:tt,held:C}of P){let M=x[Q];et.add(M);let S=`${B}-${T(M)}`,G=[];if(!tt){let N=ht.join(W(M),`${S}.png`),st=await ct(`[data-qa-block="${Q}"]`,N,`the block ${M}`);st&&(X.push({block:M,file:N}),G.push(st))}for(let{part:N,clip:st}of tt?eo(tt):[]){let D=ht.join(W(M),`${S}${N?`-${N}`:""}.png`);await z(st,!1,D,`the block ${M}${N?` (its ${N})`:""}`)&&(X.push({block:M,file:D}),G.push(st))}for(let{id:N,box:st}of C)G.some(D=>rt(st,D))?it.add(N):it.has(N)||V.add(N);await b.evaluate(N=>document.querySelector(`[data-qa-block="${N}"]`)?.removeAttribute("data-qa-block"),Q)}},ut=async(x,P,Q)=>{let tt=[...h].filter(([M])=>et.has(M)).map(([M,S])=>[M,S.filter(G=>!it.has(G))]).filter(([,M])=>M.length);if(!tt.length)return;let C=await b.evaluate((M,S)=>{let G=document.querySelector(M);if(!G)return[];let N=st=>[...G.querySelectorAll("[data-block-id]")].some(D=>D.getAttribute("data-block-id")===st&&D.getClientRects().length>0);return S.map(([st,D])=>[st,D.filter(N)]).filter(([,st])=>st.length)},x,tt);for(let[M,S]of C){let G=ht.join(W(M),`${B}-${T(M)}-${P}.png`);if(await ct(x,G,`the block ${M} (${P})`,Q)){X.push({block:M,part:P,file:G});for(let N of S)it.add(N),V.delete(N)}}},J=async x=>{let P=await b.evaluate(Yt,{scope:x,next:k,ignored:De,slack:Xe,whole:f,drawn:u});k=P.next;let Q=P.found.flatMap(C=>C.kind!=="layout"?[C]:Ue(C.what,F).filter(({kind:M})=>!(C.measured&&["table-columns","table-rows"].includes(M))).map(({kind:M,note:S})=>({...C,kind:M,what:`the kit notes ${S}`})));for(let C of Q){let M=C.shot===null?null:`${C.kind}|${C.shot}|${C.what}`,S=M&&U.get(M);if(S)!S.seen&&C.seen&&Object.assign(S,C,{state:ft});else{let G={...C,state:ft};K.push(G),M&&U.set(M,G)}}let tt=new Set(K.filter(C=>C.kind==="blocked").map(C=>C.url));for(let C of K){if(C.shot===null||!C.seen||yt.has(C.shot)||!Ke(C,F)||y?.has(Dt(C))||["request","image"].includes(C.kind)&&tt.has(C.url))continue;yt.add(C.shot);let M=ht.join(r.flagged,`${B}-${String(C.shot).padStart(2,"0")}-${C.kind}.png`);await ct(`[data-qa-shot="${C.shot}"]`,M,C.kind)&&X.push({shot:C.shot,file:M})}c.length&&await pt()},gt=x=>{let P=new Set(K.filter(tt=>tt.kind==="blocked").map(tt=>tt.url));return{findings:K.filter(tt=>!(["request","image"].includes(tt.kind)&&P.has(tt.url))&&!y?.has(Dt(tt))),counts:x,pictures:X,held:{covered:[...it],missed:[...V]}}};try{try{let S=new Promise(N=>b.once("domcontentloaded",N)),G=b.goto(g,{waitUntil:"load",timeout:6e4});if(G.catch(()=>{}),await Promise.race([S,G]),b.url()!==g)throw new Error(`the browser shows ${b.url()}`)}catch(S){return O("unverified",`the page did not load: ${S.message}`),gt(null)}await H("the page as it opens");let x=await b.evaluate(fo,Et);x.loaded||O("unverified",`the pictures (${x.images}) not all loaded in ${Et/1e3}s`),x.closed&&await H(`the page with its ${x.closed} closed disclosure${x.closed===1?"":"s"} opened`),await J(null);let P=async(S,G,N,st=null)=>{for(let D=S,a=1;D<G;D+=Me,a++){let R=ht.join(r.tiles,`${B}-${N}${String(a).padStart(2,"0")}.png`);await Wt(b.screenshot({path:R,clip:{x:0,y:D,width:F,height:Math.min(Me,G-D)},captureBeyondViewport:!0}),Et,"a tile").then(()=>X.push({tile:!0,sheet:st,file:R}),nt=>O("unverified",`no tile ${N}${a} (${nt.message})`))}};i&&await P(0,await b.evaluate(()=>document.documentElement.scrollHeight),"");let Q=async(S,G=null)=>{if(!await b.evaluate(ke,S.chain)){let{anchor:N}=await b.evaluate(Yt,{next:k,place:`[data-qa-tab="${S.index}"]`});return O("unverified","this Sheet could not be shown: its tab was clicked and its panel stayed hidden",{anchor:N}),!1}if(await H("the Sheet shown"),await J(`[data-qa-panel="${S.index}"]`),await ut(`[data-qa-panel="${S.index}"]`,`sheet${S.index+1}`,1),i&&G)await tt(G,`sheet${S.index+1}-`);else if(i){let N=await b.evaluate(st=>{let D=document.querySelector(`[data-qa-panel="${st}"]`)?.getBoundingClientRect();return D&&D.height>0?{top:Math.max(0,D.top+scrollY),bottom:D.bottom+scrollY}:null},S.index);N&&await P(N.top,N.bottom,`sheet${S.index+1}-`,{number:S.index+1,label:S.label})}return!0},tt=async(S,G="")=>{for(let N=1;N<=20;N++){let st=await b.evaluate((a,R)=>{let nt=document.querySelector(`[data-qa-card="${a}"]`),Z=nt?.querySelector(".doc-dialog-content")??nt;if(!Z)return null;if(R)Z.scrollTop=0;else{let lt=Z.scrollTop;if(Z.scrollTop+=Math.max(40,Z.clientHeight-24),Z.scrollTop===lt)return null}let mt=nt.getBoundingClientRect();return{x:mt.left+visualViewport.pageLeft,y:mt.top+visualViewport.pageTop,width:mt.width,height:mt.height}},S.index,N===1);if(!st)break;let D=ht.join(r.tiles,`${B}-card${S.index+1}-${G}${String(N).padStart(2,"0")}.png`);await z(st,!0,D,`the detail card ${Mt(S.label,24)}, tile ${G}${N}`)&&X.push({tile:!0,card:{number:S.index+1,label:S.label,part:G},file:D})}},C=0;for(let S of x.sheets)S.shown||!S.panel||S.card!==null||(ft=`Sheet ${Mt(S.label,24)}`,await Q(S)&&(C+=1));let M=0;for(let S of x.cards){ft=`detail card ${Mt(S.label,24)}`;let G=`[data-qa-card="${S.index}"]`;S.chain.length&&await b.evaluate(ke,S.chain);for(let N of S.within)await b.evaluate(ve,N);if(!await b.evaluate(ve,S.index)){let{anchor:N}=await b.evaluate(Yt,{next:k,place:G});O("unverified","this detail card could not be opened",{anchor:N});for(let st of S.within.toReversed())await b.evaluate(Gt,st);continue}M+=1,await H("the detail card opened"),await J(G),await ut(G,`card${S.index+1}`,0),i&&await tt(S);for(let N of x.sheets)N.card!==S.index||N.shown||!N.panel||(ft=`detail card ${Mt(S.label,24)}, Sheet ${Mt(N.label,24)}`,await Q(N,S)&&(C+=1));await b.evaluate(Gt,S.index);for(let N of S.within.toReversed())await b.evaluate(Gt,N)}return ft="",gt({...await b.evaluate(po),details:x.details,closed:x.closed,sheets:C,cards:x.cards.length,cardsOpened:M})}catch(x){return O("unverified",`the look ended early: ${x.message}`),gt(null)}finally{await zt(I.close())}}var _t=e=>e.split(ht.sep).join("/"),$t=(e,o,s=`${o}s`)=>`${e} ${e===1?o:s}`,Kt=e=>`${e.join(", ")}px`,go=e=>e.includes("\xD7")?e:`${e}px`;function mo({details:e,closed:o}){if(e===0)return"0 disclosures";let s=o===0?"open in the file":`${o===e?"":`${o} `}closed in the file, opened for the pictures`;return`${$t(e,"disclosure")} (${s})`}function Be(e,o=null){let s=new Map;for(let r of e){let i=o?ht.relative(o,r):"",c=_t(o&&i&&!i.startsWith("..")&&!ht.isAbsolute(i)?i:r),$=/^(.*\/)?(\d+(?:x\d+)?)-([^/]+)$/.exec(c),h=$?`${$[1]??""}\0${$[3]}`:c;s.has(h)||s.set(h,$?{head:$[1]??"",tail:$[3],looks:[]}:{whole:c});let f=s.get(h);$&&!f.looks.includes($[2])&&f.looks.push($[2])}return[...s.values()].map(r=>r.whole??`${r.head}${r.looks.length>1?`{${r.looks.join(",")}}`:r.looks[0]}-${r.tail}`)}function hn(e){let o=e.map(({folder:r,files:i})=>({folder:r,files:[...new Set(i)]})).filter(({files:r})=>r.length);if(!o.length)return null;let s=o.reduce((r,{files:i})=>r+i.length,0);return`\u4E0B\u4E00\u6B65\uFF1Aopen the ${$t(s,"picture")} of this run (none was looked at for you), and in the handoff name those you opened: ${o.flatMap(({folder:r,files:i})=>Be(i,r).map(c=>ht.isAbsolute(c)?c:`${_t(r)}/${c}`)).join(", ")}`}var Te=5,wo=/^\d{4}-\d\d-\d\d_\d\d-\d\d-\d\d(?:-\d+)?$/,$o=["flagged","changed","cards","blocks","tiles"];function xo(e=new Date,o=[]){let s=c=>String(c).padStart(2,"0"),r=`${e.getFullYear()}-${s(e.getMonth()+1)}-${s(e.getDate())}_${s(e.getHours())}-${s(e.getMinutes())}-${s(e.getSeconds())}`,i=r;for(let c=2;o.includes(i);c++)i=`${r}-${c}`;return i}async function yo(e,o=new Date){await xt.mkdir(e,{recursive:!0});for(let s of $o)await xt.rm(ht.join(e,s),{recursive:!0,force:!0});for(let s of await xt.readdir(e))s.endsWith(".png")&&await xt.rm(ht.join(e,s),{force:!0});for(;;){let s=xo(o,await xt.readdir(e));try{return await xt.mkdir(ht.join(e,s)),{name:s,directory:ht.join(e,s)}}catch(r){if(r.code!=="EEXIST")throw r}}}async function bo(e,o,s=Te){for(let c of await xt.readdir(o).catch(()=>[]))await xt.rmdir(ht.join(o,c)).catch(()=>{});await xt.rmdir(o).catch(()=>{});let i=(await xt.readdir(e).catch(()=>[])).filter(c=>wo.test(c)).sort().reverse().slice(s);for(let c of i)await xt.rm(ht.join(e,c),{recursive:!0,force:!0});return i}function So(e){let o=e.filter(Boolean),s=o.reduce((h,{sections:f})=>h+f.reduce((u,{items:y})=>u+y.reduce((F,Y)=>F+Y.count,0),0),0),r=o.length>1,i=o.flatMap(({slug:h,unneeded:f})=>f.map(u=>r?`${h}: ${u}`:u));if(!s&&!i.length)return[];let c=[`\u8981\u770B\u7684\u56FE\uFF08${s} \u5F20\uFF09\uFF1A${s?"\u4ECE\u4E0A\u5230\u4E0B\u9010\u5F20\u6253\u5F00\uFF1B\u4EA4\u63A5\u65F6\u6309\u5E8F\u53F7\u8BF4\u51FA\u4F60\u6253\u5F00\u4E86\u54EA\u51E0\u5F20":"\u8FD9\u6B21\u6CA1\u6709\u62CD\u56FE"}`],$=0;for(let{slug:h,folder:f,sections:u}of o)for(let{title:y,items:F}of u){c.push(` ${r?`${h}: `:""}${y}:`);for(let{names:Y,text:m}of F)c.push(` ${++$}. ${Y.map(B=>ht.isAbsolute(B)||!f?B:`${_t(f)}/${B}`).join(", ")} ${m}`)}if(c.push(`\u4E0D\u7528\u770B\uFF1A${i.length?`${i.join("\uFF1B")}\u3002`:"\u5176\u4F59\u7684\u90FD\u6CA1\u6709\u95EE\u9898\u3002"}`),s)for(let{slug:h,folder:f}of o)f&&c.push(`\u56FE\u5728 ${_t(f)}/\uFF08\u6BCF\u6B21\u8FD0\u884C\u4E00\u4E2A\u65B0\u6587\u4EF6\u5939\uFF0Cqa/${h}/ \u4E0B\u53EA\u7559\u6700\u8FD1 ${Te} \u6B21\uFF0C\u66F4\u65E9\u7684\u5DF2\u5220\uFF09`);return c}var Ne=(e="<slug>")=>`more pictures: gallery qa ${e} --tiles (the page, each Sheet panel and each detail card in tiles), gallery qa ${e} --blocks <id,\u2026> (the blocks you name)`,fn=Ne(),je=pe,Ee='look at the export yourself at 1024, 736 and 360px, its disclosures and detail cards opened (SKILL.md, "Export, check and look"), and say so when you hand the document over.',vo=e=>Ft(e?.message).replace(/\s*Use a different `?userDataDir`? or stop the running browser first\.?/gi,"").slice(0,300),Xt={overflow:"a reader scrolls the whole page sideways. Words that cannot break where they stand (a long path, URL or name): wrap each in <code>, which breaks where it must and keeps it whole for the reader to copy; an element wider than the window (a picture, a drawing, a width of your own): let it fit (max-width: 100%) or put it in a frame that scrolls; never cut or rewrite a path to silence this","table-columns":"not a failure. If the reader must see the column on a desktop, write its long values compactly (a cell of numbers stays on one line, so its longest value sets the column's width: a range as a\u2013b, fewer digits), move a unit out of its header into the line above the table, shorten the header, or split the table; never delete a column to silence this","chart-text-overlap":"not a failure. If the reader must read both, shorten the labels (a unit belongs in the axis's title), move one (above its row, or a leader line) or give the drawing more room at this width; never delete a label or a category to silence this","code-scrolls":'not a failure. A reader scrolls inside the frame (40 lines) for the rest; if every line must show at once, write style="--doc-code-height: none" on its <pre>; never delete code to silence this',"formula-scrolls":"not a failure. A reader scrolls the formula sideways for the rest; if it must show whole at this width, break it into lines (\\begin{aligned} \u2026 \\end{aligned}) or into two formulas; never cut a term to silence this","overflow-in-block":"not a failure. If the words run over others in the picture, give their box room at this width (a wider column in an @media rule of your <style>, or a smaller font there), or let them break (a dash or a space where a line may end); never cut the words to silence this","cut-in-block":"not a failure. If the reader must see what is cut, let the box grow with what it holds (min-height instead of height or max-height, or none), give it room at this width in an @media rule of your <style>, or let it scroll (overflow: auto); never delete the words to silence this",ticks:"not a failure. If the numbers crowd in the picture, give that axis fewer ticks at this width with axis.tickValues([...]), at most four on a phone (the domain's ends and middle; ticks(n) is only a hint to d3 and can still draw five or more), or shorter numbers (the unit in the axis's title: 2k, 1.5\u4E07); never take the axis out to silence this","svg-text-small":"not a failure. The viewBox scales the drawing's text with it: give the text a larger font-size in the viewBox's units (a viewBox 800 wide drawn 340px wide scales by 0.43, so 26 units read as 11px), or lay the drawing out for narrow widths (a viewBox of its own under an @media rule, a chart of your own drawn from its width, or HTML that wraps); never drop the labels to silence this"},ko='not a failure. A reader scrolls sideways for the rest of its long lines; if the reader must see them whole at this width, let them wrap (take data-wrap="false" off its <pre>) or break them where the code allows; a tree or a log whose lines must stay whole may scroll; never cut a line to silence this';function Mo(e){if(e.kind!=="code-scrolls")return Xt[e.kind]?[Xt[e.kind]]:[];let o=[...e.said.keys()],s=o.some(r=>/ wide, its frame /.test(r));return[...!s||o.some(r=>/ tall, its frame /.test(r))?[Xt["code-scrolls"]]:[],...s?[ko]:[]]}var Co="none is a failure: each says what to do if it matters to the reader (never delete a column or a label to silence one)",Eo="a reader scrolls it: not a problem";function qo(e,o,s=null,{folder:r=null,slug:i="<slug>"}={}){let c=[],$=Object.fromEntries(Ot.map(k=>[k,0])),h=new Map,f=new Set,u=new Map,y=[],F=k=>Be(k,r),Y=k=>k.label??String(k.width),m=new Map(e.flatMap(k=>k.pictures.filter(O=>O.shot!==void 0).map(O=>[`${Y(k)}|${O.shot}`,O.file])));for(let k of e){let{width:O,findings:g,counts:q}=k,W=Y(k),T=new Set,H=Object.fromEntries(Ot.map(J=>[J,0])),z={right:0,down:0,all:0};for(let J of g){let gt=`${J.kind}|${J.shot??""}|${J.what}`;if(T.has(gt))continue;T.add(gt);let x=Ae(J,O);H[x]+=1;let P=so(J.anchor,o);if(J.kind==="table-scrolls"){let{sideways:G=!1,down:N=!1,name:st=""}=J.scroll??{};Object.assign(z,{all:z.all+1,right:z.right+Number(G),down:z.down+Number(N)});let D=`${P}|${st}`;u.has(D)||u.set(D,{place:P,name:st,right:[],down:[]}),G&&!u.get(D).right.includes(W)&&u.get(D).right.push(W),N&&!u.get(D).down.includes(W)&&u.get(D).down.push(W)}if(x==="info"&&f.add(`${J.kind}|${P}`),x==="info"&&["table-scrolls","table-columns","table-rows"].includes(J.kind))continue;let Q=`${Ot.indexOf(x)}|${J.kind}|${P}`;h.has(Q)||(h.set(Q,{level:x,kind:J.kind,place:P,said:new Map}),x!=="info"&&($[x]+=1));let tt=h.get(Q).said,C=`${J.state?`[${J.state}] `:""}${J.what}`;tt.has(C)||tt.set(C,{labels:[],pictures:[]});let M=tt.get(C);M.labels.includes(W)||M.labels.push(W);let S=m.get(`${W}|${J.shot}`);S&&!M.pictures.includes(S)&&M.pictures.push(S)}let ct=[z.right&&`\u2192 ${z.right}`,z.down&&`\u2193 ${z.down}`].filter(Boolean).join(", "),rt=`${$t(z.all,"table scrolls","tables scroll")}${ct?` (${ct})`:""}`,pt=q?.cards?`, ${$t(q.cards,"detail card")} (${q.cardsOpened===q.cards?"closed in the file, opened in turn":`${q.cardsOpened??0} of them opened`})`:"",ut=k.laptop?"; only what the 1024px look did not find":q?`; ${$t(q.charts,"chart")}, ${$t(q.tables,"table")}, ${mo(q)}, ${$t(q.sheets,"Sheet")} shown besides the first${pt}, page ${q.height}px tall`:"";y.push({label:W,fail:H.fail,warn:H.warn,line:`${k.laptop?W:`${W.padStart(4)}px`} fail ${H.fail} \xB7 warn ${H.warn} \xB7 unverified ${H.unverified} \xB7 ${rt}${ut}`})}let B=[...h.values()].sort((k,O)=>Ot.indexOf(k.level)-Ot.indexOf(O.level)),I=e.flatMap(k=>k.pictures),b=[],K=[],X=k=>{let O={title:k,items:[]};return b.push(O),O},yt=(k,O,g)=>k.items.push({count:new Set(O).size,names:F(O),text:g}),U=X("The elements flagged in the findings above, to look at first"),et=new Set,it=new Map;for(let k of B){let O=[...new Set([...k.said.values()].flatMap(({pictures:g})=>g))].filter(g=>!et.has(g));if(O.length){for(let g of O)et.add(g);it.has(k.place)||it.set(k.place,{files:[],text:`${k.level.toUpperCase()} ${k.kind} ${k.place}`}),it.get(k.place).files.push(...O)}}for(let{files:k,text:O}of it.values())yt(U,k,O);if(s){let k=new Map;for(let q of I)q.block!==void 0&&k.set(q.block,[...k.get(q.block)??[],q.file]);let O=Zt(e),g=q=>`${s.tags?.get(q)?`${s.tags.get(q)} `:""}${q}`;s.tiles&&s.why&&c.push(`${s.why[0].toUpperCase()}${s.why.slice(1)}.`);for(let q of s.groups??[]){if(!q.ids.length&&!q.rest.length)continue;let W=X(`${q.why[0].toUpperCase()}${q.why.slice(1)}`),T=[];for(let H of q.ids){let z=o.blocks.get(H),ct=`${z?`${o.name??"doc.html"}:${z}`:`(not in ${o.name??"doc.html"})`} ${H}${s.tags?.get(H)?` ${s.tags.get(H)}`:""}`,rt=k.get(H)??[],pt=s.moved?.has(H)?" (moved: with the edges of the blocks before and after it)":"",ut=s.held?.get(H)??[],J=ut.filter(M=>s.changed?.has(M)).length,gt=q.kind==="named"?$t(ut.length,"block"):[J&&$t(J,"changed block"),ut.length-J&&$t(ut.length-J,"card")].filter(Boolean).join(" and "),x=I.some(M=>M.block===H&&M.part)?", pictured again with each Sheet panel or detail card that holds one":"",P=ut.filter(M=>O.has(M)),Q=[...new Set(P.flatMap(M=>O.get(M)))].map(M=>M.includes("\xD7")?M:`${M}px`).join(", "),tt=P.length?`; ${P.length} of them not pictured at ${Q}: gallery qa ${i} --blocks ${P.join(",")}`:"",C=ut.length?` (with the ${gt} it holds${x}${tt})`:"";rt.length?yt(W,rt,`${ct}${pt}${C}`):T.push(H);for(let M of ut){if(!k.has(M)||q.ids.includes(M))continue;let S=o.blocks.get(M);yt(W,k.get(M),`${S?`${o.name??"doc.html"}:${S}`:`(not in ${o.name??"doc.html"})`} ${M}${s.tags?.get(M)?` ${s.tags.get(M)}`:""} (held by ${H}, whose pictures did not show it at this width: pictured on its own)`)}}if(T.length&&K.push(`${T.length===1?"\u4E00\u4E2A\u5757":`${T.length} \u4E2A\u5757`}\u5728\u4EFB\u4F55\u5BBD\u5EA6\u90FD\u4E0D\u663E\u793A\uFF0C\u8BFB\u8005\u770B\u4E0D\u5230\uFF08${T.join(", ")}\uFF09`),q.rest.length){let H=`${q.rest.slice(0,6).map(g).join(", ")}${q.rest.length>6?", \u2026":""}`;q.kind==="cards"?K.push(`\u53E6\u6709 ${q.rest.length} \u4E2A\u6CA1\u6539\u8FC7\u7684\u5361\u7247\u8FD9\u6B21\u6CA1\u6709\u62CD\uFF0C\u6CA1\u6709\u6539\u52A8\u4E5F\u6CA1\u6709\u8B66\u544A\uFF08${H}\uFF09`):c.push(`${$t(q.rest.length,"changed block")} past the ${Oe} a run pictures, not pictured (${H}): gallery qa ${i} --blocks ${q.rest.join(",")}`)}}s.unknown.length&&c.push(` no block of ${o.name??"doc.html"} has the id${s.unknown.length===1?"":"s"} ${s.unknown.join(", ")}`)}let V=I.filter(k=>k.tile);if(V.length){let k=X("The page in tiles"),O=T=>F([ht.dirname(T.file)])[0],g=V.filter(T=>!T.sheet&&!T.card);g.length&&k.items.push({count:g.length,names:[`${O(g[0])}/<width>-<n>.png`],text:`the page as it opens (each Sheet area with the panel it shows first): ${$t(g.length,"tile")}`});let q=new Map;for(let{sheet:T}of V)T&&q.set(T.number,{...T,count:(q.get(T.number)?.count??0)+1});q.size&&k.items.push({count:V.filter(T=>T.sheet).length,names:[`${O(V.find(T=>T.sheet))}/<width>-sheet<i>-<n>.png`],text:`each other Sheet panel, shown in turn: ${[...q.values()].map(({number:T,label:H,count:z})=>`sheet${T} ${Mt(H,24)} ${$t(z,"tile")}`).join(", ")}`});let W=new Map;for(let{card:T}of V)T&&W.set(T.number,{...T,count:(W.get(T.number)?.count??0)+1});W.size&&k.items.push({count:V.filter(T=>T.card).length,names:[`${O(V.find(T=>T.card))}/<width>-card<i>-<n>.png${V.some(T=>T.card?.part)?" (with another panel of a Sheet in it shown, <width>-card<i>-sheet<j>-<n>.png)":""}`],text:`each detail card, opened in turn as the window shows it, its content scrolled a tile at a time: ${[...W.values()].map(({number:T,label:H,count:z})=>`card${T} ${Mt(H,24)} ${$t(z,"tile")}`).join(", ")}`})}for(let{place:k,name:O,right:g,down:q}of u.values()){let W=/^(?:doc|report)\.html:\d+/.exec(k)?.[0]??k;c.push(`${"INFO".padEnd(10)} table-scrolls: ${W}${O?` ${Mt(O,32)}`:""}: ${[g.length&&`\u2192 ${Kt(g)}`,q.length&&`\u2193 ${Kt(q)}`].filter(Boolean).join("; ")} (${Eo})`)}for(let k of B){c.push(`${k.level.toUpperCase().padEnd(10)} ${k.kind}: ${k.place}`);for(let[O,{labels:g}]of k.said)c.push(` ${Kt(g)}: ${O}`);for(let O of Mo(k))c.push(` ${O}`)}c.push(...y.map(({line:k})=>k));let ft=Ao(s,i);return ft&&c.push(ft),$.info=f.size,f.size&&K.push(`INFO \u7684 ${f.size} \u6761\uFF08${f.size===1?"\u5B83":"\u5B83\u4EEC"}\u4E0D\u662F\u95EE\u9898\uFF0C\u8BFB\u8005\u4F1A\u81EA\u5DF1\u6EDA\u52A8\u8868\u683C\u7B49\uFF09`),{lines:c,levels:$,looks:y.map(({label:k,fail:O,warn:g})=>({label:k,fail:O,warn:g})),pictures:{slug:i,folder:r,sections:b.filter(({items:k})=>k.length),unneeded:K}}}function Ao(e,o="<slug>"){let{changed:s=[],restyled:r=[],packages:i=[],cards:c=[],since:$="the last look",first:h=!1}=e?.left??{};if(!s.length&&!r.length&&!c.length)return null;let f=y=>`${y.slice(0,6).map(F=>`${e.tags?.get(F)?`${e.tags.get(F)} `:""}${F}`).join(", ")}${y.length>6?", \u2026":""}`;return`Not pictured by this run, which pictures the blocks named alone: ${[s.length&&`${$t(s.length,"block")} changed or moved since ${$} (${f(s)})`,r.length&&`${$t(r.length,"instance")} of a custom block changed since ${$}, ${i.join(", ")} (${f(r)})`,c.length&&(h?`no earlier look: ${$t(c.length,"card")} never pictured (${f(c)})`:`${$t(c.length,"card")} the change of the document's own <script> or <style> since ${$} may draw again (${f(c)})`)].filter(Boolean).join("; ")}. gallery qa ${o} pictures them.`}function Oo(e,o,s=[],{unpictured:r=!1}={}){let i=o.map(({label:y,fail:F,warn:Y})=>`${go(y)} fail ${F}, warn ${Y}`).join("; "),c=i?` (${i})`:"",$=Ne(s.length===1?s[0].slug:void 0),h={stale:"its file had changed since its export",missing:"it had none yet"},f=s.filter(({first:y})=>y).map(({slug:y,first:F})=>`${s.length>1?`${y} was`:"It was"} exported first by this run (${h[F]}).`),u=`${f.length?`. ${f.join(" ")}`:""}${s.map(({file:y})=>`
3
+ ${je}${y}`).join("")}`;if(e.fail)return`\u95EE\u9898\uFF1Afailures at ${$t(e.fail,"place")}${c}: fix them in the document's doc.html (report.html in an older document), then run this again (it exports first); ${$}${u}`;if(e.unverified)return`\u4E0B\u4E00\u6B65\uFF1Anothing failed${c}; not verified at ${$t(e.unverified,"place")}: say so when you hand the document over; ${$}${u}`;if(e.warn)return`\u4E0B\u4E00\u6B65\uFF1Anothing failed${c}; warnings at ${$t(e.warn,"place")} to look at, ${Co}; ${$}${u}`;if(r){let y=s.length===1?s[0].slug:"<slug>";return`\u4E0B\u4E00\u6B65\uFF1Anothing found${c}, and no picture taken: a plain run pictures the cards and the blocks changed since the last look, and the document has no card (a chart or a drawing, code, a whole block, a component, a flowchart, a Sheet area, columns, a figure, a table) and no block changed; run gallery qa ${y} --tiles to picture the page, each Sheet panel and each detail card in tiles, open those pictures and look at the document once yourself; gallery qa ${y} --blocks <id,\u2026> pictures the blocks you name${u}`}return`\u4E0B\u4E00\u6B65\uFF1Anothing found${c}: open the pictures listed above (\u8981\u770B\u7684\u56FE) and look at the document once yourself; ${$}${u}`}function Ro(e,{missing:o=!1,edited:s=!1,packaged:r=!1}={}){let i=At(e),c=ht.basename(It(Lt(e,Bt)).html);return`exporting first: ${o?`no export yet (${i})`:s?`${c} changed since the last export (${i})`:r?`a custom block it uses changed since the last export (${i})`:`the last export (${i}) does not say which text it was made from (an older Gallery's)`}, as gallery export ${e} does (--no-export: refuse instead)`}async function Bo(e){for(let[i,{missing:c,edited:$,packaged:h}]of e)console.log(`${i}: ${Ro(i,{missing:c,edited:$,packaged:h})}`);let o=new Map(await Promise.all(e.map(async([i])=>[i,await xt.stat(At(i)).then(c=>c.mtimeMs,()=>null)]))),s=Ie(process.execPath,[ht.join(He,"bin","gallery.mjs"),"export",...e.map(([i])=>i)],{cwd:Bt,encoding:"utf8",env:{...process.env,GALLERY_WORKSPACE:Bt},maxBuffer:256*1024*1024});s.stdout&&process.stdout.write(s.stdout),s.stderr&&process.stderr.write(s.stderr),s.error&&console.error(`the export did not run: ${s.error.message}`);let r=[];for(let[i]of e){let c=await xt.stat(At(i)).then($=>$.mtimeMs,()=>null);c!==null&&c!==o.get(i)&&!(await Qt(i,{made:!0})).problem&&r.push(i)}return r}var To=e=>String(e??"").split(/[\s,]+/).filter(Boolean);function No(e,o){let s=Ht(e);return[...new Set(o)].filter(r=>!s.has(r))}var jo=(e,o)=>`--blocks: no block of ${e} has the id${o.length===1?"":"s"} ${o.join(", ")}: nothing was looked at and no picture removed. Name ids as gallery qa prints them (data-block-id in the file).`;async function un(e){let{slugs:o,options:s,values:r}=await te({options:["--tiles","--no-export"],values:["--blocks"],argv:e}),i=r.has("--blocks")?To(r.get("--blocks")):null;if(i?.length===0)throw new jt("--blocks takes block ids: --blocks <id,\u2026>");if(i&&o.length!==1)throw new jt("--blocks names blocks of one document: name one.");let c=new Map,$=[];for(let U of o){let et=await Qt(U);et.problem&&!((et.stale||et.missing)&&!s.has("--no-export"))&&$.push(et.problem),c.set(U,et)}if($.length&&(console.error($.join(`
4
+ `)),process.exit(2)),i){let U=It(Lt(o[0],Bt)).html,et=No(Vt(await xt.readFile(U,"utf8").catch(()=>"")),i);if(et.length)throw new jt(jo(ht.resolve(U),et))}await re(o),await ge(o),await me(o);let h=[...c].filter(([,U])=>U.stale||U.missing),f=new Map(h.map(([U,et])=>[U,et.missing?"missing":"stale"]));if(h.length){let U=await Bo(h),et=h.map(([it])=>it).filter(it=>!U.includes(it));for(let it of U)c.set(it,await Qt(it,{made:!0}));et.length&&(console.error(`\u95EE\u9898\uFF1A${et.join(", ")}: the export failed (above), so nothing was looked at: fix what it says, then run this again`),process.exit(1))}let u=c,y=[...u].map(([U,{file:et}])=>({slug:U,file:et,first:f.get(U)??null})),F=(U,et)=>{for(let[it,{sha256:V,time:ft}]of u)console.log(`${it}: ${At(it)} sha256 ${V}, exported ${Jt(ft)}`);console.log(`UNVERIFIED ${U}: nothing was looked at. ${et}`);for(let{file:it}of y)console.log(`${je}${it}`);process.exit(3)},Y=le();Y||F("no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one)",`Install Chrome or Edge, or ${Ee}`);let m=await fe({executablePath:Y,args:ce()}).catch(U=>F(`the browser ${Y} did not start, twice, each time with a fresh profile (${vo(U)}; GALLERY_BROWSER=<its executable> picks another)`,`Run gallery qa once more; if it says UNVERIFIED again, ${Ee}`)),{browser:B}=m,I=Object.fromEntries(Ot.map(U=>[U,0])),b=new Map,K=!1,X=[];try{for(let[U,{file:et,sha256:it,time:V}]of u){let ft=ht.join(ze,U),k=ht.join(ft,"blocks.json");console.log(`${U}: ${At(U)} sha256 ${it}, exported ${Jt(V)} (${ht.basename(Y)}, headless)`);let O=It(Lt(U,Bt)).html,g=Vt(await xt.readFile(O,"utf8")),q=Ht(g),W=ie(q,ae(await xt.readFile(k,"utf8").catch(()=>null))),T=ne(g),H=se(g),z=ho(q,W,i,{tiles:s.has("--tiles")&&!i,page:T,packages:H,complete:!0}),ct=s.has("--tiles")||!!z.tiles;(ct||z.ids.length)&&(K=!0);let rt=await yo(ft),pt={flagged:ht.join(rt.directory,"flagged"),blocks:ht.join(rt.directory,i?"blocks":"changed"),tiles:ht.join(rt.directory,"tiles")},ut=ht.join(rt.directory,"cards");pt.folders=new Map(z.groups.flatMap(a=>a.ids.map(R=>[R,a.kind==="cards"?ut:pt.blocks])));for(let a of[pt.flagged,...i?[pt.blocks]:z.tiles?[]:[pt.blocks,ut],...ct?[pt.tiles]:[]])await xt.mkdir(a,{recursive:!0});let J=[...q].filter(([,{whole:a}])=>a).map(([a])=>a),gt=[...q].filter(([,{figure:a}])=>a).map(([a])=>a),x=(a,R=null)=>Ce(B,et,a,{out:pt,tiles:ct&&!a.laptop,blocks:a.laptop?[]:z.ids,around:z.around,held:a.laptop?new Map:z.held,whole:J,drawn:gt,known:a.laptop?R:null}),P=[];for(let[a,R]of Ut.entries()){let nt=R.laptop?Ut.slice(0,a).findIndex(Z=>!Z.laptop&&Z.width===R.width):-1;P.push(nt===-1?x(R):P[nt].then(Z=>x(R,new Set(Z.findings.map(Dt)))))}let Q=await Promise.allSettled(P),tt=Q.find(({status:a})=>a==="rejected");if(tt)throw tt.reason;let C=Q.map(({value:a},R)=>({...Ut[R],...a}));C.some(a=>a.pictures.length)&&(K=!0);for(let[a,R]of C.entries()){let nt=[...Zt(C)].filter(([,lt])=>lt.includes(R.label??String(R.width))).map(([lt])=>lt);if(!nt.length||R.laptop)continue;let Z=await Ce(B,et,R,{out:pt,blocks:nt,whole:J,drawn:gt,known:new Set(R.findings.map(Dt))}),mt=new Set(Z.pictures.filter(({block:lt})=>lt!==void 0).map(({block:lt})=>lt));C[a]={...R,pictures:[...R.pictures,...Z.pictures.filter(({block:lt})=>lt!==void 0)],held:{covered:[...new Set([...R.held.covered,...mt])],missed:R.held.missed.filter(lt=>!mt.has(lt))}},mt.size&&(K=!0)}let{lines:M,levels:S,looks:G,pictures:N}=qo(C,no(g,ht.basename(O)),{...z,tags:new Map([...q].map(([a,{tag:R}])=>[a,R]))},{folder:rt.directory,slug:U});X.push(N),console.log(M.join(`
5
+ `));for(let a of Ot)I[a]+=S[a];for(let{label:a,fail:R,warn:nt}of G){let Z=b.get(a)??{label:a,fail:0,warn:0};b.set(a,{label:a,fail:Z.fail+R,warn:Z.warn+nt})}let st=C.every(a=>a.counts&&!a.findings.some(R=>R.kind==="unverified")),D=ro(q,W,z,{named:i,verified:st,failed:S.fail>0,seen:lo(z,C),page:T,packages:H})??W;D&&await xt.writeFile(k,`${JSON.stringify(D)}
6
+ `),await bo(ft,rt.directory)}}finally{await m.close()}let yt=So(X);yt.length&&console.log(yt.join(`
7
+ `)),console.log(Oo(I,[...b.values()],y,{unpictured:!K})),process.exitCode=I.fail?1:I.unverified?4:0}export{tn as a,Ot as b,Ut as c,en as d,on as e,Ue as f,qe as g,Ye as h,Ae as i,Ke as j,Xe as k,Je as l,Oe as m,Qe as n,Ze as o,xe as p,to as q,ye as r,eo as s,be as t,oo as u,no as v,so as w,Jt as x,ao as y,Qt as z,Re as A,ro as B,Zt as C,lo as D,Se as E,co as F,ho as G,uo as H,po as I,Dt as J,Ce as K,mo as L,Be as M,hn as N,Te as O,xo as P,yo as Q,bo as R,So as S,Ne as T,fn as U,je as V,Ee as W,vo as X,Xt as Y,ko as Z,Mo as _,Co as $,Eo as aa,qo as ba,Ao as ca,Oo as da,Ro as ea,To as fa,No as ga,jo as ha,un as ia};