@agent-native/design-system 0.0.0-stage → 0.229.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/LICENSE +21 -0
- package/README.md +78 -2
- package/THIRD_PARTY_NOTICES.md +58 -0
- package/css/appearances.css +91 -0
- package/css/main.css +174 -0
- package/css/parts/accordion.css +104 -0
- package/css/parts/alert-dialog.css +159 -0
- package/css/parts/app-shell.css +45 -0
- package/css/parts/aspect-ratio.css +20 -0
- package/css/parts/autocomplete.css +366 -0
- package/css/parts/avatar.css +108 -0
- package/css/parts/badge.css +100 -0
- package/css/parts/blockquote.css +23 -0
- package/css/parts/button.css +238 -0
- package/css/parts/callout.css +108 -0
- package/css/parts/card.css +144 -0
- package/css/parts/checkbox-cards.css +59 -0
- package/css/parts/checkbox-group.css +20 -0
- package/css/parts/checkbox.css +127 -0
- package/css/parts/code.css +194 -0
- package/css/parts/collapsible.css +40 -0
- package/css/parts/combobox.css +171 -0
- package/css/parts/context-menu.css +18 -0
- package/css/parts/data-list.css +130 -0
- package/css/parts/dialog.css +251 -0
- package/css/parts/drawer.css +289 -0
- package/css/parts/em.css +16 -0
- package/css/parts/field.css +55 -0
- package/css/parts/fieldset.css +34 -0
- package/css/parts/form.css +18 -0
- package/css/parts/heading.css +25 -0
- package/css/parts/icon-button.css +30 -0
- package/css/parts/input.css +206 -0
- package/css/parts/inset.css +90 -0
- package/css/parts/item.css +208 -0
- package/css/parts/kbd.css +126 -0
- package/css/parts/link.css +99 -0
- package/css/parts/menu.css +342 -0
- package/css/parts/menubar.css +71 -0
- package/css/parts/meter.css +112 -0
- package/css/parts/navigation-menu.css +199 -0
- package/css/parts/number-field.css +124 -0
- package/css/parts/otp-field.css +137 -0
- package/css/parts/page-header.css +45 -0
- package/css/parts/popover.css +149 -0
- package/css/parts/preview-card.css +116 -0
- package/css/parts/progress.css +159 -0
- package/css/parts/quote.css +18 -0
- package/css/parts/radio-cards.css +188 -0
- package/css/parts/radio-group.css +124 -0
- package/css/parts/scroll-area.css +95 -0
- package/css/parts/segmented-control.css +191 -0
- package/css/parts/select.css +378 -0
- package/css/parts/separator.css +48 -0
- package/css/parts/sidebar.css +211 -0
- package/css/parts/skeleton.css +65 -0
- package/css/parts/slider.css +156 -0
- package/css/parts/spinner.css +52 -0
- package/css/parts/strong.css +15 -0
- package/css/parts/switch.css +138 -0
- package/css/parts/tab-nav.css +48 -0
- package/css/parts/table.css +177 -0
- package/css/parts/tabs.css +214 -0
- package/css/parts/text-area.css +140 -0
- package/css/parts/text.css +245 -0
- package/css/parts/toast.css +302 -0
- package/css/parts/toggle-group.css +25 -0
- package/css/parts/toggle.css +181 -0
- package/css/parts/toolbar.css +133 -0
- package/css/parts/tooltip.css +61 -0
- package/css/parts/visually-hidden.css +21 -0
- package/css/styles.css +73 -0
- package/css/themes/agent-native.css +2321 -0
- package/css/themes/analytics.css +1159 -0
- package/css/themes/assets.css +1159 -0
- package/css/themes/baseline.css +1107 -0
- package/css/themes/brain.css +1159 -0
- package/css/themes/calendar.css +1159 -0
- package/css/themes/chat.css +1159 -0
- package/css/themes/clips.css +1159 -0
- package/css/themes/content.css +1159 -0
- package/css/themes/crm.css +1159 -0
- package/css/themes/design.css +1159 -0
- package/css/themes/desktop.css +1159 -0
- package/css/themes/dispatch.css +1159 -0
- package/css/themes/docs.css +1159 -0
- package/css/themes/factory.css +1159 -0
- package/css/themes/forms.css +1159 -0
- package/css/themes/mail.css +1159 -0
- package/css/themes/plan.css +1159 -0
- package/css/themes/slides.css +1159 -0
- package/css/themes/tasks.css +1159 -0
- package/css/tokens.css +1249 -0
- package/package.json +67 -4
- package/src/catalog/components/alert-dialog.ts +9 -0
- package/src/catalog/components/aspect-ratio.ts +6 -0
- package/src/catalog/components/autocomplete.ts +23 -0
- package/src/catalog/components/avatar.ts +16 -0
- package/src/catalog/components/badge.ts +19 -0
- package/src/catalog/components/blockquote.ts +10 -0
- package/src/catalog/components/button.ts +24 -0
- package/src/catalog/components/callout.ts +17 -0
- package/src/catalog/components/card.ts +10 -0
- package/src/catalog/components/checkbox-cards.ts +14 -0
- package/src/catalog/components/checkbox-group.ts +13 -0
- package/src/catalog/components/checkbox.ts +13 -0
- package/src/catalog/components/code.ts +22 -0
- package/src/catalog/components/combobox.ts +23 -0
- package/src/catalog/components/context-menu.ts +20 -0
- package/src/catalog/components/data-list.ts +14 -0
- package/src/catalog/components/dialog.ts +9 -0
- package/src/catalog/components/drawer.ts +9 -0
- package/src/catalog/components/em.ts +7 -0
- package/src/catalog/components/heading.ts +11 -0
- package/src/catalog/components/index.ts +54 -0
- package/src/catalog/components/input.ts +23 -0
- package/src/catalog/components/inset.ts +15 -0
- package/src/catalog/components/item.ts +21 -0
- package/src/catalog/components/kbd.ts +9 -0
- package/src/catalog/components/link.ts +19 -0
- package/src/catalog/components/menu.ts +20 -0
- package/src/catalog/components/menubar.ts +20 -0
- package/src/catalog/components/meter.ts +19 -0
- package/src/catalog/components/number-field.ts +10 -0
- package/src/catalog/components/otp-field.ts +9 -0
- package/src/catalog/components/popover.ts +9 -0
- package/src/catalog/components/preview-card.ts +9 -0
- package/src/catalog/components/progress.ts +24 -0
- package/src/catalog/components/quote.ts +7 -0
- package/src/catalog/components/radio-cards.ts +14 -0
- package/src/catalog/components/radio-group.ts +13 -0
- package/src/catalog/components/scroll-area.ts +15 -0
- package/src/catalog/components/segmented-control.ts +8 -0
- package/src/catalog/components/select.ts +26 -0
- package/src/catalog/components/separator.ts +14 -0
- package/src/catalog/components/skeleton.ts +8 -0
- package/src/catalog/components/slider.ts +19 -0
- package/src/catalog/components/spinner.ts +15 -0
- package/src/catalog/components/strong.ts +7 -0
- package/src/catalog/components/switch.ts +19 -0
- package/src/catalog/components/tab-nav.ts +18 -0
- package/src/catalog/components/table.ts +34 -0
- package/src/catalog/components/tabs.ts +18 -0
- package/src/catalog/components/text-area.ts +24 -0
- package/src/catalog/components/text.ts +11 -0
- package/src/catalog/components/toast.ts +12 -0
- package/src/catalog/components/toggle-group.ts +17 -0
- package/src/catalog/components/toggle.ts +17 -0
- package/src/catalog/components/toolbar.ts +6 -0
- package/src/catalog/index.ts +4 -0
- package/src/catalog/parts.ts +915 -0
- package/src/catalog/prop-types-source.ts +93 -0
- package/src/catalog/prop-types.generated.ts +1402 -0
- package/src/catalog/props.ts +225 -0
- package/src/css.ts +318 -0
- package/src/generated-css.ts +21 -0
- package/src/index.ts +8 -0
- package/src/model/compare.ts +127 -0
- package/src/model/dom.ts +253 -0
- package/src/model/ids.ts +25 -0
- package/src/model/index.ts +6 -0
- package/src/model/styles.ts +254 -0
- package/src/model/types.ts +97 -0
- package/src/model/validate.ts +133 -0
- package/src/themes/appearances.ts +105 -0
- package/src/themes/baseline.ts +27 -0
- package/src/themes/index.ts +85 -0
- package/src/themes/reference.ts +9 -0
- package/src/themes/shadcn.ts +239 -0
- package/src/themes/types.ts +53 -0
- package/src/tokens/at.ts +13 -0
- package/src/tokens/base.ts +48 -0
- package/src/tokens/color/bezier.ts +111 -0
- package/src/tokens/color/index.ts +2 -0
- package/src/tokens/color/radix-generator.ts +516 -0
- package/src/tokens/dtcg.ts +298 -0
- package/src/tokens/files/foundations.tokens.json +318 -0
- package/src/tokens/files/palette.tokens.json +58 -0
- package/src/tokens/files/themes/agent-native.dark.tokens.json +405 -0
- package/src/tokens/files/themes/agent-native.light.tokens.json +405 -0
- package/src/tokens/files/themes/analytics.dark.tokens.json +391 -0
- package/src/tokens/files/themes/analytics.light.tokens.json +391 -0
- package/src/tokens/files/themes/assets.dark.tokens.json +391 -0
- package/src/tokens/files/themes/assets.light.tokens.json +391 -0
- package/src/tokens/files/themes/brain.dark.tokens.json +391 -0
- package/src/tokens/files/themes/brain.light.tokens.json +391 -0
- package/src/tokens/files/themes/calendar.dark.tokens.json +391 -0
- package/src/tokens/files/themes/calendar.light.tokens.json +391 -0
- package/src/tokens/files/themes/chat.dark.tokens.json +391 -0
- package/src/tokens/files/themes/chat.light.tokens.json +391 -0
- package/src/tokens/files/themes/clips.dark.tokens.json +391 -0
- package/src/tokens/files/themes/clips.light.tokens.json +391 -0
- package/src/tokens/files/themes/content.dark.tokens.json +391 -0
- package/src/tokens/files/themes/content.light.tokens.json +391 -0
- package/src/tokens/files/themes/crm.dark.tokens.json +391 -0
- package/src/tokens/files/themes/crm.light.tokens.json +391 -0
- package/src/tokens/files/themes/design.dark.tokens.json +391 -0
- package/src/tokens/files/themes/design.light.tokens.json +391 -0
- package/src/tokens/files/themes/desktop.dark.tokens.json +391 -0
- package/src/tokens/files/themes/desktop.light.tokens.json +391 -0
- package/src/tokens/files/themes/dispatch.dark.tokens.json +391 -0
- package/src/tokens/files/themes/dispatch.light.tokens.json +391 -0
- package/src/tokens/files/themes/docs.dark.tokens.json +391 -0
- package/src/tokens/files/themes/docs.light.tokens.json +391 -0
- package/src/tokens/files/themes/factory.dark.tokens.json +391 -0
- package/src/tokens/files/themes/factory.light.tokens.json +391 -0
- package/src/tokens/files/themes/forms.dark.tokens.json +391 -0
- package/src/tokens/files/themes/forms.light.tokens.json +391 -0
- package/src/tokens/files/themes/mail.dark.tokens.json +391 -0
- package/src/tokens/files/themes/mail.light.tokens.json +391 -0
- package/src/tokens/files/themes/plan.dark.tokens.json +391 -0
- package/src/tokens/files/themes/plan.light.tokens.json +391 -0
- package/src/tokens/files/themes/slides.dark.tokens.json +391 -0
- package/src/tokens/files/themes/slides.light.tokens.json +391 -0
- package/src/tokens/files/themes/tasks.dark.tokens.json +391 -0
- package/src/tokens/files/themes/tasks.light.tokens.json +391 -0
- package/src/tokens/palette.ts +354 -0
- package/src/tokens/primitives.ts +84 -0
- package/src/tokens/roles.ts +269 -0
- package/src/tokens/round-trip.ts +277 -0
- package/src/tokens/source.ts +302 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Appearance } from "./color/radix-generator.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Appearance-level literals that are not part of any generated scale: the
|
|
5
|
+
* translucent field fill, the dialog scrim, and the shadow tint ramp. Shadows
|
|
6
|
+
* stay black in both appearances; a tinted gray would lighten them in dark.
|
|
7
|
+
*/
|
|
8
|
+
export const BASE_BY_APPEARANCE: Record<
|
|
9
|
+
Appearance,
|
|
10
|
+
{ field: string; overlay: string; shadowTint: readonly string[] }
|
|
11
|
+
> = {
|
|
12
|
+
light: {
|
|
13
|
+
field: "#ffffffe6",
|
|
14
|
+
overlay: "#00000066",
|
|
15
|
+
shadowTint: [
|
|
16
|
+
"#0000000d",
|
|
17
|
+
"#0000001a",
|
|
18
|
+
"#00000026",
|
|
19
|
+
"#00000033",
|
|
20
|
+
"#0000004d",
|
|
21
|
+
"#00000066",
|
|
22
|
+
"#00000080",
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
dark: {
|
|
26
|
+
field: "#00000040",
|
|
27
|
+
overlay: "#00000099",
|
|
28
|
+
shadowTint: [
|
|
29
|
+
"#0000001a",
|
|
30
|
+
"#00000033",
|
|
31
|
+
"#0000004d",
|
|
32
|
+
"#00000066",
|
|
33
|
+
"#00000080",
|
|
34
|
+
"#00000099",
|
|
35
|
+
"#000000b3",
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** Tailwind v4's default shadows, which the app themes reproduce exactly. */
|
|
41
|
+
export const TAILWIND_SHADOWS = {
|
|
42
|
+
xs: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
|
|
43
|
+
sm: "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",
|
|
44
|
+
md: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
|
45
|
+
lg: "0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",
|
|
46
|
+
xl: "0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)",
|
|
47
|
+
"2xl": "0 25px 50px -12px rgb(0 0 0 / 0.25)",
|
|
48
|
+
} as const;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { at } from "../at.js";
|
|
2
|
+
|
|
3
|
+
const NEWTON_ITERATIONS = 4;
|
|
4
|
+
const NEWTON_MIN_SLOPE = 0.001;
|
|
5
|
+
const SUBDIVISION_PRECISION = 0.0000001;
|
|
6
|
+
const SUBDIVISION_MAX_ITERATIONS = 10;
|
|
7
|
+
const SPLINE_TABLE_SIZE = 11;
|
|
8
|
+
const SAMPLE_STEP_SIZE = 1 / (SPLINE_TABLE_SIZE - 1);
|
|
9
|
+
|
|
10
|
+
const a = (a1: number, a2: number) => 1 - 3 * a2 + 3 * a1;
|
|
11
|
+
const b = (a1: number, a2: number) => 3 * a2 - 6 * a1;
|
|
12
|
+
const c = (a1: number) => 3 * a1;
|
|
13
|
+
|
|
14
|
+
function calcBezier(t: number, a1: number, a2: number): number {
|
|
15
|
+
return ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getSlope(t: number, a1: number, a2: number): number {
|
|
19
|
+
return 3 * a(a1, a2) * t * t + 2 * b(a1, a2) * t + c(a1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function binarySubdivide(
|
|
23
|
+
x: number,
|
|
24
|
+
start: number,
|
|
25
|
+
end: number,
|
|
26
|
+
x1: number,
|
|
27
|
+
x2: number,
|
|
28
|
+
): number {
|
|
29
|
+
let currentX: number;
|
|
30
|
+
let currentT: number;
|
|
31
|
+
let i = 0;
|
|
32
|
+
do {
|
|
33
|
+
currentT = start + (end - start) / 2;
|
|
34
|
+
currentX = calcBezier(currentT, x1, x2) - x;
|
|
35
|
+
if (currentX > 0) end = currentT;
|
|
36
|
+
else start = currentT;
|
|
37
|
+
} while (
|
|
38
|
+
Math.abs(currentX) > SUBDIVISION_PRECISION &&
|
|
39
|
+
++i < SUBDIVISION_MAX_ITERATIONS
|
|
40
|
+
);
|
|
41
|
+
return currentT;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function newtonRaphsonIterate(
|
|
45
|
+
x: number,
|
|
46
|
+
guessT: number,
|
|
47
|
+
x1: number,
|
|
48
|
+
x2: number,
|
|
49
|
+
): number {
|
|
50
|
+
let t = guessT;
|
|
51
|
+
for (let i = 0; i < NEWTON_ITERATIONS; ++i) {
|
|
52
|
+
const slope = getSlope(t, x1, x2);
|
|
53
|
+
if (slope === 0) return t;
|
|
54
|
+
t -= (calcBezier(t, x1, x2) - x) / slope;
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function cubicBezier(
|
|
60
|
+
x1: number,
|
|
61
|
+
y1: number,
|
|
62
|
+
x2: number,
|
|
63
|
+
y2: number,
|
|
64
|
+
): (x: number) => number {
|
|
65
|
+
if (!(0 <= x1 && x1 <= 1 && 0 <= x2 && x2 <= 1)) {
|
|
66
|
+
throw new RangeError("Bezier x values must be in the [0, 1] range");
|
|
67
|
+
}
|
|
68
|
+
if (x1 === y1 && x2 === y2) return (x) => x;
|
|
69
|
+
|
|
70
|
+
const samples = new Float32Array(SPLINE_TABLE_SIZE);
|
|
71
|
+
for (let i = 0; i < SPLINE_TABLE_SIZE; ++i) {
|
|
72
|
+
samples[i] = calcBezier(i * SAMPLE_STEP_SIZE, x1, x2);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getTForX(x: number): number {
|
|
76
|
+
let intervalStart = 0;
|
|
77
|
+
let currentSample = 1;
|
|
78
|
+
const lastSample = SPLINE_TABLE_SIZE - 1;
|
|
79
|
+
for (
|
|
80
|
+
;
|
|
81
|
+
currentSample !== lastSample && at(samples, currentSample) <= x;
|
|
82
|
+
++currentSample
|
|
83
|
+
) {
|
|
84
|
+
intervalStart += SAMPLE_STEP_SIZE;
|
|
85
|
+
}
|
|
86
|
+
--currentSample;
|
|
87
|
+
|
|
88
|
+
const dist =
|
|
89
|
+
(x - at(samples, currentSample)) /
|
|
90
|
+
(at(samples, currentSample + 1) - at(samples, currentSample));
|
|
91
|
+
const guessT = intervalStart + dist * SAMPLE_STEP_SIZE;
|
|
92
|
+
const initialSlope = getSlope(guessT, x1, x2);
|
|
93
|
+
if (initialSlope >= NEWTON_MIN_SLOPE) {
|
|
94
|
+
return newtonRaphsonIterate(x, guessT, x1, x2);
|
|
95
|
+
}
|
|
96
|
+
if (initialSlope === 0) return guessT;
|
|
97
|
+
return binarySubdivide(
|
|
98
|
+
x,
|
|
99
|
+
intervalStart,
|
|
100
|
+
intervalStart + SAMPLE_STEP_SIZE,
|
|
101
|
+
x1,
|
|
102
|
+
x2,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (x) => {
|
|
107
|
+
if (x === 0) return 0;
|
|
108
|
+
if (x === 1) return 1;
|
|
109
|
+
return calcBezier(getTForX(x), y1, y2);
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
//
|
|
2
|
+
|
|
3
|
+
import * as RadixColors from "@radix-ui/colors";
|
|
4
|
+
import Color from "colorjs.io";
|
|
5
|
+
|
|
6
|
+
import { at } from "../at.js";
|
|
7
|
+
import { cubicBezier } from "./bezier.js";
|
|
8
|
+
|
|
9
|
+
export type Scale12<T = string> = [T, T, T, T, T, T, T, T, T, T, T, T];
|
|
10
|
+
export type Appearance = "light" | "dark";
|
|
11
|
+
|
|
12
|
+
const STEPS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] as const;
|
|
13
|
+
|
|
14
|
+
export const RADIX_GRAY_SCALE_NAMES = [
|
|
15
|
+
"gray",
|
|
16
|
+
"mauve",
|
|
17
|
+
"slate",
|
|
18
|
+
"sage",
|
|
19
|
+
"olive",
|
|
20
|
+
"sand",
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
export const RADIX_SCALE_NAMES = [
|
|
24
|
+
...RADIX_GRAY_SCALE_NAMES,
|
|
25
|
+
"tomato",
|
|
26
|
+
"red",
|
|
27
|
+
"ruby",
|
|
28
|
+
"crimson",
|
|
29
|
+
"pink",
|
|
30
|
+
"plum",
|
|
31
|
+
"purple",
|
|
32
|
+
"violet",
|
|
33
|
+
"iris",
|
|
34
|
+
"indigo",
|
|
35
|
+
"blue",
|
|
36
|
+
"cyan",
|
|
37
|
+
"teal",
|
|
38
|
+
"jade",
|
|
39
|
+
"green",
|
|
40
|
+
"grass",
|
|
41
|
+
"brown",
|
|
42
|
+
"orange",
|
|
43
|
+
"sky",
|
|
44
|
+
"mint",
|
|
45
|
+
"lime",
|
|
46
|
+
"yellow",
|
|
47
|
+
"amber",
|
|
48
|
+
] as const;
|
|
49
|
+
|
|
50
|
+
export type RadixScaleName = (typeof RADIX_SCALE_NAMES)[number];
|
|
51
|
+
type RadixGrayScaleName = (typeof RADIX_GRAY_SCALE_NAMES)[number];
|
|
52
|
+
|
|
53
|
+
const radixPalettes = RadixColors as unknown as Record<
|
|
54
|
+
string,
|
|
55
|
+
Record<string, string> | undefined
|
|
56
|
+
>;
|
|
57
|
+
|
|
58
|
+
function readScale(name: string, appearance: Appearance): Scale12<Color> {
|
|
59
|
+
const key = appearance === "light" ? `${name}P3` : `${name}DarkP3`;
|
|
60
|
+
const palette = radixPalettes[key];
|
|
61
|
+
if (!palette) throw new Error(`Missing Radix scale ${key}`);
|
|
62
|
+
return Object.values(palette).map((value) =>
|
|
63
|
+
new Color(value).to("oklch"),
|
|
64
|
+
) as Scale12<Color>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type ScaleTable<Name extends string> = Record<Name, Scale12<Color>>;
|
|
68
|
+
|
|
69
|
+
let cachedScales:
|
|
70
|
+
| Record<
|
|
71
|
+
Appearance,
|
|
72
|
+
{
|
|
73
|
+
all: ScaleTable<RadixScaleName>;
|
|
74
|
+
grays: ScaleTable<RadixGrayScaleName>;
|
|
75
|
+
}
|
|
76
|
+
>
|
|
77
|
+
| undefined;
|
|
78
|
+
|
|
79
|
+
function referenceScales(appearance: Appearance) {
|
|
80
|
+
if (!cachedScales) {
|
|
81
|
+
const build = (mode: Appearance) => ({
|
|
82
|
+
all: Object.fromEntries(
|
|
83
|
+
RADIX_SCALE_NAMES.map((name) => [name, readScale(name, mode)]),
|
|
84
|
+
) as ScaleTable<RadixScaleName>,
|
|
85
|
+
grays: Object.fromEntries(
|
|
86
|
+
RADIX_GRAY_SCALE_NAMES.map((name) => [name, readScale(name, mode)]),
|
|
87
|
+
) as ScaleTable<RadixGrayScaleName>,
|
|
88
|
+
});
|
|
89
|
+
cachedScales = { light: build("light"), dark: build("dark") };
|
|
90
|
+
}
|
|
91
|
+
return cachedScales[appearance];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const L = (color: Color) => color.coords[0] ?? 0;
|
|
95
|
+
const C = (color: Color) => color.coords[1] ?? 0;
|
|
96
|
+
const H = (color: Color) => color.coords[2];
|
|
97
|
+
const hasHue = (hue: number | null): hue is number =>
|
|
98
|
+
hue !== null && !Number.isNaN(hue);
|
|
99
|
+
|
|
100
|
+
export interface RadixColorsInput {
|
|
101
|
+
appearance: Appearance;
|
|
102
|
+
accent: string;
|
|
103
|
+
gray: string;
|
|
104
|
+
background: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface RadixColorsOutput {
|
|
108
|
+
accentScale: Scale12;
|
|
109
|
+
accentScaleAlpha: Scale12;
|
|
110
|
+
accentScaleWideGamut: Scale12;
|
|
111
|
+
accentScaleAlphaWideGamut: Scale12;
|
|
112
|
+
accentContrast: string;
|
|
113
|
+
grayScale: Scale12;
|
|
114
|
+
grayScaleAlpha: Scale12;
|
|
115
|
+
grayScaleWideGamut: Scale12;
|
|
116
|
+
grayScaleAlphaWideGamut: Scale12;
|
|
117
|
+
graySurface: string;
|
|
118
|
+
graySurfaceWideGamut: string;
|
|
119
|
+
accentSurface: string;
|
|
120
|
+
accentSurfaceWideGamut: string;
|
|
121
|
+
background: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function generateRadixColors({
|
|
125
|
+
appearance,
|
|
126
|
+
...args
|
|
127
|
+
}: RadixColorsInput): RadixColorsOutput {
|
|
128
|
+
const { all: allScales, grays: grayScales } = referenceScales(appearance);
|
|
129
|
+
const backgroundColor = parseColor(args.background, "background").to("oklch");
|
|
130
|
+
|
|
131
|
+
const grayBaseColor = parseColor(args.gray, "gray").to("oklch");
|
|
132
|
+
const grayScaleColors = getScaleFromColor(
|
|
133
|
+
grayBaseColor,
|
|
134
|
+
grayScales,
|
|
135
|
+
backgroundColor,
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const accentBaseColor = parseColor(args.accent, "accent").to("oklch");
|
|
139
|
+
let accentScaleColors = getScaleFromColor(
|
|
140
|
+
accentBaseColor,
|
|
141
|
+
allScales,
|
|
142
|
+
backgroundColor,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const backgroundHex = toHex(backgroundColor);
|
|
146
|
+
|
|
147
|
+
const accentBaseHex = toHex(accentBaseColor);
|
|
148
|
+
if (accentBaseHex === "#000000" || accentBaseHex === "#ffffff") {
|
|
149
|
+
accentScaleColors = grayScaleColors.map((color) =>
|
|
150
|
+
color.clone(),
|
|
151
|
+
) as Scale12<Color>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const [accent9Color, accentContrastColor] = getStep9Colors(
|
|
155
|
+
accentScaleColors,
|
|
156
|
+
accentBaseColor,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
accentScaleColors[8] = accent9Color;
|
|
160
|
+
accentScaleColors[9] = getButtonHoverColor(accent9Color, [accentScaleColors]);
|
|
161
|
+
|
|
162
|
+
const textChromaCap = Math.max(
|
|
163
|
+
C(accentScaleColors[8]),
|
|
164
|
+
C(accentScaleColors[7]),
|
|
165
|
+
);
|
|
166
|
+
accentScaleColors[10].coords[1] = Math.min(
|
|
167
|
+
textChromaCap,
|
|
168
|
+
C(accentScaleColors[10]),
|
|
169
|
+
);
|
|
170
|
+
accentScaleColors[11].coords[1] = Math.min(
|
|
171
|
+
textChromaCap,
|
|
172
|
+
C(accentScaleColors[11]),
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const accentScaleHex = accentScaleColors.map(toHex) as Scale12;
|
|
176
|
+
const accentScaleWideGamut = accentScaleColors.map(toOklchString) as Scale12;
|
|
177
|
+
const grayScaleHex = grayScaleColors.map(toHex) as Scale12;
|
|
178
|
+
const grayScaleWideGamut = grayScaleColors.map(toOklchString) as Scale12;
|
|
179
|
+
|
|
180
|
+
const surfaceAlpha = appearance === "light" ? 0.8 : 0.5;
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
accentScale: accentScaleHex,
|
|
184
|
+
accentScaleAlpha: accentScaleHex.map((color) =>
|
|
185
|
+
getAlphaColorSrgb(color, backgroundHex),
|
|
186
|
+
) as Scale12,
|
|
187
|
+
accentScaleWideGamut,
|
|
188
|
+
accentScaleAlphaWideGamut: accentScaleHex.map((color) =>
|
|
189
|
+
getAlphaColorP3(color, backgroundHex),
|
|
190
|
+
) as Scale12,
|
|
191
|
+
accentContrast: toHex(accentContrastColor),
|
|
192
|
+
|
|
193
|
+
grayScale: grayScaleHex,
|
|
194
|
+
grayScaleAlpha: grayScaleHex.map((color) =>
|
|
195
|
+
getAlphaColorSrgb(color, backgroundHex),
|
|
196
|
+
) as Scale12,
|
|
197
|
+
grayScaleWideGamut,
|
|
198
|
+
grayScaleAlphaWideGamut: grayScaleHex.map((color) =>
|
|
199
|
+
getAlphaColorP3(color, backgroundHex),
|
|
200
|
+
) as Scale12,
|
|
201
|
+
|
|
202
|
+
graySurface: appearance === "light" ? "#ffffffcc" : "rgba(0, 0, 0, 0.05)",
|
|
203
|
+
graySurfaceWideGamut:
|
|
204
|
+
appearance === "light"
|
|
205
|
+
? "color(display-p3 1 1 1 / 80%)"
|
|
206
|
+
: "color(display-p3 0 0 0 / 5%)",
|
|
207
|
+
|
|
208
|
+
accentSurface: getAlphaColorSrgb(
|
|
209
|
+
accentScaleHex[1],
|
|
210
|
+
backgroundHex,
|
|
211
|
+
surfaceAlpha,
|
|
212
|
+
),
|
|
213
|
+
accentSurfaceWideGamut: getAlphaColorP3(
|
|
214
|
+
accentScaleWideGamut[1],
|
|
215
|
+
backgroundHex,
|
|
216
|
+
surfaceAlpha,
|
|
217
|
+
),
|
|
218
|
+
|
|
219
|
+
background: backgroundHex,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function parseColor(value: string, role: string): Color {
|
|
224
|
+
try {
|
|
225
|
+
return new Color(value);
|
|
226
|
+
} catch (cause) {
|
|
227
|
+
throw new TypeError(`Unsupported ${role} color: ${value}`, { cause });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function getStep9Colors(
|
|
232
|
+
scale: Scale12<Color>,
|
|
233
|
+
accentBaseColor: Color,
|
|
234
|
+
): [Color, Color] {
|
|
235
|
+
const distance = accentBaseColor.deltaEOK(scale[0]) * 100;
|
|
236
|
+
if (distance < 25) return [scale[8], getTextColor(scale[8])];
|
|
237
|
+
return [accentBaseColor, getTextColor(accentBaseColor)];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function getButtonHoverColor(source: Color, scales: Scale12<Color>[]): Color {
|
|
241
|
+
const l = L(source);
|
|
242
|
+
const c = C(source);
|
|
243
|
+
const h = H(source);
|
|
244
|
+
const newL = l > 0.4 ? l - 0.03 / (l + 0.1) : l + 0.03 / (l + 0.1);
|
|
245
|
+
const newC = l > 0.4 && hasHue(h) ? c * 0.93 + 0 : c;
|
|
246
|
+
const buttonHoverColor = new Color("oklch", [newL, newC, h]);
|
|
247
|
+
|
|
248
|
+
let closestColor = buttonHoverColor;
|
|
249
|
+
let minDistance = Infinity;
|
|
250
|
+
for (const scale of scales) {
|
|
251
|
+
for (const color of scale) {
|
|
252
|
+
const distance = buttonHoverColor.deltaEOK(color);
|
|
253
|
+
if (distance < minDistance) {
|
|
254
|
+
minDistance = distance;
|
|
255
|
+
closestColor = color;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
buttonHoverColor.coords[1] = closestColor.coords[1];
|
|
261
|
+
buttonHoverColor.coords[2] = closestColor.coords[2];
|
|
262
|
+
return buttonHoverColor;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function getScaleFromColor<Name extends string>(
|
|
266
|
+
source: Color,
|
|
267
|
+
scales: ScaleTable<Name>,
|
|
268
|
+
backgroundColor: Color,
|
|
269
|
+
): Scale12<Color> {
|
|
270
|
+
const allColors: { scale: Name; color: Color; distance: number }[] = [];
|
|
271
|
+
for (const name of Object.keys(scales) as Name[]) {
|
|
272
|
+
for (const color of scales[name]) {
|
|
273
|
+
allColors.push({ scale: name, distance: source.deltaEOK(color), color });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
allColors.sort((left, right) => left.distance - right.distance);
|
|
277
|
+
|
|
278
|
+
const closestColors = allColors.filter(
|
|
279
|
+
(color, index, array) =>
|
|
280
|
+
index === array.findIndex((value) => value.scale === color.scale),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
const grayNames = RADIX_GRAY_SCALE_NAMES as readonly string[];
|
|
284
|
+
const allAreGrays = closestColors.every((color) =>
|
|
285
|
+
grayNames.includes(color.scale),
|
|
286
|
+
);
|
|
287
|
+
if (!allAreGrays && grayNames.includes(at(closestColors, 0).scale)) {
|
|
288
|
+
while (grayNames.includes(at(closestColors, 1).scale)) {
|
|
289
|
+
closestColors.splice(1, 1);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const colorA = at(closestColors, 0);
|
|
294
|
+
const colorB = at(closestColors, 1);
|
|
295
|
+
|
|
296
|
+
const a = colorB.distance;
|
|
297
|
+
const b = colorA.distance;
|
|
298
|
+
const c = colorA.color.deltaEOK(colorB.color);
|
|
299
|
+
|
|
300
|
+
const cosA = (b ** 2 + c ** 2 - a ** 2) / (2 * b * c);
|
|
301
|
+
const sinA = Math.sin(Math.acos(cosA));
|
|
302
|
+
const cosB = (a ** 2 + c ** 2 - b ** 2) / (2 * a * c);
|
|
303
|
+
const sinB = Math.sin(Math.acos(cosB));
|
|
304
|
+
const tanC1 = cosA / sinA;
|
|
305
|
+
const tanC2 = cosB / sinB;
|
|
306
|
+
const ratio = Math.max(0, tanC1 / tanC2) * 0.5;
|
|
307
|
+
|
|
308
|
+
const scaleA = scales[colorA.scale];
|
|
309
|
+
const scaleB = scales[colorB.scale];
|
|
310
|
+
const scale = STEPS.map((i) =>
|
|
311
|
+
new Color(Color.mix(scaleA[i], scaleB[i], ratio)).to("oklch"),
|
|
312
|
+
) as Scale12<Color>;
|
|
313
|
+
|
|
314
|
+
const baseColor = at(
|
|
315
|
+
scale
|
|
316
|
+
.slice()
|
|
317
|
+
.sort((left, right) => source.deltaEOK(left) - source.deltaEOK(right)),
|
|
318
|
+
0,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const ratioC = C(source) / C(baseColor);
|
|
322
|
+
for (const color of scale) {
|
|
323
|
+
const scaledChroma = C(color) * ratioC;
|
|
324
|
+
color.coords[1] = Number.isNaN(scaledChroma)
|
|
325
|
+
? C(source) * 1.5
|
|
326
|
+
: Math.min(C(source) * 1.5, scaledChroma);
|
|
327
|
+
color.coords[2] = H(source);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (L(scale[0]) > 0.5) {
|
|
331
|
+
const lightnessScale = scale.map(L);
|
|
332
|
+
const backgroundL = Math.max(0, Math.min(1, L(backgroundColor)));
|
|
333
|
+
const newLightnessScale = transposeProgressionStart(
|
|
334
|
+
backgroundL,
|
|
335
|
+
[1, ...lightnessScale],
|
|
336
|
+
LIGHT_MODE_EASING,
|
|
337
|
+
);
|
|
338
|
+
newLightnessScale.shift();
|
|
339
|
+
newLightnessScale.forEach((lightness, i) => {
|
|
340
|
+
at(scale, i).coords[0] = lightness;
|
|
341
|
+
});
|
|
342
|
+
return scale;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const ease: [number, number, number, number] = [...DARK_MODE_EASING];
|
|
346
|
+
const referenceBackgroundL = L(scale[0]);
|
|
347
|
+
const backgroundL = Math.max(0, Math.min(1, L(backgroundColor)));
|
|
348
|
+
|
|
349
|
+
const ratioL = backgroundL / referenceBackgroundL;
|
|
350
|
+
if (ratioL > 1) {
|
|
351
|
+
const maxRatio = 1.5;
|
|
352
|
+
for (let i = 0; i < ease.length; i++) {
|
|
353
|
+
const metaRatio = (ratioL - 1) * (maxRatio / (maxRatio - 1));
|
|
354
|
+
ease[i] =
|
|
355
|
+
ratioL > maxRatio ? 0 : Math.max(0, at(ease, i) * (1 - metaRatio));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const newLightnessScale = transposeProgressionStart(
|
|
360
|
+
L(backgroundColor),
|
|
361
|
+
scale.map(L),
|
|
362
|
+
ease,
|
|
363
|
+
);
|
|
364
|
+
newLightnessScale.forEach((lightness, i) => {
|
|
365
|
+
at(scale, i).coords[0] = lightness;
|
|
366
|
+
});
|
|
367
|
+
return scale;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function getTextColor(background: Color): Color {
|
|
371
|
+
const white = new Color("oklch", [1, 0, 0]);
|
|
372
|
+
if (Math.abs(white.contrastAPCA(background)) < 40) {
|
|
373
|
+
return new Color("oklch", [
|
|
374
|
+
0.25,
|
|
375
|
+
Math.max(0.08 * C(background), 0.04),
|
|
376
|
+
H(background),
|
|
377
|
+
]);
|
|
378
|
+
}
|
|
379
|
+
return white;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
type Rgb = readonly [number | null, number | null, number | null];
|
|
383
|
+
|
|
384
|
+
function channels(rgb: Rgb, precision: number): [number, number, number] {
|
|
385
|
+
const [r, g, b] = rgb;
|
|
386
|
+
return [
|
|
387
|
+
Math.round((r ?? 0) * precision),
|
|
388
|
+
Math.round((g ?? 0) * precision),
|
|
389
|
+
Math.round((b ?? 0) * precision),
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function getAlphaColor(
|
|
394
|
+
targetRgb: Rgb,
|
|
395
|
+
backgroundRgb: Rgb,
|
|
396
|
+
rgbPrecision: number,
|
|
397
|
+
alphaPrecision: number,
|
|
398
|
+
targetAlpha?: number,
|
|
399
|
+
): readonly [number, number, number, number] {
|
|
400
|
+
const [tr, tg, tb] = channels(targetRgb, rgbPrecision);
|
|
401
|
+
const [br, bg, bb] = channels(backgroundRgb, rgbPrecision);
|
|
402
|
+
|
|
403
|
+
const desiredRgb = tr > br || tg > bg || tb > bb ? rgbPrecision : 0;
|
|
404
|
+
|
|
405
|
+
const alphaR = (tr - br) / (desiredRgb - br);
|
|
406
|
+
const alphaG = (tg - bg) / (desiredRgb - bg);
|
|
407
|
+
const alphaB = (tb - bb) / (desiredRgb - bb);
|
|
408
|
+
|
|
409
|
+
const isPureGray = [alphaR, alphaG, alphaB].every(
|
|
410
|
+
(alpha) => alpha === alphaR,
|
|
411
|
+
);
|
|
412
|
+
if (!targetAlpha && isPureGray) {
|
|
413
|
+
const v = desiredRgb / rgbPrecision;
|
|
414
|
+
return [v, v, v, alphaR];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const clampRgb = (n: number) =>
|
|
418
|
+
Number.isNaN(n) ? 0 : Math.min(rgbPrecision, Math.max(0, n));
|
|
419
|
+
const clampA = (n: number) =>
|
|
420
|
+
Number.isNaN(n) ? 0 : Math.min(alphaPrecision, Math.max(0, n));
|
|
421
|
+
const maxAlpha = targetAlpha ?? Math.max(alphaR, alphaG, alphaB);
|
|
422
|
+
|
|
423
|
+
const A = clampA(Math.ceil(maxAlpha * alphaPrecision)) / alphaPrecision;
|
|
424
|
+
let R = Math.ceil(clampRgb(((br * (1 - A) - tr) / A) * -1));
|
|
425
|
+
let G = Math.ceil(clampRgb(((bg * (1 - A) - tg) / A) * -1));
|
|
426
|
+
let B = Math.ceil(clampRgb(((bb * (1 - A) - tb) / A) * -1));
|
|
427
|
+
|
|
428
|
+
const blendedR = blendAlpha(R, A, br);
|
|
429
|
+
const blendedG = blendAlpha(G, A, bg);
|
|
430
|
+
const blendedB = blendAlpha(B, A, bb);
|
|
431
|
+
|
|
432
|
+
if (desiredRgb === 0) {
|
|
433
|
+
if (tr <= br && tr !== blendedR) R = tr > blendedR ? R + 1 : R - 1;
|
|
434
|
+
if (tg <= bg && tg !== blendedG) G = tg > blendedG ? G + 1 : G - 1;
|
|
435
|
+
if (tb <= bb && tb !== blendedB) B = tb > blendedB ? B + 1 : B - 1;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (desiredRgb === rgbPrecision) {
|
|
439
|
+
if (tr >= br && tr !== blendedR) R = tr > blendedR ? R + 1 : R - 1;
|
|
440
|
+
if (tg >= bg && tg !== blendedG) G = tg > blendedG ? G + 1 : G - 1;
|
|
441
|
+
if (tb >= bb && tb !== blendedB) B = tb > blendedB ? B + 1 : B - 1;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return [R / rgbPrecision, G / rgbPrecision, B / rgbPrecision, A];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function blendAlpha(foreground: number, alpha: number, background: number) {
|
|
448
|
+
return Math.round(background * (1 - alpha)) + Math.round(foreground * alpha);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function getAlphaColorSrgb(
|
|
452
|
+
targetColor: string,
|
|
453
|
+
backgroundColor: string,
|
|
454
|
+
targetAlpha?: number,
|
|
455
|
+
): string {
|
|
456
|
+
const [r, g, b, a] = getAlphaColor(
|
|
457
|
+
new Color(targetColor).to("srgb").coords,
|
|
458
|
+
new Color(backgroundColor).to("srgb").coords,
|
|
459
|
+
255,
|
|
460
|
+
255,
|
|
461
|
+
targetAlpha,
|
|
462
|
+
);
|
|
463
|
+
return formatHex(new Color("srgb", [r, g, b], a).toString({ format: "hex" }));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
function getAlphaColorP3(
|
|
467
|
+
targetColor: string,
|
|
468
|
+
backgroundColor: string,
|
|
469
|
+
targetAlpha?: number,
|
|
470
|
+
): string {
|
|
471
|
+
const [r, g, b, a] = getAlphaColor(
|
|
472
|
+
new Color(targetColor).to("p3").coords,
|
|
473
|
+
new Color(backgroundColor).to("p3").coords,
|
|
474
|
+
255,
|
|
475
|
+
1000,
|
|
476
|
+
targetAlpha,
|
|
477
|
+
);
|
|
478
|
+
return new Color("p3", [r, g, b], a)
|
|
479
|
+
.toString({ precision: 4 })
|
|
480
|
+
.replace("color(p3 ", "color(display-p3 ");
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function toHex(color: Color): string {
|
|
484
|
+
return formatHex(color.to("srgb").toString({ format: "hex" }));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/** Expands #rgb and #rgba to #rrggbb and #rrggbbaa. */
|
|
488
|
+
export function formatHex(value: string): string {
|
|
489
|
+
if (!value.startsWith("#")) return value;
|
|
490
|
+
if (value.length === 4 || value.length === 5) {
|
|
491
|
+
return `#${[...value.slice(1)].map((digit) => digit + digit).join("")}`;
|
|
492
|
+
}
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const DARK_MODE_EASING: [number, number, number, number] = [1, 0, 1, 0];
|
|
497
|
+
const LIGHT_MODE_EASING: [number, number, number, number] = [0, 2, 0, 2];
|
|
498
|
+
|
|
499
|
+
function transposeProgressionStart(
|
|
500
|
+
to: number,
|
|
501
|
+
values: number[],
|
|
502
|
+
curve: [number, number, number, number],
|
|
503
|
+
): number[] {
|
|
504
|
+
const ease = cubicBezier(...curve);
|
|
505
|
+
const lastIndex = values.length - 1;
|
|
506
|
+
const diff = at(values, 0) - to;
|
|
507
|
+
return values.map((n, i) => n - diff * ease(1 - i / lastIndex));
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function toOklchString(color: Color): string {
|
|
511
|
+
const lightness = +(L(color) * 100).toFixed(1);
|
|
512
|
+
return color
|
|
513
|
+
.to("oklch")
|
|
514
|
+
.toString({ precision: 4 })
|
|
515
|
+
.replace(/(\S+)(.+)/, `oklch(${lightness}%$2`);
|
|
516
|
+
}
|