API參考·編輯域
@oriatheme/editor-core
草稿、字段元資料、智慧秤、診斷、預覽和提交會話,不依賴 DOM、儲存或框架。包裝及環境
純領域邏輯;僅預覽/保存接收由消費者創建的運行時。
bash
pnpm add @oriatheme/editor-corebash
npm install @oriatheme/editor-corebash
yarn add @oriatheme/editor-corebash
bun add @oriatheme/editor-core使用消費者專案已經選擇的套件管理器和鎖定檔案。範例僅使用包根匯出;不要從 src、dist 或註冊表範本深度匯入。
Exports
| 出口 | 簽名 | 描述 |
|---|---|---|
describeTokenContract | (contract?) => readonly TokenFieldDescriptor[] | 穩定的合約訂單字段元資料。 |
describeToken | (path, contract?) => TokenFieldDescriptor | undefined | 尋找一個編輯器欄位。 |
getTokenModeScope | (path) => 'shared' | 'mode' | 傳回標準標記編輯範圍。 |
deriveSmartScale | (input: SmartScaleInput) => readonly DerivedTokenValue[] | 擴展面向設計師的大師價值。 |
preserveScaleOverrides | (derived, current, customized) => readonly DerivedTokenValue[] | 保留明確定制的葉子。 |
createThemeEditorIdentity | (source, existingThemes) => CloneIdentity | 為預設編輯建立穩定的未使用標識。 |
createThemeEditorSession | (options) => ThemeEditorSession | 建立獨立於框架的草稿會話。 |
ThemeEditorSession
| 出口 | 簽名 | 描述 |
|---|---|---|
getSnapshot / subscribe | () => ThemeEditorSnapshot / (listener) => unsubscribe | 讀取或觀察不可變的編輯器狀態。 |
setName / setToken / setTokens | (...) => void | 按名稱、一個標記或一組原子更改草稿。 |
removeToken / resetToken / resetMode / resetAll | (...) => void | 取消設定或恢復拔模值。 |
replaceFromJson / exportJson | (json) => ImportResult / () => string | Atomically import a draft or serialize it. |
preview | (runtime, mode?) => ThemeEditorPreviewResult | 預覽僅完成有效的修訂。 |
save | (runtime) => ThemeEditorSaveResult | 驗證、建立/更新自訂主題或報告衝突。 |
reload / destroy | (theme) => void / () => void | 採用外部版本或釋放會話資源。 |
重要類型和邊界
ThemeEditorOptions 需要來源並且在編輯預設時需要標識。 ThemeEditorSaveResult 因驗證或衝突而失敗; ThemeEditorPreviewResult 因問題而失敗。請勿將此草稿狀態機複製到 React、Vue 或路由中。