@bezel-labs/loupe
v0.2.0
Published
Runtime helpers for a Storybook preview: resolve the initial theme context (URL/localStorage) and load design-token web fonts.
Maintainers
Readme
@bezel-labs/loupe
Small runtime helpers for a Storybook preview: resolve the initial theme context and load design-token web fonts. Zero dependencies, browser-only.
Install
npm install @bezel-labs/loupeUsage
resolveInitialContext — pick the initial theme context
Resolves which context (theme) to apply on load. Precedence: URL ?context= → URL
?globals=context:<name> (Storybook's format, so an embedded preview host can drive the
theme) → localStorage → fallback ("default"). A value is only honored when it's in the
known contexts list, if one is provided.
import { resolveInitialContext } from "@bezel-labs/loupe"
const context = resolveInitialContext({ contexts: ["default", "dark", "light"] })loadFonts — inject design-token web fonts
Injects a webfont stylesheet (plus preconnect hints) into <head>. Idempotent — safe to
call repeatedly. Supports Google Fonts (default) and Bunny Fonts.
import { loadFonts } from "@bezel-labs/loupe"
loadFonts([{ family: "Inter", weights: [400, 600] }])
loadFonts(fonts, { provider: "bunny" })API
resolveInitialContext, loadFonts, fontsHref, buildHref, preconnectHosts,
DEFAULT_CONTEXT, plus the related types (Context, ResolveContextOptions, FontDef,
FontProvider, FontsHrefOptions, LoadFontsOptions).
Development
npm install # install deps
npm run build # bundle ESM + CJS + types with tsup
npm test # run the Jest test suite
npm run typecheckLicense
PolyForm Shield 1.0.0 — free to use, modify, and redistribute for any purpose except building or providing a product that competes with Bezel. Open-source, internal, and commercial use are all permitted within that bound.
