@heycys/gallery 0.2.1 → 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 (169) hide show
  1. package/THIRD-PARTY-NOTICES.md +1 -1
  2. package/browser/editor/page/annotate/index.mjs +3 -2
  3. package/browser/editor/page/board/index.mjs +2 -1
  4. package/browser/editor/page/board/settings.mjs +2 -1
  5. package/browser/editor/page/core.mjs +3 -2
  6. package/browser/editor/page/custom-page.mjs +4 -3
  7. package/browser/editor/page/editor.mjs +9 -5
  8. package/browser/editor/page/emoji-picker/support.mjs +3 -2
  9. package/browser/editor/page/links/index.mjs +1 -12
  10. package/browser/editor/page/links/pages.mjs +3 -2
  11. package/browser/editor/page/outline/folds.mjs +3 -0
  12. package/browser/editor/page/post.mjs +2 -1
  13. package/browser/editor/page/present-links.mjs +4 -3
  14. package/browser/editor/page/present-shell.mjs +3 -58
  15. package/browser/editor/page/session.mjs +3 -37
  16. package/browser/editor/page/storage.mjs +5 -5
  17. package/browser/shared/component-catalog.mjs +2 -2
  18. package/browser/shared/drafts.mjs +26 -51
  19. package/browser/shared/emoji/icon-value.mjs +2 -1
  20. package/browser/shared/extension-manifest.mjs +90 -0
  21. package/browser/shared/extensions.mjs +26 -16
  22. package/browser/shared/http.mjs +1 -1
  23. package/browser/shared/i18n/en.mjs +46 -15
  24. package/browser/shared/media.mjs +2 -1
  25. package/browser/shared/outline.mjs +11 -51
  26. package/browser/shared/page-address.mjs +8 -15
  27. package/browser/shared/paths.mjs +2 -1
  28. package/browser/shared/preferences.mjs +3 -1
  29. package/browser/shared/preview-server.mjs +51 -63
  30. package/browser/shared/service-location.mjs +18 -0
  31. package/browser/shared/session.mjs +3 -6
  32. package/browser/shared/workspace-address.mjs +19 -0
  33. package/browser/shared/workspace-columns.mjs +1 -2
  34. package/browser/shared/workspace-registry.mjs +6 -40
  35. package/browser/shared/workspace.mjs +3 -6
  36. package/browser/shared/writing-preferences.mjs +6 -4
  37. package/dist/{chunk-BYSF5UMM.mjs → chunk-236JJXWY.mjs} +2 -2
  38. package/dist/{chunk-3A5I2GJK.mjs → chunk-2KAVXMKG.mjs} +1 -1
  39. package/dist/chunk-2T4PZQEP.mjs +2 -0
  40. package/dist/{chunk-SAHS56QM.mjs → chunk-3SKOU6OZ.mjs} +1 -1
  41. package/dist/{chunk-S2Y7VI4H.mjs → chunk-3XZOA7AH.mjs} +2 -2
  42. package/dist/{chunk-MKTX5PGV.mjs → chunk-43B75J5T.mjs} +1 -1
  43. package/dist/{chunk-VKSRM7EY.mjs → chunk-4B2TB5K2.mjs} +1 -1
  44. package/dist/{chunk-LV24RY2E.mjs → chunk-4K5KC6V2.mjs} +1 -1
  45. package/dist/{chunk-SOD23RGL.mjs → chunk-4KUO7R2M.mjs} +8 -8
  46. package/dist/chunk-4SNV4HA5.mjs +2 -0
  47. package/dist/chunk-53XDTHTG.mjs +4 -0
  48. package/dist/chunk-5XV3YYLG.mjs +2 -0
  49. package/dist/{chunk-VNUWREXU.mjs → chunk-65NTKF4N.mjs} +1 -1
  50. package/dist/chunk-6GV3CBB2.mjs +2 -0
  51. package/dist/{chunk-DH6GMDNN.mjs → chunk-6L6V7YR2.mjs} +1 -1
  52. package/dist/{chunk-TOE6DPLH.mjs → chunk-6NLXUKAY.mjs} +1 -1
  53. package/dist/chunk-6Q7ASAXJ.mjs +3 -0
  54. package/dist/{chunk-ZCP7BTOZ.mjs → chunk-6QBHU4DF.mjs} +1 -1
  55. package/dist/{chunk-QXVNUASA.mjs → chunk-6QWQXHAV.mjs} +1 -1
  56. package/dist/chunk-6XD6U3QA.mjs +5 -0
  57. package/dist/{chunk-36FIRJIF.mjs → chunk-742D2WWJ.mjs} +2 -2
  58. package/dist/{chunk-7M7UPWU6.mjs → chunk-7EFHNQ5B.mjs} +1 -1
  59. package/dist/{chunk-JI6T3A4Y.mjs → chunk-7ISBBDJR.mjs} +1 -1
  60. package/dist/{chunk-2GKGEVMR.mjs → chunk-7UZUQQ7Q.mjs} +25 -24
  61. package/dist/{chunk-VPVOAJ7X.mjs → chunk-AGDILNWB.mjs} +1 -1
  62. package/dist/{chunk-5IIH335D.mjs → chunk-ALZ6ZENZ.mjs} +1 -1
  63. package/dist/{chunk-G4YP7GVC.mjs → chunk-BFJGHSQN.mjs} +1 -1
  64. package/dist/chunk-BLNQUR5R.mjs +168 -0
  65. package/dist/chunk-BMX3VUHY.mjs +2 -0
  66. package/dist/chunk-BN7M3IN7.mjs +8 -0
  67. package/dist/{chunk-AMDGVDNV.mjs → chunk-BQNTTFPL.mjs} +1 -1
  68. package/dist/chunk-C257H6IA.mjs +2 -0
  69. package/dist/{chunk-74RPP2M2.mjs → chunk-C564NU2H.mjs} +1 -1
  70. package/dist/chunk-CHQU37CA.mjs +2 -0
  71. package/dist/{chunk-WCWYNFDF.mjs → chunk-E4IHAIJ7.mjs} +1 -1
  72. package/dist/{chunk-7XDYK3UC.mjs → chunk-E7656LR7.mjs} +1 -1
  73. package/dist/{chunk-KFZBYDIS.mjs → chunk-ECZBLQKK.mjs} +1 -1
  74. package/dist/{chunk-PAFSFVYB.mjs → chunk-ERE2BXYV.mjs} +1 -1
  75. package/dist/{chunk-ZEY2RLBT.mjs → chunk-ERLAIBOA.mjs} +2 -2
  76. package/dist/chunk-FFV733MA.mjs +2 -0
  77. package/dist/{chunk-CZ5KJSGK.mjs → chunk-GJJRBGMY.mjs} +1 -1
  78. package/dist/{chunk-VA3KAQZD.mjs → chunk-GKOBB6DH.mjs} +1 -1
  79. package/dist/chunk-GMJD7ID3.mjs +2 -0
  80. package/dist/{chunk-QZ35UAB4.mjs → chunk-GRAXKKG4.mjs} +1 -1
  81. package/dist/{chunk-2RKIHJI2.mjs → chunk-HYMEEXKN.mjs} +1 -1
  82. package/dist/{chunk-DKR7LFIY.mjs → chunk-IA2SIEJQ.mjs} +1 -1
  83. package/dist/{chunk-QK3VISCA.mjs → chunk-IA4PSIMD.mjs} +1 -1
  84. package/dist/chunk-JPG2LBQM.mjs +11 -0
  85. package/dist/{chunk-VGTMLQWZ.mjs → chunk-JXXHAXYH.mjs} +1 -1
  86. package/dist/{chunk-5MEXZ2UF.mjs → chunk-K3JKPFL5.mjs} +1 -1
  87. package/dist/{chunk-LE44MD3O.mjs → chunk-KLQP46Y3.mjs} +1 -1
  88. package/dist/{chunk-NAGMRVW4.mjs → chunk-LKX55H76.mjs} +1 -1
  89. package/dist/chunk-LMUZQK5O.mjs +2 -0
  90. package/dist/{chunk-CG3UHDKH.mjs → chunk-M4NRDYI5.mjs} +1 -1
  91. package/dist/{chunk-HM4E43VM.mjs → chunk-MAFIGVXY.mjs} +1 -1
  92. package/dist/{chunk-4DNHHJSL.mjs → chunk-MKIBJTJZ.mjs} +1 -1
  93. package/dist/{chunk-L7W624FD.mjs → chunk-MNWJ4EZY.mjs} +1 -1
  94. package/dist/{chunk-FXQBADMN.mjs → chunk-NHP66IWR.mjs} +1 -1
  95. package/dist/{chunk-YBB5LWZK.mjs → chunk-OEIJLMPI.mjs} +1 -1
  96. package/dist/{chunk-NWRZXELO.mjs → chunk-PAREWQGB.mjs} +1 -1
  97. package/dist/{chunk-7N2LPG33.mjs → chunk-PDZR3L3C.mjs} +1 -1
  98. package/dist/{chunk-YFJU3O7G.mjs → chunk-PLB7L22J.mjs} +1 -1
  99. package/dist/{chunk-4AMTKWDO.mjs → chunk-PUOQ65NC.mjs} +1 -1
  100. package/dist/chunk-Q4MS6OFC.mjs +2 -0
  101. package/dist/{chunk-3OFXMN6N.mjs → chunk-Q7P3Q5YX.mjs} +1 -1
  102. package/dist/{chunk-6MPKCH3P.mjs → chunk-QNECWMGR.mjs} +1 -1
  103. package/dist/{chunk-HBAUKKQH.mjs → chunk-QP7BOHE4.mjs} +1 -1
  104. package/dist/chunk-QVGOPHOF.mjs +2 -0
  105. package/dist/{chunk-NFABH3QW.mjs → chunk-RRKJMHNX.mjs} +2 -2
  106. package/dist/chunk-S3SX3COT.mjs +20 -0
  107. package/dist/{chunk-ZO7SFB2E.mjs → chunk-SQ6Y2ZMA.mjs} +2 -2
  108. package/dist/{chunk-VG5JEIUQ.mjs → chunk-TKWEX4FD.mjs} +2 -2
  109. package/dist/{chunk-CCSGFCLZ.mjs → chunk-U3SSPL4K.mjs} +1 -1
  110. package/dist/{chunk-DHB7UZ7F.mjs → chunk-U5XL7D6A.mjs} +1 -1
  111. package/dist/{chunk-CPS4SRPF.mjs → chunk-ULXSPX5H.mjs} +2 -2
  112. package/dist/{chunk-JXLSHVJ2.mjs → chunk-UMHUSOPJ.mjs} +1 -1
  113. package/dist/chunk-USIHBCSW.mjs +15 -0
  114. package/dist/{chunk-GWOYMENX.mjs → chunk-V6XZ4VIR.mjs} +1 -1
  115. package/dist/{chunk-AFGUR7SY.mjs → chunk-VPMRP2TL.mjs} +1 -1
  116. package/dist/{chunk-WTEGUPFG.mjs → chunk-VRPVVMRB.mjs} +1 -1
  117. package/dist/chunk-VZ2RQ3AM.mjs +2 -0
  118. package/dist/{chunk-XKOHV4H6.mjs → chunk-W5NPH5UA.mjs} +1 -1
  119. package/dist/chunk-WFGPMCTZ.mjs +4 -0
  120. package/dist/chunk-XZCFPKGO.mjs +2 -0
  121. package/dist/{chunk-QJ3TFJLQ.mjs → chunk-Y34NR5JL.mjs} +1 -1
  122. package/dist/{chunk-V5JRSGZF.mjs → chunk-YN37ZDLW.mjs} +1 -1
  123. package/dist/chunk-ZFGMJVJC.mjs +2 -0
  124. package/dist/{chunk-KH24LWAT.mjs → chunk-ZTHICSSF.mjs} +1 -1
  125. package/dist/cli.mjs +1 -1
  126. package/dist/server.mjs +1 -1
  127. package/dist/worker.mjs +1 -1
  128. package/kit/math.js +1 -1
  129. package/kit/runtime.js +12 -2
  130. package/kit/state.js +2 -0
  131. package/kit/ui.js +5 -1
  132. package/package.json +1 -1
  133. package/release.json +7 -7
  134. package/skill/SKILL.md +13 -13
  135. package/skill/references/building-blocks.md +1 -1
  136. package/skill/references/extensions.md +45 -9
  137. package/web/assets/{index-xP0uw3a0.css → index-FLb9jCfl.css} +1 -1
  138. package/web/assets/index-czjrXVjf.js +15 -0
  139. package/web/index.html +2 -2
  140. package/dist/chunk-46ACXOU5.mjs +0 -2
  141. package/dist/chunk-5DPABPBI.mjs +0 -2
  142. package/dist/chunk-5L26JUYA.mjs +0 -2
  143. package/dist/chunk-AEMVZYZQ.mjs +0 -166
  144. package/dist/chunk-ASAXY2DJ.mjs +0 -2
  145. package/dist/chunk-DAMVDXR3.mjs +0 -2
  146. package/dist/chunk-DLFZJJEE.mjs +0 -2
  147. package/dist/chunk-EKNHM3P4.mjs +0 -2
  148. package/dist/chunk-FCK6NXON.mjs +0 -3
  149. package/dist/chunk-FX42XU6J.mjs +0 -2
  150. package/dist/chunk-HATA2W7X.mjs +0 -2
  151. package/dist/chunk-JJNRIFND.mjs +0 -8
  152. package/dist/chunk-JL6R4FG4.mjs +0 -4
  153. package/dist/chunk-KUILYI7H.mjs +0 -4
  154. package/dist/chunk-NIW7F7LU.mjs +0 -4
  155. package/dist/chunk-OU3S466R.mjs +0 -20
  156. package/dist/chunk-QCEATQC4.mjs +0 -2
  157. package/dist/chunk-TDWJKOLN.mjs +0 -2
  158. package/dist/chunk-UGO5N3EI.mjs +0 -15
  159. package/dist/chunk-XMKHCUI6.mjs +0 -15
  160. package/dist/chunk-XQRUG4G3.mjs +0 -2
  161. package/dist/chunk-YPPJVDQI.mjs +0 -2
  162. package/dist/chunk-ZANMKAWS.mjs +0 -2
  163. package/web/assets/index-BHC5ZOMh.js +0 -15
  164. /package/dist/{chunk-N3DSBH5S.mjs → chunk-A55HN5OK.mjs} +0 -0
  165. /package/dist/{chunk-KNZJT4ET.mjs → chunk-QAIHRH3I.mjs} +0 -0
  166. /package/dist/{chunk-ZW2A6GBW.mjs → chunk-QR6A54KJ.mjs} +0 -0
  167. /package/dist/{chunk-74UW7QSL.mjs → chunk-UH4SIXTR.mjs} +0 -0
  168. /package/dist/{chunk-EKGYYOSP.mjs → chunk-W7XHE4CT.mjs} +0 -0
  169. /package/dist/{chunk-5MMN3N5J.mjs → chunk-YEY3RSFQ.mjs} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as H,c as X,e as ve}from"./chunk-N3DSBH5S.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Pe}from"node:crypto";import{existsSync as Ce,lstatSync as De,readFileSync as _,readdirSync as Me,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ke,parsePart as Ge,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as ot,OWN_SCOPE as it,PACK_FILE as ne,PACK_ID as he,readPackManifest as rt}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as at,PACKAGE_MANIFEST as I,WORKSPACE_MARK as ct,findWorkspace as lt,layoutOf as G,markerOf as ft,packageFolders as dt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),pt=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],mt=["at","edit","optional","min","max"],ut=["generated","attrs"],ht=["document","page"],wt=["document"],yt=["sizes","w","h","min","max","resize","fit","bare","consent"],y={w:12,h:24},bt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},gt=["key","label","type","options","default","required"],kt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],Ot=/^\d{4}-\d{2}-\d{2}$/,$t="settings",Et=["workspace","tables"],St=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,At=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Nt=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:At(n)}:s])),jt=["parts","text"],we=["kit.js","style.css","preview.svg"],M="template.html",zt=[I,M,...we],V=e=>[...new Set([...zt,...e])].sort(),Tt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,It=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Pe("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=De(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&_(s)}catch{return null}}var ce=new Map,vt=2e3;function _t(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(_(e)));return Date.now()-s>vt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=_t(o))}catch{}s.update(`${t}\0${f}
3
- `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},E=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},v=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ke(n).tag);function Pt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),E(n,mt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ge(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}St.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var Ct=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Dt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),E(e,ut,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(l){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,l.message))}return d.split(",").map(l=>l.trim().startsWith(":scope")?l.trim().replace(":scope",s):`${s} ${l.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)It.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let c=d=>{let a=t(d,"runtime.generated");return Ct(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(c),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var T=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Mt(e){return e===void 0?wt:((!Array.isArray(e)||e.length===0||!e.every(n=>ht.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Ft(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),E(e,yt,"card.");let n=a=>Array.isArray(a)&&a.length===2&&T(a[0],y.w)&&T(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let l=["w","h"].find(p=>e[p]!==void 0);l&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",l))}for(let a of["w","h"])e[a]!==void 0&&!T(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let l=e[a];if(l!==void 0){u(l)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),E(l,["w","h"],`card.${a}.`);for(let p of["w","h"])l[p]!==void 0&&!T(l[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=l}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,c=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([l,p])=>l<t.w||l>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let l={w:f,h:c}[a];l!==null&&!e.sizes&&(l<t[a]||l>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,l,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!bt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),e.consent!==void 0&&v(e.consent,"card.consent"),{sizes:e.sizes?e.sizes.map(([a,l])=>[a,l]):null,any:d,w:f,h:c,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1,...e.consent!==void 0?{consent:{zh:e.consent.zh,en:e.consent.en}}:{}}}var Lt=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&Ot.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Rt(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let c=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",c)),E(o,gt,`${c}.`),(typeof o.key!="string"||!kt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",c)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),v(o.label,`${c}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",c,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",c)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",c,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",c)),o.default!==void 0&&!Lt(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",c,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",c))});let t=n[$t];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Kt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Et.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Gt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Vt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)Tt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Ut(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))at.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});E(t,pt),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),v(t.name,"name"),v(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))Pt(w,$);let o=Dt(t.runtime,e),{kit:f,own:c}=Vt(t.assets,n);t.markdown!==void 0&&!jt.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Mt(t.places);Gt(d,t.parts);let a=Ft(t.card),l=Rt(t.settings,t.parts),p=Kt(t.needs),h=ye(n,M);return h&&ge(h,M),{id:e,match:Ze(e),parts:Nt(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:l,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...c])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(c))}}function Wt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Ut(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var P=()=>lt().root,Bt=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,x=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Jt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,x(s,me)]).filter(([,n])=>n.length>0)),Zt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),C=e=>{let n=Zt(e?.components?.packs);return{hidden:x(e?.components?.hidden,Bt),disabled:x(e?.components?.disabled,A),shown:x(e?.components?.shown,A),unlisted:x(e?.components?.unlisted,A),net:Jt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),qt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ft(e);return s?{value:n}:{problem:t?qt:B}}function ke(e){try{return L(_(G(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var On=(e=P())=>C(ke(e).value),Yt=["EPERM","EACCES","EBUSY","EROFS"];async function $n(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:c,pack:d,enabled:a}){let l=G(e).marker,p=await Le.readFile(l,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:ze,unlisted:Te}=C(h),g=u(h?.components)?h.components:{},Z=$(ze,t),q=$(Te,f),z={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};z.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(c!==void 0){let m={...u(g.net)?g.net:{}};c.length>0?m[n]=[...new Set(c)]:delete m[n],Object.keys(m).length>0?z.net=m:delete z.net}await He(l,`${JSON.stringify({...h??ct,components:z},null,2)}
2
+ import{a as H,c as X,e as ve}from"./chunk-A55HN5OK.mjs";ve();import{isUtf8 as _e}from"node:buffer";import{createHash as Pe}from"node:crypto";import{existsSync as Ce,lstatSync as De,readFileSync as _,readdirSync as Me,realpathSync as Q,statSync as Fe}from"node:fs";import Le from"node:fs/promises";import k from"node:path";import{isInstance as Re,parseCompound as Ke,parsePart as Ge,parseSelector as Ve,partOf as Ue}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as pe,NO_TEXT as We,PACKAGE_ID as A,PACKAGE_MARK as Be,SLOT as ee,inDocumentMenus as Je,instanceMatch as Ze,refusedInCopy as qe,settingState as Ye}from"../browser/shared/components/installed.mjs";import{writeAtomic as He}from"../browser/shared/files.mjs";import{attr as Xe,walk as Qe}from"../browser/shared/html-tree.mjs";import{HOST as me,NET as te,netHostsOf as et}from"../browser/shared/net-policy.mjs";import{inLanguage as tt,refusal as ue,said as i,saying as nt,told as st}from"../browser/shared/i18n/index.mjs";import{DEFAULT_PACK as ot,OWN_SCOPE as it,PACK_FILE as ne,PACK_ID as he,readPackManifest as rt}from"../browser/shared/pack-manifest.mjs";import{DEVICE_NAMES as at,PACKAGE_MANIFEST as I,WORKSPACE_MARK as ct,defaultWorkspace as lt,layoutOf as G,markerOf as ft,packageFolders as dt}from"../browser/shared/workspace.mjs";var se=1,oe=new Set(["code","state","sheets","tokens","dialogs","katex-styles","katex","katex-auto-render","math","d3","charts","tables"]),pt=["id","apiVersion","version","name","description","words","parts","runtime","assets","markdown","schema","places","card","settings","needs"],mt=["at","edit","optional","min","max"],ut=["generated","attrs"],ht=["document","page"],wt=["document"],yt=["sizes","w","h","min","max","resize","fit","bare","consent"],y={w:12,h:24},bt=["fixed","content"],ie={sizes:null,any:!1,w:4,h:null,min:{w:1,h:1},max:{...y},resize:!1,fit:"fixed",bare:!1},gt=["key","label","type","options","default","required"],kt=/^[a-z][a-zA-Z0-9]*$/,re=["text","number","select","date","switch","document"],Ot=/^\d{4}-\d{2}-\d{2}$/,$t="settings",Et=["workspace","tables"],St=["text","data","flow","none"],xt=/^[a-z][a-z0-9-]*$/,At=e=>`div[${ee}="${e}"], section[${ee}="${e}"]`,Nt=e=>Object.fromEntries(Object.entries(e).map(([n,s])=>[n,s.edit==="flow"?{...s,at:At(n)}:s])),jt=["parts","text"],we=["kit.js","style.css","preview.svg"],M="template.html",zt=[I,M,...we],V=e=>[...new Set([...zt,...e])].sort(),Tt=/^(?:[A-Za-z0-9_-][A-Za-z0-9._-]*\/)*[A-Za-z0-9_-][A-Za-z0-9._-]*\.[A-Za-z0-9]+$/,It=/^(?:doc-|data-doc-|data-ge-)|^data-block-id$/i,ae=256*1024,u=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),b=e=>typeof e=="string"&&e.trim()!=="",U=(e,n)=>e.id<n.id?-1:1,r=e=>{throw ue(e)},S=e=>{let n=Pe("sha256");return e(n),n.digest("hex").slice(0,16)};function j(e,n){let s=k.join(e,n);try{let t=De(s,{throwIfNoEntry:!1});if(!t)return null;if(!t.isSymbolicLink()&&!n.includes("/"))return s;let o=Q.native(s);return o.startsWith(Q.native(e)+k.sep)?o:null}catch{return null}}function ye(e,n){try{let s=j(e,n);return s&&_(s)}catch{return null}}var ce=new Map,vt=2e3;function _t(e){let{size:n,mtimeMs:s}=Fe(e),t=ce.get(e);if(t?.size===n&&t.time===s)return t.digest;let o=S(f=>f.update(_(e)));return Date.now()-s>vt&&ce.set(e,{size:n,time:s,digest:o}),o}var W=(e,n)=>S(s=>{for(let t of n){let o=j(e,t),f="none";try{o&&(f=_t(o))}catch{}s.update(`${t}\0${f}
3
+ `)}}),be=e=>e.toString("utf8").replace(/^\uFEFF/,""),ge=(e,n)=>{e.length>ae&&r(i("{0} \u6709 {1} KB\uFF0C\u800C\u6BCF\u4E00\u9875\u90FD\u5E26\u7740\u5B83\uFF0C\u6700\u591A {2} KB",n,Math.ceil(e.length/1024),ae/1024))},E=(e,n,s="")=>{for(let t of Object.keys(e))n.includes(t)||r(i("{0} \u4E0D\u662F\u81EA\u5B9A\u4E49\u5757\u7684\u6E05\u5355\u80FD\u5199\u7684\u5B57\u6BB5",`${s}${t}`))},le=(e,n)=>{for(let s of n)e[s]===void 0&&r(i("\u7F3A\u5C11 {0}",s))},v=(e,n)=>{(!u(e)||!b(e.zh)||!b(e.en)||Object.keys(e).length!==2)&&r(i("{0} \u8981\u5199\u6210 { zh, en } \u4E24\u79CD\u8BED\u8A00\u7684\u6587\u5B57",n))},F=e=>e.split(",").map(n=>n.split(">").at(-1).trim()).filter(n=>n!=="*").map(n=>Ke(n).tag);function Pt(e,n){let s=`parts.${e}`;if(u(n)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",s)),E(n,mt,`${s}.`),n.edit==="flow"){xt.test(e)||r(i("{0} \u662F\u63D2\u69FD\uFF0C\u540D\u5B57\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",s)),n.at!==void 0&&r(i('{0} \u662F\u63D2\u69FD\uFF0C\u7531 data-doc-slot="{1}" \u6807\u51FA\uFF0C\u4E0D\u5199 at',s,e)),(n.min!==void 0||n.max!==void 0)&&r(i("{0} \u662F\u63D2\u69FD\uFF0C\u4E00\u4E2A\u5B9E\u4F8B\u91CC\u53EA\u6709\u4E00\u4E2A\uFF0C\u4E0D\u5199 min\u3001max",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));return}b(n.at)||r(i("\u7F3A\u5C11 {0}",`${s}.at`));try{Ge(n.at)}catch(t){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",`${s}.at`,t.message))}St.includes(n.edit)||r(i("{0} \u7684 edit \u53EA\u80FD\u662F text\u3001data\u3001flow \u6216 none",s)),n.optional!==void 0&&typeof n.optional!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`${s}.optional`));for(let t of["min","max"])n[t]!==void 0&&!(Number.isInteger(n[t])&&n[t]>=0)&&r(i("{0} \u8981\u5199\u6210\u4E0D\u5C0F\u4E8E 0 \u7684\u6574\u6570",`${s}.${t}`));if(n.min>n.max&&r(i("{0} \u7684 min \u6BD4 max \u5927\uFF0C\u6CA1\u6709\u5B9E\u4F8B\u80FD\u6EE1\u8DB3",s)),n.edit==="text")for(let t of F(n.at))We.has(t)&&r(i("{0} \u4E0D\u80FD\u6309\u6587\u5B57\u7F16\u8F91\uFF1A<{1}> \u4E0D\u662F\u80FD\u6253\u5B57\u7684\u6587\u5B57",s,t))}var Ct=e=>e.split(",").some(n=>n.split(">").every(s=>[":scope","*"].includes(s.trim())));function Dt(e,n){if(e===void 0)return null;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime")),E(e,ut,"runtime.");let s=`[${pe}="${n}"]`,t=(d,a)=>{try{if(!b(d))throw new Error("no selector");Ve(d)}catch(l){r(i("{0} \u5199\u9519\u4E86\uFF1A{1}",a,l.message))}return d.split(",").map(l=>l.trim().startsWith(":scope")?l.trim().replace(":scope",s):`${s} ${l.trim()}`).join(", ")},{generated:o=[],attrs:f={}}=e;Array.isArray(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.generated")),u(f)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","runtime.attrs"));for(let d of Object.values(f)){(!Array.isArray(d)||!d.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","runtime.attrs"));for(let a of d)It.test(a)&&r(i("{0} \u662F Gallery \u81EA\u5DF1\u7684\u540D\u5B57\uFF0C\u81EA\u5B9A\u4E49\u5757\u4E0D\u80FD\u7528",a))}let c=d=>{let a=t(d,"runtime.generated");return Ct(d)&&r(i("{0} \u7684 {1} \u662F\u6574\u4E2A\u5B9E\u4F8B\uFF0C\u800C\u8FD9\u91CC\u53EA\u5199\u5B83\u751F\u6210\u7684\u8282\u70B9","runtime.generated",d)),a};return{generated:o.map(c),attrs:Object.fromEntries(Object.entries(f).map(([d,a])=>[t(d,"runtime.attrs"),a]))}}var T=(e,n)=>Number.isInteger(e)&&e>=1&&e<=n,O=e=>e.find((n,s)=>e.indexOf(n)!==s);function Mt(e){return e===void 0?wt:((!Array.isArray(e)||e.length===0||!e.every(n=>ht.includes(n)))&&r(i('places \u8981\u5199\u6210 document\u3001page \u4E2D\u7684\u4E00\u4E2A\u6216\u4E24\u4E2A\uFF0C\u5982 ["document"]')),O(e)&&r(i("places \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e])}function Ft(e){if(e===void 0)return ie;u(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","card")),E(e,yt,"card.");let n=a=>Array.isArray(a)&&a.length===2&&T(a[0],y.w)&&T(a[1],y.h);if(e.sizes!==void 0){(!Array.isArray(e.sizes)||e.sizes.length===0||!e.sizes.every(n))&&r(i("card.sizes \u8981\u5199\u6210 [\u5BBD, \u9AD8] \u7684\u4E00\u4E32\uFF0C\u5BBD 1 \u5230 {0} \u683C\uFF0C\u9AD8 1 \u5230 {1} \u683C",y.w,y.h));let a=O(e.sizes.map(p=>p.join("x")));a&&r(i("card.sizes \u91CC {0} \u5199\u4E86\u4E24\u6B21",a));let l=["w","h"].find(p=>e[p]!==void 0);l&&r(i("\u5199\u4E86 card.sizes\uFF0C\u5C31\u4E0D\u518D\u5199 card.{0}\uFF1A\u7B2C\u4E00\u79CD\u5927\u5C0F\u662F\u9ED8\u8BA4\u7684",l))}for(let a of["w","h"])e[a]!==void 0&&!T(e[a],y[a])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}`,y[a]));let s={};for(let a of["min","max"]){let l=e[a];if(l!==void 0){u(l)||r(i("{0} \u8981\u5199\u6210 { w, h }\uFF0C\u5355\u4F4D\u662F\u683C",`card.${a}`)),E(l,["w","h"],`card.${a}.`);for(let p of["w","h"])l[p]!==void 0&&!T(l[p],y[p])&&r(i("{0} \u8981\u5199\u6210 1 \u5230 {1} \u7684\u6574\u6570",`card.${a}.${p}`,y[p]));s[a]=l}}let t={w:s.min?.w??1,h:s.min?.h??1},o={w:s.max?.w??y.w,h:s.max?.h??y.h},f=e.sizes?e.sizes[0][0]:e.w??ie.w,c=e.sizes?e.sizes[0][1]:e.h??null,d=!!e.sizes&&(e.min!==void 0||e.max!==void 0);if(d){let a=e.sizes.find(([l,p])=>l<t.w||l>o.w||p<t.h||p>o.h);a&&r(i("card.sizes \u91CC {0} \u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4",a.join("x")))}for(let a of["w","h"]){t[a]>o[a]&&r(i("card.min.{0} \u6BD4 card.max.{0} \u5927",a));let l={w:f,h:c}[a];l!==null&&!e.sizes&&(l<t[a]||l>o[a])&&r(i("\u9ED8\u8BA4\u7684 card.{0} \u662F {1}\uFF0C\u4E0D\u5728 card.min \u5230 card.max \u4E4B\u95F4\uFF08{2} \u5230 {3}\uFF09",a,l,t[a],o[a]))}for(let a of["resize","bare"])e[a]!==void 0&&typeof e[a]!="boolean"&&r(i("{0} \u8981\u5199\u6210 true \u6216 false",`card.${a}`));return e.fit!==void 0&&!bt.includes(e.fit)&&r(i("card.fit \u53EA\u80FD\u662F fixed \u6216 content")),e.consent!==void 0&&v(e.consent,"card.consent"),{sizes:e.sizes?e.sizes.map(([a,l])=>[a,l]):null,any:d,w:f,h:c,min:t,max:o,resize:e.resize??!1,fit:e.fit??"fixed",bare:e.bare??!1,...e.consent!==void 0?{consent:{zh:e.consent.zh,en:e.consent.en}}:{}}}var Lt=(e,{type:n,options:s})=>({text:typeof e=="string",number:typeof e=="number"&&Number.isFinite(e),select:s?.includes(e),date:typeof e=="string"&&Ot.test(e),switch:typeof e=="boolean",document:typeof e=="string"})[n];function Rt(e,n){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u5B57\u6BB5","settings"));let s=[];e.forEach((o,f)=>{let c=`settings[${f}]`;u(o)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868",c)),E(o,gt,`${c}.`),(typeof o.key!="string"||!kt.test(o.key))&&r(i("{0} \u7684 key \u4EE5\u5C0F\u5199\u5B57\u6BCD\u5F00\u5934\uFF0C\u53EA\u7528\u5B57\u6BCD\u548C\u6570\u5B57\uFF08\u5982 city\u3001startDate\uFF09",c)),s.includes(o.key)&&r(i("settings \u91CC key {0} \u5199\u4E86\u4E24\u6B21",o.key)),s.push(o.key),v(o.label,`${c}.label`),re.includes(o.type)||r(i("{0} \u7684 type \u53EA\u80FD\u662F {1}",c,re.join(", "))),o.type==="select"?((!Array.isArray(o.options)||o.options.length===0||!o.options.every(b))&&r(i("{0} \u662F select\uFF0C\u8981\u6709 options\uFF1A\u4E00\u4E32\u6587\u5B57",c)),O(o.options)&&r(i("{0} \u7684 options \u91CC {1} \u5199\u4E86\u4E24\u6B21",c,O(o.options)))):o.options!==void 0&&r(i("{0} \u4E0D\u662F select\uFF0C\u4E0D\u5199 options",c)),o.default!==void 0&&!Lt(o.default,o)&&r(i("{0} \u7684 default \u548C\u5B83\u7684 type {1} \u4E0D\u7B26",c,o.type)),o.required!==void 0&&typeof o.required!="boolean"&&r(i("{0} \u7684 required \u8981\u5199 true \u6216 false",c))});let t=n[$t];return e.length>0&&!(t?.edit==="data"&&F(t.at).every(o=>o==="script")&&F(t.at).length>0)&&r(i('\u5199\u4E86 settings\uFF0Cparts \u91CC\u5C31\u8981\u6709\u4E00\u4E2A\u540D\u4E3A settings\u3001edit \u4E3A data \u7684\u90E8\u5206\uFF0C\u5B83\u662F\u4E00\u4E2A <script type="application/json">\uFF0C\u5B58\u5361\u7247\u8BBE\u7F6E\u7684\u503C')),e.map(o=>({...o}))}function Kt(e){if(e===void 0)return[];Array.isArray(e)||r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","needs"));for(let n of e)typeof n=="string"&&(Et.includes(n)||n.startsWith(te)&&me.test(n.slice(te.length)))||r(i("needs \u91CC\u7684 {0} \u4E0D\u8BA4\u8BC6\uFF1A\u53EA\u8BA4 workspace\u3001tables \u548C net:<\u57DF\u540D>\uFF08\u5C0F\u5199\u7684\u4E3B\u673A\u540D\uFF0C\u4E0D\u5E26\u7AEF\u53E3\u548C\u8DEF\u5F84\uFF0C\u53EF\u4EE5\u4EE5 *. \u5F00\u5934\uFF09",typeof n=="string"?n:JSON.stringify(n)));return O(e)&&r(i("needs \u91CC {0} \u5199\u4E86\u4E24\u6B21",O(e))),[...e]}function Gt(e,n){if(!e.includes("page"))return;let s=Object.entries(n).find(([,t])=>t.edit==="flow");s&&r(i("places \u91CC\u6709 page\uFF0C\u5C31\u4E0D\u80FD\u6709\u63D2\u69FD\uFF1A{0} \u7684 edit \u662F flow\uFF0C\u63D2\u69FD\u653E\u7684\u662F\u6587\u6863\u7684\u5757\uFF0C\u81EA\u5B9A\u4E49\u9875\u4E0A\u6CA1\u6709",`parts.${s[0]}`))}function Vt(e,n){if(e===void 0)return{kit:[],own:[]};(!Array.isArray(e)||!e.every(b))&&r(i("{0} \u8981\u5199\u6210\u4E00\u4E32\u6587\u5B57","assets"));let s=e.filter(t=>!oe.has(t));for(let t of s)Tt.test(t)||r(i("assets \u91CC\u7684 {0} \u65E2\u4E0D\u662F\u5957\u4EF6\u7684\u8D44\u6E90\uFF0C\u4E5F\u4E0D\u662F\u5757\u7684\u6587\u4EF6\u5939\u91CC\u7684\u6587\u4EF6",t)),j(n,t)||r(i("assets \u5199\u4E86 {0}\uFF0C\u5757\u7684\u6587\u4EF6\u5939\u91CC\u6CA1\u6709\u8FD9\u4E2A\u6587\u4EF6",t));return{kit:e.filter(t=>oe.has(t)),own:s}}function Ut(e,n,s){let t;try{t=JSON.parse(s)}catch(w){r(i("component.json \u4E0D\u662F JSON\uFF1A{0}",w.message))}u(t)||r(i("component.json \u5199\u7684\u4E0D\u662F\u4E00\u4E2A\u5BF9\u8C61")),A.test(e)||r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A\u8303\u56F4\u548C\u540D\u5B57\u90FD\u53EA\u7528\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26",e));for(let w of e.split("/"))at.has(w)&&r(i("{0} \u4E0D\u80FD\u505A\u81EA\u5B9A\u4E49\u5757\u7684 id\uFF1A{1} \u662F Windows \u7559\u7ED9\u8BBE\u5907\u7684\u540D\u5B57",e,w));if(t.id!==e&&r(i("\u6E05\u5355\u7684 id \u662F {0}\uFF0C\u548C\u5B83\u7684\u6587\u4EF6\u5939 {1} \u4E0D\u4E00\u6837",String(t.id),e)),le(t,["apiVersion"]),(!Number.isInteger(t.apiVersion)||t.apiVersion<1)&&r(i("apiVersion \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570")),t.apiVersion!==se)throw ue(i("\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u5757\u8981 apiVersion {0}\uFF0C\u8FD9\u4E00\u7248 Gallery \u53EA\u652F\u6301 {1}",t.apiVersion,se),{disabled:!0,version:b(t.version)?t.version:null});E(t,pt),le(t,["version","name","description","parts"]),b(t.version)||r(i("{0} \u8981\u5199\u6210\u6587\u5B57","version")),v(t.name,"name"),v(t.description,"description"),t.words!==void 0&&typeof t.words!="string"&&r(i("{0} \u8981\u5199\u6210\u6587\u5B57","words")),u(t.parts)||r(i("{0} \u8981\u5199\u6210\u4E00\u5F20\u8868","parts"));for(let[w,$]of Object.entries(t.parts))Pt(w,$);let o=Dt(t.runtime,e),{kit:f,own:c}=Vt(t.assets,n);t.markdown!==void 0&&!jt.includes(t.markdown)&&r(i("markdown \u53EA\u80FD\u662F parts \u6216 text")),t.schema!==void 0&&!(Number.isInteger(t.schema)&&t.schema>=1)&&r(i("schema \u8981\u5199\u6210\u4E00\u4E2A\u6B63\u6574\u6570"));let d=Mt(t.places);Gt(d,t.parts);let a=Ft(t.card),l=Rt(t.settings,t.parts),p=Kt(t.needs),h=ye(n,M);return h&&ge(h,M),{id:e,match:Ze(e),parts:Nt(t.parts),...o?{runtime:o}:{},...t.schema!==void 0?{schema:t.schema}:{},apiVersion:t.apiVersion,version:t.version,name:t.name,description:t.description,words:t.words??"",assets:f,markdown:t.markdown??"parts",places:d,card:a,settings:l,needs:p,files:[...new Set([...we.filter(w=>j(n,w)),...c])],template:h&&be(h),folder:n,definition:S(w=>w.update(s)),stamp:W(n,V(c))}}function Wt(e,n){try{let s=ye(n,I);return s||r(i("\u8BFB\u4E0D\u51FA component.json")),_e(s)||r(i("{0} \u4E0D\u662F UTF-8 \u7F16\u7801\uFF1A\u8BF7\u5B58\u6210 UTF-8",I)),ge(s,I),Ut(e,n,be(s))}catch(s){let t=nt(s),o=S(f=>f.update(`${W(n,V([]))} ${JSON.stringify(t)}`));return{id:e.toLowerCase(),stamp:o,problem:t,disabled:s.disabled===!0,version:s.version??null}}}var P=()=>lt(),Bt=/^[a-z0-9][a-z0-9-]*(?:\/[a-z0-9][a-z0-9-]*)?$/,x=(e,n)=>[...new Set(Array.isArray(e)?e.filter(s=>typeof s=="string"&&n.test(s)):[])],Jt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n])=>A.test(n)).map(([n,s])=>[n,x(s,me)]).filter(([,n])=>n.length>0)),Zt=e=>Object.fromEntries(Object.entries(u(e)?e:{}).filter(([n,s])=>he.test(n)&&typeof s?.enabled=="boolean").map(([n,s])=>[n,s.enabled])),C=e=>{let n=Zt(e?.components?.packs);return{hidden:x(e?.components?.hidden,Bt),disabled:x(e?.components?.disabled,A),shown:x(e?.components?.shown,A),unlisted:x(e?.components?.unlisted,A),net:Jt(e?.components?.net),packs:n,packsOff:Object.keys(n).filter(s=>n[s]===!1).sort()}},B=i("gallery.json \u8BFB\u4E0D\u51FA\u6765\uFF1A\u6539\u597D\u8FD9\u4E2A\u6587\u4EF6\u540E\u518D\u8BD5"),qt=i("gallery.json \u4E0D\u662F Gallery \u7684\u6587\u4EF6");function L(e){if(e===null)return{value:null};let{value:n,ours:s,reads:t}=ft(e);return s?{value:n}:{problem:t?qt:B}}function ke(e){try{return L(_(G(e).marker,"utf8"))}catch(n){return n.code==="ENOENT"?L(null):{problem:B}}}var On=(e=P())=>C(ke(e).value),Yt=["EPERM","EACCES","EBUSY","EROFS"];async function $n(e,{id:n,hidden:s,shown:t,disabled:o,unlisted:f,net:c,pack:d,enabled:a}){let l=G(e).marker,p=await Le.readFile(l,"utf8").catch(m=>{if(m.code==="ENOENT")return null;r(B)}),{value:h,problem:w}=L(p);w&&r(w);let $=(m,Y)=>Y===void 0?m:Y?[...new Set([...m,n])]:m.filter(Ie=>Ie!==n),{hidden:Ne,disabled:je,shown:ze,unlisted:Te}=C(h),g=u(h?.components)?h.components:{},Z=$(ze,t),q=$(Te,f),z={...g,hidden:$(Ne,s),disabled:$(je,o),...Z.length>0||Object.hasOwn(g,"shown")?{shown:Z}:{},...q.length>0||Object.hasOwn(g,"unlisted")?{unlisted:q}:{}};if(d!==void 0){let m=u(g.packs)?g.packs:{};z.packs={...m,[d]:{...u(m[d])?m[d]:{},enabled:a===!0}}}if(c!==void 0){let m={...u(g.net)?g.net:{}};c.length>0?m[n]=[...new Set(c)]:delete m[n],Object.keys(m).length>0?z.net=m:delete z.net}await He(l,`${JSON.stringify({...h??ct,components:z},null,2)}
4
4
  `,{expect:p}).catch(m=>{throw Yt.includes(m.code)&&r(i("gallery.json \u5199\u4E0D\u8FDB\u53BB\uFF1A\u53EF\u80FD\u662F\u53EA\u8BFB\u7684\uFF0C\u6216\u88AB\u522B\u7684\u7A0B\u5E8F\u5360\u7740")),m})||r(i("gallery.json \u521A\u521A\u88AB\u6539\u8FC7\uFF1A\u518D\u8BD5\u4E00\u6B21"))}var Ht=e=>({...e,off:!0,disabled:!0,problem:i("\u5728\u8BBE\u7F6E\u91CC\u505C\u7528\u4E86"),stamp:S(n=>n.update(`${e.stamp} off`))}),D=C(null),Xt=({packages:e,problems:n,settings:s=D,packs:t=new Map})=>S(o=>{for(let{id:f,stamp:c}of[...e.values(),...n.values()].sort(U))o.update(`${f} ${c}
5
5
  `);o.update(`hidden ${[...s.hidden].sort().join(" ")}
6
6
  `),o.update(`shown ${[...s.shown].sort().join(" ")}
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{a as je}from"./chunk-5MMN3N5J.mjs";import{c as $e}from"./chunk-EKGYYOSP.mjs";import{a as p,c as S,e as N}from"./chunk-5L7RYZCL.mjs";var T=S((Tr,He)=>{"use strict";var Ve=["nodebuffer","arraybuffer","fragments"],ze=typeof Blob<"u";ze&&Ve.push("blob");He.exports={BINARY_TYPES:Ve,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ze,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var X=S((kr,re)=>{"use strict";var{EMPTY_BUFFER:Qt}=T(),xe=Buffer[Symbol.species];function Jt(t,e){if(t.length===0)return Qt;if(t.length===1)return t[0];let s=Buffer.allocUnsafe(e),r=0;for(let i=0;i<t.length;i++){let n=t[i];s.set(n,r),r+=n.length}return r<e?new xe(s.buffer,s.byteOffset,r):s}function Ye(t,e,s,r,i){for(let n=0;n<i;n++)s[r+n]=t[n]^e[n&3]}function Ke(t,e){for(let s=0;s<t.length;s++)t[s]^=e[s&3]}function es(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Se(t){if(Se.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new xe(t):ArrayBuffer.isView(t)?e=new xe(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Se.readOnly=!1),e}re.exports={concat:Jt,mask:Ye,toArrayBuffer:es,toBuffer:Se,unmask:Ke};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=p("bufferutil");re.exports.mask=function(e,s,r,i,n){n<48?Ye(e,s,r,i,n):t.mask(e,s,r,i,n)},re.exports.unmask=function(e,s){e.length<32?Ke(e,s):t.unmask(e,s)}}catch{}});var Qe=S((Cr,Ze)=>{"use strict";var Xe=Symbol("kDone"),Ee=Symbol("kRun"),ve=class{constructor(e){this[Xe]=()=>{this.pending--,this[Ee]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Ee]()}[Ee](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Xe])}}};Ze.exports=ve});var G=S((Lr,st)=>{"use strict";var Z=p("zlib"),Je=X(),ts=Qe(),{kStatusCode:et}=T(),ss=Buffer[Symbol.species],rs=Buffer.from([0,0,255,255]),ne=Symbol("permessage-deflate"),k=Symbol("total-length"),W=Symbol("callback"),P=Symbol("buffers"),q=Symbol("error"),ie,be=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!ie){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ie=new ts(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[W];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let s=this._options,r=e.find(i=>!(s.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(s.serverMaxWindowBits===!1||typeof s.serverMaxWindowBits=="number"&&s.serverMaxWindowBits>i.server_max_window_bits)||typeof s.clientMaxWindowBits=="number"&&(typeof i.client_max_window_bits=="number"?s.clientMaxWindowBits>i.client_max_window_bits:!i.client_max_window_bits)));if(!r)throw new Error("None of the extension offers can be accepted");return s.serverNoContextTakeover&&(r.server_no_context_takeover=!0),s.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof s.serverMaxWindowBits=="number"&&(r.server_max_window_bits=s.serverMaxWindowBits),typeof s.clientMaxWindowBits=="number"?r.client_max_window_bits=s.clientMaxWindowBits:(r.client_max_window_bits===!0||s.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(e){let s=e[0];if(this._options.clientNoContextTakeover===!1&&s.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!s.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(s.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&s.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return s}normalizeParams(e){return e.forEach(s=>{Object.keys(s).forEach(r=>{let i=s[r];if(i.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(i=i[0],r==="client_max_window_bits"){if(i!==!0){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else if(r==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else throw new Error(`Unknown parameter "${r}"`);s[r]=i})}),e}decompress(e,s,r){ie.add(i=>{this._decompress(e,s,(n,o)=>{i(),r(n,o)})})}compress(e,s,r){ie.add(i=>{this._compress(e,s,(n,o)=>{i(),r(n,o)})})}_decompress(e,s,r){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=Z.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[ne]=this,this._inflate[k]=0,this._inflate[P]=[],this._inflate.on("error",ns),this._inflate.on("data",tt)}this._inflate[W]=r,this._inflate.write(e),s&&this._inflate.write(rs),this._inflate.flush(()=>{let n=this._inflate[q];if(n){this._inflate.close(),this._inflate=null,r(n);return}let o=Je.concat(this._inflate[P],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[P]=[],s&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),r(null,o)})}_compress(e,s,r){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=Z.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[P]=[],this._deflate.on("data",is)}this._deflate[W]=r,this._deflate.write(e),this._deflate.flush(Z.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Je.concat(this._deflate[P],this._deflate[k]);s&&(n=new ss(n.buffer,n.byteOffset,n.length-4)),this._deflate[W]=null,this._deflate[k]=0,this._deflate[P]=[],s&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),r(null,n)})}};st.exports=be;function is(t){this[P].push(t),this[k]+=t.length}function tt(t){if(this[k]+=t.length,this[ne]._maxPayload<1||this[k]<=this[ne]._maxPayload){this[P].push(t);return}this[q]=new RangeError("Max payload size exceeded"),this[q].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[q][et]=1009,this.removeListener("data",tt),this.reset()}function ns(t){if(this[ne]._inflate=null,this[q]){this[W](this[q]);return}t[et]=1007,this[W](t)}});var $=S((Nr,oe)=>{"use strict";var{isUtf8:rt}=p("buffer"),{hasBlob:os}=T(),as=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function fs(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function we(t){let e=t.length,s=0;for(;s<e;)if((t[s]&128)===0)s++;else if((t[s]&224)===192){if(s+1===e||(t[s+1]&192)!==128||(t[s]&254)===192)return!1;s+=2}else if((t[s]&240)===224){if(s+2>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||t[s]===224&&(t[s+1]&224)===128||t[s]===237&&(t[s+1]&224)===160)return!1;s+=3}else if((t[s]&248)===240){if(s+3>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||(t[s+3]&192)!==128||t[s]===240&&(t[s+1]&240)===128||t[s]===244&&t[s+1]>143||t[s]>244)return!1;s+=4}else return!1;return!0}function ls(t){return os&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}oe.exports={isBlob:ls,isValidStatusCode:fs,isValidUTF8:we,tokenChars:as};if(rt)oe.exports.isValidUTF8=function(t){return t.length<24?we(t):rt(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=p("utf-8-validate");oe.exports.isValidUTF8=function(e){return e.length<32?we(e):t(e)}}catch{}});var Le=S((Pr,ht)=>{"use strict";var{Writable:hs}=p("stream"),it=G(),{BINARY_TYPES:cs,EMPTY_BUFFER:nt,kStatusCode:us,kWebSocket:ds}=T(),{concat:Oe,toArrayBuffer:_s,unmask:ms}=X(),{isValidStatusCode:ps,isValidUTF8:ot}=$(),ae=Buffer[Symbol.species],v=0,at=1,ft=2,lt=3,Te=4,ke=5,fe=6,Ce=class extends hs{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||cs[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[ds]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,s,r){if(this._opcode===8&&this._state==v)return r();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){r(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e),new ae(r.buffer,r.byteOffset,e)}let s=Buffer.allocUnsafe(e);do{let r=this._buffers[0],i=s.length-e;e>=r.length?s.set(this._buffers.shift(),i):(s.set(new Uint8Array(r.buffer,r.byteOffset,e),i),this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return s}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case at:this.getPayloadLength16(e);break;case ft:this.getPayloadLength64(e);break;case lt:this.getMask();break;case Te:this.getData(e);break;case ke:case fe:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let s=this.consume(2);if((s[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let r=(s[0]&64)===64;if(r&&!this._extensions[it.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(s[0]&128)===128,this._opcode=s[0]&15,this._payloadLength=s[1]&127,this._opcode===0){if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(s[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=at:this._payloadLength===127?this._state=ft:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let s=this.consume(8),r=s.readUInt32BE(0);if(r>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=r*Math.pow(2,32)+s.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let s=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(s);return}this._masked?this._state=lt:this._state=Te}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Te}getData(e){let s=nt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}s=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&ms(s,this._mask)}if(this._opcode>7){this.controlMessage(s,e);return}if(this._maxFragments>0&&++this._numFragments>this._maxFragments){let r=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(r);return}if(this._compressed){this._state=ke,this.decompress(s,e);return}s.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(s)),this.dataMessage(e)}decompress(e,s){this._extensions[it.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return s(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");s(o);return}this._fragments.push(n)}this.dataMessage(s),this._state===v&&this.startLoop(s)})}dataMessage(e){if(!this._fin){this._state=v;return}let s=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=Oe(r,s):this._binaryType==="arraybuffer"?i=_s(Oe(r,s)):this._binaryType==="blob"?i=new Blob(r):i=r,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=v):(this._state=fe,setImmediate(()=>{this.emit("message",i,!0),this._state=v,this.startLoop(e)}))}else{let i=Oe(r,s);if(!this._skipUTF8Validation&&!ot(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===ke||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=v):(this._state=fe,setImmediate(()=>{this.emit("message",i,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,s){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,nt),this.end();else{let r=e.readUInt16BE(0);if(!ps(r)){let n=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");s(n);return}let i=new ae(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ot(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");s(n);return}this._loop=!1,this.emit("conclude",r,i),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=fe,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(s)}))}createError(e,s,r,i,n){this._loop=!1,this._errored=!0;let o=new e(r?`Invalid WebSocket frame: ${s}`:s);return Error.captureStackTrace(o,this.createError),o.code=n,o[us]=i,o}};ht.exports=Ce});var Be=S((Rr,dt)=>{"use strict";var{Duplex:Br}=p("stream"),{randomFillSync:gs}=p("crypto"),{types:{isUint8Array:ys}}=p("util"),ct=G(),{EMPTY_BUFFER:xs,kWebSocket:Ss,NOOP:Es}=T(),{isBlob:j,isValidStatusCode:vs}=$(),{mask:ut,toBuffer:R}=X(),b=Symbol("kByteLength"),bs=Buffer.alloc(4),le=8*1024,U,V=le,w=0,ws=1,Os=2,Ne=class t{constructor(e,s,r){this._extensions=s||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=w,this.onerror=Es,this[Ss]=void 0}static frame(e,s){let r,i=!1,n=2,o=!1;s.mask&&(r=s.maskBuffer||bs,s.generateMask?s.generateMask(r):(V===le&&(U===void 0&&(U=Buffer.alloc(le)),gs(U,0,le),V=0),r[0]=U[V++],r[1]=U[V++],r[2]=U[V++],r[3]=U[V++]),o=(r[0]|r[1]|r[2]|r[3])===0,n=6);let a;typeof e=="string"?(!s.mask||o)&&s[b]!==void 0?a=s[b]:(e=Buffer.from(e),a=e.length):(a=e.length,i=s.mask&&s.readOnly&&!o);let l=a;a>=65536?(n+=8,l=127):a>125&&(n+=2,l=126);let f=Buffer.allocUnsafe(i?a+n:n);return f[0]=s.fin?s.opcode|128:s.opcode,s.rsv1&&(f[0]|=64),f[1]=l,l===126?f.writeUInt16BE(a,2):l===127&&(f[2]=f[3]=0,f.writeUIntBE(a,4,6)),s.mask?(f[1]|=128,f[n-4]=r[0],f[n-3]=r[1],f[n-2]=r[2],f[n-1]=r[3],o?[f,e]:i?(ut(e,r,f,n,a),[f]):(ut(e,r,e,0,a),[f,e])):[f,e]}close(e,s,r,i){let n;if(e===void 0)n=xs;else{if(typeof e!="number"||!vs(e))throw new TypeError("First argument must be a valid error code number");if(s===void 0||!s.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let a=Buffer.byteLength(s);if(a>123)throw new RangeError("The message must not be greater than 123 bytes");if(n=Buffer.allocUnsafe(2+a),n.writeUInt16BE(e,0),typeof s=="string")n.write(s,2);else if(ys(s))n.set(s,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==w?this.enqueue([this.dispatch,n,!1,o,i]):this.sendFrame(t.frame(n,o),i)}ping(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):j(e)?(i=e.size,n=!1):(e=R(e),i=e.length,n=R.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}pong(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):j(e)?(i=e.size,n=!1):(e=R(e),i=e.length,n=R.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}send(e,s,r){let i=this._extensions[ct.extensionName],n=s.binary?2:1,o=s.compress,a,l;typeof e=="string"?(a=Buffer.byteLength(e),l=!1):j(e)?(a=e.size,l=!1):(e=R(e),a=e.length,l=R.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=a>=i._threshold),this._compress=o):(o=!1,n=0),s.fin&&(this._firstFragment=!0);let f={[b]:a,fin:s.fin,generateMask:this._generateMask,mask:s.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,this._compress,f,r]):this.getBlobData(e,this._compress,f,r):this._state!==w?this.enqueue([this.dispatch,e,this._compress,f,r]):this.dispatch(e,this._compress,f,r)}getBlobData(e,s,r,i){this._bufferedBytes+=r[b],this._state=Os,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Pe,this,a,i);return}this._bufferedBytes-=r[b];let o=R(n);s?this.dispatch(o,s,r,i):(this._state=w,this.sendFrame(t.frame(o,r),i),this.dequeue())}).catch(n=>{process.nextTick(Ts,this,n,i)})}dispatch(e,s,r,i){if(!s){this.sendFrame(t.frame(e,r),i);return}let n=this._extensions[ct.extensionName];this._bufferedBytes+=r[b],this._state=ws,n.compress(e,r.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Pe(this,l,i);return}this._bufferedBytes-=r[b],this._state=w,r.readOnly=!1,this.sendFrame(t.frame(a,r),i),this.dequeue()})}dequeue(){for(;this._state===w&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,s){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],s),this._socket.uncork()):this._socket.write(e[0],s)}};dt.exports=Ne;function Pe(t,e,s){typeof s=="function"&&s(e);for(let r=0;r<t._queue.length;r++){let i=t._queue[r],n=i[i.length-1];typeof n=="function"&&n(e)}}function Ts(t,e,s){Pe(t,e,s),t.onerror(e)}});var vt=S((Ur,Et)=>{"use strict";var{kForOnEventAttribute:Q,kListener:Re}=T(),_t=Symbol("kCode"),mt=Symbol("kData"),pt=Symbol("kError"),gt=Symbol("kMessage"),yt=Symbol("kReason"),z=Symbol("kTarget"),xt=Symbol("kType"),St=Symbol("kWasClean"),C=class{constructor(e){this[z]=null,this[xt]=e}get target(){return this[z]}get type(){return this[xt]}};Object.defineProperty(C.prototype,"target",{enumerable:!0});Object.defineProperty(C.prototype,"type",{enumerable:!0});var I=class extends C{constructor(e,s={}){super(e),this[_t]=s.code===void 0?0:s.code,this[yt]=s.reason===void 0?"":s.reason,this[St]=s.wasClean===void 0?!1:s.wasClean}get code(){return this[_t]}get reason(){return this[yt]}get wasClean(){return this[St]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var H=class extends C{constructor(e,s={}){super(e),this[pt]=s.error===void 0?null:s.error,this[gt]=s.message===void 0?"":s.message}get error(){return this[pt]}get message(){return this[gt]}};Object.defineProperty(H.prototype,"error",{enumerable:!0});Object.defineProperty(H.prototype,"message",{enumerable:!0});var J=class extends C{constructor(e,s={}){super(e),this[mt]=s.data===void 0?null:s.data}get data(){return this[mt]}};Object.defineProperty(J.prototype,"data",{enumerable:!0});var ks={addEventListener(t,e,s={}){for(let i of this.listeners(t))if(!s[Q]&&i[Re]===e&&!i[Q])return;let r;if(t==="message")r=function(n,o){let a=new J("message",{data:o?n:n.toString()});a[z]=this,he(e,this,a)};else if(t==="close")r=function(n,o){let a=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[z]=this,he(e,this,a)};else if(t==="error")r=function(n){let o=new H("error",{error:n,message:n.message});o[z]=this,he(e,this,o)};else if(t==="open")r=function(){let n=new C("open");n[z]=this,he(e,this,n)};else return;r[Q]=!!s[Q],r[Re]=e,s.once?this.once(t,r):this.on(t,r)},removeEventListener(t,e){for(let s of this.listeners(t))if(s[Re]===e&&!s[Q]){this.removeListener(t,s);break}}};Et.exports={CloseEvent:I,ErrorEvent:H,Event:C,EventTarget:ks,MessageEvent:J};function he(t,e,s){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,s):t.call(e,s)}});var ce=S((Ir,bt)=>{"use strict";var{tokenChars:ee}=$();function O(t,e,s){t[e]===void 0?t[e]=[s]:t[e].push(s)}function Cs(t){let e=Object.create(null),s=Object.create(null),r=!1,i=!1,n=!1,o,a,l=-1,f=-1,h=-1,c=0;for(;c<t.length;c++)if(f=t.charCodeAt(c),o===void 0)if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(c!==0&&(f===32||f===9))h===-1&&l!==-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);f===44?(O(e,g,s),s=Object.create(null)):o=g,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===void 0)if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(f===32||f===9)h===-1&&l!==-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),O(s,t.slice(l,h),!0),f===44&&(O(e,o,s),s=Object.create(null),o=void 0),l=h=-1}else if(f===61&&l!==-1&&h===-1)a=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(i){if(ee[f]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:r||(r=!0),i=!1}else if(n)if(ee[f]===1)l===-1&&(l=c);else if(f===34&&l!==-1)n=!1,h=c;else if(f===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(l!==-1&&(f===32||f===9))h===-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);r&&(g=g.replace(/\\/g,""),r=!1),O(s,a,g),f===44&&(O(e,o,s),s=Object.create(null),o=void 0),a=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||f===32||f===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let _=t.slice(l,h);return o===void 0?O(e,_,s):(a===void 0?O(s,_,!0):r?O(s,a,_.replace(/\\/g,"")):O(s,a,_),O(e,o,s)),e}function Ls(t){return Object.keys(t).map(e=>{let s=t[e];return Array.isArray(s)||(s=[s]),s.map(r=>[e].concat(Object.keys(r).map(i=>{let n=r[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}bt.exports={format:Ls,parse:Cs}});var me=S((Mr,It)=>{"use strict";var Ns=p("events"),Ps=p("https"),Bs=p("http"),Tt=p("net"),Rs=p("tls"),{randomBytes:Us,createHash:Is}=p("crypto"),{Duplex:Dr,Readable:Ar}=p("stream"),{URL:Ue}=p("url"),B=G(),Ds=Le(),As=Be(),{isBlob:Ms}=$(),{BINARY_TYPES:wt,CLOSE_TIMEOUT:Fs,EMPTY_BUFFER:ue,GUID:Ws,kForOnEventAttribute:Ie,kListener:qs,kStatusCode:Gs,kWebSocket:y,NOOP:kt}=T(),{EventTarget:{addEventListener:$s,removeEventListener:js}}=vt(),{format:Vs,parse:zs}=ce(),{toBuffer:Hs}=X(),Ct=Symbol("kAborted"),De=[8,13],L=["CONNECTING","OPEN","CLOSING","CLOSED"],Ys=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Ns{constructor(e,s,r){super(),this._binaryType=wt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ue,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,s===void 0?!r||r.protocols===void 0?s=[]:Array.isArray(r.protocols)?s=r.protocols:s=[r.protocols]:Array.isArray(s)||(typeof s=="object"&&s!==null?(r=s,r.protocols===void 0?s=[]:Array.isArray(r.protocols)?s=r.protocols:s=[r.protocols]):s=[s]),Lt(this,e,s,r)):(this._autoPong=r.autoPong,this._closeTimeout=r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){wt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,s,r){let i=new Ds({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:r.maxBufferedChunks,maxFragments:r.maxFragments,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),n=new As(e,this._extensions,r.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[y]=this,n[y]=this,e[y]=this,i.on("conclude",Zs),i.on("drain",Qs),i.on("error",Js),i.on("message",er),i.on("ping",tr),i.on("pong",sr),n.onerror=rr,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),s.length>0&&e.unshift(s),e.on("close",Bt),e.on("data",_e),e.on("end",Rt),e.on("error",Ut),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[B.extensionName]&&this._extensions[B.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,s){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._sender.close(e,s,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._readyState=t.CLOSING,Pt(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.ping(e||ue,s,r)}pong(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.pong(e||ue,s,r)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof s=="function"&&(r=s,s={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...s};this._extensions[B.extensionName]||(i.compress=!1),this._sender.send(e||ue,i,r)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ie])return e[qs];return null},set(e){for(let s of this.listeners(t))if(s[Ie]){this.removeListener(t,s);break}typeof e=="function"&&this.addEventListener(t,e,{[Ie]:!0})}})});d.prototype.addEventListener=$s;d.prototype.removeEventListener=js;It.exports=d;function Lt(t,e,s,r){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Fs,protocolVersion:De[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,protocols:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,t._closeTimeout=i.closeTimeout,!De.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${De.join(", ")})`);let n;if(e instanceof Ue)n=e;else try{n=new Ue(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",a=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!a?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:a&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;de(t,u);return}let f=o?443:80,h=Us(16).toString("base64"),c=o?Ps.request:Bs.request,_=new Set,g;if(i.createConnection=i.createConnection||(o?Xs:Ks),i.defaultPort=i.defaultPort||f,i.port=n.port||f,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(g=new B({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=Vs({[B.extensionName]:g.offer()})),s.length){for(let u of s){if(typeof u!="string"||!Ys.test(u)||_.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(u)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),a){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1]}let m;if(i.followRedirects){if(t._redirects===0){t._originalIpc=a,t._originalSecure=o,t._originalHostOrSocketPath=a?i.socketPath:n.host;let u=r&&r.headers;if(r={...r,headers:{}},u)for(let[x,M]of Object.entries(u))r.headers[x.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=a?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),m=t._req=c(i),t._redirects&&t.emit("redirect",t.url,m)}else m=t._req=c(i);i.timeout&&m.on("timeout",()=>{E(t,m,"Opening handshake has timed out")}),m.on("error",u=>{m===null||m[Ct]||(m=t._req=null,de(t,u))}),m.on("response",u=>{let x=u.headers.location,M=u.statusCode;if(x&&i.followRedirects&&M>=300&&M<400){if(++t._redirects>i.maxRedirects){E(t,m,"Maximum redirects exceeded");return}m.abort();let Y;try{Y=new Ue(x,e)}catch{let F=new SyntaxError(`Invalid URL: ${x}`);de(t,F);return}Lt(t,Y,s,r)}else t.emit("unexpected-response",m,u)||E(t,m,`Unexpected server response: ${u.statusCode}`)}),m.on("upgrade",(u,x,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;m=t._req=null;let Y=u.headers.upgrade;if(Y===void 0||Y.toLowerCase()!=="websocket"){E(t,x,"Invalid Upgrade header");return}let We=Is("sha1").update(h+Ws).digest("base64");if(u.headers["sec-websocket-accept"]!==We){E(t,x,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],K;if(F!==void 0?_.size?_.has(F)||(K="Server sent an invalid subprotocol"):K="Server sent a subprotocol but none was requested":_.size&&(K="Server sent no subprotocol"),K){E(t,x,K);return}F&&(t._protocol=F);let qe=u.headers["sec-websocket-extensions"];if(qe!==void 0){if(!g){E(t,x,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let ge;try{ge=zs(qe)}catch{E(t,x,"Invalid Sec-WebSocket-Extensions header");return}let Ge=Object.keys(ge);if(Ge.length!==1||Ge[0]!==B.extensionName){E(t,x,"Server indicated an extension that was not requested");return}try{g.accept(ge[B.extensionName])}catch{E(t,x,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[B.extensionName]=g}t.setSocket(x,M,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(m,t):m.end()}function de(t,e){t._readyState=d.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ks(t){return t.path=t.socketPath,Tt.connect(t)}function Xs(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Tt.isIP(t.host)?"":t.host),Rs.connect(t)}function E(t,e,s){t._readyState=d.CLOSING;let r=new Error(s);Error.captureStackTrace(r,E),e.setHeader?(e[Ct]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(de,t,r)):(e.destroy(r),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ae(t,e,s){if(e){let r=Ms(e)?e.size:Hs(e).length;t._socket?t._sender._bufferedBytes+=r:t._bufferedAmount+=r}if(s){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${L[t.readyState]})`);process.nextTick(s,r)}}function Zs(t,e){let s=this[y];s._closeFrameReceived=!0,s._closeMessage=e,s._closeCode=t,s._socket[y]!==void 0&&(s._socket.removeListener("data",_e),process.nextTick(Nt,s._socket),t===1005?s.close():s.close(t,e))}function Qs(){let t=this[y];t.isPaused||t._socket.resume()}function Js(t){let e=this[y];e._socket[y]!==void 0&&(e._socket.removeListener("data",_e),process.nextTick(Nt,e._socket),e.close(t[Gs])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Ot(){this[y].emitClose()}function er(t,e){this[y].emit("message",t,e)}function tr(t){let e=this[y];e._autoPong&&e.pong(t,!this._isServer,kt),e.emit("ping",t)}function sr(t){this[y].emit("pong",t)}function Nt(t){t.resume()}function rr(t){let e=this[y];e.readyState!==d.CLOSED&&(e.readyState===d.OPEN&&(e._readyState=d.CLOSING,Pt(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Pt(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Bt(){let t=this[y];if(this.removeListener("close",Bt),this.removeListener("data",_e),this.removeListener("end",Rt),t._readyState=d.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[y]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Ot),t._receiver.on("finish",Ot))}function _e(t){this[y]._receiver.write(t)||this.pause()}function Rt(){let t=this[y];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Ut(){let t=this[y];this.removeListener("error",Ut),this.on("error",kt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Ft=S((Wr,Mt)=>{"use strict";var Fr=me(),{Duplex:ir}=p("stream");function Dt(t){t.emit("close")}function nr(){!this.destroyed&&this._writableState.finished&&this.destroy()}function At(t){this.removeListener("error",At),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function or(t,e){let s=!0,r=new ir({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let a=!o&&r._readableState.objectMode?n.toString():n;r.push(a)||t.pause()}),t.once("error",function(n){r.destroyed||(s=!1,r.destroy(n))}),t.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(Dt,r);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(i),process.nextTick(Dt,r)}),s&&t.terminate()},r._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){r._final(i)});return}t._socket!==null&&(t._socket._writableState.finished?(i(),r._readableState.endEmitted&&r.destroy()):(t._socket.once("finish",function(){i()}),t.close()))},r._read=function(){t.isPaused&&t.resume()},r._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){r._write(i,n,o)});return}t.send(i,o)},r.on("end",nr),r.on("error",At),r}Mt.exports=or});var Me=S((qr,Wt)=>{"use strict";var{tokenChars:ar}=$();function fr(t){let e=new Set,s=-1,r=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(r===-1&&ar[o]===1)s===-1&&(s=i);else if(i!==0&&(o===32||o===9))r===-1&&s!==-1&&(r=i);else if(o===44){if(s===-1)throw new SyntaxError(`Unexpected character at index ${i}`);r===-1&&(r=i);let a=t.slice(s,r);if(e.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);e.add(a),s=r=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(s===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(s,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Wt.exports={parse:fr}});var Ht=S(($r,zt)=>{"use strict";var lr=p("events"),pe=p("http"),{Duplex:Gr}=p("stream"),{createHash:hr}=p("crypto"),qt=ce(),D=G(),cr=Me(),ur=me(),{CLOSE_TIMEOUT:dr,GUID:_r,kWebSocket:mr}=T(),pr=/^[+/0-9A-Za-z]{22}==$/,Gt=0,$t=1,Vt=2,Fe=class extends lr{constructor(e,s){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:256*1024,maxFragments:16*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:dr,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:ur,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=pe.createServer((r,i)=>{let n=pe.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n)}),this._server.listen(e.port,e.host,e.backlog,s)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=gr(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Gt}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Vt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(te,this);return}if(e&&this.once("close",e),this._state!==$t)if(this._state=$t,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(te,this):process.nextTick(te,this);else{let s=this._server;this._removeListeners(),this._removeListeners=this._server=null,s.close(()=>{te(this)})}}shouldHandle(e){if(this.options.path){let s=e.url.indexOf("?");if((s!==-1?e.url.slice(0,s):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,s,r,i){s.on("error",jt);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if(e.method!=="GET"){A(this,e,s,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){A(this,e,s,400,"Invalid Upgrade header");return}if(n===void 0||!pr.test(n)){A(this,e,s,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){A(this,e,s,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){se(s,400);return}let l=e.headers["sec-websocket-protocol"],f=new Set;if(l!==void 0)try{f=cr.parse(l)}catch{A(this,e,s,400,"Invalid Sec-WebSocket-Protocol header");return}let h=e.headers["sec-websocket-extensions"],c={};if(this.options.perMessageDeflate&&h!==void 0){let _=new D({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let g=qt.parse(h);g[D.extensionName]&&(_.accept(g[D.extensionName]),c[D.extensionName]=_)}catch{A(this,e,s,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let _={origin:e.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(_,(g,m,u,x)=>{if(!g)return se(s,m||401,u,x);this.completeUpgrade(c,n,f,e,s,r,i)});return}if(!this.options.verifyClient(_))return se(s,401)}this.completeUpgrade(c,n,f,e,s,r,i)}completeUpgrade(e,s,r,i,n,o,a){if(!n.readable||!n.writable)return n.destroy();if(n[mr])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Gt)return se(n,503);let f=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${hr("sha1").update(s+_r).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(r.size){let c=this.options.handleProtocols?this.options.handleProtocols(r,i):r.values().next().value;c&&(f.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[D.extensionName]){let c=e[D.extensionName].params,_=qt.format({[D.extensionName]:[c]});f.push(`Sec-WebSocket-Extensions: ${_}`),h._extensions=e}this.emit("headers",f,i),n.write(f.concat(`\r
2
+ import{a as je}from"./chunk-YEY3RSFQ.mjs";import{c as $e}from"./chunk-W7XHE4CT.mjs";import{a as p,c as S,e as N}from"./chunk-5L7RYZCL.mjs";var T=S((Tr,He)=>{"use strict";var Ve=["nodebuffer","arraybuffer","fragments"],ze=typeof Blob<"u";ze&&Ve.push("blob");He.exports={BINARY_TYPES:Ve,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ze,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var X=S((kr,re)=>{"use strict";var{EMPTY_BUFFER:Qt}=T(),xe=Buffer[Symbol.species];function Jt(t,e){if(t.length===0)return Qt;if(t.length===1)return t[0];let s=Buffer.allocUnsafe(e),r=0;for(let i=0;i<t.length;i++){let n=t[i];s.set(n,r),r+=n.length}return r<e?new xe(s.buffer,s.byteOffset,r):s}function Ye(t,e,s,r,i){for(let n=0;n<i;n++)s[r+n]=t[n]^e[n&3]}function Ke(t,e){for(let s=0;s<t.length;s++)t[s]^=e[s&3]}function es(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Se(t){if(Se.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new xe(t):ArrayBuffer.isView(t)?e=new xe(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Se.readOnly=!1),e}re.exports={concat:Jt,mask:Ye,toArrayBuffer:es,toBuffer:Se,unmask:Ke};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=p("bufferutil");re.exports.mask=function(e,s,r,i,n){n<48?Ye(e,s,r,i,n):t.mask(e,s,r,i,n)},re.exports.unmask=function(e,s){e.length<32?Ke(e,s):t.unmask(e,s)}}catch{}});var Qe=S((Cr,Ze)=>{"use strict";var Xe=Symbol("kDone"),Ee=Symbol("kRun"),ve=class{constructor(e){this[Xe]=()=>{this.pending--,this[Ee]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Ee]()}[Ee](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Xe])}}};Ze.exports=ve});var G=S((Lr,st)=>{"use strict";var Z=p("zlib"),Je=X(),ts=Qe(),{kStatusCode:et}=T(),ss=Buffer[Symbol.species],rs=Buffer.from([0,0,255,255]),ne=Symbol("permessage-deflate"),k=Symbol("total-length"),W=Symbol("callback"),P=Symbol("buffers"),q=Symbol("error"),ie,be=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!ie){let s=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ie=new ts(s)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[W];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let s=this._options,r=e.find(i=>!(s.serverNoContextTakeover===!1&&i.server_no_context_takeover||i.server_max_window_bits&&(s.serverMaxWindowBits===!1||typeof s.serverMaxWindowBits=="number"&&s.serverMaxWindowBits>i.server_max_window_bits)||typeof s.clientMaxWindowBits=="number"&&(typeof i.client_max_window_bits=="number"?s.clientMaxWindowBits>i.client_max_window_bits:!i.client_max_window_bits)));if(!r)throw new Error("None of the extension offers can be accepted");return s.serverNoContextTakeover&&(r.server_no_context_takeover=!0),s.clientNoContextTakeover&&(r.client_no_context_takeover=!0),typeof s.serverMaxWindowBits=="number"&&(r.server_max_window_bits=s.serverMaxWindowBits),typeof s.clientMaxWindowBits=="number"?r.client_max_window_bits=s.clientMaxWindowBits:(r.client_max_window_bits===!0||s.clientMaxWindowBits===!1)&&delete r.client_max_window_bits,r}acceptAsClient(e){let s=e[0];if(this._options.clientNoContextTakeover===!1&&s.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!s.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(s.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&s.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return s}normalizeParams(e){return e.forEach(s=>{Object.keys(s).forEach(r=>{let i=s[r];if(i.length>1)throw new Error(`Parameter "${r}" must have only a single value`);if(i=i[0],r==="client_max_window_bits"){if(i!==!0){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else if(r==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${r}": ${i}`);i=n}else if(r==="client_no_context_takeover"||r==="server_no_context_takeover"){if(i!==!0)throw new TypeError(`Invalid value for parameter "${r}": ${i}`)}else throw new Error(`Unknown parameter "${r}"`);s[r]=i})}),e}decompress(e,s,r){ie.add(i=>{this._decompress(e,s,(n,o)=>{i(),r(n,o)})})}compress(e,s,r){ie.add(i=>{this._compress(e,s,(n,o)=>{i(),r(n,o)})})}_decompress(e,s,r){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=Z.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[ne]=this,this._inflate[k]=0,this._inflate[P]=[],this._inflate.on("error",ns),this._inflate.on("data",tt)}this._inflate[W]=r,this._inflate.write(e),s&&this._inflate.write(rs),this._inflate.flush(()=>{let n=this._inflate[q];if(n){this._inflate.close(),this._inflate=null,r(n);return}let o=Je.concat(this._inflate[P],this._inflate[k]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[k]=0,this._inflate[P]=[],s&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),r(null,o)})}_compress(e,s,r){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?Z.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=Z.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[k]=0,this._deflate[P]=[],this._deflate.on("data",is)}this._deflate[W]=r,this._deflate.write(e),this._deflate.flush(Z.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Je.concat(this._deflate[P],this._deflate[k]);s&&(n=new ss(n.buffer,n.byteOffset,n.length-4)),this._deflate[W]=null,this._deflate[k]=0,this._deflate[P]=[],s&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),r(null,n)})}};st.exports=be;function is(t){this[P].push(t),this[k]+=t.length}function tt(t){if(this[k]+=t.length,this[ne]._maxPayload<1||this[k]<=this[ne]._maxPayload){this[P].push(t);return}this[q]=new RangeError("Max payload size exceeded"),this[q].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[q][et]=1009,this.removeListener("data",tt),this.reset()}function ns(t){if(this[ne]._inflate=null,this[q]){this[W](this[q]);return}t[et]=1007,this[W](t)}});var $=S((Nr,oe)=>{"use strict";var{isUtf8:rt}=p("buffer"),{hasBlob:os}=T(),as=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function fs(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function we(t){let e=t.length,s=0;for(;s<e;)if((t[s]&128)===0)s++;else if((t[s]&224)===192){if(s+1===e||(t[s+1]&192)!==128||(t[s]&254)===192)return!1;s+=2}else if((t[s]&240)===224){if(s+2>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||t[s]===224&&(t[s+1]&224)===128||t[s]===237&&(t[s+1]&224)===160)return!1;s+=3}else if((t[s]&248)===240){if(s+3>=e||(t[s+1]&192)!==128||(t[s+2]&192)!==128||(t[s+3]&192)!==128||t[s]===240&&(t[s+1]&240)===128||t[s]===244&&t[s+1]>143||t[s]>244)return!1;s+=4}else return!1;return!0}function ls(t){return os&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}oe.exports={isBlob:ls,isValidStatusCode:fs,isValidUTF8:we,tokenChars:as};if(rt)oe.exports.isValidUTF8=function(t){return t.length<24?we(t):rt(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=p("utf-8-validate");oe.exports.isValidUTF8=function(e){return e.length<32?we(e):t(e)}}catch{}});var Le=S((Pr,ht)=>{"use strict";var{Writable:hs}=p("stream"),it=G(),{BINARY_TYPES:cs,EMPTY_BUFFER:nt,kStatusCode:us,kWebSocket:ds}=T(),{concat:Oe,toArrayBuffer:_s,unmask:ms}=X(),{isValidStatusCode:ps,isValidUTF8:ot}=$(),ae=Buffer[Symbol.species],v=0,at=1,ft=2,lt=3,Te=4,ke=5,fe=6,Ce=class extends hs{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||cs[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[ds]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._numFragments=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=v}_write(e,s,r){if(this._opcode===8&&this._state==v)return r();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){r(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(r)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let r=this._buffers[0];return this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e),new ae(r.buffer,r.byteOffset,e)}let s=Buffer.allocUnsafe(e);do{let r=this._buffers[0],i=s.length-e;e>=r.length?s.set(this._buffers.shift(),i):(s.set(new Uint8Array(r.buffer,r.byteOffset,e),i),this._buffers[0]=new ae(r.buffer,r.byteOffset+e,r.length-e)),e-=r.length}while(e>0);return s}startLoop(e){this._loop=!0;do switch(this._state){case v:this.getInfo(e);break;case at:this.getPayloadLength16(e);break;case ft:this.getPayloadLength64(e);break;case lt:this.getMask();break;case Te:this.getData(e);break;case ke:case fe:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let s=this.consume(2);if((s[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let r=(s[0]&64)===64;if(r&&!this._extensions[it.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(s[0]&128)===128,this._opcode=s[0]&15,this._payloadLength=s[1]&127,this._opcode===0){if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=r}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(r){let i=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else{let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(s[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=at:this._payloadLength===127?this._state=ft:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let s=this.consume(8),r=s.readUInt32BE(0);if(r>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=r*Math.pow(2,32)+s.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let s=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(s);return}this._masked?this._state=lt:this._state=Te}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Te}getData(e){let s=nt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}s=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&ms(s,this._mask)}if(this._opcode>7){this.controlMessage(s,e);return}if(this._maxFragments>0&&++this._numFragments>this._maxFragments){let r=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(r);return}if(this._compressed){this._state=ke,this.decompress(s,e);return}s.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(s)),this.dataMessage(e)}decompress(e,s){this._extensions[it.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return s(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");s(o);return}this._fragments.push(n)}this.dataMessage(s),this._state===v&&this.startLoop(s)})}dataMessage(e){if(!this._fin){this._state=v;return}let s=this._messageLength,r=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._numFragments=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=Oe(r,s):this._binaryType==="arraybuffer"?i=_s(Oe(r,s)):this._binaryType==="blob"?i=new Blob(r):i=r,this._allowSynchronousEvents?(this.emit("message",i,!0),this._state=v):(this._state=fe,setImmediate(()=>{this.emit("message",i,!0),this._state=v,this.startLoop(e)}))}else{let i=Oe(r,s);if(!this._skipUTF8Validation&&!ot(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===ke||this._allowSynchronousEvents?(this.emit("message",i,!1),this._state=v):(this._state=fe,setImmediate(()=>{this.emit("message",i,!1),this._state=v,this.startLoop(e)}))}}controlMessage(e,s){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,nt),this.end();else{let r=e.readUInt16BE(0);if(!ps(r)){let n=this.createError(RangeError,`invalid status code ${r}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");s(n);return}let i=new ae(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ot(i)){let n=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");s(n);return}this._loop=!1,this.emit("conclude",r,i),this.end()}this._state=v;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=v):(this._state=fe,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=v,this.startLoop(s)}))}createError(e,s,r,i,n){this._loop=!1,this._errored=!0;let o=new e(r?`Invalid WebSocket frame: ${s}`:s);return Error.captureStackTrace(o,this.createError),o.code=n,o[us]=i,o}};ht.exports=Ce});var Be=S((Rr,dt)=>{"use strict";var{Duplex:Br}=p("stream"),{randomFillSync:gs}=p("crypto"),{types:{isUint8Array:ys}}=p("util"),ct=G(),{EMPTY_BUFFER:xs,kWebSocket:Ss,NOOP:Es}=T(),{isBlob:j,isValidStatusCode:vs}=$(),{mask:ut,toBuffer:R}=X(),b=Symbol("kByteLength"),bs=Buffer.alloc(4),le=8*1024,U,V=le,w=0,ws=1,Os=2,Ne=class t{constructor(e,s,r){this._extensions=s||{},r&&(this._generateMask=r,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=w,this.onerror=Es,this[Ss]=void 0}static frame(e,s){let r,i=!1,n=2,o=!1;s.mask&&(r=s.maskBuffer||bs,s.generateMask?s.generateMask(r):(V===le&&(U===void 0&&(U=Buffer.alloc(le)),gs(U,0,le),V=0),r[0]=U[V++],r[1]=U[V++],r[2]=U[V++],r[3]=U[V++]),o=(r[0]|r[1]|r[2]|r[3])===0,n=6);let a;typeof e=="string"?(!s.mask||o)&&s[b]!==void 0?a=s[b]:(e=Buffer.from(e),a=e.length):(a=e.length,i=s.mask&&s.readOnly&&!o);let l=a;a>=65536?(n+=8,l=127):a>125&&(n+=2,l=126);let f=Buffer.allocUnsafe(i?a+n:n);return f[0]=s.fin?s.opcode|128:s.opcode,s.rsv1&&(f[0]|=64),f[1]=l,l===126?f.writeUInt16BE(a,2):l===127&&(f[2]=f[3]=0,f.writeUIntBE(a,4,6)),s.mask?(f[1]|=128,f[n-4]=r[0],f[n-3]=r[1],f[n-2]=r[2],f[n-1]=r[3],o?[f,e]:i?(ut(e,r,f,n,a),[f]):(ut(e,r,e,0,a),[f,e])):[f,e]}close(e,s,r,i){let n;if(e===void 0)n=xs;else{if(typeof e!="number"||!vs(e))throw new TypeError("First argument must be a valid error code number");if(s===void 0||!s.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else{let a=Buffer.byteLength(s);if(a>123)throw new RangeError("The message must not be greater than 123 bytes");if(n=Buffer.allocUnsafe(2+a),n.writeUInt16BE(e,0),typeof s=="string")n.write(s,2);else if(ys(s))n.set(s,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let o={[b]:n.length,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==w?this.enqueue([this.dispatch,n,!1,o,i]):this.sendFrame(t.frame(n,o),i)}ping(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):j(e)?(i=e.size,n=!1):(e=R(e),i=e.length,n=R.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:!1};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}pong(e,s,r){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=!1):j(e)?(i=e.size,n=!1):(e=R(e),i=e.length,n=R.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:!1};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,!1,o,r]):this.getBlobData(e,!1,o,r):this._state!==w?this.enqueue([this.dispatch,e,!1,o,r]):this.sendFrame(t.frame(e,o),r)}send(e,s,r){let i=this._extensions[ct.extensionName],n=s.binary?2:1,o=s.compress,a,l;typeof e=="string"?(a=Buffer.byteLength(e),l=!1):j(e)?(a=e.size,l=!1):(e=R(e),a=e.length,l=R.readOnly),this._firstFragment?(this._firstFragment=!1,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=a>=i._threshold),this._compress=o):(o=!1,n=0),s.fin&&(this._firstFragment=!0);let f={[b]:a,fin:s.fin,generateMask:this._generateMask,mask:s.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};j(e)?this._state!==w?this.enqueue([this.getBlobData,e,this._compress,f,r]):this.getBlobData(e,this._compress,f,r):this._state!==w?this.enqueue([this.dispatch,e,this._compress,f,r]):this.dispatch(e,this._compress,f,r)}getBlobData(e,s,r,i){this._bufferedBytes+=r[b],this._state=Os,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let a=new Error("The socket was closed while the blob was being read");process.nextTick(Pe,this,a,i);return}this._bufferedBytes-=r[b];let o=R(n);s?this.dispatch(o,s,r,i):(this._state=w,this.sendFrame(t.frame(o,r),i),this.dequeue())}).catch(n=>{process.nextTick(Ts,this,n,i)})}dispatch(e,s,r,i){if(!s){this.sendFrame(t.frame(e,r),i);return}let n=this._extensions[ct.extensionName];this._bufferedBytes+=r[b],this._state=ws,n.compress(e,r.fin,(o,a)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Pe(this,l,i);return}this._bufferedBytes-=r[b],this._state=w,r.readOnly=!1,this.sendFrame(t.frame(a,r),i),this.dequeue()})}dequeue(){for(;this._state===w&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e)}sendFrame(e,s){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],s),this._socket.uncork()):this._socket.write(e[0],s)}};dt.exports=Ne;function Pe(t,e,s){typeof s=="function"&&s(e);for(let r=0;r<t._queue.length;r++){let i=t._queue[r],n=i[i.length-1];typeof n=="function"&&n(e)}}function Ts(t,e,s){Pe(t,e,s),t.onerror(e)}});var vt=S((Ur,Et)=>{"use strict";var{kForOnEventAttribute:Q,kListener:Re}=T(),_t=Symbol("kCode"),mt=Symbol("kData"),pt=Symbol("kError"),gt=Symbol("kMessage"),yt=Symbol("kReason"),z=Symbol("kTarget"),xt=Symbol("kType"),St=Symbol("kWasClean"),C=class{constructor(e){this[z]=null,this[xt]=e}get target(){return this[z]}get type(){return this[xt]}};Object.defineProperty(C.prototype,"target",{enumerable:!0});Object.defineProperty(C.prototype,"type",{enumerable:!0});var I=class extends C{constructor(e,s={}){super(e),this[_t]=s.code===void 0?0:s.code,this[yt]=s.reason===void 0?"":s.reason,this[St]=s.wasClean===void 0?!1:s.wasClean}get code(){return this[_t]}get reason(){return this[yt]}get wasClean(){return this[St]}};Object.defineProperty(I.prototype,"code",{enumerable:!0});Object.defineProperty(I.prototype,"reason",{enumerable:!0});Object.defineProperty(I.prototype,"wasClean",{enumerable:!0});var H=class extends C{constructor(e,s={}){super(e),this[pt]=s.error===void 0?null:s.error,this[gt]=s.message===void 0?"":s.message}get error(){return this[pt]}get message(){return this[gt]}};Object.defineProperty(H.prototype,"error",{enumerable:!0});Object.defineProperty(H.prototype,"message",{enumerable:!0});var J=class extends C{constructor(e,s={}){super(e),this[mt]=s.data===void 0?null:s.data}get data(){return this[mt]}};Object.defineProperty(J.prototype,"data",{enumerable:!0});var ks={addEventListener(t,e,s={}){for(let i of this.listeners(t))if(!s[Q]&&i[Re]===e&&!i[Q])return;let r;if(t==="message")r=function(n,o){let a=new J("message",{data:o?n:n.toString()});a[z]=this,he(e,this,a)};else if(t==="close")r=function(n,o){let a=new I("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[z]=this,he(e,this,a)};else if(t==="error")r=function(n){let o=new H("error",{error:n,message:n.message});o[z]=this,he(e,this,o)};else if(t==="open")r=function(){let n=new C("open");n[z]=this,he(e,this,n)};else return;r[Q]=!!s[Q],r[Re]=e,s.once?this.once(t,r):this.on(t,r)},removeEventListener(t,e){for(let s of this.listeners(t))if(s[Re]===e&&!s[Q]){this.removeListener(t,s);break}}};Et.exports={CloseEvent:I,ErrorEvent:H,Event:C,EventTarget:ks,MessageEvent:J};function he(t,e,s){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,s):t.call(e,s)}});var ce=S((Ir,bt)=>{"use strict";var{tokenChars:ee}=$();function O(t,e,s){t[e]===void 0?t[e]=[s]:t[e].push(s)}function Cs(t){let e=Object.create(null),s=Object.create(null),r=!1,i=!1,n=!1,o,a,l=-1,f=-1,h=-1,c=0;for(;c<t.length;c++)if(f=t.charCodeAt(c),o===void 0)if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(c!==0&&(f===32||f===9))h===-1&&l!==-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);f===44?(O(e,g,s),s=Object.create(null)):o=g,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);else if(a===void 0)if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(f===32||f===9)h===-1&&l!==-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c),O(s,t.slice(l,h),!0),f===44&&(O(e,o,s),s=Object.create(null),o=void 0),l=h=-1}else if(f===61&&l!==-1&&h===-1)a=t.slice(l,c),l=h=-1;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(i){if(ee[f]!==1)throw new SyntaxError(`Unexpected character at index ${c}`);l===-1?l=c:r||(r=!0),i=!1}else if(n)if(ee[f]===1)l===-1&&(l=c);else if(f===34&&l!==-1)n=!1,h=c;else if(f===92)i=!0;else throw new SyntaxError(`Unexpected character at index ${c}`);else if(f===34&&t.charCodeAt(c-1)===61)n=!0;else if(h===-1&&ee[f]===1)l===-1&&(l=c);else if(l!==-1&&(f===32||f===9))h===-1&&(h=c);else if(f===59||f===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${c}`);h===-1&&(h=c);let g=t.slice(l,h);r&&(g=g.replace(/\\/g,""),r=!1),O(s,a,g),f===44&&(O(e,o,s),s=Object.create(null),o=void 0),a=void 0,l=h=-1}else throw new SyntaxError(`Unexpected character at index ${c}`);if(l===-1||n||f===32||f===9)throw new SyntaxError("Unexpected end of input");h===-1&&(h=c);let _=t.slice(l,h);return o===void 0?O(e,_,s):(a===void 0?O(s,_,!0):r?O(s,a,_.replace(/\\/g,"")):O(s,a,_),O(e,o,s)),e}function Ls(t){return Object.keys(t).map(e=>{let s=t[e];return Array.isArray(s)||(s=[s]),s.map(r=>[e].concat(Object.keys(r).map(i=>{let n=r[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===!0?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}bt.exports={format:Ls,parse:Cs}});var me=S((Mr,It)=>{"use strict";var Ns=p("events"),Ps=p("https"),Bs=p("http"),Tt=p("net"),Rs=p("tls"),{randomBytes:Us,createHash:Is}=p("crypto"),{Duplex:Dr,Readable:Ar}=p("stream"),{URL:Ue}=p("url"),B=G(),Ds=Le(),As=Be(),{isBlob:Ms}=$(),{BINARY_TYPES:wt,CLOSE_TIMEOUT:Fs,EMPTY_BUFFER:ue,GUID:Ws,kForOnEventAttribute:Ie,kListener:qs,kStatusCode:Gs,kWebSocket:y,NOOP:kt}=T(),{EventTarget:{addEventListener:$s,removeEventListener:js}}=vt(),{format:Vs,parse:zs}=ce(),{toBuffer:Hs}=X(),Ct=Symbol("kAborted"),De=[8,13],L=["CONNECTING","OPEN","CLOSING","CLOSED"],Ys=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,d=class t extends Ns{constructor(e,s,r){super(),this._binaryType=wt[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ue,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,s===void 0?!r||r.protocols===void 0?s=[]:Array.isArray(r.protocols)?s=r.protocols:s=[r.protocols]:Array.isArray(s)||(typeof s=="object"&&s!==null?(r=s,r.protocols===void 0?s=[]:Array.isArray(r.protocols)?s=r.protocols:s=[r.protocols]):s=[s]),Lt(this,e,s,r)):(this._autoPong=r.autoPong,this._closeTimeout=r.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){wt.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,s,r){let i=new Ds({allowSynchronousEvents:r.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:r.maxBufferedChunks,maxFragments:r.maxFragments,maxPayload:r.maxPayload,skipUTF8Validation:r.skipUTF8Validation}),n=new As(e,this._extensions,r.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[y]=this,n[y]=this,e[y]=this,i.on("conclude",Zs),i.on("drain",Qs),i.on("error",Js),i.on("message",er),i.on("ping",tr),i.on("pong",sr),n.onerror=rr,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),s.length>0&&e.unshift(s),e.on("close",Bt),e.on("data",_e),e.on("end",Rt),e.on("error",Ut),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[B.extensionName]&&this._extensions[B.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,s){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._sender.close(e,s,!this._isServer,r=>{r||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._readyState=t.CLOSING,Pt(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.ping(e||ue,s,r)}pong(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(r=e,e=s=void 0):typeof s=="function"&&(r=s,s=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}s===void 0&&(s=!this._isServer),this._sender.pong(e||ue,s,r)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,s,r){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof s=="function"&&(r=s,s={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ae(this,e,r);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...s};this._extensions[B.extensionName]||(i.compress=!1),this._sender.send(e||ue,i,r)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){E(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(d,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d.prototype,"CONNECTING",{enumerable:!0,value:L.indexOf("CONNECTING")});Object.defineProperty(d,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d.prototype,"OPEN",{enumerable:!0,value:L.indexOf("OPEN")});Object.defineProperty(d,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d.prototype,"CLOSING",{enumerable:!0,value:L.indexOf("CLOSING")});Object.defineProperty(d,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});Object.defineProperty(d.prototype,"CLOSED",{enumerable:!0,value:L.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(d.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(d.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ie])return e[qs];return null},set(e){for(let s of this.listeners(t))if(s[Ie]){this.removeListener(t,s);break}typeof e=="function"&&this.addEventListener(t,e,{[Ie]:!0})}})});d.prototype.addEventListener=$s;d.prototype.removeEventListener=js;It.exports=d;function Lt(t,e,s,r){let i={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Fs,protocolVersion:De[1],maxBufferedChunks:262144,maxFragments:16384,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...r,socketPath:void 0,hostname:void 0,protocol:void 0,protocols:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,t._closeTimeout=i.closeTimeout,!De.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${De.join(", ")})`);let n;if(e instanceof Ue)n=e;else try{n=new Ue(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",a=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!a?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:a&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;de(t,u);return}let f=o?443:80,h=Us(16).toString("base64"),c=o?Ps.request:Bs.request,_=new Set,g;if(i.createConnection=i.createConnection||(o?Xs:Ks),i.defaultPort=i.defaultPort||f,i.port=n.port||f,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":h,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(g=new B({...i.perMessageDeflate,isServer:!1,maxPayload:i.maxPayload}),i.headers["Sec-WebSocket-Extensions"]=Vs({[B.extensionName]:g.offer()})),s.length){for(let u of s){if(typeof u!="string"||!Ys.test(u)||_.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");_.add(u)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),a){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1]}let m;if(i.followRedirects){if(t._redirects===0){t._originalIpc=a,t._originalSecure=o,t._originalHostOrSocketPath=a?i.socketPath:n.host;let u=r&&r.headers;if(r={...r,headers:{}},u)for(let[x,M]of Object.entries(u))r.headers[x.toLowerCase()]=M}else if(t.listenerCount("redirect")===0){let u=a?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0)}i.auth&&!r.headers.authorization&&(r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),m=t._req=c(i),t._redirects&&t.emit("redirect",t.url,m)}else m=t._req=c(i);i.timeout&&m.on("timeout",()=>{E(t,m,"Opening handshake has timed out")}),m.on("error",u=>{m===null||m[Ct]||(m=t._req=null,de(t,u))}),m.on("response",u=>{let x=u.headers.location,M=u.statusCode;if(x&&i.followRedirects&&M>=300&&M<400){if(++t._redirects>i.maxRedirects){E(t,m,"Maximum redirects exceeded");return}m.abort();let Y;try{Y=new Ue(x,e)}catch{let F=new SyntaxError(`Invalid URL: ${x}`);de(t,F);return}Lt(t,Y,s,r)}else t.emit("unexpected-response",m,u)||E(t,m,`Unexpected server response: ${u.statusCode}`)}),m.on("upgrade",(u,x,M)=>{if(t.emit("upgrade",u),t.readyState!==d.CONNECTING)return;m=t._req=null;let Y=u.headers.upgrade;if(Y===void 0||Y.toLowerCase()!=="websocket"){E(t,x,"Invalid Upgrade header");return}let We=Is("sha1").update(h+Ws).digest("base64");if(u.headers["sec-websocket-accept"]!==We){E(t,x,"Invalid Sec-WebSocket-Accept header");return}let F=u.headers["sec-websocket-protocol"],K;if(F!==void 0?_.size?_.has(F)||(K="Server sent an invalid subprotocol"):K="Server sent a subprotocol but none was requested":_.size&&(K="Server sent no subprotocol"),K){E(t,x,K);return}F&&(t._protocol=F);let qe=u.headers["sec-websocket-extensions"];if(qe!==void 0){if(!g){E(t,x,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let ge;try{ge=zs(qe)}catch{E(t,x,"Invalid Sec-WebSocket-Extensions header");return}let Ge=Object.keys(ge);if(Ge.length!==1||Ge[0]!==B.extensionName){E(t,x,"Server indicated an extension that was not requested");return}try{g.accept(ge[B.extensionName])}catch{E(t,x,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[B.extensionName]=g}t.setSocket(x,M,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}),i.finishRequest?i.finishRequest(m,t):m.end()}function de(t,e){t._readyState=d.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ks(t){return t.path=t.socketPath,Tt.connect(t)}function Xs(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Tt.isIP(t.host)?"":t.host),Rs.connect(t)}function E(t,e,s){t._readyState=d.CLOSING;let r=new Error(s);Error.captureStackTrace(r,E),e.setHeader?(e[Ct]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(de,t,r)):(e.destroy(r),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ae(t,e,s){if(e){let r=Ms(e)?e.size:Hs(e).length;t._socket?t._sender._bufferedBytes+=r:t._bufferedAmount+=r}if(s){let r=new Error(`WebSocket is not open: readyState ${t.readyState} (${L[t.readyState]})`);process.nextTick(s,r)}}function Zs(t,e){let s=this[y];s._closeFrameReceived=!0,s._closeMessage=e,s._closeCode=t,s._socket[y]!==void 0&&(s._socket.removeListener("data",_e),process.nextTick(Nt,s._socket),t===1005?s.close():s.close(t,e))}function Qs(){let t=this[y];t.isPaused||t._socket.resume()}function Js(t){let e=this[y];e._socket[y]!==void 0&&(e._socket.removeListener("data",_e),process.nextTick(Nt,e._socket),e.close(t[Gs])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Ot(){this[y].emitClose()}function er(t,e){this[y].emit("message",t,e)}function tr(t){let e=this[y];e._autoPong&&e.pong(t,!this._isServer,kt),e.emit("ping",t)}function sr(t){this[y].emit("pong",t)}function Nt(t){t.resume()}function rr(t){let e=this[y];e.readyState!==d.CLOSED&&(e.readyState===d.OPEN&&(e._readyState=d.CLOSING,Pt(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Pt(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Bt(){let t=this[y];if(this.removeListener("close",Bt),this.removeListener("data",_e),this.removeListener("end",Rt),t._readyState=d.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[y]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Ot),t._receiver.on("finish",Ot))}function _e(t){this[y]._receiver.write(t)||this.pause()}function Rt(){let t=this[y];t._readyState=d.CLOSING,t._receiver.end(),this.end()}function Ut(){let t=this[y];this.removeListener("error",Ut),this.on("error",kt),t&&(t._readyState=d.CLOSING,this.destroy())}});var Ft=S((Wr,Mt)=>{"use strict";var Fr=me(),{Duplex:ir}=p("stream");function Dt(t){t.emit("close")}function nr(){!this.destroyed&&this._writableState.finished&&this.destroy()}function At(t){this.removeListener("error",At),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function or(t,e){let s=!0,r=new ir({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(n,o){let a=!o&&r._readableState.objectMode?n.toString():n;r.push(a)||t.pause()}),t.once("error",function(n){r.destroyed||(s=!1,r.destroy(n))}),t.once("close",function(){r.destroyed||r.push(null)}),r._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(Dt,r);return}let o=!1;t.once("error",function(l){o=!0,n(l)}),t.once("close",function(){o||n(i),process.nextTick(Dt,r)}),s&&t.terminate()},r._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){r._final(i)});return}t._socket!==null&&(t._socket._writableState.finished?(i(),r._readableState.endEmitted&&r.destroy()):(t._socket.once("finish",function(){i()}),t.close()))},r._read=function(){t.isPaused&&t.resume()},r._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){r._write(i,n,o)});return}t.send(i,o)},r.on("end",nr),r.on("error",At),r}Mt.exports=or});var Me=S((qr,Wt)=>{"use strict";var{tokenChars:ar}=$();function fr(t){let e=new Set,s=-1,r=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(r===-1&&ar[o]===1)s===-1&&(s=i);else if(i!==0&&(o===32||o===9))r===-1&&s!==-1&&(r=i);else if(o===44){if(s===-1)throw new SyntaxError(`Unexpected character at index ${i}`);r===-1&&(r=i);let a=t.slice(s,r);if(e.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);e.add(a),s=r=-1}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(s===-1||r!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(s,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}Wt.exports={parse:fr}});var Ht=S(($r,zt)=>{"use strict";var lr=p("events"),pe=p("http"),{Duplex:Gr}=p("stream"),{createHash:hr}=p("crypto"),qt=ce(),D=G(),cr=Me(),ur=me(),{CLOSE_TIMEOUT:dr,GUID:_r,kWebSocket:mr}=T(),pr=/^[+/0-9A-Za-z]{22}==$/,Gt=0,$t=1,Vt=2,Fe=class extends lr{constructor(e,s){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:256*1024,maxFragments:16*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:dr,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:ur,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=pe.createServer((r,i)=>{let n=pe.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n)}),this._server.listen(e.port,e.host,e.backlog,s)):e.server&&(this._server=e.server),this._server){let r=this.emit.bind(this,"connection");this._removeListeners=gr(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,r)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Gt}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Vt){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(te,this);return}if(e&&this.once("close",e),this._state!==$t)if(this._state=$t,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(te,this):process.nextTick(te,this);else{let s=this._server;this._removeListeners(),this._removeListeners=this._server=null,s.close(()=>{te(this)})}}shouldHandle(e){if(this.options.path){let s=e.url.indexOf("?");if((s!==-1?e.url.slice(0,s):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,s,r,i){s.on("error",jt);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if(e.method!=="GET"){A(this,e,s,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){A(this,e,s,400,"Invalid Upgrade header");return}if(n===void 0||!pr.test(n)){A(this,e,s,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==13&&a!==8){A(this,e,s,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){se(s,400);return}let l=e.headers["sec-websocket-protocol"],f=new Set;if(l!==void 0)try{f=cr.parse(l)}catch{A(this,e,s,400,"Invalid Sec-WebSocket-Protocol header");return}let h=e.headers["sec-websocket-extensions"],c={};if(this.options.perMessageDeflate&&h!==void 0){let _=new D({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let g=qt.parse(h);g[D.extensionName]&&(_.accept(g[D.extensionName]),c[D.extensionName]=_)}catch{A(this,e,s,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let _={origin:e.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(_,(g,m,u,x)=>{if(!g)return se(s,m||401,u,x);this.completeUpgrade(c,n,f,e,s,r,i)});return}if(!this.options.verifyClient(_))return se(s,401)}this.completeUpgrade(c,n,f,e,s,r,i)}completeUpgrade(e,s,r,i,n,o,a){if(!n.readable||!n.writable)return n.destroy();if(n[mr])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Gt)return se(n,503);let f=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${hr("sha1").update(s+_r).digest("base64")}`],h=new this.options.WebSocket(null,void 0,this.options);if(r.size){let c=this.options.handleProtocols?this.options.handleProtocols(r,i):r.values().next().value;c&&(f.push(`Sec-WebSocket-Protocol: ${c}`),h._protocol=c)}if(e[D.extensionName]){let c=e[D.extensionName].params,_=qt.format({[D.extensionName]:[c]});f.push(`Sec-WebSocket-Extensions: ${_}`),h._extensions=e}this.emit("headers",f,i),n.write(f.concat(`\r
3
3
  `).join(`\r
4
4
  `)),n.removeListener("error",jt),h.setSocket(n,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(h),h.on("close",()=>{this.clients.delete(h),this._shouldEmitClose&&!this.clients.size&&process.nextTick(te,this)})),a(h,i)}};zt.exports=Fe;function gr(t,e){for(let s of Object.keys(e))t.on(s,e[s]);return function(){for(let r of Object.keys(e))t.removeListener(r,e[r])}}function te(t){t._state=Vt,t.emit("close")}function jt(){this.destroy()}function se(t,e,s,r){s=s||pe.STATUS_CODES[e],r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(s),...r},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${pe.STATUS_CODES[e]}\r
5
5
  `+Object.keys(r).map(i=>`${i}: ${r[i]}`).join(`\r
@@ -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{a as v,b as j}from"./chunk-2RKIHJI2.mjs";import l from"node:fs";import p from"node:path";import V from"node:zlib";import{escapeAttribute as $,escapeMarkup as _}from"../browser/shared/escape.mjs";import{componentOf as b,instancesOf as L,partOf as O}from"../browser/shared/components/index.mjs";import{ICON_COLOR_VALUES as I,TAB_ICON as N,glyphOf as B,iconKind as u,iconUrl as T,iconValueOf as S,tabIconValue as R}from"../browser/shared/emoji/icon-value.mjs";import{lineIconSvg as z}from"../browser/shared/emoji/line-icons.mjs";import{mediaTypeOf as A,mediaUrl as J}from"../browser/shared/media.mjs";import{emojiDataDirectory as P,reportsDirectory as E}from"../browser/shared/paths.mjs";import{slugPattern as G}from"../browser/shared/reports.mjs";import{documentDirectory as D}from"../browser/shared/workspace.mjs";var g=P,k=String.fromCodePoint(65039),C=null,x=null;function H(){return C??={positions:JSON.parse(l.readFileSync(p.join(g,"positions.json"),"utf8")),index:JSON.parse(l.readFileSync(p.join(g,"twemoji-index.json"),"utf8")),svg:V.gunzipSync(l.readFileSync(p.join(g,"twemoji-svg.bin")))},C}function F(e){let{positions:t,index:r,svg:o}=H(),n=[e,e.replaceAll(k,""),`${e}${k}`].find(c=>t[c]),i=n&&r[t[n][0]];return i?o.subarray(i[0],i[0]+i[1]):null}function U(e){let t=F(e);return t?`data:image/svg+xml;base64,${t.toString("base64")}`:null}function ue(e){return d(""),[...x.keys()].filter(t=>t.startsWith(`${e}/`)).map(t=>t.slice(e.length+1))}function d(e,t="currentColor"){x??=new Map(JSON.parse(l.readFileSync(p.join(g,"icons.json"),"utf8")).icons.flatMap(([,n,i,c,a])=>[[`mingcute/${n}`,c],[`tabler/${i}`,a]].filter(([,s])=>s)));let r=B(e),o=r&&x.get(`${r.set}/${r.name}`);return o?o.split("#COLOR").join(t).replace("<svg ",'<svg aria-hidden="true" '):null}function K(e){let[t,r]=I[B(e)?.color]??I.gray,o=d(e);return o&&o.replace(/<svg\b[^>]*>/,n=>`${n.replace(/ aria-hidden="true"/,"").replace(/^<svg /,'<svg xmlns="http://www.w3.org/2000/svg" ').replace(/ xmlns="http:\/\/www\.w3\.org\/2000\/svg"(?=.* xmlns=)/,"")}<style>svg{color:${t}}@media (prefers-color-scheme:dark){svg{color:${r}}}</style>`)}var W=e=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><text x="18" y="18" text-anchor="middle" dominant-baseline="central" font-size="30" font-family="'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif">${_(e)}</text></svg>`;function q({value:e,slug:t=null,tab:r=!1,reportsDirectory:o=E}){let n=z(e,{color:"#000",tab:r});if(n)return{type:"image/svg+xml",body:Buffer.from(n)};let i=u(e);if(i==="emoji")return{type:"image/svg+xml",body:F(e)??Buffer.from(W(e))};if(i==="glyph"){let a=r?K(e):d(e,"#000");return a&&{type:"image/svg+xml",body:Buffer.from(a)}}if(i!=="image"||!t||!G.test(t))return null;let c=p.join(D(t,o),e);return l.existsSync(c)?{type:A(e),body:l.readFileSync(c)}:null}var M=/(<div\b[^>]*\bclass="doc-icon"[^>]*>)([\s\S]*?)(<\/div>)/g;function de(e,{slug:t,mode:r="export",reportsDirectory:o=E}){return te(X(e,{mode:r}).replace(M,(n,i,c,a)=>{let s=S(n),y=u(s);if(!y)return n;let f=null;if(y==="emoji"){let m=U(s);f=m&&`<img alt="${$(s)}" src="${m}">`}else if(y==="glyph")f=d(s);else if(r==="preview")f=`<img src="${J("asset",t,s)}" alt="">`;else{let m=p.join(D(t,o),s),w=l.existsSync(m)?l.readFileSync(m):null;f=w&&`<img src="data:${A(s)};base64,${w.toString("base64")}" alt="">`}let h=r==="preview"?i.replace(/>$/,` data-ge-icon="${$(s)}">`):i;return f?`${h}${f}${a}`:`${h}${c}${a}`}),ee(Z(e),{slug:t,mode:r,reportsDirectory:o}))}var ye=e=>[...e.matchAll(M)].flatMap(t=>{let r=u(S(t[0]))==="image"?/<img\b[^>]*\bsrc="/.exec(t[2]):null;return r?[t.index+t[1].length+r.index]:[]}),Q=/<button\b[^>]*\bdata-tab-icon="([^"]*)"[^>]*>/g;function X(e,{mode:t="export"}={}){return e.replace(Q,(r,o)=>{if(u(o)!=="emoji"||r.includes(N))return r;let n=t==="preview"?T(o):U(o);if(!n)return r;let i=`${N}: ${R(n)}`;return/\sstyle="/.test(r)?r.replace(/\sstyle="([^"]*)"/,(c,a)=>` style="${a.replace(/;?\s*$/,"; ")}${i}"`):r.replace(/>$/,` style="${i}">`)})}function Y(e){let t=O(e,b("page").header)[0];return{all:L(e,b("icon")),own:t?O(t,b("icon").match):[]}}function Z(e){let[t]=Y(v(e)).own;return t?S(j(e,t)):null}function ee(e,{slug:t,mode:r,reportsDirectory:o}){if(!e)return null;if(r==="preview")return T(e,t,{tab:!0});let n=q({value:e,slug:t,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${Buffer.from(n.body).toString("base64")}`}var te=(e,t)=>t&&/<\/head>/i.test(e)&&!e.includes("data-doc-tab-icon")?e.replace(/<\/head>/i,()=>` <link rel="icon" href="${$(t)}" data-doc-tab-icon>
2
+ import{a as v,b as j}from"./chunk-HYMEEXKN.mjs";import l from"node:fs";import p from"node:path";import V from"node:zlib";import{escapeAttribute as $,escapeMarkup as _}from"../browser/shared/escape.mjs";import{componentOf as b,instancesOf as L,partOf as O}from"../browser/shared/components/index.mjs";import{ICON_COLOR_VALUES as I,TAB_ICON as N,glyphOf as B,iconKind as u,iconUrl as T,iconValueOf as S,tabIconValue as R}from"../browser/shared/emoji/icon-value.mjs";import{lineIconSvg as z}from"../browser/shared/emoji/line-icons.mjs";import{mediaTypeOf as A,mediaUrl as J}from"../browser/shared/media.mjs";import{emojiDataDirectory as P,reportsDirectory as E}from"../browser/shared/paths.mjs";import{slugPattern as G}from"../browser/shared/reports.mjs";import{documentDirectory as D}from"../browser/shared/workspace.mjs";var g=P,k=String.fromCodePoint(65039),C=null,x=null;function H(){return C??={positions:JSON.parse(l.readFileSync(p.join(g,"positions.json"),"utf8")),index:JSON.parse(l.readFileSync(p.join(g,"twemoji-index.json"),"utf8")),svg:V.gunzipSync(l.readFileSync(p.join(g,"twemoji-svg.bin")))},C}function F(e){let{positions:t,index:r,svg:o}=H(),n=[e,e.replaceAll(k,""),`${e}${k}`].find(c=>t[c]),i=n&&r[t[n][0]];return i?o.subarray(i[0],i[0]+i[1]):null}function U(e){let t=F(e);return t?`data:image/svg+xml;base64,${t.toString("base64")}`:null}function ue(e){return d(""),[...x.keys()].filter(t=>t.startsWith(`${e}/`)).map(t=>t.slice(e.length+1))}function d(e,t="currentColor"){x??=new Map(JSON.parse(l.readFileSync(p.join(g,"icons.json"),"utf8")).icons.flatMap(([,n,i,c,a])=>[[`mingcute/${n}`,c],[`tabler/${i}`,a]].filter(([,s])=>s)));let r=B(e),o=r&&x.get(`${r.set}/${r.name}`);return o?o.split("#COLOR").join(t).replace("<svg ",'<svg aria-hidden="true" '):null}function K(e){let[t,r]=I[B(e)?.color]??I.gray,o=d(e);return o&&o.replace(/<svg\b[^>]*>/,n=>`${n.replace(/ aria-hidden="true"/,"").replace(/^<svg /,'<svg xmlns="http://www.w3.org/2000/svg" ').replace(/ xmlns="http:\/\/www\.w3\.org\/2000\/svg"(?=.* xmlns=)/,"")}<style>svg{color:${t}}@media (prefers-color-scheme:dark){svg{color:${r}}}</style>`)}var W=e=>`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36"><text x="18" y="18" text-anchor="middle" dominant-baseline="central" font-size="30" font-family="'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif">${_(e)}</text></svg>`;function q({value:e,slug:t=null,tab:r=!1,reportsDirectory:o=E}){let n=z(e,{color:"#000",tab:r});if(n)return{type:"image/svg+xml",body:Buffer.from(n)};let i=u(e);if(i==="emoji")return{type:"image/svg+xml",body:F(e)??Buffer.from(W(e))};if(i==="glyph"){let a=r?K(e):d(e,"#000");return a&&{type:"image/svg+xml",body:Buffer.from(a)}}if(i!=="image"||!t||!G.test(t))return null;let c=p.join(D(t,o),e);return l.existsSync(c)?{type:A(e),body:l.readFileSync(c)}:null}var M=/(<div\b[^>]*\bclass="doc-icon"[^>]*>)([\s\S]*?)(<\/div>)/g;function de(e,{slug:t,mode:r="export",reportsDirectory:o=E}){return te(X(e,{mode:r}).replace(M,(n,i,c,a)=>{let s=S(n),y=u(s);if(!y)return n;let f=null;if(y==="emoji"){let m=U(s);f=m&&`<img alt="${$(s)}" src="${m}">`}else if(y==="glyph")f=d(s);else if(r==="preview")f=`<img src="${J("asset",t,s)}" alt="">`;else{let m=p.join(D(t,o),s),w=l.existsSync(m)?l.readFileSync(m):null;f=w&&`<img src="data:${A(s)};base64,${w.toString("base64")}" alt="">`}let h=r==="preview"?i.replace(/>$/,` data-ge-icon="${$(s)}">`):i;return f?`${h}${f}${a}`:`${h}${c}${a}`}),ee(Z(e),{slug:t,mode:r,reportsDirectory:o}))}var ye=e=>[...e.matchAll(M)].flatMap(t=>{let r=u(S(t[0]))==="image"?/<img\b[^>]*\bsrc="/.exec(t[2]):null;return r?[t.index+t[1].length+r.index]:[]}),Q=/<button\b[^>]*\bdata-tab-icon="([^"]*)"[^>]*>/g;function X(e,{mode:t="export"}={}){return e.replace(Q,(r,o)=>{if(u(o)!=="emoji"||r.includes(N))return r;let n=t==="preview"?T(o):U(o);if(!n)return r;let i=`${N}: ${R(n)}`;return/\sstyle="/.test(r)?r.replace(/\sstyle="([^"]*)"/,(c,a)=>` style="${a.replace(/;?\s*$/,"; ")}${i}"`):r.replace(/>$/,` style="${i}">`)})}function Y(e){let t=O(e,b("page").header)[0];return{all:L(e,b("icon")),own:t?O(t,b("icon").match):[]}}function Z(e){let[t]=Y(v(e)).own;return t?S(j(e,t)):null}function ee(e,{slug:t,mode:r,reportsDirectory:o}){if(!e)return null;if(r==="preview")return T(e,t,{tab:!0});let n=q({value:e,slug:t,tab:!0,reportsDirectory:o});return n&&`data:${n.type};base64,${Buffer.from(n.body).toString("base64")}`}var te=(e,t)=>t&&/<\/head>/i.test(e)&&!e.includes("data-doc-tab-icon")?e.replace(/<\/head>/i,()=>` <link rel="icon" href="${$(t)}" data-doc-tab-icon>
3
3
  </head>`):e;export{U as a,ue as b,d as c,q as d,de as e,ye as f,Y as g,Z as h};
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
- import{c as _}from"./chunk-BYSF5UMM.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-3OFXMN6N.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-SOD23RGL.mjs";import{M as Ae}from"./chunk-4DNHHJSL.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-3A5I2GJK.mjs";import{d as Ce,g as je}from"./chunk-5L26JUYA.mjs";import"./chunk-S2Y7VI4H.mjs";import"./chunk-XQRUG4G3.mjs";import{i as ie}from"./chunk-JJNRIFND.mjs";import{a as W}from"./chunk-JEUK3ZO7.mjs";import"./chunk-CG3UHDKH.mjs";import{a as re,b as le,e as de,f as K,g as ce}from"./chunk-4AMTKWDO.mjs";import"./chunk-QXVNUASA.mjs";import"./chunk-FCK6NXON.mjs";import"./chunk-OU3S466R.mjs";import"./chunk-QK3VISCA.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-TOE6DPLH.mjs";import"./chunk-WTEGUPFG.mjs";import"./chunk-2GKGEVMR.mjs";import{a as H,b as j,c as P,d as D,f as oe}from"./chunk-VKSRM7EY.mjs";import{a as te,e as B,f as ae}from"./chunk-LE44MD3O.mjs";import{b as se}from"./chunk-4OZWXZE5.mjs";import"./chunk-XMKHCUI6.mjs";import"./chunk-SAHS56QM.mjs";import"./chunk-KH24LWAT.mjs";import"./chunk-YFJU3O7G.mjs";import"./chunk-NWRZXELO.mjs";import{j as ne}from"./chunk-G4YP7GVC.mjs";import"./chunk-DHB7UZ7F.mjs";import"./chunk-2RKIHJI2.mjs";import"./chunk-JXLSHVJ2.mjs";import"./chunk-XKOHV4H6.mjs";import"./chunk-KFZBYDIS.mjs";import"./chunk-7XDYK3UC.mjs";import{f as Z,j as ee}from"./chunk-VG5JEIUQ.mjs";import{b as X,e as _e}from"./chunk-N3DSBH5S.mjs";import"./chunk-5L7RYZCL.mjs";_e();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import O from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as He,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as M,hasClass as q,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],De=["light","dark"],Ze=900,et=3e4,tt=new Set(["iframe","frame","object","embed"]),at=/^\d+$/,ot={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function st(e,{catalog:g,folder:o,slug:h}){let i=[],s=d=>d?.sourceCodeLocation?.startLine??1,n=(d,a)=>i.push({line:typeof d=="number"?d:s(d),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),c=[],f=[];Re(t,d=>{d.tagName&&(d.tagName==="main"&&q(d,"gallery-page")&&c.push(d),q(d,"gallery-board")&&f.push(d),q(d,"gallery-card")&&!q(d.parentNode,"gallery-board")&&n(d,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`))},{inTemplates:!1}),c.length===0&&(f.length>0||j(e).cards.length>0)&&n(1,`no <main class="gallery-page">: a page's boards stand in one (it is how a block knows it is on a page: context.place "page", and how the page follows the theme)`);let y=new Map;for(let d of f){let a=d.parentNode;for(;a&&!(a.tagName==="main"&&q(a,"gallery-page"));)a=a.parentNode;c.length&&!a&&n(d,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=M(d,"data-board-id");r===void 0||r===""?n(d,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):H.test(r)?y.has(r)?n(d,`data-board-id="${r}" again (line ${y.get(r)} has it): each board's id is its own`):y.set(r,s(d)):n(d,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let S=new Map,N=new Map;for(let d of j(e).cards){let{node:a}=d,r=M(a,"data-card-id"),k=r&&H.test(r)?`card ${r}`:"this card";r===void 0||r===""?n(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):H.test(r)?S.has(r)?n(a,`data-card-id="${r}" again (line ${S.get(r)} has it): each card's id is its own, and the page's writes go by it`):S.set(r,s(a)):n(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?n(a,`${k} holds no instance of a custom block (an element with ${He}): a card is one block's instance, gallery/static's for what only shows`):u>1?n(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):d.instance&&d.instance.parentNode!==a&&n(d.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let b={};for(let x of["x","y","w","h"]){let A=M(a,`data-${x}`),[L,E]=ot[x];A===void 0?n(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):at.test(A.trim())?Number(A)<L||Number(A)>E?n(a,`${k}'s data-${x}="${A}": ${x} is ${E===1/0?`${L} or more`:`${L} to ${E}`}${x==="w"?" (a row is 12 cells)":""}`):b[x]=Number(A):n(a,`${k}'s data-${x}="${A}" is no whole number`)}b.x!==void 0&&b.w!==void 0&&b.x+b.w>12?n(a,`${k} reaches past the row's end: data-x ${b.x} and data-w ${b.w} make ${b.x+b.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(b).length===4&&N.set(d.board,[...N.get(d.board)??[],{id:r??null,...b,line:s(a)}]),d.block&&nt(d.block,g,x=>n(d.instance,`${k}'s block ${d.block}: ${x}`))}for(let d of N.values())for(let a=0;a<d.length;a++)for(let r=a+1;r<d.length;r++){let[k,u]=[d[a],d[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&n(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return i.push(...it(e,{folder:o,slug:h})),i.sort((d,a)=>d.line-a.line)}function nt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let i=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):i?o(`it does not load (${ee("en",i.problem)}): gallery block check ${e} says why`):ae(e)&&B(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${B(e).pack===te?B(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function it(e,{folder:g,slug:o}){let h=[],i=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let n=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",c=Me(n)??(n.startsWith(i)?Me(n.slice(i.length-7)):null),f=`"${n.length>60?`${n.slice(0,60)}\u2026`:n}"`,y=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(c!==null){Qe(c)?tt.has(s.node.tagName)&&!Te(c)?h.push({line:s.line,what:`${y}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture, stylesheet or script for saving only: write what it shows in the page itself, frame a site by its https address, or offer the file with a link, <a href="${c}" download>`}):Ue(O.join(g,c))||h.push({line:s.line,what:`${y}: ${c} is not in the page's folder (${W(O.join(g,"assets"))}): put the file there${Te(c)?"":", or link to it"}`}):h.push({line:s.line,what:`${y} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!n||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(n)||h.push({line:s.line,what:`${y} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function rt(e,g){let o=P(e).text,h=[];for(let i of j(o).cards){let s=i.block?g.packages.get(i.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let n=G(D(o,i),_,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=n?.text.trim()?JSON.parse(n.text):{}}catch{continue}let c=je(s,t);c.length&&h.push({id:i.id,block:i.block,line:i.node.sourceCodeLocation?.startLine??1,empty:c})}return h}var lt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:i,zh:s})=>`${h} (${s&&s!==i?`${i}, ${s}`:i})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,dt=(e,g=!1)=>{let o=h=>M(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${M(e.node,"data-x")},${M(e.node,"data-y")}`,Pe=e=>`${M(e.node,"data-w")},${M(e.node,"data-h")}`;function ct(e,g,o){let[h,i]=[P(e).text,P(g).text],[s,n]=[j(h).cards,j(i).cards],t=new Set([...s,...n].map(a=>a.board)).size>1,c=a=>dt(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)n.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:c(a)});for(let a of n)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:c(a)});for(let a of n){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:c(r),now:c(a)}),u&&f.resized.push({id:a.id,block:a.block,was:c(r),now:c(a)});let[b,x]=[D(h,r),D(i,a)];if(b===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,L=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[E,l]=L?[G(b,_,L),G(x,_,L)]:[null,null];if(!E||!l){f.markup.push({id:a.id,block:A?a.block:null});continue}let v=E.parts.flatMap(({name:$,text:m},I)=>m===l.parts[I].text?[]:[{name:$,...Y(m,l.parts[I].text),runs:ke(m,l.parts[I].text)}]);v.length&&f.data.push({id:a.id,block:a.block,parts:v}),E.outside!==l.outside&&f.markup.push({id:a.id,block:a.block})}let y=(a,r)=>{let k="",u=0;for(let b of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,b.start),u=b.end;return k+a.slice(u)},[S,N]=[y(h,s),y(i,n)],d=a=>a.replace(/\s+/g," ");return d(S)!==d(N)&&(f.page=Y(S.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",We="(put there by Gallery)";function ht(e,g){let o=n=>{let t=new Map;for(let c of g)if(c.by===n)for(let[f,y]of Object.entries(c.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(y)?y:[]]));return t},h=o("page"),i=o("gallery"),s=n=>t=>{let c=!!h.get(t.id)?.has(n);return{...t,user:c,...!c&&i.get(t.id)?.has(n)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function pt(e,g){let o=({id:t,block:c})=>`${t}${c?` (${c})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${We}`:"",i=[];for(let t of e.added)i.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)i.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)i.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(c=>c.id===t.id)||i.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)i.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Le(t.parts).map(c=>` ${c}`));for(let t of e.markup)i.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&i.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),i.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.user)),n=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.gallery));return[`Changes since ${g}:`,...i,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...n?[` Each change marked ${We} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function ut(e,g){let{qa:o,state:h}=U(e),i=O.join(o,g,"checked.html"),s=await R.readFile(i,"utf8").catch(()=>null);if(s!==null){let{mtime:y}=await R.stat(i);return{text:s,since:`the last check that found nothing (${qe(y)}, local time, ${W(i)})`,at:y.getTime()}}let n=O.join(h,"pages",g),t=(await R.readdir(n).catch(()=>[])).filter(y=>/^\d{15}-\d{4}\.html$/.test(y)).sort();if(t.length===0)return null;let c=O.join(n,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(c,"utf8"),since:`the page as it was before its last write (${qe(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var qe=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function ft(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let c=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),y=[...t.children].find(S=>S.matches(e));return{id:t.getAttribute("data-card-id"),block:y?.getAttribute(g)??null,out:f.width>0&&(f.left<c.left-1||f.right>c.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!y?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(S=>S.complete&&S.naturalWidth===0).map(o)}}),i=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,n=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:c,at:f})=>({kind:t,block:c,waited:Date.now()-f}));return{cards:h,broken:i,stuck:n,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function wt(e,{address:g,out:o,readers:h=new Set,wait:i=ge,limits:s={}}){let{loading:n=he,ready:t=et,answer:c=pe,closing:f=de,looking:y=ue}=s,S=new Map,N=new Map,d=[],a=!1,r=(l,v,$,m,I=S)=>{if(a)return;let w=I.get(l)??{card:v,what:$,looks:[]};w.looks.push(m),I.set(l,w)},k="a browser context opened",u=(l,v,$=c)=>(k=v,ye(l,v,$)),b=Q.flatMap(l=>De.map(v=>({width:l,theme:v,view:`${l} ${v}`}))),x=null,A=async({width:l,theme:v,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
2
+ import{c as _}from"./chunk-236JJXWY.mjs";import{n as G,p as Le,r as Ee,s as Ne,t as Ie,x as Oe}from"./chunk-Q7P3Q5YX.mjs";import{c as he,d as pe,e as ue,f as fe,g as we,h as ge,i as me,j as z,l as $e,n as Y,o as ke,q as be,r as ye,s as xe,t as ve,u as Se}from"./chunk-4KUO7R2M.mjs";import{M as Ae}from"./chunk-MKIBJTJZ.mjs";import"./chunk-342HXE3Q.mjs";import"./chunk-2KAVXMKG.mjs";import{d as Ce,g as je}from"./chunk-C257H6IA.mjs";import"./chunk-3XZOA7AH.mjs";import"./chunk-XZCFPKGO.mjs";import{i as ie}from"./chunk-BN7M3IN7.mjs";import{a as W}from"./chunk-JEUK3ZO7.mjs";import"./chunk-M4NRDYI5.mjs";import{a as re,b as le,e as de,f as K,g as ce}from"./chunk-PUOQ65NC.mjs";import"./chunk-6QWQXHAV.mjs";import"./chunk-6Q7ASAXJ.mjs";import"./chunk-S3SX3COT.mjs";import"./chunk-IA4PSIMD.mjs";import"./chunk-2OHANJ6Q.mjs";import"./chunk-F4ZA6JRZ.mjs";import"./chunk-7M2BQQGZ.mjs";import"./chunk-6NLXUKAY.mjs";import"./chunk-VRPVVMRB.mjs";import"./chunk-7UZUQQ7Q.mjs";import{a as H,b as j,c as P,d as D,f as oe}from"./chunk-4B2TB5K2.mjs";import{a as te,e as B,f as ae}from"./chunk-KLQP46Y3.mjs";import{b as se}from"./chunk-4OZWXZE5.mjs";import"./chunk-USIHBCSW.mjs";import"./chunk-3SKOU6OZ.mjs";import"./chunk-ZTHICSSF.mjs";import"./chunk-PLB7L22J.mjs";import"./chunk-PAREWQGB.mjs";import{j as ne}from"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-HYMEEXKN.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import{f as Z,j as ee}from"./chunk-TKWEX4FD.mjs";import{b as X,e as _e}from"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";_e();import{existsSync as Ue}from"node:fs";import R from"node:fs/promises";import O from"node:path";import{isInstance as Ke}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as He,INSTANCE as Ye}from"../browser/shared/components/installed.mjs";import{attr as M,hasClass as q,walk as Re}from"../browser/shared/html-tree.mjs";import{assetFile as Qe,imageFile as Te,referencedFile as Me}from"../browser/shared/media.mjs";import{pageAssetAddress as Ve,pageExists as Je,pageFiles as Xe}from"../browser/shared/pages.mjs";import{layoutOf as U}from"../browser/shared/workspace.mjs";var Q=[1280,1920,600],De=["light","dark"],Ze=900,et=3e4,tt=new Set(["iframe","frame","object","embed"]),at=/^\d+$/,ot={x:[0,11],y:[0,1/0],w:[1,12],h:[1,24]};function st(e,{catalog:g,folder:o,slug:h}){let i=[],s=d=>d?.sourceCodeLocation?.startLine??1,n=(d,a)=>i.push({line:typeof d=="number"?d:s(d),what:a}),t=X(e.replace(/^/," "),{sourceCodeLocationInfo:!0}),c=[],f=[];Re(t,d=>{d.tagName&&(d.tagName==="main"&&q(d,"gallery-page")&&c.push(d),q(d,"gallery-board")&&f.push(d),q(d,"gallery-card")&&!q(d.parentNode,"gallery-board")&&n(d,`a card (class gallery-card) that is no board's child: each card stands right in a <div class="gallery-board" data-board-id="\u2026">, which lays it out, and this one is laid out by none`))},{inTemplates:!1}),c.length===0&&(f.length>0||j(e).cards.length>0)&&n(1,`no <main class="gallery-page">: a page's boards stand in one (it is how a block knows it is on a page: context.place "page", and how the page follows the theme)`);let y=new Map;for(let d of f){let a=d.parentNode;for(;a&&!(a.tagName==="main"&&q(a,"gallery-page"));)a=a.parentNode;c.length&&!a&&n(d,`a board outside <main class="gallery-page">: its cards' blocks would not know they are on a page`);let r=M(d,"data-board-id");r===void 0||r===""?n(d,"a board with no data-board-id: write one (main, side\u2026), of lowercase letters, digits and hyphens, once in the page"):H.test(r)?y.has(r)?n(d,`data-board-id="${r}" again (line ${y.get(r)} has it): each board's id is its own`):y.set(r,s(d)):n(d,`data-board-id="${r}": a board's id is lowercase letters, digits and single hyphens (main, side-2)`)}let S=new Map,N=new Map;for(let d of j(e).cards){let{node:a}=d,r=M(a,"data-card-id"),k=r&&H.test(r)?`card ${r}`:"this card";r===void 0||r===""?n(a,"a card with no data-card-id: write one (c<n>, the lowest none holds, or a name of your own), of lowercase letters, digits and hyphens: its place, its writes and the reader's state go by it"):H.test(r)?S.has(r)?n(a,`data-card-id="${r}" again (line ${S.get(r)} has it): each card's id is its own, and the page's writes go by it`):S.set(r,s(a)):n(a,`data-card-id="${r}": a card's id is lowercase letters, digits and single hyphens (c3, water)`);let u=0;Re(a,x=>{x!==a&&Ke(x)&&(u+=1)},{inTemplates:!1}),u===0?n(a,`${k} holds no instance of a custom block (an element with ${He}): a card is one block's instance, gallery/static's for what only shows`):u>1?n(a,`${k} holds ${u} instances: a card holds one (put each on a card of its own)`):d.instance&&d.instance.parentNode!==a&&n(d.instance,`${k}'s instance stands inside another element of the card: write it right in the card's <section>`);let b={};for(let x of["x","y","w","h"]){let A=M(a,`data-${x}`),[L,E]=ot[x];A===void 0?n(a,`${k} has no data-${x}: a card says its place and size in whole cells, data-x data-y data-w data-h`):at.test(A.trim())?Number(A)<L||Number(A)>E?n(a,`${k}'s data-${x}="${A}": ${x} is ${E===1/0?`${L} or more`:`${L} to ${E}`}${x==="w"?" (a row is 12 cells)":""}`):b[x]=Number(A):n(a,`${k}'s data-${x}="${A}" is no whole number`)}b.x!==void 0&&b.w!==void 0&&b.x+b.w>12?n(a,`${k} reaches past the row's end: data-x ${b.x} and data-w ${b.w} make ${b.x+b.w}, and a row is 12 cells (x + w is 12 at most)`):Object.keys(b).length===4&&N.set(d.board,[...N.get(d.board)??[],{id:r??null,...b,line:s(a)}]),d.block&&nt(d.block,g,x=>n(d.instance,`${k}'s block ${d.block}: ${x}`))}for(let d of N.values())for(let a=0;a<d.length;a++)for(let r=a+1;r<d.length;r++){let[k,u]=[d[a],d[r]];k.x<u.x+u.w&&u.x<k.x+k.w&&k.y<u.y+u.h&&u.y<k.y+k.h&&n(u.line,`card ${u.id??"here"} (x ${u.x}, y ${u.y}, ${u.w} \xD7 ${u.h}) shares cells with card ${k.id??`at line ${k.line}`} (x ${k.x}, y ${k.y}, ${k.w} \xD7 ${k.h}): no two cards of a board overlap; move one to a free spot (gallery page add finds one for a new card)`)}return i.push(...it(e,{folder:o,slug:h})),i.sort((d,a)=>d.line-a.line)}function nt(e,g,o){let h=g.packages.get(e);if(h){h.places.includes("page")||o(`a block of documents (its manifest's places has no "page"): on a custom page its card says so and runs nothing`);return}let i=g.problems.get(e);g.settings.disabled.includes(e)?o("turned off in \u8BBE\u7F6E \u203A \u7EC4\u4EF6\u5217\u8868: its card says so and runs nothing (the user turns it on again)"):i?o(`it does not load (${ee("en",i.problem)}): gallery block check ${e} says why`):ae(e)&&B(e)?o(`one of Gallery's own blocks, not yet in this workspace: gallery block add ${B(e).pack===te?B(e).name:e} puts it in`):o("no custom block of that id in this workspace: gallery block list lists them")}function it(e,{folder:g,slug:o}){let h=[],i=`${Ve(o,"assets/")}`;for(let s of ne(e,()=>!0)){let n=s.value.trim(),t=["a","area"].includes(s.node.tagName)&&s.how==="href",c=Me(n)??(n.startsWith(i)?Me(n.slice(i.length-7)):null),f=`"${n.length>60?`${n.slice(0,60)}\u2026`:n}"`,y=s.how==="css"?`<style>'s url() ${f}`:`<${s.node.tagName}>'s ${s.how==="style"?"style url()":s.how} ${f}`;if(c!==null){Qe(c)?tt.has(s.node.tagName)&&!Te(c)?h.push({line:s.line,what:`${y}: a frame of a file of the page's assets/ downloads it and shows nothing, as the server hands out a page's own file that is no picture, stylesheet or script for saving only: write what it shows in the page itself, frame a site by its https address, or offer the file with a link, <a href="${c}" download>`}):Ue(O.join(g,c))||h.push({line:s.line,what:`${y}: ${c} is not in the page's folder (${W(O.join(g,"assets"))}): put the file there${Te(c)?"":", or link to it"}`}):h.push({line:s.line,what:`${y} names a file the server serves none by: the page's own files go right in pages/${o}/assets/, each named with letters, digits, dots, dashes and underscores (assets/cover.png)`});continue}t||!n||/^(?:[a-z][a-z0-9+.-]*:|\/|#|\?)/i.test(n)||h.push({line:s.line,what:`${y} is relative to /pages/${o}, where nothing is served: put the file in pages/${o}/assets/ and write assets/<file>`})}return h}function rt(e,g){let o=P(e).text,h=[];for(let i of j(o).cards){let s=i.block?g.packages.get(i.block):null;if(!s?.settings?.some(f=>f.required)||!s.parts.settings)continue;let n=G(D(o,i),_,{...s,parts:{settings:s.parts.settings}})?.parts.find(({name:f})=>f==="settings"),t={};try{t=n?.text.trim()?JSON.parse(n.text):{}}catch{continue}let c=je(s,t);c.length&&h.push({id:i.id,block:i.block,line:i.node.sourceCodeLocation?.startLine??1,empty:c})}return h}var lt=({id:e,block:g,empty:o})=>`card ${e} (${g}) holds no ${o.map(({key:h,label:i,zh:s})=>`${h} (${s&&s!==i?`${i}, ${s}`:i})`).join(" and no ")} in its settings, which it cannot show anything without: it shows its ask for one (the grip at its top right \u203A \u8BBE\u7F6E\u2026), and no picture of the page shows what it is for. Ask the user for it, or take it from what the workspace says (\u5199\u4F5C\u504F\u597D, the documents), write it in the card's settings part, and tell them in the handoff which you did`,dt=(e,g=!1)=>{let o=h=>M(e.node,`data-${h}`)??"-";return`x ${o("x")}, y ${o("y")}, ${o("w")} \xD7 ${o("h")}${g?` on ${e.board??"-"}`:""}`},Fe=e=>`${e.board},${M(e.node,"data-x")},${M(e.node,"data-y")}`,Pe=e=>`${M(e.node,"data-w")},${M(e.node,"data-h")}`;function ct(e,g,o){let[h,i]=[P(e).text,P(g).text],[s,n]=[j(h).cards,j(i).cards],t=new Set([...s,...n].map(a=>a.board)).size>1,c=a=>dt(a,t),f={added:[],removed:[],moved:[],resized:[],data:[],markup:[],page:null,kept:0};for(let a of s)n.some(r=>r.id===a.id)||f.removed.push({id:a.id,block:a.block,cells:c(a)});for(let a of n)s.some(r=>r.id===a.id)||f.added.push({id:a.id,block:a.block,cells:c(a)});for(let a of n){let r=s.find($=>$.id===a.id);if(!r)continue;let[k,u]=[Fe(r)!==Fe(a),Pe(r)!==Pe(a)];k&&f.moved.push({id:a.id,block:a.block,was:c(r),now:c(a)}),u&&f.resized.push({id:a.id,block:a.block,was:c(r),now:c(a)});let[b,x]=[D(h,r),D(i,a)];if(b===x){!k&&!u&&(f.kept+=1);continue}let A=r.block===a.block?o.packages.get(a.block):null,L=A?{...A,parts:Object.fromEntries(Object.entries(A.parts).filter(([,$])=>$.edit==="data"))}:null,[E,l]=L?[G(b,_,L),G(x,_,L)]:[null,null];if(!E||!l){f.markup.push({id:a.id,block:A?a.block:null});continue}let v=E.parts.flatMap(({name:$,text:m},I)=>m===l.parts[I].text?[]:[{name:$,...Y(m,l.parts[I].text),runs:ke(m,l.parts[I].text)}]);v.length&&f.data.push({id:a.id,block:a.block,parts:v}),E.outside!==l.outside&&f.markup.push({id:a.id,block:a.block})}let y=(a,r)=>{let k="",u=0;for(let b of[...r].sort((x,A)=>x.start-A.start))k+=a.slice(u,b.start),u=b.end;return k+a.slice(u)},[S,N]=[y(h,s),y(i,n)],d=a=>a.replace(/\s+/g," ");return d(S)!==d(N)&&(f.page=Y(S.replace(/^\s*\n/gm,""),N.replace(/^\s*\n/gm,""))),f}var ze="(the user's, on the page)",We="(put there by Gallery)";function ht(e,g){let o=n=>{let t=new Map;for(let c of g)if(c.by===n)for(let[f,y]of Object.entries(c.cards??{}))t.set(f,new Set([...t.get(f)??[],...Array.isArray(y)?y:[]]));return t},h=o("page"),i=o("gallery"),s=n=>t=>{let c=!!h.get(t.id)?.has(n);return{...t,user:c,...!c&&i.get(t.id)?.has(n)?{gallery:!0}:{}}};return{...e,added:e.added.map(s("added")),removed:e.removed.map(s("removed")),moved:e.moved.map(s("cells")),resized:e.resized.map(s("cells")),data:e.data.map(s("content")),markup:e.markup.map(s("content"))}}function pt(e,g){let o=({id:t,block:c})=>`${t}${c?` (${c})`:""}`,h=t=>t.user?` ${ze}`:t.gallery?` ${We}`:"",i=[];for(let t of e.added)i.push(` added ${o(t)} at ${t.cells}${h(t)}`);for(let t of e.removed)i.push(` removed ${o(t)}, which stood at ${t.cells}${h(t)}`);for(let t of e.moved)i.push(` moved ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.resized)e.moved.some(c=>c.id===t.id)||i.push(` resized ${o(t)}: ${t.was} then ${t.now}${h(t)}`);for(let t of e.data)i.push(` data ${o(t)}: ${$e(t.parts)}${h(t)}`,...Le(t.parts).map(c=>` ${c}`));for(let t of e.markup)i.push(` markup ${o(t)}: its markup outside its place and its data parts${t.block?"":" (a block the workspace has not: its markup whole)"}${h(t)}`);if(e.page&&i.push(` page its own HTML outside the cards: -${e.page.removed} +${e.page.added} of its ${e.page.lines} line${e.page.lines===1?"":"s"}`),i.length===0)return[`No change since ${g}: every card where it was, with the data it had.`];let s=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.user)),n=["added","removed","moved","resized","data","markup"].some(t=>e[t].some(c=>c.gallery));return[`Changes since ${g}:`,...i,...e.kept?[e.kept===1?" The other card as it was.":` The other ${e.kept} cards as they were.`]:[],...s?[` Each change marked ${ze} is the user's own gesture on the page since then (a move, a resize, a card added or deleted there, what they typed in it), which the page wrote: leave it as it is, never put it back.`]:[],...n?[` Each change marked ${We} is Gallery's own doing, not the user's and not yours: the cards it put on the home page when it made it (\u95EE\u5019\u4E0E\u65E5\u671F, \u4FBF\u7B7E): leave it as it is.`]:[]]}async function ut(e,g){let{qa:o,state:h}=U(e),i=O.join(o,g,"checked.html"),s=await R.readFile(i,"utf8").catch(()=>null);if(s!==null){let{mtime:y}=await R.stat(i);return{text:s,since:`the last check that found nothing (${qe(y)}, local time, ${W(i)})`,at:y.getTime()}}let n=O.join(h,"pages",g),t=(await R.readdir(n).catch(()=>[])).filter(y=>/^\d{15}-\d{4}\.html$/.test(y)).sort();if(t.length===0)return null;let c=O.join(n,t.at(-1)),f=Number(t.at(-1).slice(0,15));return{text:await R.readFile(c,"utf8"),since:`the page as it was before its last write (${qe(new Date(f))}, local time; used because no check has passed yet)`,at:f}}var qe=e=>`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")} ${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`;function ft(e,g){let o=t=>`<${t.localName}${t.getAttribute("src")?` src="${t.getAttribute("src").slice(0,80)}"`:""}>`,h=[...document.querySelectorAll(".gallery-board > .gallery-card")].map(t=>{let c=t.parentElement.getBoundingClientRect(),f=t.getBoundingClientRect(),y=[...t.children].find(S=>S.matches(e));return{id:t.getAttribute("data-card-id"),block:y?.getAttribute(g)??null,out:f.width>0&&(f.left<c.left-1||f.right>c.right+1),tall:t.scrollHeight>t.clientHeight+1?{needs:t.scrollHeight,has:t.clientHeight}:null,wide:t.scrollWidth>t.clientWidth+1?{needs:t.scrollWidth,has:t.clientWidth}:null,fallback:!!y?.hasAttribute("data-doc-fallback"),error:(t.querySelector(".doc-kit-error")?.textContent??"").trim()||null,broken:[...t.querySelectorAll("img")].filter(S=>S.complete&&S.naturalWidth===0).map(o)}}),i=[...document.querySelectorAll("img")].filter(t=>!t.closest(".gallery-card")&&t.complete&&t.naturalWidth===0).map(o),s=document.documentElement.scrollWidth,n=[...globalThis.__galleryQueries?.pending.values()??[]].map(({kind:t,block:c,at:f})=>({kind:t,block:c,waited:Date.now()-f}));return{cards:h,broken:i,stuck:n,wide:s>innerWidth+1?s:0,columns:document.querySelector(".gallery-board")?.getAttribute("data-columns")??null}}async function wt(e,{address:g,out:o,readers:h=new Set,wait:i=ge,limits:s={}}){let{loading:n=he,ready:t=et,answer:c=pe,closing:f=de,looking:y=ue}=s,S=new Map,N=new Map,d=[],a=!1,r=(l,v,$,m,I=S)=>{if(a)return;let w=I.get(l)??{card:v,what:$,looks:[]};w.looks.push(m),I.set(l,w)},k="a browser context opened",u=(l,v,$=c)=>(k=v,ye(l,v,$)),b=Q.flatMap(l=>De.map(v=>({width:l,theme:v,view:`${l} ${v}`}))),x=null,A=async({width:l,theme:v,view:$})=>{let m=await u(x.newPage(),"a tab opened");try{m.on("pageerror",p=>r(`error ${z(p)}`,null,`the page threw: ${z(p)}`,$)),m.on("console",p=>{p.type()==="error"&&!/^Failed to load resource/.test(p.text())&&r(`console ${p.text().split(`
3
3
  `)[0]}`,null,`the console says ${p.text().split(`
4
4
  `)[0]}`,$)}),m.on("response",p=>{let C=new URL(p.url());p.status()>=400&&C.origin===new URL(g).origin&&C.pathname!=="/favicon.ico"&&r(`request ${C.pathname}`,null,`${C.pathname} answered ${p.status()}`,$)}),await u(be(m,{add:p=>r(`dialog ${p}`,null,`it opened a dialog (${p}), which stops a reader's page until it is answered`,$)}),"the tab was set to refuse dialogs"),await u(me(m),"the tab was set to watch the page's reads of the workspace"),await u(m.setViewport({width:l,height:Ze}),`the window went to ${l}px`),await u(m.emulateMediaFeatures([{name:"prefers-color-scheme",value:v}]),`the ${v} theme came`),await u(m.goto(g,{waitUntil:"load",timeout:0}),"the page opened",n),await u(m.waitForSelector("html[data-doc-ready][data-doc-drawn]",{timeout:0}),"the page was drawn (its html got data-doc-drawn)",t),await u(m.evaluate(()=>document.fonts?.ready.then(()=>!0)),"the page's fonts loaded");let I=await u(m.$("main"),"the page's main was found")??await u(m.$("body"),"the page's body was found");await u(I.evaluate(Oe,{still:fe,step:we,wait:i}),"the page held still");let w=await u(m.evaluate(ft,Ye,He),"the page was looked at");for(let{kind:p,block:C,waited:Ge}of w.stuck){let V=w.cards.filter(F=>C?F.block===C:h.has(F.block)),J=F=>`the workspace had not answered ${F} read of "${p}" ${Math.round(Ge/1e3)} s after it asked, so its picture shows it before it drew what it reads, which the picture then does not tell (open the page in Gallery to see it)`;if(V.length)for(let F of V)r(`unanswered ${F.id} ${p}`,F.id,J("its"),$,N);else r(`unanswered ${p}`,null,J("a card's"),$,N)}w.wide&&r("wide",null,`the page is ${w.wide}px wide in a window ${l}px wide: something of its own reaches past the window (a width of its own, a long word), and a reader scrolls it sideways`,$);for(let p of w.broken)r(`broken ${p}`,null,`a picture that does not load: ${p}`,$);for(let p of w.cards){p.fallback&&r(`fallback ${p.id}`,p.id,`its block failed: the card shows what its instance holds, read-only${p.error?` (${p.error.slice(0,200)})`:""}`,$),p.out&&r(`out ${p.id}`,p.id,"it is drawn out of its board",$),p.tall&&r(`tall ${p.id}`,p.id,`what it holds does not fit it: ${p.tall.needs}px high in a card that shows ${p.tall.has}px, the rest scrolling inside the card (give the card more cells, data-h, or a size its block lists; a block whose content grows says card.fit "content")`,$),p.wide&&r(`wide ${p.id}`,p.id,`what it holds is wider than the card: ${p.wide.needs}px in a card ${p.wide.has}px wide`,$);for(let C of p.broken)r(`broken ${p.id} ${C}`,p.id,`a picture that does not load: ${C}`,$)}let T=O.join(o,`${l}-${v}.png`);await u(m.screenshot({path:T,fullPage:!0}),"the page was pictured"),a||d.push(T)}finally{await K(m.close(),f)}},L=l=>({problems:[...S.values()],notes:[...N.values()],pictures:d,unverified:null,stuck:!1,...l}),E=null;try{x=await u(e.createBrowserContext(),"a browser context opened");for(let l of b)E=l,await gt(A(l),y,()=>k);return L({})}catch(l){return await Se(e)?L({unverified:`the browser went while it looked (${z(l)})`}):l.stuck?(r("stopped",null,mt(l,b.indexOf(E??b[0])<b.length-1),(E??b[0]).view),L({stuck:!0})):L({unverified:`the look stopped: ${z(l)}`})}finally{a=!0,await K(x?.close(),f)}}function gt(e,g,o){let h=0,i=new Promise((s,n)=>{h=setTimeout(()=>n(Object.assign(new Error(o()),{stuck:!0,doing:o(),limit:g,whole:!0})),g)});return Promise.race([e,i]).finally(()=>clearTimeout(h))}function mt(e,g){return`${e.whole?`the look was not done in ${xe(e.limit)}, waiting until ${e.doing}`:ve(e)}; the look stopped here and the browser was closed${g?", so the looks after it were not made":""}. A script of the page that never ends does this, and so may a browser that stalled: run the check once more, and if it stops at the same place again, the page holds it up`}function Be(e){let g=[...new Set(e.map(i=>i.split(" ")[0]))],o=[...new Set(e.map(i=>i.split(" ")[1]))],h=i=>i.length<2?i.join(""):`${i.slice(0,-1).join(", ")} and ${i.at(-1)}`;return`at ${h(g)}px${o.length===De.length?"":`, ${h(o)}`}`}async function Ht(e,g){if(g.length!==1)throw new se("gallery page check takes one page's slug.");let[o]=g,h=Xe(o,e);Je(o,e)||(console.error(await Ce(o,e)),process.exit(1));let i=new Date,s=await R.readFile(h.html,"utf8"),n=O.basename(h.html),t=Z(e),{boards:c,cards:f}=j(s);console.log(`${o}: ${W(h.html)}, ${c.length} board${c.length===1?"":"s"} and ${f.length} card${f.length===1?"":"s"}`);let y=[],S=st(s,{catalog:t,folder:h.folder,slug:o});for(let{line:l,what:v}of S)y.push(` FAIL ${n}:${l}: ${v}`);console.log(S.length?`Structure: ${S.length} problem${S.length===1?"":"s"}`:"Structure: nothing wrong (the page's own HTML, scripts and frames its own; every board's and card's id once, one instance a card, the cells on the board and none shared, every block one a page runs, every file of assets/ there)");for(let l of y)console.log(l);for(let l of j(P(s).text).cards)console.log(` ${l.id} ${l.block??"(no instance)"} x ${l.x}, y ${l.y}, ${l.w} \xD7 ${l.h}${c.length>1?` on ${l.board}`:""} ${n}:${l.node.sourceCodeLocation?.startLine}`);let N=rt(s,t);for(let l of N)console.log(` note ${n}:${l.line}: ${lt(l)}`);let d=await ut(e,o),a=d?await oe(U(e).state,o,d.at):[];console.log((d?pt(ht(ct(d.text,s,t),a),d.since):["No earlier version to tell changes against: the next check that finds nothing keeps this one, and says what changed since."]).join(`
5
- `));let r=new Map(j(P(s).text).cards.map(l=>[l.id,l.node.sourceCodeLocation?.startLine??1])),k=(l,v=null,$=0)=>{if(l)return{line:`FAIL ${o}: ${l} problem${l===1?"":"s"}`,code:1};if(v)return{line:`UNVERIFIED ${o}: ${v}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:I,empty:w})=>`${I} (${w.map(({key:T})=>T).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),b=async(l,v,$=0)=>{let{line:m,code:I}=k(l,v,$);if(console.log(m),I===0){let w=O.join(U(e).qa,o,"checked.html");await R.mkdir(O.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,i,i)}process.exitCode=I};if(!u.ok)return b(S.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return b(S.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Ie(e);let A=await Ee(e,{directory:h.folder,files:h,text:s}),L=O.join(U(e).qa,o,"check"),E=null;try{let{pageAloneOf:l}=await import("./chunk-DAMVDXR3.mjs"),v=l(u.port,A.slug);console.log(`Looked at: ${v} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${n}), at ${Q.join(", ")}px, light and dark`);try{E=await ce({executablePath:x,args:le()})}catch(w){return b(S.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(L,{recursive:!0,force:!0}),await R.mkdir(L,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await wt(E.browser,{address:v,out:L,readers:$});m.stuck&&(await E.close(),E=null);for(let{card:w,what:T,looks:p}of m.problems)console.log(` FAIL ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${T} (${Be(p)})`);let I=new Map(j(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:T,looks:p}of m.notes)console.log(` note ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}${I.get(w)?` (${I.get(w)})`:""}: `:""}${T} (${Be(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${W(L)}: ${m.pictures.map(w=>O.basename(w)).join(", ")}`),console.log(Ae([{folder:O.dirname(L),files:m.pictures}]))),b(S.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await E?.close(),await Ne(e,A.slug)}}export{We as GALLERYS_MARK,Q as LOOK_WIDTHS,De as THEMES,ze as USERS_MARK,ut as baselineOf,pt as changesSaid,rt as emptyRequired,lt as emptyRequiredSaid,wt as look,ht as markedTheUsers,ct as pageChanges,Ht as pageCheckCommand,st as structureProblems};
5
+ `));let r=new Map(j(P(s).text).cards.map(l=>[l.id,l.node.sourceCodeLocation?.startLine??1])),k=(l,v=null,$=0)=>{if(l)return{line:`FAIL ${o}: ${l} problem${l===1?"":"s"}`,code:1};if(v)return{line:`UNVERIFIED ${o}: ${v}; its structure was checked, and nothing is wrong with it`,code:3};let m=N.length?`; and ${N.length===1?"one card asks":`${N.length} cards ask`} for a setting no one gave (see "note" above): ${N.map(({id:I,empty:w})=>`${I} (${w.map(({key:T})=>T).join(", ")})`).join(", ")}`:"";return{line:`OK ${o}: its structure, and its ${f.length} card${f.length===1?"":"s"} at ${Q.join(", ")}px in light and dark${$?`; but ${$===1?"one card was":`${$} cards were`} pictured before the workspace answered it (see "note" above), so ${$===1?"its picture does":"their pictures do"} not show what ${$===1?"it reads":"they read"}`:""}${m}`,code:0}},u=await ie({command:`gallery page check ${o}`}),b=async(l,v,$=0)=>{let{line:m,code:I}=k(l,v,$);if(console.log(m),I===0){let w=O.join(U(e).qa,o,"checked.html");await R.mkdir(O.dirname(w),{recursive:!0}),await R.writeFile(w,s),await R.utimes(w,i,i)}process.exitCode=I};if(!u.ok)return b(S.length,`${u.message}, so the page was not looked at`);let x=re();if(!x)return b(S.length,"no Chrome, Edge or Chromium found (GALLERY_BROWSER=<its executable> picks one), so the page was not looked at");await Ie(e);let A=await Ee(e,{directory:h.folder,files:h,text:s}),L=O.join(U(e).qa,o,"check"),E=null;try{let{pageAloneOf:l}=await import("./chunk-2T4PZQEP.mjs"),v=l(u.port,A.slug);console.log(`Looked at: ${v} (a scratch copy of ${o}, gone at the end: nothing a block does as it opens writes ${n}), at ${Q.join(", ")}px, light and dark`);try{E=await ce({executablePath:x,args:le()})}catch(w){return b(S.length,`the browser ${x} did not start, twice (${z(w)}), so the page was not looked at`)}await R.rm(L,{recursive:!0,force:!0}),await R.mkdir(L,{recursive:!0});let $=new Set([...t.packages.values()].filter(({needs:w})=>w?.includes("workspace")).map(({id:w})=>w)),m=await wt(E.browser,{address:v,out:L,readers:$});m.stuck&&(await E.close(),E=null);for(let{card:w,what:T,looks:p}of m.problems)console.log(` FAIL ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}: `:""}${T} (${Be(p)})`);let I=new Map(j(s).cards.map(w=>[w.id,w.block]));for(let{card:w,what:T,looks:p}of m.notes)console.log(` note ${n}:${w?r.get(w)??1:1}: ${w?`card ${w}${I.get(w)?` (${I.get(w)})`:""}: `:""}${T} (${Be(p)})`);return m.pictures.length&&(console.log(`Pictures of the page in ${W(L)}: ${m.pictures.map(w=>O.basename(w)).join(", ")}`),console.log(Ae([{folder:O.dirname(L),files:m.pictures}]))),b(S.length+m.problems.length,m.unverified,new Set(m.notes.map(({card:w})=>w??"")).size)}finally{await E?.close(),await Ne(e,A.slug)}}export{We as GALLERYS_MARK,Q as LOOK_WIDTHS,De as THEMES,ze as USERS_MARK,ut as baselineOf,pt as changesSaid,rt as emptyRequired,lt as emptyRequiredSaid,wt as look,ht as markedTheUsers,ct as pageChanges,Ht as pageCheckCommand,st as structureProblems};
@@ -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{b as d,e as L}from"./chunk-N3DSBH5S.mjs";L();import{instanceSlots as x,isInstance as A}from"../browser/shared/components/index.mjs";import{mayHoldOldNames as I,newAttributeName as S,newAttributeValue as b,newScriptNames as N,newStyleNames as j}from"../browser/shared/old-names.mjs";var T=/^data-(?:report|doc)-(?:kit|vendor)$/;function E(o){if(typeof o!="string"||!I(o))return o;let O=d(o,{sourceCodeLocationInfo:!0}),c=[],l=(t,e,s)=>{o.slice(t,e)!==s&&c.push({start:t,end:e,text:s})};function g(t){let e=t.sourceCodeLocation?.attrs??{};for(let{name:n,value:y}of t.attrs){let r=e[n];if(!r)continue;let i=o.slice(r.startOffset,r.endOffset),f=i.indexOf("="),v=f<0?i:i.slice(0,f),m=f<0?"":i.slice(f),C=/^on/i.test(n)||/^\s*javascript:/i.test(y)?N(m):b(n,m,t.tagName);l(r.startOffset,r.endOffset,S(v)+C)}if(t.attrs.some(({name:n})=>T.test(n))||!["style","script"].includes(t.tagName))return;let s=t.childNodes?.[0]?.sourceCodeLocation;if(!s)return;let w=(t.attrs.find(({name:n})=>n==="type")?.value??"").trim().toLowerCase();if(t.tagName==="script"&&/json/.test(w))return;let p=o.slice(s.startOffset,s.endOffset);l(s.startOffset,s.endOffset,t.tagName==="style"?j(p):N(p))}let u=t=>{for(let e of t.childNodes??[]){if(A(e)){x(e).forEach(u);continue}e.tagName&&g(e),u(e.tagName==="template"&&e.content?e.content:e)}};if(u(O),!c.length)return o;c.sort((t,e)=>e.start-t.start);let a=o;for(let{start:t,end:e,text:s}of c)a=a.slice(0,t)+s+a.slice(e);return a}export{E as a};
2
+ import{b as d,e as L}from"./chunk-A55HN5OK.mjs";L();import{instanceSlots as x,isInstance as A}from"../browser/shared/components/index.mjs";import{mayHoldOldNames as I,newAttributeName as S,newAttributeValue as b,newScriptNames as N,newStyleNames as j}from"../browser/shared/old-names.mjs";var T=/^data-(?:report|doc)-(?:kit|vendor)$/;function E(o){if(typeof o!="string"||!I(o))return o;let O=d(o,{sourceCodeLocationInfo:!0}),c=[],l=(t,e,s)=>{o.slice(t,e)!==s&&c.push({start:t,end:e,text:s})};function g(t){let e=t.sourceCodeLocation?.attrs??{};for(let{name:n,value:y}of t.attrs){let r=e[n];if(!r)continue;let i=o.slice(r.startOffset,r.endOffset),f=i.indexOf("="),v=f<0?i:i.slice(0,f),m=f<0?"":i.slice(f),C=/^on/i.test(n)||/^\s*javascript:/i.test(y)?N(m):b(n,m,t.tagName);l(r.startOffset,r.endOffset,S(v)+C)}if(t.attrs.some(({name:n})=>T.test(n))||!["style","script"].includes(t.tagName))return;let s=t.childNodes?.[0]?.sourceCodeLocation;if(!s)return;let w=(t.attrs.find(({name:n})=>n==="type")?.value??"").trim().toLowerCase();if(t.tagName==="script"&&/json/.test(w))return;let p=o.slice(s.startOffset,s.endOffset);l(s.startOffset,s.endOffset,t.tagName==="style"?j(p):N(p))}let u=t=>{for(let e of t.childNodes??[]){if(A(e)){x(e).forEach(u);continue}e.tagName&&g(e),u(e.tagName==="template"&&e.content?e.content:e)}};if(u(O),!c.length)return o;c.sort((t,e)=>e.start-t.start);let a=o;for(let{start:t,end:e,text:s}of c)a=a.slice(0,t)+s+a.slice(e);return a}export{E as a};