ssqch 0.10.1 → 0.11.0

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 (93) hide show
  1. package/bundled/completions/bash +61 -15
  2. package/bundled/completions/elvish +27 -12
  3. package/bundled/completions/fish +35 -23
  4. package/bundled/completions/powershell +29 -12
  5. package/bundled/completions/zsh +39 -19
  6. package/bundled/docs/agents.md +11 -0
  7. package/bundled/docs/comparing-builds.md +37 -5
  8. package/bundled/docs/configuring.md +30 -5
  9. package/bundled/docs/field-guide.md +1 -1
  10. package/bundled/docs/github-pages.md +1 -1
  11. package/bundled/docs/index.md +1 -1
  12. package/bundled/docs/known-gaps.md +1 -1
  13. package/bundled/docs/markdown.md +63 -5
  14. package/bundled/docs/multilingual.md +20 -3
  15. package/bundled/docs/nav.yml +1 -0
  16. package/bundled/docs/netlify.md +2 -2
  17. package/bundled/docs/plugins.md +4 -4
  18. package/bundled/docs/seo.md +39 -1
  19. package/bundled/docs/template-languages.md +6 -4
  20. package/bundled/docs/templates.md +3 -3
  21. package/bundled/docs/trailheads/from-eleventy.md +25 -13
  22. package/bundled/docs/trailheads/from-hugo.md +103 -0
  23. package/bundled/docs/trailheads/from-jekyll.md +49 -15
  24. package/bundled/docs/trailheads/from-mkdocs.md +54 -9
  25. package/bundled/docs/trailheads/from-zola.md +2 -2
  26. package/bundled/docs/trailheads.md +22 -5
  27. package/bundled/docs/where-values-come-from.md +1 -1
  28. package/bundled/mkdocs/404.jinja +6 -0
  29. package/bundled/ssqch.d.ts +71 -16
  30. package/lib/assets.js +10 -9
  31. package/lib/{chunk-MUYWL4ZX.js → chunk-2L3HR67O.js} +71 -18
  32. package/lib/{chunk-ERNVEZOK.js → chunk-2QTJTEBV.js} +1 -1
  33. package/lib/{chunk-CXRHH5P5.js → chunk-3HZZY3Y7.js} +5 -5
  34. package/lib/{chunk-G67W2FTJ.js → chunk-3K237XAX.js} +9 -8
  35. package/lib/{chunk-6RSZV5O2.js → chunk-443ZQLVX.js} +3 -3
  36. package/lib/{chunk-ZZBHBLDB.js → chunk-5ELAUHRL.js} +18 -16
  37. package/lib/{chunk-MDG5A4NI.js → chunk-A75EVUJX.js} +5 -5
  38. package/lib/{chunk-JFPLNHEQ.js → chunk-AIMEXBTK.js} +28 -5
  39. package/lib/{chunk-6OUT5VFK.js → chunk-B5E27PLU.js} +10 -39
  40. package/lib/{chunk-R2YGC3VE.js → chunk-CMJ7X5WW.js} +3 -2
  41. package/lib/{chunk-MDB3D3LP.js → chunk-ERAIEV3O.js} +2 -2
  42. package/lib/{chunk-DTSTCVRX.js → chunk-FCM3NYFR.js} +11 -8
  43. package/lib/{chunk-X7C6GFUM.js → chunk-GJNIQAIH.js} +8 -8
  44. package/lib/{chunk-FYRC2HBU.js → chunk-GLJQ4C76.js} +39 -18
  45. package/lib/{chunk-BXARVN5Z.js → chunk-GS5B3CBW.js} +1 -1
  46. package/lib/chunk-H5K2ZE7B.js +219 -0
  47. package/lib/{chunk-DNWA7WNO.js → chunk-HFSWUTXX.js} +1 -1
  48. package/lib/{chunk-7JGYYAKI.js → chunk-HWW5NCVJ.js} +1 -1
  49. package/lib/{chunk-BT3NVQOD.js → chunk-I3HYKEEW.js} +1 -1
  50. package/lib/{chunk-RFNLZM7W.js → chunk-IOBC665M.js} +1 -1
  51. package/lib/chunk-JC54PHIT.js +7992 -0
  52. package/lib/{chunk-3BQJY6GF.js → chunk-KCF2Z6N7.js} +1 -1
  53. package/lib/{chunk-HMVYNV6M.js → chunk-KZZS4W2V.js} +14 -12
  54. package/lib/{chunk-XR7GFL4B.js → chunk-LJOURBYT.js} +14 -12
  55. package/lib/chunk-OQGXZYZS.js +45 -0
  56. package/lib/chunk-OSBEH67S.js +6296 -0
  57. package/lib/{chunk-FYU22VDK.js → chunk-QJ5ZFTML.js} +14 -12
  58. package/lib/{chunk-LU73FTIR.js → chunk-QLUTNR37.js} +11 -10
  59. package/lib/{chunk-DUGGZ4EE.js → chunk-RBNPBTDP.js} +1 -1
  60. package/lib/{chunk-F65YUXZ7.js → chunk-RIAOXEXC.js} +10 -4
  61. package/lib/chunk-RVXGUMFI.js +21 -0
  62. package/lib/{chunk-FZGJUJAL.js → chunk-RYIWYWRQ.js} +3 -3
  63. package/lib/{chunk-LYPKL524.js → chunk-RZYAIX2R.js} +12 -10
  64. package/lib/{chunk-3NDFUMV2.js → chunk-V2FSMOFX.js} +3 -3
  65. package/lib/{chunk-26SHWRC6.js → chunk-X2GAVYV2.js} +524 -72
  66. package/lib/chunk-XS4EJSEK.js +279 -0
  67. package/lib/chunk-YCOTX2VM.js +37 -0
  68. package/lib/{chunk-P2TRR6XK.js → chunk-Z44IAMNG.js} +85 -16
  69. package/lib/chunk-Z5OP43HU.js +2945 -0
  70. package/lib/{chunk-3LODFCCH.js → chunk-ZINLHOX4.js} +2 -2
  71. package/lib/{chunk-HNG372DW.js → chunk-ZR3JYLFB.js} +814 -12347
  72. package/lib/cli.js +78 -37
  73. package/lib/elements.js +10 -9
  74. package/lib/image.js +11 -10
  75. package/lib/links.js +10 -9
  76. package/lib/minify.js +71 -12
  77. package/lib/redirects.js +10 -9
  78. package/lib/rss.js +13 -10
  79. package/lib/sass.js +13 -243
  80. package/lib/sitemap.js +18 -15
  81. package/lib/ssqch.js +6 -4
  82. package/package.json +1 -1
  83. package/types/index.d.ts +52 -11
  84. package/types/minify.d.ts +15 -3
  85. package/types/sass.d.ts +2 -0
  86. package/types/sitemap.d.ts +2 -2
  87. package/wasm/markdown.wasm +0 -0
  88. package/wasm/minify.wasm +0 -0
  89. package/wasm/sass.wasm +0 -0
  90. package/lib/chunk-II7ZRIAC.js +0 -1285
  91. package/lib/chunk-IOXCGMSF.js +0 -1539
  92. /package/lib/{chunk-JFPLNHEQ.js.LEGAL.txt → chunk-AIMEXBTK.js.LEGAL.txt} +0 -0
  93. /package/lib/{chunk-HNG372DW.js.LEGAL.txt → chunk-ZR3JYLFB.js.LEGAL.txt} +0 -0
@@ -1,1539 +0,0 @@
1
- import { createRequire as __ssqchCreateRequire } from "node:module";
2
- const require = __ssqchCreateRequire(import.meta.url);
3
- import {
4
- closest
5
- } from "./chunk-FVZ5JBRI.js";
6
- import {
7
- globBase,
8
- globProblem,
9
- globToRegExp,
10
- isGlob
11
- } from "./chunk-DNWA7WNO.js";
12
- import {
13
- ISSUES_URL,
14
- SOMETHING_LARGE
15
- } from "./chunk-UU43WIZG.js";
16
- import {
17
- describeThrown,
18
- settle
19
- } from "./chunk-RFNLZM7W.js";
20
- import {
21
- BuildError,
22
- Diagnostics,
23
- bail,
24
- comparePaths,
25
- context,
26
- isPlainObject,
27
- loadStaticDataFile,
28
- messageOf,
29
- parseFrontMatter,
30
- readText,
31
- warn,
32
- warning
33
- } from "./chunk-JFPLNHEQ.js";
34
-
35
- // src/engines/markdown.ts
36
- import { Buffer as Buffer2 } from "node:buffer";
37
- import crypto from "node:crypto";
38
- import fs from "node:fs";
39
- import path from "node:path";
40
- import { fileURLToPath } from "node:url";
41
-
42
- // src/engines/webassembly.ts
43
- var WebAssembly = globalThis.WebAssembly;
44
-
45
- // src/engines/markdown.ts
46
- function loadHookTemplates(dir, name, engines, chain) {
47
- const out = /* @__PURE__ */ new Map();
48
- for (const kind of ["hooks", "containers"]) {
49
- let files2;
50
- try {
51
- files2 = fs.readdirSync(path.join(dir, kind));
52
- } catch {
53
- continue;
54
- }
55
- for (const file of files2.sort(comparePaths)) {
56
- const full = path.join(dir, kind, file);
57
- if (file.startsWith(".") || !fs.statSync(full, { throwIfNoEntry: false })?.isFile()) continue;
58
- const dot = file.lastIndexOf(".");
59
- if (dot <= 0) continue;
60
- const shown = `${name}/${kind}/${file}`;
61
- const ext = file.slice(dot + 1).toLowerCase();
62
- try {
63
- engines.get(ext);
64
- } catch (e) {
65
- throw context(e, shown);
66
- }
67
- const key = `${kind}/${file.slice(0, dot)}`;
68
- const other = out.get(key);
69
- if (other) throw new BuildError(`${other.name} and ${shown} are both templates for \`${key}\`; keep one`);
70
- let src;
71
- try {
72
- src = readText(full);
73
- } catch (e) {
74
- throw context(e, `reading ${shown}`);
75
- }
76
- let body;
77
- try {
78
- body = parseFrontMatter(src).body;
79
- } catch (e) {
80
- throw context(e, shown);
81
- }
82
- out.set(key, { name: shown, engines: chain(ext), body, path: full });
83
- }
84
- }
85
- return out;
86
- }
87
- function writeHighlightCss(options, output, markdown2) {
88
- const url = options.highlight ? options.highlightCss : null;
89
- if (url === null) return [];
90
- const file = path.join(output, ...url.replace(/^\/+/, "").split("/"));
91
- const css = markdown2.css();
92
- let before;
93
- try {
94
- before = fs.readFileSync(file, "utf8");
95
- } catch {
96
- }
97
- if (before !== css) {
98
- try {
99
- fs.mkdirSync(path.dirname(file), { recursive: true });
100
- fs.writeFileSync(file, css);
101
- } catch (e) {
102
- throw context(e, `writing ${file}`);
103
- }
104
- }
105
- return [file];
106
- }
107
- var page;
108
- function rendering(file) {
109
- const before = page;
110
- page = file?.replace(/^(\.\/)+/, "");
111
- return before;
112
- }
113
- var INLINE = 1;
114
- var HOOKS = 2;
115
- function markdownEngine(options, root = process.cwd()) {
116
- return new WasmMarkdown(options, root);
117
- }
118
- function checkLanguages(options, root) {
119
- if (!options.languages.length) return;
120
- const engine = new WasmMarkdown(options, root);
121
- engine.check();
122
- engine.close();
123
- }
124
- var WasmMarkdown = class {
125
- #options;
126
- #root;
127
- #hooks = /* @__PURE__ */ new Map();
128
- #engines;
129
- /** The config's functions, by the numbers the wasm calls them with. */
130
- #functions = [];
131
- #setup;
132
- #handle = -1;
133
- #wasm;
134
- constructor(options, root) {
135
- this.#options = options;
136
- this.#root = root;
137
- }
138
- /**
139
- * A page's Markdown. 0.7 waited for a site's function that answered with a promise
140
- * (`headingIds: async (text) => id`), but the wasm calls back synchronously. So when the
141
- * config has functions, a first render runs nothing of the site's (no hooks, a stand-in for
142
- * each function) and notes the calls it makes; each function is then called once, in order,
143
- * waiting for each promise as 0.7 did; and the render that counts takes those answers. A
144
- * function or a hook never runs twice. Without functions, it's one render.
145
- */
146
- render(source, data, _ctx) {
147
- const file = page ?? pageOf(data);
148
- this.#ready();
149
- if (!this.#functions.length) return this.#markdown(source, HOOKS, data, file);
150
- let asked;
151
- try {
152
- asked = this.#dryRun(source, file);
153
- } catch {
154
- return this.#markdown(source, HOOKS, data, file);
155
- }
156
- return this.#answer(asked, (answers) => this.#markdown(source, HOOKS, data, file, answers));
157
- }
158
- html(text, inline) {
159
- return this.#markdown(text, HOOKS | (inline ? INLINE : 0), {}, page, void 0, "markdown() in a template");
160
- }
161
- plain(text, inline) {
162
- return this.#markdown(text, inline ? INLINE : 0, {}, page, void 0, 'markdown() from "ssqch"');
163
- }
164
- highlight(code, lang) {
165
- const wasm = this.#ready();
166
- const [ptr, lens] = wasm.input([code, lang, page ?? ""]);
167
- const frame = wasm.frame(this, {});
168
- const [status, text, thrown] = wasm.run(frame, () => wasm.x.md_highlight(this.#handle, ptr, lens[0], lens[1], lens[2]), page);
169
- this.#waited(frame, "highlight() in a template");
170
- if (status === NOTHING) return void 0;
171
- if (status !== DONE) throw failure(text, thrown);
172
- return text;
173
- }
174
- css() {
175
- const wasm = this.#ready();
176
- const [status, text] = wasm.run(wasm.frame(this, {}), () => wasm.x.md_css(), void 0);
177
- return status === DONE ? text : "";
178
- }
179
- useHooks(hooks, engines) {
180
- const own = hooks.get("containers/slot");
181
- if (own) throw new BuildError(`${own.name}: \`slot\` is ssqch's container for a named slot (\`::: slot footer\` inside another container is its \`container.slots.footer\`), so it can't have a template. Rename the container`);
182
- this.#hooks = hooks;
183
- this.#engines = engines;
184
- this.close();
185
- this.#setup = void 0;
186
- }
187
- /** Sets up now, so that what's wrong with the options is said now. */
188
- check() {
189
- this.#ready();
190
- }
191
- /** For tests: a render that makes the wasm read past its memory, as a bug in it would. */
192
- crash(file) {
193
- const wasm = this.#ready();
194
- wasm.run(wasm.frame(this, {}), () => wasm.x.md_render(this.#handle, 4294967040, 16, 0, 0), file);
195
- }
196
- /** Lets the wasm forget this setup. */
197
- close() {
198
- if (this.#wasm && this.#handle >= 0 && !this.#wasm.dead) this.#wasm.x.md_drop(this.#handle);
199
- handles.unregister(this);
200
- this.#handle = -1;
201
- this.#wasm = void 0;
202
- }
203
- /**
204
- * One render. `answers` are what the site's functions gave, worked out before it; without
205
- * them they're called as the wasm asks, and one that answers with a promise is an error for
206
- * `what` (Markdown that's made at once, inside a template, can't wait for it).
207
- */
208
- #markdown(source, flags, data, file, answers, what = "this Markdown") {
209
- const wasm = this.#ready();
210
- const [ptr, lens] = wasm.input([source, file ?? ""]);
211
- const frame = wasm.frame(this, data);
212
- frame.answers = answers;
213
- const [status, text, thrown] = wasm.run(frame, () => wasm.x.md_render(this.#handle, ptr, lens[0], lens[1], flags), file);
214
- this.#waited(frame, what);
215
- if (status !== DONE) throw failure(text, thrown);
216
- return putBackSlots(text);
217
- }
218
- /** A render that runs nothing of the site's: the calls to its functions it would make, in order. */
219
- #dryRun(source, file) {
220
- const wasm = this.#ready();
221
- const [ptr, lens] = wasm.input([source, file ?? ""]);
222
- const frame = wasm.frame(this, {});
223
- frame.asked = [];
224
- const [status, text] = wasm.run(frame, () => wasm.x.md_render(this.#handle, ptr, lens[0], lens[1], 0), file);
225
- if (status !== DONE) throw new BuildError(text);
226
- return frame.asked;
227
- }
228
- /**
229
- * Calls the site's functions as a render will, one at a time, waiting for each promise
230
- * before the next call, as 0.7 did; then `then` with what they gave. At once while nothing
231
- * answers with a promise. After `headingIds` fails nothing more is called: the render
232
- * stops there.
233
- */
234
- #answer(asked, then) {
235
- const answers = [];
236
- const from = (i) => {
237
- for (; i < asked.length; i++) {
238
- const call = asked[i];
239
- const site2 = this.#functions[call.n];
240
- let out;
241
- try {
242
- out = site2.fn(...JSON.parse(call.args));
243
- } catch (error) {
244
- answers.push({ ...call, error });
245
- if (site2.slugger) break;
246
- continue;
247
- }
248
- if (isThenable(out)) {
249
- const waited = settle(Promise.resolve(out));
250
- return waited.then(
251
- (value) => {
252
- answers.push({ ...call, value });
253
- return from(i + 1);
254
- },
255
- (error) => {
256
- answers.push({ ...call, error });
257
- return site2.slugger ? then(answers) : from(i + 1);
258
- }
259
- );
260
- }
261
- answers.push({ ...call, value: out });
262
- }
263
- return then(answers);
264
- };
265
- return from(0);
266
- }
267
- /** After a render without answers: a function that answered with a promise is an error for `what`. */
268
- #waited(frame, what) {
269
- if (frame.waited === void 0) return;
270
- throw new BuildError(`${frame.waited} answered with a promise, and ${what} can't wait for one: it's made at once, while the template around it renders. Make the function synchronous (a page's own Markdown waits for it)`);
271
- }
272
- /** The wasm, with this setup made in it. */
273
- #ready() {
274
- const wasm = instance();
275
- if (this.#wasm === wasm && this.#handle >= 0) return wasm;
276
- this.close();
277
- this.#setup ??= this.#describe();
278
- wasm.files = this.#setup.files;
279
- const [ptr, [len]] = wasm.input([this.#setup.json]);
280
- let handle;
281
- try {
282
- [handle] = wasm.run(wasm.frame(this, {}), () => wasm.x.md_new(ptr, len), "markdown options");
283
- } finally {
284
- wasm.files = /* @__PURE__ */ new Map();
285
- }
286
- if (handle < 0) throw new BuildError(wasm.result());
287
- this.#wasm = wasm;
288
- this.#handle = handle;
289
- handles.register(this, { wasm, handle }, this);
290
- return wasm;
291
- }
292
- /** The options as the wasm reads them (`crates/ssqch-markdown/src/options.rs`), and the grammar files it reads. */
293
- #describe() {
294
- const o = this.#options;
295
- this.#functions = [];
296
- const number = (fn, name, slugger2 = false) => this.#functions.push({ fn, name, slugger: slugger2 }) - 1;
297
- const files2 = /* @__PURE__ */ new Map();
298
- const key = [];
299
- const languages = o.languages.map(([name, language]) => {
300
- if (typeof language === "function") {
301
- key.push([name]);
302
- return [name, { function: number(language, `markdown.highlight.languages.${name}`) }];
303
- }
304
- if ("alias" in language) {
305
- key.push([name, language.alias]);
306
- return [name, { alias: language.alias }];
307
- }
308
- const text = readGrammar(this.#root, name, language.grammar);
309
- files2.set(wasmPath(language.grammar), text);
310
- key.push([name, language.grammar, crypto.createHash("sha256").update(text).digest("hex")]);
311
- return [name, { grammar: language.grammar }];
312
- });
313
- const json = JSON.stringify({
314
- headingIds: o.headingIds,
315
- headingAttributes: o.headingAttributes,
316
- footnotes: o.footnotes,
317
- taskLists: o.taskLists,
318
- autolinks: o.autolinks,
319
- alerts: o.alerts,
320
- containers: o.containers,
321
- definitionLists: o.definitionLists,
322
- smartPunctuation: o.smartPunctuation,
323
- indentedCode: o.indentedCode,
324
- highlight: o.highlight,
325
- highlightCss: o.highlightCss,
326
- languages,
327
- headingIdsFunction: o.sluggerFn ? number(o.sluggerFn, "markdown.headingIds", true) : null,
328
- // `slot` is ssqch's container: it always calls back, to be kept for its parent.
329
- hooks: [...this.#hooks.keys(), "containers/slot"],
330
- languagesKey: JSON.stringify(key)
331
- });
332
- return { json, files: files2 };
333
- }
334
- hookFile(name, value, data) {
335
- return this.#hooks.has(`hooks/${name}`) ? this.renderHook(`hooks/${name}`, name, value, data) : void 0;
336
- }
337
- /** A render hook for the wasm: the template `name` with the page's data and `value` as `key`. */
338
- renderHook(name, key, value, data) {
339
- if (key === "container" && isPlainObject(value)) {
340
- if (name === "containers/slot") return keepSlot(value);
341
- const own = { ...value, props: containerProps(value.args) };
342
- own.slots = takeSlots(own);
343
- value = own;
344
- }
345
- const template = this.#hooks.get(name);
346
- const engines = this.#engines;
347
- if (!template || !engines) throw new BuildError(`no template for \`${name}\``);
348
- const hookData = { ...isPlainObject(data) ? data : {}, [key]: value };
349
- let text = template.body;
350
- for (const name2 of template.engines) {
351
- const engine = engines.get(name2);
352
- const ctx = { name: template.name, inputPath: template.path, cacheKey: `${template.name}#${name2}`, kind: "hook" };
353
- let out;
354
- try {
355
- out = engine.render(text, hookData, ctx);
356
- } catch (e) {
357
- throw context(e, `rendering ${template.name}`);
358
- }
359
- if (typeof out !== "string") {
360
- out.catch(() => {
361
- });
362
- throw new BuildError(`rendering ${template.name}: it answered with a promise (from an async filter, function or engine), and render hooks and containers can't wait for one: they render while the Markdown around them does. Make what it calls synchronous`);
363
- }
364
- text = out;
365
- }
366
- return text;
367
- }
368
- /** One of the config's functions, for the wasm: called, answered from `frame`'s answers, or (a dry run) noted and stood in for. */
369
- call(n, args, frame) {
370
- const site2 = this.#functions[n];
371
- if (!site2) throw new BuildError(`no function ${n}`);
372
- if (frame.asked) {
373
- frame.asked.push({ n, args });
374
- return standIn(site2, args);
375
- }
376
- const answer = frame.answers?.[frame.next];
377
- if (answer && answer.n === n && answer.args === args) {
378
- frame.next++;
379
- if ("error" in answer) throw answer.error;
380
- return answer.value;
381
- }
382
- const out = site2.fn(...JSON.parse(args));
383
- if (isThenable(out)) {
384
- Promise.resolve(out).catch(() => {
385
- });
386
- frame.waited ??= site2.name;
387
- return standIn(site2, args);
388
- }
389
- return out;
390
- }
391
- /** What a function threw, as 0.7 said it: the message and the site's frames. */
392
- thrown(e) {
393
- return describeThrown(e, this.#root);
394
- }
395
- };
396
- function containerProps(args) {
397
- const props = {};
398
- for (const [, name, dq, sq, bare] of String(args ?? "").matchAll(/([A-Za-z_][\w-]*)(?:="([^"]*)"|='([^']*)'|=([^\s"']+))?/g)) {
399
- if (dq !== void 0) props[name] = dq;
400
- else if (sq !== void 0) {
401
- if (/^\s*[{[]/.test(sq)) {
402
- try {
403
- props[name] = JSON.parse(sq);
404
- continue;
405
- } catch {
406
- }
407
- }
408
- props[name] = sq;
409
- } else if (bare !== void 0) props[name] = bare;
410
- else props[name] = true;
411
- }
412
- return props;
413
- }
414
- var slots = /* @__PURE__ */ new Map();
415
- var slotCount = 0;
416
- var SLOT = /\uE000slot(\d+)\uE001\n?/g;
417
- function keepSlot(value) {
418
- const props = containerProps(value.args);
419
- const name = typeof props.name === "string" ? props.name : String(value.args ?? "").trim().split(/\s+/)[0] || "default";
420
- const n = slotCount++;
421
- slots.set(n, { name, content: String(value.content ?? "") });
422
- return `\uE000slot${n}\uE001`;
423
- }
424
- function takeSlots(value) {
425
- const found = {};
426
- if (typeof value.content !== "string" || !value.content.includes("\uE000slot")) return found;
427
- value.content = value.content.replace(SLOT, (_, n) => {
428
- const slot = slots.get(Number(n));
429
- slots.delete(Number(n));
430
- if (slot) found[slot.name] = String(found[slot.name] ?? "") + slot.content;
431
- return "";
432
- });
433
- return found;
434
- }
435
- function putBackSlots(html) {
436
- if (!html.includes("\uE000slot")) return html;
437
- return html.replace(SLOT, (_, n) => {
438
- const slot = slots.get(Number(n));
439
- slots.delete(Number(n));
440
- return slot?.content ?? "";
441
- });
442
- }
443
- var handles = new FinalizationRegistry(({ wasm, handle }) => {
444
- if (!wasm.dead) wasm.x.md_drop(handle);
445
- });
446
- function pageOf(data) {
447
- const input = isPlainObject(data) && isPlainObject(data.page) ? data.page.inputPath : void 0;
448
- return typeof input === "string" ? input.replace(/^(\.\/)+/, "") : void 0;
449
- }
450
- function failure(message, thrown) {
451
- if (thrown !== void 0 && (thrown instanceof BuildError || thrown instanceof Diagnostics)) {
452
- const inner = messageOf(thrown);
453
- if (message === inner) return thrown;
454
- if (message.endsWith(`: ${inner}`)) return context(thrown, message.slice(0, -inner.length - 2));
455
- }
456
- return new BuildError(message);
457
- }
458
- function readGrammar(root, name, file) {
459
- try {
460
- return fs.readFileSync(path.resolve(root, file));
461
- } catch (e) {
462
- throw new BuildError(`markdown.highlight.languages.${name}: reading ${file}: ${ioError(e)}`);
463
- }
464
- }
465
- function ioError(e) {
466
- const code = e.code;
467
- if (code === "ENOENT") return process.platform === "win32" ? "The system cannot find the file specified. (os error 2)" : "No such file or directory (os error 2)";
468
- if (code === "EISDIR") return "Is a directory (os error 21)";
469
- if (code === "EACCES") return process.platform === "win32" ? "Access is denied. (os error 5)" : "Permission denied (os error 13)";
470
- return messageOf(e);
471
- }
472
- function wasmPath(file) {
473
- return path.posix.normalize(file.replace(/^\/+/, ""));
474
- }
475
- var DONE = 0;
476
- var ERROR = 1;
477
- var NOTHING = 2;
478
- var WASM_FILE = fileURLToPath(new URL("../../wasm/markdown.wasm", new URL("../src/engines/markdown.ts", import.meta.url).href));
479
- var compiled;
480
- var current;
481
- function instance() {
482
- if (!current) {
483
- if (!compiled) {
484
- let bytes;
485
- try {
486
- bytes = fs.readFileSync(WASM_FILE);
487
- } catch (e) {
488
- throw new BuildError(`ssqch's Markdown isn't there (${WASM_FILE}: ${messageOf(e)}); build it with node packages/ssqch/scripts/build-wasm.ts`);
489
- }
490
- compiled = new WebAssembly.Module(bytes);
491
- highlighter = highlighterOf(compiled, bytes);
492
- }
493
- current = new Wasm(compiled);
494
- if (disk?.open) giveFences(current, disk);
495
- }
496
- return current;
497
- }
498
- var FENCE_CACHE = ".cache/ssqch/highlight/fences.json";
499
- var highlighter = "";
500
- var disk;
501
- function highlighterOf(module, bytes) {
502
- const sections = WebAssembly.Module.customSections(module, "ssqch_markdown_inputs");
503
- const hash = sections.length ? Buffer2.from(sections[sections.length - 1]).toString("utf8") : "";
504
- return /^[0-9a-f]{64}$/.test(hash) ? hash : `bytes ${crypto.createHash("sha256").update(bytes).digest("hex")}`;
505
- }
506
- function beginFenceCache(root) {
507
- const file = path.join(root, FENCE_CACHE);
508
- if (disk?.file !== file) {
509
- let text = "";
510
- try {
511
- text = fs.readFileSync(file, "utf8");
512
- } catch {
513
- }
514
- disk = { file, text, given: void 0, open: true };
515
- }
516
- disk.open = true;
517
- if (current) giveFences(current, disk);
518
- }
519
- function giveFences(wasm, d) {
520
- const fresh = d.given !== wasm;
521
- const [ptr, lens] = wasm.input([highlighter, fresh ? d.text : ""]);
522
- wasm.run(wasm.frame(void 0, {}), () => wasm.x.md_fences_begin(ptr, lens[0], lens[1], fresh ? 1 : 0), "the cache of highlighted fences");
523
- d.given = wasm;
524
- }
525
- function saveFenceCache() {
526
- const d = disk;
527
- if (!d?.open) return;
528
- d.open = false;
529
- const wasm = current;
530
- if (!wasm || d.given !== wasm) return;
531
- const [ptr, [len]] = wasm.input([highlighter]);
532
- const [status, text] = wasm.run(wasm.frame(void 0, {}), () => wasm.x.md_fences_save(ptr, len), "the cache of highlighted fences");
533
- if (status !== DONE) return;
534
- try {
535
- if (text === "") {
536
- fs.rmSync(d.file, { force: true });
537
- } else {
538
- fs.mkdirSync(path.dirname(d.file), { recursive: true });
539
- const temp = `${d.file.replace(/\.json$/, "")}.${process.pid}.tmp`;
540
- try {
541
- fs.writeFileSync(temp, text);
542
- fs.renameSync(temp, d.file);
543
- } catch (e) {
544
- fs.rmSync(temp, { force: true });
545
- throw e;
546
- }
547
- }
548
- d.text = text;
549
- } catch {
550
- d.given = void 0;
551
- }
552
- }
553
- var WASI_EBADF = 8;
554
- var WASI_ENOENT = 44;
555
- var WASI_ENOSYS = 52;
556
- var ROOT_FD = 3;
557
- var Wasm = class {
558
- x;
559
- /** Set by a trap (a panic in the Rust): this instance is done, and the next call starts another. */
560
- dead = false;
561
- /** Files the wasm can read while it sets up (a site's grammars), by their paths from `/`. */
562
- files = /* @__PURE__ */ new Map();
563
- #open = /* @__PURE__ */ new Map();
564
- #nextFd = ROOT_FD + 1;
565
- #frames = [];
566
- #bytes = Buffer2.alloc(0);
567
- constructor(module) {
568
- const wasi = this.#wasi();
569
- const imports = {
570
- // Anything else std might ask for isn't there.
571
- wasi_snapshot_preview1: new Proxy(wasi, { get: (target, name) => target[name] ?? (() => WASI_ENOSYS) }),
572
- ssqch: this.#host()
573
- };
574
- this.x = new WebAssembly.Instance(module, imports).exports;
575
- this.x._initialize();
576
- }
577
- /** The wasm's memory as a Buffer (a new one after the memory grows). */
578
- bytes() {
579
- const buffer = this.x.memory.buffer;
580
- if (this.#bytes.buffer !== buffer) this.#bytes = Buffer2.from(buffer);
581
- return this.#bytes;
582
- }
583
- /** Copies strings into one buffer the wasm takes: its address, and each string's length in bytes. */
584
- input(parts) {
585
- const lens = parts.map((part) => Buffer2.byteLength(part, "utf8"));
586
- const ptr = this.x.md_alloc(lens.reduce((sum, n) => sum + n, 0));
587
- const bytes = this.bytes();
588
- let at = ptr;
589
- parts.forEach((part, i) => {
590
- at += bytes.write(part, at, lens[i], "utf8");
591
- });
592
- return [ptr, lens];
593
- }
594
- result() {
595
- const ptr = this.x.md_result_ptr();
596
- return this.bytes().toString("utf8", ptr, ptr + this.x.md_result_len());
597
- }
598
- /** Makes a call for `owner`, whose hooks get `data`: its status, its result, and what a call back threw. */
599
- /** A call for `owner`, whose hooks get `data`. */
600
- frame(owner, data) {
601
- return { owner, data, next: 0 };
602
- }
603
- /** Makes a call in `frame`: its status, its result, and what a call back threw. `what` names the page (or the setup) if the wasm crashes. */
604
- run(frame, call, what) {
605
- if (this.dead) throw internal("its WebAssembly stopped", what);
606
- this.#frames.push(frame);
607
- try {
608
- const status = call();
609
- if (this.dead) throw internal("its WebAssembly stopped", what);
610
- return [status, this.result(), frame.thrown];
611
- } catch (e) {
612
- if (e instanceof WebAssembly.RuntimeError) throw this.#trapped(e, what);
613
- this.#stop();
614
- throw e;
615
- } finally {
616
- this.#frames.pop();
617
- }
618
- }
619
- #stop() {
620
- this.dead = true;
621
- if (current === this) current = void 0;
622
- }
623
- #trapped(e, what) {
624
- this.#stop();
625
- let message = "";
626
- try {
627
- this.x.md_panic();
628
- message = this.result();
629
- } catch {
630
- }
631
- return internal(message || `it crashed (${e.message})`, what);
632
- }
633
- /** Leaves Node's answer to a call back where the wasm reads it. */
634
- #reply(out, status, text) {
635
- const len = Buffer2.byteLength(text, "utf8");
636
- const ptr = this.x.md_alloc(len);
637
- const bytes = this.bytes();
638
- bytes.write(text, ptr, len, "utf8");
639
- bytes.writeUInt32LE(ptr, out);
640
- bytes.writeUInt32LE(len, out + 4);
641
- return status;
642
- }
643
- #text(ptr, len) {
644
- return this.bytes().toString("utf8", ptr, ptr + len);
645
- }
646
- /** What the wasm calls: nothing here may throw into it, so every answer is a status. */
647
- #host() {
648
- return {
649
- hook: (namePtr, nameLen, keyPtr, keyLen, valuePtr, valueLen, out) => {
650
- const frame = this.#frames[this.#frames.length - 1];
651
- try {
652
- const value = JSON.parse(this.#text(valuePtr, valueLen));
653
- return this.#reply(out, DONE, frame.owner.renderHook(this.#text(namePtr, nameLen), this.#text(keyPtr, keyLen), value, frame.data));
654
- } catch (e) {
655
- frame.thrown = e;
656
- return this.#reply(out, ERROR, messageOf(e));
657
- }
658
- },
659
- call: (n, argsPtr, argsLen, out) => {
660
- const frame = this.#frames[this.#frames.length - 1];
661
- try {
662
- return this.#reply(out, DONE, toWasm(frame.owner.call(n, this.#text(argsPtr, argsLen), frame)));
663
- } catch (e) {
664
- frame.thrown = e;
665
- return this.#reply(out, ERROR, frame.owner.thrown(e));
666
- }
667
- },
668
- warn: (codePtr, codeLen, messagePtr, messageLen, filePtr, fileLen) => {
669
- try {
670
- if (this.#frames[this.#frames.length - 1]?.asked) return;
671
- const file = this.#text(filePtr, fileLen);
672
- warn(warning(this.#text(codePtr, codeLen), this.#text(messagePtr, messageLen), file === "" ? {} : { file }));
673
- } catch {
674
- }
675
- }
676
- };
677
- }
678
- /**
679
- * The calls Rust's std makes on `wasm32-wasip1`: no environment, real clocks, a fixed-seed
680
- * random generator (a `HashMap`'s order then repeats), standard error for a stray print, and
681
- * one folder, `/`, holding only the files Node gives it.
682
- */
683
- #wasi() {
684
- const view = () => new DataView(this.x.memory.buffer);
685
- let seed = 0x5eed5ca7c4edf007n;
686
- const mask = (1n << 64n) - 1n;
687
- return {
688
- environ_sizes_get: (count, size) => {
689
- view().setUint32(count, 0, true);
690
- view().setUint32(size, 0, true);
691
- return 0;
692
- },
693
- environ_get: () => 0,
694
- args_sizes_get: (count, size) => {
695
- view().setUint32(count, 0, true);
696
- view().setUint32(size, 0, true);
697
- return 0;
698
- },
699
- args_get: () => 0,
700
- clock_time_get: (id, _precision, out) => {
701
- view().setBigUint64(out, id === 0 ? BigInt(Date.now()) * 1000000n : process.hrtime.bigint(), true);
702
- return 0;
703
- },
704
- random_get: (ptr, len) => {
705
- const bytes = new Uint8Array(this.x.memory.buffer, ptr, len);
706
- for (let at = 0; at < len; at += 8) {
707
- seed ^= seed >> 12n;
708
- seed = (seed ^ seed << 25n) & mask;
709
- seed ^= seed >> 27n;
710
- let v = seed * 0x2545f4914f6cdd1dn & mask;
711
- for (let i = 0; i < 8 && at + i < len; i++) {
712
- bytes[at + i] = Number(v & 0xffn);
713
- v >>= 8n;
714
- }
715
- }
716
- return 0;
717
- },
718
- fd_write: (fd, iovs, count, written) => {
719
- const v = view();
720
- let total = 0;
721
- for (let i = 0; i < count; i++) {
722
- const ptr = v.getUint32(iovs + i * 8, true);
723
- const len = v.getUint32(iovs + i * 8 + 4, true);
724
- if (fd === 1 || fd === 2) process.stderr.write(new Uint8Array(this.x.memory.buffer, ptr, len).slice());
725
- total += len;
726
- }
727
- v.setUint32(written, total, true);
728
- return 0;
729
- },
730
- fd_prestat_get: (fd, out) => {
731
- if (fd !== ROOT_FD) return WASI_EBADF;
732
- view().setUint8(out, 0);
733
- view().setUint32(out + 4, 1, true);
734
- return 0;
735
- },
736
- fd_prestat_dir_name: (fd, ptr, len) => {
737
- if (fd !== ROOT_FD || len < 1) return WASI_EBADF;
738
- view().setUint8(ptr, "/".charCodeAt(0));
739
- return 0;
740
- },
741
- fd_fdstat_get: (fd, out) => {
742
- const filetype = fd === ROOT_FD ? 3 : this.#open.has(fd) ? 4 : fd <= 2 ? 2 : -1;
743
- if (filetype < 0) return WASI_EBADF;
744
- const v = view();
745
- v.setUint8(out, filetype);
746
- v.setUint16(out + 2, 0, true);
747
- v.setBigUint64(out + 8, mask, true);
748
- v.setBigUint64(out + 16, mask, true);
749
- return 0;
750
- },
751
- fd_filestat_get: (fd, out) => {
752
- const file = this.#open.get(fd);
753
- if (!file) return WASI_EBADF;
754
- new Uint8Array(this.x.memory.buffer, out, 64).fill(0);
755
- view().setUint8(out + 16, 4);
756
- view().setBigUint64(out + 32, BigInt(file.data.length), true);
757
- return 0;
758
- },
759
- path_open: (dirfd, _dirflags, ptr, len, _oflags, _base, _inheriting, _fdflags, out) => {
760
- if (dirfd !== ROOT_FD) return WASI_EBADF;
761
- const data = this.files.get(wasmPath(this.#text(ptr, len)));
762
- if (!data) return WASI_ENOENT;
763
- const fd = this.#nextFd++;
764
- this.#open.set(fd, { data, at: 0 });
765
- view().setUint32(out, fd, true);
766
- return 0;
767
- },
768
- fd_read: (fd, iovs, count, read) => {
769
- const file = this.#open.get(fd);
770
- if (!file) return WASI_EBADF;
771
- const v = view();
772
- let total = 0;
773
- for (let i = 0; i < count && file.at < file.data.length; i++) {
774
- const ptr = v.getUint32(iovs + i * 8, true);
775
- const len = v.getUint32(iovs + i * 8 + 4, true);
776
- const n = file.data.copy(this.bytes(), ptr, file.at, Math.min(file.at + len, file.data.length));
777
- file.at += n;
778
- total += n;
779
- }
780
- v.setUint32(read, total, true);
781
- return 0;
782
- },
783
- fd_close: (fd) => this.#open.delete(fd) || fd === ROOT_FD ? 0 : WASI_EBADF,
784
- proc_exit: (code) => {
785
- throw new Error(`exited with ${code}`);
786
- }
787
- };
788
- }
789
- };
790
- function internal(message, what) {
791
- return new BuildError(`${SOMETHING_LARGE}: internal error while processing ${what ?? page ?? "Markdown"}: ${message} (this is a bug in ssqch; please report it at ${ISSUES_URL})`);
792
- }
793
- function standIn(site2, args) {
794
- if (site2.slugger) return "";
795
- const [code] = JSON.parse(args);
796
- return [[String(code)]];
797
- }
798
- var isThenable = (v) => (typeof v === "object" || typeof v === "function") && v !== null && typeof v.then === "function";
799
- var UNDEFINED = { "\0": "undefined" };
800
- var FUNCTION = { "\0": "function" };
801
- function toWasm(value) {
802
- return JSON.stringify(value, function(key, v) {
803
- const original = this[key];
804
- if (original instanceof Date) return { "\0": "date", v: Number.isNaN(original.getTime()) ? "" : original.toISOString() };
805
- if (v === void 0 || typeof v === "symbol") return UNDEFINED;
806
- if (typeof v === "function") return FUNCTION;
807
- if (typeof v === "number" && !Number.isFinite(v)) return { "\0": String(v) };
808
- if (typeof v === "bigint") return Number(v);
809
- return v;
810
- });
811
- }
812
-
813
- // src/markdown-options.ts
814
- function defaultMarkdownOptions() {
815
- return {
816
- headingIds: "github",
817
- headingAttributes: true,
818
- footnotes: true,
819
- taskLists: true,
820
- autolinks: true,
821
- alerts: true,
822
- containers: true,
823
- definitionLists: false,
824
- smartPunctuation: false,
825
- indentedCode: true,
826
- highlight: false,
827
- highlightCss: "/highlight.css",
828
- languages: [],
829
- sluggerFn: null
830
- };
831
- }
832
- var MARKDOWN_KEYS = ["headingIds", "headingAttributes", "footnotes", "taskLists", "autolinks", "alerts", "containers", "definitionLists", "smartPunctuation", "indentedCode", "highlight"];
833
- var FLAGS = ["headingAttributes", "footnotes", "taskLists", "autolinks", "alerts", "containers", "definitionLists", "smartPunctuation", "indentedCode"];
834
- var typeOf = (v) => typeof v;
835
- function applyMarkdownOptions(options, value) {
836
- if (!isPlainObject(value)) bail(`markdown must be an object, not ${typeOf(value)}`);
837
- for (const [key, v] of Object.entries(value)) {
838
- if (key === "headingIds") {
839
- if (typeof v === "function") {
840
- options.sluggerFn = v;
841
- options.headingIds = "github";
842
- } else if (v === false || v === null) options.headingIds = null;
843
- else if (v === true) options.headingIds = "github";
844
- else if (typeof v === "string") {
845
- if (v !== "github" && v !== "blackfriday" && v !== "ascii") bail(`markdown.headingIds: unknown slugger "${v}" (use "github", "blackfriday", "ascii" or false)`);
846
- options.headingIds = v;
847
- } else bail(`markdown.headingIds must be "github", "blackfriday", "ascii" or false, not ${typeOf(v)}`);
848
- } else if (key === "highlight") {
849
- if (typeof v === "boolean") options.highlight = v;
850
- else if (isPlainObject(v)) {
851
- options.highlight = true;
852
- for (const [k, setting] of Object.entries(v)) {
853
- if (k === "css") {
854
- if (setting === false || setting === null) options.highlightCss = null;
855
- else if (typeof setting === "string" && setting.startsWith("/") && !setting.includes("..")) options.highlightCss = setting;
856
- else bail(`markdown.highlight.css must be a path like "/assets/highlight.css", or false, not ${typeof setting === "string" ? `"${setting}"` : typeOf(setting)}`);
857
- } else if (k === "languages") {
858
- if (!isPlainObject(setting)) bail(`markdown.highlight.languages must be an object of { name: highlighter }, not ${typeOf(setting)}`);
859
- for (const [name, language] of Object.entries(setting)) setLanguage(options, name, language);
860
- } else bail(`markdown.highlight.${k} isn't an option (options: css, languages)`);
861
- }
862
- } else bail(`markdown.highlight must be true, false or { css, languages }, not ${typeOf(v)}`);
863
- } else if (FLAGS.includes(key)) {
864
- if (typeof v !== "boolean") bail(`markdown.${key} must be true or false, not ${typeOf(v)}`);
865
- options[key] = v;
866
- } else {
867
- const near = closest(key, MARKDOWN_KEYS);
868
- bail(`markdown.${key} isn't an option${near ? ` (did you mean \`${near}\`?)` : ""} (options: ${MARKDOWN_KEYS.join(", ")})`);
869
- }
870
- }
871
- }
872
- function setLanguage(options, name, value) {
873
- let language;
874
- if (typeof value === "function") language = value;
875
- else if (typeof value === "string" && value.endsWith(".sublime-syntax")) language = { grammar: value };
876
- else if (typeof value === "string" && /[/\\]/.test(value)) bail(`markdown.highlight.languages.${name}: "${value}" isn't a .sublime-syntax file (a grammar's file name ends with .sublime-syntax)`);
877
- else if (typeof value === "string" && value.trim() !== "") language = { alias: value.trim().toLowerCase() };
878
- else bail(`markdown.highlight.languages.${name} must be a function (code, lang) => tokens, another language's name, or a path to a .sublime-syntax file, not ${typeOf(value)}`);
879
- if (name === "" || /[\s{},`]/.test(name)) bail(`markdown.highlight.languages: "${name}" can't be a language's name; a fence's language is one word (\`chordpro\`, \`cho\`)`);
880
- const lower = name.toLowerCase();
881
- const entry = options.languages.find(([n]) => n === lower);
882
- if (entry) entry[1] = language;
883
- else options.languages.push([lower, language]);
884
- }
885
-
886
- // src/slug.ts
887
- var ALPHANUMERIC = /[\p{Alphabetic}\p{N}]/u;
888
- function lowercase(text) {
889
- if (!text.includes("\u03A3")) return text.toLowerCase();
890
- let out = "";
891
- for (const c of text) out += c.toLowerCase();
892
- return out;
893
- }
894
- function slugWith(text, separator, apostrophesSeparate) {
895
- let out = "";
896
- let gap = false;
897
- for (const c of lowercase(text)) {
898
- if (ALPHANUMERIC.test(c)) {
899
- if (gap && out !== "") out += separator;
900
- gap = false;
901
- out += c;
902
- } else if (apostrophesSeparate || c !== "'" && c !== "\u2019") {
903
- gap = true;
904
- }
905
- }
906
- return out;
907
- }
908
- function slugOptions(option) {
909
- if (option === void 0 || option === null) return ["-", false];
910
- if (typeof option === "string") return [option, false];
911
- if (isPlainObject(option)) {
912
- const unknown = Object.keys(option).find((k) => k !== "separator" && k !== "apostrophes");
913
- if (unknown !== void 0) throw new BuildError(`slugify: unknown option \`${unknown}\` (options: separator, apostrophes)`);
914
- const separator = option.separator === void 0 || option.separator === null ? "-" : String(option.separator);
915
- const a = option.apostrophes;
916
- if (a === void 0 || a === null || a === "drop") return [separator, false];
917
- if (a === "separate") return [separator, true];
918
- throw new BuildError(`slugify: \`apostrophes\` is "drop" or "separate", not ${String(a)}`);
919
- }
920
- throw new BuildError(`slugify: the second argument is a separator ("_") or { separator, apostrophes }, not a ${typeof option}`);
921
- }
922
- function slugify(text, options) {
923
- const [separator, apostrophes] = slugOptions(options);
924
- return slugWith(text === void 0 || text === null ? "" : String(text), separator, apostrophes);
925
- }
926
-
927
- // src/api.ts
928
- import fs3 from "node:fs";
929
- import path2 from "node:path";
930
-
931
- // src/image/header.ts
932
- import fs2 from "node:fs";
933
- import zlib from "node:zlib";
934
- var FileBytes = class {
935
- fd;
936
- size;
937
- head;
938
- constructor(file) {
939
- this.fd = fs2.openSync(file, "r");
940
- try {
941
- this.size = fs2.fstatSync(this.fd).size;
942
- this.head = Buffer.allocUnsafe(Math.min(this.size, 16384));
943
- fs2.readSync(this.fd, this.head, 0, this.head.length, 0);
944
- } catch (e) {
945
- fs2.closeSync(this.fd);
946
- throw e;
947
- }
948
- }
949
- /** Exactly `length` bytes at `at`, or an error past the end. */
950
- read(at, length) {
951
- if (at < 0 || at + length > this.size) throw new Error(UNEXPECTED_END);
952
- if (at + length <= this.head.length) return this.head.subarray(at, at + length);
953
- const out = Buffer.alloc(length);
954
- fs2.readSync(this.fd, out, 0, length, at);
955
- return out;
956
- }
957
- close() {
958
- fs2.closeSync(this.fd);
959
- }
960
- };
961
- function withBytes(file, read) {
962
- const bytes = new FileBytes(file);
963
- try {
964
- return read(bytes);
965
- } finally {
966
- bytes.close();
967
- }
968
- }
969
- function guessFormat(head) {
970
- const starts = (...bytes) => bytes.every((b, i) => head[i] === b);
971
- const text = (at, s) => [...s].every((c, i) => head[at + i] === c.charCodeAt(0));
972
- if (starts(137, 80, 78, 71, 13, 10, 26, 10)) return "png";
973
- if (starts(255, 216, 255)) return "jpeg";
974
- if (text(0, "GIF89a") || text(0, "GIF87a")) return "gif";
975
- if (text(0, "RIFF") && text(8, "WEBP")) return "webp";
976
- if (text(0, "MM\0*") || text(0, "II*\0") || text(0, "BM") || starts(0, 0, 1, 0) || text(0, "#?RADIANCE") || text(0, "qoif") || text(4, "ftyp") || text(0, "DDS ") || starts(118, 47, 49, 1) || text(0, "farbfeld") || /^P[1-7]$/.test(String.fromCharCode(head[0] ?? 0, head[1] ?? 0))) return "other";
977
- return void 0;
978
- }
979
- var formatError = (format, message) => new Error(`Format error decoding ${format}: ${message}`);
980
- var UNEXPECTED_END = "unexpected end of file";
981
- var UNFILLED = "failed to fill whole buffer";
982
- function probeFile(file, named) {
983
- return withBytes(file, (bytes) => {
984
- const guessed = guessFormat(bytes.read(0, Math.min(32, bytes.size)));
985
- const format = guessed !== void 0 && guessed !== "other" ? guessed : named;
986
- return format === void 0 ? void 0 : probeBytes(bytes, format);
987
- });
988
- }
989
- function probeBytes(bytes, format) {
990
- switch (format) {
991
- case "jpeg":
992
- return probeJpeg(bytes);
993
- case "png":
994
- return probePng(bytes);
995
- case "gif":
996
- return probeGif(bytes);
997
- case "webp":
998
- return probeWebp(bytes);
999
- }
1000
- }
1001
- function probeGif(bytes) {
1002
- const eof = () => formatError("Gif", "Unexpected End of File");
1003
- if (bytes.size < 6) throw eof();
1004
- const magic = bytes.read(0, 6).toString("latin1");
1005
- if (magic !== "GIF87a" && magic !== "GIF89a") throw formatError("Gif", "malformed GIF header");
1006
- if (bytes.size < 13 + gifTableSize(bytes.read(6, Math.min(7, bytes.size - 6))[4] ?? 0)) throw eof();
1007
- return { format: "gif", width: bytes.read(6, 2).readUInt16LE(0), height: bytes.read(8, 2).readUInt16LE(0), orientation: 1 };
1008
- }
1009
- var gifTableSize = (flags) => flags & 128 ? 3 * 2 ** ((flags & 7) + 1) : 0;
1010
- function oriented(p) {
1011
- return p.orientation >= 5 && p.orientation <= 8 ? [p.height, p.width] : [p.width, p.height];
1012
- }
1013
- function probeJpeg(bytes) {
1014
- const end = bytes.size;
1015
- const short = (expected, at2) => formatError("Jpeg", `I/O errors Not enough bytes, expected ${expected} but found ${Math.max(0, Math.min(expected, end - at2))}`);
1016
- if (end < 2) throw short(2, 0);
1017
- const magic = bytes.read(0, 2).readUInt16BE(0);
1018
- if (magic !== 65496) throw formatError("Jpeg", `Error parsing image. Illegal start bytes:${magic.toString(16).toUpperCase()}`);
1019
- let at = 2;
1020
- let size;
1021
- let grey = false;
1022
- let exif;
1023
- const icc = [];
1024
- for (; ; ) {
1025
- if (at >= end) throw short(1, at);
1026
- if (bytes.read(at++, 1)[0] !== 255) continue;
1027
- let marker;
1028
- do {
1029
- if (at >= end) throw short(1, at);
1030
- marker = bytes.read(at++, 1)[0];
1031
- } while (marker === 255 || marker === 0);
1032
- if (marker === 1 || marker >= 208 && marker <= 216) continue;
1033
- if (marker === 217) throw formatError("Jpeg", "Premature End of image");
1034
- if (at + 2 > end) throw short(2, at);
1035
- const length = bytes.read(at, 2).readUInt16BE(0);
1036
- if (length < 2) throw formatError("Jpeg", `Found a marker with invalid length : ${length}`);
1037
- const body = at + 2;
1038
- if (body + length - 2 > end) {
1039
- if (marker === 219) throw short(body < end && bytes.read(body, 1)[0] >> 4 ? 128 : 64, body + 1);
1040
- const skipped = marker === 224 || marker >= 227 && marker <= 239 || marker === 254 || !(marker >= 192 && marker <= 226);
1041
- if (marker === 224 && length > 5 && body + 5 > end) throw short(5, body);
1042
- throw skipped ? short(1, end) : short(length - 2, body);
1043
- }
1044
- if (marker === 218) break;
1045
- if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
1046
- if (!size && length >= 8) {
1047
- const sof = bytes.read(body, 6);
1048
- size = [sof.readUInt16BE(3), sof.readUInt16BE(1)];
1049
- grey = sof[5] === 1;
1050
- }
1051
- } else if (marker === 225 && length >= 8) {
1052
- const data = bytes.read(body, length - 2);
1053
- if (!exif && data.subarray(0, 6).toString("latin1") === "Exif\0\0") exif = data.subarray(6);
1054
- } else if (marker === 226 && length >= 16) {
1055
- const data = bytes.read(body, length - 2);
1056
- if (data.subarray(0, 12).toString("latin1") === "ICC_PROFILE\0") icc.push([data[12], data.subarray(14)]);
1057
- }
1058
- at = body + length - 2;
1059
- }
1060
- if (!size) throw new Error("no frame header (SOF) found");
1061
- icc.sort((a, b) => a[0] - b[0]);
1062
- return { format: "jpeg", width: size[0], height: size[1], orientation: exif ? exifOrientation(exif) : 1, icc: icc.length ? Buffer.concat(icc.map(([, part]) => part)) : void 0, grey };
1063
- }
1064
- var PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
1065
- function probePng(bytes) {
1066
- const signature = bytes.read(0, Math.min(8, bytes.size));
1067
- if (!signature.equals(PNG_SIGNATURE.subarray(0, signature.length))) throw formatError("Png", "Invalid PNG signature.");
1068
- const ihdr = bytes.read(16, 10);
1069
- const [depth, colour] = [ihdr[8], ihdr[9]];
1070
- const out = { format: "png", width: ihdr.readUInt32BE(0), height: ihdr.readUInt32BE(4), orientation: 1, grey: colour === 0 || colour === 4, sixteen: depth === 16 };
1071
- let at = 8;
1072
- for (; ; ) {
1073
- const head = bytes.read(at, 8);
1074
- const length = head.readUInt32BE(0);
1075
- const type = head.subarray(4, 8).toString("latin1");
1076
- if (type === "IDAT") break;
1077
- if (type === "IEND") throw formatError("Png", "IDAT or fdAT chunk is missing.");
1078
- if (type === "iCCP" && !out.icc) {
1079
- const data = bytes.read(at + 8, length);
1080
- const name = data.indexOf(0);
1081
- try {
1082
- out.icc = zlib.inflateSync(data.subarray(name + 2));
1083
- } catch {
1084
- }
1085
- } else if (type === "eXIf") {
1086
- out.orientation = exifOrientation(bytes.read(at + 8, length));
1087
- }
1088
- at += 12 + length;
1089
- }
1090
- return out;
1091
- }
1092
- function probeWebp(bytes) {
1093
- if (bytes.size < 8) throw new Error(UNFILLED);
1094
- if (bytes.read(0, 4).toString("latin1") !== "RIFF") throw formatError("WebP", "Invalid Chunk header: [52, 49, 46, 46]");
1095
- if (bytes.size < 20) throw new Error(UNFILLED);
1096
- const signature = bytes.read(8, 4);
1097
- if (signature.toString("latin1") !== "WEBP") throw formatError("WebP", `Invalid WebP signature: [${[...signature].map((b) => b.toString(16)).join(", ")}]`);
1098
- try {
1099
- return webpChunks(bytes);
1100
- } catch (e) {
1101
- if (e.message === UNEXPECTED_END) throw new Error(UNFILLED);
1102
- throw e;
1103
- }
1104
- }
1105
- function webpChunks(bytes) {
1106
- const out = { format: "webp", width: 0, height: 0, orientation: 1 };
1107
- let at = 12;
1108
- let sized = false;
1109
- while (at + 8 <= bytes.size) {
1110
- const head = bytes.read(at, 8);
1111
- const type = head.subarray(0, 4).toString("latin1");
1112
- const length = head.readUInt32LE(4);
1113
- const body = at + 8;
1114
- if (type === "VP8X") {
1115
- const d = bytes.read(body, 10);
1116
- [out.width, out.height] = [d.readUIntLE(4, 3) + 1, d.readUIntLE(7, 3) + 1];
1117
- sized = true;
1118
- } else if (type === "VP8 " && !sized) {
1119
- const d = bytes.read(body, 10);
1120
- [out.width, out.height] = [d.readUInt16LE(6) & 16383, d.readUInt16LE(8) & 16383];
1121
- sized = true;
1122
- } else if (type === "VP8L" && !sized) {
1123
- const bits = bytes.read(body + 1, 4).readUInt32LE(0);
1124
- [out.width, out.height] = [(bits & 16383) + 1, (bits >>> 14 & 16383) + 1];
1125
- sized = true;
1126
- } else if (type === "ICCP") {
1127
- out.icc = Buffer.from(bytes.read(body, length));
1128
- }
1129
- at = body + length + (length & 1);
1130
- }
1131
- if (!sized) throw new Error(UNFILLED);
1132
- return out;
1133
- }
1134
- function undecodable(contents, format) {
1135
- switch (format) {
1136
- case "png":
1137
- return pngDamage(contents);
1138
- case "gif":
1139
- return gifDamage(contents);
1140
- case "webp":
1141
- return webpDamage(contents);
1142
- case "jpeg":
1143
- return void 0;
1144
- }
1145
- }
1146
- function pngDamage(png) {
1147
- let at = 8;
1148
- for (; ; ) {
1149
- if (at + 12 > png.length) return UNEXPECTED_END;
1150
- const length = png.readUInt32BE(at);
1151
- if (at + 12 + length > png.length) return UNEXPECTED_END;
1152
- const type = png.subarray(at + 4, at + 8);
1153
- if ((type[0] & 32) === 0) {
1154
- const [stored, sum] = [png.readUInt32BE(at + 8 + length), zlib.crc32(png.subarray(at + 4, at + 8 + length)) >>> 0];
1155
- if (stored !== sum) {
1156
- const flag = (i) => (type[i] & 32) !== 0;
1157
- const name = [...type].map((c) => String.fromCharCode(c)).join("");
1158
- return `Format error decoding Png: CRC error: expected 0x${stored.toString(16)} have 0x${sum.toString(16)} while decoding ChunkType { type: ${name}, critical: ${!flag(0)}, private: ${flag(1)}, reserved: ${flag(2)}, safecopy: ${flag(3)} } chunk.`;
1159
- }
1160
- }
1161
- if (type.toString("latin1") === "IEND") return void 0;
1162
- at += 12 + length;
1163
- }
1164
- }
1165
- function gifDamage(gif) {
1166
- const eof = "Format error decoding Gif: Unexpected End of File";
1167
- let at = 13 + gifTableSize(gif[10]);
1168
- const blocks = (from) => {
1169
- let i = from;
1170
- for (; ; ) {
1171
- if (i >= gif.length) return -1;
1172
- const n = gif[i];
1173
- i += 1 + n;
1174
- if (n === 0) return i;
1175
- }
1176
- };
1177
- for (; ; ) {
1178
- if (at >= gif.length) return eof;
1179
- const kind = gif[at];
1180
- if (kind === 33) {
1181
- if (at + 2 > gif.length) return eof;
1182
- at = blocks(at + 2);
1183
- if (at === -1) return eof;
1184
- } else if (kind === 44) {
1185
- if (at + 10 > gif.length) return eof;
1186
- at = blocks(at + 11 + gifTableSize(gif[at + 9]));
1187
- return at === -1 || at > gif.length ? eof : void 0;
1188
- } else {
1189
- return void 0;
1190
- }
1191
- }
1192
- }
1193
- function webpDamage(webp) {
1194
- let at = 12;
1195
- while (at < webp.length) {
1196
- if (at + 8 > webp.length) return UNFILLED;
1197
- const type = webp.toString("latin1", at, at + 4);
1198
- const length = webp.readUInt32LE(at + 4);
1199
- if (at + 8 + length > webp.length) return type === "VP8 " || type === "VP8L" || type === "ALPH" || type === "ANMF" ? "Format error decoding WebP: Corrupt bitstream" : UNFILLED;
1200
- at += 8 + length + (length & 1);
1201
- }
1202
- return void 0;
1203
- }
1204
- function exifOrientation(exif) {
1205
- try {
1206
- const data = exif.subarray(0, 6).toString("latin1") === "Exif\0\0" ? exif.subarray(6) : exif;
1207
- const order = data.subarray(0, 2).toString("latin1");
1208
- if (order !== "II" && order !== "MM") return 1;
1209
- const le = order === "II";
1210
- const u16 = (at) => le ? data.readUInt16LE(at) : data.readUInt16BE(at);
1211
- const u32 = (at) => le ? data.readUInt32LE(at) : data.readUInt32BE(at);
1212
- if (u16(2) !== 42) return 1;
1213
- const ifd = u32(4);
1214
- const count = u16(ifd);
1215
- for (let i = 0; i < count; i++) {
1216
- const entry = ifd + 2 + i * 12;
1217
- if (u16(entry) === 274) {
1218
- const value = u16(entry + 8);
1219
- return value >= 1 && value <= 8 ? value : 1;
1220
- }
1221
- }
1222
- } catch {
1223
- }
1224
- return 1;
1225
- }
1226
- function imageSize(file) {
1227
- try {
1228
- return withBytes(file, (bytes) => {
1229
- const head = bytes.read(0, 12);
1230
- const text = (at, s) => head.subarray(at, at + s.length).toString("latin1") === s;
1231
- if (head[0] === 255 && head[1] === 216 && head[2] === 255) return jpegSize(bytes);
1232
- if (text(0, "\x89PNG")) return [bytes.read(16, 4).readUInt32BE(0), bytes.read(20, 4).readUInt32BE(0)];
1233
- if (text(0, "GIF8")) return [bytes.read(6, 2).readUInt16LE(0), bytes.read(8, 2).readUInt16LE(0)];
1234
- if (text(0, "II") && (head[2] === 42 || head[2] === 43) && head[3] === 0 || text(0, "MM\0") && (head[3] === 42 || head[3] === 43)) return tiffSize(bytes);
1235
- if (text(0, "RIFF") && text(8, "WEBP")) return webpSize(bytes);
1236
- if (text(4, "ftyp")) return heifSize(bytes);
1237
- if (text(0, "BM")) return [bytes.read(18, 4).readUInt32LE(0), bytes.read(22, 4).readUInt32LE(0)];
1238
- if (text(0, "8BPS")) return [bytes.read(18, 4).readUInt32BE(0), bytes.read(14, 4).readUInt32BE(0)];
1239
- if (head[0] === 0 && head[1] === 0 && head[2] === 1 && head[3] === 0) return icoSize(bytes);
1240
- if (text(0, "qoif")) return [bytes.read(4, 4).readUInt32BE(0), bytes.read(8, 4).readUInt32BE(0)];
1241
- return void 0;
1242
- });
1243
- } catch {
1244
- return void 0;
1245
- }
1246
- }
1247
- function jpegSize(bytes) {
1248
- let at = 2;
1249
- let depth = 0;
1250
- for (; ; ) {
1251
- const marker = bytes.read(at, 2);
1252
- if (marker[0] !== 255) throw new Error("corrupted");
1253
- const page2 = marker[1];
1254
- if (page2 >= 192 && page2 <= 195 || page2 >= 197 && page2 <= 199 || page2 >= 201 && page2 <= 203 || page2 >= 205 && page2 <= 207) {
1255
- if (depth === 0) {
1256
- const sof = bytes.read(at + 5, 4);
1257
- return [sof.readUInt16BE(2), sof.readUInt16BE(0)];
1258
- }
1259
- } else if (page2 === 216) depth++;
1260
- else if (page2 === 217) {
1261
- depth--;
1262
- if (depth < 0) throw new Error("corrupted");
1263
- }
1264
- at += 2 + bytes.read(at + 2, 2).readUInt16BE(0);
1265
- }
1266
- }
1267
- function webpSize(bytes) {
1268
- const tag = bytes.read(12, 4)[3];
1269
- if (tag === 32) return [bytes.read(26, 2).readUInt16LE(0), bytes.read(28, 2).readUInt16LE(0)];
1270
- if (tag === 76) {
1271
- const dims = bytes.read(21, 4).readUInt32LE(0);
1272
- return [(dims & 16383) + 1, (dims >>> 14 & 16383) + 1];
1273
- }
1274
- if (tag === 88) return [bytes.read(24, 3).readUIntLE(0, 3) + 1, bytes.read(27, 3).readUIntLE(0, 3) + 1];
1275
- throw new Error("invalid VP8 tag");
1276
- }
1277
- function tiffSize(bytes) {
1278
- const le = bytes.read(0, 2).toString("latin1") === "II";
1279
- const u16 = (at2) => le ? bytes.read(at2, 2).readUInt16LE(0) : bytes.read(at2, 2).readUInt16BE(0);
1280
- const u32 = (at2) => le ? bytes.read(at2, 4).readUInt32LE(0) : bytes.read(at2, 4).readUInt32BE(0);
1281
- const u64 = (at2) => Number(le ? bytes.read(at2, 8).readBigUInt64LE(0) : bytes.read(at2, 8).readBigUInt64BE(0));
1282
- const big = u16(2) === 43;
1283
- let at = 4;
1284
- if (big) {
1285
- if (u16(4) !== 8 || u16(6) !== 0) throw new Error("invalid BigTIFF header");
1286
- at = 8;
1287
- }
1288
- const ifd = big ? u64(at) : u32(at);
1289
- if (ifd === 0) throw new Error("invalid IFD offset");
1290
- const count = big ? u64(ifd) : u16(ifd);
1291
- let entry = ifd + (big ? 8 : 2);
1292
- let width;
1293
- let height;
1294
- for (let i = 0; i < count; i++) {
1295
- const tag = u16(entry);
1296
- const kind = u16(entry + 2);
1297
- const valueAt = entry + (big ? 12 : 8);
1298
- const size = [1, 2, 6, 7].includes(kind) ? 1 : kind === 3 || kind === 8 ? 2 : [4, 9, 11, 13].includes(kind) ? 4 : kind === 5 || kind === 10 ? 8 : kind === 12 ? 8 : kind >= 16 && kind <= 18 && big ? 8 : -1;
1299
- if (size === -1) throw new Error("invalid IFD type");
1300
- bytes.read(valueAt, big ? 8 : 4);
1301
- const value = size === 2 ? u16(valueAt) : size === 4 ? u32(valueAt) : void 0;
1302
- if (tag === 256) width = value;
1303
- else if (tag === 257) height = value;
1304
- if (width !== void 0 && height !== void 0) return [width, height];
1305
- entry = valueAt + (big ? 8 : 4);
1306
- }
1307
- throw new Error("no dimensions in the IFD's tags");
1308
- }
1309
- function icoSize(bytes) {
1310
- const count = bytes.read(4, 2).readUInt16LE(0);
1311
- let best;
1312
- let at = 6;
1313
- for (let i = 0; i < count; i++) {
1314
- let entry;
1315
- try {
1316
- entry = bytes.read(at, 2);
1317
- } catch {
1318
- break;
1319
- }
1320
- const size = [(entry[0] + 255 & 255) + 1, (entry[1] + 255 & 255) + 1];
1321
- if (!best || size[0] > best[0] || size[0] === best[0] && size[1] > best[1]) best = size;
1322
- at += 16;
1323
- }
1324
- if (!best) throw new Error("corrupted");
1325
- return best;
1326
- }
1327
- function heifSize(bytes) {
1328
- let at = bytes.read(0, 4).readUInt32BE(0);
1329
- const skipTo = (tag) => {
1330
- for (; ; ) {
1331
- const head = bytes.read(at, 8);
1332
- const size = head.readUInt32BE(0);
1333
- at += 8;
1334
- if (head.subarray(4, 8).toString("latin1") === tag) return size;
1335
- if (size < 8) throw new Error(`invalid heif box size: ${size}`);
1336
- at += size - 8;
1337
- }
1338
- };
1339
- skipTo("meta");
1340
- at += 4;
1341
- skipTo("iprp");
1342
- let ipco = skipTo("ipco");
1343
- let [width, height] = [0, 0];
1344
- let found = false;
1345
- let rotation = 0;
1346
- for (; ; ) {
1347
- let head;
1348
- try {
1349
- head = bytes.read(at, 8);
1350
- } catch {
1351
- break;
1352
- }
1353
- const size = head.readUInt32BE(0);
1354
- const tag = head.subarray(4, 8).toString("latin1");
1355
- at += 8;
1356
- if (size < 8) {
1357
- if (tag === "mdat") break;
1358
- throw new Error("corrupted");
1359
- }
1360
- if (tag === "ispe") {
1361
- found = true;
1362
- const box = bytes.read(at, 12);
1363
- at += 12;
1364
- const [w, h] = [box.readUInt32BE(4), box.readUInt32BE(8)];
1365
- if (w * h > width * height) [width, height] = [w, h];
1366
- } else if (tag === "irot") {
1367
- rotation = bytes.read(at, 1)[0];
1368
- at += 1;
1369
- } else if (size >= ipco) {
1370
- break;
1371
- } else {
1372
- ipco -= size;
1373
- at += size - 8;
1374
- }
1375
- }
1376
- if (!found) throw new Error("not enough data");
1377
- return rotation === 1 || rotation === 3 ? [height, width] : [width, height];
1378
- }
1379
-
1380
- // src/api.ts
1381
- function defaultMarkdown() {
1382
- const engine = markdownEngine(defaultMarkdownOptions());
1383
- return (text, inline) => engine.plain(text, inline);
1384
- }
1385
- var site = { root: process.cwd(), input: null, markdown: null };
1386
- var defineConfig = (config) => config;
1387
- function markdown(text, options = {}) {
1388
- for (const key of Object.keys(options ?? {})) {
1389
- if (key !== "inline") throw new TypeError(`markdown(): unknown option "${key}" (options: inline)`);
1390
- }
1391
- site.markdown ??= defaultMarkdown();
1392
- return site.markdown(String(text ?? ""), Boolean(options?.inline));
1393
- }
1394
- function readData(file) {
1395
- const rel = String(file);
1396
- const abs = path2.resolve(site.root, rel);
1397
- const call = `readData(${JSON.stringify(rel)})`;
1398
- if (!/\.(json|ya?ml|toml)$/i.test(rel)) throw new BuildError(`${call}: not a JSON, YAML or TOML file`);
1399
- if (!fs3.statSync(abs, { throwIfNoEntry: false })?.isFile()) throw new BuildError(`${call}: no such file (reading ${abs})`);
1400
- const value = loadStaticDataFile(abs);
1401
- if (value === void 0) throw new BuildError(`${call}: not a JSON, YAML or TOML file`);
1402
- return value;
1403
- }
1404
- function files(pattern, options = {}) {
1405
- for (const key of Object.keys(options ?? {})) {
1406
- if (key !== "dimensions") throw new TypeError(`files(): unknown option "${key}" (options: dimensions)`);
1407
- }
1408
- const given = String(pattern ?? "");
1409
- const call = `files(${JSON.stringify(given)})`;
1410
- const glob = given.trim().replace(/^(\.\/)+/, "");
1411
- if (glob === "") throw new BuildError(`${call}: give a glob, like files("images/*.jpg")`);
1412
- if (path2.isAbsolute(glob) || glob.split("/").includes("..")) throw new BuildError(`${call}: the glob is from the project root, and can't leave it`);
1413
- const problem = globProblem(glob);
1414
- if (problem) throw new BuildError(`${call}: not a glob (error parsing glob '${glob}': ${problem})`);
1415
- const matches = globToRegExp(glob, { ignoreCase: true });
1416
- const base = isGlob(glob) ? globBase(glob) : path2.posix.dirname(glob) === "." ? "" : path2.posix.dirname(glob);
1417
- const found = [];
1418
- const walk = (dir, rel) => {
1419
- let entries;
1420
- try {
1421
- entries = fs3.readdirSync(dir, { withFileTypes: true });
1422
- } catch {
1423
- return;
1424
- }
1425
- for (const entry of entries) {
1426
- const abs = path2.join(dir, entry.name);
1427
- const p = rel ? `${rel}/${entry.name}` : entry.name;
1428
- const stat = fs3.statSync(abs, { throwIfNoEntry: false });
1429
- if (!stat) continue;
1430
- if (stat.isDirectory()) walk(abs, p);
1431
- else if (stat.isFile() && entry.name !== ".DS_Store" && matches.test(p)) found.push([p, abs, stat]);
1432
- }
1433
- };
1434
- walk(path2.join(site.root, base), base);
1435
- found.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
1436
- const sizes = options?.dimensions ? imageSizes(found) : [];
1437
- return found.map(([rel, abs, stat], i) => {
1438
- const name = path2.basename(abs);
1439
- const dot = name.lastIndexOf(".");
1440
- const [stem, ext] = dot > 0 ? [name.slice(0, dot), name.slice(dot + 1).toLowerCase()] : [name, ""];
1441
- const fromInput = site.input && abs.startsWith(site.input + path2.sep) ? path2.relative(site.input, abs).split(path2.sep).join("/") : rel;
1442
- const named = dateInName(name);
1443
- const info = { path: rel, url: `/${fromInput}`, name, stem, ext, date: named ?? stat.mtime, dateFrom: named ? "name" : "modified", size: stat.size };
1444
- if (options?.dimensions) [info.width, info.height] = sizes[i] ?? [null, null];
1445
- return info;
1446
- });
1447
- }
1448
- var SIZES_CACHE = ".cache/ssqch/image-sizes.json";
1449
- function imageSizes(found) {
1450
- const file = path2.join(site.root, SIZES_CACHE);
1451
- let cache = {};
1452
- try {
1453
- const parsed = JSON.parse(fs3.readFileSync(file, "utf8"), (_key, value, context2) => typeof value === "number" ? context2?.source ?? String(value) : value);
1454
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) cache = parsed;
1455
- } catch {
1456
- }
1457
- let changed = false;
1458
- const sizes = found.map(([rel, abs]) => {
1459
- const stat = fs3.statSync(abs, { bigint: true, throwIfNoEntry: false });
1460
- const stamp = [String(stat?.size ?? 0), String(stat?.mtimeNs ?? 0)];
1461
- const kept = cache[rel];
1462
- if (Array.isArray(kept) && kept[0] === stamp[0] && kept[1] === stamp[1]) {
1463
- const size2 = kept[2];
1464
- return Array.isArray(size2) ? [Number(size2[0]), Number(size2[1])] : void 0;
1465
- }
1466
- const size = imageSize(abs);
1467
- cache[rel] = [stamp[0], stamp[1], size ? [String(size[0]), String(size[1])] : null];
1468
- changed = true;
1469
- return size;
1470
- });
1471
- if (changed) {
1472
- const json = `{${Object.entries(cache).map(([rel, [size, modified, dims]]) => `${JSON.stringify(rel)}:[${size},${modified},${dims ? `[${dims[0]},${dims[1]}]` : "null"}]`).join(",")}}`;
1473
- try {
1474
- fs3.mkdirSync(path2.dirname(file), { recursive: true });
1475
- fs3.writeFileSync(file, json);
1476
- } catch {
1477
- }
1478
- }
1479
- return sizes;
1480
- }
1481
- function dateInName(name) {
1482
- const compact = /^(\d{4})(\d{2})(\d{2})(?!\d)/.exec(name);
1483
- const dashed = /^(\d{4})-(\d{2})-(\d{2})/.exec(name);
1484
- const found = compact ?? dashed;
1485
- if (!found) return void 0;
1486
- const [year, month, day] = [Number(found[1]), Number(found[2]), Number(found[3])];
1487
- const date = new Date(Date.UTC(year, month - 1, day));
1488
- return date.getUTCMonth() === month - 1 && date.getUTCDate() === day ? date : void 0;
1489
- }
1490
- function slugify2(text, options) {
1491
- return slugify(text, options);
1492
- }
1493
- function slugger(options = {}) {
1494
- const separator = slugify2("a b", options).slice(1, -1);
1495
- const seen = /* @__PURE__ */ new Map();
1496
- return (text) => {
1497
- const base = slugify2(text, options);
1498
- if (!seen.has(base)) {
1499
- seen.set(base, 0);
1500
- return base;
1501
- }
1502
- let n = seen.get(base);
1503
- let made;
1504
- do {
1505
- n++;
1506
- made = `${base}${separator}${n}`;
1507
- } while (seen.has(made));
1508
- seen.set(base, n);
1509
- seen.set(made, 0);
1510
- return made;
1511
- };
1512
- }
1513
- var api_default = { defineConfig, markdown, readData, files, slugify: slugify2, slugger };
1514
-
1515
- export {
1516
- probeFile,
1517
- oriented,
1518
- undecodable,
1519
- WebAssembly,
1520
- loadHookTemplates,
1521
- writeHighlightCss,
1522
- rendering,
1523
- markdownEngine,
1524
- checkLanguages,
1525
- beginFenceCache,
1526
- saveFenceCache,
1527
- defaultMarkdownOptions,
1528
- applyMarkdownOptions,
1529
- slugWith,
1530
- slugOptions,
1531
- site,
1532
- defineConfig,
1533
- markdown,
1534
- readData,
1535
- files,
1536
- slugify2 as slugify,
1537
- slugger,
1538
- api_default
1539
- };