@wordpress/theme 0.1.1-next.2f1c7c01b.0 → 0.2.1-next.16d95556a.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 +5 -1
- package/bin/generate-primitive-tokens/index.ts +1 -1
- package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +5 -24
- package/bin/terrazzo-plugin-inline-alias-values/index.ts +84 -0
- package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +19 -39
- package/build/color-ramps/index.js +5 -5
- package/build/color-ramps/index.js.map +2 -2
- package/build/color-ramps/lib/constants.js +4 -4
- package/build/color-ramps/lib/constants.js.map +2 -2
- package/build/color-ramps/lib/default-ramps.js +154 -154
- package/build/color-ramps/lib/default-ramps.js.map +2 -2
- package/build/color-ramps/lib/find-color-with-constraints.js +36 -53
- package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build/color-ramps/lib/index.js +72 -64
- package/build/color-ramps/lib/index.js.map +2 -2
- package/build/color-ramps/lib/ramp-configs.js +3 -3
- package/build/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build/color-ramps/lib/types.js.map +1 -1
- package/build/color-ramps/lib/utils.js +63 -2
- package/build/color-ramps/lib/utils.js.map +2 -2
- package/build/prebuilt/js/design-tokens.js +5 -10
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/json/figma.json +105 -905
- package/build/prebuilt/ts/color-tokens.js +137 -0
- package/build/prebuilt/ts/color-tokens.js.map +7 -0
- package/build/token-id.js +30 -0
- package/build/token-id.js.map +7 -0
- package/build/use-theme-provider-styles.js +15 -27
- package/build/use-theme-provider-styles.js.map +3 -3
- package/build-module/color-ramps/index.js +5 -5
- package/build-module/color-ramps/index.js.map +2 -2
- package/build-module/color-ramps/lib/constants.js +3 -3
- package/build-module/color-ramps/lib/constants.js.map +2 -2
- package/build-module/color-ramps/lib/default-ramps.js +154 -154
- package/build-module/color-ramps/lib/default-ramps.js.map +2 -2
- package/build-module/color-ramps/lib/find-color-with-constraints.js +38 -60
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +76 -66
- package/build-module/color-ramps/lib/index.js.map +2 -2
- package/build-module/color-ramps/lib/ramp-configs.js +3 -3
- package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
- package/build-module/color-ramps/lib/utils.js +63 -2
- package/build-module/color-ramps/lib/utils.js.map +2 -2
- package/build-module/prebuilt/js/design-tokens.js +5 -10
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/json/figma.json +105 -905
- package/build-module/prebuilt/ts/color-tokens.js +117 -0
- package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
- package/build-module/token-id.js +6 -0
- package/build-module/token-id.js.map +7 -0
- package/build-module/use-theme-provider-styles.js +15 -27
- package/build-module/use-theme-provider-styles.js.map +2 -2
- package/build-types/color-ramps/lib/constants.d.ts +2 -2
- package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +2 -3
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/types.d.ts +2 -4
- package/build-types/color-ramps/lib/types.d.ts.map +1 -1
- package/build-types/color-ramps/lib/utils.d.ts +21 -2
- 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/color-ramps/stories/ramp-table.d.ts +2 -4
- package/build-types/color-ramps/stories/ramp-table.d.ts.map +1 -1
- package/build-types/prebuilt/ts/color-tokens.d.ts +7 -0
- package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/build-types/theme-provider.d.ts.map +1 -1
- package/build-types/token-id.d.ts +9 -0
- package/build-types/token-id.d.ts.map +1 -0
- package/build-types/use-theme-provider-styles.d.ts.map +1 -1
- package/docs/ds-tokens.md +10 -178
- package/package.json +4 -4
- package/src/color-ramps/index.ts +5 -5
- package/src/color-ramps/lib/constants.ts +7 -5
- package/src/color-ramps/lib/default-ramps.ts +154 -154
- package/src/color-ramps/lib/find-color-with-constraints.ts +53 -77
- package/src/color-ramps/lib/index.ts +100 -100
- package/src/color-ramps/lib/ramp-configs.ts +3 -3
- package/src/color-ramps/lib/types.ts +2 -7
- package/src/color-ramps/lib/utils.ts +109 -5
- package/src/color-ramps/stories/index.story.tsx +4 -1
- package/src/color-ramps/stories/ramp-table.tsx +15 -26
- package/src/color-ramps/test/__snapshots__/index.test.ts.snap +16891 -1059
- package/src/color-ramps/test/index.test.ts +43 -16
- package/src/prebuilt/css/design-tokens.css +88 -413
- package/src/prebuilt/js/design-tokens.js +5 -10
- package/src/prebuilt/json/figma.json +105 -905
- package/src/prebuilt/ts/color-tokens.ts +117 -0
- package/src/stories/index.story.tsx +4 -18
- package/src/test/token-id.test.ts +12 -0
- package/src/token-id.ts +9 -0
- package/src/use-theme-provider-styles.ts +17 -35
- package/terrazzo.config.ts +15 -12
- package/tokens/color.json +82 -82
- package/tokens/dimension.json +75 -0
- package/tsconfig.bin.tsbuildinfo +1 -1
- package/tsconfig.src.tsbuildinfo +1 -1
- package/build/prebuilt/ts/design-tokens.js +0 -391
- package/build/prebuilt/ts/design-tokens.js.map +0 -7
- package/build-module/prebuilt/ts/design-tokens.js +0 -371
- package/build-module/prebuilt/ts/design-tokens.js.map +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
- package/src/prebuilt/ts/design-tokens.ts +0 -371
- package/tokens/spacing.json +0 -45
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Theme
|
|
2
|
+
|
|
3
|
+
<div class="callout callout-alert">
|
|
4
|
+
This package is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
|
|
5
|
+
</div>
|
|
2
6
|
|
|
3
7
|
A theming package that's part of the WordPress Design System. It has two parts:
|
|
4
8
|
|
|
@@ -87,7 +87,7 @@ function generatePrimitiveColorTokens() {
|
|
|
87
87
|
ramp.ramp
|
|
88
88
|
) ) {
|
|
89
89
|
colorJson.color.primitive[ scaleName ][ tokenName ] = {
|
|
90
|
-
$value: transformColorStringToDTCGValue( tokenValue
|
|
90
|
+
$value: transformColorStringToDTCGValue( tokenValue ),
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
} );
|
|
@@ -4,10 +4,6 @@
|
|
|
4
4
|
import { FORMAT_ID } from '@terrazzo/plugin-css';
|
|
5
5
|
import type { Plugin } from '@terrazzo/parser';
|
|
6
6
|
|
|
7
|
-
function isPrivateToken( token: string ) {
|
|
8
|
-
return /-private-/i.test( token );
|
|
9
|
-
}
|
|
10
|
-
|
|
11
7
|
function titleCase( str: string ) {
|
|
12
8
|
return str[ 0 ].toUpperCase() + str.slice( 1 );
|
|
13
9
|
}
|
|
@@ -24,7 +20,6 @@ export default function pluginDsTokenDocs( {
|
|
|
24
20
|
return;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
const primitiveTokens: TokensMap = {};
|
|
28
23
|
const semanticTokens: TokensMap = {};
|
|
29
24
|
// Re-use transformed tokens from the CSS plugin
|
|
30
25
|
for ( const token of getTransforms( {
|
|
@@ -46,24 +41,16 @@ export default function pluginDsTokenDocs( {
|
|
|
46
41
|
.at( -1 )
|
|
47
42
|
?.split( '.json' )[ 0 ] ?? 'Miscellaneous';
|
|
48
43
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
: semanticTokens;
|
|
53
|
-
tokensObject[ group ] ??= {};
|
|
54
|
-
tokensObject[ group ][ token.localID ] =
|
|
44
|
+
// Group by category
|
|
45
|
+
semanticTokens[ group ] ??= {};
|
|
46
|
+
semanticTokens[ group ][ token.localID ] =
|
|
55
47
|
token.token.$description ?? 'N/A';
|
|
56
48
|
}
|
|
57
49
|
|
|
58
|
-
function tokensToMdTable(
|
|
59
|
-
tokens: TokensMap,
|
|
60
|
-
isPrivate: boolean = false
|
|
61
|
-
) {
|
|
50
|
+
function tokensToMdTable( tokens: TokensMap ) {
|
|
62
51
|
return Object.entries( tokens )
|
|
63
52
|
.map( ( [ group, tokensInGroup ] ) => [
|
|
64
|
-
`### ${ titleCase( group ) }
|
|
65
|
-
isPrivate ? ' (private)' : ''
|
|
66
|
-
}`,
|
|
53
|
+
`### ${ titleCase( group ) }`,
|
|
67
54
|
'',
|
|
68
55
|
'| Variable name | Description |',
|
|
69
56
|
'|---|---|',
|
|
@@ -89,12 +76,6 @@ export default function pluginDsTokenDocs( {
|
|
|
89
76
|
'## Semantic tokens',
|
|
90
77
|
'',
|
|
91
78
|
...tokensToMdTable( semanticTokens ),
|
|
92
|
-
'',
|
|
93
|
-
'## Primitive tokens',
|
|
94
|
-
'',
|
|
95
|
-
'**🚨 Note: These tokens are only private implementation details of the Theme, and should never be referenced / consumed directly in the code.**',
|
|
96
|
-
'',
|
|
97
|
-
...tokensToMdTable( primitiveTokens, true ),
|
|
98
79
|
'', // final empty line
|
|
99
80
|
].join( '\n' )
|
|
100
81
|
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { type Plugin } from '@terrazzo/parser';
|
|
5
|
+
|
|
6
|
+
interface InlineAliasValuesOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Output filename for the generated aliased tokens mapping.
|
|
9
|
+
*/
|
|
10
|
+
filename?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pattern matching IDs of tokens whose values should be inlined into their alias references.
|
|
14
|
+
*/
|
|
15
|
+
pattern: RegExp;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional function to transform token IDs in the output.
|
|
19
|
+
*/
|
|
20
|
+
tokenId?: ( tokenId: string ) => string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Inlines the values of tokens matching the given pattern into their alias
|
|
25
|
+
* references. Matching tokens are removed from the output, and a TypeScript
|
|
26
|
+
* file is emitted with the mapping of aliased tokens.
|
|
27
|
+
*
|
|
28
|
+
* @param options The options for the plugin.
|
|
29
|
+
* @param options.filename
|
|
30
|
+
* @param options.pattern
|
|
31
|
+
* @param options.tokenId
|
|
32
|
+
*/
|
|
33
|
+
export default function inlineAliasValues( {
|
|
34
|
+
filename,
|
|
35
|
+
pattern,
|
|
36
|
+
tokenId = ( id ) => id,
|
|
37
|
+
}: InlineAliasValuesOptions ): Plugin {
|
|
38
|
+
const aliasedBy: Record< string, string[] > = {};
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
name: '@wordpress/terrazzo-plugin-inline-alias-values',
|
|
42
|
+
async transform( { tokens } ) {
|
|
43
|
+
Object.keys( tokens )
|
|
44
|
+
.filter( ( id ) => pattern.test( id ) )
|
|
45
|
+
.forEach( ( id ) => {
|
|
46
|
+
const token = tokens[ id ];
|
|
47
|
+
if ( token.aliasedBy ) {
|
|
48
|
+
aliasedBy[ tokenId( id ) ] =
|
|
49
|
+
token.aliasedBy.map( tokenId );
|
|
50
|
+
|
|
51
|
+
for ( const aliasedId of token.aliasedBy ) {
|
|
52
|
+
Object.assign( tokens[ aliasedId ], {
|
|
53
|
+
$value: token.$value,
|
|
54
|
+
mode: token.mode,
|
|
55
|
+
originalValue: token.originalValue,
|
|
56
|
+
} );
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
delete tokens[ id ];
|
|
61
|
+
} );
|
|
62
|
+
},
|
|
63
|
+
async build( { outputFile } ) {
|
|
64
|
+
if ( ! filename ) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const json = JSON.stringify( aliasedBy, null, 2 );
|
|
69
|
+
|
|
70
|
+
outputFile(
|
|
71
|
+
filename,
|
|
72
|
+
[
|
|
73
|
+
'/**',
|
|
74
|
+
' * This file is generated by the @wordpress/terrazzo-plugin-inline-alias-values plugin.',
|
|
75
|
+
' * Do not edit this file directly.',
|
|
76
|
+
' */',
|
|
77
|
+
'',
|
|
78
|
+
`export default ${ json } as Record< string, string[] >;`,
|
|
79
|
+
'',
|
|
80
|
+
].join( '\n' )
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
import { FORMAT_ID } from '@terrazzo/plugin-css';
|
|
5
5
|
import type { Plugin } from '@terrazzo/parser';
|
|
6
6
|
|
|
7
|
-
function isPrivateToken( token: string ) {
|
|
8
|
-
return /-private-/i.test( token );
|
|
9
|
-
}
|
|
10
|
-
|
|
11
7
|
export default function pluginKnownWpdsCssVariables( {
|
|
12
|
-
|
|
8
|
+
filename = 'design-tokens.js',
|
|
13
9
|
} = {} ): Plugin {
|
|
14
10
|
return {
|
|
15
11
|
name: '@terrazzo/plugin-known-wpds-css-variables',
|
|
@@ -31,42 +27,26 @@ export default function pluginKnownWpdsCssVariables( {
|
|
|
31
27
|
continue;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
tokensToExport[ token.localID ][ token.mode ] = token.value;
|
|
38
|
-
}
|
|
30
|
+
tokensToExport[ token.localID ] ??= {};
|
|
31
|
+
tokensToExport[ token.localID ][ token.mode ] = token.value;
|
|
39
32
|
}
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
: tokensToExport,
|
|
59
|
-
null,
|
|
60
|
-
2
|
|
61
|
-
) }${
|
|
62
|
-
filename.endsWith( '.ts' ) && modes
|
|
63
|
-
? ' as Record< string, Record< string, string > >'
|
|
64
|
-
: ''
|
|
65
|
-
}`,
|
|
66
|
-
'', // final empty line
|
|
67
|
-
].join( '\n' )
|
|
68
|
-
);
|
|
69
|
-
}
|
|
34
|
+
outputFile(
|
|
35
|
+
filename,
|
|
36
|
+
[
|
|
37
|
+
'/**',
|
|
38
|
+
' * This file is generated by the @terrazzo/plugin-known-wpds-css-variables plugin.',
|
|
39
|
+
' * Do not edit this file directly.',
|
|
40
|
+
' */',
|
|
41
|
+
'',
|
|
42
|
+
`export default ${ JSON.stringify(
|
|
43
|
+
Array.from( new Set( Object.keys( tokensToExport ) ) ),
|
|
44
|
+
null,
|
|
45
|
+
2
|
|
46
|
+
) }`,
|
|
47
|
+
'', // final empty line
|
|
48
|
+
].join( '\n' )
|
|
49
|
+
);
|
|
70
50
|
},
|
|
71
51
|
};
|
|
72
52
|
}
|
|
@@ -46,7 +46,7 @@ function getBgRampInfo(ramp) {
|
|
|
46
46
|
pinLightness: {
|
|
47
47
|
stepName: STEP_TO_PIN,
|
|
48
48
|
value: (0, import_utils.clampAccentScaleReferenceLightness)(
|
|
49
|
-
(0, import_fn.get)((0, import_fn.parse)(ramp.ramp[STEP_TO_PIN]
|
|
49
|
+
(0, import_fn.get)((0, import_fn.parse)(ramp.ramp[STEP_TO_PIN]), [import_fn.OKLCH, "l"]),
|
|
50
50
|
ramp.direction
|
|
51
51
|
)
|
|
52
52
|
}
|
|
@@ -68,8 +68,8 @@ function checkAccessibleCombinations({
|
|
|
68
68
|
import_constants.CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
|
|
69
69
|
for (const bg of bgs) {
|
|
70
70
|
for (const fg of fgs) {
|
|
71
|
-
const bgColor = (0, import_fn.parse)(ramp.ramp[bg]
|
|
72
|
-
const fgColor = (0, import_fn.parse)(ramp.ramp[fg]
|
|
71
|
+
const bgColor = (0, import_fn.parse)(ramp.ramp[bg]);
|
|
72
|
+
const fgColor = (0, import_fn.parse)(ramp.ramp[fg]);
|
|
73
73
|
if ((0, import_color_utils.getContrast)(bgColor, fgColor) < target) {
|
|
74
74
|
unmetTargets.push({
|
|
75
75
|
bgName: bg,
|
|
@@ -87,8 +87,8 @@ function checkAccessibleCombinations({
|
|
|
87
87
|
import_constants.CONTRAST_COMBINATIONS.forEach(({ bgs, fgs, target }) => {
|
|
88
88
|
for (const bg of bgs) {
|
|
89
89
|
for (const fg of fgs) {
|
|
90
|
-
const bgColor = (0, import_fn.parse)(bgRamp.ramp[bg]
|
|
91
|
-
const fgColor = (0, import_fn.parse)(ramp.ramp[fg]
|
|
90
|
+
const bgColor = (0, import_fn.parse)(bgRamp.ramp[bg]);
|
|
91
|
+
const fgColor = (0, import_fn.parse)(ramp.ramp[fg]);
|
|
92
92
|
if ((0, import_color_utils.getContrast)(bgColor, fgColor) < target) {
|
|
93
93
|
unmetTargets.push({
|
|
94
94
|
bgName: bg,
|
|
@@ -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 { 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 ]
|
|
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,
|
|
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 ] ), [ 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 ] );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ] );\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 ] );\n\t\t\t\t\tconst fgColor = parse( ramp.ramp[ fg ] );\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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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,CAAE;AACzC,gBAAM,cAAU,iBAAO,KAAK,KAAM,EAAG,CAAE;AACvC,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
6
|
"names": ["import_constants"]
|
|
7
7
|
}
|
|
@@ -22,8 +22,8 @@ __export(constants_exports, {
|
|
|
22
22
|
ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS: () => ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS,
|
|
23
23
|
BLACK: () => BLACK,
|
|
24
24
|
CONTRAST_COMBINATIONS: () => CONTRAST_COMBINATIONS,
|
|
25
|
+
CONTRAST_EPSILON: () => CONTRAST_EPSILON,
|
|
25
26
|
DEFAULT_SEED_COLORS: () => DEFAULT_SEED_COLORS,
|
|
26
|
-
LIGHTNESS_EPSILON: () => LIGHTNESS_EPSILON,
|
|
27
27
|
MAX_BISECTION_ITERATIONS: () => MAX_BISECTION_ITERATIONS,
|
|
28
28
|
UNIVERSAL_CONTRAST_TOPUP: () => UNIVERSAL_CONTRAST_TOPUP,
|
|
29
29
|
WHITE: () => WHITE,
|
|
@@ -34,13 +34,13 @@ var import_fn = require("colorjs.io/fn");
|
|
|
34
34
|
var import_register_color_spaces = require("./register-color-spaces");
|
|
35
35
|
var WHITE = (0, import_fn.to)("white", import_fn.OKLCH);
|
|
36
36
|
var BLACK = (0, import_fn.to)("black", import_fn.OKLCH);
|
|
37
|
-
var UNIVERSAL_CONTRAST_TOPUP = 0.
|
|
37
|
+
var UNIVERSAL_CONTRAST_TOPUP = 0.012;
|
|
38
38
|
var WHITE_TEXT_CONTRAST_MARGIN = 3.1;
|
|
39
39
|
var ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS = {
|
|
40
40
|
lighter: { min: 0.2, max: 0.4 },
|
|
41
41
|
darker: { min: 0.75, max: 0.98 }
|
|
42
42
|
};
|
|
43
|
-
var
|
|
43
|
+
var CONTRAST_EPSILON = 4e-3;
|
|
44
44
|
var MAX_BISECTION_ITERATIONS = 10;
|
|
45
45
|
var CONTRAST_COMBINATIONS = [
|
|
46
46
|
{
|
|
@@ -88,8 +88,8 @@ var DEFAULT_SEED_COLORS = {
|
|
|
88
88
|
ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS,
|
|
89
89
|
BLACK,
|
|
90
90
|
CONTRAST_COMBINATIONS,
|
|
91
|
+
CONTRAST_EPSILON,
|
|
91
92
|
DEFAULT_SEED_COLORS,
|
|
92
|
-
LIGHTNESS_EPSILON,
|
|
93
93
|
MAX_BISECTION_ITERATIONS,
|
|
94
94
|
UNIVERSAL_CONTRAST_TOPUP,
|
|
95
95
|
WHITE,
|
|
@@ -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 { 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
|
|
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;
|
|
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 and rounding errors.\n// - the `CONTRAST_EPSILON` value is 0.004, so the real contrast can be lower by this amount.\n// - the max contrast between adjacent RGB values is 1.016, so half of the difference (0.008) can be rounding error.\n// - the sum is 0.012: the margin we add to ensure that the target contrast is met after all the rounding.\nexport const UNIVERSAL_CONTRAST_TOPUP = 0.012;\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// Contrast precision we aim for. Approximately 1/256, resolution of an 8-bit number.\nexport const CONTRAST_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;AAMjC,IAAM,2BAA2B;AAOjC,IAAM,6BAA6B;AAOnC,IAAM,yCAAyC;AAAA,EACrD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