@modular/sdk/theme
20 exports in 3 groups.
Interfaces6
- ModularThemeinterfaceeditor, tokens
- ThemeEditorRulesinterfacesemantic, semanticHighlighting, textMate
- ThemeSemanticRuleinterfaceselector, settings
- ThemeSemanticSettingsinterfacebold, fontStyle, foreground, italic, strikethrough, underline
- ThemeTextMateRuleinterfacescope, settings
- ThemeTextMateSettingsinterfacebackground, fontFamily, fontSize, fontStyle, foreground, lineHeight
Types4
- ModularThemeDefinitiontype{ readonly [Category in keyof ModularThemeTokens]?: { readonly [Token in keyof ModularThemeTokens[Category]]?: ModularThemeTokens[Category][Token]; }; }
- ModularThemeTokenstypeSemanticTokenContract & { readonly color: { readonly [Token in PaletteTokenName]: string; }; }
- ResolvedTokenstypeRepresents a fully resolved token structure where all categories and tokens are readonly. This is the shape of tokens after all references and computed functions have been resolved.
- ThemeEditorOptionstypePartial<ThemeEditorRules>
Functions10
- adjustHuefunctionAdjust the hue of a color. Rotates the hue on the color wheel.
- alphafunctionSet the alpha/opacity of a color.
- contrastfunctionGet a contrasting color (black or white) for text readability. Uses WCAG relative luminance calculation to determine the best contrast.
- darkenfunctionDarken a color by a percentage. Works in HSL space for perceptually uniform results.
- defineModularThemefunction(definition: ModularThemeDefinition, editorOptions?: ThemeEditorOptions) => ModularTheme
- defineThemefunctionDefine a theme with full type safety. Creates a theme from a definition where tokens can be: - Literal values (`'#007bff'`, `16`) - References to other tokens (`'$color.brand'`) - Computed functions (`(t) => t.spacing.base * 4`) The returned Theme object provides: - `tokens`: Fully resolved token values with autocomplete - `css`: Generated CSS custom properties string - `extend()`: Method to create derived themes with overrides
- lightenfunctionLighten a color by a percentage. Works in HSL space for perceptually uniform results.
- mixfunctionMix two colors together. Uses linear interpolation in RGB space.
- saturatefunctionAdjust the saturation of a color. Works in HSL space.
- tokenAccessorfunctionCreate a typed token accessor helper for computed functions. This enables autocomplete on the `t` parameter in callbacks. The accessor returns an identity function that preserves the callback type while providing full type inference for the tokens parameter.