@wordpress/theme 0.1.0 → 0.1.1-next.2f1c7c01b.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/README.md +69 -9
- package/bin/generate-default-ramps/index.ts +49 -0
- package/bin/generate-primitive-tokens/index.ts +14 -9
- package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +11 -4
- package/build/color-ramps/index.js +21 -39
- package/build/color-ramps/index.js.map +3 -3
- package/build/color-ramps/lib/color-utils.js +39 -0
- package/build/color-ramps/lib/color-utils.js.map +7 -0
- package/build/color-ramps/lib/constants.js +18 -25
- package/build/color-ramps/lib/constants.js.map +3 -3
- package/build/color-ramps/lib/default-ramps.js +220 -0
- package/build/color-ramps/lib/default-ramps.js.map +7 -0
- package/build/color-ramps/lib/find-color-with-constraints.js +57 -71
- package/build/color-ramps/lib/find-color-with-constraints.js.map +3 -3
- package/build/color-ramps/lib/index.js +25 -68
- package/build/color-ramps/lib/index.js.map +3 -3
- package/build/color-ramps/lib/ramp-configs.js +12 -11
- package/build/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build/color-ramps/lib/register-color-spaces.js +7 -0
- package/build/color-ramps/lib/register-color-spaces.js.map +7 -0
- package/build/color-ramps/lib/taper-chroma.js +35 -27
- package/build/color-ramps/lib/taper-chroma.js.map +3 -3
- package/build/color-ramps/lib/types.js +2 -1
- package/build/color-ramps/lib/types.js.map +1 -1
- package/build/color-ramps/lib/utils.js +12 -9
- package/build/color-ramps/lib/utils.js.map +2 -2
- package/build/context.js +3 -2
- package/build/context.js.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +3 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/prebuilt/js/design-tokens.js +14 -1
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/json/figma.json +214 -32
- package/build/prebuilt/ts/design-tokens.js +38 -1
- package/build/prebuilt/ts/design-tokens.js.map +2 -2
- package/build/private-apis.js +3 -2
- package/build/private-apis.js.map +1 -1
- package/build/theme-provider.js +19 -17
- package/build/theme-provider.js.map +4 -4
- package/build/types/css-modules.d.js +0 -1
- package/build/types.js +2 -1
- package/build/types.js.map +1 -1
- package/build/use-theme-provider-styles.js +50 -36
- package/build/use-theme-provider-styles.js.map +3 -3
- package/build-module/color-ramps/index.js +20 -28
- package/build-module/color-ramps/index.js.map +2 -2
- package/build-module/color-ramps/lib/color-utils.js +19 -0
- package/build-module/color-ramps/lib/color-utils.js.map +7 -0
- package/build-module/color-ramps/lib/constants.js +13 -10
- package/build-module/color-ramps/lib/constants.js.map +2 -2
- package/build-module/color-ramps/lib/default-ramps.js +196 -0
- package/build-module/color-ramps/lib/default-ramps.js.map +7 -0
- package/build-module/color-ramps/lib/find-color-with-constraints.js +56 -60
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +28 -55
- package/build-module/color-ramps/lib/index.js.map +3 -3
- package/build-module/color-ramps/lib/ramp-configs.js +11 -10
- package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build-module/color-ramps/lib/register-color-spaces.js +7 -0
- package/build-module/color-ramps/lib/register-color-spaces.js.map +7 -0
- package/build-module/color-ramps/lib/taper-chroma.js +40 -16
- package/build-module/color-ramps/lib/taper-chroma.js.map +2 -2
- package/build-module/color-ramps/lib/utils.js +7 -4
- package/build-module/color-ramps/lib/utils.js.map +2 -2
- package/build-module/context.js +2 -1
- package/build-module/context.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +2 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/prebuilt/js/design-tokens.js +13 -0
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/json/figma.json +214 -32
- package/build-module/prebuilt/ts/design-tokens.js +37 -0
- package/build-module/prebuilt/ts/design-tokens.js.map +2 -2
- package/build-module/private-apis.js +2 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/theme-provider.js +18 -6
- package/build-module/theme-provider.js.map +3 -3
- package/build-module/use-theme-provider-styles.js +52 -31
- package/build-module/use-theme-provider-styles.js.map +2 -2
- package/build-types/color-ramps/index.d.ts +9 -16
- package/build-types/color-ramps/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/color-utils.d.ts +22 -0
- package/build-types/color-ramps/lib/color-utils.d.ts.map +1 -0
- package/build-types/color-ramps/lib/constants.d.ts +6 -8
- package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
- package/build-types/color-ramps/lib/default-ramps.d.ts +7 -0
- package/build-types/color-ramps/lib/default-ramps.d.ts.map +1 -0
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +7 -5
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/index.d.ts +5 -2
- package/build-types/color-ramps/lib/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/register-color-spaces.d.ts +2 -0
- package/build-types/color-ramps/lib/register-color-spaces.d.ts.map +1 -0
- package/build-types/color-ramps/lib/taper-chroma.d.ts +7 -3
- package/build-types/color-ramps/lib/taper-chroma.d.ts.map +1 -1
- package/build-types/color-ramps/lib/utils.d.ts +7 -3
- package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
- package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
- package/build-types/prebuilt/ts/design-tokens.d.ts.map +1 -1
- package/build-types/use-theme-provider-styles.d.ts +4 -0
- package/build-types/use-theme-provider-styles.d.ts.map +1 -1
- package/docs/ds-tokens.md +34 -0
- package/package.json +19 -9
- package/src/color-ramps/index.ts +24 -41
- package/src/color-ramps/lib/color-utils.ts +34 -0
- package/src/color-ramps/lib/constants.ts +8 -6
- package/src/color-ramps/lib/default-ramps.ts +200 -0
- package/src/color-ramps/lib/find-color-with-constraints.ts +70 -79
- package/src/color-ramps/lib/index.ts +27 -61
- package/src/color-ramps/lib/register-color-spaces.ts +13 -0
- package/src/color-ramps/lib/taper-chroma.ts +47 -19
- package/src/color-ramps/lib/utils.ts +8 -9
- package/src/color-ramps/stories/index.story.tsx +16 -22
- package/src/color-ramps/test/__snapshots__/index.test.ts.snap +96 -96
- package/src/color-ramps/test/index.test.ts +27 -15
- package/src/prebuilt/css/design-tokens.css +90 -32
- package/src/prebuilt/js/design-tokens.js +12 -0
- package/src/prebuilt/json/figma.json +214 -32
- package/src/prebuilt/ts/design-tokens.ts +36 -0
- package/src/use-theme-provider-styles.ts +47 -25
- package/tokens/color.json +184 -32
- package/tsconfig.bin.json +13 -0
- package/tsconfig.bin.tsbuildinfo +1 -0
- package/tsconfig.json +6 -4
- package/tsconfig.src.json +9 -0
- package/tsconfig.src.tsbuildinfo +1 -0
- package/bin/build-tokens.js +0 -83
- package/build/color-ramps/lib/cache-utils.js +0 -57
- package/build/color-ramps/lib/cache-utils.js.map +0 -7
- package/build/style.module.css.js +0 -2
- package/build-module/color-ramps/lib/cache-utils.js +0 -31
- package/build-module/color-ramps/lib/cache-utils.js.map +0 -7
- package/build-module/style.module.css.js +0 -1
- package/build-style/style.css +0 -3
- package/build-types/color-ramps/lib/cache-utils.d.ts +0 -22
- package/build-types/color-ramps/lib/cache-utils.d.ts.map +0 -1
- package/src/color-ramps/lib/cache-utils.ts +0 -56
- package/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -9,35 +9,95 @@ A theming package that's part of the WordPress Design System. It has two parts:
|
|
|
9
9
|
|
|
10
10
|
In the **[Design Tokens Reference](docs/ds-tokens.md)** document there is a complete reference of all available design tokens including colors, spacing, typography, and more.
|
|
11
11
|
|
|
12
|
+
### Color Tokens
|
|
13
|
+
|
|
14
|
+
The design system defines color tokens using the following naming scheme:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
--wpds-<element>-<tone>[-<emphasis>][-<state>]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Element** specifies what the color is applied to.
|
|
21
|
+
|
|
22
|
+
| Value | Description |
|
|
23
|
+
| -------------------- | ------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `bg-surface` | Backgrounds of layout or container surfaces. |
|
|
25
|
+
| `bg-interactive` | Backgrounds of interactive elements such as buttons, inputs, and toggles. |
|
|
26
|
+
| `bg-track` | Backgrounds of track components like scrollbars and slider tracks. |
|
|
27
|
+
| `bg-thumb` | Backgrounds of thumb components like scrollbar thumbs and slider thumbs. |
|
|
28
|
+
| `fg-content` | Foreground color for text and icons in static content. |
|
|
29
|
+
| `fg-interactive` | Foreground color for text and icons in interactive elements such as links and buttons. |
|
|
30
|
+
| `stroke-surface` | Decorative borders and dividers for non-interactive surfaces. |
|
|
31
|
+
| `stroke-interactive` | Accessible borders for interactive controls. |
|
|
32
|
+
| `stroke-focus` | Stroke color specifically for focus rings. |
|
|
33
|
+
|
|
34
|
+
**Tone** defines the semantic intent of the color.
|
|
35
|
+
|
|
36
|
+
| Value | Description |
|
|
37
|
+
| --------- | ---------------------------------------------------------------------------------------- |
|
|
38
|
+
| `neutral` | Neutrally toned UI elements. |
|
|
39
|
+
| `brand` | Brand-accented or primary action colors. |
|
|
40
|
+
| `success` | Positive or completed states. |
|
|
41
|
+
| `info` | Informational or system-generated context. |
|
|
42
|
+
| `caution` | Heads-up or low-severity issues; “proceed carefully.” |
|
|
43
|
+
| `warning` | Higher-severity or time-sensitive issues that require user attention but are not errors. |
|
|
44
|
+
| `error` | Blocking issues, validation failures, or destructive actions. |
|
|
45
|
+
|
|
46
|
+
> [!NOTE]
|
|
47
|
+
> `caution` and `warning` represent two escalation levels of non-error severity.
|
|
48
|
+
> Use **`caution`** for guidance or minor risks, and **`warning`** when the user must act to prevent an error.
|
|
49
|
+
|
|
50
|
+
**Emphasis** adjusts color strength relative to the base tone, if specified. The default is a normal emphasis.
|
|
51
|
+
|
|
52
|
+
| Value | Description |
|
|
53
|
+
| -------------------- | ------------------------------------------- |
|
|
54
|
+
| `strong` | Higher contrast and/or elevated emphasis. |
|
|
55
|
+
| `weak` | Subtle variant for secondary or muted elements. |
|
|
56
|
+
|
|
57
|
+
**State** represents the interactive state of the element, if specified. The default is an idle state.
|
|
58
|
+
|
|
59
|
+
| Value | Description |
|
|
60
|
+
| ---------- | ---------------------------------------- |
|
|
61
|
+
| `active` | Hovered, pressed, or selected state. |
|
|
62
|
+
| `disabled` | Unavailable or inoperable state. |
|
|
63
|
+
|
|
12
64
|
## Theme Provider
|
|
13
65
|
|
|
14
|
-
The `ThemeProvider` is a React component that should wrap your application to provide design tokens and theme context to the child UI components.
|
|
66
|
+
The `ThemeProvider` is a React component that should wrap your application to provide design tokens and theme context to the child UI components. It accepts a set of customizable seed values and automatically generates a set of design tokens, which are exposed as CSS custom properties for use throughout the application.
|
|
15
67
|
|
|
16
68
|
```tsx
|
|
17
69
|
import { ThemeProvider } from '@wordpress/theme';
|
|
18
70
|
|
|
19
71
|
function App() {
|
|
20
72
|
return (
|
|
21
|
-
<ThemeProvider color={ {
|
|
73
|
+
<ThemeProvider color={ { primary: 'blue' } }>
|
|
22
74
|
{ /* Your app content */ }
|
|
23
75
|
</ThemeProvider>
|
|
24
76
|
);
|
|
25
77
|
}
|
|
26
78
|
```
|
|
27
79
|
|
|
80
|
+
The `color` prop accepts an object with the following optional properties:
|
|
81
|
+
|
|
82
|
+
- `primary`: The primary/accent seed color (default: `'#3858e9'`)
|
|
83
|
+
- `bg`: The background seed color (default: `'#f8f8f8'`)
|
|
84
|
+
|
|
85
|
+
Both properties accept any valid CSS color value. The theme system automatically generates appropriate color ramps and determines light/dark mode based on these seed colors.
|
|
86
|
+
|
|
87
|
+
### Nesting Providers
|
|
88
|
+
|
|
28
89
|
The provider can be used recursively to override or modify the theme for a specific subtree.
|
|
29
90
|
|
|
30
91
|
```tsx
|
|
31
|
-
<ThemeProvider>
|
|
32
|
-
{ /*
|
|
33
|
-
<ThemeProvider color={ {
|
|
92
|
+
<ThemeProvider color={ { bg: 'white' } }>
|
|
93
|
+
{ /* light-themed UI components */ }
|
|
94
|
+
<ThemeProvider color={ { bg: '#1e1e1e' } }>
|
|
34
95
|
{ /* dark-themed UI components */ }
|
|
35
|
-
<ThemeProvider color={ {
|
|
36
|
-
{ /*
|
|
96
|
+
<ThemeProvider color={ { primary: 'red' } }>
|
|
97
|
+
{ /* dark-themed with red accent */ }
|
|
37
98
|
</ThemeProvider>
|
|
38
|
-
{ /* dark-themed UI components */ }
|
|
39
99
|
</ThemeProvider>
|
|
40
|
-
{ /*
|
|
100
|
+
{ /* light-themed UI components */ }
|
|
41
101
|
</ThemeProvider>
|
|
42
102
|
```
|
|
43
103
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { writeFile } from 'node:fs/promises';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
import {
|
|
12
|
+
DEFAULT_SEED_COLORS,
|
|
13
|
+
buildBgRamp,
|
|
14
|
+
buildAccentRamp,
|
|
15
|
+
} from '../../src/color-ramps/index.ts';
|
|
16
|
+
|
|
17
|
+
const __dirname = dirname( fileURLToPath( import.meta.url ) );
|
|
18
|
+
|
|
19
|
+
const bgRamp = buildBgRamp( DEFAULT_SEED_COLORS.bg );
|
|
20
|
+
const accentRamps = Object.fromEntries(
|
|
21
|
+
[ ...Object.entries( DEFAULT_SEED_COLORS ) ]
|
|
22
|
+
.filter( ( [ scaleName ] ) => scaleName !== 'bg' )
|
|
23
|
+
.map( ( [ scaleName, seed ] ) => [
|
|
24
|
+
scaleName,
|
|
25
|
+
buildAccentRamp( seed, bgRamp ),
|
|
26
|
+
] )
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const ramps = { bg: bgRamp, ...accentRamps };
|
|
30
|
+
|
|
31
|
+
const outputPath = join(
|
|
32
|
+
__dirname,
|
|
33
|
+
'../../src/color-ramps/lib/default-ramps.ts'
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const content = `
|
|
37
|
+
/**
|
|
38
|
+
* Internal dependencies
|
|
39
|
+
*/
|
|
40
|
+
import type { RampResult } from './types';
|
|
41
|
+
import type { DEFAULT_SEED_COLORS } from './constants';
|
|
42
|
+
|
|
43
|
+
export const DEFAULT_RAMPS: Record<
|
|
44
|
+
keyof typeof DEFAULT_SEED_COLORS,
|
|
45
|
+
RampResult
|
|
46
|
+
> = ${ JSON.stringify( ramps ) };
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
await writeFile( outputPath, content );
|
|
@@ -4,11 +4,19 @@
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { fileURLToPath } from 'url';
|
|
7
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
parse,
|
|
9
|
+
to,
|
|
10
|
+
serialize,
|
|
11
|
+
OKLCH,
|
|
12
|
+
sRGB,
|
|
13
|
+
type PlainColorObject,
|
|
14
|
+
} from 'colorjs.io/fn';
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* Internal dependencies
|
|
11
18
|
*/
|
|
19
|
+
import '../../src/color-ramps/lib/register-color-spaces';
|
|
12
20
|
import {
|
|
13
21
|
DEFAULT_SEED_COLORS,
|
|
14
22
|
buildBgRamp,
|
|
@@ -23,9 +31,9 @@ const colorJsonPath = path.join( __dirname, '../../tokens/color.json' );
|
|
|
23
31
|
|
|
24
32
|
const transformColorStringToDTCGValue = ( color: string ) => {
|
|
25
33
|
if ( /oklch|p3/.test( color ) ) {
|
|
26
|
-
let parsed:
|
|
34
|
+
let parsed: PlainColorObject;
|
|
27
35
|
try {
|
|
28
|
-
parsed =
|
|
36
|
+
parsed = to( parse( color ), OKLCH );
|
|
29
37
|
} catch {
|
|
30
38
|
return color;
|
|
31
39
|
}
|
|
@@ -39,7 +47,7 @@ const transformColorStringToDTCGValue = ( color: string ) => {
|
|
|
39
47
|
isNaN( coords[ 2 ] ) ? 0 : coords[ 2 ], // h
|
|
40
48
|
],
|
|
41
49
|
...( parsed.alpha < 1 ? { alpha: parsed.alpha } : undefined ),
|
|
42
|
-
hex:
|
|
50
|
+
hex: serialize( to( parsed, sRGB ), { format: 'hex' } ),
|
|
43
51
|
};
|
|
44
52
|
}
|
|
45
53
|
|
|
@@ -58,15 +66,12 @@ function generatePrimitiveColorTokens() {
|
|
|
58
66
|
);
|
|
59
67
|
|
|
60
68
|
// Build the ramps
|
|
61
|
-
const bgRamp = buildBgRamp(
|
|
69
|
+
const bgRamp = buildBgRamp( DEFAULT_SEED_COLORS.bg );
|
|
62
70
|
const accentRamps = [ ...Object.entries( DEFAULT_SEED_COLORS ) ]
|
|
63
71
|
.filter( ( [ scaleName ] ) => scaleName !== 'bg' )
|
|
64
72
|
.map( ( [ scaleName, seed ] ) => ( {
|
|
65
73
|
scaleName,
|
|
66
|
-
ramp: buildAccentRamp(
|
|
67
|
-
seed,
|
|
68
|
-
bgRamp,
|
|
69
|
-
} ),
|
|
74
|
+
ramp: buildAccentRamp( seed, bgRamp ),
|
|
70
75
|
} ) );
|
|
71
76
|
|
|
72
77
|
// Convert the ramp values in a DTCG compatible format
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { Plugin, TokenNormalized } from '@terrazzo/parser';
|
|
5
5
|
import { transformCSSValue } from '@terrazzo/token-tools/css';
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
parse,
|
|
8
|
+
to,
|
|
9
|
+
serialize,
|
|
10
|
+
sRGB,
|
|
11
|
+
type ColorConstructor,
|
|
12
|
+
} from 'colorjs.io/fn';
|
|
7
13
|
|
|
8
14
|
/**
|
|
9
15
|
* Internal dependencies
|
|
10
16
|
*/
|
|
17
|
+
import '../../src/color-ramps/lib/register-color-spaces';
|
|
11
18
|
import { FORMAT_JSON_ID } from './lib';
|
|
12
19
|
|
|
13
20
|
function titleCase( str: string ) {
|
|
@@ -113,15 +120,15 @@ function transformColorToken(
|
|
|
113
120
|
|
|
114
121
|
// Always convert to hex
|
|
115
122
|
// (easier to convert to Figma RGB, and includes clamping)
|
|
116
|
-
let convertedColor:
|
|
123
|
+
let convertedColor: ColorConstructor;
|
|
117
124
|
try {
|
|
118
|
-
convertedColor =
|
|
125
|
+
convertedColor = parse( cssColorValue );
|
|
119
126
|
} catch {
|
|
120
127
|
console.warn( 'Unexpected: could not convert token value to Color' );
|
|
121
128
|
return;
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
return
|
|
131
|
+
return serialize( to( convertedColor, sRGB ), { format: 'hex' } );
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
export default function pluginFigmaDsTokenManager( {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
@@ -17,15 +14,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
14
|
}
|
|
18
15
|
return to;
|
|
19
16
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/theme/src/color-ramps/index.ts
|
|
29
20
|
var color_ramps_exports = {};
|
|
30
21
|
__export(color_ramps_exports, {
|
|
31
22
|
DEFAULT_SEED_COLORS: () => import_constants2.DEFAULT_SEED_COLORS,
|
|
@@ -34,48 +25,39 @@ __export(color_ramps_exports, {
|
|
|
34
25
|
checkAccessibleCombinations: () => checkAccessibleCombinations
|
|
35
26
|
});
|
|
36
27
|
module.exports = __toCommonJS(color_ramps_exports);
|
|
37
|
-
var
|
|
28
|
+
var import_fn = require("colorjs.io/fn");
|
|
29
|
+
var import_register_color_spaces = require("./lib/register-color-spaces");
|
|
38
30
|
var import_lib = require("./lib/index");
|
|
39
31
|
var import_utils = require("./lib/utils");
|
|
40
32
|
var import_ramp_configs = require("./lib/ramp-configs");
|
|
41
|
-
var
|
|
33
|
+
var import_color_utils = require("./lib/color-utils");
|
|
42
34
|
var import_constants = require("./lib/constants");
|
|
43
35
|
var import_constants2 = require("./lib/constants");
|
|
44
|
-
function buildBgRamp({
|
|
45
|
-
seed,
|
|
46
|
-
debug
|
|
47
|
-
}) {
|
|
36
|
+
function buildBgRamp(seed) {
|
|
48
37
|
if (typeof seed !== "string" || seed.trim() === "") {
|
|
49
38
|
throw new Error("Seed color must be a non-empty string");
|
|
50
39
|
}
|
|
51
|
-
return (0, import_lib.buildRamp)(seed, import_ramp_configs.BG_RAMP_CONFIG
|
|
40
|
+
return (0, import_lib.buildRamp)(seed, import_ramp_configs.BG_RAMP_CONFIG);
|
|
52
41
|
}
|
|
53
|
-
|
|
42
|
+
var STEP_TO_PIN = "surface2";
|
|
54
43
|
function getBgRampInfo(ramp) {
|
|
55
44
|
return {
|
|
56
45
|
mainDirection: ramp.direction,
|
|
57
46
|
pinLightness: {
|
|
58
47
|
stepName: STEP_TO_PIN,
|
|
59
48
|
value: (0, import_utils.clampAccentScaleReferenceLightness)(
|
|
60
|
-
|
|
49
|
+
(0, import_fn.get)((0, import_fn.parse)(ramp.ramp[STEP_TO_PIN].color), [import_fn.OKLCH, "l"]),
|
|
61
50
|
ramp.direction
|
|
62
51
|
)
|
|
63
52
|
}
|
|
64
53
|
};
|
|
65
54
|
}
|
|
66
|
-
function buildAccentRamp({
|
|
67
|
-
seed,
|
|
68
|
-
bgRamp,
|
|
69
|
-
debug
|
|
70
|
-
}) {
|
|
55
|
+
function buildAccentRamp(seed, bgRamp) {
|
|
71
56
|
if (typeof seed !== "string" || seed.trim() === "") {
|
|
72
57
|
throw new Error("Seed color must be a non-empty string");
|
|
73
58
|
}
|
|
74
59
|
const bgRampInfo = bgRamp ? getBgRampInfo(bgRamp) : void 0;
|
|
75
|
-
return (0, import_lib.buildRamp)(seed, import_ramp_configs.ACCENT_RAMP_CONFIG,
|
|
76
|
-
...bgRampInfo,
|
|
77
|
-
debug
|
|
78
|
-
});
|
|
60
|
+
return (0, import_lib.buildRamp)(seed, import_ramp_configs.ACCENT_RAMP_CONFIG, bgRampInfo);
|
|
79
61
|
}
|
|
80
62
|
function checkAccessibleCombinations({
|
|
81
63
|
bgRamp,
|
|
@@ -86,14 +68,14 @@ function checkAccessibleCombinations({
|
|
|
86
68
|
import_constants.CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
|
|
87
69
|
for (const bg of bgs) {
|
|
88
70
|
for (const fg of fgs) {
|
|
89
|
-
const bgColor =
|
|
90
|
-
const fgColor =
|
|
91
|
-
if ((0,
|
|
71
|
+
const bgColor = (0, import_fn.parse)(ramp.ramp[bg].color);
|
|
72
|
+
const fgColor = (0, import_fn.parse)(ramp.ramp[fg].color);
|
|
73
|
+
if ((0, import_color_utils.getContrast)(bgColor, fgColor) < target) {
|
|
92
74
|
unmetTargets.push({
|
|
93
75
|
bgName: bg,
|
|
94
|
-
bgColor:
|
|
76
|
+
bgColor: (0, import_fn.serialize)(bgColor),
|
|
95
77
|
fgName: fg,
|
|
96
|
-
fgColor:
|
|
78
|
+
fgColor: (0, import_fn.serialize)(fgColor),
|
|
97
79
|
unmetContrast: target
|
|
98
80
|
});
|
|
99
81
|
}
|
|
@@ -105,14 +87,14 @@ function checkAccessibleCombinations({
|
|
|
105
87
|
import_constants.CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
|
|
106
88
|
for (const bg of bgs) {
|
|
107
89
|
for (const fg of fgs) {
|
|
108
|
-
const bgColor =
|
|
109
|
-
const fgColor =
|
|
110
|
-
if ((0,
|
|
90
|
+
const bgColor = (0, import_fn.parse)(bgRamp.ramp[bg].color);
|
|
91
|
+
const fgColor = (0, import_fn.parse)(ramp.ramp[fg].color);
|
|
92
|
+
if ((0, import_color_utils.getContrast)(bgColor, fgColor) < target) {
|
|
111
93
|
unmetTargets.push({
|
|
112
94
|
bgName: bg,
|
|
113
|
-
bgColor:
|
|
95
|
+
bgColor: (0, import_fn.serialize)(bgColor),
|
|
114
96
|
fgName: fg,
|
|
115
|
-
fgColor:
|
|
97
|
+
fgColor: (0, import_fn.serialize)(fgColor),
|
|
116
98
|
unmetContrast: target
|
|
117
99
|
});
|
|
118
100
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/color-ramps/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_constants"
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { get, OKLCH, parse, serialize } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './lib/register-color-spaces';\nimport { buildRamp } from './lib/index';\nimport { clampAccentScaleReferenceLightness } from './lib/utils';\nimport { BG_RAMP_CONFIG, ACCENT_RAMP_CONFIG } from './lib/ramp-configs';\nimport type {\n\tRampResult as InternalRampResult,\n\tRampDirection,\n\tRamp,\n} from './lib/types';\nimport { getContrast } from './lib/color-utils';\nimport { CONTRAST_COMBINATIONS } from './lib/constants';\nexport { DEFAULT_SEED_COLORS } from './lib/constants';\n\n/**\n * Creates a background ramp.\n * @param seed The seed color for the background ramp.\n */\nexport function buildBgRamp( seed: string ) {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\treturn buildRamp( seed, BG_RAMP_CONFIG );\n}\n\nconst STEP_TO_PIN = 'surface2';\nfunction getBgRampInfo( ramp: InternalRampResult ): {\n\tmainDirection: RampDirection;\n\tpinLightness: {\n\t\tstepName: keyof Ramp;\n\t\tvalue: number;\n\t};\n} {\n\treturn {\n\t\tmainDirection: ramp.direction,\n\t\tpinLightness: {\n\t\t\tstepName: STEP_TO_PIN,\n\t\t\tvalue: clampAccentScaleReferenceLightness(\n\t\t\t\tget( parse( ramp.ramp[ STEP_TO_PIN ].color ), [ OKLCH, 'l' ] ),\n\t\t\t\tramp.direction\n\t\t\t),\n\t\t},\n\t};\n}\n\n/**\n * Creates an accent ramp (ie used by primary, success, info, warning and error\n * ramps).\n * @param seed The seed color for the accent ramp.\n * @param bgRamp The ramp of the background on which the accent is shown.\n */\nexport function buildAccentRamp(\n\tseed: string,\n\tbgRamp?: InternalRampResult\n): InternalRampResult {\n\tif ( typeof seed !== 'string' || seed.trim() === '' ) {\n\t\tthrow new Error( 'Seed color must be a non-empty string' );\n\t}\n\n\tconst bgRampInfo = bgRamp ? getBgRampInfo( bgRamp ) : undefined;\n\treturn buildRamp( seed, ACCENT_RAMP_CONFIG, bgRampInfo );\n}\n\n/**\n * Checks that all bg/fg combinations generated by the ramps meet contrast\n * targets.\n * @param params\n * @param params.bgRamp\n * @param params.accentRamps\n */\nexport function checkAccessibleCombinations( {\n\tbgRamp,\n\taccentRamps = [],\n}: {\n\tbgRamp: InternalRampResult;\n\taccentRamps?: InternalRampResult[];\n} ) {\n\tconst unmetTargets: {\n\t\tbgName: keyof Ramp;\n\t\tbgColor: string;\n\t\tfgName: keyof Ramp;\n\t\tfgColor: string;\n\t\tunmetContrast: number;\n\t}[] = [];\n\n\t// Assess combinations within each ramp\n\t[ bgRamp, ...accentRamps ].forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = parse( ramp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: serialize( bgColor ),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: serialize( fgColor ),\n\t\t\t\t\t\t\tunmetContrast: target,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t} );\n\t// Assess each accent ramp's fg color against bg ramp\n\taccentRamps.forEach( ( ramp ) => {\n\t\tCONTRAST_COMBINATIONS.forEach( ( { bgs, fgs, target } ) => {\n\t\t\tfor ( const bg of bgs ) {\n\t\t\t\tfor ( const fg of fgs ) {\n\t\t\t\t\tconst bgColor = parse( bgRamp.ramp[ bg ].color );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ].color );\n\t\t\t\t\tif ( getContrast( bgColor, fgColor ) < target ) {\n\t\t\t\t\t\tunmetTargets.push( {\n\t\t\t\t\t\t\tbgName: bg,\n\t\t\t\t\t\t\tbgColor: serialize( bgColor ),\n\t\t\t\t\t\t\tfgName: fg,\n\t\t\t\t\t\t\tfgColor: serialize( fgColor ),\n\t\t\t\t\t\t\tunmetContrast: target,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t} );\n\n\treturn unmetTargets;\n}\n\nexport type RampResult = InternalRampResult;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gBAA6C;AAK7C,mCAAO;AACP,iBAA0B;AAC1B,mBAAmD;AACnD,0BAAmD;AAMnD,yBAA4B;AAC5B,uBAAsC;AACtC,IAAAA,oBAAoC;AAM7B,SAAS,YAAa,MAAe;AAC3C,MAAK,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,IAAK;AACrD,UAAM,IAAI,MAAO,uCAAwC;AAAA,EAC1D;AAEA,aAAO,sBAAW,MAAM,kCAAe;AACxC;AAEA,IAAM,cAAc;AACpB,SAAS,cAAe,MAMtB;AACD,SAAO;AAAA,IACN,eAAe,KAAK;AAAA,IACpB,cAAc;AAAA,MACb,UAAU;AAAA,MACV,WAAO;AAAA,YACN,mBAAK,iBAAO,KAAK,KAAM,WAAY,EAAE,KAAM,GAAG,CAAE,iBAAO,GAAI,CAAE;AAAA,QAC7D,KAAK;AAAA,MACN;AAAA,IACD;AAAA,EACD;AACD;AAQO,SAAS,gBACf,MACA,QACqB;AACrB,MAAK,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,IAAK;AACrD,UAAM,IAAI,MAAO,uCAAwC;AAAA,EAC1D;AAEA,QAAM,aAAa,SAAS,cAAe,MAAO,IAAI;AACtD,aAAO,sBAAW,MAAM,wCAAoB,UAAW;AACxD;AASO,SAAS,4BAA6B;AAAA,EAC5C;AAAA,EACA,cAAc,CAAC;AAChB,GAGI;AACH,QAAM,eAMA,CAAC;AAGP,GAAE,QAAQ,GAAG,WAAY,EAAE,QAAS,CAAE,SAAU;AAC/C,2CAAsB,QAAS,CAAE,EAAE,KAAK,KAAK,OAAO,MAAO;AAC1D,iBAAY,MAAM,KAAM;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,cAAU,iBAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,gBAAM,cAAU,iBAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,kBAAK,gCAAa,SAAS,OAAQ,IAAI,QAAS;AAC/C,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,aAAS,qBAAW,OAAQ;AAAA,cAC5B,QAAQ;AAAA,cACR,aAAS,qBAAW,OAAQ;AAAA,cAC5B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,cAAY,QAAS,CAAE,SAAU;AAChC,2CAAsB,QAAS,CAAE,EAAE,KAAK,KAAK,OAAO,MAAO;AAC1D,iBAAY,MAAM,KAAM;AACvB,mBAAY,MAAM,KAAM;AACvB,gBAAM,cAAU,iBAAO,OAAO,KAAM,EAAG,EAAE,KAAM;AAC/C,gBAAM,cAAU,iBAAO,KAAK,KAAM,EAAG,EAAE,KAAM;AAC7C,kBAAK,gCAAa,SAAS,OAAQ,IAAI,QAAS;AAC/C,yBAAa,KAAM;AAAA,cAClB,QAAQ;AAAA,cACR,aAAS,qBAAW,OAAQ;AAAA,cAC5B,QAAQ;AAAA,cACR,aAAS,qBAAW,OAAQ;AAAA,cAC5B,eAAe;AAAA,YAChB,CAAE;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AAEF,SAAO;AACR;",
|
|
6
|
+
"names": ["import_constants"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to2, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
13
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to2;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/theme/src/color-ramps/lib/color-utils.ts
|
|
20
|
+
var color_utils_exports = {};
|
|
21
|
+
__export(color_utils_exports, {
|
|
22
|
+
getColorString: () => getColorString,
|
|
23
|
+
getContrast: () => getContrast
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(color_utils_exports);
|
|
26
|
+
var import_fn = require("colorjs.io/fn");
|
|
27
|
+
var import_register_color_spaces = require("./register-color-spaces");
|
|
28
|
+
function getColorString(color) {
|
|
29
|
+
return (0, import_fn.serialize)((0, import_fn.to)(color, import_fn.sRGB), { format: "hex", inGamut: true });
|
|
30
|
+
}
|
|
31
|
+
function getContrast(colorA, colorB) {
|
|
32
|
+
return (0, import_fn.contrastWCAG21)(colorA, colorB);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
getColorString,
|
|
37
|
+
getContrast
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=color-utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/color-ramps/lib/color-utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tto,\n\tserialize,\n\tcontrastWCAG21,\n\tsRGB,\n\ttype ColorTypes,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\n\n/**\n * Get string representation of a color\n * @param color Color object to stringify\n * @return String representation\n */\nexport function getColorString( color: ColorTypes ): string {\n\treturn serialize( to( color, sRGB ), { format: 'hex', inGamut: true } );\n}\n\n/**\n * Get contrast value between two colors\n * @param colorA First color\n * @param colorB Second color\n * @return WCAG 2.1 contrast ratio\n */\nexport function getContrast( colorA: ColorTypes, colorB: ColorTypes ): number {\n\treturn contrastWCAG21( colorA, colorB );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gBAMO;AAKP,mCAAO;AAOA,SAAS,eAAgB,OAA4B;AAC3D,aAAO,yBAAW,cAAI,OAAO,cAAK,GAAG,EAAE,QAAQ,OAAO,SAAS,KAAK,CAAE;AACvE;AAQO,SAAS,YAAa,QAAoB,QAA6B;AAC7E,aAAO,0BAAgB,QAAQ,MAAO;AACvC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __export = (target, all) => {
|
|
9
6
|
for (var name in all)
|
|
10
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
8
|
};
|
|
12
|
-
var __copyProps = (
|
|
9
|
+
var __copyProps = (to2, from, except, desc) => {
|
|
13
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(
|
|
16
|
-
__defProp(
|
|
12
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
13
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
14
|
}
|
|
18
|
-
return
|
|
15
|
+
return to2;
|
|
19
16
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/theme/src/color-ramps/lib/constants.ts
|
|
29
20
|
var constants_exports = {};
|
|
30
21
|
__export(constants_exports, {
|
|
31
22
|
ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS: () => ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS,
|
|
@@ -39,18 +30,19 @@ __export(constants_exports, {
|
|
|
39
30
|
WHITE_TEXT_CONTRAST_MARGIN: () => WHITE_TEXT_CONTRAST_MARGIN
|
|
40
31
|
});
|
|
41
32
|
module.exports = __toCommonJS(constants_exports);
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
var import_fn = require("colorjs.io/fn");
|
|
34
|
+
var import_register_color_spaces = require("./register-color-spaces");
|
|
35
|
+
var WHITE = (0, import_fn.to)("white", import_fn.OKLCH);
|
|
36
|
+
var BLACK = (0, import_fn.to)("black", import_fn.OKLCH);
|
|
37
|
+
var UNIVERSAL_CONTRAST_TOPUP = 0.05;
|
|
38
|
+
var WHITE_TEXT_CONTRAST_MARGIN = 3.1;
|
|
39
|
+
var ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {
|
|
48
40
|
lighter: { min: 0.2, max: 0.4 },
|
|
49
41
|
darker: { min: 0.75, max: 0.98 }
|
|
50
42
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
var LIGHTNESS_EPSILON = 4e-3;
|
|
44
|
+
var MAX_BISECTION_ITERATIONS = 10;
|
|
45
|
+
var CONTRAST_COMBINATIONS = [
|
|
54
46
|
{
|
|
55
47
|
bgs: ["surface1", "surface2", "surface3"],
|
|
56
48
|
fgs: ["fgSurface3", "fgSurface4"],
|
|
@@ -82,11 +74,12 @@ const CONTRAST_COMBINATIONS = [
|
|
|
82
74
|
target: 3
|
|
83
75
|
}
|
|
84
76
|
];
|
|
85
|
-
|
|
77
|
+
var DEFAULT_SEED_COLORS = {
|
|
86
78
|
bg: "#f8f8f8",
|
|
87
79
|
primary: "#3858e9",
|
|
88
80
|
info: "#0090ff",
|
|
89
81
|
success: "#4ab866",
|
|
82
|
+
caution: "#f0d149",
|
|
90
83
|
warning: "#f0b849",
|
|
91
84
|
error: "#cc1818"
|
|
92
85
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/constants.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { to, OKLCH } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport type { Ramp } from './types';\n\nexport const WHITE = to( 'white', OKLCH );\nexport const BLACK = to( 'black', OKLCH );\n\n// Margin added to target contrasts to counter for algorithm approximations\n// and rounding errors.\nexport const UNIVERSAL_CONTRAST_TOPUP = 0.05;\n\n// When enabling \"lighter direction\" bias, this is the amount by which\n// black text contrast needs to be greater than white text contrast.\n// The higher the value, the stronger the preference for white text.\n// The current value has been determined empirically as the highest value\n// that won't cause the algo not to be able to correctly solve all contrasts.\nexport const WHITE_TEXT_CONTRAST_MARGIN = 3.1;\n\n// These values are used as thresholds when trying to match the background\n// ramp's lightness while calculating an accent ramp. They prevent the accent\n// scale from being pinned to lightness values in the middle of the range,\n// which would cause the algorithm to struggle to satisfy the accent scale\n// constraints and therefore produce unexpected results.\nexport const ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {\n\tlighter: { min: 0.2, max: 0.4 },\n\tdarker: { min: 0.75, max: 0.98 },\n} as const;\n\n// Lightness precision we aim for. Approximately 1/256, resolution of an 8-bit number.\nexport const LIGHTNESS_EPSILON = 4e-3;\n\nexport const MAX_BISECTION_ITERATIONS = 10;\n\nexport const CONTRAST_COMBINATIONS: {\n\tbgs: ( keyof Ramp )[];\n\tfgs: ( keyof Ramp )[];\n\ttarget: number;\n}[] = [\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'fgSurface3', 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface4', 'surface5' ],\n\t\tfgs: [ 'fgSurface4' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFill1' ],\n\t\tfgs: [ 'fgFill' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'bgFillInverted1' ],\n\t\tfgs: [ 'fgFillInverted' ],\n\t\ttarget: 4.5,\n\t},\n\t{\n\t\tbgs: [ 'surface1', 'surface2', 'surface3' ],\n\t\tfgs: [ 'stroke3' ],\n\t\ttarget: 3,\n\t},\n];\n\n// Used when generating the DTCG tokens and the static color ramps.\nexport const DEFAULT_SEED_COLORS = {\n\tbg: '#f8f8f8',\n\tprimary: '#3858e9',\n\tinfo: '#0090ff',\n\tsuccess: '#4ab866',\n\tcaution: '#f0d149',\n\twarning: '#f0b849',\n\terror: '#cc1818',\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gBAA0B;AAK1B,mCAAO;AAGA,IAAM,YAAQ,cAAI,SAAS,eAAM;AACjC,IAAM,YAAQ,cAAI,SAAS,eAAM;AAIjC,IAAM,2BAA2B;AAOjC,IAAM,6BAA6B;AAOnC,IAAM,yCAAyC;AAAA,EACrD,SAAS,EAAE,KAAK,KAAK,KAAK,IAAI;AAAA,EAC9B,QAAQ,EAAE,KAAK,MAAM,KAAK,KAAK;AAChC;AAGO,IAAM,oBAAoB;AAE1B,IAAM,2BAA2B;AAEjC,IAAM,wBAIP;AAAA,EACL;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAAK,CAAE,cAAc,YAAa;AAAA,IAClC,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,UAAW;AAAA,IAC9B,KAAK,CAAE,YAAa;AAAA,IACpB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,SAAU;AAAA,IACjB,KAAK,CAAE,QAAS;AAAA,IAChB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,iBAAkB;AAAA,IACzB,KAAK,CAAE,gBAAiB;AAAA,IACxB,QAAQ;AAAA,EACT;AAAA,EACA;AAAA,IACC,KAAK,CAAE,YAAY,YAAY,UAAW;AAAA,IAC1C,KAAK,CAAE,SAAU;AAAA,IACjB,QAAQ;AAAA,EACT;AACD;AAGO,IAAM,sBAAsB;AAAA,EAClC,IAAI;AAAA,EACJ,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|