@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.
@@ -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,49 @@
1
+ import { ColorStep } from "./color.js";
2
+ import { ColorSlot, SlotRule } from "./colorSlot.js";
3
+ import { SemanticColorName, SemanticNamespace, ThemeName } from "./semantic.js";
4
+ /** Primitive 변수 이름. 예: `--tide-color-blue-600` */
5
+ export declare function primitiveVar(name: string): string;
6
+ /** 계열 변수 이름. 예: `--tide-blue-solid` */
7
+ export declare function familyVar(family: string, slot: ColorSlot): string;
8
+ /** accent 슬롯 변수 이름. 예: `--tide-accent-solid` */
9
+ export declare function accentVar(slot: ColorSlot): string;
10
+ /** Semantic Token 변수 이름. 예: `--tide-bg-primary-solid` */
11
+ export declare function semanticVar(className: string): string;
12
+ /**
13
+ * 계열 하나의 Theme 블록 선언(슬롯마다 한 줄).
14
+ * @param stepHex 계열 단계의 hex. 덮기·섞기 값을 계산할 때 쓴다.
15
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
16
+ */
17
+ export declare function familyThemeDeclarations(family: string, steps: Readonly<Record<ColorSlot, SlotRule>>, theme: ThemeName, stepHex: (step: ColorStep) => string): string[];
18
+ /**
19
+ * `[data-color="<색 이름>"]` 규칙 하나. Role은 Role Token을, 계열은 계열 변수를 꽂는다.
20
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
21
+ */
22
+ export declare function dataColorRule(name: string): string;
23
+ /**
24
+ * Theme 블록의 accent 기본값(primary). data-color가 없는 요소도 그 Theme의 값을 읽는다.
25
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
26
+ */
27
+ export declare function accentDefaultDeclarations(): string[];
28
+ /**
29
+ * Tide 색 계열 전체의 Theme 블록 선언.
30
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
31
+ */
32
+ export declare function tideFamilyThemeDeclarations(theme: ThemeName): string[];
33
+ /**
34
+ * Role Token이 Theme에서 계열 변수의 별칭이면 그 변수 참조를 돌려준다. 덮어쓴 슬롯이거나 Role Token이 아니면 undefined다.
35
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
36
+ */
37
+ export declare function roleAliasCss(className: SemanticColorName, theme: ThemeName): string | undefined;
38
+ /** accent Utility class 하나. key는 Utility class에서 접두사를 뺀 이름이다. */
39
+ export interface AccentUtility {
40
+ readonly namespace: SemanticNamespace;
41
+ readonly key: string;
42
+ readonly slot: ColorSlot;
43
+ }
44
+ /**
45
+ * accent Utility class 목록. 예: `bg-accent-solid` → `--tide-accent-solid`, `text-accent` → `--tide-accent-text`,
46
+ * `border-accent-subtle` → `--tide-accent-subtle-border`
47
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
48
+ */
49
+ export declare const accentUtilities: readonly AccentUtility[];
@@ -0,0 +1,122 @@
1
+ import { color } from "./color.js";
2
+ import { colorFamilyNames, isRole, roleNames, roleSlotToken } from "./colorName.js";
3
+ import { colorSlots, familySlotSteps, isSlotStep, slotPrimitive, slotValueHex } from "./colorSlot.js";
4
+ import { roleFamily, semanticEntries, slotColorValue } from "./semantic.js";
5
+
6
+ // src/colorCss.ts
7
+ /** Primitive 변수 이름. 예: `--tide-color-blue-600` */
8
+ function primitiveVar(name) {
9
+ return `--tide-color-${name}`;
10
+ }
11
+ /** 계열 변수 이름. 예: `--tide-blue-solid` */
12
+ function familyVar(family, slot) {
13
+ return `--tide-${family}-${slot}`;
14
+ }
15
+ /** accent 슬롯 변수 이름. 예: `--tide-accent-solid` */
16
+ function accentVar(slot) {
17
+ return `--tide-accent-${slot}`;
18
+ }
19
+ /** Semantic Token 변수 이름. 예: `--tide-bg-primary-solid` */
20
+ function semanticVar(className) {
21
+ return `--tide-${className}`;
22
+ }
23
+ /**
24
+ * 슬롯 값의 CSS 표현. 계열 단계는 Primitive 변수를, white·black은 Tide Primitive 변수를 가리킨다.
25
+ * 덮기·섞기는 빌드할 때 계산한 hex다(런타임 `color-mix()`를 쓰지 않는다. 대비 검사와 같은 값이다, ADR 0022).
26
+ */
27
+ function slotCss(family, value, stepHex) {
28
+ return isSlotStep(value) ? `var(${primitiveVar(slotPrimitive(family, value))})` : slotValueHex(value, stepHex);
29
+ }
30
+ /**
31
+ * 계열 하나의 Theme 블록 선언(슬롯마다 한 줄).
32
+ * @param stepHex 계열 단계의 hex. 덮기·섞기 값을 계산할 때 쓴다.
33
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
34
+ */
35
+ function familyThemeDeclarations(family, steps, theme, stepHex) {
36
+ return colorSlots.map((slot) => ` ${familyVar(family, slot)}: ${slotCss(family, steps[slot][theme], stepHex)};`);
37
+ }
38
+ /** accent 슬롯에 변수를 꽂는 선언 */
39
+ function accentDeclarations(source) {
40
+ return colorSlots.map((slot) => ` ${accentVar(slot)}: var(${source(slot)});`);
41
+ }
42
+ /**
43
+ * `[data-color="<색 이름>"]` 규칙 하나. Role은 Role Token을, 계열은 계열 변수를 꽂는다.
44
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
45
+ */
46
+ function dataColorRule(name) {
47
+ const source = isRole(name) ? (slot) => semanticVar(roleSlotToken(name, slot)) : (slot) => familyVar(name, slot);
48
+ return [
49
+ `[data-color="${name}"] {`,
50
+ ...accentDeclarations(source),
51
+ "}"
52
+ ].join("\n");
53
+ }
54
+ /**
55
+ * Theme 블록의 accent 기본값(primary). data-color가 없는 요소도 그 Theme의 값을 읽는다.
56
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
57
+ */
58
+ function accentDefaultDeclarations() {
59
+ return accentDeclarations((slot) => semanticVar(roleSlotToken("primary", slot)));
60
+ }
61
+ /**
62
+ * Tide 색 계열 전체의 Theme 블록 선언.
63
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
64
+ */
65
+ function tideFamilyThemeDeclarations(theme) {
66
+ return colorFamilyNames.flatMap((family) => familyThemeDeclarations(family, familySlotSteps(family), theme, (step) => color[family][step]));
67
+ }
68
+ const roleAliases = new Map(roleNames.flatMap((role) => colorSlots.map((slot) => [roleSlotToken(role, slot), slot]).filter(([token]) => token.includes(`-${role}`)).map(([token, slot]) => [token, {
69
+ family: roleFamily[role],
70
+ slot
71
+ }])));
72
+ /**
73
+ * Role Token이 Theme에서 계열 변수의 별칭이면 그 변수 참조를 돌려준다. 덮어쓴 슬롯이거나 Role Token이 아니면 undefined다.
74
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
75
+ */
76
+ function roleAliasCss(className, theme) {
77
+ const alias = roleAliases.get(className);
78
+ if (!alias) return void 0;
79
+ const family = alias.family;
80
+ const familyValue = slotColorValue(family, familySlotSteps(family)[alias.slot][theme]);
81
+ const entry = semanticEntries().find((candidate) => candidate.className === className);
82
+ return JSON.stringify(entry.value[theme]) === JSON.stringify(familyValue) ? `var(${familyVar(family, alias.slot)})` : void 0;
83
+ }
84
+ /**
85
+ * accent Utility class 목록. 예: `bg-accent-solid` → `--tide-accent-solid`, `text-accent` → `--tide-accent-text`,
86
+ * `border-accent-subtle` → `--tide-accent-subtle-border`
87
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
88
+ */
89
+ const accentUtilities = [
90
+ ...colorSlots.filter((slot) => slot !== "text" && slot !== "border" && slot !== "subtle-border" && slot !== "on-solid" && slot !== "on-subtle").map((slot) => ({
91
+ namespace: "background",
92
+ key: `accent-${slot}`,
93
+ slot
94
+ })),
95
+ {
96
+ namespace: "text",
97
+ key: "accent",
98
+ slot: "text"
99
+ },
100
+ {
101
+ namespace: "text",
102
+ key: "accent-on-solid",
103
+ slot: "on-solid"
104
+ },
105
+ {
106
+ namespace: "text",
107
+ key: "accent-on-subtle",
108
+ slot: "on-subtle"
109
+ },
110
+ {
111
+ namespace: "border",
112
+ key: "accent",
113
+ slot: "border"
114
+ },
115
+ {
116
+ namespace: "border",
117
+ key: "accent-subtle",
118
+ slot: "subtle-border"
119
+ }
120
+ ];
121
+
122
+ export { accentDefaultDeclarations, accentUtilities, accentVar, dataColorRule, familyThemeDeclarations, familyVar, primitiveVar, roleAliasCss, semanticVar, tideFamilyThemeDeclarations };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `@tide-design/foundation/color-family`: 앱이 자기 브랜드 색 계열을 더하는 API.
3
+ *
4
+ * 앱은 `defineColorFamily`로 11단계 스케일을 정의하고, `tide-color build <파일>`로 CSS를 만든다.
5
+ * CSS는 Tide 계열과 같은 매핑 규칙으로 light·dark 계열 변수와 `[data-color="<이름>"]` 규칙을 담는다.
6
+ * @packageDocumentation
7
+ */
8
+ import { ColorStep } from "./color.js";
9
+ import { ColorSlot, SlotColorRef, SlotMix, SlotOverlay, SlotOverrides, SlotRule, SlotStep, SlotValue } from "./colorSlot.js";
10
+ import { ColorContrastResult, ColorContrastRule } from "./contrast.js";
11
+ import { ThemeName } from "./semantic.js";
12
+ /** 50~950의 11단계 스케일. 값은 `#rrggbb` hex다. */
13
+ export type ColorScale = Readonly<Record<ColorStep, string>>;
14
+ /** `defineColorFamily`에 넘기는 값 */
15
+ export interface ColorFamilyInput<Name extends string> {
16
+ /** 색 이름. `data-color`와 변수 이름(`--tide-<이름>-solid`)에 쓴다. 소문자, 숫자, `-`만 쓴다. */
17
+ readonly name: Name;
18
+ /** 11단계 스케일 전체 */
19
+ readonly scale: ColorScale;
20
+ /**
21
+ * 매핑 규칙에서 덮어쓸 슬롯 값. 예: 밝은 계열의 `on-solid`를 `{ light: 950, dark: 950 }`으로.
22
+ * 단계 대신 덮기(`{ step: 100, overlay: "gray-950", amount: 0.04 }`)나 섞기(`{ mix: ["gray-950", 950] }`)도 쓸 수 있다.
23
+ */
24
+ readonly overrides?: SlotOverrides;
25
+ }
26
+ /** 검증을 마친 앱 색 계열 */
27
+ export interface ColorFamilyDefinition<Name extends string = string> {
28
+ readonly name: Name;
29
+ readonly scale: ColorScale;
30
+ readonly overrides: SlotOverrides;
31
+ }
32
+ /**
33
+ * 앱 브랜드 색 계열을 정의한다. 이름, 스케일, 덮어쓸 값이 올바른지 확인하고 그대로 돌려준다.
34
+ *
35
+ * ```ts
36
+ * // brand.ts
37
+ * import { defineColorFamily } from "@tide-design/foundation/color-family";
38
+ *
39
+ * export default defineColorFamily({
40
+ * name: "brand",
41
+ * scale: { 50: "#fcf0f5", 100: "#fee5f0", ... 950: "#5c1d3f" },
42
+ * });
43
+ * ```
44
+ *
45
+ * @throws 이름이 Tide 색 이름과 겹치거나, 스케일 단계가 빠졌거나, hex가 `#rrggbb`가 아니면
46
+ */
47
+ export declare function defineColorFamily<const Name extends string>(input: ColorFamilyInput<Name>): ColorFamilyDefinition<Name>;
48
+ /** 앱 계열의 Theme별 슬롯 hex */
49
+ export declare function colorFamilySlotHex(family: ColorFamilyDefinition): Record<ThemeName, Record<ColorSlot, string>>;
50
+ /** 앱 계열을 Tide와 같은 대비 쌍 규칙으로 light·dark에서 검사한다. 미달이면 `pass`가 false다. */
51
+ export declare function checkColorFamily(family: ColorFamilyDefinition): ColorContrastResult[];
52
+ /**
53
+ * 앱 계열의 CSS. Primitive 변수, light·dark 계열 변수, `[data-color]` 규칙을 담는다.
54
+ * Tide CSS(`@tide-design/components/styles.css` 또는 foundation CSS) 다음에 불러온다.
55
+ */
56
+ export declare function colorFamilyCss(families: readonly ColorFamilyDefinition[]): string;
57
+ export type { ColorContrastResult, ColorContrastRule, ColorSlot, SlotColorRef, SlotMix, SlotOverlay, SlotOverrides, SlotRule, SlotStep, SlotValue };
@@ -0,0 +1,125 @@
1
+ import { color } from "./color.js";
2
+ import { tideColorNames } from "./colorName.js";
3
+ import { dataColorRule, familyThemeDeclarations, primitiveVar } from "./colorCss.js";
4
+ import { colorSlots, resolveSlotSteps, slotPrimitive, slotValueHex } from "./colorSlot.js";
5
+ import { checkColorContrast } from "./contrast.js";
6
+
7
+ // src/colorFamily.ts
8
+ /**
9
+ * `@tide-design/foundation/color-family`: 앱이 자기 브랜드 색 계열을 더하는 API.
10
+ *
11
+ * 앱은 `defineColorFamily`로 11단계 스케일을 정의하고, `tide-color build <파일>`로 CSS를 만든다.
12
+ * CSS는 Tide 계열과 같은 매핑 규칙으로 light·dark 계열 변수와 `[data-color="<이름>"]` 규칙을 담는다.
13
+ * @packageDocumentation
14
+ */
15
+ const steps = Object.keys(color.blue).map(Number);
16
+ const reservedNames = /* @__PURE__ */ new Set([
17
+ ...tideColorNames,
18
+ "accent",
19
+ "white",
20
+ "black",
21
+ "color",
22
+ "bg",
23
+ "text",
24
+ "border",
25
+ "outline",
26
+ "font",
27
+ "rounded",
28
+ "shadow",
29
+ "duration",
30
+ "ease",
31
+ "z",
32
+ "focus"
33
+ ]);
34
+ function isSlotStep(value) {
35
+ return value === "white" || value === "black" || steps.includes(value);
36
+ }
37
+ /** 덮기·섞기가 참조할 수 있는 색: 그 계열 단계, 또는 Tide Primitive 이름 */
38
+ function isColorRef(value) {
39
+ return steps.includes(value) || Object.hasOwn(primitiveNames, value);
40
+ }
41
+ const primitiveNames = Object.fromEntries(Object.entries(color).flatMap(([name, scale]) => typeof scale === "string" ? [[name, true]] : Object.keys(scale).map((step) => [`${name}-${step}`, true])));
42
+ /** 슬롯 값: 단계, 덮기(`{ step, overlay, amount }`), 섞기(`{ mix: [a, b] }`) */
43
+ function isSlotValue(value) {
44
+ if (isSlotStep(value)) return true;
45
+ if (typeof value !== "object" || value === null) return false;
46
+ const record = value;
47
+ if ("mix" in record) return Object.keys(record).length === 1 && Array.isArray(record.mix) && record.mix.length === 2 && record.mix.every(isColorRef);
48
+ return Object.keys(record).length === 3 && steps.includes(record.step) && typeof record.overlay === "string" && Object.hasOwn(primitiveNames, record.overlay) && typeof record.amount === "number" && record.amount > 0 && record.amount < 1;
49
+ }
50
+ /**
51
+ * 앱 브랜드 색 계열을 정의한다. 이름, 스케일, 덮어쓸 값이 올바른지 확인하고 그대로 돌려준다.
52
+ *
53
+ * ```ts
54
+ * // brand.ts
55
+ * import { defineColorFamily } from "@tide-design/foundation/color-family";
56
+ *
57
+ * export default defineColorFamily({
58
+ * name: "brand",
59
+ * scale: { 50: "#fcf0f5", 100: "#fee5f0", ... 950: "#5c1d3f" },
60
+ * });
61
+ * ```
62
+ *
63
+ * @throws 이름이 Tide 색 이름과 겹치거나, 스케일 단계가 빠졌거나, hex가 `#rrggbb`가 아니면
64
+ */
65
+ function defineColorFamily(input) {
66
+ const { name, scale, overrides = {} } = input;
67
+ if (!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(name)) throw new Error(`색 이름은 소문자로 시작하는 kebab-case여야 한다: "${name}"`);
68
+ if (reservedNames.has(name)) throw new Error(`"${name}"은 Tide가 쓰는 이름이라 앱 색 계열 이름으로 쓸 수 없다.`);
69
+ for (const step of steps) {
70
+ const hex = scale[step];
71
+ if (typeof hex !== "string" || !/^#[0-9a-f]{6}$/i.test(hex)) throw new Error(`${name}-${step}: #rrggbb hex가 아니다(${String(hex)})`);
72
+ }
73
+ const extraSteps = Object.keys(scale).filter((step) => !steps.includes(Number(step)));
74
+ if (extraSteps.length > 0) throw new Error(`${name}: 스케일에 없는 단계가 있다(${extraSteps.join(", ")})`);
75
+ for (const [slot, rule] of Object.entries(overrides)) {
76
+ if (!colorSlots.includes(slot)) throw new Error(`${name}: 없는 슬롯을 덮어썼다(${slot})`);
77
+ for (const [theme, step] of Object.entries(rule ?? {})) if (theme !== "light" && theme !== "dark" || !isSlotValue(step)) throw new Error(`${name}: ${slot}.${theme} 값이 단계(50~950, white, black), 덮기, 섞기가 아니다`);
78
+ }
79
+ return {
80
+ name,
81
+ scale: Object.fromEntries(steps.map((step) => [step, scale[step].toLowerCase()])),
82
+ overrides
83
+ };
84
+ }
85
+ /** 앱 계열의 슬롯별 단계(규칙 + 덮어쓸 값) */
86
+ function slotSteps(family) {
87
+ return resolveSlotSteps(family.overrides);
88
+ }
89
+ /** 앱 계열의 Theme별 슬롯 hex */
90
+ function colorFamilySlotHex(family) {
91
+ const resolved = slotSteps(family);
92
+ const hex = (value) => slotValueHex(value, (step) => family.scale[step]);
93
+ return {
94
+ light: Object.fromEntries(colorSlots.map((slot) => [slot, hex(resolved[slot].light)])),
95
+ dark: Object.fromEntries(colorSlots.map((slot) => [slot, hex(resolved[slot].dark)]))
96
+ };
97
+ }
98
+ /** 앱 계열을 Tide와 같은 대비 쌍 규칙으로 light·dark에서 검사한다. 미달이면 `pass`가 false다. */
99
+ function checkColorFamily(family) {
100
+ return checkColorContrast(colorFamilySlotHex(family));
101
+ }
102
+ /**
103
+ * 앱 계열의 CSS. Primitive 변수, light·dark 계열 변수, `[data-color]` 규칙을 담는다.
104
+ * Tide CSS(`@tide-design/components/styles.css` 또는 foundation CSS) 다음에 불러온다.
105
+ */
106
+ function colorFamilyCss(families) {
107
+ const themeBlock = (theme) => families.flatMap((family) => familyThemeDeclarations(family.name, slotSteps(family), theme, (step) => family.scale[step]));
108
+ return [
109
+ ":root {",
110
+ ...families.flatMap((family) => steps.map((step) => ` ${primitiveVar(slotPrimitive(family.name, step))}: ${family.scale[step]};`)),
111
+ "}",
112
+ "",
113
+ ":root,\n[data-theme=\"light\"] {",
114
+ ...themeBlock("light"),
115
+ "}",
116
+ "",
117
+ "[data-theme=\"dark\"] {",
118
+ ...themeBlock("dark"),
119
+ "}",
120
+ "",
121
+ ...families.flatMap((family) => [dataColorRule(family.name), ""])
122
+ ].join("\n");
123
+ }
124
+
125
+ export { checkColorFamily, colorFamilyCss, colorFamilySlotHex, defineColorFamily };
@@ -0,0 +1,40 @@
1
+ import { ColorFamily } from "./color.js";
2
+ import { ColorSlot } from "./colorSlot.js";
3
+ import { SemanticColorName, ThemeName, ThemedColor, TideRole } from "./semantic.js";
4
+ /** Tide에 들어 있는 색 이름. 앱이 augmentation으로 더한 이름은 들어 있지 않다. */
5
+ export type TideColor = TideRole | ColorFamily;
6
+ /**
7
+ * Role 이름 목록(neutral, primary, success, warning, danger, info 순서).
8
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
9
+ */
10
+ export declare const roleNames: readonly TideRole[];
11
+ /**
12
+ * Tide 색 계열 목록(`color`의 11단계 계열 순서).
13
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
14
+ */
15
+ export declare const colorFamilyNames: readonly ColorFamily[];
16
+ /**
17
+ * Tide 색 이름 목록. Role 다음에 색 계열이 온다.
18
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
19
+ */
20
+ export declare const tideColorNames: readonly TideColor[];
21
+ /**
22
+ * Tide Role인지 확인한다. 앱 Role은 Role Token이 없어서 false다.
23
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
24
+ */
25
+ export declare function isRole(name: string): name is TideRole;
26
+ /**
27
+ * Role 슬롯이 가리키는 Semantic Token. 예: (`primary`, `solid`) → `bg-primary-solid`, (`neutral`, `text`) → `text-default`
28
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
29
+ */
30
+ export declare function roleSlotToken(role: TideRole, slot: ColorSlot): SemanticColorName;
31
+ /**
32
+ * Tide 색 이름 하나의 슬롯별 값(Theme별 Primitive).
33
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
34
+ */
35
+ export declare function colorSlotValues(name: TideColor): Record<ColorSlot, ThemedColor>;
36
+ /**
37
+ * Tide 색 이름 하나의 슬롯별 hex(Theme 하나).
38
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
39
+ */
40
+ export declare function colorSlotHex(name: TideColor, theme: ThemeName): Record<ColorSlot, string>;