reshaped 3.6.0-canary.4 → 3.6.0-canary.6
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/CHANGELOG.md +10 -1
- package/dist/bundle.css +1 -1
- package/dist/bundle.js +6 -6
- package/dist/cjs/cli/theming/index.d.ts +3 -3
- package/dist/cjs/cli/theming/index.js +2 -2
- package/dist/cjs/cli/theming/tailwind.d.ts +2 -3
- package/dist/cjs/cli/theming/tailwind.js +1 -1
- package/dist/cjs/themes/_generator/definitions/slate.js +1 -1
- package/dist/cjs/themes/_generator/tokens/color/color.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/color/color.transforms.js +29 -7
- package/dist/cjs/themes/_generator/tokens/color/color.types.d.ts +28 -3
- package/dist/cjs/themes/_generator/tokens/color/utilities/a11y.d.ts +20 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/a11y.js +64 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/convert.d.ts +11 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/convert.js +33 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/generateColors.d.ts +4 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/generateColors.js +152 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/generateMetaColors.d.ts +4 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/generateMetaColors.js +68 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/tests/a11y.test.js +38 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/tests/convert.test.d.ts +1 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/tests/convert.test.js +48 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/tests/generateColors.test.d.ts +1 -0
- package/dist/cjs/themes/_generator/tokens/color/utilities/tests/generateColors.test.js +21 -0
- package/dist/{themes/_generator/utilities → cjs/themes/_generator/tokens}/css.d.ts +1 -1
- package/dist/cjs/themes/_generator/tokens/duration/duration.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/duration/duration.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/easing/easing.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/easing/easing.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/font/font.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/font/font.transforms.js +3 -3
- package/dist/cjs/themes/_generator/tokens/fontFamily/fontFamily.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/fontFamily/fontFamily.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/fontWeight/fontWeight.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/fontWeight/fontWeight.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/radius/radius.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/radius/radius.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/shadow/shadow.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/shadow/shadow.transforms.js +4 -4
- package/dist/cjs/themes/_generator/tokens/types.d.ts +19 -17
- package/dist/cjs/themes/_generator/tokens/unit/unit.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/unit/unit.transforms.js +2 -2
- package/dist/cjs/themes/_generator/tokens/unit/utilities/generate.d.ts +5 -0
- package/dist/cjs/themes/_generator/{utilities/generateUnits.js → tokens/unit/utilities/generate.js} +5 -4
- package/dist/cjs/themes/_generator/tokens/viewport/viewport.transforms.d.ts +2 -2
- package/dist/cjs/themes/_generator/tokens/viewport/viewport.transforms.js +2 -2
- package/dist/cjs/themes/_generator/transform.d.ts +3 -2
- package/dist/cjs/themes/_generator/transform.js +45 -11
- package/dist/cjs/themes/_generator/types.d.ts +4 -8
- package/dist/cjs/themes/_generator/utilities/mergeDefinitions.d.ts +1 -3
- package/dist/cjs/themes/_generator/utilities/mergeDefinitions.js +6 -4
- package/dist/cjs/themes/figma/tailwind.css +1 -1
- package/dist/cjs/themes/figma/theme.css +1 -1
- package/dist/cjs/themes/fragments/twitter/tailwind.css +1 -1
- package/dist/cjs/themes/fragments/twitter/theme.css +1 -1
- package/dist/cjs/themes/index.d.ts +4 -11
- package/dist/cjs/themes/index.js +2 -5
- package/dist/cjs/themes/reshaped/tailwind.css +1 -1
- package/dist/cjs/themes/reshaped/theme.css +1 -1
- package/dist/cjs/themes/slate/tailwind.css +1 -1
- package/dist/cjs/themes/slate/theme.css +1 -1
- package/dist/cjs/types/config.d.ts +11 -7
- package/dist/cli/theming/index.d.ts +3 -3
- package/dist/cli/theming/index.js +2 -2
- package/dist/cli/theming/tailwind.d.ts +2 -3
- package/dist/cli/theming/tailwind.js +1 -1
- package/dist/components/Accordion/Accordion.types.d.ts +2 -1
- package/dist/components/Accordion/AccordionContent.js +3 -2
- package/dist/components/Accordion/AccordionControlled.js +3 -2
- package/dist/components/Accordion/tests/Accordion.stories.d.ts +4 -0
- package/dist/components/Accordion/tests/Accordion.stories.js +11 -0
- package/dist/components/Autocomplete/tests/Autocomplete.stories.js +3 -6
- package/dist/components/DropdownMenu/DropdownMenu.types.d.ts +1 -1
- package/dist/components/FormControl/FormControl.context.d.ts +1 -1
- package/dist/components/ScrollArea/ScrollArea.js +1 -1
- package/dist/components/TextField/TextField.js +2 -2
- package/dist/components/TextField/TextField.module.css +1 -1
- package/dist/tests/ThemesPlayground.d.ts +2 -0
- package/dist/tests/ThemesPlayground.js +90 -0
- package/dist/tests/themes.stories.d.ts +16 -0
- package/dist/{themes/_generator/tests → tests}/themes.stories.js +74 -15
- package/dist/themes/_generator/definitions/slate.js +1 -1
- package/dist/themes/_generator/tokens/color/color.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/color/color.transforms.js +29 -7
- package/dist/themes/_generator/tokens/color/color.types.d.ts +28 -3
- package/dist/themes/_generator/tokens/color/utilities/a11y.d.ts +20 -0
- package/dist/themes/_generator/tokens/color/utilities/a11y.js +58 -0
- package/dist/themes/_generator/tokens/color/utilities/convert.d.ts +11 -0
- package/dist/themes/_generator/tokens/color/utilities/convert.js +27 -0
- package/dist/themes/_generator/tokens/color/utilities/generateColors.d.ts +4 -0
- package/dist/themes/_generator/tokens/color/utilities/generateColors.js +150 -0
- package/dist/themes/_generator/tokens/color/utilities/generateMetaColors.d.ts +4 -0
- package/dist/themes/_generator/tokens/color/utilities/generateMetaColors.js +66 -0
- package/dist/{cjs/themes/_generator/utilities → themes/_generator/tokens}/css.d.ts +1 -1
- package/dist/themes/_generator/tokens/duration/duration.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/duration/duration.transforms.js +2 -2
- package/dist/themes/_generator/tokens/easing/easing.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/easing/easing.transforms.js +2 -2
- package/dist/themes/_generator/tokens/font/font.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/font/font.transforms.js +3 -3
- package/dist/themes/_generator/tokens/fontFamily/fontFamily.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/fontFamily/fontFamily.transforms.js +2 -2
- package/dist/themes/_generator/tokens/fontWeight/fontWeight.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/fontWeight/fontWeight.transforms.js +2 -2
- package/dist/themes/_generator/tokens/radius/radius.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/radius/radius.transforms.js +2 -2
- package/dist/themes/_generator/tokens/shadow/shadow.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/shadow/shadow.transforms.js +4 -4
- package/dist/themes/_generator/tokens/types.d.ts +19 -17
- package/dist/themes/_generator/tokens/unit/unit.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/unit/unit.transforms.js +2 -2
- package/dist/themes/_generator/tokens/unit/utilities/generate.d.ts +5 -0
- package/dist/themes/_generator/{utilities/generateUnits.js → tokens/unit/utilities/generate.js} +4 -5
- package/dist/themes/_generator/tokens/viewport/viewport.transforms.d.ts +2 -2
- package/dist/themes/_generator/tokens/viewport/viewport.transforms.js +2 -2
- package/dist/themes/_generator/transform.d.ts +3 -2
- package/dist/themes/_generator/transform.js +45 -11
- package/dist/themes/_generator/types.d.ts +4 -8
- package/dist/themes/_generator/utilities/mergeDefinitions.d.ts +1 -3
- package/dist/themes/_generator/utilities/mergeDefinitions.js +6 -4
- package/dist/themes/figma/tailwind.css +1 -1
- package/dist/themes/figma/theme.css +1 -1
- package/dist/themes/fragments/twitter/tailwind.css +1 -1
- package/dist/themes/fragments/twitter/theme.css +1 -1
- package/dist/themes/index.d.ts +4 -11
- package/dist/themes/index.js +1 -4
- package/dist/themes/reshaped/tailwind.css +1 -1
- package/dist/themes/reshaped/theme.css +1 -1
- package/dist/themes/slate/tailwind.css +1 -1
- package/dist/themes/slate/theme.css +1 -1
- package/dist/types/config.d.ts +11 -7
- package/dist/types/global.d.ts +3 -0
- package/package.json +24 -23
- package/dist/cjs/themes/_generator/utilities/color.d.ts +0 -105
- package/dist/cjs/themes/_generator/utilities/color.js +0 -409
- package/dist/cjs/themes/_generator/utilities/generateBackgroundColors.d.ts +0 -4
- package/dist/cjs/themes/_generator/utilities/generateBackgroundColors.js +0 -59
- package/dist/cjs/themes/_generator/utilities/generateColors.d.ts +0 -11
- package/dist/cjs/themes/_generator/utilities/generateColors.js +0 -178
- package/dist/cjs/themes/_generator/utilities/generateUnits.d.ts +0 -4
- package/dist/cjs/themes/_generator/utilities/mergeDeep.d.ts +0 -5
- package/dist/cjs/themes/_generator/utilities/mergeDeep.js +0 -24
- package/dist/cjs/themes/_generator/utilities/resolveTokenReference.d.ts +0 -3
- package/dist/cjs/themes/_generator/utilities/resolveTokenReference.js +0 -18
- package/dist/cjs/themes/_generator/utilities/tests/color.test.js +0 -81
- package/dist/themes/_generator/tests/themes.stories.d.ts +0 -16
- package/dist/themes/_generator/utilities/color.d.ts +0 -105
- package/dist/themes/_generator/utilities/color.js +0 -377
- package/dist/themes/_generator/utilities/generateBackgroundColors.d.ts +0 -4
- package/dist/themes/_generator/utilities/generateBackgroundColors.js +0 -57
- package/dist/themes/_generator/utilities/generateColors.d.ts +0 -11
- package/dist/themes/_generator/utilities/generateColors.js +0 -176
- package/dist/themes/_generator/utilities/generateUnits.d.ts +0 -4
- package/dist/themes/_generator/utilities/mergeDeep.d.ts +0 -5
- package/dist/themes/_generator/utilities/mergeDeep.js +0 -22
- package/dist/themes/_generator/utilities/resolveTokenReference.d.ts +0 -3
- package/dist/themes/_generator/utilities/resolveTokenReference.js +0 -16
- /package/dist/cjs/themes/_generator/{utilities/tests/color.test.d.ts → tokens/color/utilities/tests/a11y.test.d.ts} +0 -0
- /package/dist/cjs/themes/_generator/{utilities → tokens}/css.js +0 -0
- /package/dist/themes/_generator/{utilities → tokens}/css.js +0 -0
@@ -1,18 +1,21 @@
|
|
1
|
-
import
|
2
|
-
import { Example } from "
|
3
|
-
import View from "
|
4
|
-
import Button from "
|
5
|
-
import Badge from "
|
6
|
-
import Alert from "
|
7
|
-
import Card from "
|
8
|
-
import Avatar from "
|
9
|
-
import DropdownMenu from "
|
10
|
-
import TextField from "
|
11
|
-
import Theme from "
|
12
|
-
import IconZap from "
|
13
|
-
import Link from "
|
14
|
-
import Text from "
|
15
|
-
import { getThemeCSS, generateThemeColors, baseThemeDefinition } from "
|
1
|
+
import { useLayoutEffect, useState } from "react";
|
2
|
+
import { Example } from "../utilities/storybook/index.js";
|
3
|
+
import View from "../components/View/index.js";
|
4
|
+
import Button from "../components/Button/index.js";
|
5
|
+
import Badge from "../components/Badge/index.js";
|
6
|
+
import Alert from "../components/Alert/index.js";
|
7
|
+
import Card from "../components/Card/index.js";
|
8
|
+
import Avatar from "../components/Avatar/index.js";
|
9
|
+
import DropdownMenu from "../components/DropdownMenu/index.js";
|
10
|
+
import TextField from "../components/TextField/index.js";
|
11
|
+
import Theme, { useTheme } from "../components/Theme/index.js";
|
12
|
+
import IconZap from "../icons/Mic.js";
|
13
|
+
import Link from "../components/Link/index.js";
|
14
|
+
import Text from "../components/Text/index.js";
|
15
|
+
import { getThemeCSS, generateThemeColors, baseThemeDefinition } from "../themes/index.js";
|
16
|
+
import ThemePlayground from "./ThemesPlayground.js";
|
17
|
+
import Actionable from "../components/Actionable/index.js";
|
18
|
+
import Switch from "../components/Switch/index.js";
|
16
19
|
export default {
|
17
20
|
title: "Internal/Themes",
|
18
21
|
parameters: {
|
@@ -23,6 +26,62 @@ export default {
|
|
23
26
|
},
|
24
27
|
},
|
25
28
|
};
|
29
|
+
const colors = [
|
30
|
+
"#2563eb",
|
31
|
+
"#4f39f6",
|
32
|
+
"#4a8200",
|
33
|
+
"#0891b2",
|
34
|
+
"#34d399",
|
35
|
+
"#fe9a00",
|
36
|
+
"#be185d",
|
37
|
+
"#ff2056",
|
38
|
+
"#000000",
|
39
|
+
];
|
40
|
+
export const test = () => {
|
41
|
+
const { colorMode } = useTheme();
|
42
|
+
const [activeColor, setColor] = useState(colors[0]);
|
43
|
+
const [theme, setTheme] = useState("");
|
44
|
+
const [algo, setAlgo] = useState("wcag");
|
45
|
+
useLayoutEffect(() => {
|
46
|
+
setTheme(getThemeCSS("test", {
|
47
|
+
color: generateThemeColors({
|
48
|
+
primary: activeColor === colors[0] ? undefined : activeColor,
|
49
|
+
}),
|
50
|
+
}, {
|
51
|
+
colorContrastAlgorithm: algo,
|
52
|
+
}));
|
53
|
+
}, [activeColor, algo]);
|
54
|
+
return (<>
|
55
|
+
<style>{theme}</style>
|
56
|
+
<Theme name="test">
|
57
|
+
<View gap={4}>
|
58
|
+
<View direction="row" align="center" gap={4}>
|
59
|
+
{colors.map((color) => {
|
60
|
+
const hex = colorMode === "dark" && color === "#000000" ? "#ffffff" : color;
|
61
|
+
return (<Actionable key={color} onClick={() => setColor(color)} borderRadius="inherit">
|
62
|
+
<View width={5} height={5} borderRadius="circular" attributes={{
|
63
|
+
style: {
|
64
|
+
transition: `box-shadow var(--rs-duration-fast) var(--rs-easing-standard)`,
|
65
|
+
background: hex,
|
66
|
+
boxShadow: color === activeColor
|
67
|
+
? `0 0 0 3px var(--rs-color-background-elevation-base), 0 0 0 5px ${hex}`
|
68
|
+
: undefined,
|
69
|
+
},
|
70
|
+
}}/>
|
71
|
+
</Actionable>);
|
72
|
+
})}
|
73
|
+
<View.Item gapBefore="auto">
|
74
|
+
<Switch name="algo" onChange={(args) => setAlgo(args.checked ? "apca" : "wcag")}>
|
75
|
+
Use APCA
|
76
|
+
</Switch>
|
77
|
+
</View.Item>
|
78
|
+
</View>
|
79
|
+
|
80
|
+
<ThemePlayground />
|
81
|
+
</View>
|
82
|
+
</Theme>
|
83
|
+
</>);
|
84
|
+
};
|
26
85
|
const css = getThemeCSS("green", {
|
27
86
|
color: {
|
28
87
|
backgroundPrimary: { hex: "#1abc9c", hexDark: "#00E5C4" },
|
@@ -1,18 +1,40 @@
|
|
1
|
-
const
|
2
|
-
const
|
3
|
-
|
1
|
+
const transformTokenForMode = (args) => {
|
2
|
+
const { hex, oklch } = args;
|
3
|
+
if (oklch) {
|
4
|
+
const components = `${Number(oklch.l.toFixed(4))} ${Number(oklch.c.toFixed(4))} ${Number(oklch.h?.toFixed(4) || 0)}`;
|
5
|
+
const alphaSuffix = oklch?.alpha === undefined ? "" : ` / ${Number(oklch.alpha.toFixed(4))}`;
|
6
|
+
return `oklch(${components}${alphaSuffix})`;
|
7
|
+
}
|
8
|
+
if (hex)
|
9
|
+
return hex;
|
10
|
+
throw new Error(`[Reshaped] ${JSON.stringify(args)} is missing a color value`);
|
11
|
+
};
|
12
|
+
const transformToken = (name, token) => {
|
13
|
+
const { hex, hexDark, oklch, oklchDark } = token;
|
14
|
+
// Apply color to both modes if dark mode is not available
|
15
|
+
const hasDark = !!hexDark || !!oklchDark;
|
16
|
+
const value = transformTokenForMode({ oklch, hex });
|
17
|
+
const darkValue = hasDark ? transformTokenForMode({ oklch: oklchDark, hex: hexDark }) : undefined;
|
18
|
+
const separateModes = hasDark && value !== darkValue;
|
19
|
+
const defaultMode = separateModes ? "light" : undefined;
|
4
20
|
const result = [
|
5
|
-
{
|
21
|
+
{
|
22
|
+
name,
|
23
|
+
tokenType: "color",
|
24
|
+
type: "variable",
|
25
|
+
value,
|
26
|
+
mode: defaultMode,
|
27
|
+
},
|
6
28
|
];
|
7
|
-
if (
|
29
|
+
if (darkValue && separateModes) {
|
8
30
|
result.push({
|
9
31
|
name,
|
10
32
|
tokenType: "color",
|
11
33
|
type: "variable",
|
12
|
-
value:
|
34
|
+
value: darkValue,
|
13
35
|
mode: "dark",
|
14
36
|
});
|
15
37
|
}
|
16
38
|
return result;
|
17
39
|
};
|
18
|
-
export default
|
40
|
+
export default transformToken;
|
@@ -1,7 +1,32 @@
|
|
1
|
+
import type { Oklch } from "culori/fn";
|
2
|
+
export type Hue = "primary" | "positive" | "critical" | "warning" | "neutral" | "brand";
|
1
3
|
export type Name = "foregroundNeutral" | "foregroundNeutralFaded" | "foregroundDisabled" | "foregroundPrimary" | "foregroundCritical" | "foregroundWarning" | "foregroundPositive" | "borderNeutral" | "borderNeutralFaded" | "borderDisabled" | "borderPrimary" | "borderPrimaryFaded" | "borderCritical" | "borderCriticalFaded" | "borderWarning" | "borderWarningFaded" | "borderPositive" | "borderPositiveFaded" | "backgroundNeutral" | "backgroundNeutralFaded" | "backgroundDisabled" | "backgroundDisabledFaded" | "backgroundPrimary" | "backgroundPrimaryFaded" | "backgroundCritical" | "backgroundCriticalFaded" | "backgroundWarning" | "backgroundWarningFaded" | "backgroundPositive" | "backgroundPositiveFaded" | "backgroundPage" | "backgroundPageFaded" | "backgroundElevationBase" | "backgroundElevationRaised" | "backgroundElevationOverlay" | "brand" | "white" | "black";
|
2
4
|
export type GeneratedOnName = "onBackgroundNeutral" | "onBackgroundPrimary" | "onBackgroundPositive" | "onBackgroundWarning" | "onBackgroundCritical";
|
3
5
|
export type GeneratedRGBName = "rgbBackgroundNeutral" | "rgbBackgroundNeutralFaded" | "rgbBackgroundDisabled" | "rgbBackgroundDisabledFaded" | "rgbBackgroundPrimary" | "rgbBackgroundPrimaryFaded" | "rgbBackgroundCritical" | "rgbBackgroundCriticalFaded" | "rgbBackgroundWarning" | "rgbBackgroundWarningFaded" | "rgbBackgroundPositive" | "rgbBackgroundPositiveFaded" | "rgbBackgroundPage" | "rgbBackgroundPageFaded" | "rgbBackgroundElevationBase" | "rgbBackgroundElevationRaised" | "rgbBackgroundElevationOverlay";
|
4
|
-
export type
|
5
|
-
|
6
|
-
|
6
|
+
export type RgbColor = {
|
7
|
+
r: number;
|
8
|
+
g: number;
|
9
|
+
b: number;
|
10
|
+
};
|
11
|
+
export type OklchColor = Omit<Oklch, "mode">;
|
12
|
+
export type HexColor = string;
|
13
|
+
export type ColorValue = HexColor | Token;
|
14
|
+
export type OklchOnlyToken = {
|
15
|
+
oklch: OklchColor;
|
16
|
+
oklchDark?: OklchColor;
|
17
|
+
};
|
18
|
+
export type OklchToken = OklchOnlyToken & {
|
19
|
+
hex?: never;
|
20
|
+
hexDark?: never;
|
21
|
+
};
|
22
|
+
export type HexToken = {
|
23
|
+
hex: HexColor;
|
24
|
+
hexDark?: HexColor;
|
25
|
+
oklch?: never;
|
26
|
+
oklchDark?: never;
|
27
|
+
};
|
28
|
+
export type Token = OklchToken | HexToken;
|
29
|
+
export type InternalToken = {
|
30
|
+
oklch: Oklch;
|
31
|
+
oklchDark?: Oklch;
|
7
32
|
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { type Oklch } from "culori/fn";
|
2
|
+
export declare const getOnColorWCAG: (args: {
|
3
|
+
bgColor: Oklch;
|
4
|
+
lightColor: Oklch;
|
5
|
+
darkColor: Oklch;
|
6
|
+
}) => Oklch;
|
7
|
+
export declare const getOnColorAPCA: (args: {
|
8
|
+
bgColor: Oklch;
|
9
|
+
lightColor: Oklch;
|
10
|
+
darkColor: Oklch;
|
11
|
+
}) => Oklch;
|
12
|
+
/**
|
13
|
+
* General
|
14
|
+
*/
|
15
|
+
export declare const getOnColor: (args: {
|
16
|
+
bgColor: Oklch;
|
17
|
+
lightColor: Oklch;
|
18
|
+
darkColor: Oklch;
|
19
|
+
algorithm?: "wcag" | "apca";
|
20
|
+
}) => Oklch;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { oklchToRgb } from "./convert.js";
|
2
|
+
/**
|
3
|
+
* WCAG
|
4
|
+
*/
|
5
|
+
const RED = 0.2126;
|
6
|
+
const GREEN = 0.7152;
|
7
|
+
const BLUE = 0.0722;
|
8
|
+
const GAMMA = 2.4;
|
9
|
+
function luminanceWCAG(r, g, b) {
|
10
|
+
const a = [r, g, b].map((v) => {
|
11
|
+
return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, GAMMA);
|
12
|
+
});
|
13
|
+
return a[0] * RED + a[1] * GREEN + a[2] * BLUE;
|
14
|
+
}
|
15
|
+
function contrastWCAG(rgb1, rgb2) {
|
16
|
+
const lum1 = luminanceWCAG(...rgb1);
|
17
|
+
const lum2 = luminanceWCAG(...rgb2);
|
18
|
+
const brightest = Math.max(lum1, lum2);
|
19
|
+
const darkest = Math.min(lum1, lum2);
|
20
|
+
return (brightest + 0.05) / (darkest + 0.05);
|
21
|
+
}
|
22
|
+
export const getOnColorWCAG = (args) => {
|
23
|
+
const { bgColor, lightColor, darkColor } = args;
|
24
|
+
const bgRgb = oklchToRgb(bgColor);
|
25
|
+
const lightRgb = oklchToRgb(lightColor);
|
26
|
+
return contrastWCAG([bgRgb.r, bgRgb.g, bgRgb.b], [lightRgb.r, lightRgb.g, lightRgb.b]) > 4.5
|
27
|
+
? lightColor
|
28
|
+
: darkColor;
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* APCA
|
32
|
+
*/
|
33
|
+
function luminanceAPCA(oklch) {
|
34
|
+
const { r, g, b } = oklchToRgb(oklch);
|
35
|
+
return (0.2126 * Math.pow(r / 255, 2.2) +
|
36
|
+
0.7152 * Math.pow(g / 255, 2.2) +
|
37
|
+
0.0722 * Math.pow(b / 255, 2.2));
|
38
|
+
}
|
39
|
+
export const getOnColorAPCA = (args) => {
|
40
|
+
const { bgColor, lightColor, darkColor } = args;
|
41
|
+
const backgroundLuminance = luminanceAPCA(bgColor);
|
42
|
+
const lightLuminance = luminanceAPCA(lightColor);
|
43
|
+
const darkLuminance = luminanceAPCA(darkColor);
|
44
|
+
const contrastWithLight = Math.abs(lightLuminance - backgroundLuminance);
|
45
|
+
const contrastWithDark = Math.abs(darkLuminance - backgroundLuminance);
|
46
|
+
return contrastWithLight > contrastWithDark ? lightColor : darkColor;
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* General
|
50
|
+
*/
|
51
|
+
export const getOnColor = (args) => {
|
52
|
+
if (args.algorithm === "apca") {
|
53
|
+
return getOnColorAPCA(args);
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
return getOnColorWCAG(args);
|
57
|
+
}
|
58
|
+
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { type Oklch } from "culori/fn";
|
2
|
+
import type * as TColor from "../color.types";
|
3
|
+
export declare const hexToOklch: (hex: string) => Oklch;
|
4
|
+
export declare const oklchToRgb: (oklch: Oklch) => {
|
5
|
+
r: number;
|
6
|
+
g: number;
|
7
|
+
b: number;
|
8
|
+
mode: "rgb";
|
9
|
+
alpha?: number;
|
10
|
+
};
|
11
|
+
export declare const tokenToOklchToken: (token: TColor.Token) => TColor.InternalToken;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { useMode, modeOklch, formatHex, modeRgb } from "culori/fn";
|
2
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
3
|
+
const oklch = useMode(modeOklch);
|
4
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
5
|
+
const rgb = useMode(modeRgb);
|
6
|
+
export const hexToOklch = (hex) => {
|
7
|
+
const result = oklch(formatHex(hex));
|
8
|
+
if (!result)
|
9
|
+
throw new Error(`[Reshaped] Can't convert ${hex} to oklch`);
|
10
|
+
return result;
|
11
|
+
};
|
12
|
+
export const oklchToRgb = (oklch) => {
|
13
|
+
const value = rgb(oklch);
|
14
|
+
return {
|
15
|
+
...value,
|
16
|
+
r: Number(value.r.toFixed(4)),
|
17
|
+
g: Number(value.g.toFixed(4)),
|
18
|
+
b: Number(value.b.toFixed(4)),
|
19
|
+
};
|
20
|
+
};
|
21
|
+
export const tokenToOklchToken = (token) => {
|
22
|
+
const hexDarkFallback = token.hexDark ? hexToOklch(token.hexDark) : undefined;
|
23
|
+
return {
|
24
|
+
oklch: token.oklch ? { ...token.oklch, mode: "oklch" } : hexToOklch(token.hex),
|
25
|
+
oklchDark: token.oklchDark ? { ...token.oklchDark, mode: "oklch" } : hexDarkFallback,
|
26
|
+
};
|
27
|
+
};
|
@@ -0,0 +1,150 @@
|
|
1
|
+
import { hexToOklch, tokenToOklchToken } from "./convert.js";
|
2
|
+
const parseColor = (color) => {
|
3
|
+
const isString = typeof color === "string";
|
4
|
+
if (!isString && "oklch" in color && color.oklch) {
|
5
|
+
return {
|
6
|
+
light: color.oklch,
|
7
|
+
dark: color.oklchDark,
|
8
|
+
};
|
9
|
+
}
|
10
|
+
const hexLight = isString ? color : color.hex;
|
11
|
+
const hexDark = isString ? undefined : color.hexDark;
|
12
|
+
const light = hexToOklch(hexLight);
|
13
|
+
const dark = hexDark ? hexToOklch(hexDark) : undefined;
|
14
|
+
if (!light) {
|
15
|
+
throw new Error(`[Reshaped] Failed when parsing color: ${JSON.stringify(color)}`);
|
16
|
+
}
|
17
|
+
return { light, dark };
|
18
|
+
};
|
19
|
+
const getDarkModeColor = (lch) => {
|
20
|
+
const { l, c } = lch;
|
21
|
+
// Top boundary at which background colors are perceived as vibrant
|
22
|
+
const vibrancyThreshold = 0.25;
|
23
|
+
// A linear modifier of how gray a color is, gray = 1, vibrant = 0
|
24
|
+
const neutralFactor = Math.min(1, Math.max(0, (vibrancyThreshold - c) / vibrancyThreshold));
|
25
|
+
// Non-linear modification to make gray color inversion progress faster
|
26
|
+
const easedVibrancy = 1 - Math.pow(neutralFactor, 2);
|
27
|
+
const invertedL = 1 - l;
|
28
|
+
// Take plain inversion and increase it back by vibrancy modifier
|
29
|
+
// Vibrant colors should get back to almost the original value
|
30
|
+
// while non-briant colors should lean towards full inversion
|
31
|
+
// Example:
|
32
|
+
// Black should become white in dark mode
|
33
|
+
// Light gray should become dark gray
|
34
|
+
// Vibrant blue should stay vibrant blue
|
35
|
+
const darkL = invertedL + (l - invertedL) * easedVibrancy;
|
36
|
+
// Make sure dark mode value doesn't become too dark and is still visible on dark page background
|
37
|
+
const clampedDarkL = Math.max(0.36, darkL);
|
38
|
+
return { ...lch, c: c * 0.8, l: clampedDarkL };
|
39
|
+
};
|
40
|
+
const generateColorValues = (key, token) => {
|
41
|
+
const { light: bg, dark } = parseColor(token);
|
42
|
+
const capitalizedKey = key.charAt(0).toUpperCase() + key.slice(1);
|
43
|
+
const neutral = key === "neutral";
|
44
|
+
const warning = key === "warning";
|
45
|
+
const bgDark = dark || getDarkModeColor(bg);
|
46
|
+
const bgFaded = {
|
47
|
+
...bg,
|
48
|
+
l: 0.97,
|
49
|
+
c: neutral ? 0.005 : warning ? 0.04 : 0.02,
|
50
|
+
};
|
51
|
+
const bgFadedDark = {
|
52
|
+
...bgDark,
|
53
|
+
l: 0.25,
|
54
|
+
// For primary color with low chroma, we still have to make sure it stays low
|
55
|
+
c: neutral ? 0.01 : bgDark.c / 5,
|
56
|
+
};
|
57
|
+
const fg = neutral ? { ...bg, l: 0.2 } : { ...bg, l: 0.5 };
|
58
|
+
const fgDark = neutral ? { ...bgDark, l: 0.96 } : { ...bgDark, l: 0.75, c: bg.c * 0.85 };
|
59
|
+
const bd = neutral ? { ...bg, l: 0, alpha: 0.12 } : { ...bg, l: bg.l - 0.08 };
|
60
|
+
const bdDark = neutral ? { ...bgDark, l: 1, alpha: 0.16 } : { ...bgDark, l: bgDark.l + 0.08 };
|
61
|
+
const bdFaded = neutral
|
62
|
+
? { ...bgFaded, l: 0, alpha: 0.08 }
|
63
|
+
: { ...bgFaded, l: bgFaded.l - 0.05, c: bgFaded.c + 0.01 };
|
64
|
+
const bdFadedDark = neutral
|
65
|
+
? { ...bgFadedDark, l: 1, alpha: 0.08 }
|
66
|
+
: { ...bgFadedDark, l: bgFadedDark.l + 0.1 };
|
67
|
+
const output = {
|
68
|
+
[`background${capitalizedKey}`]: {
|
69
|
+
oklch: bg,
|
70
|
+
oklchDark: bgDark,
|
71
|
+
},
|
72
|
+
[`background${capitalizedKey}Faded`]: {
|
73
|
+
oklch: bgFaded,
|
74
|
+
oklchDark: bgFadedDark,
|
75
|
+
},
|
76
|
+
[`border${capitalizedKey}`]: {
|
77
|
+
oklch: bd,
|
78
|
+
oklchDark: bdDark,
|
79
|
+
},
|
80
|
+
[`border${capitalizedKey}Faded`]: {
|
81
|
+
oklch: bdFaded,
|
82
|
+
oklchDark: bdFadedDark,
|
83
|
+
},
|
84
|
+
[`foreground${capitalizedKey}`]: {
|
85
|
+
oklch: fg,
|
86
|
+
oklchDark: fgDark,
|
87
|
+
},
|
88
|
+
};
|
89
|
+
if (neutral) {
|
90
|
+
output[`foreground${capitalizedKey}Faded`] = {
|
91
|
+
oklch: { ...fg, l: fg.l + 0.25 },
|
92
|
+
oklchDark: { ...fgDark, l: fgDark.l - 0.15 },
|
93
|
+
};
|
94
|
+
output[`backgroundDisabled`] = {
|
95
|
+
oklch: { ...bg, l: 0.95, c: 0 },
|
96
|
+
oklchDark: { ...bgDark, l: 0.28, c: 0 },
|
97
|
+
};
|
98
|
+
output[`backgroundDisabledFaded`] = {
|
99
|
+
oklch: { ...bg, l: 0.98, c: 0 },
|
100
|
+
oklchDark: { ...bgDark, l: 0.23, c: 0 },
|
101
|
+
};
|
102
|
+
output[`borderDisabled`] = {
|
103
|
+
oklch: { ...bd, alpha: 0.06 },
|
104
|
+
oklchDark: { ...bgDark, l: 0.28, c: 0 },
|
105
|
+
};
|
106
|
+
output[`foregroundDisabled`] = {
|
107
|
+
oklch: { ...fg, l: 0.84, c: 0 },
|
108
|
+
oklchDark: { ...fgDark, l: 0.4, c: 0 },
|
109
|
+
};
|
110
|
+
output[`backgroundElevationBase`] = {
|
111
|
+
oklch: { ...bg, l: 1, c: 0 },
|
112
|
+
oklchDark: { ...bgDark, l: 0.2, c: 0 },
|
113
|
+
};
|
114
|
+
output[`backgroundElevationRaised`] = {
|
115
|
+
oklch: { ...bg, l: 1, c: 0 },
|
116
|
+
oklchDark: { ...bgDark, l: 0.21, c: 0 },
|
117
|
+
};
|
118
|
+
output[`backgroundElevationOverlay`] = {
|
119
|
+
oklch: { ...bg, l: 1, c: 0 },
|
120
|
+
oklchDark: { ...bgDark, l: 0.22, c: 0 },
|
121
|
+
};
|
122
|
+
output[`backgroundPage`] = {
|
123
|
+
oklch: { ...bg, l: 1, c: 0 },
|
124
|
+
oklchDark: { ...bgDark, l: 0.16, c: 0 },
|
125
|
+
};
|
126
|
+
output[`backgroundPageFaded`] = {
|
127
|
+
oklch: { ...bg, l: 0.97, c: 0 },
|
128
|
+
oklchDark: { ...bgDark, l: 0.18, c: 0 },
|
129
|
+
};
|
130
|
+
}
|
131
|
+
return output;
|
132
|
+
};
|
133
|
+
const getOklchToken = (color) => {
|
134
|
+
const token = typeof color === "string" ? { hex: color } : color;
|
135
|
+
return tokenToOklchToken(token);
|
136
|
+
};
|
137
|
+
const generateColors = (args = {}) => {
|
138
|
+
const { primary = { oklch: { l: 0.55, c: 0.24, h: 262.67 } }, critical = { oklch: { l: 0.59, c: 0.22, h: 26.97 } }, warning = { oklch: { l: 0.86, c: 0.18, h: 89.84 } }, positive = { oklch: { l: 0.53, c: 0.13, h: 153.78 } }, neutral = { oklch: { l: 0.92, c: 0.01, h: 262.67 } }, brand, } = args;
|
139
|
+
return {
|
140
|
+
...generateColorValues("primary", getOklchToken(primary)),
|
141
|
+
...generateColorValues("critical", getOklchToken(critical)),
|
142
|
+
...generateColorValues("warning", getOklchToken(warning)),
|
143
|
+
...generateColorValues("positive", getOklchToken(positive)),
|
144
|
+
...generateColorValues("neutral", getOklchToken(neutral)),
|
145
|
+
brand: getOklchToken(brand || primary),
|
146
|
+
white: getOklchToken("#ffffff"),
|
147
|
+
black: getOklchToken("#000000"),
|
148
|
+
};
|
149
|
+
};
|
150
|
+
export default generateColors;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type * as T from "../../../types";
|
2
|
+
import { GeneratedThemeDefinition, PassedThemeDefinition } from "../../types";
|
3
|
+
declare const generateMetaColors: (definition: PassedThemeDefinition, themeOptions?: T.PublicOptions["themeOptions"]) => GeneratedThemeDefinition["color"] | undefined;
|
4
|
+
export default generateMetaColors;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { capitalize } from "../../../../../utilities/string.js";
|
2
|
+
import { bgWithDynamicForeground } from "../../../constants.js";
|
3
|
+
import { hexToOklch, oklchToRgb, tokenToOklchToken } from "./convert.js";
|
4
|
+
import { getOnColor } from "./a11y.js";
|
5
|
+
const whiteColor = hexToOklch("#ffffff");
|
6
|
+
const blackColor = hexToOklch("#000000");
|
7
|
+
const generateMetaColors = (definition, themeOptions = {}) => {
|
8
|
+
if (!definition.color)
|
9
|
+
return;
|
10
|
+
const { onColorValues = {}, colorContrastAlgorithm } = themeOptions;
|
11
|
+
const result = {};
|
12
|
+
Object.keys(definition.color).forEach((tokenName) => {
|
13
|
+
const bgToken = definition.color?.[tokenName];
|
14
|
+
const generatedForegroundName = `on${capitalize(tokenName)}`;
|
15
|
+
const generatedRGBName = `rgb${capitalize(tokenName)}`;
|
16
|
+
const generateOnColorsFor = [
|
17
|
+
...bgWithDynamicForeground,
|
18
|
+
...(themeOptions?.generateOnColorsFor || []),
|
19
|
+
];
|
20
|
+
const needsDynamicForeground = generateOnColorsFor.includes(tokenName) && !definition.color?.[generatedForegroundName];
|
21
|
+
const needsRGB = tokenName.startsWith("background") ||
|
22
|
+
tokenName.endsWith("black") ||
|
23
|
+
tokenName.endsWith("white");
|
24
|
+
if (!bgToken)
|
25
|
+
return;
|
26
|
+
const oklchBgToken = tokenToOklchToken(bgToken);
|
27
|
+
if (needsDynamicForeground) {
|
28
|
+
const overrideKeys = Object.keys(onColorValues);
|
29
|
+
const onColorKey = overrideKeys.find((key) => tokenName.toLowerCase().includes(key));
|
30
|
+
const onColor = onColorKey && onColorValues[onColorKey];
|
31
|
+
const lightColor = onColor && "hexLight" in onColor
|
32
|
+
? hexToOklch(onColor.hexLight)
|
33
|
+
: onColor?.oklchLight || whiteColor;
|
34
|
+
const darkColor = onColor && "hexDark" in onColor
|
35
|
+
? hexToOklch(onColor.hexDark)
|
36
|
+
: onColor?.oklchDark || blackColor;
|
37
|
+
const light = getOnColor({
|
38
|
+
bgColor: oklchBgToken.oklch,
|
39
|
+
lightColor: { ...lightColor, mode: "oklch" },
|
40
|
+
darkColor: { ...darkColor, mode: "oklch" },
|
41
|
+
algorithm: colorContrastAlgorithm,
|
42
|
+
});
|
43
|
+
const dark = oklchBgToken.oklchDark &&
|
44
|
+
getOnColor({
|
45
|
+
bgColor: oklchBgToken.oklchDark,
|
46
|
+
lightColor: { ...lightColor, mode: "oklch" },
|
47
|
+
darkColor: { ...darkColor, mode: "oklch" },
|
48
|
+
algorithm: colorContrastAlgorithm,
|
49
|
+
});
|
50
|
+
result[generatedForegroundName] = {
|
51
|
+
oklch: light,
|
52
|
+
oklchDark: dark,
|
53
|
+
};
|
54
|
+
}
|
55
|
+
if (needsRGB) {
|
56
|
+
const rgb = oklchToRgb(oklchBgToken.oklch);
|
57
|
+
const rgbDark = oklchBgToken.oklchDark && oklchToRgb(oklchBgToken.oklchDark);
|
58
|
+
result[generatedRGBName] = {
|
59
|
+
hex: `${rgb.r * 255}, ${rgb.g * 255}, ${rgb.b * 255}`,
|
60
|
+
hexDark: rgbDark && `${rgbDark.r * 255}, ${rgbDark.g * 255}, ${rgbDark.b * 255}`,
|
61
|
+
};
|
62
|
+
}
|
63
|
+
});
|
64
|
+
return result;
|
65
|
+
};
|
66
|
+
export default generateMetaColors;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type * as T from "
|
1
|
+
import type * as T from "./types";
|
2
2
|
export declare const getVariableName: (tokenName: string, tokenType?: string) => string;
|
3
3
|
export declare const createVariable: (token: T.TransformedToken) => string;
|
4
4
|
export declare const createMedia: (token: T.TransformedToken) => string;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const
|
1
|
+
const transformToken = (name, token) => [
|
2
2
|
{
|
3
3
|
name,
|
4
4
|
tokenType: "duration",
|
@@ -6,4 +6,4 @@ const transformedToken = (name, token) => [
|
|
6
6
|
value: `${token.ms}ms`,
|
7
7
|
},
|
8
8
|
];
|
9
|
-
export default
|
9
|
+
export default transformToken;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const
|
1
|
+
const transformToken = (name, token) => [
|
2
2
|
{
|
3
3
|
name,
|
4
4
|
tokenType: "easing",
|
@@ -6,4 +6,4 @@ const transformedToken = (name, token) => [
|
|
6
6
|
value: `cubic-bezier(${token.x1}, ${token.y1}, ${token.x2}, ${token.y2})`,
|
7
7
|
},
|
8
8
|
];
|
9
|
-
export default
|
9
|
+
export default transformToken;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { getVariableName } from "
|
1
|
+
import { getVariableName } from "../css.js";
|
2
2
|
const BASE_REM_SIZE = 16;
|
3
|
-
const
|
3
|
+
const transformToken = (name, token) => {
|
4
4
|
const result = [];
|
5
5
|
result.push({
|
6
6
|
name,
|
@@ -38,4 +38,4 @@ const transformedToken = (name, token) => {
|
|
38
38
|
});
|
39
39
|
return result;
|
40
40
|
};
|
41
|
-
export default
|
41
|
+
export default transformToken;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type * as T from "./fontFamily.types";
|
2
2
|
import type { Transformer } from "../types";
|
3
|
-
declare const
|
4
|
-
export default
|
3
|
+
declare const transformToken: Transformer<T.Token>;
|
4
|
+
export default transformToken;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const
|
1
|
+
const transformToken = (name, token) => [
|
2
2
|
{
|
3
3
|
name,
|
4
4
|
tokenType: "fontFamily",
|
@@ -6,4 +6,4 @@ const transformedToken = (name, token) => [
|
|
6
6
|
value: `${token.family}`,
|
7
7
|
},
|
8
8
|
];
|
9
|
-
export default
|
9
|
+
export default transformToken;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type * as T from "./fontWeight.types";
|
2
2
|
import type { Transformer } from "../types";
|
3
|
-
declare const
|
4
|
-
export default
|
3
|
+
declare const transformToken: Transformer<T.Token>;
|
4
|
+
export default transformToken;
|