@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
48 lines (47 loc) • 1.69 kB
TypeScript
import type { FieldState, Simplify } from "./types";
/**
* An individual image within an image field. The base image and each thumbnail
* uses this type.
*
* @typeParam State - State of the field which determines its shape.
*
* @see {@link ImageField} for a full image field type.
*/
export type ImageFieldImage<State extends FieldState = FieldState> = State extends "empty" ? EmptyImageFieldImage : FilledImageFieldImage;
export interface FilledImageFieldImage {
id: string;
url: string;
dimensions: {
width: number;
height: number;
};
edit: {
x: number;
y: number;
zoom: number;
background: string;
};
alt: string | null;
copyright: string | null;
}
export interface EmptyImageFieldImage {
id?: null;
url?: null;
dimensions?: null;
edit?: null;
alt?: null;
copyright?: null;
}
/**
* An image field.
*
* **Note**: Passing `null` to the `ThumbnailNames` parameter is deprecated and
* will be removed in a future version. Use `never` instead.
*
* @typeParam ThumbnailNames - Names of thumbnails. If the field does not
* contain thumbnails, `never` can be used to "disable" thumbnail fields.
* @typeParam State - State of the field which determines its shape.
*
* @see Image field documentation: {@link https://prismic.io/docs/image}
*/
export type ImageField<ThumbnailNames extends string | null = never, State extends FieldState = FieldState> = Simplify<State extends "filled" ? ImageFieldImage<State> & Record<Extract<ThumbnailNames, string>, ImageFieldImage<State>> : ImageFieldImage<State> & Record<Extract<ThumbnailNames, string>, ImageFieldImage<State>>>;