@heycys/gallery 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/page/annotate/index.mjs +3 -2
  3. package/browser/editor/page/board/index.mjs +2 -1
  4. package/browser/editor/page/board/settings.mjs +2 -1
  5. package/browser/editor/page/core.mjs +3 -2
  6. package/browser/editor/page/custom-page.mjs +4 -3
  7. package/browser/editor/page/editor.mjs +13 -7
  8. package/browser/editor/page/emoji-picker/support.mjs +3 -2
  9. package/browser/editor/page/links/index.mjs +1 -12
  10. package/browser/editor/page/links/pages.mjs +3 -2
  11. package/browser/editor/page/outline/folds.mjs +3 -0
  12. package/browser/editor/page/post.mjs +2 -1
  13. package/browser/editor/page/present-links.mjs +4 -3
  14. package/browser/editor/page/present-shell.mjs +3 -58
  15. package/browser/editor/page/session.mjs +3 -37
  16. package/browser/editor/page/storage.mjs +5 -5
  17. package/browser/shared/component-catalog.mjs +2 -2
  18. package/browser/shared/drafts.mjs +26 -51
  19. package/browser/shared/emoji/icon-value.mjs +2 -1
  20. package/browser/shared/extension-manifest.mjs +90 -0
  21. package/browser/shared/extensions.mjs +26 -16
  22. package/browser/shared/http.mjs +1 -1
  23. package/browser/shared/i18n/en.mjs +46 -15
  24. package/browser/shared/media.mjs +2 -1
  25. package/browser/shared/outline.mjs +11 -51
  26. package/browser/shared/page-address.mjs +8 -15
  27. package/browser/shared/paths.mjs +2 -1
  28. package/browser/shared/preferences.mjs +3 -1
  29. package/browser/shared/preview-server.mjs +51 -63
  30. package/browser/shared/service-location.mjs +18 -0
  31. package/browser/shared/session.mjs +3 -6
  32. package/browser/shared/workspace-address.mjs +22 -0
  33. package/browser/shared/workspace-columns.mjs +1 -2
  34. package/browser/shared/workspace-registry.mjs +6 -40
  35. package/browser/shared/workspace.mjs +3 -6
  36. package/browser/shared/writing-preferences.mjs +6 -4
  37. package/dist/{chunk-5MEXZ2UF.mjs → chunk-225ALKYI.mjs} +1 -1
  38. package/dist/{chunk-7N2LPG33.mjs → chunk-2HS7ZBPU.mjs} +1 -1
  39. package/dist/chunk-3F57LEN5.mjs +2 -0
  40. package/dist/{chunk-MKTX5PGV.mjs → chunk-43B75J5T.mjs} +1 -1
  41. package/dist/{chunk-VKSRM7EY.mjs → chunk-4B2TB5K2.mjs} +1 -1
  42. package/dist/{chunk-LV24RY2E.mjs → chunk-4K5KC6V2.mjs} +1 -1
  43. package/dist/chunk-5GK7HS62.mjs +2 -0
  44. package/dist/chunk-6GV3CBB2.mjs +2 -0
  45. package/dist/{chunk-TOE6DPLH.mjs → chunk-6NLXUKAY.mjs} +1 -1
  46. package/dist/{chunk-ZCP7BTOZ.mjs → chunk-6QBHU4DF.mjs} +1 -1
  47. package/dist/{chunk-QXVNUASA.mjs → chunk-6QWQXHAV.mjs} +1 -1
  48. package/dist/chunk-6XD6U3QA.mjs +5 -0
  49. package/dist/{chunk-DKR7LFIY.mjs → chunk-6Y3HYOBM.mjs} +1 -1
  50. package/dist/{chunk-36FIRJIF.mjs → chunk-742D2WWJ.mjs} +2 -2
  51. package/dist/{chunk-7M7UPWU6.mjs → chunk-7EFHNQ5B.mjs} +1 -1
  52. package/dist/{chunk-2GKGEVMR.mjs → chunk-7UZUQQ7Q.mjs} +25 -24
  53. package/dist/{chunk-VPVOAJ7X.mjs → chunk-AGDILNWB.mjs} +1 -1
  54. package/dist/{chunk-5IIH335D.mjs → chunk-ALZ6ZENZ.mjs} +1 -1
  55. package/dist/{chunk-G4YP7GVC.mjs → chunk-BFJGHSQN.mjs} +1 -1
  56. package/dist/{chunk-AMDGVDNV.mjs → chunk-BQNTTFPL.mjs} +1 -1
  57. package/dist/chunk-BX5AKINW.mjs +15 -0
  58. package/dist/{chunk-PAFSFVYB.mjs → chunk-BYNPEUDS.mjs} +1 -1
  59. package/dist/{chunk-74RPP2M2.mjs → chunk-C564NU2H.mjs} +1 -1
  60. package/dist/{chunk-DH6GMDNN.mjs → chunk-CRDG6EF2.mjs} +1 -1
  61. package/dist/{chunk-7XDYK3UC.mjs → chunk-E7656LR7.mjs} +1 -1
  62. package/dist/{chunk-KFZBYDIS.mjs → chunk-ECZBLQKK.mjs} +1 -1
  63. package/dist/{chunk-ZEY2RLBT.mjs → chunk-ERLAIBOA.mjs} +2 -2
  64. package/dist/{chunk-YFJU3O7G.mjs → chunk-FJLM7YE7.mjs} +1 -1
  65. package/dist/{chunk-AFGUR7SY.mjs → chunk-FNCCVGKX.mjs} +1 -1
  66. package/dist/{chunk-VNUWREXU.mjs → chunk-FOJ3K5Z3.mjs} +1 -1
  67. package/dist/{chunk-WCWYNFDF.mjs → chunk-FQ72LZHB.mjs} +1 -1
  68. package/dist/chunk-G7N7YFVD.mjs +2 -0
  69. package/dist/chunk-GIRXJBGC.mjs +2 -0
  70. package/dist/{chunk-VA3KAQZD.mjs → chunk-GKOBB6DH.mjs} +1 -1
  71. package/dist/chunk-GMJD7ID3.mjs +2 -0
  72. package/dist/chunk-GQJMVSSN.mjs +2 -0
  73. package/dist/{chunk-QZ35UAB4.mjs → chunk-GRAXKKG4.mjs} +1 -1
  74. package/dist/{chunk-SAHS56QM.mjs → chunk-HX4DLE3J.mjs} +1 -1
  75. package/dist/{chunk-2RKIHJI2.mjs → chunk-HYMEEXKN.mjs} +1 -1
  76. package/dist/{chunk-QK3VISCA.mjs → chunk-IA4PSIMD.mjs} +1 -1
  77. package/dist/chunk-IS7N3N6Q.mjs +168 -0
  78. package/dist/{chunk-CZ5KJSGK.mjs → chunk-JJNHKGTD.mjs} +1 -1
  79. package/dist/chunk-JPG2LBQM.mjs +11 -0
  80. package/dist/chunk-JYK5WJPM.mjs +2 -0
  81. package/dist/{chunk-LE44MD3O.mjs → chunk-KLQP46Y3.mjs} +1 -1
  82. package/dist/chunk-L55NOXBE.mjs +4 -0
  83. package/dist/{chunk-FXQBADMN.mjs → chunk-LCB6MARS.mjs} +1 -1
  84. package/dist/{chunk-SOD23RGL.mjs → chunk-LJLVCU6W.mjs} +8 -8
  85. package/dist/{chunk-NAGMRVW4.mjs → chunk-LKX55H76.mjs} +1 -1
  86. package/dist/chunk-LMUZQK5O.mjs +2 -0
  87. package/dist/{chunk-CG3UHDKH.mjs → chunk-M4NRDYI5.mjs} +1 -1
  88. package/dist/{chunk-HM4E43VM.mjs → chunk-MAFIGVXY.mjs} +1 -1
  89. package/dist/chunk-NLDF35P5.mjs +2 -0
  90. package/dist/{chunk-3OFXMN6N.mjs → chunk-NMF3IPYA.mjs} +1 -1
  91. package/dist/chunk-ONKC4BCC.mjs +2 -0
  92. package/dist/{chunk-CPS4SRPF.mjs → chunk-OU6ZZVBX.mjs} +2 -2
  93. package/dist/{chunk-NWRZXELO.mjs → chunk-PAREWQGB.mjs} +1 -1
  94. package/dist/{chunk-BYSF5UMM.mjs → chunk-PKVK6WFC.mjs} +2 -2
  95. package/dist/{chunk-4AMTKWDO.mjs → chunk-PUOQ65NC.mjs} +1 -1
  96. package/dist/{chunk-L7W624FD.mjs → chunk-QJAVCTY7.mjs} +1 -1
  97. package/dist/{chunk-6MPKCH3P.mjs → chunk-QNECWMGR.mjs} +1 -1
  98. package/dist/{chunk-HBAUKKQH.mjs → chunk-QP7BOHE4.mjs} +1 -1
  99. package/dist/chunk-QVGOPHOF.mjs +2 -0
  100. package/dist/{chunk-NFABH3QW.mjs → chunk-RRKJMHNX.mjs} +2 -2
  101. package/dist/chunk-S3SX3COT.mjs +20 -0
  102. package/dist/chunk-SQ3FQCCN.mjs +8 -0
  103. package/dist/{chunk-ZO7SFB2E.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  104. package/dist/{chunk-3A5I2GJK.mjs → chunk-T4Y2ZSVX.mjs} +1 -1
  105. package/dist/{chunk-VG5JEIUQ.mjs → chunk-TKWEX4FD.mjs} +2 -2
  106. package/dist/{chunk-CCSGFCLZ.mjs → chunk-U3SSPL4K.mjs} +1 -1
  107. package/dist/{chunk-DHB7UZ7F.mjs → chunk-U5XL7D6A.mjs} +1 -1
  108. package/dist/{chunk-JXLSHVJ2.mjs → chunk-UMHUSOPJ.mjs} +1 -1
  109. package/dist/chunk-UTF7GBQU.mjs +4 -0
  110. package/dist/chunk-UTMAY3WK.mjs +2 -0
  111. package/dist/{chunk-S2Y7VI4H.mjs → chunk-V4ZHRALW.mjs} +2 -2
  112. package/dist/{chunk-GWOYMENX.mjs → chunk-V6XZ4VIR.mjs} +1 -1
  113. package/dist/{chunk-WTEGUPFG.mjs → chunk-VRPVVMRB.mjs} +1 -1
  114. package/dist/{chunk-XKOHV4H6.mjs → chunk-W5NPH5UA.mjs} +1 -1
  115. package/dist/{chunk-VGTMLQWZ.mjs → chunk-WD4U6XXT.mjs} +1 -1
  116. package/dist/{chunk-4DNHHJSL.mjs → chunk-XBNFXWAW.mjs} +1 -1
  117. package/dist/chunk-XZV72SQ4.mjs +2 -0
  118. package/dist/{chunk-QJ3TFJLQ.mjs → chunk-Y34NR5JL.mjs} +1 -1
  119. package/dist/{chunk-YBB5LWZK.mjs → chunk-YFJB534W.mjs} +1 -1
  120. package/dist/{chunk-V5JRSGZF.mjs → chunk-YN37ZDLW.mjs} +1 -1
  121. package/dist/chunk-Z6OKLRHC.mjs +2 -0
  122. package/dist/chunk-ZLS2FRS6.mjs +3 -0
  123. package/dist/{chunk-JI6T3A4Y.mjs → chunk-ZMHUDYLV.mjs} +1 -1
  124. package/dist/{chunk-KH24LWAT.mjs → chunk-ZTHICSSF.mjs} +1 -1
  125. package/dist/cli.mjs +1 -1
  126. package/dist/server.mjs +1 -1
  127. package/dist/worker.mjs +1 -1
  128. package/kit/math.js +1 -1
  129. package/kit/runtime.js +13 -2
  130. package/kit/state.js +2 -0
  131. package/kit/ui.js +5 -1
  132. package/package.json +1 -1
  133. package/release.json +7 -7
  134. package/skill/SKILL.md +13 -13
  135. package/skill/references/building-blocks.md +1 -1
  136. package/skill/references/extensions.md +45 -9
  137. package/web/assets/index-D8P8uhDW.js +15 -0
  138. package/web/assets/{index-xP0uw3a0.css → index-FLb9jCfl.css} +1 -1
  139. package/web/index.html +2 -2
  140. package/dist/chunk-46ACXOU5.mjs +0 -2
  141. package/dist/chunk-5DPABPBI.mjs +0 -2
  142. package/dist/chunk-5L26JUYA.mjs +0 -2
  143. package/dist/chunk-AEMVZYZQ.mjs +0 -166
  144. package/dist/chunk-ASAXY2DJ.mjs +0 -2
  145. package/dist/chunk-DAMVDXR3.mjs +0 -2
  146. package/dist/chunk-DLFZJJEE.mjs +0 -2
  147. package/dist/chunk-EKNHM3P4.mjs +0 -2
  148. package/dist/chunk-FCK6NXON.mjs +0 -3
  149. package/dist/chunk-FX42XU6J.mjs +0 -2
  150. package/dist/chunk-HATA2W7X.mjs +0 -2
  151. package/dist/chunk-JJNRIFND.mjs +0 -8
  152. package/dist/chunk-JL6R4FG4.mjs +0 -4
  153. package/dist/chunk-KUILYI7H.mjs +0 -4
  154. package/dist/chunk-NIW7F7LU.mjs +0 -4
  155. package/dist/chunk-OU3S466R.mjs +0 -20
  156. package/dist/chunk-QCEATQC4.mjs +0 -2
  157. package/dist/chunk-TDWJKOLN.mjs +0 -2
  158. package/dist/chunk-UGO5N3EI.mjs +0 -15
  159. package/dist/chunk-XMKHCUI6.mjs +0 -15
  160. package/dist/chunk-XQRUG4G3.mjs +0 -2
  161. package/dist/chunk-YPPJVDQI.mjs +0 -2
  162. package/dist/chunk-ZANMKAWS.mjs +0 -2
  163. package/web/assets/index-BHC5ZOMh.js +0 -15
  164. /package/dist/{chunk-N3DSBH5S.mjs → chunk-A55HN5OK.mjs} +0 -0
  165. /package/dist/{chunk-KNZJT4ET.mjs → chunk-QAIHRH3I.mjs} +0 -0
  166. /package/dist/{chunk-ZW2A6GBW.mjs → chunk-QR6A54KJ.mjs} +0 -0
  167. /package/dist/{chunk-74UW7QSL.mjs → chunk-UH4SIXTR.mjs} +0 -0
  168. /package/dist/{chunk-EKGYYOSP.mjs → chunk-W7XHE4CT.mjs} +0 -0
  169. /package/dist/{chunk-5MMN3N5J.mjs → chunk-YEY3RSFQ.mjs} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{E as re,J as ae,K as ne,O as ie,P as ce,a as C,b as Q,c as F,g as X,h as Z,n as D,o as ee,r as te,s as se,t as oe}from"./chunk-3OFXMN6N.mjs";import{j as K}from"./chunk-SOD23RGL.mjs";import{d as le}from"./chunk-5L26JUYA.mjs";import{i as q}from"./chunk-JJNRIFND.mjs";import{a as L}from"./chunk-JEUK3ZO7.mjs";import{a as M,b as z,g as J}from"./chunk-4AMTKWDO.mjs";import{b as x,c as T}from"./chunk-VKSRM7EY.mjs";import{b as E}from"./chunk-4OZWXZE5.mjs";import{f as H,j as Y}from"./chunk-VG5JEIUQ.mjs";import{b as V,e as pe}from"./chunk-N3DSBH5S.mjs";pe();import N from"node:fs/promises";import P from"node:path";import{isInstance as ge}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as me}from"../browser/shared/components/installed.mjs";import{attr as we,walk as $e}from"../browser/shared/html-tree.mjs";import{pageExists as ye,pageFiles as be}from"../browser/shared/pages.mjs";import{layoutOf as Ee}from"../browser/shared/workspace.mjs";var xe="card ids aside",ke="nothing else in page.html changed (card ids aside)",Se=e=>new Promise(s=>setTimeout(s,e)),Te=/^\/__gallery\/pages\/[a-z0-9-]+\/cards$/,de=e=>{let s=null;return $e(V(e,{sourceCodeLocationInfo:!0}),n=>{s??=ge(n)?n:null},{inTemplates:!1}),s},fe=(e,s)=>{let n=s.node.sourceCodeLocation.startTag.endOffset;return{frame:e.slice(s.start,n).replace(/\s+data-[xywh]="[^"]*"/g,""),rest:e.slice(n,s.end)}};function Ce(e,s,n,a){let[o,d]=[x(e).cards,x(s).cards],c=[],t=r=>`card ${r.id}${r.block?` (${r.block})`:""}`,l=r=>["x","y","w","h"].map(i=>`${i} ${we(r.node,`data-${i}`)??"-"}`).join(", ");for(let r of o){let i=d.find(g=>g.id===r.id);if(!i){c.push(`${t(r)} taken out`);continue}let m=r.board!==i.board;(m||l(r)!==l(i))&&c.push(`${t(r)}'s place, ${l(r)}${m?` on ${r.board}`:""} then ${l(i)}${m?` on ${i.board}`:""}`);let[h,p]=[fe(e,r),fe(s,i)];if(h.frame===p.frame&&h.rest===p.rest)continue;if(r.id!==n){c.push(t(r));continue}h.frame!==p.frame&&c.push(`${t(r)}'s own frame (an attribute of its <section> but its place)`);let[f,$]=[D(h.rest,de,a),D(p.rest,de,a)];!f||!$?c.push(`${t(r)}'s instance`):f.outside!==$.outside&&c.push(`${t(r)} itself, outside its data parts (a part edited as text or none, or what its instance holds besides its parts)`)}for(let r of d)o.some(i=>i.id===r.id)||c.push(`a ${t(r)} put in`);let w=(r,i)=>{let m="",h=0;for(let p of[...i].sort((f,$)=>f.start-$.start))m+=r.slice(h,p.start),h=p.end;return(m+r.slice(h)).replace(/\s+/g," ")};return(w(e,o)!==w(s,d)||!c.length)&&c.push("the page's own HTML outside its cards (its head, its style, its header)"),c.join("; ")}function Ie(e,s,{card:n,found:a}){let[o,d]=[T(e).text,T(s).text],t=ee(o,d,l=>x(l).cards.find(w=>w.id===n)?.instance??null,a);return t.outside&&(t.outside={...t.outside,what:Ce(o,d,n,a)}),t}async function Oe(e){try{return await e.waitForSelector("[data-doc-ready]",{timeout:C}).catch(s=>{if(s.name==="TimeoutError")throw s;return e.waitForSelector("[data-doc-ready]",{timeout:C})}),await e.waitForFunction(()=>globalThis.__galleryTryEditable===!0&&!!document.querySelector("script[data-ge-page]"),{timeout:C}),!0}catch(s){if(s.name!=="TimeoutError")throw s;return!1}}function ve(e){return e?.startsWith("stopped")?`the page service refused the board's write (${e.slice(7).trim()||"no reason given"}), and the page showed itself again as the file holds it`:{refused:"the page service refused the board's write: the card was changed or taken out meanwhile (someone else's write of page.html), and the page showed itself again as the file holds it",offline:"the page could not reach the server (offline)",reloading:"the page loaded itself again (page.html or a custom block it holds changed meanwhile, or the page service refused a write)",syncing:`its write took more than ${F/1e3}s to be answered`}[e]}function Ae(e){let s=[],n=new Map;return e.on("request",a=>{if(a.method()!=="POST"||!Te.test(new URL(a.url()).pathname))return;let o={done:!1,status:null,answer:null,failed:null};s.push(o),n.set(a,o)}),e.on("response",a=>{let o=n.get(a.request());o&&(o.status=a.status(),o.done=!0,o.status!==200&&a.json().then(d=>{o.answer=d},()=>{}))}),e.on("requestfailed",a=>{let o=n.get(a);o&&(o.failed=a.failure()?.errorText??"failed",o.done=!0)}),{mark:async()=>s.length,async until(a){let o=Date.now();for(let d=0;;await Se(100)){let c=s.slice(a);if(c.length===0){if(Date.now()-o>Q)return"unchanged";continue}if(c.some(l=>!l.done)){if(d=0,Date.now()-o>F)return"syncing";continue}if(++d<4)continue;if(c.some(l=>l.failed))return"offline";let t=c.find(l=>l.status!==200);return t?t.answer?.refused||t.status===409&&!t.answer?"refused":`stopped ${t.answer?.reason??`HTTP ${t.status}`}`:"saved"}}}}function Re({card:e,found:s}){let n={...s,parts:Object.fromEntries(Object.entries(s.parts).filter(([,a])=>a.edit==="data"))};return{where:{card:e},ready:Oe,saves:Ae,changes:(a,o)=>Ie(a,o,{card:e,found:n}),plain:()=>!1,stayed:ve,outside:"problem",outsideSaid:a=>`card ${e}'s data parts: ${a.what}, where a reader's gesture on the card is to change its data parts alone`,aside:xe,inside:ke,framed:a=>a.closest(".gallery-card")??a}}var Le=e=>` ${e.id} ${e.block??"(no instance)"} x ${e.x}, y ${e.y}, w ${e.w}, h ${e.h}${e.board?` on board ${e.board}`:""}`;async function Ke(e,{named:s,values:n,seconds:a={},keep:o,replace:d=!1}){if(s.length===0)throw new E("Name the page and the card: gallery page try <slug> <card id> and the gesture.");if(s.length===1)throw new E(`Name the card of ${s[0]} to try: gallery page try ${s[0]} <card id> and the gesture (its data-card-id; gallery page check ${s[0]} lists the cards).`);if(s.length>2)throw new E("gallery page try takes a page's slug and a card's id.");let c=await X(n,a,d),[t,l]=s,w=n.has("--steps")?P.resolve(n.get("--steps")):null,r=c?[c]:await Z(w),i=be(t,e);ye(t,e)||(console.error(await le(t,e)),process.exit(1));let m=await N.readFile(i.html,"utf8"),{cards:h}=x(T(m).text),p=h.find(u=>u.id===l);if(!p)throw new E(h.length?`${t} has no card ${l}: its cards are
2
+ import{E as re,J as ae,K as ne,O as ie,P as ce,a as C,b as Q,c as F,g as X,h as Z,n as D,o as ee,r as te,s as se,t as oe}from"./chunk-NMF3IPYA.mjs";import{j as K}from"./chunk-LJLVCU6W.mjs";import{d as le}from"./chunk-XZV72SQ4.mjs";import{i as q}from"./chunk-SQ3FQCCN.mjs";import{a as L}from"./chunk-JEUK3ZO7.mjs";import{a as M,b as z,g as J}from"./chunk-PUOQ65NC.mjs";import{b as x,c as T}from"./chunk-4B2TB5K2.mjs";import{b as E}from"./chunk-4OZWXZE5.mjs";import{f as H,j as Y}from"./chunk-TKWEX4FD.mjs";import{b as V,e as pe}from"./chunk-A55HN5OK.mjs";pe();import N from"node:fs/promises";import P from"node:path";import{isInstance as ge}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as me}from"../browser/shared/components/installed.mjs";import{attr as we,walk as $e}from"../browser/shared/html-tree.mjs";import{pageExists as ye,pageFiles as be}from"../browser/shared/pages.mjs";import{layoutOf as Ee}from"../browser/shared/workspace.mjs";var xe="card ids aside",ke="nothing else in page.html changed (card ids aside)",Se=e=>new Promise(s=>setTimeout(s,e)),Te=/^\/__gallery\/pages\/[a-z0-9-]+\/cards$/,de=e=>{let s=null;return $e(V(e,{sourceCodeLocationInfo:!0}),n=>{s??=ge(n)?n:null},{inTemplates:!1}),s},fe=(e,s)=>{let n=s.node.sourceCodeLocation.startTag.endOffset;return{frame:e.slice(s.start,n).replace(/\s+data-[xywh]="[^"]*"/g,""),rest:e.slice(n,s.end)}};function Ce(e,s,n,a){let[o,d]=[x(e).cards,x(s).cards],c=[],t=r=>`card ${r.id}${r.block?` (${r.block})`:""}`,l=r=>["x","y","w","h"].map(i=>`${i} ${we(r.node,`data-${i}`)??"-"}`).join(", ");for(let r of o){let i=d.find(g=>g.id===r.id);if(!i){c.push(`${t(r)} taken out`);continue}let m=r.board!==i.board;(m||l(r)!==l(i))&&c.push(`${t(r)}'s place, ${l(r)}${m?` on ${r.board}`:""} then ${l(i)}${m?` on ${i.board}`:""}`);let[h,p]=[fe(e,r),fe(s,i)];if(h.frame===p.frame&&h.rest===p.rest)continue;if(r.id!==n){c.push(t(r));continue}h.frame!==p.frame&&c.push(`${t(r)}'s own frame (an attribute of its <section> but its place)`);let[f,$]=[D(h.rest,de,a),D(p.rest,de,a)];!f||!$?c.push(`${t(r)}'s instance`):f.outside!==$.outside&&c.push(`${t(r)} itself, outside its data parts (a part edited as text or none, or what its instance holds besides its parts)`)}for(let r of d)o.some(i=>i.id===r.id)||c.push(`a ${t(r)} put in`);let w=(r,i)=>{let m="",h=0;for(let p of[...i].sort((f,$)=>f.start-$.start))m+=r.slice(h,p.start),h=p.end;return(m+r.slice(h)).replace(/\s+/g," ")};return(w(e,o)!==w(s,d)||!c.length)&&c.push("the page's own HTML outside its cards (its head, its style, its header)"),c.join("; ")}function Ie(e,s,{card:n,found:a}){let[o,d]=[T(e).text,T(s).text],t=ee(o,d,l=>x(l).cards.find(w=>w.id===n)?.instance??null,a);return t.outside&&(t.outside={...t.outside,what:Ce(o,d,n,a)}),t}async function Oe(e){try{return await e.waitForSelector("[data-doc-ready]",{timeout:C}).catch(s=>{if(s.name==="TimeoutError")throw s;return e.waitForSelector("[data-doc-ready]",{timeout:C})}),await e.waitForFunction(()=>globalThis.__galleryTryEditable===!0&&!!document.querySelector("script[data-ge-page]"),{timeout:C}),!0}catch(s){if(s.name!=="TimeoutError")throw s;return!1}}function ve(e){return e?.startsWith("stopped")?`the page service refused the board's write (${e.slice(7).trim()||"no reason given"}), and the page showed itself again as the file holds it`:{refused:"the page service refused the board's write: the card was changed or taken out meanwhile (someone else's write of page.html), and the page showed itself again as the file holds it",offline:"the page could not reach the server (offline)",reloading:"the page loaded itself again (page.html or a custom block it holds changed meanwhile, or the page service refused a write)",syncing:`its write took more than ${F/1e3}s to be answered`}[e]}function Ae(e){let s=[],n=new Map;return e.on("request",a=>{if(a.method()!=="POST"||!Te.test(new URL(a.url()).pathname))return;let o={done:!1,status:null,answer:null,failed:null};s.push(o),n.set(a,o)}),e.on("response",a=>{let o=n.get(a.request());o&&(o.status=a.status(),o.done=!0,o.status!==200&&a.json().then(d=>{o.answer=d},()=>{}))}),e.on("requestfailed",a=>{let o=n.get(a);o&&(o.failed=a.failure()?.errorText??"failed",o.done=!0)}),{mark:async()=>s.length,async until(a){let o=Date.now();for(let d=0;;await Se(100)){let c=s.slice(a);if(c.length===0){if(Date.now()-o>Q)return"unchanged";continue}if(c.some(l=>!l.done)){if(d=0,Date.now()-o>F)return"syncing";continue}if(++d<4)continue;if(c.some(l=>l.failed))return"offline";let t=c.find(l=>l.status!==200);return t?t.answer?.refused||t.status===409&&!t.answer?"refused":`stopped ${t.answer?.reason??`HTTP ${t.status}`}`:"saved"}}}}function Re({card:e,found:s}){let n={...s,parts:Object.fromEntries(Object.entries(s.parts).filter(([,a])=>a.edit==="data"))};return{where:{card:e},ready:Oe,saves:Ae,changes:(a,o)=>Ie(a,o,{card:e,found:n}),plain:()=>!1,stayed:ve,outside:"problem",outsideSaid:a=>`card ${e}'s data parts: ${a.what}, where a reader's gesture on the card is to change its data parts alone`,aside:xe,inside:ke,framed:a=>a.closest(".gallery-card")??a}}var Le=e=>` ${e.id} ${e.block??"(no instance)"} x ${e.x}, y ${e.y}, w ${e.w}, h ${e.h}${e.board?` on board ${e.board}`:""}`;async function Ke(e,{named:s,values:n,seconds:a={},keep:o,replace:d=!1}){if(s.length===0)throw new E("Name the page and the card: gallery page try <slug> <card id> and the gesture.");if(s.length===1)throw new E(`Name the card of ${s[0]} to try: gallery page try ${s[0]} <card id> and the gesture (its data-card-id; gallery page check ${s[0]} lists the cards).`);if(s.length>2)throw new E("gallery page try takes a page's slug and a card's id.");let c=await X(n,a,d),[t,l]=s,w=n.has("--steps")?P.resolve(n.get("--steps")):null,r=c?[c]:await Z(w),i=be(t,e);ye(t,e)||(console.error(await le(t,e)),process.exit(1));let m=await N.readFile(i.html,"utf8"),{cards:h}=x(T(m).text),p=h.find(u=>u.id===l);if(!p)throw new E(h.length?`${t} has no card ${l}: its cards are
3
3
  ${h.map(Le).join(`
4
- `)}`:`${t} has no card yet: gallery page add ${t} <block> puts one on it.`);let f=P.basename(i.html),$=p.node.sourceCodeLocation?.startLine??null;p.instance||(console.error(`Card ${l} of ${t} (${f}:${$}) holds no instance of a custom block (an element with ${me}): there is nothing on it to try.`),process.exit(1));let g=p.block,_=H(e),k=_.packages.get(g);if(!k){let u=_.problems.get(g);console.error(u?.off?`${g} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so on the page and runs nothing.`:u?`${g} does not load (${Y("en",u.problem)}), so its card runs nothing: gallery block check ${g} says why.`:`No custom block ${g} in this workspace, so its card runs nothing: gallery block list says which there are${g.startsWith("gallery/")?`, and gallery block add ${g.slice(8)} puts one of Gallery's own in`:""}.`),process.exit(1)}k.places.includes("page")||(console.error(`${g} is a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing, so there is nothing to try there (gallery block try tries it in a document).`),process.exit(1)),console.log(`${g} in card ${l} of ${t}, at ${f}:${$}: ${L(i.html)}`),w&&console.log(`Steps: ${r.length} from ${L(w)}, made one after another in one page`);let S=await q({command:`gallery page try ${t}`});if(!S.ok){console.log(`UNVERIFIED ${t}: ${S.message}`),process.exitCode=3;return}let{pageAloneOf:j}=await import("./chunk-DAMVDXR3.mjs");await oe(e);let B=[],G=async u=>{let b=await te(e,{directory:i.folder,files:i,text:u});return B.push(b.slug),b},I=Re({card:l,found:k});try{let u=o?{slug:t,file:i.html}:await G(m),b=j(S.port,u.slug);console.log(o?`Page: ${b} (the custom page alone, editable: the Agent's own; --keep: what ${re(r)} write stays in ${f}, and every page open on it shows it, the user's too; the server runs on after this command)`:`Page: ${b} (a scratch copy of ${t}, its page alone, editable, made for this trial and gone at its end: ${f} is not written, and no page of the user's shows the trial; the server runs on after this command)`);let O=M();if(!O){console.log(`UNVERIFIED ${t}: no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so nothing was tried`),process.exitCode=3;return}let v;try{v=await J({executablePath:O,args:z()})}catch(R){console.log(`UNVERIFIED ${t}: the browser ${O} did not start, twice, each time with a fresh profile (${K(R)}; GALLERY_BROWSER=<its executable> picks another), so nothing was tried`),process.exitCode=3;return}let A=P.join(Ee(e).qa,t,"try");try{await N.rm(A,{recursive:!0,force:!0}),await N.mkdir(A,{recursive:!0});let R=async y=>{if(o)return{address:b,file:u.file};let W=await G(y);return{address:j(S.port,W.slug),file:W.file}},U;try{U=await ae(v.browser,{root:e,address:b,fresh:R,steps:r,keep:o,file:u.file,name:f,line:$,found:k,out:A,host:I})}catch(y){if(y instanceof E&&y.made&&console.log(ce({name:f,steps:r,keep:o,host:I},y.made).join(`
4
+ `)}`:`${t} has no card yet: gallery page add ${t} <block> puts one on it.`);let f=P.basename(i.html),$=p.node.sourceCodeLocation?.startLine??null;p.instance||(console.error(`Card ${l} of ${t} (${f}:${$}) holds no instance of a custom block (an element with ${me}): there is nothing on it to try.`),process.exit(1));let g=p.block,_=H(e),k=_.packages.get(g);if(!k){let u=_.problems.get(g);console.error(u?.off?`${g} is turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so on the page and runs nothing.`:u?`${g} does not load (${Y("en",u.problem)}), so its card runs nothing: gallery block check ${g} says why.`:`No custom block ${g} in this workspace, so its card runs nothing: gallery block list says which there are${g.startsWith("gallery/")?`, and gallery block add ${g.slice(8)} puts one of Gallery's own in`:""}.`),process.exit(1)}k.places.includes("page")||(console.error(`${g} is a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing, so there is nothing to try there (gallery block try tries it in a document).`),process.exit(1)),console.log(`${g} in card ${l} of ${t}, at ${f}:${$}: ${L(i.html)}`),w&&console.log(`Steps: ${r.length} from ${L(w)}, made one after another in one page`);let S=await q({command:`gallery page try ${t}`});if(!S.ok){console.log(`UNVERIFIED ${t}: ${S.message}`),process.exitCode=3;return}let{pageAloneOf:j}=await import("./chunk-ONKC4BCC.mjs");await oe(e);let B=[],G=async u=>{let b=await te(e,{directory:i.folder,files:i,text:u});return B.push(b.slug),b},I=Re({card:l,found:k});try{let u=o?{slug:t,file:i.html}:await G(m),b=j(S.port,u.slug);console.log(o?`Page: ${b} (the custom page alone, editable: the Agent's own; --keep: what ${re(r)} write stays in ${f}, and every page open on it shows it, the user's too; the server runs on after this command)`:`Page: ${b} (a scratch copy of ${t}, its page alone, editable, made for this trial and gone at its end: ${f} is not written, and no page of the user's shows the trial; the server runs on after this command)`);let O=M();if(!O){console.log(`UNVERIFIED ${t}: no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so nothing was tried`),process.exitCode=3;return}let v;try{v=await J({executablePath:O,args:z()})}catch(R){console.log(`UNVERIFIED ${t}: the browser ${O} did not start, twice, each time with a fresh profile (${K(R)}; GALLERY_BROWSER=<its executable> picks another), so nothing was tried`),process.exitCode=3;return}let A=P.join(Ee(e).qa,t,"try");try{await N.rm(A,{recursive:!0,force:!0}),await N.mkdir(A,{recursive:!0});let R=async y=>{if(o)return{address:b,file:u.file};let W=await G(y);return{address:j(S.port,W.slug),file:W.file}},U;try{U=await ae(v.browser,{root:e,address:b,fresh:R,steps:r,keep:o,file:u.file,name:f,line:$,found:k,out:A,host:I})}catch(y){if(y instanceof E&&y.made&&console.log(ce({name:f,steps:r,keep:o,host:I},y.made).join(`
5
5
  `)),y.stuck)return ne(t,y,f,o);throw y}let{lines:ue,code:he}=ie({slug:t,name:f,steps:r,keep:o,host:I},U);console.log(ue.join(`
6
6
  `)),process.exitCode=he}finally{await v.close()}}finally{for(let u of B)await se(e,u)}}export{xe as a,ke as b,de as c,Ce as d,Ie as e,Ae as f,Re as g,Ke as h};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{spawn as O}from"node:child_process";import{existsSync as I}from"node:fs";import C from"node:fs/promises";import _ from"node:os";import q from"node:path";import{APART as S}from"../browser/editor/components/registry.mjs";var N=6e4,x=600,B=["A4","A3","Letter","Legal","Tabloid"];function F(){if(process.env.GALLERY_BROWSER)return process.env.GALLERY_BROWSER;let{PROGRAMFILES:o="","PROGRAMFILES(X86)":e="",LOCALAPPDATA:r="",HOME:i=""}=process.env;return({win32:[`${o}\\Google\\Chrome\\Application\\chrome.exe`,`${e}\\Google\\Chrome\\Application\\chrome.exe`,`${r}\\Google\\Chrome\\Application\\chrome.exe`,`${e}\\Microsoft\\Edge\\Application\\msedge.exe`,`${o}\\Microsoft\\Edge\\Application\\msedge.exe`],darwin:["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","/Applications/Chromium.app/Contents/MacOS/Chromium",...i?[`${i}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`,`${i}/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge`,`${i}/Applications/Chromium.app/Contents/MacOS/Chromium`]:[]],linux:["/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/opt/google/chrome/chrome","/usr/bin/microsoft-edge","/usr/bin/microsoft-edge-stable","/opt/microsoft/msedge/msedge","/usr/bin/chromium","/usr/bin/chromium-browser","/snap/bin/chromium"]}[process.platform]??[]).find(s=>s&&I(s))??null}var $=()=>process.getuid?.()===0?["--no-sandbox"]:[],te=()=>["--no-first-run","--no-default-browser-check","--disable-extensions","--hide-scrollbars","--lang=zh-CN",...$()];function oe(o,e,r=[]){let i=o.location()?.url??"";return!/^Failed to load resource|^Refused to |Content Security Policy/.test(o.text())&&(!i||i.startsWith(e)||r.includes(i))}var re=o=>o.evaluateOnNewDocument(()=>{globalThis.__qaViolations=[],document.addEventListener("securitypolicyviolation",e=>{globalThis.__qaViolations.push({url:e.blockedURI,directive:e.effectiveDirective||e.violatedDirective,source:e.sourceFile,line:e.lineNumber})})}),V=3e4,W=5e3;function ie(o,e=W){let r=0,i=new Promise(c=>{r=setTimeout(c,e)});return Promise.race([Promise.resolve(o).catch(()=>{}),i]).finally(()=>clearTimeout(r))}var E=o=>new Promise(e=>setTimeout(e,o).unref()),D=o=>String(o??"").replace(/\s+/g," ").trim(),M=o=>{let e=o.split(/\r?\n/).map(D).filter(Boolean).at(-1);return e?`: ${e.slice(0,200)}`:""};async function se({executablePath:o,args:e=[],attempts:r=2,start:i=H}){let c=[];for(let s=0;s<r;s+=1){let n=await C.mkdtemp(q.join(_.tmpdir(),"gallery-browser-")),t=()=>C.rm(n,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{});try{let{browser:a,stop:l}=await i({executablePath:o,args:e,profile:n});return{browser:a,failures:c,close:async()=>{await l().catch(()=>{}),await t()}}}catch(a){c.push(D(a?.message??a)),await t()}}throw Object.assign(new Error(c.at(-1)??"the browser did not start"),{failures:c})}async function H({executablePath:o,args:e,profile:r,starting:i=V}){let{default:c}=await import("./chunk-ZEY2RLBT.mjs"),s=await c.defaultArgs({headless:!0,userDataDir:r,args:[...e,"--remote-debugging-port=0"]}),n=process.platform!=="win32",t=O(o,s,{stdio:["ignore","ignore","pipe"],windowsHide:!0,detached:n}),a=!1;t.on("error",()=>a||=t.pid===void 0);let l=()=>a||t.exitCode!==null||t.signalCode!==null,u=new Promise(f=>t.once("exit",f)),m=()=>{if(!l())try{n?process.kill(-t.pid,"SIGKILL"):t.kill()}catch{try{t.kill("SIGKILL")}catch{}}};process.once("exit",m);let p="",d=new Promise((f,w)=>{let g=setTimeout(()=>w(new Error(`it said nothing of its DevTools port in ${i/1e3}s${M(p)}`)),i);t.stderr.setEncoding("utf8"),t.stderr.on("data",h=>{p=`${p}${h}`.slice(-4e3);let y=/DevTools listening on (ws:\/\/\S+)/.exec(p);y&&(clearTimeout(g),f(y[1]))}),t.once("error",h=>(clearTimeout(g),w(h))),t.once("exit",(h,y)=>(clearTimeout(g),w(new Error(`it stopped (${y??`exit ${h}`}) before it opened its DevTools port${M(p)}`))))}),A=async()=>{try{l()||await Promise.race([u,E(5e3)]),m(),l()||await Promise.race([u,E(3e3)])}finally{process.off("exit",m)}},v;try{let f=await d,w=0,g=new Promise((y,G)=>{w=setTimeout(()=>G(new Error(`it opened its DevTools port and did not answer in ${i/1e3}s`)),i)}),h=c.connect({browserWSEndpoint:f,defaultViewport:{width:800,height:600}});h.catch(()=>{}),v=await Promise.race([h,g]).finally(()=>clearTimeout(w))}catch(f){throw m(),await A(),f}return{browser:v,stop:async()=>{await Promise.race([v.close().catch(()=>{}),E(5e3)]),await A()}}}var b=null,L=0,T=0;async function K(){let o=F();if(!o)throw Object.assign(new Error("\u6CA1\u6709\u627E\u5230 Chrome \u6216 Edge\uFF1A\u5BFC\u51FA PDF \u9700\u8981\u7535\u8111\u4E0A\u88C5\u6709\u5176\u4E2D\u4E00\u4E2A\u6D4F\u89C8\u5668"),{reason:"browser"});let{default:e}=await import("./chunk-ZEY2RLBT.mjs");return e.launch({executablePath:o,headless:!0,args:["--no-first-run","--no-default-browser-check","--disable-extensions",...$()]})}async function R(o,e){clearTimeout(L),T+=1,b??=K().catch(i=>{throw b=null,i});let r=await(await b).newPage();try{return await r.emulateMediaFeatures([{name:"prefers-reduced-motion",value:"reduce"},{name:"prefers-color-scheme",value:"light"}]),await r.setViewport({width:1200,height:900}),await r.setContent(o,{waitUntil:"load",timeout:6e4}),await P(r,{changing:x}),await e(r)}finally{await r.close().catch(()=>{}),T-=1,T===0&&(L=setTimeout(async()=>{let i=b;b=null,(await i?.catch(()=>null))?.close().catch(()=>{})},N))}}async function P(o,{timeout:e=15e3,changing:r=e}={}){let i=[],c=(n,t,a=e)=>{t!==!0&&i.push(`${n} (${t===!1?`not in ${a/1e3}s`:t})`)},s=(n,t=e)=>o.evaluate(n,t).catch(a=>a.message);return c("the fonts loaded",await s(n=>Promise.race([Promise.resolve(document.fonts?.ready).then(()=>!0),new Promise(t=>setTimeout(()=>t(!1),n))]))),c("the kit's first drawing done (data-doc-drawn)",await s(n=>new Promise(t=>{let a=Date.now(),l=()=>{!globalThis.DocKit||document.documentElement.hasAttribute("data-doc-drawn")?(globalThis.DocCode?.colorAll?.(),t(!0)):Date.now()-a>n?t(!1):setTimeout(l,50)};l()}))),c("the page done changing",await s(n=>new Promise(t=>{let a=()=>[document.documentElement.scrollHeight,...[...document.querySelectorAll("[style]")].map(d=>d.getAttribute("style")),...[...document.adoptedStyleSheets??[]].flatMap(d=>[...d.cssRules].map(A=>A.cssText)),...[...document.querySelectorAll("svg, canvas")].map(d=>d.outerHTML.length),[...document.images].filter(d=>d.complete).length].join("|"),l=Date.now(),u=a(),m=0,p=()=>{let d=a();m=d===u?m+1:0,u=d,m>=3?t(!0):Date.now()-l>n?t(!1):setTimeout(p,100)};setTimeout(p,100)}),r),r),i}async function k(o){await o.evaluate(()=>{document.documentElement.setAttribute("data-doc-theme","light");for(let e of document.querySelectorAll("[data-doc-sheets]")){let r=e.querySelector(":scope > .doc-sheet-tabs");if(r){for(let i of r.querySelectorAll(":scope > .doc-sheet-tab")){let c=i.getAttribute("data-sheet-tab"),s=[...e.querySelectorAll(":scope > [data-doc-sheet]")].find(a=>a.getAttribute("data-doc-sheet")===c);if(!s)continue;s.hidden=!1,s.removeAttribute("aria-hidden"),s.style.setProperty("display","block","important");let n=r.cloneNode(!1);n.removeAttribute("id"),n.removeAttribute("role"),n.style.setProperty("break-after","avoid");let t=i.cloneNode(!0);t.removeAttribute("id"),t.setAttribute("aria-selected","true"),t.classList.add("is-active"),n.append(t),s.before(n)}r.style.setProperty("display","none","important")}}for(let e of document.querySelectorAll("details"))e.open=!0;window.dispatchEvent(new Event("resize"))}),await P(o,{changing:x})}var j={A4:793.7,A3:1122.5,Letter:816,Legal:816,Tabloid:1056},z=96;async function U(o,e){await o.emulateMediaType("print");let r=await o.evaluate(()=>Math.max(0,innerWidth-document.documentElement.clientWidth));await o.setViewport({width:Math.floor(e)+r,height:900}),await P(o,{changing:x})}function ne(o,{paper:e="A4",scale:r=1}={}){let i=B.includes(e)?e:"A4",c=Math.min(2,Math.max(.1,r));return R(o,async s=>(await k(s),await U(s,(j[i]-2*z)/c),Buffer.from(await s.pdf({format:i,scale:c,printBackground:!0,margin:{top:"1in",right:"1in",bottom:"1in",left:"1in"}}))))}function ae(o){return R(o,async e=>{await k(e);let r=e.viewport(),i=await e.$$("main figure.doc-figure"),c=[];for(let s of i){let n=0;try{n=await s.evaluate(async(t,a)=>{let l=[];for(let u=t.closest(a);u;u=u.parentElement.closest(a))l.unshift(u);for(let u of l)u.style.setProperty("height","auto"),u.style.setProperty("max-height","calc(100dvh - (2 * var(--doc-dialog-margin)))"),u.showModal();return await new Promise(u=>requestAnimationFrame(()=>requestAnimationFrame(u))),l.length?Math.ceil(t.getBoundingClientRect().height):0},S),n&&(await e.setViewport({...r,height:r.height+n}),await P(e,{changing:x})),await s.evaluate(t=>t.scrollIntoView({block:"center"})),c.push(Buffer.from(await s.screenshot({type:"png"})))}catch{c.push(null)}await s.evaluate((t,a)=>{for(let l=t.closest(a);l;l=l.parentElement.closest(a))l.close(),l.style.removeProperty("height"),l.style.removeProperty("max-height"),l.getAttribute("style")||l.removeAttribute("style")},S).catch(()=>{}),n&&await e.setViewport(r).catch(()=>{})}return c})}export{F as a,te as b,oe as c,re as d,W as e,ie as f,se as g,P as h,ne as i,ae as j};
2
+ import{spawn as O}from"node:child_process";import{existsSync as I}from"node:fs";import C from"node:fs/promises";import _ from"node:os";import q from"node:path";import{APART as S}from"../browser/editor/components/registry.mjs";var N=6e4,x=600,B=["A4","A3","Letter","Legal","Tabloid"];function F(){if(process.env.GALLERY_BROWSER)return process.env.GALLERY_BROWSER;let{PROGRAMFILES:o="","PROGRAMFILES(X86)":e="",LOCALAPPDATA:r="",HOME:i=""}=process.env;return({win32:[`${o}\\Google\\Chrome\\Application\\chrome.exe`,`${e}\\Google\\Chrome\\Application\\chrome.exe`,`${r}\\Google\\Chrome\\Application\\chrome.exe`,`${e}\\Microsoft\\Edge\\Application\\msedge.exe`,`${o}\\Microsoft\\Edge\\Application\\msedge.exe`],darwin:["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","/Applications/Chromium.app/Contents/MacOS/Chromium",...i?[`${i}/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`,`${i}/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge`,`${i}/Applications/Chromium.app/Contents/MacOS/Chromium`]:[]],linux:["/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/opt/google/chrome/chrome","/usr/bin/microsoft-edge","/usr/bin/microsoft-edge-stable","/opt/microsoft/msedge/msedge","/usr/bin/chromium","/usr/bin/chromium-browser","/snap/bin/chromium"]}[process.platform]??[]).find(s=>s&&I(s))??null}var $=()=>process.getuid?.()===0?["--no-sandbox"]:[],te=()=>["--no-first-run","--no-default-browser-check","--disable-extensions","--hide-scrollbars","--lang=zh-CN",...$()];function oe(o,e,r=[]){let i=o.location()?.url??"";return!/^Failed to load resource|^Refused to |Content Security Policy/.test(o.text())&&(!i||i.startsWith(e)||r.includes(i))}var re=o=>o.evaluateOnNewDocument(()=>{globalThis.__qaViolations=[],document.addEventListener("securitypolicyviolation",e=>{globalThis.__qaViolations.push({url:e.blockedURI,directive:e.effectiveDirective||e.violatedDirective,source:e.sourceFile,line:e.lineNumber})})}),V=3e4,W=5e3;function ie(o,e=W){let r=0,i=new Promise(c=>{r=setTimeout(c,e)});return Promise.race([Promise.resolve(o).catch(()=>{}),i]).finally(()=>clearTimeout(r))}var E=o=>new Promise(e=>setTimeout(e,o).unref()),D=o=>String(o??"").replace(/\s+/g," ").trim(),M=o=>{let e=o.split(/\r?\n/).map(D).filter(Boolean).at(-1);return e?`: ${e.slice(0,200)}`:""};async function se({executablePath:o,args:e=[],attempts:r=2,start:i=H}){let c=[];for(let s=0;s<r;s+=1){let n=await C.mkdtemp(q.join(_.tmpdir(),"gallery-browser-")),t=()=>C.rm(n,{recursive:!0,force:!0,maxRetries:5,retryDelay:200}).catch(()=>{});try{let{browser:a,stop:l}=await i({executablePath:o,args:e,profile:n});return{browser:a,failures:c,close:async()=>{await l().catch(()=>{}),await t()}}}catch(a){c.push(D(a?.message??a)),await t()}}throw Object.assign(new Error(c.at(-1)??"the browser did not start"),{failures:c})}async function H({executablePath:o,args:e,profile:r,starting:i=V}){let{default:c}=await import("./chunk-ERLAIBOA.mjs"),s=await c.defaultArgs({headless:!0,userDataDir:r,args:[...e,"--remote-debugging-port=0"]}),n=process.platform!=="win32",t=O(o,s,{stdio:["ignore","ignore","pipe"],windowsHide:!0,detached:n}),a=!1;t.on("error",()=>a||=t.pid===void 0);let l=()=>a||t.exitCode!==null||t.signalCode!==null,u=new Promise(f=>t.once("exit",f)),m=()=>{if(!l())try{n?process.kill(-t.pid,"SIGKILL"):t.kill()}catch{try{t.kill("SIGKILL")}catch{}}};process.once("exit",m);let p="",d=new Promise((f,w)=>{let g=setTimeout(()=>w(new Error(`it said nothing of its DevTools port in ${i/1e3}s${M(p)}`)),i);t.stderr.setEncoding("utf8"),t.stderr.on("data",h=>{p=`${p}${h}`.slice(-4e3);let y=/DevTools listening on (ws:\/\/\S+)/.exec(p);y&&(clearTimeout(g),f(y[1]))}),t.once("error",h=>(clearTimeout(g),w(h))),t.once("exit",(h,y)=>(clearTimeout(g),w(new Error(`it stopped (${y??`exit ${h}`}) before it opened its DevTools port${M(p)}`))))}),A=async()=>{try{l()||await Promise.race([u,E(5e3)]),m(),l()||await Promise.race([u,E(3e3)])}finally{process.off("exit",m)}},v;try{let f=await d,w=0,g=new Promise((y,G)=>{w=setTimeout(()=>G(new Error(`it opened its DevTools port and did not answer in ${i/1e3}s`)),i)}),h=c.connect({browserWSEndpoint:f,defaultViewport:{width:800,height:600}});h.catch(()=>{}),v=await Promise.race([h,g]).finally(()=>clearTimeout(w))}catch(f){throw m(),await A(),f}return{browser:v,stop:async()=>{await Promise.race([v.close().catch(()=>{}),E(5e3)]),await A()}}}var b=null,L=0,T=0;async function K(){let o=F();if(!o)throw Object.assign(new Error("\u6CA1\u6709\u627E\u5230 Chrome \u6216 Edge\uFF1A\u5BFC\u51FA PDF \u9700\u8981\u7535\u8111\u4E0A\u88C5\u6709\u5176\u4E2D\u4E00\u4E2A\u6D4F\u89C8\u5668"),{reason:"browser"});let{default:e}=await import("./chunk-ERLAIBOA.mjs");return e.launch({executablePath:o,headless:!0,args:["--no-first-run","--no-default-browser-check","--disable-extensions",...$()]})}async function R(o,e){clearTimeout(L),T+=1,b??=K().catch(i=>{throw b=null,i});let r=await(await b).newPage();try{return await r.emulateMediaFeatures([{name:"prefers-reduced-motion",value:"reduce"},{name:"prefers-color-scheme",value:"light"}]),await r.setViewport({width:1200,height:900}),await r.setContent(o,{waitUntil:"load",timeout:6e4}),await P(r,{changing:x}),await e(r)}finally{await r.close().catch(()=>{}),T-=1,T===0&&(L=setTimeout(async()=>{let i=b;b=null,(await i?.catch(()=>null))?.close().catch(()=>{})},N))}}async function P(o,{timeout:e=15e3,changing:r=e}={}){let i=[],c=(n,t,a=e)=>{t!==!0&&i.push(`${n} (${t===!1?`not in ${a/1e3}s`:t})`)},s=(n,t=e)=>o.evaluate(n,t).catch(a=>a.message);return c("the fonts loaded",await s(n=>Promise.race([Promise.resolve(document.fonts?.ready).then(()=>!0),new Promise(t=>setTimeout(()=>t(!1),n))]))),c("the kit's first drawing done (data-doc-drawn)",await s(n=>new Promise(t=>{let a=Date.now(),l=()=>{!globalThis.DocKit||document.documentElement.hasAttribute("data-doc-drawn")?(globalThis.DocCode?.colorAll?.(),t(!0)):Date.now()-a>n?t(!1):setTimeout(l,50)};l()}))),c("the page done changing",await s(n=>new Promise(t=>{let a=()=>[document.documentElement.scrollHeight,...[...document.querySelectorAll("[style]")].map(d=>d.getAttribute("style")),...[...document.adoptedStyleSheets??[]].flatMap(d=>[...d.cssRules].map(A=>A.cssText)),...[...document.querySelectorAll("svg, canvas")].map(d=>d.outerHTML.length),[...document.images].filter(d=>d.complete).length].join("|"),l=Date.now(),u=a(),m=0,p=()=>{let d=a();m=d===u?m+1:0,u=d,m>=3?t(!0):Date.now()-l>n?t(!1):setTimeout(p,100)};setTimeout(p,100)}),r),r),i}async function k(o){await o.evaluate(()=>{document.documentElement.setAttribute("data-doc-theme","light");for(let e of document.querySelectorAll("[data-doc-sheets]")){let r=e.querySelector(":scope > .doc-sheet-tabs");if(r){for(let i of r.querySelectorAll(":scope > .doc-sheet-tab")){let c=i.getAttribute("data-sheet-tab"),s=[...e.querySelectorAll(":scope > [data-doc-sheet]")].find(a=>a.getAttribute("data-doc-sheet")===c);if(!s)continue;s.hidden=!1,s.removeAttribute("aria-hidden"),s.style.setProperty("display","block","important");let n=r.cloneNode(!1);n.removeAttribute("id"),n.removeAttribute("role"),n.style.setProperty("break-after","avoid");let t=i.cloneNode(!0);t.removeAttribute("id"),t.setAttribute("aria-selected","true"),t.classList.add("is-active"),n.append(t),s.before(n)}r.style.setProperty("display","none","important")}}for(let e of document.querySelectorAll("details"))e.open=!0;window.dispatchEvent(new Event("resize"))}),await P(o,{changing:x})}var j={A4:793.7,A3:1122.5,Letter:816,Legal:816,Tabloid:1056},z=96;async function U(o,e){await o.emulateMediaType("print");let r=await o.evaluate(()=>Math.max(0,innerWidth-document.documentElement.clientWidth));await o.setViewport({width:Math.floor(e)+r,height:900}),await P(o,{changing:x})}function ne(o,{paper:e="A4",scale:r=1}={}){let i=B.includes(e)?e:"A4",c=Math.min(2,Math.max(.1,r));return R(o,async s=>(await k(s),await U(s,(j[i]-2*z)/c),Buffer.from(await s.pdf({format:i,scale:c,printBackground:!0,margin:{top:"1in",right:"1in",bottom:"1in",left:"1in"}}))))}function ae(o){return R(o,async e=>{await k(e);let r=e.viewport(),i=await e.$$("main figure.doc-figure"),c=[];for(let s of i){let n=0;try{n=await s.evaluate(async(t,a)=>{let l=[];for(let u=t.closest(a);u;u=u.parentElement.closest(a))l.unshift(u);for(let u of l)u.style.setProperty("height","auto"),u.style.setProperty("max-height","calc(100dvh - (2 * var(--doc-dialog-margin)))"),u.showModal();return await new Promise(u=>requestAnimationFrame(()=>requestAnimationFrame(u))),l.length?Math.ceil(t.getBoundingClientRect().height):0},S),n&&(await e.setViewport({...r,height:r.height+n}),await P(e,{changing:x})),await s.evaluate(t=>t.scrollIntoView({block:"center"})),c.push(Buffer.from(await s.screenshot({type:"png"})))}catch{c.push(null)}await s.evaluate((t,a)=>{for(let l=t.closest(a);l;l=l.parentElement.closest(a))l.close(),l.style.removeProperty("height"),l.style.removeProperty("max-height"),l.getAttribute("style")||l.removeAttribute("style")},S).catch(()=>{}),n&&await e.setViewport(r).catch(()=>{})}return c})}export{F as a,te as b,oe as c,re as d,W as e,ie as f,se as g,P as h,ne as i,ae as j};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{d as m,i as g,k as p}from"./chunk-JJNRIFND.mjs";import{b as a,f as l,i as c}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as i}from"../browser/shared/paths.mjs";import{joinDefaultTree as b,joinedLine as k}from"../browser/shared/drafts.mjs";var D=5e3;async function v(f){let{positional:s,options:u}=l({options:["--no-browser"],argv:f});if(s.length>1)throw new a("Name one document at most.");let{slug:o=null,block:w=null}=s.length?await c(s[0]):{};console.log(`\u5DE5\u4F5C\u533A\uFF1A${i}`);let e=await g({slug:o,baseline:o!==null});if(e.ok||console.error(e.message),e.reason==="missing"){let{HOME:n,pageExists:d}=await import("../browser/shared/pages.mjs"),{missingPageSaid:E,HOME_NOT_MADE:r}=await import("./chunk-DAMVDXR3.mjs");d(o,i)?console.error(`"${o}" is a custom page, not a document: gallery page open ${o} opens it and gives its address.`):o===n&&await E(o,i)===r&&console.error(r)}if(o!==null&&e.reason!=="missing"){let{roundBegins:n}=await import("./chunk-TDWJKOLN.mjs");await n(o,e.ok?{}:{wait:D})}if(o!==null&&e.reason!=="missing"){let n=k(await b(i,o));n&&console.log(n)}e.ok||process.exit(1);let t=await p(o,e,w);for(let n of t)console.log(n);console.log(await m(t,u))}export{v as run};
2
+ import{d as m,i as g,k as p}from"./chunk-SQ3FQCCN.mjs";import{b as a,f as l,i as c}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{reportsDirectory as i}from"../browser/shared/paths.mjs";import{joinDefaultTree as b,joinedLine as k}from"../browser/shared/drafts.mjs";var D=5e3;async function v(f){let{positional:s,options:u}=l({options:["--no-browser"],argv:f});if(s.length>1)throw new a("Name one document at most.");let{slug:o=null,block:w=null}=s.length?await c(s[0]):{};console.log(`\u5DE5\u4F5C\u533A\uFF1A${i}`);let e=await g({slug:o,baseline:o!==null});if(e.ok||console.error(e.message),e.reason==="missing"){let{HOME:n,pageExists:d}=await import("../browser/shared/pages.mjs"),{missingPageSaid:E,HOME_NOT_MADE:r}=await import("./chunk-ONKC4BCC.mjs");d(o,i)?console.error(`"${o}" is a custom page, not a document: gallery page open ${o} opens it and gives its address.`):o===n&&await E(o,i)===r&&console.error(r)}if(o!==null&&e.reason!=="missing"){let{roundBegins:n}=await import("./chunk-Z6OKLRHC.mjs");await n(o,e.ok?{}:{wait:D})}if(o!==null&&e.reason!=="missing"){let n=k(await b(i,o));n&&console.log(n)}e.ok||process.exit(1);let t=await p(o,e,w);for(let n of t)console.log(n);console.log(await m(t,u))}export{v as run};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c}from"./chunk-HBAUKKQH.mjs";import"./chunk-YPPJVDQI.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as documentsOf,c as run,b as when};
2
+ import{a,b,c}from"./chunk-QP7BOHE4.mjs";import"./chunk-GMJD7ID3.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as documentsOf,c as run,b as when};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as S,b as K,c as E,d as v,e as x,f as H}from"./chunk-YPPJVDQI.mjs";import{a as D,b as j}from"./chunk-JEUK3ZO7.mjs";import{b as M,f as R,h as T}from"./chunk-4OZWXZE5.mjs";import O from"node:fs/promises";import _ from"node:path";import{iconKind as ee}from"../browser/shared/emoji/icon-value.mjs";import{descendantsIn as J,parentIn as C}from"../browser/shared/outline.mjs";import{topOf as U}from"../browser/shared/outline-shape.mjs";import{fullAddress as z,namedPlace as te}from"../browser/shared/page-address.mjs";import{reportsDirectory as G}from"../browser/shared/paths.mjs";import{documentLinks as Q,listReportSlugs as oe,roleOf as ne}from"../browser/shared/reports.mjs";import{documentDirectory as se,documentFiles as le,isSlugName as ie}from"../browser/shared/workspace.mjs";import{isWorkspace as W,readRegistry as re,workspaceKey as Y}from"../browser/shared/workspace-registry.mjs";import{findIn as ce,rankReports as V,reportLines as ae}from"../browser/shared/search.mjs";async function X(i=G){let n=(await oe(i)).filter(ie);return(await Promise.all(n.map(async a=>{let r=se(a,i),{html:u,json:s}=le(r),g=await O.stat(u).catch(()=>null);if(!g?.isFile()||await ne(r)==="instructions")return null;let l=await O.readFile(s,"utf8").then(JSON.parse).catch(()=>({})),d=t=>typeof t=="string"?t.replace(/\s+/g," ").trim():"";return{slug:a,title:d(l.title)||a,description:d(l.description),edited:g.mtimeMs,file:u}}))).filter(Boolean)}var P=i=>{let n=new Date(i),o=a=>String(a).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`},k=i=>`${i} document${i===1?"":"s"}`;async function de(i,n,o){let a=[...new Set(o.toLowerCase().split(/\s+/).filter(Boolean))],r=new Set(n.map(({slug:s})=>s));return(await Promise.all(i.filter(({slug:s})=>!r.has(s)).map(async s=>{let g=ae(await O.readFile(s.file,"utf8").catch(()=>"")),l=a.map(d=>ce(g,d,{most:1})).filter(({count:d})=>d>0);return l.length?{...s,words:l.length,count:l.reduce((d,{count:t})=>d+t,0),hit:l[0].hits[0].text}:null}))).filter(Boolean).sort((s,g)=>g.words-s.words||g.count-s.count||g.edited-s.edited)}var q=i=>[...i.documents.values()].filter(n=>typeof n.url=="string"),F=i=>`${i} web link${i===1?"":"s"}`;async function ge(i,n){if(i.length>1)throw new M("--tree takes one document at most (its slug, link or address).");let o=await S(),a=new Map(n.map(e=>[e.slug,e])),r=new Map((o.extensions??[]).map(e=>[e.id,e])),u=o.columns.filter(e=>(!e.extension||r.has(e.extension))&&!e.hidden&&!e.away),s=u.length>1?u:null,g=o.children[""]??[],l=null;if(i.length===1){let e=await H(i[0],"--tree",o);if(e.refused){for(let h of await j({reading:!0}))console.log(h);console.error(e.refused),process.exit(1)}l=e.slug,g=[l]}for(let e of await j({reading:!0}))console.log(e);let d=e=>console.log(`${e.title}\u680F\uFF08\u6269\u5C55 ${e.id}\uFF1A${e.error?`\u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.error.message}`:`${e.count} \u4E2A\u6761\u76EE`}\uFF1Bgallery extension check ${e.id} \u6253\u51FA\u5B83\u4EEC\uFF09`),t=()=>{for(let e of r.values())d(e)},p=u.filter(e=>!e.extension).flatMap(e=>J(o.children,U(e.id))),f=p.filter(e=>o.documents.get(e)?.url!==void 0).length,m=p.length-f;if(m+f===0){console.log('No documents yet: gallery new <slug> "<title>" makes one.'),l===null&&t();return}let w=f?`${k(m)} and ${F(f)}`:k(m);if(l===null)console.log(`${w}, as the sidebar shows them (one under another indented)${s?", column by column":""}:`);else{let e=J(o.children,l),h=e.some($=>o.documents.get($)?.url!==void 0)?`${e.length} ${e.length===1?"entry":"entries"}`:k(e.length);console.log(x(o,l)),console.log(e.length?`${v(o,l)} and the ${h} under it, as the sidebar shows them:`:`${v(o,l)}, with no document under it:`)}let c=(e,h)=>{let{title:$,description:y,icon:b,url:B,draft:N}=o.documents.get(e),A=a.get(e)?.edited,L=E(o,e),I=B!==void 0?[`\u7F51\u9875\u94FE\u63A5\uFF1A${B}`]:N?[N.missing?"\u522B\u5904\u7684\u5E95\u7A3F\uFF0C\u627E\u4E0D\u5230\u4E86":L?`\u300C${L}\u300D\u7684\u5E95\u7A3F\uFF1A${N.path}`:`\u522B\u5904\u7684\u5E95\u7A3F\uFF1A${N.path}`]:[...L?[`\u300C${L}\u300D\u7684\u6587\u6863`]:[],...y?[`\u8BF4\u660E\uFF1A${y}`]:[],...A?[`\u4E0A\u6B21\u7F16\u8F91\uFF1A${P(A)}`]:[]];console.log(`${" ".repeat(h)}${e} ${ee(b)==="emoji"?`${b} `:""}${$}${I.length?` \uFF08${I.join("\uFF1B")}\uFF09`:""}`);for(let Z of o.children[e]??[])c(Z,h+1)};if(l!==null||!s){for(let e of g)c(e,0);l===null&&t();return}for(let e of s){if(e.extension){d(r.get(e.extension)),r.delete(e.extension);continue}let h=o.children[U(e.id)]??[];console.log(`${K(e)}\u680F${h.length?"":"\uFF08\u7A7A\uFF09"}`);for(let $ of h)c($,1)}t()}async function fe(i){let n=_.resolve(G),o=(t,p)=>Y(t)===Y(p),a=[n,...re().workspaces.map(({root:t})=>t).filter(t=>!o(t,n))],r=a.filter(W),u=a.filter(t=>!W(t)),s=(await Promise.all(r.map(async t=>(await X(t)).map(p=>({...p,root:t}))))).flat(),g=i.join(" ").trim(),l=V(s,g),d=`${r.length} workspace${r.length===1?"":"s"}`;if(console.log(`Searched ${d} of this machine (gallery workspaces lists them; the current one: ${n}).`),s.length===0)console.log(`No documents in ${r.length===1?"it":"any of them"} yet.`);else if(l.length===0)console.log(`No document's title, description or slug in the ${d} holds ${g.split(/\s+/).map(t=>`"${t}"`).join(" or ")}: gallery list --all lists all ${s.length}.`);else{console.log(g?`${l.length} of ${k(s.length)}, the best match first:`:`${k(s.length)}, the one edited last first:`);let t=new Map,p=f=>(t.has(f)||t.set(f,Promise.all([Q(f),S(f)]).then(([{links:m},w])=>({links:m,tree:w}))),t.get(f));for(let{root:f,slug:m,title:w,description:c,edited:e,file:h}of l){let{links:$,tree:y}=await p(f);console.log(`\u5DE5\u4F5C\u533A\uFF1A${f}`),console.log(`${m} ${w}`),c&&console.log(` \u8BF4\u660E\uFF1A${c}`),C(y.children,m)&&console.log(` ${x(y,m)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:m},$)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P(e)}`),console.log(` ${D(h)}`)}console.log('One in another workspace is worked on there: pass its \u5DE5\u4F5C\u533A as --workspace to every command (gallery open <slug> --workspace "<\u5DE5\u4F5C\u533A>" gives its address).')}u.length&&console.log(`Not searched, no longer there (gallery workspaces --forget <path> forgets one, nothing on disk changed): ${u.join(", ")}`)}async function Me(i){let{positional:n,options:o}=R({options:["--tree","--all"],argv:i});if(o.has("--all")){if(o.has("--tree"))throw new M("--all and --tree go apart: --tree is the current workspace's tree.");return fe(n)}let a=await X();if(o.has("--tree"))return ge(n,a);let r=n.join(" ").trim(),{links:u}=await Q(),s=n.length===1?te(n[0],u):null,g=s&&s.slug!==n[0],l=g?a.filter(({slug:c})=>c===s.slug):V(a,r),d=[...l,...r&&!g?await de(a,l,r):[]],t=await S(),p=r.toLowerCase().split(/\s+/).filter(Boolean),f=g?[]:q(t).filter(({slug:c,title:e,url:h})=>!p.length||p.some($=>`${e} ${h} ${c}`.toLowerCase().includes($))),m=n.length===1&&d.length===0&&f.length===0?await T(n[0]):null;for(let c of await j({reading:!0}))console.log(c);let w=()=>{if(!f.length)return;let c=q(t).length;console.log(r?`${f.length} of ${F(c)} in the sidebar:`:`${F(c)} in the sidebar:`);for(let{slug:e,title:h,url:$}of f)console.log(`${e} ${h}`),console.log(` \u7F51\u9875\u94FE\u63A5\uFF1A${$}`),C(t.children,e)&&console.log(` ${x(t,e)}`)};if(m)console.log(m);else if(a.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.'),w();else if(d.length===0&&f.length===0)console.log(`No document's title, description, slug or text holds ${r.split(/\s+/).map(c=>`"${c}"`).join(" or ")}: gallery list lists all ${a.length}.`);else if(d.length===0)w();else{console.log(r?`${d.length} of ${k(a.length)}, the best match first:`:`${k(a.length)}, the one edited last first:`);for(let{slug:c,title:e,description:h,edited:$,file:y,hit:b}of d)console.log(`${c} ${e}`),h&&console.log(` \u8BF4\u660E\uFF1A${h}`),b&&console.log(` \u6B63\u6587\uFF1A${b}`),C(t.children,c)&&console.log(` ${x(t,c)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:c},u)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P($)}`),console.log(` ${D(y)}`);w()}}export{X as a,P as b,Me as c};
2
+ import{a as S,b as K,c as E,d as v,e as x,f as H}from"./chunk-GMJD7ID3.mjs";import{a as D,b as j}from"./chunk-JEUK3ZO7.mjs";import{b as M,f as R,h as T}from"./chunk-4OZWXZE5.mjs";import O from"node:fs/promises";import _ from"node:path";import{iconKind as ee}from"../browser/shared/emoji/icon-value.mjs";import{descendantsIn as J,parentIn as C}from"../browser/shared/outline.mjs";import{topOf as U}from"../browser/shared/outline-shape.mjs";import{fullAddress as z,namedPlace as te}from"../browser/shared/page-address.mjs";import{reportsDirectory as G}from"../browser/shared/paths.mjs";import{documentLinks as Q,listReportSlugs as oe,roleOf as ne}from"../browser/shared/reports.mjs";import{documentDirectory as se,documentFiles as le,isSlugName as ie}from"../browser/shared/workspace.mjs";import{isWorkspace as W,readRegistry as re,workspaceKey as Y}from"../browser/shared/workspace-registry.mjs";import{findIn as ce,rankReports as V,reportLines as ae}from"../browser/shared/search.mjs";async function X(i=G){let n=(await oe(i)).filter(ie);return(await Promise.all(n.map(async a=>{let r=se(a,i),{html:u,json:s}=le(r),g=await O.stat(u).catch(()=>null);if(!g?.isFile()||await ne(r)==="instructions")return null;let l=await O.readFile(s,"utf8").then(JSON.parse).catch(()=>({})),d=t=>typeof t=="string"?t.replace(/\s+/g," ").trim():"";return{slug:a,title:d(l.title)||a,description:d(l.description),edited:g.mtimeMs,file:u}}))).filter(Boolean)}var P=i=>{let n=new Date(i),o=a=>String(a).padStart(2,"0");return`${n.getFullYear()}-${o(n.getMonth()+1)}-${o(n.getDate())} ${o(n.getHours())}:${o(n.getMinutes())}`},k=i=>`${i} document${i===1?"":"s"}`;async function de(i,n,o){let a=[...new Set(o.toLowerCase().split(/\s+/).filter(Boolean))],r=new Set(n.map(({slug:s})=>s));return(await Promise.all(i.filter(({slug:s})=>!r.has(s)).map(async s=>{let g=ae(await O.readFile(s.file,"utf8").catch(()=>"")),l=a.map(d=>ce(g,d,{most:1})).filter(({count:d})=>d>0);return l.length?{...s,words:l.length,count:l.reduce((d,{count:t})=>d+t,0),hit:l[0].hits[0].text}:null}))).filter(Boolean).sort((s,g)=>g.words-s.words||g.count-s.count||g.edited-s.edited)}var q=i=>[...i.documents.values()].filter(n=>typeof n.url=="string"),F=i=>`${i} web link${i===1?"":"s"}`;async function ge(i,n){if(i.length>1)throw new M("--tree takes one document at most (its slug, link or address).");let o=await S(),a=new Map(n.map(e=>[e.slug,e])),r=new Map((o.extensions??[]).map(e=>[e.id,e])),u=o.columns.filter(e=>(!e.extension||r.has(e.extension))&&!e.hidden&&!e.away),s=u.length>1?u:null,g=o.children[""]??[],l=null;if(i.length===1){let e=await H(i[0],"--tree",o);if(e.refused){for(let h of await j({reading:!0}))console.log(h);console.error(e.refused),process.exit(1)}l=e.slug,g=[l]}for(let e of await j({reading:!0}))console.log(e);let d=e=>console.log(`${e.title}\u680F\uFF08\u6269\u5C55 ${e.id}\uFF1A${e.error?`\u6761\u76EE\u8BFB\u4E0D\u51FA\u6765\uFF1A${e.error.message}`:`${e.count} \u4E2A\u6761\u76EE`}\uFF1Bgallery extension check ${e.id} \u6253\u51FA\u5B83\u4EEC\uFF09`),t=()=>{for(let e of r.values())d(e)},p=u.filter(e=>!e.extension).flatMap(e=>J(o.children,U(e.id))),f=p.filter(e=>o.documents.get(e)?.url!==void 0).length,m=p.length-f;if(m+f===0){console.log('No documents yet: gallery new <slug> "<title>" makes one.'),l===null&&t();return}let w=f?`${k(m)} and ${F(f)}`:k(m);if(l===null)console.log(`${w}, as the sidebar shows them (one under another indented)${s?", column by column":""}:`);else{let e=J(o.children,l),h=e.some($=>o.documents.get($)?.url!==void 0)?`${e.length} ${e.length===1?"entry":"entries"}`:k(e.length);console.log(x(o,l)),console.log(e.length?`${v(o,l)} and the ${h} under it, as the sidebar shows them:`:`${v(o,l)}, with no document under it:`)}let c=(e,h)=>{let{title:$,description:y,icon:b,url:B,draft:N}=o.documents.get(e),A=a.get(e)?.edited,L=E(o,e),I=B!==void 0?[`\u7F51\u9875\u94FE\u63A5\uFF1A${B}`]:N?[N.missing?"\u522B\u5904\u7684\u5E95\u7A3F\uFF0C\u627E\u4E0D\u5230\u4E86":L?`\u300C${L}\u300D\u7684\u5E95\u7A3F\uFF1A${N.path}`:`\u522B\u5904\u7684\u5E95\u7A3F\uFF1A${N.path}`]:[...L?[`\u300C${L}\u300D\u7684\u6587\u6863`]:[],...y?[`\u8BF4\u660E\uFF1A${y}`]:[],...A?[`\u4E0A\u6B21\u7F16\u8F91\uFF1A${P(A)}`]:[]];console.log(`${" ".repeat(h)}${e} ${ee(b)==="emoji"?`${b} `:""}${$}${I.length?` \uFF08${I.join("\uFF1B")}\uFF09`:""}`);for(let Z of o.children[e]??[])c(Z,h+1)};if(l!==null||!s){for(let e of g)c(e,0);l===null&&t();return}for(let e of s){if(e.extension){d(r.get(e.extension)),r.delete(e.extension);continue}let h=o.children[U(e.id)]??[];console.log(`${K(e)}\u680F${h.length?"":"\uFF08\u7A7A\uFF09"}`);for(let $ of h)c($,1)}t()}async function fe(i){let n=_.resolve(G),o=(t,p)=>Y(t)===Y(p),a=[n,...re().workspaces.map(({root:t})=>t).filter(t=>!o(t,n))],r=a.filter(W),u=a.filter(t=>!W(t)),s=(await Promise.all(r.map(async t=>(await X(t)).map(p=>({...p,root:t}))))).flat(),g=i.join(" ").trim(),l=V(s,g),d=`${r.length} workspace${r.length===1?"":"s"}`;if(console.log(`Searched ${d} of this machine (gallery workspaces lists them; the current one: ${n}).`),s.length===0)console.log(`No documents in ${r.length===1?"it":"any of them"} yet.`);else if(l.length===0)console.log(`No document's title, description or slug in the ${d} holds ${g.split(/\s+/).map(t=>`"${t}"`).join(" or ")}: gallery list --all lists all ${s.length}.`);else{console.log(g?`${l.length} of ${k(s.length)}, the best match first:`:`${k(s.length)}, the one edited last first:`);let t=new Map,p=f=>(t.has(f)||t.set(f,Promise.all([Q(f),S(f)]).then(([{links:m},w])=>({links:m,tree:w}))),t.get(f));for(let{root:f,slug:m,title:w,description:c,edited:e,file:h}of l){let{links:$,tree:y}=await p(f);console.log(`\u5DE5\u4F5C\u533A\uFF1A${f}`),console.log(`${m} ${w}`),c&&console.log(` \u8BF4\u660E\uFF1A${c}`),C(y.children,m)&&console.log(` ${x(y,m)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:m},$)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P(e)}`),console.log(` ${D(h)}`)}console.log('One in another workspace is worked on there: pass its \u5DE5\u4F5C\u533A as --workspace to every command (gallery open <slug> --workspace "<\u5DE5\u4F5C\u533A>" gives its address).')}u.length&&console.log(`Not searched, no longer there (gallery workspaces --forget <path> forgets one, nothing on disk changed): ${u.join(", ")}`)}async function Me(i){let{positional:n,options:o}=R({options:["--tree","--all"],argv:i});if(o.has("--all")){if(o.has("--tree"))throw new M("--all and --tree go apart: --tree is the current workspace's tree.");return fe(n)}let a=await X();if(o.has("--tree"))return ge(n,a);let r=n.join(" ").trim(),{links:u}=await Q(),s=n.length===1?te(n[0],u):null,g=s&&s.slug!==n[0],l=g?a.filter(({slug:c})=>c===s.slug):V(a,r),d=[...l,...r&&!g?await de(a,l,r):[]],t=await S(),p=r.toLowerCase().split(/\s+/).filter(Boolean),f=g?[]:q(t).filter(({slug:c,title:e,url:h})=>!p.length||p.some($=>`${e} ${h} ${c}`.toLowerCase().includes($))),m=n.length===1&&d.length===0&&f.length===0?await T(n[0]):null;for(let c of await j({reading:!0}))console.log(c);let w=()=>{if(!f.length)return;let c=q(t).length;console.log(r?`${f.length} of ${F(c)} in the sidebar:`:`${F(c)} in the sidebar:`);for(let{slug:e,title:h,url:$}of f)console.log(`${e} ${h}`),console.log(` \u7F51\u9875\u94FE\u63A5\uFF1A${$}`),C(t.children,e)&&console.log(` ${x(t,e)}`)};if(m)console.log(m);else if(a.length===0)console.log('No documents yet: gallery new <slug> "<title>" makes one.'),w();else if(d.length===0&&f.length===0)console.log(`No document's title, description, slug or text holds ${r.split(/\s+/).map(c=>`"${c}"`).join(" or ")}: gallery list lists all ${a.length}.`);else if(d.length===0)w();else{console.log(r?`${d.length} of ${k(a.length)}, the best match first:`:`${k(a.length)}, the one edited last first:`);for(let{slug:c,title:e,description:h,edited:$,file:y,hit:b}of d)console.log(`${c} ${e}`),h&&console.log(` \u8BF4\u660E\uFF1A${h}`),b&&console.log(` \u6B63\u6587\uFF1A${b}`),C(t.children,c)&&console.log(` ${x(t,c)}`),console.log(` \u5730\u5740\uFF1A${z("",{slug:c},u)}`),console.log(` \u4E0A\u6B21\u7F16\u8F91\uFF1A${P($)}`),console.log(` ${D(y)}`);w()}}export{X as a,P as b,Me as c};
@@ -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 n,f as t}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{answerOf as p,readAnnouncement as a,stopServer as d}from"../browser/shared/preview-server.mjs";async function u(i){let{positional:r}=t({argv:i});if(r.length>0)throw new n(`gallery stop takes no arguments: ${r[0]}`);let e=await a(),s=e?await p(e,1e4):"no";if(s==="no")return void console.log("No Gallery server runs.");s==="busy"&&(console.error(`The Gallery server on port ${e.port} (pid ${e.pid}) took the request and gave no answer in 10s: it is busy or stuck. Run gallery stop again in a while, or end process ${e.pid} yourself.`),process.exit(1)),e.kind==="dev"&&(console.error(`The shared Gallery server is npm run dev's (port ${e.port}, pid ${e.pid}): stop it where it runs.`),process.exit(1));let o=await d(e);o.ok||(console.error(o.message),process.exit(1)),console.log(`Stopped the server on port ${e.port} (pid ${e.pid})${o.killed?": it did not stop by itself in 10s, so its process was ended":""}.`)}export{u as run};