@arun-dev/tokens 0.35.0 → 0.36.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/createBrand.cjs +328 -244
- package/dist/createBrand.d.cts +43 -43
- package/dist/createBrand.d.ts +43 -43
- package/dist/createBrand.js +323 -215
- package/package.json +7 -6
- package/src/components/calendar.css +20 -0
- package/src/createBrand.ts +4 -0
package/dist/createBrand.cjs
CHANGED
|
@@ -1,273 +1,359 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/createBrand.ts
|
|
21
|
-
var createBrand_exports = {};
|
|
22
|
-
__export(createBrand_exports, {
|
|
23
|
-
CONTRAST_REQUIREMENTS: () => CONTRAST_REQUIREMENTS,
|
|
24
|
-
DEFAULT_NEUTRAL: () => DEFAULT_NEUTRAL,
|
|
25
|
-
contrastRatio: () => contrastRatio,
|
|
26
|
-
createBrand: () => createBrand,
|
|
27
|
-
generatePaletteFromSeed: () => generatePaletteFromSeed
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(createBrand_exports);
|
|
30
|
-
var DEFAULT_NEUTRAL = {
|
|
31
|
-
0: "#ffffff",
|
|
32
|
-
50: "#f8fafc",
|
|
33
|
-
100: "#f1f5f9",
|
|
34
|
-
200: "#e2e8f0",
|
|
35
|
-
300: "#cbd5e1",
|
|
36
|
-
400: "#96a5ba",
|
|
37
|
-
500: "#64748b",
|
|
38
|
-
600: "#475569",
|
|
39
|
-
700: "#334155",
|
|
40
|
-
800: "#1e293b",
|
|
41
|
-
900: "#0f172a",
|
|
42
|
-
950: "#020617"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/createBrand.ts
|
|
3
|
+
const DEFAULT_NEUTRAL = {
|
|
4
|
+
0: "#ffffff",
|
|
5
|
+
50: "#f8fafc",
|
|
6
|
+
100: "#f1f5f9",
|
|
7
|
+
200: "#e2e8f0",
|
|
8
|
+
300: "#cbd5e1",
|
|
9
|
+
400: "#96a5ba",
|
|
10
|
+
500: "#64748b",
|
|
11
|
+
600: "#475569",
|
|
12
|
+
700: "#334155",
|
|
13
|
+
800: "#1e293b",
|
|
14
|
+
900: "#0f172a",
|
|
15
|
+
950: "#020617"
|
|
43
16
|
};
|
|
44
17
|
function hexToRgb(hex) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
const h = hex.replace("#", "");
|
|
19
|
+
return [
|
|
20
|
+
parseInt(h.slice(0, 2), 16) / 255,
|
|
21
|
+
parseInt(h.slice(2, 4), 16) / 255,
|
|
22
|
+
parseInt(h.slice(4, 6), 16) / 255
|
|
23
|
+
];
|
|
51
24
|
}
|
|
52
25
|
function rgbToHsl(r, g, b) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
26
|
+
const max = Math.max(r, g, b);
|
|
27
|
+
const min = Math.min(r, g, b);
|
|
28
|
+
const l = (max + min) / 2;
|
|
29
|
+
if (max === min) return [
|
|
30
|
+
0,
|
|
31
|
+
0,
|
|
32
|
+
l * 100
|
|
33
|
+
];
|
|
34
|
+
const d = max - min;
|
|
35
|
+
const s = l > .5 ? d / (2 - max - min) : d / (max + min);
|
|
36
|
+
let h;
|
|
37
|
+
switch (max) {
|
|
38
|
+
case r:
|
|
39
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
40
|
+
break;
|
|
41
|
+
case g:
|
|
42
|
+
h = ((b - r) / d + 2) / 6;
|
|
43
|
+
break;
|
|
44
|
+
default: h = ((r - g) / d + 4) / 6;
|
|
45
|
+
}
|
|
46
|
+
return [
|
|
47
|
+
h * 360,
|
|
48
|
+
s * 100,
|
|
49
|
+
l * 100
|
|
50
|
+
];
|
|
71
51
|
}
|
|
72
52
|
function hslToHex(h, s, l) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
53
|
+
const sl = s / 100;
|
|
54
|
+
const ll = l / 100;
|
|
55
|
+
const a = sl * Math.min(ll, 1 - ll);
|
|
56
|
+
const f = (n) => {
|
|
57
|
+
const k = (n + h / 30) % 12;
|
|
58
|
+
const color = ll - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
59
|
+
return Math.round(255 * color).toString(16).padStart(2, "0");
|
|
60
|
+
};
|
|
61
|
+
return `#${f(0)}${f(8)}${f(4)}`;
|
|
82
62
|
}
|
|
63
|
+
/** WCAG 2 relative luminance of a #rrggbb colour. */
|
|
83
64
|
function relativeLuminance(hex) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
87
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
65
|
+
const [r, g, b] = hexToRgb(hex).map((v) => v <= .03928 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4);
|
|
66
|
+
return .2126 * r + .7152 * g + .0722 * b;
|
|
88
67
|
}
|
|
68
|
+
/** WCAG 2 contrast ratio between two #rrggbb colours, from 1 to 21. */
|
|
89
69
|
function contrastRatio(a, b) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
const lighter = Math.max(relativeLuminance(a), relativeLuminance(b));
|
|
71
|
+
const darker = Math.min(relativeLuminance(a), relativeLuminance(b));
|
|
72
|
+
return (lighter + .05) / (darker + .05);
|
|
93
73
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
74
|
+
/** Lightness targets for each shade step */
|
|
75
|
+
const SHADE_LIGHTNESS = {
|
|
76
|
+
50: 97,
|
|
77
|
+
100: 93,
|
|
78
|
+
200: 86,
|
|
79
|
+
300: 75,
|
|
80
|
+
400: 64,
|
|
81
|
+
500: 53,
|
|
82
|
+
600: 44,
|
|
83
|
+
700: 36,
|
|
84
|
+
800: 28,
|
|
85
|
+
900: 20,
|
|
86
|
+
950: 14
|
|
106
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Generate an 11-step palette from a seed hex color.
|
|
90
|
+
* Uses HSL color space — perceptually approximate but dependency-free.
|
|
91
|
+
*/
|
|
107
92
|
function generatePaletteFromSeed(seed) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
);
|
|
116
|
-
return Object.fromEntries(entries);
|
|
93
|
+
const [r, g, b] = hexToRgb(seed);
|
|
94
|
+
const [h, s] = rgbToHsl(r, g, b);
|
|
95
|
+
const entries = Object.entries(SHADE_LIGHTNESS).map(([shade, targetL]) => {
|
|
96
|
+
const adjustedS = targetL > 80 ? s * .55 : targetL < 25 ? s * .75 : s;
|
|
97
|
+
return [Number(shade), hslToHex(h, Math.min(adjustedS, 100), targetL)];
|
|
98
|
+
});
|
|
99
|
+
return Object.fromEntries(entries);
|
|
117
100
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
101
|
+
const STATUS_LIGHT = {
|
|
102
|
+
"--color-status-success": "#15803d",
|
|
103
|
+
"--color-status-success-bg": "#f0fdf4",
|
|
104
|
+
"--color-status-error": "#b91c1c",
|
|
105
|
+
"--color-status-error-bg": "#fef2f2",
|
|
106
|
+
"--color-status-warning": "#b45309",
|
|
107
|
+
"--color-status-warning-bg": "#fffbeb"
|
|
125
108
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
109
|
+
const STATUS_DARK = {
|
|
110
|
+
"--color-status-success": "#4ade80",
|
|
111
|
+
"--color-status-success-bg": "#052e16",
|
|
112
|
+
"--color-status-error": "#f87171",
|
|
113
|
+
"--color-status-error-bg": "#450a0a",
|
|
114
|
+
"--color-status-warning": "#fbbf24",
|
|
115
|
+
"--color-status-warning-bg": "#451a03"
|
|
133
116
|
};
|
|
134
117
|
function deriveLight() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
};
|
|
118
|
+
return {
|
|
119
|
+
"--color-bg-primary": "var(--color-neutral-0)",
|
|
120
|
+
"--color-bg-secondary": "var(--color-neutral-50)",
|
|
121
|
+
"--color-bg-surface": "var(--color-neutral-100)",
|
|
122
|
+
"--color-bg-accent": "var(--color-brand-50)",
|
|
123
|
+
"--color-bg-inverse": "var(--color-neutral-900)",
|
|
124
|
+
"--color-text-primary": "var(--color-neutral-900)",
|
|
125
|
+
"--color-text-secondary": "var(--color-neutral-700)",
|
|
126
|
+
"--color-text-muted": "var(--color-neutral-600)",
|
|
127
|
+
"--color-text-accent": "var(--color-brand-700)",
|
|
128
|
+
"--color-text-inverse": "var(--color-neutral-50)",
|
|
129
|
+
"--color-text-on-accent": "var(--color-neutral-0)",
|
|
130
|
+
"--color-border-default": "var(--color-neutral-200)",
|
|
131
|
+
"--color-border-subtle": "var(--color-neutral-100)",
|
|
132
|
+
"--color-border-strong": "var(--color-neutral-300)",
|
|
133
|
+
"--color-border-accent": "var(--color-brand-300)",
|
|
134
|
+
...STATUS_LIGHT,
|
|
135
|
+
"--color-status-info": "var(--color-brand-600)",
|
|
136
|
+
"--color-status-info-bg": "var(--color-brand-50)"
|
|
137
|
+
};
|
|
156
138
|
}
|
|
157
139
|
function deriveDark() {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
};
|
|
140
|
+
return {
|
|
141
|
+
"--color-bg-primary": "var(--color-neutral-900)",
|
|
142
|
+
"--color-bg-secondary": "var(--color-neutral-800)",
|
|
143
|
+
"--color-bg-surface": "var(--color-neutral-700)",
|
|
144
|
+
"--color-bg-accent": "var(--color-brand-950)",
|
|
145
|
+
"--color-bg-inverse": "var(--color-neutral-50)",
|
|
146
|
+
"--color-text-primary": "var(--color-neutral-100)",
|
|
147
|
+
"--color-text-secondary": "var(--color-neutral-300)",
|
|
148
|
+
"--color-text-muted": "var(--color-neutral-400)",
|
|
149
|
+
"--color-text-accent": "var(--color-brand-300)",
|
|
150
|
+
"--color-text-inverse": "var(--color-neutral-900)",
|
|
151
|
+
"--color-text-on-accent": "var(--color-neutral-950)",
|
|
152
|
+
"--color-border-default": "var(--color-neutral-700)",
|
|
153
|
+
"--color-border-subtle": "var(--color-neutral-800)",
|
|
154
|
+
"--color-border-strong": "var(--color-neutral-600)",
|
|
155
|
+
"--color-border-accent": "var(--color-brand-700)",
|
|
156
|
+
...STATUS_DARK,
|
|
157
|
+
"--color-status-info": "var(--color-brand-300)",
|
|
158
|
+
"--color-status-info-bg": "var(--color-brand-950)"
|
|
159
|
+
};
|
|
179
160
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
161
|
+
/**
|
|
162
|
+
* Every pairing of semantic tokens that @arun-dev/ui draws one on the other, with the WCAG
|
|
163
|
+
* contrast it needs: 7 where the default brand is audited AAA, 4.5 for other text, 3 for
|
|
164
|
+
* icons, accent bars and focus outlines. A brand that skips createBrand should meet these too.
|
|
165
|
+
*/
|
|
166
|
+
const CONTRAST_REQUIREMENTS = [
|
|
167
|
+
{
|
|
168
|
+
foreground: "--color-text-primary",
|
|
169
|
+
background: "--color-bg-primary",
|
|
170
|
+
min: 7
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
foreground: "--color-text-primary",
|
|
174
|
+
background: "--color-bg-secondary",
|
|
175
|
+
min: 7
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
foreground: "--color-text-primary",
|
|
179
|
+
background: "--color-bg-surface",
|
|
180
|
+
min: 4.5
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
foreground: "--color-text-secondary",
|
|
184
|
+
background: "--color-bg-primary",
|
|
185
|
+
min: 7
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
foreground: "--color-text-muted",
|
|
189
|
+
background: "--color-bg-primary",
|
|
190
|
+
min: 4.5
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
foreground: "--color-text-inverse",
|
|
194
|
+
background: "--color-bg-inverse",
|
|
195
|
+
min: 7
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
foreground: "--color-text-primary",
|
|
199
|
+
background: "--color-bg-accent",
|
|
200
|
+
min: 7
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
foreground: "--color-text-accent",
|
|
204
|
+
background: "--color-bg-primary",
|
|
205
|
+
min: 7
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
foreground: "--color-text-accent",
|
|
209
|
+
background: "--color-bg-secondary",
|
|
210
|
+
min: 4.5
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
foreground: "--color-text-accent",
|
|
214
|
+
background: "--color-bg-surface",
|
|
215
|
+
min: 4.5
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
foreground: "--color-text-accent",
|
|
219
|
+
background: "--color-bg-accent",
|
|
220
|
+
min: 4.5
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
foreground: "--color-text-on-accent",
|
|
224
|
+
background: "--color-text-accent",
|
|
225
|
+
min: 7
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
foreground: "--color-status-success",
|
|
229
|
+
background: "--color-status-success-bg",
|
|
230
|
+
min: 4.5
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
foreground: "--color-status-error",
|
|
234
|
+
background: "--color-status-error-bg",
|
|
235
|
+
min: 4.5
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
foreground: "--color-status-warning",
|
|
239
|
+
background: "--color-status-warning-bg",
|
|
240
|
+
min: 4.5
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
foreground: "--color-status-info",
|
|
244
|
+
background: "--color-status-info-bg",
|
|
245
|
+
min: 4.5
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
foreground: "--color-status-info",
|
|
249
|
+
background: "--color-bg-primary",
|
|
250
|
+
min: 3
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
foreground: "--color-status-error",
|
|
254
|
+
background: "--color-bg-primary",
|
|
255
|
+
min: 4.5
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
foreground: "--color-status-warning",
|
|
259
|
+
background: "--color-bg-primary",
|
|
260
|
+
min: 3
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
foreground: "--color-status-success",
|
|
264
|
+
background: "--color-bg-primary",
|
|
265
|
+
min: 3
|
|
266
|
+
}
|
|
203
267
|
];
|
|
204
|
-
|
|
205
|
-
|
|
268
|
+
const BRAND_VAR = /^var\(--color-brand-(\d+)\)$/;
|
|
269
|
+
const NEUTRAL_VAR = /^var\(--color-neutral-(\d+)\)$/;
|
|
270
|
+
/** The colour a semantic value stands for: a brand shade, a neutral shade or a literal. */
|
|
206
271
|
function resolveColor(value, palette, neutral) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
272
|
+
const brand = BRAND_VAR.exec(value);
|
|
273
|
+
if (brand) return palette[Number(brand[1])];
|
|
274
|
+
const gray = NEUTRAL_VAR.exec(value);
|
|
275
|
+
if (gray) return neutral[Number(gray[1])];
|
|
276
|
+
return value;
|
|
212
277
|
}
|
|
278
|
+
/** The same colour, lighter or darker by `step` HSL points; its hue and saturation kept. */
|
|
213
279
|
function shiftLightness(hex, step) {
|
|
214
|
-
|
|
215
|
-
|
|
280
|
+
const [h, s, l] = rgbToHsl(...hexToRgb(hex));
|
|
281
|
+
return hslToHex(h, s, Math.min(100, Math.max(0, l + step)));
|
|
216
282
|
}
|
|
217
|
-
|
|
283
|
+
const SHADES = Object.keys(SHADE_LIGHTNESS).map(Number);
|
|
284
|
+
/**
|
|
285
|
+
* Moves the shades of a seeded palette until every pairing in CONTRAST_REQUIREMENTS passes in
|
|
286
|
+
* both themes. HSL lightness is not how light a colour looks — a yellow at the 700 step is
|
|
287
|
+
* still bright — so fixed steps alone cannot promise contrast.
|
|
288
|
+
*
|
|
289
|
+
* In each failing pair the brand shade moves, away from the colour it sits on or under: the
|
|
290
|
+
* foreground's when both are brand shades. Hue and saturation stay, so the brand still reads
|
|
291
|
+
* as its seed. The scale is then kept in order, light to dark, by moving its neighbours on.
|
|
292
|
+
*/
|
|
218
293
|
function fitContrast(palette, neutral) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
fitted[shade] = shiftLightness(fitted[shade], 1);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (!moved) break;
|
|
253
|
-
}
|
|
254
|
-
return fitted;
|
|
294
|
+
const fitted = { ...palette };
|
|
295
|
+
const themes = [deriveLight(), deriveDark()];
|
|
296
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
297
|
+
let moved = false;
|
|
298
|
+
for (const theme of themes) for (const { foreground, background, min } of CONTRAST_REQUIREMENTS) {
|
|
299
|
+
const fgValue = theme[foreground] ?? "";
|
|
300
|
+
const bgValue = theme[background] ?? "";
|
|
301
|
+
const fgShade = BRAND_VAR.exec(fgValue)?.[1];
|
|
302
|
+
const bgShade = BRAND_VAR.exec(bgValue)?.[1];
|
|
303
|
+
const shade = Number(fgShade ?? bgShade);
|
|
304
|
+
if (!fgShade && !bgShade) continue;
|
|
305
|
+
const other = resolveColor(fgShade ? bgValue : fgValue, fitted, neutral);
|
|
306
|
+
const step = relativeLuminance(other) > .18 ? -1 : 1;
|
|
307
|
+
for (let i = 0; i < 100 && contrastRatio(fitted[shade], other) < min; i++) {
|
|
308
|
+
fitted[shade] = shiftLightness(fitted[shade], step);
|
|
309
|
+
moved = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const middle = SHADES.indexOf(500);
|
|
313
|
+
for (let i = middle + 1; i < SHADES.length; i++) {
|
|
314
|
+
const [before, shade] = [SHADES[i - 1], SHADES[i]];
|
|
315
|
+
for (let n = 0; n < 100 && relativeLuminance(fitted[shade]) >= relativeLuminance(fitted[before]); n++) fitted[shade] = shiftLightness(fitted[shade], -1);
|
|
316
|
+
}
|
|
317
|
+
for (let i = middle - 1; i >= 0; i--) {
|
|
318
|
+
const [after, shade] = [SHADES[i + 1], SHADES[i]];
|
|
319
|
+
for (let n = 0; n < 100 && relativeLuminance(fitted[shade]) <= relativeLuminance(fitted[after]); n++) fitted[shade] = shiftLightness(fitted[shade], 1);
|
|
320
|
+
}
|
|
321
|
+
if (!moved) break;
|
|
322
|
+
}
|
|
323
|
+
return fitted;
|
|
255
324
|
}
|
|
256
325
|
function toVars(tokens, indent = " ") {
|
|
257
|
-
|
|
326
|
+
return Object.entries(tokens).map(([k, v]) => `${indent}${k}: ${v};`).join("\n");
|
|
258
327
|
}
|
|
259
328
|
function paletteVars(palette) {
|
|
260
|
-
|
|
329
|
+
return Object.keys(SHADE_LIGHTNESS).map((shade) => ` --color-brand-${shade}: ${palette[shade]};`).join("\n");
|
|
261
330
|
}
|
|
262
331
|
function neutralVars(neutral) {
|
|
263
|
-
|
|
332
|
+
return [
|
|
333
|
+
0,
|
|
334
|
+
50,
|
|
335
|
+
100,
|
|
336
|
+
200,
|
|
337
|
+
300,
|
|
338
|
+
400,
|
|
339
|
+
500,
|
|
340
|
+
600,
|
|
341
|
+
700,
|
|
342
|
+
800,
|
|
343
|
+
900,
|
|
344
|
+
950
|
|
345
|
+
].map((shade) => ` --color-neutral-${shade}: ${neutral[shade]};`).join("\n");
|
|
264
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Generate a complete brand CSS string from a palette or seed color.
|
|
349
|
+
* Write the output to a .css file and import it in your globals.css.
|
|
350
|
+
*/
|
|
265
351
|
function createBrand(input) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
352
|
+
const { name, neutral = DEFAULT_NEUTRAL } = input;
|
|
353
|
+
const palette = "seed" in input ? fitContrast(generatePaletteFromSeed(input.seed), neutral) : input.palette;
|
|
354
|
+
const light = deriveLight();
|
|
355
|
+
const dark = deriveDark();
|
|
356
|
+
return `/* ${name} brand — generated by createBrand (@arun-dev/tokens) */
|
|
271
357
|
/* Re-run createBrand to regenerate after palette changes. */
|
|
272
358
|
|
|
273
359
|
:root {
|
|
@@ -293,11 +379,9 @@ ${toVars(light)}
|
|
|
293
379
|
}
|
|
294
380
|
`;
|
|
295
381
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
generatePaletteFromSeed
|
|
303
|
-
});
|
|
382
|
+
//#endregion
|
|
383
|
+
exports.CONTRAST_REQUIREMENTS = CONTRAST_REQUIREMENTS;
|
|
384
|
+
exports.DEFAULT_NEUTRAL = DEFAULT_NEUTRAL;
|
|
385
|
+
exports.contrastRatio = contrastRatio;
|
|
386
|
+
exports.createBrand = createBrand;
|
|
387
|
+
exports.generatePaletteFromSeed = generatePaletteFromSeed;
|