OriaTheme
外观

API 参考 · 浏览器 Runtime

@oriatheme/runtime-dom

浏览器端外部 store、原子 DOM 应用、持久化、Bootstrap 与 View Transition。

包与运行环境

SSR 导入安全;start、Storage 和 DOM 写入只在浏览器执行。

bash
pnpm add @oriatheme/presets @oriatheme/runtime-dom

选择使用方项目已有的一种包管理器和 lockfile;示例只使用 package root export,不要从 src、dist 或 registry template 深层导入。

工厂与首屏 API

ExportSignatureDescription
createOriaThemeRuntime(config: OriaThemeConfig) => OriaThemeRuntimeCreates the SSR-safe store and client DOM runtime.
bootstrapTheme(options?: BootstrapOptions) => voidApplies one valid active snapshot before framework mount.
createBootstrapScript(options: BootstrapOptions) => stringCreates a self-contained script for a caller-supplied snapshot.
createBootstrapStorageScript(options?) => stringCreates a head-safe LocalStorage bootstrap script.
ts
import { bootstrapTheme, createOriaThemeRuntime } from "@oriatheme/runtime-dom";
import { oriaPresetThemes } from "@oriatheme/presets";

bootstrapTheme({ contract: { name: "oria-standard", version: 2 } });
const runtime = createOriaThemeRuntime({
  presets: oriaPresetThemes,
  defaultThemeId: "oria-default",
});
runtime.start();

OriaThemeRuntime

ExportSignatureDescription
start / destroy() => voidAttach or release browser listeners and DOM ownership.
getSnapshot / subscribe() => ThemeSnapshot / (listener) => unsubscribeRead or subscribe to the external store.
setTheme / setAppearance(id | mode, options?) => voidSelect an existing theme or user preference; can animate explicit actions.
createCustomTheme({ theme }) => ThemeDefinitionPersists a complete valid custom theme.
updateCustomTheme(id, patch, options?) => ThemeDefinitionUpdates an existing custom theme only.
duplicateTheme / removeCustomTheme(id, identity) => ThemeDefinition / (id) => voidCopies a preset/custom theme or removes a custom theme.
previewTheme(theme, mode?) => PreviewHandleApplies a valid in-memory preview; dispose restores formal state.
exportTheme / importTheme(id) => string / (json, options?) => ThemeDefinitionExports a saved theme or imports a fully validated custom theme.
reset() => voidReturns runtime preference and custom state to its initial configuration.

重要类型与边界

OriaThemeConfig 要求 presets 和 defaultThemeId;contract 默认 oria-standard@2,migrations 显式注册后才接受 v1 持久化主题(否则安全拒绝)。BootstrapOptions.contract 声明后只恢复完全匹配的 snapshot。ThemeSnapshot 提供 preference、resolvedMode、resolvedTheme、preset/custom 列表和 error。ThemeStorage 可替换默认持久化,ThemeChangeOptions 的 animate 只用于显式用户操作。persist appearance,绝不持久化 resolvedMode。