UNPKG

@adonis-agora/media

Version:

Media-library for AdonisJS — owner collections (MIME whitelist, single-file replace, ordering), image conversions (eager/lazy), pluggable content transformers (HLS video via mediabunny, metadata probe, image blur-up placeholder), and column attachments, a

88 lines • 4.33 kB
import type { ConversionPreset } from './image_processor.js'; import type { MediaRecord } from './media_record.js'; /** * Everything an `<img>` needs to render a stored image the way `next/image` does — a `srcset` of * the collection's sizes, the intrinsic dimensions to reserve layout, and the blur-up preview. * Plain JSON: hand it to the page as a prop (Inertia, a JSON API) and render it with * `<MediaImage image={...} />` from `@adonis-agora/media-react`, or spread it on an `<img>`. */ export interface ResponsiveImage { /** The widest candidate (or the original when there are none) — the `src` fallback. */ src: string; /** `"<url> 320w, <url> 960w"`. Absent when no candidate has a known width. */ srcSet?: string; /** Intrinsic width of the image as displayed (EXIF orientation applied). */ width?: number; /** Intrinsic height of the image as displayed. */ height?: number; /** Blur-up preview, when the collection declares `transformers.placeholder()`. */ placeholder?: { dataUrl: string; color: string; }; /** * The record's focal point (`setFocalPoint()`), for CSS crops: `<MediaImage>` turns it into * `object-position`, so `object-fit: cover` keeps the same part the server's crops keep. */ focalPoint?: { x: number; y: number; }; } export interface ResponsiveImageOptions { /** * Presets to offer as `srcset` candidates. Default: every preset of the collection. Presets that * would not be the same picture at another resolution are always left out — a `blur` preset, or * one whose fixed `width`×`height` crops to a different aspect ratio than the original. */ conversions?: string[]; /** * Generate a candidate preset that has not been generated yet (cached afterwards, like `url()`). * Default `false`: missing ones are skipped, so building the props never resizes on the request * path — declare the presets you list here `eager: true` so they exist from the attach on. */ generate?: boolean; /** * Sign every URL for this long (seconds or a duration string) instead of using the public URL — * for a private bucket. For the app's own delivery route, use {@link url}. */ expiresIn?: string | number; /** * Build each URL yourself (`conversion` is `undefined` for the original), e.g. to point at the * app's delivery route. Takes precedence over {@link expiresIn}. */ url?: (conversion: string | undefined) => string | Promise<string>; /** * Build the `srcSet` from the delivery route's on-demand resize instead of presets: one * candidate per width, as `media.library.deliveryUrl(id, { width })` — signed when * `delivery.signing` is configured. `true` uses `delivery.images.widths` below the original's * width; pass `widths` (any, when signed) and `quality` to choose. */ onDemand?: boolean | { widths?: readonly number[]; quality?: number; }; } /** Formats every current browser decodes; anything else (HEIC, TIFF) is never a candidate. */ export declare const BROWSER_IMAGE_TYPES: Set<string>; /** A `srcset` candidate before its URL is resolved; `conversion` is `undefined` for the original. */ export interface ImageCandidate { conversion: string | undefined; width: number; /** Its height, when known — what an art-directed group reports as its intrinsic size. */ height?: number; } /** * Pick the `srcset` candidates of a record: the generated presets that are the same picture at * another width, plus the original when it is a browser-decodable image of known width. Sorted * narrowest first, one per width. Pure — {@link MediaLibrary.image} resolves the URLs. * * "The same picture" means the same aspect ratio as a reference: the original's, or — when the * caller lists `include` explicitly, which is how an art-directed `<source>` (square crops for * phones, say) asks for its group — the first listed conversion's. The original joins only if it * matches that reference. * * @internal exported for tests. */ export declare function imageCandidates(record: MediaRecord, presets: ConversionPreset[], include?: string[]): ImageCandidate[]; //# sourceMappingURL=responsive_image.d.ts.map