@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.
Files changed (106) hide show
  1. package/README.md +5 -1
  2. package/bin/generate-primitive-tokens/index.ts +1 -1
  3. package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +5 -24
  4. package/bin/terrazzo-plugin-inline-alias-values/index.ts +84 -0
  5. package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +19 -39
  6. package/build/color-ramps/index.js +5 -5
  7. package/build/color-ramps/index.js.map +2 -2
  8. package/build/color-ramps/lib/constants.js +4 -4
  9. package/build/color-ramps/lib/constants.js.map +2 -2
  10. package/build/color-ramps/lib/default-ramps.js +154 -154
  11. package/build/color-ramps/lib/default-ramps.js.map +2 -2
  12. package/build/color-ramps/lib/find-color-with-constraints.js +36 -53
  13. package/build/color-ramps/lib/find-color-with-constraints.js.map +2 -2
  14. package/build/color-ramps/lib/index.js +72 -64
  15. package/build/color-ramps/lib/index.js.map +2 -2
  16. package/build/color-ramps/lib/ramp-configs.js +3 -3
  17. package/build/color-ramps/lib/ramp-configs.js.map +1 -1
  18. package/build/color-ramps/lib/types.js.map +1 -1
  19. package/build/color-ramps/lib/utils.js +63 -2
  20. package/build/color-ramps/lib/utils.js.map +2 -2
  21. package/build/prebuilt/js/design-tokens.js +5 -10
  22. package/build/prebuilt/js/design-tokens.js.map +2 -2
  23. package/build/prebuilt/json/figma.json +105 -905
  24. package/build/prebuilt/ts/color-tokens.js +137 -0
  25. package/build/prebuilt/ts/color-tokens.js.map +7 -0
  26. package/build/token-id.js +30 -0
  27. package/build/token-id.js.map +7 -0
  28. package/build/use-theme-provider-styles.js +15 -27
  29. package/build/use-theme-provider-styles.js.map +3 -3
  30. package/build-module/color-ramps/index.js +5 -5
  31. package/build-module/color-ramps/index.js.map +2 -2
  32. package/build-module/color-ramps/lib/constants.js +3 -3
  33. package/build-module/color-ramps/lib/constants.js.map +2 -2
  34. package/build-module/color-ramps/lib/default-ramps.js +154 -154
  35. package/build-module/color-ramps/lib/default-ramps.js.map +2 -2
  36. package/build-module/color-ramps/lib/find-color-with-constraints.js +38 -60
  37. package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
  38. package/build-module/color-ramps/lib/index.js +76 -66
  39. package/build-module/color-ramps/lib/index.js.map +2 -2
  40. package/build-module/color-ramps/lib/ramp-configs.js +3 -3
  41. package/build-module/color-ramps/lib/ramp-configs.js.map +1 -1
  42. package/build-module/color-ramps/lib/utils.js +63 -2
  43. package/build-module/color-ramps/lib/utils.js.map +2 -2
  44. package/build-module/prebuilt/js/design-tokens.js +5 -10
  45. package/build-module/prebuilt/js/design-tokens.js.map +2 -2
  46. package/build-module/prebuilt/json/figma.json +105 -905
  47. package/build-module/prebuilt/ts/color-tokens.js +117 -0
  48. package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
  49. package/build-module/token-id.js +6 -0
  50. package/build-module/token-id.js.map +7 -0
  51. package/build-module/use-theme-provider-styles.js +15 -27
  52. package/build-module/use-theme-provider-styles.js.map +2 -2
  53. package/build-types/color-ramps/lib/constants.d.ts +2 -2
  54. package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
  55. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +2 -3
  56. package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
  57. package/build-types/color-ramps/lib/index.d.ts.map +1 -1
  58. package/build-types/color-ramps/lib/types.d.ts +2 -4
  59. package/build-types/color-ramps/lib/types.d.ts.map +1 -1
  60. package/build-types/color-ramps/lib/utils.d.ts +21 -2
  61. package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
  62. package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
  63. package/build-types/color-ramps/stories/ramp-table.d.ts +2 -4
  64. package/build-types/color-ramps/stories/ramp-table.d.ts.map +1 -1
  65. package/build-types/prebuilt/ts/color-tokens.d.ts +7 -0
  66. package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -0
  67. package/build-types/stories/index.story.d.ts.map +1 -1
  68. package/build-types/theme-provider.d.ts.map +1 -1
  69. package/build-types/token-id.d.ts +9 -0
  70. package/build-types/token-id.d.ts.map +1 -0
  71. package/build-types/use-theme-provider-styles.d.ts.map +1 -1
  72. package/docs/ds-tokens.md +10 -178
  73. package/package.json +4 -4
  74. package/src/color-ramps/index.ts +5 -5
  75. package/src/color-ramps/lib/constants.ts +7 -5
  76. package/src/color-ramps/lib/default-ramps.ts +154 -154
  77. package/src/color-ramps/lib/find-color-with-constraints.ts +53 -77
  78. package/src/color-ramps/lib/index.ts +100 -100
  79. package/src/color-ramps/lib/ramp-configs.ts +3 -3
  80. package/src/color-ramps/lib/types.ts +2 -7
  81. package/src/color-ramps/lib/utils.ts +109 -5
  82. package/src/color-ramps/stories/index.story.tsx +4 -1
  83. package/src/color-ramps/stories/ramp-table.tsx +15 -26
  84. package/src/color-ramps/test/__snapshots__/index.test.ts.snap +16891 -1059
  85. package/src/color-ramps/test/index.test.ts +43 -16
  86. package/src/prebuilt/css/design-tokens.css +88 -413
  87. package/src/prebuilt/js/design-tokens.js +5 -10
  88. package/src/prebuilt/json/figma.json +105 -905
  89. package/src/prebuilt/ts/color-tokens.ts +117 -0
  90. package/src/stories/index.story.tsx +4 -18
  91. package/src/test/token-id.test.ts +12 -0
  92. package/src/token-id.ts +9 -0
  93. package/src/use-theme-provider-styles.ts +17 -35
  94. package/terrazzo.config.ts +15 -12
  95. package/tokens/color.json +82 -82
  96. package/tokens/dimension.json +75 -0
  97. package/tsconfig.bin.tsbuildinfo +1 -1
  98. package/tsconfig.src.tsbuildinfo +1 -1
  99. package/build/prebuilt/ts/design-tokens.js +0 -391
  100. package/build/prebuilt/ts/design-tokens.js.map +0 -7
  101. package/build-module/prebuilt/ts/design-tokens.js +0 -371
  102. package/build-module/prebuilt/ts/design-tokens.js.map +0 -7
  103. package/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
  104. package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
  105. package/src/prebuilt/ts/design-tokens.ts +0 -371
  106. 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,22 @@ 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( [ `--wpds-color-${ aliasedId }`, tokenValue ] );
166
+ }
167
+ }
168
+ }
172
169
 
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
- );
170
+ return entries;
180
171
  }
181
172
 
182
173
  function generateStyles( {
@@ -188,17 +179,8 @@ function generateStyles( {
188
179
  } ): CSSProperties {
189
180
  return Object.fromEntries(
190
181
  [
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 ) ),
182
+ // Semantic color tokens
183
+ colorTokensCSS( computedColorRamps ),
202
184
  // Legacy overrides
203
185
  legacyWpAdminThemeOverridesCSS( primary ),
204
186
  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',