imagepressor 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/dist/canvas.d.cts +19 -0
- package/dist/canvas.d.ts +14 -1
- package/dist/canvas.d.ts.map +1 -1
- package/dist/index.cjs +52 -13
- package/dist/index.cjs.map +8 -8
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +52 -13
- package/dist/index.js.map +8 -8
- package/dist/jpeg.d.cts +54 -0
- package/dist/jpeg.d.ts +26 -4
- package/dist/jpeg.d.ts.map +1 -1
- package/dist/types.d.cts +40 -0
- package/dist/types.d.ts +0 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.cts +41 -0
- package/dist/utils.d.ts +18 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/webp.d.cts +37 -0
- package/dist/webp.d.ts +1 -1
- package/dist/webp.d.ts.map +1 -1
- package/dist/worker.d.cts +13 -0
- package/dist/worker.d.ts +8 -1
- package/dist/worker.d.ts.map +1 -1
- package/package.json +16 -6
package/dist/jpeg.d.cts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ImageMetadata } from "./types.cjs";
|
|
2
|
+
export type { ImageMetadata } from "./types.cjs";
|
|
3
|
+
export type MetadataEntryKind = "jpeg-app1" | "jpeg-app2" | "webp-exif" | "webp-iccp";
|
|
4
|
+
export interface MetadataEntry {
|
|
5
|
+
kind: MetadataEntryKind;
|
|
6
|
+
/**
|
|
7
|
+
* JPEG entries hold the full APPn segment (marker + length + payload).
|
|
8
|
+
* WebP entries hold the raw chunk payload (no fourCC, no chunk size).
|
|
9
|
+
*/
|
|
10
|
+
bytes: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export interface ExtractedMetadata {
|
|
13
|
+
/** Normalized raw TIFF bytes (orientation set to 1), without APP1 or Exif\0\0. */
|
|
14
|
+
exifTiff?: Uint8Array;
|
|
15
|
+
/** Contiguous raw ICC profile bytes. */
|
|
16
|
+
iccProfile?: Uint8Array;
|
|
17
|
+
/** Extra JPEG APP1/APP2 segments (e.g. XMP, MPF) for JPEG -> JPEG passthrough. */
|
|
18
|
+
extraJpegSegments: Uint8Array[];
|
|
19
|
+
}
|
|
20
|
+
export type IccColorSpaceKind = "srgb" | "display-p3" | "other" | "unknown";
|
|
21
|
+
/**
|
|
22
|
+
* Extracts format-agnostic EXIF TIFF and ICC profile data (plus extra JPEG
|
|
23
|
+
* segments for JPEG -> JPEG) without round-tripping WebP payloads through
|
|
24
|
+
* synthetic JPEG APPn headers.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractImageMetadata(fileOrBlob: Blob): Promise<ExtractedMetadata>;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes extracted metadata into JPEG APP1/APP2 segments for JPEG output.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildJpegMetadataSegments(meta: ExtractedMetadata, includeIcc?: boolean): Uint8Array[];
|
|
31
|
+
/**
|
|
32
|
+
* Inspects an ICC profile's header and 'desc' tag to determine whether it
|
|
33
|
+
* describes sRGB, Display P3, or another color space (e.g. AdobeRGB, CMYK).
|
|
34
|
+
*/
|
|
35
|
+
export declare function detectIccColorSpace(icc: Uint8Array): IccColorSpaceKind;
|
|
36
|
+
/**
|
|
37
|
+
* Extracts raw EXIF (APP1 / RIFF EXIF) and ICC Profile (APP2 / RIFF ICCP)
|
|
38
|
+
* metadata segments from a JPEG or WebP file, normalized to JPEG APP segments.
|
|
39
|
+
* EXIF orientation is normalized to 1 on the returned copy.
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractMetadataSegments(fileOrBlob: Blob): Promise<Uint8Array[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Normalizes the EXIF Orientation tag to 1 (normal / top-left) in place.
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeExifOrientation(segment: Uint8Array): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Injects raw original metadata segments into a canvas-compressed JPEG blob.
|
|
48
|
+
*/
|
|
49
|
+
export declare function spliceMetadataIntoBlob(compressedBlob: Blob, metadataSegments: Uint8Array[]): Promise<Blob>;
|
|
50
|
+
/**
|
|
51
|
+
* Inspects raw JPEG or WebP markers/chunks to extract camera info, orientation, and
|
|
52
|
+
* whether an ICC color profile is embedded.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getImageMetadata(fileOrBlob: Blob): Promise<ImageMetadata>;
|
package/dist/jpeg.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { ImageMetadata } from "./types";
|
|
2
|
-
export type
|
|
3
|
-
export type { ImageMetadata };
|
|
1
|
+
import type { ImageMetadata } from "./types.js";
|
|
2
|
+
export type { ImageMetadata } from "./types.js";
|
|
4
3
|
export type MetadataEntryKind = "jpeg-app1" | "jpeg-app2" | "webp-exif" | "webp-iccp";
|
|
5
4
|
export interface MetadataEntry {
|
|
6
5
|
kind: MetadataEntryKind;
|
|
@@ -10,6 +9,30 @@ export interface MetadataEntry {
|
|
|
10
9
|
*/
|
|
11
10
|
bytes: Uint8Array;
|
|
12
11
|
}
|
|
12
|
+
export interface ExtractedMetadata {
|
|
13
|
+
/** Normalized raw TIFF bytes (orientation set to 1), without APP1 or Exif\0\0. */
|
|
14
|
+
exifTiff?: Uint8Array;
|
|
15
|
+
/** Contiguous raw ICC profile bytes. */
|
|
16
|
+
iccProfile?: Uint8Array;
|
|
17
|
+
/** Extra JPEG APP1/APP2 segments (e.g. XMP, MPF) for JPEG -> JPEG passthrough. */
|
|
18
|
+
extraJpegSegments: Uint8Array[];
|
|
19
|
+
}
|
|
20
|
+
export type IccColorSpaceKind = "srgb" | "display-p3" | "other" | "unknown";
|
|
21
|
+
/**
|
|
22
|
+
* Extracts format-agnostic EXIF TIFF and ICC profile data (plus extra JPEG
|
|
23
|
+
* segments for JPEG -> JPEG) without round-tripping WebP payloads through
|
|
24
|
+
* synthetic JPEG APPn headers.
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractImageMetadata(fileOrBlob: Blob): Promise<ExtractedMetadata>;
|
|
27
|
+
/**
|
|
28
|
+
* Serializes extracted metadata into JPEG APP1/APP2 segments for JPEG output.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildJpegMetadataSegments(meta: ExtractedMetadata, includeIcc?: boolean): Uint8Array[];
|
|
31
|
+
/**
|
|
32
|
+
* Inspects an ICC profile's header and 'desc' tag to determine whether it
|
|
33
|
+
* describes sRGB, Display P3, or another color space (e.g. AdobeRGB, CMYK).
|
|
34
|
+
*/
|
|
35
|
+
export declare function detectIccColorSpace(icc: Uint8Array): IccColorSpaceKind;
|
|
13
36
|
/**
|
|
14
37
|
* Extracts raw EXIF (APP1 / RIFF EXIF) and ICC Profile (APP2 / RIFF ICCP)
|
|
15
38
|
* metadata segments from a JPEG or WebP file, normalized to JPEG APP segments.
|
|
@@ -29,5 +52,4 @@ export declare function spliceMetadataIntoBlob(compressedBlob: Blob, metadataSeg
|
|
|
29
52
|
* whether an ICC color profile is embedded.
|
|
30
53
|
*/
|
|
31
54
|
export declare function getImageMetadata(fileOrBlob: Blob): Promise<ImageMetadata>;
|
|
32
|
-
export declare const getJpegMetadata: typeof getImageMetadata;
|
|
33
55
|
//# sourceMappingURL=jpeg.d.ts.map
|
package/dist/jpeg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../src/jpeg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"jpeg.d.ts","sourceRoot":"","sources":["../src/jpeg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAS7C,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAK7C,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,CAAC;AAChB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB;;;OAGG;IACH,KAAK,EAAE,UAAU,CAAC;CACnB;AACD,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,wCAAwC;IACxC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,kFAAkF;IAClF,iBAAiB,EAAE,UAAU,EAAE,CAAC;CACjC;AACD,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,SAAS,CAAC;AA4M5E;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,IAAI,GACf,OAAO,CAAC,iBAAiB,CAAC,CA2C5B;AACD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,iBAAiB,EACvB,UAAU,UAAO,GAChB,UAAU,EAAE,CAWd;AACD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,GAAG,iBAAiB,CAqDtE;AACD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,IAAI,GACf,OAAO,CAAC,UAAU,EAAE,CAAC,CA4BvB;AACD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAUrE;AACD;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,cAAc,EAAE,IAAI,EACpB,gBAAgB,EAAE,UAAU,EAAE,GAC7B,OAAO,CAAC,IAAI,CAAC,CA8Df;AACD;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,IAAI,GACf,OAAO,CAAC,aAAa,CAAC,CA6BxB"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface CompressOptions {
|
|
2
|
+
/** Target maximum output file size in megabytes (e.g. 1 for 1 MB). If omitted or Infinity, compression is governed by quality and dimensions without a hard megabyte ceiling. */
|
|
3
|
+
maxSizeMB?: number;
|
|
4
|
+
/** Maximum width in pixels. Proportional downscaling preserves aspect ratio. */
|
|
5
|
+
maxWidth?: number;
|
|
6
|
+
/** Maximum height in pixels. Proportional downscaling preserves aspect ratio. */
|
|
7
|
+
maxHeight?: number;
|
|
8
|
+
/** Compression quality between 0.0 and 1.0. Default: 0.85 */
|
|
9
|
+
quality?: number;
|
|
10
|
+
/** Output MIME type. Default: WebP for WebP/PNG inputs, otherwise JPEG (PNG is re-encoded as WebP because PNG has no lossy mode). */
|
|
11
|
+
mimeType?: "image/jpeg" | "image/webp";
|
|
12
|
+
/** Whether to preserve JPEG & WebP EXIF (camera, lens, ISO) and the embedded ICC color profile. Default: true. Metadata preservation is best-effort and never fails a compression. */
|
|
13
|
+
preserveMetadata?: boolean;
|
|
14
|
+
/** Whether to run compression off the main thread in a Web Worker. Default: true */
|
|
15
|
+
useWebWorker?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to output the original image if the compressed result is larger than the original.
|
|
18
|
+
* Default: true for same-format compression; optional for format conversions (e.g. WebP to JPEG).
|
|
19
|
+
* Ignored when `maxSizeMB` is set: the smallest attempt is returned so the requested ceiling wins.
|
|
20
|
+
*/
|
|
21
|
+
strict?: boolean;
|
|
22
|
+
/** AbortSignal to cancel compression. */
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
/** Progress notification callback (progress: 0 to 100, stage: descriptive phase). */
|
|
25
|
+
onProgress?: (progress: number, stage: string) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface CompressionResult {
|
|
28
|
+
blob: Blob;
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
}
|
|
32
|
+
export interface ImageMetadata {
|
|
33
|
+
hasExif: boolean;
|
|
34
|
+
hasIccProfile: boolean;
|
|
35
|
+
orientation?: number;
|
|
36
|
+
make?: string;
|
|
37
|
+
model?: string;
|
|
38
|
+
dateTime?: string;
|
|
39
|
+
colorSpace: string;
|
|
40
|
+
}
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,iLAAiL;IACjL,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qIAAqI;IACrI,QAAQ,CAAC,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,sLAAsL;IACtL,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oFAAoF;IACpF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qFAAqF;IACrF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxD;AACD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,iLAAiL;IACjL,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qIAAqI;IACrI,QAAQ,CAAC,EAAE,YAAY,GAAG,YAAY,CAAC;IACvC,sLAAsL;IACtL,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oFAAoF;IACpF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,qFAAqF;IACrF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxD;AACD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type InputMime = "image/jpeg" | "image/webp" | "image/png";
|
|
2
|
+
export declare const EXIF_PREFIX: readonly [69, 120, 105, 102, 0, 0];
|
|
3
|
+
export declare const ICC_PREFIX: readonly [73, 67, 67, 95, 80, 82, 79, 70, 73, 76, 69, 0];
|
|
4
|
+
export declare function hasBytesAt(bytes: Uint8Array, offset: number, prefix: readonly number[]): boolean;
|
|
5
|
+
export declare function toDataView(bytes: Uint8Array): DataView;
|
|
6
|
+
/**
|
|
7
|
+
* Validates a TIFF header at `tiffStart`. When `requireIfd` is true (default),
|
|
8
|
+
* also verifies the IFD0 offset points within the buffer.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseTiffHeader(view: DataView, tiffStart: number, requireIfd?: boolean): {
|
|
11
|
+
isLittleEndian: boolean;
|
|
12
|
+
ifdStart: number;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare function resolveDefaultMime(inputMime?: string): "image/jpeg" | "image/webp";
|
|
15
|
+
/**
|
|
16
|
+
* Detects the input MIME type from the blob type, falling back to the file name.
|
|
17
|
+
* This is the single rule used by the library and the demo.
|
|
18
|
+
*/
|
|
19
|
+
export declare function detectInputMime(fileOrBlob: File | Blob, fileName?: string): InputMime | undefined;
|
|
20
|
+
export declare function sniffImageContainer(view: DataView): "jpeg" | "webp" | null;
|
|
21
|
+
/**
|
|
22
|
+
* Sniffs the first bytes of a blob to decide whether it is a JPEG or WebP
|
|
23
|
+
* container. Returns null for anything else, so non-image blobs are never
|
|
24
|
+
* walked or reported as "missing EXIF".
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectImageContainer(fileOrBlob: Blob): Promise<"jpeg" | "webp" | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Proportional downscale that honours both positive maxWidth and maxHeight.
|
|
29
|
+
* Shared by the OffscreenCanvas and HTMLCanvasElement paths.
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeTargetSize(width: number, height: number, maxWidth?: number, maxHeight?: number): {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Throws the signal's abort reason when the signal has already been aborted.
|
|
37
|
+
* `AbortSignal.throwIfAborted` is available in Chrome 100+, Firefox 97+,
|
|
38
|
+
* Safari 15.4+, Bun 1.0+, and Deno 1.17+.
|
|
39
|
+
*/
|
|
40
|
+
export declare function assertNotAborted(signal?: AbortSignal): void;
|
|
41
|
+
export declare function abortReason(signal?: AbortSignal): unknown;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
export type InputMime = "image/jpeg" | "image/webp" | "image/png";
|
|
2
|
+
export declare const EXIF_PREFIX: readonly [69, 120, 105, 102, 0, 0];
|
|
3
|
+
export declare const ICC_PREFIX: readonly [73, 67, 67, 95, 80, 82, 79, 70, 73, 76, 69, 0];
|
|
4
|
+
export declare function hasBytesAt(bytes: Uint8Array, offset: number, prefix: readonly number[]): boolean;
|
|
5
|
+
export declare function toDataView(bytes: Uint8Array): DataView;
|
|
6
|
+
/**
|
|
7
|
+
* Validates a TIFF header at `tiffStart`. When `requireIfd` is true (default),
|
|
8
|
+
* also verifies the IFD0 offset points within the buffer.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseTiffHeader(view: DataView, tiffStart: number, requireIfd?: boolean): {
|
|
11
|
+
isLittleEndian: boolean;
|
|
12
|
+
ifdStart: number;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare function resolveDefaultMime(inputMime?: string): "image/jpeg" | "image/webp";
|
|
2
15
|
/**
|
|
3
16
|
* Detects the input MIME type from the blob type, falling back to the file name.
|
|
4
17
|
* This is the single rule used by the library and the demo.
|
|
5
18
|
*/
|
|
6
19
|
export declare function detectInputMime(fileOrBlob: File | Blob, fileName?: string): InputMime | undefined;
|
|
20
|
+
export declare function sniffImageContainer(view: DataView): "jpeg" | "webp" | null;
|
|
7
21
|
/**
|
|
8
22
|
* Sniffs the first bytes of a blob to decide whether it is a JPEG or WebP
|
|
9
23
|
* container. Returns null for anything else, so non-image blobs are never
|
|
@@ -11,7 +25,7 @@ export declare function detectInputMime(fileOrBlob: File | Blob, fileName?: stri
|
|
|
11
25
|
*/
|
|
12
26
|
export declare function detectImageContainer(fileOrBlob: Blob): Promise<"jpeg" | "webp" | null>;
|
|
13
27
|
/**
|
|
14
|
-
* Proportional downscale that honours both maxWidth and maxHeight.
|
|
28
|
+
* Proportional downscale that honours both positive maxWidth and maxHeight.
|
|
15
29
|
* Shared by the OffscreenCanvas and HTMLCanvasElement paths.
|
|
16
30
|
*/
|
|
17
31
|
export declare function computeTargetSize(width: number, height: number, maxWidth?: number, maxHeight?: number): {
|
|
@@ -20,8 +34,9 @@ export declare function computeTargetSize(width: number, height: number, maxWidt
|
|
|
20
34
|
};
|
|
21
35
|
/**
|
|
22
36
|
* Throws the signal's abort reason when the signal has already been aborted.
|
|
23
|
-
* `AbortSignal.throwIfAborted` is available in
|
|
24
|
-
*
|
|
37
|
+
* `AbortSignal.throwIfAborted` is available in Chrome 100+, Firefox 97+,
|
|
38
|
+
* Safari 15.4+, Bun 1.0+, and Deno 1.17+.
|
|
25
39
|
*/
|
|
26
40
|
export declare function assertNotAborted(signal?: AbortSignal): void;
|
|
41
|
+
export declare function abortReason(signal?: AbortSignal): unknown;
|
|
27
42
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;AAClE;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,IAAI,GAAG,IAAI,EACvB,QAAQ,CAAC,EAAE,MAAM,GAChB,SAAS,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,WAAW,CAAC;AAClE,eAAO,MAAM,WAAW,oCAAgD,CAAC;AACzE,eAAO,MAAM,UAAU,0DAEb,CAAC;AACX,wBAAgB,UAAU,CACxB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,MAAM,EAAE,GACxB,OAAO,CAMT;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAEtD;AACD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,EACd,SAAS,EAAE,MAAM,EACjB,UAAU,UAAO,GAChB;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAUtD;AACD,wBAAgB,kBAAkB,CAChC,SAAS,CAAC,EAAE,MAAM,GACjB,YAAY,GAAG,YAAY,CAI7B;AACD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,IAAI,GAAG,IAAI,EACvB,QAAQ,CAAC,EAAE,MAAM,GAChB,SAAS,GAAG,SAAS,CAUvB;AACD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAU1E;AACD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,IAAI,GACf,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAIjC;AACD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAoBnC;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAE3D;AACD,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAEzD"}
|
package/dist/webp.d.cts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const EXIF_FLAG = 8;
|
|
2
|
+
export declare const ALPHA_FLAG = 16;
|
|
3
|
+
export declare const ICCP_FLAG = 32;
|
|
4
|
+
export declare const XMP_FLAG = 4;
|
|
5
|
+
export declare const ANIMATION_FLAG = 2;
|
|
6
|
+
export interface WebPChunk {
|
|
7
|
+
fourCC: string;
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export declare function parseChunks(bytes: Uint8Array): WebPChunk[];
|
|
11
|
+
export declare function getImageDimensions(chunks: WebPChunk[]): {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
alpha: boolean;
|
|
15
|
+
} | null;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a VP8X extended chunk preserving image features.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createVP8X(chunks: WebPChunk[], exif: boolean, icc: boolean, fallbackWidth?: number, fallbackHeight?: number, fallbackAlpha?: boolean): WebPChunk;
|
|
20
|
+
/**
|
|
21
|
+
* Strips JPEG APP1 markers and "Exif\0\0" identifiers, ensuring the EXIF payload
|
|
22
|
+
* begins directly with a valid TIFF header (II or MM) as required by the WebP specification.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeExif(exif: Uint8Array): Uint8Array;
|
|
25
|
+
/**
|
|
26
|
+
* Strips JPEG APP2 markers and "ICC_PROFILE\0" headers to return raw ICC data.
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeIcc(icc: Uint8Array): Uint8Array;
|
|
29
|
+
export declare function serializeChunks(chunks: WebPChunk[]): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* Attaches or replaces EXIF and ICC metadata in a WebP file without re-encoding pixels.
|
|
32
|
+
*/
|
|
33
|
+
export declare function insertWebPExif(webp: Uint8Array, rawExif?: Uint8Array, rawIcc?: Uint8Array, fallbackWidth?: number, fallbackHeight?: number): Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* Splices raw metadata segments (JPEG APP1/APP2) into a canvas-compressed WebP Blob.
|
|
36
|
+
*/
|
|
37
|
+
export declare function spliceWebpMetadata(webpBlob: Blob, metadataSegments: Uint8Array[], width?: number, height?: number): Promise<Blob>;
|
package/dist/webp.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare function getImageDimensions(chunks: WebPChunk[]): {
|
|
|
16
16
|
/**
|
|
17
17
|
* Creates a VP8X extended chunk preserving image features.
|
|
18
18
|
*/
|
|
19
|
-
export declare function createVP8X(chunks: WebPChunk[], exif: boolean, icc: boolean, fallbackWidth?: number, fallbackHeight?: number): WebPChunk;
|
|
19
|
+
export declare function createVP8X(chunks: WebPChunk[], exif: boolean, icc: boolean, fallbackWidth?: number, fallbackHeight?: number, fallbackAlpha?: boolean): WebPChunk;
|
|
20
20
|
/**
|
|
21
21
|
* Strips JPEG APP1 markers and "Exif\0\0" identifiers, ensuring the EXIF payload
|
|
22
22
|
* begins directly with a valid TIFF header (II or MM) as required by the WebP specification.
|
package/dist/webp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webp.d.ts","sourceRoot":"","sources":["../src/webp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webp.d.ts","sourceRoot":"","sources":["../src/webp.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,SAAS,IAAO,CAAC;AAC9B,eAAO,MAAM,UAAU,KAAO,CAAC;AAC/B,eAAO,MAAM,SAAS,KAAO,CAAC;AAC9B,eAAO,MAAM,QAAQ,IAAO,CAAC;AAC7B,eAAO,MAAM,cAAc,IAAO,CAAC;AAGnC,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;CAClB;AAiBD,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,CA8B1D;AACD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,EAAE,GAClB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAmC1D;AACD;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,OAAO,EACZ,aAAa,CAAC,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,UAAQ,GACpB,SAAS,CAqBX;AACD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAY1D;AACD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAWxD;AACD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAyB/D;AACD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,UAAU,EAChB,OAAO,CAAC,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE,UAAU,EACnB,aAAa,CAAC,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,GACtB,UAAU,CAmCZ;AACD;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,IAAI,EACd,gBAAgB,EAAE,UAAU,EAAE,EAC9B,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CAwCf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type CanvasColorSpace, type CompressionSession } from "./canvas.cjs";
|
|
2
|
+
import type { CompressionResult } from "./types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a single-worker encoding session that keeps the worker and decoded
|
|
5
|
+
* `ImageBitmap` alive across `maxSizeMB` retries, falling back transparently
|
|
6
|
+
* to main-thread execution if `blob:` workers are unavailable or CSP-blocked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createWorkerEncoder(blob: Blob, colorSpace?: CanvasColorSpace): CompressionSession;
|
|
9
|
+
/**
|
|
10
|
+
* Runs image compression off the main thread in a Web Worker using createImageBitmap + OffscreenCanvas.
|
|
11
|
+
* If Web Workers or OffscreenCanvas are blocked or unavailable, automatically falls back to main-thread processing.
|
|
12
|
+
*/
|
|
13
|
+
export declare function compressWithWorker(blob: Blob, maxWidth: number | undefined, maxHeight: number | undefined, quality: number, mimeType: string, signal?: AbortSignal): Promise<CompressionResult>;
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CanvasColorSpace, type CompressionSession } from "./canvas.js";
|
|
2
|
+
import type { CompressionResult } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a single-worker encoding session that keeps the worker and decoded
|
|
5
|
+
* `ImageBitmap` alive across `maxSizeMB` retries, falling back transparently
|
|
6
|
+
* to main-thread execution if `blob:` workers are unavailable or CSP-blocked.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createWorkerEncoder(blob: Blob, colorSpace?: CanvasColorSpace): CompressionSession;
|
|
2
9
|
/**
|
|
3
10
|
* Runs image compression off the main thread in a Web Worker using createImageBitmap + OffscreenCanvas.
|
|
4
11
|
* If Web Workers or OffscreenCanvas are blocked or unavailable, automatically falls back to main-thread processing.
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAGxB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAkEjD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,EACV,UAAU,CAAC,EAAE,gBAAgB,GAC5B,kBAAkB,CA8IpB;AACD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAc5B"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imagepressor",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "High-performance, zero-dependency, client-side image compression library that runs off the main thread in a Web Worker, preserving camera EXIF metadata and Display P3 color profiles.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"main": "./dist/index.cjs",
|
|
6
8
|
"module": "./dist/index.js",
|
|
7
9
|
"types": "./dist/index.d.ts",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
},
|
|
15
22
|
"files": [
|
|
@@ -19,7 +26,9 @@
|
|
|
19
26
|
],
|
|
20
27
|
"scripts": {
|
|
21
28
|
"build": "bun run build.ts",
|
|
22
|
-
"test": "bun test"
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"lint": "oxlint src tests build.ts"
|
|
23
32
|
},
|
|
24
33
|
"keywords": [
|
|
25
34
|
"imagepressor",
|
|
@@ -49,7 +58,8 @@
|
|
|
49
58
|
"url": "https://github.com/ijaik/imagepressor/issues"
|
|
50
59
|
},
|
|
51
60
|
"devDependencies": {
|
|
52
|
-
"@types/bun": "1.4.
|
|
61
|
+
"@types/bun": "^1.4.5",
|
|
62
|
+
"oxlint": "^1.90.0",
|
|
53
63
|
"typescript": "5.9.3"
|
|
54
64
|
}
|
|
55
65
|
}
|