应用开发者
自定义主题
从不可变预设复制、完整校验后保存,并将导入、预览与持久化保持在 Runtime 的原子边界内。预设不可改写
ts
const copied = runtime.duplicateTheme("oria-default", {
id: "brand-2026",
name: "Brand 2026",
});
runtime.updateCustomTheme(copied.id, {
name: "Brand 2026 (refined)",
modes: { light: draftLightTokens, dark: draftDarkTokens },
});
runtime.setTheme(copied.id);duplicateTheme 生成 custom theme。不能修改或删除 preset;删除当前 custom theme 时 Runtime 会退回配置的默认主题。
预览不是持久化
previewTheme 仅应用当前完整有效的草稿,不改变偏好或 Storage。释放 handle 后会恢复最新正式状态。保存则通过 createCustomTheme 或 updateCustomTheme 完整校验后写入。
导入始终经过 Contract
ts
try {
const imported = runtime.importTheme(json);
runtime.setTheme(imported.id);
} catch (error) {
// Branch on OriaThemeError.code, not its English message.
}导入会变成 custom theme,不能覆盖 preset;无效 JSON 或 Token 不会部分应用。展示 OriaThemeError.code 或校验 issues,而不是匹配错误文本。
继续:应用自定义预设