Repository navigation
v0.28.0
Images and icons. foldkit-media 0.1.0 is its first release: an image's facts, a provider and a
layout give every attribute of its markup, a server (/server, /cloudflare, /sharp) or a
build (/vite) makes and keeps each variant, and icons are data a build reads from an Iconify set
or an SVG file. foldkit-mixins-ui 0.17.0 draws them (Image, Figure, Icon.view, an
Avatar picture), and foldkit-mixins 0.17.0 adds the theme's icon tokens and keeps a
reader's theme and knobs before the first paint. foldkit-richtext 0.5.0 lets an Image carry its
facts, foldkit-primitives 0.15.0 adds decodeImage, foldkit-ssr 0.8.0 adds emit,
foldkit-mixins-richtext 0.5.0 draws its icons from Lucide's data, and foldkit-plus is 0.10.0.
Packages that pin one of them republish with a patch so their ranges cover the new versions
(foldkit-builder, foldkit-cms, foldkit-cms-drizzle, foldkit-composition,
foldkit-mixins-builder, foldkit-mixins-crud, foldkit-mixins-data-grid,
foldkit-mixins-form, foldkit-mixins-surface, foldkit-richtext-code,
foldkit-richtext-code-shiki, foldkit-richtext-dom, foldkit-richtext-markdown,
foldkit-site). One change needs code: ColorPicker.popover now draws the whole Popover and takes
its Model and Messages (see Changed).
Added
foldkit-richtext: a standardImagemay carry itsasset,foldkit-media'sImageAssetof
what itssrcnames, as stored; with it, the standard rendering writes theimg'swidthand
height(at the drawnwidthwhen set), so a page holds the image's box before the file
arrives, andimageBox(props)gives a rendering of its own the same. Optional: a document
without it is as valid as before.foldkit-mediais a new dependency.examples/cms: the site'sImageblock may carry itsasset, the facts of the file itssrc
names, hidden from the inspector; with them the image's box is its own shape before the file
arrives, while the facts' key is still thesrc(an edited address falls back to 4:3).foldkit-primitives:decodeImage(source)fetches and decodes a picture before it is shown,
yieldingDecodedorDecodeFailed; given candidates, the one the browser would draw.foldkit-ssr: a static site'semit(pages)adds files made from the generated pages, written
beside them; a path outside the output, or on a file the build or the client build writes, is
refused.writeEmittedwrites them without the plugin.foldkit-mixins:Theme.knobScript({ key?, selector? })andTheme.chooseKnobs(theme, { base, key?, selector? })keep a reader's knob values and apply them before the first paint, as
schemeScriptandchooseSchemedo for the scheme: the head script applies the kept knob
variables to one unlayered rule, and the Command rewrites that rule and keeps those that differ
frombase. Seedocs/design/theme-robustness-DESIGN.md.foldkit-mixins:Themes.choose(themes, name, key?)shows a named theme and keeps it, and
Themes.script(themes, key?)is a head script that shows the kept one before the first paint,
on the attributeThemes.applywrites; a name no theme has is ignored.foldkit-media0.1.0, its first release: responsive images as URLs to write.Picture.deriveturns
anImageAsset's facts, aProviderand aLayout(Fixed,Constrained,FullWidth) into
every attribute of an image's markup:srcsetand asourceper format from oneWidths
ladder,sizes, the reserved box, loading priority, and a placeholder background (a color, a
ThumbHash, or the smallest width; none behind a transparent image). Providers:cdnCgi
(Cloudflare's/cdn-cgi/image/),fromFiles(a build's variants) andhosted(its own server,
whose route,/_image/<hash>/w640.avif,foldkit-media/server'sMediaApideclares with the same
Schema).Variant.space({ widths, formats, qualities, revision })bounds every variant a server makes; a
changed output is a newrevision, written into the URL (w640.r1.avif; none at 0), and a
server answers an earlier revision while it keeps the variant, else with a302to the current
URL, kept briefly, since a rollback answers the old URL again.Picture.preloadwrites
the page's largest image's<link rel="preload">for an SSRhead.Picture.ogImagegives an absolute
og:imageURL at least 1200 wide, never AVIF.
foldkit-media/serverservesProvider.hosted's route over three services,Originals,
TransformerandVariants: a variant is made once and kept, served immutable, and a failure is
its own status (400, 404, 413, 502, 503), never the original (only a variant is kept long; every
refusal is kept a minute at the edge and not by a browser, since a later release in a rollout, or
the same one configured otherwise, may answer it), with headers decided in one place
(headersFor): anETagand 304, a cache lifetime for each answer, CORS,nosniff,Server-Timing.serveFetchhosts it in a Worker,
layerin an EffectHttpRouter.foldkit-media/cloudflaregives its services from a Worker's bindings:
originalsR2,transformerImages(the Images binding) andvariantsR2(R2 behind the Cache API).
examples/cloudflareserves/_image/with them, and takes an upload only with itsUPLOAD_TOKENsecret.OriginalsandVariantsare kept in
any EffectKeyValueStore(originalsKeyValueStore,variantsKeyValueStore), and
keyValueStoreR2is an R2 bucket as one.foldkit-media/sharp'stransformerSharpserves a Node server: it
refuses an original above its pixel limit with a 413 before decoding it, and runs at most
concurrencytransforms (limitTransforms);layercoalesces concurrent misses for a variant (serveFetchdoes not: a Worker request cannot wait on another's work), and sharp reads an original as its EXIF orientation shows it. Rate limits apply to misses only:
admissionRateLimiter(Effect'sRateLimiter) oradmissionRateLimit(a Workers rate-limit
binding) answers a 429 withRetry-After.materializewrites the hosted variants a static site's pages
name, asfoldkit-ssr'semit, andheadersRule()is the_headersrule they need.
describe(in the core) derives an original's facts through anInspector(foldkit-media/browser's
inspectorBrowser, the browser's own decoder, so an editor describes a file where it is chosen;
inspectorSharp,
inspectorImages), andfactsOf(url)describes an image named only by URL, from allowed hosts at their default port,
kept and revalidated with itsETag.Iconholds an icon as data (IconData: itsviewBox,
what its root paints, its drawing):Icon.serializewrites it as one SVG document and
Icon.maskUrlas a CSSurl()for a mask.foldkit-media/icons, for builds, reads an SVG file
(parse) or an Iconify set's icon (fromIconify, through its aliases) into it, and refuses,
naming the icon, any element or attribute outside a presentational allowlist, a link or
url()outside the icon or to an id it does not define, a CSS function other than a colour, a
transform orurl(), an Iconify icon or alias that rotates or flips, and a CSS escape.Icon.key(icon)names an icon by its content, and
Icon.prefixIds(icon, prefix)renames the ids it defines and every reference to them.
Icon.withStroke(icon, { width?, corners? })redraws an icon's strokes, for a mask CSS cannot
reach, andIcon.maskUrlescapes only what a quoted CSSurl()cannot hold, a fifth shorter.
foldkit-media/vite'sicons({ iconify, folders, dts })makes icons imports:
import { arrowLeft } from 'virtual:foldkit-icons/lucide'reads an installed Iconify set or a
folder of the application's SVGs, the bundle holds only what is imported, and a written
declaration names every icon, so a misspelt one is a type error. A refused SVG in a folder fails
the build; a refused Iconify icon is left out, and the declaration says why.
foldkit-media/vite'simages({ widths?, sources?, fallback?, quality? })makes an image in the
repository an import:import hero from './hero.jpg?image'is{ asset, provider }, its facts
read once through sharp and a file written for each ladder width up to its own in each format,
named by content and kept whole in Vite's cache by the original's hash, at most one original read
per core at once; the development server makes
the same variants on request.foldkit-media/clienttypes the import.
foldkit-media/unpic'sdetect(url, options?)is the provider of an image on a host that resizes
it (Shopify, Cloudinary, imgix and the rest unpic knows, an optional peer), or none: theimg
asks forauto, a format the host ignores is never offered as asource, and an asset on another
host gets no URL.
foldkit-media/server's upload route (uploadLayer,serveUploadFetch):POST /_media/upload
takes animage/*body under a byte cap, keeps it by its SHA-256 inUploads
(uploadsKeyValueStore,foldkit-media/cloudflare'suploadsR2), and answers its facts as an
ImageAsset; who may upload is a requiredUploadPolicy, asked before the body is read.GET /_media/facts?url=, behind the same policy, answers the facts of an image named by URL through
factsOf, from the hostsfacts: { allow }names (none by default), or a422.foldkit-media:Icon.draw(icon, h, { key?, size? })draws anIconDataas inline SVG through
any view builder of its shape (SvgBuilder; Foldkit'shis one), every attribute in the
server's markup,1emsquare unlesssizeis given and kept so in a squeezed flex row,
aria-hidden, its ids prefixed by the
icon's content so two icons sharing an id each paint their own;keysets two copies of one icon
apart.foldkit-mixins-ui'sIcon.viewfills its glyph with the drawing.foldkit-mixins-richtext: the chrome's icons are generated from@iconify-json/lucide(pnpm icons, from the package'sicons.json) and drawn withfoldkit-media'sIcon.drawand
Icon.maskUrl, in place of hand-copied paths, so they are today's Lucide drawings. A drawn
icon's size is now written in pixels (width="16px"), and its stroke sits on each path.
foldkit-mediais a new dependency.foldkit-mixins: the theme'sicontokens are the masks of the icons the components draw
themselves (search,eye,eye-off,pipette,rotate-ccw,rotate-cw,success,warning,
error,info,lock,close; their names areChromeIcon), Lucide's by default, written by
pnpm icons. Command, PasswordInput, ColorPicker, ImageCropper, Toast and the data grid draw from
them in place of their hand-written masks, so the toast's marks are Lucide's stroked drawings now.
foldkit-mixins-ui'sIcons.tokens(pack, { width?, corners? })is an application's own pack as
its own tokens, a pack missing a name being a type error. Two knobs:icon.sizemultiplies every
icon box (theiconrung ofladder), andicon.strokeisborder.glyph, the stroke of the
checks, chevrons and guides recipes draw in CSS, until now a fixed2px.foldkit-mixins-ui:Image, apicturedrawn fromfoldkit-media: asourceper format, the
img's candidates andsizes, its box held before the file arrives, lazy unlesspriority,
and the placeholder painted behind it.altisImage.described(text)orImage.decorative,
never omitted.Recipes.Imagehasfit(cover,contain),edge(none,line),ratio
(auto,square,video,portrait, cropped at the focal point) andradius.
Image.watchLoad, beside the style, marks its load state and hides a failed image.Image.preloadsIn
is afoldkit-ssrHeadthat preloads each image the rendered page drew withpriority.Image.audit
warns, in a development build, of a blurry or wasteful image and of two drawn withpriority. An image with no
variant keeps its box and its alt text. An asset'sfocusplaces a crop (--fk-image-focus), and a
ThumbHash paints its picture for thepriorityimage and its average color for the rest.foldkit-mixins-ui:Figure, afigureholding its content and afigcaptionin the caption
role;Recipes.Figurehasalign(start,center).foldkit-mixins-ui: anAvatar'ssrcmay be anAvatarPicture({ asset, provider, width }),
drawn with the candidatesfoldkit-mediaderives for that width, so a small avatar fetches a
small variant.Avatar.widthOf(size)gives that width from the recipe's own sizes.
foldkit-mediais a new peer dependency. Seedocs/design/media-DESIGN.md.
Changed
foldkit-mixins-ui:ColorPicker.popoverdraws the whole Popover, not atoViewfor one:
it takes the Popover's Model and Messages (popover,onPopover, andanchor;
popoverMixinsis the oldpopoveroption) and requires the Popover made with
contentFocus: true, throwing for one without. The panel opens on the area's thumb, and
focus leaving it closes one the keys or a finger opened. A popover opened by touch, a pen or the keys closed at the
first press inside it, so the area and the tracks could not be dragged.foldkit-mixins-ui: a CardGroup's highlight is a film over the card the pointer is on, the
card's size, whatever itssurface. Under cards with a surface it showed only as a rim in the
gap around them, beside the card's own hover; a card in a group with a highlight now draws no
hover of its own.
Fixed
foldkit-mixins-ui: a Card'smediais an accent tile only around a bare icon (svg,
img); an Avatar or anything else leads at its own size, at the card's start. The docs site's
profile card passed its Avatar asimage, which bleeds to the edges in a 16:9 band, and the
avatar sat in the band's corner with the band empty beside it.foldkit-mixins-ui: a ColorPicker's hue and alpha tracks stay in their channel: a Slider is
at least 12rem wide, which ran the tracks under the swatch in a narrow picker, as in a
popover; a holder lays one narrower with--fk-slider-min-length. The popover's trigger keeps
the width of its format's widest text, so it no longer resizes, and moves its panel, as the
color's text changes length.foldkit-mixins-ui: a Sidebar's icon is centred in its slot, and its content on the column
with its edge, so a rail's icons sit in its middle; an icon smaller than its slot sat at the
slot's start, and the default variant's edge took a pixel from the content's side.foldkit-mixins-ui: a Checkbox's check is centered in its box at every size; it stood low and a
little left, by about 8% of the box.foldkit-mixins-ui: a mixed Checkbox's dash is the check's stroke, 2px, on whole pixel rows
across the box's middle; it was a tenth of the box, 1.4px at 16px, blurred off its rows.foldkit-mixins-ui: the AngleSlider's dial, thumb and markers stay round in a theme whose
radius-factoris 0; they read the radius scale before, which squared them off.