@aakaar/dictionary 0.0.2 → 0.0.4
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/index.cjs +494 -52
- package/dist/index.d.cts +58 -3
- package/dist/index.d.ts +58 -3
- package/dist/index.js +498 -56
- package/dist/index.mjs +7576 -0
- package/package.json +8 -1
package/dist/index.d.ts
CHANGED
|
@@ -24,10 +24,65 @@ type CategoryDesignTokens = {
|
|
|
24
24
|
category: string;
|
|
25
25
|
tokens: DesignToken[];
|
|
26
26
|
};
|
|
27
|
+
type PrimaryPalette = {
|
|
28
|
+
primary0: DesignToken;
|
|
29
|
+
primary10: DesignToken;
|
|
30
|
+
primary20: DesignToken;
|
|
31
|
+
primary30: DesignToken;
|
|
32
|
+
primary40: DesignToken;
|
|
33
|
+
primary50: DesignToken;
|
|
34
|
+
primary60: DesignToken;
|
|
35
|
+
primary70: DesignToken;
|
|
36
|
+
primary80: DesignToken;
|
|
37
|
+
primary90: DesignToken;
|
|
38
|
+
primary95: DesignToken;
|
|
39
|
+
primary100: DesignToken;
|
|
40
|
+
};
|
|
41
|
+
type AakaarColorScheme = {
|
|
42
|
+
primary: DesignToken;
|
|
43
|
+
onPrimary: DesignToken;
|
|
44
|
+
primaryContainer: DesignToken;
|
|
45
|
+
onPrimaryContainer: DesignToken;
|
|
46
|
+
secondary: DesignToken;
|
|
47
|
+
onSecondary: DesignToken;
|
|
48
|
+
secondaryContainer: DesignToken;
|
|
49
|
+
onSecondaryContainer: DesignToken;
|
|
50
|
+
tertiary: DesignToken;
|
|
51
|
+
onTertiary: DesignToken;
|
|
52
|
+
tertiaryContainer: DesignToken;
|
|
53
|
+
onTertiaryContainer: DesignToken;
|
|
54
|
+
error: DesignToken;
|
|
55
|
+
onError: DesignToken;
|
|
56
|
+
errorContainer: DesignToken;
|
|
57
|
+
onErrorContainer: DesignToken;
|
|
58
|
+
background: DesignToken;
|
|
59
|
+
onBackground: DesignToken;
|
|
60
|
+
surface: DesignToken;
|
|
61
|
+
onSurface: DesignToken;
|
|
62
|
+
surfaceVariant: DesignToken;
|
|
63
|
+
onSurfaceVariant: DesignToken;
|
|
64
|
+
outline: DesignToken;
|
|
65
|
+
outlineVariant: DesignToken;
|
|
66
|
+
shadow: DesignToken;
|
|
67
|
+
scrim: DesignToken;
|
|
68
|
+
inverseSurface: DesignToken;
|
|
69
|
+
inverseOnSurface: DesignToken;
|
|
70
|
+
inversePrimary: DesignToken;
|
|
71
|
+
};
|
|
72
|
+
type BlackAndWhiteScheme = {
|
|
73
|
+
white: DesignToken;
|
|
74
|
+
black: DesignToken;
|
|
75
|
+
};
|
|
76
|
+
type ColorStrategyOutput = {
|
|
77
|
+
primaryPalette: PrimaryPalette;
|
|
78
|
+
lightDark: AakaarColorScheme;
|
|
79
|
+
blackAndWhite: BlackAndWhiteScheme;
|
|
80
|
+
};
|
|
81
|
+
type ColorStrategy = "material" | "harmony";
|
|
27
82
|
|
|
28
83
|
declare const transformTokenToCssObject: (token: DesignToken) => CssObject;
|
|
29
84
|
declare const transformTokenToCSSVariable: (colorToken: DesignToken) => string;
|
|
30
|
-
declare const buildCategoryDesignTokens: (color: string) => CategoryDesignTokens[];
|
|
31
|
-
declare const runCss: (color: string) => string;
|
|
85
|
+
declare const buildCategoryDesignTokens: (color: string, strategy?: ColorStrategy) => CategoryDesignTokens[];
|
|
86
|
+
declare const runCss: (color: string, strategy?: ColorStrategy) => string;
|
|
32
87
|
|
|
33
|
-
export { type CategoryDesignTokens, type CssObject, type DesignToken, Size, VariableCase, buildCategoryDesignTokens, runCss, transformTokenToCSSVariable, transformTokenToCssObject };
|
|
88
|
+
export { type AakaarColorScheme, type BlackAndWhiteScheme, type CategoryDesignTokens, type ColorStrategy, type ColorStrategyOutput, type CssObject, type DesignToken, type PrimaryPalette, Size, VariableCase, buildCategoryDesignTokens, runCss, transformTokenToCSSVariable, transformTokenToCssObject };
|
package/dist/index.js
CHANGED
|
@@ -38,45 +38,6 @@ var transformCase = (text, target) => {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
// src/lib/css/colors.ts
|
|
42
|
-
import {
|
|
43
|
-
argbFromHex,
|
|
44
|
-
hexFromArgb,
|
|
45
|
-
themeFromSourceColor
|
|
46
|
-
} from "@material/material-color-utilities";
|
|
47
|
-
import Color from "colorjs.io";
|
|
48
|
-
var theme = (color) => themeFromSourceColor(argbFromHex(color));
|
|
49
|
-
var transformHexToOkLch = (color) => {
|
|
50
|
-
const oklchColor = new Color(color).to("oklch");
|
|
51
|
-
return oklchColor.toString({ precision: 2 });
|
|
52
|
-
};
|
|
53
|
-
var transformColorToToken = (name, color) => {
|
|
54
|
-
return {
|
|
55
|
-
name: `color-${name}`,
|
|
56
|
-
value: transformHexToOkLch(hexFromArgb(color))
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
var lightTokens = (theme2) => Object.entries(theme2.schemes.light.toJSON()).map(
|
|
60
|
-
([colorName, colorValue]) => transformColorToToken(colorName, colorValue)
|
|
61
|
-
);
|
|
62
|
-
var darkTokens = (theme2) => Object.entries(theme2.schemes.dark.toJSON()).map(
|
|
63
|
-
([colorName, colorValue]) => transformColorToToken(colorName, colorValue)
|
|
64
|
-
);
|
|
65
|
-
var lightDarkTokens = (theme2) => {
|
|
66
|
-
const light = lightTokens(theme2);
|
|
67
|
-
const dark = darkTokens(theme2);
|
|
68
|
-
return light.map((lightToken, index) => ({
|
|
69
|
-
name: lightToken.name,
|
|
70
|
-
value: `light-dark(${lightToken.value}, ${dark[index].value})`
|
|
71
|
-
}));
|
|
72
|
-
};
|
|
73
|
-
var primaryPaletteTokens = (theme2) => {
|
|
74
|
-
const tones = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];
|
|
75
|
-
return tones.map(
|
|
76
|
-
(tone) => transformColorToToken(`primary${tone}`, theme2.palettes.primary.tone(tone))
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
41
|
// src/lib/css/shadow.ts
|
|
81
42
|
var transformShadowToToken = (name, size, value) => {
|
|
82
43
|
return {
|
|
@@ -205,6 +166,494 @@ var radiusTokens = [
|
|
|
205
166
|
}
|
|
206
167
|
];
|
|
207
168
|
|
|
169
|
+
// src/lib/css/strategy/harmony/harmony-colors.ts
|
|
170
|
+
import Color from "colorjs.io";
|
|
171
|
+
var theme = (color) => {
|
|
172
|
+
const sourceColor = new Color(color);
|
|
173
|
+
return sourceColor;
|
|
174
|
+
};
|
|
175
|
+
var transformHexToOkLch = (color) => {
|
|
176
|
+
if (color.startsWith("light-dark(")) {
|
|
177
|
+
return color;
|
|
178
|
+
}
|
|
179
|
+
const oklchColor = new Color(color).to("oklch");
|
|
180
|
+
return oklchColor.toString({ precision: 3 });
|
|
181
|
+
};
|
|
182
|
+
var transformColorToToken = (name, color) => {
|
|
183
|
+
return {
|
|
184
|
+
name: `color-${name}`,
|
|
185
|
+
value: transformHexToOkLch(color)
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
var generateHarmoniousHue = (baseHue, harmonyType, index = 0) => {
|
|
189
|
+
switch (harmonyType) {
|
|
190
|
+
case "analogous":
|
|
191
|
+
return (baseHue + index * 30 + 360) % 360;
|
|
192
|
+
case "complementary":
|
|
193
|
+
return (baseHue + 180) % 360;
|
|
194
|
+
case "triadic":
|
|
195
|
+
return (baseHue + index * 120) % 360;
|
|
196
|
+
case "split-complementary":
|
|
197
|
+
return index === 0 ? (baseHue + 150) % 360 : (baseHue + 210) % 360;
|
|
198
|
+
default:
|
|
199
|
+
return baseHue;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var optimizeLightnessForContrast = (lightness, chroma, isLight) => {
|
|
203
|
+
if (isLight) {
|
|
204
|
+
return Math.max(0.25, Math.min(0.65, lightness - chroma * 0.3));
|
|
205
|
+
}
|
|
206
|
+
return Math.max(0.35, Math.min(0.8, lightness + chroma * 0.4));
|
|
207
|
+
};
|
|
208
|
+
var generateOptimalChroma = (baseChroma, purpose) => {
|
|
209
|
+
const chromaMap = {
|
|
210
|
+
primary: Math.max(0.15, Math.min(0.37, baseChroma)),
|
|
211
|
+
secondary: Math.max(0.12, Math.min(0.32, baseChroma * 0.85)),
|
|
212
|
+
tertiary: Math.max(0.1, Math.min(0.28, baseChroma * 0.75)),
|
|
213
|
+
neutral: Math.max(5e-3, Math.min(0.04, baseChroma * 0.2))
|
|
214
|
+
};
|
|
215
|
+
return chromaMap[purpose];
|
|
216
|
+
};
|
|
217
|
+
var harmonyLightDarkTokens = (sourceColor) => {
|
|
218
|
+
const baseColor = sourceColor;
|
|
219
|
+
const baseOklch = baseColor.to("oklch");
|
|
220
|
+
const baseHue = Number.isNaN(baseOklch.h) ? 240 : baseOklch.h;
|
|
221
|
+
const baseChroma = Math.max(baseOklch.c, 0.1);
|
|
222
|
+
const baseLightness = baseOklch.l;
|
|
223
|
+
const primaryChroma = generateOptimalChroma(baseChroma, "primary");
|
|
224
|
+
const primaryLightLightness = optimizeLightnessForContrast(
|
|
225
|
+
baseLightness,
|
|
226
|
+
primaryChroma,
|
|
227
|
+
true
|
|
228
|
+
);
|
|
229
|
+
const primaryDarkLightness = optimizeLightnessForContrast(
|
|
230
|
+
baseLightness,
|
|
231
|
+
primaryChroma,
|
|
232
|
+
false
|
|
233
|
+
);
|
|
234
|
+
let lightPrimary = new Color("oklch", [
|
|
235
|
+
primaryLightLightness,
|
|
236
|
+
primaryChroma,
|
|
237
|
+
baseHue
|
|
238
|
+
]);
|
|
239
|
+
let darkPrimary = new Color("oklch", [
|
|
240
|
+
primaryDarkLightness,
|
|
241
|
+
primaryChroma,
|
|
242
|
+
baseHue
|
|
243
|
+
]);
|
|
244
|
+
if (lightPrimary.to("oklch").l > 0.8 || lightPrimary.to("oklch").c < 0.08) {
|
|
245
|
+
lightPrimary = new Color("oklch", [0.5, 0.2, 240]);
|
|
246
|
+
darkPrimary = new Color("oklch", [0.7, 0.2, 240]);
|
|
247
|
+
}
|
|
248
|
+
const secondaryHue = generateHarmoniousHue(baseHue, "analogous", 1);
|
|
249
|
+
const secondaryChroma = generateOptimalChroma(baseChroma, "secondary");
|
|
250
|
+
const lightSecondary = new Color("oklch", [
|
|
251
|
+
optimizeLightnessForContrast(baseLightness, secondaryChroma, true),
|
|
252
|
+
secondaryChroma,
|
|
253
|
+
secondaryHue
|
|
254
|
+
]);
|
|
255
|
+
const darkSecondary = new Color("oklch", [
|
|
256
|
+
optimizeLightnessForContrast(baseLightness, secondaryChroma, false),
|
|
257
|
+
secondaryChroma,
|
|
258
|
+
secondaryHue
|
|
259
|
+
]);
|
|
260
|
+
const tertiaryHue = generateHarmoniousHue(baseHue, "analogous", -1);
|
|
261
|
+
const tertiaryChroma = generateOptimalChroma(baseChroma, "tertiary");
|
|
262
|
+
const lightTertiary = new Color("oklch", [
|
|
263
|
+
optimizeLightnessForContrast(baseLightness, tertiaryChroma, true),
|
|
264
|
+
tertiaryChroma,
|
|
265
|
+
tertiaryHue
|
|
266
|
+
]);
|
|
267
|
+
const darkTertiary = new Color("oklch", [
|
|
268
|
+
optimizeLightnessForContrast(baseLightness, tertiaryChroma, false),
|
|
269
|
+
tertiaryChroma,
|
|
270
|
+
tertiaryHue
|
|
271
|
+
]);
|
|
272
|
+
const errorChroma = Math.max(0.18, Math.min(0.35, baseChroma));
|
|
273
|
+
const lightError = new Color("oklch", [0.55, errorChroma, 25]);
|
|
274
|
+
const darkError = new Color("oklch", [0.75, errorChroma, 25]);
|
|
275
|
+
const neutralChroma = generateOptimalChroma(baseChroma, "neutral");
|
|
276
|
+
const lightBackground = new Color("oklch", [
|
|
277
|
+
0.99,
|
|
278
|
+
neutralChroma * 0.5,
|
|
279
|
+
baseHue
|
|
280
|
+
]);
|
|
281
|
+
const darkBackground = new Color("oklch", [
|
|
282
|
+
0.08,
|
|
283
|
+
neutralChroma * 1.5,
|
|
284
|
+
baseHue
|
|
285
|
+
]);
|
|
286
|
+
const lightSurface = new Color("oklch", [0.98, neutralChroma * 0.8, baseHue]);
|
|
287
|
+
const darkSurface = new Color("oklch", [0.11, neutralChroma * 1.2, baseHue]);
|
|
288
|
+
const lightPrimaryContainer = new Color("oklch", [
|
|
289
|
+
0.95,
|
|
290
|
+
primaryChroma * 0.3,
|
|
291
|
+
baseHue
|
|
292
|
+
]);
|
|
293
|
+
const darkPrimaryContainer = new Color("oklch", [
|
|
294
|
+
0.2,
|
|
295
|
+
primaryChroma * 0.8,
|
|
296
|
+
baseHue
|
|
297
|
+
]);
|
|
298
|
+
const lightSecondaryContainer = new Color("oklch", [
|
|
299
|
+
0.94,
|
|
300
|
+
secondaryChroma * 0.25,
|
|
301
|
+
secondaryHue
|
|
302
|
+
]);
|
|
303
|
+
const darkSecondaryContainer = new Color("oklch", [
|
|
304
|
+
0.18,
|
|
305
|
+
secondaryChroma * 0.75,
|
|
306
|
+
secondaryHue
|
|
307
|
+
]);
|
|
308
|
+
const lightTertiaryContainer = new Color("oklch", [
|
|
309
|
+
0.93,
|
|
310
|
+
tertiaryChroma * 0.2,
|
|
311
|
+
tertiaryHue
|
|
312
|
+
]);
|
|
313
|
+
const darkTertiaryContainer = new Color("oklch", [
|
|
314
|
+
0.16,
|
|
315
|
+
tertiaryChroma * 0.7,
|
|
316
|
+
tertiaryHue
|
|
317
|
+
]);
|
|
318
|
+
const lightErrorContainer = new Color("oklch", [
|
|
319
|
+
0.96,
|
|
320
|
+
errorChroma * 0.15,
|
|
321
|
+
25
|
|
322
|
+
]);
|
|
323
|
+
const darkErrorContainer = new Color("oklch", [0.22, errorChroma * 0.6, 25]);
|
|
324
|
+
const lightSurfaceVariant = new Color("oklch", [
|
|
325
|
+
0.96,
|
|
326
|
+
neutralChroma * 1.2,
|
|
327
|
+
baseHue
|
|
328
|
+
]);
|
|
329
|
+
const darkSurfaceVariant = new Color("oklch", [
|
|
330
|
+
0.18,
|
|
331
|
+
neutralChroma * 2,
|
|
332
|
+
baseHue
|
|
333
|
+
]);
|
|
334
|
+
const lightOutline = new Color("oklch", [0.72, neutralChroma * 3, baseHue]);
|
|
335
|
+
const darkOutline = new Color("oklch", [0.68, neutralChroma * 3, baseHue]);
|
|
336
|
+
const lightOutlineVariant = new Color("oklch", [
|
|
337
|
+
0.88,
|
|
338
|
+
neutralChroma * 2,
|
|
339
|
+
baseHue
|
|
340
|
+
]);
|
|
341
|
+
const darkOutlineVariant = new Color("oklch", [
|
|
342
|
+
0.35,
|
|
343
|
+
neutralChroma * 2,
|
|
344
|
+
baseHue
|
|
345
|
+
]);
|
|
346
|
+
const lightInverseSurface = new Color("oklch", [
|
|
347
|
+
0.15,
|
|
348
|
+
neutralChroma * 1.5,
|
|
349
|
+
baseHue
|
|
350
|
+
]);
|
|
351
|
+
const darkInverseSurface = new Color("oklch", [
|
|
352
|
+
0.92,
|
|
353
|
+
neutralChroma * 0.8,
|
|
354
|
+
baseHue
|
|
355
|
+
]);
|
|
356
|
+
const lightInversePrimary = new Color("oklch", [
|
|
357
|
+
0.85,
|
|
358
|
+
primaryChroma * 0.6,
|
|
359
|
+
baseHue
|
|
360
|
+
]);
|
|
361
|
+
const darkInversePrimary = new Color("oklch", [
|
|
362
|
+
0.45,
|
|
363
|
+
primaryChroma * 0.9,
|
|
364
|
+
baseHue
|
|
365
|
+
]);
|
|
366
|
+
const generateContrastingOnColor = (lightBg, darkBg) => {
|
|
367
|
+
const lightBgL = lightBg.to("oklch").l;
|
|
368
|
+
const darkBgL = darkBg.to("oklch").l;
|
|
369
|
+
const lightForeground = lightBgL > 0.6 ? "#000000" : "#ffffff";
|
|
370
|
+
const darkForeground = darkBgL > 0.6 ? "#000000" : "#ffffff";
|
|
371
|
+
return `light-dark(${lightForeground}, ${darkForeground})`;
|
|
372
|
+
};
|
|
373
|
+
return {
|
|
374
|
+
// Primary colors - the main brand color with enhanced contrast
|
|
375
|
+
primary: transformColorToToken(
|
|
376
|
+
"primary",
|
|
377
|
+
`light-dark(${lightPrimary.toString({ format: "hex" })}, ${darkPrimary.toString({ format: "hex" })})`
|
|
378
|
+
),
|
|
379
|
+
onPrimary: transformColorToToken(
|
|
380
|
+
"onPrimary",
|
|
381
|
+
generateContrastingOnColor(lightPrimary, darkPrimary)
|
|
382
|
+
),
|
|
383
|
+
primaryContainer: transformColorToToken(
|
|
384
|
+
"primaryContainer",
|
|
385
|
+
`light-dark(${lightPrimaryContainer.toString({ format: "hex" })}, ${darkPrimaryContainer.toString({ format: "hex" })})`
|
|
386
|
+
),
|
|
387
|
+
onPrimaryContainer: transformColorToToken(
|
|
388
|
+
"onPrimaryContainer",
|
|
389
|
+
generateContrastingOnColor(lightPrimaryContainer, darkPrimaryContainer)
|
|
390
|
+
),
|
|
391
|
+
// Secondary colors - harmonious supporting accent
|
|
392
|
+
secondary: transformColorToToken(
|
|
393
|
+
"secondary",
|
|
394
|
+
`light-dark(${lightSecondary.toString({ format: "hex" })}, ${darkSecondary.toString({ format: "hex" })})`
|
|
395
|
+
),
|
|
396
|
+
onSecondary: transformColorToToken(
|
|
397
|
+
"onSecondary",
|
|
398
|
+
generateContrastingOnColor(lightSecondary, darkSecondary)
|
|
399
|
+
),
|
|
400
|
+
secondaryContainer: transformColorToToken(
|
|
401
|
+
"secondaryContainer",
|
|
402
|
+
`light-dark(${lightSecondaryContainer.toString({ format: "hex" })}, ${darkSecondaryContainer.toString({ format: "hex" })})`
|
|
403
|
+
),
|
|
404
|
+
onSecondaryContainer: transformColorToToken(
|
|
405
|
+
"onSecondaryContainer",
|
|
406
|
+
generateContrastingOnColor(
|
|
407
|
+
lightSecondaryContainer,
|
|
408
|
+
darkSecondaryContainer
|
|
409
|
+
)
|
|
410
|
+
),
|
|
411
|
+
// Tertiary colors - split-complementary accent
|
|
412
|
+
tertiary: transformColorToToken(
|
|
413
|
+
"tertiary",
|
|
414
|
+
`light-dark(${lightTertiary.toString({ format: "hex" })}, ${darkTertiary.toString({ format: "hex" })})`
|
|
415
|
+
),
|
|
416
|
+
onTertiary: transformColorToToken(
|
|
417
|
+
"onTertiary",
|
|
418
|
+
generateContrastingOnColor(lightTertiary, darkTertiary)
|
|
419
|
+
),
|
|
420
|
+
tertiaryContainer: transformColorToToken(
|
|
421
|
+
"tertiaryContainer",
|
|
422
|
+
`light-dark(${lightTertiaryContainer.toString({ format: "hex" })}, ${darkTertiaryContainer.toString({ format: "hex" })})`
|
|
423
|
+
),
|
|
424
|
+
onTertiaryContainer: transformColorToToken(
|
|
425
|
+
"onTertiaryContainer",
|
|
426
|
+
generateContrastingOnColor(lightTertiaryContainer, darkTertiaryContainer)
|
|
427
|
+
),
|
|
428
|
+
// Error colors - accessibility optimized
|
|
429
|
+
error: transformColorToToken(
|
|
430
|
+
"error",
|
|
431
|
+
`light-dark(${lightError.toString({ format: "hex" })}, ${darkError.toString({ format: "hex" })})`
|
|
432
|
+
),
|
|
433
|
+
onError: transformColorToToken(
|
|
434
|
+
"onError",
|
|
435
|
+
generateContrastingOnColor(lightError, darkError)
|
|
436
|
+
),
|
|
437
|
+
errorContainer: transformColorToToken(
|
|
438
|
+
"errorContainer",
|
|
439
|
+
`light-dark(${lightErrorContainer.toString({ format: "hex" })}, ${darkErrorContainer.toString({ format: "hex" })})`
|
|
440
|
+
),
|
|
441
|
+
onErrorContainer: transformColorToToken(
|
|
442
|
+
"onErrorContainer",
|
|
443
|
+
generateContrastingOnColor(lightErrorContainer, darkErrorContainer)
|
|
444
|
+
),
|
|
445
|
+
// Background and surface colors with subtle tinting
|
|
446
|
+
background: transformColorToToken(
|
|
447
|
+
"background",
|
|
448
|
+
`light-dark(${lightBackground.toString({ format: "hex" })}, ${darkBackground.toString({ format: "hex" })})`
|
|
449
|
+
),
|
|
450
|
+
onBackground: transformColorToToken(
|
|
451
|
+
"onBackground",
|
|
452
|
+
generateContrastingOnColor(lightBackground, darkBackground)
|
|
453
|
+
),
|
|
454
|
+
surface: transformColorToToken(
|
|
455
|
+
"surface",
|
|
456
|
+
`light-dark(${lightSurface.toString({ format: "hex" })}, ${darkSurface.toString({ format: "hex" })})`
|
|
457
|
+
),
|
|
458
|
+
onSurface: transformColorToToken(
|
|
459
|
+
"onSurface",
|
|
460
|
+
generateContrastingOnColor(lightSurface, darkSurface)
|
|
461
|
+
),
|
|
462
|
+
surfaceVariant: transformColorToToken(
|
|
463
|
+
"surfaceVariant",
|
|
464
|
+
`light-dark(${lightSurfaceVariant.toString({ format: "hex" })}, ${darkSurfaceVariant.toString({ format: "hex" })})`
|
|
465
|
+
),
|
|
466
|
+
onSurfaceVariant: transformColorToToken(
|
|
467
|
+
"onSurfaceVariant",
|
|
468
|
+
generateContrastingOnColor(lightSurfaceVariant, darkSurfaceVariant)
|
|
469
|
+
),
|
|
470
|
+
// Outline colors with enhanced visibility
|
|
471
|
+
outline: transformColorToToken(
|
|
472
|
+
"outline",
|
|
473
|
+
`light-dark(${lightOutline.toString({ format: "hex" })}, ${darkOutline.toString({ format: "hex" })})`
|
|
474
|
+
),
|
|
475
|
+
outlineVariant: transformColorToToken(
|
|
476
|
+
"outlineVariant",
|
|
477
|
+
`light-dark(${lightOutlineVariant.toString({ format: "hex" })}, ${darkOutlineVariant.toString({ format: "hex" })})`
|
|
478
|
+
),
|
|
479
|
+
// Shadow and scrim - optimized for depth perception
|
|
480
|
+
shadow: transformColorToToken(
|
|
481
|
+
"shadow",
|
|
482
|
+
"light-dark(oklch(0 0 0 / 0.2), oklch(0 0 0 / 0.4))"
|
|
483
|
+
),
|
|
484
|
+
scrim: transformColorToToken(
|
|
485
|
+
"scrim",
|
|
486
|
+
"light-dark(oklch(0 0 0 / 0.4), oklch(0 0 0 / 0.6))"
|
|
487
|
+
),
|
|
488
|
+
// Inverse colors with proper contrast
|
|
489
|
+
inverseSurface: transformColorToToken(
|
|
490
|
+
"inverseSurface",
|
|
491
|
+
`light-dark(${lightInverseSurface.toString({ format: "hex" })}, ${darkInverseSurface.toString({ format: "hex" })})`
|
|
492
|
+
),
|
|
493
|
+
inverseOnSurface: transformColorToToken(
|
|
494
|
+
"inverseOnSurface",
|
|
495
|
+
generateContrastingOnColor(lightInverseSurface, darkInverseSurface)
|
|
496
|
+
),
|
|
497
|
+
inversePrimary: transformColorToToken(
|
|
498
|
+
"inversePrimary",
|
|
499
|
+
`light-dark(${lightInversePrimary.toString({ format: "hex" })}, ${darkInversePrimary.toString({ format: "hex" })})`
|
|
500
|
+
)
|
|
501
|
+
};
|
|
502
|
+
};
|
|
503
|
+
var harmonyPrimaryPaletteTokens = (sourceColor) => {
|
|
504
|
+
const tones = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];
|
|
505
|
+
const sourceOklch = sourceColor.to("oklch");
|
|
506
|
+
const baseHue = Number.isNaN(sourceOklch.h) ? 240 : sourceOklch.h;
|
|
507
|
+
const baseChroma = Math.max(sourceOklch.c, 0.1);
|
|
508
|
+
const generateToneColor = (tone) => {
|
|
509
|
+
let lightness;
|
|
510
|
+
let chroma;
|
|
511
|
+
if (tone === 0) {
|
|
512
|
+
lightness = 0;
|
|
513
|
+
chroma = 0;
|
|
514
|
+
} else if (tone === 100) {
|
|
515
|
+
lightness = 1;
|
|
516
|
+
chroma = 0;
|
|
517
|
+
} else {
|
|
518
|
+
lightness = (tone / 100) ** 0.8;
|
|
519
|
+
const chromaMultiplier = tone < 20 || tone > 90 ? 0.3 + 0.7 * Math.sin(tone / 100 * Math.PI) : 0.8 + 0.2 * Math.sin(tone / 100 * Math.PI);
|
|
520
|
+
chroma = baseChroma * chromaMultiplier;
|
|
521
|
+
}
|
|
522
|
+
const color = new Color("oklch", [lightness, chroma, baseHue]);
|
|
523
|
+
return color.toString({ format: "hex" });
|
|
524
|
+
};
|
|
525
|
+
return Object.fromEntries(
|
|
526
|
+
tones.map((tone) => [
|
|
527
|
+
`primary${tone}`,
|
|
528
|
+
transformColorToToken(`primary${tone}`, generateToneColor(tone))
|
|
529
|
+
])
|
|
530
|
+
);
|
|
531
|
+
};
|
|
532
|
+
var harmonyBlackAndWhiteTokens = (sourceColor) => {
|
|
533
|
+
let baseHue = 0;
|
|
534
|
+
if (sourceColor) {
|
|
535
|
+
const sourceOklch = sourceColor.to("oklch");
|
|
536
|
+
baseHue = Number.isNaN(sourceOklch.h) ? 0 : sourceOklch.h;
|
|
537
|
+
}
|
|
538
|
+
const enhancedWhite = new Color("oklch", [0.99, 2e-3, baseHue]);
|
|
539
|
+
const enhancedBlack = new Color("oklch", [0.05, 5e-3, baseHue]);
|
|
540
|
+
return {
|
|
541
|
+
white: {
|
|
542
|
+
name: "white",
|
|
543
|
+
value: transformHexToOkLch(
|
|
544
|
+
`light-dark(${enhancedWhite.toString({ format: "hex" })}, ${enhancedWhite.toString({ format: "hex" })})`
|
|
545
|
+
)
|
|
546
|
+
},
|
|
547
|
+
black: {
|
|
548
|
+
name: "black",
|
|
549
|
+
value: transformHexToOkLch(
|
|
550
|
+
`light-dark(${enhancedBlack.toString({ format: "hex" })}, ${enhancedBlack.toString({ format: "hex" })})`
|
|
551
|
+
)
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/lib/css/strategy/harmony/index.ts
|
|
557
|
+
var harmonyColorStrategy = (color) => {
|
|
558
|
+
const sourceColor = theme(color);
|
|
559
|
+
return {
|
|
560
|
+
primaryPalette: harmonyPrimaryPaletteTokens(sourceColor),
|
|
561
|
+
lightDark: harmonyLightDarkTokens(sourceColor),
|
|
562
|
+
blackAndWhite: harmonyBlackAndWhiteTokens(sourceColor)
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/lib/css/strategy/material/material-colors.ts
|
|
567
|
+
import {
|
|
568
|
+
argbFromHex,
|
|
569
|
+
hexFromArgb,
|
|
570
|
+
themeFromSourceColor
|
|
571
|
+
} from "@material/material-color-utilities";
|
|
572
|
+
import Color2 from "colorjs.io";
|
|
573
|
+
var theme2 = (color) => themeFromSourceColor(argbFromHex(color));
|
|
574
|
+
var transformHexToOkLch2 = (color) => {
|
|
575
|
+
const oklchColor = new Color2(color).to("oklch");
|
|
576
|
+
return oklchColor.toString({ precision: 2 });
|
|
577
|
+
};
|
|
578
|
+
var transformColorToToken2 = (name, color) => {
|
|
579
|
+
return {
|
|
580
|
+
name: `color-${name}`,
|
|
581
|
+
value: transformHexToOkLch2(hexFromArgb(color))
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
var lightDarkTokens = (theme3) => {
|
|
585
|
+
const light = Object.fromEntries(
|
|
586
|
+
Object.entries(theme3.schemes.light.toJSON()).map(([key, value]) => [
|
|
587
|
+
key,
|
|
588
|
+
transformHexToOkLch2(hexFromArgb(value))
|
|
589
|
+
])
|
|
590
|
+
);
|
|
591
|
+
const dark = Object.fromEntries(
|
|
592
|
+
Object.entries(theme3.schemes.dark.toJSON()).map(([key, value]) => [
|
|
593
|
+
key,
|
|
594
|
+
transformHexToOkLch2(hexFromArgb(value))
|
|
595
|
+
])
|
|
596
|
+
);
|
|
597
|
+
return Object.entries(light).reduce((acc, [colorName, lightToken]) => {
|
|
598
|
+
const darkToken = dark[colorName];
|
|
599
|
+
if (darkToken) {
|
|
600
|
+
acc[colorName] = {
|
|
601
|
+
name: `color-${colorName}`,
|
|
602
|
+
value: `light-dark(${lightToken}, ${darkToken})`
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
return acc;
|
|
606
|
+
}, {});
|
|
607
|
+
};
|
|
608
|
+
var primaryPaletteTokens = (theme3) => {
|
|
609
|
+
const tones = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100];
|
|
610
|
+
return Object.fromEntries(
|
|
611
|
+
tones.map((tone) => [
|
|
612
|
+
`primary${tone}`,
|
|
613
|
+
transformColorToToken2(
|
|
614
|
+
`primary${tone}`,
|
|
615
|
+
theme3.palettes.primary.tone(tone)
|
|
616
|
+
)
|
|
617
|
+
])
|
|
618
|
+
);
|
|
619
|
+
};
|
|
620
|
+
var blackAndWhiteTokens = () => {
|
|
621
|
+
return {
|
|
622
|
+
white: {
|
|
623
|
+
name: "white",
|
|
624
|
+
value: "#fff"
|
|
625
|
+
},
|
|
626
|
+
black: {
|
|
627
|
+
name: "black",
|
|
628
|
+
value: "#000"
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// src/lib/css/strategy/material/index.ts
|
|
634
|
+
var materialColorStrategy = (color) => {
|
|
635
|
+
const generatedTheme = theme2(color);
|
|
636
|
+
return {
|
|
637
|
+
primaryPalette: primaryPaletteTokens(generatedTheme),
|
|
638
|
+
lightDark: lightDarkTokens(generatedTheme),
|
|
639
|
+
blackAndWhite: blackAndWhiteTokens()
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// src/lib/css/strategy/index.ts
|
|
644
|
+
var colorStrategy = (strategy, color) => {
|
|
645
|
+
switch (strategy) {
|
|
646
|
+
case "material": {
|
|
647
|
+
return materialColorStrategy(color);
|
|
648
|
+
}
|
|
649
|
+
case "harmony": {
|
|
650
|
+
return harmonyColorStrategy(color);
|
|
651
|
+
}
|
|
652
|
+
default:
|
|
653
|
+
throw new Error(`Unknown color strategy: ${strategy}`);
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
208
657
|
// src/lib/css/index.ts
|
|
209
658
|
var transformTokenToCssObject = (token) => {
|
|
210
659
|
const name = `--${transformCase(token.name, "KEBAB" /* KEBAB */)}`;
|
|
@@ -225,18 +674,8 @@ var buildForCategory = (category, tokens) => {
|
|
|
225
674
|
}
|
|
226
675
|
return output;
|
|
227
676
|
};
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
name: "white",
|
|
231
|
-
value: "#fff"
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
name: "black",
|
|
235
|
-
value: "#000"
|
|
236
|
-
}
|
|
237
|
-
];
|
|
238
|
-
var buildCategoryDesignTokens = (color) => {
|
|
239
|
-
const generatedTheme = theme(color);
|
|
677
|
+
var buildCategoryDesignTokens = (color, strategy = "harmony") => {
|
|
678
|
+
const strategyResult = colorStrategy(strategy, color);
|
|
240
679
|
return [
|
|
241
680
|
{
|
|
242
681
|
category: "Reset Colors",
|
|
@@ -249,11 +688,13 @@ var buildCategoryDesignTokens = (color) => {
|
|
|
249
688
|
},
|
|
250
689
|
{
|
|
251
690
|
category: "Primary Colors",
|
|
252
|
-
tokens:
|
|
691
|
+
tokens: Object.values(strategyResult.primaryPalette).concat(
|
|
692
|
+
Object.values(strategyResult.blackAndWhite)
|
|
693
|
+
)
|
|
253
694
|
},
|
|
254
695
|
{
|
|
255
|
-
category: "
|
|
256
|
-
tokens:
|
|
696
|
+
category: "Palette Colors",
|
|
697
|
+
tokens: Object.values(strategyResult.lightDark)
|
|
257
698
|
},
|
|
258
699
|
{
|
|
259
700
|
category: "Scale",
|
|
@@ -298,9 +739,10 @@ var buildCategoryDesignTokens = (color) => {
|
|
|
298
739
|
}
|
|
299
740
|
];
|
|
300
741
|
};
|
|
301
|
-
var runCss = (color) => {
|
|
302
|
-
const categoryTokens = buildCategoryDesignTokens(color);
|
|
742
|
+
var runCss = (color, strategy = "harmony") => {
|
|
743
|
+
const categoryTokens = buildCategoryDesignTokens(color, strategy);
|
|
303
744
|
const output = [];
|
|
745
|
+
output.push(`/* Aakaar Design Tokens: Source: ${color} */`);
|
|
304
746
|
output.push("@theme {");
|
|
305
747
|
for (const category of categoryTokens) {
|
|
306
748
|
output.push(...buildForCategory(category.category, category.tokens));
|