@crabcrop/url 0.9.11 → 0.10.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 +35 -7
- package/dist/bytes.d.ts +21 -0
- package/dist/bytes.js +86 -0
- package/dist/crypto/aes-gcm.d.ts +21 -0
- package/dist/crypto/aes-gcm.js +248 -0
- package/dist/crypto/node.d.ts +11 -0
- package/dist/crypto/node.js +41 -0
- package/dist/crypto/portable.d.ts +14 -0
- package/dist/crypto/portable.js +60 -0
- package/dist/crypto/sha256.d.ts +14 -0
- package/dist/crypto/sha256.js +131 -0
- package/dist/explain.d.ts +55 -7
- package/dist/explain.js +116 -65
- package/dist/index.d.ts +2 -1
- package/dist/index.js +60 -50
- package/dist/limits.d.ts +9 -0
- package/dist/limits.js +9 -0
- package/dist/operations.d.ts +8 -20
- package/dist/operations.js +133 -71
- package/package.json +11 -3
package/dist/operations.js
CHANGED
|
@@ -9,20 +9,24 @@
|
|
|
9
9
|
* pipeline and the equivalent hand-written string produce
|
|
10
10
|
* byte-identical URLs. Validation throws at build time, like
|
|
11
11
|
* `buildSrcSet` does for widths: a value the server would 400
|
|
12
|
-
* never gets signed.
|
|
12
|
+
* never gets signed. The closed sets (formats, aligns, anchors,
|
|
13
|
+
* modes, factors, shapes) and the class-name checks come from
|
|
14
|
+
* the explainer (issue #482), so the builders and the
|
|
15
|
+
* explainer read one copy of them. The numeric bounds are
|
|
16
|
+
* still written on each side: the builders check numbers, the
|
|
17
|
+
* explainer checks their spellings.
|
|
13
18
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"gif",
|
|
17
|
-
"jpeg",
|
|
18
|
-
"jxl",
|
|
19
|
-
"png",
|
|
20
|
-
"webp",
|
|
21
|
-
];
|
|
22
|
-
const MAX_DIMENSION = 16383;
|
|
19
|
+
import { BLEND_MODES, classFoldKey, CROP_ALIGNS, CURVE_CHANNELS, DPR_FACTORS, FLIP_AXES, IMAGE_FORMATS, isClassName, isOneOf, JPEG_SUBSAMPLINGS, MASK_SHAPES, MAX_OBJECTS_CLASSES, QUALITY_FORMATS, STUDIO_BACKDROPS, STUDIO_MODES, STUDIO_SHADOWS, TEXT_ANCHORS, UPSCALE_FACTORS, } from "./explain.js";
|
|
20
|
+
import { MAX_DIMENSION } from "./limits.js";
|
|
23
21
|
function fail(what, value, rule) {
|
|
24
22
|
throw new Error(`${what} must be ${rule}, got ${JSON.stringify(value)}`);
|
|
25
23
|
}
|
|
24
|
+
/** A closed set spelled for an error message: `2 or 4`, `1, 1.5, 2, or 3`. */
|
|
25
|
+
function eitherOf(values, quote = false) {
|
|
26
|
+
const words = values.map((v) => (quote ? `"${v}"` : String(v)));
|
|
27
|
+
const last = words.pop();
|
|
28
|
+
return words.length === 1 ? `${words[0]} or ${last}` : `${words.join(", ")}, or ${last}`;
|
|
29
|
+
}
|
|
26
30
|
function intIn(what, value, min, max) {
|
|
27
31
|
if (!Number.isSafeInteger(value) || value < min || value > max) {
|
|
28
32
|
fail(what, value, `an integer from ${min} to ${max}`);
|
|
@@ -36,19 +40,92 @@ function floatIn(what, value, min, max) {
|
|
|
36
40
|
return value;
|
|
37
41
|
}
|
|
38
42
|
function positiveFloat(what, value) {
|
|
39
|
-
|
|
43
|
+
// The server reads a 32-bit float: past its range the value
|
|
44
|
+
// is infinite there, and a positive value below it is zero.
|
|
45
|
+
const f32 = Math.fround(value);
|
|
46
|
+
if (!Number.isFinite(f32) || f32 <= 0) {
|
|
40
47
|
fail(what, value, "a positive number");
|
|
41
48
|
}
|
|
42
49
|
return value;
|
|
43
50
|
}
|
|
51
|
+
/** Spell `digits * 10^exponent` in plain decimal, no exponent. */
|
|
52
|
+
function plainDecimal(digits, exponent) {
|
|
53
|
+
const text = digits.toString();
|
|
54
|
+
if (exponent >= 0)
|
|
55
|
+
return text + "0".repeat(exponent);
|
|
56
|
+
const padded = text.padStart(1 - exponent, "0");
|
|
57
|
+
const whole = padded.slice(0, padded.length + exponent);
|
|
58
|
+
const fraction = padded.slice(padded.length + exponent).replace(/0+$/, "");
|
|
59
|
+
return fraction ? `${whole}.${fraction}` : whole;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The canonical spelling of a 32-bit float parameter (issue
|
|
63
|
+
* #472). The server parses these arguments as `f32` and
|
|
64
|
+
* prints them back as Rust's float `Display` does: the
|
|
65
|
+
* shortest decimal that reads back as the same f32 (the
|
|
66
|
+
* closer of two, a tie going up), never an exponent. So the
|
|
67
|
+
* double `0.1 + 0.2` spells `0.3`, the form the server keys
|
|
68
|
+
* its cache on, not its 17-digit double spelling. The search
|
|
69
|
+
* is exact, on the float's binary value in BigInt
|
|
70
|
+
* arithmetic, so no double rounding can pick a spelling Rust
|
|
71
|
+
* would not.
|
|
72
|
+
*/
|
|
73
|
+
function num(value) {
|
|
74
|
+
const f = Math.fround(value);
|
|
75
|
+
if (!Number.isFinite(f)) {
|
|
76
|
+
throw new Error(`${value} is outside the 32-bit float range the server parses`);
|
|
77
|
+
}
|
|
78
|
+
if (f === 0)
|
|
79
|
+
return "0";
|
|
80
|
+
const view = new DataView(new ArrayBuffer(4));
|
|
81
|
+
view.setFloat32(0, Math.abs(f));
|
|
82
|
+
const bits = view.getUint32(0);
|
|
83
|
+
const biased = bits >>> 23;
|
|
84
|
+
const fraction = bits & 0x7fffff;
|
|
85
|
+
const mantissa = BigInt(biased === 0 ? fraction : fraction | 0x800000);
|
|
86
|
+
// In units of a quarter ulp, 2^unit: the float sits at
|
|
87
|
+
// 4 * mantissa and reads back from any decimal strictly
|
|
88
|
+
// between the midpoints to its neighbors, which lie half as
|
|
89
|
+
// far below at a power of two (the binade below is finer).
|
|
90
|
+
// A decimal exactly on a midpoint rounds to the even
|
|
91
|
+
// mantissa, so the ends count only for an even one.
|
|
92
|
+
const unit = (biased === 0 ? 1 : biased) - 152;
|
|
93
|
+
const center = 4n * mantissa;
|
|
94
|
+
const low = fraction === 0 && biased > 1 ? center - 1n : center - 2n;
|
|
95
|
+
const high = center + 2n;
|
|
96
|
+
const inclusive = mantissa % 2n === 0n;
|
|
97
|
+
const sign = f < 0 ? "-" : "";
|
|
98
|
+
// From one decade above the value down, the first decimal
|
|
99
|
+
// exponent with a candidate in the interval gives the
|
|
100
|
+
// shortest spelling. Only the two neighbors of the value at
|
|
101
|
+
// that exponent can qualify, and an f32 needs at most nine
|
|
102
|
+
// significant digits, so the loop is short.
|
|
103
|
+
for (let k = Math.floor(Math.log10(Math.abs(f))) + 2;; k--) {
|
|
104
|
+
// Compare digits * 10^k with units * 2^unit as integers.
|
|
105
|
+
const binary = (unit > 0 ? 2n ** BigInt(unit) : 1n) * (k < 0 ? 10n ** BigInt(-k) : 1n);
|
|
106
|
+
const step = (unit < 0 ? 2n ** BigInt(-unit) : 1n) * (k > 0 ? 10n ** BigInt(k) : 1n);
|
|
107
|
+
const at = center * binary;
|
|
108
|
+
const below = (at / step) * step;
|
|
109
|
+
const above = below + step;
|
|
110
|
+
const lowEnd = low * binary;
|
|
111
|
+
const highEnd = high * binary;
|
|
112
|
+
const downFits = inclusive ? below >= lowEnd : below > lowEnd;
|
|
113
|
+
const upFits = inclusive ? above <= highEnd : above < highEnd;
|
|
114
|
+
if (downFits || upFits) {
|
|
115
|
+
const down = downFits && (!upFits || 2n * (at - below) < step);
|
|
116
|
+
return sign + plainDecimal((down ? below : above) / step, k);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
44
120
|
/**
|
|
45
|
-
* The canonical
|
|
121
|
+
* The canonical spelling of a 64-bit float parameter (the
|
|
122
|
+
* convolution kernel's values): integers without a fraction,
|
|
46
123
|
* other values in plain decimal (the grammar takes no
|
|
47
124
|
* exponent forms). JavaScript's shortest round-trip spelling
|
|
48
125
|
* agrees with the server's for the magnitudes the grammar
|
|
49
126
|
* allows; exponent spellings are expanded to plain decimal.
|
|
50
127
|
*/
|
|
51
|
-
function
|
|
128
|
+
function kernelNum(value) {
|
|
52
129
|
if (Number.isSafeInteger(value))
|
|
53
130
|
return String(value);
|
|
54
131
|
const s = String(value);
|
|
@@ -97,33 +174,13 @@ function encodeArg(text) {
|
|
|
97
174
|
}
|
|
98
175
|
function className(what, name) {
|
|
99
176
|
const trimmed = name.trim();
|
|
100
|
-
|
|
101
|
-
// units: a name of multibyte characters can pass a
|
|
102
|
-
// length check here and still be rejected there, so
|
|
103
|
-
// measure the encoded form, as the explainer does.
|
|
104
|
-
const bytes = new TextEncoder().encode(trimmed).length;
|
|
105
|
-
if (bytes < 1 || bytes > 64 || !/^[\p{L}\p{N} _.\-/]+$/u.test(trimmed)) {
|
|
177
|
+
if (!isClassName(trimmed)) {
|
|
106
178
|
fail(what, name, "1 to 64 UTF-8 bytes of letters, digits, space, `_`, `.`, `-`, `/`");
|
|
107
179
|
}
|
|
108
|
-
|
|
180
|
+
// The server trims the name before it validates and keys
|
|
181
|
+
// on it, so the trimmed name is the canonical one.
|
|
182
|
+
return encodeArg(trimmed);
|
|
109
183
|
}
|
|
110
|
-
const CROP_ALIGNS = ["center", "smart", "face", "top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right"];
|
|
111
|
-
const ANCHORS = [
|
|
112
|
-
"top-left",
|
|
113
|
-
"top-center",
|
|
114
|
-
"top-right",
|
|
115
|
-
"center-left",
|
|
116
|
-
"center",
|
|
117
|
-
"center-right",
|
|
118
|
-
"bottom-left",
|
|
119
|
-
"bottom-center",
|
|
120
|
-
"bottom-right",
|
|
121
|
-
];
|
|
122
|
-
const BLEND_MODES = ["normal", "multiply", "screen", "overlay"];
|
|
123
|
-
const CURVE_CHANNELS = ["rgb", "r", "g", "b"];
|
|
124
|
-
const STUDIO_MODES = ["product", "scene"];
|
|
125
|
-
const STUDIO_SHADOWS = ["soft", "strong", "none"];
|
|
126
|
-
const IMAGE_FORMATS = ["jpeg", "jpg", "png", "webp", "jxl", "avif", "gif", "mp4", "webm"];
|
|
127
184
|
/** Operation segments, one typed call per segment kind. */
|
|
128
185
|
export const ops = {
|
|
129
186
|
/** `300x200`; each side a Dimension (0 proportional, negative flips). */
|
|
@@ -149,7 +206,7 @@ export const ops = {
|
|
|
149
206
|
},
|
|
150
207
|
/** `crop:300x200` or `crop:300x200:smart`; an exact pixel box. */
|
|
151
208
|
crop(width, height, align = "center") {
|
|
152
|
-
if (!CROP_ALIGNS
|
|
209
|
+
if (!isOneOf(CROP_ALIGNS, align)) {
|
|
153
210
|
fail("crop align", align, `one of ${CROP_ALIGNS.join(", ")}`);
|
|
154
211
|
}
|
|
155
212
|
const box = pixelBox("crop", width, height);
|
|
@@ -163,10 +220,11 @@ export const ops = {
|
|
|
163
220
|
* Needs a detection model configured on the server; when
|
|
164
221
|
* none of the classes is detected the render falls back
|
|
165
222
|
* to the plain center crop of the same size. Duplicate
|
|
166
|
-
* classes (case-insensitive
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
223
|
+
* classes (ASCII case-insensitive, as the server compares
|
|
224
|
+
* them: `E` repeats `e`, `É` does not repeat `é`) are
|
|
225
|
+
* spelled once, as the server's canonical form spells
|
|
226
|
+
* them; at most 32 distinct classes, and a 33rd throws,
|
|
227
|
+
* since the server rejects it with `invalid_crop`.
|
|
170
228
|
*/
|
|
171
229
|
cropObjects(width, height, classes, scale = 1) {
|
|
172
230
|
if (!Array.isArray(classes) || classes.length < 1) {
|
|
@@ -178,16 +236,19 @@ export const ops = {
|
|
|
178
236
|
const names = [];
|
|
179
237
|
for (const name of classes) {
|
|
180
238
|
const encoded = className("crop objects class", name);
|
|
181
|
-
const key =
|
|
239
|
+
const key = classFoldKey(name.trim());
|
|
182
240
|
if (!seen.has(key)) {
|
|
183
|
-
if (names.length ===
|
|
241
|
+
if (names.length === MAX_OBJECTS_CLASSES) {
|
|
184
242
|
fail("crop objects classes", classes, "an array of 1 to 32 distinct class names");
|
|
185
243
|
}
|
|
186
244
|
seen.add(key);
|
|
187
245
|
names.push(encoded);
|
|
188
246
|
}
|
|
189
247
|
}
|
|
190
|
-
|
|
248
|
+
// Checked as the f32 the server reads (as are zoom, blur
|
|
249
|
+
// and gamma below): a positive double that rounds to f32
|
|
250
|
+
// zero would otherwise be spelled `0`, which it refuses.
|
|
251
|
+
if (!Number.isFinite(scale) || Math.fround(scale) <= 0 || scale > 100) {
|
|
191
252
|
fail("crop objects scale", scale, "a number above 0 and at most 100");
|
|
192
253
|
}
|
|
193
254
|
const box = pixelBox("crop", width, height);
|
|
@@ -223,7 +284,7 @@ export const ops = {
|
|
|
223
284
|
}
|
|
224
285
|
return v;
|
|
225
286
|
};
|
|
226
|
-
if (!Number.isFinite(zoom) || zoom <= 0 || zoom > 100) {
|
|
287
|
+
if (!Number.isFinite(zoom) || Math.fround(zoom) <= 0 || zoom > 100) {
|
|
227
288
|
fail("focalpoint zoom", zoom, "a number above 0 and at most 100");
|
|
228
289
|
}
|
|
229
290
|
return `focalpoint:${num(frac("focalpoint x", x))}x${num(frac("focalpoint y", y))}:${num(zoom)}`;
|
|
@@ -315,7 +376,8 @@ export const filter = {
|
|
|
315
376
|
},
|
|
316
377
|
/** Gaussian blur by sigma: positive, at most the server's 512 cap. */
|
|
317
378
|
blur(sigma) {
|
|
318
|
-
|
|
379
|
+
// The server also refuses a subnormal f32 sigma.
|
|
380
|
+
if (!Number.isFinite(sigma) || Math.fround(sigma) < 2 ** -126 || sigma > 512) {
|
|
319
381
|
fail("blur sigma", sigma, "a positive number up to 512");
|
|
320
382
|
}
|
|
321
383
|
return `blur(${num(sigma)})`;
|
|
@@ -334,7 +396,7 @@ export const filter = {
|
|
|
334
396
|
},
|
|
335
397
|
/** Gamma correction divisor: 0 < g <= 10 (1 unchanged; above 1 brightens midtones). */
|
|
336
398
|
gamma(value) {
|
|
337
|
-
if (!Number.isFinite(value) || value <= 0 || value > 10) {
|
|
399
|
+
if (!Number.isFinite(value) || Math.fround(value) <= 0 || value > 10) {
|
|
338
400
|
fail("gamma", value, "a number above 0 and at most 10");
|
|
339
401
|
}
|
|
340
402
|
return `gamma(${num(value)})`;
|
|
@@ -374,7 +436,7 @@ export const filter = {
|
|
|
374
436
|
* nearest end value.
|
|
375
437
|
*/
|
|
376
438
|
curve(channel, points) {
|
|
377
|
-
if (!CURVE_CHANNELS
|
|
439
|
+
if (!isOneOf(CURVE_CHANNELS, channel)) {
|
|
378
440
|
fail("curve channel", channel, `one of ${CURVE_CHANNELS.join(", ")}`);
|
|
379
441
|
}
|
|
380
442
|
if (points.length < 2 || points.length > 16) {
|
|
@@ -408,7 +470,7 @@ export const filter = {
|
|
|
408
470
|
}
|
|
409
471
|
for (const v of values) {
|
|
410
472
|
floatIn("convolution kernel value", v, -1024, 1024);
|
|
411
|
-
if (!/^-?\d+(\.\d+)?$/.test(
|
|
473
|
+
if (!/^-?\d+(\.\d+)?$/.test(kernelNum(v))) {
|
|
412
474
|
fail("convolution kernel value", v, "a plain decimal (the grammar takes no exponent forms)");
|
|
413
475
|
}
|
|
414
476
|
}
|
|
@@ -419,7 +481,7 @@ export const filter = {
|
|
|
419
481
|
fail("convolution normalize", normalize, "a boolean or 0/1");
|
|
420
482
|
}
|
|
421
483
|
const flag = normalize === true || normalize === 1 ? 1 : 0;
|
|
422
|
-
return `convolution(${values.map(
|
|
484
|
+
return `convolution(${values.map(kernelNum).join(",")},${flag})`;
|
|
423
485
|
},
|
|
424
486
|
/**
|
|
425
487
|
* Film grain: one noise value per pixel, added equally
|
|
@@ -476,8 +538,8 @@ export const filter = {
|
|
|
476
538
|
parts.push(fallback === "auto" ? "auto" : String(intIn("quality", fallback, 1, 100)));
|
|
477
539
|
}
|
|
478
540
|
for (const name of names.sort()) {
|
|
479
|
-
if (!
|
|
480
|
-
fail("quality", name, `one of ${
|
|
541
|
+
if (!isOneOf(QUALITY_FORMATS, name)) {
|
|
542
|
+
fail("quality", name, `one of ${QUALITY_FORMATS.join(", ")}`);
|
|
481
543
|
}
|
|
482
544
|
const value = entries[name];
|
|
483
545
|
parts.push(`${name}:${value === "auto" ? "auto" : intIn("quality", value, 1, 100)}`);
|
|
@@ -496,7 +558,7 @@ export const filter = {
|
|
|
496
558
|
* format cannot honour throws here, like the server's 400.
|
|
497
559
|
*/
|
|
498
560
|
format(format, options = {}) {
|
|
499
|
-
if (!IMAGE_FORMATS
|
|
561
|
+
if (!isOneOf(IMAGE_FORMATS, format)) {
|
|
500
562
|
fail("format", format, `one of ${IMAGE_FORMATS.join(", ")}`);
|
|
501
563
|
}
|
|
502
564
|
// The output segment is the canonical spelling: the
|
|
@@ -512,8 +574,8 @@ export const filter = {
|
|
|
512
574
|
if (options.progressive)
|
|
513
575
|
args.push("progressive");
|
|
514
576
|
if (options.subsampling !== undefined) {
|
|
515
|
-
if (!
|
|
516
|
-
fail("subsampling", options.subsampling,
|
|
577
|
+
if (!isOneOf(JPEG_SUBSAMPLINGS, options.subsampling)) {
|
|
578
|
+
fail("subsampling", options.subsampling, `one of ${JPEG_SUBSAMPLINGS.join(", ")}`);
|
|
517
579
|
}
|
|
518
580
|
args.push(`subsampling:${options.subsampling}`);
|
|
519
581
|
}
|
|
@@ -567,7 +629,7 @@ export const filter = {
|
|
|
567
629
|
* `studio("product")` are the same string.
|
|
568
630
|
*/
|
|
569
631
|
studio(mode, options = {}) {
|
|
570
|
-
if (!STUDIO_MODES
|
|
632
|
+
if (!isOneOf(STUDIO_MODES, mode)) {
|
|
571
633
|
fail("studio mode", mode, `one of ${STUDIO_MODES.join(", ")}`);
|
|
572
634
|
}
|
|
573
635
|
const { bg, shadow, pad } = options;
|
|
@@ -577,11 +639,11 @@ export const filter = {
|
|
|
577
639
|
const parts = [mode];
|
|
578
640
|
if (mode === "product") {
|
|
579
641
|
if (bg !== undefined) {
|
|
580
|
-
const value =
|
|
642
|
+
const value = isOneOf(STUDIO_BACKDROPS, bg) ? bg : hex6("studio bg", bg);
|
|
581
643
|
parts.push(`bg:${value}`);
|
|
582
644
|
}
|
|
583
645
|
if (shadow !== undefined) {
|
|
584
|
-
if (!STUDIO_SHADOWS
|
|
646
|
+
if (!isOneOf(STUDIO_SHADOWS, shadow)) {
|
|
585
647
|
fail("studio shadow", shadow, `one of ${STUDIO_SHADOWS.join(", ")}`);
|
|
586
648
|
}
|
|
587
649
|
if (shadow !== "soft")
|
|
@@ -597,15 +659,15 @@ export const filter = {
|
|
|
597
659
|
},
|
|
598
660
|
/** AI upscale by the given factor. */
|
|
599
661
|
upscale(factor) {
|
|
600
|
-
if (
|
|
601
|
-
fail("upscale factor", factor,
|
|
662
|
+
if (!isOneOf(UPSCALE_FACTORS, factor)) {
|
|
663
|
+
fail("upscale factor", factor, eitherOf(UPSCALE_FACTORS));
|
|
602
664
|
}
|
|
603
665
|
return `upscale(${factor})`;
|
|
604
666
|
},
|
|
605
667
|
/** Device pixel ratio the sizes are multiplied by. */
|
|
606
668
|
dpr(factor) {
|
|
607
|
-
if (!
|
|
608
|
-
fail("dpr", factor,
|
|
669
|
+
if (!isOneOf(DPR_FACTORS, factor)) {
|
|
670
|
+
fail("dpr", factor, eitherOf(DPR_FACTORS));
|
|
609
671
|
}
|
|
610
672
|
return `dpr(${num(factor)})`;
|
|
611
673
|
},
|
|
@@ -628,8 +690,8 @@ export const filter = {
|
|
|
628
690
|
return `border(${intIn("border width", width, 0, MAX_DIMENSION)},${hex6("border color", color)})`;
|
|
629
691
|
},
|
|
630
692
|
mask(shape) {
|
|
631
|
-
if (
|
|
632
|
-
fail("mask shape", shape,
|
|
693
|
+
if (!isOneOf(MASK_SHAPES, shape)) {
|
|
694
|
+
fail("mask shape", shape, eitherOf(MASK_SHAPES, true));
|
|
633
695
|
}
|
|
634
696
|
return `mask(${shape})`;
|
|
635
697
|
},
|
|
@@ -639,13 +701,13 @@ export const filter = {
|
|
|
639
701
|
monochrome(color) {
|
|
640
702
|
return `monochrome(${hex6("monochrome color", color)})`;
|
|
641
703
|
},
|
|
642
|
-
/** Mosaic block size in pixels: 1..
|
|
704
|
+
/** Mosaic block size in pixels: 1..{@link MAX_DIMENSION}. */
|
|
643
705
|
pixelate(blockSize) {
|
|
644
706
|
return `pixelate(${intIn("pixelate size", blockSize, 1, MAX_DIMENSION)})`;
|
|
645
707
|
},
|
|
646
708
|
flip(axis) {
|
|
647
|
-
if (
|
|
648
|
-
fail("flip axis", axis,
|
|
709
|
+
if (!isOneOf(FLIP_AXES, axis)) {
|
|
710
|
+
fail("flip axis", axis, eitherOf(FLIP_AXES, true));
|
|
649
711
|
}
|
|
650
712
|
return `flip(${axis})`;
|
|
651
713
|
},
|
|
@@ -667,7 +729,7 @@ export const filter = {
|
|
|
667
729
|
intIn("overlay x", x, -2147483648, 2147483647);
|
|
668
730
|
intIn("overlay y", y, -2147483648, 2147483647);
|
|
669
731
|
intIn("overlay alpha", alpha, 0, 100);
|
|
670
|
-
if (!BLEND_MODES
|
|
732
|
+
if (!isOneOf(BLEND_MODES, blend)) {
|
|
671
733
|
fail("overlay blend", blend, `one of ${BLEND_MODES.join(", ")}`);
|
|
672
734
|
}
|
|
673
735
|
if (url === "")
|
|
@@ -680,8 +742,8 @@ export const filter = {
|
|
|
680
742
|
* canonical spelling is always eight lowercase hex digits.
|
|
681
743
|
*/
|
|
682
744
|
text(content, size, color, anchor) {
|
|
683
|
-
if (!
|
|
684
|
-
fail("text anchor", anchor, `one of ${
|
|
745
|
+
if (!isOneOf(TEXT_ANCHORS, anchor)) {
|
|
746
|
+
fail("text anchor", anchor, `one of ${TEXT_ANCHORS.join(", ")}`);
|
|
685
747
|
}
|
|
686
748
|
if (content === "")
|
|
687
749
|
fail("text", content, "a non-empty label");
|
package/package.json
CHANGED
|
@@ -13,15 +13,23 @@
|
|
|
13
13
|
"name": "@crabcrop/url",
|
|
14
14
|
"keywords": ["image", "url", "signing", "hmac", "cdn", "crabcrop"],
|
|
15
15
|
"files": ["dist"],
|
|
16
|
+
"imports": {
|
|
17
|
+
"#crypto": {
|
|
18
|
+
"browser": "./dist/crypto/portable.js",
|
|
19
|
+
"node": "./dist/crypto/node.js",
|
|
20
|
+
"default": "./dist/crypto/portable.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
16
23
|
"publishConfig": { "access": "public" },
|
|
17
24
|
"repository": { "type": "git", "url": "git+https://github.com/dayvson/crabcrop.git", "directory": "sdks/typescript" },
|
|
18
25
|
"scripts": {
|
|
19
|
-
"build": "tsc",
|
|
26
|
+
"build": "tsc && tsc -p tsconfig.browser.json",
|
|
20
27
|
"prepack": "npm run build",
|
|
21
|
-
"
|
|
28
|
+
"pretest": "npm run build && tsc -p tsconfig.test.json",
|
|
29
|
+
"test": "node --test && node --conditions=browser --test"
|
|
22
30
|
},
|
|
23
31
|
"type": "module",
|
|
24
|
-
"version": "0.
|
|
32
|
+
"version": "0.10.0",
|
|
25
33
|
"devDependencies": {
|
|
26
34
|
"@types/node": "^26.6.5",
|
|
27
35
|
"typescript": "^7.0.2"
|