@tide-design/foundation 0.0.0-stage → 0.11.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,172 @@
1
+ import { primitiveHex } from "./color.js";
2
+
3
+ // src/color-slot.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,121 @@
1
+ export declare const color: {
2
+ readonly white: "#ffffff";
3
+ readonly black: "#000000";
4
+ readonly blue: {
5
+ readonly 50: "#eff4fc";
6
+ readonly 100: "#e3eefd";
7
+ readonly 200: "#c9d7eb";
8
+ readonly 300: "#a7c0e3";
9
+ readonly 400: "#65a1f9";
10
+ readonly 500: "#3183f5";
11
+ readonly 600: "#4e7aba";
12
+ readonly 700: "#2b5fa8";
13
+ readonly 800: "#184c93";
14
+ readonly 900: "#114080";
15
+ readonly 950: "#113465";
16
+ };
17
+ readonly gray: {
18
+ readonly 50: "#f5f5f6";
19
+ readonly 100: "#e8e8ea";
20
+ readonly 200: "#d7d8da";
21
+ readonly 300: "#bec1c4";
22
+ readonly 400: "#9da1a6";
23
+ readonly 500: "#82878e";
24
+ readonly 600: "#747a81";
25
+ readonly 700: "#5b6068";
26
+ readonly 800: "#4a4e54";
27
+ readonly 900: "#3f4247";
28
+ readonly 950: "#28292c";
29
+ };
30
+ readonly green: {
31
+ readonly 50: "#ecf7ee";
32
+ readonly 100: "#dbf5df";
33
+ readonly 200: "#c2dfc7";
34
+ readonly 300: "#9ecba6";
35
+ readonly 400: "#60b775";
36
+ readonly 500: "#15a14c";
37
+ readonly 600: "#428a55";
38
+ readonly 700: "#0b7335";
39
+ readonly 800: "#055f2a";
40
+ readonly 900: "#045123";
41
+ readonly 950: "#02471e";
42
+ };
43
+ readonly amber: {
44
+ readonly 50: "#f8f4e5";
45
+ readonly 100: "#f7edc8";
46
+ readonly 200: "#e2d6a9";
47
+ readonly 300: "#d6bb79";
48
+ readonly 400: "#ca9734";
49
+ readonly 500: "#b47900";
50
+ readonly 600: "#9b702f";
51
+ readonly 700: "#815600";
52
+ readonly 800: "#6a4600";
53
+ readonly 900: "#5b3b00";
54
+ readonly 950: "#543601";
55
+ };
56
+ readonly red: {
57
+ readonly 50: "#fcf1ef";
58
+ readonly 100: "#ffe6e3";
59
+ readonly 200: "#efcdc8";
60
+ readonly 300: "#e5aea7";
61
+ readonly 400: "#f47368";
62
+ readonly 500: "#ea3e39";
63
+ readonly 600: "#b55a51";
64
+ readonly 700: "#a82d29";
65
+ readonly 800: "#921315";
66
+ readonly 900: "#7c1212";
67
+ readonly 950: "#671513";
68
+ };
69
+ readonly cyan: {
70
+ readonly 50: "#edf5f9";
71
+ readonly 100: "#ddf1f9";
72
+ readonly 200: "#c1dbe6";
73
+ readonly 300: "#97c6da";
74
+ readonly 400: "#51aed0";
75
+ readonly 500: "#0094bc";
76
+ readonly 600: "#3484a1";
77
+ readonly 700: "#006a87";
78
+ readonly 800: "#00576f";
79
+ readonly 900: "#004a5f";
80
+ readonly 950: "#1c4351";
81
+ };
82
+ readonly purple: {
83
+ readonly 50: "#f5f2fc";
84
+ readonly 100: "#f0e9ff";
85
+ readonly 200: "#d9d0ed";
86
+ readonly 300: "#c4b5e4";
87
+ readonly 400: "#ad8de5";
88
+ readonly 500: "#956ed3";
89
+ readonly 600: "#8469b0";
90
+ readonly 700: "#6b4e99";
91
+ readonly 800: "#583e81";
92
+ readonly 900: "#4b336f";
93
+ readonly 950: "#412963";
94
+ };
95
+ readonly mint: {
96
+ readonly 50: "#ebf6f5";
97
+ readonly 100: "#d7f4f1";
98
+ readonly 200: "#b9dfdb";
99
+ readonly 300: "#91cbc6";
100
+ readonly 400: "#54b3ad";
101
+ readonly 500: "#219a94";
102
+ readonly 600: "#3a8883";
103
+ readonly 700: "#116e6a";
104
+ readonly 800: "#0b5a57";
105
+ readonly 900: "#0e4c49";
106
+ readonly 950: "#11403e";
107
+ };
108
+ };
109
+ type ColorTable = typeof color;
110
+ /** 11단계 스케일을 가진 계열 이름. 예: `blue` */
111
+ export type ColorFamily = { [Key in keyof ColorTable]: ColorTable[Key] extends string ? never : Key; }[keyof ColorTable];
112
+ /** 스케일 단계. 50~950의 11단계 */
113
+ export type ColorStep = keyof ColorTable["blue"];
114
+ /** Primitive 이름. 예: `blue-600`, `white` */
115
+ export type PrimitiveColorName = { [Key in keyof ColorTable]: ColorTable[Key] extends string ? Key : never; }[keyof ColorTable] | { [Family in ColorFamily]: `${Family}-${ColorStep}`; }[ColorFamily];
116
+ /**
117
+ * Primitive 이름을 정본 hex로 바꾼다.
118
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
119
+ */
120
+ export declare function primitiveHex(name: PrimitiveColorName): string;
121
+ export {};
package/dist/color.js ADDED
@@ -0,0 +1,122 @@
1
+ // src/color.ts
2
+ const color = {
3
+ white: "#ffffff",
4
+ black: "#000000",
5
+ blue: {
6
+ 50: "#eff4fc",
7
+ 100: "#e3eefd",
8
+ 200: "#c9d7eb",
9
+ 300: "#a7c0e3",
10
+ 400: "#65a1f9",
11
+ 500: "#3183f5",
12
+ 600: "#4e7aba",
13
+ 700: "#2b5fa8",
14
+ 800: "#184c93",
15
+ 900: "#114080",
16
+ 950: "#113465"
17
+ },
18
+ gray: {
19
+ 50: "#f5f5f6",
20
+ 100: "#e8e8ea",
21
+ 200: "#d7d8da",
22
+ 300: "#bec1c4",
23
+ 400: "#9da1a6",
24
+ 500: "#82878e",
25
+ 600: "#747a81",
26
+ 700: "#5b6068",
27
+ 800: "#4a4e54",
28
+ 900: "#3f4247",
29
+ 950: "#28292c"
30
+ },
31
+ green: {
32
+ 50: "#ecf7ee",
33
+ 100: "#dbf5df",
34
+ 200: "#c2dfc7",
35
+ 300: "#9ecba6",
36
+ 400: "#60b775",
37
+ 500: "#15a14c",
38
+ 600: "#428a55",
39
+ 700: "#0b7335",
40
+ 800: "#055f2a",
41
+ 900: "#045123",
42
+ 950: "#02471e"
43
+ },
44
+ amber: {
45
+ 50: "#f8f4e5",
46
+ 100: "#f7edc8",
47
+ 200: "#e2d6a9",
48
+ 300: "#d6bb79",
49
+ 400: "#ca9734",
50
+ 500: "#b47900",
51
+ 600: "#9b702f",
52
+ 700: "#815600",
53
+ 800: "#6a4600",
54
+ 900: "#5b3b00",
55
+ 950: "#543601"
56
+ },
57
+ red: {
58
+ 50: "#fcf1ef",
59
+ 100: "#ffe6e3",
60
+ 200: "#efcdc8",
61
+ 300: "#e5aea7",
62
+ 400: "#f47368",
63
+ 500: "#ea3e39",
64
+ 600: "#b55a51",
65
+ 700: "#a82d29",
66
+ 800: "#921315",
67
+ 900: "#7c1212",
68
+ 950: "#671513"
69
+ },
70
+ cyan: {
71
+ 50: "#edf5f9",
72
+ 100: "#ddf1f9",
73
+ 200: "#c1dbe6",
74
+ 300: "#97c6da",
75
+ 400: "#51aed0",
76
+ 500: "#0094bc",
77
+ 600: "#3484a1",
78
+ 700: "#006a87",
79
+ 800: "#00576f",
80
+ 900: "#004a5f",
81
+ 950: "#1c4351"
82
+ },
83
+ purple: {
84
+ 50: "#f5f2fc",
85
+ 100: "#f0e9ff",
86
+ 200: "#d9d0ed",
87
+ 300: "#c4b5e4",
88
+ 400: "#ad8de5",
89
+ 500: "#956ed3",
90
+ 600: "#8469b0",
91
+ 700: "#6b4e99",
92
+ 800: "#583e81",
93
+ 900: "#4b336f",
94
+ 950: "#412963"
95
+ },
96
+ mint: {
97
+ 50: "#ebf6f5",
98
+ 100: "#d7f4f1",
99
+ 200: "#b9dfdb",
100
+ 300: "#91cbc6",
101
+ 400: "#54b3ad",
102
+ 500: "#219a94",
103
+ 600: "#3a8883",
104
+ 700: "#116e6a",
105
+ 800: "#0b5a57",
106
+ 900: "#0e4c49",
107
+ 950: "#11403e"
108
+ }
109
+ };
110
+ /**
111
+ * Primitive 이름을 정본 hex로 바꾼다.
112
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
113
+ */
114
+ function primitiveHex(name) {
115
+ if (name === "white" || name === "black") return color[name];
116
+ const index = name.lastIndexOf("-");
117
+ const family = name.slice(0, index);
118
+ const step = Number(name.slice(index + 1));
119
+ return color[family][step];
120
+ }
121
+
122
+ export { color, primitiveHex };
@@ -0,0 +1,73 @@
1
+ import { ColorSlot } from "./color-slot.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 {};
@@ -0,0 +1,193 @@
1
+ import { mixHex } from "./color-slot.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 };
@@ -0,0 +1,9 @@
1
+ import { ColorFamily, ColorStep, PrimitiveColorName, color } from "./color.js";
2
+ import { ColorSlot } from "./color-slot.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 };