Changelog

@ogygia/image

Every release of @ogygia/image, newest first.

Latest
0.16.0
Versions
1
  1. 0.16.0 minor

    Minor Changes

    • sharp makes AVIF files at effort 2 (was 4): about twice as fast to encode, for files about 0.2% larger. Every file gets a new name once (the encoder's version moved).
    • cloudflare({ links?, binding? }) from @ogygia/image/vite is an encoder for Cloudflare Workers: a page the Worker renders on request names each file as an Image Transformations link (/cdn-cgi/image/<options>/<original>), or with links: false its image endpoint makes each file with the Worker's Images binding (default IMAGES) and keeps it in caches.default; a Worker without that binding answers 500 and says image_binding_missing. cloudflare() on any adapter but adapter-cloudflare (adapter-auto included) fails the server build with image_option_invalid. Prerendered pages still name the files the build makes. A page rendered on request, or in dev, that asks the encoder for a crop or operation it cannot make (Cloudflare: an entropy position, a turn other than a quarter, normalize, negate, gamma, tint, modulate hue or lightness, an AVIF source; a link also cannot make a PNG from another format) fails to render with image_encoder_cannot, naming the encoder and the need. A build for an adapter whose runtime cannot load sharp, with sharp() as the encoder, now says image_no_encoder once, naming cloudflare(), instead of image_adapter_no_encoder (removed) once per build pass. The image endpoint's reader checks an original with Web Crypto, so a Worker's image endpoint needs no Node crypto.
    • image({ encoder }) says who makes the image files: sharp() from @ogygia/image/vite (the default, as before: the app's own endpoint makes every live file and the build every prerendered one), or a list in order of priority (one platform, at most one encoder that makes files at the app's endpoint, sharp() only last); anything else fails the build with image_option_invalid. A Node server bundle now loads the files it reads and notes on disk only in dev and in the build. getImage()'s sources rows may carry media, sizes, width and height beside type and srcset, and <Img> writes them on each <source> when present (type is now optional); today's rows are unchanged.
    • With content({ markdown }) and image() listed, a local markdown image (![alt](./photo.jpg), relative to the post, spaces and accents included) renders through <Img> with the prose preset (or image({ markdown: { width } })), and a frontmatter value starting with ./ or ../ that names an image becomes a descriptor (accept it in a schema with v.custom<ImageDescriptor>(isImage)). A missing file, an HTML <img> naming a local file (image_markdown_html) and a local image in import.meta.og.md(text) (image_markdown_no_file) fail the build. image({ markdown: false }) leaves markdown images as plain <img>, and image({ markdown: { animated: 'motion' } }) shows a moving markdown image (an animated GIF or WebP) with that preset instead, so its width and sizes pick narrower files (a name image({ presets }) does not declare fails the build with image_option_invalid). import.meta.og.image() works in a markdown page's <script> too.
    • New package @ogygia/image: list image({ presets }) from @ogygia/image/vite beside ogygia(), read an image with import.meta.og.image('./hero.jpg') (or many with import.meta.og.image.glob('./gallery/*.jpg')), and render it with <Img of={hero} preset="cover" alt="…" />. The build reads each source once (its size and a blur placeholder of a few hundred bytes at most) and encodes nothing; <Img> picks the files from a preset or its own layout (constrained, fullWidth, fixed), width, aspect and position, and names each one by a signed URL that the image endpoint makes on first request, in dev and on a live server. A prerendered page's files (a getImage() CSS background too) are made by the build as static files under _app/immutable/og/, named by their recipe, so adapter-static sites need no server and keep the same image URLs across builds with no OGYGIA_SECRET. import.meta.og.image(src, { warm: 'cover' }) makes a preset's files there at build for pages rendered on a live server. Crops are real files (a 1/1 thumbnail downloads a square), a fixed 48-pixel avatar asks for 48 and 96 only, animated GIFs become animated WebP, SVGs are served as they are, and a changed or unsigned URL is refused. priority preloads the page's main image from the head, morph names an image for a view transition, and the HTML carries no client script and no inline event handler (the placeholder and a crop are inline styles, the placeholder a data: image). sharp is a peer the app installs (pnpm add @ogygia/image sharp): a build or dev server that cannot find it in the app, or a server build that lists it only in devDependencies (adapter-node would bundle it, and every image would answer 500), fails with image_sharp_missing. The server loads sharp on the first image request, never at start; it keeps its files on disk to a size, answers from memory when the disk cannot write, sends a URL with a query string to the bare URL, and answers 503 past a bounded line of encodes. Every file is named by a hash of its source's bytes and is never made from an original that no longer matches it, so an edited image gets new URLs and an old page's URL answers 404, never the new pixels. A URL made absolute with new URL(src, page.url) (an og:image, an RSS feed) names the file at kit.prerender.origin on a prerendered page. getImage() gives the same answer outside the component, and isImage checks a frontmatter image field (v.custom<ImageDescriptor>(isImage)). A missing file, a file outside src/, a non-literal argument, an unknown option, an unknown preset, a descriptor whose id or placeholder the build did not make, a size of 0 or less (fractions are rounded) or an image too large to encode fails with a code.
    • Remote images at build: image({ remote: { hosts } }) lets import.meta.og.image('https://…'), a markdown image and a frontmatter URL on a listed host be fetched into the build cache (asked again on each build, a 304 keeps the copy, an offline build uses it and warns image_remote_stale) and become a file source like any other; an unlisted URL fails the build with image_remote_host (which replaces image_remote_unsupported), and a fetch with no copy that fails is image_remote_failed.
    • Remote images at request: remoteImage(url, { width, height, alt?, version? }) makes a descriptor of an image a server load learns per request (a CMS entry's); the image endpoint fetches its URL (signed into the file's URL) under image({ remote: { hosts, maxBytes, timeout } }), one fetch per URL, and answers its files public, max-age=<rest of the maxAge window>, stale-while-revalidate=<maxAge>, never immutable; refusals are 404 (unlisted host, a redirect off the list, or a host listed only by *. that resolves to a private address, a rule the build's fetch now follows too), 413, 504 and 502, each no-store and said as image_remote_refused; a prerendered page's remoteImage() is fetched by the build and its files named by the bytes; cloudflare() links name the whole URL, and image_vercel_config now requires images.remotePatterns for each remote.hosts entry (type VercelRemotePattern).
    • Share cards: import.meta.og.image.card('./Card.svelte', { width, height, fonts }) returns (props) => ImageDescriptor, a Svelte component (and the components it imports, with their scoped CSS) drawn as a PNG by satori, satori-html and @resvg/resvg-js (optional peers the app installs; a build with a card and none of them fails image_card_engine_missing). Props are one JSON object of at most 2048 characters in the URL (image_card_props), signed into each file's .card/ tail; fonts are .woff, .ttf or .otf files whose family, weight and style the build reads (image_card_font); CSS satori cannot draw fails image_card_css, naming the property; an image a card names (<img src>, a style's url()) is read by ogygia and handed to satori as bytes, never fetched by it: an asset of the build, an http(s) URL on a remote.hosts host (under its size, time and private-address limits) or a data: URL, anything else image_card_source, and each is fitted to the card with sharp first (refused past 16383 × 16383 pixels from its header, drawn from a card-sized copy when larger), so a small file of huge dimensions cannot take the draw's memory; a link's href is no image. A prerendered page's card is drawn by the build into _app/immutable/og/, a live page's by the image endpoint on the first ask, kept forever and named by a digest of every module and font the card is made from (a card that shows a remote image follows remote.maxAge instead, never immutable, and the build names its file by the bytes it got); on an edge runtime a live page's card is the build's file when a prerendered page made it, else 404 with image_no_encoder (which gains what: 'card'). Descriptors gain from: 'card' and card. In dev, an og:image or twitter:image naming an AVIF or WebP file says image_share_format.
    • sharp({ effort: { avif } }) sets how hard sharp works on AVIF files, a whole number from 0 to 9 (default 2): a higher one makes smaller files and slower builds. Anything else fails the build with image_option_invalid.
    • A moving image (an animated GIF or WebP) offers its first frame as a still to visitors who ask for less motion (<source media="(prefers-reduced-motion: reduce)">, files named with -s; Cloudflare makes it with anim=false); with vercel() alone, which cannot keep one frame, no still is offered and the build warns image_still_left_out. import.meta.og.image(src, { dark: './x-dark.png' }) gives an image a dark file of the same shape (another shape fails with image_option_invalid), shown at (prefers-color-scheme: dark); image({ theme: { dark, light } }) makes it follow an app's own theme selectors instead, as two <picture>s a static stylesheet picks between, the hidden one never downloaded. Art direction: a preset's art: [{ media, aspect?, position?, width? }], <Img art> and getImage(of, { art }) (another crop, or another source with of), and the macro's art: { '<media>': './x.jpg' }; each twin row carries its own width and height, so nothing shifts when the media changes. warm warms twins too. getImage()'s result names one preload per candidate set, preloads (each with its media when the image has twins), in place of preload. @ogygia/image exports the types Twin (one entry of an art list) and LaidPreload (one of getImage()'s preloads), so an app can name them.
    • vercel({ sizes?, qualities? }) from @ogygia/image/vite is an encoder for adapter-vercel: a page rendered on request names each file as a Vercel Image Optimization link (/_vercel/image?url=…&w=…&q=…), its width snapped up to sizes, AVIF or WebP picked by Vercel from the browser's Accept; hand encoder.images to the adapter (adapter({ images })). Prerendered pages still name the files the build makes. image({ encoder: [vercel(), sharp()] }): a list is in order of priority, the first encoder that can make a file making it, so the crops, positions, operations, named PNG or JPEG, and GIF, TIFF or animated sources Vercel cannot make go to the app's own sharp endpoint; with vercel() alone they fail to render with image_encoder_cannot. A build that lists vercel() fails with image_vercel_config when adapter-vercel's .vercel/output/config.json images lacks a width, quality or format the app names, or the host of a full-URL paths.assets, or when it opens more than the app needs (no qualities, or localPatterns unset or wider than the app's originals), or when the adapter is not adapter-vercel. vercel()'s images lists qualities 60 and 80 by default and localPatterns for /_app/immutable/assets/ only, and a plugin or preset quality it does not list fails the build with image_option_invalid.

    Patch Changes

    • A responsive image no longer gets a ladder width within a tenth of a width its layout already names (its width, twice it, or the source's own): a 900 px constrained image makes 900 and no 960, so a build makes fewer files for the same srcset choices.
    • With vercel() alone, a share card for a page rendered on request is now drawn (every one answered 500 image_settle_failed, since no encoder made files there); one that names an image fails image_card_source, saying to list sharp().
    • A Vercel function now draws a share card for a page rendered on request (it answered 500 image_settle_failed): a server card's chunk names satori's harfbuzz WebAssembly file, so Vercel's file tracing keeps it in the function.

    Dependencies: @ogygia/compiler@0.16.0, @ogygia/core@0.16.0, @ogygia/machine@0.16.0