@tide-design/foundation 0.0.0-placeholder → 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.
package/dist/cli.js ADDED
@@ -0,0 +1,970 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from "node:path";
3
+ import process from "node:process";
4
+ import { pathToFileURL } from "node:url";
5
+
6
+ // src/color.ts
7
+ const color = {
8
+ white: "#ffffff",
9
+ black: "#000000",
10
+ blue: {
11
+ 50: "#eff4fc",
12
+ 100: "#e3eefd",
13
+ 200: "#c9d7eb",
14
+ 300: "#a7c0e3",
15
+ 400: "#65a1f9",
16
+ 500: "#3183f5",
17
+ 600: "#4e7aba",
18
+ 700: "#2b5fa8",
19
+ 800: "#184c93",
20
+ 900: "#114080",
21
+ 950: "#113465"
22
+ },
23
+ gray: {
24
+ 50: "#f5f5f6",
25
+ 100: "#e8e8ea",
26
+ 200: "#d7d8da",
27
+ 300: "#bec1c4",
28
+ 400: "#9da1a6",
29
+ 500: "#82878e",
30
+ 600: "#747a81",
31
+ 700: "#5b6068",
32
+ 800: "#4a4e54",
33
+ 900: "#3f4247",
34
+ 950: "#28292c"
35
+ },
36
+ green: {
37
+ 50: "#ecf7ee",
38
+ 100: "#dbf5df",
39
+ 200: "#c2dfc7",
40
+ 300: "#9ecba6",
41
+ 400: "#60b775",
42
+ 500: "#15a14c",
43
+ 600: "#428a55",
44
+ 700: "#0b7335",
45
+ 800: "#055f2a",
46
+ 900: "#045123",
47
+ 950: "#02471e"
48
+ },
49
+ amber: {
50
+ 50: "#f8f4e5",
51
+ 100: "#f7edc8",
52
+ 200: "#e2d6a9",
53
+ 300: "#d6bb79",
54
+ 400: "#ca9734",
55
+ 500: "#b47900",
56
+ 600: "#9b702f",
57
+ 700: "#815600",
58
+ 800: "#6a4600",
59
+ 900: "#5b3b00",
60
+ 950: "#543601"
61
+ },
62
+ red: {
63
+ 50: "#fcf1ef",
64
+ 100: "#ffe6e3",
65
+ 200: "#efcdc8",
66
+ 300: "#e5aea7",
67
+ 400: "#f47368",
68
+ 500: "#ea3e39",
69
+ 600: "#b55a51",
70
+ 700: "#a82d29",
71
+ 800: "#921315",
72
+ 900: "#7c1212",
73
+ 950: "#671513"
74
+ },
75
+ cyan: {
76
+ 50: "#edf5f9",
77
+ 100: "#ddf1f9",
78
+ 200: "#c1dbe6",
79
+ 300: "#97c6da",
80
+ 400: "#51aed0",
81
+ 500: "#0094bc",
82
+ 600: "#3484a1",
83
+ 700: "#006a87",
84
+ 800: "#00576f",
85
+ 900: "#004a5f",
86
+ 950: "#1c4351"
87
+ },
88
+ purple: {
89
+ 50: "#f5f2fc",
90
+ 100: "#f0e9ff",
91
+ 200: "#d9d0ed",
92
+ 300: "#c4b5e4",
93
+ 400: "#ad8de5",
94
+ 500: "#956ed3",
95
+ 600: "#8469b0",
96
+ 700: "#6b4e99",
97
+ 800: "#583e81",
98
+ 900: "#4b336f",
99
+ 950: "#412963"
100
+ },
101
+ mint: {
102
+ 50: "#ebf6f5",
103
+ 100: "#d7f4f1",
104
+ 200: "#b9dfdb",
105
+ 300: "#91cbc6",
106
+ 400: "#54b3ad",
107
+ 500: "#219a94",
108
+ 600: "#3a8883",
109
+ 700: "#116e6a",
110
+ 800: "#0b5a57",
111
+ 900: "#0e4c49",
112
+ 950: "#11403e"
113
+ }
114
+ };
115
+ /**
116
+ * Primitive 이름을 정본 hex로 바꾼다.
117
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
118
+ */
119
+ function primitiveHex(name) {
120
+ if (name === "white" || name === "black") return color[name];
121
+ const index = name.lastIndexOf("-");
122
+ const family = name.slice(0, index);
123
+ const step = Number(name.slice(index + 1));
124
+ return color[family][step];
125
+ }
126
+
127
+ // src/color-slot.ts
128
+ /**
129
+ * 색 계열 변수 묶음의 슬롯. CSS에서는 `--tide-<색 이름>-<슬롯>`과 `--tide-accent-<슬롯>`으로 나간다.
130
+ */
131
+ const colorSlots = [
132
+ "solid",
133
+ "solid-hover",
134
+ "solid-active",
135
+ "subtle",
136
+ "subtle-hover",
137
+ "subtle-active",
138
+ "faint",
139
+ "text",
140
+ "border",
141
+ "subtle-border",
142
+ "on-solid",
143
+ "on-subtle"
144
+ ];
145
+ /**
146
+ * 슬롯 매핑 규칙.
147
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
148
+ */
149
+ const slotRule = {
150
+ solid: {
151
+ light: 600,
152
+ dark: 600
153
+ },
154
+ "solid-hover": {
155
+ light: {
156
+ step: 600,
157
+ overlay: "black",
158
+ amount: .14
159
+ },
160
+ dark: {
161
+ step: 600,
162
+ overlay: "black",
163
+ amount: .14
164
+ }
165
+ },
166
+ "solid-active": {
167
+ light: {
168
+ step: 600,
169
+ overlay: "black",
170
+ amount: .2
171
+ },
172
+ dark: {
173
+ step: 600,
174
+ overlay: "black",
175
+ amount: .2
176
+ }
177
+ },
178
+ subtle: {
179
+ light: 100,
180
+ dark: 950
181
+ },
182
+ "subtle-hover": {
183
+ light: {
184
+ step: 100,
185
+ overlay: "gray-950",
186
+ amount: .04
187
+ },
188
+ dark: {
189
+ step: 950,
190
+ overlay: "white",
191
+ amount: .06
192
+ }
193
+ },
194
+ "subtle-active": {
195
+ light: {
196
+ step: 100,
197
+ overlay: "gray-950",
198
+ amount: .08
199
+ },
200
+ dark: {
201
+ step: 950,
202
+ overlay: "white",
203
+ amount: .1
204
+ }
205
+ },
206
+ faint: {
207
+ light: 50,
208
+ dark: { mix: ["gray-950", 950] }
209
+ },
210
+ text: {
211
+ light: 700,
212
+ dark: 300
213
+ },
214
+ border: {
215
+ light: 600,
216
+ dark: 400
217
+ },
218
+ "subtle-border": {
219
+ light: 200,
220
+ dark: 800
221
+ },
222
+ "on-solid": {
223
+ light: "white",
224
+ dark: "white"
225
+ },
226
+ "on-subtle": {
227
+ light: 950,
228
+ dark: 100
229
+ }
230
+ };
231
+ /**
232
+ * Tide 계열별 덮어쓸 값.
233
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
234
+ */
235
+ const familyOverrides = {};
236
+ /**
237
+ * 규칙에 덮어쓸 값을 얹은 슬롯별 값.
238
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
239
+ */
240
+ function resolveSlotSteps(...overrides) {
241
+ return Object.fromEntries(colorSlots.map((slot) => {
242
+ return [slot, overrides.reduce((current, override) => ({
243
+ ...current,
244
+ ...override?.[slot]
245
+ }), slotRule[slot])];
246
+ }));
247
+ }
248
+ /**
249
+ * 슬롯 단계를 Primitive 이름으로 바꾼다. 예: (`blue`, 600) → `blue-600`, (`blue`, `white`) → `white`
250
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
251
+ */
252
+ function slotPrimitive(family, step) {
253
+ return typeof step === "number" ? `${family}-${step}` : step;
254
+ }
255
+ /**
256
+ * 슬롯 값이 단계 하나인지(덮기·섞기가 아닌지) 확인한다.
257
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
258
+ */
259
+ function isSlotStep$1(value) {
260
+ return typeof value !== "object";
261
+ }
262
+ /**
263
+ * 두 색을 섞은 값(`#rrggbb`). sRGB 채널마다 `a × (1 − amount) + b × amount`를 반올림한다.
264
+ * 불투명한 색을 그 위에 `amount`만큼 덮은 값(브라우저의 알파 합성)과 같다.
265
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
266
+ */
267
+ function mixHex(a, b, amount) {
268
+ const channels = (hex) => {
269
+ const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);
270
+ if (!match) throw new Error(`불투명한 6자리 hex가 아니다: ${hex}`);
271
+ return match.slice(1).map((channel) => Number.parseInt(channel, 16));
272
+ };
273
+ const from = channels(a);
274
+ const to = channels(b);
275
+ return `#${from.map((value, index) => Math.round(value * (1 - amount) + to[index] * amount).toString(16).padStart(2, "0")).join("")}`;
276
+ }
277
+ /**
278
+ * 슬롯 값의 hex. 덮기·섞기는 여기서 계산한다(빌드 시 hex로 넣는다. 런타임 `color-mix()`를 쓰지 않는다).
279
+ * @param stepHex 계열 단계의 hex. Tide 계열은 `color`, 앱 계열은 그 스케일이다.
280
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
281
+ */
282
+ function slotValueHex(value, stepHex) {
283
+ const ref = (color) => typeof color === "number" ? stepHex(color) : primitiveHex(color);
284
+ if (typeof value !== "object") return ref(value);
285
+ if ("mix" in value) return mixHex(ref(value.mix[0]), ref(value.mix[1]), .5);
286
+ return mixHex(stepHex(value.step), primitiveHex(value.overlay), value.amount);
287
+ }
288
+
289
+ // src/semantic.ts
290
+ /**
291
+ * Role이 참조하는 Primitive 계열.
292
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
293
+ */
294
+ const roleFamily = {
295
+ neutral: "gray",
296
+ primary: "blue",
297
+ success: "green",
298
+ warning: "amber",
299
+ danger: "red",
300
+ info: "cyan"
301
+ };
302
+ /**
303
+ * Role별로 계열 규칙에서 덮어쓸 값.
304
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
305
+ */
306
+ const roleOverrides = { neutral: {
307
+ subtle: { dark: 900 },
308
+ "subtle-hover": { dark: 800 },
309
+ "subtle-active": { dark: 700 }
310
+ } };
311
+ /**
312
+ * 역할 Token 대신 공통 Semantic Token을 쓰는 Role 슬롯. on-solid는 모든 Role이 `text-on-solid`를 쓴다.
313
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
314
+ */
315
+ const roleSharedSlots = { neutral: {
316
+ text: "text-default",
317
+ border: "border-strong",
318
+ "on-subtle": "text-default"
319
+ } };
320
+ /**
321
+ * 계열 슬롯 값을 Semantic 값으로 바꾼다. 단계는 Primitive 이름, 덮기·섞기는 `MixedColor`다.
322
+ * 예: (`blue`, 600) → `blue-600`, (`blue`, 100 + gray-950 4%) → `{ base: "blue-100", mix: "gray-950", amount: 0.04 }`
323
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
324
+ */
325
+ function slotColorValue(family, value) {
326
+ const name = (ref) => slotPrimitive(family, ref);
327
+ if (typeof value !== "object") return name(value);
328
+ if ("mix" in value) return {
329
+ base: name(value.mix[0]),
330
+ mix: name(value.mix[1]),
331
+ amount: .5
332
+ };
333
+ return {
334
+ base: name(value.step),
335
+ mix: value.overlay,
336
+ amount: value.amount
337
+ };
338
+ }
339
+ const roles$1 = Object.keys(roleFamily);
340
+ const backgroundSlots = colorSlots.filter((slot) => slot !== "text" && slot !== "border" && slot !== "subtle-border" && slot !== "on-solid" && slot !== "on-subtle");
341
+ /** 그 슬롯을 공통 Token과 나눠 쓰지 않는 Role */
342
+ function ownRoles(slot) {
343
+ const shared = roleSharedSlots;
344
+ return roles$1.filter((role) => !Object.hasOwn(shared[role] ?? {}, slot));
345
+ }
346
+ /** Role 슬롯이 가리키는 값. 계열 규칙 → 계열 덮어쓸 값 → Role 덮어쓸 값 순서로 얹는다. */
347
+ function roleSlotColor(role, slot) {
348
+ const family = roleFamily[role];
349
+ const steps = resolveSlotSteps(familyOverrides[family], roleOverrides[role])[slot];
350
+ return {
351
+ light: slotColorValue(family, steps.light),
352
+ dark: slotColorValue(family, steps.dark)
353
+ };
354
+ }
355
+ const commonBackground = {
356
+ canvas: {
357
+ light: "white",
358
+ dark: "gray-950"
359
+ },
360
+ surface: {
361
+ light: "white",
362
+ dark: "gray-950"
363
+ },
364
+ raised: {
365
+ light: "white",
366
+ dark: "gray-900"
367
+ },
368
+ disabled: {
369
+ light: "gray-100",
370
+ dark: "gray-900"
371
+ },
372
+ overlay: {
373
+ light: {
374
+ primitive: "gray-950",
375
+ alpha: .5
376
+ },
377
+ dark: {
378
+ primitive: "gray-950",
379
+ alpha: .7
380
+ }
381
+ },
382
+ hover: {
383
+ light: {
384
+ primitive: "gray-950",
385
+ alpha: .04
386
+ },
387
+ dark: {
388
+ primitive: "white",
389
+ alpha: .06
390
+ }
391
+ },
392
+ active: {
393
+ light: {
394
+ primitive: "gray-950",
395
+ alpha: .08
396
+ },
397
+ dark: {
398
+ primitive: "white",
399
+ alpha: .1
400
+ }
401
+ }
402
+ };
403
+ const commonText = {
404
+ default: {
405
+ light: "gray-900",
406
+ dark: "gray-50"
407
+ },
408
+ muted: {
409
+ light: "gray-700",
410
+ dark: "gray-300"
411
+ },
412
+ disabled: {
413
+ light: "gray-400",
414
+ dark: "gray-600"
415
+ },
416
+ "on-solid": {
417
+ light: "white",
418
+ dark: "white"
419
+ }
420
+ };
421
+ const commonBorder = {
422
+ default: {
423
+ light: "gray-200",
424
+ dark: "gray-800"
425
+ },
426
+ strong: {
427
+ light: "gray-500",
428
+ dark: "gray-400"
429
+ },
430
+ raised: {
431
+ light: "transparent",
432
+ dark: "gray-800"
433
+ }
434
+ };
435
+ const commonOutline = { focus: {
436
+ light: "blue-600",
437
+ dark: "blue-400"
438
+ } };
439
+ const semantic = {
440
+ background: {
441
+ ...commonBackground,
442
+ ...Object.fromEntries(roles$1.flatMap((role) => backgroundSlots.map((slot) => [`${role}-${slot}`, roleSlotColor(role, slot)])))
443
+ },
444
+ text: {
445
+ ...commonText,
446
+ ...Object.fromEntries(ownRoles("text").map((role) => [role, roleSlotColor(role, "text")])),
447
+ ...Object.fromEntries(ownRoles("on-subtle").map((role) => [`${role}-on-subtle`, roleSlotColor(role, "on-subtle")]))
448
+ },
449
+ border: {
450
+ ...commonBorder,
451
+ ...Object.fromEntries(ownRoles("border").map((role) => [role, roleSlotColor(role, "border")])),
452
+ ...Object.fromEntries(ownRoles("subtle-border").map((role) => [`${role}-subtle`, roleSlotColor(role, "subtle-border")]))
453
+ },
454
+ outline: commonOutline
455
+ };
456
+ const semanticPrefix = {
457
+ background: "bg",
458
+ text: "text",
459
+ border: "border",
460
+ outline: "outline"
461
+ };
462
+ /**
463
+ * 모든 Semantic Token(namespace, Utility class 이름, Theme별 값).
464
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
465
+ */
466
+ function semanticEntries() {
467
+ return Object.keys(semantic).flatMap((namespace) => Object.entries(semantic[namespace]).map(([key, value]) => ({
468
+ namespace,
469
+ key,
470
+ className: `${semanticPrefix[namespace]}-${key}`,
471
+ value
472
+ })));
473
+ }
474
+ /**
475
+ * 값을 hex로 바꾼다. alpha가 있으면 8자리 hex(`#rrggbbaa`)다. `transparent`는 `#00000000`이다.
476
+ * 덮기·섞기(`MixedColor`)는 계산한 6자리 hex다.
477
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
478
+ */
479
+ function colorValueHex(value) {
480
+ if (value === "transparent") return "#00000000";
481
+ if (typeof value === "string") return primitiveHex(value);
482
+ if ("base" in value) return mixHex(primitiveHex(value.base), primitiveHex(value.mix), value.amount);
483
+ const alpha = Math.round(value.alpha * 255).toString(16).padStart(2, "0");
484
+ return `${primitiveHex(value.primitive)}${alpha}`;
485
+ }
486
+ /**
487
+ * Semantic Token이 Theme에서 가리키는 hex.
488
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
489
+ */
490
+ function semanticHex(name, theme) {
491
+ const entry = semanticEntries().find((candidate) => candidate.className === name);
492
+ if (!entry) throw new Error(`Semantic Token이 아니다: ${name}`);
493
+ return colorValueHex(entry.value[theme]);
494
+ }
495
+
496
+ // src/color-name.ts
497
+ /**
498
+ * Role 이름 목록(neutral, primary, success, warning, danger, info 순서).
499
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
500
+ */
501
+ const roleNames = Object.keys(roleFamily);
502
+ /**
503
+ * Tide 색 계열 목록(`color`의 11단계 계열 순서).
504
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
505
+ */
506
+ const colorFamilyNames = Object.keys(color).filter((name) => typeof color[name] !== "string");
507
+ /**
508
+ * Tide 색 이름 목록. Role 다음에 색 계열이 온다.
509
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
510
+ */
511
+ const tideColorNames = [...roleNames, ...colorFamilyNames];
512
+ /**
513
+ * Tide Role인지 확인한다. 앱 Role은 Role Token이 없어서 false다.
514
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
515
+ */
516
+ function isRole(name) {
517
+ return Object.hasOwn(roleFamily, name);
518
+ }
519
+ /**
520
+ * Role 슬롯이 가리키는 Semantic Token. 예: (`primary`, `solid`) → `bg-primary-solid`, (`neutral`, `text`) → `text-default`
521
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
522
+ */
523
+ function roleSlotToken(role, slot) {
524
+ if (slot === "on-solid") return "text-on-solid";
525
+ const shared = roleSharedSlots[role]?.[slot];
526
+ if (shared) return shared;
527
+ switch (slot) {
528
+ case "text":
529
+ case "border": return `${slot}-${role}`;
530
+ case "on-subtle": return `text-${role}-on-subtle`;
531
+ case "subtle-border": return `border-${role}-subtle`;
532
+ default: return `bg-${role}-${slot}`;
533
+ }
534
+ }
535
+
536
+ // src/color-css.ts
537
+ /** Primitive 변수 이름. 예: `--tide-color-blue-600` */
538
+ function primitiveVar(name) {
539
+ return `--tide-color-${name}`;
540
+ }
541
+ /** 계열 변수 이름. 예: `--tide-blue-solid` */
542
+ function familyVar(family, slot) {
543
+ return `--tide-${family}-${slot}`;
544
+ }
545
+ /** accent 슬롯 변수 이름. 예: `--tide-accent-solid` */
546
+ function accentVar(slot) {
547
+ return `--tide-accent-${slot}`;
548
+ }
549
+ /** Semantic Token 변수 이름. 예: `--tide-bg-primary-solid` */
550
+ function semanticVar(className) {
551
+ return `--tide-${className}`;
552
+ }
553
+ /**
554
+ * 슬롯 값의 CSS 표현. 계열 단계는 Primitive 변수를, white·black은 Tide Primitive 변수를 가리킨다.
555
+ * 덮기·섞기는 빌드할 때 계산한 hex다(런타임 `color-mix()`를 쓰지 않는다. 대비 검사와 같은 값이다, ADR 0022).
556
+ */
557
+ function slotCss(family, value, stepHex) {
558
+ return isSlotStep$1(value) ? `var(${primitiveVar(slotPrimitive(family, value))})` : slotValueHex(value, stepHex);
559
+ }
560
+ /**
561
+ * 계열 하나의 Theme 블록 선언(슬롯마다 한 줄).
562
+ * @param stepHex 계열 단계의 hex. 덮기·섞기 값을 계산할 때 쓴다.
563
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
564
+ */
565
+ function familyThemeDeclarations(family, steps, theme, stepHex) {
566
+ return colorSlots.map((slot) => ` ${familyVar(family, slot)}: ${slotCss(family, steps[slot][theme], stepHex)};`);
567
+ }
568
+ /** accent 슬롯에 변수를 꽂는 선언 */
569
+ function accentDeclarations(source) {
570
+ return colorSlots.map((slot) => ` ${accentVar(slot)}: var(${source(slot)});`);
571
+ }
572
+ /**
573
+ * `[data-color="<색 이름>"]` 규칙 하나. Role은 Role Token을, 계열은 계열 변수를 꽂는다.
574
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
575
+ */
576
+ function dataColorRule(name) {
577
+ const source = isRole(name) ? (slot) => semanticVar(roleSlotToken(name, slot)) : (slot) => familyVar(name, slot);
578
+ return [
579
+ `[data-color="${name}"] {`,
580
+ ...accentDeclarations(source),
581
+ "}"
582
+ ].join("\n");
583
+ }
584
+ const roleAliases = new Map(roleNames.flatMap((role) => colorSlots.map((slot) => [roleSlotToken(role, slot), slot]).filter(([token]) => token.includes(`-${role}`)).map(([token, slot]) => [token, {
585
+ family: roleFamily[role],
586
+ slot
587
+ }])));
588
+ /**
589
+ * accent Utility class 목록. 예: `bg-accent-solid` → `--tide-accent-solid`, `text-accent` → `--tide-accent-text`,
590
+ * `border-accent-subtle` → `--tide-accent-subtle-border`
591
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
592
+ */
593
+ const accentUtilities = [
594
+ ...colorSlots.filter((slot) => slot !== "text" && slot !== "border" && slot !== "subtle-border" && slot !== "on-solid" && slot !== "on-subtle").map((slot) => ({
595
+ namespace: "background",
596
+ key: `accent-${slot}`,
597
+ slot
598
+ })),
599
+ {
600
+ namespace: "text",
601
+ key: "accent",
602
+ slot: "text"
603
+ },
604
+ {
605
+ namespace: "text",
606
+ key: "accent-on-solid",
607
+ slot: "on-solid"
608
+ },
609
+ {
610
+ namespace: "text",
611
+ key: "accent-on-subtle",
612
+ slot: "on-subtle"
613
+ },
614
+ {
615
+ namespace: "border",
616
+ key: "accent",
617
+ slot: "border"
618
+ },
619
+ {
620
+ namespace: "border",
621
+ key: "accent-subtle",
622
+ slot: "subtle-border"
623
+ }
624
+ ];
625
+
626
+ // src/contrast.ts
627
+ const surfaces = [
628
+ "bg-canvas",
629
+ "bg-surface",
630
+ "bg-raised"
631
+ ];
632
+ const roles = [
633
+ "primary",
634
+ "success",
635
+ "warning",
636
+ "danger",
637
+ "info"
638
+ ];
639
+ const allRoles = ["neutral", ...roles];
640
+ const solidStates = [
641
+ "solid",
642
+ "solid-hover",
643
+ "solid-active"
644
+ ];
645
+ const onSubtleRest = ["faint", "subtle"];
646
+ const subtleTransient = ["subtle-hover", "subtle-active"];
647
+ const neutralStates = ["bg-hover", "bg-active"];
648
+ const neutralStateSurface = "bg-canvas";
649
+ function pairs(foregrounds, backgrounds, minRatio) {
650
+ return foregrounds.flatMap((foreground) => backgrounds.map((background) => ({
651
+ foreground,
652
+ background,
653
+ minRatio
654
+ })));
655
+ }
656
+ const contrastPairs = [
657
+ ...pairs(["text-default", "text-muted"], surfaces, 4.5),
658
+ ...pairs(["text-default"], [
659
+ "faint",
660
+ "subtle",
661
+ "subtle-active"
662
+ ].map((state) => `bg-neutral-${state}`), 4.5),
663
+ ...pairs(["text-default"], ["bg-neutral-subtle-hover"], 4),
664
+ ...roles.flatMap((role) => pairs([`text-${role}`], [...surfaces, `bg-${role}-subtle`], 4.5)),
665
+ ...roles.flatMap((role) => pairs([`text-${role}-on-subtle`], onSubtleRest.map((state) => `bg-${role}-${state}`), 4.5)),
666
+ ...roles.flatMap((role) => pairs([`text-${role}-on-subtle`], subtleTransient.map((state) => `bg-${role}-${state}`), 4)),
667
+ ...roles.flatMap((role) => pairs([`text-${role}`], [`bg-${role}-faint`], 4.5)),
668
+ ...neutralStates.map((background) => ({
669
+ foreground: "text-default",
670
+ background,
671
+ minRatio: 4,
672
+ surface: neutralStateSurface
673
+ })),
674
+ ...neutralStates.map((background) => ({
675
+ foreground: "text-default",
676
+ background,
677
+ minRatio: 4,
678
+ surface: "bg-raised"
679
+ })),
680
+ ...pairs(["text-on-solid"], allRoles.flatMap((role) => solidStates.map((state) => `bg-${role}-${state}`)), 4),
681
+ ...pairs([
682
+ "border-strong",
683
+ ...roles.map((role) => `border-${role}`),
684
+ "outline-focus"
685
+ ], surfaces, 3),
686
+ ...pairs(["outline-focus"], allRoles.map((role) => `bg-${role}-subtle`), 3),
687
+ ...roles.flatMap((role) => pairs([`text-${role}`], [`bg-${role}-subtle-active`], 3))
688
+ ];
689
+ /**
690
+ * 대비 검사에서 뺀 Semantic Token과 이유.
691
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
692
+ */
693
+ const contrastExclusions = [
694
+ {
695
+ token: "border-default",
696
+ reason: "장식용 구분선이다. 경계 식별에 쓰지 않는다."
697
+ },
698
+ {
699
+ token: "border-raised",
700
+ reason: "raised 표면의 장식용 경계다(light 투명, dark gray-800). 표면 구분은 그림자와 배경 밝기가 맡고, 대비 의무가 없다."
701
+ },
702
+ {
703
+ token: "bg-disabled",
704
+ reason: "비활성 상태는 WCAG 대비 요건 밖이다. Component가 속성과 cursor로도 표현한다."
705
+ },
706
+ {
707
+ token: "text-disabled",
708
+ reason: "비활성 상태는 WCAG 대비 요건 밖이다. Component가 속성과 cursor로도 표현한다."
709
+ },
710
+ {
711
+ token: "bg-overlay",
712
+ reason: "modal 뒤를 가리는 반투명 막이다. 위에 글자를 두지 않는다."
713
+ },
714
+ ...allRoles.map((role) => ({
715
+ token: `border-${role}-subtle`,
716
+ reason: "파스텔 테두리(subtle-border)는 꾸밈이다. subtle 바탕과 on-subtle 글자만으로 알아볼 수 있어 경계 대비 의무가 없다."
717
+ }))
718
+ ];
719
+ /**
720
+ * 색 이름 하나의 대비 쌍 규칙.
721
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
722
+ */
723
+ const colorContrastRules = [
724
+ ...[...surfaces, "subtle"].map((background) => ({
725
+ foreground: "text",
726
+ background,
727
+ minRatio: 4.5
728
+ })),
729
+ {
730
+ foreground: "text",
731
+ background: "faint",
732
+ minRatio: 4.5
733
+ },
734
+ ...onSubtleRest.map((background) => ({
735
+ foreground: "on-subtle",
736
+ background,
737
+ minRatio: 4.5
738
+ })),
739
+ ...subtleTransient.map((background) => ({
740
+ foreground: "on-subtle",
741
+ background,
742
+ minRatio: 4
743
+ })),
744
+ ...solidStates.map((background) => ({
745
+ foreground: "on-solid",
746
+ background,
747
+ minRatio: 4
748
+ })),
749
+ ...surfaces.map((background) => ({
750
+ foreground: "border",
751
+ background,
752
+ minRatio: 3
753
+ })),
754
+ {
755
+ foreground: "text",
756
+ background: "subtle-active",
757
+ minRatio: 3
758
+ }
759
+ ];
760
+ /**
761
+ * 색 이름 하나의 슬롯 hex로 대비 쌍 규칙을 light·dark에서 검사한다. 표면 층은 Tide Token 값을 쓴다.
762
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
763
+ */
764
+ function checkColorContrast(slotHex) {
765
+ return ["light", "dark"].flatMap((theme) => colorContrastRules.map((rule) => {
766
+ const background = rule.background.startsWith("bg-") ? opaqueSemanticHex(rule.background, theme, rule.surface) : slotHex[theme][rule.background];
767
+ const ratio = contrastRatio(slotHex[theme][rule.foreground], background);
768
+ return {
769
+ ...rule,
770
+ theme,
771
+ ratio,
772
+ pass: ratio >= rule.minRatio
773
+ };
774
+ }));
775
+ }
776
+ /**
777
+ * Semantic Token의 불투명한 hex. 반투명 Token(8자리 hex)은 `surface` 위에 합성한다(브라우저가 그리는 값과 같다).
778
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
779
+ */
780
+ function opaqueSemanticHex(name, theme, surface) {
781
+ const hex = semanticHex(name, theme);
782
+ if (hex.length === 7) return hex;
783
+ if (!surface) throw new Error(`반투명 Token은 아래 표면이 있어야 검사할 수 있다: ${name}`);
784
+ const alpha = Number.parseInt(hex.slice(7), 16) / 255;
785
+ return mixHex(opaqueSemanticHex(surface, theme), hex.slice(0, 7), alpha);
786
+ }
787
+ /** WCAG 2.x 상대 휘도. `#rrggbb`만 받는다. */
788
+ function relativeLuminance(hex) {
789
+ const match = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex);
790
+ if (!match) throw new Error(`불투명한 6자리 hex가 아니다: ${hex}`);
791
+ const [r, g, b] = match.slice(1).map((channel) => {
792
+ const value = Number.parseInt(channel, 16) / 255;
793
+ return value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
794
+ });
795
+ return .2126 * r + .7152 * g + .0722 * b;
796
+ }
797
+ /**
798
+ * 두 색의 WCAG 2.x 대비비(1~21). 순서는 상관없다.
799
+ * 반투명 색(8자리 hex)은 받지 않는다. 대비 검사에서 overlay와 shadow는 제외한다.
800
+ * @internal `@tide-design/foundation/internal` 전용. 앱 개발자용 공개 계약이 아니다(문서 앱·빌드 스크립트·테스트용).
801
+ */
802
+ function contrastRatio(foreground, background) {
803
+ const a = relativeLuminance(foreground);
804
+ const b = relativeLuminance(background);
805
+ return (Math.max(a, b) + .05) / (Math.min(a, b) + .05);
806
+ }
807
+
808
+ // src/color-family.ts
809
+ /**
810
+ * `@tide-design/foundation/color-family`: 앱이 자기 브랜드 색 계열을 더하는 API.
811
+ *
812
+ * 앱은 `defineColorFamily`로 11단계 스케일을 정의하고, `tide-color build <파일>`로 CSS를 만든다.
813
+ * CSS는 Tide 계열과 같은 매핑 규칙으로 light·dark 계열 변수와 `[data-color="<이름>"]` 규칙을 담는다.
814
+ * @packageDocumentation
815
+ */
816
+ const steps = Object.keys(color.blue).map(Number);
817
+ const reservedNames = /* @__PURE__ */ new Set([
818
+ ...tideColorNames,
819
+ "accent",
820
+ "white",
821
+ "black",
822
+ "color",
823
+ "bg",
824
+ "text",
825
+ "border",
826
+ "outline",
827
+ "font",
828
+ "rounded",
829
+ "shadow",
830
+ "duration",
831
+ "ease",
832
+ "z",
833
+ "focus"
834
+ ]);
835
+ function isSlotStep(value) {
836
+ return value === "white" || value === "black" || steps.includes(value);
837
+ }
838
+ /** 덮기·섞기가 참조할 수 있는 색: 그 계열 단계, 또는 Tide Primitive 이름 */
839
+ function isColorRef(value) {
840
+ return steps.includes(value) || Object.hasOwn(primitiveNames, value);
841
+ }
842
+ const primitiveNames = Object.fromEntries(Object.entries(color).flatMap(([name, scale]) => typeof scale === "string" ? [[name, true]] : Object.keys(scale).map((step) => [`${name}-${step}`, true])));
843
+ /** 슬롯 값: 단계, 덮기(`{ step, overlay, amount }`), 섞기(`{ mix: [a, b] }`) */
844
+ function isSlotValue(value) {
845
+ if (isSlotStep(value)) return true;
846
+ if (typeof value !== "object" || value === null) return false;
847
+ const record = value;
848
+ if ("mix" in record) return Object.keys(record).length === 1 && Array.isArray(record.mix) && record.mix.length === 2 && record.mix.every(isColorRef);
849
+ 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;
850
+ }
851
+ /**
852
+ * 앱 브랜드 색 계열을 정의한다. 이름, 스케일, 덮어쓸 값이 올바른지 확인하고 그대로 돌려준다.
853
+ *
854
+ * ```ts
855
+ * // brand.ts
856
+ * import { defineColorFamily } from "@tide-design/foundation/color-family";
857
+ *
858
+ * export default defineColorFamily({
859
+ * name: "brand",
860
+ * scale: { 50: "#fcf0f5", 100: "#fee5f0", ... 950: "#5c1d3f" },
861
+ * });
862
+ * ```
863
+ *
864
+ * @throws 이름이 Tide 색 이름과 겹치거나, 스케일 단계가 빠졌거나, hex가 `#rrggbb`가 아니면
865
+ */
866
+ function defineColorFamily(input) {
867
+ const { name, scale, overrides = {} } = input;
868
+ if (!/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/.test(name)) throw new Error(`색 이름은 소문자로 시작하는 kebab-case여야 한다: "${name}"`);
869
+ if (reservedNames.has(name)) throw new Error(`"${name}"은 Tide가 쓰는 이름이라 앱 색 계열 이름으로 쓸 수 없다.`);
870
+ for (const step of steps) {
871
+ const hex = scale[step];
872
+ if (typeof hex !== "string" || !/^#[0-9a-f]{6}$/i.test(hex)) throw new Error(`${name}-${step}: #rrggbb hex가 아니다(${String(hex)})`);
873
+ }
874
+ const extraSteps = Object.keys(scale).filter((step) => !steps.includes(Number(step)));
875
+ if (extraSteps.length > 0) throw new Error(`${name}: 스케일에 없는 단계가 있다(${extraSteps.join(", ")})`);
876
+ for (const [slot, rule] of Object.entries(overrides)) {
877
+ if (!colorSlots.includes(slot)) throw new Error(`${name}: 없는 슬롯을 덮어썼다(${slot})`);
878
+ 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), 덮기, 섞기가 아니다`);
879
+ }
880
+ return {
881
+ name,
882
+ scale: Object.fromEntries(steps.map((step) => [step, scale[step].toLowerCase()])),
883
+ overrides
884
+ };
885
+ }
886
+ /** 앱 계열의 슬롯별 단계(규칙 + 덮어쓸 값) */
887
+ function slotSteps(family) {
888
+ return resolveSlotSteps(family.overrides);
889
+ }
890
+ /** 앱 계열의 Theme별 슬롯 hex */
891
+ function colorFamilySlotHex(family) {
892
+ const resolved = slotSteps(family);
893
+ const hex = (value) => slotValueHex(value, (step) => family.scale[step]);
894
+ return {
895
+ light: Object.fromEntries(colorSlots.map((slot) => [slot, hex(resolved[slot].light)])),
896
+ dark: Object.fromEntries(colorSlots.map((slot) => [slot, hex(resolved[slot].dark)]))
897
+ };
898
+ }
899
+ /** 앱 계열을 Tide와 같은 대비 쌍 규칙으로 light·dark에서 검사한다. 미달이면 `pass`가 false다. */
900
+ function checkColorFamily(family) {
901
+ return checkColorContrast(colorFamilySlotHex(family));
902
+ }
903
+ /**
904
+ * 앱 계열의 CSS. Primitive 변수, light·dark 계열 변수, `[data-color]` 규칙을 담는다.
905
+ * Tide CSS(`@tide-design/components/styles.css` 또는 foundation CSS) 다음에 불러온다.
906
+ */
907
+ function colorFamilyCss(families) {
908
+ const themeBlock = (theme) => families.flatMap((family) => familyThemeDeclarations(family.name, slotSteps(family), theme, (step) => family.scale[step]));
909
+ return [
910
+ ":root {",
911
+ ...families.flatMap((family) => steps.map((step) => ` ${primitiveVar(slotPrimitive(family.name, step))}: ${family.scale[step]};`)),
912
+ "}",
913
+ "",
914
+ ":root,\n[data-theme=\"light\"] {",
915
+ ...themeBlock("light"),
916
+ "}",
917
+ "",
918
+ "[data-theme=\"dark\"] {",
919
+ ...themeBlock("dark"),
920
+ "}",
921
+ "",
922
+ ...families.flatMap((family) => [dataColorRule(family.name), ""])
923
+ ].join("\n");
924
+ }
925
+
926
+ // src/cli.ts
927
+ const usage = "사용법: tide-color build <색 계열 파일(.ts, .js)> > <출력 CSS>";
928
+ async function loadFamilies(file) {
929
+ const exported = (await import(pathToFileURL(resolve(file)).href)).default;
930
+ if (exported === void 0) throw new Error(`${file}에 default export가 없다. defineColorFamily 결과를 default로 내보낸다.`);
931
+ const families = (Array.isArray(exported) ? exported : [exported]).map((family) => defineColorFamily(family));
932
+ const names = families.map((family) => family.name);
933
+ const duplicated = names.filter((name, index) => names.indexOf(name) !== index);
934
+ if (duplicated.length > 0) throw new Error(`같은 색 이름이 두 번 나온다: ${duplicated.join(", ")}`);
935
+ return families;
936
+ }
937
+ async function build(file) {
938
+ const families = await loadFamilies(file);
939
+ let failed = 0;
940
+ for (const family of families) {
941
+ const results = checkColorFamily(family);
942
+ const failures = results.filter((result) => !result.pass);
943
+ failed += failures.length;
944
+ for (const failure of failures) process.stderr.write(`대비 미달 ${family.name} ${failure.theme}: ${failure.foreground} / ${failure.background} ${failure.ratio.toFixed(2)}:1 < ${failure.minRatio}:1\n`);
945
+ process.stderr.write(`${family.name}: 대비 쌍 ${results.length}개 중 ${results.length - failures.length}개 통과\n`);
946
+ }
947
+ if (failed > 0) {
948
+ process.stderr.write("대비 기준에 못 미쳐 CSS를 만들지 않았다. 스케일을 고치거나 overrides로 슬롯 단계를 바꾼다.\n");
949
+ return 1;
950
+ }
951
+ const header = `/* tide-color가 ${file}에서 만들었다. 직접 고치지 않는다. Tide CSS 다음에 불러온다. */\n`;
952
+ process.stdout.write(header + colorFamilyCss(families));
953
+ return 0;
954
+ }
955
+ async function main(args) {
956
+ const [command, file, ...rest] = args;
957
+ if (command !== "build" || !file || rest.length > 0) {
958
+ process.stderr.write(`${usage}\n`);
959
+ return 2;
960
+ }
961
+ try {
962
+ return await build(file);
963
+ } catch (error) {
964
+ process.stderr.write(`tide-color: ${error instanceof Error ? error.message : String(error)}\n`);
965
+ return 1;
966
+ }
967
+ }
968
+ process.exitCode = await main(process.argv.slice(2));
969
+
970
+ export { };