@heycys/gallery 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/components/icon/page.mjs +6 -4
  3. package/browser/editor/components/icons.mjs +2 -2
  4. package/browser/editor/page/annotate/index.mjs +3 -2
  5. package/browser/editor/page/board/index.mjs +2 -1
  6. package/browser/editor/page/board/settings.mjs +2 -1
  7. package/browser/editor/page/clipboard/import/read.mjs +20 -2
  8. package/browser/editor/page/core.mjs +3 -2
  9. package/browser/editor/page/custom-page.mjs +4 -3
  10. package/browser/editor/page/editor.mjs +9 -5
  11. package/browser/editor/page/emoji-picker/support.mjs +3 -2
  12. package/browser/editor/page/links/index.mjs +1 -12
  13. package/browser/editor/page/links/pages.mjs +3 -2
  14. package/browser/editor/page/outline/folds.mjs +3 -0
  15. package/browser/editor/page/post.mjs +2 -1
  16. package/browser/editor/page/present-links.mjs +4 -3
  17. package/browser/editor/page/present-shell.mjs +3 -58
  18. package/browser/editor/page/session.mjs +3 -37
  19. package/browser/editor/page/storage.mjs +5 -5
  20. package/browser/shared/component-catalog.mjs +2 -2
  21. package/browser/shared/document-copy.mjs +43 -0
  22. package/browser/shared/drafts.mjs +32 -50
  23. package/browser/shared/emoji/icon-value.mjs +4 -3
  24. package/browser/shared/extension-manifest.mjs +90 -0
  25. package/browser/shared/extensions.mjs +93 -7
  26. package/browser/shared/http.mjs +1 -1
  27. package/browser/shared/i18n/en.mjs +55 -14
  28. package/browser/shared/media.mjs +2 -1
  29. package/browser/shared/outline-shape.mjs +6 -0
  30. package/browser/shared/outline.mjs +95 -10
  31. package/browser/shared/page-address.mjs +8 -15
  32. package/browser/shared/paths.mjs +2 -1
  33. package/browser/shared/preferences.mjs +3 -1
  34. package/browser/shared/preview-server.mjs +51 -63
  35. package/browser/shared/service-location.mjs +18 -0
  36. package/browser/shared/session.mjs +3 -6
  37. package/browser/shared/workspace-address.mjs +19 -0
  38. package/browser/shared/workspace-columns.mjs +12 -9
  39. package/browser/shared/workspace-registry.mjs +6 -40
  40. package/browser/shared/workspace.mjs +3 -6
  41. package/browser/shared/writing-preferences.mjs +6 -4
  42. package/dist/{chunk-W7665ZEC.mjs → chunk-236JJXWY.mjs} +2 -2
  43. package/dist/{chunk-EAIFITAV.mjs → chunk-2KAVXMKG.mjs} +1 -1
  44. package/dist/chunk-2T4PZQEP.mjs +2 -0
  45. package/dist/{chunk-HXG7EOPJ.mjs → chunk-3SKOU6OZ.mjs} +1 -1
  46. package/dist/{chunk-AR5D57ZD.mjs → chunk-3XZOA7AH.mjs} +2 -2
  47. package/dist/{chunk-UYVCQK3H.mjs → chunk-4B2TB5K2.mjs} +1 -1
  48. package/dist/{chunk-3MBRL2PM.mjs → chunk-4KUO7R2M.mjs} +8 -8
  49. package/dist/chunk-4SNV4HA5.mjs +2 -0
  50. package/dist/chunk-53XDTHTG.mjs +4 -0
  51. package/dist/chunk-5XV3YYLG.mjs +2 -0
  52. package/dist/{chunk-ZDLPUOAG.mjs → chunk-65NTKF4N.mjs} +1 -1
  53. package/dist/chunk-6GV3CBB2.mjs +2 -0
  54. package/dist/{chunk-WQDQWCX5.mjs → chunk-6L6V7YR2.mjs} +1 -1
  55. package/dist/{chunk-ITOH5EGO.mjs → chunk-6NLXUKAY.mjs} +1 -1
  56. package/dist/chunk-6Q7ASAXJ.mjs +3 -0
  57. package/dist/{chunk-7OG26PGF.mjs → chunk-6QWQXHAV.mjs} +1 -1
  58. package/dist/chunk-6XD6U3QA.mjs +5 -0
  59. package/dist/{chunk-YNAWBAYN.mjs → chunk-7EFHNQ5B.mjs} +1 -1
  60. package/dist/{chunk-OFHXGWOX.mjs → chunk-7ISBBDJR.mjs} +1 -1
  61. package/dist/{chunk-QE5RG76S.mjs → chunk-7UZUQQ7Q.mjs} +29 -24
  62. package/dist/chunk-BLNQUR5R.mjs +168 -0
  63. package/dist/chunk-BMX3VUHY.mjs +2 -0
  64. package/dist/chunk-BN7M3IN7.mjs +8 -0
  65. package/dist/{chunk-K5XATEOO.mjs → chunk-BQNTTFPL.mjs} +1 -1
  66. package/dist/chunk-C257H6IA.mjs +2 -0
  67. package/dist/chunk-CHQU37CA.mjs +2 -0
  68. package/dist/{chunk-CMA72MAG.mjs → chunk-E4IHAIJ7.mjs} +1 -1
  69. package/dist/{chunk-VS7JIGJW.mjs → chunk-E7656LR7.mjs} +1 -1
  70. package/dist/{chunk-VFX2KNHP.mjs → chunk-ECZBLQKK.mjs} +1 -1
  71. package/dist/{chunk-MN7BZL4R.mjs → chunk-ERE2BXYV.mjs} +1 -1
  72. package/dist/chunk-FFV733MA.mjs +2 -0
  73. package/dist/{chunk-AHN3NFKJ.mjs → chunk-GJJRBGMY.mjs} +1 -1
  74. package/dist/{chunk-BZ5RAF7L.mjs → chunk-GKOBB6DH.mjs} +1 -1
  75. package/dist/chunk-GMJD7ID3.mjs +2 -0
  76. package/dist/{chunk-OEXWRJME.mjs → chunk-IA2SIEJQ.mjs} +1 -1
  77. package/dist/chunk-JPG2LBQM.mjs +11 -0
  78. package/dist/{chunk-POTA2FV4.mjs → chunk-JXXHAXYH.mjs} +1 -1
  79. package/dist/{chunk-FDMAXMQA.mjs → chunk-K3JKPFL5.mjs} +1 -1
  80. package/dist/{chunk-J5PUIV3Y.mjs → chunk-KLQP46Y3.mjs} +1 -1
  81. package/dist/chunk-LMUZQK5O.mjs +2 -0
  82. package/dist/{chunk-JLTZF4LA.mjs → chunk-M4NRDYI5.mjs} +1 -1
  83. package/dist/{chunk-HPOI4ZX7.mjs → chunk-MKIBJTJZ.mjs} +1 -1
  84. package/dist/{chunk-5K44HLTZ.mjs → chunk-MNWJ4EZY.mjs} +1 -1
  85. package/dist/{chunk-FETSREUN.mjs → chunk-NHP66IWR.mjs} +1 -1
  86. package/dist/{chunk-PGDE24N5.mjs → chunk-OEIJLMPI.mjs} +1 -1
  87. package/dist/{chunk-YROX2O22.mjs → chunk-PDZR3L3C.mjs} +1 -1
  88. package/dist/{chunk-6N3PX4XX.mjs → chunk-PLB7L22J.mjs} +1 -1
  89. package/dist/{chunk-LM4XFQHZ.mjs → chunk-Q4MS6OFC.mjs} +1 -1
  90. package/dist/{chunk-7JDX4E65.mjs → chunk-Q7P3Q5YX.mjs} +1 -1
  91. package/dist/{chunk-ZHEHPMBK.mjs → chunk-QNECWMGR.mjs} +1 -1
  92. package/dist/{chunk-YI43RG4P.mjs → chunk-QP7BOHE4.mjs} +1 -1
  93. package/dist/chunk-QVGOPHOF.mjs +2 -0
  94. package/dist/{chunk-DAZL73VK.mjs → chunk-RRKJMHNX.mjs} +2 -2
  95. package/dist/chunk-S3SX3COT.mjs +20 -0
  96. package/dist/{chunk-HDWTZ763.mjs → chunk-TKWEX4FD.mjs} +2 -2
  97. package/dist/{chunk-YLPSMDIS.mjs → chunk-ULXSPX5H.mjs} +2 -2
  98. package/dist/chunk-USIHBCSW.mjs +15 -0
  99. package/dist/{chunk-TR7TWGHB.mjs → chunk-VPMRP2TL.mjs} +1 -1
  100. package/dist/{chunk-ZQS6H473.mjs → chunk-VRPVVMRB.mjs} +1 -1
  101. package/dist/{chunk-F6HVDZR4.mjs → chunk-VZ2RQ3AM.mjs} +1 -1
  102. package/dist/{chunk-R2ZDLJYT.mjs → chunk-W5NPH5UA.mjs} +1 -1
  103. package/dist/chunk-WFGPMCTZ.mjs +4 -0
  104. package/dist/chunk-XZCFPKGO.mjs +2 -0
  105. package/dist/{chunk-4OKWZY5E.mjs → chunk-YN37ZDLW.mjs} +1 -1
  106. package/dist/chunk-ZFGMJVJC.mjs +2 -0
  107. package/dist/cli.mjs +1 -1
  108. package/dist/server.mjs +1 -1
  109. package/dist/worker.mjs +1 -1
  110. package/kit/report.css +3 -3
  111. package/kit/runtime.js +12 -2
  112. package/kit/state.js +2 -0
  113. package/kit/ui.js +5 -1
  114. package/package.json +1 -1
  115. package/release.json +7 -7
  116. package/skill/SKILL.md +13 -12
  117. package/skill/references/building-blocks.md +1 -1
  118. package/skill/references/extensions.md +48 -8
  119. package/web/assets/index-FLb9jCfl.css +1 -0
  120. package/web/assets/index-czjrXVjf.js +15 -0
  121. package/web/index.html +2 -2
  122. package/dist/chunk-5XA2ZBAE.mjs +0 -8
  123. package/dist/chunk-67N2QJYT.mjs +0 -2
  124. package/dist/chunk-6KBYRA2C.mjs +0 -2
  125. package/dist/chunk-DJISHPUL.mjs +0 -3
  126. package/dist/chunk-EKNHM3P4.mjs +0 -2
  127. package/dist/chunk-EP25HDAJ.mjs +0 -2
  128. package/dist/chunk-GHOYKMQ3.mjs +0 -4
  129. package/dist/chunk-IV64FFI4.mjs +0 -2
  130. package/dist/chunk-J43Z6LSS.mjs +0 -2
  131. package/dist/chunk-JA7G53PC.mjs +0 -2
  132. package/dist/chunk-JZT7I2OJ.mjs +0 -2
  133. package/dist/chunk-L2SUIS5S.mjs +0 -2
  134. package/dist/chunk-L7UP52JO.mjs +0 -2
  135. package/dist/chunk-MTYYHM2G.mjs +0 -15
  136. package/dist/chunk-MXUBKDRO.mjs +0 -15
  137. package/dist/chunk-NAMN3RAF.mjs +0 -2
  138. package/dist/chunk-ORID3AE7.mjs +0 -166
  139. package/dist/chunk-SWUTTZCN.mjs +0 -2
  140. package/dist/chunk-U7NZI6N4.mjs +0 -4
  141. package/dist/chunk-UJQJKNGK.mjs +0 -2
  142. package/dist/chunk-ZWWC4KLF.mjs +0 -20
  143. package/web/assets/index-BM_K-Auu.css +0 -1
  144. package/web/assets/index-DRslOBiv.js +0 -15
@@ -1,4 +1,4 @@
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 $,a as H,c as y,d as v,e as q,f as K,g as Y,i as V,k as X,o as z}from"./chunk-VS7JIGJW.mjs";import{g as P}from"./chunk-HDWTZ763.mjs";import{b as S,e as U}from"./chunk-A55HN5OK.mjs";U();import{HOSTS as A,IDENTITY as dt}from"../browser/editor/components/registry.mjs";import{CODE as ut,MATH as tt,MEDIA as mt,PAGE as pt,TABLE as gt}from"../browser/editor/components/kit.mjs";import{TAB as ht}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as Nt,isInstance as w,matchesNode as x,partOf as bt}from"../browser/shared/components/index.mjs";import{texSource as It}from"../browser/editor/components/math/index.mjs";import{MENTION as M,MENTION_ICON as J,MENTION_PAGE as Q}from"../browser/shared/components/mention.mjs";import{imageFile as et}from"../browser/shared/media.mjs";import{isFileLink as kt}from"../browser/shared/page-address.mjs";import{isInkClass as xt}from"../browser/editor/page/marks.mjs";import{ownInline as Tt}from"../browser/editor/page/own.mjs";import{attr as h,hasClass as Ot}from"../browser/shared/html-tree.mjs";var Lt=new Set(["h1","h2","h3","h4","p","li"]),Ct=new Set(["h3","h4","p","figcaption"]),Et=Object.entries(A).flatMap(([t,e])=>(e.parts??[]).map(([r,a])=>{let c=Nt(r);if(c?.parts?.[a]?.edit!=="text")throw new Error(`Host ${t}: ${r} has no part ${a} edited as text`);return{kind:t,match:c.match,at:c.parts[a].at}})),St=t=>Et.filter(({match:e})=>x(t,e)).flatMap(({kind:e,at:r})=>bt(t,r).map(a=>({kind:e,part:a}))),vt=t=>t.sort((e,r)=>e.part.sourceCodeLocation.startOffset-r.part.sourceCodeLocation.startOffset),$t=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),wt=new Set(["ul","ol","blockquote"]),_=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),le={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function At(t,e,r){let a=A[t];if(!a)throw new Error(`Unknown block kind ${t}`);return a.caps({bound:r,blockLevel:y.has(e)})}var st=t=>t.tagName==="span"&&x(t,tt.inline),Bt=t=>t.tagName==="a"&&Ot(t,M),Pt=/^https?:\/\/[^\s"<>]+$/i,C=t=>t.attrs.map(e=>e.name).sort().join(),yt=t=>h(t,"class")===M&&t.childNodes.length===0&&(C(t)==="class"||C(t)===`class,${Q}`&&h(t,Q)==="");function _t(t){if(yt(t))return null;if(C(t)!=="class,href"||h(t,"class")!==M||!(Pt.test(h(t,"href"))||kt(h(t,"href"))))return"mention";let[e,...r]=t.childNodes;return(e?.tagName==="img"?C(e)==="alt,class,src"&&h(e,"class")===J&&h(e,"alt")===""&&et(h(e,"src")):e?.tagName==="span"&&C(e)==="class"&&h(e,"class")===J&&e.childNodes.length===0)&&r.length>0&&r.every(c=>c.nodeName==="#text")&&r.some(c=>c.value.trim())?null:"mention"}var Mt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(xt),jt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===ht,ot=t=>$t.has(t.tagName)||Mt(t)||jt(t),B=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":B(e)),at=t=>Tt(t.tagName,t.attrs,B(t)),Z=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==dt),Wt=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),Dt=(t,e,r={})=>t==="text"?y.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!r.plain;function j(t,e,r=!1,{cell:a=!1,pictures:c=a,known:l=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(r===!0)return`tag:${n.tagName}`;if(n.attrs.some(m=>/^on/i.test(m.name)))return"markup";if(r==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(a&&(n.tagName==="ul"||n.tagName==="ol")){let m=Ut(n,e,l);if(m)return m;continue}if(c&&n.tagName==="img"){if(Ft(n))return"picture";continue}if(st(n)){if(n.childNodes.some(m=>m.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(Bt(n)){let m=_t(n);if(m)return m;e.push(n.sourceCodeLocation);continue}if(at(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!ot(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&Wt(h(n,"href")??""))return"link";let N=j(n,e,!1,{known:l,pictures:c});if(N)return N}return null}var Gt=["src","alt","width"],Rt=/^[1-9]\d{0,3}$/;function Ft(t){let r=t.attrs.map(l=>l.name).find(l=>!Gt.includes(l));if(r)return`the attribute ${r}`;let a=h(t,"src");if(!et(a))return`its src (${a===void 0?"none":a.slice(0,80)}): no picture of the document's assets/ folder`;let c=h(t,"width");return c===void 0||Rt.test(c)?null:`its width (${c}): a whole number of pixels`}function Ut(t,e,r){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let a of t.childNodes){if(a.nodeName==="#text"&&!a.value.trim())continue;if(a.tagName!=="li")return`tag:${a.tagName??"text"}`;if(a.attrs.length>0||!a.sourceCodeLocation?.endTag)return"markup";let c=j(a,e,!1,{known:r,pictures:!0});if(c)return c}return null}function T(t){let e=[],r=[],a=new Map,c=null,l=(o,s,i=null)=>{let u=o.sourceCodeLocation;if(!A[s]||!u?.startTag||h(o,"contenteditable")!==void 0)return!1;let k=[],f=Dt(s,o.tagName),p=i?{childNodes:o.childNodes.slice(0,o.childNodes.indexOf(i))}:o,G=u.endTag?j(p,k,f,{cell:s==="cell"}):"markup";if(G)return r.push({at:u.startTag.endOffset-1,reason:G}),!1;let L=u.startTag.endOffset,ft=i?L+t.slice(L,i.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:u.endTag.startOffset,R={id:e.length,tag:o.tagName,kind:s,bound:!1,caps:{},start:u.startOffset,end:u.endOffset,innerStart:L,innerEnd:ft,atoms:k.map(F=>[F.startOffset-L,F.endOffset-L]),wrapper:null,nested:!!i,node:o};return e.push(R),a.set(o,R),!0},n=o=>(o.childNodes??[]).filter(s=>s.tagName),N=o=>{let s=o.sourceCodeLocation;return s?.startTag&&s.endTag?t.slice(s.startTag.endOffset,s.endTag.startOffset):null},m=o=>o.tagName!=="a"&&!Z(o)&&B(o)&&n(o).every(s=>at(s)?!B(s):ot(s)||st(s)),I=o=>{for(let s of n(o))s.tagName==="td"||s.tagName==="th"?l(s,"cell"):["thead","tbody","tfoot","tr"].includes(s.tagName)&&I(s)},d=o=>{for(let s of n(o))s.tagName==="table"?I(s):!_.has(s.tagName)&&!w(s)&&d(s)},b=o=>{let s=n(o);s.length===1&&s[0].tagName==="code"&&o.childNodes.every(i=>i.tagName||!i.value?.trim())?l(s[0],"code"):s.length===0?l(o,"code"):o.sourceCodeLocation?.startTag&&r.push({at:o.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},g=(o,s=!0)=>{for(let i of n(o)){let u=i.tagName,k=w(i);for(let{kind:f,part:p}of vt(k?$[V(i)].textParts(i,c??=P().packages):St(i)))l(p,f);if(k){for(let{element:f}of Y(i))g(f,s);continue}if(u==="div"&&x(i,ut.match)){for(let f of n(i))f.tagName==="pre"&&h(f,"contenteditable")===void 0&&b(f);continue}if(!(_.has(u)||h(i,"contenteditable")!==void 0))if(u==="table")I(i);else if(u==="figure"){let f=x(i,mt);for(let p of n(i))if(!(f&&p.tagName==="figcaption"))if(Ct.has(p.tagName))l(p,"field");else if(p.tagName==="table")I(p);else{if(_.has(p.tagName))continue;w(p)?g({childNodes:[p]},s):f||v(p)||Z(p)?d(p):g({childNodes:[p]},s)}}else if(u==="details")for(let f of n(i))w(f)?g({childNodes:[f]},s):f.tagName!=="summary"&&g(f,s);else if(u==="h1"&&(o.tagName==="header"||x(i,pt.title)))l(i,"title");else if(u==="li"&&K(i))g({childNodes:n(i)},s);else if(Lt.has(u)){let f=u==="li"?q(i):[];f?.length>0?(l(i,"flow",f[0]),g({childNodes:f},s)):l(i,"flow")||g(i,!1)}else if(u==="div"&&x(i,tt.block)&&n(i).length===0&&It(N(i)))l(i,"tex");else if(u==="div"&&x(i,gt.lead))for(let f of n(i))f.tagName==="span"&&l(f,"field");else s&&!v(i)&&m(i)?l(i,"text"):(g(i,s&&!v(i)),wt.has(u)&&it(i))}},it=o=>{let s=o.sourceCodeLocation,i=n(o).map(f=>a.get(f));if(!(i.length>0&&i.every(Boolean)&&o.childNodes.every(f=>f.tagName||f.nodeName==="#text"&&!f.value.trim()))||!s?.endTag)return;let k={start:s.startOffset,end:s.endOffset,ids:i.map(f=>f.id)};i.forEach(f=>f.wrapper=k)},W=o=>{for(let s of n(o))(s.tagName==="main"?g:W)(s)},D=S(t,{sourceCodeLocationInfo:!0});W(D);let{units:E,boxes:ct,referenced:lt}=X(D,t);for(let o of E)o.grid=!!$[o.kind]?.plain?.(o.node);for(let o of E){let s=$[o.kind]?.dataOf?.(t,o.node,c??=P().packages);s&&(o.parts=Object.fromEntries(Object.entries(s).map(([i,u])=>[i,H(u)])))}for(let o of e){let s=null;for(let i of E)i.start<=o.start&&o.start<i.end&&(!s||i.start>s.start)&&(s=i);o.unit=s?.id??null,o.self=s&&s.at===o.innerStart-1?s.id:null,o.self!==null&&(s.text=o.id),o.path=s&&o.self===null?Ht(s,o.node):null,A.text&&o.kind==="flow"&&o.self===null&&(s?.kind==="block"||s?.kind==="figure")&&(o.kind="text"),o.bound=lt(o.node)!==null,o.caps=Object.fromEntries(At(o.kind,o.tag,o.bound).map(i=>[i,!0]))}return{blocks:e,locks:r,units:E,boxes:ct}}function Ht(t,e){let r=[],a=e;for(;a&&!t.nodes.includes(a);a=a.parentNode){let c=(a.parentNode?.childNodes??[]).filter(l=>l.tagName===a.tagName);r.unshift([a.tagName,c.indexOf(a),c.length])}return a?[a===t.node?"unit":a===t.nodes[0]&&t.lead!==null?"lead":"panel",...r]:null}var fe=t=>T(t).blocks;function de(t){let{units:e,boxes:r}=T(t);return{units:e,boxes:r}}U();import{randomBlockId as qt}from"../browser/shared/ids.mjs";import{IDENTITY as O}from"../browser/editor/components/registry.mjs";var Kt=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function be(t,e=qt){let{units:r}=T(t),a=new Set([...t.matchAll(Kt)].map(d=>d[1]??d[2])),c=()=>{for(;;){let d=e();if(!a.has(d))return a.add(d)&&d}},l=new Set,n=[],N=[],m=[];for(let d of r)if(d.blockId)l.has(d.blockId)&&d.blockIdAttr?(N.push(d.blockId),n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${c()}"`})):l.add(d.blockId);else{let b=c();if(d.blockIdAttr)n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${b}"`});else{let g=z(t,d.at);n.push({start:g,end:g,text:` ${O}="${b}"`})}m.push({id:b,tag:rt(d.tag,d.attrs),at:d.elStart})}let I=t;for(let d of n.sort((b,g)=>g.start-b.start))I=I.slice(0,d.start)+d.text+I.slice(d.end);return m.sort((d,b)=>d.at-b.at),{text:I,added:m.length,renamed:N,given:m.map(({id:d,tag:b})=>({id:d,tag:b}))}}function Ie(t){let e=nt(t);return T(t).units.filter(r=>!r.blockId).sort((r,a)=>r.elStart-a.elStart).map(r=>({line:e(r.elStart),tag:rt(r.tag,r.attrs)}))}function ke(t,e){let r=new Map(e.map(c=>[c.id,c])),a=nt(t);return T(t).units.filter(c=>r.has(c.blockId)).sort((c,l)=>c.elStart-l.elStart).map(c=>({...r.get(c.blockId),line:a(c.elStart)}))}function nt(t){let e=[0];for(let r=t.indexOf(`
2
+ import{D as $,a as H,c as y,d as v,e as q,f as K,g as Y,i as V,k as X,o as z}from"./chunk-E7656LR7.mjs";import{g as P}from"./chunk-TKWEX4FD.mjs";import{b as S,e as U}from"./chunk-A55HN5OK.mjs";U();import{HOSTS as A,IDENTITY as dt}from"../browser/editor/components/registry.mjs";import{CODE as ut,MATH as tt,MEDIA as mt,PAGE as pt,TABLE as gt}from"../browser/editor/components/kit.mjs";import{TAB as ht}from"../browser/editor/components/paragraph/index.mjs";import{componentOf as Nt,isInstance as w,matchesNode as x,partOf as bt}from"../browser/shared/components/index.mjs";import{texSource as It}from"../browser/editor/components/math/index.mjs";import{MENTION as M,MENTION_ICON as J,MENTION_PAGE as Q}from"../browser/shared/components/mention.mjs";import{imageFile as et}from"../browser/shared/media.mjs";import{isFileLink as kt}from"../browser/shared/page-address.mjs";import{isInkClass as xt}from"../browser/editor/page/marks.mjs";import{ownInline as Tt}from"../browser/editor/page/own.mjs";import{attr as h,hasClass as Ot}from"../browser/shared/html-tree.mjs";var Lt=new Set(["h1","h2","h3","h4","p","li"]),Ct=new Set(["h3","h4","p","figcaption"]),Et=Object.entries(A).flatMap(([t,e])=>(e.parts??[]).map(([r,a])=>{let c=Nt(r);if(c?.parts?.[a]?.edit!=="text")throw new Error(`Host ${t}: ${r} has no part ${a} edited as text`);return{kind:t,match:c.match,at:c.parts[a].at}})),St=t=>Et.filter(({match:e})=>x(t,e)).flatMap(({kind:e,at:r})=>bt(t,r).map(a=>({kind:e,part:a}))),vt=t=>t.sort((e,r)=>e.part.sourceCodeLocation.startOffset-r.part.sourceCodeLocation.startOffset),$t=new Set(["strong","em","b","i","u","s","code","a","br","sup","sub"]),wt=new Set(["ul","ol","blockquote"]),_=new Set(["pre","summary","button","label","select","textarea","form","template","script","style","svg","math","iframe","object","noscript","canvas","video","audio"]),le={p:"p",h1:"p",h2:"p",h3:"p",h4:"p",li:"li"};function At(t,e,r){let a=A[t];if(!a)throw new Error(`Unknown block kind ${t}`);return a.caps({bound:r,blockLevel:y.has(e)})}var st=t=>t.tagName==="span"&&x(t,tt.inline),Bt=t=>t.tagName==="a"&&Ot(t,M),Pt=/^https?:\/\/[^\s"<>]+$/i,C=t=>t.attrs.map(e=>e.name).sort().join(),yt=t=>h(t,"class")===M&&t.childNodes.length===0&&(C(t)==="class"||C(t)===`class,${Q}`&&h(t,Q)==="");function _t(t){if(yt(t))return null;if(C(t)!=="class,href"||h(t,"class")!==M||!(Pt.test(h(t,"href"))||kt(h(t,"href"))))return"mention";let[e,...r]=t.childNodes;return(e?.tagName==="img"?C(e)==="alt,class,src"&&h(e,"class")===J&&h(e,"alt")===""&&et(h(e,"src")):e?.tagName==="span"&&C(e)==="class"&&h(e,"class")===J&&e.childNodes.length===0)&&r.length>0&&r.every(c=>c.nodeName==="#text")&&r.some(c=>c.value.trim())?null:"mention"}var Mt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value.trim().split(/\s+/).every(xt),jt=t=>t.tagName==="span"&&t.attrs.length===1&&t.attrs[0].name==="class"&&t.attrs[0].value===ht,ot=t=>$t.has(t.tagName)||Mt(t)||jt(t),B=t=>(t.childNodes??[]).some(e=>e.nodeName==="#text"?e.value.trim()!=="":B(e)),at=t=>Tt(t.tagName,t.attrs,B(t)),Z=t=>t.attrs.some(e=>e.name==="id"||e.name.startsWith("data-")&&e.name!==dt),Wt=t=>/^(javascript|vbscript|data):/i.test(t.replace(/[\u0000- ]/g,"")),Dt=(t,e,r={})=>t==="text"?y.has(e)?!1:"atoms":t==="title"||t==="code"||t==="codeTitle"||t==="tex"||!!r.plain;function j(t,e,r=!1,{cell:a=!1,pictures:c=a,known:l=null}={}){for(let n of t.childNodes){if(n.nodeName==="#text")continue;if(!n.tagName)return"comment";if(r===!0)return`tag:${n.tagName}`;if(n.attrs.some(m=>/^on/i.test(m.name)))return"markup";if(r==="atoms"){if(!n.sourceCodeLocation?.endTag&&n.tagName!=="br")return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(a&&(n.tagName==="ul"||n.tagName==="ol")){let m=Ut(n,e,l);if(m)return m;continue}if(c&&n.tagName==="img"){if(Ft(n))return"picture";continue}if(st(n)){if(n.childNodes.some(m=>m.nodeName!=="#text"))return"markup";e.push(n.sourceCodeLocation);continue}if(Bt(n)){let m=_t(n);if(m)return m;e.push(n.sourceCodeLocation);continue}if(at(n)){if(!n.sourceCodeLocation?.endTag)return"markup";if(l&&!l(n.sourceCodeLocation))return`tag:${n.tagName}`;e.push(n.sourceCodeLocation);continue}if(!ot(n))return`tag:${n.tagName}`;if(n.tagName!=="br"&&!n.sourceCodeLocation?.endTag)return"markup";if(n.tagName==="a"&&Wt(h(n,"href")??""))return"link";let N=j(n,e,!1,{known:l,pictures:c});if(N)return N}return null}var Gt=["src","alt","width"],Rt=/^[1-9]\d{0,3}$/;function Ft(t){let r=t.attrs.map(l=>l.name).find(l=>!Gt.includes(l));if(r)return`the attribute ${r}`;let a=h(t,"src");if(!et(a))return`its src (${a===void 0?"none":a.slice(0,80)}): no picture of the document's assets/ folder`;let c=h(t,"width");return c===void 0||Rt.test(c)?null:`its width (${c}): a whole number of pixels`}function Ut(t,e,r){if(t.attrs.length>0||!t.sourceCodeLocation?.endTag)return"markup";for(let a of t.childNodes){if(a.nodeName==="#text"&&!a.value.trim())continue;if(a.tagName!=="li")return`tag:${a.tagName??"text"}`;if(a.attrs.length>0||!a.sourceCodeLocation?.endTag)return"markup";let c=j(a,e,!1,{known:r,pictures:!0});if(c)return c}return null}function T(t){let e=[],r=[],a=new Map,c=null,l=(o,s,i=null)=>{let u=o.sourceCodeLocation;if(!A[s]||!u?.startTag||h(o,"contenteditable")!==void 0)return!1;let k=[],f=Dt(s,o.tagName),p=i?{childNodes:o.childNodes.slice(0,o.childNodes.indexOf(i))}:o,G=u.endTag?j(p,k,f,{cell:s==="cell"}):"markup";if(G)return r.push({at:u.startTag.endOffset-1,reason:G}),!1;let L=u.startTag.endOffset,ft=i?L+t.slice(L,i.sourceCodeLocation.startOffset).replace(/[ \t\r\n\f]+$/,"").length:u.endTag.startOffset,R={id:e.length,tag:o.tagName,kind:s,bound:!1,caps:{},start:u.startOffset,end:u.endOffset,innerStart:L,innerEnd:ft,atoms:k.map(F=>[F.startOffset-L,F.endOffset-L]),wrapper:null,nested:!!i,node:o};return e.push(R),a.set(o,R),!0},n=o=>(o.childNodes??[]).filter(s=>s.tagName),N=o=>{let s=o.sourceCodeLocation;return s?.startTag&&s.endTag?t.slice(s.startTag.endOffset,s.endTag.startOffset):null},m=o=>o.tagName!=="a"&&!Z(o)&&B(o)&&n(o).every(s=>at(s)?!B(s):ot(s)||st(s)),I=o=>{for(let s of n(o))s.tagName==="td"||s.tagName==="th"?l(s,"cell"):["thead","tbody","tfoot","tr"].includes(s.tagName)&&I(s)},d=o=>{for(let s of n(o))s.tagName==="table"?I(s):!_.has(s.tagName)&&!w(s)&&d(s)},b=o=>{let s=n(o);s.length===1&&s[0].tagName==="code"&&o.childNodes.every(i=>i.tagName||!i.value?.trim())?l(s[0],"code"):s.length===0?l(o,"code"):o.sourceCodeLocation?.startTag&&r.push({at:o.sourceCodeLocation.startTag.endOffset-1,reason:"markup"})},g=(o,s=!0)=>{for(let i of n(o)){let u=i.tagName,k=w(i);for(let{kind:f,part:p}of vt(k?$[V(i)].textParts(i,c??=P().packages):St(i)))l(p,f);if(k){for(let{element:f}of Y(i))g(f,s);continue}if(u==="div"&&x(i,ut.match)){for(let f of n(i))f.tagName==="pre"&&h(f,"contenteditable")===void 0&&b(f);continue}if(!(_.has(u)||h(i,"contenteditable")!==void 0))if(u==="table")I(i);else if(u==="figure"){let f=x(i,mt);for(let p of n(i))if(!(f&&p.tagName==="figcaption"))if(Ct.has(p.tagName))l(p,"field");else if(p.tagName==="table")I(p);else{if(_.has(p.tagName))continue;w(p)?g({childNodes:[p]},s):f||v(p)||Z(p)?d(p):g({childNodes:[p]},s)}}else if(u==="details")for(let f of n(i))w(f)?g({childNodes:[f]},s):f.tagName!=="summary"&&g(f,s);else if(u==="h1"&&(o.tagName==="header"||x(i,pt.title)))l(i,"title");else if(u==="li"&&K(i))g({childNodes:n(i)},s);else if(Lt.has(u)){let f=u==="li"?q(i):[];f?.length>0?(l(i,"flow",f[0]),g({childNodes:f},s)):l(i,"flow")||g(i,!1)}else if(u==="div"&&x(i,tt.block)&&n(i).length===0&&It(N(i)))l(i,"tex");else if(u==="div"&&x(i,gt.lead))for(let f of n(i))f.tagName==="span"&&l(f,"field");else s&&!v(i)&&m(i)?l(i,"text"):(g(i,s&&!v(i)),wt.has(u)&&it(i))}},it=o=>{let s=o.sourceCodeLocation,i=n(o).map(f=>a.get(f));if(!(i.length>0&&i.every(Boolean)&&o.childNodes.every(f=>f.tagName||f.nodeName==="#text"&&!f.value.trim()))||!s?.endTag)return;let k={start:s.startOffset,end:s.endOffset,ids:i.map(f=>f.id)};i.forEach(f=>f.wrapper=k)},W=o=>{for(let s of n(o))(s.tagName==="main"?g:W)(s)},D=S(t,{sourceCodeLocationInfo:!0});W(D);let{units:E,boxes:ct,referenced:lt}=X(D,t);for(let o of E)o.grid=!!$[o.kind]?.plain?.(o.node);for(let o of E){let s=$[o.kind]?.dataOf?.(t,o.node,c??=P().packages);s&&(o.parts=Object.fromEntries(Object.entries(s).map(([i,u])=>[i,H(u)])))}for(let o of e){let s=null;for(let i of E)i.start<=o.start&&o.start<i.end&&(!s||i.start>s.start)&&(s=i);o.unit=s?.id??null,o.self=s&&s.at===o.innerStart-1?s.id:null,o.self!==null&&(s.text=o.id),o.path=s&&o.self===null?Ht(s,o.node):null,A.text&&o.kind==="flow"&&o.self===null&&(s?.kind==="block"||s?.kind==="figure")&&(o.kind="text"),o.bound=lt(o.node)!==null,o.caps=Object.fromEntries(At(o.kind,o.tag,o.bound).map(i=>[i,!0]))}return{blocks:e,locks:r,units:E,boxes:ct}}function Ht(t,e){let r=[],a=e;for(;a&&!t.nodes.includes(a);a=a.parentNode){let c=(a.parentNode?.childNodes??[]).filter(l=>l.tagName===a.tagName);r.unshift([a.tagName,c.indexOf(a),c.length])}return a?[a===t.node?"unit":a===t.nodes[0]&&t.lead!==null?"lead":"panel",...r]:null}var fe=t=>T(t).blocks;function de(t){let{units:e,boxes:r}=T(t);return{units:e,boxes:r}}U();import{randomBlockId as qt}from"../browser/shared/ids.mjs";import{IDENTITY as O}from"../browser/editor/components/registry.mjs";var Kt=/\sdata-block-id\s*=\s*(?:"([^"]*)"|'([^']*)')/gi;function be(t,e=qt){let{units:r}=T(t),a=new Set([...t.matchAll(Kt)].map(d=>d[1]??d[2])),c=()=>{for(;;){let d=e();if(!a.has(d))return a.add(d)&&d}},l=new Set,n=[],N=[],m=[];for(let d of r)if(d.blockId)l.has(d.blockId)&&d.blockIdAttr?(N.push(d.blockId),n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${c()}"`})):l.add(d.blockId);else{let b=c();if(d.blockIdAttr)n.push({start:d.blockIdAttr.start,end:d.blockIdAttr.end,text:`${O}="${b}"`});else{let g=z(t,d.at);n.push({start:g,end:g,text:` ${O}="${b}"`})}m.push({id:b,tag:rt(d.tag,d.attrs),at:d.elStart})}let I=t;for(let d of n.sort((b,g)=>g.start-b.start))I=I.slice(0,d.start)+d.text+I.slice(d.end);return m.sort((d,b)=>d.at-b.at),{text:I,added:m.length,renamed:N,given:m.map(({id:d,tag:b})=>({id:d,tag:b}))}}function Ie(t){let e=nt(t);return T(t).units.filter(r=>!r.blockId).sort((r,a)=>r.elStart-a.elStart).map(r=>({line:e(r.elStart),tag:rt(r.tag,r.attrs)}))}function ke(t,e){let r=new Map(e.map(c=>[c.id,c])),a=nt(t);return T(t).units.filter(c=>r.has(c.blockId)).sort((c,l)=>c.elStart-l.elStart).map(c=>({...r.get(c.blockId),line:a(c.elStart)}))}function nt(t){let e=[0];for(let r=t.indexOf(`
3
3
  `);r!==-1;r=t.indexOf(`
4
4
  `,r+1))e.push(r+1);return r=>{let[a,c]=[0,e.length-1];for(;a<c;){let l=a+c+1>>1;e[l]<=r?a=l:c=l-1}return a+1}}function rt(t,e=[]){let r=e.filter(({name:l})=>l!==O&&l!=="style"),a=l=>{let n=l.replace(/\s+/g," "),N=n.length>32?`${n.slice(0,31)}\u2026`:n;return N===""?"":/[\s"'=<>`]/.test(N)?`="${N.replaceAll('"',"&quot;")}"`:`=${N}`},c=r.slice(0,3).map(({name:l,value:n})=>`${l}${a(n)}`);return`<${[t,...c,...r.length>3?["\u2026"]:[]].join(" ")}>`}function xe(t){let e=new Map,r=a=>{let c=a.attrs?.find(n=>n.name===O)?.value,l=a.sourceCodeLocation?.attrs?.[O]??a.sourceCodeLocation;c!==void 0&&e.set(c,[...e.get(c)??[],l]);for(let n of a.content?.childNodes??a.childNodes??[])r(n)};return r(S(t,{sourceCodeLocationInfo:!0})),[...e].filter(([,a])=>a.length>1).map(([a,c])=>({id:a,lines:c.map(l=>l?.startLine),columns:c.map(l=>l?.startCol)}))}export{le as a,Dt as b,j as c,Ft as d,T as e,fe as f,de as g,qt as h,Kt as i,be as j,Ie as k,ke as l,xe as m};
@@ -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}from"./chunk-JA7G53PC.mjs";import"./chunk-YI43RG4P.mjs";import"./chunk-NAMN3RAF.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as nameHint,b as run};
2
+ import{a,b}from"./chunk-ZFGMJVJC.mjs";import"./chunk-QP7BOHE4.mjs";import"./chunk-GMJD7ID3.mjs";import"./chunk-JEUK3ZO7.mjs";import"./chunk-WFGPMCTZ.mjs";import"./chunk-7UZUQQ7Q.mjs";import"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";export{a as nameHint,b as run};
@@ -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 l,d as g}from"./chunk-WFGPMCTZ.mjs";import{j as p,k as d}from"./chunk-4B2TB5K2.mjs";import{u as f}from"./chunk-KLQP46Y3.mjs";import{b as h,f as u}from"./chunk-4OZWXZE5.mjs";import b from"node:fs/promises";import x from"node:path";import{reportsDirectory as j}from"../browser/shared/paths.mjs";import{sameDirectory as i}from"../browser/shared/preview-server.mjs";import{copyOldDocuments as v,defaultWorkspace as k,ensureWorkspace as D,layoutOf as G}from"../browser/shared/workspace.mjs";import{nameProblem as N,writeWorkspaceName as O}from"../browser/shared/workspace-name.mjs";import{registerQuietly as C}from"../browser/shared/workspace-registry.mjs";var $=(o,t)=>`${o} ${t}${o===1?"":"s"}`;function W(o,t,r){let{preferences:s}=G(r);return[o.copied.length?`Copied ${$(o.copied.length,"document")} from ${t}: ${o.copied.join(", ")}`:`Copied no documents from ${t}.`,...o.skipped.length?[`Skipped (the slug is taken here, or the folder's name is no slug): ${o.skipped.join(", ")}`]:[],...o.kept.length?[`Left behind (a name a workspace keeps for itself, for its custom blocks here, which no new document takes): ${o.kept.join(", ")}`]:[],...o.preferences==="copied"?[`\u5199\u4F5C\u504F\u597D\uFF1Acopied (${s})`]:o.preferences==="kept"?[`\u5199\u4F5C\u504F\u597D\uFF1Akept the workspace's (${s}); the old one was not copied`]:[],...o.outline?[`Sidebar order: ${o.outline}`]:[],...o.page?[`\u5199\u4F5C\u504F\u597D's page: ${o.page==="copied"?"copied":"kept the workspace's"}`]:[],...o.emoji?[`Emoji library: ${o.emoji} added`]:[],...o.history?[`Recent versions: ${$(o.history,"document")}`]:[],...o.packages.length?[`Custom blocks: ${o.packages.join(", ")}`]:[]]}async function q(o){let{values:t}=u({values:["--from","--name"],argv:o}),r=j,s=t.get("--name"),c=s===void 0?null:N(s);if(c)throw new h(c);let m;try{let{made:e,ours:a,reads:y}=await D(r,{state:i(r,k())});a||(console.error(g(r,y)),process.exit(1)),m=e}catch(e){if(!e.code)throw e;console.error(l(r,e.code)),process.exit(1)}if(console.log(`\u5DE5\u4F5C\u533A\uFF1A${r}\uFF08${m?"\u65B0\u5EFA":"\u5DF2\u6709"}\uFF09`),s!==void 0)try{let e=await O(r,s);console.log(`\u540D\u5B57\uFF1A${e.name}${e.before&&e.before!==e.name?` (it was "${e.before}")`:""}`)}catch(e){console.error(e.code?l(r,e.code):e.message),process.exit(1)}if(await C(r),t.has("--from")){let e=x.resolve(t.get("--from"));await b.stat(e).then(a=>a.isDirectory(),()=>!1)||(console.error(`No such folder: ${e} (--from names an older Gallery's reports/ folder).`),process.exit(1)),i(e,r)&&(console.error(`${e} is this workspace: --from names another folder (an older Gallery's reports/).`),process.exit(1));for(let a of W(await v({from:e,to:r}),e,r))console.log(a)}if(!i(r,k())){console.log('Next: gallery new <slug> "<title>" makes a document; gallery open opens Gallery.');return}let w=await f(r);for(let e of w.packs)e.failed?console.warn(`\u5757\u5305\uFF1AGallery's pack ${e.id} was not installed (${e.failed}); a later start tries again.`):e.first&&console.log(`\u5757\u5305\uFF1A${e.name.zh} (${e.id} ${e.version}, ${e.added.length+e.same.length+e.updated.length} blocks)${e.id==="gallery-soft"?", switched off: \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 turns it on":""}`);let n=await p(r);n.did==="made"?console.log(`\u9996\u9875\uFF1A${n.file} (the home page, its cards Gallery's today and note; the workbench opens it first)`):n.did==="failed"&&console.warn(`\u9996\u9875\uFF1A${d(n)}`),console.log('Next: gallery new <slug> "<title>" makes a document; gallery open opens the workbench.')}export{W as a,q as b};
@@ -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{k as u}from"./chunk-6N3PX4XX.mjs";import n from"node:fs/promises";import d from"node:path";import{writeAtomic as h}from"../browser/shared/files.mjs";import{documentFiles as A}from"../browser/shared/workspace.mjs";var I=s=>n.access(s).then(()=>!0,()=>!1);async function q(s,{create:y,slugOf:F,folderOf:j,fill:p,place:x,under:N="",said:J="\u5BFC\u5165\u81EA {0}",lang:O=null}){let e=[],c=[];async function f(t,r,S){let i=await F(t,S);await y(i,t.title,J.replace("{0}",()=>t.from),{lang:O});let a=j(i),{html:l,json:m}=A(a),k=await n.readFile(l,"utf8");await h(l,u(await p({source:k,nodes:t.nodes,icon:t.icon,own:t.own,raws:t.raws,lang:t.lang}))),t.files.length&&await n.mkdir(d.join(a,"assets"),{recursive:!0});for(let{from:o,name:v}of t.files){let w=d.join(a,"assets",v);await I(w)||await n.copyFile(o,w)}if(t.icon){let o=JSON.parse(await n.readFile(m,"utf8"));await h(m,`${JSON.stringify({...o,icon:t.icon},null,2)}
2
+ import{k as u}from"./chunk-PLB7L22J.mjs";import n from"node:fs/promises";import d from"node:path";import{writeAtomic as h}from"../browser/shared/files.mjs";import{documentFiles as A}from"../browser/shared/workspace.mjs";var I=s=>n.access(s).then(()=>!0,()=>!1);async function q(s,{create:y,slugOf:F,folderOf:j,fill:p,place:x,under:N="",said:J="\u5BFC\u5165\u81EA {0}",lang:O=null}){let e=[],c=[];async function f(t,r,S){let i=await F(t,S);await y(i,t.title,J.replace("{0}",()=>t.from),{lang:O});let a=j(i),{html:l,json:m}=A(a),k=await n.readFile(l,"utf8");await h(l,u(await p({source:k,nodes:t.nodes,icon:t.icon,own:t.own,raws:t.raws,lang:t.lang}))),t.files.length&&await n.mkdir(d.join(a,"assets"),{recursive:!0});for(let{from:o,name:v}of t.files){let w=d.join(a,"assets",v);await I(w)||await n.copyFile(o,w)}if(t.icon){let o=JSON.parse(await n.readFile(m,"utf8"));await h(m,`${JSON.stringify({...o,icon:t.icon},null,2)}
3
3
  `)}await x(i,r),e.push(i);for(let o of t.children??[])await f(o,i,null);return i}for(let[t,r]of s.entries())c.push(await f(r,N,t));return{made:e,top:c}}export{q as a};
@@ -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 f,d as g,e as h,f as $,g as v,i as y,j as r,k as x}from"./chunk-NAMN3RAF.mjs";import{b as c,f as p}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{descendantsIn as A}from"../browser/shared/outline.mjs";async function N(L){let{positional:u,options:I,values:T}=p({options:["--top","--first"],values:["--under","--after"],argv:L});if(u.length!==1)throw new c("Name the document to move, one.");let e=x(T,I);if(e.under===void 0&&!e.top&&e.after===void 0&&!e.first)throw new c("Say where it goes: --under <document> or --top, and --after <document> or --first.");let s=await f(),a=async(b,k)=>{let d=await $(b,k,s);return d.refused&&(console.error(d.refused),process.exit(1)),d.slug},t=await a(u[0],"the document to move"),l=e.under!==void 0?await a(e.under,"--under"):e.top?"":void 0,m=e.after!==void 0?await a(e.after,"--after"):null,o=await y(t,{parent:l,after:m,first:e.first});o.ok||(console.error(v(s,t,o.reason,{parent:l,after:m,message:o.message})),process.exit(1));let n=await f(),i=A(n.children,t).length,w=`${g(n,t)}${i?` with the ${i} document${i===1?"":"s"} under it`:""}`;o.moved?console.log(`Moved ${w}: now ${r(n,o)}; it was ${r(s,o.from)}.`):console.log(`${w} is there already: ${r(n,o)}.`),console.log(h(n,t))}export{N as run};
2
+ import{a as f,d as g,e as h,f as $,g as v,i as y,j as r,k as x}from"./chunk-GMJD7ID3.mjs";import{b as c,f as p}from"./chunk-4OZWXZE5.mjs";import"./chunk-5L7RYZCL.mjs";import{descendantsIn as A}from"../browser/shared/outline.mjs";async function N(L){let{positional:u,options:I,values:T}=p({options:["--top","--first"],values:["--under","--after"],argv:L});if(u.length!==1)throw new c("Name the document to move, one.");let e=x(T,I);if(e.under===void 0&&!e.top&&e.after===void 0&&!e.first)throw new c("Say where it goes: --under <document> or --top, and --after <document> or --first.");let s=await f(),a=async(b,k)=>{let d=await $(b,k,s);return d.refused&&(console.error(d.refused),process.exit(1)),d.slug},t=await a(u[0],"the document to move"),l=e.under!==void 0?await a(e.under,"--under"):e.top?"":void 0,m=e.after!==void 0?await a(e.after,"--after"):null,o=await y(t,{parent:l,after:m,first:e.first});o.ok||(console.error(v(s,t,o.reason,{parent:l,after:m,message:o.message})),process.exit(1));let n=await f(),i=A(n.children,t).length,w=`${g(n,t)}${i?` with the ${i} document${i===1?"":"s"} under it`:""}`;o.moved?console.log(`Moved ${w}: now ${r(n,o)}; it was ${r(s,o.from)}.`):console.log(`${w} is there already: ${r(n,o)}.`),console.log(h(n,t))}export{N as run};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as g,i as S}from"./chunk-4OZWXZE5.mjs";import{workspaceBase as _}from"../browser/shared/service-location.mjs";import I from"node:fs/promises";import{listExtensions as C}from"../browser/shared/extensions.mjs";import{ancestorsIn as M,moveDocument as P,outlineAndFile as A}from"../browser/shared/outline.mjs";import{DOCS as k,groupOfTop as B,isForeign as b,isTop as G,topIn as J,topOf as U}from"../browser/shared/outline-shape.mjs";import{draftFacts as q,draftOf as z,registeredIds as K,workspaceNames as R}from"../browser/shared/drafts.mjs";import{reportsDirectory as u}from"../browser/shared/paths.mjs";import{findPreviewServer as W}from"../browser/shared/preview-server.mjs";import{roleOf as X}from"../browser/shared/reports.mjs";import{nameStops as H,workspaceName as Q}from"../browser/shared/workspace-name.mjs";import{workspaceKey as w}from"../browser/shared/workspace-registry.mjs";import{defaultWorkspace as V,documentDirectory as y,documentFiles as Y,pageSlug as Z,readLink as ee}from"../browser/shared/workspace.mjs";async function ge(e=u,{others:t=w(e)===w(u)}={}){let{outline:{children:n,groups:o,links:s,shown:i},others:c}=await A(e,{others:t}),m=te(e,o,i),a=new Set(i.map(({id:r})=>r)),p=o.map(r=>({...r,name:m.get(r.id)??null,...t&&r.workspace&&!a.has(r.workspace)?{away:!0}:{}})),$=p.filter(r=>!r.extension),F=await C(e),x=Object.values(n).flat(),N=r=>typeof r=="string"?r.replace(/\s+/g," ").trim():"",j=x.some(b)?K():null,E=new Map(await Promise.all(x.map(async r=>{if(b(r)){let d=z(r),O=c.find(({id:L})=>L===d?.ws)?.facts.get(d.slug),f=O?{...O,missing:null}:await q(r,j);return[r,{slug:r,title:f.title,description:f.description,icon:f.icon,...f.url?{url:f.url}:{},draft:{path:f.path,missing:f.missing,ws:d?.ws??null}}]}if(s.includes(r)){let d=await ee(y(r,e));return[r,{slug:r,title:d?.title??r,description:"",icon:d?.icon??null,url:d?.url??""}]}let h=await I.readFile(Y(y(r,e)).json,"utf8").then(JSON.parse).catch(()=>({}));return[r,{slug:r,title:N(h?.title)||r,description:N(h?.description),icon:typeof h?.icon=="string"?h.icon:null}]})));return{children:n,groups:$,columns:p,extensions:F,documents:E}}function te(e,t,n=[]){let o=w(V()),s=new Set(t.map(({workspace:a})=>a).filter(Boolean)),i=H(),c=s.size?R(s,{stops:i}):new Map,m=new Map;for(let a of t)if(a.id===k)m.set(a.id,w(e)===o?"\u9ED8\u8BA4\u6587\u6863":Q(e,{stops:i}).name);else if(a.workspace){let p=n.find(({id:$})=>$===a.workspace);m.set(a.id,p?.isDefault?"\u9ED8\u8BA4\u6587\u6863":c.get(a.workspace)?.name??a.workspace)}else a.role==="links"&&m.set(a.id,"\u94FE\u63A5");return m}var v=e=>e?.title??e?.name??(e?.id===k?"\u6587\u6863":e?.role==="links"?"\u94FE\u63A5":e?"\u672A\u547D\u540D\u680F":"\u6587\u6863"),T=(e,t)=>e.groups?.find(({id:n})=>n===B(t));function ye(e,t){let n=e.documents.get(t);if(!n||n.url!==void 0)return null;let o=D(e,t),s=n.draft?.ws??null,i=s?e.groups.find(c=>c.workspace===s):e.groups.find(c=>c.id===k);return i&&U(i.id)===o?null:i?i.hidden?i.name??s:v(i):s}var l=({documents:e},t)=>`${t} (${e.get(t)?.title??t})`,D=(e,t)=>J(e.children,t)??"";function ke(e,t){let n=M(e.children,t).map(i=>l(e,i)),o=D(e,t),s=[...o===""?[]:[`${v(T(e,o))}\u680F`],...n];return`\u4F4D\u7F6E\uFF1A${s.length?s.join(" \u203A "):"\u9876\u5C42"}`}async function ve(e,t,n){let{slug:o}=await S(e);if(o===await Z(u))return{refused:`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`};if(!n.documents.has(o)){let s=y(o,u);return{refused:await X(s)==="instructions"?`${e} is the \u5199\u4F5C\u504F\u597D page, which the sidebar lists apart: it moves nowhere and holds no documents (${t}).`:`No document "${e}" (${t}): gallery list --tree shows the documents and where they are.`}}return{slug:o}}var ne={"cross-workspace":()=>"Not moved: copying to another workspace requires confirmation in Gallery; the original stays in its workspace.",missing:(e,t)=>`No document "${t}" in the sidebar's tree: gallery list --tree shows them.`,parent:(e,t,{parent:n})=>`No document "${n}" to put ${l(e,t)} under: gallery list --tree shows them.`,after:(e,t,{after:n})=>`No document "${n}" to put ${l(e,t)} after: gallery list --tree shows them.`,level:(e,t,{parent:n,after:o})=>`${l(e,o)} is not under ${n?l(e,n):"the top level"}: --after names a document at the level it goes to.`,itself:(e,t)=>`${l(e,t)} cannot go after itself.`,inside:(e,t,{parent:n,after:o})=>n===void 0&&o?`${l(e,t)} cannot go after ${l(e,o)}, which is under it.`:`${l(e,t)} cannot go under ${n===t?"itself":`${l(e,n)}, which is under it`}.`,instructions:(e,t)=>"The \u5199\u4F5C\u504F\u597D page is listed apart: it moves nowhere and holds no documents."},xe=(e,t,n,o={})=>(ne[n]??((s,i,{message:c})=>`Not moved: ${c??n}.`))(e,t,o);async function oe(e,t,n="move"){let o=`127.0.0.1:${e.port}`;try{let i=await(await fetch(`http://${o}${_(u)}/__gallery/workspace/${n}`,{method:"POST",headers:{"Content-Type":"application/json",Origin:`http://${o}`,"X-Gallery-Token":e.token},body:JSON.stringify({...t,workspace:u}),signal:AbortSignal.timeout(3e4)})).json().catch(()=>null);return typeof i?.ok!="boolean"||["elsewhere","token","host","origin","unknown"].includes(i.reason)?null:i}catch{return null}}async function Ne(e,{parent:t=void 0,after:n=null,first:o=!1}={}){let s=await W(),i={slug:e,...t!==void 0?{parent:t}:{},after:n,first:o},c=s?await oe(s,i):null;return c||P(u,e,{parent:t,after:n,first:o})}function Oe(e,{parent:t,index:n}){let o=e.children[t]??[],s=t===""?"at the top level":G(t)?`at the top of the ${v(T(e,t))} column`:`under ${l(e,t)}`;return o.length===1?`${s}, the only ${o.some(i=>e.documents.get(i)?.url!==void 0)?"entry":"document"} there`:n===0?`${s}, first`:`${s}, right after ${l(e,o[n-1])}${n===o.length-1?", last":""}`}function Se(e,t,{top:n=!0}={}){let o=e.get("--under"),s=e.get("--after");if(o!==void 0&&t.has("--top"))throw new g("--under and --top are two places: give one.");if(s!==void 0&&t.has("--first"))throw new g("--after and --first are two places: give one.");return{under:o,top:n&&t.has("--top"),after:s,first:t.has("--first")}}export{ge as a,v as b,ye as c,l as d,ke as e,ve as f,xe as g,oe as h,Ne as i,Oe as j,Se as k};
@@ -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 m,b as u,c as f,d}from"./chunk-EAIFITAV.mjs";import{b as p}from"./chunk-67N2QJYT.mjs";import{j as n}from"./chunk-4OZWXZE5.mjs";import{l as i,t as a,w as c}from"./chunk-MXUBKDRO.mjs";import{reportsDirectory as g}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as y}from"../browser/shared/workspace.mjs";var k=()=>`No documents in ${g} yet: gallery new <slug> "<title>" makes one.`;async function A(w){let{slugs:e,options:h}=await n({options:["--allow-failures"],argv:w,noneIsAll:!0});e.length===0&&(console.error(k()),process.exit(1)),await p(e),await f(e),await d(e);let{reports:r,failures:t}=await i(e,{prepare:m()}),s=r.filter(o=>!t.has(o.slug));for(let o of s)console.log(`OK ${o.slug}`);for(let o of e)y($(o,g)).both&&console.log(`note ${o}: both doc.html and report.html: report.html is not read`);a(r),u(r);let l=s.length+t.size;console.log(`Checked ${l} document${l===1?"":"s"}: ${s.length} passed, ${t.size} failed.`),await c(t,{allow:h.has("--allow-failures")})}export{k as a,A as b};
2
+ import{a as m,b as u,c as f,d}from"./chunk-2KAVXMKG.mjs";import{b as p}from"./chunk-XZCFPKGO.mjs";import{j as n}from"./chunk-4OZWXZE5.mjs";import{l as i,t as a,w as c}from"./chunk-USIHBCSW.mjs";import{reportsDirectory as g}from"../browser/shared/paths.mjs";import{documentDirectory as $,documentFiles as y}from"../browser/shared/workspace.mjs";var k=()=>`No documents in ${g} yet: gallery new <slug> "<title>" makes one.`;async function A(w){let{slugs:e,options:h}=await n({options:["--allow-failures"],argv:w,noneIsAll:!0});e.length===0&&(console.error(k()),process.exit(1)),await p(e),await f(e),await d(e);let{reports:r,failures:t}=await i(e,{prepare:m()}),s=r.filter(o=>!t.has(o.slug));for(let o of s)console.log(`OK ${o.slug}`);for(let o of e)y($(o,g)).both&&console.log(`note ${o}: both doc.html and report.html: report.html is not read`);a(r),u(r);let l=s.length+t.size;console.log(`Checked ${l} document${l===1?"":"s"}: ${s.length} passed, ${t.size} failed.`),await c(t,{allow:h.has("--allow-failures")})}export{k as a,A as b};
@@ -0,0 +1,11 @@
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 Qt,b as Xt}from"./chunk-ALZ6ZENZ.mjs";import{a as mt}from"./chunk-UMHUSOPJ.mjs";import{b as Vt,e as Ae}from"./chunk-A55HN5OK.mjs";import{randomBytes as kt}from"node:crypto";import h from"node:fs/promises";import{serviceLocation as Be}from"../browser/shared/service-location.mjs";import w from"node:path";import{writeAtomic as R}from"../browser/shared/files.mjs";import{sendJson as G}from"../browser/shared/http.mjs";import{said as B,saying as Et}from"../browser/shared/i18n/index.mjs";import{reportsDirectory as He}from"../browser/shared/paths.mjs";import{moveDocument as Ue,outlineAndFile as ze,ownsOutline as Ke,placeIn as nt,readOutline as te,validOutline as ee,withOutlineLock as ne,writeHead as Ve,writeOutline as Qe,writtenAs as Xe}from"../browser/shared/outline.mjs";Ae();import et from"node:fs/promises";import pt from"node:path";import{attr as Fe,walk as $e}from"../browser/shared/html-tree.mjs";import{escapeAttribute as Re}from"../browser/shared/escape.mjs";import{COMPONENTS_FOLDER as Je,DOCUMENT_FOLDERS as Te,SHARED_FOLDERS as Ce,documentFiles as Zt,packageFolders as _e,readLink as Me}from"../browser/shared/workspace.mjs";async function Pt(O,m){let k=await et.readdir(pt.join(O,m),{withFileTypes:!0});if(!Ce.includes(m))return k.map(({name:j})=>j);let c=m===Je?new Set(_e(O).map(({id:j})=>j.split("/")[0])):new Set;return k.filter(j=>j.isFile()||Te.includes(j.name)&&!c.has(j.name)).map(({name:j})=>j)}async function Nt(O,m,k,c,{names:j=new Map}={}){let x=pt.join(O,m),vt=await et.access(Zt(x).html).then(()=>!0,()=>!1)?null:await Me(x),C=new Set(["",...await Pt(O,m)]);if(await et.cp(x,k,{recursive:!0,errorOnExist:!0,force:!1,filter:N=>C.has(pt.relative(x,N).split(pt.sep)[0])}),vt)return[];let Z=Zt(k).html,v=await et.readFile(Z,"utf8"),ct=mt(v),q=new Map,H=new Set;$e(Vt(ct.replace(/^\uFEFF/," "),{sourceCodeLocationInfo:!0}),N=>{let A=Fe(N,"data-doc-component");A&&H.add(A);for(let{name:E,value:S}of N.attrs??[]){let F=N.sourceCodeLocation?.attrs?.[E];if(!F)continue;let _=/^(\.\.\/)([a-z0-9]+(?:-[a-z0-9]+)*)(\/.*)$/.exec(S),lt=E==="data-doc-id"&&S===m?c:["href","src","poster"].includes(E)&&_&&j.has(_[2])?`../${j.get(_[2])}${_[3]}`:S;lt!==S&&q.set(F.startOffset,{to:F.endOffset,text:`${E}="${Re(lt)}"`})}});let l=[...q].sort(([N],[A])=>A-N).reduce((N,[A,E])=>N.slice(0,A)+E.text+N.slice(E.to),ct);return await et.writeFile(Z,l),[...H]}import{storedHead as Ze}from"../browser/shared/sidebar-head.mjs";import{DOCS as ht,columnWorkspaceId as qe,entryWorkspace as De,entryPattern as tn,isForeign as ie,isTop as V,topOf as X}from"../browser/shared/outline-shape.mjs";import{addDraft as en,addWorkspace as nn,draftEntry as re,draftFacts as oe,draftOf as it,findDraft as rn,foreignMarker as on,projectChoices as an,registeredIds as gt,workspaceNames as sn,workspaceOf as rt}from"../browser/shared/drafts.mjs";import{forgetSnapshot as It,shownWorkspaces as cn}from"../browser/shared/workspace-columns.mjs";import{nameStops as ln}from"../browser/shared/workspace-name.mjs";import{registerWorkspace as un,workspaceId as Lt,workspaceKey as ae}from"../browser/shared/workspace-registry.mjs";import{spawn as We}from"node:child_process";import qt from"node:path";var Ge=O=>!["","0",void 0].includes(O);function Ye(O,{platform:m=process.platform,env:k=process.env}={}){return Ge(k.GALLERY_NO_BROWSER)?{skip:"GALLERY_NO_BROWSER is set"}:m==="win32"?{command:qt.join(k.SystemRoot||k.windir||"C:\\Windows","explorer.exe"),args:[`/select,"${O}"`],verbatim:!0}:m==="darwin"?{command:"open",args:["-R",O]}:!k.DISPLAY&&!k.WAYLAND_DISPLAY?{skip:"no display here (neither DISPLAY nor WAYLAND_DISPLAY is set)"}:{command:"xdg-open",args:[qt.dirname(O)]}}function Dt(O,m){let k=Ye(O,m);return k.skip?Promise.resolve({opened:!1,why:k.skip}):new Promise(c=>{let j;try{j=We(k.command,k.args,{detached:!0,stdio:"ignore",windowsHide:!1,windowsVerbatimArguments:!!k.verbatim})}catch(x){return c({opened:!1,why:x.code??x.message})}j.once("error",x=>c({opened:!1,why:x.code??x.message})),j.once("spawn",()=>{j.unref(),c({opened:!0})})})}import{LINK_FILE as At,linkStem as fn,linkValue as ot,ownAddress as Ft,readLinkText as dn}from"../browser/shared/web-links.mjs";import{sameDirectory as at}from"../browser/shared/preview-server.mjs";import{listReportSlugs as wn,slugPattern as P}from"../browser/shared/reports.mjs";import{PAGE_SLUG as mn,SHARED_FOLDERS as se,defaultWorkspace as yt,documentDirectory as pn,documentFiles as Ot,ensureWorkspace as kn,idHolder as hn,isDocSlug as gn,layoutOf as $t,listTrash as ce,newDocSlug as jt,pageSlug as yn,readLink as Rt,slugTaken as On,trashIdPattern as le}from"../browser/shared/workspace.mjs";import{createPage as jn,headOf as ue,listPages as fe,newPageSlug as Sn,pageFiles as st,readPageMeta as Jt,renamePage as vn}from"../browser/shared/pages.mjs";import{editExtension as xn,extensionSource as bn,listExtensions as Pn}from"../browser/shared/extensions.mjs";import{effectiveLook as Tt,ownLookFor as Nn,ownLookOf as En,sameLook as In,withLookField as de}from"../browser/shared/document-look.mjs";import{workspaceLook as Ct,writeWorkspaceLook as Ln}from"../browser/shared/workspace-look.mjs";import{findIn as An,tidyQuery as Fn}from"../browser/shared/search.mjs";var $n=([O,m,k,...c])=>c.length?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2} \u7B49 {3} \u6761",O,m,k,c.length+3):k!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}\uFF1B{2}",O,m,k):m!==void 0?B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}\uFF1B{1}",O,m):B("\u68C0\u67E5\u6CA1\u6709\u901A\u8FC7\uFF1A{0}",O),St=O=>O==="en"?"en":null,Rn=32*1024*1024;async function Y(O,m){for(let k=0;;k++)try{return await h.rename(O,m)}catch(c){if(!["EPERM","EBUSY","EACCES"].includes(c.code))throw c;if(k>=5)break;await new Promise(j=>setTimeout(j,60*(k+1)))}await h.cp(O,m,{recursive:!0,errorOnExist:!0,force:!1}),await h.rm(O,{recursive:!0,force:!0,maxRetries:5})}var Jn=O=>w.resolve(O);function xi({unified:O=!1,edits:m,reports:k,reportsDirectory:c=He,server:j={kind:"dev",version:null,stop:null},components:x=null,changed:J=()=>{},index:vt=null,web:C=null,projects:Z={touch(){},indexOf:async()=>null}}){let{trash:v}=$t(c),ct=null,q=()=>ct??=ln(),H=vt??Xt({root:c,read:Qt(m),draw:(t,e)=>k.words(t,e)}),l=(t,e,n)=>[t,{ok:!1,reason:e,...Et(n)}],N=t=>h.readFile(t,"utf8").then(JSON.parse).catch(()=>null),A=t=>pn(t,c),E=t=>Ot(A(t)),S=t=>w.join(c,t),F=t=>D(Ot(S(t)).html),_=t=>Promise.resolve(m.forgetChanges?.(t)).catch(()=>{}),lt=t=>Pt(c,t),_t=async(t,e,n)=>{await h.mkdir(n,{recursive:!0});let i=[];try{for(let r of t)await Y(w.join(e,r),w.join(n,r)),i.push(r)}catch(r){for(let o of i)await Y(w.join(n,o),w.join(e,o));throw r}},we=async(t,e)=>{if(!se.includes(t))return Y(S(t),e);await _t(await lt(t),S(t),e),await h.rmdir(S(t)).catch(()=>{})},me=async(t,e)=>se.includes(t)&&!await F(t)&&(await Promise.all((await h.readdir(e)).map(n=>D(w.join(S(t),n))))).every(n=>!n),Mt=async t=>await N(Ot(t).json)??{},$=async t=>{let{title:e=t,description:n="",type:i,instructions:r,icon:o,look:a}=await Mt(A(t)),s=r===!0?{}:Tt(a,Ct(c));return{slug:t,title:e,description:n,...i?{type:i}:{},...typeof o=="string"&&o?{icon:o}:{},...r===!0?{instructions:!0}:{},...Object.keys(s).length?{look:s}:{}}},ut=async t=>{let e=await Rt(S(t));return e&&{slug:t,title:e.title,description:"",kind:"link",url:e.url,...e.icon?{icon:e.icon}:{},...e.siteIcon?{siteIcon:e.siteIcon}:{}}},pe=async(t,e,n=[])=>{let i=it(t),r=i&&n.find(({id:W})=>W===i.ws),o=r?.facts.get(i.slug);if(o){let W=w.join(r.root,i.slug);return{slug:t,title:o.title,description:o.description,kind:o.kind==="link"?"link":"draft",workspace:i.ws,...o.icon?{icon:o.icon}:{},...o.kind==="link"?{url:o.url,siteIcon:o.siteIcon}:{},path:o.path,folder:W,root:r.root}}let{ws:a,title:s,description:u,icon:p,path:g,folder:f,root:d,missing:y,kind:L,url:Q,siteIcon:K}=await oe(t,e);return{slug:t,title:s,description:u,kind:L==="link"?"link":"draft",workspace:a,...L==="link"?{url:Q,siteIcon:K}:{},...p?{icon:p}:{},...g?{path:g,folder:f,root:d}:{},...y?{missing:y}:{}}},Wt=async(t,e,n,i)=>ie(t)?pe(t,n,i):e.includes(t)?await ut(t)??{slug:t,title:t,description:"",kind:"link",url:""}:$(t),b=Lt(c),ke=()=>ae(yt())===ae(c),he=(t,e)=>{let n=t.shown.find(({isDefault:s})=>s)?.id??(ke()?b:null),i=new Set([...t.drafts.map(s=>it(s)?.ws),...t.groups.map(({workspace:s})=>s),...t.shown.map(({id:s})=>s)].filter(Boolean)),r=new Set(t.groups.filter(({workspace:s,title:u})=>s&&!u).map(({workspace:s})=>s));t.groups.find(({id:s})=>s===ht)?.title||r.add(b),r.delete(n);let o=sn(new Set([...i,b]),{ids:new Map([...e,[b,[c]]]),stops:q(),among:r});Z.touch(new Map([...o].filter(([s])=>s!==b).map(([s,{root:u}])=>[s,u])));let a=Object.fromEntries([...i].map(s=>[s,{...o.get(s)??{missing:rt(s,e).refused??"unknown"},...s===n?{default:!0}:{}}]));return a[b]={...o.get(b),there:!0,self:!0,...b===n?{default:!0}:{}},a},U=()=>yn(c),ge=async(t,e)=>{let n=await Mt(A(t));await R(E(t).json,`${JSON.stringify({...n,[e]:!0},null,2)}
3
+ `)},D=t=>h.access(t).then(()=>!0,()=>!1),ft=async(t,{own:e=null}={})=>{let n=new Set((await wt()).map(({slug:i})=>i));n.delete(e);for(let i=1;;i++){let r=i===1?t:`${t}-${i}`;if(!On(r,c)&&!n.has(r))return r}},xt=async t=>{let e=await ft(t.slug,{own:t.slug});return gn(t.slug)?e===t.slug&&!await hn(t.slug,c)?e:jt(c):e},ye=async(t,e)=>{let n=E(t).html,i=await h.readFile(n,"utf8"),r=mt(i).replace(`data-doc-id="${e}"`,`data-doc-id="${t}"`);r!==i&&await R(n,r)},I=()=>te(c),M=async t=>{await Qe(c,t),J()},T=t=>ne(c,t);async function dt(t,e="",n=1/0){await T(async()=>{let i=await I();nt(i,t,e,n),await M(i)})}async function Oe(t,{parent:e="",after:n=null,first:i=!1}={}){await T(async()=>{let r=await I();for(let a of Object.values(r.children))a.includes(t)&&a.splice(a.indexOf(t),1);let o=typeof n=="string"?Object.keys(r.children).find(a=>r.children[a].includes(n)):void 0;o!==void 0?nt(r,t,o,r.children[o].indexOf(n)+1):nt(r,t,typeof e=="string"?e:"",i===!0?0:1/0),await M(r)})}function je(t,e){let n=new Set(Object.values(t.children).flat()),i={...t.children};for(let{id:r}of e.groups){if(r===ht)continue;let o=a=>{let s=(e.children[a]??[]).filter(u=>!n.has(u));(V(a)||s.length)&&(i[a]=s),s.forEach(o)};o(X(r))}return{groups:e.groups,children:i}}function Gt(t){return T(async()=>{let e=await I();for(let[n,i]of Object.entries(e.children)){let r=i.indexOf(t);if(!(r<0))return i.splice(r,1,...e.children[t]??[]),delete e.children[t],await M(e),{parent:n,index:r}}return{parent:"",index:1/0}})}let Se=(t,e)=>H.lines(t,e),Yt=t=>N(w.join(v,t,"entry.json")),wt=()=>ce(c),ve=()=>O?[...gt()].filter(([t,e])=>t!==b&&e.length===1).map(([t,e])=>({id:t,root:e[0]})):[],Bt=async()=>[...await wt(),...(await Promise.all(ve().map(async({id:t,root:e})=>(await ce(e)).map(n=>({...n,id:re(t,n.id),slug:re(t,n.slug)}))))).flat()];async function xe(t){let e=await Jt(t,c);if(!e)return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762");let n=`${Date.now().toString(36)}-${kt(3).toString("hex")}`;try{await h.mkdir(w.join(v,n),{recursive:!0}),await Y(st(t,c).folder,w.join(v,n,"page"))}catch(r){throw await h.rm(w.join(v,n),{recursive:!0,force:!0}).catch(()=>{}),r}let i={id:n,kind:"page",slug:t,title:e.title,at:Date.now(),parent:"",index:-1};return await R(w.join(v,n,"entry.json"),`${JSON.stringify(i,null,2)}
4
+ `),[200,{ok:!0,entry:i}]}async function be(t){let e=w.join(v,t.id,"page"),n=await xt(t);if(await h.mkdir($t(c).customPages,{recursive:!0}),await Y(e,st(n,c).folder),n!==t.slug){let{html:i}=st(n,c),r=await h.readFile(i,"utf8").catch(()=>null),o=r?.replace(`data-page-id="${t.slug}"`,`data-page-id="${n}"`);r!==null&&o!==r&&await R(i,o)}return await h.rm(w.join(v,t.id),{recursive:!0,force:!0}),[200,{ok:!0,page:await Jt(n,c),entry:{...t,slug:n}}]}async function Pe(t){let e=await Rt(S(t));if(!e)return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let n=`${Date.now().toString(36)}-${kt(3).toString("hex")}`,i=await I(),{parent:r,index:o}=await Gt(t);try{await h.mkdir(w.join(v,n),{recursive:!0}),await Y(S(t),w.join(v,n,"link"))}catch(s){throw await T(()=>M(i)),await h.rm(w.join(v,n),{recursive:!0,force:!0}).catch(()=>{}),s}let a={id:n,kind:"link",slug:t,title:e.title,at:Date.now(),parent:r,index:Number.isFinite(o)?o:-1};return await R(w.join(v,n,"entry.json"),`${JSON.stringify(a,null,2)}
5
+ `),[200,{ok:!0,entry:a}]}async function Ne(t){let e=w.join(v,t.id,"link"),n=await xt(t);return await Y(e,S(n)),await h.rm(w.join(v,t.id),{recursive:!0,force:!0}),await dt(n,t.parent,t.index<0?1/0:t.index),[200,{ok:!0,report:await ut(n),entry:{...t,slug:n}}]}function Ee(t,{parent:e,after:n,first:i}){let r=a=>V(a)?Object.hasOwn(t.children,a):Object.values(t.children).some(s=>s.includes(a));if(n!=null){let a=Object.keys(t.children).find(s=>t.children[s].includes(n));return a===void 0?{refused:[404,"after","\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE"]}:e!=null&&e!==a?{refused:[409,"level","\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6761\u76EE\u4E0D\u5728\u8FD9\u4E00\u5C42"]}:{parent:a,index:t.children[a].indexOf(n)+1}}let o=e??X(ht);return V(o)&&t.groups.some(a=>a.extension&&X(a.id)===o)?{refused:[409,"extension","\u6269\u5C55\u7684\u680F\u91CC\u653E\u4E0D\u4E86\u522B\u7684\u6761\u76EE"]}:r(o)?{parent:o,index:i?0:(t.children[o]??[]).length}:{refused:[404,"parent",V(o)?"\u627E\u4E0D\u5230\u8FD9\u4E00\u680F":"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6761\u76EE"]}}let z=new Map;function Ie(t){let e=z.get(t);if(e&&Date.now()-e.at<36e5)return e.answer;let n=C?C.frameable(t).catch(()=>({frameable:!0,reason:"unknown"})):Promise.resolve({frameable:!0,reason:"unknown"});return z.size>=500&&z.delete(z.keys().next().value),z.set(t,{at:Date.now(),answer:n}),n.then(i=>{["auth","unknown"].includes(i.reason)&&z.get(t)?.answer===n&&z.delete(t)}),n}function Ht(t,e){return C?.icon?(async()=>{let n=await C.icon(e).catch(()=>null);if(!n)return null;let i=w.join(S(t),At),r=await h.readFile(i,"utf8").catch(()=>null),o=r===null?null:dn(r);if(!o||o.url!==e||o.siteIcon===n)return null;let a=ot({...o,siteIcon:n});return a.refused||!a.value.siteIcon||!await R(i,`${JSON.stringify(a.value,null,2)}
6
+ `,{expect:r})?null:(J(),n)})().catch(()=>null):Promise.resolve(null)}let Ut={info:async()=>[200,{ok:!0,version:1,gallery:j.version,token:m.token,commands:[...Object.keys(tt)],server:{pid:process.pid,home:w.resolve(yt()),data:Be().data,version:j.version,kind:j.kind}}],async outline(){let{outline:t,others:e}=await ze(c),n=await U(),i=[...Object.values(t.children).flat(),...n?[n]:[]],r=gt(),o=async d=>[d,await Wt(d,t.links,r,e)],[a,s,u,p]=await Promise.all([Promise.all(i.map(o)),fe(yt()),Bt(),Pn(c)]),g=p.map(({id:d,file:y,revision:L,title:Q,icon:K,entries:W,count:bt,error:Kt})=>({id:d,file:y,revision:L,title:Q,...K?{icon:K}:{},entries:W,count:bt,...Kt?{error:Et(Kt)}:{}})),f=await ue(c,s);return[200,{ok:!0,outline:t,instructions:n,reports:Object.fromEntries(a),pages:s,head:f,trash:u,workspaces:he(t,r),self:b,shared:!0,extensions:g}]},trash:async()=>[200,{ok:!0,entries:await Bt()}],async stats(t){let e=t.get("slug")??"",n=P.test(e)?await H.facts(e).catch(()=>null):null;return n?[200,{ok:!0,edited:n.edited,words:n.words}]:l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},async query(t){let e;try{e=JSON.parse(t.get("options")??"{}")}catch{return[400,{ok:!1,reason:"options",message:"options is JSON"}]}return H.query(t.get("kind")??"",e,{doc:t.get("doc")})},components:async()=>[200,{ok:!0,...x.read()}],async source(t){let e=t.get("slug")??"",n=t.get("kind")==="page";if(!P.test(e))return l(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let i=w.resolve(n?st(e,c).html:E(e).html);return await D(i)?[200,{ok:!0,path:i}]:l(404,"missing",n?"\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762":"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863")},projects:async()=>[200,{ok:!0,workspaces:await an(c,{stops:q()})}],async search(t){let e=Fn(t.get("q")??"");if(!e)return[200,{ok:!0,results:[]}];let{children:n,groups:i,links:r}=await I(),o=[],a=f=>(n[f]??[]).forEach(d=>{!r.includes(d)&&(!ie(d)||it(d))&&o.push(d),a(d)});for(let{id:f}of i)a(X(f));let s=e.toLowerCase(),u=new Map(await Promise.all(o.map(async f=>[f,await Wt(f,r,gt())]))),p=JSON.stringify([...u].map(([f,{title:d}])=>[f,d])),g=(await Promise.all(o.map(async f=>{let d=it(f),y=d?rt(d.ws):null,L=y&&!y.refused?await Z.indexOf(y.root):null,Q=d?await L?.lines(d.slug,p):await Se(f,p);if(!Q)return null;let K=String(u.get(f).title).toLowerCase().includes(s),{count:W,hits:bt}=An(Q,e);return K||W?{slug:f,title:K,count:W,hits:bt}:null}))).filter(Boolean);return g.sort((f,d)=>Number(d.title)-Number(f.title)||d.count-f.count),[200,{ok:!0,results:g.slice(0,50)}]}},tt={async"extension-edit"({id:t,...e}){let n=await bn(c,t),i=await ne(n?.root??c,()=>xn(n?.root??c,t,e),{local:!0});return i.ok?(i.written&&J(),[200,{ok:!0}]):l(i.status,i.reason,i.error)},async outline({outline:t,base:e}){return!ee(t)||e!==void 0&&!ee(e)?l(400,"outline","\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21"):Ke(c,t)?await T(async()=>{let i=await I();return e!==void 0&&!Xe(e,i)?!1:(await M(t.groups?t:je(t,i)),!0)})?[200,{ok:!0,outline:await I()}]:l(409,"stale","\u6587\u6863\u76EE\u5F55\u521A\u5728\u522B\u5904\u6539\u8FC7"):l(409,"cross-workspace","\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E")},async move({slug:t,parent:e,after:n=null,first:i=!1,workspace:r}){if(typeof r=="string"&&!at(r,c))return l(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863");let o=u=>typeof u=="string"&&P.test(u);if(!o(t)||e!==void 0&&e!==""&&!o(e)||n!==null&&!o(n)||typeof i!="boolean")return l(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let a=await U();if(a!==null&&[t,e,n].includes(a))return l(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u5728\u6587\u6863\u76EE\u5F55\u91CC\uFF0C\u4E0D\u80FD\u79FB\u52A8\uFF0C\u4E0B\u9762\u4E5F\u4E0D\u80FD\u653E\u6587\u6863");let s=await Ue(c,t,{parent:e,after:n,first:i});if(s.written&&J(),!s.ok){let[u,p]={missing:[404,"\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"],parent:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863"],after:[404,"\u627E\u4E0D\u5230\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863"],level:[409,"\u8981\u653E\u5728\u5B83\u540E\u9762\u7684\u6587\u6863\u4E0D\u5728\u8FD9\u4E00\u5C42"],itself:[409,"\u6587\u6863\u4E0D\u80FD\u653E\u5728\u5B83\u81EA\u5DF1\u540E\u9762"],inside:[409,"\u6587\u6863\u4E0D\u80FD\u79FB\u5230\u5B83\u81EA\u5DF1\u6216\u5B83\u4E0B\u9762\u7684\u6587\u6863\u4E0B\u9762"],"cross-workspace":[409,"\u8DE8\u5DE5\u4F5C\u533A\u8BF7\u590D\u5236\uFF0C\u4E0D\u80FD\u53EA\u79FB\u52A8\u76EE\u5F55\u4F4D\u7F6E"]}[s.reason];return l(u,s.reason,p)}return[200,{ok:!0,...s,outline:await I()}]},async create({title:t,description:e,parent:n="",after:i=null,first:r=!1,language:o}){let a=typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,200):"",s=await jt(c);return await _(s),await k.create(s,a,typeof e=="string"&&e.trim()?e.trim():"\u65B0\u6587\u6863",{lang:St(o)}),await Oe(s,{parent:n,after:i,first:r}),[200,{ok:!0,report:await $(s)}]},async instructions({title:t,description:e,language:n}){let i=await U();if(i)return[200,{ok:!0,report:await $(i)}];let r=await ft(mn),o=(a,s)=>typeof a=="string"&&a.trim()?a.trim().slice(0,200):s;return await k.create(r,o(t,"\u5199\u4F5C\u504F\u597D"),o(e,"Agent \u6BCF\u6B21\u5199\u62A5\u544A\u524D\u90FD\u4F1A\u5148\u8BFB\u7684\u5199\u4F5C\u504F\u597D"),{lang:St(n),page:!0}),await ge(r,"instructions"),[200,{ok:!0,report:await $(r)}]},async components({id:t,hidden:e,shown:n,disabled:i,unlisted:r,net:o,pack:a,enabled:s}){try{return[200,{ok:!0,...await x.write(a!==void 0?{pack:a,enabled:s}:{id:t,hidden:e,shown:n,disabled:i,unlisted:r,net:o})}]}catch(u){return l(409,"components",u)}},async duplicate({slug:t,suffix:e,untitled:n}){if(typeof t!="string"||!P.test(t)||!await F(t))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let i=await jt(c);await _(i),await Nt(c,t,S(i),i);let{title:r}=await $(t),o=r||(typeof n=="string"&&n.trim()?n.trim().slice(0,50):"\u672A\u547D\u540D\u6587\u6863"),a=await m.renameReport(i,`${o}${typeof e=="string"&&e.length>0&&e.length<=20?e:"\uFF08\u526F\u672C\uFF09"}`),s=await I(),[u,p]=Object.entries(s.children).find(([,g])=>g.includes(t))??["",null];return await dt(i,u,p?p.indexOf(t)+1:1/0),[200,{ok:!0,report:await $(i),notes:a.notes??[]}]},async"copy-from"({sourceWs:t,slug:e,parent:n="",index:i=0}){let r=typeof t=="string"?rt(t):{};if(!r.root||t===b||typeof e!="string"||!P.test(e)||typeof n!="string"||!V(n)&&!tn.test(n)||!Number.isInteger(i)||i<0)return l(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let o=await te(r.root);if(!Object.values(o.children).some(f=>f.includes(e)))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let a=[],s=f=>{if(!P.test(f)||a.includes(f))throw new Error("\u6587\u6863\u76EE\u5F55\u7684\u7ED3\u6784\u4E0D\u5BF9\uFF1A\u6BCF\u4EFD\u6587\u6863\u53EA\u80FD\u51FA\u73B0\u4E00\u6B21");a.push(f);for(let d of o.children[f]??[])s(d)};s(e);let u=new Map;for(let f of a){let d;do d=await jt(c);while([...u.values()].includes(d));u.set(f,d)}let p=w.join($t(c).gallery,`copy-${kt(8).toString("hex")}`),g=[];try{await h.mkdir(p,{recursive:!0});for(let f of a)await Nt(r.root,f,w.join(p,u.get(f)),u.get(f),{names:u});return await T(async()=>{let f=await I();if((V(n)?qe(f.groups.find(y=>X(y.id)===n),b):De(n,b))!==b||(V(n)?!f.groups.some(y=>X(y.id)===n&&!y.extension):!Object.values(f.children).some(y=>y.includes(n))))throw new Error("\u627E\u4E0D\u5230\u8981\u653E\u5230\u5B83\u4E0B\u9762\u7684\u6587\u6863");for(let y of a){let L=u.get(y);await h.rename(w.join(p,L),S(L)),g.push(S(L))}It(c),nt(f,u.get(e),n,i);for(let y of a)o.children[y]?.length&&(f.children[u.get(y)]=o.children[y].map(L=>u.get(L)));await M(f)}),[200,{ok:!0,slug:u.get(e),count:a.length}]}catch(f){for(let d of g)await h.rm(d,{recursive:!0,force:!0});return It(c),l(409,"copy",f.text?f:f.message)}finally{await h.rm(p,{recursive:!0,force:!0})}},async look({slug:t,look:e}){if(typeof t!="string"||!P.test(t)||!await F(t))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(t===await U())return l(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");if(e!==null&&(typeof e!="object"||Array.isArray(e)))return l(400,"look","\u5B57\u4F53\u4E0E\u5E03\u5C40\u4E0D\u5BF9");let n=E(t).json,i=null;try{i=JSON.parse(await h.readFile(n,"utf8"))}catch{}if(!i||typeof i!="object"||Array.isArray(i))return l(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let r=de(i,Nn(e,Ct(c)));return JSON.stringify(r)!==JSON.stringify(i)&&await R(n,`${JSON.stringify(r,null,2)}
7
+ `),[200,{ok:!0,report:await $(t)}]},async looks({slug:t}){if(typeof t!="string"||!P.test(t)||!await F(t))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let e=await U();if(t===e)return l(409,"instructions","\u5199\u4F5C\u504F\u597D\u6CA1\u6709\u5B57\u4F53\u4E0E\u5E03\u5C40");let n=await N(E(t).json);if(!n||typeof n!="object"||Array.isArray(n))return l(409,"metadata","\u8FD9\u4EFD\u6587\u6863\u7684\u6807\u9898\u548C\u8BF4\u660E\u8BFB\u4E0D\u51FA\u6765");let i=Ct(c),r=Tt(n.look,i);try{await Ln(c,r)}catch(u){return l(409,"workspace",u)}let o=0,a=(await wn(c)).filter(u=>u!==e).map(u=>({json:E(u).json,self:u===t})),s=(await wt()).filter(({kind:u})=>u==="document").map(({id:u})=>({json:Ot(w.join(v,u,"report")).json,self:!1}));for(let{json:u,self:p}of[...a,...s])for(let g=0;g<3;g++){let f=await h.readFile(u,"utf8").catch(()=>null),d=null;try{d=JSON.parse(f??"")}catch{}if(!d||typeof d!="object"||Array.isArray(d)||!Object.hasOwn(d,"look")||d.instructions===!0)break;let y=await R(u,`${JSON.stringify(de(d,{}),null,2)}
8
+ `,{expect:f}).catch(()=>null);if(y===null)break;if(y){!p&&Object.keys(En(d.look)).length>0&&!In(Tt(d.look,i),r)&&o++;break}}return[200,{ok:!0,look:r,replaced:o,report:await $(t)}]},async head({order:t}){let e=Ze(t);return e?(await T(()=>Ve(c,e)),J(),[200,{ok:!0,head:await ue(c,await fe(yt()))}]):l(400,"head","\u4FA7\u680F\u5934\u90E8\u7684\u987A\u5E8F\u4E0D\u5BF9")},async"new-page"({title:t,after:e=null,language:n}){let i=typeof t=="string"?t.replace(/\s+/g," ").trim():"";if(!i||i.length>200)return l(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57");if(e!==null&&(typeof e!="string"||!P.test(e)))return l(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let r=await Sn(c);return await jn(r,i,{root:c,blank:!0,after:e,...St(n)?{lang:St(n)}:{}}),J(),[200,{ok:!0,page:await Jt(r,c)}]},async rename({slug:t,title:e,kind:n="document"}){if(typeof t!="string"||!P.test(t))return l(400,"slug","\u6587\u6863\u540D\u4E0D\u5BF9");if(n==="page"){let r;try{r=await vn(t,e,c)}catch{return l(400,"title","\u6807\u9898\u4E0D\u80FD\u662F\u7A7A\u7684\uFF0C\u4E5F\u4E0D\u80FD\u8D85\u8FC7 200 \u4E2A\u5B57")}return r?[200,{ok:!0,page:r}]:l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u9875\u9762")}let i=await m.renameReport(t,e);return i.ok?[200,{ok:!0,report:await $(t),notes:i.notes}]:l({title:400,missing:404}[i.reason]??409,i.reason,i.message??"\u6539\u540D\u6CA1\u6709\u6210\u529F")},async trash({slug:t,kind:e="document"}){if(typeof t!="string"||!P.test(t))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");if(e==="page")return xe(t);if(e==="link")return Pe(t);if(t===await U())return l(409,"instructions","\u5199\u4F5C\u504F\u597D\u4E0D\u80FD\u79FB\u5230\u56DE\u6536\u533A");if(!await F(t))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{title:n}=await $(t),i=`${Date.now().toString(36)}-${kt(3).toString("hex")}`,r=await I(),{parent:o,index:a}=await Gt(t);try{await h.mkdir(w.join(v,i),{recursive:!0}),await we(t,w.join(v,i,"report"))}catch(u){throw await T(()=>M(r)),await h.rm(w.join(v,i),{recursive:!0,force:!0}).catch(()=>{}),u}let s={id:i,kind:"document",slug:t,title:n,at:Date.now(),parent:o,index:Number.isFinite(a)?a:-1};return await R(w.join(v,i,"entry.json"),`${JSON.stringify(s,null,2)}
9
+ `),[200,{ok:!0,entry:s}]},async restore({id:t}){let e=typeof t=="string"&&le.test(t)?await Yt(t):null;if(!e)return l(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879");if(e.kind==="page")return be(e);if(e.kind==="link")return Ne(e);let n=w.join(v,t,"report"),i=await me(e.slug,n),r=i?e.slug:await xt(e);return i?await _t(await h.readdir(n),n,S(r)):await Y(n,S(r)),r!==e.slug&&await ye(r,e.slug),await h.rm(w.join(v,t),{recursive:!0,force:!0}),await dt(r,e.parent,e.index<0?1/0:e.index),[200,{ok:!0,report:await $(r),entry:{...e,kind:"document",slug:r}}]},async destroy({id:t}){let e=typeof t=="string"&&le.test(t)?await Yt(t):null;return e?((e.kind??"document")==="document"&&!await F(e.slug)&&await _(e.slug),await h.rm(w.join(v,t),{recursive:!0,force:!0}),[200,{ok:!0}]):l(404,"missing","\u56DE\u6536\u533A\u91CC\u6CA1\u6709\u8FD9\u4E00\u9879")},async link({url:t,title:e,icon:n=null,parent:i,after:r=null,first:o=!1},{port:a,wait:s=!1}={}){let u=ot({url:t,title:e,icon:n});if(u.refused)return l(400,u.refused,u.message);if(Ft(u.value.url,a))return l(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(i!=null&&typeof i!="string"||r!==null&&typeof r!="string"||typeof o!="boolean")return l(400,"body","\u8BF7\u6C42\u683C\u5F0F\u4E0D\u5BF9");let p=await T(async()=>{let f=await I(),d=Ee(f,{parent:i,after:r,first:o||i==null&&r===null});if(d.refused)return d;let y=await ft(fn(u.value.title,u.value.url));return await h.mkdir(S(y),{recursive:!0}),await R(w.join(S(y),At),`${JSON.stringify(u.value,null,2)}
10
+ `),nt(f,y,d.parent,d.index),await M(f),{slug:y,parent:d.parent,index:d.index}});if(p.refused)return l(...p.refused);let g=Ht(p.slug,u.value.url);return s&&await g,[200,{ok:!0,link:await ut(p.slug),parent:p.parent,index:p.index,outline:await I()}]},async"link-set"({slug:t,url:e,title:n,icon:i},{port:r,wait:o=!1}={}){let a=typeof t=="string"&&P.test(t)?await Rt(S(t)):null;if(!a)return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u94FE\u63A5");let s=e??a.url,u=ot({url:s,title:n??a.title,icon:i===void 0?a.icon??null:i,siteIcon:a.siteIcon??null});if(u.refused)return l(400,u.refused,u.message);let p=u.value.url!==a.url;if(p&&Ft(u.value.url,r))return l(409,"own","\u8FD9\u662F Gallery \u81EA\u5DF1\u7684\u5730\u5740\uFF0C\u8BF7\u76F4\u63A5\u94FE\u63A5\u6587\u6863");if(p&&delete u.value.siteIcon,JSON.stringify(u.value)!==JSON.stringify(a)&&await R(w.join(S(t),At),`${JSON.stringify(u.value,null,2)}
11
+ `),p){let g=Ht(t,u.value.url);o&&await g}return[200,{ok:!0,link:await ut(t)}]},async"draft-add"({path:t,confirm:e=!1,after:n=null}){let i=await rn(t),r=typeof n=="string"?n:null;if(i.kind==="missing")return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u6216\u6587\u4EF6\u5939");if(i.kind==="plain")return l(409,"plain","\u8FD9\u4E0D\u662F Gallery \u7684\u5E95\u7A3F\u6216\u5DE5\u4F5C\u533A\uFF0C\u53EF\u4EE5\u7528\u300C\u5BFC\u5165\u300D\u628A\u6587\u4EF6\u590D\u5236\u8FDB\u6765");if(i.kind==="nested")return l(409,"nested","\u8FD9\u4EFD\u5E95\u7A3F\u4E0D\u5728\u5B83\u5DE5\u4F5C\u533A\u7684\u7B2C\u4E00\u5C42\uFF08\u5728\u56DE\u6536\u533A\u91CC\uFF0C\u6216\u662F\u5199\u4F5C\u504F\u597D\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");if(i.kind==="name")return l(409,"name","\u8FD9\u4E2A\u6587\u4EF6\u5939\u7684\u540D\u5B57\u4E0D\u662F Gallery \u6587\u6863\u7684\u5199\u6CD5\uFF08\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26\uFF09\uFF0C\u4E0D\u80FD\u6DFB\u52A0");let o=i.kind==="workspace"?i.root:i.kind==="folder"?null:i.root,a=!o||!cn(c).some(g=>at(g.root,o));if(!o){let g=i.kind==="folder"?i.folder:i.parent;if(on(g))return l(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));if(e!==!0)return[409,{ok:!1,reason:"unregistered",folder:g,...Et(B("\u4F1A\u628A {0} \u767B\u8BB0\u6210\u4E00\u4E2A\u5DE5\u4F5C\u533A\uFF08\u5728\u91CC\u9762\u653E gallery.json \u548C .gallery/\uFF09",g))}];if(!(await kn(g)).ours)return l(409,"marker",B("{0} \u91CC\u7684 gallery.json \u662F\u522B\u7684\u7A0B\u5E8F\u7684\uFF0C\u4E0D\u80FD\u628A\u5B83\u767B\u8BB0\u6210\u5DE5\u4F5C\u533A",g));o=g}let s=i.kind==="workspace"||i.kind==="folder";if(at(o,c))return[200,{ok:!0,kind:s?"workspace":"draft",own:!0,existing:!0,...s?{column:ht}:{entry:i.slug}}];let u=await un(o,{force:!0}).catch(()=>"failed"),p=rt(Lt(o));return p.refused==="ambiguous"?l(409,"ambiguous",B("\u672C\u673A\u767B\u8BB0\u7684 {0} \u4E2A\u5DE5\u4F5C\u533A\u7F16\u53F7\u76F8\u540C\uFF08{1}\uFF09\uFF0C\u5148\u7528 gallery workspaces --forget \u53BB\u6389\u5176\u4E2D\u4E00\u4E2A",p.roots.length,Lt(o))):!p.root||!at(p.root,o)?u==="temporary"?l(409,"temporary","\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5728\u7CFB\u7EDF\u7684\u4E34\u65F6\u6587\u4EF6\u5939\u91CC\uFF0C\u4E0D\u80FD\u6DFB\u52A0"):l(409,"registry","\u6CA1\u80FD\u628A\u5B83\u7684\u5DE5\u4F5C\u533A\u8BB0\u8FDB\u672C\u673A\u7684\u767B\u8BB0\u8868"):(It(o),s?[200,{ok:!0,kind:"workspace",...await nn(c,o,{changed:J,after:r})}]:[200,{ok:!0,kind:"draft",...await en(c,o,i.slug,{changed:J,pick:!0,after:r,fresh:a})}])},async export({slug:t}){if(typeof t!="string"||!P.test(t)||!await D(A(t)))return l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863");let{problems:e=[],file:n,refused:i}=await k.export(t);return i?l(i.reason==="missing"?404:409,i.reason,i.message):e.length?l(422,"check",$n(e)):[200,{ok:!0,path:Jn(n)}]}},zt={async frameable({url:t},{port:e}){let n=typeof t=="string"?ot({url:t,title:"-"}):{refused:"url"};return n.refused?l(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740"):Ft(n.value.url,e)?[200,{ok:!0,frameable:!1,reason:"own"}]:[200,{ok:!0,...await Ie(n.value.url)}]},async reveal({entry:t,ws:e,page:n}){let i=gt(),r=null;return typeof n=="string"?r=P.test(n)?st(n,c).folder:null:typeof t=="string"&&it(t)?r=(await oe(t,i)).folder:e===b?r=w.resolve(c):typeof e=="string"&&(r=rt(e,i).root??null),!r||!await D(r)?l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4E2A\u6587\u4EF6\u5939"):[200,{ok:!0,path:r,...await Dt(r)}]},async title({url:t}){let e=typeof t=="string"?ot({url:t,title:"-"}):{refused:"url"};if(e.refused)return l(400,"url","\u8FD9\u4E0D\u662F\u4E00\u4E2A\u7F51\u5740");let n=C?await C.title(e.value.url).catch(()=>""):"",i=typeof n=="string"?n:n?.title,r=["auth","unknown"].includes(n?.reason)?n.reason:void 0;return[200,{ok:!0,title:typeof i=="string"?i.slice(0,200):"",...r?{reason:r}:{}}]}};function Le(t,e,n){if(t.method==="GET"&&Object.hasOwn(Ut,n)){let r=t.headers.host??"",o=t.socket.localPort;return r!==`127.0.0.1:${o}`&&r!==`localhost:${o}`?G(e,403,{ok:!1,reason:"host"}):Ut[n](new URL(t.url??"/","http://localhost").searchParams).then(([a,s])=>G(e,a,s),a=>G(e,...l(500,"read",a)))}if(t.method==="POST"&&n==="stop")return m.respond(async r=>{let o=await m.check(r);return o.error?o.error:j.kind!=="cli"||typeof j.stop!="function"?l(409,"dev","\u8FD9\u662F npm run dev \u7684\u670D\u52A1\u5668\uFF1A\u5728\u8FD0\u884C\u5B83\u7684\u5730\u65B9\u505C\u6B62\u5B83"):(e.once("finish",()=>j.stop()),[200,{ok:!0,pid:process.pid}])})(t,e);if(t.method==="POST"&&n==="pack-install")return m.respond(async r=>{let o=await m.check(r,Rn);if(o.error)return o.error;if(!x?.install)return l(404,"unknown");try{return[200,{ok:!0,...x.install(o.body??{})}]}catch(a){if(!a.code)throw a;return l(409,a.code,a)}})(t,e);if(t.method==="POST"&&n==="todo")return(async()=>{let r=await m.check(t);if(r.error)return r.error;let{slug:o,items:a}=r.body??{};return typeof o!="string"||!P.test(o)||!Array.isArray(a)?[400,{ok:!1,reason:"body"}]:!await F(o)||o===await U()?l(404,"missing","\u627E\u4E0D\u5230\u8FD9\u4EFD\u6587\u6863"):m.setTodos(o,a)})().then(([r,o])=>G(e,r,o),r=>G(e,...l(500,"write",r.message)));let i={port:t.socket.localPort};return t.method==="POST"&&Object.hasOwn(tt,n)?m.respond(async r=>{let o=await m.check(r);if(o.error)return o.error;let a=o.body&&typeof o.body=="object"?o.body:{};return typeof a.workspace=="string"&&!at(a.workspace,c)?l(409,"elsewhere","\u8FD9\u4E2A\u9884\u89C8\u670D\u52A1\u5668\u7BA1\u7684\u662F\u53E6\u4E00\u4E2A\u76EE\u5F55\u7684\u6587\u6863"):tt[n](a,i)})(t,e):t.method==="POST"&&Object.hasOwn(zt,n)?(async()=>{let r=await m.check(t);return r.error?r.error:zt[n](r.body&&typeof r.body=="object"?r.body:{},i)})().then(([r,o])=>G(e,r,o),r=>G(e,...l(500,"read",r))):G(e,404,{ok:!1,reason:"unknown"})}return{handle:Le,outline:I,trashEntries:wt,place:dt,freeSlug:ft,index:H,run:(t,e,n={})=>Object.hasOwn(tt,t)?tt[t](e??{},{wait:!0,...n}):Promise.resolve(l(404,"unknown","\u6CA1\u6709\u8FD9\u4E2A\u547D\u4EE4"))}}export{xi as a};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-IV64FFI4.mjs";import{c as P,d as W}from"./chunk-GHOYKMQ3.mjs";import"./chunk-QE5RG76S.mjs";import"./chunk-UYVCQK3H.mjs";import"./chunk-J5PUIV3Y.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as R}from"node:crypto";import{existsSync as X,readdirSync as G,readFileSync as Y,statSync as _}from"node:fs";import c from"node:fs/promises";import q from"node:os";import i from"node:path";import{release as J,reportsDirectory as V,skillDirectory as H}from"../browser/shared/paths.mjs";import{copyOldDocuments as Q,ensureWorkspace as Z,layoutOf as z,oldStateOf as K}from"../browser/shared/workspace.mjs";var S=o=>_(o,{throwIfNoEntry:!1})?.isDirectory()??!1;function ee({agent:o=null,project:e=!1,dir:r=null,cwd:t=process.cwd(),env:s=process.env}={}){if(r)return[{agent:null,target:i.resolve(t,r),skills:null}];let a=o?[o]:Object.keys(y),u=d=>e?i.join(i.resolve(t),y[d].project):i.resolve(y[d].home(s)),p=a.filter(d=>S(u(d)));return(o||p.length?o?a:p:["claude"]).map(d=>{let h=i.join(u(d),"skills");return{agent:d,target:i.join(h,"gallery"),skills:h}})}function te(o){try{return C(Y(i.join(o,"SKILL.md"),"utf8"))}catch{return null}}function T(o){let e=_(o,{throwIfNoEntry:!1});if(!e)return{kind:"absent"};if(!e.isDirectory())return{kind:"other",why:"it is a file"};let r=G(o);if(r.length===0)return{kind:"absent"};if(r.includes(".git"))return{kind:"other",why:"it is a git checkout"};let t=te(o),s=u=>r.includes(u);return(s("package.json")&&s("src")||s("reports"))&&(t==="gallery"||t==="html-report-studio")?{kind:"fat",name:t}:t==="gallery"&&!s("package.json")&&!s("src")&&!s("reports")?{kind:"thin"}:{kind:"other",why:t?`its SKILL.md is the skill "${t}"`:"it holds no Gallery skill"}}function oe(o){return S(o)?G(o,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(".")).map(e=>i.join(o,e.name)).filter(e=>T(e).kind==="fat"):[]}function re(o){let e=i.join(K(o),"servers");return S(e)?G(e).filter(r=>r.endsWith(".json")).flatMap(r=>{try{let{pid:t,port:s}=JSON.parse(Y(i.join(e,r),"utf8"));return!Number.isInteger(t)||t<=0||t===process.pid?[]:(process.kill(t,0),[{pid:t,port:s}])}catch(t){return t.code==="EPERM"?[{pid:Number.NaN,port:null}]:[]}}):[]}async function O(o){let e=0,r=0,t=async s=>{for(let a of await c.readdir(s,{withFileTypes:!0})){let u=i.join(s,a.name);a.isDirectory()?await t(u):(e++,r+=(await c.lstat(u)).size)}};return await t(o).catch(()=>{}),{files:e,bytes:r}}var B=o=>`${(o/1024/1024).toFixed(1)} MB`,se=(o,e)=>`${o} ${e}${o===1?"":"s"}`;async function v(o,e){for(let r=0;;r++)try{return await c.rename(o,e)}catch(t){if(process.platform!=="win32"||r>=10||!["EPERM","EBUSY","EACCES"].includes(t.code))throw t;await new Promise(s=>setTimeout(s,100*(r+1)))}}function ne(o,e=new Date){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,t=i.join(z(o).gallery,`old-skill-${r}`);for(let s=1;;s++){let a=s===1?t:`${t}-${s}`;if(!X(a))return a}}async function ie(o,e){await c.mkdir(i.dirname(e),{recursive:!0});try{return await v(o,e),null}catch(s){if(s.code!=="EXDEV")return`${s.code??s.message}`}let r=await O(o);await c.cp(o,e,{recursive:!0,preserveTimestamps:!0,verbatimSymlinks:!0,errorOnExist:!0,force:!1});let t=await O(e);return t.files!==r.files||t.bytes!==r.bytes?`the copy holds ${t.files} files, ${t.bytes} bytes, of ${r.files}, ${r.bytes}: the old folder was left as it was`:(await c.rm(o,{recursive:!0,force:!0}),null)}async function U(o){let e=[],r=async t=>{for(let s of await c.readdir(t,{withFileTypes:!0})){let a=i.join(t,s.name);s.isDirectory()?await r(a):e.push([i.relative(o,a).split(i.sep).join("/"),await c.readFile(a)])}};return await r(o),e.sort(([t],[s])=>t<s?-1:t>s?1:0)}var le=(o,e)=>o.length===e.length&&o.every(([r,t],s)=>r===e[s][0]&&t.equals(e[s][1]));async function ae(o,e,r){if(r==="thin"&&le(await U(o),await U(e)))return"same";let t=i.dirname(e);await c.mkdir(t,{recursive:!0});let s=R(4).toString("hex"),a=i.join(t,`.gallery-skill-new-${s}`);if(await c.cp(o,a,{recursive:!0}),r==="absent")return X(e)&&await c.rmdir(e),await v(a,e),"new";let u=i.join(t,`.gallery-skill-old-${s}`);await v(e,u);try{await v(a,e)}catch(p){throw await v(u,e).catch(()=>{}),await c.rm(a,{recursive:!0,force:!0}),p}return await c.rm(u,{recursive:!0,force:!0}),"updated"}async function $e(o,{version:e}){let{positional:r,options:t,values:s}=M({options:["--project"],values:["--agent","--dir"],argv:o});if(r[0]!=="install")throw new j(r.length?`No such skill command: ${r[0]} (install).`:"Say what to do: gallery skill install.");if(r.length>1)throw new j(`gallery skill install takes no other argument: ${r[1]}`);let a=s.get("--agent")??null;if(a!==null&&!Object.hasOwn(y,a))throw new j(`--agent is claude or codex, not ${a}.`);let u=s.get("--dir")??null;if(u!==null&&(a!==null||t.has("--project")))throw new j("--dir names the skill's folder itself: not with --agent or --project.");let p=ee({agent:a,project:t.has("--project"),dir:u}),d=[],h=p.map(n=>({...n,...T(n.target)}));for(let{target:n,kind:l,why:f}of h)l==="other"&&d.push(`${n} holds something that is not a Gallery skill (${f}): move it away, or pass --dir <another folder>.`);let N=[...new Set(h.flatMap(({target:n,kind:l,skills:f})=>[...l==="fat"?[n]:[],...f?oe(f):[]]))];for(let n of N)for(let{pid:l,port:f}of re(n))d.push(Number.isNaN(l)?`The older Gallery skill ${n} has a preview server running that this user cannot see: stop it first.`:`The older Gallery skill ${n} has its preview server running (pid ${l}${f?`, port ${f}`:""}): stop it first (close the window that runs it, or end process ${l}), then run gallery skill install again.`);if(d.length){for(let n of d)console.error(n);console.error("Nothing was changed."),process.exit(1)}if(N.length){let n=V;try{let{ours:l,reads:f}=await Z(n);l||(console.error(W(n,f)),process.exit(1))}catch(l){if(!l.code)throw l;console.error(P(n,l.code)),process.exit(1)}console.log(`\u5DE5\u4F5C\u533A\uFF1A${n}`);for(let l of N){console.log(`An older Gallery skill (the whole tools) is in ${l}: its documents go into the workspace, then it moves out of the skills folder.`);let f=i.join(l,"reports");if(S(f)){let m=await Q({from:f,to:n,state:K(l)});for(let w of A(m,f,n))console.log(` ${w}`)}else console.log(" It holds no documents (no reports/ folder).");let g=i.join(l,"exports");if(S(g)){let m=z(n).exports;await c.mkdir(m,{recursive:!0});let w=[],I=[];for(let E of(await c.readdir(g)).filter(x=>x.endsWith(".html")).sort())try{await c.copyFile(i.join(g,E),i.join(m,E),c.constants.COPYFILE_EXCL),w.push(E)}catch(x){if(x.code!=="EEXIST")throw x;I.push(E)}w.length&&console.log(` Exports: copied ${se(w.length,"file")} into ${m}: ${w.join(", ")}`),I.length&&console.log(` Exports not copied (the name is taken in ${m}; they stay in the moved folder's exports/): ${I.join(", ")}`)}let{bytes:k}=await O(l),$=await O(i.join(l,"node_modules")),D=ne(n),L=await ie(l,D);L&&(console.error(`Could not move ${l} to ${D} (${L}). Its documents are copied; move the folder out of the skills folder yourself (it is never needed in it again), then run gallery skill install again.`),process.exit(1)),console.log(` Moved the old skill to ${D} (${B(k)}${$.files?`; its node_modules/, ${B($.bytes)}, may be deleted: nothing reads it any more`:""}).`)}}let F=H,b=null;if(!J){let{buildSkill:n}=await import("./chunk-UGWMMEJ5.mjs");b=await c.mkdtemp(i.join(q.tmpdir(),"gallery-skill-")),F=i.join(b,"gallery"),n(F,{version:e})}try{let n=!1;for(let{agent:l,target:f}of h){let g=T(f).kind,k=await ae(F,f,g),$=l?` for ${y[l].name}`:"";console.log(k==="same"?`The Gallery skill ${e}${$} is installed already, unchanged: ${f}`:`${k==="updated"?"Updated":"Installed"} the Gallery skill ${e}${$}: ${f}`),n||=k!=="same"}n&&console.log("Open a new Agent session to use it.")}finally{b&&await c.rm(b,{recursive:!0,force:!0})}}export{y as AGENTS,T as kindOf,$e as run,ee as targetsOf};
2
+ import{a as y,b as C}from"./chunk-Q4UEPUWF.mjs";import{a as A}from"./chunk-FFV733MA.mjs";import{c as P,d as W}from"./chunk-WFGPMCTZ.mjs";import"./chunk-7UZUQQ7Q.mjs";import"./chunk-4B2TB5K2.mjs";import"./chunk-KLQP46Y3.mjs";import{b as j,f as M}from"./chunk-4OZWXZE5.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{randomBytes as R}from"node:crypto";import{existsSync as X,readdirSync as G,readFileSync as Y,statSync as _}from"node:fs";import c from"node:fs/promises";import q from"node:os";import i from"node:path";import{release as J,reportsDirectory as V,skillDirectory as H}from"../browser/shared/paths.mjs";import{copyOldDocuments as Q,ensureWorkspace as Z,layoutOf as z,oldStateOf as K}from"../browser/shared/workspace.mjs";var S=o=>_(o,{throwIfNoEntry:!1})?.isDirectory()??!1;function ee({agent:o=null,project:e=!1,dir:r=null,cwd:t=process.cwd(),env:s=process.env}={}){if(r)return[{agent:null,target:i.resolve(t,r),skills:null}];let a=o?[o]:Object.keys(y),u=d=>e?i.join(i.resolve(t),y[d].project):i.resolve(y[d].home(s)),p=a.filter(d=>S(u(d)));return(o||p.length?o?a:p:["claude"]).map(d=>{let h=i.join(u(d),"skills");return{agent:d,target:i.join(h,"gallery"),skills:h}})}function te(o){try{return C(Y(i.join(o,"SKILL.md"),"utf8"))}catch{return null}}function T(o){let e=_(o,{throwIfNoEntry:!1});if(!e)return{kind:"absent"};if(!e.isDirectory())return{kind:"other",why:"it is a file"};let r=G(o);if(r.length===0)return{kind:"absent"};if(r.includes(".git"))return{kind:"other",why:"it is a git checkout"};let t=te(o),s=u=>r.includes(u);return(s("package.json")&&s("src")||s("reports"))&&(t==="gallery"||t==="html-report-studio")?{kind:"fat",name:t}:t==="gallery"&&!s("package.json")&&!s("src")&&!s("reports")?{kind:"thin"}:{kind:"other",why:t?`its SKILL.md is the skill "${t}"`:"it holds no Gallery skill"}}function oe(o){return S(o)?G(o,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.name.startsWith(".")).map(e=>i.join(o,e.name)).filter(e=>T(e).kind==="fat"):[]}function re(o){let e=i.join(K(o),"servers");return S(e)?G(e).filter(r=>r.endsWith(".json")).flatMap(r=>{try{let{pid:t,port:s}=JSON.parse(Y(i.join(e,r),"utf8"));return!Number.isInteger(t)||t<=0||t===process.pid?[]:(process.kill(t,0),[{pid:t,port:s}])}catch(t){return t.code==="EPERM"?[{pid:Number.NaN,port:null}]:[]}}):[]}async function O(o){let e=0,r=0,t=async s=>{for(let a of await c.readdir(s,{withFileTypes:!0})){let u=i.join(s,a.name);a.isDirectory()?await t(u):(e++,r+=(await c.lstat(u)).size)}};return await t(o).catch(()=>{}),{files:e,bytes:r}}var B=o=>`${(o/1024/1024).toFixed(1)} MB`,se=(o,e)=>`${o} ${e}${o===1?"":"s"}`;async function v(o,e){for(let r=0;;r++)try{return await c.rename(o,e)}catch(t){if(process.platform!=="win32"||r>=10||!["EPERM","EBUSY","EACCES"].includes(t.code))throw t;await new Promise(s=>setTimeout(s,100*(r+1)))}}function ne(o,e=new Date){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`,t=i.join(z(o).gallery,`old-skill-${r}`);for(let s=1;;s++){let a=s===1?t:`${t}-${s}`;if(!X(a))return a}}async function ie(o,e){await c.mkdir(i.dirname(e),{recursive:!0});try{return await v(o,e),null}catch(s){if(s.code!=="EXDEV")return`${s.code??s.message}`}let r=await O(o);await c.cp(o,e,{recursive:!0,preserveTimestamps:!0,verbatimSymlinks:!0,errorOnExist:!0,force:!1});let t=await O(e);return t.files!==r.files||t.bytes!==r.bytes?`the copy holds ${t.files} files, ${t.bytes} bytes, of ${r.files}, ${r.bytes}: the old folder was left as it was`:(await c.rm(o,{recursive:!0,force:!0}),null)}async function U(o){let e=[],r=async t=>{for(let s of await c.readdir(t,{withFileTypes:!0})){let a=i.join(t,s.name);s.isDirectory()?await r(a):e.push([i.relative(o,a).split(i.sep).join("/"),await c.readFile(a)])}};return await r(o),e.sort(([t],[s])=>t<s?-1:t>s?1:0)}var le=(o,e)=>o.length===e.length&&o.every(([r,t],s)=>r===e[s][0]&&t.equals(e[s][1]));async function ae(o,e,r){if(r==="thin"&&le(await U(o),await U(e)))return"same";let t=i.dirname(e);await c.mkdir(t,{recursive:!0});let s=R(4).toString("hex"),a=i.join(t,`.gallery-skill-new-${s}`);if(await c.cp(o,a,{recursive:!0}),r==="absent")return X(e)&&await c.rmdir(e),await v(a,e),"new";let u=i.join(t,`.gallery-skill-old-${s}`);await v(e,u);try{await v(a,e)}catch(p){throw await v(u,e).catch(()=>{}),await c.rm(a,{recursive:!0,force:!0}),p}return await c.rm(u,{recursive:!0,force:!0}),"updated"}async function $e(o,{version:e}){let{positional:r,options:t,values:s}=M({options:["--project"],values:["--agent","--dir"],argv:o});if(r[0]!=="install")throw new j(r.length?`No such skill command: ${r[0]} (install).`:"Say what to do: gallery skill install.");if(r.length>1)throw new j(`gallery skill install takes no other argument: ${r[1]}`);let a=s.get("--agent")??null;if(a!==null&&!Object.hasOwn(y,a))throw new j(`--agent is claude or codex, not ${a}.`);let u=s.get("--dir")??null;if(u!==null&&(a!==null||t.has("--project")))throw new j("--dir names the skill's folder itself: not with --agent or --project.");let p=ee({agent:a,project:t.has("--project"),dir:u}),d=[],h=p.map(n=>({...n,...T(n.target)}));for(let{target:n,kind:l,why:f}of h)l==="other"&&d.push(`${n} holds something that is not a Gallery skill (${f}): move it away, or pass --dir <another folder>.`);let N=[...new Set(h.flatMap(({target:n,kind:l,skills:f})=>[...l==="fat"?[n]:[],...f?oe(f):[]]))];for(let n of N)for(let{pid:l,port:f}of re(n))d.push(Number.isNaN(l)?`The older Gallery skill ${n} has a preview server running that this user cannot see: stop it first.`:`The older Gallery skill ${n} has its preview server running (pid ${l}${f?`, port ${f}`:""}): stop it first (close the window that runs it, or end process ${l}), then run gallery skill install again.`);if(d.length){for(let n of d)console.error(n);console.error("Nothing was changed."),process.exit(1)}if(N.length){let n=V;try{let{ours:l,reads:f}=await Z(n);l||(console.error(W(n,f)),process.exit(1))}catch(l){if(!l.code)throw l;console.error(P(n,l.code)),process.exit(1)}console.log(`\u5DE5\u4F5C\u533A\uFF1A${n}`);for(let l of N){console.log(`An older Gallery skill (the whole tools) is in ${l}: its documents go into the workspace, then it moves out of the skills folder.`);let f=i.join(l,"reports");if(S(f)){let m=await Q({from:f,to:n,state:K(l)});for(let w of A(m,f,n))console.log(` ${w}`)}else console.log(" It holds no documents (no reports/ folder).");let g=i.join(l,"exports");if(S(g)){let m=z(n).exports;await c.mkdir(m,{recursive:!0});let w=[],I=[];for(let E of(await c.readdir(g)).filter(x=>x.endsWith(".html")).sort())try{await c.copyFile(i.join(g,E),i.join(m,E),c.constants.COPYFILE_EXCL),w.push(E)}catch(x){if(x.code!=="EEXIST")throw x;I.push(E)}w.length&&console.log(` Exports: copied ${se(w.length,"file")} into ${m}: ${w.join(", ")}`),I.length&&console.log(` Exports not copied (the name is taken in ${m}; they stay in the moved folder's exports/): ${I.join(", ")}`)}let{bytes:k}=await O(l),$=await O(i.join(l,"node_modules")),D=ne(n),L=await ie(l,D);L&&(console.error(`Could not move ${l} to ${D} (${L}). Its documents are copied; move the folder out of the skills folder yourself (it is never needed in it again), then run gallery skill install again.`),process.exit(1)),console.log(` Moved the old skill to ${D} (${B(k)}${$.files?`; its node_modules/, ${B($.bytes)}, may be deleted: nothing reads it any more`:""}).`)}}let F=H,b=null;if(!J){let{buildSkill:n}=await import("./chunk-UGWMMEJ5.mjs");b=await c.mkdtemp(i.join(q.tmpdir(),"gallery-skill-")),F=i.join(b,"gallery"),n(F,{version:e})}try{let n=!1;for(let{agent:l,target:f}of h){let g=T(f).kind,k=await ae(F,f,g),$=l?` for ${y[l].name}`:"";console.log(k==="same"?`The Gallery skill ${e}${$} is installed already, unchanged: ${f}`:`${k==="updated"?"Updated":"Installed"} the Gallery skill ${e}${$}: ${f}`),n||=k!=="same"}n&&console.log("Open a new Agent session to use it.")}finally{b&&await c.rm(b,{recursive:!0,force:!0})}}export{y as AGENTS,T as kindOf,$e as run,ee as targetsOf};
@@ -1,2 +1,2 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-DJISHPUL.mjs";import"./chunk-ITOH5EGO.mjs";import"./chunk-ZQS6H473.mjs";import"./chunk-HXG7EOPJ.mjs";import"./chunk-6N3PX4XX.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-R2ZDLJYT.mjs";import"./chunk-VFX2KNHP.mjs";import"./chunk-VS7JIGJW.mjs";import"./chunk-HDWTZ763.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l}from"./chunk-6Q7ASAXJ.mjs";import"./chunk-6NLXUKAY.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-3SKOU6OZ.mjs";import"./chunk-PLB7L22J.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";export{e as BASELINE_FROM,h as adoptIdless,g as baselineOf,b as blocksOf,k as exportBaselines,j as exportedText,i as hasBaseline,d as packageStamps,c as pageOf,l as previewBaseline,a as rankOf,f as readBaseline};
@@ -1,4 +1,4 @@
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 V,c as ce,e as le,j as X}from"./chunk-HDWTZ763.mjs";import{createHash as $e}from"node:crypto";import v from"node:fs";import h from"node:path";import{packsDirectory as T}from"../browser/shared/paths.mjs";import{PACKAGE_MANIFEST as M,layoutOf as Q}from"../browser/shared/workspace.mjs";var je="gallery",ee=/^(?:\.DS_Store|\._.*|Thumbs\.db|ehthumbs\.db|desktop\.ini)$/i,W=n=>ee.test(n);function G(n){return v.readdirSync(n,{recursive:!0,withFileTypes:!0}).filter(e=>e.isFile()&&!ee.test(e.name)).map(e=>h.relative(n,h.join(e.parentPath,e.name)).split(h.sep).join("/")).sort()}var Y=n=>[...n.filter(e=>e!==M),...n.includes(M)?[M]:[]];function E(n){return v.existsSync(n)?z(G(n).map(e=>({name:e,data:v.readFileSync(h.join(n,e))}))):null}function z(n){let e=$e("sha256"),t=n.filter(({name:i})=>!ee.test(i.split("/").at(-1))).sort((i,s)=>i.name<s.name?-1:i.name>s.name?1:0);for(let{name:i,data:s}of t)e.update(`${i}\0`).update(s).update(`
2
+ import{b as V,c as ce,e as le,j as X}from"./chunk-TKWEX4FD.mjs";import{createHash as $e}from"node:crypto";import v from"node:fs";import h from"node:path";import{packsDirectory as T}from"../browser/shared/paths.mjs";import{PACKAGE_MANIFEST as M,layoutOf as Q}from"../browser/shared/workspace.mjs";var je="gallery",ee=/^(?:\.DS_Store|\._.*|Thumbs\.db|ehthumbs\.db|desktop\.ini)$/i,W=n=>ee.test(n);function G(n){return v.readdirSync(n,{recursive:!0,withFileTypes:!0}).filter(e=>e.isFile()&&!ee.test(e.name)).map(e=>h.relative(n,h.join(e.parentPath,e.name)).split(h.sep).join("/")).sort()}var Y=n=>[...n.filter(e=>e!==M),...n.includes(M)?[M]:[]];function E(n){return v.existsSync(n)?z(G(n).map(e=>({name:e,data:v.readFileSync(h.join(n,e))}))):null}function z(n){let e=$e("sha256"),t=n.filter(({name:i})=>!ee.test(i.split("/").at(-1))).sort((i,s)=>i.name<s.name?-1:i.name>s.name?1:0);for(let{name:i,data:s}of t)e.update(`${i}\0`).update(s).update(`
3
3
  `);return e.digest("hex").slice(0,16)}var Z=n=>{try{return v.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name).sort()}catch{return[]}},_=(n=T)=>Z(n);function D(n=T){return Z(n).flatMap(e=>Z(h.join(n,e)).flatMap(t=>{let i=h.join(n,e,t);try{let s=JSON.parse(v.readFileSync(h.join(i,M),"utf8"));return s.id!==`${e}/${t}`?[]:[{name:t,id:s.id,pack:e,folder:i,version:s.version,title:s.name,description:s.description,places:s.places??["document"]}]}catch{return[]}}))}function Ue(n,e=T){let t=n.includes("/")?n:`${je}/${n}`;return D(e).find(i=>i.id===t)??null}var Ve=(n,e=T)=>_(e).includes(String(n).split("/")[0]);function P(n){try{let e=JSON.parse(v.readFileSync(Q(n).blocks,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function K(n,e){let t=Q(n).blocks;v.mkdirSync(h.dirname(t),{recursive:!0}),v.writeFileSync(t,`${JSON.stringify(e,null,2)}
4
4
  `)}var he=(n,e)=>h.join(Q(n).components,...e.split("/"));function ne(n,e){let t=he(n,e.id),i=E(t);if(i===null)return{added:!1,version:null,changed:!1,behind:!1};let s=null;try{s=JSON.parse(v.readFileSync(h.join(t,M),"utf8")).version??null}catch{}let a=P(n)[e.id],c=E(e.folder),o=i!==c&&i!==a?.fingerprint;return{added:!0,version:s,changed:o,behind:!o&&i!==c}}function xe(n,e){let t=he(n,e.id),i=ne(n,e);if(i.changed)throw Object.assign(new Error(`${e.id} was changed after it was added`),{code:"changed",folder:t});let s=E(e.folder),a=P(n);if(i.added&&!i.behind)return a[e.id]?.fingerprint!==s&&K(n,{...a,[e.id]:{version:e.version,fingerprint:s}}),{did:"same",folder:t};let c=G(e.folder);if(i.added)for(let o of G(t))c.includes(o)||v.rmSync(h.join(t,o));for(let o of Y(c))v.mkdirSync(h.dirname(h.join(t,o)),{recursive:!0}),v.copyFileSync(h.join(e.folder,o),h.join(t,o));return K(n,{...a,[e.id]:{version:e.version,fingerprint:s}}),{did:i.added?"updated":"added",from:i.version,folder:t}}var ae=n=>/^\d+\.\d+\.\d+$/.test(String(n??""))?n.split(".").map(Number):null;function L(n,e){let[t,i]=[ae(n),ae(e)];if(!t||!i)return n!==e;let s=t.findIndex((a,c)=>a!==i[c]);return s!==-1&&t[s]>i[s]}function Xe(n,e){let t=ne(n,e);return t.changed&&L(e.version,t.version)?e.version:null}var fe=new Map,me=()=>{};function Oe(n,{updated:e,kept:t,failed:i}){let s=[];e.length&&s.push(`Gallery's own blocks in ${n}, as they were added, updated to this Gallery's: ${e.map(({id:a,from:c,to:o})=>`${a} ${c??"?"} -> ${o}`).join(", ")}`);for(let{id:a,version:c,shipped:o}of t)s.push(`${a} in ${n} was changed after it was added, so it stays at ${c??"its version"}: Gallery's is ${o} (\u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 says how to take it)`);for(let{id:a,to:c,why:o}of i)s.push(`${a} in ${n} could not be updated to Gallery's ${c}: ${o}`);return s}function Fe(n,{ids:e=null,directory:t=T,log:i=null}={}){let s={updated:[],kept:[],failed:[]},a=h.resolve(n);for(let c of D(t)){if(e&&!e.includes(c.id))continue;let o=`${a}\0${h.resolve(c.folder)}`;if(fe.get(o)!==c.version){fe.set(o,c.version);try{let r=ne(n,c);if(r.changed&&L(c.version,r.version)&&s.kept.push({id:c.id,version:r.version,shipped:c.version}),!r.behind)continue;xe(n,c).did==="updated"&&s.updated.push({id:c.id,from:r.version,to:c.version})}catch(r){s.failed.push({id:c.id,to:c.version,why:r?.message??String(r)})}}}for(let c of Oe(a,s))(i??me)(c);return s}var de=new Set,pe=n=>process.platform==="win32"?h.resolve(n).toLowerCase():h.resolve(n);function Ze(n,e){de.add(pe(n)),me=e,le((t,i)=>{de.has(pe(t))&&Fe(t,{ids:i})},_())}var ue=n=>[n,n.replace("/","-")],be=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");function Qe(n,e,t=T){for(let i of D(t)){if(i.id===e)continue;let s;try{s=v.readFileSync(h.join(i.folder,"preview.svg"))}catch{continue}if(s.equals(n)||Buffer.from(Ae(i,e)["preview.svg"]??"").equals(n))return i}return null}function Ae(n,e){let[t,i]=[ue(n.id),ue(e)],s=new RegExp(t.map(be).join("|"),"g"),a={};for(let c of G(n.folder)){let o=v.readFileSync(h.join(n.folder,c));if(/\.(?:json|html|md|css|js|svg)$/.test(c)){let r=o.toString("utf8").replace(s,f=>i[t.indexOf(f)]);c===M&&(r=r.replace(/"version":\s*"[^"]*"/,'"version": "0.1.0"')),a[c]=r}else a[c]=o}return Object.fromEntries(Y(Object.keys(a)).map(c=>[c,a[c]]))}import m from"node:fs";import u from"node:path";import{refusal as Pe,said as k}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as Ee,OWN_SCOPE as te,PACK_FILE as F,PACK_ID as ye,readPackManifest as ie}from"../browser/shared/pack-manifest.mjs";import{packsDirectory as ge}from"../browser/shared/paths.mjs";import{DEVICE_NAMES as _e,PACKAGE_MANIFEST as R,layoutOf as H,markerOf as Ne,packageFolders as Ie}from"../browser/shared/workspace.mjs";var oe=Object.freeze(["gallery-soft"]);function fn(n,e={}){let t=P(n).packs;return oe.filter(i=>e?.[i]===void 0&&!b(t?.[i]))}var Me="GALLERY_NO_PACKS",Ge=(n=process.env)=>!["","0","false",void 0].includes(n[Me]),q=2e3,re=64*1024*1024,Se=/^[a-z0-9][a-z0-9-]*$/,b=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),j=(n,e)=>{throw Pe(e,{code:n})};function Te(n){let e=[];for(let t of m.readdirSync(n,{recursive:!0,withFileTypes:!0})){if(!t.isFile())continue;e.length>=q&&j("size",k("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",q,re/1024/1024));let i=u.relative(n,u.join(t.parentPath,t.name)).split(u.sep).join("/");e.push({name:i,data:m.readFileSync(u.join(n,...i.split("/")))})}return e}function Ce(n,{refuse:e=()=>{}}={}){let t=[],i=0;for(let{name:r,data:f}of n){let d=String(r).replace(/\\/g,"/");if(d.endsWith("/"))continue;let y=d.split("/");(d.startsWith("/")||/^[A-Za-z]:/.test(d)||d.includes("\0")||y.some(l=>l===""||l==="."||l===".."))&&j("path",k("{0} \u6307\u5411\u5757\u5305\u5916\u9762\uFF0C\u4E0D\u80FD\u88C5",String(r))),!(y[0]==="__MACOSX"||W(y.at(-1)))&&(i+=f.length,t.push({name:d,data:f}))}(t.length>q||i>re)&&j("size",k("\u5757\u5305\u592A\u5927\uFF1A\u6700\u591A {0} \u4E2A\u6587\u4EF6\u3001{1} MB",q,re/1024/1024));let s=t;if(!t.some(({name:r})=>r===F)){let r=new Set(t.map(({name:d})=>d.split("/")[0])),[f]=r;(r.size!==1||!t.some(({name:d})=>d===`${f}/${F}`))&&j("manifest",k("\u6700\u4E0A\u4E00\u5C42\u6CA1\u6709 pack.json\uFF1A\u5757\u5305\u662F\u4E00\u4E2A\u6587\u4EF6\u5939\uFF0C\u6700\u4E0A\u4E00\u5C42\u653E pack.json\uFF0C\u6BCF\u4E2A\u5757\u4E00\u4E2A\u6587\u4EF6\u5939")),s=t.map(({name:d,data:y})=>({name:d.slice(f.length+1),data:y}))}let a=ie(s.find(({name:r})=>r===F).data.toString("utf8"));e(a);let c=new Map,o=[];for(let r of s){let[f,...d]=r.name.split("/");if(d.length===0){o.push(r);continue}c.has(f)||c.set(f,[]),c.get(f).push({name:d.join("/"),data:r.data})}for(let[r,f]of c){(!Se.test(r)||_e.has(r))&&j("block",k("{0} \u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u540D\uFF1A\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",r));let d=f.find(l=>l.name===R);d||j("block",k("{0}/ \u91CC\u6CA1\u6709 component.json",r));let y;try{y=JSON.parse(d.data.toString("utf8").replace(/^/,"")).id}catch{j("block",k("{0}/component.json \u4E0D\u662F JSON",r))}y!==`${a.id}/${r}`&&j("block",k("{0}/component.json \u7684 id \u8981\u5199\u6210 {1}",r,`${a.id}/${r}`))}return{manifest:a,blocks:c,own:o}}function Ke(n){try{let e=JSON.parse(n.find(({name:t})=>t===R).data.toString("utf8").replace(/^/,"")).version;return typeof e=="string"?e:null}catch{return null}}function ve(n){try{return m.readdirSync(n,{withFileTypes:!0}).filter(e=>e.isFile()&&!W(e.name)).map(e=>e.name).sort()}catch{return[]}}function ke(n){let e=ve(n);return e.length?z(e.map(t=>({name:t,data:m.readFileSync(u.join(n,t))}))):null}function ze(n){try{return m.readdirSync(n).some(e=>!W(e))}catch{return!1}}function se(n,e,{replacing:t=!1,last:i=R}={}){let s=e.map(({name:o})=>o);if(t)for(let o of G(n))s.includes(o)||m.rmSync(u.join(n,...o.split("/")),{force:!0});let a=new Map(e.map(o=>[o.name,o.data])),c=i===R?Y(s):[...s.filter(o=>o!==i),...s.includes(i)?[i]:[]];for(let o of c){let r=u.join(n,...o.split("/"));m.mkdirSync(u.dirname(r),{recursive:!0}),m.writeFileSync(r,a.get(o))}}function De(n,e,{official:t=!1,shippedIds:i=_()}={}){let{manifest:s,blocks:a,own:c}=Ce(e,{refuse:({id:g})=>{!t&&i.includes(g)&&j("official",k("{0} \u662F Gallery \u81EA\u5E26\u7684\u5757\u5305\u7528\u7684 id\uFF1A\u6362\u4E00\u4E2A id \u518D\u88C5",g))}}),{id:o}=s,r=u.join(H(n).components,o),f=P(n),d=b(f.packs)?f.packs:{},y=b(d[o])?d[o]:null;!t&&!y&&ze(r)&&j("taken",k("\u5DE5\u4F5C\u533A\u91CC\u5DF2\u7ECF\u6709 components/{0}\uFF1A\u8FD9\u4E2A\u540D\u5B57\u88AB\u522B\u7684\u5757\u5305\u6216\u522B\u4EBA\u5199\u7684\u5757\u7528\u7740\uFF0C\u6362\u4E00\u4E2A id\uFF0C\u6216\u5148\u628A\u90A3\u4E2A\u6587\u4EF6\u5939\u632A\u8D70",o));let l={id:o,name:s.name,version:s.version,from:y?.version??null,folder:r,added:[],updated:[],same:[],kept:[],removed:[],skipped:[],ownKept:!1},w=[...a.keys()].sort();for(let g of w){let p=`${o}/${g}`,O=a.get(g),$=u.join(r,g),B=z(O),I=E($),J=b(f[p])?f[p]:null;if(I===null){if(t&&J){l.skipped.push(p);continue}se($,O),l.added.push(p)}else if(I===B)l.same.push(p);else if(J&&I===J.fingerprint)se($,O,{replacing:!0}),l.updated.push(p);else{l.kept.push(p);continue}f[p]={version:Ke(O),fingerprint:B}}for(let g of Array.isArray(y?.blocks)?y.blocks:[]){let p=String(g).split("/")[1];if(!p||a.has(p)||!Se.test(p))continue;let O=u.join(r,p),$=E(O);if($!==null&&$!==f[g]?.fingerprint){l.kept.push(g);continue}$!==null&&(m.rmSync(O,{recursive:!0,force:!0,maxRetries:5,retryDelay:100}),l.removed.push(g)),delete f[g]}let x=ke(r),A=z(c);if(x!==A)if(x===null||x===y?.fingerprint){let g=c.map(({name:p})=>p);for(let p of ve(r))g.includes(p)||m.rmSync(u.join(r,p),{force:!0});m.mkdirSync(r,{recursive:!0}),se(r,c,{last:F})}else l.ownKept=!0;let N=l.added.length+l.updated.length+l.removed.length>0||x!==A&&!l.ownKept;return l.did=y?N?"updated":"same":"installed",f.packs={...d,[o]:{version:s.version,fingerprint:l.ownKept?y.fingerprint:A,blocks:w.map(g=>`${o}/${g}`),...t?{official:!0}:{}}},K(n,f),l}function dn(n,e,{shippedIds:t=_()}={}){t.includes(e)&&j("official",k("{0} \u662F Gallery \u81EA\u5E26\u7684\u5757\u5305\uFF0C\u4E0D\u80FD\u5220\u9664\uFF1A\u5728 \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 \u91CC\u628A\u5B83\u5173\u6389",e));let i=u.join(H(n).components,e);(!ye.test(e)||!m.existsSync(i))&&j("missing",k("\u5DE5\u4F5C\u533A\u91CC\u6CA1\u6709\u5757\u5305 {0}",e));let s=P(n),a=b(s.packs)&&b(s.packs[e])?s.packs[e]:null;a||j("own",k("components/{0} \u4E0D\u662F\u88C5\u8FDB\u6765\u7684\u5757\u5305\uFF0C\u91CC\u9762\u7684\u5757\u662F\u6709\u4EBA\u5728\u8FD9\u4E2A\u5DE5\u4F5C\u533A\u5199\u7684\uFF1A\u8981\u5220\u5C31\u81EA\u5DF1\u5220\u6389\u8FD9\u4E2A\u6587\u4EF6\u5939",e)),m.rmSync(i,{recursive:!0,force:!0,maxRetries:5,retryDelay:100});for(let r of Object.keys(s))r.startsWith(`${e}/`)&&delete s[r];let{[e]:c,...o}=s.packs;return K(n,{...s,packs:o}),{id:e,version:a.version??null,blocks:Array.isArray(a.blocks)?a.blocks:[]}}var Le=n=>({zh:X("zh",n),en:X("en",n)});function pn(n,{settings:e=null,shippedIds:t=_(),directory:i=ge}={}){let{components:s}=H(n),a=P(n),c=b(a.packs)?a.packs:{},o=Ie(n),r=new Set([te,...o.map(({id:l})=>l.split("/")[0])]);try{for(let l of m.readdirSync(s))ye.test(l)&&m.existsSync(u.join(s,l,F))&&r.add(l)}catch{}let f=(e??V(n)).packs??{},d=[...r].map(l=>{let w=u.join(s,l),x=null,A=null;if(m.existsSync(u.join(w,F)))try{x=ie(m.readFileSync(u.join(w,F),"utf8")),x.id!==l&&(A=k("pack.json \u7684 id \u662F {0}\uFF0C\u5B83\u7684\u6587\u4EF6\u5939\u5374\u662F components/{1}",x.id,l),x=null)}catch(S){A=S}let N=b(c[l])?c[l]:null,g=o.filter(S=>S.id.startsWith(`${l}/`)),p=N?g.filter(S=>b(a[S.id])&&E(S.folder)!==a[S.id].fingerprint).map(S=>S.id):[];N&&ke(w)!==N.fingerprint&&p.push(`${l}/${F}`);let O=t.includes(l),$=null;if(O)try{$=ie(m.readFileSync(u.join(i,l,F),"utf8"))}catch{}let B=S=>{try{return JSON.parse(m.readFileSync(u.join(s,...S.split("/"),R),"utf8")).version??null}catch{return null}},I=O?D(i):[],we=O&&$&&p.some(S=>S.endsWith(`/${F}`)?L($.version,x?.version??null):I.some(U=>U.id===S)&&L(I.find(U=>U.id===S).version,B(S)))?$.version:null,C=l===te?Ee:x??(A?null:$);return{id:l,name:C?.name??{zh:l,en:l},description:C?.description??null,version:x?.version??null,author:C?.author??null,homepage:C?.homepage??null,icon:C?.icon??null,kind:l===te?"default":O?"official":N?"installed":"own",problem:A?Le(A):null,blocks:g.length,enabled:f[l]!==!1,changed:p,newer:we}}),y=({id:l,kind:w})=>w==="default"?-1:w==="official"?t.indexOf(l):w==="installed"?1e3:2e3;return d.sort((l,w)=>y(l)-y(w)||(l.id<w.id?-1:1))}function Re(n,e,t){let i=[],s=u.resolve(n);return t?i.push(`Gallery's pack ${e.id} ${e.version} installed in ${s} (${e.added.length+e.same.length+e.updated.length} blocks)${oe.includes(e.id)?", switched off: \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868 turns it on":""}`):(e.added.length&&i.push(`Gallery's pack ${e.id} in ${s} has new blocks: ${e.added.join(", ")}`),e.updated.length&&i.push(`Gallery's pack ${e.id} in ${s}, its blocks as they were installed, updated to this Gallery's: ${e.updated.join(", ")}`),e.removed.length&&i.push(`Gallery's pack ${e.id} in ${s}: ${e.removed.join(", ")} no longer in it, taken out`)),i}async function un(n,{directory:e=ge,env:t=process.env,log:i=()=>{}}={}){if(Ge(t))return{did:"off",packs:[]};let s={ours:!1};try{s=Ne(m.readFileSync(H(n).marker,"utf8"))}catch{}if(!s.ours)return{did:"unread",packs:[]};let a=_(e),c=[];for(let o of a)try{let r=!b(P(n).packs?.[o]);r&&oe.includes(o)&&V(n).packs[o]===void 0&&await ce(n,{pack:o,enabled:!1});let f=De(n,Te(u.join(e,o)),{official:!0,shippedIds:a});c.push({...f,first:r});for(let d of Re(n,f,r))i(d)}catch(r){i(`Gallery's pack ${o} could not be installed in ${u.resolve(n)}: ${r?.message??r}`),c.push({id:o,failed:r?.message??String(r)})}return{did:"done",packs:c}}export{je as a,Y as b,_ as c,D as d,Ue as e,Ve as f,P as g,ne as h,xe as i,L as j,Xe as k,Fe as l,Ze as m,Qe as n,Ae as o,fn as p,Te as q,De as r,dn as s,pn as t,un as u};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as h,b as v,d as p,e as S,h as j,j as I}from"./chunk-GMJD7ID3.mjs";import{a as A}from"./chunk-JEUK3ZO7.mjs";import{a as C}from"./chunk-JPG2LBQM.mjs";import"./chunk-ALZ6ZENZ.mjs";import"./chunk-IA4PSIMD.mjs";import{g as O}from"./chunk-7M2BQQGZ.mjs";import{b as i,f as g,i as y}from"./chunk-4OZWXZE5.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import D from"node:path";import{pageLinks as F,pageOfLink as J}from"../browser/shared/page-links.mjs";import{reportsDirectory as E}from"../browser/shared/paths.mjs";import{findPreviewServer as K}from"../browser/shared/preview-server.mjs";import{topOf as M}from"../browser/shared/outline-shape.mjs";import{LINK_FILE as U,linkAddress as P,linkIcon as T}from"../browser/shared/web-links.mjs";var $=t=>t.replace(/\s+/g," ").trim(),k=t=>t==null?"none":JSON.stringify(t);async function x(t,e){let n=await K(),o=n?await j(n,e,t):null;if(o)return o;let[,s]=await C({edits:{},reports:{},reportsDirectory:E,web:{icon:a=>O(a)}}).run(t,e);return s}function _(t,e){let n=[...t.documents.values()].filter(({url:a})=>a!==void 0),o=J(F(n),e.replace(/^.*#/,""));return o?{slug:o,link:t.documents.get(o)}:{refused:t.documents.get(e)?`${p(t,e)} is a document, not a web link: gallery set changes a document.`:`No web link "${e}": gallery list --tree shows the sidebar's entries.`}}var W=(t,e)=>t.groups.find(n=>[v(n),n.id].some(o=>o.toLowerCase()===$(e).toLowerCase()))??null;async function B(t,e,n){if(t.length!==2)throw new i('Name the address and the name: gallery link add <url> "<name>".');let[o,s]=t,a=P(o);if(a.refused)throw new i(`Not an address a web link takes: ${o} (${{url:"no address",scheme:"http or https only",long:"2048 characters at most"}[a.refused]}).`);if(!$(s))throw new i("The name is never empty.");let d=n.get("--column"),u=n.get("--under"),l=n.get("--after"),c=n.get("--icon");if(d!==void 0&&u!==void 0)throw new i("--column and --under are two places: give one.");if(l!==void 0&&e.has("--first"))throw new i("--after and --first are two places: give one.");if(c!==void 0&&!T(c))throw new i(`Not an icon a web link takes: ${c} (an emoji, or an icon of the \u56FE\u6807 tab as /icons/<name>_<color>.svg).`);let f=await h(),w;if(d!==void 0){let L=W(f,d);L||(console.error(`No column "${d}" in the sidebar (${f.groups.map(v).join(", ")}): nothing added.`),process.exit(1)),w=M(L.id)}u!==void 0&&(w=(await y(u)).slug);let r=l===void 0?null:(await y(l)).slug,q=e.has("--first")||u===void 0&&r===null,m=await x("link",{url:a.url,title:$(s),...c?{icon:c}:{},...w!==void 0?{parent:w}:{},after:r,first:q});m?.ok||(console.error(`Not added: ${m?.message??m?.reason??"no answer"}.`),process.exit(1));let b=await h(),{slug:N,url:z}=m.link;console.log(`Added the web link ${p(b,N)}: ${z}`),console.log(`Placed it ${I(b,{parent:m.parent,index:m.index})}.`),console.log(S(b,N)),console.log(`It is ${A(D.join(E,N,U))}; the workbench shows the page beside the sidebar (a site that refuses frames: \u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00).`)}async function G(t,e){if(t.length!==1)throw new i("Name one web link, then what to set: --url, --title, --icon.");if(!["--url","--title","--icon"].some(r=>e.has(r)))throw new i('Say what to set: --url <address>, --title "<name>", --icon <emoji|none>.');let n=e.has("--title")?$(e.get("--title")):void 0;if(n==="")throw new i("--title takes the words of the name: a web link's name is never empty.");let o;if(e.has("--url")){let r=P(e.get("--url"));if(r.refused)throw new i(`Not an address a web link takes: ${e.get("--url")}.`);o=r.url}let s;if(e.has("--icon")){let r=e.get("--icon").trim();if(r!=="none"&&!T(r))throw new i(`Not an icon a web link takes: ${r} (an emoji, none, or an icon of the \u56FE\u6807 tab).`);s=r==="none"?null:r}let a=await h(),d=_(a,t[0]);d.refused&&(console.error(d.refused),process.exit(1));let{slug:u,link:l}=d,c=await x("link-set",{slug:u,...o!==void 0?{url:o}:{},...n!==void 0?{title:n}:{},...s!==void 0?{icon:s}:{}});c?.ok||(console.error(`Not set: ${c?.message??c?.reason??"no answer"}.`),process.exit(1));let f=c.link,w=[...n!==void 0&&n!==l.title?[` title: ${k(l.title)} \u2192 ${k(f.title)}`]:[],...o!==void 0&&f.url!==l.url?[` url: ${l.url} \u2192 ${f.url}`]:[],...s!==void 0&&(f.icon??null)!==(l.icon??null)?[` icon: ${k(l.icon)} \u2192 ${k(f.icon??null)}`]:[]];if(!w.length)return void console.log(`Nothing to change: ${u} has ${e.size===1?"that already":"those already"}.`);console.log(`Set the web link ${u}:`);for(let r of w)console.log(r)}async function H(t){if(t.length!==1)throw new i("Name one web link to move to the trash.");let e=await h(),n=_(e,t[0]);n.refused&&(console.error(n.refused),process.exit(1));let o=await x("trash",{slug:n.slug,kind:"link"});o?.ok||(console.error(`Not moved to the trash: ${o?.message??o?.reason??"no answer"}.`),process.exit(1)),console.log(`Moved the web link ${p(e,n.slug)} to the trash: the workbench's \u8BBE\u7F6E \u203A \u56DE\u6536\u533A restores it where it was.`)}async function se(t){let[e,...n]=t;if(e==="add"){let{positional:o,options:s,values:a}=g({options:["--first"],values:["--column","--under","--after","--icon"],argv:n});return B(o,s,a)}if(e==="set"){let{positional:o,values:s}=g({values:["--url","--title","--icon"],argv:n});return G(o,s)}if(e==="remove"){let{positional:o}=g({argv:n});return H(o)}throw new i(e?`No such action: link ${e} (add, set, remove).`:"Say what to do: gallery link add, set or remove.")}export{se as run};
@@ -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{e as H,f as K,g as Q}from"./chunk-ZWWC4KLF.mjs";import{d as D,f as E,g as T,h as F}from"./chunk-HDWTZ763.mjs";import{existsSync as R}from"node:fs";var U=120;function W(n,I){let p=({packages:s,problems:c})=>new Map([...s,...c].map(([a,{stamp:t}])=>[a,t])),[l,f]=[p(n),p(I)];return[...new Set([...l.keys(),...f.keys()])].filter(s=>l.get(s)!==f.get(s)).sort()}function A({root:n,tell:I,delay:p=U,quiet:l=Q,hold:f=H,limit:s=K,now:c=Date.now,timers:a={set:(t,m)=>setTimeout(t,m),clear:t=>clearTimeout(t)}}){let t=null,m=0,u=null,r=new Map;T(n);let M=i=>{t&&m<=c()+i||(a.clear(t),m=c()+i,t=a.set(w,i),t.unref?.())};function w({settled:i=!1}={}){t=null;let d=T(n),o=E(n,d.settings),b=c();o.stamp!==u?.stamp&&(u={stamp:o.stamp,at:b});let y=b-u.at;if(y<l&&!i)return M(l-y);let g=new Map(o.packages),k=new Map(o.problems),h=1/0;for(let[e,L]of d.packages){if(!(!o.settings.disabled.includes(e)&&(k.has(e)||!g.has(e)&&R(L.folder)))){r.delete(e);continue}r.has(e)||r.set(e,u.at);let O=Math.min(f-y,s-(b-r.get(e)));if(O<=0){r.delete(e);continue}g.set(e,L),k.delete(e),h=Math.min(h,O)}let{settings:C,packs:S}=o,x=D({packages:g,problems:k,settings:C,packs:S});if(x!==d.stamp){let e={packages:g,problems:k,settings:C,packs:S,stamp:x};F(n,e),I(e,W(d,e))}h!==1/0&&M(h)}return{changed:()=>M(p),taken(){a.clear(t),w({settled:!0})},close(){a.clear(t),t=null}}}export{U as a,A as b};
2
+ import{e as H,f as K,g as Q}from"./chunk-S3SX3COT.mjs";import{d as D,f as E,g as T,h as F}from"./chunk-TKWEX4FD.mjs";import{existsSync as R}from"node:fs";var U=120;function W(n,I){let p=({packages:s,problems:c})=>new Map([...s,...c].map(([a,{stamp:t}])=>[a,t])),[l,f]=[p(n),p(I)];return[...new Set([...l.keys(),...f.keys()])].filter(s=>l.get(s)!==f.get(s)).sort()}function A({root:n,tell:I,delay:p=U,quiet:l=Q,hold:f=H,limit:s=K,now:c=Date.now,timers:a={set:(t,m)=>setTimeout(t,m),clear:t=>clearTimeout(t)}}){let t=null,m=0,u=null,r=new Map;T(n);let M=i=>{t&&m<=c()+i||(a.clear(t),m=c()+i,t=a.set(w,i),t.unref?.())};function w({settled:i=!1}={}){t=null;let d=T(n),o=E(n,d.settings),b=c();o.stamp!==u?.stamp&&(u={stamp:o.stamp,at:b});let y=b-u.at;if(y<l&&!i)return M(l-y);let g=new Map(o.packages),k=new Map(o.problems),h=1/0;for(let[e,L]of d.packages){if(!(!o.settings.disabled.includes(e)&&(k.has(e)||!g.has(e)&&R(L.folder)))){r.delete(e);continue}r.has(e)||r.set(e,u.at);let O=Math.min(f-y,s-(b-r.get(e)));if(O<=0){r.delete(e);continue}g.set(e,L),k.delete(e),h=Math.min(h,O)}let{settings:C,packs:S}=o,x=D({packages:g,problems:k,settings:C,packs:S});if(x!==d.stamp){let e={packages:g,problems:k,settings:C,packs:S,stamp:x};F(n,e),I(e,W(d,e))}h!==1/0&&M(h)}return{changed:()=>M(p),taken(){a.clear(t),w({settled:!0})},close(){a.clear(t),t=null}}}export{U as a,A as b};