main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
// eslint-disable-next-line no-shadow
export const enum AVIFTune {
auto,
psnr,
ssim,
}
export interface EncodeOptions {
cqLevel: number
denoiseLevel: number
cqAlphaLevel: number
tileRowsLog2: number
tileColsLog2: number
speed: number
subsample: number
chromaDeltaQ: boolean
sharpness: number
tune: AVIFTune
}
export interface AVIFModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions
): Uint8Array
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<AVIFModule>
export default moduleFactory

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

272
node_modules/next/dist/esm/server/lib/squoosh/codecs.js generated vendored Normal file
View File

@@ -0,0 +1,272 @@
import { promises as fsp } from "fs";
import * as path from "path";
import { instantiateEmscriptenWasm, pathify } from "./emscripten-utils.js";
// @ts-ignore
import mozEnc from "./mozjpeg/mozjpeg_node_enc.js";
const mozEncWasm = path.resolve(__dirname, "./mozjpeg/mozjpeg_node_enc.wasm");
// @ts-ignore
import mozDec from "./mozjpeg/mozjpeg_node_dec.js";
const mozDecWasm = path.resolve(__dirname, "./mozjpeg/mozjpeg_node_dec.wasm");
// @ts-ignore
import webpEnc from "./webp/webp_node_enc.js";
const webpEncWasm = path.resolve(__dirname, "./webp/webp_node_enc.wasm");
// @ts-ignore
import webpDec from "./webp/webp_node_dec.js";
const webpDecWasm = path.resolve(__dirname, "./webp/webp_node_dec.wasm");
// @ts-ignore
import avifEnc from "./avif/avif_node_enc.js";
const avifEncWasm = path.resolve(__dirname, "./avif/avif_node_enc.wasm");
// @ts-ignore
import avifDec from "./avif/avif_node_dec.js";
const avifDecWasm = path.resolve(__dirname, "./avif/avif_node_dec.wasm");
// PNG
// @ts-ignore
import * as pngEncDec from "./png/squoosh_png.js";
const pngEncDecWasm = path.resolve(__dirname, "./png/squoosh_png_bg.wasm");
const pngEncDecInit = ()=>pngEncDec.default(fsp.readFile(pathify(pngEncDecWasm)));
// OxiPNG
// @ts-ignore
import * as oxipng from "./png/squoosh_oxipng.js";
const oxipngWasm = path.resolve(__dirname, "./png/squoosh_oxipng_bg.wasm");
const oxipngInit = ()=>oxipng.default(fsp.readFile(pathify(oxipngWasm)));
// Resize
// @ts-ignore
import * as resize from "./resize/squoosh_resize.js";
const resizeWasm = path.resolve(__dirname, "./resize/squoosh_resize_bg.wasm");
const resizeInit = ()=>resize.default(fsp.readFile(pathify(resizeWasm)));
// rotate
const rotateWasm = path.resolve(__dirname, "./rotate/rotate.wasm");
// Our decoders currently rely on a `ImageData` global.
import ImageData from "./image_data";
globalThis.ImageData = ImageData;
function resizeNameToIndex(name) {
switch(name){
case "triangle":
return 0;
case "catrom":
return 1;
case "mitchell":
return 2;
case "lanczos3":
return 3;
default:
throw Error(`Unknown resize algorithm "${name}"`);
}
}
function resizeWithAspect({ input_width, input_height, target_width, target_height }) {
if (!target_width && !target_height) {
throw Error("Need to specify at least width or height when resizing");
}
if (target_width && target_height) {
return {
width: target_width,
height: target_height
};
}
if (!target_width) {
return {
width: Math.round(input_width / input_height * target_height),
height: target_height
};
}
return {
width: target_width,
height: Math.round(input_height / input_width * target_width)
};
}
export const preprocessors = {
resize: {
name: "Resize",
description: "Resize the image before compressing",
instantiate: async ()=>{
await resizeInit();
return (buffer, input_width, input_height, { width, height, method, premultiply, linearRGB })=>{
({ width, height } = resizeWithAspect({
input_width,
input_height,
target_width: width,
target_height: height
}));
const imageData = new ImageData(resize.resize(buffer, input_width, input_height, width, height, resizeNameToIndex(method), premultiply, linearRGB), width, height);
resize.cleanup();
return imageData;
};
},
defaultOptions: {
method: "lanczos3",
fitMethod: "stretch",
premultiply: true,
linearRGB: true
}
},
rotate: {
name: "Rotate",
description: "Rotate image",
instantiate: async ()=>{
return async (buffer, width, height, { numRotations })=>{
const degrees = numRotations * 90 % 360;
const sameDimensions = degrees === 0 || degrees === 180;
const size = width * height * 4;
const instance = (await WebAssembly.instantiate(await fsp.readFile(pathify(rotateWasm)))).instance;
const { memory } = instance.exports;
const additionalPagesNeeded = Math.ceil((size * 2 - memory.buffer.byteLength + 8) / (64 * 1024));
if (additionalPagesNeeded > 0) {
memory.grow(additionalPagesNeeded);
}
const view = new Uint8ClampedArray(memory.buffer);
view.set(buffer, 8);
instance.exports.rotate(width, height, degrees);
return new ImageData(view.slice(size + 8, size * 2 + 8), sameDimensions ? width : height, sameDimensions ? height : width);
};
},
defaultOptions: {
numRotations: 0
}
}
};
export const codecs = {
mozjpeg: {
name: "MozJPEG",
extension: "jpg",
detectors: [
/^\xFF\xD8\xFF/
],
dec: ()=>instantiateEmscriptenWasm(mozDec, mozDecWasm),
enc: ()=>instantiateEmscriptenWasm(mozEnc, mozEncWasm),
defaultEncoderOptions: {
quality: 75,
baseline: false,
arithmetic: false,
progressive: true,
optimize_coding: true,
smoothing: 0,
color_space: 3 /*YCbCr*/ ,
quant_table: 3,
trellis_multipass: false,
trellis_opt_zero: false,
trellis_opt_table: false,
trellis_loops: 1,
auto_subsample: true,
chroma_subsample: 2,
separate_chroma_quality: false,
chroma_quality: 75
},
autoOptimize: {
option: "quality",
min: 0,
max: 100
}
},
webp: {
name: "WebP",
extension: "webp",
detectors: [
/^RIFF....WEBPVP8[LX ]/s
],
dec: ()=>instantiateEmscriptenWasm(webpDec, webpDecWasm),
enc: ()=>instantiateEmscriptenWasm(webpEnc, webpEncWasm),
defaultEncoderOptions: {
quality: 75,
target_size: 0,
target_PSNR: 0,
method: 4,
sns_strength: 50,
filter_strength: 60,
filter_sharpness: 0,
filter_type: 1,
partitions: 0,
segments: 4,
pass: 1,
show_compressed: 0,
preprocessing: 0,
autofilter: 0,
partition_limit: 0,
alpha_compression: 1,
alpha_filtering: 1,
alpha_quality: 100,
lossless: 0,
exact: 0,
image_hint: 0,
emulate_jpeg_size: 0,
thread_level: 0,
low_memory: 0,
near_lossless: 100,
use_delta_palette: 0,
use_sharp_yuv: 0
},
autoOptimize: {
option: "quality",
min: 0,
max: 100
}
},
avif: {
name: "AVIF",
extension: "avif",
// eslint-disable-next-line no-control-regex
detectors: [
/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/
],
dec: ()=>instantiateEmscriptenWasm(avifDec, avifDecWasm),
enc: async ()=>{
return instantiateEmscriptenWasm(avifEnc, avifEncWasm);
},
defaultEncoderOptions: {
cqLevel: 33,
cqAlphaLevel: -1,
denoiseLevel: 0,
tileColsLog2: 0,
tileRowsLog2: 0,
speed: 6,
subsample: 1,
chromaDeltaQ: false,
sharpness: 0,
tune: 0 /* AVIFTune.auto */
},
autoOptimize: {
option: "cqLevel",
min: 62,
max: 0
}
},
oxipng: {
name: "OxiPNG",
extension: "png",
// eslint-disable-next-line no-control-regex
detectors: [
/^\x89PNG\x0D\x0A\x1A\x0A/
],
dec: async ()=>{
await pngEncDecInit();
return {
decode: (buffer)=>{
const imageData = pngEncDec.decode(buffer);
pngEncDec.cleanup();
return imageData;
}
};
},
enc: async ()=>{
await pngEncDecInit();
await oxipngInit();
return {
encode: (buffer, width, height, opts)=>{
const simplePng = pngEncDec.encode(new Uint8Array(buffer), width, height);
const imageData = oxipng.optimise(simplePng, opts.level, false);
oxipng.cleanup();
return imageData;
}
};
},
defaultEncoderOptions: {
level: 2
},
autoOptimize: {
option: "level",
min: 6,
max: 1
}
}
};
//# sourceMappingURL=codecs.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,121 @@
// These types roughly model the object that the JS files generated by Emscripten define. Copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/emscripten/index.d.ts and turned into a type definition rather than a global to support our way of using Emscripten.
declare namespace EmscriptenWasm {
type ModuleFactory<T extends Module = Module> = (
moduleOverrides?: ModuleOpts
) => Promise<T>
type EnvironmentType = 'WEB' | 'NODE' | 'SHELL' | 'WORKER'
// Options object for modularized Emscripten files. Shoe-horned by @surma.
// FIXME: This an incomplete definition!
interface ModuleOpts {
mainScriptUrlOrBlob?: string
noInitialRun?: boolean
locateFile?: (url: string) => string
onRuntimeInitialized?: () => void
}
interface Module {
print(str: string): void
printErr(str: string): void
arguments: string[]
environment: EnvironmentType
preInit: { (): void }[]
preRun: { (): void }[]
postRun: { (): void }[]
preinitializedWebGLContext: WebGLRenderingContext
noInitialRun: boolean
noExitRuntime: boolean
logReadFiles: boolean
filePackagePrefixURL: string
wasmBinary: ArrayBuffer
destroy(object: object): void
getPreloadedPackage(
remotePackageName: string,
remotePackageSize: number
): ArrayBuffer
instantiateWasm(
imports: WebAssembly.Imports,
successCallback: (module: WebAssembly.Module) => void
): WebAssembly.Exports
locateFile(url: string): string
onCustomMessage(event: MessageEvent): void
Runtime: any
ccall(
ident: string,
returnType: string | null,
argTypes: string[],
args: any[]
): any
cwrap(ident: string, returnType: string | null, argTypes: string[]): any
setValue(ptr: number, value: any, type: string, noSafe?: boolean): void
getValue(ptr: number, type: string, noSafe?: boolean): number
ALLOC_NORMAL: number
ALLOC_STACK: number
ALLOC_STATIC: number
ALLOC_DYNAMIC: number
ALLOC_NONE: number
allocate(slab: any, types: string, allocator: number, ptr: number): number
allocate(slab: any, types: string[], allocator: number, ptr: number): number
Pointer_stringify(ptr: number, length?: number): string
UTF16ToString(ptr: number): string
stringToUTF16(str: string, outPtr: number): void
UTF32ToString(ptr: number): string
stringToUTF32(str: string, outPtr: number): void
// USE_TYPED_ARRAYS == 1
HEAP: Int32Array
IHEAP: Int32Array
FHEAP: Float64Array
// USE_TYPED_ARRAYS == 2
HEAP8: Int8Array
HEAP16: Int16Array
HEAP32: Int32Array
HEAPU8: Uint8Array
HEAPU16: Uint16Array
HEAPU32: Uint32Array
HEAPF32: Float32Array
HEAPF64: Float64Array
TOTAL_STACK: number
TOTAL_MEMORY: number
FAST_MEMORY: number
addOnPreRun(cb: () => any): void
addOnInit(cb: () => any): void
addOnPreMain(cb: () => any): void
addOnExit(cb: () => any): void
addOnPostRun(cb: () => any): void
// Tools
intArrayFromString(
stringy: string,
dontAddNull?: boolean,
length?: number
): number[]
intArrayToString(array: number[]): string
writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void
writeArrayToMemory(array: number[], buffer: number): void
writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void
addRunDependency(id: any): void
removeRunDependency(id: any): void
preloadedImages: any
preloadedAudios: any
_malloc(size: number): number
_free(ptr: number): void
// Augmentations below by @surma.
onRuntimeInitialized: () => void | null
}
}

View File

@@ -0,0 +1,22 @@
import { fileURLToPath } from "url";
export function pathify(path) {
if (path.startsWith("file://")) {
path = fileURLToPath(path);
}
return path;
}
export function instantiateEmscriptenWasm(factory, path, workerJS = "") {
return factory({
locateFile (requestPath) {
// The glue code generated by emscripten uses the original
// file names of the worker file and the wasm binary.
// These will have changed in the bundling process and
// we need to inject them here.
if (requestPath.endsWith(".wasm")) return pathify(path);
if (requestPath.endsWith(".worker.js")) return pathify(workerJS);
return requestPath;
}
});
}
//# sourceMappingURL=emscripten-utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/squoosh/emscripten-utils.ts"],"names":["fileURLToPath","pathify","path","startsWith","instantiateEmscriptenWasm","factory","workerJS","locateFile","requestPath","endsWith"],"mappings":"AAAA,SAASA,aAAa,QAAQ,MAAK;AAEnC,OAAO,SAASC,QAAQC,IAAY;IAClC,IAAIA,KAAKC,UAAU,CAAC,YAAY;QAC9BD,OAAOF,cAAcE;IACvB;IACA,OAAOA;AACT;AAEA,OAAO,SAASE,0BACdC,OAAwC,EACxCH,IAAY,EACZI,WAAmB,EAAE;IAErB,OAAOD,QAAQ;QACbE,YAAWC,WAAW;YACpB,0DAA0D;YAC1D,qDAAqD;YACrD,sDAAsD;YACtD,+BAA+B;YAC/B,IAAIA,YAAYC,QAAQ,CAAC,UAAU,OAAOR,QAAQC;YAClD,IAAIM,YAAYC,QAAQ,CAAC,eAAe,OAAOR,QAAQK;YACvD,OAAOE;QACT;IACF;AACF"}

View File

@@ -0,0 +1,21 @@
export default class ImageData {
static from(input) {
return new ImageData(input.data || input._data, input.width, input.height);
}
get data() {
if (Object.prototype.toString.call(this._data) === "[object Object]") {
return Buffer.from(Object.values(this._data));
}
if (this._data instanceof Buffer || this._data instanceof Uint8Array || this._data instanceof Uint8ClampedArray) {
return Buffer.from(this._data);
}
throw new Error("invariant");
}
constructor(data, width, height){
this._data = data;
this.width = width;
this.height = height;
}
}
//# sourceMappingURL=image_data.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/squoosh/image_data.ts"],"names":["ImageData","from","input","data","_data","width","height","Object","prototype","toString","call","Buffer","values","Uint8Array","Uint8ClampedArray","Error","constructor"],"mappings":"AAAA,eAAe,MAAMA;IACnB,OAAOC,KAAKC,KAAgB,EAAa;QACvC,OAAO,IAAIF,UAAUE,MAAMC,IAAI,IAAID,MAAME,KAAK,EAAEF,MAAMG,KAAK,EAAEH,MAAMI,MAAM;IAC3E;IAMA,IAAIH,OAAe;QACjB,IAAII,OAAOC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAAC,IAAI,CAACN,KAAK,MAAM,mBAAmB;YACpE,OAAOO,OAAOV,IAAI,CAACM,OAAOK,MAAM,CAAC,IAAI,CAACR,KAAK;QAC7C;QACA,IACE,IAAI,CAACA,KAAK,YAAYO,UACtB,IAAI,CAACP,KAAK,YAAYS,cACtB,IAAI,CAACT,KAAK,YAAYU,mBACtB;YACA,OAAOH,OAAOV,IAAI,CAAC,IAAI,CAACG,KAAK;QAC/B;QACA,MAAM,IAAIW,MAAM;IAClB;IAEAC,YACEb,IAA6C,EAC7CE,KAAa,EACbC,MAAc,CACd;QACA,IAAI,CAACF,KAAK,GAAGD;QACb,IAAI,CAACE,KAAK,GAAGA;QACb,IAAI,CAACC,MAAM,GAAGA;IAChB;AACF"}

77
node_modules/next/dist/esm/server/lib/squoosh/impl.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
import { codecs as supportedFormats, preprocessors } from "./codecs";
import ImageData from "./image_data";
export async function decodeBuffer(_buffer) {
var _Object_entries_find;
const buffer = Buffer.from(_buffer);
const firstChunk = buffer.slice(0, 16);
const firstChunkString = Array.from(firstChunk).map((v)=>String.fromCodePoint(v)).join("");
const key = (_Object_entries_find = Object.entries(supportedFormats).find(([, { detectors }])=>detectors.some((detector)=>detector.exec(firstChunkString)))) == null ? void 0 : _Object_entries_find[0];
if (!key) {
throw Error(`Buffer has an unsupported format`);
}
const encoder = supportedFormats[key];
const mod = await encoder.dec();
const rgba = mod.decode(new Uint8Array(buffer));
return rgba;
}
export async function rotate(image, numRotations) {
image = ImageData.from(image);
const m = await preprocessors["rotate"].instantiate();
return await m(image.data, image.width, image.height, {
numRotations
});
}
export async function resize({ image, width, height }) {
image = ImageData.from(image);
const p = preprocessors["resize"];
const m = await p.instantiate();
return await m(image.data, image.width, image.height, {
...p.defaultOptions,
width,
height
});
}
export async function encodeJpeg(image, { quality }) {
image = ImageData.from(image);
const e = supportedFormats["mozjpeg"];
const m = await e.enc();
const r = await m.encode(image.data, image.width, image.height, {
...e.defaultEncoderOptions,
quality
});
return Buffer.from(r);
}
export async function encodeWebp(image, { quality }) {
image = ImageData.from(image);
const e = supportedFormats["webp"];
const m = await e.enc();
const r = await m.encode(image.data, image.width, image.height, {
...e.defaultEncoderOptions,
quality
});
return Buffer.from(r);
}
export async function encodeAvif(image, { quality }) {
image = ImageData.from(image);
const e = supportedFormats["avif"];
const m = await e.enc();
const val = e.autoOptimize.min || 62;
const r = await m.encode(image.data, image.width, image.height, {
...e.defaultEncoderOptions,
// Think of cqLevel as the "amount" of quantization (0 to 62),
// so a lower value yields higher quality (0 to 100).
cqLevel: Math.round(val - quality / 100 * val)
});
return Buffer.from(r);
}
export async function encodePng(image) {
image = ImageData.from(image);
const e = supportedFormats["oxipng"];
const m = await e.enc();
const r = await m.encode(image.data, image.width, image.height, {
...e.defaultEncoderOptions
});
return Buffer.from(r);
}
//# sourceMappingURL=impl.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/squoosh/impl.ts"],"names":["codecs","supportedFormats","preprocessors","ImageData","decodeBuffer","_buffer","Object","buffer","Buffer","from","firstChunk","slice","firstChunkString","Array","map","v","String","fromCodePoint","join","key","entries","find","detectors","some","detector","exec","Error","encoder","mod","dec","rgba","decode","Uint8Array","rotate","image","numRotations","m","instantiate","data","width","height","resize","p","defaultOptions","encodeJpeg","quality","e","enc","r","encode","defaultEncoderOptions","encodeWebp","encodeAvif","val","autoOptimize","min","cqLevel","Math","round","encodePng"],"mappings":"AAAA,SAASA,UAAUC,gBAAgB,EAAEC,aAAa,QAAQ,WAAU;AACpE,OAAOC,eAAe,eAAc;AAIpC,OAAO,eAAeC,aACpBC,OAA4B;QAOhBC;IALZ,MAAMC,SAASC,OAAOC,IAAI,CAACJ;IAC3B,MAAMK,aAAaH,OAAOI,KAAK,CAAC,GAAG;IACnC,MAAMC,mBAAmBC,MAAMJ,IAAI,CAACC,YACjCI,GAAG,CAAC,CAACC,IAAMC,OAAOC,aAAa,CAACF,IAChCG,IAAI,CAAC;IACR,MAAMC,OAAMb,uBAAAA,OAAOc,OAAO,CAACnB,kBAAkBoB,IAAI,CAAC,CAAC,GAAG,EAAEC,SAAS,EAAE,CAAC,GAClEA,UAAUC,IAAI,CAAC,CAACC,WAAaA,SAASC,IAAI,CAACb,wCADjCN,oBAET,CAAC,EAAE;IACN,IAAI,CAACa,KAAK;QACR,MAAMO,MAAM,CAAC,gCAAgC,CAAC;IAChD;IACA,MAAMC,UAAU1B,gBAAgB,CAACkB,IAAI;IACrC,MAAMS,MAAM,MAAMD,QAAQE,GAAG;IAC7B,MAAMC,OAAOF,IAAIG,MAAM,CAAC,IAAIC,WAAWzB;IACvC,OAAOuB;AACT;AAEA,OAAO,eAAeG,OACpBC,KAAgB,EAChBC,YAAoB;IAEpBD,QAAQ/B,UAAUM,IAAI,CAACyB;IAEvB,MAAME,IA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AAEA,OAAO,eAAeI,WACpBlB,KAAgB,EAChB,EAAEW,OAAO,EAAuB;IAEhCX,QAAQ/B,UAAUM,IAAI,CAACyB;IAEvB,MAAMY,IAAI7C,gBAAgB,CAAC,OAAO;IAClC,MAAMmC,IAAI,MAAMU,EAAEC,GAAG;IACrB,MAAMM,MAAMP,EAAEQ,YAAY,CAACC,GAAG,IAAI;IAClC,MAAMP,IAAI,MAAMZ,EAAEa,MAAM,CAACf,MAAMI,IAAI,EAAEJ,MAAMK,KAAK,EAAEL,MAAMM,MAAM,EAAE;QAC9D,GAAGM,EAAEI,qBAAqB;QAC1B,8DAA8D;QAC9D,qDAAqD;QACrDM,SAASC,KAAKC,KAAK,CAACL,MAAM,AAACR,UAAU,MAAOQ;IAC9C;IACA,OAAO7C,OAAOC,IAAI,CAACuC;AACrB;AAEA,OAAO,eAAeW,UACpBzB,KAAgB;IAEhBA,QAAQ/B,UAAUM,IAAI,CAACyB;IAEvB,MAAMY,IAAI7C,gBAAgB,CAAC,SAAS;IACpC,MAAMmC,IAAI,MAAMU,EAAEC,GAAG;IACrB,MAAMC,IAAI,MAAMZ,EAAEa,MAAM,CAACf,MAAMI,IAAI,EAAEJ,MAAMK,KAAK,EAAEL,MAAMM,MAAM,EAAE;QAC9D,GAAGM,EAAEI,qBAAqB;IAC5B;IACA,OAAO1C,OAAOC,IAAI,CAACuC;AACrB"}

69
node_modules/next/dist/esm/server/lib/squoosh/main.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
import { Worker } from "next/dist/compiled/jest-worker";
import * as path from "path";
import { execOnce } from "../../../shared/lib/utils";
import { cpus } from "os";
const getWorker = execOnce(()=>new Worker(path.resolve(__dirname, "impl"), {
enableWorkerThreads: true,
// There will be at most 6 workers needed since each worker will take
// at least 1 operation type.
numWorkers: Math.max(1, Math.min(cpus().length - 1, 6)),
computeWorkerKey: (method)=>method
}));
export async function getMetadata(buffer) {
const worker = getWorker();
const { width, height } = await worker.decodeBuffer(buffer);
return {
width,
height
};
}
export async function processBuffer(buffer, operations, encoding, quality) {
const worker = getWorker();
let imageData = await worker.decodeBuffer(buffer);
for (const operation of operations){
if (operation.type === "rotate") {
imageData = await worker.rotate(imageData, operation.numRotations);
} else if (operation.type === "resize") {
const opt = {
image: imageData,
width: 0,
height: 0
};
if (operation.width && imageData.width && imageData.width > operation.width) {
opt.width = operation.width;
}
if (operation.height && imageData.height && imageData.height > operation.height) {
opt.height = operation.height;
}
if (opt.width > 0 || opt.height > 0) {
imageData = await worker.resize(opt);
}
}
}
switch(encoding){
case "jpeg":
return Buffer.from(await worker.encodeJpeg(imageData, {
quality
}));
case "webp":
return Buffer.from(await worker.encodeWebp(imageData, {
quality
}));
case "avif":
const avifQuality = quality - 20;
return Buffer.from(await worker.encodeAvif(imageData, {
quality: Math.max(avifQuality, 0)
}));
case "png":
return Buffer.from(await worker.encodePng(imageData));
default:
throw Error(`Unsupported encoding format`);
}
}
export async function decodeBuffer(buffer) {
const worker = getWorker();
const imageData = await worker.decodeBuffer(buffer);
return imageData;
}
//# sourceMappingURL=main.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/lib/squoosh/main.ts"],"names":["Worker","path","execOnce","cpus","getWorker","resolve","__dirname","enableWorkerThreads","numWorkers","Math","max","min","length","computeWorkerKey","method","getMetadata","buffer","worker","width","height","decodeBuffer","processBuffer","operations","encoding","quality","imageData","operation","type","rotate","numRotations","opt","image","resize","Buffer","from","encodeJpeg","encodeWebp","avifQuality","encodeAvif","encodePng","Error"],"mappings":"AAAA,SAASA,MAAM,QAAQ,iCAAgC;AACvD,YAAYC,UAAU,OAAM;AAC5B,SAASC,QAAQ,QAAQ,4BAA2B;AACpD,SAASC,IAAI,QAAQ,KAAI;AAgBzB,MAAMC,YAAYF,SAChB,IACE,IAAIF,OAAOC,KAAKI,OAAO,CAACC,WAAW,SAAS;QAC1CC,qBAAqB;QACrB,qEAAqE;QACrE,6BAA6B;QAC7BC,YAAYC,KAAKC,GAAG,CAAC,G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AAW;gBAAED;YAAQ;QAClE,KAAK;YACH,MAAMa,cAAcb,UAAU;YAC9B,OAAOS,OAAOC,IAAI,CAChB,MAAMjB,OAAOqB,UAAU,CAACb,WAAW;gBACjCD,SAASf,KAAKC,GAAG,CAAC2B,aAAa;YACjC;QAEJ,KAAK;YACH,OAAOJ,OAAOC,IAAI,CAAC,MAAMjB,OAAOsB,SAAS,CAACd;QAC5C;YACE,MAAMe,MAAM,CAAC,2BAA2B,CAAC;IAC7C;AACF;AAEA,OAAO,eAAepB,aAAaJ,MAAc;IAC/C,MAAMC,SAAkCb;IACxC,MAAMqB,YAAY,MAAMR,OAAOG,YAAY,CAACJ;IAC5C,OAAOS;AACT"}

View File

@@ -0,0 +1,38 @@
// eslint-disable-next-line no-shadow
export const enum MozJpegColorSpace {
GRAYSCALE = 1,
RGB,
YCbCr,
}
export interface EncodeOptions {
quality: number
baseline: boolean
arithmetic: boolean
progressive: boolean
optimize_coding: boolean
smoothing: number
color_space: MozJpegColorSpace
quant_table: number
trellis_multipass: boolean
trellis_opt_zero: boolean
trellis_opt_table: boolean
trellis_loops: number
auto_subsample: boolean
chroma_subsample: number
separate_chroma_quality: boolean
chroma_quality: number
}
export interface MozJPEGModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions
): Uint8Array
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<MozJPEGModule>
export default moduleFactory

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,95 @@
let wasm;
let cachedTextDecoder = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder.decode();
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {Uint8Array} data
* @param {number} level
* @param {boolean} interlace
* @returns {Uint8Array}
*/ export function optimise(data, level, interlace) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.optimise(retptr, ptr0, len0, level, interlace);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v1 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally{
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
async function load(module, imports) {
if (typeof Response === "function" && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === "function") {
return await WebAssembly.instantiateStreaming(module, imports);
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return {
instance,
module
};
} else {
return instance;
}
}
}
async function init(input) {
const imports = {};
imports.wbg = {};
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
}
export default init;
// Manually remove the wasm and memory references to trigger GC
export function cleanup() {
wasm = null;
cachegetUint8Memory0 = null;
cachegetInt32Memory0 = null;
}
//# sourceMappingURL=squoosh_oxipng.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/lib/squoosh/png/squoosh_oxipng.js"],"names":["wasm","cachedTextDecoder","TextDecoder","ignoreBOM","fatal","decode","cachegetUint8Memory0","getUint8Memory0","buffer","memory","Uint8Array","getStringFromWasm0","ptr","len","subarray","WASM_VECTOR_LEN","passArray8ToWasm0","arg","malloc","length","set","cachegetInt32Memory0","getInt32Memory0","Int32Array","getArrayU8FromWasm0","optimise","data","level","interlace","retptr","__wbindgen_add_to_stack_pointer","ptr0","__wbindgen_malloc","len0","r0","r1","v1","slice","__wbindgen_free","load","module","imports","Response","WebAssembly","instantiateStreaming","bytes","arrayBuffer","instantiate","instance","Instance","init","input","wbg","__wbindgen_throw","arg0","arg1","Error","Request","URL","fetch","exports","__wbindgen_wasm_module","cleanup"],"mappings":"AAAA,IAAIA;AAEJ,IAAIC,oBAAoB,IAAIC,YAAY,SAAS;IAC/CC,WAAW;IACXC,OAAO;AACT;AAEAH,kBAAkBI,MAAM;AAExB,IAAIC,uBAAuB;AAC3B,SAASC;IACP,IACED,yBAAyB,QACzBA,qBAAqBE,MAAM,KAAKR,KAAKS,MAAM,CAACD,MAAM,EAClD;QACAF,uBAAuB,IAAII,WAAWV,KAAKS,MAAM,CAACD,MAAM;IAC1D;IACA,OAAOF;AACT;AAEA,SAASK,mBAAmBC,GAAG,EAAEC,GAAG;IAClC,OAAOZ,kBAAkBI,MAAM,CAACE,kBAAkBO,QAAQ,CAACF,KAAKA,MAAMC;AACxE;AAEA,IAAIE,kBAAkB;AAEtB,SAASC,kBAAkBC,GAAG,EAAEC,MAAM;IACpC,MAAMN,MAAMM,OAAOD,IAAIE,MAAM,GAAG;IAChCZ,kBAAkBa,GAAG,C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AAW,CAACP,QAAQC;QAEvD,IAAIO,oBAAoBL,YAAYM,QAAQ,EAAE;YAC5C,OAAO;gBAAED;gBAAUR;YAAO;QAC5B,OAAO;YACL,OAAOQ;QACT;IACF;AACF;AAEA,eAAeE,KAAKC,KAAK;IACvB,MAAMV,UAAU,CAAC;IACjBA,QAAQW,GAAG,GAAG,CAAC;IACfX,QAAQW,GAAG,CAACC,gBAAgB,GAAG,SAAUC,IAAI,EAAEC,IAAI;QACjD,MAAM,IAAIC,MAAM7C,mBAAmB2C,MAAMC;IAC3C;IAEA,IACE,OAAOJ,UAAU,YAChB,OAAOM,YAAY,cAAcN,iBAAiBM,WAClD,OAAOC,QAAQ,cAAcP,iBAAiBO,KAC/C;QACAP,QAAQQ,MAAMR;IAChB;IAEA,MAAM,EAAEH,QAAQ,EAAER,MAAM,EAAE,GAAG,MAAMD,KAAK,MAAMY,OAAOV;IAErDzC,OAAOgD,SAASY,OAAO;IACvBV,KAAKW,sBAAsB,GAAGrB;IAE9B,OAAOxC;AACT;AAEA,eAAekD,KAAI;AAEnB,+DAA+D;AAC/D,OAAO,SAASY;IACd9D,OAAO;IACPM,uBAAuB;IACvBe,uBAAuB;AACzB"}

View File

@@ -0,0 +1,144 @@
let wasm;
let cachedTextDecoder = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder.decode();
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
function getStringFromWasm0(ptr, len) {
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
}
let cachegetUint8ClampedMemory0 = null;
function getUint8ClampedMemory0() {
if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {
cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
}
return cachegetUint8ClampedMemory0;
}
function getClampedArrayU8FromWasm0(ptr, len) {
return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
}
const heap = new Array(32).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
function getArrayU8FromWasm0(ptr, len) {
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {Uint8Array} data
* @param {number} width
* @param {number} height
* @returns {Uint8Array}
*/ export function encode(data, width, height) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.encode(retptr, ptr0, len0, width, height);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v1 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally{
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
function getObject(idx) {
return heap[idx];
}
function dropObject(idx) {
if (idx < 36) return;
heap[idx] = heap_next;
heap_next = idx;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
/**
* @param {Uint8Array} data
* @returns {ImageData}
*/ export function decode(data) {
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
var ret = wasm.decode(ptr0, len0);
return takeObject(ret);
}
async function load(module, imports) {
if (typeof Response === "function" && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === "function") {
return await WebAssembly.instantiateStreaming(module, imports);
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return {
instance,
module
};
} else {
return instance;
}
}
}
async function init(input) {
const imports = {};
imports.wbg = {};
imports.wbg.__wbg_newwithownedu8clampedarrayandsh_787b2db8ea6bfd62 = function(arg0, arg1, arg2, arg3) {
var v0 = getClampedArrayU8FromWasm0(arg0, arg1).slice();
wasm.__wbindgen_free(arg0, arg1 * 1);
var ret = new ImageData(v0, arg2 >>> 0, arg3 >>> 0);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
}
export default init;
// Manually remove the wasm and memory references to trigger GC
export function cleanup() {
wasm = null;
cachegetUint8ClampedMemory0 = null;
cachegetUint8Memory0 = null;
cachegetInt32Memory0 = null;
}
//# sourceMappingURL=squoosh_png.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/lib/squoosh/png/squoosh_png.js"],"names":["wasm","cachedTextDecoder","TextDecoder","ignoreBOM","fatal","decode","cachegetUint8Memory0","getUint8Memory0","buffer","memory","Uint8Array","getStringFromWasm0","ptr","len","subarray","cachegetUint8ClampedMemory0","getUint8ClampedMemory0","Uint8ClampedArray","getClampedArrayU8FromWasm0","heap","Array","fill","undefined","push","heap_next","length","addHeapObject","obj","idx","WASM_VECTOR_LEN","passArray8ToWasm0","arg","malloc","set","cachegetInt32Memory0","getInt32Memory0","Int32Array","getArrayU8FromWasm0","encode","data","width","height","retptr","__wbindgen_add_to_stack_pointer","ptr0","__wbindgen_malloc","len0","r0","r1","v1","slice","__wbindgen_free","getObject","dropObject","takeObject","ret","load","module","imports","Response","WebAssembly","instantiateStreaming","bytes","arrayBuffer","instantiate","instance","Instance","init","input","wbg","__wbg_newwithownedu8clampedarrayandsh_787b2db8ea6bfd62","arg0","arg1","arg2","arg3","v0","ImageData","__wbindgen_throw","Error","Request","URL","fetch","exports","__wbindgen_wasm_module","cleanup"],"mappings":"AAAA,IAAIA;AAEJ,IAAIC,oBAAoB,IAAIC,YAAY,SAAS;IAC/CC,WAAW;IACXC,OAAO;AACT;AAEAH,kBAAkBI,MAAM;AAExB,IAAIC,uBAAuB;AAC3B,SAASC;IACP,IACED,yBAAyB,QACzBA,qBAAqBE,MAAM,KAAKR,KAAKS,MAAM,CAACD,MAAM,EAClD;QACAF,uBAAuB,IAAII,WAAWV,KAAKS,MAAM,CAACD,MAAM;IAC1D;IACA,OAAOF;AACT;AAEA,SAASK,mBAAmBC,GAAG,EAAEC,GAAG;IAClC,OAAOZ,kBAAkBI,MAAM,CAACE,kBAAkBO,QAAQ,CAACF,KAAKA,MAAMC;AACxE;AAEA,IAAIE,8BAA8B;AAClC,SAASC;IACP,IACED,gCAAgC,QAChCA,4BAA4BP,MAAM,KAAKR,KAAKS,MAAM,CAACD,MAAM,EACzD;QACAO,8BAA8B,IAAIE,kBAAkBjB,KAAKS,MAAM,CAACD,MAAM;IACxE;IACA,OAAOO;AACT;AAEA,SAASG,2BAA2BN,GAAG,EAAEC,GAAG;IAC1C,OAAOG,yBAAyBF,QAAQ,CAACF,MAAM,GAAGA,MAAM,IAAIC;AAC9D;AAEA,MAAMM,OAAO,IAAIC,MAAM,IAAIC,IAAI,CAACC;AAEhCH,KAAKI,IAAI,CAACD,WAAW,MAAM,MAAM;AAEjC,IAAIE,YAAYL,KAAKM,MAAM;AAE3B,SAASC,cAAcC,GAAG;IACxB,IAAIH,cAAcL,KAAKM,MAAM,EAAEN,K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AAOhD,cAAc6B;IACvB;IACFG,QAAQW,GAAG,CAACQ,gBAAgB,GAAG,SAAUN,IAAI,EAAEC,IAAI;QACjD,MAAM,IAAIM,MAAMnE,mBAAmB4D,MAAMC;IAC3C;IAEA,IACE,OAAOJ,UAAU,YAChB,OAAOW,YAAY,cAAcX,iBAAiBW,WAClD,OAAOC,QAAQ,cAAcZ,iBAAiBY,KAC/C;QACAZ,QAAQa,MAAMb;IAChB;IAEA,MAAM,EAAEH,QAAQ,EAAER,MAAM,EAAE,GAAG,MAAMD,KAAK,MAAMY,OAAOV;IAErD1D,OAAOiE,SAASiB,OAAO;IACvBf,KAAKgB,sBAAsB,GAAG1B;IAE9B,OAAOzD;AACT;AAEA,eAAemE,KAAI;AAEnB,+DAA+D;AAC/D,OAAO,SAASiB;IACdpF,OAAO;IACPe,8BAA8B;IAC9BT,uBAAuB;IACvB4B,uBAAuB;AACzB"}

View File

@@ -0,0 +1,95 @@
let wasm;
let cachegetUint8Memory0 = null;
function getUint8Memory0() {
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachegetUint8Memory0;
}
let WASM_VECTOR_LEN = 0;
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1);
getUint8Memory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
let cachegetInt32Memory0 = null;
function getInt32Memory0() {
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
}
return cachegetInt32Memory0;
}
let cachegetUint8ClampedMemory0 = null;
function getUint8ClampedMemory0() {
if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {
cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
}
return cachegetUint8ClampedMemory0;
}
function getClampedArrayU8FromWasm0(ptr, len) {
return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {Uint8Array} input_image
* @param {number} input_width
* @param {number} input_height
* @param {number} output_width
* @param {number} output_height
* @param {number} typ_idx
* @param {boolean} premultiply
* @param {boolean} color_space_conversion
* @returns {Uint8ClampedArray}
*/ export function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);
var len0 = WASM_VECTOR_LEN;
wasm.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
var v1 = getClampedArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1);
return v1;
} finally{
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
async function load(module, imports) {
if (typeof Response === "function" && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === "function") {
return await WebAssembly.instantiateStreaming(module, imports);
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return {
instance,
module
};
} else {
return instance;
}
}
}
async function init(input) {
const imports = {};
if (typeof input === "string" || typeof Request === "function" && input instanceof Request || typeof URL === "function" && input instanceof URL) {
input = fetch(input);
}
const { instance, module } = await load(await input, imports);
wasm = instance.exports;
init.__wbindgen_wasm_module = module;
return wasm;
}
export default init;
// Manually remove the wasm and memory references to trigger GC
export function cleanup() {
wasm = null;
cachegetUint8Memory0 = null;
cachegetInt32Memory0 = null;
}
//# sourceMappingURL=squoosh_resize.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/server/lib/squoosh/resize/squoosh_resize.js"],"names":["wasm","cachegetUint8Memory0","getUint8Memory0","buffer","memory","Uint8Array","WASM_VECTOR_LEN","passArray8ToWasm0","arg","malloc","ptr","length","set","cachegetInt32Memory0","getInt32Memory0","Int32Array","cachegetUint8ClampedMemory0","getUint8ClampedMemory0","Uint8ClampedArray","getClampedArrayU8FromWasm0","len","subarray","resize","input_image","input_width","input_height","output_width","output_height","typ_idx","premultiply","color_space_conversion","retptr","__wbindgen_add_to_stack_pointer","ptr0","__wbindgen_malloc","len0","r0","r1","v1","slice","__wbindgen_free","load","module","imports","Response","WebAssembly","instantiateStreaming","bytes","arrayBuffer","instantiate","instance","Instance","init","input","Request","URL","fetch","exports","__wbindgen_wasm_module","cleanup"],"mappings":"AAAA,IAAIA;AAEJ,IAAIC,uBAAuB;AAC3B,SAASC;IACP,IACED,yBAAyB,QACzBA,qBAAqBE,MAAM,KAAKH,KAAKI,MAAM,CAACD,MAAM,EAClD;QACAF,uBAAuB,IAAII,WAAWL,KAAKI,MAAM,CAACD,MAAM;IAC1D;IACA,OAAOF;AACT;AAEA,IAAIK,kBAAkB;AAEtB,SAASC,kBAAkBC,GAAG,EAAEC,MAAM;IACpC,MAAMC,MAAMD,OAAOD,IAAIG,MAAM,GAAG;IAChCT,kBAAkBU,GAAG,CAACJ,KAAKE,MAAM;IACjCJ,kBAAkBE,IAAIG,MAAM;IAC5B,OAAOD;AACT;AAEA,IAAIG,uBAAuB;AAC3B,SAASC;IACP,IACED,yBAAyB,QACzBA,qBAAqBV,MAAM,KAAKH,KAAKI,MAAM,CAACD,MAAM,EAClD;QACAU,uBAAuB,IAAIE,WAAWf,KAAKI,MAAM,CAACD,MAAM;IAC1D;IACA,OAAOU;AACT;AAEA,IAAIG,8BAA8B;AAClC,SAASC;IACP,IACED,gCAAgC,QAChCA,4BAA4Bb,MAAM,KAAKH,KAAKI,MAAM,CAACD,MAAM,EACzD;QACAa,8BAA8B,IAAIE,kBAAkBlB,KAAKI,MAAM,CAACD,MAAM;IACxE;IACA,OAAOa;AACT;AAEA,SAASG,2BAA2BT,GAAG,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IAEjB,IACE,OAAOU,UAAU,YAChB,OAAOC,YAAY,cAAcD,iBAAiBC,WAClD,OAAOC,QAAQ,cAAcF,iBAAiBE,KAC/C;QACAF,QAAQG,MAAMH;IAChB;IAEA,MAAM,EAAEH,QAAQ,EAAER,MAAM,EAAE,GAAG,MAAMD,KAAK,MAAMY,OAAOV;IAErD3C,OAAOkD,SAASO,OAAO;IACvBL,KAAKM,sBAAsB,GAAGhB;IAE9B,OAAO1C;AACT;AAEA,eAAeoD,KAAI;AAEnB,+DAA+D;AAC/D,OAAO,SAASO;IACd3D,OAAO;IACPC,uBAAuB;IACvBY,uBAAuB;AACzB"}

View File

@@ -0,0 +1,42 @@
export interface EncodeOptions {
quality: number
target_size: number
target_PSNR: number
method: number
sns_strength: number
filter_strength: number
filter_sharpness: number
filter_type: number
partitions: number
segments: number
pass: number
show_compressed: number
preprocessing: number
autofilter: number
partition_limit: number
alpha_compression: number
alpha_filtering: number
alpha_quality: number
lossless: number
exact: number
image_hint: number
emulate_jpeg_size: number
thread_level: number
low_memory: number
near_lossless: number
use_delta_palette: number
use_sharp_yuv: number
}
export interface WebPModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions
): Uint8Array
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<WebPModule>
export default moduleFactory

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long