@nitida/asset-client 0.16.0 → 0.16.2
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/AGENTS.md +4 -4
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -22
- package/dist/index.d.ts +38 -22
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +9 -6
- package/src/slots.ts +6 -9
- package/src/transform.ts +18 -20
package/src/transform.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* On-the-fly transform URL builder.
|
|
3
3
|
*
|
|
4
4
|
* Mirrors the server's DSL canonicalizer byte-for-byte so a URL generated
|
|
5
|
-
* here hashes to the same
|
|
5
|
+
* here hashes to the same cache key as the server's canonical form.
|
|
6
6
|
*
|
|
7
|
-
* Canonicalization rules (
|
|
8
|
-
* `apps/asset-manager/src/features/assets/transform.dsl.ts`):
|
|
7
|
+
* Canonicalization rules (kept in sync with the server):
|
|
9
8
|
* - Drop entries whose value is `undefined`
|
|
10
9
|
* - Sort keys alphabetically
|
|
11
10
|
* - Numbers rendered without leading zeros or trailing dots
|
|
@@ -23,7 +22,7 @@ import type { AssetDTO } from "./index";
|
|
|
23
22
|
import { getCdnBase } from "./index";
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
* Widths the CDN edge whitelists (DoS guard
|
|
25
|
+
* Widths the CDN edge whitelists (DoS guard).
|
|
27
26
|
* Requesting any OTHER width returns HTTP 400 at the edge (unsigned URLs). These are the
|
|
28
27
|
* 1× base ladder values; DPR ×2/×3 multiples are applied + whitelisted server-side. Import
|
|
29
28
|
* this instead of hardcoding magic widths so an unsupported size is caught in review/IDE.
|
|
@@ -77,9 +76,9 @@ export type TransformOptions = {
|
|
|
77
76
|
height?: number;
|
|
78
77
|
/** Resize fit mode. Default `cover` server-side. */
|
|
79
78
|
fit?: TransformFit;
|
|
80
|
-
/** Crop gravity. `auto`
|
|
79
|
+
/** Crop gravity. `auto` picks the region with the most visual salience. */
|
|
81
80
|
gravity?: TransformGravity;
|
|
82
|
-
/** Output format. `auto` → policy decides
|
|
81
|
+
/** Output format. `auto` → the platform's policy decides. */
|
|
83
82
|
format?: TransformFormat;
|
|
84
83
|
/** Output quality. `auto` → format-specific default. */
|
|
85
84
|
quality?: "auto" | number;
|
|
@@ -90,16 +89,15 @@ export type TransformOptions = {
|
|
|
90
89
|
*
|
|
91
90
|
* - `removebg`: remove the background; output is a transparent PNG
|
|
92
91
|
* of the foreground subject. Forces `format=png` regardless of
|
|
93
|
-
* other format hints.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* from R2 — no inference, no per-image cost.
|
|
92
|
+
* other format hints. A single cache miss per (sha, dsl) tuple;
|
|
93
|
+
* subsequent identical DSLs serve from cache — no inference, no
|
|
94
|
+
* per-image cost.
|
|
97
95
|
*
|
|
98
|
-
* - `genfill`: aspect-extension outpaint
|
|
99
|
-
*
|
|
96
|
+
* - `genfill`: aspect-extension outpaint. Requires BOTH `width`
|
|
97
|
+
* and `height` — the server
|
|
100
98
|
* fits the source centered into the target canvas and outpaints
|
|
101
99
|
* the gutters. Output is PNG (forced) at exactly target dims.
|
|
102
|
-
* ~$0.05/image first time; same
|
|
100
|
+
* ~$0.05/image first time; same cache as removebg after.
|
|
103
101
|
* Primary use case: building OG cards (1200×630) from portrait
|
|
104
102
|
* listing photos without awkward edge mirroring.
|
|
105
103
|
*/
|
|
@@ -121,7 +119,7 @@ export type TransformOptions = {
|
|
|
121
119
|
* the escape hatch for SIGNED URLs that need an off-ladder custom width.
|
|
122
120
|
*
|
|
123
121
|
* The edge whitelist only rejects off-ladder widths on UNSIGNED URLs; a valid
|
|
124
|
-
* `?sig=` earns the whitelist bypass at the
|
|
122
|
+
* `?sig=` earns the whitelist bypass at the edge (the server still
|
|
125
123
|
* does the real HMAC check). So a custom width is ONLY safe when the URL is
|
|
126
124
|
* signed — hence this type is accepted exclusively by the signing helpers
|
|
127
125
|
* ({@link getSignedTransformUrl} / `aq.transform(asset, opts, { sign: true })`),
|
|
@@ -181,10 +179,10 @@ export function serializeTransform(opts: SignedTransformOptions): string {
|
|
|
181
179
|
function extForOptions(opts: SignedTransformOptions): string {
|
|
182
180
|
// effect=removebg forces PNG output server-side (needs alpha).
|
|
183
181
|
if (opts.effect === "removebg") return "png";
|
|
184
|
-
// effect=genfill defaults to WebP (12× lighter than the raw
|
|
182
|
+
// effect=genfill defaults to WebP (12× lighter than the raw generated
|
|
185
183
|
// PNG output with no visible loss at q=85). Explicit `format=png`
|
|
186
184
|
// opts back into lossless for print / marketing fold-outs. The server
|
|
187
|
-
// re-encodes
|
|
185
|
+
// re-encodes the generated PNG → target format before caching.
|
|
188
186
|
if (opts.effect === "genfill") {
|
|
189
187
|
switch (opts.format) {
|
|
190
188
|
case "png":
|
|
@@ -222,8 +220,8 @@ function extForOptions(opts: SignedTransformOptions): string {
|
|
|
222
220
|
* Build a transform URL for a VIDEO asset. Same DSL shape as image
|
|
223
221
|
* transforms; the server branches on the asset's `kind` column. Video
|
|
224
222
|
* URLs use `.mp4` (default) or `.webm` extension and on cache miss the
|
|
225
|
-
* server returns 202 Accepted while a
|
|
226
|
-
* subsequent GETs return 302 to the cached
|
|
223
|
+
* server returns 202 Accepted while a background job encodes the clip;
|
|
224
|
+
* subsequent GETs return 302 to the cached object.
|
|
227
225
|
*
|
|
228
226
|
* <video src={aq.transformVideo(asset, { width: 1080, height: 1920 })}
|
|
229
227
|
* autoPlay muted loop playsInline />
|
|
@@ -271,8 +269,8 @@ export function getVideoTransformUrl(
|
|
|
271
269
|
* }
|
|
272
270
|
* ```
|
|
273
271
|
*
|
|
274
|
-
* On first request the server returns 202 Accepted while a
|
|
275
|
-
*
|
|
272
|
+
* On first request the server returns 202 Accepted while a background
|
|
273
|
+
* job transcodes the ladder (typically 1-3 min for a 90 s source);
|
|
276
274
|
* subsequent requests get 302 to the cached master.m3u8. Keep the
|
|
277
275
|
* progressive MP4 as a fallback source for that window.
|
|
278
276
|
*
|