react-smart-copy 1.17.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/dist/capture.cjs +30 -153
- package/dist/capture.cjs.map +1 -1
- package/dist/capture.d.cts +2 -25
- package/dist/capture.d.ts +2 -25
- package/dist/capture.js +5 -128
- package/dist/capture.js.map +1 -1
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs +102 -0
- package/dist/chunks/clipboard-adapter-Cfz-rzw3.cjs.map +1 -0
- package/dist/chunks/clipboard-adapter-CtH4VELE.d.cts +43 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js +97 -0
- package/dist/chunks/clipboard-adapter-DEXkXxwV.js.map +1 -0
- package/dist/chunks/clipboard-adapter-Ds0irroN.d.ts +43 -0
- package/dist/chunks/contrast-C6CVklEI.cjs +842 -0
- package/dist/chunks/contrast-C6CVklEI.cjs.map +1 -0
- package/dist/chunks/contrast-DpK2JIVu.js +789 -0
- package/dist/chunks/contrast-DpK2JIVu.js.map +1 -0
- package/dist/chunks/copy-interceptor-C6NABy1l.d.ts +141 -0
- package/dist/chunks/copy-interceptor-CZWzGOkL.d.cts +141 -0
- package/dist/chunks/core-Cp2HSpaz.js +1035 -0
- package/dist/chunks/core-Cp2HSpaz.js.map +1 -0
- package/dist/chunks/core-DYf_Lhbe.cjs +1142 -0
- package/dist/chunks/core-DYf_Lhbe.cjs.map +1 -0
- package/dist/chunks/deadline-C29AlS_Q.js +46 -0
- package/dist/chunks/deadline-C29AlS_Q.js.map +1 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs +51 -0
- package/dist/chunks/deadline-DkiB8ZHE.cjs.map +1 -0
- package/dist/chunks/errors-9h8sdFFX.js +120 -0
- package/dist/chunks/errors-9h8sdFFX.js.map +1 -0
- package/dist/chunks/errors-BwOF6T_M.cjs +167 -0
- package/dist/chunks/errors-BwOF6T_M.cjs.map +1 -0
- package/dist/chunks/index-mr7sSAgP.d.ts +426 -0
- package/dist/chunks/index-vz0iW5V2.d.cts +426 -0
- package/dist/chunks/mime--LB7kdqG.cjs +153 -0
- package/dist/chunks/mime--LB7kdqG.cjs.map +1 -0
- package/dist/chunks/mime-aa-HA2dm.js +100 -0
- package/dist/chunks/mime-aa-HA2dm.js.map +1 -0
- package/dist/chunks/paste-adapter--SPL4PRE.d.cts +35 -0
- package/dist/chunks/paste-adapter-uahXnTYk.d.ts +35 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs +289 -0
- package/dist/chunks/paste-reader-Bo01IMC_.cjs.map +1 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js +224 -0
- package/dist/chunks/paste-reader-D9i7yMXF.js.map +1 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.cts +96 -0
- package/dist/chunks/paste-reader-DcXnRWQr.d.ts +96 -0
- package/dist/chunks/payload-CUymxwim.cjs +100 -0
- package/dist/chunks/payload-CUymxwim.cjs.map +1 -0
- package/dist/chunks/payload-CcwKJ_bU.d.cts +162 -0
- package/dist/chunks/payload-Cl_8hCI5.d.ts +162 -0
- package/dist/chunks/payload-DGw-JOo7.js +71 -0
- package/dist/chunks/payload-DGw-JOo7.js.map +1 -0
- package/dist/chunks/payload-DI5AorDz.js +103 -0
- package/dist/chunks/payload-DI5AorDz.js.map +1 -0
- package/dist/chunks/payload-J6GjHuh3.cjs +132 -0
- package/dist/chunks/payload-J6GjHuh3.cjs.map +1 -0
- package/dist/chunks/share-Bop47Znn.js +208 -0
- package/dist/chunks/share-Bop47Znn.js.map +1 -0
- package/dist/chunks/share-C0esXvRK.d.cts +115 -0
- package/dist/chunks/share-ayDz974N.cjs +231 -0
- package/dist/chunks/share-ayDz974N.cjs.map +1 -0
- package/dist/chunks/share-e7FenIr2.d.ts +115 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs +77 -0
- package/dist/chunks/text-field-Ba8W3v4R.cjs.map +1 -0
- package/dist/chunks/text-field-C0SGmvvR.d.cts +18 -0
- package/dist/chunks/text-field-C0SGmvvR.d.ts +18 -0
- package/dist/chunks/text-field-DUvrMMaK.js +66 -0
- package/dist/chunks/text-field-DUvrMMaK.js.map +1 -0
- package/dist/chunks/url-BcMYVCXQ.js +135 -0
- package/dist/chunks/url-BcMYVCXQ.js.map +1 -0
- package/dist/chunks/url-D4PGsRm8.cjs +164 -0
- package/dist/chunks/url-D4PGsRm8.cjs.map +1 -0
- package/dist/chunks/url-DWdElCT3.d.cts +43 -0
- package/dist/chunks/url-DWdElCT3.d.ts +43 -0
- package/dist/code.cjs +20 -109
- package/dist/code.cjs.map +1 -1
- package/dist/code.d.cts +4 -28
- package/dist/code.d.ts +4 -28
- package/dist/code.js +4 -93
- package/dist/code.js.map +1 -1
- package/dist/color.cjs +21 -893
- package/dist/color.cjs.map +1 -1
- package/dist/color.d.cts +4 -28
- package/dist/color.d.ts +4 -28
- package/dist/color.js +4 -876
- package/dist/color.js.map +1 -1
- package/dist/core.cjs +52 -1659
- package/dist/core.d.cts +8 -878
- package/dist/core.d.ts +8 -878
- package/dist/core.js +7 -1614
- package/dist/image.cjs +23 -91
- package/dist/image.cjs.map +1 -1
- package/dist/image.d.cts +1 -0
- package/dist/image.d.ts +1 -0
- package/dist/image.js +5 -73
- package/dist/image.js.map +1 -1
- package/dist/index.cjs +74 -2072
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -978
- package/dist/index.d.ts +8 -978
- package/dist/index.js +7 -2005
- package/dist/index.js.map +1 -1
- package/dist/link.cjs +24 -338
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +5 -83
- package/dist/link.d.ts +5 -83
- package/dist/link.js +5 -319
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +8 -97
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -16
- package/dist/markdown.d.ts +3 -16
- package/dist/markdown.js +3 -92
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +26 -934
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +4 -90
- package/dist/rich.d.ts +4 -90
- package/dist/rich.js +4 -912
- package/dist/rich.js.map +1 -1
- package/dist/share.cjs +5 -640
- package/dist/share.d.cts +3 -248
- package/dist/share.d.ts +3 -248
- package/dist/share.js +1 -637
- package/dist/structured.cjs +13 -95
- package/dist/structured.cjs.map +1 -1
- package/dist/structured.d.cts +2 -11
- package/dist/structured.d.ts +2 -11
- package/dist/structured.js +4 -86
- package/dist/structured.js.map +1 -1
- package/dist/table.cjs +11 -39
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +2 -12
- package/dist/table.d.ts +2 -12
- package/dist/table.js +2 -30
- package/dist/table.js.map +1 -1
- package/dist/testing.cjs +10 -43
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +6 -181
- package/dist/testing.d.ts +6 -181
- package/dist/testing.js +3 -36
- package/dist/testing.js.map +1 -1
- package/package.json +20 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/share.cjs.map +0 -1
- package/dist/share.js.map +0 -1
package/dist/image.cjs
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
|
+
|
|
1
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return cause === void 0 ? {
|
|
5
|
-
type,
|
|
6
|
-
message
|
|
7
|
-
} : {
|
|
8
|
-
type,
|
|
9
|
-
message,
|
|
10
|
-
cause
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Branded (not `instanceof`) so failures stay recognisable even when the core
|
|
15
|
-
* is bundled twice, e.g. `react-smart-copy` and `react-smart-copy/core` together.
|
|
16
|
-
*/
|
|
17
|
-
const COPY_FAILURE_BRAND = Symbol.for("react-smart-copy.CopyFailure");
|
|
18
|
-
/** Error thrown by adapters to carry a fully classified {@link CopyError}. */
|
|
19
|
-
var CopyFailure = class extends Error {
|
|
20
|
-
constructor(copyError) {
|
|
21
|
-
super(copyError.message);
|
|
22
|
-
this[COPY_FAILURE_BRAND] = true;
|
|
23
|
-
this.name = "CopyFailure";
|
|
24
|
-
this.copyError = copyError;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
/** Shorthand for throwing a classified failure. */
|
|
28
|
-
function copyFailure(type, message, cause) {
|
|
29
|
-
return new CopyFailure(createCopyError(type, message, cause));
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
3
|
+
const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
|
|
4
|
+
const require_deadline = require("./chunks/deadline-DkiB8ZHE.cjs");
|
|
32
5
|
//#region src/image/bytes.ts
|
|
33
6
|
/** Bounds-checked reads over a byte array: out-of-range reads return `null`, never garbage. */
|
|
34
7
|
var Bytes = class Bytes {
|
|
@@ -77,8 +50,8 @@ const DEFAULT_IMAGE_MAX_INPUT_BYTES = 104857600;
|
|
|
77
50
|
/** Reads a Blob into memory, refusing anything larger than `maxBytes`. */
|
|
78
51
|
async function readBlob(blob, maxBytes) {
|
|
79
52
|
const candidate = blob;
|
|
80
|
-
if (typeof candidate !== "object" || candidate === null || typeof candidate.size !== "number") throw copyFailure("invalid-payload", "Expected an image Blob or File.");
|
|
81
|
-
if (blob.size > maxBytes) throw copyFailure("too-large", `The image is ${String(blob.size)} bytes; maxInputBytes is ${String(maxBytes)}.`);
|
|
53
|
+
if (typeof candidate !== "object" || candidate === null || typeof candidate.size !== "number") throw require_errors.copyFailure("invalid-payload", "Expected an image Blob or File.");
|
|
54
|
+
if (blob.size > maxBytes) throw require_errors.copyFailure("too-large", `The image is ${String(blob.size)} bytes; maxInputBytes is ${String(maxBytes)}.`);
|
|
82
55
|
return new Bytes(new Uint8Array(await blob.arrayBuffer()));
|
|
83
56
|
}
|
|
84
57
|
function concat(parts) {
|
|
@@ -840,7 +813,7 @@ function parse(bytes) {
|
|
|
840
813
|
function inputLimit(value) {
|
|
841
814
|
if (value === void 0) return DEFAULT_IMAGE_MAX_INPUT_BYTES;
|
|
842
815
|
if (value === Infinity || Number.isInteger(value) && value > 0) return value;
|
|
843
|
-
throw copyFailure("invalid-payload", `\`maxInputBytes\` must be a positive integer or Infinity (received ${String(value)}).`);
|
|
816
|
+
throw require_errors.copyFailure("invalid-payload", `\`maxInputBytes\` must be a positive integer or Infinity (received ${String(value)}).`);
|
|
844
817
|
}
|
|
845
818
|
/**
|
|
846
819
|
* What an image file is and what it carries, read from its bytes without
|
|
@@ -859,7 +832,7 @@ async function readImageInfo(blob, options = {}) {
|
|
|
859
832
|
function flag(value, fallback, name) {
|
|
860
833
|
if (value === void 0) return fallback;
|
|
861
834
|
if (typeof value === "boolean") return value;
|
|
862
|
-
throw copyFailure("invalid-payload", `\`${name}\` must be a boolean.`);
|
|
835
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a boolean.`);
|
|
863
836
|
}
|
|
864
837
|
/** Strips a parsed file; shared with `prepareImage`. Returns `null` when the format can't be stripped losslessly. */
|
|
865
838
|
function stripParsed(parsed, source, keepColorProfile, keepOrientation) {
|
|
@@ -895,51 +868,10 @@ async function stripMetadata(blob, options = {}) {
|
|
|
895
868
|
const keepOrientation = flag(options.keepOrientation, true, "keepOrientation");
|
|
896
869
|
const parsed = parse(await readBlob(blob, inputLimit(options.maxInputBytes)));
|
|
897
870
|
const stripped = stripParsed(parsed, blob, keepColorProfile, keepOrientation);
|
|
898
|
-
if (stripped === null) throw copyFailure("unsupported-format", parsed.info.format === null ? "Not an image this module can read (JPEG, PNG, WebP, GIF, BMP, AVIF or HEIC)." : `${parsed.info.mimeType} metadata can't be removed without re-encoding; use prepareImage().`);
|
|
871
|
+
if (stripped === null) throw require_errors.copyFailure("unsupported-format", parsed.info.format === null ? "Not an image this module can read (JPEG, PNG, WebP, GIF, BMP, AVIF or HEIC)." : `${parsed.info.mimeType} metadata can't be removed without re-encoding; use prepareImage().`);
|
|
899
872
|
return stripped;
|
|
900
873
|
}
|
|
901
874
|
//#endregion
|
|
902
|
-
//#region src/capture/deadline.ts
|
|
903
|
-
/**
|
|
904
|
-
* Runs `task` with a timeout and an optional caller `AbortSignal`. The task
|
|
905
|
-
* receives a signal that fires on either, so cooperative work can stop early.
|
|
906
|
-
* Rejects with classified `timeout` / `aborted` failures.
|
|
907
|
-
*/
|
|
908
|
-
function withDeadline(task, options) {
|
|
909
|
-
const { timeoutMs, label } = options;
|
|
910
|
-
const external = options.signal;
|
|
911
|
-
if (external?.aborted) return Promise.reject(copyFailure("aborted", `${label} was aborted.`, external.reason));
|
|
912
|
-
const controller = new AbortController();
|
|
913
|
-
return new Promise((resolve, reject) => {
|
|
914
|
-
const finish = (abort) => {
|
|
915
|
-
clearTimeout(timer);
|
|
916
|
-
external?.removeEventListener("abort", onAbort);
|
|
917
|
-
/* c8 ignore next -- abort=false path is never used; kept for future API flexibility */
|
|
918
|
-
if (abort) controller.abort();
|
|
919
|
-
};
|
|
920
|
-
const fail = (failure) => {
|
|
921
|
-
finish(true);
|
|
922
|
-
reject(failure);
|
|
923
|
-
};
|
|
924
|
-
const onAbort = () => {
|
|
925
|
-
fail(copyFailure("aborted", `${label} was aborted.`, external.reason));
|
|
926
|
-
};
|
|
927
|
-
const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => {
|
|
928
|
-
fail(copyFailure("timeout", `${label} timed out after ${String(timeoutMs)} ms.`));
|
|
929
|
-
}, timeoutMs);
|
|
930
|
-
external?.addEventListener("abort", onAbort, { once: true });
|
|
931
|
-
new Promise((run) => {
|
|
932
|
-
run(task(controller.signal));
|
|
933
|
-
}).then((value) => {
|
|
934
|
-
finish(true);
|
|
935
|
-
resolve(value);
|
|
936
|
-
}, (cause) => {
|
|
937
|
-
finish(true);
|
|
938
|
-
reject(cause);
|
|
939
|
-
});
|
|
940
|
-
});
|
|
941
|
-
}
|
|
942
|
-
//#endregion
|
|
943
875
|
//#region src/image/prepare.ts
|
|
944
876
|
function createCanvas(width, height) {
|
|
945
877
|
if (typeof OffscreenCanvas === "function") return new OffscreenCanvas(width, height);
|
|
@@ -950,7 +882,7 @@ function createCanvas(width, height) {
|
|
|
950
882
|
}
|
|
951
883
|
function context(canvas) {
|
|
952
884
|
const ctx = canvas.getContext("2d");
|
|
953
|
-
if (ctx === null) throw copyFailure("unsupported", "Canvas 2D rendering is not available.");
|
|
885
|
+
if (ctx === null) throw require_errors.copyFailure("unsupported", "Canvas 2D rendering is not available.");
|
|
954
886
|
ctx.imageSmoothingEnabled = true;
|
|
955
887
|
ctx.imageSmoothingQuality = "high";
|
|
956
888
|
return ctx;
|
|
@@ -963,7 +895,7 @@ function toBlob(canvas, type, quality) {
|
|
|
963
895
|
return new Promise((resolve, reject) => {
|
|
964
896
|
canvas.toBlob((blob) => {
|
|
965
897
|
if (blob) resolve(blob);
|
|
966
|
-
else reject(copyFailure("blob-generation-failed", "The canvas produced no image (too large for this browser?)."));
|
|
898
|
+
else reject(require_errors.copyFailure("blob-generation-failed", "The canvas produced no image (too large for this browser?)."));
|
|
967
899
|
}, type, quality);
|
|
968
900
|
});
|
|
969
901
|
}
|
|
@@ -1015,7 +947,7 @@ const DEFAULT_IMAGE_MAX_PIXELS = 16777216;
|
|
|
1015
947
|
const DEFAULT_IMAGE_QUALITY = .85;
|
|
1016
948
|
const DEFAULT_IMAGE_MIN_QUALITY = .5;
|
|
1017
949
|
const DEFAULT_IMAGE_TIMEOUT_MS = 3e4;
|
|
1018
|
-
const invalid = (message) => copyFailure("invalid-payload", message);
|
|
950
|
+
const invalid = (message) => require_errors.copyFailure("invalid-payload", message);
|
|
1019
951
|
function limit(value, fallback, name) {
|
|
1020
952
|
if (value === void 0) return fallback;
|
|
1021
953
|
if (value === Infinity || Number.isInteger(value) && value > 0) return value;
|
|
@@ -1103,16 +1035,16 @@ async function prepareImage(source, options = {}) {
|
|
|
1103
1035
|
const background = options.background ?? "#fff";
|
|
1104
1036
|
if (typeof background !== "string") throw invalid("`background` must be a CSS colour string.");
|
|
1105
1037
|
const maxInputBytes = inputLimit(options.maxInputBytes);
|
|
1106
|
-
return withDeadline(async (signal) => {
|
|
1038
|
+
return require_deadline.withDeadline(async (signal) => {
|
|
1107
1039
|
const parsed = parse(await readBlob(source, maxInputBytes));
|
|
1108
1040
|
const { info } = parsed;
|
|
1109
1041
|
const original = {
|
|
1110
1042
|
info,
|
|
1111
1043
|
size: source.size
|
|
1112
1044
|
};
|
|
1113
|
-
if (info.format === null && !source.type.startsWith("image/")) throw copyFailure("unsupported-format", "Not an image: the bytes match no image format and the type is not image/*.");
|
|
1114
|
-
if (info.width !== null && info.height !== null && info.width * info.height > maxInputPixels) throw copyFailure("too-large", `The image has ${String(info.width * info.height)} pixels; maxInputPixels is ${String(maxInputPixels)}.`);
|
|
1115
|
-
if (info.animated && animated === "reject") throw copyFailure("unsupported-format", "Animated images are not accepted (animated: \"reject\").");
|
|
1045
|
+
if (info.format === null && !source.type.startsWith("image/")) throw require_errors.copyFailure("unsupported-format", "Not an image: the bytes match no image format and the type is not image/*.");
|
|
1046
|
+
if (info.width !== null && info.height !== null && info.width * info.height > maxInputPixels) throw require_errors.copyFailure("too-large", `The image has ${String(info.width * info.height)} pixels; maxInputPixels is ${String(maxInputPixels)}.`);
|
|
1047
|
+
if (info.animated && animated === "reject") throw require_errors.copyFailure("unsupported-format", "Animated images are not accepted (animated: \"reject\").");
|
|
1116
1048
|
const fits = (width, height) => width === null || height === null || width <= maxWidth && height <= maxHeight && width * height <= maxPixels;
|
|
1117
1049
|
const swapped = info.orientation >= 5 && (info.format === "jpeg" || info.format === "png");
|
|
1118
1050
|
const shownWidth = swapped ? info.height : info.width;
|
|
@@ -1134,17 +1066,17 @@ async function prepareImage(source, options = {}) {
|
|
|
1134
1066
|
original
|
|
1135
1067
|
};
|
|
1136
1068
|
}
|
|
1137
|
-
if (keepAnimation) throw copyFailure("too-large", "An animated image can only fit the size limits by losing its frames: use animated: \"first-frame\".");
|
|
1069
|
+
if (keepAnimation) throw require_errors.copyFailure("too-large", "An animated image can only fit the size limits by losing its frames: use animated: \"first-frame\".");
|
|
1138
1070
|
const environment = options.environment ?? getDefaultImageEnvironment();
|
|
1139
|
-
if (environment === null) throw copyFailure("unsupported", "Re-encoding an image needs createImageBitmap and a canvas (a browser).");
|
|
1071
|
+
if (environment === null) throw require_errors.copyFailure("unsupported", "Re-encoding an image needs createImageBitmap and a canvas (a browser).");
|
|
1140
1072
|
let image;
|
|
1141
1073
|
try {
|
|
1142
1074
|
image = await environment.decode(source, signal);
|
|
1143
1075
|
} catch (cause) {
|
|
1144
|
-
throw cause
|
|
1076
|
+
throw require_errors.isCopyFailure(cause) ? cause : require_errors.copyFailure("unsupported-format", "This browser could not decode the image.", cause);
|
|
1145
1077
|
}
|
|
1146
1078
|
try {
|
|
1147
|
-
if (image.width * image.height > maxInputPixels) throw copyFailure("too-large", `The image has ${String(image.width * image.height)} pixels; maxInputPixels is ${String(maxInputPixels)}.`);
|
|
1079
|
+
if (image.width * image.height > maxInputPixels) throw require_errors.copyFailure("too-large", `The image has ${String(image.width * image.height)} pixels; maxInputPixels is ${String(maxInputPixels)}.`);
|
|
1148
1080
|
const fit = Math.min(1, maxWidth / image.width, maxHeight / image.height, Math.sqrt(maxPixels / (image.width * image.height)));
|
|
1149
1081
|
return await encodeWithin(environment, image, {
|
|
1150
1082
|
info,
|
|
@@ -1185,7 +1117,7 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1185
1117
|
let encodes = 0;
|
|
1186
1118
|
let smallest = Infinity;
|
|
1187
1119
|
const encode = async (type, scale, quality) => {
|
|
1188
|
-
if (signal.aborted) throw copyFailure("aborted", "Preparing the image was aborted.");
|
|
1120
|
+
if (signal.aborted) throw require_errors.copyFailure("aborted", "Preparing the image was aborted.");
|
|
1189
1121
|
if (encodes >= MAX_ENCODES) throw new SearchSignal("exhausted");
|
|
1190
1122
|
encodes += 1;
|
|
1191
1123
|
const width = Math.max(1, Math.round(image.width * scale));
|
|
@@ -1200,10 +1132,10 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1200
1132
|
background: type === "image/jpeg" ? settings.background : null
|
|
1201
1133
|
}, signal);
|
|
1202
1134
|
} catch (cause) {
|
|
1203
|
-
throw cause
|
|
1135
|
+
throw require_errors.isCopyFailure(cause) ? cause : require_errors.copyFailure("blob-generation-failed", `Encoding ${type} failed.`, cause);
|
|
1204
1136
|
}
|
|
1205
1137
|
if (blob.type !== type) {
|
|
1206
|
-
if (requested !== "auto") throw copyFailure("unsupported-format", `This browser can't encode ${type}.`);
|
|
1138
|
+
if (requested !== "auto") throw require_errors.copyFailure("unsupported-format", `This browser can't encode ${type}.`);
|
|
1207
1139
|
throw new SearchSignal("unavailable");
|
|
1208
1140
|
}
|
|
1209
1141
|
smallest = Math.min(smallest, blob.size);
|
|
@@ -1277,7 +1209,7 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1277
1209
|
if (!(signalled instanceof SearchSignal)) throw signalled;
|
|
1278
1210
|
if (signalled.reason === "exhausted") break;
|
|
1279
1211
|
}
|
|
1280
|
-
throw copyFailure("too-large", smallest === Infinity ? "No output format could be encoded here." : `Could not get the image under maxBytes (${String(maxBytes)}); the smallest result was ${String(smallest)} bytes.`);
|
|
1212
|
+
throw require_errors.copyFailure("too-large", smallest === Infinity ? "No output format could be encoded here." : `Could not get the image under maxBytes (${String(maxBytes)}); the smallest result was ${String(smallest)} bytes.`);
|
|
1281
1213
|
}
|
|
1282
1214
|
//#endregion
|
|
1283
1215
|
exports.DEFAULT_IMAGE_MAX_INPUT_BYTES = DEFAULT_IMAGE_MAX_INPUT_BYTES;
|