Skip to content

Browser Helpers

Utility functions for working with browser operations.

FunctionDescription
createFileStoreCreates a file store on a named Cache API cache: keep a computed set of files (a bake, a download, extracted layers) un…
decodeImageLoads an image and waits until it is decoded, so it can be painted without a flash or a decoding pause (e.g.
loadFontLoads a font and registers it in `document.fonts`, so CSS and canvas can use `family` right away.
matchesMediaWhether the document currently matches a CSS media query.
observeIntersectionCalls `callback` each time `element` enters or leaves the viewport (or `options.root`), with an `IntersectionObserver`…
observeResizeCalls `callback` each time the size of `element` changes, with a `ResizeObserver` dedicated to it.
onPointerIntentTells a tap from a drag, and hover from touch, on one element: the pointer-event logic every draggable or clickable wid…
prefersReducedMotionWhether the user asked the system to reduce motion (`prefers-reduced-motion: reduce`).
preloadImagesLoads and decodes several images with decodeImage, a few at a time, with `mapSettled` from `helpers4/array`.
reflectAttributeDefines a property on `element` that is backed by an HTML attribute — what a custom element needs for `<my-card heading…
requestWorkerRuns one job in a module worker: starts it, posts the request, relays its progress, resolves with its result and ends i…
sha256HexThe SHA-256 digest of some data as a hexadecimal string, optionally cut short: a compact content key, not a security ch…
watchMediaCalls `listener` each time a CSS media query starts or stops matching.
whenIdleRuns `callback` when the browser is idle, with `requestIdleCallback`, for work that can wait (prefetching, analytics, w…