@wordpress/theme 0.1.1-next.2f1c7c01b.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.
Files changed (91) hide show
  1. package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +5 -24
  2. package/bin/terrazzo-plugin-inline-alias-values/index.ts +84 -0
  3. package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +19 -39
  4. package/build/color-ramps/lib/constants.js +4 -4
  5. package/build/color-ramps/lib/constants.js.map +2 -2
  6. package/build/color-ramps/lib/default-ramps.js +82 -82
  7. package/build/color-ramps/lib/default-ramps.js.map +1 -1
  8. package/build/color-ramps/lib/find-color-with-constraints.js +36 -53
  9. package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
  10. package/build/color-ramps/lib/index.js +64 -63
  11. package/build/color-ramps/lib/index.js.map +2 -2
  12. package/build/color-ramps/lib/ramp-configs.js +3 -3
  13. package/build/color-ramps/lib/ramp-configs.js.map +1 -1
  14. package/build/color-ramps/lib/utils.js +63 -2
  15. package/build/color-ramps/lib/utils.js.map +2 -2
  16. package/build/prebuilt/js/design-tokens.js +5 -10
  17. package/build/prebuilt/js/design-tokens.js.map +2 -2
  18. package/build/prebuilt/json/figma.json +105 -905
  19. package/build/prebuilt/ts/color-tokens.js +137 -0
  20. package/build/prebuilt/ts/color-tokens.js.map +7 -0
  21. package/build/token-id.js +30 -0
  22. package/build/token-id.js.map +7 -0
  23. package/build/use-theme-provider-styles.js +18 -27
  24. package/build/use-theme-provider-styles.js.map +3 -3
  25. package/build-module/color-ramps/lib/constants.js +3 -3
  26. package/build-module/color-ramps/lib/constants.js.map +2 -2
  27. package/build-module/color-ramps/lib/default-ramps.js +82 -82
  28. package/build-module/color-ramps/lib/default-ramps.js.map +1 -1
  29. package/build-module/color-ramps/lib/find-color-with-constraints.js +38 -60
  30. package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
  31. package/build-module/color-ramps/lib/index.js +68 -65
  32. package/build-module/color-ramps/lib/index.js.map +2 -2
  33. package/build-module/color-ramps/lib/ramp-configs.js +3 -3
  34. package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
  35. package/build-module/color-ramps/lib/utils.js +63 -2
  36. package/build-module/color-ramps/lib/utils.js.map +2 -2
  37. package/build-module/prebuilt/js/design-tokens.js +5 -10
  38. package/build-module/prebuilt/js/design-tokens.js.map +2 -2
  39. package/build-module/prebuilt/json/figma.json +105 -905
  40. package/build-module/prebuilt/ts/color-tokens.js +117 -0
  41. package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
  42. package/build-module/token-id.js +6 -0
  43. package/build-module/token-id.js.map +7 -0
  44. package/build-module/use-theme-provider-styles.js +18 -27
  45. package/build-module/use-theme-provider-styles.js.map +2 -2
  46. package/build-types/color-ramps/lib/constants.d.ts +2 -2
  47. package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
  48. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +2 -3
  49. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
  50. package/build-types/color-ramps/lib/index.d.ts.map +1 -1
  51. package/build-types/color-ramps/lib/utils.d.ts +21 -2
  52. package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
  53. package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
  54. package/build-types/prebuilt/ts/color-tokens.d.ts +7 -0
  55. package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -0
  56. package/build-types/stories/index.story.d.ts.map +1 -1
  57. package/build-types/theme-provider.d.ts.map +1 -1
  58. package/build-types/token-id.d.ts +9 -0
  59. package/build-types/token-id.d.ts.map +1 -0
  60. package/build-types/use-theme-provider-styles.d.ts.map +1 -1
  61. package/docs/ds-tokens.md +10 -178
  62. package/package.json +4 -4
  63. package/src/color-ramps/lib/constants.ts +7 -5
  64. package/src/color-ramps/lib/default-ramps.ts +82 -82
  65. package/src/color-ramps/lib/find-color-with-constraints.ts +53 -77
  66. package/src/color-ramps/lib/index.ts +98 -102
  67. package/src/color-ramps/lib/ramp-configs.ts +3 -3
  68. package/src/color-ramps/lib/utils.ts +109 -5
  69. package/src/color-ramps/test/__snapshots__/index.test.ts.snap +45706 -360
  70. package/src/color-ramps/test/index.test.ts +41 -14
  71. package/src/prebuilt/css/design-tokens.css +88 -413
  72. package/src/prebuilt/js/design-tokens.js +5 -10
  73. package/src/prebuilt/json/figma.json +105 -905
  74. package/src/prebuilt/ts/color-tokens.ts +117 -0
  75. package/src/stories/index.story.tsx +4 -18
  76. package/src/test/token-id.test.ts +12 -0
  77. package/src/token-id.ts +9 -0
  78. package/src/use-theme-provider-styles.ts +20 -35
  79. package/terrazzo.config.ts +15 -12
  80. package/tokens/color.json +82 -82
  81. package/tokens/dimension.json +75 -0
  82. package/tsconfig.bin.tsbuildinfo +1 -1
  83. package/tsconfig.src.tsbuildinfo +1 -1
  84. package/build/prebuilt/ts/design-tokens.js +0 -391
  85. package/build/prebuilt/ts/design-tokens.js.map +0 -7
  86. package/build-module/prebuilt/ts/design-tokens.js +0 -371
  87. package/build-module/prebuilt/ts/design-tokens.js.map +0 -7
  88. package/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
  89. package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
  90. package/src/prebuilt/ts/design-tokens.ts +0 -371
  91. package/tokens/spacing.json +0 -45
@@ -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
- if ( name.includes( 'private' ) ) {
62
- primitiveProps[ name ] = ruleStyle
63
- .getPropertyValue( name )
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 { primitiveProps, semanticProps, legacyProps };
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
+ } );
@@ -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, '' );
@@ -23,7 +23,7 @@ import { useMemo, useContext } from '@wordpress/element';
23
23
  */
24
24
  import './color-ramps/lib/register-color-spaces';
25
25
  import { ThemeContext } from './context';
26
- import semanticVariables from './prebuilt/ts/design-tokens';
26
+ import colorTokens from './prebuilt/ts/color-tokens';
27
27
  import {
28
28
  buildBgRamp,
29
29
  buildAccentRamp,
@@ -152,31 +152,25 @@ function legacyWpAdminThemeOverridesCSS( accent: string ): Entry[] {
152
152
  ];
153
153
  }
154
154
 
155
- function semanticTokensCSS(
156
- filterFn: ( entry: [ string, Record< string, string > ] ) => boolean = () =>
157
- true
155
+ function colorTokensCSS(
156
+ computedColorRamps: Map< string, RampResult >
158
157
  ): Entry[] {
159
- return Object.entries( semanticVariables )
160
- .filter( filterFn )
161
- .map( ( [ variableName, modesAndValues ] ) => [
162
- variableName,
163
- modesAndValues[ '.' ],
164
- ] );
165
- }
166
-
167
- const toKebabCase = ( str: string ) =>
168
- str.replace(
169
- /[A-Z]+(?![a-z])|[A-Z]/g,
170
- ( $, ofs ) => ( ofs ? '-' : '' ) + $.toLowerCase()
171
- );
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
+ }
172
172
 
173
- function colorRampCSS( ramp: RampResult, prefix: string ): Entry[] {
174
- return [ ...Object.entries( ramp.ramp ) ].map(
175
- ( [ tokenName, tokenValue ] ) => [
176
- `${ prefix }${ toKebabCase( tokenName ) }`,
177
- tokenValue.color,
178
- ]
179
- );
173
+ return entries;
180
174
  }
181
175
 
182
176
  function generateStyles( {
@@ -188,17 +182,8 @@ function generateStyles( {
188
182
  } ): CSSProperties {
189
183
  return Object.fromEntries(
190
184
  [
191
- // Primitive tokens
192
- Array.from( computedColorRamps )
193
- .map( ( [ rampName, computedColorRamp ] ) => [
194
- colorRampCSS(
195
- computedColorRamp,
196
- `--wpds-color-private-${ rampName }-`
197
- ),
198
- ] )
199
- .flat( 2 ),
200
- // Semantic color tokens (other semantic tokens for now are static)
201
- semanticTokensCSS( ( [ key ] ) => /color/.test( key ) ),
185
+ // Semantic color tokens
186
+ colorTokensCSS( computedColorRamps ),
202
187
  // Legacy overrides
203
188
  legacyWpAdminThemeOverridesCSS( primary ),
204
189
  legacyWpComponentsOverridesCSS,
@@ -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
- exports: [
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',