tempest-react-sdk 0.31.1 → 0.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +2 -0
  2. package/bin/lib/design/collect.mjs +103 -0
  3. package/bin/lib/design/findings.mjs +70 -0
  4. package/bin/lib/design/functions.mjs +188 -0
  5. package/bin/lib/design/functions.test.mjs +127 -0
  6. package/bin/lib/design/index.mjs +80 -0
  7. package/bin/lib/design/index.test.mjs +129 -0
  8. package/bin/lib/design/markers.mjs +76 -0
  9. package/bin/lib/design/markers.test.mjs +60 -0
  10. package/bin/lib/design/mask.mjs +209 -0
  11. package/bin/lib/design/mask.test.mjs +69 -0
  12. package/bin/lib/design/scan.mjs +229 -0
  13. package/bin/lib/design/scan.test.mjs +218 -0
  14. package/bin/lib/doctor/doctor.e2e.test.mjs +79 -2
  15. package/bin/tempest.mjs +83 -3
  16. package/dist/imaging/canvas.cjs +2 -0
  17. package/dist/imaging/canvas.cjs.map +1 -0
  18. package/dist/imaging/canvas.js +23 -0
  19. package/dist/imaging/canvas.js.map +1 -0
  20. package/dist/imaging/compress.cjs +2 -0
  21. package/dist/imaging/compress.cjs.map +1 -0
  22. package/dist/imaging/compress.js +43 -0
  23. package/dist/imaging/compress.js.map +1 -0
  24. package/dist/imaging/decode.cjs +2 -0
  25. package/dist/imaging/decode.cjs.map +1 -0
  26. package/dist/imaging/decode.js +42 -0
  27. package/dist/imaging/decode.js.map +1 -0
  28. package/dist/imaging/encode.cjs +2 -0
  29. package/dist/imaging/encode.cjs.map +1 -0
  30. package/dist/imaging/encode.js +48 -0
  31. package/dist/imaging/encode.js.map +1 -0
  32. package/dist/imaging/exceptions.cjs +2 -0
  33. package/dist/imaging/exceptions.cjs.map +1 -0
  34. package/dist/imaging/exceptions.js +26 -0
  35. package/dist/imaging/exceptions.js.map +1 -0
  36. package/dist/imaging/thumbnails.cjs +2 -0
  37. package/dist/imaging/thumbnails.cjs.map +1 -0
  38. package/dist/imaging/thumbnails.js +34 -0
  39. package/dist/imaging/thumbnails.js.map +1 -0
  40. package/dist/imaging/transform.cjs +2 -0
  41. package/dist/imaging/transform.cjs.map +1 -0
  42. package/dist/imaging/transform.js +97 -0
  43. package/dist/imaging/transform.js.map +1 -0
  44. package/dist/imaging/use-image-processing.cjs +2 -0
  45. package/dist/imaging/use-image-processing.cjs.map +1 -0
  46. package/dist/imaging/use-image-processing.js +45 -0
  47. package/dist/imaging/use-image-processing.js.map +1 -0
  48. package/dist/imaging.cjs +1 -0
  49. package/dist/imaging.d.ts +541 -0
  50. package/dist/imaging.js +9 -0
  51. package/dist/tabular/assets.cjs +2 -0
  52. package/dist/tabular/assets.cjs.map +1 -0
  53. package/dist/tabular/assets.js +19 -0
  54. package/dist/tabular/assets.js.map +1 -0
  55. package/dist/tabular/cache.cjs +2 -0
  56. package/dist/tabular/cache.cjs.map +1 -0
  57. package/dist/tabular/cache.js +48 -0
  58. package/dist/tabular/cache.js.map +1 -0
  59. package/dist/tabular/exceptions.cjs +2 -0
  60. package/dist/tabular/exceptions.cjs.map +1 -0
  61. package/dist/tabular/exceptions.js +30 -0
  62. package/dist/tabular/exceptions.js.map +1 -0
  63. package/dist/tabular/manifest.cjs +2 -0
  64. package/dist/tabular/manifest.cjs.map +1 -0
  65. package/dist/tabular/manifest.js +42 -0
  66. package/dist/tabular/manifest.js.map +1 -0
  67. package/dist/tabular/predictor.cjs +2 -0
  68. package/dist/tabular/predictor.cjs.map +1 -0
  69. package/dist/tabular/predictor.js +111 -0
  70. package/dist/tabular/predictor.js.map +1 -0
  71. package/dist/tabular/use-tabular-predictor.cjs +2 -0
  72. package/dist/tabular/use-tabular-predictor.cjs.map +1 -0
  73. package/dist/tabular/use-tabular-predictor.js +51 -0
  74. package/dist/tabular/use-tabular-predictor.js.map +1 -0
  75. package/dist/tabular.cjs +1 -0
  76. package/dist/tabular.d.ts +509 -0
  77. package/dist/tabular.js +7 -0
  78. package/package.json +11 -1
@@ -0,0 +1,45 @@
1
+ import { resizeImage as e } from "./transform.js";
2
+ import { compressToTarget as t } from "./compress.js";
3
+ import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
4
+ //#region src/imaging/use-image-processing.ts
5
+ function o(e) {
6
+ let [t, n] = a(null);
7
+ return r(() => {
8
+ if (e == null) {
9
+ n(null);
10
+ return;
11
+ }
12
+ let t = URL.createObjectURL(e);
13
+ return n(t), () => {
14
+ URL.revokeObjectURL(t);
15
+ };
16
+ }, [e]), { url: t };
17
+ }
18
+ function s() {
19
+ let [o, s] = a(null), [c, l] = a("idle"), [u, d] = a(null), f = i(!0);
20
+ r(() => (f.current = !0, () => {
21
+ f.current = !1;
22
+ }), []);
23
+ let p = n(async (e) => {
24
+ f.current && (l("working"), d(null));
25
+ try {
26
+ let t = await e();
27
+ return f.current && (s(t), l("done")), t;
28
+ } catch (e) {
29
+ let t = e instanceof Error ? e : Error(String(e));
30
+ throw f.current && (d(t), l("error")), t;
31
+ }
32
+ }, []);
33
+ return {
34
+ resize: n((t, n = {}) => p(() => e(t, n)), [p]),
35
+ compress: n((e, n) => p(() => t(e, n)), [p]),
36
+ result: o,
37
+ status: c,
38
+ error: u,
39
+ isWorking: c === "working"
40
+ };
41
+ }
42
+ //#endregion
43
+ export { o as useImagePreview, s as useImageProcessing };
44
+
45
+ //# sourceMappingURL=use-image-processing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-image-processing.js","names":[],"sources":["../../src/imaging/use-image-processing.ts"],"sourcesContent":["/**\n * React bindings for image work.\n *\n * Two things components get wrong every time: they leak object URLs (an\n * `URL.createObjectURL` without its `revokeObjectURL` holds the whole blob\n * in memory for the page's lifetime), and they set state after unmounting\n * when a slow resize finishes late. Both live here instead of in each\n * component.\n */\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\n\nimport { compressToTarget, type CompressedImage } from \"./compress\";\nimport type { CompressOptions, ImageSource, ProcessedImage, ResizeOptions } from \"./types\";\nimport { resizeImage } from \"./transform\";\n\n/** What {@link useImagePreview} returns. */\nexport interface UseImagePreviewResult {\n /** Object URL for the current source, or `null`. */\n readonly url: string | null;\n}\n\n/**\n * Hold an object URL for a blob, and revoke it when it is replaced.\n *\n * @example\n * ```tsx\n * function Preview({ file }: { file: File | null }) {\n * const { url } = useImagePreview(file);\n * return url === null ? null : <img src={url} alt=\"\" />;\n * }\n * ```\n *\n * @param source The blob to preview, or `null`.\n * @returns The object URL, valid until the source changes or the component\n * unmounts.\n */\nexport function useImagePreview(source: Blob | null | undefined): UseImagePreviewResult {\n const [url, setUrl] = useState<string | null>(null);\n\n useEffect(() => {\n if (source === null || source === undefined) {\n setUrl(null);\n return;\n }\n const created = URL.createObjectURL(source);\n setUrl(created);\n return () => {\n URL.revokeObjectURL(created);\n };\n }, [source]);\n\n return { url };\n}\n\n/** Lifecycle of a processing call. */\nexport type ImageProcessingStatus = \"idle\" | \"working\" | \"done\" | \"error\";\n\n/** What {@link useImageProcessing} returns. */\nexport interface UseImageProcessingResult {\n /** Resize (and re-encode) an image. */\n readonly resize: (source: ImageSource, options?: ResizeOptions) => Promise<ProcessedImage>;\n /** Compress an image into a byte budget. */\n readonly compress: (source: ImageSource, options: CompressOptions) => Promise<CompressedImage>;\n /** The most recent result. */\n readonly result: ProcessedImage | null;\n /** Where the last call is. */\n readonly status: ImageProcessingStatus;\n /** Why the last call failed. */\n readonly error: Error | null;\n /** Whether a call is in flight. */\n readonly isWorking: boolean;\n}\n\n/**\n * Run image operations with status tracking, safe against unmount.\n *\n * @example\n * ```tsx\n * function Upload() {\n * const { compress, isWorking, result } = useImageProcessing();\n *\n * async function onPick(file: File) {\n * const ready = await compress(file, { maxBytes: 1_000_000, width: 1600 });\n * await fetch(\"/api/photos\", { method: \"POST\", body: ready.blob });\n * }\n *\n * return <input type=\"file\" disabled={isWorking} onChange={(e) => onPick(e.target.files![0]!)} />;\n * }\n * ```\n *\n * The returned promises still reject on failure, so a caller can `try`\n * around them; `status` and `error` exist for rendering, not for swallowing\n * the failure.\n *\n * @returns The operations plus their state.\n */\nexport function useImageProcessing(): UseImageProcessingResult {\n const [result, setResult] = useState<ProcessedImage | null>(null);\n const [status, setStatus] = useState<ImageProcessingStatus>(\"idle\");\n const [error, setError] = useState<Error | null>(null);\n const mounted = useRef(true);\n\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const run = useCallback(\n async <T extends ProcessedImage>(work: () => Promise<T>): Promise<T> => {\n if (mounted.current) {\n setStatus(\"working\");\n setError(null);\n }\n try {\n const produced = await work();\n if (mounted.current) {\n setResult(produced);\n setStatus(\"done\");\n }\n return produced;\n } catch (caught) {\n const failure = caught instanceof Error ? caught : new Error(String(caught));\n if (mounted.current) {\n setError(failure);\n setStatus(\"error\");\n }\n throw failure;\n }\n },\n [],\n );\n\n const resize = useCallback(\n (source: ImageSource, options: ResizeOptions = {}) =>\n run(() => resizeImage(source, options)),\n [run],\n );\n\n const compress = useCallback(\n (source: ImageSource, options: CompressOptions) =>\n run(() => compressToTarget(source, options)),\n [run],\n );\n\n return {\n resize,\n compress,\n result,\n status,\n error,\n isWorking: status === \"working\",\n };\n}\n"],"mappings":";;;;AAqCA,SAAgB,EAAgB,GAAwD;CACpF,IAAM,CAAC,GAAK,KAAU,EAAwB,IAAI;CAclD,OAZA,QAAgB;EACZ,IAAI,KAAW,MAA8B;GACzC,EAAO,IAAI;GACX;EACJ;EACA,IAAM,IAAU,IAAI,gBAAgB,CAAM;EAE1C,OADA,EAAO,CAAO,SACD;GACT,IAAI,gBAAgB,CAAO;EAC/B;CACJ,GAAG,CAAC,CAAM,CAAC,GAEJ,EAAE,OAAI;AACjB;AA4CA,SAAgB,IAA+C;CAC3D,IAAM,CAAC,GAAQ,KAAa,EAAgC,IAAI,GAC1D,CAAC,GAAQ,KAAa,EAAgC,MAAM,GAC5D,CAAC,GAAO,KAAY,EAAuB,IAAI,GAC/C,IAAU,EAAO,EAAI;CAE3B,SACI,EAAQ,UAAU,UACL;EACT,EAAQ,UAAU;CACtB,IACD,CAAC,CAAC;CAEL,IAAM,IAAM,EACR,OAAiC,MAAuC;EACpE,AAAI,EAAQ,YACR,EAAU,SAAS,GACnB,EAAS,IAAI;EAEjB,IAAI;GACA,IAAM,IAAW,MAAM,EAAK;GAK5B,OAJI,EAAQ,YACR,EAAU,CAAQ,GAClB,EAAU,MAAM,IAEb;EACX,SAAS,GAAQ;GACb,IAAM,IAAU,aAAkB,QAAQ,IAAa,MAAM,OAAO,CAAM,CAAC;GAK3E,MAJI,EAAQ,YACR,EAAS,CAAO,GAChB,EAAU,OAAO,IAEf;EACV;CACJ,GACA,CAAC,CACL;CAcA,OAAO;EACH,QAbW,GACV,GAAqB,IAAyB,CAAC,MAC5C,QAAU,EAAY,GAAQ,CAAO,CAAC,GAC1C,CAAC,CAAG,CAUJ;EACA,UARa,GACZ,GAAqB,MAClB,QAAU,EAAiB,GAAQ,CAAO,CAAC,GAC/C,CAAC,CAAG,CAKJ;EACA;EACA;EACA;EACA,WAAW,MAAW;CAC1B;AACJ"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./imaging/exceptions.cjs"),t=require("./imaging/canvas.cjs"),n=require("./imaging/decode.cjs"),r=require("./imaging/encode.cjs"),i=require("./imaging/transform.cjs"),a=require("./imaging/compress.cjs"),o=require("./imaging/thumbnails.cjs"),s=require("./imaging/use-image-processing.cjs");exports.DEFAULT_BACKGROUND=i.DEFAULT_BACKGROUND,exports.DEFAULT_COMPRESS_STEPS=a.DEFAULT_COMPRESS_STEPS,exports.DEFAULT_MAX_QUALITY=a.DEFAULT_MAX_QUALITY,exports.DEFAULT_MIN_QUALITY=a.DEFAULT_MIN_QUALITY,exports.DEFAULT_QUALITY=r.DEFAULT_QUALITY,exports.DEFAULT_TYPE=r.DEFAULT_TYPE,exports.ImageDecodeError=e.ImageDecodeError,exports.ImageEncodeError=e.ImageEncodeError,exports.ImagingError=e.ImagingError,exports.ImagingUnavailableError=e.ImagingUnavailableError,exports.UnsupportedImageTypeError=e.UnsupportedImageTypeError,exports.bestSupportedType=r.bestSupportedType,exports.compressToTarget=a.compressToTarget,exports.createSurface=t.createSurface,exports.createThumbnails=o.createThumbnails,exports.cropImage=i.cropImage,exports.decodeImage=n.decodeImage,exports.drawScaled=t.drawScaled,exports.encodeImage=r.encodeImage,exports.flipImage=i.flipImage,exports.getContext=t.getContext,exports.readImageInfo=n.readImageInfo,exports.resetImageTypeSupportCache=r.resetImageTypeSupportCache,exports.resizeImage=i.resizeImage,exports.rotateImage=i.rotateImage,exports.supportsImageType=r.supportsImageType,exports.useImagePreview=s.useImagePreview,exports.useImageProcessing=s.useImageProcessing;
@@ -0,0 +1,541 @@
1
+ /**
2
+ * Pick the smallest format this browser can actually produce.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const type = await bestSupportedType(["image/avif", "image/webp", "image/jpeg"]);
7
+ * ```
8
+ *
9
+ * @param preferences Formats in preference order.
10
+ * @returns The first supported one, falling back to `image/jpeg`, which
11
+ * every canvas implementation encodes.
12
+ */
13
+ export declare function bestSupportedType(preferences?: readonly ImageType[]): Promise<ImageType>;
14
+
15
+ /** What {@link compressToTarget} produced. */
16
+ export declare interface CompressedImage extends ProcessedImage {
17
+ /** The quality it settled on. */
18
+ readonly quality: number;
19
+ /** How many encodes it took. */
20
+ readonly attempts: number;
21
+ /**
22
+ * Whether the result actually fits the budget.
23
+ *
24
+ * `false` means the image could not reach it even at `minQuality` —
25
+ * reported rather than thrown, because a 2.1 MB result against a 2 MB
26
+ * budget is usually still worth uploading, and that call is the
27
+ * caller's.
28
+ */
29
+ readonly withinBudget: boolean;
30
+ }
31
+
32
+ /** Options for {@link compressToTarget}. */
33
+ export declare interface CompressOptions extends ResizeOptions {
34
+ /** Byte budget the result must fit in. */
35
+ readonly maxBytes: number;
36
+ /** Lowest quality worth producing. Defaults to `0.4`. */
37
+ readonly minQuality?: number;
38
+ /** Highest quality to start from. Defaults to `0.92`. */
39
+ readonly maxQuality?: number;
40
+ /** Search steps. Defaults to `6`, which resolves quality to ~1%. */
41
+ readonly steps?: number;
42
+ }
43
+
44
+ /**
45
+ * Compress an image until it fits a byte budget.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const upload = await compressToTarget(file, {
50
+ * maxBytes: 2 * 1024 * 1024,
51
+ * width: 2000,
52
+ * type: "image/webp",
53
+ * });
54
+ *
55
+ * if (!upload.withinBudget) {
56
+ * console.warn(`still ${upload.bytes} bytes at quality ${upload.quality}`);
57
+ * }
58
+ * ```
59
+ *
60
+ * Resizing first is what usually does the work: halving the long edge
61
+ * removes three quarters of the pixels, which no quality setting matches.
62
+ * Pass `width`/`height` when the source is a full-resolution photo.
63
+ *
64
+ * @param source Anything decodable.
65
+ * @param options Byte budget plus the usual resize and format options.
66
+ * @returns The best result found, and whether it fits.
67
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
68
+ */
69
+ export declare function compressToTarget(source: ImageSource, options: CompressOptions): Promise<CompressedImage>;
70
+
71
+ /**
72
+ * Create a drawing surface, preferring `OffscreenCanvas`.
73
+ *
74
+ * `OffscreenCanvas` works inside a worker, which is where a PWA wants this
75
+ * running: resizing a 12-megapixel photo on the main thread blocks the UI
76
+ * for tens of milliseconds per image.
77
+ *
78
+ * @param width Surface width in pixels.
79
+ * @param height Surface height in pixels.
80
+ * @returns The surface.
81
+ * @throws {@link ImagingUnavailableError} when neither kind exists — a
82
+ * server render, or a test environment without a canvas.
83
+ */
84
+ export declare function createSurface(width: number, height: number): Surface;
85
+
86
+ /**
87
+ * Produce several sizes from a single decode.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const [thumb, card] = await createThumbnails(file, [
92
+ * { name: "thumb", size: 96 },
93
+ * { name: "card", size: 480 },
94
+ * ]);
95
+ * ```
96
+ *
97
+ * Sizes are the **longest edge**, and the aspect ratio is kept, so a
98
+ * portrait and a landscape photo both fit the same grid cell without a
99
+ * separate calculation per orientation.
100
+ *
101
+ * @param source Anything decodable.
102
+ * @param specs The sizes to produce.
103
+ * @param options Shared format and quality.
104
+ * @returns One result per spec, in the order requested.
105
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
106
+ */
107
+ export declare function createThumbnails(source: ImageSource, specs: readonly ThumbnailSpec[], options?: EncodeOptions): Promise<Thumbnail[]>;
108
+
109
+ /**
110
+ * Crop a rectangle out of an image, in source pixels.
111
+ *
112
+ * The rectangle is clamped to the image, so a crop dragged past the edge
113
+ * produces a smaller result instead of transparent padding.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const badge = await cropImage(file, { x: 120, y: 80, width: 400, height: 400 });
118
+ * ```
119
+ *
120
+ * @param source Anything decodable.
121
+ * @param rect The region to keep.
122
+ * @param options Format and quality.
123
+ * @returns The encoded crop.
124
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
125
+ */
126
+ export declare function cropImage(source: ImageSource, rect: CropRect, options?: EncodeOptions): Promise<ProcessedImage>;
127
+
128
+ /** A rectangle in source pixels. */
129
+ export declare interface CropRect {
130
+ readonly x: number;
131
+ readonly y: number;
132
+ readonly width: number;
133
+ readonly height: number;
134
+ }
135
+
136
+ /** A decoded image, ready to draw. */
137
+ export declare interface DecodedImage {
138
+ /** The pixels. */
139
+ readonly bitmap: ImageBitmap;
140
+ /** Width in pixels, after orientation was applied. */
141
+ readonly width: number;
142
+ /** Height in pixels, after orientation was applied. */
143
+ readonly height: number;
144
+ }
145
+
146
+ /**
147
+ * Decode any supported source into a bitmap, oriented as the photographer
148
+ * held the camera.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * const { bitmap, width, height } = await decodeImage(file);
153
+ * ```
154
+ *
155
+ * @param source A `Blob`/`File`, URL string, `ImageBitmap`, `ImageData`,
156
+ * `HTMLImageElement`, or a canvas.
157
+ * @returns The decoded pixels and their dimensions.
158
+ * @throws {@link ImageDecodeError} when the bytes are not a decodable image,
159
+ * or the URL cannot be fetched.
160
+ */
161
+ export declare function decodeImage(source: ImageSource): Promise<DecodedImage>;
162
+
163
+ /** Background used when a format cannot carry transparency. */
164
+ export declare const DEFAULT_BACKGROUND = "#ffffff";
165
+
166
+ /** Search steps when the caller does not choose. */
167
+ export declare const DEFAULT_COMPRESS_STEPS = 6;
168
+
169
+ /** Highest quality to start from by default. */
170
+ export declare const DEFAULT_MAX_QUALITY = 0.92;
171
+
172
+ /** Lowest quality worth producing by default. */
173
+ export declare const DEFAULT_MIN_QUALITY = 0.4;
174
+
175
+ /** Quality used when the caller does not choose. */
176
+ export declare const DEFAULT_QUALITY = 0.85;
177
+
178
+ /** Format used when the caller does not choose. */
179
+ export declare const DEFAULT_TYPE: ImageType;
180
+
181
+ /**
182
+ * Draw a bitmap into a surface with high-quality filtering.
183
+ *
184
+ * @param bitmap The source pixels.
185
+ * @param target Destination surface.
186
+ * @param box Where to draw inside the destination.
187
+ * @param background Fill painted before drawing.
188
+ */
189
+ export declare function drawScaled(bitmap: ImageBitmap, target: Surface, box: {
190
+ x: number;
191
+ y: number;
192
+ width: number;
193
+ height: number;
194
+ }, background?: string): void;
195
+
196
+ /**
197
+ * Encode a surface into image bytes.
198
+ *
199
+ * @param surface The canvas to encode.
200
+ * @param options Format and quality.
201
+ * @returns The blob plus the dimensions and the type actually produced.
202
+ * @throws {@link ImageEncodeError} when the canvas produces nothing.
203
+ */
204
+ export declare function encodeImage(surface: Surface, options?: EncodeOptions): Promise<ProcessedImage>;
205
+
206
+ /** Options for {@link encodeImage}. */
207
+ export declare interface EncodeOptions {
208
+ /** Output format. Defaults to `image/jpeg`. */
209
+ readonly type?: ImageType;
210
+ /** Quality for lossy formats, `0`-`1`. Defaults to `0.85`. */
211
+ readonly quality?: number;
212
+ }
213
+
214
+ /**
215
+ * Mirror an image horizontally, vertically, or both.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * const selfie = await flipImage(capture, { horizontal: true });
220
+ * ```
221
+ *
222
+ * @param source Anything decodable.
223
+ * @param axes Which axes to mirror.
224
+ * @param options Format and quality.
225
+ * @returns The flipped image.
226
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
227
+ */
228
+ export declare function flipImage(source: ImageSource, axes: {
229
+ horizontal?: boolean;
230
+ vertical?: boolean;
231
+ }, options?: EncodeOptions): Promise<ProcessedImage>;
232
+
233
+ /**
234
+ * Get a 2-D context configured for image work.
235
+ *
236
+ * `imageSmoothingQuality = "high"` is the setting that makes a steep
237
+ * downscale average its source pixels instead of sampling them sparsely.
238
+ *
239
+ * @param surface The surface to draw on.
240
+ * @param background Optional fill painted before anything else.
241
+ * @returns The context.
242
+ * @throws {@link ImagingUnavailableError} when the context cannot be created.
243
+ */
244
+ export declare function getContext(surface: Surface, background?: string): SurfaceContext;
245
+
246
+ /** The source could not be decoded into pixels. */
247
+ export declare class ImageDecodeError extends ImagingError {
248
+ constructor(message: string, options?: ErrorOptions);
249
+ }
250
+
251
+ /** The canvas could not produce encoded bytes. */
252
+ export declare class ImageEncodeError extends ImagingError {
253
+ constructor(message: string, options?: ErrorOptions);
254
+ }
255
+
256
+ /** What a file holds, without decoding all of it. */
257
+ export declare interface ImageInfo {
258
+ readonly width: number;
259
+ readonly height: number;
260
+ /** MIME type as reported by the blob. */
261
+ readonly type: string;
262
+ /** Size in bytes. */
263
+ readonly bytes: number;
264
+ /** `width / height`. */
265
+ readonly aspectRatio: number;
266
+ }
267
+
268
+ /** Lifecycle of a processing call. */
269
+ export declare type ImageProcessingStatus = "idle" | "working" | "done" | "error";
270
+
271
+ /**
272
+ * Types for browser-side image processing.
273
+ */
274
+ /** Anything the module can decode. */
275
+ export declare type ImageSource = Blob | File | ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | string;
276
+
277
+ /** Encodable image formats. */
278
+ export declare type ImageType = "image/jpeg" | "image/png" | "image/webp" | "image/avif";
279
+
280
+ /**
281
+ * Errors thrown by the imaging module.
282
+ *
283
+ * `name` is a literal string on every subclass: minifiers rename classes,
284
+ * and a derived `new.target.name` ships as `error.name === "t"`.
285
+ */
286
+ /** Base class for every error this module throws. */
287
+ export declare class ImagingError extends Error {
288
+ constructor(message: string, options?: ErrorOptions);
289
+ }
290
+
291
+ /** The environment has no canvas to draw on. */
292
+ export declare class ImagingUnavailableError extends ImagingError {
293
+ constructor(message: string, options?: ErrorOptions);
294
+ }
295
+
296
+ /** The result of an operation that produced an encoded image. */
297
+ export declare interface ProcessedImage {
298
+ /** The encoded bytes. */
299
+ readonly blob: Blob;
300
+ /** Output width. */
301
+ readonly width: number;
302
+ /** Output height. */
303
+ readonly height: number;
304
+ /** Output format actually produced — not necessarily the one asked for. */
305
+ readonly type: string;
306
+ /** Size in bytes. */
307
+ readonly bytes: number;
308
+ }
309
+
310
+ /**
311
+ * Read an image's dimensions, type and size.
312
+ *
313
+ * Decodes to measure, which is the only reliable way in a browser — there
314
+ * is no header parser here, and guessing dimensions from a MIME type is not
315
+ * a thing. Cheap enough for a preview, not for a thousand files in a loop.
316
+ *
317
+ * @example
318
+ * ```ts
319
+ * const info = await readImageInfo(file);
320
+ * if (info.bytes > 5_000_000) {
321
+ * // ask before uploading
322
+ * }
323
+ * ```
324
+ *
325
+ * @param blob The image file.
326
+ * @returns Its dimensions, MIME type, byte size and aspect ratio.
327
+ * @throws {@link ImageDecodeError} when the blob is not a decodable image.
328
+ */
329
+ export declare function readImageInfo(blob: Blob): Promise<ImageInfo>;
330
+
331
+ /**
332
+ * Clear the format-support cache.
333
+ *
334
+ * Only useful in tests: browser support does not change at runtime.
335
+ */
336
+ export declare function resetImageTypeSupportCache(): void;
337
+
338
+ /**
339
+ * How a resize fits the requested box.
340
+ *
341
+ * - `contain`: the whole image fits inside the box; the result may be
342
+ * smaller than the box in one dimension.
343
+ * - `cover`: the box is filled; the overflow is cropped, centred.
344
+ * - `fill`: the image is stretched to the box, changing its aspect ratio.
345
+ * - `pad`: like `contain`, but the result is exactly the box, with the
346
+ * remainder painted in `background`.
347
+ */
348
+ export declare type ResizeFit = "contain" | "cover" | "fill" | "pad";
349
+
350
+ /**
351
+ * Resize an image, re-encoding it.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * const resized = await resizeImage(file, { width: 1600, type: "image/webp" });
356
+ * console.log(resized.width, resized.bytes, resized.type);
357
+ * ```
358
+ *
359
+ * @param source Anything decodable.
360
+ * @param options Target box, fit, format and quality.
361
+ * @returns The encoded result.
362
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
363
+ * @throws {@link ImageEncodeError} when the canvas produces no bytes.
364
+ */
365
+ export declare function resizeImage(source: ImageSource, options?: ResizeOptions): Promise<ProcessedImage>;
366
+
367
+ /** Options for {@link resizeImage}. */
368
+ export declare interface ResizeOptions extends EncodeOptions {
369
+ /** Target width in pixels. */
370
+ readonly width?: number;
371
+ /** Target height in pixels. */
372
+ readonly height?: number;
373
+ /** How the image fits the box. Defaults to `contain`. */
374
+ readonly fit?: ResizeFit;
375
+ /** Fill colour for `pad`, and behind transparency when encoding JPEG. */
376
+ readonly background?: string;
377
+ /**
378
+ * Never scale an image up.
379
+ *
380
+ * On by default: enlarging a photo adds no detail and multiplies the
381
+ * bytes, which is the opposite of what a resize is usually for.
382
+ */
383
+ readonly withoutEnlargement?: boolean;
384
+ }
385
+
386
+ /**
387
+ * Rotate an image by a multiple of 90 degrees.
388
+ *
389
+ * Restricted to right angles on purpose: an arbitrary angle needs a
390
+ * decision about the corners (crop, pad, or grow the canvas) that belongs
391
+ * to the caller's design, not to a utility default.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * const upright = await rotateImage(file, 90);
396
+ * ```
397
+ *
398
+ * @param source Anything decodable.
399
+ * @param degrees `90`, `180`, `270` — or any multiple, normalised.
400
+ * @param options Format and quality.
401
+ * @returns The rotated image.
402
+ * @throws {@link ImageDecodeError} when the source cannot be decoded.
403
+ * @throws {@link RangeError} when the angle is not a multiple of 90.
404
+ */
405
+ export declare function rotateImage(source: ImageSource, degrees: number, options?: EncodeOptions): Promise<ProcessedImage>;
406
+
407
+ /**
408
+ * Whether this browser can actually encode a format.
409
+ *
410
+ * Asks for a 1x1 image in that type and checks what came back, because
411
+ * that is the only answer that counts: a browser that "supports" WebP for
412
+ * display may still not encode it.
413
+ *
414
+ * @example
415
+ * ```ts
416
+ * const type = (await supportsImageType("image/webp")) ? "image/webp" : "image/jpeg";
417
+ * const resized = await resizeImage(file, { width: 1200, type });
418
+ * ```
419
+ *
420
+ * @param type The format to test.
421
+ * @returns Whether encoding produces that type. Cached per type.
422
+ */
423
+ export declare function supportsImageType(type: ImageType): Promise<boolean>;
424
+
425
+ /**
426
+ * The drawing surface, and the one thing everyone gets wrong on it.
427
+ *
428
+ * **JPEG has no alpha.** Encoding a transparent PNG as JPEG paints the
429
+ * transparent pixels black. Filling the surface first is the difference
430
+ * between a photo on a white background and one with a black hole in it.
431
+ *
432
+ * What is *not* here is worth recording. The received wisdom for downscaling
433
+ * on a canvas is to halve repeatedly, because a single `drawImage` into a
434
+ * much smaller box was said to alias. That was implemented here, and then
435
+ * measured: on a 512 px checkerboard reduced to 32 px, the stepwise result
436
+ * and the single high-quality draw were **pixel-identical** (standard
437
+ * deviation 0.0 on both) in Chromium and Firefox — while stepwise cost
438
+ * **39.19 ms against 0.13 ms** on a 4000x3000 photo, 300 times more, and
439
+ * allocated three intermediate canvases on a device that may not have the
440
+ * memory. Modern engines honour `imageSmoothingQuality = "high"`, which is
441
+ * what this module sets. The halving was deleted rather than kept "just in
442
+ * case": unmeasurable benefit at 300x the cost is not insurance, it is
443
+ * ballast.
444
+ */
445
+ /** A canvas this module can draw on, on the main thread or in a worker. */
446
+ export declare type Surface = OffscreenCanvas | HTMLCanvasElement;
447
+
448
+ /** A 2-D context from either surface kind. */
449
+ export declare type SurfaceContext = OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;
450
+
451
+ /** A produced thumbnail. */
452
+ export declare interface Thumbnail extends ProcessedImage {
453
+ readonly name: string;
454
+ }
455
+
456
+ /** One requested size. */
457
+ export declare interface ThumbnailSpec {
458
+ /** Name to find it by in the result. */
459
+ readonly name: string;
460
+ /** Longest edge in pixels. */
461
+ readonly size: number;
462
+ /** Format and quality, overriding the shared options. */
463
+ readonly encode?: EncodeOptions;
464
+ }
465
+
466
+ /**
467
+ * The browser cannot encode the requested format.
468
+ *
469
+ * Worth its own class because the failure is otherwise silent: asking a
470
+ * canvas for an unsupported type does not throw — it hands back a PNG,
471
+ * and an app that trusted the request ships 4 MB where it expected 300 KB.
472
+ */
473
+ export declare class UnsupportedImageTypeError extends ImagingError {
474
+ constructor(message: string, options?: ErrorOptions);
475
+ }
476
+
477
+ /**
478
+ * Hold an object URL for a blob, and revoke it when it is replaced.
479
+ *
480
+ * @example
481
+ * ```tsx
482
+ * function Preview({ file }: { file: File | null }) {
483
+ * const { url } = useImagePreview(file);
484
+ * return url === null ? null : <img src={url} alt="" />;
485
+ * }
486
+ * ```
487
+ *
488
+ * @param source The blob to preview, or `null`.
489
+ * @returns The object URL, valid until the source changes or the component
490
+ * unmounts.
491
+ */
492
+ export declare function useImagePreview(source: Blob | null | undefined): UseImagePreviewResult;
493
+
494
+ /** What {@link useImagePreview} returns. */
495
+ export declare interface UseImagePreviewResult {
496
+ /** Object URL for the current source, or `null`. */
497
+ readonly url: string | null;
498
+ }
499
+
500
+ /**
501
+ * Run image operations with status tracking, safe against unmount.
502
+ *
503
+ * @example
504
+ * ```tsx
505
+ * function Upload() {
506
+ * const { compress, isWorking, result } = useImageProcessing();
507
+ *
508
+ * async function onPick(file: File) {
509
+ * const ready = await compress(file, { maxBytes: 1_000_000, width: 1600 });
510
+ * await fetch("/api/photos", { method: "POST", body: ready.blob });
511
+ * }
512
+ *
513
+ * return <input type="file" disabled={isWorking} onChange={(e) => onPick(e.target.files![0]!)} />;
514
+ * }
515
+ * ```
516
+ *
517
+ * The returned promises still reject on failure, so a caller can `try`
518
+ * around them; `status` and `error` exist for rendering, not for swallowing
519
+ * the failure.
520
+ *
521
+ * @returns The operations plus their state.
522
+ */
523
+ export declare function useImageProcessing(): UseImageProcessingResult;
524
+
525
+ /** What {@link useImageProcessing} returns. */
526
+ export declare interface UseImageProcessingResult {
527
+ /** Resize (and re-encode) an image. */
528
+ readonly resize: (source: ImageSource, options?: ResizeOptions) => Promise<ProcessedImage>;
529
+ /** Compress an image into a byte budget. */
530
+ readonly compress: (source: ImageSource, options: CompressOptions) => Promise<CompressedImage>;
531
+ /** The most recent result. */
532
+ readonly result: ProcessedImage | null;
533
+ /** Where the last call is. */
534
+ readonly status: ImageProcessingStatus;
535
+ /** Why the last call failed. */
536
+ readonly error: Error | null;
537
+ /** Whether a call is in flight. */
538
+ readonly isWorking: boolean;
539
+ }
540
+
541
+ export { }
@@ -0,0 +1,9 @@
1
+ import { ImageDecodeError as e, ImageEncodeError as t, ImagingError as n, ImagingUnavailableError as r, UnsupportedImageTypeError as i } from "./imaging/exceptions.js";
2
+ import { createSurface as a, drawScaled as o, getContext as s } from "./imaging/canvas.js";
3
+ import { decodeImage as c, readImageInfo as l } from "./imaging/decode.js";
4
+ import { DEFAULT_QUALITY as u, DEFAULT_TYPE as d, bestSupportedType as f, encodeImage as p, resetImageTypeSupportCache as m, supportsImageType as h } from "./imaging/encode.js";
5
+ import { DEFAULT_BACKGROUND as g, cropImage as _, flipImage as v, resizeImage as y, rotateImage as b } from "./imaging/transform.js";
6
+ import { DEFAULT_COMPRESS_STEPS as x, DEFAULT_MAX_QUALITY as S, DEFAULT_MIN_QUALITY as C, compressToTarget as w } from "./imaging/compress.js";
7
+ import { createThumbnails as T } from "./imaging/thumbnails.js";
8
+ import { useImagePreview as E, useImageProcessing as D } from "./imaging/use-image-processing.js";
9
+ export { g as DEFAULT_BACKGROUND, x as DEFAULT_COMPRESS_STEPS, S as DEFAULT_MAX_QUALITY, C as DEFAULT_MIN_QUALITY, u as DEFAULT_QUALITY, d as DEFAULT_TYPE, e as ImageDecodeError, t as ImageEncodeError, n as ImagingError, r as ImagingUnavailableError, i as UnsupportedImageTypeError, f as bestSupportedType, w as compressToTarget, a as createSurface, T as createThumbnails, _ as cropImage, c as decodeImage, o as drawScaled, p as encodeImage, v as flipImage, s as getContext, l as readImageInfo, m as resetImageTypeSupportCache, y as resizeImage, b as rotateImage, h as supportsImageType, E as useImagePreview, D as useImageProcessing };
@@ -0,0 +1,2 @@
1
+ const e=require("../_virtual/_rolldown/runtime.cjs");let t=require("onnxruntime-web");t=e.__toESM(t,1);var n=[`ort-wasm-simd-threaded.wasm`,`ort-wasm-simd-threaded.mjs`,`ort-wasm-simd-threaded.jsep.wasm`,`ort-wasm-simd-threaded.jsep.mjs`];function r(e){t.env.wasm.wasmPaths=e.endsWith(`/`)?e:`${e}/`}function i(e){let t=e.endsWith(`/`)?e:`${e}/`;return n.map(e=>`${t}${e}`)}exports.ORT_WASM_ASSETS=n,exports.configureOrtAssets=r,exports.ortAssetUrls=i;
2
+ //# sourceMappingURL=assets.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.cjs","names":[],"sources":["../../src/tabular/assets.ts"],"sourcesContent":["/**\n * The runtime's own assets, which are the other half of working offline.\n *\n * ONNX Runtime Web does **not** embed its WebAssembly binary, not even in\n * the `.bundle` builds. Measured in Chromium: the default entry fetches\n * `ort-wasm-simd-threaded.jsep.wasm` at session creation, and serving the\n * app without that file fails with `Aborted(both async and sync fetching of\n * the wasm failed)` — an error that says nothing about the missing file.\n *\n * So an offline app has to ship those binaries and precache them. This\n * module names them and points the runtime at a local directory.\n */\n\nimport * as ort from \"onnxruntime-web\";\n\n/**\n * The WebAssembly binaries ONNX Runtime Web may request.\n *\n * Which one is fetched depends on the browser's threading and SIMD support,\n * so an app that must work everywhere ships all of them. Chromium with the\n * default entry point fetched the `jsep` build.\n */\nexport const ORT_WASM_ASSETS: readonly string[] = [\n \"ort-wasm-simd-threaded.wasm\",\n \"ort-wasm-simd-threaded.mjs\",\n \"ort-wasm-simd-threaded.jsep.wasm\",\n \"ort-wasm-simd-threaded.jsep.mjs\",\n];\n\n/**\n * Point ONNX Runtime Web at locally served WebAssembly binaries.\n *\n * Call once, before creating any predictor.\n *\n * @example\n * ```ts\n * configureOrtAssets(\"/ort/\");\n * const predictor = await TabularPredictor.create(\"/models/classifier.onnx\");\n * ```\n *\n * @param basePath Directory the binaries are served from, with a trailing\n * slash. Copy them there at build time — for Vite, from\n * `node_modules/onnxruntime-web/dist/`.\n */\nexport function configureOrtAssets(basePath: string): void {\n ort.env.wasm.wasmPaths = basePath.endsWith(\"/\") ? basePath : `${basePath}/`;\n}\n\n/**\n * The URLs a service worker should precache for offline inference.\n *\n * The model file is not included: it is cached by\n * {@link fetchModelBytes} on first use, under its own bucket.\n *\n * @example\n * ```ts\n * installPrecache([...ortAssetUrls(\"/ort/\"), \"/index.html\"]);\n * ```\n *\n * @param basePath Directory the binaries are served from.\n * @returns Absolute-from-root URLs for every runtime asset.\n */\nexport function ortAssetUrls(basePath: string): string[] {\n const prefix = basePath.endsWith(\"/\") ? basePath : `${basePath}/`;\n return ORT_WASM_ASSETS.map((asset) => `${prefix}${asset}`);\n}\n"],"mappings":"uGAsBA,IAAa,EAAqC,CAC9C,8BACA,6BACA,mCACA,iCACJ,EAiBA,SAAgB,EAAmB,EAAwB,CACvD,EAAI,IAAI,KAAK,UAAY,EAAS,SAAS,GAAG,EAAI,EAAW,GAAG,EAAS,EAC7E,CAgBA,SAAgB,EAAa,EAA4B,CACrD,IAAM,EAAS,EAAS,SAAS,GAAG,EAAI,EAAW,GAAG,EAAS,GAC/D,OAAO,EAAgB,IAAK,GAAU,GAAG,IAAS,GAAO,CAC7D"}
@@ -0,0 +1,19 @@
1
+ import * as e from "onnxruntime-web";
2
+ //#region src/tabular/assets.ts
3
+ var t = [
4
+ "ort-wasm-simd-threaded.wasm",
5
+ "ort-wasm-simd-threaded.mjs",
6
+ "ort-wasm-simd-threaded.jsep.wasm",
7
+ "ort-wasm-simd-threaded.jsep.mjs"
8
+ ];
9
+ function n(t) {
10
+ e.env.wasm.wasmPaths = t.endsWith("/") ? t : `${t}/`;
11
+ }
12
+ function r(e) {
13
+ let n = e.endsWith("/") ? e : `${e}/`;
14
+ return t.map((e) => `${n}${e}`);
15
+ }
16
+ //#endregion
17
+ export { t as ORT_WASM_ASSETS, n as configureOrtAssets, r as ortAssetUrls };
18
+
19
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.js","names":[],"sources":["../../src/tabular/assets.ts"],"sourcesContent":["/**\n * The runtime's own assets, which are the other half of working offline.\n *\n * ONNX Runtime Web does **not** embed its WebAssembly binary, not even in\n * the `.bundle` builds. Measured in Chromium: the default entry fetches\n * `ort-wasm-simd-threaded.jsep.wasm` at session creation, and serving the\n * app without that file fails with `Aborted(both async and sync fetching of\n * the wasm failed)` — an error that says nothing about the missing file.\n *\n * So an offline app has to ship those binaries and precache them. This\n * module names them and points the runtime at a local directory.\n */\n\nimport * as ort from \"onnxruntime-web\";\n\n/**\n * The WebAssembly binaries ONNX Runtime Web may request.\n *\n * Which one is fetched depends on the browser's threading and SIMD support,\n * so an app that must work everywhere ships all of them. Chromium with the\n * default entry point fetched the `jsep` build.\n */\nexport const ORT_WASM_ASSETS: readonly string[] = [\n \"ort-wasm-simd-threaded.wasm\",\n \"ort-wasm-simd-threaded.mjs\",\n \"ort-wasm-simd-threaded.jsep.wasm\",\n \"ort-wasm-simd-threaded.jsep.mjs\",\n];\n\n/**\n * Point ONNX Runtime Web at locally served WebAssembly binaries.\n *\n * Call once, before creating any predictor.\n *\n * @example\n * ```ts\n * configureOrtAssets(\"/ort/\");\n * const predictor = await TabularPredictor.create(\"/models/classifier.onnx\");\n * ```\n *\n * @param basePath Directory the binaries are served from, with a trailing\n * slash. Copy them there at build time — for Vite, from\n * `node_modules/onnxruntime-web/dist/`.\n */\nexport function configureOrtAssets(basePath: string): void {\n ort.env.wasm.wasmPaths = basePath.endsWith(\"/\") ? basePath : `${basePath}/`;\n}\n\n/**\n * The URLs a service worker should precache for offline inference.\n *\n * The model file is not included: it is cached by\n * {@link fetchModelBytes} on first use, under its own bucket.\n *\n * @example\n * ```ts\n * installPrecache([...ortAssetUrls(\"/ort/\"), \"/index.html\"]);\n * ```\n *\n * @param basePath Directory the binaries are served from.\n * @returns Absolute-from-root URLs for every runtime asset.\n */\nexport function ortAssetUrls(basePath: string): string[] {\n const prefix = basePath.endsWith(\"/\") ? basePath : `${basePath}/`;\n return ORT_WASM_ASSETS.map((asset) => `${prefix}${asset}`);\n}\n"],"mappings":";;AAsBA,IAAa,IAAqC;CAC9C;CACA;CACA;CACA;AACJ;AAiBA,SAAgB,EAAmB,GAAwB;CACvD,EAAI,IAAI,KAAK,YAAY,EAAS,SAAS,GAAG,IAAI,IAAW,GAAG,EAAS;AAC7E;AAgBA,SAAgB,EAAa,GAA4B;CACrD,IAAM,IAAS,EAAS,SAAS,GAAG,IAAI,IAAW,GAAG,EAAS;CAC/D,OAAO,EAAgB,KAAK,MAAU,GAAG,IAAS,GAAO;AAC7D"}
@@ -0,0 +1,2 @@
1
+ const e=require("./exceptions.cjs");var t=`tempest-tabular-models`;function n(){return globalThis.caches!==void 0}async function r(t,r={}){let a=r.cacheName??`tempest-tabular-models`;if(!n())return await i(t,r.requestInit);let o=await globalThis.caches.open(a);if(r.revalidate!==!0){let e=await o.match(t);if(e!==void 0)return new Uint8Array(await e.arrayBuffer())}try{let n=await fetch(t,r.requestInit);if(!n.ok)throw new e.ModelFetchError(`Failed to download the model: ${n.status} ${n.statusText}`);return await o.put(t,n.clone()),new Uint8Array(await n.arrayBuffer())}catch(n){let r=await o.match(t);if(r!==void 0)return new Uint8Array(await r.arrayBuffer());throw n instanceof e.ModelFetchError?n:new e.ModelFetchError(`The model is not cached and could not be downloaded: ${t}. Warm the cache while online — prefetch it at install time, or precache it in the service worker.`,{cause:n})}}async function i(t,n){try{let r=await fetch(t,n);if(!r.ok)throw new e.ModelFetchError(`Failed to download the model: ${r.status} ${r.statusText}`);return new Uint8Array(await r.arrayBuffer())}catch(n){throw n instanceof e.ModelFetchError?n:new e.ModelFetchError(`Failed to download the model: ${t}`,{cause:n})}}async function a(e,r=t){return n()?await(await globalThis.caches.open(r)).match(e)!==void 0:!1}async function o(e,r,i=t){if(!n())return!1;let a=await globalThis.caches.open(i),o=new Uint8Array(r).buffer;return await a.put(e,new Response(o,{headers:{"content-type":`application/octet-stream`}})),!0}async function s(e,r=t){return n()?e===void 0?await globalThis.caches.delete(r):await(await globalThis.caches.open(r)).delete(e):!1}exports.DEFAULT_MODEL_CACHE=t,exports.cacheModelBytes=o,exports.clearModelCache=s,exports.fetchModelBytes=r,exports.isModelCached=a;
2
+ //# sourceMappingURL=cache.cjs.map