@tide-design/foundation 0.0.0-stage → 0.11.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/LICENSE +21 -0
- package/dist/cli.js +970 -0
- package/dist/color.d.ts +121 -0
- package/dist/color.js +122 -0
- package/dist/colorCss.d.ts +49 -0
- package/dist/colorCss.js +122 -0
- package/dist/colorFamily.d.ts +57 -0
- package/dist/colorFamily.js +125 -0
- package/dist/colorName.d.ts +40 -0
- package/dist/colorName.js +68 -0
- package/dist/colorSlot.d.ts +153 -0
- package/dist/colorSlot.js +172 -0
- package/dist/contrast.d.ts +73 -0
- package/dist/contrast.js +193 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/internal.d.ts +15 -0
- package/dist/internal.js +10 -0
- package/dist/motion.d.ts +20 -0
- package/dist/motion.js +17 -0
- package/dist/semantic.d.ts +265 -0
- package/dist/semantic.js +225 -0
- package/dist/shape.d.ts +89 -0
- package/dist/shape.js +93 -0
- package/dist/stacking.d.ts +17 -0
- package/dist/stacking.js +18 -0
- package/dist/tailwind-merge.d.ts +5 -0
- package/dist/tailwind-merge.js +528 -0
- package/dist/tailwind.css +290 -0
- package/dist/tokens.css +767 -0
- package/dist/typography.d.ts +132 -0
- package/dist/typography.js +145 -0
- package/package.json +60 -3
- package/README.md +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { color } from "./color.js";
|
|
2
|
+
import { colorSlots, familySlotSteps } from "./colorSlot.js";
|
|
3
|
+
import { colorValueHex, roleFamily, roleSharedSlots, semanticEntries, slotColorValue } from "./semantic.js";
|
|
4
|
+
|
|
5
|
+
// src/colorName.ts
|
|
6
|
+
/**
|
|
7
|
+
* Role 이름 목록(neutral, primary, success, warning, danger, info 순서).
|
|
8
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
9
|
+
*/
|
|
10
|
+
const roleNames = Object.keys(roleFamily);
|
|
11
|
+
/**
|
|
12
|
+
* Tide 색 계열 목록(`color`의 11단계 계열 순서).
|
|
13
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
14
|
+
*/
|
|
15
|
+
const colorFamilyNames = Object.keys(color).filter((name) => typeof color[name] !== "string");
|
|
16
|
+
/**
|
|
17
|
+
* Tide 색 이름 목록. Role 다음에 색 계열이 온다.
|
|
18
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
19
|
+
*/
|
|
20
|
+
const tideColorNames = [...roleNames, ...colorFamilyNames];
|
|
21
|
+
/**
|
|
22
|
+
* Tide Role인지 확인한다. 앱 Role은 Role Token이 없어서 false다.
|
|
23
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
24
|
+
*/
|
|
25
|
+
function isRole(name) {
|
|
26
|
+
return Object.hasOwn(roleFamily, name);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Role 슬롯이 가리키는 Semantic Token. 예: (`primary`, `solid`) → `bg-primary-solid`, (`neutral`, `text`) → `text-default`
|
|
30
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
31
|
+
*/
|
|
32
|
+
function roleSlotToken(role, slot) {
|
|
33
|
+
if (slot === "on-solid") return "text-on-solid";
|
|
34
|
+
const shared = roleSharedSlots[role]?.[slot];
|
|
35
|
+
if (shared) return shared;
|
|
36
|
+
switch (slot) {
|
|
37
|
+
case "text":
|
|
38
|
+
case "border": return `${slot}-${role}`;
|
|
39
|
+
case "on-subtle": return `text-${role}-on-subtle`;
|
|
40
|
+
case "subtle-border": return `border-${role}-subtle`;
|
|
41
|
+
default: return `bg-${role}-${slot}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Tide 색 이름 하나의 슬롯별 값(Theme별 Primitive).
|
|
46
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
47
|
+
*/
|
|
48
|
+
function colorSlotValues(name) {
|
|
49
|
+
if (isRole(name)) {
|
|
50
|
+
const entries = new Map(semanticEntries().map((entry) => [entry.className, entry.value]));
|
|
51
|
+
return Object.fromEntries(colorSlots.map((slot) => [slot, entries.get(roleSlotToken(name, slot))]));
|
|
52
|
+
}
|
|
53
|
+
const steps = familySlotSteps(name);
|
|
54
|
+
return Object.fromEntries(colorSlots.map((slot) => [slot, {
|
|
55
|
+
light: slotColorValue(name, steps[slot].light),
|
|
56
|
+
dark: slotColorValue(name, steps[slot].dark)
|
|
57
|
+
}]));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Tide 색 이름 하나의 슬롯별 hex(Theme 하나).
|
|
61
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
62
|
+
*/
|
|
63
|
+
function colorSlotHex(name, theme) {
|
|
64
|
+
const values = colorSlotValues(name);
|
|
65
|
+
return Object.fromEntries(colorSlots.map((slot) => [slot, colorValueHex(values[slot][theme])]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { colorFamilyNames, colorSlotHex, colorSlotValues, isRole, roleNames, roleSlotToken, tideColorNames };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { ColorFamily, ColorStep, PrimitiveColorName } from "./color.js";
|
|
2
|
+
/**
|
|
3
|
+
* 색 계열 변수 묶음의 슬롯. CSS에서는 `--tide-<색 이름>-<슬롯>`과 `--tide-accent-<슬롯>`으로 나간다.
|
|
4
|
+
*/
|
|
5
|
+
export declare const colorSlots: readonly ["solid", "solid-hover", "solid-active", "subtle", "subtle-hover", "subtle-active", "faint", "text", "border", "subtle-border", "on-solid", "on-subtle"];
|
|
6
|
+
/** 색 계열 변수 묶음의 슬롯 이름. 예: `solid`, `subtle-hover`, `on-subtle` */
|
|
7
|
+
export type ColorSlot = (typeof colorSlots)[number];
|
|
8
|
+
/** 배경 슬롯(solid 3단계, subtle 3단계, faint) */
|
|
9
|
+
export type BackgroundSlot = Exclude<ColorSlot, "text" | "border" | "subtle-border" | "on-solid" | "on-subtle">;
|
|
10
|
+
/** 슬롯이 가리키는 단계: 그 계열 스케일의 단계, 또는 `white`·`black` */
|
|
11
|
+
export type SlotStep = ColorStep | "white" | "black";
|
|
12
|
+
/** 덮기·섞기가 참조하는 색: 숫자는 그 계열의 단계, 문자열은 Tide Primitive 이름(예: `gray-950`, `white`) */
|
|
13
|
+
export type SlotColorRef = ColorStep | PrimitiveColorName;
|
|
14
|
+
/** 덮기: 계열 단계 위에 색을 `amount`만큼 덮은 값. 예: 100 + gray-950 4% → `{ step: 100, overlay: "gray-950", amount: 0.04 }` */
|
|
15
|
+
export interface SlotOverlay {
|
|
16
|
+
readonly step: ColorStep;
|
|
17
|
+
readonly overlay: PrimitiveColorName;
|
|
18
|
+
/** 덮는 비율. 0보다 크고 1보다 작다. */
|
|
19
|
+
readonly amount: number;
|
|
20
|
+
}
|
|
21
|
+
/** 섞기: 두 색을 반씩 섞은 값. 예: gray-950과 950 → `{ mix: ["gray-950", 950] }` */
|
|
22
|
+
export interface SlotMix {
|
|
23
|
+
readonly mix: readonly [SlotColorRef, SlotColorRef];
|
|
24
|
+
}
|
|
25
|
+
/** 슬롯 값: 단계 하나, 덮기, 섞기 */
|
|
26
|
+
export type SlotValue = SlotStep | SlotOverlay | SlotMix;
|
|
27
|
+
/** Theme별 슬롯 값 */
|
|
28
|
+
export interface SlotRule {
|
|
29
|
+
readonly light: SlotValue;
|
|
30
|
+
readonly dark: SlotValue;
|
|
31
|
+
}
|
|
32
|
+
/** 계열마다 덮어쓸 슬롯 값. Theme 하나만 덮어써도 된다. */
|
|
33
|
+
export type SlotOverrides = { readonly [Slot in ColorSlot]?: Partial<SlotRule>; };
|
|
34
|
+
/**
|
|
35
|
+
* 슬롯 매핑 규칙.
|
|
36
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
37
|
+
*/
|
|
38
|
+
export declare const slotRule: {
|
|
39
|
+
readonly solid: {
|
|
40
|
+
readonly light: 600;
|
|
41
|
+
readonly dark: 600;
|
|
42
|
+
};
|
|
43
|
+
readonly "solid-hover": {
|
|
44
|
+
readonly light: {
|
|
45
|
+
readonly step: 600;
|
|
46
|
+
readonly overlay: "black";
|
|
47
|
+
readonly amount: 0.14;
|
|
48
|
+
};
|
|
49
|
+
readonly dark: {
|
|
50
|
+
readonly step: 600;
|
|
51
|
+
readonly overlay: "black";
|
|
52
|
+
readonly amount: 0.14;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
readonly "solid-active": {
|
|
56
|
+
readonly light: {
|
|
57
|
+
readonly step: 600;
|
|
58
|
+
readonly overlay: "black";
|
|
59
|
+
readonly amount: 0.2;
|
|
60
|
+
};
|
|
61
|
+
readonly dark: {
|
|
62
|
+
readonly step: 600;
|
|
63
|
+
readonly overlay: "black";
|
|
64
|
+
readonly amount: 0.2;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly subtle: {
|
|
68
|
+
readonly light: 100;
|
|
69
|
+
readonly dark: 950;
|
|
70
|
+
};
|
|
71
|
+
readonly "subtle-hover": {
|
|
72
|
+
readonly light: {
|
|
73
|
+
readonly step: 100;
|
|
74
|
+
readonly overlay: "gray-950";
|
|
75
|
+
readonly amount: 0.04;
|
|
76
|
+
};
|
|
77
|
+
readonly dark: {
|
|
78
|
+
readonly step: 950;
|
|
79
|
+
readonly overlay: "white";
|
|
80
|
+
readonly amount: 0.06;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
readonly "subtle-active": {
|
|
84
|
+
readonly light: {
|
|
85
|
+
readonly step: 100;
|
|
86
|
+
readonly overlay: "gray-950";
|
|
87
|
+
readonly amount: 0.08;
|
|
88
|
+
};
|
|
89
|
+
readonly dark: {
|
|
90
|
+
readonly step: 950;
|
|
91
|
+
readonly overlay: "white";
|
|
92
|
+
readonly amount: 0.1;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
readonly faint: {
|
|
96
|
+
readonly light: 50;
|
|
97
|
+
readonly dark: {
|
|
98
|
+
readonly mix: readonly ["gray-950", 950];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
readonly text: {
|
|
102
|
+
readonly light: 700;
|
|
103
|
+
readonly dark: 300;
|
|
104
|
+
};
|
|
105
|
+
readonly border: {
|
|
106
|
+
readonly light: 600;
|
|
107
|
+
readonly dark: 400;
|
|
108
|
+
};
|
|
109
|
+
readonly "subtle-border": {
|
|
110
|
+
readonly light: 200;
|
|
111
|
+
readonly dark: 800;
|
|
112
|
+
};
|
|
113
|
+
readonly "on-solid": {
|
|
114
|
+
readonly light: "white";
|
|
115
|
+
readonly dark: "white";
|
|
116
|
+
};
|
|
117
|
+
readonly "on-subtle": {
|
|
118
|
+
readonly light: 950;
|
|
119
|
+
readonly dark: 100;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Tide 계열별 덮어쓸 값.
|
|
124
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
125
|
+
*/
|
|
126
|
+
export declare const familyOverrides: {};
|
|
127
|
+
/**
|
|
128
|
+
* 규칙에 덮어쓸 값을 얹은 슬롯별 값.
|
|
129
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveSlotSteps(...overrides: (SlotOverrides | undefined)[]): Record<ColorSlot, SlotRule>;
|
|
132
|
+
/**
|
|
133
|
+
* 슬롯 단계를 Primitive 이름으로 바꾼다. 예: (`blue`, 600) → `blue-600`, (`blue`, `white`) → `white`
|
|
134
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
135
|
+
*/
|
|
136
|
+
export declare function slotPrimitive(family: string, step: SlotColorRef): string;
|
|
137
|
+
/**
|
|
138
|
+
* 두 색을 섞은 값(`#rrggbb`). sRGB 채널마다 `a × (1 − amount) + b × amount`를 반올림한다.
|
|
139
|
+
* 불투명한 색을 그 위에 `amount`만큼 덮은 값(브라우저의 알파 합성)과 같다.
|
|
140
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
141
|
+
*/
|
|
142
|
+
export declare function mixHex(a: string, b: string, amount: number): string;
|
|
143
|
+
/**
|
|
144
|
+
* 슬롯 값의 hex. 덮기·섞기는 여기서 계산한다(빌드 시 hex로 넣는다. 런타임 `color-mix()`를 쓰지 않는다).
|
|
145
|
+
* @param stepHex 계열 단계의 hex. Tide 계열은 `color`, 앱 계열은 그 스케일이다.
|
|
146
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
147
|
+
*/
|
|
148
|
+
export declare function slotValueHex(value: SlotValue, stepHex: (step: ColorStep) => string): string;
|
|
149
|
+
/**
|
|
150
|
+
* Tide 계열 하나의 슬롯별 값(규칙 + 그 계열의 덮어쓸 값).
|
|
151
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
152
|
+
*/
|
|
153
|
+
export declare function familySlotSteps(family: ColorFamily): Record<ColorSlot, SlotRule>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { primitiveHex } from "./color.js";
|
|
2
|
+
|
|
3
|
+
// src/colorSlot.ts
|
|
4
|
+
/**
|
|
5
|
+
* 색 계열 변수 묶음의 슬롯. CSS에서는 `--tide-<색 이름>-<슬롯>`과 `--tide-accent-<슬롯>`으로 나간다.
|
|
6
|
+
*/
|
|
7
|
+
const colorSlots = [
|
|
8
|
+
"solid",
|
|
9
|
+
"solid-hover",
|
|
10
|
+
"solid-active",
|
|
11
|
+
"subtle",
|
|
12
|
+
"subtle-hover",
|
|
13
|
+
"subtle-active",
|
|
14
|
+
"faint",
|
|
15
|
+
"text",
|
|
16
|
+
"border",
|
|
17
|
+
"subtle-border",
|
|
18
|
+
"on-solid",
|
|
19
|
+
"on-subtle"
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* 슬롯 매핑 규칙.
|
|
23
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
24
|
+
*/
|
|
25
|
+
const slotRule = {
|
|
26
|
+
solid: {
|
|
27
|
+
light: 600,
|
|
28
|
+
dark: 600
|
|
29
|
+
},
|
|
30
|
+
"solid-hover": {
|
|
31
|
+
light: {
|
|
32
|
+
step: 600,
|
|
33
|
+
overlay: "black",
|
|
34
|
+
amount: .14
|
|
35
|
+
},
|
|
36
|
+
dark: {
|
|
37
|
+
step: 600,
|
|
38
|
+
overlay: "black",
|
|
39
|
+
amount: .14
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"solid-active": {
|
|
43
|
+
light: {
|
|
44
|
+
step: 600,
|
|
45
|
+
overlay: "black",
|
|
46
|
+
amount: .2
|
|
47
|
+
},
|
|
48
|
+
dark: {
|
|
49
|
+
step: 600,
|
|
50
|
+
overlay: "black",
|
|
51
|
+
amount: .2
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
subtle: {
|
|
55
|
+
light: 100,
|
|
56
|
+
dark: 950
|
|
57
|
+
},
|
|
58
|
+
"subtle-hover": {
|
|
59
|
+
light: {
|
|
60
|
+
step: 100,
|
|
61
|
+
overlay: "gray-950",
|
|
62
|
+
amount: .04
|
|
63
|
+
},
|
|
64
|
+
dark: {
|
|
65
|
+
step: 950,
|
|
66
|
+
overlay: "white",
|
|
67
|
+
amount: .06
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"subtle-active": {
|
|
71
|
+
light: {
|
|
72
|
+
step: 100,
|
|
73
|
+
overlay: "gray-950",
|
|
74
|
+
amount: .08
|
|
75
|
+
},
|
|
76
|
+
dark: {
|
|
77
|
+
step: 950,
|
|
78
|
+
overlay: "white",
|
|
79
|
+
amount: .1
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
faint: {
|
|
83
|
+
light: 50,
|
|
84
|
+
dark: { mix: ["gray-950", 950] }
|
|
85
|
+
},
|
|
86
|
+
text: {
|
|
87
|
+
light: 700,
|
|
88
|
+
dark: 300
|
|
89
|
+
},
|
|
90
|
+
border: {
|
|
91
|
+
light: 600,
|
|
92
|
+
dark: 400
|
|
93
|
+
},
|
|
94
|
+
"subtle-border": {
|
|
95
|
+
light: 200,
|
|
96
|
+
dark: 800
|
|
97
|
+
},
|
|
98
|
+
"on-solid": {
|
|
99
|
+
light: "white",
|
|
100
|
+
dark: "white"
|
|
101
|
+
},
|
|
102
|
+
"on-subtle": {
|
|
103
|
+
light: 950,
|
|
104
|
+
dark: 100
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Tide 계열별 덮어쓸 값.
|
|
109
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
110
|
+
*/
|
|
111
|
+
const familyOverrides = {};
|
|
112
|
+
/**
|
|
113
|
+
* 규칙에 덮어쓸 값을 얹은 슬롯별 값.
|
|
114
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
115
|
+
*/
|
|
116
|
+
function resolveSlotSteps(...overrides) {
|
|
117
|
+
return Object.fromEntries(colorSlots.map((slot) => {
|
|
118
|
+
return [slot, overrides.reduce((current, override) => ({
|
|
119
|
+
...current,
|
|
120
|
+
...override?.[slot]
|
|
121
|
+
}), slotRule[slot])];
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 슬롯 단계를 Primitive 이름으로 바꾼다. 예: (`blue`, 600) → `blue-600`, (`blue`, `white`) → `white`
|
|
126
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
127
|
+
*/
|
|
128
|
+
function slotPrimitive(family, step) {
|
|
129
|
+
return typeof step === "number" ? `${family}-${step}` : step;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 슬롯 값이 단계 하나인지(덮기·섞기가 아닌지) 확인한다.
|
|
133
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
134
|
+
*/
|
|
135
|
+
function isSlotStep(value) {
|
|
136
|
+
return typeof value !== "object";
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 두 색을 섞은 값(`#rrggbb`). sRGB 채널마다 `a × (1 − amount) + b × amount`를 반올림한다.
|
|
140
|
+
* 불투명한 색을 그 위에 `amount`만큼 덮은 값(브라우저의 알파 합성)과 같다.
|
|
141
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
142
|
+
*/
|
|
143
|
+
function mixHex(a, b, amount) {
|
|
144
|
+
const channels = (hex) => {
|
|
145
|
+
const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);
|
|
146
|
+
if (!match) throw new Error(`불투명한 6자리 hex가 아니다: ${hex}`);
|
|
147
|
+
return match.slice(1).map((channel) => Number.parseInt(channel, 16));
|
|
148
|
+
};
|
|
149
|
+
const from = channels(a);
|
|
150
|
+
const to = channels(b);
|
|
151
|
+
return `#${from.map((value, index) => Math.round(value * (1 - amount) + to[index] * amount).toString(16).padStart(2, "0")).join("")}`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* 슬롯 값의 hex. 덮기·섞기는 여기서 계산한다(빌드 시 hex로 넣는다. 런타임 `color-mix()`를 쓰지 않는다).
|
|
155
|
+
* @param stepHex 계열 단계의 hex. Tide 계열은 `color`, 앱 계열은 그 스케일이다.
|
|
156
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
157
|
+
*/
|
|
158
|
+
function slotValueHex(value, stepHex) {
|
|
159
|
+
const ref = (color) => typeof color === "number" ? stepHex(color) : primitiveHex(color);
|
|
160
|
+
if (typeof value !== "object") return ref(value);
|
|
161
|
+
if ("mix" in value) return mixHex(ref(value.mix[0]), ref(value.mix[1]), .5);
|
|
162
|
+
return mixHex(stepHex(value.step), primitiveHex(value.overlay), value.amount);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Tide 계열 하나의 슬롯별 값(규칙 + 그 계열의 덮어쓸 값).
|
|
166
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
167
|
+
*/
|
|
168
|
+
function familySlotSteps(family) {
|
|
169
|
+
return resolveSlotSteps(familyOverrides[family]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { colorSlots, familyOverrides, familySlotSteps, isSlotStep, mixHex, resolveSlotSteps, slotPrimitive, slotRule, slotValueHex };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ColorSlot } from "./colorSlot.js";
|
|
2
|
+
import { SemanticColorName, ThemeName } from "./semantic.js";
|
|
3
|
+
/**
|
|
4
|
+
* 대비 하한 세 등급(ADR 0023).
|
|
5
|
+
* - `4.5`: 정지 상태의 글자(표면 층·subtle·faint 위 글자, 선택 유지 바탕 위 글자)
|
|
6
|
+
* - `4`: hover·누름 같은 일시 상태의 글자, solid 위 글자(on-solid)
|
|
7
|
+
* - `3`: 글자가 아닌 UI 요소(경계, 포커스 표시, Switch thumb)
|
|
8
|
+
*/
|
|
9
|
+
export type ContrastMinRatio = 4.5 | 4 | 3;
|
|
10
|
+
/** 함께 쓰이는 글자(또는 경계)와 배경의 짝. Utility class 이름으로 적는다. */
|
|
11
|
+
export interface ContrastPair {
|
|
12
|
+
readonly foreground: SemanticColorName;
|
|
13
|
+
readonly background: SemanticColorName;
|
|
14
|
+
/** 정지 상태 글자는 4.5, 일시 상태 글자와 solid 위 글자는 4, UI 경계·포커스·thumb은 3(ADR 0023) */
|
|
15
|
+
readonly minRatio: ContrastMinRatio;
|
|
16
|
+
/** 배경이 반투명(`bg-hover`·`bg-active`)이면 그 아래 표면. 배경을 이 표면 위에 합성한 값으로 검사한다. */
|
|
17
|
+
readonly surface?: SemanticColorName;
|
|
18
|
+
}
|
|
19
|
+
/** 대비 검사에서 빼는 Semantic Token과 그 이유 */
|
|
20
|
+
export interface ContrastExclusion {
|
|
21
|
+
readonly token: SemanticColorName;
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
}
|
|
24
|
+
declare const surfaces: readonly ["bg-canvas", "bg-surface", "bg-raised"];
|
|
25
|
+
declare const neutralStates: readonly ["bg-hover", "bg-active"];
|
|
26
|
+
export declare const contrastPairs: readonly ContrastPair[];
|
|
27
|
+
/**
|
|
28
|
+
* 대비 검사에서 뺀 Semantic Token과 이유.
|
|
29
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
30
|
+
*/
|
|
31
|
+
export declare const contrastExclusions: readonly ContrastExclusion[];
|
|
32
|
+
/** 색 이름 하나에서 함께 쓰는 슬롯 짝. 배경은 같은 색의 슬롯이거나 표면 층·무채색 호버 Token이다. */
|
|
33
|
+
export interface ColorContrastRule {
|
|
34
|
+
readonly foreground: ColorSlot;
|
|
35
|
+
readonly background: ColorSlot | (typeof surfaces)[number] | (typeof neutralStates)[number];
|
|
36
|
+
/** 정지 상태 글자는 4.5, 일시 상태 글자와 solid 위 글자는 4, UI 요소는 3(ADR 0023) */
|
|
37
|
+
readonly minRatio: ContrastMinRatio;
|
|
38
|
+
/** 배경이 반투명이면 그 아래 표면. 배경을 이 표면 위에 합성한 값으로 검사한다. */
|
|
39
|
+
readonly surface?: (typeof surfaces)[number];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 색 이름 하나의 대비 쌍 규칙.
|
|
43
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
44
|
+
*/
|
|
45
|
+
export declare const colorContrastRules: readonly ColorContrastRule[];
|
|
46
|
+
/** 대비 쌍 규칙 하나를 Theme 하나에서 검사한 결과 */
|
|
47
|
+
export interface ColorContrastResult extends ColorContrastRule {
|
|
48
|
+
readonly theme: ThemeName;
|
|
49
|
+
readonly ratio: number;
|
|
50
|
+
readonly pass: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 색 이름 하나의 슬롯 hex로 대비 쌍 규칙을 light·dark에서 검사한다. 표면 층은 Tide Token 값을 쓴다.
|
|
54
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
55
|
+
*/
|
|
56
|
+
export declare function checkColorContrast(slotHex: Readonly<Record<ThemeName, Readonly<Record<ColorSlot, string>>>>): ColorContrastResult[];
|
|
57
|
+
/**
|
|
58
|
+
* Semantic Token의 불투명한 hex. 반투명 Token(8자리 hex)은 `surface` 위에 합성한다(브라우저가 그리는 값과 같다).
|
|
59
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
60
|
+
*/
|
|
61
|
+
export declare function opaqueSemanticHex(name: SemanticColorName, theme: ThemeName, surface?: SemanticColorName): string;
|
|
62
|
+
/**
|
|
63
|
+
* 대비 쌍 하나의 Theme별 대비비. 반투명 배경은 쌍의 표면(`surface`) 위에 합성한 값으로 계산한다.
|
|
64
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
65
|
+
*/
|
|
66
|
+
export declare function contrastPairRatio(pair: ContrastPair, theme: ThemeName): number;
|
|
67
|
+
/**
|
|
68
|
+
* 두 색의 WCAG 2.x 대비비(1~21). 순서는 상관없다.
|
|
69
|
+
* 반투명 색(8자리 hex)은 받지 않는다. 대비 검사에서 overlay와 shadow는 제외한다.
|
|
70
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
71
|
+
*/
|
|
72
|
+
export declare function contrastRatio(foreground: string, background: string): number;
|
|
73
|
+
export {};
|
package/dist/contrast.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { mixHex } from "./colorSlot.js";
|
|
2
|
+
import { semanticHex } from "./semantic.js";
|
|
3
|
+
|
|
4
|
+
// src/contrast.ts
|
|
5
|
+
const surfaces = [
|
|
6
|
+
"bg-canvas",
|
|
7
|
+
"bg-surface",
|
|
8
|
+
"bg-raised"
|
|
9
|
+
];
|
|
10
|
+
const roles = [
|
|
11
|
+
"primary",
|
|
12
|
+
"success",
|
|
13
|
+
"warning",
|
|
14
|
+
"danger",
|
|
15
|
+
"info"
|
|
16
|
+
];
|
|
17
|
+
const allRoles = ["neutral", ...roles];
|
|
18
|
+
const solidStates = [
|
|
19
|
+
"solid",
|
|
20
|
+
"solid-hover",
|
|
21
|
+
"solid-active"
|
|
22
|
+
];
|
|
23
|
+
const onSubtleRest = ["faint", "subtle"];
|
|
24
|
+
const subtleTransient = ["subtle-hover", "subtle-active"];
|
|
25
|
+
const neutralStates = ["bg-hover", "bg-active"];
|
|
26
|
+
const neutralStateSurface = "bg-canvas";
|
|
27
|
+
function pairs(foregrounds, backgrounds, minRatio) {
|
|
28
|
+
return foregrounds.flatMap((foreground) => backgrounds.map((background) => ({
|
|
29
|
+
foreground,
|
|
30
|
+
background,
|
|
31
|
+
minRatio
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
const contrastPairs = [
|
|
35
|
+
...pairs(["text-default", "text-muted"], surfaces, 4.5),
|
|
36
|
+
...pairs(["text-default"], [
|
|
37
|
+
"faint",
|
|
38
|
+
"subtle",
|
|
39
|
+
"subtle-active"
|
|
40
|
+
].map((state) => `bg-neutral-${state}`), 4.5),
|
|
41
|
+
...pairs(["text-default"], ["bg-neutral-subtle-hover"], 4),
|
|
42
|
+
...roles.flatMap((role) => pairs([`text-${role}`], [...surfaces, `bg-${role}-subtle`], 4.5)),
|
|
43
|
+
...roles.flatMap((role) => pairs([`text-${role}-on-subtle`], onSubtleRest.map((state) => `bg-${role}-${state}`), 4.5)),
|
|
44
|
+
...roles.flatMap((role) => pairs([`text-${role}-on-subtle`], subtleTransient.map((state) => `bg-${role}-${state}`), 4)),
|
|
45
|
+
...roles.flatMap((role) => pairs([`text-${role}`], [`bg-${role}-faint`], 4.5)),
|
|
46
|
+
...neutralStates.map((background) => ({
|
|
47
|
+
foreground: "text-default",
|
|
48
|
+
background,
|
|
49
|
+
minRatio: 4,
|
|
50
|
+
surface: neutralStateSurface
|
|
51
|
+
})),
|
|
52
|
+
...neutralStates.map((background) => ({
|
|
53
|
+
foreground: "text-default",
|
|
54
|
+
background,
|
|
55
|
+
minRatio: 4,
|
|
56
|
+
surface: "bg-raised"
|
|
57
|
+
})),
|
|
58
|
+
...pairs(["text-on-solid"], allRoles.flatMap((role) => solidStates.map((state) => `bg-${role}-${state}`)), 4),
|
|
59
|
+
...pairs([
|
|
60
|
+
"border-strong",
|
|
61
|
+
...roles.map((role) => `border-${role}`),
|
|
62
|
+
"outline-focus"
|
|
63
|
+
], surfaces, 3),
|
|
64
|
+
...pairs(["outline-focus"], allRoles.map((role) => `bg-${role}-subtle`), 3),
|
|
65
|
+
...roles.flatMap((role) => pairs([`text-${role}`], [`bg-${role}-subtle-active`], 3))
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* 대비 검사에서 뺀 Semantic Token과 이유.
|
|
69
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
70
|
+
*/
|
|
71
|
+
const contrastExclusions = [
|
|
72
|
+
{
|
|
73
|
+
token: "border-default",
|
|
74
|
+
reason: "장식용 구분선이다. 경계 식별에 쓰지 않는다."
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
token: "border-raised",
|
|
78
|
+
reason: "raised 표면의 장식용 경계다(light 투명, dark gray-800). 표면 구분은 그림자와 배경 밝기가 맡고, 대비 의무가 없다."
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
token: "bg-disabled",
|
|
82
|
+
reason: "비활성 상태는 WCAG 대비 요건 밖이다. Component가 속성과 cursor로도 표현한다."
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
token: "text-disabled",
|
|
86
|
+
reason: "비활성 상태는 WCAG 대비 요건 밖이다. Component가 속성과 cursor로도 표현한다."
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
token: "bg-overlay",
|
|
90
|
+
reason: "modal 뒤를 가리는 반투명 막이다. 위에 글자를 두지 않는다."
|
|
91
|
+
},
|
|
92
|
+
...allRoles.map((role) => ({
|
|
93
|
+
token: `border-${role}-subtle`,
|
|
94
|
+
reason: "파스텔 테두리(subtle-border)는 꾸밈이다. subtle 바탕과 on-subtle 글자만으로 알아볼 수 있어 경계 대비 의무가 없다."
|
|
95
|
+
}))
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* 색 이름 하나의 대비 쌍 규칙.
|
|
99
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
100
|
+
*/
|
|
101
|
+
const colorContrastRules = [
|
|
102
|
+
...[...surfaces, "subtle"].map((background) => ({
|
|
103
|
+
foreground: "text",
|
|
104
|
+
background,
|
|
105
|
+
minRatio: 4.5
|
|
106
|
+
})),
|
|
107
|
+
{
|
|
108
|
+
foreground: "text",
|
|
109
|
+
background: "faint",
|
|
110
|
+
minRatio: 4.5
|
|
111
|
+
},
|
|
112
|
+
...onSubtleRest.map((background) => ({
|
|
113
|
+
foreground: "on-subtle",
|
|
114
|
+
background,
|
|
115
|
+
minRatio: 4.5
|
|
116
|
+
})),
|
|
117
|
+
...subtleTransient.map((background) => ({
|
|
118
|
+
foreground: "on-subtle",
|
|
119
|
+
background,
|
|
120
|
+
minRatio: 4
|
|
121
|
+
})),
|
|
122
|
+
...solidStates.map((background) => ({
|
|
123
|
+
foreground: "on-solid",
|
|
124
|
+
background,
|
|
125
|
+
minRatio: 4
|
|
126
|
+
})),
|
|
127
|
+
...surfaces.map((background) => ({
|
|
128
|
+
foreground: "border",
|
|
129
|
+
background,
|
|
130
|
+
minRatio: 3
|
|
131
|
+
})),
|
|
132
|
+
{
|
|
133
|
+
foreground: "text",
|
|
134
|
+
background: "subtle-active",
|
|
135
|
+
minRatio: 3
|
|
136
|
+
}
|
|
137
|
+
];
|
|
138
|
+
/**
|
|
139
|
+
* 색 이름 하나의 슬롯 hex로 대비 쌍 규칙을 light·dark에서 검사한다. 표면 층은 Tide Token 값을 쓴다.
|
|
140
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
141
|
+
*/
|
|
142
|
+
function checkColorContrast(slotHex) {
|
|
143
|
+
return ["light", "dark"].flatMap((theme) => colorContrastRules.map((rule) => {
|
|
144
|
+
const background = rule.background.startsWith("bg-") ? opaqueSemanticHex(rule.background, theme, rule.surface) : slotHex[theme][rule.background];
|
|
145
|
+
const ratio = contrastRatio(slotHex[theme][rule.foreground], background);
|
|
146
|
+
return {
|
|
147
|
+
...rule,
|
|
148
|
+
theme,
|
|
149
|
+
ratio,
|
|
150
|
+
pass: ratio >= rule.minRatio
|
|
151
|
+
};
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Semantic Token의 불투명한 hex. 반투명 Token(8자리 hex)은 `surface` 위에 합성한다(브라우저가 그리는 값과 같다).
|
|
156
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
157
|
+
*/
|
|
158
|
+
function opaqueSemanticHex(name, theme, surface) {
|
|
159
|
+
const hex = semanticHex(name, theme);
|
|
160
|
+
if (hex.length === 7) return hex;
|
|
161
|
+
if (!surface) throw new Error(`반투명 Token은 아래 표면이 있어야 검사할 수 있다: ${name}`);
|
|
162
|
+
const alpha = Number.parseInt(hex.slice(7), 16) / 255;
|
|
163
|
+
return mixHex(opaqueSemanticHex(surface, theme), hex.slice(0, 7), alpha);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 대비 쌍 하나의 Theme별 대비비. 반투명 배경은 쌍의 표면(`surface`) 위에 합성한 값으로 계산한다.
|
|
167
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
168
|
+
*/
|
|
169
|
+
function contrastPairRatio(pair, theme) {
|
|
170
|
+
return contrastRatio(opaqueSemanticHex(pair.foreground, theme), opaqueSemanticHex(pair.background, theme, pair.surface));
|
|
171
|
+
}
|
|
172
|
+
/** WCAG 2.x 상대 휘도. `#rrggbb`만 받는다. */
|
|
173
|
+
function relativeLuminance(hex) {
|
|
174
|
+
const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);
|
|
175
|
+
if (!match) throw new Error(`불투명한 6자리 hex가 아니다: ${hex}`);
|
|
176
|
+
const [r, g, b] = match.slice(1).map((channel) => {
|
|
177
|
+
const value = Number.parseInt(channel, 16) / 255;
|
|
178
|
+
return value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
|
|
179
|
+
});
|
|
180
|
+
return .2126 * r + .7152 * g + .0722 * b;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* 두 색의 WCAG 2.x 대비비(1~21). 순서는 상관없다.
|
|
184
|
+
* 반투명 색(8자리 hex)은 받지 않는다. 대비 검사에서 overlay와 shadow는 제외한다.
|
|
185
|
+
* @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
|
|
186
|
+
*/
|
|
187
|
+
function contrastRatio(foreground, background) {
|
|
188
|
+
const a = relativeLuminance(foreground);
|
|
189
|
+
const b = relativeLuminance(background);
|
|
190
|
+
return (Math.max(a, b) + .05) / (Math.min(a, b) + .05);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { checkColorContrast, colorContrastRules, contrastExclusions, contrastPairRatio, contrastPairs, contrastRatio, opaqueSemanticHex };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ColorFamily, ColorStep, PrimitiveColorName, color } from "./color.js";
|
|
2
|
+
import { ColorSlot } from "./colorSlot.js";
|
|
3
|
+
import { AlphaColor, Color, ColorFamilyName, ColorFamilyRegistry, MixedColor, Role, RoleRegistry, SemanticColorName, SemanticColorValue, SemanticNamespace, ThemeName, ThemedColor, TideRole, semantic, semanticPrefix } from "./semantic.js";
|
|
4
|
+
import { ContrastExclusion, ContrastMinRatio, ContrastPair, contrastPairs } from "./contrast.js";
|
|
5
|
+
import { FontFamilyName, FontSizeStep, FontWeightName, TextStyleName, TextStyleValue, fontFamily, fontSize, fontWeight, textStyle } from "./typography.js";
|
|
6
|
+
import { RadiusName, ShadowLayer, ShadowName, focusRing, radius, shadow } from "./shape.js";
|
|
7
|
+
import { DurationName, EasingName, duration, easing } from "./motion.js";
|
|
8
|
+
import { ZIndexName, zIndex } from "./stacking.js";
|
|
9
|
+
export { type AlphaColor, type Color, type ColorFamily, type ColorFamilyName, type ColorFamilyRegistry, type ColorSlot, type ColorStep, type ContrastExclusion, type ContrastMinRatio, type ContrastPair, type DurationName, type EasingName, type FontFamilyName, type FontSizeStep, type FontWeightName, type MixedColor, type PrimitiveColorName, type RadiusName, type Role, type RoleRegistry, type SemanticColorName, type SemanticColorValue, type SemanticNamespace, type ShadowLayer, type ShadowName, type TextStyleName, type TextStyleValue, type ThemeName, type ThemedColor, type TideRole, type ZIndexName, color, contrastPairs, duration, easing, focusRing, fontFamily, fontSize, fontWeight, radius, semantic, semanticPrefix, shadow, textStyle, zIndex };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { color } from "./color.js";
|
|
2
|
+
import { semantic, semanticPrefix } from "./semantic.js";
|
|
3
|
+
import { contrastPairs } from "./contrast.js";
|
|
4
|
+
import { fontFamily, fontSize, fontWeight, textStyle } from "./typography.js";
|
|
5
|
+
import { focusRing, radius, shadow } from "./shape.js";
|
|
6
|
+
import { duration, easing } from "./motion.js";
|
|
7
|
+
import { zIndex } from "./stacking.js";
|
|
8
|
+
|
|
9
|
+
export { color, contrastPairs, duration, easing, focusRing, fontFamily, fontSize, fontWeight, radius, semantic, semanticPrefix, shadow, textStyle, zIndex };
|