@hia/theme-core 0.6.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/color/apca.d.ts +48 -0
- package/dist/color/apca.js +94 -0
- package/dist/color/contrast.d.ts +46 -0
- package/dist/color/contrast.js +113 -1
- package/dist/color/image-extract.d.ts +56 -0
- package/dist/color/image-extract.js +217 -0
- package/dist/color/semantic.d.ts +52 -0
- package/dist/color/semantic.js +68 -0
- package/dist/color/vision.d.ts +22 -0
- package/dist/color/vision.js +63 -0
- package/dist/export/dtcg.d.ts +70 -0
- package/dist/export/dtcg.js +433 -0
- package/dist/export/editor-themes.d.ts +62 -0
- package/dist/export/editor-themes.js +201 -0
- package/dist/export/inject-template.js +6 -2
- package/dist/export/registry.js +5 -1
- package/dist/export/tailwind.js +13 -1
- package/dist/export/tailwind4.d.ts +14 -0
- package/dist/export/tailwind4.js +66 -0
- package/dist/export/wordpress.js +1 -1
- package/dist/gradient/render.d.ts +4 -2
- package/dist/gradient/render.js +44 -5
- package/dist/index.d.ts +16 -1
- package/dist/index.js +29 -4
- package/dist/studio.js +3 -3
- package/dist/theme.js +12 -1
- package/dist/token/css.js +23 -3
- package/dist/token/json.js +6 -0
- package/dist/token/radius.d.ts +38 -0
- package/dist/token/radius.js +94 -0
- package/dist/types.d.ts +31 -0
- package/package.json +1 -1
package/dist/token/css.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { collectCustomShades, exportGradientVariableLines } from '../gradient/render.js';
|
|
2
|
+
import { radiusSequence, shadowCss } from './radius.js';
|
|
2
3
|
// 将完整主题导出为 :root CSS 自定义属性文本(设计系统/小程序消费入口)。
|
|
3
4
|
// <lang zh-CN>包含角色基色、前景色、主副色各 10 级色阶、渐变引用的自定义色阶(ADR-004 附加式)、
|
|
4
|
-
// 第三角色(ADR-007 v2
|
|
5
|
+
// 第三角色(ADR-007 v2,仅三色模式)、辅助色槽位与全部渐变变量;`W-tb-P37` 追加语义状态色、
|
|
6
|
+
// 圆角与阴影令牌;缩进贴近手写样式表。</lang>
|
|
5
7
|
// <lang en>Emits role base colors, foregrounds, 10-step scales, gradient-referenced custom shades
|
|
6
|
-
// (ADR-004 additive), the third role (ADR-007 v2, triad only), auxiliary slots and all gradient vars
|
|
8
|
+
// (ADR-004 additive), the third role (ADR-007 v2, triad only), auxiliary slots and all gradient vars;
|
|
9
|
+
// `W-tb-P37` adds semantic status tokens, radius and shadow tokens.</lang>
|
|
7
10
|
export function exportThemeCss(theme) {
|
|
8
11
|
// 自定义色阶:与运行时变量同源(collectCustomShades 去重插值),保证导出即可用。
|
|
9
12
|
// <lang zh-CN>键名与 --hia-primary-{shade} 规则一致,消费方 var() 引用无需区分。</lang>
|
|
@@ -29,14 +32,31 @@ export function exportThemeCss(theme) {
|
|
|
29
32
|
` --hia-on-aux${i}: ${aux.on};`,
|
|
30
33
|
...Object.entries(aux.scale).map(([k, v]) => `--hia-aux${i}-${k}: ${v};`)
|
|
31
34
|
].join('\n ')).join(theme.auxiliary.length ? '\n' : '');
|
|
35
|
+
// 语义状态色(ADR-012):仅当主题携带该组时输出;键名 --hia-<status>[-<shade>]/--hia-on-<status>。
|
|
36
|
+
// <lang zh-CN>未派生的旧主题不出现该段(产物与旧版一致)。</lang>
|
|
37
|
+
// <lang en>Emitted only when the theme carries the group; old themes without it keep identical output.</lang>
|
|
38
|
+
const semanticLines = theme.semantic ? Object.entries(theme.semantic).map(([k, role]) => [
|
|
39
|
+
` --hia-${k}: ${role.value};`,
|
|
40
|
+
` --hia-on-${k}: ${role.on};`,
|
|
41
|
+
...Object.entries(role.scale).map(([shade, v]) => `--hia-${k}-${shade}: ${v};`)
|
|
42
|
+
].join('\n ')).join('\n') : '';
|
|
43
|
+
// 圆角/阴影(`W-tb-P37`):五档圆角 px + 三档阴影字符串;阴影可随主色染色。
|
|
44
|
+
// <lang en>Radius/shadow (`W-tb-P37`): five radius steps (px) + three shadow strings; shadows may tint with
|
|
45
|
+
// the primary.</lang>
|
|
46
|
+
const radius = radiusSequence(theme.radius);
|
|
47
|
+
const shadows = shadowCss(theme.shadow, theme.primary.value);
|
|
48
|
+
const radiusLines = Object.entries(radius).map(([k, v]) => ` --hia-radius-${k}: ${v}px;`).join('\n');
|
|
49
|
+
const shadowLines = Object.entries(shadows).map(([k, v]) => ` --hia-shadow-${k}: ${v};`).join('\n');
|
|
32
50
|
return `:root {
|
|
33
51
|
--hia-primary: ${theme.primary.value};
|
|
34
52
|
--hia-on-primary: ${theme.primary.on};
|
|
35
53
|
--hia-secondary: ${theme.secondary.value};
|
|
36
54
|
--hia-on-secondary: ${theme.secondary.on};
|
|
37
55
|
${Object.entries(theme.primary.scale).map(([k, v]) => `--hia-primary-${k}: ${v};`).join('\n ')}${primaryCustom ? `\n ${primaryCustom}` : ''}
|
|
38
|
-
${Object.entries(theme.secondary.scale).map(([k, v]) => `--hia-secondary-${k}: ${v};`).join('\n ')}${secondaryCustom ? `\n ${secondaryCustom}` : ''}${thirdLines ? `\n ${thirdLines}` : ''}${auxLines ? `\n ${auxLines}` : ''}
|
|
56
|
+
${Object.entries(theme.secondary.scale).map(([k, v]) => `--hia-secondary-${k}: ${v};`).join('\n ')}${secondaryCustom ? `\n ${secondaryCustom}` : ''}${thirdLines ? `\n ${thirdLines}` : ''}${auxLines ? `\n ${auxLines}` : ''}${semanticLines ? `\n ${semanticLines}` : ''}
|
|
39
57
|
${exportGradientVariableLines(theme.gradients)}
|
|
58
|
+
${radiusLines}
|
|
59
|
+
${shadowLines}
|
|
40
60
|
}`;
|
|
41
61
|
}
|
|
42
62
|
//# sourceMappingURL=css.js.map
|
package/dist/token/json.js
CHANGED
|
@@ -28,6 +28,12 @@ export function exportThemeJson(theme) {
|
|
|
28
28
|
auxiliary: theme.auxiliary.map(a => ({ name: a.name, value: a.value, scale: a.scale, on: a.on })),
|
|
29
29
|
typography: theme.typography,
|
|
30
30
|
spacing: theme.spacing,
|
|
31
|
+
// 语义状态色 + 圆角/阴影(`W-tb-P37`,ADR-012):可选组,携带时全量输出(消费方免重建)。
|
|
32
|
+
// <lang en>Semantic statuses + radius/shadow (`W-tb-P37`, ADR-012): optional groups emitted in full when
|
|
33
|
+
// present, so consumers need no rebuild.</lang>
|
|
34
|
+
...(theme.semantic ? { semantic: theme.semantic } : {}),
|
|
35
|
+
...(theme.radius ? { radius: theme.radius } : {}),
|
|
36
|
+
...(theme.shadow ? { shadow: theme.shadow } : {}),
|
|
31
37
|
gradients: theme.gradients
|
|
32
38
|
}, null, 2);
|
|
33
39
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lang zh-CN 圆角与阴影令牌(`W-tb-P37`,ADR-006 契约位落地):档位派生纯函数。
|
|
3
|
+
* 圆角五档由基准值派生;阴影三档由强度派生(可混入主色低透明度做品牌化阴影)。
|
|
4
|
+
* 全部纯函数、无 IO——与色阶/间距同一套生成式令牌管线(ADR-006 决策 2)。
|
|
5
|
+
*
|
|
6
|
+
* @lang en Radius & shadow tokens (`W-tb-P37`, ADR-006 contract slot landed): pure derivation functions.
|
|
7
|
+
* Five radius steps derive from one base; three shadow levels derive from strength (optionally tinted with
|
|
8
|
+
* the primary colour). Pure and IO-free — the same generative pipeline as scales/spacing (ADR-006 decision 2).
|
|
9
|
+
*/
|
|
10
|
+
import type { RadiusTokens, ShadowTokens } from '../types.js';
|
|
11
|
+
/** @lang zh-CN 圆角档位键。 @lang en Radius step keys. */
|
|
12
|
+
export type RadiusStep = 'sm' | 'md' | 'lg' | 'xl' | 'pill';
|
|
13
|
+
/** @lang zh-CN 圆角令牌默认值(8px 基准——主流设计系统最常见档)。 @lang en Radius defaults (8px base — the most common design-system step). */
|
|
14
|
+
export declare const RADIUS_DEFAULTS: RadiusTokens;
|
|
15
|
+
/** @lang zh-CN 阴影令牌默认值(soft 档——适合浅色后台)。 @lang en Shadow defaults (soft — suits light consoles). */
|
|
16
|
+
export declare const SHADOW_DEFAULTS: ShadowTokens;
|
|
17
|
+
export declare function cloneRadiusTokens(tokens?: Partial<RadiusTokens> | null): RadiusTokens;
|
|
18
|
+
export declare function cloneShadowTokens(tokens?: Partial<ShadowTokens> | null): ShadowTokens;
|
|
19
|
+
/**
|
|
20
|
+
* @lang zh-CN 圆角档位序列(px):sm=base/2、md=base、lg=×1.5、xl=×2、pill=胶囊(999 保证全圆)。
|
|
21
|
+
* overrides 按 `radius-sm` 等键覆写单档。纯函数。
|
|
22
|
+
* @lang en Radius sequence (px): sm=base/2, md=base, lg=×1.5, xl=×2, pill=999 (guaranteed full round).
|
|
23
|
+
* Overrides apply per step via keys like `radius-sm`. Pure.
|
|
24
|
+
*/
|
|
25
|
+
export declare function radiusSequence(tokens?: Partial<RadiusTokens> | null): Record<RadiusStep, number>;
|
|
26
|
+
/** @lang zh-CN 阴影档位键(sm/md/lg)。 @lang en Shadow level keys (sm/md/lg). */
|
|
27
|
+
export type ShadowLevel = 'sm' | 'md' | 'lg';
|
|
28
|
+
/**
|
|
29
|
+
* @lang zh-CN 阴影三档 CSS box-shadow 字符串:`x y blur spread color` 双层(环境层 + 贴近层)。
|
|
30
|
+
* tintFromPrimary 时阴影色向主色色相偏移(低饱和、低透明度)——品牌化但不脏版面。
|
|
31
|
+
* strength='none' 时全部为 'none'(可读性兜底:调用方不必分支)。overrides 按键 `shadow-sm` 等覆写。
|
|
32
|
+
* @lang en Shadow CSS box-shadow strings for three levels: two-layer `x y blur spread color` (ambient + key).
|
|
33
|
+
* tintFromPrimary shifts shadow hue toward the primary (low sat/alpha — branded but not muddy);
|
|
34
|
+
* strength='none' yields 'none' for all levels so callers need no branching. Overrides via keys like
|
|
35
|
+
* `shadow-sm`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function shadowCss(tokens: Partial<ShadowTokens> | null | undefined, primaryHex: string): Record<ShadowLevel, string>;
|
|
38
|
+
//# sourceMappingURL=radius.d.ts.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { hexToRgb } from '../color/convert.js';
|
|
2
|
+
/** @lang zh-CN 圆角令牌默认值(8px 基准——主流设计系统最常见档)。 @lang en Radius defaults (8px base — the most common design-system step). */
|
|
3
|
+
export const RADIUS_DEFAULTS = { base: 8 };
|
|
4
|
+
/** @lang zh-CN 阴影令牌默认值(soft 档——适合浅色后台)。 @lang en Shadow defaults (soft — suits light consoles). */
|
|
5
|
+
export const SHADOW_DEFAULTS = { strength: 'soft' };
|
|
6
|
+
// 补齐圆角配置:缺省/非法回退默认值(clone 语义,向后兼容 ADR-006 决策 4)。
|
|
7
|
+
// <lang en>Normalise radius config: missing/invalid falls back to defaults (clone semantics, ADR-006 decision 4).</lang>
|
|
8
|
+
export function cloneRadiusTokens(tokens) {
|
|
9
|
+
const base = tokens && Number.isFinite(tokens.base) && tokens.base >= 0 ? tokens.base : RADIUS_DEFAULTS.base;
|
|
10
|
+
return { base, overrides: tokens?.overrides ? { ...tokens.overrides } : undefined };
|
|
11
|
+
}
|
|
12
|
+
// 补齐阴影配置:非法强度回退 soft。
|
|
13
|
+
// <lang en>Normalise shadow config: invalid strength falls back to soft.</lang>
|
|
14
|
+
export function cloneShadowTokens(tokens) {
|
|
15
|
+
const strength = tokens && ['none', 'soft', 'medium', 'strong'].includes(tokens.strength) ? tokens.strength : SHADOW_DEFAULTS.strength;
|
|
16
|
+
return { strength, tintFromPrimary: tokens?.tintFromPrimary ?? false, overrides: tokens?.overrides ? { ...tokens.overrides } : undefined };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @lang zh-CN 圆角档位序列(px):sm=base/2、md=base、lg=×1.5、xl=×2、pill=胶囊(999 保证全圆)。
|
|
20
|
+
* overrides 按 `radius-sm` 等键覆写单档。纯函数。
|
|
21
|
+
* @lang en Radius sequence (px): sm=base/2, md=base, lg=×1.5, xl=×2, pill=999 (guaranteed full round).
|
|
22
|
+
* Overrides apply per step via keys like `radius-sm`. Pure.
|
|
23
|
+
*/
|
|
24
|
+
export function radiusSequence(tokens) {
|
|
25
|
+
const t = cloneRadiusTokens(tokens);
|
|
26
|
+
const pill = 999;
|
|
27
|
+
const seq = {
|
|
28
|
+
sm: Math.round(t.base / 2),
|
|
29
|
+
md: Math.round(t.base),
|
|
30
|
+
lg: Math.round(t.base * 1.5),
|
|
31
|
+
xl: Math.round(t.base * 2),
|
|
32
|
+
pill
|
|
33
|
+
};
|
|
34
|
+
// 覆写:显式指定某档则用覆写值(pill 覆写同样尊重)。
|
|
35
|
+
// <lang en>Overrides: an explicit step wins (pill overrides respected too).</lang>
|
|
36
|
+
for (const step of Object.keys(seq)) {
|
|
37
|
+
const key = `radius-${step}`;
|
|
38
|
+
const v = t.overrides?.[key];
|
|
39
|
+
if (Number.isFinite(v))
|
|
40
|
+
seq[step] = v;
|
|
41
|
+
}
|
|
42
|
+
return seq;
|
|
43
|
+
}
|
|
44
|
+
// 各强度的阴影基参数:偏移/模糊/透明度随强度递增。
|
|
45
|
+
// <lang en>Shadow base params per strength: offset/blur/alpha grow with strength.</lang>
|
|
46
|
+
const SHADOW_PARAMS = {
|
|
47
|
+
none: null,
|
|
48
|
+
soft: { y: 1, blur: 3, spread: 0, alpha: 0.10 },
|
|
49
|
+
medium: { y: 2, blur: 8, spread: 0, alpha: 0.14 },
|
|
50
|
+
strong: { y: 4, blur: 16, spread: 0, alpha: 0.20 }
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @lang zh-CN 阴影三档 CSS box-shadow 字符串:`x y blur spread color` 双层(环境层 + 贴近层)。
|
|
54
|
+
* tintFromPrimary 时阴影色向主色色相偏移(低饱和、低透明度)——品牌化但不脏版面。
|
|
55
|
+
* strength='none' 时全部为 'none'(可读性兜底:调用方不必分支)。overrides 按键 `shadow-sm` 等覆写。
|
|
56
|
+
* @lang en Shadow CSS box-shadow strings for three levels: two-layer `x y blur spread color` (ambient + key).
|
|
57
|
+
* tintFromPrimary shifts shadow hue toward the primary (low sat/alpha — branded but not muddy);
|
|
58
|
+
* strength='none' yields 'none' for all levels so callers need no branching. Overrides via keys like
|
|
59
|
+
* `shadow-sm`.
|
|
60
|
+
*/
|
|
61
|
+
export function shadowCss(tokens, primaryHex) {
|
|
62
|
+
const t = cloneShadowTokens(tokens);
|
|
63
|
+
const out = {};
|
|
64
|
+
for (const level of ['sm', 'md', 'lg']) {
|
|
65
|
+
const key = `shadow-${level}`;
|
|
66
|
+
const override = t.overrides?.[key];
|
|
67
|
+
if (override) {
|
|
68
|
+
out[level] = override;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const params = SHADOW_PARAMS[t.strength];
|
|
72
|
+
if (!params) {
|
|
73
|
+
out[level] = 'none';
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
// 双层阴影:外层环境阴影(大模糊低透明)+ 内层贴近阴影(小偏移)。
|
|
77
|
+
// <lang en>Two layers: outer ambient (large blur, low alpha) + inner key shadow (small offset).</lang>
|
|
78
|
+
const scale = level === 'sm' ? 1 : level === 'md' ? 1.8 : 3.2;
|
|
79
|
+
const alpha = params.alpha * (level === 'sm' ? 1 : level === 'md' ? 1.05 : 1.15);
|
|
80
|
+
if (t.tintFromPrimary) {
|
|
81
|
+
// 染色阴影:主色线性 RGB 与中性暗色按 alpha 混出阴影基色。
|
|
82
|
+
// <lang en>Tinted shadow: mix the primary's linear RGB with a neutral dark at alpha.</lang>
|
|
83
|
+
const [r, g, b] = hexToRgb(primaryHex);
|
|
84
|
+
const mix = (c) => Math.round((c * 0.35 + 0.08 * 0.65) * 255);
|
|
85
|
+
const shade = `rgb(${mix(r)} ${mix(g)} ${mix(b)} / ${alpha.toFixed(3)})`;
|
|
86
|
+
out[level] = `0 ${params.y * scale}px ${params.blur * scale}px ${params.spread}px ${shade}, 0 ${params.y}px ${params.blur}px 0 ${shade}`;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
out[level] = `0 ${params.y * scale}px ${params.blur * scale}px ${params.spread}px rgb(15 23 42 / ${alpha.toFixed(3)}), 0 ${params.y}px ${params.blur}px 0 rgb(15 23 42 / ${alpha.toFixed(3)})`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=radius.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -46,6 +46,22 @@ export interface SpacingTokens {
|
|
|
46
46
|
levels: number;
|
|
47
47
|
overrides?: Record<string, number>;
|
|
48
48
|
}
|
|
49
|
+
export interface RadiusTokens {
|
|
50
|
+
base: number;
|
|
51
|
+
overrides?: Record<string, number>;
|
|
52
|
+
}
|
|
53
|
+
export interface ShadowTokens {
|
|
54
|
+
strength: 'none' | 'soft' | 'medium' | 'strong';
|
|
55
|
+
tintFromPrimary?: boolean;
|
|
56
|
+
overrides?: Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
export type SemanticStatusKey = 'success' | 'info' | 'warning' | 'danger';
|
|
59
|
+
export interface SemanticTokens {
|
|
60
|
+
success: RoleColor;
|
|
61
|
+
info: RoleColor;
|
|
62
|
+
warning: RoleColor;
|
|
63
|
+
danger: RoleColor;
|
|
64
|
+
}
|
|
49
65
|
export interface Theme {
|
|
50
66
|
name: string;
|
|
51
67
|
category: string;
|
|
@@ -60,6 +76,9 @@ export interface Theme {
|
|
|
60
76
|
seriesRelation: SeriesRelationId;
|
|
61
77
|
thirdColor?: RoleColor;
|
|
62
78
|
auxiliary: RoleColor[];
|
|
79
|
+
radius?: RadiusTokens;
|
|
80
|
+
shadow?: ShadowTokens;
|
|
81
|
+
semantic?: SemanticTokens;
|
|
63
82
|
}
|
|
64
83
|
export interface ThemeInput {
|
|
65
84
|
name?: string;
|
|
@@ -78,6 +97,9 @@ export interface ThemeInput {
|
|
|
78
97
|
thirdColor?: RoleColor;
|
|
79
98
|
auxiliary?: RoleColor[];
|
|
80
99
|
auxiliaryModifiers?: AuxiliaryModifier[];
|
|
100
|
+
radius?: RadiusTokens;
|
|
101
|
+
shadow?: ShadowTokens;
|
|
102
|
+
semantic?: SemanticTokens;
|
|
81
103
|
}
|
|
82
104
|
export interface PrimaryCandidate {
|
|
83
105
|
id: string;
|
|
@@ -107,6 +129,10 @@ export interface Preset {
|
|
|
107
129
|
seriesRelation?: SeriesRelationId;
|
|
108
130
|
thirdColor?: RoleColor;
|
|
109
131
|
auxiliary?: RoleColor[];
|
|
132
|
+
radius?: RadiusTokens;
|
|
133
|
+
shadow?: ShadowTokens;
|
|
134
|
+
semantic?: SemanticTokens;
|
|
135
|
+
semanticDerived?: Record<string, boolean>;
|
|
110
136
|
}
|
|
111
137
|
export interface HarmonyDef {
|
|
112
138
|
id: string;
|
|
@@ -136,6 +162,11 @@ export interface ThemeDraft {
|
|
|
136
162
|
thirdColor?: RoleColor;
|
|
137
163
|
auxiliary?: RoleColor[];
|
|
138
164
|
auxiliaryModifiers?: AuxiliaryModifier[];
|
|
165
|
+
radius?: RadiusTokens;
|
|
166
|
+
shadow?: ShadowTokens;
|
|
167
|
+
semantic?: SemanticTokens;
|
|
168
|
+
/** @lang zh-CN 语义色派生标记(ADR-012):true=仍随主色派生;缺省 false=用户值不跟随。 @lang en Semantic derivation flags (ADR-012): true = still derived from primary; absent/false = user-managed. */
|
|
169
|
+
semanticDerived?: Record<string, boolean>;
|
|
139
170
|
}
|
|
140
171
|
export type SeriesMode = 'single' | 'dual' | 'triad';
|
|
141
172
|
export type SeriesRelationId = 'manual' | 'complement' | 'clash' | 'neutral' | 'analogous' | 'split-complement' | 'tertiary' | 'primary-combo' | 'secondary-combo' | 'pure';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hia/theme-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"description": "HIA cross-platform theme domain core: models, OKLCH algorithms, theme studio state, gradient rendering, token export and website-color analysis.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "HIA Theme Builder contributors",
|