@heycys/gallery 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +1 -1
  2. package/THIRD-PARTY-NOTICES.md +1 -1
  3. package/assets/preview/runtime.js +156 -0
  4. package/assets/preview/shell.html +107 -0
  5. package/assets/writing-preferences.md +1 -1
  6. package/browser/editor/components/divider/index.mjs +1 -1
  7. package/browser/editor/page/annotate/card.mjs +6 -0
  8. package/browser/editor/page/annotate/index.mjs +22 -2
  9. package/browser/editor/page/columns/index.mjs +1 -1
  10. package/browser/editor/page/conflicts.mjs +1 -1
  11. package/browser/editor/page/drag/index.mjs +1 -1
  12. package/browser/editor/page/editor.mjs +43 -5
  13. package/browser/editor/page/focus.mjs +104 -0
  14. package/browser/editor/page/handle/index.mjs +14 -2
  15. package/browser/editor/page/links/index.mjs +2 -2
  16. package/browser/editor/page/quiet.mjs +3 -3
  17. package/browser/editor/page/resize/index.mjs +1 -1
  18. package/browser/editor/page/session.mjs +4 -1
  19. package/browser/editor/page/ui.mjs +1 -1
  20. package/browser/shared/annotations.mjs +22 -3
  21. package/browser/shared/block-packs.mjs +13 -4
  22. package/browser/shared/document-look.mjs +14 -0
  23. package/browser/shared/drafts.mjs +1 -1
  24. package/browser/shared/extension-manifest.mjs +40 -12
  25. package/browser/shared/favorite-merge.mjs +17 -0
  26. package/browser/shared/favorites.mjs +77 -0
  27. package/browser/shared/i18n/en.mjs +123 -24
  28. package/browser/shared/outline-ops.mjs +109 -0
  29. package/browser/shared/outline.mjs +6 -0
  30. package/browser/shared/pages.mjs +20 -8
  31. package/browser/shared/paths.mjs +5 -2
  32. package/browser/shared/preference-documents.mjs +137 -0
  33. package/browser/shared/presence.mjs +94 -0
  34. package/browser/shared/preview-server.mjs +8 -5
  35. package/browser/shared/qa-levels.mjs +9 -1
  36. package/browser/shared/session.mjs +4 -0
  37. package/browser/shared/shipped-blocks.mjs +22 -4
  38. package/browser/shared/startup.mjs +101 -0
  39. package/browser/shared/workspace-address.mjs +3 -0
  40. package/browser/shared/workspace-columns.mjs +1 -1
  41. package/browser/shared/workspace-look.mjs +21 -8
  42. package/browser/shared/workspace-registry.mjs +6 -3
  43. package/browser/shared/workspace.mjs +37 -10
  44. package/browser/shared/writing-preferences.mjs +2 -42
  45. package/dist/chunk-25LYSMAE.mjs +2 -0
  46. package/dist/chunk-2I6ZVC5O.mjs +2 -0
  47. package/dist/{chunk-M4NRDYI5.mjs → chunk-2MYTOOP6.mjs} +1 -1
  48. package/dist/chunk-2VNENLER.mjs +2 -0
  49. package/dist/chunk-3FERXZF5.mjs +4 -0
  50. package/dist/chunk-3M6SBBGU.mjs +2 -0
  51. package/dist/chunk-3VCAAF34.mjs +2 -0
  52. package/dist/{chunk-JXXHAXYH.mjs → chunk-3ZTRLGSA.mjs} +1 -1
  53. package/dist/chunk-4FRA5AUE.mjs +2 -0
  54. package/dist/chunk-4LR2QEC2.mjs +4 -0
  55. package/dist/chunk-56SVJENP.mjs +966 -0
  56. package/dist/chunk-5CQISL2G.mjs +4 -0
  57. package/dist/{chunk-RRKJMHNX.mjs → chunk-5I5ZDDWC.mjs} +5 -5
  58. package/dist/chunk-5IHDLEB4.mjs +10 -0
  59. package/dist/chunk-5LRDMV7O.mjs +2 -0
  60. package/dist/chunk-5MVUYRKG.mjs +5 -0
  61. package/dist/chunk-5TLLIZT7.mjs +2 -0
  62. package/dist/chunk-6ILJWFYW.mjs +4 -0
  63. package/dist/chunk-6N25CJ6Y.mjs +3 -0
  64. package/dist/{chunk-SQ6Y2ZMA.mjs → chunk-7DTINW6U.mjs} +2 -2
  65. package/dist/chunk-7KWAGKIK.mjs +2 -0
  66. package/dist/chunk-7WNUOAFK.mjs +2 -0
  67. package/dist/chunk-7XCRW5RC.mjs +2 -0
  68. package/dist/{chunk-ERE2BXYV.mjs → chunk-7XSDTILF.mjs} +1 -1
  69. package/dist/chunk-ABKYFOVR.mjs +2 -0
  70. package/dist/chunk-AMUF7PUN.mjs +2 -0
  71. package/dist/{chunk-PLB7L22J.mjs → chunk-B2EIMERT.mjs} +2 -2
  72. package/dist/{chunk-QNECWMGR.mjs → chunk-B45IAAU6.mjs} +1 -1
  73. package/dist/chunk-B6RAGF4R.mjs +2 -0
  74. package/dist/chunk-BSJKFE7I.mjs +4 -0
  75. package/dist/chunk-C72EEVLK.mjs +2 -0
  76. package/dist/chunk-CRAUKZ23.mjs +4 -0
  77. package/dist/chunk-F4CT35KL.mjs +2 -0
  78. package/dist/chunk-F63BNJLG.mjs +2 -0
  79. package/dist/chunk-FBKUPS44.mjs +2 -0
  80. package/dist/chunk-FL52ZL5Z.mjs +15 -0
  81. package/dist/chunk-FOZCU4VW.mjs +2 -0
  82. package/dist/chunk-G5HV7BC3.mjs +2 -0
  83. package/dist/{chunk-ERLAIBOA.mjs → chunk-GB5SOYQJ.mjs} +2 -2
  84. package/dist/chunk-GN3SG3IF.mjs +2 -0
  85. package/dist/{chunk-6QWQXHAV.mjs → chunk-HFTBVEZK.mjs} +1 -1
  86. package/dist/chunk-IOW5HLRK.mjs +2 -0
  87. package/dist/chunk-IQ3GJNTI.mjs +6 -0
  88. package/dist/chunk-K6SPFBUJ.mjs +2 -0
  89. package/dist/chunk-K7Y7SPTS.mjs +2 -0
  90. package/dist/chunk-L2IJCEUH.mjs +2 -0
  91. package/dist/{chunk-GPIWQ4X4.mjs → chunk-L3VT6LM4.mjs} +1 -1
  92. package/dist/chunk-L4WLQYFC.mjs +5 -0
  93. package/dist/{chunk-FFV733MA.mjs → chunk-LAMCAGK6.mjs} +1 -1
  94. package/dist/chunk-LHGKPMTI.mjs +2 -0
  95. package/dist/chunk-LJZIYVNA.mjs +3 -0
  96. package/dist/chunk-LSVCTLS2.mjs +2 -0
  97. package/dist/chunk-LZY74XTP.mjs +2 -0
  98. package/dist/chunk-MC4LRSVH.mjs +2 -0
  99. package/dist/chunk-MCEXN4G5.mjs +2 -0
  100. package/dist/chunk-MTLAOCFF.mjs +181 -0
  101. package/dist/chunk-MZ66LN3B.mjs +2 -0
  102. package/dist/chunk-N5QWJRRI.mjs +2 -0
  103. package/dist/chunk-NF4MMOUB.mjs +2 -0
  104. package/dist/chunk-NHJYAJ73.mjs +3 -0
  105. package/dist/chunk-NRSD7SVY.mjs +2 -0
  106. package/dist/chunk-NT23I4XW.mjs +2 -0
  107. package/dist/chunk-NUALABIS.mjs +3 -0
  108. package/dist/chunk-NW6LAU22.mjs +2 -0
  109. package/dist/chunk-NWWHDGKF.mjs +5 -0
  110. package/dist/chunk-OFRCVMSJ.mjs +2 -0
  111. package/dist/chunk-OKVQQ3CX.mjs +4 -0
  112. package/dist/chunk-OM24O4KR.mjs +8 -0
  113. package/dist/{chunk-4B2TB5K2.mjs → chunk-PBMOC7KA.mjs} +2 -2
  114. package/dist/chunk-PVTCP43W.mjs +2 -0
  115. package/dist/chunk-Q62HZAJS.mjs +2 -0
  116. package/dist/chunk-QBJWIR3Q.mjs +2 -0
  117. package/dist/chunk-QDSEZX7Z.mjs +6 -0
  118. package/dist/chunk-QR4V4A2Z.mjs +15 -0
  119. package/dist/{chunk-QVGOPHOF.mjs → chunk-QRLVVZ3R.mjs} +1 -1
  120. package/dist/chunk-QW3QG67J.mjs +2 -0
  121. package/dist/chunk-R2T2EVWY.mjs +8 -0
  122. package/dist/{chunk-GJJRBGMY.mjs → chunk-R5RERE6G.mjs} +1 -1
  123. package/dist/chunk-RFHEWT3Y.mjs +5 -0
  124. package/dist/chunk-RS2Z2JQP.mjs +2 -0
  125. package/dist/chunk-S6YEC4GE.mjs +16 -0
  126. package/dist/chunk-SHZLMGGW.mjs +2 -0
  127. package/dist/chunk-TALJQM2O.mjs +2 -0
  128. package/dist/chunk-TLNJWEFY.mjs +22 -0
  129. package/dist/{chunk-6Q7ASAXJ.mjs → chunk-TQZU7D7C.mjs} +1 -1
  130. package/dist/chunk-UTKNWYBA.mjs +2 -0
  131. package/dist/chunk-V3TM3TEN.mjs +2 -0
  132. package/dist/chunk-V3XROSP5.mjs +7 -0
  133. package/dist/{chunk-6QBHU4DF.mjs → chunk-V5JTW2LH.mjs} +1 -1
  134. package/dist/chunk-VAXLSISW.mjs +4 -0
  135. package/dist/chunk-VBHI3RG6.mjs +2 -0
  136. package/dist/{chunk-6L6V7YR2.mjs → chunk-VKZJRGDR.mjs} +1 -1
  137. package/dist/chunk-VZXZM7NS.mjs +2 -0
  138. package/dist/chunk-WDS6HEPE.mjs +2 -0
  139. package/dist/chunk-WHGANNEY.mjs +13 -0
  140. package/dist/chunk-WMJWC4QY.mjs +56 -0
  141. package/dist/{chunk-VZ2RQ3AM.mjs → chunk-WWONJJQS.mjs} +1 -1
  142. package/dist/chunk-X4WNLFIK.mjs +2 -0
  143. package/dist/chunk-XNNCQROX.mjs +11 -0
  144. package/dist/chunk-XRYECF23.mjs +170 -0
  145. package/dist/{chunk-K3JKPFL5.mjs → chunk-Z4NEXXFK.mjs} +1 -1
  146. package/dist/{chunk-236JJXWY.mjs → chunk-ZFVF2YPV.mjs} +2 -2
  147. package/dist/chunk-ZM2IX3R2.mjs +2 -0
  148. package/dist/chunk-ZNGGDUZI.mjs +2 -0
  149. package/dist/chunk-ZOEJQOKT.mjs +2 -0
  150. package/dist/cli.mjs +1 -1
  151. package/dist/server.mjs +1 -1
  152. package/dist/update-fetch.mjs +1 -1
  153. package/dist/worker.mjs +1 -1
  154. package/kit/runtime.js +1 -0
  155. package/package.json +1 -1
  156. package/release.json +4 -4
  157. package/skill/SKILL.md +54 -148
  158. package/skill/references/building-blocks.md +4 -4
  159. package/skill/references/charts-and-figures.md +73 -0
  160. package/skill/references/extensions.md +47 -4
  161. package/skill/references/pages-and-data.md +22 -3
  162. package/skill/references/preference-files.md +7 -0
  163. package/skill/references/previews.md +17 -0
  164. package/skill/references/writing-html.md +21 -82
  165. package/web/assets/index-B4uUluLM.js +15 -0
  166. package/web/assets/index-C3vHT8sH.css +1 -0
  167. package/web/index.html +2 -2
  168. package/dist/chunk-2KAVXMKG.mjs +0 -4
  169. package/dist/chunk-2T4PZQEP.mjs +0 -2
  170. package/dist/chunk-3SKOU6OZ.mjs +0 -10
  171. package/dist/chunk-3XZOA7AH.mjs +0 -170
  172. package/dist/chunk-4KUO7R2M.mjs +0 -16
  173. package/dist/chunk-4OZWXZE5.mjs +0 -5
  174. package/dist/chunk-4SNV4HA5.mjs +0 -2
  175. package/dist/chunk-53XDTHTG.mjs +0 -4
  176. package/dist/chunk-5XV3YYLG.mjs +0 -2
  177. package/dist/chunk-65NTKF4N.mjs +0 -6
  178. package/dist/chunk-6GV3CBB2.mjs +0 -2
  179. package/dist/chunk-6NLXUKAY.mjs +0 -4
  180. package/dist/chunk-6XD6U3QA.mjs +0 -5
  181. package/dist/chunk-7EFHNQ5B.mjs +0 -3
  182. package/dist/chunk-7ISBBDJR.mjs +0 -2
  183. package/dist/chunk-7M2BQQGZ.mjs +0 -2
  184. package/dist/chunk-7UZUQQ7Q.mjs +0 -554
  185. package/dist/chunk-ALZ6ZENZ.mjs +0 -3
  186. package/dist/chunk-BLNQUR5R.mjs +0 -168
  187. package/dist/chunk-BMX3VUHY.mjs +0 -2
  188. package/dist/chunk-BN7M3IN7.mjs +0 -8
  189. package/dist/chunk-C257H6IA.mjs +0 -2
  190. package/dist/chunk-CHQU37CA.mjs +0 -2
  191. package/dist/chunk-DR73Y2UJ.mjs +0 -3
  192. package/dist/chunk-E4IHAIJ7.mjs +0 -2
  193. package/dist/chunk-EURLTOTZ.mjs +0 -4
  194. package/dist/chunk-F4ZA6JRZ.mjs +0 -3
  195. package/dist/chunk-GKOBB6DH.mjs +0 -2
  196. package/dist/chunk-GMJD7ID3.mjs +0 -2
  197. package/dist/chunk-IA2SIEJQ.mjs +0 -2
  198. package/dist/chunk-JEUK3ZO7.mjs +0 -2
  199. package/dist/chunk-JPG2LBQM.mjs +0 -11
  200. package/dist/chunk-KLQP46Y3.mjs +0 -4
  201. package/dist/chunk-LMUZQK5O.mjs +0 -2
  202. package/dist/chunk-MKIBJTJZ.mjs +0 -6
  203. package/dist/chunk-MNWJ4EZY.mjs +0 -2
  204. package/dist/chunk-NHP66IWR.mjs +0 -5
  205. package/dist/chunk-OEIJLMPI.mjs +0 -2
  206. package/dist/chunk-PDZR3L3C.mjs +0 -2
  207. package/dist/chunk-PUOQ65NC.mjs +0 -2
  208. package/dist/chunk-Q4MS6OFC.mjs +0 -2
  209. package/dist/chunk-Q7P3Q5YX.mjs +0 -13
  210. package/dist/chunk-QP7BOHE4.mjs +0 -2
  211. package/dist/chunk-S3SX3COT.mjs +0 -20
  212. package/dist/chunk-TANZRINB.mjs +0 -2
  213. package/dist/chunk-UGWMMEJ5.mjs +0 -15
  214. package/dist/chunk-ULXSPX5H.mjs +0 -5
  215. package/dist/chunk-USIHBCSW.mjs +0 -15
  216. package/dist/chunk-VPMRP2TL.mjs +0 -2
  217. package/dist/chunk-WFGPMCTZ.mjs +0 -4
  218. package/dist/chunk-XZCFPKGO.mjs +0 -2
  219. package/dist/chunk-ZFGMJVJC.mjs +0 -2
  220. package/web/assets/index-FLb9jCfl.css +0 -1
  221. package/web/assets/index-czjrXVjf.js +0 -15
  222. /package/dist/{chunk-PAREWQGB.mjs → chunk-NOGQX56R.mjs} +0 -0
@@ -0,0 +1,10 @@
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 i,q as C}from"./chunk-B2EIMERT.mjs";import{a as g,c as w}from"./chunk-HYMEEXKN.mjs";import{g as E,o as A,p as y}from"./chunk-TKWEX4FD.mjs";import u from"node:path";import{attr as N,hasClass as Y,walk as O}from"../browser/shared/html-tree.mjs";import{projectRoot as P,sdkDirectory as k,typeRoots as H}from"../browser/shared/paths.mjs";var V=new Set(["application/ecmascript","application/javascript","application/x-ecmascript","application/x-javascript","text/ecmascript","text/javascript","text/javascript1.0","text/javascript1.1","text/javascript1.2","text/javascript1.3","text/javascript1.4","text/javascript1.5","text/jscript","text/livescript","text/x-ecmascript","text/x-javascript"]);function b(t,{diffs:s=!1,tree:n=g(t)}={}){let r=[];return O(n,a=>{if(a.tagName!=="script"||N(a,"src")!==void 0)return;let o=(N(a,"type")||"").trim().toLowerCase(),l=s&&o==="application/json"&&a.parentNode?.tagName?a.parentNode:null,e=l&&Y(l,"doc-diff")?"__declaredDiff(":void 0;if(!e&&o&&o!=="module"&&!V.has(o))return;let{startTag:c,endTag:p}=a.sourceCodeLocation??{};c&&r.push({start:c.endOffset,end:p?.startOffset??t.length,module:o==="module",...e?{call:e}:{}})},{inTemplates:!1}),r}function L(t,s,n=[]){let r=[],a=0,o="",l=e=>e.replace(/[^\r\n]/g," ");for(let{start:e,end:c,call:p}of s){let f=o+l(t.slice(a+o.length,e));if(p){let h=q(f,p,o.length);if(h===null){n.push(e);continue}f=h}r.push(f,t.slice(e,c)),a=c,o=p?");":""}return r.push(o+l(t.slice(a+o.length)),`
3
+ export {};
4
+ `),r.join("")}function q(t,s,n){let r=t.length;for(;;){let a=Math.max(t.lastIndexOf(`
5
+ `,r-1)+1,n),o=t[r-1]==="\r"?r-1:r;if(o-a>=s.length)return t.slice(0,o-s.length)+s+t.slice(o);if(a<=n)return null;r=a-1}}function Nt(t,s=g(t)){return L(t,b(t,{tree:s}))}var X=new Set(["href","src","action","formaction"]),Z=t=>{try{return decodeURIComponent(t)}catch{return t}};function Q(t,s){let n=b(t,{tree:s}).map(({start:r,end:a})=>({code:t.slice(r,a),start:r,where:"the document's script"}));return O(s,r=>{for(let{name:a,value:o}of r.attrs){let l=r.sourceCodeLocation?.attrs?.[a]?.startLine??r.sourceCodeLocation?.startLine,e=X.has(a)?o.replace(/[\t\n\r]/g,"").replace(/^[\u0000-\u0020]+/,""):"";/^on[a-z]+$/.test(a)?n.push({code:o,line:l,where:`the ${a} attribute of <${r.tagName}>`}):/^javascript:/i.test(e)&&n.push({code:Z(e.slice(11)),line:l,where:`the javascript: address of <${r.tagName} ${a}>`})}},{inTemplates:!1}),n}var R=new Set(["fetch","XMLHttpRequest","WebSocket","EventSource","sendBeacon","import"]),S=new Set(["window","globalThis","self"]),tt=t=>i.isIdentifier(t)?t.text==="navigator":i.isPropertyAccessExpression(t)&&t.name.text==="navigator"&&i.isIdentifier(t.expression)&&S.has(t.expression.text);function I(t){let{initializer:s}=i.walkUpBindingElementsAndPatterns(t);return!!s&&i.isIdentifier(s)&&S.has(s.text)}function et(t){let s=t.parent;return i.isPropertyAccessExpression(s)&&s.name===t?i.isIdentifier(s.expression)&&S.has(s.expression.text):i.isBindingElement(s)&&s.propertyName===t?I(s):!((i.isPropertyAssignment(s)||i.isMethodDeclaration(s)||i.isPropertyDeclaration(s)||i.isGetAccessorDeclaration(s)||i.isSetAccessorDeclaration(s))&&s.name===t)}function st(t,s){return i.isIdentifier(t)&&s.has(t.text)&&et(t)?{name:t.text,reference:i.isPropertyAccessExpression(t.parent)&&t.parent.name===t?t.parent:t}:i.isElementAccessExpression(t)&&i.isIdentifier(t.expression)&&S.has(t.expression.text)&&i.isStringLiteralLike(t.argumentExpression)&&s.has(t.argumentExpression.text)?{name:t.argumentExpression.text,reference:t}:i.isPropertyAccessExpression(t)&&s.has(t.name.text)&&t.name.text==="sendBeacon"&&tt(t.expression)?{name:"sendBeacon",reference:t}:s.has("import")&&i.isCallExpression(t)&&t.expression.kind===i.SyntaxKind.ImportKeyword?{name:"import",reference:t.expression}:null}function nt(t,s){let n=new Map,r=(e,c)=>{let p=e.parent;for(;p&&!c(p);)p=p.parent;return p??t},a=e=>i.isFunctionLike(e)||i.isBlock(e)||i.isCaseBlock(e)||i.isForStatement(e)||i.isForInStatement(e)||i.isForOfStatement(e),o=e=>i.isFunctionExpression(e)||i.isClassExpression(e)?e:i.isFunctionDeclaration(e)||i.isClassDeclaration(e)?r(e,a):i.isCatchClause(e.parent)?e.parent:r(e,i.getCombinedNodeFlags(e)&i.NodeFlags.BlockScoped?a:i.isFunctionLike),l=e=>{(i.isParameter(e)||i.isVariableDeclaration(e)||i.isBindingElement(e)||i.isFunctionDeclaration(e)||i.isClassDeclaration(e)||i.isFunctionExpression(e)||i.isClassExpression(e))&&e.name&&i.isIdentifier(e.name)&&s.has(e.name.text)&&!(i.isBindingElement(e)&&I(e))&&n.set(e.name.text,[...n.get(e.name.text)??[],o(e)]),i.forEachChild(e,l)};return l(t),n}function rt(t,s=[]){for(let n=t;n;n=n.parent)if(s.includes(n))return!0;return!1}function Ft(t,s,{tree:n=g(t)}={}){let r=[];for(let{code:a,start:o,line:l,where:e}of Q(t,n))for(let{name:c,how:p,at:f}of $(a,s))r.push({name:c,how:p,line:l??w(t,o+f),where:e});return r.sort((a,o)=>a.line-o.line)}function $(t,s){if(![...s].some(l=>t.includes(l)))return[];let n=[],r=i.createSourceFile("code.js",t,i.ScriptTarget.Latest,!0,i.ScriptKind.JS),a=nt(r,s),o=l=>{let e=st(l,s),c=e?.reference.parent;if(e&&!i.isTypeOfExpression(c)&&!(i.isIdentifier(e.reference)&&rt(l,a.get(e.name)))){let p=(i.isCallExpression(c)||i.isNewExpression(c))&&c.expression===e.reference?i.isNewExpression(c)?"new":"call":"use";n.push({name:e.name,how:p,at:l.getStart(r)})}i.forEachChild(l,o)};return o(r),n}var it=new Set([2304,2552]),at=new Set([2300,2451,2448,2449,2450]),M=t=>it.has(t)||at.has(t)||t>=1e3&&t<2e3;function ot(t,s,n){if(!t.file||n.has(t)||M(t.code))return!1;let r=t.start??-1;return s.some(a=>!a.call&&a.start<=r&&r<a.end)}var ct=(t,s)=>/\bNumberValue\b/.test(t)||/\bd3\.(?:min|max|extent)\(/.test(s)?"; here d3 reads values of no type as strings: give the data its shape once with JSDoc, /** @type {Array<{ label: string, value: number }>} */ const rows = data;, and d3.min or d3.max may give undefined (?? 0)":"";function B(t){let s={allowJs:!0,checkJs:!0,noEmit:!0,allowUmdGlobalAccess:!0,strict:!0,noImplicitAny:!1,target:i.ScriptTarget.ES2022,module:i.ModuleKind.ESNext,moduleResolution:i.ModuleResolutionKind.Bundler,lib:["lib.es2022.d.ts","lib.dom.d.ts","lib.dom.iterable.d.ts"],types:["d3"],typeRoots:H,skipLibCheck:!1},n=i.createCompilerHost(s),r=n.readFile.bind(n),a=n.fileExists.bind(n);return n.readFile=o=>t.get(u.resolve(o))??r(o),n.fileExists=o=>t.has(u.resolve(o))||a(o),i.createProgram([u.join(k,"index.d.ts"),...t.keys()],s,n)}function _(t,s){let n=t.getSourceFiles().filter(r=>{let a=u.resolve(r.fileName);return s.has(a)||a.startsWith(k+u.sep)});return i.sortAndDeduplicateDiagnostics([...t.getConfigFileParsingDiagnostics(),...t.getOptionsDiagnostics(),...t.getSyntacticDiagnostics(),...t.getGlobalDiagnostics(),...n.flatMap(r=>t.getSemanticDiagnostics(r))])}var lt=/\bDoc[A-Z]\w*/,pt=(t,s)=>lt.test(s)||(t.relatedInformation??[]).some(({file:n})=>n&&u.resolve(n.fileName).startsWith(k+u.sep)),F={katex:"katex","katex-auto-render":"renderMathInElement"};function Ot(t,{assets:s=[]}={}){let n=u.join(P,"reports","__package__","kit.js"),r=t.replace(/^([ \t]*)(?:<!--|-->)/gm,"$1//"),a=s.filter(c=>Object.hasOwn(F,c)).map(c=>`declare const ${F[c]}: any;
6
+ `),o=B(new Map([[n,`${r}
7
+ export {};
8
+ `],...a.length?[[u.join(u.dirname(n),"assets.d.ts"),a.join("")]]:[]])),l=new Set(o.getSyntacticDiagnostics()),e=new Map;for(let c of _(o,new Set([n]))){if(!c.file||u.resolve(c.file.fileName)!==n)continue;let{line:p}=c.file.getLineAndCharacterOfPosition(c.start??0),f=i.flattenDiagnosticMessageText(c.messageText," "),h=`${p} ${f}`;e.has(h)||e.set(h,{line:p+1,code:c.code,message:f,refused:l.has(c)||M(c.code)||pt(c,f)})}return[...e.values()]}function Pt(t){let s=new Map,n=new Map,r=new Map,a=[];for(let e of t){let c=b(e.html,{diffs:!0}),p=[c.filter(m=>!m.module),...c.filter(m=>m.module).map(m=>[m])],f=u.join(P,"reports",u.basename(u.dirname(e.htmlPath)),u.basename(e.htmlPath)),h=[];p.forEach((m,x)=>{let d=`${f}.${x}.js`;s.set(d,L(e.html,m,h)),n.set(d,u.resolve(e.htmlPath)),r.set(d,m)});for(let m of h){let x=e.html.slice(0,m).split(`
9
+ `),d=u.resolve(e.htmlPath);a.push({htmlPath:u.resolve(e.htmlPath),text:`${d}:${x.length}:${x.at(-1).length+1} a declared diff's options could not be checked: write its <script type="application/json"> tag on a line of its own`})}}if(![...r.values()].some(e=>e.length))return a;let o=B(s),l=new Set(o.getSyntacticDiagnostics());return[...a,..._(o,new Set(s.keys())).map(e=>{let c=e.file?.getLineAndCharacterOfPosition(e.start||0),p=e.file?n.get(u.resolve(e.file.fileName))??null:null,f=p||e.file?.fileName,h=f?u.resolve(f):"SDK",m=i.flattenDiagnosticMessageText(e.messageText," "),x=p!==null&&ot(e,r.get(u.resolve(e.file.fileName))??[],l);return{htmlPath:p,text:`${h}${c?`:${c.line+1}:${c.character+1}`:""} TS${e.code}: ${m}`,typeOnly:x,...x?{note:`line ${c.line+1}: TS${e.code} in the document's script (column ${c.character+1}): ${m} (strict TypeScript's word on a type: a note, not a failure; the browser runs the script as written: guard the value where it can really be null or of another type${ct(m,e.file.text.split(`
10
+ `)[c.line]??"")})`}:{}}})]}import{readFileSync as K}from"node:fs";import{BODY as ut,isInstance as ft}from"../browser/shared/components/index.mjs";import{ATTRIBUTE as G,PACKAGE_MARK as v}from"../browser/shared/components/installed.mjs";import{cssReferences as W,cssWithAddresses as mt}from"../browser/shared/css-references.mjs";import{packageScript as ht,scriptText as xt,styleText as gt}from"../browser/shared/export-wrap.mjs";import{attr as D,walk as U}from"../browser/shared/html-tree.mjs";import{mediaTypeOf as dt}from"../browser/shared/media.mjs";var wt=new RegExp(G,"i");function Yt(t,s=null,n=null){if(!wt.test(t))return[];let{packages:r}=s??E(),a=new Set;return U(n??g(t),o=>{ft(o)&&a.add(D(o,G))},ut),[...a].map(o=>r.get(o)).filter(Boolean)}function Ht(t,s){if(s.length===0)return t;let n=s.map(A);return C(t,{styles:n.flatMap(({styles:r})=>r),scripts:n.flatMap(({scripts:r})=>r)})}function j(t,s){try{return K(y(t,s)).toString("utf8").replace(/^\uFEFF/,"")}catch{return null}}var J=/^(?:data:|#|$)/i,St=/^(?:[a-z][a-z0-9+.-]*:|\/)/i,z=t=>t.replace(/^\.\//,"").replace(/[?#].*$/,""),Et=(t,s)=>mt(s,W(s),({value:n,kind:r})=>{let a=z(n);if(r==="import"||J.test(n)||!t.files.includes(a))return null;let o=y(t,a);return o&&`data:${dt(a)};base64,${K(o).toString("base64")}`}),T=new Set(["eval","Function"]),yt=new Set([...R,...T]),kt={call:t=>`calls ${t}(\u2026)`,new:t=>`creates new ${t}(\u2026)`,use:t=>`uses ${t}`};function bt(t){if(!t.files.includes("style.css"))return[];let s=j(t,"style.css")??"";return W(s).flatMap(({value:n,kind:r,index:a})=>{let o=r==="import"?"has an @import, which an export cannot hold: write what it imports into style.css":J.test(n)?null:St.test(n)?`loads ${n}: external resources are not portable`:t.files.includes(z(n))?null:`names ${n}, which an export cannot hold: put the file in the package and name it in its assets`;return o?[{line:w(s,a),what:o}]:[]})}function $t(t){if(!t.files.includes("kit.js"))return[];let s=j(t,"kit.js")??"";return $(s,yt).filter(({name:n,how:r})=>r!=="use"||!T.has(n)).map(({name:n,how:r,at:a})=>({line:w(s,a),what:`${kt[r](n)}: ${T.has(n)?"an export runs no code made from words":"the export blocks the network; put its data in the instance"}`}))}var Vt=t=>t.flatMap(s=>[...bt(s).map(({what:n})=>`${s.id}: its style.css ${n}`),...$t(s).map(({line:n,what:r})=>`${s.id}: line ${n} of its kit.js ${r}`)]);function vt(t,s){let n=`${v}="${t.id}"`,r=j(t,s);return r===null?null:s==="kit.js"?`<script ${n}>${xt(ht(r))}</script>`:`<style ${n}>${gt(Et(t,r))}</style>`}function qt(t,s=null){if(!t.includes(v))return t;let{packages:n}=s??E(),r=[];U(g(t),l=>{let e=n.get(D(l,v)),c=l.tagName==="link"?"style.css":l.tagName==="script"&&D(l,"src")!==void 0?"kit.js":null,p=l.sourceCodeLocation,f=e&&c&&p?vt(e,c):null;f&&r.push({start:p.startOffset,end:p.endOffset,copy:f})},{inTemplates:!1});let a="",o=0;for(let{start:l,end:e,copy:c}of r)a+=t.slice(o,l)+c,o=e;return a+t.slice(o)}export{Nt as a,R as b,Ft as c,$ as d,Ot as e,Pt as f,Yt as g,Ht as h,j as i,bt as j,$t as k,Vt as l,qt as m};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{a as ae}from"./chunk-VZXZM7NS.mjs";import{b as Q,c as V}from"./chunk-342HXE3Q.mjs";import{a as L,b as W,c as Y,d as ee}from"./chunk-OKVQQ3CX.mjs";import{a as Z,b as G,h as H}from"./chunk-X4WNLFIK.mjs";import{b as M,c as te,d as oe,e as N,f as R,g as se,h as re}from"./chunk-5MVUYRKG.mjs";import{a as O,k as K}from"./chunk-LHGKPMTI.mjs";import"./chunk-TLNJWEFY.mjs";import"./chunk-ZOEJQOKT.mjs";import{b as I}from"./chunk-LJZIYVNA.mjs";import"./chunk-IA4PSIMD.mjs";import{k as P,n as z,p as C,q as U,t as q,u as T,v as _}from"./chunk-QR4V4A2Z.mjs";import"./chunk-ZTHICSSF.mjs";import{k as X}from"./chunk-TQZU7D7C.mjs";import"./chunk-5IHDLEB4.mjs";import"./chunk-B2EIMERT.mjs";import{c as J}from"./chunk-2OHANJ6Q.mjs";import"./chunk-6N25CJ6Y.mjs";import"./chunk-F4CT35KL.mjs";import"./chunk-BFJGHSQN.mjs";import"./chunk-U5XL7D6A.mjs";import"./chunk-6ILJWFYW.mjs";import{b as B}from"./chunk-VRPVVMRB.mjs";import"./chunk-HYMEEXKN.mjs";import{b as d,j as D}from"./chunk-L4WLQYFC.mjs";import"./chunk-NOGQX56R.mjs";import"./chunk-UMHUSOPJ.mjs";import"./chunk-W5NPH5UA.mjs";import"./chunk-ECZBLQKK.mjs";import"./chunk-E7656LR7.mjs";import"./chunk-TKWEX4FD.mjs";import"./chunk-A55HN5OK.mjs";import"./chunk-5L7RYZCL.mjs";import{writeAtomic as de}from"../browser/shared/files.mjs";import pe from"node:fs/promises";import y from"node:path";import{readOutline as ne}from"../browser/shared/outline.mjs";import{exportsDirectory as le,reportsDirectory as m}from"../browser/shared/paths.mjs";import{documentDirectory as ge,documentFiles as he,layoutOf as we}from"../browser/shared/workspace.mjs";function ie(t=m){let r=I({root:t,read:async f=>{let s=await pe.readFile(he(ge(f,t)).html,"utf8").catch(()=>null);return s===null?null:{source:s,text:B(s).text}},activity:re({file:we(t).activity})});return f=>r.snapshot(f)}var be=(t,o)=>{let[r,f]=[y.resolve(t),y.resolve(o)];return process.platform==="linux"?r===f:r.toLowerCase()===f.toLowerCase()},ye=M,fe={pdf:"PDF",markdown:"Markdown",html:"\u79BB\u7EBF\u6587\u4EF6"};function $e(t,o){let r=o.get("--format")??([...t,...o.keys()].some(n=>["--no-files","--subpages","--folders","--out"].includes(n))?"html":null);if(r!==null&&!Object.hasOwn(M,r))throw new d(`--format takes pdf, markdown or html, not ${r}.`);if((o.has("--paper")||o.has("--scale"))&&r!=="pdf")throw new d("--paper and --scale are for --format pdf.");if(t.has("--folders")&&!t.has("--subpages"))throw new d("--folders makes a folder for each page's subpages: it goes with --subpages.");if(r===null)return null;let f="A4";if(o.has("--paper")&&(f=O.find(n=>n.toLowerCase()===o.get("--paper").toLowerCase()),!f))throw new d(`--paper takes ${O.join(", ")}, not ${o.get("--paper")}.`);let s=1;if(o.has("--scale")){let n=Number(o.get("--scale"));if(!(n>10&&n<200))throw new d(`--scale takes a percentage above 10 and below 200 (100 is the page as it is), not ${o.get("--scale")}.`);s=n/100}let g={format:r,content:t.has("--no-files")?"no_files":"everything",subpages:t.has("--subpages"),folders:t.has("--folders"),paper:f,scale:s};if(!te(g))throw new d("Not an export the workbench makes.");let h=o.get("--out");return r==="html"&&g.content==="everything"&&!g.subpages&&h===void 0?null:{exporting:g,out:h}}var xe=(t,o)=>t.reason==="check"&&t.failures?.length?t.failures.map(r=>t.slug===o?r:`${t.slug}: ${r}`):[t.message],ke=t=>{try{return J(t).map(o=>o.name)}catch{return[]}};async function Te(t){let{slugs:o,options:r,values:f}=await D({options:["--allow-failures","--no-files","--subpages","--folders"],values:["--format","--paper","--scale","--out"],argv:t}),s=$e(r,f);o.length===0&&(console.error(ae()),process.exit(1));let g=s?N({reportsDirectory:m,titleOf:R(m),outline:()=>ne(m),render:null,format:s.exporting.format}):null,h=new Map;if(s?.exporting.subpages)for(let e of o)h.set(e,await se(g,e));let n=[...new Set([...o,...[...h.values()].flat()])],ce=await X(n),w=await P(n,{prepare:L({say:!1})}),u=await Z(n.filter(e=>!w.has(e)));await G(n.filter(e=>w.has(e)||u.failures.has(e))),await Y(n),await ee(n);let $=n.filter(e=>!w.has(e)&&!u.failures.has(e)),A=L({say:!1}),b,x=[],c,S=[],E=new Map,v=new Map;if(!s)({built:b,exported:x,failures:c}=$.length>0?await U($,{prepare:A,workspace:ie()}):{built:[],exported:[],failures:new Map});else{({built:b,failures:c}=$.length>0?await z($,{prepare:A}):{built:[],failures:new Map});for(let[i,p]of[...w,...u.failures])c.set(i,p);for(let[i,p]of c)E.set(i,p);c=new Map;let e=await C({directory:m,workspace:ie()}),a=s.out===void 0?le:y.resolve(s.out),{format:l}=s.exporting;for(let i of o)try{let p=await oe(i,s.exporting,N({reportsDirectory:m,titleOf:R(m),outline:()=>ne(m),render:e,format:l,made:v})),k=p.type==="application/zip",F=!k&&l==="html"&&s.exporting.content==="no_files"&&be(a,le),j=k?`${i}.zip`:`${i}${F?"-no-files":""}.${ye[l]}`;await pe.mkdir(a,{recursive:!0}),await de(y.join(a,j),p.data);let ue=k?`${fe[l]} \u538B\u7F29\u5305`:F?"\u79BB\u7EBF\u6587\u4EF6\uFF0C\u4E0D\u542B\u6587\u4EF6\u548C\u56FE\u7247":fe[l];S.push({slug:i,file:y.join(a,j),bytes:p.data.length,label:ue,names:k?ke(p.data):[]})}catch(p){c.set(i,xe(p,i))}}if(await K(),!s)for(let[e,a]of[...w,...u.failures])c.set(e,a);await T(c,{exportNote:!s});for(let[e,a]of E){console.log(`\u95EE\u9898\uFF1A${e} \u6CA1\u901A\u8FC7\u68C0\u67E5\uFF08${a.length} \u5904\uFF09\uFF0C\u6587\u4EF6\u7167\u5199\u4E86\uFF0C\u548C\u754C\u9762\u7684\u300C\u5BFC\u51FA\u300D\u4E00\u6837\uFF1B\u6539\u597D\u540E\u518D\u5BFC\u51FA\u4E00\u6B21\uFF1A`);for(let l of a)console.log(` - ${l}`)}await ce.keep(s?[...v.keys()]:x.map(({slug:e})=>e),s?v:null);let me=new Map(b.map(({report:e,removed:a})=>[e.slug,a]));for(let{slug:e,bytes:a,sha256:l}of x){let i=me.get(e),p=i.length>0?`; shared scripts and styles left out (unused): ${i.join(", ")}`:"";console.log(`Exported ${Q(e)} (${a.toLocaleString("en-US")} bytes, sha256 ${l})${p}`)}for(let{file:e,bytes:a,names:l}of S)console.log(`Exported ${e} (${a.toLocaleString("en-US")} bytes)`),l.length>0&&console.log(` holds ${l.length} file${l.length===1?"":"s"}: ${l.slice(0,12).join(", ")}${l.length>12?", \u2026":""}`);q(b.map(({report:e})=>e)),W(b.map(({report:e})=>e));for(let e of u.lines)console.log(e);u.written.length>0&&console.log(H(u.written));for(let{slug:e}of x)console.log(V(e));for(let{file:e,label:a}of S)console.log(`\u4EA4\u7ED9\u7528\u6237\uFF08${a}\uFF09\uFF1A${e}`);_(c,{above:!0,allow:r.has("--allow-failures")})}export{Te as run};
@@ -0,0 +1,5 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{b as Z,m as G,n as H}from"./chunk-LHGKPMTI.mjs";import{c as q,d as K}from"./chunk-QR4V4A2Z.mjs";import{a as V}from"./chunk-2OHANJ6Q.mjs";import B from"node:fs/promises";import pe from"node:path";import{Worker as ae}from"node:worker_threads";import{refusal as ce,said as le}from"../browser/shared/i18n/index.mjs";var fe=6e4,O=null,ue=0,I=0,A=new Map;function me(){O=new ae(new URL("./worker.mjs",import.meta.url)),O.on("message",({id:r,result:s,error:t})=>{let i=A.get(r);i&&(A.delete(r),t?i.reject(Object.assign(new Error(t.message),t)):i.resolve(s),A.size===0&&(O?.unref(),de()))});let n=r=>{for(let s of A.values())s.reject(r);A.clear(),O=null};O.on("error",n),O.on("exit",r=>n(ce(le("\u8F6C\u6362\u8FDB\u7A0B\u610F\u5916\u9000\u51FA\uFF08{0}\uFF09",r))))}function de(){clearTimeout(I),I=setTimeout(()=>{if(A.size===0&&O){let n=O;O=null,n.removeAllListeners("exit"),n.terminate()}},fe),I.unref?.()}function Q(n,r){clearTimeout(I),O||me();let s=++ue;return new Promise((t,i)=>{A.set(s,{resolve:t,reject:i}),O.ref(),O.postMessage({id:s,type:n,payload:r})})}import{pageLanguage as he}from"../browser/shared/components/page.mjs";import{exportSourceOf as we}from"../browser/shared/export-wrap.mjs";import{documentLinks as ge}from"../browser/shared/reports.mjs";function M(n){return String(n??"").replace(/[\\/:*?"<>|\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim().slice(0,100).trim()||"Untitled"}function C(n,r){let s=n.lastIndexOf("."),[t,i]=s>0?[n.slice(0,s),n.slice(s)]:[n,""];for(let a=0;;a+=1){let o=a===0?n:`${t} ${a}${i}`;if(!r.has(o.toLowerCase()))return r.add(o.toLowerCase()),o}}function E(n,r){let s=n.split("/").slice(0,-1),t=r.split("/"),i=0;for(;i<s.length&&i<t.length-1&&s[i]===t[i];)i+=1;return[...s.slice(i).map(()=>".."),...t.slice(i)].map(o=>o===".."?o:encodeURIComponent(o).replace(/\(/g,"%28").replace(/\)/g,"%29")).join("/")}import{documentDirectory as X,documentFiles as ee}from"../browser/shared/workspace.mjs";var te={markdown:"md",html:"html",pdf:"pdf"},ye={markdown:"text/markdown; charset=utf-8",html:"text/html; charset=utf-8",pdf:"application/pdf"},ke=n=>typeof n=="number"&&n>.1&&n<2;function Be(n){let{format:r,content:s="everything",subpages:t=!1,folders:i=!0,paper:a="A4",scale:o=1}=n??{};return Object.hasOwn(te,r)&&["everything","no_files"].includes(s)&&typeof t=="boolean"&&typeof i=="boolean"&&["A4","A3","Letter","Legal","Tabloid"].includes(a)&&ke(o)}async function Je(n,r,s){let{format:t,content:i="everything",subpages:a=!1,folders:o=!0,paper:p="A4",scale:k=1}=r,b=te[t],l=i==="everything",v=[],$=new Map,N=e=>$.get(e)??$.set(e,new Set).get(e),c=async(e,u)=>{let g=await s.titleOf(e),d=C(`${M(g)}.${b}`,N(u)),x=u?`${u}/${d}`:d,T=o?x.slice(0,-(b.length+1)):"";if(v.push({slug:e,title:g,file:x,folder:T,files:u?`${u}/assets`:"assets"}),a)for(let R of await s.childrenOf(e))await c(R,T)};await c(n,"");let{links:y}=await s.links(),h=(e,u)=>q(u,e.slug,g=>{let d=t==="pdf"?null:v.find(x=>x.slug===g)?.file??null;return d&&E(e.file,d)},{blocks:t!=="markdown",links:y}),m=[],w=[];for(let e of v)if(t==="markdown"){await s.check(e.slug);let u=X(e.slug,s.reportsDirectory),g=K(await B.readFile(ee(u).html,"utf8"),{slug:e.slug,mode:"words",reportsDirectory:s.reportsDirectory}),d=h(e,g),x=l&&!!Z(),{text:T,files:R,charts:ie,charted:_}=await Q("markdown",{source:d,title:e.title,pictures:x}),S=T,D=new Map;if(R.forEach(({src:j,name:P},L)=>{D.has(j)||(D.set(j,`${e.files}/${C(M(P),N(e.files))}`),l&&w.push({from:pe.join(u,j),name:D.get(j)}));let F=D.get(j);S=S.replace(`\0F${L}\0`,()=>E(e.file,F))}),x&&ie>0&&S.includes("\0C")){let j=await H(await s.offline(e.slug,{files:!0})).catch(()=>[]);S=S.replace(/^.*\u0000C(\d+)\u0000.*$/gm,(P,L)=>{let F=j[Number(L)];if(!F)return"\0gone\0";let W=`${e.files}/${C(he(d)==="en"?_[Number(L)]?"Chart.png":"Figure.png":_[Number(L)]?"\u56FE\u8868.png":"\u56FE.png",N(e.files))}`;return m.push({name:W,data:F,later:!0}),P.replace(`\0C${L}\0`,()=>E(e.file,W))}).replace(/\n*\u0000gone\u0000\n*/g,`
3
+
4
+ `).replace(/^\n+|\n+$/g,"")}m.push({name:e.file,data:S})}else t==="html"?m.push({name:e.file,data:h(e,await s.offline(e.slug,{files:l}))}):m.push({name:e.file,data:await G(h(e,await s.offline(e.slug,{files:l})),{paper:p,scale:k})});for(let e of w){let u=await B.readFile(e.from).catch(()=>null);u&&m.push({name:e.name,data:u})}let f=[...m.filter(e=>!e.later&&v.some(u=>u.file===e.name)),...m.filter(e=>e.later||!v.some(u=>u.file===e.name))];return f.length===1?{name:f[0].name,type:ye[t],data:Buffer.isBuffer(f[0].data)?f[0].data:Buffer.from(f[0].data,"utf8")}:{name:`${M(v[0].title)}.zip`,type:"application/zip",data:V(f)}}function Ye({reportsDirectory:n,titleOf:r,outline:s,render:t,format:i,ready:a=async()=>{},made:o=new Map}){return{reportsDirectory:n,titleOf:r,childrenOf:async p=>{let{children:k,links:b=[]}=await s(),l=v=>(k[v]??[]).flatMap($=>b.includes($)||$.startsWith("~")?l($):[$]);return l(p)},links:()=>ge(n),offline:async(p,k)=>{await a(p);let b=await t(p,k),l=i==="markdown"?null:we(b);return l&&o.set(p,l),b},check:async p=>(await a(p),t.check(p))}}var ze=n=>async r=>{try{return JSON.parse(await B.readFile(ee(X(r,n)).json,"utf8")).title||r}catch{return r}};async function Ue(n,r){let s=[],t=async i=>{for(let a of await n.childrenOf(i))s.push(a),await t(a)};return await t(r),s}import ne from"node:fs/promises";import be from"node:path";import{writeAtomic as xe}from"../browser/shared/files.mjs";var re=371,Y=1,z=["reader","agent"],se=/^\d{4}-\d{2}-\d{2}$/,oe=n=>String(n).padStart(2,"0");function U(n){let r=new Date(n);return`${r.getFullYear()}-${oe(r.getMonth()+1)}-${oe(r.getDate())}`}function J(n,r){let[s,t,i]=n.split("-").map(Number);return U(new Date(s,t-1,i+r,12))}function Oe(n){let r;try{r=JSON.parse(n)}catch{return null}let s=a=>a!==null&&typeof a=="object"&&!Array.isArray(a);if(!s(r)||r.version!==Y||!se.test(r.since??"")||!s(r.days)||!s(r.seen))return null;let t={};for(let[a,o]of Object.entries(r.days))if(!(!se.test(a)||!s(o)))for(let[p,k]of Object.entries(o))for(let b of z){let l=k?.[b];Array.isArray(l)&&l.length===2&&l.every(Number.isInteger)&&l[0]>0&&(((t[a]??={})[p]??={})[b]=[l[0],l[1]])}let i={};for(let[a,o]of Object.entries(r.seen))s(o)&&Number.isFinite(o.mtime)&&typeof o.hash=="string"&&Number.isInteger(o.words)&&(i[a]={mtime:o.mtime,hash:o.hash,words:o.words});return{version:Y,since:r.since,days:t,seen:i}}function Ve({file:n,now:r=()=>new Date,wait:s=1e3}){let t=null,i=null,a=!1,o=null,p=Promise.resolve(),k=()=>U(r());function b(){return i??=ne.readFile(n,"utf8").then(Oe,()=>null).then(c=>(t=c??{version:Y,since:k(),days:{},seen:{},fresh:!0},c||(a=!0),t)),i}function l(){a=!0,!o&&(o=setTimeout(()=>{o=null,$()},s),o.unref?.())}function v(){let c=J(k(),-(re-1));for(let f of Object.keys(t.days))f<c&&delete t.days[f];let{version:y,since:h,days:m,seen:w}=t;return`${JSON.stringify({version:y,since:h<c?c:h,days:m,seen:w})}
5
+ `}function $(){if(!t||!a)return p;a=!1,clearTimeout(o),o=null;let c=v();return p=p.then(async()=>{await ne.mkdir(be.dirname(n),{recursive:!0}),await xe(n,c)}).catch(()=>{}),p}function N(c,y,h,m){let w=((t.days[y]??={})[c]??={})[z.includes(h)?h:"agent"]??=[0,0];w[0]+=1,w[1]+=m}return{load:b,get since(){return t?.since??k()},record(c,{hash:y,words:h,mtime:m,by:w}){if(!t)return!1;let f=t.seen[c];return t.seen[c]={mtime:m,hash:y,words:h},f?.hash===y?(f.mtime!==m&&l(),!1):(N(c,k(),w,h-(f?.words??0)),l(),!0)},async catchUp(c,y,{kept:h=[]}={}){await b();let m=t.fresh===!0;delete t.fresh;let w=0;for(let{slug:e,mtime:u}of c){let g=t.seen[e];if(g&&g.mtime===u)continue;let d=await y(e).catch(()=>null);if(!d||(t.seen[e]={mtime:d.edited,hash:d.hash,words:d.words},a=!0,m||g?.hash===d.hash))continue;let x=U(d.edited);N(e,x<t.since?t.since:x,"agent",d.words-(g?.words??0)),w+=1}let f=new Set([...c.map(({slug:e})=>e),...h]);for(let e of Object.keys(t.seen))f.has(e)||(delete t.seen[e],a=!0);return a&&l(),w},days(c=365){let y=k(),h=t?.since??y,m=J(y,-(Math.max(1,Math.min(re,c))-1));m<h&&(m=h);let w=[];for(let f=m;f<=y;f=J(f,1)){let e={date:f,edits:0,words:0,reader:{edits:0,words:0},agent:{edits:0,words:0}};for(let u of Object.values(t?.days[f]??{}))for(let g of z){let[d,x]=u[g]??[0,0];e[g].edits+=d,e[g].words+=x,e.edits+=d,e.words+=x}w.push(e)}return w},flush:$,async close(){clearTimeout(o),o=null,await $()}}}export{Q as a,te as b,Be as c,Je as d,Ye as e,ze as f,Ue as g,Ve as h};
@@ -0,0 +1,2 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{listPreferenceDocuments as o}from"../browser/shared/preference-documents.mjs";import n from"node:path";import{reportsDirectory as a}from"../browser/shared/paths.mjs";var l=r=>n.resolve(r);async function c({reading:r=!1}={}){let t=await o(),s=t.filter(e=>e.enabled);return[`\u5DE5\u4F5C\u533A\uFF1A${n.resolve(a)}`,...s.length?["\u5199\u4F5C\u504F\u597D\uFF1A\u4EE5\u4E0B\u662F\u542F\u7528\u7684\u6587\u6863\uFF0C\u6309\u6807\u9898\u548C\u5185\u5BB9\u9009\u62E9\u672C\u6B21\u4EFB\u52A1\u9002\u7528\u7684\u89C4\u5219\uFF08gallery preferences list\uFF09\u3002",...s.map(e=>` ${e.name}\uFF1A${l(e.file)}`)]:["\u5199\u4F5C\u504F\u597D\uFF1A\u5168\u90E8\u5DF2\u505C\u7528\u3002\u6309\u672C\u6B21\u7528\u6237\u8981\u6C42\u5199\u4F5C\u3002"],...r&&t.some(e=>e.made)?["\u63D0\u793A\uFF1Apreferences/\u9879\u76EE\u62A5\u544A\u5199\u4F5C.md was made now from Gallery defaults. Only change writing preferences when the user requests it."]:[]]}export{l as a,c as b};
@@ -0,0 +1,4 @@
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 U,b as Z,c as ot,d as X}from"./chunk-W5NPH5UA.mjs";import{e as L}from"./chunk-ECZBLQKK.mjs";import{D as nt,a as J,b as V,l as tt,m as D,o as et}from"./chunk-E7656LR7.mjs";import{b as Y,c as P,e as Q}from"./chunk-A55HN5OK.mjs";function Nt(t){let{blocks:s,locks:o,units:n,boxes:a}=L(t),l=Ot(t,[...s.map(e=>({at:e.innerStart-1,text:` data-ge-block="${e.id}"`})),...o.map(e=>({at:e.at,text:` data-ge-lock="${e.reason}"`})),...n.map(e=>({at:e.at,text:` data-ge-unit="${e.id}"${e.grid?" data-ge-grid":""}${e.keep?` data-ge-keep="${e.keep.reason}"${e.keep.own?" data-ge-keep-own":""}`:""}`})),...n.filter(e=>e.lead!==null).map(e=>({at:e.lead,text:` data-ge-lead="${e.id}"`})),...a.map(e=>({at:e.at,text:` data-ge-box="${e.id}"${e.pure?" data-ge-pure":""}`}))]),m={version:J(t),blocks:s.map(e=>({id:e.id,tag:e.tag,kind:e.kind,caps:Object.keys(e.caps),inner:t.slice(e.innerStart,e.innerEnd),atoms:e.atoms,unit:e.unit,...e.path?{path:e.path}:{},...e.self!==null?{self:!0}:{}})),units:n.map(e=>({id:e.id,kind:e.kind,parent:e.parent,hash:D(t,e),...e.blockId?{blockId:e.blockId}:{},...e.keep?{keep:e.keep}:{},...e.grid?{grid:!0}:{},...e.parts?{parts:e.parts}:{}})),boxes:a.map(e=>({id:e.id,kind:e.kind,unit:e.unit,...e.key!==null?{key:e.key}:{}}))};return{html:l,map:m}}function Ot(t,s,o=!0){let n=[],a=0;for(let l of[...s].sort((m,e)=>m.at-e.at)){if(t[l.at]!==">"){if(o)throw new Error(`Unexpected start tag before offset ${l.at}.`);continue}let m=et(t,l.at);n.push(t.slice(a,m),l.text),a=m}return n.push(t.slice(a)),n.join("")}Q();import{treeText as _}from"../browser/shared/annotations.mjs";import{attr as q}from"../browser/shared/html-tree.mjs";var st=2e3*2e3,F=2e3,rt=50,at=1500;function it(t,s,o,n){let a="",l=s;for(let m of n)m.end<=l||m.start>=o||(m.start>l&&(a+=t.slice(l,m.start)),l=Math.max(l,m.end));return a+t.slice(l,o)}var ct=t=>t.replace(/\s+/g," ").trim(),It=t=>/\S/.test(t.replace(/<!--[^]*?-->/g,"").replace(/<[^>]*>/g,"").replace(/\u0000/g,"")),lt=t=>t.companion?[{start:t.start,end:t.end},{start:t.companion.start,end:t.companion.end}]:[{start:t.start,end:t.end}];function C(t){let s=L(t),{units:o,blocks:n}=s,a=o[0]?.node??n[0]?.node??null;for(;a?.parentNode;)a=a.parentNode;let l=a?tt(t,[a]):[],m=[...o].sort((i,h)=>i.start-h.start||h.end-i.end),e=new Map,w=[];for(let i of m){for(;w.length&&w.at(-1).end<=i.start;)w.pop();e.set(i,w.at(-1)??null),w.push(i)}for(let i of o.filter(h=>h.companion)){let{start:h,end:E}=i.companion;for(let O of o){if(O===i||O.start<h||O.end>E)continue;let S=e.get(O);(!S||S.start<h)&&e.set(O,i)}}let p=new Map;for(let i of o){let h=e.get(i);h&&p.set(h,[...p.get(h)??[],i])}let u=n.find(i=>i.kind==="title")??null,c=[...o.map(i=>({unit:i,at:i.elStart})),...u?[{unit:null,at:u.start}]:[]].sort((i,h)=>i.at-h.at),f=new Map(c.map((i,h)=>[i.unit,h])),r=new Map;for(let i of o)i.blockId&&r.set(i.blockId,(r.get(i.blockId)??0)+1);let k=c.map(({unit:i})=>{if(!i){let T=ct(it(t,u.start,u.end,l));return{unit:null,title:!0,kind:"title",key:`title\0${T}`,own:T,counts:1,parent:null,blockId:null,text:_(u.node).slice(0,F)}}let h=p.get(i)??[],E=[...h.flatMap(lt),...l].sort((T,A)=>T.start-A.start),O=ct(lt(i).map(({start:T,end:A})=>it(t,T,A,E)).join("\0")),S=h.length>0&&!It(O),M=e.get(i);return{unit:i,kind:i.kind,key:`${i.kind}\0${O}`,own:O,counts:S?0:1,parent:M?f.get(M):null,blockId:i.blockId,text:_(i.node).slice(0,F)}}),N=null;return{rows:k,scanned:s,ref:i=>i.title?{title:!0}:i.blockId&&r.get(i.blockId)===1?{id:i.blockId}:(N??=(()=>{let h=new Map,E=new Map;for(let{unit:O}of c){if(!O)continue;let S=D(t,O);E.set(O,{hash:S,nth:h.get(S)??0}),h.set(S,(h.get(S)??0)+1)}return E})(),N.get(i.unit))}}function St(t,s){if(t.length*s.length<=st)return Z(t,s);let o=r=>r.reduce((k,N)=>k.set(N,(k.get(N)??0)+1),new Map),[n,a]=[o(t),o(s)],l=new Map;s.forEach((r,k)=>{a.get(r)===1&&n.get(r)===1&&l.set(r,k)});let m=[];t.forEach((r,k)=>{l.has(r)&&m.push([k,l.get(r)])});let e=[],w=[];m.forEach(([,r],k)=>{let N=0,B=e.length;for(;N<B;){let i=N+B>>1;m[e[i]][1]<r?N=i+1:B=i}w[k]=N>0?e[N-1]:-1,e[N]=k});let p=[];for(let r=e.at(-1)??-1;r>=0;r=w[r])p.unshift(m[r]);let u=[],[c,f]=[0,0];for(let[r,k]of[...p,[t.length,s.length]]){if((r-c)*(k-f)<=st)for(let[N,B]of Z(t.slice(c,r),s.slice(f,k)))u.push([c+N,f+B]);r<t.length&&u.push([r,k]),[c,f]=[r+1,k+1]}return u}var ft=(t,s)=>s.nested?_(P(t.slice(s.innerStart,s.innerEnd))):_(s.node),dt=t=>t.match(/[A-Za-z0-9]+|\s+|[^A-Za-z0-9\s]/gu)?.length??0,pt=({scanned:t},s)=>(s.title?t.blocks.filter(o=>o.kind==="title"):t.blocks.filter(o=>o.unit===s.unit.id)).sort((o,n)=>o.innerStart-n.innerStart);function bt(t){let s=[],o=n=>{for(let a of n.childNodes??[])a.tagName==="tr"?s.push((a.childNodes??[]).filter(l=>l.tagName==="td"||l.tagName==="th").map(l=>_(l).replace(/\s+/g," ")).join(" \xB7 ")):a.tagName&&o(a.tagName==="template"?a.content:a)};return o(t),s.length?s.join(`
3
+ `):_(t)}function ht(t,s,o){let n=t[s],a=0;for(let p=n.parent;p!==null;p=t[p].parent)o(p)&&(a+=1);let l=n.title?"h1":n.unit.node.tagName,m=n.title?n.text:bt(P(n.own.replace(/\u0000/g," "))).slice(0,F),e={kind:n.kind,tag:l,depth:a,text:m},w=l==="li"?n.unit.node.parentNode:null;if((w?.tagName==="ul"||w?.tagName==="ol")&&(e.marker=w.tagName,w.tagName==="ol")){let p=(w.childNodes??[]).filter(u=>u.tagName==="li");e.number=(Number.parseInt(q(w,"start")??"1",10)||1)+p.indexOf(n.unit.node)}return e}function gt(t,s){if(t===s)return null;let o=C(t),n=C(s),[a,l]=[o.rows.map(d=>d.key),n.rows.map(d=>d.key)],m=St(a,l);if(m.length===a.length&&m.length===l.length)return null;let e=d=>{let x=new Map;for(let b of d)b.blockId&&x.set(b.blockId,(x.get(b.blockId)??0)+1);return b=>!!b.blockId&&x.get(b.blockId)===1},[w,p]=[e(o.rows),e(n.rows)],u=[],[c,f]=[0,0];for(let[d,x]of[...m,[a.length,l.length]]){let b=new Map;for(let g=f;g<x;g++)p(n.rows[g])&&b.set(n.rows[g].blockId,g);let $=[],j=f-1;for(let g=c;g<d;g++){let I=w(o.rows[g])?b.get(o.rows[g].blockId):void 0;I!==void 0&&I>j&&($.push([g,I]),j=I)}let R=[],[y,v]=[c,f];for(let[g,I]of[...$,[d,x]]){for(;y<g;y++){let W=o.rows[y];for(let z=v;z<I;z++){let K=n.rows[z];if(K.kind===W.kind&&(W.title||ot(W.own,K.own))){R.push([y,z]),v=z+1;break}}}g<d&&R.push([g,I]),[y,v]=[g+1,I+1]}R.sort((g,I)=>g[0]-I[0]),[y,v]=[c,f];for(let[g,I]of[...R,[d,x]]){for(;y<g;y++)u.push({type:"del",i:y});for(;v<I;v++)u.push({type:"ins",j:v});g<d&&u.push({type:"chg",i:g,j:I}),[y,v]=[g+1,I+1]}d<a.length&&u.push({type:"same",i:d,j:x}),[c,f]=[d+1,x+1]}let r=new Set(u.filter(d=>d.type==="ins").map(d=>d.j)),k=new Set(u.filter(d=>d.type==="del").map(d=>d.i)),N=(d,x)=>{let b=new Set;for(let $ of x)if(d[$].counts)for(let j=d[$].parent;j!==null;j=d[j].parent)b.add(j);return $=>d[$].counts||(b.has($)?0:1)},[B,i]=[N(n.rows,r),N(o.rows,k)],h={added:0,changed:0,removed:0},E=[],O=[],S=[],M,T=null,A=null,G=d=>{if(!T)return;let x=Math.max(0,T.rows.length-rt);S.push({...d!==null?{before:n.ref(n.rows[d])}:A!==null?{after:n.ref(n.rows[A])}:{into:"main"},count:T.count,rows:T.rows.slice(0,rt),...x?{more:x}:{}}),T=null},H=d=>k.has(d)&&o.rows[d].counts>0;for(let d of u){if(d.type==="del"){T??={count:0,rows:[]},T.count+=i(d.i),h.removed+=i(d.i),H(d.i)&&T.rows.push(ht(o.rows,d.i,H));continue}if(G(d.j),A=d.j,d.type==="ins"){let x=n.rows[d.j];h.added+=B(d.j),(x.parent===null||!r.has(x.parent))&&E.push({ref:n.ref(x)})}else if(d.type==="chg"){let[x,b]=[o.rows[d.i],n.rows[d.j]];h.changed+=1;let $=pt(o,x),j=pt(n,b),R=[],y=$.length!==j.length||$.length===0||$.some((v,g)=>v.tag!==j[g].tag);y||($.forEach((v,g)=>{let[I,W]=[ft(t,v),ft(s,j[g])];dt(I)>at||dt(W)>at?y=!0:I!==W&&R.push({nth:g,base:I})}),R.length===0&&(y=!0)),y&&(R=[]),O.push({ref:n.ref(b),...y?{whole:!0}:{texts:R}}),b.title&&(M={base:x.text})}}return G(null),{counts:h,added:E,changed:O,...M?{title:M}:{},removed:S}}var ut=40;function yt(t,s){let o=gt(t,s);if(!o)return null;let{rows:n,ref:a}=C(s),l=new Map(n.map(p=>[JSON.stringify(a(p)),p])),m=p=>{let u=p.replace(/\s+/g," ").trim();return u.length>ut?`${u.slice(0,ut)}\u2026`:u},e=(p,u)=>{let c=l.get(JSON.stringify(u));if(!c)return null;let f=c.title?"h1":c.unit.node.tagName;return{change:p,kind:c.kind,tag:f,id:c.blockId??null,text:m(c.text),...c.title?{title:!0}:{},at:n.indexOf(c)}},w=[...o.added.map(({ref:p})=>e("added",p)),...o.changed.map(({ref:p})=>e("changed",p))].filter(Boolean);for(let p of o.removed){let u=p.before?l.get(JSON.stringify(p.before)):p.after?l.get(JSON.stringify(p.after)):null,c=u?n.indexOf(u)+(p.before?-.5:.5):-1;p.rows.forEach((f,r)=>w.push({change:"removed",kind:f.kind,tag:f.tag,id:null,text:m(f.text),at:c+r/1e3}))}return{counts:o.counts,blocks:w.sort((p,u)=>p.at-u.at).map(({at:p,...u})=>u)}}var mt=400;function Mt(t){let{rows:s}=C(t),o=a=>s[a].counts>0,n=s.map((a,l)=>l).filter(o);return{rows:n.slice(0,mt).map(a=>ht(s,a,o)),more:Math.max(0,n.length-mt)}}function Tt(t){let{units:s}=L(t),o=a=>{for(let l=a;l;l=l.parentNode)if(l.tagName&&(q(l,"data-doc-placeholder")!==void 0||l.tagName==="header"||(q(l,"class")??"").split(/\s+/).includes("doc-header")))return!1;return!0},n=a=>/^(img|picture|svg|canvas|video|audio|iframe|object|embed)$/.test(a.tagName??"")||(a.childNodes??[]).some(n);return!s.some(a=>o(a.node)&&(_(a.node)!==""||n(a.node)))}function $t(t,s){try{return X({current:t,ids:!0,...s}).text}catch{return t}}function Et(t,s){try{let o=L(t).blocks.find(a=>a.kind==="title");if(!o)return t;let n=U({current:t,edits:[{id:o.id,parts:[{keep:!0,html:s}]}],ids:!1});return n.ok?n.text:t}catch{return t}}import{IDENTITY as be}from"../browser/editor/components/registry.mjs";Q();import{COMPONENTS as vt,instancesOf as jt,partOf as wt}from"../browser/shared/components/index.mjs";import{attr as kt}from"../browser/shared/html-tree.mjs";var xt=new Set(["main","section","article","aside","nav","header","footer","div","details","dialog","figure","blockquote","table","ul","ol","dl"]),Bt=new Set(["script","style","template","textarea","title","xmp","iframe","noembed","noframes","noscript","plaintext","pre","code","kbd","samp","var","svg","math"]),Rt=vt.filter(t=>t.match&&t.pairs);function At(t){let s=t.replace(/^/," "),o=Y(s,{sourceCodeLocationInfo:!0}),n=c=>s.slice(0,c).split(`
4
+ `).length,a=[],l=(c,f,r)=>a.push({key:c,tag:s.slice(f,r).replace(/\s+/g," "),line:n(f),offset:f});V(o,"main")||l("no <main> in the file",0,0);let m=[],e=new Set,w=c=>{for(let f of c.childNodes??[]){let r=f.sourceCodeLocation;if(f.nodeName==="#comment"){r&&m.push([r.startOffset,r.endOffset]);continue}if(f.tagName){if(r?.startTag&&m.push([r.startTag.startOffset,r.startTag.endOffset]),Bt.has(f.tagName)){r&&m.push([r.startOffset,r.endOffset??s.length]);continue}r?.endTag&&e.add(r.endTag.startOffset),xt.has(f.tagName)&&r?.startTag&&!r.endTag&&l(`<${f.tagName}> not closed`,r.startTag.startOffset,r.startTag.endOffset),w(f)}}};w(o),m.sort((c,f)=>c[0]-f[0]);let p="",u=0;for(let[c,f]of m)f<=u||(p+=s.slice(u,Math.max(u,c))+" ".repeat(f-Math.max(u,c)),u=f);p+=s.slice(u);for(let c of p.matchAll(/<\/([A-Za-z][A-Za-z0-9]*)[^<>]*>?/g)){let f=c[1].toLowerCase();xt.has(f)&&!e.has(c.index)&&l(`</${f}> closes nothing`,c.index,c.index+c[0].length)}for(let c of Rt)for(let f of jt(o,c))for(let{a:r,attrA:k,b:N,attrB:B}of c.pairs){let i=wt(f,c.parts[r].at).map(M=>kt(M,k)),h=wt(f,c.parts[N].at).map(M=>kt(M,B)),E=M=>new Set(M).size===M.length,O=E(i)&&E(h)&&i.length===h.length&&i.every(M=>h.includes(M)),S=f.sourceCodeLocation;!O&&S&&l(`${c.id}: ${r} and ${N} do not pair`,S.startOffset,S.startTag?.endOffset??S.startOffset)}return a.sort((c,f)=>c.offset-f.offset).map(({key:c,tag:f,line:r})=>({key:c,tag:f,line:r,text:`${c} (line ${r})`}))}var Oe=(t,s,o,n)=>nt.installed.rewrite(t,s,o,{packages:n});export{Nt as a,At as b,gt as c,yt as d,Mt as e,Tt as f,$t as g,Et as h,Oe as i};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __galleryRequire } from "node:module"; import { fileURLToPath as __galleryPath } from "node:url"; const require = __galleryRequire(import.meta.url); const __filename = __galleryPath(import.meta.url); const __dirname = __galleryPath(new URL(".", import.meta.url));
2
+ import{c as L,d as _,e as D,h as N}from"./chunk-F4CT35KL.mjs";import{createHash as q,randomUUID as Q}from"node:crypto";import m from"node:fs/promises";import y from"node:path";import{refusal as V,said as T,saying as X}from"../browser/shared/i18n/index.mjs";import{extensionOf as Y,imageExtension as Z,imageFile as B,mediaTypeOf as tt,UPLOAD_LIMITS as p}from"../browser/shared/media.mjs";import{slugPattern as F}from"../browser/shared/reports.mjs";import{documentDirectory as M,documentFiles as et,layoutOf as nt}from"../browser/shared/workspace.mjs";var z=i=>Y(String(i??"").replace(/[?#].*$/,"")),it=i=>{let e=String(i??"").replace(/[?#].*$/,"");e=e.slice(e.lastIndexOf("/")+1);try{e=decodeURIComponent(e)}catch{}return e.replace(/[\u0000-\u001f<>:"/\\|?*]/g,"").trim().slice(0,120)||"file"};function rt(i){let e=i.subarray(0,16);return e[0]===137&&e.toString("latin1",1,4)==="PNG"?"image/png":e[0]===0&&e[1]===0&&e[2]===1&&e[3]===0?"image/x-icon":e[0]===255&&e[1]===216?"image/jpeg":e.toString("latin1",0,4)==="GIF8"?"image/gif":e.toString("latin1",0,4)==="RIFF"&&e.toString("latin1",8,12)==="WEBP"?"image/webp":e.toString("latin1",4,12)==="ftypavif"?"image/avif":/^\s*(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*<svg\b/i.test(i.subarray(0,512).toString("utf8"))?"image/svg+xml":null}var w=(i,e)=>V(e,{reason:i}),S=(i,e)=>{let l=rt(i);if(!l)throw w("type","\u4EC5\u652F\u6301\u56FE\u7247");return Z(l)},at=(i,e)=>z(e),ot=(i,e)=>{let l=z(e);if(!["html","htm","pdf"].includes(l)||l==="pdf"&&i.subarray(0,5).toString("latin1")!=="%PDF-")throw w("type","\u53EA\u80FD\u5D4C\u5165 HTML \u6216 PDF \u6587\u4EF6");return l},j={big:i=>T("\u56FE\u7247\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",i),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u5F20\u56FE\u7247"},U={big:i=>T("\u6587\u4EF6\u592A\u5927\uFF08\u6700\u591A {0} MB\uFF09",i),unreachable:"\u4E0B\u8F7D\u4E0D\u4E86\u8FD9\u4E2A\u6587\u4EF6"},k={icon:{limit:p.icon,words:j,extension:S},image:{limit:p.image,words:j,extension:S},file:{limit:p.file,words:U,extension:at,named:!0},embed:{limit:p.embed,words:U,extension:ot,named:!0}};function wt(i,e,l,b){let s=k[i].extension(l,b);return`${i}-${e.slice(0,12)}${s?`.${s}`:""}`}function bt({reportsDirectory:i}){let e=nt(i).emojiLibrary,l=async t=>{let n=M(t,i);return await m.stat(et(n).html).catch(()=>null)?n:null},b=y.join(e,"library.json"),s=(t,n,r)=>[t,{ok:!1,reason:n,...X(r)}];async function O(t,n,{stem:r,limit:a,words:c=j,extension:f=S,given:o}){let u=f(n,o);if(n.length>a)throw w("size",c.big(a/1024/1024));let d=`${r}-${q("sha256").update(n).digest("hex").slice(0,12)}${u?`.${u}`:""}`;await m.mkdir(t,{recursive:!0});let h=y.join(t,d);return await m.stat(h).catch(()=>null)||await m.writeFile(h,n),d}let E=(t,n,r,a=p.icon)=>O(t,n,{stem:r,limit:a});async function I(t,n,r=j){let a=await L(t,{unreachable:r.unreachable});if(!a.ok)throw w("download",r.unreachable);let c=await _(a,n);if(!c)throw w("size",r.big(n/1024/1024));return c}async function $(){try{let t=JSON.parse(await m.readFile(b,"utf8"));return Array.isArray(t)?t:[]}catch{return[]}}let v=t=>({id:t.id,name:t.name,url:`/__gallery/edit/emoji-library/${t.file}`,created_time:t.created,alive:!0});async function A(t){let{slug:n,data:r,url:a,library:c}=t??{},f=Object.hasOwn(k,t?.kind)?t.kind:"icon";if(typeof n!="string"||!F.test(n))return s(400,"body");let o=await l(n);if(!o)return s(404,"missing");let{limit:u,words:d,extension:h,named:J}=k[f];try{let g,x;if(typeof r=="string")g=Buffer.from(r,"base64"),x=t.name;else if(typeof a=="string")g=await I(a,u,d),x=a;else if(typeof c=="string"){let P=(await $()).find(K=>K.id===c);if(!P)return s(404,"library","\u8FD9\u4E2A\u81EA\u5B9A\u4E49\u8868\u60C5\u5DF2\u4E0D\u5728\u8868\u60C5\u5E93\u91CC");g=await m.readFile(y.join(e,P.file))}else return s(400,"body");return[200,{ok:!0,path:`assets/${await O(y.join(o,"assets"),g,{stem:f,limit:u,words:d,extension:h,given:x})}`,...J?{name:it(x),size:g.length}:{}}]}catch(g){return s(422,g.reason??"write",g)}}async function R(t){let{slug:n,url:r,parts:a="all"}=t??{};if(typeof n!="string"||!F.test(n)||typeof r!="string"||!["all","icon","title"].includes(a))return s(400,"body");let c=await l(n);if(!c)return s(404,"missing");try{return[200,{ok:!0,...await N(r,async(o,u)=>`assets/${await E(y.join(c,"assets"),o,u,p.image)}`,{icon:a!=="title",cover:a==="all"})}]}catch(f){return s(422,f.reason??"download",f)}}async function W(t){return typeof t?.url!="string"?s(400,"body"):[200,{ok:!0,...await D(t.url)}]}async function C(t){let{slug:n,name:r,url:a,data:c}=t??{};if(typeof r!="string"||!/^[\p{Ll}\p{Lo}\d_-]{1,49}$/u.test(r)||typeof a!="string"&&typeof c!="string")return s(400,"body");let f=await $();if(f.some(o=>o.name===r))return s(409,"name","\u540D\u79F0\u5DF2\u88AB\u5360\u7528");try{let o;typeof c=="string"?o=Buffer.from(c,"base64"):B(a)&&typeof n=="string"&&F.test(n)?o=await m.readFile(y.join(M(n,i),a)):o=await I(a,p.icon);let u=await E(e,o,"emoji"),d={id:Q(),name:r,file:u,created:Date.now()};return await m.writeFile(b,`${JSON.stringify([...f,d],null,2)}
3
+ `),[200,{ok:!0,entry:v(d)}]}catch(o){return s(422,o.reason??"write",o)}}let G=async()=>[200,{ok:!0,list:(await $()).map(v)}];async function H(t){if(!B(`assets/${t}`))return null;let n=await m.readFile(y.join(e,t)).catch(()=>null);return n&&{type:tt(t),body:n}}return{upload:A,unfurl:R,frameable:W,addEmoji:C,listEmojis:G,readEmoji:H}}export{wt as a,bt as b};