@wordpress/theme 0.8.1-next.v.202603102151.0 → 0.9.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 (65) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +25 -2
  3. package/build/esbuild-plugins/esbuild-ds-token-fallbacks.cjs +1 -1
  4. package/build/esbuild-plugins/esbuild-ds-token-fallbacks.cjs.map +2 -2
  5. package/build/postcss-plugins/add-fallback-to-var.cjs +9 -3
  6. package/build/postcss-plugins/add-fallback-to-var.cjs.map +2 -2
  7. package/build/postcss-plugins/ds-token-fallbacks.cjs +9 -3
  8. package/build/postcss-plugins/ds-token-fallbacks.cjs.map +2 -2
  9. package/build/prebuilt/js/design-token-fallbacks.cjs +6 -0
  10. package/build/prebuilt/js/design-token-fallbacks.cjs.map +2 -2
  11. package/build/prebuilt/js/design-tokens.cjs +6 -0
  12. package/build/prebuilt/js/design-tokens.cjs.map +2 -2
  13. package/build/prebuilt/ts/token-types.cjs.map +1 -1
  14. package/build/stylelint-plugins/no-token-fallback-values.cjs +73 -0
  15. package/build/stylelint-plugins/no-token-fallback-values.cjs.map +7 -0
  16. package/build/vite-plugins/vite-ds-token-fallbacks.cjs +4 -1
  17. package/build/vite-plugins/vite-ds-token-fallbacks.cjs.map +2 -2
  18. package/build-module/esbuild-plugins/esbuild-ds-token-fallbacks.mjs +1 -1
  19. package/build-module/esbuild-plugins/esbuild-ds-token-fallbacks.mjs.map +2 -2
  20. package/build-module/postcss-plugins/add-fallback-to-var.mjs +9 -3
  21. package/build-module/postcss-plugins/add-fallback-to-var.mjs.map +2 -2
  22. package/build-module/postcss-plugins/ds-token-fallbacks.mjs +9 -3
  23. package/build-module/postcss-plugins/ds-token-fallbacks.mjs.map +2 -2
  24. package/build-module/prebuilt/js/design-token-fallbacks.mjs +6 -0
  25. package/build-module/prebuilt/js/design-token-fallbacks.mjs.map +2 -2
  26. package/build-module/prebuilt/js/design-tokens.mjs +6 -0
  27. package/build-module/prebuilt/js/design-tokens.mjs.map +2 -2
  28. package/build-module/stylelint-plugins/no-token-fallback-values.mjs +43 -0
  29. package/build-module/stylelint-plugins/no-token-fallback-values.mjs.map +7 -0
  30. package/build-module/vite-plugins/vite-ds-token-fallbacks.mjs +4 -1
  31. package/build-module/vite-plugins/vite-ds-token-fallbacks.mjs.map +2 -2
  32. package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
  33. package/build-types/postcss-plugins/add-fallback-to-var.d.ts +10 -4
  34. package/build-types/postcss-plugins/add-fallback-to-var.d.ts.map +1 -1
  35. package/build-types/postcss-plugins/ds-token-fallbacks.d.mts +13 -3
  36. package/build-types/postcss-plugins/ds-token-fallbacks.d.mts.map +1 -1
  37. package/build-types/prebuilt/js/design-token-fallbacks.d.mts +6 -0
  38. package/build-types/prebuilt/ts/token-types.d.ts +4 -0
  39. package/build-types/prebuilt/ts/token-types.d.ts.map +1 -1
  40. package/build-types/stylelint-plugins/no-token-fallback-values.d.mts +4 -0
  41. package/build-types/stylelint-plugins/no-token-fallback-values.d.mts.map +1 -0
  42. package/package.json +11 -6
  43. package/src/color-ramps/stories/index.story.tsx +0 -1
  44. package/src/esbuild-plugins/esbuild-ds-token-fallbacks.mjs +1 -1
  45. package/src/postcss-plugins/add-fallback-to-var.ts +19 -8
  46. package/src/postcss-plugins/ds-token-fallbacks.mjs +21 -7
  47. package/src/postcss-plugins/test/add-fallback-to-var.test.ts +52 -0
  48. package/src/prebuilt/css/design-tokens.css +12 -0
  49. package/src/prebuilt/js/design-token-fallbacks.mjs +6 -0
  50. package/src/prebuilt/js/design-tokens.mjs +6 -0
  51. package/src/prebuilt/ts/token-types.ts +5 -0
  52. package/src/stories/index.story.tsx +1 -1
  53. package/src/stylelint-plugins/no-token-fallback-values.mjs +55 -0
  54. package/src/stylelint-plugins/test/.stylelintrc.no-setting-wpds-custom-properties.json +6 -0
  55. package/src/stylelint-plugins/test/.stylelintrc.no-token-fallback-values.json +6 -0
  56. package/src/stylelint-plugins/test/.stylelintrc.no-unknown-ds-tokens.json +6 -0
  57. package/src/stylelint-plugins/test/__snapshots__/no-token-fallback-values.test.ts.snap +60 -0
  58. package/src/stylelint-plugins/test/fixtures/no-token-fallback-values-invalid.css +16 -0
  59. package/src/stylelint-plugins/test/fixtures/no-token-fallback-values-valid.css +18 -0
  60. package/src/stylelint-plugins/test/no-setting-wpds-custom-properties.test.ts +6 -2
  61. package/src/stylelint-plugins/test/no-token-fallback-values.test.ts +51 -0
  62. package/src/stylelint-plugins/test/no-unknown-ds-tokens.test.ts +6 -2
  63. package/src/stylelint-plugins/test/utils/index.ts +7 -4
  64. package/src/vite-plugins/vite-ds-token-fallbacks.mjs +4 -1
  65. package/src/stylelint-plugins/test/.stylelintrc.json +0 -10
@@ -0,0 +1,55 @@
1
+ import stylelint from 'stylelint';
2
+
3
+ const {
4
+ createPlugin,
5
+ utils: { report, ruleMessages, validateOptions },
6
+ } = stylelint;
7
+
8
+ const ruleName = 'plugin-wpds/no-token-fallback-values';
9
+
10
+ /**
11
+ * Matches `var(--wpds-<name>,` — the comma signals a fallback value.
12
+ * Captures the token name (e.g. `--wpds-color-fg-content-neutral`).
13
+ */
14
+ const varWithFallbackRegex = /var\(\s*(--wpds-[\w-]+)\s*,/g;
15
+
16
+ const messages = ruleMessages( ruleName, {
17
+ rejected: ( tokenName ) =>
18
+ `Do not add a fallback value for Design System token '${ tokenName }'. Fallbacks are injected automatically at build time.`,
19
+ } );
20
+
21
+ /** @type {import('stylelint').Rule} */
22
+ const ruleFunction = ( primary ) => {
23
+ return ( root, result ) => {
24
+ const validOptions = validateOptions( result, ruleName, {
25
+ actual: primary,
26
+ possible: [ true ],
27
+ } );
28
+
29
+ if ( ! validOptions ) {
30
+ return;
31
+ }
32
+
33
+ root.walkDecls( ( ruleNode ) => {
34
+ const { value } = ruleNode;
35
+
36
+ let match;
37
+ varWithFallbackRegex.lastIndex = 0;
38
+ while ( ( match = varWithFallbackRegex.exec( value ) ) !== null ) {
39
+ report( {
40
+ message: messages.rejected( match[ 1 ] ),
41
+ node: ruleNode,
42
+ word: match[ 0 ],
43
+ result,
44
+ ruleName,
45
+ } );
46
+ }
47
+ } );
48
+ };
49
+ };
50
+
51
+ ruleFunction.ruleName = ruleName;
52
+ ruleFunction.messages = messages;
53
+
54
+ /** @type {import('stylelint').Plugin} */
55
+ export default createPlugin( ruleName, ruleFunction );
@@ -0,0 +1,6 @@
1
+ {
2
+ "plugins": [ "../no-setting-wpds-custom-properties.mjs" ],
3
+ "rules": {
4
+ "plugin-wpds/no-setting-wpds-custom-properties": true
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "plugins": [ "../no-token-fallback-values.mjs" ],
3
+ "rules": {
4
+ "plugin-wpds/no-token-fallback-values": true
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "plugins": [ "../no-unknown-ds-tokens.mjs" ],
3
+ "rules": {
4
+ "plugin-wpds/no-unknown-ds-tokens": true
5
+ }
6
+ }
@@ -0,0 +1,60 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`flags warnings with invalid css (wpds fallbacks) snapshot matches warnings 1`] = `
4
+ [
5
+ {
6
+ "column": 9,
7
+ "endColumn": 45,
8
+ "endLine": 3,
9
+ "line": 3,
10
+ "rule": "plugin-wpds/no-token-fallback-values",
11
+ "severity": "error",
12
+ "text": "Do not add a fallback value for Design System token '--wpds-color-fg-content-neutral'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
13
+ },
14
+ {
15
+ "column": 20,
16
+ "endColumn": 61,
17
+ "endLine": 4,
18
+ "line": 4,
19
+ "rule": "plugin-wpds/no-token-fallback-values",
20
+ "severity": "error",
21
+ "text": "Do not add a fallback value for Design System token '--wpds-color-bg-surface-neutral-weak'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
22
+ },
23
+ {
24
+ "column": 17,
25
+ "endColumn": 45,
26
+ "endLine": 5,
27
+ "line": 5,
28
+ "rule": "plugin-wpds/no-token-fallback-values",
29
+ "severity": "error",
30
+ "text": "Do not add a fallback value for Design System token '--wpds-border-radius-sm'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
31
+ },
32
+ {
33
+ "column": 11,
34
+ "endColumn": 41,
35
+ "endLine": 10,
36
+ "line": 10,
37
+ "rule": "plugin-wpds/no-token-fallback-values",
38
+ "severity": "error",
39
+ "text": "Do not add a fallback value for Design System token '--wpds-border-width-focus'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
40
+ },
41
+ {
42
+ "column": 53,
43
+ "endColumn": 89,
44
+ "endLine": 10,
45
+ "line": 10,
46
+ "rule": "plugin-wpds/no-token-fallback-values",
47
+ "severity": "error",
48
+ "text": "Do not add a fallback value for Design System token '--wpds-color-stroke-focus-brand'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
49
+ },
50
+ {
51
+ "column": 32,
52
+ "endColumn": 68,
53
+ "endLine": 15,
54
+ "line": 15,
55
+ "rule": "plugin-wpds/no-token-fallback-values",
56
+ "severity": "error",
57
+ "text": "Do not add a fallback value for Design System token '--wpds-color-fg-content-neutral'. Fallbacks are injected automatically at build time. (plugin-wpds/no-token-fallback-values)",
58
+ },
59
+ ]
60
+ `;
@@ -0,0 +1,16 @@
1
+ /* Invalid: Using wpds tokens with fallbacks */
2
+ .with-fallback {
3
+ color: var(--wpds-color-fg-content-neutral, #1e1e1e);
4
+ background-color: var(--wpds-color-bg-surface-neutral-weak, #f0f0f0);
5
+ border-radius: var(--wpds-border-radius-sm, 2px);
6
+ }
7
+
8
+ /* Invalid: Fallbacks in complex values */
9
+ .complex {
10
+ outline: var(--wpds-border-width-focus, 2px) solid var(--wpds-color-stroke-focus-brand, #0073aa);
11
+ }
12
+
13
+ /* Invalid: A wpds token with a fallback, even when nested inside another var() */
14
+ .nested-with-fallback {
15
+ color: var(--my-custom-color, var(--wpds-color-fg-content-neutral, #1e1e1e));
16
+ }
@@ -0,0 +1,18 @@
1
+ /* Valid: Using wpds tokens without fallbacks */
2
+ .example {
3
+ color: var(--wpds-color-fg-content-neutral);
4
+ background-color: var(--wpds-color-bg-surface-neutral);
5
+ border-radius: var(--wpds-border-radius-sm);
6
+ padding: var(--wpds-dimension-padding-md);
7
+ }
8
+
9
+ /* Valid: Non-wpds custom properties with fallbacks are fine */
10
+ .other-vars {
11
+ color: var(--my-custom-color, red);
12
+ background: var(--some-other-var, #fff);
13
+ }
14
+
15
+ /* Valid: A wpds token used as a fallback of a non-wpds var, with no comma after the wpds token */
16
+ .nested-no-fallback {
17
+ color: var(--my-custom-color, var(--wpds-color-fg-content-neutral));
18
+ }
@@ -1,11 +1,14 @@
1
1
  import { getStylelintResult } from './utils';
2
2
 
3
+ const CONFIG = './.stylelintrc.no-setting-wpds-custom-properties.json';
4
+
3
5
  describe( 'flags no warnings with valid wpds custom properties css', () => {
4
6
  let result: ReturnType< typeof getStylelintResult >;
5
7
 
6
8
  beforeEach( () => {
7
9
  result = getStylelintResult(
8
- './fixtures/no-setting-wpds-custom-properties-valid.css'
10
+ './fixtures/no-setting-wpds-custom-properties-valid.css',
11
+ CONFIG
9
12
  );
10
13
  } );
11
14
 
@@ -25,7 +28,8 @@ describe( 'flags warnings with invalid wpds custom properties css', () => {
25
28
 
26
29
  beforeEach( () => {
27
30
  result = getStylelintResult(
28
- './fixtures/no-setting-wpds-custom-properties-invalid.css'
31
+ './fixtures/no-setting-wpds-custom-properties-invalid.css',
32
+ CONFIG
29
33
  );
30
34
  } );
31
35
 
@@ -0,0 +1,51 @@
1
+ import { getStylelintResult } from './utils';
2
+
3
+ const CONFIG = './.stylelintrc.no-token-fallback-values.json';
4
+
5
+ describe( 'flags no warnings with valid css (no wpds fallbacks)', () => {
6
+ let result: ReturnType< typeof getStylelintResult >;
7
+
8
+ beforeEach( () => {
9
+ result = getStylelintResult(
10
+ './fixtures/no-token-fallback-values-valid.css',
11
+ CONFIG
12
+ );
13
+ } );
14
+
15
+ it( 'did not error', () => {
16
+ return result.then( ( data ) => expect( data.errored ).toBeFalsy() );
17
+ } );
18
+
19
+ it( 'flags no warnings', () => {
20
+ return result.then( ( data ) =>
21
+ expect( data.results[ 0 ].warnings ).toHaveLength( 0 )
22
+ );
23
+ } );
24
+ } );
25
+
26
+ describe( 'flags warnings with invalid css (wpds fallbacks)', () => {
27
+ let result: ReturnType< typeof getStylelintResult >;
28
+
29
+ beforeEach( () => {
30
+ result = getStylelintResult(
31
+ './fixtures/no-token-fallback-values-invalid.css',
32
+ CONFIG
33
+ );
34
+ } );
35
+
36
+ it( 'did error', () => {
37
+ return result.then( ( data ) => expect( data.errored ).toBeTruthy() );
38
+ } );
39
+
40
+ it( 'flags correct number of warnings', () => {
41
+ return result.then( ( data ) =>
42
+ expect( data.results[ 0 ].warnings ).toHaveLength( 6 )
43
+ );
44
+ } );
45
+
46
+ it( 'snapshot matches warnings', () => {
47
+ return result.then( ( data ) =>
48
+ expect( data.results[ 0 ].warnings ).toMatchSnapshot()
49
+ );
50
+ } );
51
+ } );
@@ -1,11 +1,14 @@
1
1
  import { getStylelintResult } from './utils';
2
2
 
3
+ const CONFIG = './.stylelintrc.no-unknown-ds-tokens.json';
4
+
3
5
  describe( 'flags no warnings with valid wpds tokens css', () => {
4
6
  let result: ReturnType< typeof getStylelintResult >;
5
7
 
6
8
  beforeEach( () => {
7
9
  result = getStylelintResult(
8
- './fixtures/no-unknown-ds-tokens-valid.css'
10
+ './fixtures/no-unknown-ds-tokens-valid.css',
11
+ CONFIG
9
12
  );
10
13
  } );
11
14
 
@@ -25,7 +28,8 @@ describe( 'flags warnings with invalid wpds tokens css', () => {
25
28
 
26
29
  beforeEach( () => {
27
30
  result = getStylelintResult(
28
- './fixtures/no-unknown-ds-tokens-invalid.css'
31
+ './fixtures/no-unknown-ds-tokens-invalid.css',
32
+ CONFIG
29
33
  );
30
34
  } );
31
35
 
@@ -4,17 +4,20 @@ import childProcess from 'node:child_process';
4
4
 
5
5
  const execute = util.promisify( childProcess.exec );
6
6
 
7
- const generateStylelintCommand = ( filename: string ): string =>
7
+ const generateStylelintCommand = (
8
+ filename: string,
9
+ configFile: string
10
+ ): string =>
8
11
  'npx stylelint ' +
9
12
  path.resolve( __dirname, '../', filename ) +
10
13
  ' -c ' +
11
- path.resolve( __dirname, '../', './.stylelintrc.json' ) +
14
+ path.resolve( __dirname, '../', configFile ) +
12
15
  ' --formatter json' +
13
16
  ' --ignore-path ' +
14
17
  path.resolve( __dirname, '../', './.stylelintignore' );
15
18
 
16
- export const getStylelintResult = ( filename: string ) =>
17
- execute( generateStylelintCommand( filename ) )
19
+ export const getStylelintResult = ( filename: string, configFile: string ) =>
20
+ execute( generateStylelintCommand( filename, configFile ) )
18
21
  .then( ( { stderr } ) => {
19
22
  return {
20
23
  errored: false,
@@ -21,7 +21,10 @@ const plugin = () => ( {
21
21
  }
22
22
  // Sourcemap omitted: replacements are small, inline substitutions
23
23
  // that preserve line structure, so the debugging impact is negligible.
24
- return { code: addFallbackToVar( code ), map: null };
24
+ return {
25
+ code: addFallbackToVar( code, { escapeQuotes: true } ),
26
+ map: null,
27
+ };
25
28
  },
26
29
  } );
27
30
 
@@ -1,10 +0,0 @@
1
- {
2
- "plugins": [
3
- "../no-unknown-ds-tokens.mjs",
4
- "../no-setting-wpds-custom-properties.mjs"
5
- ],
6
- "rules": {
7
- "plugin-wpds/no-unknown-ds-tokens": true,
8
- "plugin-wpds/no-setting-wpds-custom-properties": true
9
- }
10
- }