OriaTheme
GitHub

API reference · Core themes

@oriatheme/core

Theme-contract, validation, resolution, and import/export APIs with no DOM, Storage, React, or Vue dependency.

Package and environment

Pure TypeScript; safe in Node, SSR, and browser module evaluation.

bash
pnpm add @oriatheme/core

Use the package manager and lockfile already chosen by the consumer project. Examples use package-root exports only; do not deep-import from src, dist, or registry templates.

Public functions

ExportSignatureDescription
defineTokenContract(input: TokenContractInput) => TokenContractCreates an immutable, validated contract.
extendTokenContract(base, extension) => TokenContractAdds contract tokens without losing the base.
getTokenDefinition(contract, path) => TokenDefinition | undefinedLooks up a declared token.
token / colorToken(type, options) => TokenDefinitionCreates contract-token definitions.
validateTheme(input, contract) => ValidationResult<ThemeDefinition>Never throws for untrusted serialized input.
normalizeTheme(theme, contract) => ThemeDefinitionCanonicalizes order and fills contract defaults.
resolveTheme(theme, mode, options?) => ResolvedThemeResolves references and compiles safe CSS variables.
resolveThemeWithContract(theme, contract, mode, options?) => ResolvedThemeSafe resolver with an explicit contract.
cloneTheme(theme, identity, clock?) => ThemeDefinitionMakes a timestamped complete copy.
createThemeFromSeed(seed, options) => ThemeDefinitionCreates a complete standard-contract custom theme.
exportTheme(theme) => stringSerializes the public theme format.
importTheme(json, options) => ImportResultValidates JSON, forces custom kind, and handles conflicts.
analyzeTheme(theme, contract) => ThemeDiagnosticsReturns blocking errors and contrast warnings.
contrastRatio(foreground, background) => numberComputes WCAG contrast for static hex colors.
toCssVariable(path, prefix?, cssNameStyle?) => `--${string}`Converts a validated path to a CSS custom property.
isTokenPath(value) => value is TokenPathNarrows a string to a branded token path.
oriaStandardContract / oriaDefaultThemeTokenContract / ThemeDefinitionThe default oria-standard@2 contract and default theme since 0.3.0.
oriaStandardContractV1 / oriaDefaultThemeV1TokenContract / ThemeDefinitionLegacy v1 exports retained only as migration input.
migrateOriaStandardV1ToV2(input: unknown) => ThemeMigrationResultConverts a complete v1 standard theme to v2 with warnings and requiresReview.
ts
import { oriaStandardContract, resolveTheme, validateTheme } from "@oriatheme/core";

const checked = validateTheme(input, oriaStandardContract);
if (checked.ok) {
  const resolved = resolveTheme(checked.value, "dark");
  // resolved.variables is safe compiler output.
}

Branch on validateTheme or importTheme results for user input; do not match error messages.

Important types and boundaries

ThemeDefinition is the complete serialized theme (schemaVersion 1; the default contract is oria-standard@2 since 0.3.0); TokenContract describes paths and safe values; ValidationResult / ImportResult discriminate on ok; OriaThemeError.code is the stable error branch. ResolvedTheme contains compiled variables and colorScheme. ThemeMigrationResult carries the migrated theme, warnings, and requiresReview.