@perako/design-tokens
v0.0.4
Published
Dependency-free Perako design tokens for web and React Native.
Readme
@perako/design-tokens
Dependency-free source of truth for Perako color, spacing, radius, typography, and semantic light/dark themes. Consumable from React DOM (web) and React Native (mobile) with no runtime dependencies.
This is the canonical layer. New brand colors, core radii, type sizes, shadows, spacing
values, and semantic aliases start here — apps and the UI packages should not invent
divergent scales (see plan.md → Governance Rules).
Install
npm install @perako/design-tokensExports
import {
primitives, // raw color/space/radius/typography scales
lightTheme, // semantic light theme
darkTheme, // semantic dark theme
themes, // { light, dark }
allTokens, // { primitives, themes }
createCssVariableMap,// theme -> { "--p-...": value }
createCssBlock, // (selector, vars) -> css string
createThemeCss, // full :root + [data-theme="dark"] css
createNativeTheme, // theme -> React Native theme object
rnLightTheme, // createNativeTheme(lightTheme)
rnDarkTheme, // createNativeTheme(darkTheme)
icons, // platform-neutral stroke-icon registry (name -> {viewBox, elements})
iconNames, // IconName[]
logoMark, // themeable Perako logo as inline vector data
brandAssets, // manifest of canonical brand files (logos, app icons, favicons, social)
} from "@perako/design-tokens";Generated artifacts (also published):
@perako/design-tokens/css→dist/tokens.css(:rootlight +[data-theme="dark"])@perako/design-tokens/tokens.json→dist/tokens.json(primitives + both themes)
Web usage
import { createThemeCss } from "@perako/design-tokens";
// Inject once at the app root; toggle dark mode with [data-theme="dark"] on <html>.
const css = createThemeCss(); // or import "@perako/design-tokens/css"Variables are emitted under the --p- prefix, e.g. --p-color-action-primary,
--p-radius-card, --p-shadow-card, --p-gradient-accent.
React Native usage
import { rnLightTheme, rnDarkTheme, createNativeTheme } from "@perako/design-tokens";
const theme = isDark ? rnDarkTheme : rnLightTheme;
// theme.colors.action.primary, theme.semanticRadius.card, theme.shadows.card, ...Icons & brand assets
icons is a platform-neutral registry of the app's stroke icons (24×24, drawn with
currentColor), extracted from the design viewer. Each entry is { viewBox, elements[] }
where elements are primitive shapes (path/circle/rect/line/polyline/polygon).
@perako/ui-web and @perako/ui-native render these through a shared <Icon name=… />.
logoMark is the Perako "P" logo as inline vector data with per-theme fills, rendered by
<Logo /> on both platforms. brandAssets is a typed manifest of the canonical brand
files (logos, iOS/Android app icons, favicons, social) — it points at their source
location in this repo; the raster/SVG binaries are build artifacts, not bundled at runtime.
The icon registry is generated from the viewer's inline SVGs:
npm run icons:generate # rewrites src/icons.ts from ../../src/componentsNaming lives in scripts/icon-names.json (signature → name); the generator fails loudly
on any unnamed glyph so new viewer icons can't slip through unnoticed.
Scripts
npm run build # tsc + generate dist/tokens.css and dist/tokens.json
npm run typecheck
npm run test # build + smoke tests asserting required tokens/vars/RN keysToken changes must keep the smoke tests green — they prove the required CSS variables and React Native theme keys still exist.
