@qw-ui/tokens 0.1.0 → 0.2.0

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.
@@ -0,0 +1,122 @@
1
+ export declare const FIGMA_COLOR_COLLECTION = "Color";
2
+ export declare const FIGMA_COLOR_PREFIX = "qw";
3
+ export declare const T1_COLOR_KEYS: readonly ["brand", "black", "white", "gray", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "brown"];
4
+ export type T1ColorKey = (typeof T1_COLOR_KEYS)[number];
5
+ export declare const FIGMA_T1_SEED_HEX: Record<T1ColorKey, string>;
6
+ export declare const T2_ALPHA_STEPS: readonly [5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
7
+ export declare const T2_ALPHA_KEYS: ["a5", "a10", "a20", "a30", "a40", "a50", "a60", "a70", "a80", "a90", "a100"];
8
+ export type T2AlphaStep = (typeof T2_ALPHA_STEPS)[number];
9
+ export type T2AlphaKey = (typeof T2_ALPHA_KEYS)[number];
10
+ export declare const T2_OKLCH_STEPS: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
11
+ export type T2OklchStep = (typeof T2_OKLCH_STEPS)[number];
12
+ export declare const FIGMA_T2_SOLID_SCALE: Record<T1ColorKey, Record<T2OklchStep, string>>;
13
+ export declare const FIGMA_T3_COLOR_ROLES: {
14
+ readonly "surface.base": {
15
+ readonly light: "color.white.base";
16
+ readonly dark: "color.black.base";
17
+ };
18
+ readonly "surface.subtle": {
19
+ readonly light: "color.gray.50";
20
+ readonly dark: "color.gray.900";
21
+ };
22
+ readonly "surface.elevated": {
23
+ readonly light: "color.white.base";
24
+ readonly dark: "color.gray.800";
25
+ };
26
+ readonly "surface.header": {
27
+ readonly light: "color.gray.100";
28
+ readonly dark: "color.gray.700";
29
+ };
30
+ readonly "surface.brand-subtle": {
31
+ readonly light: "color.blue.50";
32
+ readonly dark: "color.blue.800";
33
+ };
34
+ readonly "content.primary": {
35
+ readonly light: "color.black.base";
36
+ readonly dark: "color.white.base";
37
+ };
38
+ readonly "content.secondary": {
39
+ readonly light: "color.gray.600";
40
+ readonly dark: "color.gray.base";
41
+ };
42
+ readonly "content.tertiary": {
43
+ readonly light: "color.gray.base";
44
+ readonly dark: "color.gray.600";
45
+ };
46
+ readonly "content.placeholder": {
47
+ readonly light: "color.gray.300";
48
+ readonly dark: "color.white.a30";
49
+ };
50
+ readonly "content.intro": {
51
+ readonly light: "color.gray.400";
52
+ readonly dark: "color.gray.500";
53
+ };
54
+ readonly "border.default": {
55
+ readonly light: "color.gray.100";
56
+ readonly dark: "color.gray.700";
57
+ };
58
+ readonly "border.strong": {
59
+ readonly light: "color.gray.300";
60
+ readonly dark: "color.gray.600";
61
+ };
62
+ readonly "border.focus": {
63
+ readonly light: "color.brand.base";
64
+ readonly dark: "color.brand.500";
65
+ };
66
+ readonly "fill.subtle": {
67
+ readonly light: "color.gray.50";
68
+ readonly dark: "color.white.a20";
69
+ };
70
+ readonly "fill.hover": {
71
+ readonly light: "color.gray.100";
72
+ readonly dark: "color.gray.800";
73
+ };
74
+ readonly "fill.active": {
75
+ readonly light: "color.blue.50";
76
+ readonly dark: "color.blue.800";
77
+ };
78
+ readonly "fill.disabled": {
79
+ readonly light: "color.gray.50";
80
+ readonly dark: "color.gray.900";
81
+ };
82
+ readonly "action.brand": {
83
+ readonly light: "color.brand.base";
84
+ readonly dark: "color.brand.500";
85
+ };
86
+ readonly "action.product": {
87
+ readonly light: "color.blue.base";
88
+ readonly dark: "color.blue.600";
89
+ };
90
+ readonly "action.selected": {
91
+ readonly light: "color.blue.a20";
92
+ readonly dark: "color.blue.a40";
93
+ };
94
+ readonly "action.inverse": {
95
+ readonly light: "color.white.base";
96
+ readonly dark: "color.black.base";
97
+ };
98
+ readonly "status.success": {
99
+ readonly light: "color.green.base";
100
+ readonly dark: "color.green.base";
101
+ };
102
+ readonly "status.warning": {
103
+ readonly light: "color.yellow.base";
104
+ readonly dark: "color.yellow.base";
105
+ };
106
+ readonly "status.danger": {
107
+ readonly light: "color.red.400";
108
+ readonly dark: "color.red.400";
109
+ };
110
+ readonly "status.info": {
111
+ readonly light: "color.blue.base";
112
+ readonly dark: "color.blue.600";
113
+ };
114
+ readonly "overlay.scrim": {
115
+ readonly light: "color.black.a50";
116
+ readonly dark: "color.black.a70";
117
+ };
118
+ readonly "overlay.guide": {
119
+ readonly light: "color.black.a70";
120
+ readonly dark: "color.black.a70";
121
+ };
122
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * SeedColorValue — DTCG Color module 结构化颜色(design-tokens.org 2025.10)。
3
+ * Seed 层颜色不再用十六进制字符串:结构化后输出 Web / iOS / Android / Figma
4
+ * 插件 / 文档都更稳定,且支持 oklch 等更高级色彩空间直接作为设计输入。
5
+ *
6
+ * - srgb:components = [r, g, b],各分量 0–1(不是 0–255)。
7
+ * - oklch:components = [l, c, h](l 0–1、c ≥0、h 角度)。
8
+ */
9
+ export interface SeedColorValue {
10
+ colorSpace: "srgb" | "oklch";
11
+ components: [number, number, number];
12
+ alpha: number;
13
+ }
14
+ type CuloriColor = {
15
+ mode: "rgb";
16
+ r: number;
17
+ g: number;
18
+ b: number;
19
+ alpha?: number;
20
+ } | {
21
+ mode: "oklch";
22
+ l: number;
23
+ c: number;
24
+ h: number;
25
+ alpha?: number;
26
+ };
27
+ /** SeedColorValue → culori 可消费的颜色对象。 */
28
+ export declare function toCulori(c: SeedColorValue): CuloriColor;
29
+ /** 十六进制(#rgb / #rrggbb)→ 结构化 srgb SeedColorValue。编辑器色板输入的桥。 */
30
+ export declare function hexToSeedColor(hex: string): SeedColorValue;
31
+ /** 结构化颜色 → #rrggbb(丢 alpha;oklch 会先转 sRGB)。展示/对比度计算用。 */
32
+ export declare function seedColorToHex(c: SeedColorValue): string;
33
+ /**
34
+ * 结构化颜色 → CSS 颜色字符串。srgb 且不透明输出 hex;srgb 半透明输出
35
+ * `rgb(r g b / a)`;oklch 保持原生 `oklch(l c h / a)`(relative color 派生保真)。
36
+ */
37
+ export declare function seedColorToCss(c: SeedColorValue): string;
38
+ export {};
@@ -0,0 +1,14 @@
1
+ import { type CompatEntry, type CompatRegistry } from "./schema.js";
2
+ export interface CompatBuild {
3
+ light: Record<string, string>;
4
+ dark: Record<string, string>;
5
+ /** path → cssVar */
6
+ paths: Record<string, string>;
7
+ /** component → suffix[] */
8
+ byComponent: Record<string, string[]>;
9
+ entries: CompatEntry[];
10
+ graceDays: number;
11
+ }
12
+ export declare function buildCompatFromRegistry(registry: CompatRegistry): CompatBuild;
13
+ /** 生成 compat token-paths TypeScript 片段(并入 tokens.ts) */
14
+ export declare function formatCompatTypes(build: CompatBuild): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 将 legacy hex(含 /NN% 透明度后缀)或 DTCG srgb 结构转为 CSS 颜色字符串。
3
+ */
4
+ export declare function compatColorToCss(input: string | {
5
+ colorSpace: "srgb";
6
+ components: [number, number, number];
7
+ alpha: number;
8
+ }): string;
@@ -0,0 +1,5 @@
1
+ export { compatRegistrySchema, compatEntrySchema, compatPathToCssVar, compatComponentOf, compatSuffixOf, } from "./schema.js";
2
+ export type { CompatEntry, CompatRegistry, CompatStatus } from "./schema.js";
3
+ export { compatColorToCss } from "./color.js";
4
+ export { buildCompatFromRegistry, formatCompatTypes, } from "./build.js";
5
+ export type { CompatBuild } from "./build.js";
@@ -0,0 +1,114 @@
1
+ import { z } from "zod";
2
+ export declare const compatStatusSchema: z.ZodEnum<{
3
+ active: "active";
4
+ aliased: "aliased";
5
+ deprecated: "deprecated";
6
+ }>;
7
+ export declare const compatEntrySchema: z.ZodObject<{
8
+ path: z.ZodString;
9
+ type: z.ZodEnum<{
10
+ color: "color";
11
+ dimension: "dimension";
12
+ motion: "motion";
13
+ typography: "typography";
14
+ }>;
15
+ value: z.ZodUnion<readonly [z.ZodObject<{
16
+ light: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
17
+ colorSpace: z.ZodLiteral<"srgb">;
18
+ components: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
19
+ alpha: z.ZodNumber;
20
+ }, z.core.$strip>, z.ZodString]>;
21
+ dark: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
22
+ colorSpace: z.ZodLiteral<"srgb">;
23
+ components: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
24
+ alpha: z.ZodNumber;
25
+ }, z.core.$strip>, z.ZodString]>;
26
+ }, z.core.$strip>, z.ZodObject<{
27
+ value: z.ZodNumber;
28
+ unit: z.ZodEnum<{
29
+ "%": "%";
30
+ em: "em";
31
+ px: "px";
32
+ rem: "rem";
33
+ }>;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ aliasOf: z.ZodString;
36
+ }, z.core.$strip>]>;
37
+ source: z.ZodObject<{
38
+ figma: z.ZodString;
39
+ nodeId: z.ZodString;
40
+ legacyName: z.ZodNullable<z.ZodString>;
41
+ }, z.core.$strip>;
42
+ introducedBy: z.ZodString;
43
+ reason: z.ZodString;
44
+ owner: z.ZodString;
45
+ targetSemanticRole: z.ZodNullable<z.ZodString>;
46
+ status: z.ZodEnum<{
47
+ active: "active";
48
+ aliased: "aliased";
49
+ deprecated: "deprecated";
50
+ }>;
51
+ reviewAfter: z.ZodString;
52
+ migrationIssue: z.ZodNullable<z.ZodString>;
53
+ }, z.core.$strip>;
54
+ export declare const compatRegistrySchema: z.ZodObject<{
55
+ $description: z.ZodOptional<z.ZodString>;
56
+ version: z.ZodLiteral<1>;
57
+ graceDays: z.ZodDefault<z.ZodNumber>;
58
+ entries: z.ZodArray<z.ZodObject<{
59
+ path: z.ZodString;
60
+ type: z.ZodEnum<{
61
+ color: "color";
62
+ dimension: "dimension";
63
+ motion: "motion";
64
+ typography: "typography";
65
+ }>;
66
+ value: z.ZodUnion<readonly [z.ZodObject<{
67
+ light: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
68
+ colorSpace: z.ZodLiteral<"srgb">;
69
+ components: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
70
+ alpha: z.ZodNumber;
71
+ }, z.core.$strip>, z.ZodString]>;
72
+ dark: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
73
+ colorSpace: z.ZodLiteral<"srgb">;
74
+ components: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
75
+ alpha: z.ZodNumber;
76
+ }, z.core.$strip>, z.ZodString]>;
77
+ }, z.core.$strip>, z.ZodObject<{
78
+ value: z.ZodNumber;
79
+ unit: z.ZodEnum<{
80
+ "%": "%";
81
+ em: "em";
82
+ px: "px";
83
+ rem: "rem";
84
+ }>;
85
+ }, z.core.$strip>, z.ZodObject<{
86
+ aliasOf: z.ZodString;
87
+ }, z.core.$strip>]>;
88
+ source: z.ZodObject<{
89
+ figma: z.ZodString;
90
+ nodeId: z.ZodString;
91
+ legacyName: z.ZodNullable<z.ZodString>;
92
+ }, z.core.$strip>;
93
+ introducedBy: z.ZodString;
94
+ reason: z.ZodString;
95
+ owner: z.ZodString;
96
+ targetSemanticRole: z.ZodNullable<z.ZodString>;
97
+ status: z.ZodEnum<{
98
+ active: "active";
99
+ aliased: "aliased";
100
+ deprecated: "deprecated";
101
+ }>;
102
+ reviewAfter: z.ZodString;
103
+ migrationIssue: z.ZodNullable<z.ZodString>;
104
+ }, z.core.$strip>>;
105
+ }, z.core.$strip>;
106
+ export type CompatEntry = z.infer<typeof compatEntrySchema>;
107
+ export type CompatRegistry = z.infer<typeof compatRegistrySchema>;
108
+ export type CompatStatus = z.infer<typeof compatStatusSchema>;
109
+ /** path → CSS 变量名:`button.color.bg-soft-brand` → `--qw-compat-button-color-bg-soft-brand` */
110
+ export declare function compatPathToCssVar(path: string): string;
111
+ /** path → component slug(第一段) */
112
+ export declare function compatComponentOf(path: string): string;
113
+ /** path → helper suffix(component 之后的段,用 `-` 连接) */
114
+ export declare function compatSuffixOf(path: string): string;
@@ -0,0 +1,25 @@
1
+ import type { Seed } from "../schema.js";
2
+ export { toVar } from "./naming.js";
3
+ export type { Layer } from "./naming.js";
4
+ export { ramp, STEPS, L_TARGETS, chromaFactor, contrastRatio } from "./oklch.js";
5
+ export type { Step, Ramp } from "./oklch.js";
6
+ export type { SemanticMode as Mode } from "./semantic.js";
7
+ export type { ReferenceRecipe, ReferenceTokens, ReferenceBuild, Derivation, ShadowLevel, ShadowShape, } from "./reference.js";
8
+ export { buildReference, allReferenceRecipes, evaluateDerivation, seedRefsOf, formatDerivation, seedValueAt, RAMP_COLORS, BLACK_ALPHA, WHITE_ALPHA, RADIUS_FACTORS, FONT_SIZE_FACTORS, DURATION_FACTORS, SHADOW_LEVELS, FONT_FAMILY_KEYS, } from "./reference.js";
9
+ export { buildSemanticStructural, buildSemanticColor, semanticRoleEntries, RADIUS_ROLES, CONTROL_HEIGHT_ROLES, ICON_SIZE_ROLES, INSET_STACK_ROLES, Z_INDEX_ROLES, MOTION_DURATION_ROLES, FONT_FAMILY_ROLES, TYPOGRAPHY_ROLES, TYPOGRAPHY_FIELDS, COLOR_ROLES, SHADOW_COMPOSITE_ROLES, } from "./semantic.js";
10
+ export type { SemanticRoleEntry, ColorRoleRefs, TypographyRole } from "./semantic.js";
11
+ export interface DerivedTokens {
12
+ /** 亮色全量 CSS 变量:--qw-ref-* ∪ --qw-sem-*(light 取值)。 */
13
+ light: Record<string, string>;
14
+ /** 暗色全量 CSS 变量:--qw-ref-* ∪ --qw-sem-*(dark 取值)。 */
15
+ dark: Record<string, string>;
16
+ }
17
+ /**
18
+ * derive — 单源派生(RFC 0001)。喂一个 Seed,编排 T2 Reference → T3 Semantic,
19
+ * 返回亮/暗两套全量 CSS 变量映射(含 --qw-ref-* 与 --qw-sem-*)。
20
+ * 外部签名/返回值形状与改造前保持一致(FR-014),供 `@qw-ui/react`、`@qw-ui/vue` 的
21
+ * ConfigProvider 直接消费,无需改动。
22
+ *
23
+ * 注意:`validateSeed` 不在此处调用(沿用现状契约),校验是调用方的责任。
24
+ */
25
+ export declare function derive(seed: Seed): DerivedTokens;
@@ -0,0 +1,18 @@
1
+ import { type Derivation } from "./reference.js";
2
+ import type { Seed } from "../schema.js";
3
+ /** Seed 拍平成 `--qw-seed-*` → CSS 值。live CSS 里唯一携带具体数值的层。 */
4
+ export declare function seedCssVars(seed: Seed): Record<string, string>;
5
+ /** 一条 Derivation → 引用 `--qw-seed-*` 的 CSS 原生表达式。 */
6
+ export declare function derivationToCssExpr(d: Derivation): string;
7
+ export interface LiveCssOptions {
8
+ /** 亮色作用域选择器,默认 ":root"。 */
9
+ selector?: string;
10
+ /** 暗色作用域选择器,默认 '[data-qw-mode="dark"]'。 */
11
+ darkSelector?: string;
12
+ }
13
+ /**
14
+ * 生成整份 live CSS:
15
+ * 1. seed 块(具体数值);2. ref 块(表达式派生);3. sem 块(light 别名);
16
+ * 4. dark 块(仅重映射随 mode 变化的 sem 颜色别名)。
17
+ */
18
+ export declare function buildLiveCss(seed: Seed, options?: LiveCssOptions): string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * T1/T2/T3 token 的 CSS 变量命名:`--qw-{layer}-{kebab(path)}`。
3
+ *
4
+ * `layer` 区分 Seed("seed",仅出现在 live CSS 产物里、供响应式级联的锚点变量)、
5
+ * Reference("ref",原子层,组件禁止直接引用)与 Semantic("sem",组件唯一
6
+ * 合法消费入口)。`path` 的每个 segment 是内部 TS 属性名(天然 camelCase,
7
+ * 如 "brandSubtle"/"controlSize"),命名前需转成 kebab-case 才能对齐
8
+ * packages/tokens/design/*.tokens.json 里锁定的 cssVar 字符串。
9
+ *
10
+ * 例:toVar("sem", ["color","surface","brandSubtle"]) → "--qw-sem-color-surface-brand-subtle"
11
+ * toVar("sem", ["size","controlHeight","sm"]) → "--qw-sem-size-control-height-sm"
12
+ * toVar("seed", ["color","brand"]) → "--qw-seed-color-brand"
13
+ *
14
+ * 这是唯一命名口子,运行时 flat var map、build-tokens.ts 的 CSS 出口与
15
+ * live CSS 生成器共用。
16
+ */
17
+ export type Layer = "seed" | "ref" | "sem";
18
+ export declare function toVar(layer: Layer, path: string[]): string;
@@ -0,0 +1,28 @@
1
+ import { type SeedColorValue } from "../color.js";
2
+ /** 10 档 token: 50 / 100 / 200 / ... / 900 */
3
+ export declare const STEPS: readonly [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
4
+ export type Step = (typeof STEPS)[number];
5
+ /**
6
+ * OKLCH L 目标曲线 — 感知均匀的亮度阶梯 (0..1)。
7
+ * 50 最亮 → 900 最暗;端点 0.972 / 0.18 避免纯白纯黑导致对比"塌"。
8
+ * (替换原 HSV:HSV 在感知上不均匀,深档发灰/浅档发白,WCAG 易不过。)
9
+ *
10
+ * 导出供 live-css 生成器复用:CSS relative color 语法
11
+ * `oklch(from var(--seed) L calc(c * f) h)` 的 L/f 常量与这里同源。
12
+ */
13
+ export declare const L_TARGETS: Record<Step, number>;
14
+ /**
15
+ * chroma 端点衰减 — 在 L 的亮/暗两端轻微衰减 chroma,避免 out-of-gamut;
16
+ * 中段 (L≈0.6) 保留全 chroma。
17
+ */
18
+ export declare function chromaFactor(l: number): number;
19
+ export type Ramp = Record<Step, string>;
20
+ /**
21
+ * 给一个 seed 颜色(结构化 SeedColorValue 或 CSS 颜色字符串),算 10 阶 ramp。
22
+ * L 走目标曲线,hue 固定,chroma 端点衰减后再 clampChroma 收进 sRGB 色域。
23
+ */
24
+ export declare function ramp(seedColor: SeedColorValue | string): Ramp;
25
+ /** 相对亮度 (WCAG) — 用于对偶/校验时的对比度判断。 */
26
+ export declare function relativeLuminance(hex: string): number;
27
+ /** WCAG 对比度 (1..21)。 */
28
+ export declare function contrastRatio(fg: string, bg: string): number;
@@ -0,0 +1,189 @@
1
+ import { type Step } from "./oklch.js";
2
+ import { type T2OklchStep } from "../color-architecture.js";
3
+ import type { Seed } from "../schema.js";
4
+ /**
5
+ * T2 Reference(Primitive)派生 —— RFC 0001 §2.1,v3 声明式重构。
6
+ *
7
+ * v3 核心变化:每条 Reference token 的派生规则不再是不透明的 `(seed) => string`
8
+ * 函数,而是可机器读取的 `Derivation` AST——同一份 AST 同时驱动:
9
+ * 1. 运行时求值(evaluateDerivation → tokens);
10
+ * 2. DTCG design 文件生成(scripts/export-design-tokens.ts,$value 全部结构化引用);
11
+ * 3. live CSS 生成(derive/live-css.ts,relative color / calc 表达式);
12
+ * 4. Token Studio 的派生公式展示(formatDerivation)。
13
+ *
14
+ * `seedRefs` 由 AST 自动推导(seedRefsOf),不再手写;可追溯性校验
15
+ * (derive/reference.test.ts)遍历 recipes 断言 seedRefs 非空。
16
+ * 颜色层对齐 Figma `Color/qw` 变量集合:
17
+ * - T1 Seed 为 12 个单色种子;
18
+ * - T2 Reference 为每个 seed 的 A5-A100 Alpha 通道、50-900 OKLCH 设计校准实色色阶、base 引用。
19
+ */
20
+ export type ShadowLevel = "sm" | "md" | "lg";
21
+ export type Derivation =
22
+ /** 直通引用 Seed 字段(dimension/number/duration 字符串或数字)。 */
23
+ {
24
+ kind: "alias";
25
+ seedRef: string;
26
+ }
27
+ /** dimension 字符串 × factor;round:"int" 时四舍五入为整数(字号档位用)。 */
28
+ | {
29
+ kind: "scale";
30
+ seedRef: string;
31
+ factor: number;
32
+ round?: "int";
33
+ }
34
+ /** 无单位数字 × factor(zIndex 刻度)。 */
35
+ | {
36
+ kind: "scaleNumber";
37
+ seedRef: string;
38
+ factor: number;
39
+ }
40
+ /** 无单位数字 + delta(lineHeight tight/relaxed = base ∓ 0.25)。 */
41
+ | {
42
+ kind: "offsetNumber";
43
+ seedRef: string;
44
+ delta: number;
45
+ }
46
+ /** dimension + 另一 dimension × n(controlSize/iconSize sm/lg = base ∓ spacing.step × n)。 */
47
+ | {
48
+ kind: "offsetSteps";
49
+ seedRef: string;
50
+ stepRef: string;
51
+ n: number;
52
+ }
53
+ /** OKLCH 感知均匀色阶(L 曲线 + chroma 端点衰减,算法见 oklch.ts)。 */
54
+ | {
55
+ kind: "oklchRamp";
56
+ seedRef: string;
57
+ step: Step;
58
+ }
59
+ /** Figma 校准后的 OKLCH 实色色阶;血缘仍指向 T1 seed,但数值由设计稿拍板。 */
60
+ | {
61
+ kind: "figmaOklchScale";
62
+ seedRef: string;
63
+ step: T2OklchStep;
64
+ value: string;
65
+ }
66
+ /** T1 seed 颜色的固定 Alpha 通道。 */
67
+ | {
68
+ kind: "seedAlpha";
69
+ seedRef: string;
70
+ alpha: number;
71
+ }
72
+ /** 旧版纯黑/纯白透明度工具刻度。保留求值器兼容,不再由 T2 主链路生成。 */
73
+ | {
74
+ kind: "alphaScale";
75
+ channel: "black" | "white";
76
+ stepRef: string;
77
+ multiplier: number;
78
+ }
79
+ /** 字体栈(string[] → CSS font-family 列表)。 */
80
+ | {
81
+ kind: "fontStack";
82
+ seedRef: string;
83
+ }
84
+ /** cubic-bezier 四元组 → CSS 函数。 */
85
+ | {
86
+ kind: "cubicBezier";
87
+ seedRef: string;
88
+ }
89
+ /** 白名单字面量(色彩空间数学端点,非设计决策)。 */
90
+ | {
91
+ kind: "literal";
92
+ value: string;
93
+ }
94
+ /** 阴影档位:形状 = shadow.base × 档位比例,颜色 = alphaStep × 档位倍数。 */
95
+ | {
96
+ kind: "shadowLayer";
97
+ level: ShadowLevel;
98
+ };
99
+ export interface ReferenceRecipe {
100
+ path: string[];
101
+ cssVar: string;
102
+ /** 由 derivation 自动推导的 Seed 依赖(点分路径),供可追溯性校验与血缘展示。 */
103
+ seedRefs: string[];
104
+ derivation: Derivation;
105
+ }
106
+ /** 拍平后的 CSS 变量映射:cssVar → 字符串值(--qw-ref-* 全集)。 */
107
+ export type ReferenceTokens = Record<string, string>;
108
+ /** 阴影形状(不含颜色),供 Semantic 层复合 effect.shadow.* 时引用固定形状字段。 */
109
+ export interface ShadowShape {
110
+ offsetX: string;
111
+ offsetY: string;
112
+ blur: string;
113
+ spread: string;
114
+ }
115
+ export interface ReferenceBuild {
116
+ recipes: ReferenceRecipe[];
117
+ tokens: ReferenceTokens;
118
+ shapes: {
119
+ shadow: {
120
+ sm: ShadowShape;
121
+ md: ShadowShape;
122
+ lg: ShadowShape;
123
+ };
124
+ };
125
+ }
126
+ /** 按点分路径读 Seed 字段("size.spacing.step" → seed.size.spacing.step)。 */
127
+ export declare function seedValueAt(seed: Seed, dotted: string): unknown;
128
+ export declare function formatFontFamily(list: string[]): string;
129
+ /** 阴影档位系数:形状(offset/blur/spread 缩放)+ 颜色(alphaStep 倍数)。 */
130
+ export declare const SHADOW_LEVELS: Record<ShadowLevel, {
131
+ offset: number;
132
+ blur: number;
133
+ alphaMult: number;
134
+ }>;
135
+ /** 求值:一条 Derivation + Seed → 最终 CSS 值字符串。 */
136
+ export declare function evaluateDerivation(d: Derivation, seed: Seed): string;
137
+ /** Seed 依赖推导:AST 里出现的全部 Seed 点分路径。 */
138
+ export declare function seedRefsOf(d: Derivation): string[];
139
+ /** 人读派生公式(Token Studio 展示用)。 */
140
+ export declare function formatDerivation(d: Derivation): string;
141
+ export declare const RAMP_COLORS: readonly ["brand", "black", "white", "gray", "red", "orange", "yellow", "green", "cyan", "blue", "purple", "brown"];
142
+ /** 1. 12 个 Seed ×(A5-A100 Alpha 通道 + 50-900 Figma OKLCH 校准色阶 + base)。 */
143
+ export declare function buildColorRampRecipes(): ReferenceRecipe[];
144
+ /** @deprecated Figma T2 已不再使用 neutral 0/1000 端点;保留给历史迁移脚本。 */
145
+ export declare function buildNeutralEndpointRecipes(): ReferenceRecipe[];
146
+ export declare const BLACK_ALPHA: ReadonlyArray<readonly [string, number]>;
147
+ export declare const WHITE_ALPHA: ReadonlyArray<readonly [string, number]>;
148
+ /** @deprecated Figma T2 已改为每个 Seed 自带 Alpha 通道;保留给历史迁移脚本。 */
149
+ export declare function buildAlphaScaleRecipes(): ReferenceRecipe[];
150
+ /** 4. 间距刻度 = spacing.step × N (N=1..8)。 */
151
+ export declare function buildSpacingRecipes(): ReferenceRecipe[];
152
+ /** 圆角档位系数(sm/lg 从 base 派生;默认 base=8px → 4/8/14)。 */
153
+ export declare const RADIUS_FACTORS: {
154
+ readonly sm: 0.5;
155
+ readonly md: 1;
156
+ readonly lg: 1.75;
157
+ };
158
+ /** 5. 圆角刻度:sm/md/lg 由 radius.base 按系数派生,full 直通独立裁切基准。 */
159
+ export declare function buildRadiusRecipes(): ReferenceRecipe[];
160
+ /** 6. 控件/图标尺寸:md = base 直通,sm/lg = base ∓ spacing.step × n(控件 ×2、图标 ×1)。 */
161
+ export declare function buildControlIconSizeRecipes(): ReferenceRecipe[];
162
+ /** 7. 描边宽度 —— 直通引用。 */
163
+ export declare function buildBorderWidthRecipes(): ReferenceRecipe[];
164
+ /** 8. 行高(typography 类目):normal 直通 Seed,tight/relaxed = base ∓ 0.25。 */
165
+ export declare function buildLineHeightRecipes(): ReferenceRecipe[];
166
+ /** 9. 禁用态不透明度 —— 直通引用。 */
167
+ export declare function buildOpacityRecipes(): ReferenceRecipe[];
168
+ /** 10. 层级刻度 = zIndex.step × N (N=1..4);角色分配交给 Semantic 层。 */
169
+ export declare function buildZIndexRecipes(): ReferenceRecipe[];
170
+ export declare const FONT_FAMILY_KEYS: readonly ["text", "number", "code", "textMacLatin", "textMacZh", "textMacJa", "textWindowsLatin", "textWindowsZh", "textWindowsJa"];
171
+ /** 字号档位倍数(沿用既定视觉:14px 基准 → 12/16/20/24)。 */
172
+ export declare const FONT_SIZE_FACTORS: Record<string, number>;
173
+ /** 11. 排版原子:字体族(三族 + 平台/语言变体)/字重直通,字号按既定倍数派生。 */
174
+ export declare function buildTypographyRecipes(): ReferenceRecipe[];
175
+ /** 动效时长档位倍数。 */
176
+ export declare const DURATION_FACTORS: {
177
+ readonly fast: 0.5;
178
+ readonly slow: 1.6;
179
+ };
180
+ /** 12. 动效:duration 按倍数派生,easing 直通。 */
181
+ export declare function buildMotionRecipes(): ReferenceRecipe[];
182
+ /**
183
+ * 13. 阴影:形状由 effect.shadow.base 按各档位比例缩放,颜色沿用
184
+ * alphaStep 结构锚点。它不是 Figma Color 变量体系里的 T2 颜色 token。
185
+ */
186
+ export declare function buildShadowRecipes(): ReferenceRecipe[];
187
+ export declare function allReferenceRecipes(): ReferenceRecipe[];
188
+ /** T2 顶层入口:喂一个 Seed,产出全量 Reference recipes + 拍平后的 CSS 变量映射 + 阴影形状(供 Semantic 层消费)。 */
189
+ export declare function buildReference(seed: Seed): ReferenceBuild;
@@ -0,0 +1,75 @@
1
+ import type { ReferenceBuild, ShadowLevel } from "./reference.js";
2
+ /**
3
+ * T3 Semantic 派生 —— RFC 0001 §2.1,v3 修订。
4
+ *
5
+ * R7 类型隔离(强制 FR-010):本模块**不 import `Seed`/`schema.ts`** 任何符号,
6
+ * 只接受 `buildReference()` 的输出(`ReferenceBuild`)。Semantic 角色永远经由
7
+ * Reference 层中转到 Seed,不允许绕过 Reference 直接引用 Seed 字段。
8
+ *
9
+ * v3 变化:全部角色表从模块私有改为导出的结构化元数据(SEMANTIC_ROLES),
10
+ * 供 design 文件生成器(scripts/export-design-tokens.ts)、live CSS 生成器
11
+ * (derive/live-css.ts)与 Token Studio 的血缘展示共用同一份事实。
12
+ */
13
+ export type SemanticMode = "light" | "dark";
14
+ export declare const RADIUS_ROLES: Record<string, string>;
15
+ export declare const CONTROL_HEIGHT_ROLES: Record<string, string>;
16
+ export declare const ICON_SIZE_ROLES: Record<string, string>;
17
+ export declare const INSET_STACK_ROLES: Record<string, string>;
18
+ export declare const Z_INDEX_ROLES: Record<string, string>;
19
+ export declare const MOTION_DURATION_ROLES: Record<string, string>;
20
+ /** 字体族角色:text(正文缺省)/ number(数字数据)/ code(等宽)。 */
21
+ export declare const FONT_FAMILY_ROLES: Record<string, string>;
22
+ export interface TypographyRole {
23
+ fontFamilyRef: string;
24
+ fontSizeRef: string;
25
+ fontWeightRef: string;
26
+ lineHeightRef: string;
27
+ letterSpacingRef: string;
28
+ }
29
+ /** typography.* 复合角色:每个字段各自引用 Reference(无任何裸字面量)。 */
30
+ export declare const TYPOGRAPHY_ROLES: Record<string, TypographyRole>;
31
+ export declare const TYPOGRAPHY_FIELDS: readonly ["fontFamily", "fontSize", "fontWeight", "lineHeight", "letterSpacing"];
32
+ export interface ColorRoleRefs {
33
+ light: string;
34
+ dark: string;
35
+ }
36
+ export declare const COLOR_ROLES: Record<string, ColorRoleRefs>;
37
+ /** 复合阴影角色:形状取 Reference effect.shadow.<level>,颜色取 color.shadow。 */
38
+ export declare const SHADOW_COMPOSITE_ROLES: Record<string, ShadowLevel>;
39
+ export type SemanticRoleEntry = {
40
+ kind: "structural";
41
+ /** Semantic 路径(点分,如 "size.radius.control")。 */
42
+ path: string;
43
+ cssVar: string;
44
+ /** 引用的 Reference 路径(点分)。 */
45
+ refPath: string;
46
+ } | {
47
+ kind: "color";
48
+ path: string;
49
+ cssVar: string;
50
+ refPath: {
51
+ light: string;
52
+ dark: string;
53
+ };
54
+ } | {
55
+ kind: "shadowComposite";
56
+ path: string;
57
+ cssVar: string;
58
+ /** 形状来源(reference.effect.shadow.<level>)+ 颜色来源。 */
59
+ shapeRef: string;
60
+ colorRole: string;
61
+ };
62
+ /**
63
+ * 全量 Semantic 角色的结构化血缘表——"角色 → 引用的 Reference 路径(含 light/dark 分支)"。
64
+ * 与 buildSemanticStructural/buildSemanticColor 的产出一一对应(顺序一致)。
65
+ */
66
+ export declare function semanticRoleEntries(): SemanticRoleEntry[];
67
+ /**
68
+ * 结构类(mode 无关):尺寸角色 + 字体族角色 + 排版复合角色 + 动效时长/缓动。
69
+ * `effect.shadow.*` 的颜色字段随 mode 变化,归入 `buildSemanticColor`。
70
+ */
71
+ export declare function buildSemanticStructural(reference: ReferenceBuild): Record<string, string>;
72
+ /**
73
+ * 颜色类(light/dark 分别求值):color.* 全部角色。
74
+ */
75
+ export declare function buildSemanticColor(reference: ReferenceBuild, mode: SemanticMode): Record<string, string>;