Skip to content

Repository files navigation

@goobits/themes

A SvelteKit theme system with Svelte 5 state and zero-flash server rendering.

Resolve light, dark, system, and named schemes consistently across cookies, local storage, server hooks, blocking startup, and application controls.

Why Themes · Quick start · Public surface · Documentation


Why Themes

The repository directory is theme-engine; the published package and canonical consumer identity are @goobits/themes.

The package keeps theme configuration, persistence, server preference parsing, pre-paint initialization, Svelte state, controls, design tokens, and preset CSS behind one contract. It supports light, dark, and system modes, named schemes, fixed-mode schemes, route overrides, namespaced cookies and local storage, Goo presets, and one-step migration from a legacy scheme key.

Quick start

In the current workspace dependency graph, use Node.js 22 or newer with Svelte 5/SvelteKit. The manifest still declares Node 18, but the runtime @goobits/logger dependency declares Node 22; reconcile those engines before claiming Node 18 support. @goobits/themes currently depends on the source-only @goobits/logger workspace package, so consume both from pinned workspace/submodule checkouts until that distribution dependency is reconciled; a standalone registry install is not verified by this checkout.

Create configuration:

import{createThemeConfig}from'@goobits/themes/core'exportconstthemeConfig=createThemeConfig({schemes: {default: {},dark: {displayName: 'Dark Mode',fixedMode: 'dark'},},defaultMode: 'system',defaultScheme: 'default',persistence: {storageKey: 'my-app-theme',themeCookie: 'my-app-theme-mode',schemeCookie: 'my-app-theme-scheme',},})

Wire server preferences and the blocking script through the SvelteKit hook:

import{createThemeHooks}from'@goobits/themes/server'import{themeConfig}from'$lib/config/theme'exportconsthandle=createThemeHooks(themeConfig,{blockingScript: true,}).transform

Keep <html lang="en" class="%sveltekit.theme%"> in src/app.html, return { preferences: locals.themePreferences } from src/routes/+layout.server.ts, and wrap the application with ThemeProvider from @goobits/themes/svelte. It reads data.preferences, or callers can pass the value as serverPreferences. Import one theme bundle, such as @goobits/themes/themes/bundle.css.

Public surface

ImportResponsibility
@goobits/themesConvenience barrel re-exporting core, Goo, server, Svelte, and utility surfaces
/coreConfiguration, types, theme resolution, and theme management
/svelteThemeProvider, controls, and Svelte integration
/serverSvelteKit hooks, preference parsing, and blocking script generation
/server/gooGoo-specific SSR support
/gooGoo preset helpers
/utilsFocused shared utilities
/themes/*Base tokens, presets, Goo bundles, and generated preset assets

Source-aware workspace conditions point to src; published defaults point to the built dist surface. The export map is the exact package inventory.

CSS contract

data-theme carries the resolved light or dark mode. Explicit and system-resolved mode classes remain separate, while scheme identity belongs in .scheme-* classes. For a one-time migration, configure legacySchemeStorageKey and optional schemeAliases; the blocking script canonicalizes the stored value before paint and removes the old key after the new preference is saved.

Documentation

Development

pnpm install --frozen-lockfile
pnpm build
pnpm test
pnpm check:goo

pnpm release changes versions, generated Goo assets, Git state, and the npm registry. It is an owner-only publication command, not a verification step.

License

MIT © Goobits

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages