@clhaas/palette-kit 0.1.0 → 0.1.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/dist/alpha/generateAlphaScale.d.ts +5 -0
- package/dist/alpha/generateAlphaScale.js +34 -0
- package/dist/contrast/apca.d.ts +2 -0
- package/dist/contrast/apca.js +5 -0
- package/dist/contrast/onSolid.d.ts +6 -0
- package/dist/contrast/onSolid.js +28 -0
- package/dist/contrast/solveText.d.ts +2 -0
- package/dist/contrast/solveText.js +31 -0
- package/dist/createTheme.d.ts +32 -0
- package/dist/createTheme.js +75 -0
- package/dist/data/radixSeeds.d.ts +3 -0
- package/dist/data/radixSeeds.js +34 -0
- package/dist/diagnostics/analyzeScale.d.ts +2 -0
- package/dist/diagnostics/analyzeScale.js +4 -0
- package/dist/diagnostics/analyzeTheme.d.ts +2 -0
- package/dist/diagnostics/analyzeTheme.js +35 -0
- package/dist/diagnostics/warnings.d.ts +2 -0
- package/dist/diagnostics/warnings.js +20 -0
- package/dist/engine/curves.d.ts +9 -0
- package/dist/engine/curves.js +48 -0
- package/dist/engine/oklch.d.ts +8 -0
- package/dist/engine/oklch.js +40 -0
- package/dist/engine/templates.d.ts +14 -0
- package/dist/engine/templates.js +45 -0
- package/dist/exporters/selectColorMode.d.ts +2 -0
- package/dist/exporters/selectColorMode.js +19 -0
- package/dist/exporters/toCssVars.d.ts +12 -0
- package/dist/exporters/toCssVars.js +84 -0
- package/dist/exporters/toJson.d.ts +3 -0
- package/dist/exporters/toJson.js +25 -0
- package/dist/exporters/toReactNative.d.ts +30 -0
- package/dist/exporters/toReactNative.js +26 -0
- package/dist/exporters/toTailwind.d.ts +16 -0
- package/dist/exporters/toTailwind.js +90 -0
- package/dist/exporters/toTs.d.ts +3 -0
- package/dist/exporters/toTs.js +28 -0
- package/dist/generateScale.d.ts +15 -0
- package/dist/generateScale.js +96 -0
- package/{src/index.ts → dist/index.d.ts} +1 -15
- package/dist/index.js +15 -0
- package/dist/tokens/presetRadixLikeUi.d.ts +5 -0
- package/dist/tokens/presetRadixLikeUi.js +55 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.js +1 -0
- package/package.json +18 -2
- package/.markdownlint.json +0 -4
- package/biome.json +0 -43
- package/src/alpha/generateAlphaScale.ts +0 -43
- package/src/contrast/apca.ts +0 -7
- package/src/contrast/onSolid.ts +0 -38
- package/src/contrast/solveText.ts +0 -49
- package/src/createTheme.ts +0 -130
- package/src/data/radixSeeds.ts +0 -37
- package/src/diagnostics/analyzeScale.ts +0 -6
- package/src/diagnostics/analyzeTheme.ts +0 -54
- package/src/diagnostics/warnings.ts +0 -25
- package/src/engine/curves.ts +0 -64
- package/src/engine/oklch.ts +0 -53
- package/src/engine/templates.ts +0 -58
- package/src/exporters/selectColorMode.ts +0 -25
- package/src/exporters/toCssVars.ts +0 -116
- package/src/exporters/toJson.ts +0 -31
- package/src/exporters/toReactNative.ts +0 -39
- package/src/exporters/toTailwind.ts +0 -110
- package/src/exporters/toTs.ts +0 -34
- package/src/generateScale.ts +0 -163
- package/src/tokens/presetRadixLikeUi.ts +0 -75
- package/src/types.ts +0 -63
- package/tsconfig.json +0 -14
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Theme } from "../types.js";
|
|
2
|
-
|
|
3
|
-
type ReactNativeOptions = {
|
|
4
|
-
includeTokens?: boolean;
|
|
5
|
-
includeScales?: boolean;
|
|
6
|
-
includeAlpha?: boolean;
|
|
7
|
-
includeP3?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function toReactNative(theme: Theme, options?: ReactNativeOptions) {
|
|
11
|
-
const includeTokens = options?.includeTokens ?? true;
|
|
12
|
-
const includeScales = options?.includeScales ?? true;
|
|
13
|
-
const includeAlpha = options?.includeAlpha ?? true;
|
|
14
|
-
const includeP3 = options?.includeP3 ?? false;
|
|
15
|
-
|
|
16
|
-
function buildMode(mode: "light" | "dark") {
|
|
17
|
-
const scales = includeScales
|
|
18
|
-
? Object.fromEntries(Object.entries(theme.scales).map(([slot, scale]) => [slot, scale[mode]]))
|
|
19
|
-
: {};
|
|
20
|
-
const p3 = includeP3
|
|
21
|
-
? Object.fromEntries(
|
|
22
|
-
Object.entries(theme.scales)
|
|
23
|
-
.filter(([, scale]) => scale.p3?.[mode])
|
|
24
|
-
.map(([slot, scale]) => [slot, scale.p3?.[mode]]),
|
|
25
|
-
)
|
|
26
|
-
: undefined;
|
|
27
|
-
return {
|
|
28
|
-
tokens: includeTokens ? theme.tokens[mode] : {},
|
|
29
|
-
scales,
|
|
30
|
-
alpha: includeAlpha ? theme.alpha?.[mode] : undefined,
|
|
31
|
-
p3,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
light: buildMode("light"),
|
|
37
|
-
dark: buildMode("dark"),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { Theme } from "../types.js";
|
|
2
|
-
|
|
3
|
-
type TailwindOptions = {
|
|
4
|
-
mode?: "light" | "dark" | "both";
|
|
5
|
-
includeTokens?: boolean;
|
|
6
|
-
includeScales?: boolean;
|
|
7
|
-
includeAlpha?: boolean;
|
|
8
|
-
includeP3?: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
function setNested(target: Record<string, unknown>, path: string[], value: unknown) {
|
|
12
|
-
let cursor = target;
|
|
13
|
-
for (let i = 0; i < path.length - 1; i += 1) {
|
|
14
|
-
const key = path[i];
|
|
15
|
-
if (!cursor[key] || typeof cursor[key] !== "object") {
|
|
16
|
-
cursor[key] = {};
|
|
17
|
-
}
|
|
18
|
-
cursor = cursor[key] as Record<string, unknown>;
|
|
19
|
-
}
|
|
20
|
-
cursor[path[path.length - 1]] = value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function tokensToNested(tokens: Record<string, string>): Record<string, unknown> {
|
|
24
|
-
const output: Record<string, unknown> = {};
|
|
25
|
-
for (const [token, value] of Object.entries(tokens)) {
|
|
26
|
-
setNested(output, token.split("."), value);
|
|
27
|
-
}
|
|
28
|
-
return output;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function scalesToNested(scales: Theme["scales"], mode: "light" | "dark", useP3?: boolean) {
|
|
32
|
-
const output: Record<string, unknown> = {};
|
|
33
|
-
for (const [slot, scale] of Object.entries(scales)) {
|
|
34
|
-
const source = useP3 ? scale.p3?.[mode] : scale[mode];
|
|
35
|
-
if (!source) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const stepMap: Record<string, string> = {};
|
|
39
|
-
for (const [step, value] of Object.entries(source)) {
|
|
40
|
-
stepMap[String(step)] = value;
|
|
41
|
-
}
|
|
42
|
-
output[slot] = stepMap;
|
|
43
|
-
}
|
|
44
|
-
return output;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function alphaToNested(alpha: Theme["alpha"], mode: "light" | "dark") {
|
|
48
|
-
if (!alpha) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
const output: Record<string, string> = {};
|
|
52
|
-
for (const [step, value] of Object.entries(alpha[mode])) {
|
|
53
|
-
output[String(step)] = value;
|
|
54
|
-
}
|
|
55
|
-
return output;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function toTailwind(theme: Theme, options?: TailwindOptions) {
|
|
59
|
-
const mode = options?.mode ?? "both";
|
|
60
|
-
const includeTokens = options?.includeTokens ?? true;
|
|
61
|
-
const includeScales = options?.includeScales ?? false;
|
|
62
|
-
const includeAlpha = options?.includeAlpha ?? false;
|
|
63
|
-
const includeP3 = options?.includeP3 ?? false;
|
|
64
|
-
|
|
65
|
-
function buildModeTokens(modeKey: "light" | "dark", useP3?: boolean) {
|
|
66
|
-
const colors: Record<string, unknown> = {};
|
|
67
|
-
|
|
68
|
-
if (includeTokens) {
|
|
69
|
-
colors.tokens = tokensToNested(theme.tokens[modeKey]);
|
|
70
|
-
}
|
|
71
|
-
if (includeScales) {
|
|
72
|
-
colors.scale = scalesToNested(theme.scales, modeKey, useP3);
|
|
73
|
-
}
|
|
74
|
-
if (includeAlpha && theme.alpha) {
|
|
75
|
-
colors.alpha = alphaToNested(theme.alpha, modeKey);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return colors;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const colors: Record<string, unknown> = {};
|
|
82
|
-
if (mode === "light" || mode === "both") {
|
|
83
|
-
colors.light = buildModeTokens("light");
|
|
84
|
-
}
|
|
85
|
-
if (mode === "dark" || mode === "both") {
|
|
86
|
-
colors.dark = buildModeTokens("dark");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (includeP3) {
|
|
90
|
-
const hasP3 = Object.values(theme.scales).some((scale) => scale.p3);
|
|
91
|
-
if (hasP3) {
|
|
92
|
-
const p3: Record<string, unknown> = {};
|
|
93
|
-
if (mode === "light" || mode === "both") {
|
|
94
|
-
p3.light = buildModeTokens("light", true);
|
|
95
|
-
}
|
|
96
|
-
if (mode === "dark" || mode === "both") {
|
|
97
|
-
p3.dark = buildModeTokens("dark", true);
|
|
98
|
-
}
|
|
99
|
-
colors.p3 = p3;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
theme: {
|
|
105
|
-
extend: {
|
|
106
|
-
colors,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
package/src/exporters/toTs.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Theme, ThemeColorMode } from "../types.js";
|
|
2
|
-
|
|
3
|
-
export function toTs(theme: Theme): string {
|
|
4
|
-
const serialized = JSON.stringify(theme, null, 2);
|
|
5
|
-
return `export const theme = ${serialized} as const;\n`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function toTsWithMode(theme: Theme, mode: "srgb" | "p3"): string {
|
|
9
|
-
if (mode === "p3") {
|
|
10
|
-
const serialized = JSON.stringify(toP3Theme(theme), null, 2);
|
|
11
|
-
return `export const theme = ${serialized} as const;\n`;
|
|
12
|
-
}
|
|
13
|
-
const serialized = JSON.stringify(theme, null, 2);
|
|
14
|
-
return `export const theme = ${serialized} as const;\n`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function toP3Theme(theme: Theme): ThemeColorMode {
|
|
18
|
-
const scales = Object.fromEntries(
|
|
19
|
-
Object.entries(theme.scales).map(([slot, scale]) => {
|
|
20
|
-
if (!scale.p3) {
|
|
21
|
-
return [slot, scale];
|
|
22
|
-
}
|
|
23
|
-
return [
|
|
24
|
-
slot,
|
|
25
|
-
{
|
|
26
|
-
...scale,
|
|
27
|
-
light: scale.p3.light,
|
|
28
|
-
dark: scale.p3.dark,
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
}),
|
|
32
|
-
);
|
|
33
|
-
return { ...theme, scales };
|
|
34
|
-
}
|
package/src/generateScale.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { radixSeeds } from "./data/radixSeeds.js";
|
|
2
|
-
import { type CurveConfig, resolveCurves } from "./engine/curves.js";
|
|
3
|
-
import {
|
|
4
|
-
compressToP3,
|
|
5
|
-
compressToSrgb,
|
|
6
|
-
hexToOklch,
|
|
7
|
-
inP3Gamut,
|
|
8
|
-
inSrgbGamut,
|
|
9
|
-
oklchToHex,
|
|
10
|
-
oklchToP3,
|
|
11
|
-
} from "./engine/oklch.js";
|
|
12
|
-
import { selectTemplateId, templates } from "./engine/templates.js";
|
|
13
|
-
import type { ColorHex, ColorP3, ColorSource, Scale, Step, TemplateId } from "./types.js";
|
|
14
|
-
|
|
15
|
-
const steps: Step[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
16
|
-
|
|
17
|
-
type GenerateScaleOptions = {
|
|
18
|
-
source: ColorSource;
|
|
19
|
-
mode?: "light" | "dark" | "both";
|
|
20
|
-
anchorStep?: Step;
|
|
21
|
-
template?: "auto" | TemplateId;
|
|
22
|
-
curves?: CurveConfig;
|
|
23
|
-
gamut?: { strategy: "compress" | "clip" };
|
|
24
|
-
p3?: boolean;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
function getSeedHex(source: ColorSource): ColorHex {
|
|
28
|
-
if (source.source === "seed") {
|
|
29
|
-
return source.value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const seed = radixSeeds[source.name];
|
|
33
|
-
if (!seed) {
|
|
34
|
-
throw new Error(`Unknown Radix seed: ${source.name}`);
|
|
35
|
-
}
|
|
36
|
-
return seed;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function normalizeHue(hue: number): number {
|
|
40
|
-
const normalized = ((hue % 360) + 360) % 360;
|
|
41
|
-
return normalized;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function buildScaleForMode(
|
|
45
|
-
seedHex: ColorHex,
|
|
46
|
-
templateId: TemplateId,
|
|
47
|
-
anchorStep: Step,
|
|
48
|
-
curves?: CurveConfig,
|
|
49
|
-
gamutStrategy: "compress" | "clip" = "compress",
|
|
50
|
-
mode: "light" | "dark" = "light",
|
|
51
|
-
includeP3 = false,
|
|
52
|
-
): {
|
|
53
|
-
scale: Record<Step, ColorHex>;
|
|
54
|
-
p3?: Record<Step, ColorP3>;
|
|
55
|
-
outOfGamutCount: number;
|
|
56
|
-
outOfP3GamutCount: number;
|
|
57
|
-
} {
|
|
58
|
-
const seedOklch = hexToOklch(seedHex);
|
|
59
|
-
const template = templates[mode][templateId];
|
|
60
|
-
const anchor = template[anchorStep];
|
|
61
|
-
const dL = seedOklch.l - anchor.l;
|
|
62
|
-
const dC = seedOklch.c - anchor.c;
|
|
63
|
-
const dH = seedOklch.h - anchor.h;
|
|
64
|
-
const curveSet = resolveCurves(curves);
|
|
65
|
-
|
|
66
|
-
const output = {} as Record<Step, ColorHex>;
|
|
67
|
-
const p3Output = includeP3 ? ({} as Record<Step, ColorP3>) : undefined;
|
|
68
|
-
let outOfGamutCount = 0;
|
|
69
|
-
let outOfP3GamutCount = 0;
|
|
70
|
-
|
|
71
|
-
for (const step of steps) {
|
|
72
|
-
const base = template[step];
|
|
73
|
-
const l = base.l + dL * curveSet.lightness[step];
|
|
74
|
-
const c = Math.max(0, base.c + dC * curveSet.chroma[step]);
|
|
75
|
-
const h = normalizeHue(base.h + dH);
|
|
76
|
-
const candidate = { l, c, h };
|
|
77
|
-
let current = candidate;
|
|
78
|
-
|
|
79
|
-
if (!inSrgbGamut(current)) {
|
|
80
|
-
outOfGamutCount += 1;
|
|
81
|
-
if (gamutStrategy === "compress") {
|
|
82
|
-
current = compressToSrgb(current);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
output[step] = oklchToHex(current);
|
|
87
|
-
|
|
88
|
-
if (p3Output) {
|
|
89
|
-
let p3Current = candidate;
|
|
90
|
-
if (!inP3Gamut(p3Current)) {
|
|
91
|
-
outOfP3GamutCount += 1;
|
|
92
|
-
p3Current = compressToP3(p3Current);
|
|
93
|
-
}
|
|
94
|
-
p3Output[step] = oklchToP3(p3Current);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
scale: output,
|
|
100
|
-
p3: p3Output,
|
|
101
|
-
outOfGamutCount,
|
|
102
|
-
outOfP3GamutCount,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function generateScale(options: GenerateScaleOptions): Scale {
|
|
107
|
-
const seedHex = getSeedHex(options.source);
|
|
108
|
-
const anchorStep = options.anchorStep ?? 9;
|
|
109
|
-
const mode = options.mode ?? "both";
|
|
110
|
-
const templateId =
|
|
111
|
-
options.template === "auto" || !options.template
|
|
112
|
-
? selectTemplateId(hexToOklch(seedHex))
|
|
113
|
-
: options.template;
|
|
114
|
-
const gamutStrategy = options.gamut?.strategy ?? "compress";
|
|
115
|
-
|
|
116
|
-
const lightResult = buildScaleForMode(
|
|
117
|
-
seedHex,
|
|
118
|
-
templateId,
|
|
119
|
-
anchorStep,
|
|
120
|
-
options.curves,
|
|
121
|
-
gamutStrategy,
|
|
122
|
-
"light",
|
|
123
|
-
options.p3 ?? false,
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const darkResult = buildScaleForMode(
|
|
127
|
-
seedHex,
|
|
128
|
-
templateId,
|
|
129
|
-
anchorStep,
|
|
130
|
-
options.curves,
|
|
131
|
-
gamutStrategy,
|
|
132
|
-
"dark",
|
|
133
|
-
options.p3 ?? false,
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const scale: Scale = {
|
|
137
|
-
light: lightResult.scale,
|
|
138
|
-
dark: darkResult.scale,
|
|
139
|
-
p3:
|
|
140
|
-
lightResult.p3 && darkResult.p3 ? { light: lightResult.p3, dark: darkResult.p3 } : undefined,
|
|
141
|
-
meta: {
|
|
142
|
-
outOfGamutCount: lightResult.outOfGamutCount + darkResult.outOfGamutCount,
|
|
143
|
-
outOfP3GamutCount: lightResult.outOfP3GamutCount + darkResult.outOfP3GamutCount,
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
if (mode === "light") {
|
|
148
|
-
return {
|
|
149
|
-
...scale,
|
|
150
|
-
dark: scale.light,
|
|
151
|
-
p3: scale.p3 ? { light: scale.p3.light, dark: scale.p3.light } : undefined,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
if (mode === "dark") {
|
|
155
|
-
return {
|
|
156
|
-
...scale,
|
|
157
|
-
light: scale.dark,
|
|
158
|
-
p3: scale.p3 ? { light: scale.p3.dark, dark: scale.p3.dark } : undefined,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return scale;
|
|
163
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { ColorHex, Scale, Step } from "../types.js";
|
|
2
|
-
|
|
3
|
-
type TokenMapEntry = {
|
|
4
|
-
token: string;
|
|
5
|
-
slot: string;
|
|
6
|
-
step: Step;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const tokenMap: TokenMapEntry[] = [
|
|
11
|
-
{ token: "bg.app", slot: "neutral", step: 1 },
|
|
12
|
-
{ token: "bg.subtle", slot: "neutral", step: 2 },
|
|
13
|
-
{ token: "surface.card", slot: "neutral", step: 2 },
|
|
14
|
-
{ token: "surface.raised", slot: "neutral", step: 3 },
|
|
15
|
-
{ token: "component.bg", slot: "neutral", step: 3 },
|
|
16
|
-
{ token: "component.bgHover", slot: "neutral", step: 4 },
|
|
17
|
-
{ token: "component.bgActive", slot: "neutral", step: 5 },
|
|
18
|
-
{ token: "border.subtle", slot: "neutral", step: 6 },
|
|
19
|
-
{ token: "border.default", slot: "neutral", step: 7 },
|
|
20
|
-
{ token: "border.strong", slot: "neutral", step: 8 },
|
|
21
|
-
{ token: "text.secondary", slot: "neutral", step: 11 },
|
|
22
|
-
{ token: "text.primary", slot: "neutral", step: 12 },
|
|
23
|
-
{ token: "text.disabled", slot: "neutral", step: 10 },
|
|
24
|
-
|
|
25
|
-
{ token: "focus.ring", slot: "accent", step: 8 },
|
|
26
|
-
{ token: "accent.solid", slot: "accent", step: 9 },
|
|
27
|
-
{ token: "accent.solidHover", slot: "accent", step: 10 },
|
|
28
|
-
{ token: "accent.border", slot: "accent", step: 7 },
|
|
29
|
-
{ token: "accent.subtle", slot: "accent", step: 3 },
|
|
30
|
-
{ token: "accent.subtleHover", slot: "accent", step: 4 },
|
|
31
|
-
|
|
32
|
-
{ token: "status.success.solidBg", slot: "success", step: 9, required: false },
|
|
33
|
-
{ token: "status.success.solidHover", slot: "success", step: 10, required: false },
|
|
34
|
-
{ token: "status.success.subtleBg", slot: "success", step: 3, required: false },
|
|
35
|
-
{ token: "status.success.border", slot: "success", step: 7, required: false },
|
|
36
|
-
{ token: "status.success.text", slot: "success", step: 11, required: false },
|
|
37
|
-
{ token: "status.success.textStrong", slot: "success", step: 12, required: false },
|
|
38
|
-
|
|
39
|
-
{ token: "status.warning.solidBg", slot: "warning", step: 9, required: false },
|
|
40
|
-
{ token: "status.warning.solidHover", slot: "warning", step: 10, required: false },
|
|
41
|
-
{ token: "status.warning.subtleBg", slot: "warning", step: 3, required: false },
|
|
42
|
-
{ token: "status.warning.border", slot: "warning", step: 7, required: false },
|
|
43
|
-
{ token: "status.warning.text", slot: "warning", step: 11, required: false },
|
|
44
|
-
{ token: "status.warning.textStrong", slot: "warning", step: 12, required: false },
|
|
45
|
-
|
|
46
|
-
{ token: "status.danger.solidBg", slot: "danger", step: 9, required: false },
|
|
47
|
-
{ token: "status.danger.solidHover", slot: "danger", step: 10, required: false },
|
|
48
|
-
{ token: "status.danger.subtleBg", slot: "danger", step: 3, required: false },
|
|
49
|
-
{ token: "status.danger.border", slot: "danger", step: 7, required: false },
|
|
50
|
-
{ token: "status.danger.text", slot: "danger", step: 11, required: false },
|
|
51
|
-
{ token: "status.danger.textStrong", slot: "danger", step: 12, required: false },
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
export function buildPresetTokens(scales: Record<string, Scale>): {
|
|
55
|
-
light: Record<string, ColorHex>;
|
|
56
|
-
dark: Record<string, ColorHex>;
|
|
57
|
-
} {
|
|
58
|
-
const light: Record<string, ColorHex> = {};
|
|
59
|
-
const dark: Record<string, ColorHex> = {};
|
|
60
|
-
|
|
61
|
-
for (const { token, slot, step, required } of tokenMap) {
|
|
62
|
-
const scale = scales[slot];
|
|
63
|
-
if (!scale) {
|
|
64
|
-
if (required === false) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
throw new Error(`Missing scale for slot: ${slot}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
light[token] = scale.light[step];
|
|
71
|
-
dark[token] = scale.dark[step];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return { light, dark };
|
|
75
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export type Step = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
2
|
-
|
|
3
|
-
export type ColorHex = `#${string}`;
|
|
4
|
-
export type ColorP3 = string;
|
|
5
|
-
|
|
6
|
-
export type RadixSeedName = string;
|
|
7
|
-
|
|
8
|
-
export type TemplateId = "neutral" | "warm" | "cool";
|
|
9
|
-
|
|
10
|
-
export type ColorSource =
|
|
11
|
-
| { source: "seed"; value: ColorHex }
|
|
12
|
-
| { source: "radix"; name: RadixSeedName };
|
|
13
|
-
|
|
14
|
-
export type ScaleDiagnostics = {
|
|
15
|
-
outOfGamutCount: number;
|
|
16
|
-
outOfP3GamutCount?: number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type Scale = {
|
|
20
|
-
light: Record<Step, ColorHex>;
|
|
21
|
-
dark: Record<Step, ColorHex>;
|
|
22
|
-
p3?: {
|
|
23
|
-
light: Record<Step, ColorP3>;
|
|
24
|
-
dark: Record<Step, ColorP3>;
|
|
25
|
-
};
|
|
26
|
-
meta?: ScaleDiagnostics;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type ScaleColorMode = Omit<Scale, "light" | "dark"> & {
|
|
30
|
-
light: Record<Step, string>;
|
|
31
|
-
dark: Record<Step, string>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type AlphaScale = {
|
|
35
|
-
light: Record<Step, ColorHex>;
|
|
36
|
-
dark: Record<Step, ColorHex>;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type ThemeDiagnostics = {
|
|
40
|
-
contrast: Record<string, number>;
|
|
41
|
-
outOfGamutCount: number;
|
|
42
|
-
warnings?: string[];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type Theme = {
|
|
46
|
-
scales: Record<string, Scale>;
|
|
47
|
-
tokens: {
|
|
48
|
-
light: Record<string, ColorHex>;
|
|
49
|
-
dark: Record<string, ColorHex>;
|
|
50
|
-
};
|
|
51
|
-
alpha?: AlphaScale;
|
|
52
|
-
diagnostics?: ThemeDiagnostics;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type ThemeColorMode = Omit<Theme, "scales"> & {
|
|
56
|
-
scales: Record<string, ScaleColorMode>;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type OklchColor = {
|
|
60
|
-
l: number;
|
|
61
|
-
c: number;
|
|
62
|
-
h: number;
|
|
63
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "NodeNext",
|
|
5
|
-
"moduleResolution": "NodeNext",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"noEmit": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/**/*.ts"],
|
|
13
|
-
"exclude": ["examples/**", "tests/**", "node_modules/**"]
|
|
14
|
-
}
|