@wordpress/theme 0.1.0 → 0.2.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-ds-tokens-docs/index.ts +5 -24
- package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +11 -4
- 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 +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 +20 -27
- 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 +60 -91
- package/build/color-ramps/lib/find-color-with-constraints.js.map +3 -3
- package/build/color-ramps/lib/index.js +77 -119
- package/build/color-ramps/lib/index.js.map +3 -3
- package/build/color-ramps/lib/ramp-configs.js +15 -14
- package/build/color-ramps/lib/ramp-configs.js.map +2 -2
- 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 +75 -11
- 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 +19 -11
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/json/figma.json +165 -783
- package/build/prebuilt/ts/color-tokens.js +137 -0
- package/build/prebuilt/ts/color-tokens.js.map +7 -0
- 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/token-id.js +30 -0
- package/build/token-id.js.map +7 -0
- 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 +67 -62
- 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 +14 -11
- 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 +61 -87
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +85 -109
- package/build-module/color-ramps/lib/index.js.map +3 -3
- package/build-module/color-ramps/lib/ramp-configs.js +14 -13
- package/build-module/color-ramps/lib/ramp-configs.js.map +2 -2
- 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 +70 -6
- 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 +18 -10
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/json/figma.json +165 -783
- package/build-module/prebuilt/ts/color-tokens.js +117 -0
- package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
- 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/token-id.js +6 -0
- package/build-module/token-id.js.map +7 -0
- package/build-module/use-theme-provider-styles.js +69 -57
- 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 +7 -9
- 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 +8 -7
- 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 +28 -5
- 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/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 +4 -0
- package/build-types/use-theme-provider-styles.d.ts.map +1 -1
- package/docs/ds-tokens.md +22 -156
- 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 +13 -9
- package/src/color-ramps/lib/default-ramps.ts +200 -0
- package/src/color-ramps/lib/find-color-with-constraints.ts +83 -116
- package/src/color-ramps/lib/index.ts +107 -145
- package/src/color-ramps/lib/ramp-configs.ts +3 -3
- 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 +117 -14
- package/src/color-ramps/stories/index.story.tsx +16 -22
- package/src/color-ramps/test/__snapshots__/index.test.ts.snap +45722 -376
- package/src/color-ramps/test/index.test.ts +68 -29
- package/src/prebuilt/css/design-tokens.css +88 -355
- package/src/prebuilt/js/design-tokens.js +17 -10
- package/src/prebuilt/json/figma.json +165 -783
- 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 +67 -60
- package/terrazzo.config.ts +15 -12
- package/tokens/color.json +221 -69
- package/tokens/dimension.json +75 -0
- 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/prebuilt/ts/design-tokens.js +0 -354
- package/build/prebuilt/ts/design-tokens.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/prebuilt/ts/design-tokens.js +0 -334
- package/build-module/prebuilt/ts/design-tokens.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/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
- package/src/color-ramps/lib/cache-utils.ts +0 -56
- package/src/prebuilt/ts/design-tokens.ts +0 -335
- package/tokens/spacing.json +0 -45
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is generated by the @wordpress/terrazzo-plugin-inline-alias-values plugin.
|
|
3
|
+
* Do not edit this file directly.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
'primary-bgFill1': [ 'bg-interactive-brand-strong' ],
|
|
8
|
+
'primary-fgFill': [
|
|
9
|
+
'fg-interactive-brand-strong-active',
|
|
10
|
+
'fg-interactive-brand-strong',
|
|
11
|
+
],
|
|
12
|
+
'primary-bgFill2': [ 'bg-interactive-brand-strong-active' ],
|
|
13
|
+
'primary-surface2': [ 'bg-interactive-brand-active' ],
|
|
14
|
+
'primary-surface4': [ 'bg-interactive-brand-weak-active' ],
|
|
15
|
+
'primary-fgSurface3': [
|
|
16
|
+
'fg-interactive-brand-active',
|
|
17
|
+
'fg-interactive-brand',
|
|
18
|
+
],
|
|
19
|
+
'primary-stroke3': [
|
|
20
|
+
'bg-thumb-brand-active',
|
|
21
|
+
'bg-thumb-brand',
|
|
22
|
+
'stroke-focus-brand',
|
|
23
|
+
'stroke-interactive-brand',
|
|
24
|
+
'stroke-surface-brand-strong',
|
|
25
|
+
],
|
|
26
|
+
'primary-stroke4': [ 'stroke-interactive-brand-active' ],
|
|
27
|
+
'primary-stroke1': [ 'stroke-surface-brand' ],
|
|
28
|
+
'primary-surface1': [ 'bg-surface-brand' ],
|
|
29
|
+
'info-surface2': [ 'bg-surface-info-weak' ],
|
|
30
|
+
'info-surface4': [ 'bg-surface-info' ],
|
|
31
|
+
'info-fgSurface4': [ 'fg-content-info' ],
|
|
32
|
+
'info-fgSurface3': [ 'fg-content-info-weak' ],
|
|
33
|
+
'info-stroke3': [ 'stroke-surface-info-strong' ],
|
|
34
|
+
'info-stroke1': [ 'stroke-surface-info' ],
|
|
35
|
+
'success-surface2': [ 'bg-surface-success-weak' ],
|
|
36
|
+
'success-surface4': [ 'bg-surface-success' ],
|
|
37
|
+
'success-fgSurface4': [ 'fg-content-success' ],
|
|
38
|
+
'success-fgSurface3': [ 'fg-content-success-weak' ],
|
|
39
|
+
'success-stroke3': [ 'stroke-surface-success-strong' ],
|
|
40
|
+
'success-stroke1': [ 'stroke-surface-success' ],
|
|
41
|
+
'warning-surface2': [ 'bg-surface-warning-weak' ],
|
|
42
|
+
'warning-surface4': [ 'bg-surface-warning' ],
|
|
43
|
+
'warning-fgSurface4': [ 'fg-content-warning' ],
|
|
44
|
+
'warning-fgSurface3': [ 'fg-content-warning-weak' ],
|
|
45
|
+
'warning-stroke3': [ 'stroke-surface-warning-strong' ],
|
|
46
|
+
'warning-stroke1': [ 'stroke-surface-warning' ],
|
|
47
|
+
'error-surface2': [ 'bg-surface-error-weak' ],
|
|
48
|
+
'error-surface4': [ 'bg-surface-error' ],
|
|
49
|
+
'error-fgSurface4': [ 'fg-content-error' ],
|
|
50
|
+
'error-fgSurface3': [ 'fg-content-error-weak' ],
|
|
51
|
+
'error-stroke3': [
|
|
52
|
+
'stroke-interactive-error-strong',
|
|
53
|
+
'stroke-surface-error-strong',
|
|
54
|
+
],
|
|
55
|
+
'error-stroke1': [ 'stroke-surface-error' ],
|
|
56
|
+
'bg-surface2': [ 'bg-surface-neutral' ],
|
|
57
|
+
'bg-surface6': [
|
|
58
|
+
'bg-interactive-brand-strong-disabled',
|
|
59
|
+
'bg-interactive-neutral-strong-disabled',
|
|
60
|
+
],
|
|
61
|
+
'bg-surface5': [
|
|
62
|
+
'bg-interactive-brand-disabled',
|
|
63
|
+
'bg-interactive-brand-weak-disabled',
|
|
64
|
+
'bg-interactive-neutral-disabled',
|
|
65
|
+
'bg-interactive-neutral-weak-disabled',
|
|
66
|
+
],
|
|
67
|
+
'bg-surface4': [
|
|
68
|
+
'bg-interactive-neutral-active',
|
|
69
|
+
'bg-interactive-neutral-weak-active',
|
|
70
|
+
],
|
|
71
|
+
'bg-surface3': [ 'bg-surface-neutral-strong' ],
|
|
72
|
+
'bg-fgSurface4': [
|
|
73
|
+
'fg-content-neutral',
|
|
74
|
+
'fg-interactive-neutral-active',
|
|
75
|
+
'fg-interactive-neutral',
|
|
76
|
+
],
|
|
77
|
+
'bg-fgSurface3': [
|
|
78
|
+
'fg-content-neutral-weak',
|
|
79
|
+
'fg-interactive-brand-strong-disabled',
|
|
80
|
+
'fg-interactive-neutral-strong-disabled',
|
|
81
|
+
'fg-interactive-neutral-weak',
|
|
82
|
+
],
|
|
83
|
+
'bg-fgSurface2': [
|
|
84
|
+
'fg-interactive-brand-disabled',
|
|
85
|
+
'fg-interactive-neutral-disabled',
|
|
86
|
+
'fg-interactive-neutral-weak-disabled',
|
|
87
|
+
],
|
|
88
|
+
'bg-stroke3': [
|
|
89
|
+
'bg-thumb-neutral-weak',
|
|
90
|
+
'stroke-interactive-neutral',
|
|
91
|
+
'stroke-surface-neutral-strong',
|
|
92
|
+
],
|
|
93
|
+
'bg-stroke4': [
|
|
94
|
+
'bg-thumb-neutral-weak-active',
|
|
95
|
+
'stroke-interactive-neutral-active',
|
|
96
|
+
'stroke-interactive-neutral-strong',
|
|
97
|
+
],
|
|
98
|
+
'bg-stroke2': [
|
|
99
|
+
'bg-thumb-brand-disabled',
|
|
100
|
+
'bg-track-neutral',
|
|
101
|
+
'stroke-interactive-brand-disabled',
|
|
102
|
+
'stroke-interactive-neutral-disabled',
|
|
103
|
+
'stroke-surface-neutral',
|
|
104
|
+
],
|
|
105
|
+
'bg-stroke1': [ 'bg-track-neutral-weak', 'stroke-surface-neutral-weak' ],
|
|
106
|
+
'bg-bgFillInverted2': [ 'bg-interactive-neutral-strong-active' ],
|
|
107
|
+
'bg-bgFillInverted1': [ 'bg-interactive-neutral-strong' ],
|
|
108
|
+
'bg-fgFillInverted': [
|
|
109
|
+
'fg-interactive-neutral-strong-active',
|
|
110
|
+
'fg-interactive-neutral-strong',
|
|
111
|
+
],
|
|
112
|
+
'bg-surface1': [ 'bg-surface-neutral-weak' ],
|
|
113
|
+
'caution-surface2': [ 'bg-surface-caution-weak' ],
|
|
114
|
+
'caution-surface4': [ 'bg-surface-caution' ],
|
|
115
|
+
'caution-fgSurface4': [ 'fg-content-caution' ],
|
|
116
|
+
'caution-fgSurface3': [ 'fg-content-caution-weak' ],
|
|
117
|
+
} as Record< string, string[] >;
|
|
@@ -39,7 +39,6 @@ const meta: Meta< typeof ThemeProvider > = {
|
|
|
39
39
|
export default meta;
|
|
40
40
|
|
|
41
41
|
function getCSSCustomPropsFromStylesheets() {
|
|
42
|
-
const primitiveProps: Record< string, string > = {};
|
|
43
42
|
const semanticProps: Record< string, string > = {};
|
|
44
43
|
const legacyProps: Record< string, string > = {};
|
|
45
44
|
|
|
@@ -58,15 +57,9 @@ function getCSSCustomPropsFromStylesheets() {
|
|
|
58
57
|
.trim();
|
|
59
58
|
}
|
|
60
59
|
if ( name.startsWith( '--wpds-color' ) ) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.trim();
|
|
65
|
-
} else {
|
|
66
|
-
semanticProps[ name ] = ruleStyle
|
|
67
|
-
.getPropertyValue( name )
|
|
68
|
-
.trim();
|
|
69
|
-
}
|
|
60
|
+
semanticProps[ name ] = ruleStyle
|
|
61
|
+
.getPropertyValue( name )
|
|
62
|
+
.trim();
|
|
70
63
|
}
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -79,7 +72,7 @@ function getCSSCustomPropsFromStylesheets() {
|
|
|
79
72
|
}
|
|
80
73
|
}
|
|
81
74
|
|
|
82
|
-
return {
|
|
75
|
+
return { semanticProps, legacyProps };
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
const ColorTokenTable = ( {
|
|
@@ -126,11 +119,9 @@ const ColorTokenTable = ( {
|
|
|
126
119
|
const DSTokensList = () => {
|
|
127
120
|
const [ props, setProps ] = useState< {
|
|
128
121
|
semanticProps: Record< string, string >;
|
|
129
|
-
primitiveProps: Record< string, string >;
|
|
130
122
|
legacyProps: Record< string, string >;
|
|
131
123
|
} >( {
|
|
132
124
|
semanticProps: {},
|
|
133
|
-
primitiveProps: {},
|
|
134
125
|
legacyProps: {},
|
|
135
126
|
} );
|
|
136
127
|
|
|
@@ -143,11 +134,6 @@ const DSTokensList = () => {
|
|
|
143
134
|
<h1>DS Color tokens</h1>
|
|
144
135
|
<h2>Semantic tokens (can be consumed directly)</h2>
|
|
145
136
|
<ColorTokenTable tokens={ props.semanticProps } />
|
|
146
|
-
<h2>Primitive tokens (should not be consumed directly)</h2>
|
|
147
|
-
<details>
|
|
148
|
-
<summary>Click to expand</summary>
|
|
149
|
-
<ColorTokenTable tokens={ props.primitiveProps } />
|
|
150
|
-
</details>
|
|
151
137
|
<h2>Legacy tokens (should not be consumed directly)</h2>
|
|
152
138
|
<details>
|
|
153
139
|
<summary>Click to expand</summary>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { publicTokenId } from '../token-id';
|
|
5
|
+
|
|
6
|
+
describe( 'publicTokenId', () => {
|
|
7
|
+
it( 'should remove default states and visibility identifiers from the token id', () => {
|
|
8
|
+
expect(
|
|
9
|
+
publicTokenId( 'color.semantic.bg-surface.success.weak.resting' )
|
|
10
|
+
).toBe( 'color.bg-surface.success.weak' );
|
|
11
|
+
} );
|
|
12
|
+
} );
|
package/src/token-id.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a token ID by removing default states and visibility identifiers,
|
|
3
|
+
* making it human-readable as a publicly-accessible variable name.
|
|
4
|
+
*
|
|
5
|
+
* @param id The token ID to normalize.
|
|
6
|
+
* @return The normalized token ID.
|
|
7
|
+
*/
|
|
8
|
+
export const publicTokenId = ( id: string ) =>
|
|
9
|
+
id.replace( /\.(normal|resting|semantic|primitive)/g, '' );
|
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import type { CSSProperties } from 'react';
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
parse,
|
|
7
|
+
to,
|
|
8
|
+
get,
|
|
9
|
+
serialize,
|
|
10
|
+
sRGB,
|
|
11
|
+
HSL,
|
|
12
|
+
type ColorTypes,
|
|
13
|
+
} from 'colorjs.io/fn';
|
|
14
|
+
import memoize from 'memize';
|
|
6
15
|
|
|
7
16
|
/**
|
|
8
17
|
* WordPress dependencies
|
|
@@ -12,8 +21,9 @@ import { useMemo, useContext } from '@wordpress/element';
|
|
|
12
21
|
/**
|
|
13
22
|
* Internal dependencies
|
|
14
23
|
*/
|
|
24
|
+
import './color-ramps/lib/register-color-spaces';
|
|
15
25
|
import { ThemeContext } from './context';
|
|
16
|
-
import
|
|
26
|
+
import colorTokens from './prebuilt/ts/color-tokens';
|
|
17
27
|
import {
|
|
18
28
|
buildBgRamp,
|
|
19
29
|
buildAccentRamp,
|
|
@@ -24,6 +34,9 @@ import type { ThemeProviderProps } from './types';
|
|
|
24
34
|
|
|
25
35
|
type Entry = [ string, string ];
|
|
26
36
|
|
|
37
|
+
const getCachedBgRamp = memoize( buildBgRamp, { maxSize: 10 } );
|
|
38
|
+
const getCachedAccentRamp = memoize( buildAccentRamp, { maxSize: 10 } );
|
|
39
|
+
|
|
27
40
|
const legacyWpComponentsOverridesCSS: Entry[] = [
|
|
28
41
|
[ '--wp-components-color-accent', 'var(--wp-admin-theme-color)' ],
|
|
29
42
|
[
|
|
@@ -80,37 +93,49 @@ const legacyWpComponentsOverridesCSS: Entry[] = [
|
|
|
80
93
|
],
|
|
81
94
|
];
|
|
82
95
|
|
|
83
|
-
function customRgbFormat( color:
|
|
84
|
-
const rgb =
|
|
85
|
-
return [ rgb.r, rgb.g, rgb.b ]
|
|
96
|
+
function customRgbFormat( color: ColorTypes ) {
|
|
97
|
+
const rgb = to( color, sRGB );
|
|
98
|
+
return [ get( rgb, 'srgb.r' ), get( rgb, 'srgb.g' ), get( rgb, 'srgb.b' ) ]
|
|
86
99
|
.map( ( n ) => Math.round( n * 255 ) )
|
|
87
100
|
.join( ', ' );
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
function legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {
|
|
91
|
-
const parsedAccent =
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
const darker10 =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
const parsedAccent = to( parse( accent ), HSL );
|
|
105
|
+
|
|
106
|
+
const coords = parsedAccent.coords;
|
|
107
|
+
const darker10 = to(
|
|
108
|
+
{
|
|
109
|
+
space: HSL,
|
|
110
|
+
coords: [
|
|
111
|
+
coords[ 0 ], // h
|
|
112
|
+
coords[ 1 ], // s
|
|
113
|
+
Math.max( 0, Math.min( 100, coords[ 2 ] - 5 ) ), // l (reduced by 5%)
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
sRGB
|
|
117
|
+
);
|
|
118
|
+
const darker20 = to(
|
|
119
|
+
{
|
|
120
|
+
space: HSL,
|
|
121
|
+
coords: [
|
|
122
|
+
coords[ 0 ], // h
|
|
123
|
+
coords[ 1 ], // s
|
|
124
|
+
Math.max( 0, Math.min( 100, coords[ 2 ] - 10 ) ), // l (reduced by 10%)
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
sRGB
|
|
128
|
+
);
|
|
104
129
|
|
|
105
130
|
return [
|
|
106
131
|
[
|
|
107
132
|
'--wp-admin-theme-color',
|
|
108
|
-
|
|
133
|
+
serialize( to( parsedAccent, sRGB ), { format: 'hex' } ),
|
|
109
134
|
],
|
|
110
135
|
[ '--wp-admin-theme-color--rgb', customRgbFormat( parsedAccent ) ],
|
|
111
136
|
[
|
|
112
137
|
'--wp-admin-theme-color-darker-10',
|
|
113
|
-
|
|
138
|
+
serialize( darker10, { format: 'hex' } ),
|
|
114
139
|
],
|
|
115
140
|
[
|
|
116
141
|
'--wp-admin-theme-color-darker-10--rgb',
|
|
@@ -118,7 +143,7 @@ function legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {
|
|
|
118
143
|
],
|
|
119
144
|
[
|
|
120
145
|
'--wp-admin-theme-color-darker-20',
|
|
121
|
-
|
|
146
|
+
serialize( darker20, { format: 'hex' } ),
|
|
122
147
|
],
|
|
123
148
|
[
|
|
124
149
|
'--wp-admin-theme-color-darker-20--rgb',
|
|
@@ -127,31 +152,25 @@ function legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {
|
|
|
127
152
|
];
|
|
128
153
|
}
|
|
129
154
|
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
true
|
|
155
|
+
function colorTokensCSS(
|
|
156
|
+
computedColorRamps: Map< string, RampResult >
|
|
133
157
|
): Entry[] {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
const entries: Entry[] = [];
|
|
159
|
+
|
|
160
|
+
for ( const [ rampName, { ramp } ] of computedColorRamps ) {
|
|
161
|
+
for ( const [ tokenName, tokenValue ] of Object.entries( ramp ) ) {
|
|
162
|
+
const key = `${ rampName }-${ tokenName }`;
|
|
163
|
+
const aliasedBy = colorTokens[ key ] ?? [];
|
|
164
|
+
for ( const aliasedId of aliasedBy ) {
|
|
165
|
+
entries.push( [
|
|
166
|
+
`--wpds-color-${ aliasedId }`,
|
|
167
|
+
tokenValue.color,
|
|
168
|
+
] );
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
147
172
|
|
|
148
|
-
|
|
149
|
-
return [ ...Object.entries( ramp.ramp ) ].map(
|
|
150
|
-
( [ tokenName, tokenValue ] ) => [
|
|
151
|
-
`${ prefix }${ toKebabCase( tokenName ) }`,
|
|
152
|
-
tokenValue.color,
|
|
153
|
-
]
|
|
154
|
-
);
|
|
173
|
+
return entries;
|
|
155
174
|
}
|
|
156
175
|
|
|
157
176
|
function generateStyles( {
|
|
@@ -163,17 +182,8 @@ function generateStyles( {
|
|
|
163
182
|
} ): CSSProperties {
|
|
164
183
|
return Object.fromEntries(
|
|
165
184
|
[
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
.map( ( [ rampName, computedColorRamp ] ) => [
|
|
169
|
-
colorRampCSS(
|
|
170
|
-
computedColorRamp,
|
|
171
|
-
`--wpds-color-private-${ rampName }-`
|
|
172
|
-
),
|
|
173
|
-
] )
|
|
174
|
-
.flat( 2 ),
|
|
175
|
-
// Semantic color tokens (other semantic tokens for now are static)
|
|
176
|
-
semanticTokensCSS( ( [ key ] ) => /color/.test( key ) ),
|
|
185
|
+
// Semantic color tokens
|
|
186
|
+
colorTokensCSS( computedColorRamps ),
|
|
177
187
|
// Legacy overrides
|
|
178
188
|
legacyWpAdminThemeOverridesCSS( primary ),
|
|
179
189
|
legacyWpComponentsOverridesCSS,
|
|
@@ -219,17 +229,14 @@ export function useThemeProviderStyles( {
|
|
|
219
229
|
|
|
220
230
|
// Generate ramps.
|
|
221
231
|
const computedColorRamps = new Map< string, RampResult >();
|
|
222
|
-
const bgRamp =
|
|
232
|
+
const bgRamp = getCachedBgRamp( seeds.bg );
|
|
223
233
|
Object.entries( seeds ).forEach( ( [ rampName, seed ] ) => {
|
|
224
234
|
if ( rampName === 'bg' ) {
|
|
225
235
|
computedColorRamps.set( rampName, bgRamp );
|
|
226
236
|
} else {
|
|
227
237
|
computedColorRamps.set(
|
|
228
238
|
rampName,
|
|
229
|
-
|
|
230
|
-
seed,
|
|
231
|
-
bgRamp,
|
|
232
|
-
} )
|
|
239
|
+
getCachedAccentRamp( seed, bgRamp )
|
|
233
240
|
);
|
|
234
241
|
}
|
|
235
242
|
} );
|
package/terrazzo.config.ts
CHANGED
|
@@ -4,34 +4,40 @@
|
|
|
4
4
|
import { defineConfig } from '@terrazzo/cli';
|
|
5
5
|
import pluginCSS from '@terrazzo/plugin-css';
|
|
6
6
|
import { makeCSSVar } from '@terrazzo/token-tools/css';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
9
10
|
*/
|
|
10
11
|
import pluginFigmaDsTokenManager from './bin/terrazzo-plugin-figma-ds-token-manager/index';
|
|
11
12
|
import pluginKnownWpdsCssVariables from './bin/terrazzo-plugin-known-wpds-css-variables/index';
|
|
12
13
|
import pluginDsTokenDocs from './bin/terrazzo-plugin-ds-tokens-docs/index';
|
|
14
|
+
import inlineAliasValues from './bin/terrazzo-plugin-inline-alias-values/index';
|
|
15
|
+
import { publicTokenId } from './src/token-id.ts';
|
|
13
16
|
|
|
14
17
|
export default defineConfig( {
|
|
15
18
|
tokens: [
|
|
16
19
|
'./tokens/border.json',
|
|
17
20
|
'./tokens/color.json',
|
|
21
|
+
'./tokens/dimension.json',
|
|
18
22
|
'./tokens/elevation.json',
|
|
19
|
-
'./tokens/spacing.json',
|
|
20
23
|
'./tokens/typography.json',
|
|
21
24
|
],
|
|
22
25
|
outDir: './src/prebuilt',
|
|
23
26
|
|
|
24
27
|
plugins: [
|
|
28
|
+
inlineAliasValues( {
|
|
29
|
+
pattern: /^color\.primitive\./,
|
|
30
|
+
filename: 'ts/color-tokens.ts',
|
|
31
|
+
tokenId: ( tokenId ) =>
|
|
32
|
+
publicTokenId( tokenId )
|
|
33
|
+
.replace( /^color\./, '' )
|
|
34
|
+
.replace( /\./g, '-' ),
|
|
35
|
+
} ),
|
|
36
|
+
inlineAliasValues( { pattern: /^dimension\.primitive\./ } ),
|
|
25
37
|
pluginCSS( {
|
|
26
38
|
filename: 'css/design-tokens.css',
|
|
27
39
|
variableName: ( token ) =>
|
|
28
|
-
makeCSSVar(
|
|
29
|
-
`wpds.${ token.id
|
|
30
|
-
.replace( /normal/g, '' )
|
|
31
|
-
.replace( /resting/g, '' )
|
|
32
|
-
.replace( /primitive/g, 'private' )
|
|
33
|
-
.replace( /semantic/g, '' ) }`
|
|
34
|
-
),
|
|
40
|
+
makeCSSVar( `wpds.${ publicTokenId( token.id ) }` ),
|
|
35
41
|
baseSelector: ':root',
|
|
36
42
|
modeSelectors: [
|
|
37
43
|
{
|
|
@@ -47,10 +53,7 @@ export default defineConfig( {
|
|
|
47
53
|
filename: 'json/figma.json',
|
|
48
54
|
} ),
|
|
49
55
|
pluginKnownWpdsCssVariables( {
|
|
50
|
-
|
|
51
|
-
{ filename: 'js/design-tokens.js', modes: false },
|
|
52
|
-
{ filename: 'ts/design-tokens.ts', modes: true },
|
|
53
|
-
],
|
|
56
|
+
filename: 'js/design-tokens.js',
|
|
54
57
|
} ),
|
|
55
58
|
pluginDsTokenDocs( {
|
|
56
59
|
filename: '../../docs/ds-tokens.md',
|