import { O as LouiseEnv } from "./types-B8yzm4Q0.js"; //#region src/core/media/dimensions.d.ts interface ImageDimensions { width: number; height: number; } /** * Read intrinsic pixel dimensions via the Cloudflare Images binding's `.info()`, * a real decode that sizes every raster format robustly (and applies EXIF * orientation). Returns `null` for vector input (SVG, which has no intrinsic * pixel size) or on any Images error, so a caller can fall back to * {@link imageDimensions} (the binding-free header parser, which now also covers * AVIF/HEIF and TIFF). Prefer this in the upload path when an `IMAGES` binding is * available; it's the authoritative path, the header parser the lightweight * fallback. */ declare function imageInfo(images: ImagesBinding, bytes: Uint8Array | ArrayBuffer): Promise; /** * Parse intrinsic pixel dimensions from an image's header bytes (PNG, GIF, * JPEG, WebP, AVIF/HEIF, TIFF). Pass enough of the file to include the header—the * first few KB is always plenty; the whole buffer is fine. Returns `null` * when the size can't be read (unsupported format, or a truncated/odd header). */ declare function imageDimensions(bytes: Uint8Array): ImageDimensions | null; //#endregion //#region src/core/media/sniff.d.ts /** The image MIME types Louise verifies and serves. SVG is intentionally * excluded: it is not sniffable here and would be a hosted-HTML/script risk on * a public media domain. */ type SniffedImageType = "image/jpeg" | "image/png" | "image/gif" | "image/webp" | "image/tiff" | "image/avif"; /** * Sniff the real image type from the leading magic bytes rather than trusting * the client-supplied MIME. Pass the first ~32 bytes of the file. Returns the * verified MIME type, or `null` if the bytes aren't a supported image. */ declare function sniffImageType(bytes: Uint8Array): SniffedImageType | null; //#endregion //#region src/core/media/storage.d.ts /** Hard ceiling on a single upload. Without it the bucket streams whatever is * posted, bloating storage and cost. Overridable per call. */ declare const DEFAULT_MAX_BYTES: number; interface PutMediaOptions { /** Key prefix grouping uploads by purpose (for example, `"web"`). Default `"web"`. */ scope?: string; /** Max accepted size in bytes. Default {@link DEFAULT_MAX_BYTES} (10 MB). */ maxBytes?: number; /** `Cache-Control` stored on the object. Default: 1-year immutable. */ cacheControl?: string; /** Optional Cloudflare Images binding. When provided, dimensions are read via * `.info()` (which covers AVIF/TIFF, unlike the header parser); on any Images * failure it falls back to the header parser, so passing it never regresses. */ images?: ImagesBinding; } /** Outcome of {@link putMedia}: either the stored object, or a rejection with * the HTTP status a route handler should surface. `width`/`height` are the * intrinsic pixel dimensions when the header could be read, else `null`. */ type PutMediaResult = { ok: true; key: string; contentType: string; size: number; width: number | null; height: number | null; } | { ok: false; status: 413 | 415; error: string; }; /** * Verify and store an uploaded image in R2. The bytes are sniffed for a real * image signature (the client MIME is never trusted); the object is stored with * the *verified* content type and an immutable cache header. The serving route * should set `X-Content-Type-Options: nosniff` on the response (this helper only * writes the object). Rejects oversize files (413) and non-images (415) without * writing anything. */ declare function putMedia(bucket: R2Bucket, file: File, opts?: PutMediaOptions): Promise; interface MediaItem { key: string; url: string; size: number; /** ISO 8601 upload timestamp. */ uploaded: string; } /** Join a public media base URL and an object key into an absolute URL. */ declare function mediaUrl(base: string, key: string): string; /** * Whether `value` is a URL served from this site's media base (`MEDIA_URL`)—an * asset in the media library rather than an external hotlink. A prefix match on * the normalized base (what {@link mediaUrl} builds is always `base` + `/` + * key). The empty string is NOT media; a caller that treats "unset" as valid * checks that separately. This is the one definition of "media-backed" the * sanitizer, the sections validator, and the settings route all enforce with. */ declare function isMediaUrl(base: string, value: string): boolean; /** * List everything in the bucket, newest first, so a media picker can browse * what's actually stored. Pages through R2's 1000-object limit so nothing is * hidden. `base` is the public media URL used to build each item's `url`. */ declare function listMedia(bucket: R2Bucket, base: string): Promise; /** Remove one object from the bucket. Delete-safety (the reference scan) is the * caller's decision; run {@link findMediaReferences} first when appropriate. */ declare function deleteMedia(bucket: R2Bucket, key: string): Promise; /** Asset-level metadata for a media row, keyed for render-time lookup. */ interface MediaMeta { key: string; url: string; alt: string | null; caption: string | null; width: number | null; height: number | null; } /** * Load asset-level metadata (alt/caption/dimensions) from the `media` registry, * keyed by public URL, so a render pass can fill an image's `alt` from its asset * default when a per-usage override isn't set. `tableName` is the site's `media` * table name, `base` its `MEDIA_URL`. * * Pass `urls` (the specific public URLs a render actually needs) to scope the * query to just those rows—a bounded `IN (…)` lookup instead of a full-table * scan, so this stays cheap even on a large library. Omit `urls` to load the * whole registry (only sensible for a small table). */ declare function mediaMetaByUrl(db: D1Database, tableName: string, base: string, urls?: readonly string[]): Promise>; interface MediaReference { /** Human label for the collection ("Artwork", "Product", "Settings"). */ collection: string; /** The referencing record's title/name so the editor knows what breaks. */ label: string; } /** * One table to cross-reference a media key against, described by name so the * scan needs no drizzle schema. `columns` are the text columns whose contents * may embed a key: `images[]` URL arrays, embedded ``/ProseMirror `src` * in rich text, or settings JSON. `labelColumn` is read as the record label. */ interface MediaRefSource { collection: string; table: string; columns: string[]; labelColumn: string; } /** * Escape LIKE wildcards so a key containing `_` or `%` (both legal after key * sanitization) can't over-match unrelated rows. Pairs with `ESCAPE '\'`. */ declare function likePattern(needle: string): string; /** * Cross-reference an object key against content in D1 before deleting it. The * timestamped key is unique enough that a substring scan catches every place it * can appear (image-URL arrays, rich-text `src` embeds, settings JSON). Returns * the referencing records so a panel can warn "Used by: …". This is the * fallback that also covers rich-text embeds that don't go through a `media` * reference row; with the `media` table, primary delete-safety is a join. */ declare function findMediaReferences(db: D1Database, key: string, sources: MediaRefSource[]): Promise; //#endregion //#region src/core/media/transform.d.ts interface CfImageOptions { width?: number; height?: number; /** Resize behaviour; `cover` fills and crops, `contain` letterboxes. */ fit?: "cover" | "contain" | "scale-down" | "crop" | "pad"; /** Focal point for cover-crops; `auto` lets Cloudflare pick the subject. */ gravity?: "auto" | "center" | "left" | "right" | "top" | "bottom"; /** `auto` serves AVIF/WebP when the client supports it. */ format?: "auto" | "webp" | "avif" | "jpeg"; quality?: number; } /** * Rewrite a media URL to a Cloudflare-resized derivative. Only same-origin * `/cdn-cgi/image/` path rewriting is used, so it works for any image served * from a resizing-enabled zone. Non-URLs (or parse failures) return the input * untouched, so callers can pass it unconditionally. */ declare function cfImage(url: string, opts: CfImageOptions): string; /** * A square, focal-cropped source + 2× retina descriptor for a circular render. * `size` is the CSS display diameter in px. Pair with a CSS circle mask. */ declare function circleImage(url: string, size: number): { src: string; srcset: string; }; /** Options for {@link cfImageSrcset}: the largest 1× display width plus the * usual cover-crop knobs. `ratio` (for example, `"16/10"`) derives each derivative's * height so the crop matches what CSS `object-fit` shows (no wasted pixels); * omit it for a width-only resize. `steps` are DPR multipliers of `width`. */ interface CfImageSrcsetOptions { width: number; ratio?: string; steps?: readonly number[]; fit?: CfImageOptions["fit"]; gravity?: CfImageOptions["gravity"]; quality?: number; } /** * A width-descriptor `srcset` (+ a default `src`) for a rectangular render. The * browser picks the smallest derivative that covers the rendered width at the * device's DPR—retina included—so a huge master ships as a right-sized * AVIF/WebP. Pair the returned `srcset` with a `sizes` attribute describing the * rendered width. Mirrors {@link circleImage} for non-square frames. Pure (no * binding); a non-URL `url` passes through {@link cfImage} untouched. */ declare function cfImageSrcset(url: string, opts: CfImageSrcsetOptions): { src: string; srcset: string; }; /** Options for {@link transformImage}. Mirrors the Image-Resizing knobs, but the * output `format` is a concrete encode (default AVIF) since bytes are produced, * not an `auto` served per `Accept`. */ interface TransformImageOptions { width?: number; height?: number; /** Resize behaviour; `cover` fills and crops, `contain` letterboxes. */ fit?: "cover" | "contain" | "scale-down" | "crop" | "pad"; /** Focal point for cover-crops; `auto` lets Cloudflare pick the subject. */ gravity?: "auto" | "center" | "left" | "right" | "top" | "bottom" | "face"; /** Encoded output format. Default `"avif"`. */ format?: "avif" | "webp" | "jpeg" | "png"; quality?: number; } /** * Server-side re-encode a source image to a resized/cropped derivative with the * Cloudflare Images binding, returning a `Response` whose body is the encoded * bytes and whose `content-type` is the output format. Use when you need the * transformed bytes (a stored crop persisted back to R2, an OG source, etc.); * for public on-the-fly derivatives prefer the zero-cost URL rewrite * ({@link cfImage}). The binding is passed explicitly—see {@link LouiseMediaEnv} * for the optional `IMAGES` contract. */ declare function transformImage(images: ImagesBinding, input: ReadableStream | Uint8Array | ArrayBuffer, opts?: TransformImageOptions): Promise; /** A per-usage crop: focal position (0–100, as a %) plus zoom (`scale` ≥ 1). */ interface Crop { x: number; y: number; scale: number; } /** * Turn a {@link Crop} into inline style properties for an `` inside a * fixed frame: focal `object-position` + `scale` zoom about the same focal * point. Framework-generic—spread into a JSX `style` object or stringify for * an `style=""` attribute. Sites that prefer CSS custom properties can read the * same `{ x, y, scale }` into `--crop-*` vars instead. */ declare function cropStyle(crop: Crop): { objectPosition: string; transform: string; transformOrigin: string; }; //#endregion //#region src/core/media/proxy.d.ts interface ImageProxyConfig { /** Where the route is mounted, for example, `"/api/img"`. Used to build URLs. */ path: string; /** Exact hostnames the proxy will fetch from. Anything else is a 400. */ allowHosts: readonly string[]; /** * The only widths the proxy will produce. A layout decision—match your * `sizes`. Anything else is a 400, so the edge caches a bounded set. */ widths: readonly number[]; /** `cf.image.fit`. Default `"scale-down"`—never upscales. */ fit?: "scale-down" | "contain" | "cover" | "crop" | "pad"; /** `cf.image.quality`, 1–100. Omitted, Cloudflare's default applies. */ quality?: number; /** Formats to negotiate from `Accept`, in preference order. Default avif, then webp. */ formats?: readonly ("avif" | "webp")[]; /** * `Cache-Control` on a resized response. Default `public, max-age=86400`. * If the source URLs are content-addressed (a new image gets a new URL, as * signed URLs do), `public, max-age=31536000, immutable` is safe. */ cacheControl?: string; /** Edge cache lifetime for the fetched original, seconds. Omitted, Cloudflare's default. */ edgeCacheTtl?: number; /** What a failed resize does. Default `"redirect"` to the original. */ onFailure?: "redirect" | "error"; /** Query parameter names. Default `src` and `w`. */ params?: { src?: string; width?: string; }; } interface ImageProxy { /** The route handler. Mount it at `path` for GET. */ handle(request: Request): Promise; /** The proxied URL for `src` at `width`, or `src` unchanged when its host isn't allowed. */ url(src: string, width: number): string; /** A `srcset` over every configured width, or `undefined` when `src`'s host isn't allowed. */ srcset(src: string): string | undefined; } /** * Build a resize proxy for third-party images. One config drives both the * route and the URLs your markup emits, so the two cannot disagree on which * widths exist. * * ```ts * const fwImages = defineImageProxy({ * path: "/api/img/fw", * allowHosts: [FW_IMAGE_HOST], * widths: [320, 640, 960, 1280], * }); * // route: export const GET = ({ request }) => fwImages.handle(request); * // markup: * ``` */ declare function defineImageProxy(config: ImageProxyConfig): ImageProxy; //#endregion //#region src/core/media/types.d.ts /** * Bindings the Louise media primitives read off a Worker's `env`. A site whose * `Env` handles media should `extends LouiseMediaEnv`. Widens the security base * (`LouiseEnv`) with the R2 bucket and its public base URL. The helpers in * `./storage` take the bucket explicitly, so this interface is the typed * bindings *contract*—not something the functions reach for implicitly. */ interface LouiseMediaEnv extends LouiseEnv { /** R2 bucket holding uploaded assets. */ MEDIA: R2Bucket; /** Public base URL the bucket is served from (for example, `https://media.example.com`). * The public URL of an object is `MEDIA_URL` + "/" + its key. */ MEDIA_URL: string; /** Optional Cloudflare Images binding. When present, the media primitives use * it for server-side re-encoded transforms ({@link transformImage}) and to * read the dimensions of formats the header parser can't ({@link imageInfo}: * AVIF, TIFF). Absent → callers fall back to Image-Resizing URL rewriting * ({@link cfImage}) and the header-byte parser ({@link imageDimensions}). * Declare it in `wrangler.jsonc`: `"images": { "binding": "IMAGES" }`. */ IMAGES?: ImagesBinding; } //#endregion export { sniffImageType as A, isMediaUrl as C, mediaUrl as D, mediaMetaByUrl as E, imageDimensions as M, imageInfo as N, putMedia as O, findMediaReferences as S, listMedia as T, MediaRefSource as _, CfImageOptions as a, PutMediaResult as b, TransformImageOptions as c, circleImage as d, cropStyle as f, MediaMeta as g, MediaItem as h, defineImageProxy as i, ImageDimensions as j, SniffedImageType as k, cfImage as l, DEFAULT_MAX_BYTES as m, ImageProxy as n, CfImageSrcsetOptions as o, transformImage as p, ImageProxyConfig as r, Crop as s, LouiseMediaEnv as t, cfImageSrcset as u, MediaReference as v, likePattern as w, deleteMedia as x, PutMediaOptions as y };