GitHub ↗

参考及开发文档Reference & Development Docs

面向二次开发者与集成方。完整架构决策(ADR)与过程材料见仓库内说明。For integrators and contributors. Full ADRs and process records live in the repository.

1 · 仓库结构1 · Repository Layout

mono-repo,四包各自独立构建、测试与发布:A monorepo; the four packages build, test and release independently:

包Package职责Responsibility许可证License
HIA/core公共核心:主题模型、配色算法(Oklch)、关系规则推导、Token 导出适配器、宝典数据。三端以本地包链接复用。Shared core: theme model, Oklch color math, harmony rule engine, token export adapters, baodian data. Reused by all ends via local package links.MIT
HIA/web网页版(Vite),共享渲染器为三端 UI 单一事实来源,部署 GitHub Pages。Web app (Vite); its shared renderer is the single source of truth for all UI, deployed to GitHub Pages.MIT
HIA/electronElectron 桌面版:复用 web 渲染产物,隐藏 BrowserWindow 真实渲染取色。Electron desktop: reuses the web renderer; hidden BrowserWindow performs real-render extraction.Apache-2.0
HIA/tauriTauri 桌面版:Rust 后端 chromiumoxide 采集,CDP 逐请求 SSRF 拦截。Tauri desktop: Rust backend collects via chromiumoxide with per-request CDP SSRF interception.MIT

2 · 主题模型契约(摘要)2 · Theme Model Contract (summary)

完整契约见 HIA/core/src/types.ts 与 ADR-007(配色关系模式与辅助色):The full contract is in HIA/core/src/types.ts and ADR-007 (harmony modes & auxiliary colors):

字段Field类型Type语义Semantics
primary / secondary / thirdColorRoleColor主体色成员;RoleColor = { name, value, scale(50..900), on },色阶由 HEX 重建。Body-color members; RoleColor = { name, value, scale(50..900), on } with scales rebuilt from HEX.
seriesMode'single'|'dual'|'triad'主体色模式,由成员数派生(装配语义:缺省补默认)。Body mode, derived from member count (assembly semantics: missing → default).
seriesRelationSeriesRelationId十种关系规则之一(manual/complement/clash/neutral/analogous/split-complement/tertiary/primary-combo/secondary-combo/pure)。One of ten rules (manual/complement/clash/neutral/analogous/split-complement/tertiary/primary-combo/secondary-combo/pure).
auxiliaryRoleColor[]辅助色独立维度,0..12 槽位,与主体色模式无关。Independent auxiliary dimension, 0..12 slots, unrelated to the body mode.
gradientsGradientSettings8 渐变角色;family 支持 ColorFamily | 'third' | 'auxN'(N 为槽位索引)。Eight gradient roles; family accepts ColorFamily | 'third' | 'auxN' (N = slot index).
向后兼容原则:旧数据缺字段一律按 dual/manual/空辅助槽补默认;ThemeInput 与 Preset 均可选携带新字段,清洗层(sanitizePreset)做白名单校验并由 HEX 重建色阶。Backward compatibility: missing fields default to dual/manual/empty aux. ThemeInput and Preset carry the new fields optionally; the sanitize layer (sanitizePreset) whitelists values and rebuilds scales from HEX.

3 · core API 速览3 · core API Quick Tour

import {
  buildTheme, createThemeDraft, presetFromDraft, draftFromPreset,
  deriveSecondaryByRelation, deriveThirdByRelation, generateAuxiliaryCandidates,
  exportThemeCss, exportThemeJson, getExportTarget,
  encodeShareHash, decodeShareHash, buildSharePayload,
  parseThemePack, mergeImportedPresets, serializeThemeLibrary,
  FORM_PACKS, BAODIAN_PALETTE, SERIES_RELATION_DEFS,
} from '@hia/theme-core';

4 · Token 结构(CSS 变量)4 · Token Structure (CSS variables)

导出的 CSS 变量遵循分层命名:Exported variables follow layered naming:

--hia-primary-50 … --hia-primary-900   /* primary, 10 shades */
--hia-secondary-*, --hia-third-*        /* secondary / third families */
--hia-aux0-50 … --hia-auxN-900          /* auxiliary slots (N = index) */
--hia-on-primary / --hia-on-aux0        /* foregrounds (WCAG auto-picked) */
--hia-fs-h1 / --hia-line-height-body    /* typography & line-height tokens (ADR-006) */

运行时(预览区)另有 --p/--s/--t/--a{N} 前缀的快捷变量供 mock 与渐变消费。At runtime the preview area also exposes --p/--s/--t/--a{N} shorthand variables for mocks and gradients.

5 · 导出适配器5 · Export Adapters

6 · 桌面端架构与取色6 · Desktop Architecture & Extraction

两端共享同一 scanner bundle(HIA/extractor/dist/browser-scanner.bundle.js,IIFE 自包含),保证评分一致;构建校验脚本断言三端内容哈希一致。Both desktop ends share one scanner bundle (HIA/extractor/dist/browser-scanner.bundle.js, self-contained IIFE) so scores match; a build script asserts bundle hash equality across ends.

7 · 二次开发7 · Development

推荐环境:Node 22 LTS(仓库 .mise.toml 锁定,mise install)、PowerShell 7(Windows)、Rust stable(仅 Tauri)。Recommended: Node 22 LTS (pinned in .mise.toml, mise install), PowerShell 7 on Windows, Rust stable (Tauri only).

# Build core and run its tests
cd HIA/core && npm install && npm run build && node --test test/
# Web dev server
cd HIA/web && npm install && npm run dev
# Electron / Tauri
cd HIA/electron && npm install && npm start
cd HIA/tauri && npm install && npm run build

代码约定:全部语义节点中英双语文档化注释(ROP);三端渲染器产物哈希一致性由 CI 断言;新增第三方依赖须登记来源/版本/许可证并优先宽松许可。Conventions: bilingual (zh/en) doc comments on every semantic node (ROP); CI asserts renderer hash equality across ends; new third-party dependencies must record source/version/license, permissive licenses preferred.