@capacms/sdk 1.0.0-next.10 → 1.0.0-next.11

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.
@@ -113,6 +113,13 @@ export interface ImageParams {
113
113
  dpr: number;
114
114
  upscale: boolean;
115
115
  keepMetadata: boolean;
116
+ /**
117
+ * `fp` and `rect` (ENG-5959), read by `parseFocalParams` and only for a
118
+ * project with the focal point and crop on; absent otherwise, and then the
119
+ * two are unknown keys like any other.
120
+ */
121
+ focalPoint?: FocalPoint;
122
+ rect?: CropRect;
116
123
  /** True when any parameter that changes the bytes was supplied. */
117
124
  wantsTransform: boolean;
118
125
  }
@@ -154,7 +161,16 @@ export interface CanonicalResult {
154
161
  *
155
162
  * @param rawQuery the query string as received, without the leading `?`
156
163
  */
157
- export declare function canonicalise(rawQuery: string, params: ImageParams): CanonicalResult;
164
+ export declare function canonicalise(rawQuery: string, params: ImageParams, options?: CanonicalOptions): CanonicalResult;
165
+ export interface CanonicalOptions {
166
+ /**
167
+ * True when `fp` and `rect` are parameters here (the project has the focal
168
+ * point and crop on): they are then spelled from `params` like the others,
169
+ * and their presence enables canonicalisation. False or absent, they are
170
+ * unknown keys, kept verbatim, exactly as before ENG-5959.
171
+ */
172
+ focal?: boolean;
173
+ }
158
174
  /**
159
175
  * The canonical spelling itself, without `canonicalise`'s gate.
160
176
  *
@@ -168,7 +184,7 @@ export declare function canonicalise(rawQuery: string, params: ImageParams): Can
168
184
  * @param rawQuery the query string, without the leading `?`; read only for the
169
185
  * keys this module does not know, which are kept
170
186
  */
171
- export declare function canonicalQuery(rawQuery: string, params: ImageParams): string;
187
+ export declare function canonicalQuery(rawQuery: string, params: ImageParams, options?: CanonicalOptions): string;
172
188
  /**
173
189
  * A stable string identifying the transform, for the ETag.
174
190
  *
@@ -188,3 +204,111 @@ export declare function buildSignature(params: ImageParams, resolvedFormat?: Con
188
204
  * preference, so an entry carrying it is skipped rather than matched.
189
205
  */
190
206
  export declare function resolveAutoFormat(accept: string | undefined | null): "avif" | "webp" | null;
207
+ /** A focal point: fractions of the oriented image, from the left and the top. */
208
+ export interface FocalPoint {
209
+ x: number;
210
+ y: number;
211
+ }
212
+ /** A crop: fractions of the oriented image. */
213
+ export interface CropRect {
214
+ x: number;
215
+ y: number;
216
+ width: number;
217
+ height: number;
218
+ }
219
+ /** `fp` and `rect`: parameters only where the focal point and crop are on. */
220
+ export declare const FOCAL_PARAMS: Set<string>;
221
+ /** Decimal places a fraction keeps: a ten-thousandth, under a pixel up to 10,000 px. */
222
+ export declare const FRACTION_DECIMALS = 4;
223
+ /** A number rounded to FRACTION_DECIMALS. */
224
+ export declare function roundFraction(n: number): number;
225
+ /**
226
+ * A focal point from stored metadata or a request body, or null when it is
227
+ * not one: an object whose `x` and `y` are numbers from 0 to 1.
228
+ */
229
+ export declare function readFocalPoint(value: unknown): FocalPoint | null;
230
+ /**
231
+ * A crop from stored metadata or a request body, or null when it is not one:
232
+ * `x`, `y`, `width` and `height` from 0 to 1, a width and a height above 0,
233
+ * and inside the image.
234
+ */
235
+ export declare function readCrop(value: unknown): CropRect | null;
236
+ /**
237
+ * A focal point exactly as the api stores one (`normaliseFocalPatch` in
238
+ * apps/api routes/v2/file-uploads.ts): `{ x, y }` and no other key, numbers
239
+ * from 0 to 1. Stricter than `readFocalPoint`, which reads one out of any
240
+ * object that has them: this is the test for "ENG-5959 wrote this", which a
241
+ * replace carries over and the legacy routes hide. Anything else under the
242
+ * name is a project's own metadata and is left alone.
243
+ */
244
+ export declare function isStoredFocalPoint(value: unknown): value is FocalPoint;
245
+ /** A crop exactly as the api stores one: `{ x, y, width, height }` and no other key. See `isStoredFocalPoint`. */
246
+ export declare function isStoredCrop(value: unknown): value is CropRect;
247
+ export type FocalParseResult = {
248
+ ok: true;
249
+ focalPoint?: FocalPoint;
250
+ rect?: CropRect;
251
+ } | {
252
+ ok: false;
253
+ rejection: ParamRejection;
254
+ };
255
+ /**
256
+ * `fp` and `rect`, for a project with the focal point and crop on. The route
257
+ * calls it after it knows the file's project; anywhere else the two are
258
+ * unknown keys and this is never called.
259
+ */
260
+ export declare function parseFocalParams(query: Record<string, unknown>): FocalParseResult;
261
+ /** What the file says, from its `file_uploads.metadata`. */
262
+ export interface StoredFocal {
263
+ focalPoint: FocalPoint | null;
264
+ crop: CropRect | null;
265
+ }
266
+ /**
267
+ * The crop and focal point a request applies: the URL's, else the file's,
268
+ * and the file's only for a `fit=cover` crop to both a width and a height.
269
+ * A blur placeholder keeps its own square geometry and applies only a `rect`
270
+ * the URL names.
271
+ */
272
+ /**
273
+ * A crop to a shape: `fit=cover` with a width and a height, and no blur. The
274
+ * one request the file's stored focal point and crop apply to.
275
+ */
276
+ export declare function isCoverCrop(params: ImageParams): boolean;
277
+ /**
278
+ * True when this request's bytes depend on the file's STORED focal point or
279
+ * crop: a cover crop that does not name both `fp` and `rect` itself. Its
280
+ * bytes change under the same URL when an editor saves either, so a browser
281
+ * must not keep them as long as an immutable variant (`GET /files/*`).
282
+ */
283
+ export declare function followsStoredFocal(params: ImageParams): boolean;
284
+ export declare function appliedFocal(params: ImageParams, stored: StoredFocal | null): {
285
+ rect: CropRect | null;
286
+ focalPoint: FocalPoint | null;
287
+ };
288
+ /** A region of the oriented source, in whole pixels, for sharp's `extract`. */
289
+ export interface PixelRegion {
290
+ left: number;
291
+ top: number;
292
+ width: number;
293
+ height: number;
294
+ }
295
+ /**
296
+ * The part of the source to cut out before the resize, or null for none.
297
+ *
298
+ * `source` is the image as a person sees it. `target` is the `fit=cover` box
299
+ * (width and height after dpr), or null for any other request. The crop is cut
300
+ * first; with a target and a focal point, the window of the target's shape
301
+ * that a cover resize would keep is then moved, inside the crop, so its centre
302
+ * is as close to the focal point as the crop allows. Without a focal point the
303
+ * crop alone is returned and the resize centres in it as it always has.
304
+ *
305
+ * The window is the largest of the target's shape that fits the crop, so the
306
+ * resize that follows scales it to the target without cutting anything more.
307
+ */
308
+ export declare function focalRegion(source: {
309
+ width: number;
310
+ height: number;
311
+ }, target: {
312
+ width: number;
313
+ height: number;
314
+ } | null, rect: CropRect | null, focalPoint: FocalPoint | null): PixelRegion | null;
@@ -312,6 +312,18 @@ function num(n) {
312
312
  function encodePart(text) {
313
313
  return encodeURIComponent(text).replace(/'/g, "%27");
314
314
  }
315
+ /**
316
+ * `fp` and `rect` are comma lists, spelled with bare commas: a browser sends a
317
+ * query's `,` as it is, so `fp=0.25,0.5` comes back byte for byte, and reads
318
+ * better than `fp=0.25%2C0.5`. Only where they are parameters; an unknown key
319
+ * keeps `encodePart`'s spelling, as before.
320
+ */
321
+ function listValue(key, options) {
322
+ return options.focal === true && FOCAL_PARAMS.has(key);
323
+ }
324
+ function encodeList(value) {
325
+ return value.split(",").map(encodePart).join(",");
326
+ }
315
327
  /**
316
328
  * The canonical spelling of a query, so `?width=200&format=webp` and
317
329
  * `?format=webp&width=200` are one edge object rather than two.
@@ -324,12 +336,12 @@ function encodePart(text) {
324
336
  *
325
337
  * @param rawQuery the query string as received, without the leading `?`
326
338
  */
327
- export function canonicalise(rawQuery, params) {
339
+ export function canonicalise(rawQuery, params, options = {}) {
328
340
  const received = new URLSearchParams(rawQuery);
329
- const usesNewParam = [...received.keys()].some((k) => NEW_PARAMS.has(k));
341
+ const usesNewParam = [...received.keys()].some((k) => NEW_PARAMS.has(k) || (options.focal === true && FOCAL_PARAMS.has(k)));
330
342
  if (!usesNewParam)
331
343
  return { query: rawQuery, isCanonical: true };
332
- const query = canonicalQuery(rawQuery, params);
344
+ const query = canonicalQuery(rawQuery, params, options);
333
345
  return { query, isCanonical: query === rawQuery };
334
346
  }
335
347
  /**
@@ -345,7 +357,7 @@ export function canonicalise(rawQuery, params) {
345
357
  * @param rawQuery the query string, without the leading `?`; read only for the
346
358
  * keys this module does not know, which are kept
347
359
  */
348
- export function canonicalQuery(rawQuery, params) {
360
+ export function canonicalQuery(rawQuery, params, options = {}) {
349
361
  const received = new URLSearchParams(rawQuery);
350
362
  const keys = [...new Set([...received.keys()])];
351
363
  const out = new Map();
@@ -377,6 +389,12 @@ export function canonicalQuery(rawQuery, params) {
377
389
  out.set("upscale", "1");
378
390
  if (params.keepMetadata)
379
391
  out.set("keepMetadata", "1");
392
+ if (options.focal === true) {
393
+ if (params.focalPoint !== undefined)
394
+ out.set("fp", fractions([params.focalPoint.x, params.focalPoint.y]));
395
+ if (params.rect !== undefined)
396
+ out.set("rect", fractions([params.rect.x, params.rect.y, params.rect.width, params.rect.height]));
397
+ }
380
398
  // Unknown keys are preserved verbatim (first value wins, repeats collapse),
381
399
  // so a cache-buster survives the redirect instead of being silently dropped.
382
400
  //
@@ -386,6 +404,8 @@ export function canonicalQuery(rawQuery, params) {
386
404
  for (const key of keys) {
387
405
  if (LEGACY_PARAMS.has(key) || NEW_PARAMS.has(key))
388
406
  continue;
407
+ if (options.focal === true && FOCAL_PARAMS.has(key))
408
+ continue;
389
409
  const value = received.get(key) ?? "";
390
410
  if (key === "" && value === "")
391
411
  continue;
@@ -393,7 +413,7 @@ export function canonicalQuery(rawQuery, params) {
393
413
  }
394
414
  const sorted = [...out.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
395
415
  return sorted
396
- .map(([k, v]) => (v === "" ? encodePart(k) : `${encodePart(k)}=${encodePart(v)}`))
416
+ .map(([k, v]) => (v === "" ? encodePart(k) : `${encodePart(k)}=${listValue(k, options) ? encodeList(v) : encodePart(v)}`))
397
417
  .join("&");
398
418
  }
399
419
  /**
@@ -424,6 +444,16 @@ export function buildSignature(params, resolvedFormat) {
424
444
  parts.push(`q${params.quality}`);
425
445
  if (params.keepMetadata)
426
446
  parts.push("meta");
447
+ // The crop and the focal point this transform applies (`appliedFocal`), from
448
+ // the URL or from the file, so a new focal point on the file is a new ETag
449
+ // under the same URL. Colons, not the URL's commas: If-None-Match is a
450
+ // comma-separated list, and an ETag with a comma in it never matches its
451
+ // own revalidation (files.ts ifNoneMatchSatisfied), so every one would be a
452
+ // full 200.
453
+ if (params.rect !== undefined)
454
+ parts.push(`r${fractions([params.rect.x, params.rect.y, params.rect.width, params.rect.height], ":")}`);
455
+ if (params.focalPoint !== undefined)
456
+ parts.push(`p${fractions([params.focalPoint.x, params.focalPoint.y], ":")}`);
427
457
  return parts.join("_") || "raw";
428
458
  }
429
459
  /**
@@ -459,3 +489,192 @@ export function resolveAutoFormat(accept) {
459
489
  return "webp";
460
490
  return null;
461
491
  }
492
+ /** `fp` and `rect`: parameters only where the focal point and crop are on. */
493
+ export const FOCAL_PARAMS = new Set(["fp", "rect"]);
494
+ /** Decimal places a fraction keeps: a ten-thousandth, under a pixel up to 10,000 px. */
495
+ export const FRACTION_DECIMALS = 4;
496
+ /** Slack for `x + width <= 1` after rounding to FRACTION_DECIMALS. */
497
+ const FRACTION_EPSILON = 1e-9;
498
+ /** A number rounded to FRACTION_DECIMALS. */
499
+ export function roundFraction(n) {
500
+ const scale = 10 ** FRACTION_DECIMALS;
501
+ return Math.round(n * scale) / scale;
502
+ }
503
+ function fraction(value) {
504
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)
505
+ return null;
506
+ return roundFraction(value);
507
+ }
508
+ function plainObject(value) {
509
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
510
+ }
511
+ /**
512
+ * A focal point from stored metadata or a request body, or null when it is
513
+ * not one: an object whose `x` and `y` are numbers from 0 to 1.
514
+ */
515
+ export function readFocalPoint(value) {
516
+ const v = plainObject(value);
517
+ if (!v)
518
+ return null;
519
+ const x = fraction(v.x);
520
+ const y = fraction(v.y);
521
+ return x === null || y === null ? null : { x, y };
522
+ }
523
+ /**
524
+ * A crop from stored metadata or a request body, or null when it is not one:
525
+ * `x`, `y`, `width` and `height` from 0 to 1, a width and a height above 0,
526
+ * and inside the image.
527
+ */
528
+ export function readCrop(value) {
529
+ const v = plainObject(value);
530
+ if (!v)
531
+ return null;
532
+ const x = fraction(v.x);
533
+ const y = fraction(v.y);
534
+ const width = fraction(v.width);
535
+ const height = fraction(v.height);
536
+ if (x === null || y === null || width === null || height === null)
537
+ return null;
538
+ if (width <= 0 || height <= 0)
539
+ return null;
540
+ if (x + width > 1 + FRACTION_EPSILON || y + height > 1 + FRACTION_EPSILON)
541
+ return null;
542
+ return { x, y, width, height };
543
+ }
544
+ /** True when `value` has exactly these own keys, in any order. */
545
+ function hasExactly(value, keys) {
546
+ const own = Object.keys(value);
547
+ return own.length === keys.length && keys.every((key) => own.includes(key));
548
+ }
549
+ /**
550
+ * A focal point exactly as the api stores one (`normaliseFocalPatch` in
551
+ * apps/api routes/v2/file-uploads.ts): `{ x, y }` and no other key, numbers
552
+ * from 0 to 1. Stricter than `readFocalPoint`, which reads one out of any
553
+ * object that has them: this is the test for "ENG-5959 wrote this", which a
554
+ * replace carries over and the legacy routes hide. Anything else under the
555
+ * name is a project's own metadata and is left alone.
556
+ */
557
+ export function isStoredFocalPoint(value) {
558
+ const v = plainObject(value);
559
+ return v !== null && hasExactly(v, ["x", "y"]) && readFocalPoint(v) !== null;
560
+ }
561
+ /** A crop exactly as the api stores one: `{ x, y, width, height }` and no other key. See `isStoredFocalPoint`. */
562
+ export function isStoredCrop(value) {
563
+ const v = plainObject(value);
564
+ return v !== null && hasExactly(v, ["x", "y", "width", "height"]) && readCrop(v) !== null;
565
+ }
566
+ /** Numbers as the canonical URL spells them: comma separated, no trailing zeros. */
567
+ function fractions(values, separator = ",") {
568
+ return values.map((n) => String(roundFraction(n))).join(separator);
569
+ }
570
+ /** `0.25,0.5` into numbers, or null when any part is not a plain decimal. */
571
+ function decimalList(text, count) {
572
+ const parts = text.split(",");
573
+ if (parts.length !== count)
574
+ return null;
575
+ const out = [];
576
+ for (const part of parts) {
577
+ const n = strictNumber(part);
578
+ if (n === null)
579
+ return null;
580
+ out.push(n);
581
+ }
582
+ return out;
583
+ }
584
+ /**
585
+ * `fp` and `rect`, for a project with the focal point and crop on. The route
586
+ * calls it after it knows the file's project; anywhere else the two are
587
+ * unknown keys and this is never called.
588
+ */
589
+ export function parseFocalParams(query) {
590
+ const reject = (error, param) => ({ ok: false, rejection: { error, param } });
591
+ const fpRaw = single(query.fp, "fp");
592
+ if (!fpRaw.ok)
593
+ return { ok: false, rejection: fpRaw.rejection };
594
+ let focalPoint;
595
+ if (fpRaw.value !== undefined) {
596
+ const list = decimalList(fpRaw.value, 2);
597
+ const read = list ? readFocalPoint({ x: list[0], y: list[1] }) : null;
598
+ if (!read)
599
+ return reject("`fp` must be two numbers from 0 to 1, x,y", "fp");
600
+ focalPoint = read;
601
+ }
602
+ const rectRaw = single(query.rect, "rect");
603
+ if (!rectRaw.ok)
604
+ return { ok: false, rejection: rectRaw.rejection };
605
+ let rect;
606
+ if (rectRaw.value !== undefined) {
607
+ const list = decimalList(rectRaw.value, 4);
608
+ const read = list ? readCrop({ x: list[0], y: list[1], width: list[2], height: list[3] }) : null;
609
+ if (!read) {
610
+ return reject("`rect` must be four numbers from 0 to 1, x,y,width,height, with a width and a height above 0, inside the image", "rect");
611
+ }
612
+ rect = read;
613
+ }
614
+ return { ok: true, focalPoint, rect };
615
+ }
616
+ /**
617
+ * The crop and focal point a request applies: the URL's, else the file's,
618
+ * and the file's only for a `fit=cover` crop to both a width and a height.
619
+ * A blur placeholder keeps its own square geometry and applies only a `rect`
620
+ * the URL names.
621
+ */
622
+ /**
623
+ * A crop to a shape: `fit=cover` with a width and a height, and no blur. The
624
+ * one request the file's stored focal point and crop apply to.
625
+ */
626
+ export function isCoverCrop(params) {
627
+ return params.fit === "cover" && params.width !== undefined && params.height !== undefined && params.blur === undefined;
628
+ }
629
+ /**
630
+ * True when this request's bytes depend on the file's STORED focal point or
631
+ * crop: a cover crop that does not name both `fp` and `rect` itself. Its
632
+ * bytes change under the same URL when an editor saves either, so a browser
633
+ * must not keep them as long as an immutable variant (`GET /files/*`).
634
+ */
635
+ export function followsStoredFocal(params) {
636
+ return isCoverCrop(params) && (params.focalPoint === undefined || params.rect === undefined);
637
+ }
638
+ export function appliedFocal(params, stored) {
639
+ const cover = isCoverCrop(params);
640
+ const rect = params.rect ?? (cover ? stored?.crop ?? null : null);
641
+ const focalPoint = cover ? params.focalPoint ?? stored?.focalPoint ?? null : null;
642
+ return { rect, focalPoint };
643
+ }
644
+ /**
645
+ * The part of the source to cut out before the resize, or null for none.
646
+ *
647
+ * `source` is the image as a person sees it. `target` is the `fit=cover` box
648
+ * (width and height after dpr), or null for any other request. The crop is cut
649
+ * first; with a target and a focal point, the window of the target's shape
650
+ * that a cover resize would keep is then moved, inside the crop, so its centre
651
+ * is as close to the focal point as the crop allows. Without a focal point the
652
+ * crop alone is returned and the resize centres in it as it always has.
653
+ *
654
+ * The window is the largest of the target's shape that fits the crop, so the
655
+ * resize that follows scales it to the target without cutting anything more.
656
+ */
657
+ export function focalRegion(source, target, rect, focalPoint) {
658
+ const W = Math.max(1, Math.round(source.width));
659
+ const H = Math.max(1, Math.round(source.height));
660
+ let region = { left: 0, top: 0, width: W, height: H };
661
+ if (rect) {
662
+ const left = Math.min(W - 1, Math.round(rect.x * W));
663
+ const top = Math.min(H - 1, Math.round(rect.y * H));
664
+ region = {
665
+ left,
666
+ top,
667
+ width: Math.max(1, Math.min(W - left, Math.round(rect.width * W))),
668
+ height: Math.max(1, Math.min(H - top, Math.round(rect.height * H))),
669
+ };
670
+ }
671
+ if (!target || !focalPoint)
672
+ return rect ? region : null;
673
+ const scale = Math.max(target.width / region.width, target.height / region.height);
674
+ const width = Math.max(1, Math.min(region.width, Math.round(target.width / scale)));
675
+ const height = Math.max(1, Math.min(region.height, Math.round(target.height / scale)));
676
+ const clamp = (value, lo, hi) => Math.min(hi, Math.max(lo, value));
677
+ const left = clamp(Math.round(focalPoint.x * W - width / 2), region.left, region.left + region.width - width);
678
+ const top = clamp(Math.round(focalPoint.y * H - height / 2), region.top, region.top + region.height - height);
679
+ return { left, top, width, height };
680
+ }
@@ -9,21 +9,33 @@
9
9
  * from the rules the API serves by (`canonicalQuery` and `parseImageParams`,
10
10
  * compiled in from @capa/shared at build time), so the two cannot drift.
11
11
  *
12
- * Three rules beside the API's:
12
+ * Four rules beside the API's:
13
13
  * - Nothing is enlarged. When the image's own width is known (the `/api/`
14
14
  * media shape carries it), a request for more pixels than it has is brought
15
15
  * down to its size, keeping the requested shape.
16
16
  * - `format=auto` is only sent when asked for.
17
17
  * - A URL that is not a Capa image comes back unchanged.
18
+ * - A crop to a shape (`fit: "cover"` with a width and a height) of a media
19
+ * value that carries an editor's focal point or crop names them in the URL
20
+ * (`fp`, `rect`), so moving the focal point gives a new URL rather than a
21
+ * copy cached under the old one. A media value without them, and a URL or
22
+ * a key without `fp` or `rect`, builds exactly the URL it always did.
18
23
  *
19
24
  * A stored URL on `api.capacms.com/files/` (older uploads) names the same file
20
25
  * as the CDN: the CDN fetches from that host. Built URLs go to the CDN host,
21
26
  * where a resized copy is cached at the edge rather than made again by the
22
27
  * origin on every request.
23
28
  */
24
- import { MAX_OUTPUT_EDGE, type ImageFit, type ImageFormat } from "./shared-params.generated.js";
29
+ import { MAX_OUTPUT_EDGE, type CropRect, type FocalPoint, type ImageFit, type ImageFormat } from "./shared-params.generated.js";
25
30
  export type { ImageFit, ImageFormat };
26
31
  export { MAX_OUTPUT_EDGE };
32
+ /**
33
+ * The spot in an image an editor marked as the one that matters most, as
34
+ * fractions of the image from 0 to 1: `x` from the left, `y` from the top.
35
+ */
36
+ export type ImageFocalPoint = FocalPoint;
37
+ /** The part of an image an editor chose to show, as fractions of the image from 0 to 1. */
38
+ export type ImageCrop = CropRect;
27
39
  /** Where Capa serves files. A media `url` from the API starts with this and `/files/`. */
28
40
  export declare const CAPA_CDN_ORIGIN = "https://cdn.capacms.com";
29
41
  /**
@@ -43,6 +55,14 @@ export interface ImageLike {
43
55
  height?: number | null;
44
56
  /** The file's kind. Anything but `image` (or a missing kind) is returned unchanged. */
45
57
  type?: string | null;
58
+ /**
59
+ * The editor's focal point, where `/api/` sends one. A crop to a shape
60
+ * (`fit: "cover"` with a width and a height) centres on it, and its URL
61
+ * names it as `fp`.
62
+ */
63
+ focalPoint?: ImageFocalPoint | null;
64
+ /** The editor's crop, where `/api/` sends one. A crop to a shape stays inside it, and its URL names it as `rect`. */
65
+ crop?: ImageCrop | null;
46
66
  }
47
67
  /** A media value, a full CDN URL, or a file key (`sunns_1790971326210_d54fed020806.jpg`). */
48
68
  export type ImageSource = string | ImageLike;
@@ -66,6 +86,14 @@ export interface ImageOptions {
66
86
  * currently returns JPEG, so use `webp` until that is fixed.
67
87
  */
68
88
  format?: ImageFormat;
89
+ /**
90
+ * The focal point for a crop to a shape (`fit: "cover"` with a width and a
91
+ * height), in place of the media value's. Other requests have nothing to
92
+ * centre, so it is left out of their URL.
93
+ */
94
+ focalPoint?: ImageFocalPoint | null;
95
+ /** A crop, in place of the media value's. It applies to any resize, and on its own crops the image. */
96
+ crop?: ImageCrop | null;
69
97
  }
70
98
  /** The options `srcSet` takes: each candidate's width comes from its list, and its height from `aspectRatio`. */
71
99
  export interface SrcSetOptions {
@@ -74,6 +102,10 @@ export interface SrcSetOptions {
74
102
  fit?: ImageFit;
75
103
  quality?: number;
76
104
  format?: ImageFormat;
105
+ /** As `imageUrl`'s: applies to each candidate cropped to a shape (`aspectRatio` with `fit: "cover"`). */
106
+ focalPoint?: ImageFocalPoint | null;
107
+ /** As `imageUrl`'s: applies to every candidate. */
108
+ crop?: ImageCrop | null;
77
109
  }
78
110
  /**
79
111
  * The URL of a Capa image, resized as `options` say, spelled exactly as Capa's
@@ -118,3 +150,38 @@ export declare function srcSet(image: ImageSource | null | undefined, widths: re
118
150
  * ```
119
151
  */
120
152
  export declare function sizes(breakpoints: Readonly<Record<number, string>>, fallback?: string): string;
153
+ /**
154
+ * What `/api/` sends of an image's placeholders, where Capa makes them: a
155
+ * tiny blurred copy as a data URL, and its colours.
156
+ */
157
+ export interface PlaceholderLike {
158
+ blurDataURL?: string | null;
159
+ averageColor?: string | null;
160
+ dominantColor?: string | null;
161
+ }
162
+ /** next/image's `placeholder` and `blurDataURL` props, to spread onto an `<Image>`. */
163
+ export type ImagePlaceholder = {
164
+ placeholder: "blur";
165
+ blurDataURL: string;
166
+ } | {
167
+ placeholder: "empty";
168
+ };
169
+ /**
170
+ * next/image's placeholder props for a media value: `placeholder="blur"` with
171
+ * its `blurDataURL` when it has one, and `placeholder="empty"` otherwise, so
172
+ * the result can always be spread:
173
+ *
174
+ * ```tsx
175
+ * <Image src={imageUrl(hero)} alt={hero.alt ?? ""} width={1200} height={800} {...imagePlaceholder(hero)} />
176
+ * ```
177
+ */
178
+ export declare function imagePlaceholder(image: PlaceholderLike | null | undefined): ImagePlaceholder;
179
+ /**
180
+ * A colour to paint an image's space with while it loads, as `#rrggbb`: its
181
+ * average colour, else its dominant one, else undefined.
182
+ *
183
+ * ```tsx
184
+ * <div style={{ backgroundColor: placeholderColor(hero) }}>...</div>
185
+ * ```
186
+ */
187
+ export declare function placeholderColor(image: PlaceholderLike | null | undefined): string | undefined;