@wordpress/theme 0.4.0 → 0.4.1-next.8fd3f8831.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/CHANGELOG.md +9 -0
- package/README.md +43 -33
- package/build/color-ramps/{index.js → index.cjs} +8 -8
- package/build/color-ramps/lib/{color-utils.js → color-utils.cjs} +2 -2
- package/build/color-ramps/lib/{constants.js → constants.cjs} +2 -2
- package/build/color-ramps/lib/{default-ramps.js → default-ramps.cjs} +1 -1
- package/build/color-ramps/lib/{find-color-with-constraints.js → find-color-with-constraints.cjs} +6 -6
- package/build/color-ramps/lib/{index.js → index.cjs} +6 -6
- package/build/color-ramps/lib/{ramp-configs.js → ramp-configs.cjs} +1 -1
- package/build/color-ramps/lib/{register-color-spaces.js → register-color-spaces.cjs} +1 -1
- package/build/color-ramps/lib/{taper-chroma.js → taper-chroma.cjs} +2 -2
- package/build/color-ramps/lib/{types.js → types.cjs} +1 -1
- package/build/color-ramps/lib/{utils.js → utils.cjs} +4 -4
- package/build/{context.js → context.cjs} +1 -1
- package/build/{index.js → index.cjs} +2 -2
- package/build/index.cjs.map +7 -0
- package/build/{lock-unlock.js → lock-unlock.cjs} +1 -1
- package/build/prebuilt/js/{design-tokens.js → design-tokens.cjs} +1 -1
- package/build/prebuilt/ts/{color-tokens.js → color-tokens.cjs} +1 -1
- package/build/prebuilt/ts/token-types.cjs +18 -0
- package/build/prebuilt/ts/token-types.cjs.map +7 -0
- package/build/{private-apis.js → private-apis.cjs} +4 -4
- package/build/{theme-provider.js → theme-provider.cjs} +3 -3
- package/build/{types.js → types.cjs} +1 -1
- package/build/{use-theme-provider-styles.js → use-theme-provider-styles.cjs} +6 -6
- package/build-module/color-ramps/index.js +7 -7
- package/build-module/color-ramps/lib/color-utils.js +1 -1
- package/build-module/color-ramps/lib/constants.js +1 -1
- package/build-module/color-ramps/lib/find-color-with-constraints.js +5 -5
- package/build-module/color-ramps/lib/index.js +5 -5
- package/build-module/color-ramps/lib/taper-chroma.js +1 -1
- package/build-module/color-ramps/lib/utils.js +3 -3
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +2 -2
- package/build-module/prebuilt/ts/token-types.js +1 -0
- package/build-module/prebuilt/ts/token-types.js.map +7 -0
- package/build-module/private-apis.js +3 -3
- package/build-module/theme-provider.js +2 -2
- package/build-module/use-theme-provider-styles.js +4 -4
- package/build-types/index.d.ts +2 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/prebuilt/ts/token-types.d.ts +49 -0
- package/build-types/prebuilt/ts/token-types.d.ts.map +1 -0
- package/package.json +14 -6
- package/src/index.ts +2 -1
- package/src/prebuilt/ts/token-types.ts +125 -0
- package/bin/generate-default-ramps/index.ts +0 -49
- package/bin/generate-primitive-tokens/index.ts +0 -113
- package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +0 -84
- package/bin/terrazzo-plugin-inline-alias-values/index.ts +0 -113
- package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +0 -52
- package/bin/terrazzo-plugin-mode-overrides/index.ts +0 -208
- package/build/index.js.map +0 -7
- package/docs/ds-tokens.md +0 -176
- package/terrazzo.config.ts +0 -123
- package/tokens/border.json +0 -56
- package/tokens/color.json +0 -1559
- package/tokens/dimension.json +0 -169
- package/tokens/elevation.json +0 -201
- package/tokens/modes/border.high-dpi.json +0 -15
- package/tokens/modes/dimension.comfortable.json +0 -54
- package/tokens/modes/dimension.compact.json +0 -54
- package/tokens/typography.json +0 -93
- package/tsconfig.bin.json +0 -13
- package/tsconfig.bin.tsbuildinfo +0 -1
- package/tsconfig.json +0 -11
- package/tsconfig.src.json +0 -9
- package/tsconfig.src.tsbuildinfo +0 -1
- /package/build/color-ramps/{index.js.map → index.cjs.map} +0 -0
- /package/build/color-ramps/lib/{color-utils.js.map → color-utils.cjs.map} +0 -0
- /package/build/color-ramps/lib/{constants.js.map → constants.cjs.map} +0 -0
- /package/build/color-ramps/lib/{default-ramps.js.map → default-ramps.cjs.map} +0 -0
- /package/build/color-ramps/lib/{find-color-with-constraints.js.map → find-color-with-constraints.cjs.map} +0 -0
- /package/build/color-ramps/lib/{index.js.map → index.cjs.map} +0 -0
- /package/build/color-ramps/lib/{ramp-configs.js.map → ramp-configs.cjs.map} +0 -0
- /package/build/color-ramps/lib/{register-color-spaces.js.map → register-color-spaces.cjs.map} +0 -0
- /package/build/color-ramps/lib/{taper-chroma.js.map → taper-chroma.cjs.map} +0 -0
- /package/build/color-ramps/lib/{types.js.map → types.cjs.map} +0 -0
- /package/build/color-ramps/lib/{utils.js.map → utils.cjs.map} +0 -0
- /package/build/{context.js.map → context.cjs.map} +0 -0
- /package/build/{lock-unlock.js.map → lock-unlock.cjs.map} +0 -0
- /package/build/prebuilt/js/{design-tokens.js.map → design-tokens.cjs.map} +0 -0
- /package/build/prebuilt/ts/{color-tokens.js.map → color-tokens.cjs.map} +0 -0
- /package/build/{private-apis.js.map → private-apis.cjs.map} +0 -0
- /package/build/{theme-provider.js.map → theme-provider.cjs.map} +0 -0
- /package/build/{types.js.map → types.cjs.map} +0 -0
- /package/build/{use-theme-provider-styles.js.map → use-theme-provider-styles.cjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/theme/src/theme-provider.tsx
|
|
2
2
|
import { useMemo, useId } from "@wordpress/element";
|
|
3
|
-
import { ThemeContext } from "./context";
|
|
4
|
-
import { useThemeProviderStyles } from "./use-theme-provider-styles";
|
|
3
|
+
import { ThemeContext } from "./context.js";
|
|
4
|
+
import { useThemeProviderStyles } from "./use-theme-provider-styles.js";
|
|
5
5
|
|
|
6
6
|
// packages/theme/src/style.module.css
|
|
7
7
|
var css = `.style-module__root__26kw6 {
|
|
@@ -9,14 +9,14 @@ import {
|
|
|
9
9
|
} from "colorjs.io/fn";
|
|
10
10
|
import memoize from "memize";
|
|
11
11
|
import { useMemo, useContext } from "@wordpress/element";
|
|
12
|
-
import "./color-ramps/lib/register-color-spaces";
|
|
13
|
-
import { ThemeContext } from "./context";
|
|
14
|
-
import colorTokens from "./prebuilt/ts/color-tokens";
|
|
12
|
+
import "./color-ramps/lib/register-color-spaces.js";
|
|
13
|
+
import { ThemeContext } from "./context.js";
|
|
14
|
+
import colorTokens from "./prebuilt/ts/color-tokens.js";
|
|
15
15
|
import {
|
|
16
16
|
buildBgRamp,
|
|
17
17
|
buildAccentRamp,
|
|
18
18
|
DEFAULT_SEED_COLORS
|
|
19
|
-
} from "./color-ramps";
|
|
19
|
+
} from "./color-ramps/index.js";
|
|
20
20
|
var getCachedBgRamp = memoize(buildBgRamp, { maxSize: 10 });
|
|
21
21
|
var getCachedAccentRamp = memoize(buildAccentRamp, { maxSize: 10 });
|
|
22
22
|
var legacyWpComponentsOverridesCSS = [
|
package/build-types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,mBAAmB,2BAA2B,CAAC;AAC/C,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is generated by the @wordpress/terrazzo-plugin-typescript-types plugin.
|
|
3
|
+
* Do not edit this file directly.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Size scale for padding tokens.
|
|
7
|
+
*/
|
|
8
|
+
export type PaddingSize = '2xs' | 'xs' | 'sm' | 'md' | 'lg';
|
|
9
|
+
/**
|
|
10
|
+
* Size scale for gap tokens.
|
|
11
|
+
*/
|
|
12
|
+
export type GapSize = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
13
|
+
/**
|
|
14
|
+
* Size scale for border radius tokens.
|
|
15
|
+
*/
|
|
16
|
+
export type BorderRadiusSize = 'xs' | 'sm' | 'md' | 'lg';
|
|
17
|
+
/**
|
|
18
|
+
* Size scale for border width tokens.
|
|
19
|
+
*/
|
|
20
|
+
export type BorderWidthSize = 'xs' | 'sm' | 'md' | 'lg';
|
|
21
|
+
/**
|
|
22
|
+
* Target elements that tokens can be applied to.
|
|
23
|
+
*/
|
|
24
|
+
export type Target = 'surface' | 'interactive' | 'track' | 'thumb' | 'content' | 'focus';
|
|
25
|
+
/**
|
|
26
|
+
* Background color variants for surface elements.
|
|
27
|
+
*/
|
|
28
|
+
export type SurfaceBackgroundColor = 'neutral' | 'neutral-strong' | 'neutral-weak' | 'brand' | 'success' | 'success-weak' | 'info' | 'info-weak' | 'warning' | 'warning-weak' | 'caution' | 'caution-weak' | 'error' | 'error-weak';
|
|
29
|
+
/**
|
|
30
|
+
* Background color variants for interactive elements.
|
|
31
|
+
*/
|
|
32
|
+
export type InteractiveBackgroundColor = 'neutral' | 'neutral-strong' | 'neutral-weak' | 'brand' | 'brand-strong' | 'brand-weak' | 'error' | 'error-strong' | 'error-weak';
|
|
33
|
+
/**
|
|
34
|
+
* Foreground color variants for content text and icons.
|
|
35
|
+
*/
|
|
36
|
+
export type ContentForegroundColor = 'neutral' | 'neutral-weak' | 'success' | 'success-weak' | 'info' | 'info-weak' | 'warning' | 'warning-weak' | 'caution' | 'caution-weak' | 'error' | 'error-weak';
|
|
37
|
+
/**
|
|
38
|
+
* Foreground color variants for interactive element text and icons.
|
|
39
|
+
*/
|
|
40
|
+
export type InteractiveForegroundColor = 'neutral' | 'neutral-strong' | 'neutral-weak' | 'brand' | 'brand-strong' | 'error' | 'error-strong';
|
|
41
|
+
/**
|
|
42
|
+
* Stroke color variants for surface borders.
|
|
43
|
+
*/
|
|
44
|
+
export type SurfaceStrokeColor = 'neutral' | 'neutral-weak' | 'neutral-strong' | 'brand' | 'brand-strong' | 'success' | 'success-strong' | 'info' | 'info-strong' | 'warning' | 'warning-strong' | 'error' | 'error-strong';
|
|
45
|
+
/**
|
|
46
|
+
* Stroke color variants for interactive element borders.
|
|
47
|
+
*/
|
|
48
|
+
export type InteractiveStrokeColor = 'neutral' | 'neutral-strong' | 'brand' | 'error' | 'error-strong';
|
|
49
|
+
//# sourceMappingURL=token-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-types.d.ts","sourceRoot":"","sources":["../../../src/prebuilt/ts/token-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,MAAM,GACf,SAAS,GACT,aAAa,GACb,OAAO,GACP,OAAO,GACP,SAAS,GACT,OAAO,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC/B,SAAS,GACT,gBAAgB,GAChB,cAAc,GACd,OAAO,GACP,SAAS,GACT,cAAc,GACd,MAAM,GACN,WAAW,GACX,SAAS,GACT,cAAc,GACd,SAAS,GACT,cAAc,GACd,OAAO,GACP,YAAY,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,0BAA0B,GACnC,SAAS,GACT,gBAAgB,GAChB,cAAc,GACd,OAAO,GACP,cAAc,GACd,YAAY,GACZ,OAAO,GACP,cAAc,GACd,YAAY,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC/B,SAAS,GACT,cAAc,GACd,SAAS,GACT,cAAc,GACd,MAAM,GACN,WAAW,GACX,SAAS,GACT,cAAc,GACd,SAAS,GACT,cAAc,GACd,OAAO,GACP,YAAY,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,0BAA0B,GACnC,SAAS,GACT,gBAAgB,GAChB,cAAc,GACd,OAAO,GACP,cAAc,GACd,OAAO,GACP,cAAc,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC3B,SAAS,GACT,cAAc,GACd,gBAAgB,GAChB,OAAO,GACP,cAAc,GACd,SAAS,GACT,gBAAgB,GAChB,MAAM,GACN,aAAa,GACb,SAAS,GACT,gBAAgB,GAChB,OAAO,GACP,cAAc,CAAC;AAElB;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAC/B,SAAS,GACT,gBAAgB,GAChB,OAAO,GACP,OAAO,GACP,cAAc,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/theme",
|
|
3
|
-
"version": "0.4.0",
|
|
3
|
+
"version": "0.4.1-next.8fd3f8831.0",
|
|
4
4
|
"description": "Theme and context provider for the WordPress Design System.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -22,13 +22,21 @@
|
|
|
22
22
|
"node": ">=18.12.0",
|
|
23
23
|
"npm": ">=8.19.2"
|
|
24
24
|
},
|
|
25
|
-
"
|
|
25
|
+
"files": [
|
|
26
|
+
"src",
|
|
27
|
+
"build",
|
|
28
|
+
"build-module",
|
|
29
|
+
"build-types",
|
|
30
|
+
"*.md"
|
|
31
|
+
],
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "build/index.cjs",
|
|
26
34
|
"module": "build-module/index.js",
|
|
27
35
|
"exports": {
|
|
28
36
|
".": {
|
|
29
37
|
"types": "./build-types/index.d.ts",
|
|
30
38
|
"import": "./build-module/index.js",
|
|
31
|
-
"default": "./build/index.
|
|
39
|
+
"default": "./build/index.cjs"
|
|
32
40
|
},
|
|
33
41
|
"./design-tokens.css": "./src/prebuilt/css/design-tokens.css",
|
|
34
42
|
"./design-tokens.js": "./src/prebuilt/js/design-tokens.js",
|
|
@@ -43,8 +51,8 @@
|
|
|
43
51
|
"build-module/color-ramps/lib/register-color-spaces.js"
|
|
44
52
|
],
|
|
45
53
|
"dependencies": {
|
|
46
|
-
"@wordpress/element": "^6.
|
|
47
|
-
"@wordpress/private-apis": "^1.
|
|
54
|
+
"@wordpress/element": "^6.36.1-next.8fd3f8831.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.36.1-next.8fd3f8831.0",
|
|
48
56
|
"colorjs.io": "^0.5.2",
|
|
49
57
|
"memize": "^2.1.0"
|
|
50
58
|
},
|
|
@@ -64,5 +72,5 @@
|
|
|
64
72
|
"build": "npm run build:tokens && npm run build:default-ramps",
|
|
65
73
|
"postbuild": "prettier --write tokens/color.json tokens/modes src/prebuilt src/color-ramps/lib/default-ramps.ts docs"
|
|
66
74
|
},
|
|
67
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "e582b351bc4c4b8734bb087f63a3beec9875c3c7"
|
|
68
76
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is generated by the @wordpress/terrazzo-plugin-typescript-types plugin.
|
|
3
|
+
* Do not edit this file directly.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Size scale for padding tokens.
|
|
8
|
+
*/
|
|
9
|
+
export type PaddingSize = '2xs' | 'xs' | 'sm' | 'md' | 'lg';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Size scale for gap tokens.
|
|
13
|
+
*/
|
|
14
|
+
export type GapSize = '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Size scale for border radius tokens.
|
|
18
|
+
*/
|
|
19
|
+
export type BorderRadiusSize = 'xs' | 'sm' | 'md' | 'lg';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Size scale for border width tokens.
|
|
23
|
+
*/
|
|
24
|
+
export type BorderWidthSize = 'xs' | 'sm' | 'md' | 'lg';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Target elements that tokens can be applied to.
|
|
28
|
+
*/
|
|
29
|
+
export type Target =
|
|
30
|
+
| 'surface'
|
|
31
|
+
| 'interactive'
|
|
32
|
+
| 'track'
|
|
33
|
+
| 'thumb'
|
|
34
|
+
| 'content'
|
|
35
|
+
| 'focus';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Background color variants for surface elements.
|
|
39
|
+
*/
|
|
40
|
+
export type SurfaceBackgroundColor =
|
|
41
|
+
| 'neutral'
|
|
42
|
+
| 'neutral-strong'
|
|
43
|
+
| 'neutral-weak'
|
|
44
|
+
| 'brand'
|
|
45
|
+
| 'success'
|
|
46
|
+
| 'success-weak'
|
|
47
|
+
| 'info'
|
|
48
|
+
| 'info-weak'
|
|
49
|
+
| 'warning'
|
|
50
|
+
| 'warning-weak'
|
|
51
|
+
| 'caution'
|
|
52
|
+
| 'caution-weak'
|
|
53
|
+
| 'error'
|
|
54
|
+
| 'error-weak';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Background color variants for interactive elements.
|
|
58
|
+
*/
|
|
59
|
+
export type InteractiveBackgroundColor =
|
|
60
|
+
| 'neutral'
|
|
61
|
+
| 'neutral-strong'
|
|
62
|
+
| 'neutral-weak'
|
|
63
|
+
| 'brand'
|
|
64
|
+
| 'brand-strong'
|
|
65
|
+
| 'brand-weak'
|
|
66
|
+
| 'error'
|
|
67
|
+
| 'error-strong'
|
|
68
|
+
| 'error-weak';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Foreground color variants for content text and icons.
|
|
72
|
+
*/
|
|
73
|
+
export type ContentForegroundColor =
|
|
74
|
+
| 'neutral'
|
|
75
|
+
| 'neutral-weak'
|
|
76
|
+
| 'success'
|
|
77
|
+
| 'success-weak'
|
|
78
|
+
| 'info'
|
|
79
|
+
| 'info-weak'
|
|
80
|
+
| 'warning'
|
|
81
|
+
| 'warning-weak'
|
|
82
|
+
| 'caution'
|
|
83
|
+
| 'caution-weak'
|
|
84
|
+
| 'error'
|
|
85
|
+
| 'error-weak';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Foreground color variants for interactive element text and icons.
|
|
89
|
+
*/
|
|
90
|
+
export type InteractiveForegroundColor =
|
|
91
|
+
| 'neutral'
|
|
92
|
+
| 'neutral-strong'
|
|
93
|
+
| 'neutral-weak'
|
|
94
|
+
| 'brand'
|
|
95
|
+
| 'brand-strong'
|
|
96
|
+
| 'error'
|
|
97
|
+
| 'error-strong';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Stroke color variants for surface borders.
|
|
101
|
+
*/
|
|
102
|
+
export type SurfaceStrokeColor =
|
|
103
|
+
| 'neutral'
|
|
104
|
+
| 'neutral-weak'
|
|
105
|
+
| 'neutral-strong'
|
|
106
|
+
| 'brand'
|
|
107
|
+
| 'brand-strong'
|
|
108
|
+
| 'success'
|
|
109
|
+
| 'success-strong'
|
|
110
|
+
| 'info'
|
|
111
|
+
| 'info-strong'
|
|
112
|
+
| 'warning'
|
|
113
|
+
| 'warning-strong'
|
|
114
|
+
| 'error'
|
|
115
|
+
| 'error-strong';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Stroke color variants for interactive element borders.
|
|
119
|
+
*/
|
|
120
|
+
export type InteractiveStrokeColor =
|
|
121
|
+
| 'neutral'
|
|
122
|
+
| 'neutral-strong'
|
|
123
|
+
| 'brand'
|
|
124
|
+
| 'error'
|
|
125
|
+
| 'error-strong';
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { writeFile } from 'node:fs/promises';
|
|
5
|
-
import { dirname, join } from 'node:path';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import {
|
|
12
|
-
DEFAULT_SEED_COLORS,
|
|
13
|
-
buildBgRamp,
|
|
14
|
-
buildAccentRamp,
|
|
15
|
-
} from '../../src/color-ramps/index.ts';
|
|
16
|
-
|
|
17
|
-
const __dirname = dirname( fileURLToPath( import.meta.url ) );
|
|
18
|
-
|
|
19
|
-
const bgRamp = buildBgRamp( DEFAULT_SEED_COLORS.bg );
|
|
20
|
-
const accentRamps = Object.fromEntries(
|
|
21
|
-
[ ...Object.entries( DEFAULT_SEED_COLORS ) ]
|
|
22
|
-
.filter( ( [ scaleName ] ) => scaleName !== 'bg' )
|
|
23
|
-
.map( ( [ scaleName, seed ] ) => [
|
|
24
|
-
scaleName,
|
|
25
|
-
buildAccentRamp( seed, bgRamp ),
|
|
26
|
-
] )
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const ramps = { bg: bgRamp, ...accentRamps };
|
|
30
|
-
|
|
31
|
-
const outputPath = join(
|
|
32
|
-
__dirname,
|
|
33
|
-
'../../src/color-ramps/lib/default-ramps.ts'
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const content = `
|
|
37
|
-
/**
|
|
38
|
-
* Internal dependencies
|
|
39
|
-
*/
|
|
40
|
-
import type { RampResult } from './types';
|
|
41
|
-
import type { DEFAULT_SEED_COLORS } from './constants';
|
|
42
|
-
|
|
43
|
-
export const DEFAULT_RAMPS: Record<
|
|
44
|
-
keyof typeof DEFAULT_SEED_COLORS,
|
|
45
|
-
RampResult
|
|
46
|
-
> = ${ JSON.stringify( ramps ) };
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
await writeFile( outputPath, content );
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
7
|
-
import { parse, to, serialize, sRGB } from 'colorjs.io/fn';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
import '../../src/color-ramps/lib/register-color-spaces';
|
|
13
|
-
import {
|
|
14
|
-
DEFAULT_SEED_COLORS,
|
|
15
|
-
buildBgRamp,
|
|
16
|
-
buildAccentRamp,
|
|
17
|
-
} from '../../src/color-ramps/index';
|
|
18
|
-
|
|
19
|
-
const __filename = fileURLToPath( import.meta.url );
|
|
20
|
-
const __dirname = path.dirname( __filename );
|
|
21
|
-
|
|
22
|
-
// Path to the color.json file
|
|
23
|
-
const colorJsonPath = path.join( __dirname, '../../tokens/color.json' );
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Rounds a given hex value (0-255) to 3 decimal places.
|
|
27
|
-
*
|
|
28
|
-
* 3 decimal places is the minimum precision for lossless hex serialization.
|
|
29
|
-
* With 3 decimal places rounding to the nearest 0.001, the maximum rounding
|
|
30
|
-
* error is 0.0005. With 256 possible hex values, 0.0005 × 256 = 0.128,
|
|
31
|
-
* guaranteeing the rounded value stays within 0.5 of the original value.
|
|
32
|
-
*
|
|
33
|
-
* @param n - The hex value to round.
|
|
34
|
-
* @return The rounded hex value.
|
|
35
|
-
*/
|
|
36
|
-
const roundHexComponent = ( n: number ) => Math.round( n * 1000 ) / 1000;
|
|
37
|
-
|
|
38
|
-
const transformColorStringToDTCGValue = ( color: string ) => {
|
|
39
|
-
const parsed = to( parse( color ), sRGB );
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
colorSpace: 'srgb',
|
|
43
|
-
components: parsed.coords.map( roundHexComponent ),
|
|
44
|
-
...( parsed.alpha < 1 ? { alpha: parsed.alpha } : undefined ),
|
|
45
|
-
hex: serialize( parsed, { format: 'hex' } ),
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Main function
|
|
50
|
-
function generatePrimitiveColorTokens() {
|
|
51
|
-
const startTime = performance.now();
|
|
52
|
-
console.log( '🎨 Starting primitive color tokens generation...' );
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
// Read the color.json file
|
|
56
|
-
const colorJson = JSON.parse(
|
|
57
|
-
fs.readFileSync( colorJsonPath, 'utf8' )
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Build the ramps
|
|
61
|
-
const bgRamp = buildBgRamp( DEFAULT_SEED_COLORS.bg );
|
|
62
|
-
const accentRamps = [ ...Object.entries( DEFAULT_SEED_COLORS ) ]
|
|
63
|
-
.filter( ( [ scaleName ] ) => scaleName !== 'bg' )
|
|
64
|
-
.map( ( [ scaleName, seed ] ) => ( {
|
|
65
|
-
scaleName,
|
|
66
|
-
ramp: buildAccentRamp( seed, bgRamp ),
|
|
67
|
-
} ) );
|
|
68
|
-
|
|
69
|
-
// Convert the ramp values in a DTCG compatible format
|
|
70
|
-
[
|
|
71
|
-
{
|
|
72
|
-
scaleName: 'bg',
|
|
73
|
-
ramp: bgRamp,
|
|
74
|
-
},
|
|
75
|
-
...accentRamps,
|
|
76
|
-
].forEach( ( { scaleName, ramp } ) => {
|
|
77
|
-
colorJson[ 'wpds-color' ].primitive[ scaleName ] = {};
|
|
78
|
-
for ( const [ tokenName, tokenValue ] of Object.entries(
|
|
79
|
-
ramp.ramp
|
|
80
|
-
) ) {
|
|
81
|
-
colorJson[ 'wpds-color' ].primitive[ scaleName ][ tokenName ] =
|
|
82
|
-
{
|
|
83
|
-
$value: transformColorStringToDTCGValue( tokenValue ),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
} );
|
|
87
|
-
|
|
88
|
-
// Write the updated JSON back to the file with proper formatting
|
|
89
|
-
fs.writeFileSync(
|
|
90
|
-
colorJsonPath,
|
|
91
|
-
JSON.stringify( colorJson, null, '\t' )
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const endTime = performance.now();
|
|
95
|
-
const duration = endTime - startTime;
|
|
96
|
-
console.log(
|
|
97
|
-
`✅ Successfully updated color.json (${ duration.toFixed( 2 ) }ms)`
|
|
98
|
-
);
|
|
99
|
-
} catch ( error ) {
|
|
100
|
-
const endTime = performance.now();
|
|
101
|
-
const duration = endTime - startTime;
|
|
102
|
-
console.error(
|
|
103
|
-
`❌ Error updating color tokens after ${ duration.toFixed(
|
|
104
|
-
2
|
|
105
|
-
) }ms:`,
|
|
106
|
-
error
|
|
107
|
-
);
|
|
108
|
-
process.exit( 1 );
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Run the script
|
|
113
|
-
generatePrimitiveColorTokens();
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { FORMAT_ID } from '@terrazzo/plugin-css';
|
|
5
|
-
import type { Plugin } from '@terrazzo/parser';
|
|
6
|
-
|
|
7
|
-
function titleCase( str: string ) {
|
|
8
|
-
return str[ 0 ].toUpperCase() + str.slice( 1 );
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type TokensMap = Record< string, Record< string, string > >;
|
|
12
|
-
|
|
13
|
-
export default function pluginDsTokenDocs( {
|
|
14
|
-
filename = 'design-tokens.md',
|
|
15
|
-
} = {} ): Plugin {
|
|
16
|
-
return {
|
|
17
|
-
name: '@terrazzo/terrazzo-plugin-ds-tokens-docs',
|
|
18
|
-
async build( { getTransforms, outputFile } ) {
|
|
19
|
-
if ( ! filename ) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const semanticTokens: TokensMap = {};
|
|
24
|
-
// Re-use transformed tokens from the CSS plugin
|
|
25
|
-
for ( const token of getTransforms( {
|
|
26
|
-
format: FORMAT_ID,
|
|
27
|
-
id: '*',
|
|
28
|
-
mode: '.',
|
|
29
|
-
} ) ) {
|
|
30
|
-
if ( token.localID === undefined ) {
|
|
31
|
-
console.warn(
|
|
32
|
-
'Unexpected — Missing local ID when building token list for eslint plugin'
|
|
33
|
-
);
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Use the tokens filename (without .json) as the group name
|
|
38
|
-
const group =
|
|
39
|
-
token.token.source.loc
|
|
40
|
-
?.split( '/' )
|
|
41
|
-
.at( -1 )
|
|
42
|
-
?.split( '.json' )[ 0 ] ?? 'Miscellaneous';
|
|
43
|
-
|
|
44
|
-
// Group by category
|
|
45
|
-
semanticTokens[ group ] ??= {};
|
|
46
|
-
semanticTokens[ group ][ token.localID ] =
|
|
47
|
-
token.token.$description ?? 'N/A';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function tokensToMdTable( tokens: TokensMap ) {
|
|
51
|
-
return Object.entries( tokens )
|
|
52
|
-
.map( ( [ group, tokensInGroup ] ) => [
|
|
53
|
-
`### ${ titleCase( group ) }`,
|
|
54
|
-
'',
|
|
55
|
-
'| Variable name | Description |',
|
|
56
|
-
'|---|---|',
|
|
57
|
-
...Object.entries( tokensInGroup ).map(
|
|
58
|
-
( [ name, description ] ) =>
|
|
59
|
-
`| \`${ name }\` | ${ description } |`
|
|
60
|
-
),
|
|
61
|
-
'',
|
|
62
|
-
] )
|
|
63
|
-
.flat( 2 );
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
outputFile(
|
|
67
|
-
filename,
|
|
68
|
-
[
|
|
69
|
-
'<!--',
|
|
70
|
-
'This file is generated by @terrazzo/terrazzo-plugin-ds-tokens-docs.',
|
|
71
|
-
'Do not edit directly.',
|
|
72
|
-
'-->',
|
|
73
|
-
'',
|
|
74
|
-
'# DS Tokens reference',
|
|
75
|
-
'',
|
|
76
|
-
'## Semantic tokens',
|
|
77
|
-
'',
|
|
78
|
-
...tokensToMdTable( semanticTokens ),
|
|
79
|
-
'', // final empty line
|
|
80
|
-
].join( '\n' )
|
|
81
|
-
);
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { type Plugin, type TokenNormalized } 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
|
-
// Map of primitive token ID -> array of references to inline
|
|
44
|
-
const inlineMap: Record< string, TokenNormalized[] > = {};
|
|
45
|
-
|
|
46
|
-
// Single pass: identify primitives and collect references
|
|
47
|
-
for ( const [ id, token ] of Object.entries( tokens ) ) {
|
|
48
|
-
const shouldInline = pattern.test( id );
|
|
49
|
-
|
|
50
|
-
if ( shouldInline ) {
|
|
51
|
-
// Track this token for inlining
|
|
52
|
-
inlineMap[ id ] = [];
|
|
53
|
-
|
|
54
|
-
// Track aliased tokens for output file
|
|
55
|
-
if ( token.aliasedBy ) {
|
|
56
|
-
aliasedBy[ tokenId( id ) ] =
|
|
57
|
-
token.aliasedBy.map( tokenId );
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Check if this token's main value references a primitive
|
|
62
|
-
if ( token.aliasOf && pattern.test( token.aliasOf ) ) {
|
|
63
|
-
inlineMap[ token.aliasOf ] ??= [];
|
|
64
|
-
inlineMap[ token.aliasOf ].push( token );
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Check if any mode values reference a primitive
|
|
68
|
-
for ( const modeValue of Object.values( token.mode ) ) {
|
|
69
|
-
const { aliasOf } = modeValue;
|
|
70
|
-
if ( aliasOf && pattern.test( aliasOf ) ) {
|
|
71
|
-
const primitiveId = aliasOf;
|
|
72
|
-
inlineMap[ primitiveId ] ??= [];
|
|
73
|
-
inlineMap[ primitiveId ].push( modeValue );
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Inline values and delete primitives
|
|
79
|
-
for ( const [ id, references ] of Object.entries( inlineMap ) ) {
|
|
80
|
-
const token = tokens[ id ];
|
|
81
|
-
|
|
82
|
-
for ( const target of references ) {
|
|
83
|
-
target.$value = token.$value;
|
|
84
|
-
target.originalValue = token.originalValue;
|
|
85
|
-
delete target.aliasOf;
|
|
86
|
-
delete target.aliasChain;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
delete tokens[ id ];
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
async build( { outputFile } ) {
|
|
93
|
-
if ( ! filename ) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const json = JSON.stringify( aliasedBy, null, 2 );
|
|
98
|
-
|
|
99
|
-
outputFile(
|
|
100
|
-
filename,
|
|
101
|
-
[
|
|
102
|
-
'/**',
|
|
103
|
-
' * This file is generated by the @wordpress/terrazzo-plugin-inline-alias-values plugin.',
|
|
104
|
-
' * Do not edit this file directly.',
|
|
105
|
-
' */',
|
|
106
|
-
'',
|
|
107
|
-
`export default ${ json } as Record< string, string[] >;`,
|
|
108
|
-
'',
|
|
109
|
-
].join( '\n' )
|
|
110
|
-
);
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { FORMAT_ID } from '@terrazzo/plugin-css';
|
|
5
|
-
import type { Plugin } from '@terrazzo/parser';
|
|
6
|
-
|
|
7
|
-
export default function pluginKnownWpdsCssVariables( {
|
|
8
|
-
filename = 'design-tokens.js',
|
|
9
|
-
} = {} ): Plugin {
|
|
10
|
-
return {
|
|
11
|
-
name: '@terrazzo/plugin-known-wpds-css-variables',
|
|
12
|
-
async build( { getTransforms, outputFile } ) {
|
|
13
|
-
// Either a string (modes=false) or an object (modes=true)
|
|
14
|
-
const tokensToExport: Record<
|
|
15
|
-
string,
|
|
16
|
-
Record< string, string | Record< string, string > >
|
|
17
|
-
> = {};
|
|
18
|
-
|
|
19
|
-
for ( const token of getTransforms( {
|
|
20
|
-
format: FORMAT_ID,
|
|
21
|
-
id: '*',
|
|
22
|
-
} ) ) {
|
|
23
|
-
if ( ! token.localID ) {
|
|
24
|
-
console.warn(
|
|
25
|
-
'Unexpected — Missing local ID when building token list for eslint plugin'
|
|
26
|
-
);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
tokensToExport[ token.localID ] ??= {};
|
|
31
|
-
tokensToExport[ token.localID ][ token.mode ] = token.value;
|
|
32
|
-
}
|
|
33
|
-
|
|
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
|
-
);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|