react-smart-copy 1.17.2 → 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 +9 -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 -112
- 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 +3 -95
- 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 -94
- 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 +3 -74
- 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,37 +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
|
-
function isCopyFailure(value) {
|
|
28
|
-
return typeof value === "object" && value !== null && value[COPY_FAILURE_BRAND] === true;
|
|
29
|
-
}
|
|
30
|
-
/** Shorthand for throwing a classified failure. */
|
|
31
|
-
function copyFailure(type, message, cause) {
|
|
32
|
-
return new CopyFailure(createCopyError(type, message, cause));
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
3
|
+
const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
|
|
4
|
+
const require_deadline = require("./chunks/deadline-DkiB8ZHE.cjs");
|
|
35
5
|
//#region src/image/bytes.ts
|
|
36
6
|
/** Bounds-checked reads over a byte array: out-of-range reads return `null`, never garbage. */
|
|
37
7
|
var Bytes = class Bytes {
|
|
@@ -80,8 +50,8 @@ const DEFAULT_IMAGE_MAX_INPUT_BYTES = 104857600;
|
|
|
80
50
|
/** Reads a Blob into memory, refusing anything larger than `maxBytes`. */
|
|
81
51
|
async function readBlob(blob, maxBytes) {
|
|
82
52
|
const candidate = blob;
|
|
83
|
-
if (typeof candidate !== "object" || candidate === null || typeof candidate.size !== "number") throw copyFailure("invalid-payload", "Expected an image Blob or File.");
|
|
84
|
-
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)}.`);
|
|
85
55
|
return new Bytes(new Uint8Array(await blob.arrayBuffer()));
|
|
86
56
|
}
|
|
87
57
|
function concat(parts) {
|
|
@@ -843,7 +813,7 @@ function parse(bytes) {
|
|
|
843
813
|
function inputLimit(value) {
|
|
844
814
|
if (value === void 0) return DEFAULT_IMAGE_MAX_INPUT_BYTES;
|
|
845
815
|
if (value === Infinity || Number.isInteger(value) && value > 0) return value;
|
|
846
|
-
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)}).`);
|
|
847
817
|
}
|
|
848
818
|
/**
|
|
849
819
|
* What an image file is and what it carries, read from its bytes without
|
|
@@ -862,7 +832,7 @@ async function readImageInfo(blob, options = {}) {
|
|
|
862
832
|
function flag(value, fallback, name) {
|
|
863
833
|
if (value === void 0) return fallback;
|
|
864
834
|
if (typeof value === "boolean") return value;
|
|
865
|
-
throw copyFailure("invalid-payload", `\`${name}\` must be a boolean.`);
|
|
835
|
+
throw require_errors.copyFailure("invalid-payload", `\`${name}\` must be a boolean.`);
|
|
866
836
|
}
|
|
867
837
|
/** Strips a parsed file; shared with `prepareImage`. Returns `null` when the format can't be stripped losslessly. */
|
|
868
838
|
function stripParsed(parsed, source, keepColorProfile, keepOrientation) {
|
|
@@ -898,51 +868,10 @@ async function stripMetadata(blob, options = {}) {
|
|
|
898
868
|
const keepOrientation = flag(options.keepOrientation, true, "keepOrientation");
|
|
899
869
|
const parsed = parse(await readBlob(blob, inputLimit(options.maxInputBytes)));
|
|
900
870
|
const stripped = stripParsed(parsed, blob, keepColorProfile, keepOrientation);
|
|
901
|
-
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().`);
|
|
902
872
|
return stripped;
|
|
903
873
|
}
|
|
904
874
|
//#endregion
|
|
905
|
-
//#region src/capture/deadline.ts
|
|
906
|
-
/**
|
|
907
|
-
* Runs `task` with a timeout and an optional caller `AbortSignal`. The task
|
|
908
|
-
* receives a signal that fires on either, so cooperative work can stop early.
|
|
909
|
-
* Rejects with classified `timeout` / `aborted` failures.
|
|
910
|
-
*/
|
|
911
|
-
function withDeadline(task, options) {
|
|
912
|
-
const { timeoutMs, label } = options;
|
|
913
|
-
const external = options.signal;
|
|
914
|
-
if (external?.aborted) return Promise.reject(copyFailure("aborted", `${label} was aborted.`, external.reason));
|
|
915
|
-
const controller = new AbortController();
|
|
916
|
-
return new Promise((resolve, reject) => {
|
|
917
|
-
const finish = (abort) => {
|
|
918
|
-
clearTimeout(timer);
|
|
919
|
-
external?.removeEventListener("abort", onAbort);
|
|
920
|
-
/* c8 ignore next -- abort=false path is never used; kept for future API flexibility */
|
|
921
|
-
if (abort) controller.abort();
|
|
922
|
-
};
|
|
923
|
-
const fail = (failure) => {
|
|
924
|
-
finish(true);
|
|
925
|
-
reject(failure);
|
|
926
|
-
};
|
|
927
|
-
const onAbort = () => {
|
|
928
|
-
fail(copyFailure("aborted", `${label} was aborted.`, external.reason));
|
|
929
|
-
};
|
|
930
|
-
const timer = timeoutMs === Infinity ? void 0 : setTimeout(() => {
|
|
931
|
-
fail(copyFailure("timeout", `${label} timed out after ${String(timeoutMs)} ms.`));
|
|
932
|
-
}, timeoutMs);
|
|
933
|
-
external?.addEventListener("abort", onAbort, { once: true });
|
|
934
|
-
new Promise((run) => {
|
|
935
|
-
run(task(controller.signal));
|
|
936
|
-
}).then((value) => {
|
|
937
|
-
finish(true);
|
|
938
|
-
resolve(value);
|
|
939
|
-
}, (cause) => {
|
|
940
|
-
finish(true);
|
|
941
|
-
reject(cause);
|
|
942
|
-
});
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
//#endregion
|
|
946
875
|
//#region src/image/prepare.ts
|
|
947
876
|
function createCanvas(width, height) {
|
|
948
877
|
if (typeof OffscreenCanvas === "function") return new OffscreenCanvas(width, height);
|
|
@@ -953,7 +882,7 @@ function createCanvas(width, height) {
|
|
|
953
882
|
}
|
|
954
883
|
function context(canvas) {
|
|
955
884
|
const ctx = canvas.getContext("2d");
|
|
956
|
-
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.");
|
|
957
886
|
ctx.imageSmoothingEnabled = true;
|
|
958
887
|
ctx.imageSmoothingQuality = "high";
|
|
959
888
|
return ctx;
|
|
@@ -966,7 +895,7 @@ function toBlob(canvas, type, quality) {
|
|
|
966
895
|
return new Promise((resolve, reject) => {
|
|
967
896
|
canvas.toBlob((blob) => {
|
|
968
897
|
if (blob) resolve(blob);
|
|
969
|
-
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?)."));
|
|
970
899
|
}, type, quality);
|
|
971
900
|
});
|
|
972
901
|
}
|
|
@@ -1018,7 +947,7 @@ const DEFAULT_IMAGE_MAX_PIXELS = 16777216;
|
|
|
1018
947
|
const DEFAULT_IMAGE_QUALITY = .85;
|
|
1019
948
|
const DEFAULT_IMAGE_MIN_QUALITY = .5;
|
|
1020
949
|
const DEFAULT_IMAGE_TIMEOUT_MS = 3e4;
|
|
1021
|
-
const invalid = (message) => copyFailure("invalid-payload", message);
|
|
950
|
+
const invalid = (message) => require_errors.copyFailure("invalid-payload", message);
|
|
1022
951
|
function limit(value, fallback, name) {
|
|
1023
952
|
if (value === void 0) return fallback;
|
|
1024
953
|
if (value === Infinity || Number.isInteger(value) && value > 0) return value;
|
|
@@ -1106,16 +1035,16 @@ async function prepareImage(source, options = {}) {
|
|
|
1106
1035
|
const background = options.background ?? "#fff";
|
|
1107
1036
|
if (typeof background !== "string") throw invalid("`background` must be a CSS colour string.");
|
|
1108
1037
|
const maxInputBytes = inputLimit(options.maxInputBytes);
|
|
1109
|
-
return withDeadline(async (signal) => {
|
|
1038
|
+
return require_deadline.withDeadline(async (signal) => {
|
|
1110
1039
|
const parsed = parse(await readBlob(source, maxInputBytes));
|
|
1111
1040
|
const { info } = parsed;
|
|
1112
1041
|
const original = {
|
|
1113
1042
|
info,
|
|
1114
1043
|
size: source.size
|
|
1115
1044
|
};
|
|
1116
|
-
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/*.");
|
|
1117
|
-
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)}.`);
|
|
1118
|
-
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\").");
|
|
1119
1048
|
const fits = (width, height) => width === null || height === null || width <= maxWidth && height <= maxHeight && width * height <= maxPixels;
|
|
1120
1049
|
const swapped = info.orientation >= 5 && (info.format === "jpeg" || info.format === "png");
|
|
1121
1050
|
const shownWidth = swapped ? info.height : info.width;
|
|
@@ -1137,17 +1066,17 @@ async function prepareImage(source, options = {}) {
|
|
|
1137
1066
|
original
|
|
1138
1067
|
};
|
|
1139
1068
|
}
|
|
1140
|
-
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\".");
|
|
1141
1070
|
const environment = options.environment ?? getDefaultImageEnvironment();
|
|
1142
|
-
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).");
|
|
1143
1072
|
let image;
|
|
1144
1073
|
try {
|
|
1145
1074
|
image = await environment.decode(source, signal);
|
|
1146
1075
|
} catch (cause) {
|
|
1147
|
-
throw isCopyFailure(cause) ? cause : copyFailure("unsupported-format", "This browser could not decode the image.", cause);
|
|
1076
|
+
throw require_errors.isCopyFailure(cause) ? cause : require_errors.copyFailure("unsupported-format", "This browser could not decode the image.", cause);
|
|
1148
1077
|
}
|
|
1149
1078
|
try {
|
|
1150
|
-
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)}.`);
|
|
1151
1080
|
const fit = Math.min(1, maxWidth / image.width, maxHeight / image.height, Math.sqrt(maxPixels / (image.width * image.height)));
|
|
1152
1081
|
return await encodeWithin(environment, image, {
|
|
1153
1082
|
info,
|
|
@@ -1188,7 +1117,7 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1188
1117
|
let encodes = 0;
|
|
1189
1118
|
let smallest = Infinity;
|
|
1190
1119
|
const encode = async (type, scale, quality) => {
|
|
1191
|
-
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.");
|
|
1192
1121
|
if (encodes >= MAX_ENCODES) throw new SearchSignal("exhausted");
|
|
1193
1122
|
encodes += 1;
|
|
1194
1123
|
const width = Math.max(1, Math.round(image.width * scale));
|
|
@@ -1203,10 +1132,10 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1203
1132
|
background: type === "image/jpeg" ? settings.background : null
|
|
1204
1133
|
}, signal);
|
|
1205
1134
|
} catch (cause) {
|
|
1206
|
-
throw isCopyFailure(cause) ? cause : copyFailure("blob-generation-failed", `Encoding ${type} failed.`, cause);
|
|
1135
|
+
throw require_errors.isCopyFailure(cause) ? cause : require_errors.copyFailure("blob-generation-failed", `Encoding ${type} failed.`, cause);
|
|
1207
1136
|
}
|
|
1208
1137
|
if (blob.type !== type) {
|
|
1209
|
-
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}.`);
|
|
1210
1139
|
throw new SearchSignal("unavailable");
|
|
1211
1140
|
}
|
|
1212
1141
|
smallest = Math.min(smallest, blob.size);
|
|
@@ -1280,7 +1209,7 @@ async function encodeWithin(environment, image, settings) {
|
|
|
1280
1209
|
if (!(signalled instanceof SearchSignal)) throw signalled;
|
|
1281
1210
|
if (signalled.reason === "exhausted") break;
|
|
1282
1211
|
}
|
|
1283
|
-
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.`);
|
|
1284
1213
|
}
|
|
1285
1214
|
//#endregion
|
|
1286
1215
|
exports.DEFAULT_IMAGE_MAX_INPUT_BYTES = DEFAULT_IMAGE_MAX_INPUT_BYTES;
|