create-opentray 0.21.1 → 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.
- package/README.md +28 -6
- package/dist/avif-DCXcyYJR.mjs +2 -0
- package/dist/{bin-va204Tk0.mjs → bin-Dyfucd3C.mjs} +4598 -750
- package/dist/bin-Dyfucd3C.mjs.map +1 -0
- package/dist/bin.mjs +1 -1
- package/dist/decode-C4b5NXc_.mjs +1236 -0
- package/dist/decode-C4b5NXc_.mjs.map +1 -0
- package/dist/decode-Dsj9J0OD.mjs +1214 -0
- package/dist/decode-Dsj9J0OD.mjs.map +1 -0
- package/dist/decode-FysWS28R.mjs +254 -0
- package/dist/decode-FysWS28R.mjs.map +1 -0
- package/dist/decode-Xr7mARKr.mjs +1262 -0
- package/dist/decode-Xr7mARKr.mjs.map +1 -0
- package/dist/{decode-ico-NdYuFN-i.mjs → decode-ico-D3SL2BXi.mjs} +2 -2
- package/dist/{decode-ico-NdYuFN-i.mjs.map → decode-ico-D3SL2BXi.mjs.map} +1 -1
- package/dist/full.umd-oM1VUBRH.mjs +3055 -0
- package/dist/full.umd-oM1VUBRH.mjs.map +1 -0
- package/dist/index.d.mts +123 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/jpeg-B4tsxG5f.mjs +2 -0
- package/dist/png-rD0XEazj.mjs +35 -0
- package/dist/png-rD0XEazj.mjs.map +1 -0
- package/dist/raster-BQ07mKLu.mjs +493 -0
- package/dist/raster-BQ07mKLu.mjs.map +1 -0
- package/dist/resize-B47sgoOb.mjs +489 -0
- package/dist/resize-B47sgoOb.mjs.map +1 -0
- package/dist/resvg-wasm-fcJTLpJs.mjs +522 -0
- package/dist/resvg-wasm-fcJTLpJs.mjs.map +1 -0
- package/dist/rolldown-runtime-JspESFgx.mjs +35 -0
- package/dist/shell/assets/browse.js +1 -1
- package/dist/shell/assets/index.css +1 -1
- package/dist/shell/assets/main.js +17 -17
- package/dist/skill/SKILL.md +46 -17
- package/dist/skill/references/cli-reference.md +8 -3
- package/dist/skill/references/how-it-works.md +30 -0
- package/dist/webp-CcbaCrQ7.mjs +2 -0
- package/dist/webui/assets/browse.js +1 -1
- package/dist/webui/assets/index.css +1 -1
- package/dist/webui/assets/main.js +17 -17
- package/package.json +6 -7
- package/skill/SKILL.md +46 -17
- package/skill/references/cli-reference.md +8 -3
- package/skill/references/how-it-works.md +30 -0
- package/dist/bin-va204Tk0.mjs.map +0 -1
|
@@ -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;AAE9D,MAAa,wBACX,KAAK,iBAAiB,MAAM,QAAQ;;;;;;;;;;;;;;;;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ACT;;AAeA,MAAa,oBACX,OACA,iBAAiB,KACjB,aAAa,QACF;CACX,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK,QAAQ,KAAK,GAAG;EAC7C,IAAI,MAAM,KAAK,IAAI,MAAO,gBAAgB;EAC1C,IACE,MAAM,KAAK,MAAO,cAClB,MAAM,KAAK,IAAI,MAAO,cACtB,MAAM,KAAK,IAAI,MAAO,YAEtB,UAAU;CAEd;CACA,OAAO,UAAU,MAAM,QAAQ,MAAM;AACvC"}
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/util.js
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2020 Google Inc. All Rights Reserved.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
* See the License for the specific language governing permissions and
|
|
12
|
+
* limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
function getContainOffsets(sw, sh, dw, dh) {
|
|
15
|
+
const currentAspect = sw / sh;
|
|
16
|
+
const endAspect = dw / dh;
|
|
17
|
+
if (endAspect > currentAspect) {
|
|
18
|
+
const newSh = sw / endAspect;
|
|
19
|
+
return {
|
|
20
|
+
sw,
|
|
21
|
+
sh: newSh,
|
|
22
|
+
sx: 0,
|
|
23
|
+
sy: (sh - newSh) / 2
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const newSw = sh * endAspect;
|
|
27
|
+
return {
|
|
28
|
+
sh,
|
|
29
|
+
sw: newSw,
|
|
30
|
+
sx: (sw - newSw) / 2,
|
|
31
|
+
sy: 0
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/lib/resize/pkg/squoosh_resize.js
|
|
36
|
+
let wasm$2;
|
|
37
|
+
let cachedUint8Memory0 = null;
|
|
38
|
+
function getUint8Memory0() {
|
|
39
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) cachedUint8Memory0 = new Uint8Array(wasm$2.memory.buffer);
|
|
40
|
+
return cachedUint8Memory0;
|
|
41
|
+
}
|
|
42
|
+
let WASM_VECTOR_LEN$2 = 0;
|
|
43
|
+
function passArray8ToWasm0$1(arg, malloc) {
|
|
44
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
45
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
46
|
+
WASM_VECTOR_LEN$2 = arg.length;
|
|
47
|
+
return ptr;
|
|
48
|
+
}
|
|
49
|
+
let cachedInt32Memory0$1 = null;
|
|
50
|
+
function getInt32Memory0$1() {
|
|
51
|
+
if (cachedInt32Memory0$1 === null || cachedInt32Memory0$1.byteLength === 0) cachedInt32Memory0$1 = new Int32Array(wasm$2.memory.buffer);
|
|
52
|
+
return cachedInt32Memory0$1;
|
|
53
|
+
}
|
|
54
|
+
let cachedUint8ClampedMemory0 = null;
|
|
55
|
+
function getUint8ClampedMemory0() {
|
|
56
|
+
if (cachedUint8ClampedMemory0 === null || cachedUint8ClampedMemory0.byteLength === 0) cachedUint8ClampedMemory0 = new Uint8ClampedArray(wasm$2.memory.buffer);
|
|
57
|
+
return cachedUint8ClampedMemory0;
|
|
58
|
+
}
|
|
59
|
+
function getClampedArrayU8FromWasm0$1(ptr, len) {
|
|
60
|
+
ptr = ptr >>> 0;
|
|
61
|
+
return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param {Uint8Array} input_image
|
|
65
|
+
* @param {number} input_width
|
|
66
|
+
* @param {number} input_height
|
|
67
|
+
* @param {number} output_width
|
|
68
|
+
* @param {number} output_height
|
|
69
|
+
* @param {number} typ_idx
|
|
70
|
+
* @param {boolean} premultiply
|
|
71
|
+
* @param {boolean} color_space_conversion
|
|
72
|
+
* @returns {Uint8ClampedArray}
|
|
73
|
+
*/
|
|
74
|
+
function resize$3(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
|
|
75
|
+
try {
|
|
76
|
+
const retptr = wasm$2.__wbindgen_add_to_stack_pointer(-16);
|
|
77
|
+
const ptr0 = passArray8ToWasm0$1(input_image, wasm$2.__wbindgen_malloc);
|
|
78
|
+
const len0 = WASM_VECTOR_LEN$2;
|
|
79
|
+
wasm$2.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
|
|
80
|
+
var r0 = getInt32Memory0$1()[retptr / 4 + 0];
|
|
81
|
+
var r1 = getInt32Memory0$1()[retptr / 4 + 1];
|
|
82
|
+
var v2 = getClampedArrayU8FromWasm0$1(r0, r1).slice();
|
|
83
|
+
wasm$2.__wbindgen_free(r0, r1 * 1, 1);
|
|
84
|
+
return v2;
|
|
85
|
+
} finally {
|
|
86
|
+
wasm$2.__wbindgen_add_to_stack_pointer(16);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function __wbg_load$2(module, imports) {
|
|
90
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
91
|
+
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
92
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
if (module.headers.get("Content-Type") != "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
95
|
+
else throw e;
|
|
96
|
+
}
|
|
97
|
+
const bytes = await module.arrayBuffer();
|
|
98
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
99
|
+
} else {
|
|
100
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
101
|
+
if (instance instanceof WebAssembly.Instance) return {
|
|
102
|
+
instance,
|
|
103
|
+
module
|
|
104
|
+
};
|
|
105
|
+
else return instance;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function __wbg_get_imports$2() {
|
|
109
|
+
const imports = {};
|
|
110
|
+
imports.wbg = {};
|
|
111
|
+
return imports;
|
|
112
|
+
}
|
|
113
|
+
function __wbg_finalize_init$2(instance, module) {
|
|
114
|
+
wasm$2 = instance.exports;
|
|
115
|
+
__wbg_init$2.__wbindgen_wasm_module = module;
|
|
116
|
+
cachedInt32Memory0$1 = null;
|
|
117
|
+
cachedUint8Memory0 = null;
|
|
118
|
+
cachedUint8ClampedMemory0 = null;
|
|
119
|
+
return wasm$2;
|
|
120
|
+
}
|
|
121
|
+
async function __wbg_init$2(input) {
|
|
122
|
+
if (wasm$2 !== void 0) return wasm$2;
|
|
123
|
+
if (typeof input === "undefined") input = new URL("squoosh_resize_bg.wasm", import.meta.url);
|
|
124
|
+
const imports = __wbg_get_imports$2();
|
|
125
|
+
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) input = fetch(input);
|
|
126
|
+
const { instance, module } = await __wbg_load$2(await input, imports);
|
|
127
|
+
return __wbg_finalize_init$2(instance, module);
|
|
128
|
+
}
|
|
129
|
+
const isRunningInCloudFlareWorkers$2 = globalThis.ServiceWorkerGlobalScope !== void 0 && typeof self !== "undefined" && globalThis.caches && globalThis.caches.default !== void 0;
|
|
130
|
+
const isRunningInNode$2 = typeof process === "object" && process.release && process.release.name === "node";
|
|
131
|
+
if (isRunningInCloudFlareWorkers$2 || isRunningInNode$2) {
|
|
132
|
+
if (!globalThis.ImageData) globalThis.ImageData = class ImageData {
|
|
133
|
+
constructor(data, width, height) {
|
|
134
|
+
this.data = data;
|
|
135
|
+
this.width = width;
|
|
136
|
+
this.height = height;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
if (import.meta.url === void 0) import.meta.url = "https://localhost";
|
|
140
|
+
if (typeof self !== "undefined" && self.location === void 0) self.location = { href: "" };
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/lib/hqx/pkg/squooshhqx.js
|
|
144
|
+
let wasm$1;
|
|
145
|
+
let cachedUint32Memory0 = null;
|
|
146
|
+
function getUint32Memory0() {
|
|
147
|
+
if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) cachedUint32Memory0 = new Uint32Array(wasm$1.memory.buffer);
|
|
148
|
+
return cachedUint32Memory0;
|
|
149
|
+
}
|
|
150
|
+
let WASM_VECTOR_LEN$1 = 0;
|
|
151
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
152
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
153
|
+
getUint32Memory0().set(arg, ptr / 4);
|
|
154
|
+
WASM_VECTOR_LEN$1 = arg.length;
|
|
155
|
+
return ptr;
|
|
156
|
+
}
|
|
157
|
+
let cachedInt32Memory0 = null;
|
|
158
|
+
function getInt32Memory0() {
|
|
159
|
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) cachedInt32Memory0 = new Int32Array(wasm$1.memory.buffer);
|
|
160
|
+
return cachedInt32Memory0;
|
|
161
|
+
}
|
|
162
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
163
|
+
ptr = ptr >>> 0;
|
|
164
|
+
return getUint32Memory0().subarray(ptr / 4, ptr / 4 + len);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @param {Uint32Array} input_image
|
|
168
|
+
* @param {number} input_width
|
|
169
|
+
* @param {number} input_height
|
|
170
|
+
* @param {number} factor
|
|
171
|
+
* @returns {Uint32Array}
|
|
172
|
+
*/
|
|
173
|
+
function resize$2(input_image, input_width, input_height, factor) {
|
|
174
|
+
try {
|
|
175
|
+
const retptr = wasm$1.__wbindgen_add_to_stack_pointer(-16);
|
|
176
|
+
const ptr0 = passArray32ToWasm0(input_image, wasm$1.__wbindgen_malloc);
|
|
177
|
+
const len0 = WASM_VECTOR_LEN$1;
|
|
178
|
+
wasm$1.resize(retptr, ptr0, len0, input_width, input_height, factor);
|
|
179
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
180
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
181
|
+
var v2 = getArrayU32FromWasm0(r0, r1).slice();
|
|
182
|
+
wasm$1.__wbindgen_free(r0, r1 * 4, 4);
|
|
183
|
+
return v2;
|
|
184
|
+
} finally {
|
|
185
|
+
wasm$1.__wbindgen_add_to_stack_pointer(16);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function __wbg_load$1(module, imports) {
|
|
189
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
190
|
+
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
191
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
if (module.headers.get("Content-Type") != "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
194
|
+
else throw e;
|
|
195
|
+
}
|
|
196
|
+
const bytes = await module.arrayBuffer();
|
|
197
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
198
|
+
} else {
|
|
199
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
200
|
+
if (instance instanceof WebAssembly.Instance) return {
|
|
201
|
+
instance,
|
|
202
|
+
module
|
|
203
|
+
};
|
|
204
|
+
else return instance;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function __wbg_get_imports$1() {
|
|
208
|
+
const imports = {};
|
|
209
|
+
imports.wbg = {};
|
|
210
|
+
return imports;
|
|
211
|
+
}
|
|
212
|
+
function __wbg_finalize_init$1(instance, module) {
|
|
213
|
+
wasm$1 = instance.exports;
|
|
214
|
+
__wbg_init$1.__wbindgen_wasm_module = module;
|
|
215
|
+
cachedInt32Memory0 = null;
|
|
216
|
+
cachedUint32Memory0 = null;
|
|
217
|
+
return wasm$1;
|
|
218
|
+
}
|
|
219
|
+
async function __wbg_init$1(input) {
|
|
220
|
+
if (wasm$1 !== void 0) return wasm$1;
|
|
221
|
+
if (typeof input === "undefined") input = new URL("squooshhqx_bg.wasm", import.meta.url);
|
|
222
|
+
const imports = __wbg_get_imports$1();
|
|
223
|
+
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) input = fetch(input);
|
|
224
|
+
const { instance, module } = await __wbg_load$1(await input, imports);
|
|
225
|
+
return __wbg_finalize_init$1(instance, module);
|
|
226
|
+
}
|
|
227
|
+
const isRunningInCloudFlareWorkers$1 = globalThis.ServiceWorkerGlobalScope !== void 0 && typeof self !== "undefined" && globalThis.caches && globalThis.caches.default !== void 0;
|
|
228
|
+
const isRunningInNode$1 = typeof process === "object" && process.release && process.release.name === "node";
|
|
229
|
+
if (isRunningInCloudFlareWorkers$1 || isRunningInNode$1) {
|
|
230
|
+
if (!globalThis.ImageData) globalThis.ImageData = class ImageData {
|
|
231
|
+
constructor(data, width, height) {
|
|
232
|
+
this.data = data;
|
|
233
|
+
this.width = width;
|
|
234
|
+
this.height = height;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
if (import.meta.url === void 0) import.meta.url = "https://localhost";
|
|
238
|
+
if (typeof self !== "undefined" && self.location === void 0) self.location = { href: "" };
|
|
239
|
+
}
|
|
240
|
+
//#endregion
|
|
241
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/lib/magic-kernel/pkg/jsquash_magic_kernel.js
|
|
242
|
+
let wasm;
|
|
243
|
+
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
244
|
+
ptr = ptr >>> 0;
|
|
245
|
+
return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
246
|
+
}
|
|
247
|
+
let cachedUint8ArrayMemory0 = null;
|
|
248
|
+
function getUint8ArrayMemory0() {
|
|
249
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
250
|
+
return cachedUint8ArrayMemory0;
|
|
251
|
+
}
|
|
252
|
+
let cachedUint8ClampedArrayMemory0 = null;
|
|
253
|
+
function getUint8ClampedArrayMemory0() {
|
|
254
|
+
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
255
|
+
return cachedUint8ClampedArrayMemory0;
|
|
256
|
+
}
|
|
257
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
258
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
259
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
260
|
+
WASM_VECTOR_LEN = arg.length;
|
|
261
|
+
return ptr;
|
|
262
|
+
}
|
|
263
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
264
|
+
if (realloc === void 0) {
|
|
265
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
266
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
267
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
268
|
+
WASM_VECTOR_LEN = buf.length;
|
|
269
|
+
return ptr;
|
|
270
|
+
}
|
|
271
|
+
let len = arg.length;
|
|
272
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
273
|
+
const mem = getUint8ArrayMemory0();
|
|
274
|
+
let offset = 0;
|
|
275
|
+
for (; offset < len; offset++) {
|
|
276
|
+
const code = arg.charCodeAt(offset);
|
|
277
|
+
if (code > 127) break;
|
|
278
|
+
mem[ptr + offset] = code;
|
|
279
|
+
}
|
|
280
|
+
if (offset !== len) {
|
|
281
|
+
if (offset !== 0) arg = arg.slice(offset);
|
|
282
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
283
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
284
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
285
|
+
offset += ret.written;
|
|
286
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
287
|
+
}
|
|
288
|
+
WASM_VECTOR_LEN = offset;
|
|
289
|
+
return ptr;
|
|
290
|
+
}
|
|
291
|
+
const cachedTextEncoder = new TextEncoder();
|
|
292
|
+
if (!("encodeInto" in cachedTextEncoder)) cachedTextEncoder.encodeInto = function(arg, view) {
|
|
293
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
294
|
+
view.set(buf);
|
|
295
|
+
return {
|
|
296
|
+
read: arg.length,
|
|
297
|
+
written: buf.length
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
let WASM_VECTOR_LEN = 0;
|
|
301
|
+
/**
|
|
302
|
+
* @param {Uint8Array} data
|
|
303
|
+
* @param {number} input_width
|
|
304
|
+
* @param {number} input_height
|
|
305
|
+
* @param {number} output_width
|
|
306
|
+
* @param {number} output_height
|
|
307
|
+
* @param {string} version
|
|
308
|
+
* @returns {ImageData}
|
|
309
|
+
*/
|
|
310
|
+
function resize$1(data, input_width, input_height, output_width, output_height, version) {
|
|
311
|
+
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
312
|
+
const len0 = WASM_VECTOR_LEN;
|
|
313
|
+
const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
314
|
+
const len1 = WASM_VECTOR_LEN;
|
|
315
|
+
return wasm.resize(ptr0, len0, input_width, input_height, output_width, output_height, ptr1, len1);
|
|
316
|
+
}
|
|
317
|
+
const EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set([
|
|
318
|
+
"basic",
|
|
319
|
+
"cors",
|
|
320
|
+
"default"
|
|
321
|
+
]);
|
|
322
|
+
async function __wbg_load(module, imports) {
|
|
323
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
324
|
+
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
325
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
326
|
+
} catch (e) {
|
|
327
|
+
if (module.ok && EXPECTED_RESPONSE_TYPES.has(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
328
|
+
else throw e;
|
|
329
|
+
}
|
|
330
|
+
const bytes = await module.arrayBuffer();
|
|
331
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
332
|
+
} else {
|
|
333
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
334
|
+
if (instance instanceof WebAssembly.Instance) return {
|
|
335
|
+
instance,
|
|
336
|
+
module
|
|
337
|
+
};
|
|
338
|
+
else return instance;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function __wbg_get_imports() {
|
|
342
|
+
const imports = {};
|
|
343
|
+
imports.wbg = {};
|
|
344
|
+
imports.wbg.__wbg_new_with_owned_u8_clamped_array_and_sh_e8143e95833a3ec3 = function(arg0, arg1, arg2, arg3) {
|
|
345
|
+
var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
|
|
346
|
+
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
347
|
+
return new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
|
|
348
|
+
};
|
|
349
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
350
|
+
const table = wasm.__wbindgen_externrefs;
|
|
351
|
+
const offset = table.grow(4);
|
|
352
|
+
table.set(0, void 0);
|
|
353
|
+
table.set(offset + 0, void 0);
|
|
354
|
+
table.set(offset + 1, null);
|
|
355
|
+
table.set(offset + 2, true);
|
|
356
|
+
table.set(offset + 3, false);
|
|
357
|
+
};
|
|
358
|
+
return imports;
|
|
359
|
+
}
|
|
360
|
+
function __wbg_finalize_init(instance, module) {
|
|
361
|
+
wasm = instance.exports;
|
|
362
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
363
|
+
cachedUint8ArrayMemory0 = null;
|
|
364
|
+
cachedUint8ClampedArrayMemory0 = null;
|
|
365
|
+
wasm.__wbindgen_start();
|
|
366
|
+
return wasm;
|
|
367
|
+
}
|
|
368
|
+
async function __wbg_init(module_or_path) {
|
|
369
|
+
if (wasm !== void 0) return wasm;
|
|
370
|
+
if (typeof module_or_path !== "undefined") if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
371
|
+
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
372
|
+
if (typeof module_or_path === "undefined") module_or_path = new URL("jsquash_magic_kernel_bg.wasm", import.meta.url);
|
|
373
|
+
const imports = __wbg_get_imports();
|
|
374
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
375
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
376
|
+
return __wbg_finalize_init(instance, module);
|
|
377
|
+
}
|
|
378
|
+
const isRunningInCloudFlareWorkers = globalThis.ServiceWorkerGlobalScope !== void 0 && typeof self !== "undefined" && globalThis.caches && globalThis.caches.default !== void 0;
|
|
379
|
+
const isRunningInNode = typeof process === "object" && process.release && process.release.name === "node";
|
|
380
|
+
if (isRunningInCloudFlareWorkers || isRunningInNode) {
|
|
381
|
+
if (!globalThis.ImageData) globalThis.ImageData = class ImageData {
|
|
382
|
+
constructor(data, width, height) {
|
|
383
|
+
this.data = data;
|
|
384
|
+
this.width = width;
|
|
385
|
+
this.height = height;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
if (import.meta.url === void 0) import.meta.url = "https://localhost";
|
|
389
|
+
if (typeof self !== "undefined" && self.location === void 0) self.location = { href: "" };
|
|
390
|
+
}
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/meta.js
|
|
393
|
+
const defaultOptions = {
|
|
394
|
+
width: 1,
|
|
395
|
+
height: 1,
|
|
396
|
+
method: "lanczos3",
|
|
397
|
+
fitMethod: "stretch",
|
|
398
|
+
premultiply: true,
|
|
399
|
+
linearRGB: true
|
|
400
|
+
};
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region ../../node_modules/.pnpm/@jsquash+resize@2.1.1/node_modules/@jsquash/resize/index.js
|
|
403
|
+
const MAGIC_KERNEL_METHODS = [
|
|
404
|
+
"magicKernel",
|
|
405
|
+
"magicKernelSharp2013",
|
|
406
|
+
"magicKernelSharp2021"
|
|
407
|
+
];
|
|
408
|
+
let resizeWasmReady;
|
|
409
|
+
let hqxWasmReady;
|
|
410
|
+
let magicKernelWasmReady;
|
|
411
|
+
function initResize(moduleOrPath) {
|
|
412
|
+
if (!resizeWasmReady) resizeWasmReady = __wbg_init$2(moduleOrPath);
|
|
413
|
+
return resizeWasmReady;
|
|
414
|
+
}
|
|
415
|
+
function initHqx(moduleOrPath) {
|
|
416
|
+
if (!hqxWasmReady) hqxWasmReady = __wbg_init$1(moduleOrPath);
|
|
417
|
+
return hqxWasmReady;
|
|
418
|
+
}
|
|
419
|
+
function initMagicKernel(moduleOrPath) {
|
|
420
|
+
if (!magicKernelWasmReady) magicKernelWasmReady = __wbg_init(moduleOrPath);
|
|
421
|
+
return magicKernelWasmReady;
|
|
422
|
+
}
|
|
423
|
+
function optsIsHqxOpts(opts) {
|
|
424
|
+
return opts.method === "hqx";
|
|
425
|
+
}
|
|
426
|
+
function optsIsMagicKernelOpts(opts) {
|
|
427
|
+
return MAGIC_KERNEL_METHODS.includes(opts.method);
|
|
428
|
+
}
|
|
429
|
+
function crop(data, sx, sy, sw, sh) {
|
|
430
|
+
const inputPixels = new Uint32Array(data.data.buffer);
|
|
431
|
+
for (let y = 0; y < sh; y += 1) {
|
|
432
|
+
const start = (y + sy) * data.width + sx;
|
|
433
|
+
inputPixels.copyWithin(y * sw, start, start + sw);
|
|
434
|
+
}
|
|
435
|
+
return new ImageData(new Uint8ClampedArray(inputPixels.buffer.slice(0, sw * sh * 4)), sw, sh);
|
|
436
|
+
}
|
|
437
|
+
function clamp(num, { min = Number.MIN_VALUE, max = Number.MAX_VALUE }) {
|
|
438
|
+
return Math.min(Math.max(num, min), max);
|
|
439
|
+
}
|
|
440
|
+
/** Resize methods by index */
|
|
441
|
+
const resizeMethods = [
|
|
442
|
+
"triangle",
|
|
443
|
+
"catrom",
|
|
444
|
+
"mitchell",
|
|
445
|
+
"lanczos3"
|
|
446
|
+
];
|
|
447
|
+
async function hqx(input, opts) {
|
|
448
|
+
await initHqx();
|
|
449
|
+
const widthRatio = opts.width / input.width;
|
|
450
|
+
const heightRatio = opts.height / input.height;
|
|
451
|
+
const factor = clamp(Math.ceil(Math.max(widthRatio, heightRatio)), {
|
|
452
|
+
min: 1,
|
|
453
|
+
max: 4
|
|
454
|
+
});
|
|
455
|
+
if (factor === 1) return input;
|
|
456
|
+
const result = resize$2(new Uint32Array(input.data.buffer), input.width, input.height, factor);
|
|
457
|
+
return new ImageData(new Uint8ClampedArray(result.buffer), input.width * factor, input.height * factor);
|
|
458
|
+
}
|
|
459
|
+
async function magicKernel(input, opts) {
|
|
460
|
+
await initMagicKernel();
|
|
461
|
+
return resize$1(new Uint8Array(input.data.buffer), input.width, input.height, opts.width, opts.height, opts.method);
|
|
462
|
+
}
|
|
463
|
+
async function resize(data, overrideOptions) {
|
|
464
|
+
let options = {
|
|
465
|
+
...defaultOptions,
|
|
466
|
+
...overrideOptions
|
|
467
|
+
};
|
|
468
|
+
let input = data;
|
|
469
|
+
initResize();
|
|
470
|
+
if (optsIsHqxOpts(options)) {
|
|
471
|
+
input = await hqx(input, options);
|
|
472
|
+
options = {
|
|
473
|
+
...options,
|
|
474
|
+
method: "catrom"
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
await resizeWasmReady;
|
|
478
|
+
if (options.fitMethod === "contain") {
|
|
479
|
+
const { sx, sy, sw, sh } = getContainOffsets(data.width, data.height, options.width, options.height);
|
|
480
|
+
input = crop(input, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh));
|
|
481
|
+
}
|
|
482
|
+
if (optsIsMagicKernelOpts(options)) return magicKernel(input, options);
|
|
483
|
+
const result = resize$3(new Uint8Array(input.data.buffer), input.width, input.height, options.width, options.height, resizeMethods.indexOf(options.method), options.premultiply, options.linearRGB);
|
|
484
|
+
return new ImageData(new Uint8ClampedArray(result.buffer), options.width, options.height);
|
|
485
|
+
}
|
|
486
|
+
//#endregion
|
|
487
|
+
export { resize as default, initResize };
|
|
488
|
+
|
|
489
|
+
//# sourceMappingURL=resize-B47sgoOb.mjs.map
|