create-opentray 0.21.0 → 0.22.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 (46) hide show
  1. package/README.md +28 -6
  2. package/dist/avif-DCXcyYJR.mjs +2 -0
  3. package/dist/bin-Dyfucd3C.mjs +20810 -0
  4. package/dist/bin-Dyfucd3C.mjs.map +1 -0
  5. package/dist/bin.mjs +1 -1
  6. package/dist/decode-C4b5NXc_.mjs +1236 -0
  7. package/dist/decode-C4b5NXc_.mjs.map +1 -0
  8. package/dist/decode-Dsj9J0OD.mjs +1214 -0
  9. package/dist/decode-Dsj9J0OD.mjs.map +1 -0
  10. package/dist/decode-FysWS28R.mjs +254 -0
  11. package/dist/decode-FysWS28R.mjs.map +1 -0
  12. package/dist/decode-Xr7mARKr.mjs +1262 -0
  13. package/dist/decode-Xr7mARKr.mjs.map +1 -0
  14. package/dist/decode-ico-D3SL2BXi.mjs +274 -0
  15. package/dist/decode-ico-D3SL2BXi.mjs.map +1 -0
  16. package/dist/full.umd-oM1VUBRH.mjs +3055 -0
  17. package/dist/full.umd-oM1VUBRH.mjs.map +1 -0
  18. package/dist/index.d.mts +491 -11
  19. package/dist/index.d.mts.map +1 -1
  20. package/dist/index.mjs +1 -2
  21. package/dist/jpeg-B4tsxG5f.mjs +2 -0
  22. package/dist/png-rD0XEazj.mjs +35 -0
  23. package/dist/png-rD0XEazj.mjs.map +1 -0
  24. package/dist/raster-BQ07mKLu.mjs +493 -0
  25. package/dist/raster-BQ07mKLu.mjs.map +1 -0
  26. package/dist/resize-B47sgoOb.mjs +489 -0
  27. package/dist/resize-B47sgoOb.mjs.map +1 -0
  28. package/dist/resvg-wasm-fcJTLpJs.mjs +522 -0
  29. package/dist/resvg-wasm-fcJTLpJs.mjs.map +1 -0
  30. package/dist/rolldown-runtime-JspESFgx.mjs +35 -0
  31. package/dist/shell/assets/browse.js +1 -1
  32. package/dist/shell/assets/index.css +1 -1
  33. package/dist/shell/assets/main.js +17 -17
  34. package/dist/skill/SKILL.md +46 -17
  35. package/dist/skill/references/cli-reference.md +8 -3
  36. package/dist/skill/references/how-it-works.md +30 -0
  37. package/dist/webp-CcbaCrQ7.mjs +2 -0
  38. package/dist/webui/assets/browse.js +1 -1
  39. package/dist/webui/assets/index.css +1 -1
  40. package/dist/webui/assets/main.js +17 -17
  41. package/package.json +7 -8
  42. package/skill/SKILL.md +46 -17
  43. package/skill/references/cli-reference.md +8 -3
  44. package/skill/references/how-it-works.md +30 -0
  45. package/dist/bin-Dl6P1QjJ.mjs +0 -2213
  46. package/dist/bin-Dl6P1QjJ.mjs.map +0 -1
@@ -0,0 +1,493 @@
1
+ import { i as __toESM } from "./rolldown-runtime-JspESFgx.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { readFile, readdir } from "node:fs/promises";
4
+ import { homedir, platform } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { readFileSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ //#region ../icon/src/assets.ts
9
+ /**
10
+ * Bundled asset resolution. Assets live at the package root (`assets/`),
11
+ * exactly one level above both `src/` (source checkout) and `dist/` (built
12
+ * output), so the resolution is uniform: package.json `files` ships both
13
+ * `dist` and `assets`.
14
+ */
15
+ const moduleDirectory = dirname(fileURLToPath(import.meta.url));
16
+ const assetsDirectory = () => join(moduleDirectory, "..", "assets");
17
+ //#endregion
18
+ //#region ../icon/src/fonts.ts
19
+ /**
20
+ * Glyph font ladder (plan D5; spike-verified): the WASM rasterizer cannot
21
+ * autoload system fonts, and `loadSystemFonts: true` silently drops text, so
22
+ * every render must pass explicit `fontBuffers`:
23
+ *
24
+ * 1. the embedded OFL subset (deterministic Latin rendering everywhere), then
25
+ * 2. a bounded, ranked scan of well-known OS font directories (CJK and other
26
+ * scripts beyond the embedded subset).
27
+ *
28
+ * Rendering quality is verified empirically downstream (text-presence pixel
29
+ * check in default-icon.ts) — the ladder never silently accepts a blank tile.
30
+ */
31
+ /** Family name referenced by generated glyph SVG text elements. */
32
+ const GLYPH_FONT_FAMILY = "OpenTray Glyph";
33
+ /**
34
+ * Preferred font basenames, highest priority first. CJK-capable fonts lead:
35
+ * the embedded subset already covers Latin, so discovery exists for wider
36
+ * scripts. UI fonts follow so headless Linux still finds a fallback.
37
+ */
38
+ const PREFERRED_PATTERNS = [
39
+ /pingfang|stheiti|hiragino|songti|heiti|kaiti|yuanti/i,
40
+ /sourcehan|source-han|noto.{0,12}(cjk|sc|tc|jp|kr)|wqy|droidsansfallback/i,
41
+ /msyh|msjh|simsun|simhei|simkai|simfang|deng/i,
42
+ /segoeui|arial|helvetica|liberationsans|dejavusans|roboto-regular|ubuntu-regular/i
43
+ ];
44
+ const FONT_EXTENSIONS = /* @__PURE__ */ new Set([
45
+ ".ttf",
46
+ ".otf",
47
+ ".ttc",
48
+ ".otc"
49
+ ]);
50
+ /** Discovery caps: glyph generation reads fonts once per cache miss. */
51
+ const MAX_FONT_FILES = 10;
52
+ const MAX_TOTAL_BYTES = 192 * 1024 * 1024;
53
+ const systemFontDirectories = () => {
54
+ const home = homedir();
55
+ switch (platform()) {
56
+ case "darwin": return [
57
+ "/System/Library/Fonts",
58
+ "/System/Library/Fonts/Supplemental",
59
+ "/Library/Fonts",
60
+ join(home, "Library", "Fonts")
61
+ ];
62
+ case "win32": return [join(process.env.SystemRoot ?? "C:\\Windows", "Fonts"), join(process.env.LOCALAPPDATA ?? join(home, "AppData", "Local"), "Microsoft", "Windows", "Fonts")];
63
+ default: return [
64
+ "/usr/share/fonts",
65
+ "/usr/local/share/fonts",
66
+ join(home, ".local", "share", "fonts"),
67
+ join(home, ".fonts")
68
+ ];
69
+ }
70
+ };
71
+ const listFontFiles = async (directory, depth = 2) => {
72
+ const found = [];
73
+ let entries;
74
+ try {
75
+ entries = await readdir(directory, { withFileTypes: true });
76
+ } catch {
77
+ return found;
78
+ }
79
+ for (const entry of entries) {
80
+ const entryPath = join(directory, entry.name);
81
+ if (entry.isDirectory() && depth > 0) found.push(...await listFontFiles(entryPath, depth - 1));
82
+ else if (entry.isFile() && FONT_EXTENSIONS.has(extOf(entry.name))) found.push(entryPath);
83
+ }
84
+ return found;
85
+ };
86
+ const extOf = (name) => {
87
+ const dot = name.lastIndexOf(".");
88
+ return dot === -1 ? "" : name.slice(dot).toLowerCase();
89
+ };
90
+ const priorityOf = (path) => {
91
+ for (let index = 0; index < PREFERRED_PATTERNS.length; index += 1) if (PREFERRED_PATTERNS[index].test(path)) return index;
92
+ return PREFERRED_PATTERNS.length;
93
+ };
94
+ const cache = /* @__PURE__ */ new Map();
95
+ /** Embedded OFL subset bytes (Inter SemiBold, latin; see assets/*.OFL.txt). */
96
+ const embeddedGlyphFont = async () => {
97
+ const path = join(assetsDirectory(), "inter-glyph.ttf");
98
+ const cached = cache.get(path);
99
+ if (cached !== void 0) return cached;
100
+ const bytes = new Uint8Array(await readFile(path));
101
+ cache.set(path, bytes);
102
+ return bytes;
103
+ };
104
+ let ladderPromise;
105
+ let ladderFingerprintPromise;
106
+ /**
107
+ * Stable identity of the discovered ladder (path + byte length pairs): OS
108
+ * font changes invalidate generated-icon caches without hashing font bytes.
109
+ */
110
+ const glyphLadderFingerprint = () => {
111
+ ladderFingerprintPromise ??= (async () => {
112
+ const parts = [];
113
+ for (const buffer of await glyphFontLadder()) parts.push(`${buffer.byteLength}`);
114
+ return parts.join(",");
115
+ })();
116
+ return ladderFingerprintPromise;
117
+ };
118
+ /**
119
+ * The full font ladder for resvg `fontBuffers`: embedded subset first, then a
120
+ * bounded ranked selection from the OS. Deterministic order, memoized.
121
+ */
122
+ const glyphFontLadder = () => {
123
+ ladderPromise ??= (async () => {
124
+ const embedded = await embeddedGlyphFont();
125
+ const candidates = [];
126
+ for (const directory of systemFontDirectories()) for (const path of await listFontFiles(directory)) candidates.push({
127
+ path,
128
+ priority: priorityOf(path)
129
+ });
130
+ candidates.sort((a, b) => a.priority - b.priority || (a.path < b.path ? -1 : 1));
131
+ const buffers = [embedded];
132
+ let total = embedded.byteLength;
133
+ for (const { path } of candidates) {
134
+ if (buffers.length >= MAX_FONT_FILES || total >= MAX_TOTAL_BYTES) break;
135
+ const cached = cache.get(path);
136
+ if (cached !== void 0) {
137
+ buffers.push(cached);
138
+ total += cached.byteLength;
139
+ continue;
140
+ }
141
+ try {
142
+ const bytes = new Uint8Array(await readFile(path));
143
+ cache.set(path, bytes);
144
+ buffers.push(bytes);
145
+ total += bytes.byteLength;
146
+ } catch {}
147
+ }
148
+ return buffers;
149
+ })();
150
+ return ladderPromise;
151
+ };
152
+ //#endregion
153
+ //#region ../icon/src/types.ts
154
+ const makeImage = (data, width, height) => ({
155
+ data,
156
+ width,
157
+ height,
158
+ colorSpace: "srgb"
159
+ });
160
+ //#endregion
161
+ //#region ../icon/src/wasm.ts
162
+ /**
163
+ * Lazy WASM bootstrap for the kernel's image stack (spike-verified
164
+ * 2026-09-09, demos/wasm-spike):
165
+ *
166
+ * - jsquash v3 codecs auto-`init()` through `fetch(new URL(...))` which Node
167
+ * rejects for file URLs. The only reliable Node path is pre-initializing
168
+ * with the wasm bytes read from disk, via each codec's subpath export.
169
+ * - `@resvg/resvg-wasm` cannot load system fonts in a WASM environment; text
170
+ * must arrive as explicit `fontBuffers` (see fonts.ts). `loadSystemFonts`
171
+ * stays false everywhere — with it true, resvg silently drops text.
172
+ *
173
+ * Every loader is a memoized singleton so repeated generation calls pay the
174
+ * wasm handshake once per process. Initialization failure throws a typed
175
+ * error; callers (runtime daemon, build tools) decide their own fallback.
176
+ */
177
+ const require = createRequire(import.meta.url);
178
+ /**
179
+ * Exact-typed wasm bytes (TS 5.7 typed-array variance: a fresh copy over a
180
+ * plain `ArrayBuffer` keeps codec signatures satisfied without casts).
181
+ */
182
+ const readWasm = (request) => {
183
+ const bytes = readFileSync(require.resolve(request));
184
+ const out = new Uint8Array(new ArrayBuffer(bytes.byteLength));
185
+ out.set(bytes);
186
+ return out;
187
+ };
188
+ /**
189
+ * Compiled module for the emscripten-generation codecs (jpeg/webp/avif),
190
+ * whose `init` accepts a `WebAssembly.Module` positionally (typing gap in
191
+ * their d.ts); the wasm-bindgen generation (png v3, resize, resvg) takes raw
192
+ * bytes instead.
193
+ */
194
+ const readModule = (request) => new WebAssembly.Module(readWasm(request));
195
+ let pngReady;
196
+ let resizeReady;
197
+ let resvgReady;
198
+ /** PNG decode/encode (shared wasm instance between decode and encode). */
199
+ const loadPng = () => {
200
+ pngReady ??= (async () => {
201
+ const { init } = await import("./decode-FysWS28R.mjs");
202
+ await init(readWasm("@jsquash/png/codec/pkg/squoosh_png_bg.wasm"));
203
+ })();
204
+ return pngReady;
205
+ };
206
+ /** Lanczos/other resize kernels. */
207
+ const loadResize = () => {
208
+ resizeReady ??= (async () => {
209
+ const { initResize } = await import("./resize-B47sgoOb.mjs");
210
+ await initResize(readWasm("@jsquash/resize/lib/resize/pkg/squoosh_resize_bg.wasm"));
211
+ })();
212
+ return resizeReady;
213
+ };
214
+ /** SVG rasterizer. */
215
+ const loadResvg = () => {
216
+ resvgReady ??= (async () => {
217
+ const { initWasm } = await import("./resvg-wasm-fcJTLpJs.mjs");
218
+ await initWasm(readWasm("@resvg/resvg-wasm/index_bg.wasm"));
219
+ })();
220
+ return resvgReady;
221
+ };
222
+ /** Decode a PNG to RGBA pixels. */
223
+ const decodePng = async (bytes) => {
224
+ await loadPng();
225
+ const { decode } = await import("./png-rD0XEazj.mjs");
226
+ const buffer = new ArrayBuffer(bytes.byteLength);
227
+ new Uint8Array(buffer).set(bytes);
228
+ const decoded = await decode(buffer);
229
+ if (decoded === null) throw new Error("PNG decode failed");
230
+ return decoded;
231
+ };
232
+ /** Encode RGBA pixels to PNG bytes (no density metadata; see encode.ts pHYs). */
233
+ const encodePng = async (image) => {
234
+ await loadPng();
235
+ const { encode } = await import("./png-rD0XEazj.mjs");
236
+ return new Uint8Array(await encode(image));
237
+ };
238
+ //#endregion
239
+ //#region ../icon/src/raster.ts
240
+ /**
241
+ * Raster foundation for the icon kernel (spike-verified): format-dispatched
242
+ * WASM decoding, aspect-preserving resize with manual letterboxing, EXIF
243
+ * orientation, SVG rasterization through the font ladder, and the raw pixel
244
+ * operations (paste / contain / trim / dest-in clip) that the composition and
245
+ * generation paths are built on.
246
+ */
247
+ const imageOf = (image) => makeImage(new Uint8ClampedArray(image.data), image.width, image.height);
248
+ const emptyImageOf = (width, height) => makeImage(new Uint8ClampedArray(width * height * 4), width, height);
249
+ const cloneImage = (image) => imageOf(image);
250
+ const sniffFormat = (bytes) => {
251
+ if (bytes.length >= 8 && bytes[0] === 137 && bytes[1] === 80) return "png";
252
+ if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216) return "jpeg";
253
+ if (bytes.length >= 12 && bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69) return "webp";
254
+ if (bytes.length >= 12 && bytes[4] === 102 && bytes[5] === 116 && bytes[6] === 121 && bytes[7] === 112) return "avif";
255
+ const head = new TextDecoder().decode(bytes.subarray(0, 1024).filter((byte) => byte !== 0)).trimStart();
256
+ if (head.startsWith("<?xml") || head.startsWith("<svg")) return "svg";
257
+ return "unknown";
258
+ };
259
+ /** JPEG EXIF orientation (1–8); non-JPEG and missing tags report 1. */
260
+ const exifOrientationOf = async (format, bytes) => {
261
+ if (format !== "jpeg") return 1;
262
+ const imported = await import("./full.umd-oM1VUBRH.mjs").then((m) => /* @__PURE__ */ __toESM(m.default, 1));
263
+ const orientation = (imported.default ?? imported).orientation;
264
+ return await orientation(bytes) ?? 1;
265
+ };
266
+ /** Apply an EXIF orientation value to raw pixels. */
267
+ const applyOrientation = (image, orientation) => {
268
+ if (orientation <= 1 || orientation > 8) return image;
269
+ const { width, height, data } = image;
270
+ const swap = orientation >= 5;
271
+ const out = emptyImageOf(swap ? height : width, swap ? width : height);
272
+ const outW = out.width;
273
+ for (let y = 0; y < height; y += 1) for (let x = 0; x < width; x += 1) {
274
+ const source = (y * width + x) * 4;
275
+ let targetX = x;
276
+ let targetY = y;
277
+ switch (orientation) {
278
+ case 2:
279
+ targetX = width - 1 - x;
280
+ break;
281
+ case 3:
282
+ targetX = width - 1 - x;
283
+ targetY = height - 1 - y;
284
+ break;
285
+ case 4:
286
+ targetY = height - 1 - y;
287
+ break;
288
+ case 5:
289
+ targetX = y;
290
+ targetY = x;
291
+ break;
292
+ case 6:
293
+ targetX = y;
294
+ targetY = width - 1 - x;
295
+ break;
296
+ case 7:
297
+ targetX = height - 1 - y;
298
+ targetY = x;
299
+ break;
300
+ case 8:
301
+ targetX = height - 1 - y;
302
+ targetY = width - 1 - x;
303
+ break;
304
+ default: break;
305
+ }
306
+ const target = (targetY * outW + targetX) * 4;
307
+ out.data[target] = data[source];
308
+ out.data[target + 1] = data[source + 1];
309
+ out.data[target + 2] = data[source + 2];
310
+ out.data[target + 3] = data[source + 3];
311
+ }
312
+ return out;
313
+ };
314
+ /**
315
+ * Decode an encoded raster image (PNG/JPEG/WebP/AVIF) or rasterize an SVG
316
+ * (through the font ladder; text never silently drops) to RGBA pixels.
317
+ * JPEG orientation is applied so phone-photo sources compose upright.
318
+ */
319
+ const decodeImage = async (bytes) => {
320
+ const format = sniffFormat(bytes);
321
+ const decoded = await (async () => {
322
+ switch (format) {
323
+ case "png": return decodePng(bytes);
324
+ case "jpeg": {
325
+ const { init } = await import("./decode-Xr7mARKr.mjs");
326
+ await init(readModule("@jsquash/jpeg/codec/dec/mozjpeg_dec.wasm"));
327
+ const { decode } = await import("./jpeg-B4tsxG5f.mjs");
328
+ return orThrow("JPEG", await decode(toExactBuffer(bytes)));
329
+ }
330
+ case "webp": {
331
+ const { init } = await import("./decode-C4b5NXc_.mjs");
332
+ await init(readModule("@jsquash/webp/codec/dec/webp_dec.wasm"));
333
+ const { decode } = await import("./webp-CcbaCrQ7.mjs");
334
+ return orThrow("WebP", await decode(toExactBuffer(bytes)));
335
+ }
336
+ case "avif": {
337
+ const { init } = await import("./decode-Dsj9J0OD.mjs");
338
+ await init(readModule("@jsquash/avif/codec/dec/avif_dec.wasm"));
339
+ const { decode } = await import("./avif-DCXcyYJR.mjs");
340
+ return orThrow("AVIF", await decode(toExactBuffer(bytes)));
341
+ }
342
+ case "svg": return rasterizeSvg(new TextDecoder().decode(bytes), 1024);
343
+ default: throw new Error("unsupported icon source format (expected PNG/JPEG/WebP/AVIF/SVG bytes)");
344
+ }
345
+ })();
346
+ return applyOrientation(decoded, await exifOrientationOf(format, bytes));
347
+ };
348
+ /** Copy into a standalone ArrayBuffer for codecs that demand exactly that. */
349
+ const toExactBuffer = (bytes) => {
350
+ const out = new ArrayBuffer(bytes.byteLength);
351
+ new Uint8Array(out).set(bytes);
352
+ return out;
353
+ };
354
+ const orThrow = (label, image) => {
355
+ if (image === null) throw new Error(`${label} decode failed`);
356
+ return image;
357
+ };
358
+ const decodeImageFile = async (path) => decodeImage(new Uint8Array(await readFile(path)));
359
+ /** Rasterize an SVG string with the kernel font ladder attached. */
360
+ const rasterizeSvg = async (svg, width) => {
361
+ await loadResvg();
362
+ const { Resvg } = await import("./resvg-wasm-fcJTLpJs.mjs");
363
+ const rendered = new Resvg(svg, {
364
+ fitTo: {
365
+ mode: "width",
366
+ value: width
367
+ },
368
+ font: {
369
+ loadSystemFonts: false,
370
+ fontBuffers: [...await glyphFontLadder()],
371
+ defaultFontFamily: GLYPH_FONT_FAMILY
372
+ },
373
+ background: "rgba(0,0,0,0)"
374
+ }).render();
375
+ return makeImage(new Uint8ClampedArray(rendered.pixels), rendered.width, rendered.height);
376
+ };
377
+ const encodeImagePng = (image) => encodePng(image);
378
+ /**
379
+ * Resize with a chosen sampling kernel. The WASM resize is an exact
380
+ * width/height remap, so callers pass aspect-true targets.
381
+ */
382
+ const resizeImage = async (image, width, height, method = "lanczos3") => {
383
+ if (image.width === width && image.height === height) return imageOf(image);
384
+ const { default: resize } = await import("./resize-B47sgoOb.mjs");
385
+ await loadResize();
386
+ if (method === "nearest") return resizeNearest(image, width, height);
387
+ return resize(image, {
388
+ width,
389
+ height,
390
+ method: "lanczos3"
391
+ });
392
+ };
393
+ /** Point sampling for pixel-art sources (sharp `kernel: nearest` port). */
394
+ const resizeNearest = (image, width, height) => {
395
+ const out = emptyImageOf(width, height);
396
+ for (let y = 0; y < height; y += 1) {
397
+ const sourceY = Math.min(image.height - 1, Math.floor(y * image.height / height));
398
+ for (let x = 0; x < width; x += 1) {
399
+ const sourceX = Math.min(image.width - 1, Math.floor(x * image.width / width));
400
+ const s = (sourceY * image.width + sourceX) * 4;
401
+ const t = (y * width + x) * 4;
402
+ out.data[t] = image.data[s];
403
+ out.data[t + 1] = image.data[s + 1];
404
+ out.data[t + 2] = image.data[s + 2];
405
+ out.data[t + 3] = image.data[s + 3];
406
+ }
407
+ }
408
+ return out;
409
+ };
410
+ /**
411
+ * Aspect-preserving scale to fit INSIDE a box without padding (sharp
412
+ * `fit: "inside"` semantics) — analysis paths must not add letterbox pixels
413
+ * that would dilute coverage statistics.
414
+ */
415
+ const insideImage = async (image, maxSize, method = "lanczos3") => {
416
+ const scale = Math.min(maxSize / image.width, maxSize / image.height);
417
+ return resizeImage(image, Math.max(1, Math.round(image.width * scale)), Math.max(1, Math.round(image.height * scale)), method);
418
+ };
419
+ /**
420
+ * `fit: contain` with TRANSPARENT letterboxing — the sharp default padding is
421
+ * opaque black, and the composition laws require transparency (create
422
+ * round-12 defect note).
423
+ */
424
+ const containImage = async (image, width, height, method = "lanczos3") => {
425
+ if (image.width === width && image.height === height) return imageOf(image);
426
+ const scale = Math.min(width / image.width, height / image.height);
427
+ const scaled = await resizeImage(image, Math.max(1, Math.round(image.width * scale)), Math.max(1, Math.round(image.height * scale)), method);
428
+ const canvas = emptyImageOf(width, height);
429
+ pasteImage(canvas, scaled, Math.round((width - scaled.width) / 2), Math.round((height - scaled.height) / 2));
430
+ return canvas;
431
+ };
432
+ /** Source-over paste of `source` onto `target` at the given offset. */
433
+ const pasteImage = (target, source, left, top) => {
434
+ for (let y = 0; y < source.height; y += 1) {
435
+ const targetY = top + y;
436
+ if (targetY < 0 || targetY >= target.height) continue;
437
+ for (let x = 0; x < source.width; x += 1) {
438
+ const targetX = left + x;
439
+ if (targetX < 0 || targetX >= target.width) continue;
440
+ const s = (y * source.width + x) * 4;
441
+ const t = (targetY * target.width + targetX) * 4;
442
+ const alpha = source.data[s + 3] / 255;
443
+ const inverse = 1 - alpha;
444
+ target.data[t] = source.data[s] * alpha + target.data[t] * inverse;
445
+ target.data[t + 1] = source.data[s + 1] * alpha + target.data[t + 1] * inverse;
446
+ target.data[t + 2] = source.data[s + 2] * alpha + target.data[t + 2] * inverse;
447
+ target.data[t + 3] = Math.round(source.data[s + 3] + target.data[t + 3] * inverse);
448
+ }
449
+ }
450
+ };
451
+ /**
452
+ * Bounding box of pixels with alpha above `threshold`. Deliberate deviation
453
+ * from sharp's `.trim()`, which keyed on the top-left pixel COLOR: opaque
454
+ * letterboxed sources (e.g. a white-matte logo JPEG) no longer crop their
455
+ * background — alpha is the honest content signal for icon foregrounds.
456
+ */
457
+ const trimBounds = (image, threshold = 0) => {
458
+ let minX = image.width;
459
+ let minY = image.height;
460
+ let maxX = -1;
461
+ let maxY = -1;
462
+ for (let y = 0; y < image.height; y += 1) for (let x = 0; x < image.width; x += 1) if (image.data[(y * image.width + x) * 4 + 3] > threshold) {
463
+ if (x < minX) minX = x;
464
+ if (x > maxX) maxX = x;
465
+ if (y < minY) minY = y;
466
+ if (y > maxY) maxY = y;
467
+ }
468
+ if (maxX < 0) return null;
469
+ return {
470
+ left: minX,
471
+ top: minY,
472
+ width: maxX - minX + 1,
473
+ height: maxY - minY + 1
474
+ };
475
+ };
476
+ const cropImage = (image, left, top, width, height) => {
477
+ const out = emptyImageOf(width, height);
478
+ pasteImage(out, image, -left, -top);
479
+ return out;
480
+ };
481
+ /** Fraction of near-white opaque pixels (0–1) — the glyph text-presence probe. */
482
+ const brightPixelRatio = (image, alphaThreshold = 200, brightness = 230) => {
483
+ let bright = 0;
484
+ for (let i = 0; i < image.data.length; i += 4) {
485
+ if (image.data[i + 3] <= alphaThreshold) continue;
486
+ if (image.data[i] >= brightness && image.data[i + 1] >= brightness && image.data[i + 2] >= brightness) bright += 1;
487
+ }
488
+ return bright / (image.width * image.height);
489
+ };
490
+ //#endregion
491
+ export { assetsDirectory as _, decodeImage as a, encodeImagePng as c, rasterizeSvg as d, resizeImage as f, glyphLadderFingerprint as g, embeddedGlyphFont as h, cropImage as i, insideImage as l, GLYPH_FONT_FAMILY as m, cloneImage as n, decodeImageFile as o, trimBounds as p, containImage as r, emptyImageOf as s, brightPixelRatio as t, pasteImage as u };
492
+
493
+ //# sourceMappingURL=raster-BQ07mKLu.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raster-BQ07mKLu.mjs","names":[],"sources":["../../icon/src/assets.ts","../../icon/src/fonts.ts","../../icon/src/types.ts","../../icon/src/wasm.ts","../../icon/src/raster.ts"],"sourcesContent":["/**\n * Bundled asset resolution. Assets live at the package root (`assets/`),\n * exactly one level above both `src/` (source checkout) and `dist/` (built\n * output), so the resolution is uniform: package.json `files` ships both\n * `dist` and `assets`.\n */\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst moduleDirectory = dirname(fileURLToPath(import.meta.url));\n\nexport const assetsDirectory = (): string =>\n join(moduleDirectory, \"..\", \"assets\");\n","/**\n * Glyph font ladder (plan D5; spike-verified): the WASM rasterizer cannot\n * autoload system fonts, and `loadSystemFonts: true` silently drops text, so\n * every render must pass explicit `fontBuffers`:\n *\n * 1. the embedded OFL subset (deterministic Latin rendering everywhere), then\n * 2. a bounded, ranked scan of well-known OS font directories (CJK and other\n * scripts beyond the embedded subset).\n *\n * Rendering quality is verified empirically downstream (text-presence pixel\n * check in default-icon.ts) — the ladder never silently accepts a blank tile.\n */\nimport { readdir, readFile } from \"node:fs/promises\";\nimport type { Dirent } from \"node:fs\";\nimport { homedir, platform } from \"node:os\";\nimport { join } from \"node:path\";\n\nimport { assetsDirectory } from \"./assets\";\n\n/** Family name referenced by generated glyph SVG text elements. */\nexport const GLYPH_FONT_FAMILY = \"OpenTray Glyph\";\n\n/**\n * Preferred font basenames, highest priority first. CJK-capable fonts lead:\n * the embedded subset already covers Latin, so discovery exists for wider\n * scripts. UI fonts follow so headless Linux still finds a fallback.\n */\nconst PREFERRED_PATTERNS: readonly RegExp[] = [\n /pingfang|stheiti|hiragino|songti|heiti|kaiti|yuanti/i,\n /sourcehan|source-han|noto.{0,12}(cjk|sc|tc|jp|kr)|wqy|droidsansfallback/i,\n /msyh|msjh|simsun|simhei|simkai|simfang|deng/i,\n /segoeui|arial|helvetica|liberationsans|dejavusans|roboto-regular|ubuntu-regular/i,\n];\n\nconst FONT_EXTENSIONS = new Set([\".ttf\", \".otf\", \".ttc\", \".otc\"]);\n/** Discovery caps: glyph generation reads fonts once per cache miss. */\nconst MAX_FONT_FILES = 10;\nconst MAX_TOTAL_BYTES = 192 * 1024 * 1024;\n\nconst systemFontDirectories = (): readonly string[] => {\n const home = homedir();\n switch (platform()) {\n case \"darwin\":\n return [\n \"/System/Library/Fonts\",\n \"/System/Library/Fonts/Supplemental\",\n \"/Library/Fonts\",\n join(home, \"Library\", \"Fonts\"),\n ];\n case \"win32\":\n return [\n join(process.env.SystemRoot ?? \"C:\\\\Windows\", \"Fonts\"),\n join(\n process.env.LOCALAPPDATA ?? join(home, \"AppData\", \"Local\"),\n \"Microsoft\",\n \"Windows\",\n \"Fonts\",\n ),\n ];\n default:\n return [\n \"/usr/share/fonts\",\n \"/usr/local/share/fonts\",\n join(home, \".local\", \"share\", \"fonts\"),\n join(home, \".fonts\"),\n ];\n }\n};\n\nconst listFontFiles = async (\n directory: string,\n depth = 2,\n): Promise<readonly string[]> => {\n const found: string[] = [];\n let entries: readonly Dirent[];\n try {\n entries = await readdir(directory, { withFileTypes: true });\n } catch {\n return found;\n }\n for (const entry of entries) {\n const entryPath = join(directory, entry.name);\n if (entry.isDirectory() && depth > 0) {\n found.push(...(await listFontFiles(entryPath, depth - 1)));\n } else if (entry.isFile() && FONT_EXTENSIONS.has(extOf(entry.name))) {\n found.push(entryPath);\n }\n }\n return found;\n};\n\nconst extOf = (name: string): string => {\n const dot = name.lastIndexOf(\".\");\n return dot === -1 ? \"\" : name.slice(dot).toLowerCase();\n};\n\nconst priorityOf = (path: string): number => {\n for (let index = 0; index < PREFERRED_PATTERNS.length; index += 1) {\n if (PREFERRED_PATTERNS[index]!.test(path)) return index;\n }\n return PREFERRED_PATTERNS.length;\n};\n\nconst cache = new Map<string, Uint8Array>();\n\n/** Embedded OFL subset bytes (Inter SemiBold, latin; see assets/*.OFL.txt). */\nexport const embeddedGlyphFont = async (): Promise<Uint8Array> => {\n const path = join(assetsDirectory(), \"inter-glyph.ttf\");\n const cached = cache.get(path);\n if (cached !== undefined) return cached;\n const bytes = new Uint8Array(await readFile(path));\n cache.set(path, bytes);\n return bytes;\n};\n\nlet ladderPromise: Promise<readonly Uint8Array[]> | undefined;\nlet ladderFingerprintPromise: Promise<string> | undefined;\n\n/**\n * Stable identity of the discovered ladder (path + byte length pairs): OS\n * font changes invalidate generated-icon caches without hashing font bytes.\n */\nexport const glyphLadderFingerprint = (): Promise<string> => {\n ladderFingerprintPromise ??= (async () => {\n const parts: string[] = [];\n for (const buffer of await glyphFontLadder()) {\n parts.push(`${buffer.byteLength}`);\n }\n return parts.join(\",\");\n })();\n return ladderFingerprintPromise;\n};\n\n/**\n * The full font ladder for resvg `fontBuffers`: embedded subset first, then a\n * bounded ranked selection from the OS. Deterministic order, memoized.\n */\nexport const glyphFontLadder = (): Promise<readonly Uint8Array[]> => {\n ladderPromise ??= (async () => {\n const embedded = await embeddedGlyphFont();\n const candidates: { path: string; priority: number }[] = [];\n for (const directory of systemFontDirectories()) {\n for (const path of await listFontFiles(directory)) {\n candidates.push({ path, priority: priorityOf(path) });\n }\n }\n candidates.sort(\n (a, b) => a.priority - b.priority || (a.path < b.path ? -1 : 1),\n );\n const buffers: Uint8Array[] = [embedded];\n let total = embedded.byteLength;\n for (const { path } of candidates) {\n if (buffers.length >= MAX_FONT_FILES || total >= MAX_TOTAL_BYTES) break;\n const cached = cache.get(path);\n if (cached !== undefined) {\n buffers.push(cached);\n total += cached.byteLength;\n continue;\n }\n try {\n const bytes = new Uint8Array(await readFile(path));\n cache.set(path, bytes);\n buffers.push(bytes);\n total += bytes.byteLength;\n } catch {\n // Unreadable font files are skipped; the ladder degrades gracefully.\n }\n }\n return buffers;\n })();\n return ladderPromise;\n};\n\n/** Test hook: forget memoized font state. */\nexport const resetGlyphFontCache = (): void => {\n cache.clear();\n ladderPromise = undefined;\n};\n","/**\n * Shared value types for the icon kernel.\n *\n * `ImageData` (the one browser type the WASM codecs exchange) resolves from\n * the DOM lib that the codec `.d.ts` files pull into the program; at RUNTIME\n * Node has no global `ImageData` constructor until a codec's glue polyfills\n * it. The kernel therefore never calls the constructor — it builds plain\n * structural objects through `makeImage`, which satisfies the same interface\n * on every runtime (Node, Bun, browsers).\n */\nexport type ImageDataLike = ImageData;\n\nexport const makeImage = (\n data: Uint8ClampedArray<ArrayBuffer>,\n width: number,\n height: number,\n): ImageDataLike => ({ data, width, height, colorSpace: \"srgb\" });\n","/**\n * Lazy WASM bootstrap for the kernel's image stack (spike-verified\n * 2026-09-09, demos/wasm-spike):\n *\n * - jsquash v3 codecs auto-`init()` through `fetch(new URL(...))` which Node\n * rejects for file URLs. The only reliable Node path is pre-initializing\n * with the wasm bytes read from disk, via each codec's subpath export.\n * - `@resvg/resvg-wasm` cannot load system fonts in a WASM environment; text\n * must arrive as explicit `fontBuffers` (see fonts.ts). `loadSystemFonts`\n * stays false everywhere — with it true, resvg silently drops text.\n *\n * Every loader is a memoized singleton so repeated generation calls pay the\n * wasm handshake once per process. Initialization failure throws a typed\n * error; callers (runtime daemon, build tools) decide their own fallback.\n */\nimport { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\n\nimport type { ImageDataLike } from \"./types\";\n\nconst require = createRequire(import.meta.url);\n\n/**\n * Exact-typed wasm bytes (TS 5.7 typed-array variance: a fresh copy over a\n * plain `ArrayBuffer` keeps codec signatures satisfied without casts).\n */\nconst readWasm = (request: string): Uint8Array<ArrayBuffer> => {\n const bytes = readFileSync(require.resolve(request));\n const out = new Uint8Array(new ArrayBuffer(bytes.byteLength));\n out.set(bytes);\n return out;\n};\n\n/**\n * Compiled module for the emscripten-generation codecs (jpeg/webp/avif),\n * whose `init` accepts a `WebAssembly.Module` positionally (typing gap in\n * their d.ts); the wasm-bindgen generation (png v3, resize, resvg) takes raw\n * bytes instead.\n */\nconst readModule = (request: string): WebAssembly.Module =>\n new WebAssembly.Module(readWasm(request));\n\nexport { readWasm, readModule };\n\nlet pngReady: Promise<void> | undefined;\nlet resizeReady: Promise<void> | undefined;\nlet resvgReady: Promise<void> | undefined;\n\n/** PNG decode/encode (shared wasm instance between decode and encode). */\nexport const loadPng = (): Promise<void> => {\n pngReady ??= (async () => {\n const { init } = await import(\"@jsquash/png/decode.js\");\n await init(readWasm(\"@jsquash/png/codec/pkg/squoosh_png_bg.wasm\"));\n })();\n return pngReady;\n};\n\n/** Lanczos/other resize kernels. */\nexport const loadResize = (): Promise<void> => {\n resizeReady ??= (async () => {\n const { initResize } = await import(\"@jsquash/resize\");\n await initResize(\n readWasm(\"@jsquash/resize/lib/resize/pkg/squoosh_resize_bg.wasm\"),\n );\n })();\n return resizeReady;\n};\n\n/** SVG rasterizer. */\nexport const loadResvg = (): Promise<void> => {\n resvgReady ??= (async () => {\n const { initWasm } = await import(\"@resvg/resvg-wasm\");\n await initWasm(readWasm(\"@resvg/resvg-wasm/index_bg.wasm\"));\n })();\n return resvgReady;\n};\n\n/** Decode a PNG to RGBA pixels. */\nexport const decodePng = async (bytes: Uint8Array): Promise<ImageDataLike> => {\n await loadPng();\n const { decode } = await import(\"@jsquash/png\");\n const buffer = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(buffer).set(bytes);\n const decoded = await decode(buffer);\n if (decoded === null) throw new Error(\"PNG decode failed\");\n return decoded;\n};\n\n/** Encode RGBA pixels to PNG bytes (no density metadata; see encode.ts pHYs). */\nexport const encodePng = async (image: ImageDataLike): Promise<Uint8Array> => {\n await loadPng();\n const { encode } = await import(\"@jsquash/png\");\n return new Uint8Array(await encode(image));\n};\n\nexport class IconKernelInitError extends Error {\n constructor(\n readonly stage: string,\n readonly cause: unknown,\n ) {\n super(`icon kernel wasm initialization failed at ${stage}: ${String(cause)}`);\n this.name = \"IconKernelInitError\";\n }\n}\n","/**\n * Raster foundation for the icon kernel (spike-verified): format-dispatched\n * WASM decoding, aspect-preserving resize with manual letterboxing, EXIF\n * orientation, SVG rasterization through the font ladder, and the raw pixel\n * operations (paste / contain / trim / dest-in clip) that the composition and\n * generation paths are built on.\n */\nimport { readFile } from \"node:fs/promises\";\n\nimport { GLYPH_FONT_FAMILY, glyphFontLadder } from \"./fonts\";\nimport { makeImage, type ImageDataLike } from \"./types\";\nimport { decodePng, encodePng, loadResize, loadResvg, readModule } from \"./wasm\";\n\nexport type { ImageDataLike };\n\nconst imageOf = (image: ImageDataLike): ImageDataLike =>\n makeImage(new Uint8ClampedArray(image.data), image.width, image.height);\n\nexport const emptyImageOf = (width: number, height: number): ImageDataLike =>\n makeImage(new Uint8ClampedArray(width * height * 4), width, height);\n\nexport const cloneImage = (image: ImageDataLike): ImageDataLike => imageOf(image);\n\n/* ---------------------------------- decode --------------------------------- */\n\nconst sniffFormat = (bytes: Uint8Array): \"png\" | \"jpeg\" | \"webp\" | \"avif\" | \"svg\" | \"unknown\" => {\n if (bytes.length >= 8 && bytes[0] === 0x89 && bytes[1] === 0x50) return \"png\";\n if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8) return \"jpeg\";\n if (\n bytes.length >= 12 &&\n bytes[0] === 0x52 &&\n bytes[1] === 0x49 &&\n bytes[2] === 0x46 &&\n bytes[3] === 0x46 &&\n bytes[8] === 0x57 &&\n bytes[9] === 0x45\n ) {\n return \"webp\";\n }\n if (bytes.length >= 12 && bytes[4] === 0x66 && bytes[5] === 0x74 && bytes[6] === 0x79 && bytes[7] === 0x70) {\n return \"avif\";\n }\n const head = new TextDecoder()\n .decode(bytes.subarray(0, 1024).filter((byte) => byte !== 0))\n .trimStart();\n if (head.startsWith(\"<?xml\") || head.startsWith(\"<svg\")) return \"svg\";\n return \"unknown\";\n};\n\n/** JPEG EXIF orientation (1–8); non-JPEG and missing tags report 1. */\nconst exifOrientationOf = async (\n format: string,\n bytes: Uint8Array,\n): Promise<number> => {\n if (format !== \"jpeg\") return 1;\n // exifr ships CJS; under Node ESM the callable lives on `default`, while\n // bundler-run tests also accept the named form — resolve both.\n const imported = await import(\"exifr\");\n const orientation = (imported.default ?? imported).orientation;\n return (await orientation(bytes)) ?? 1;\n};\n\n/** Apply an EXIF orientation value to raw pixels. */\nconst applyOrientation = (\n image: ImageDataLike,\n orientation: number,\n): ImageDataLike => {\n if (orientation <= 1 || orientation > 8) return image;\n const { width, height, data } = image;\n const swap = orientation >= 5;\n const out = emptyImageOf(swap ? height : width, swap ? width : height);\n const outW = out.width;\n for (let y = 0; y < height; y += 1) {\n for (let x = 0; x < width; x += 1) {\n const source = (y * width + x) * 4;\n let targetX = x;\n let targetY = y;\n switch (orientation) {\n case 2: targetX = width - 1 - x; break;\n case 3: targetX = width - 1 - x; targetY = height - 1 - y; break;\n case 4: targetY = height - 1 - y; break;\n case 5: targetX = y; targetY = x; break;\n case 6: targetX = y; targetY = width - 1 - x; break;\n case 7: targetX = height - 1 - y; targetY = x; break;\n case 8: targetX = height - 1 - y; targetY = width - 1 - x; break;\n default: break;\n }\n const target = (targetY * outW + targetX) * 4;\n out.data[target] = data[source]!;\n out.data[target + 1] = data[source + 1]!;\n out.data[target + 2] = data[source + 2]!;\n out.data[target + 3] = data[source + 3]!;\n }\n }\n return out;\n};\n\n/**\n * Decode an encoded raster image (PNG/JPEG/WebP/AVIF) or rasterize an SVG\n * (through the font ladder; text never silently drops) to RGBA pixels.\n * JPEG orientation is applied so phone-photo sources compose upright.\n */\nexport const decodeImage = async (bytes: Uint8Array): Promise<ImageDataLike> => {\n const format = sniffFormat(bytes);\n const decoded = await (async (): Promise<ImageDataLike> => {\n switch (format) {\n case \"png\":\n return decodePng(bytes);\n case \"jpeg\": {\n // The emscripten-generation `init` accepts a compiled module as its\n // first positional parameter (runtime-verified); its published d.ts\n // only types the overrides object, hence the targeted cast.\n const { init } = await import(\"@jsquash/jpeg/decode.js\");\n await init(\n readModule(\"@jsquash/jpeg/codec/dec/mozjpeg_dec.wasm\") as never,\n );\n const { decode } = await import(\"@jsquash/jpeg\");\n return orThrow(\"JPEG\", await decode(toExactBuffer(bytes)));\n }\n case \"webp\": {\n const { init } = await import(\"@jsquash/webp/decode.js\");\n await init(\n readModule(\"@jsquash/webp/codec/dec/webp_dec.wasm\") as never,\n );\n const { decode } = await import(\"@jsquash/webp\");\n return orThrow(\"WebP\", await decode(toExactBuffer(bytes)));\n }\n case \"avif\": {\n const { init } = await import(\"@jsquash/avif/decode.js\");\n await init(\n readModule(\"@jsquash/avif/codec/dec/avif_dec.wasm\") as never,\n );\n const { decode } = await import(\"@jsquash/avif\");\n return orThrow(\"AVIF\", await decode(toExactBuffer(bytes)));\n }\n case \"svg\":\n return rasterizeSvg(new TextDecoder().decode(bytes), 1024);\n default:\n throw new Error(\n \"unsupported icon source format (expected PNG/JPEG/WebP/AVIF/SVG bytes)\",\n );\n }\n })();\n return applyOrientation(decoded, await exifOrientationOf(format, bytes));\n};\n\n/** Copy into a standalone ArrayBuffer for codecs that demand exactly that. */\nconst toExactBuffer = (bytes: Uint8Array): ArrayBuffer => {\n const out = new ArrayBuffer(bytes.byteLength);\n new Uint8Array(out).set(bytes);\n return out;\n};\n\nconst orThrow = (label: string, image: ImageDataLike | null): ImageDataLike => {\n if (image === null) throw new Error(`${label} decode failed`);\n return image;\n};\n\nexport const decodeImageFile = async (path: string): Promise<ImageDataLike> =>\n decodeImage(new Uint8Array(await readFile(path)));\n\n/** Rasterize an SVG string with the kernel font ladder attached. */\nexport const rasterizeSvg = async (\n svg: string,\n width: number,\n): Promise<ImageDataLike> => {\n await loadResvg();\n const { Resvg } = await import(\"@resvg/resvg-wasm\");\n const resvg = new Resvg(svg, {\n fitTo: { mode: \"width\", value: width },\n font: {\n loadSystemFonts: false,\n fontBuffers: [...(await glyphFontLadder())],\n defaultFontFamily: GLYPH_FONT_FAMILY,\n },\n background: \"rgba(0,0,0,0)\",\n });\n const rendered = resvg.render();\n return makeImage(\n new Uint8ClampedArray(rendered.pixels),\n rendered.width,\n rendered.height,\n );\n};\n\nexport const encodeImagePng = (image: ImageDataLike): Promise<Uint8Array> =>\n encodePng(image);\n\n/* ---------------------------------- resize --------------------------------- */\n\nexport type ResizeMethod = \"lanczos3\" | \"nearest\";\n\n/**\n * Resize with a chosen sampling kernel. The WASM resize is an exact\n * width/height remap, so callers pass aspect-true targets.\n */\nexport const resizeImage = async (\n image: ImageDataLike,\n width: number,\n height: number,\n method: ResizeMethod = \"lanczos3\",\n): Promise<ImageDataLike> => {\n if (image.width === width && image.height === height) return imageOf(image);\n const { default: resize } = await import(\"@jsquash/resize\");\n await loadResize();\n if (method === \"nearest\") {\n return resizeNearest(image, width, height);\n }\n return resize(image, { width, height, method: \"lanczos3\" });\n};\n\n/** Point sampling for pixel-art sources (sharp `kernel: nearest` port). */\nconst resizeNearest = (\n image: ImageDataLike,\n width: number,\n height: number,\n): ImageDataLike => {\n const out = emptyImageOf(width, height);\n for (let y = 0; y < height; y += 1) {\n const sourceY = Math.min(image.height - 1, Math.floor((y * image.height) / height));\n for (let x = 0; x < width; x += 1) {\n const sourceX = Math.min(image.width - 1, Math.floor((x * image.width) / width));\n const s = (sourceY * image.width + sourceX) * 4;\n const t = (y * width + x) * 4;\n out.data[t] = image.data[s]!;\n out.data[t + 1] = image.data[s + 1]!;\n out.data[t + 2] = image.data[s + 2]!;\n out.data[t + 3] = image.data[s + 3]!;\n }\n }\n return out;\n};\n\n/**\n * Aspect-preserving scale to fit INSIDE a box without padding (sharp\n * `fit: \"inside\"` semantics) — analysis paths must not add letterbox pixels\n * that would dilute coverage statistics.\n */\nexport const insideImage = async (\n image: ImageDataLike,\n maxSize: number,\n method: ResizeMethod = \"lanczos3\",\n): Promise<ImageDataLike> => {\n const scale = Math.min(maxSize / image.width, maxSize / image.height);\n return resizeImage(\n image,\n Math.max(1, Math.round(image.width * scale)),\n Math.max(1, Math.round(image.height * scale)),\n method,\n );\n};\n\n/**\n * `fit: contain` with TRANSPARENT letterboxing — the sharp default padding is\n * opaque black, and the composition laws require transparency (create\n * round-12 defect note).\n */\nexport const containImage = async (\n image: ImageDataLike,\n width: number,\n height: number,\n method: ResizeMethod = \"lanczos3\",\n): Promise<ImageDataLike> => {\n if (image.width === width && image.height === height) return imageOf(image);\n const scale = Math.min(width / image.width, height / image.height);\n const scaled = await resizeImage(\n image,\n Math.max(1, Math.round(image.width * scale)),\n Math.max(1, Math.round(image.height * scale)),\n method,\n );\n const canvas = emptyImageOf(width, height);\n pasteImage(\n canvas,\n scaled,\n Math.round((width - scaled.width) / 2),\n Math.round((height - scaled.height) / 2),\n );\n return canvas;\n};\n\n/* ------------------------------ pixel operations ---------------------------- */\n\n/** Source-over paste of `source` onto `target` at the given offset. */\nexport const pasteImage = (\n target: ImageDataLike,\n source: ImageDataLike,\n left: number,\n top: number,\n): void => {\n for (let y = 0; y < source.height; y += 1) {\n const targetY = top + y;\n if (targetY < 0 || targetY >= target.height) continue;\n for (let x = 0; x < source.width; x += 1) {\n const targetX = left + x;\n if (targetX < 0 || targetX >= target.width) continue;\n const s = (y * source.width + x) * 4;\n const t = (targetY * target.width + targetX) * 4;\n const alpha = source.data[s + 3]! / 255;\n const inverse = 1 - alpha;\n target.data[t] =\n source.data[s]! * alpha + target.data[t]! * inverse;\n target.data[t + 1] =\n source.data[s + 1]! * alpha + target.data[t + 1]! * inverse;\n target.data[t + 2] =\n source.data[s + 2]! * alpha + target.data[t + 2]! * inverse;\n target.data[t + 3] = Math.round(\n source.data[s + 3]! + target.data[t + 3]! * inverse,\n );\n }\n }\n};\n\n/**\n * Bounding box of pixels with alpha above `threshold`. Deliberate deviation\n * from sharp's `.trim()`, which keyed on the top-left pixel COLOR: opaque\n * letterboxed sources (e.g. a white-matte logo JPEG) no longer crop their\n * background — alpha is the honest content signal for icon foregrounds.\n */\nexport const trimBounds = (\n image: ImageDataLike,\n threshold = 0,\n): { left: number; top: number; width: number; height: number } | null => {\n let minX = image.width;\n let minY = image.height;\n let maxX = -1;\n let maxY = -1;\n for (let y = 0; y < image.height; y += 1) {\n for (let x = 0; x < image.width; x += 1) {\n if (image.data[(y * image.width + x) * 4 + 3]! > threshold) {\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n }\n }\n }\n if (maxX < 0) return null;\n return {\n left: minX,\n top: minY,\n width: maxX - minX + 1,\n height: maxY - minY + 1,\n };\n};\n\nexport const cropImage = (\n image: ImageDataLike,\n left: number,\n top: number,\n width: number,\n height: number,\n): ImageDataLike => {\n const out = emptyImageOf(width, height);\n pasteImage(out, image, -left, -top);\n return out;\n};\n\n/** Fraction of pixels whose alpha exceeds `alphaThreshold` (0–1). */\nexport const opaqueCoverage = (\n image: ImageDataLike,\n alphaThreshold = 200,\n): number => {\n let opaque = 0;\n for (let i = 3; i < image.data.length; i += 4) {\n if (image.data[i]! > alphaThreshold) opaque += 1;\n }\n return opaque / (image.width * image.height);\n};\n\n/** Fraction of near-white opaque pixels (0–1) — the glyph text-presence probe. */\nexport const brightPixelRatio = (\n image: ImageDataLike,\n alphaThreshold = 200,\n brightness = 230,\n): number => {\n let bright = 0;\n for (let i = 0; i < image.data.length; i += 4) {\n if (image.data[i + 3]! <= alphaThreshold) continue;\n if (\n image.data[i]! >= brightness &&\n image.data[i + 1]! >= brightness &&\n image.data[i + 2]! >= brightness\n ) {\n bright += 1;\n }\n }\n return bright / (image.width * image.height);\n};\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAM,kBAAkB,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;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